diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/assigned.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/assigned.php index 32b7ef734..6d2a558c3 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/assigned.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/assigned.php @@ -8,20 +8,35 @@ class Assigned{ ////////////////////////////////////////////Functions//////////////////////////////////////////////////// //Assigns a ticket to a user or returns error message - public static function AssignTicket( $user_id, $ticket_id) { + public static function assignTicket( $user_id, $ticket_id) { $dbl = new DBLayer("lib"); //check if ticket is already assigned, if so return "ALREADY ASSIGNED" if(! Assigned::isAssigned($ticket_id)){ $assignation = new Assigned(); $assignation->set(array('User' => $user_id, 'Ticket' => $ticket_id)); $assignation->create(); - return "SUCCESS"; + return "SUCCESS_ASSIGNED"; }else{ return "ALREADY_ASSIGNED"; } } + //Unsign a ticket to a user or returns error message + public static function unAssignTicket( $user_id, $ticket_id) { + $dbl = new DBLayer("lib"); + //check if ticket is really assigned to that user + if( Assigned::isAssigned($ticket_id, $user_id)){ + $assignation = new Assigned(); + $assignation->set(array('User' => $user_id, 'Ticket' => $ticket_id)); + $assignation->delete(); + return "SUCCESS_UNASSIGNED"; + }else{ + return "NOT_ASSIGNED"; + } + + } + // Get the id of the user assigned to a ticket public static function getUserAssignedToTicket($ticket_id) { $dbl = new DBLayer("lib"); @@ -33,10 +48,13 @@ class Assigned{ } - public static function isAssigned( $ticket_id ) { + public static function isAssigned( $ticket_id, $user_id = 0) { $dbl = new DBLayer("lib"); //check if ticket is already assigned - if( $dbl->execute(" SELECT * FROM `assigned` WHERE `Ticket` = :ticket_id", array('ticket_id' => $ticket_id) )->rowCount() ){ + + if($user_id == 0 && $dbl->execute(" SELECT * FROM `assigned` WHERE `Ticket` = :ticket_id", array('ticket_id' => $ticket_id) )->rowCount() ){ + return true; + }else if( $dbl->execute(" SELECT * FROM `assigned` WHERE `Ticket` = :ticket_id and `User` = :user_id", array('ticket_id' => $ticket_id, 'user_id' => $user_id) )->rowCount()){ return true; }else{ return false; @@ -51,12 +69,12 @@ class Assigned{ //set values public function set($values) { $this->setUser($values['User']); - $this->setGroup($values['Ticket']); + $this->setTicket($values['Ticket']); } public function create() { $dbl = new DBLayer("lib"); - $query = "INSERT INTO `assigned' (`User`,`Ticket`) VALUES (:user, :ticket)"; + $query = "INSERT INTO `assigned` (`User`,`Ticket`) VALUES (:user, :ticket)"; $values = Array('user' => $this->getUser(), 'ticket' => $this->getTicket()); $dbl->execute($query, $values); } @@ -65,7 +83,7 @@ class Assigned{ public function delete() { $dbl = new DBLayer("lib"); $query = "DELETE FROM `assigned` WHERE `User` = :user_id and `Ticket` = :ticket_id"; - $values = array('user_id' => $this->getUser() ,'ticket_id' => $this->getGroup()); + $values = array('user_id' => $this->getUser() ,'ticket_id' => $this->getTicket()); $dbl->execute($query, $values); } diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket.php index cfcd6f3df..24732f3f4 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket.php @@ -10,7 +10,21 @@ class Ticket{ private $author; private $priority; - ////////////////////////////////////////////Functions//////////////////////////////////////////////////// + ////////////////////////////////////////////Functions//////////////////////////////////////////////////// + + /*FUNCTION: ticketExists + * returns true if ticket exists + * + */ + public static function ticketExists($id) { + $dbl = new DBLayer("lib"); + //check if ticket is already assigned + if( $dbl->execute(" SELECT * FROM `ticket` WHERE `TId` = :ticket_id", array('ticket_id' => $id) )->rowCount() ){ + return true; + }else{ + return false; + } + } /*FUNCTION: getStatusArray * returns all possible statusses @@ -130,7 +144,23 @@ class Ticket{ } } + //returns SUCCESS_ASSIGNED, TICKET_NOT_EXISTING or ALREADY_ASSIGNED + public static function assignTicket($user_id, $ticket_id){ + if(self::ticketExists($ticket_id)){ + return Assigned::assignTicket($user_id, $ticket_id); + }else{ + return "TICKET_NOT_EXISTING"; + } + } + //returns SUCCESS_UNASSIGNED, TICKET_NOT_EXISTING or NOT_ASSIGNED + public static function unAssignTicket($user_id, $ticket_id){ + if(self::ticketExists($ticket_id)){ + return Assigned::unAssignTicket($user_id, $ticket_id); + }else{ + return "TICKET_NOT_EXISTING"; + } + } ////////////////////////////////////////////Methods//////////////////////////////////////////////////// public function __construct() { diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini index 930ab69f1..8f5613e9f 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini @@ -30,7 +30,12 @@ t_send = "Send reply" [show_user] [show_queue] -not_assigned = "None" +not_assigned = "Open" +success_assigned = "The ticket was successfully assigned!" +success_unassigned = "The ticket was successfully unassigned!" +ticket_not_existing = "That ticket doesn't exist!" +already_assigned = "That ticket is already assigned to someone!" +not_assigned = "That ticket isn't assigned to you!" [show_sgroup] add_to_group_success = "The user has been added to the group!" diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/fr.ini b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/fr.ini index 8a9257305..f3f208a0f 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/fr.ini +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/fr.ini @@ -30,7 +30,7 @@ t_send = "Envoyer la reponse" [show_user] [show_queue] -not_assigned = "Ne pas" +not_assigned = "Libre" [show_sgroup] add_to_group_success = "ce user est ajoute sur la groupe!" diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_queue.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_queue.php index ff8818e4f..097b5c4f7 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_queue.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_queue.php @@ -4,24 +4,43 @@ function show_queue(){ //if logged in & queue id is given if(WebUsers::isLoggedIn() && isset($_GET['get'])){ + if( Ticket_User::isMod($_SESSION['ticket_user'])){ - $result['queue_action'] = filter_var($_GET['get'], FILTER_SANITIZE_STRING); + $result['queue_view'] = filter_var($_GET['get'], FILTER_SANITIZE_STRING); - $queueArray = Ticket_Queue_Handler::getTickets($result['queue_action']); - if ($queueArray != "ERROR"){ + $queueArray = Ticket_Queue_Handler::getTickets($result['queue_view']); + + //if queue_view is a valid parameter value + if ($queueArray != "ERROR"){ + + $user_id = $_SESSION['ticket_user']->getTUserId(); + + if(isset($_POST['action'])){ + switch($_POST['action']){ + case "assignTicket": + $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT); + $result['ACTION_RESULT'] = Ticket::assignTicket($user_id, $ticket_id); + break; + case "unAssignTicket": + + $ticket_id = filter_var($_POST['ticket_id'], FILTER_SANITIZE_NUMBER_INT); + $result['ACTION_RESULT'] = Ticket::unAssignTicket($user_id, $ticket_id); + break; + } + } + $result['tickets'] = Gui_Elements::make_table($queueArray, Array("getTId","getTitle","getTimestamp","getAuthor()->getExternId","getTicket_Category()->getName","getStatus","getStatusText","getAssigned"), Array("tId","title","timestamp","authorExtern","category","status","statusText","assigned")); - $i = 0; foreach( $result['tickets'] as $ticket){ $result['tickets'][$i]['author'] = WebUsers::getUsername($ticket['authorExtern']); $result['tickets'][$i]['assignedText'] = WebUsers::getUsername($ticket['assigned']); $i++; } - if(Ticket_User::isMod($_SESSION['ticket_user'])){ - $result['isMod'] = "TRUE"; - } + $result['user_id'] = $_SESSION['ticket_user']->getTUserId(); return $result; - }else{ + + }else{ + //ERROR: Doesn't exist! $_SESSION['error_code'] = "404"; header("Location: index.php?page=error"); diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_queue.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_queue.tpl index f5f5a2120..df5c2cb7a 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_queue.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_queue.tpl @@ -2,7 +2,7 @@