diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/in_support_group.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/in_support_group.php new file mode 100644 index 000000000..f60e9ecb7 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/in_support_group.php @@ -0,0 +1,69 @@ +execute(" SELECT * FROM `in_support_group` WHERE `User` = :user_id and `Group` = :group_id ", array('user_id' => $user_id, 'group_id' => $group_id) )->rowCount() ){ + return true; + }else{ + return false; + } + } + + ////////////////////////////////////////////Methods//////////////////////////////////////////////////// + + public function __construct() { + } + + //set values + public function set($values) { + $this->setUser($values['User']); + $this->setGroup($values['Group']); + } + + public function create() { + $dbl = new DBLayer("lib"); + $query = "INSERT INTO `in_support_group` (`User`,`Group`) VALUES (:user, :group)"; + $values = Array('user' => $this->user, 'group' => $this->group); + $dbl->execute($query, $values); + } + + //Load with sGroupId + public function load( $user_id, $group_id) { + $dbl = new DBLayer("lib"); + $statement = $dbl->execute("SELECT * FROM `in_support_group` WHERE `Group` = :group_id", Array('group_id' => $group_id)); + $row = $statement->fetch(); + $this->set($row); + } + + + ////////////////////////////////////////////Getters//////////////////////////////////////////////////// + + public function getUser(){ + return $this->user; + } + + public function getGroup(){ + return $this->group; + } + + ////////////////////////////////////////////Setters//////////////////////////////////////////////////// + + public function setUser($u){ + $this->user = $u; + } + + public function setGroup($g){ + $this->group = $g; + } + + +} \ No newline at end of file diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/support_group.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/support_group.php index be4399a75..29478b896 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/support_group.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/support_group.php @@ -38,7 +38,7 @@ class Support_Group{ public static function createSupportGroup( $name, $tag) { if(strlen($name) < 21 && strlen($name) > 4 &&strlen($tag) < 8 && strlen($tag) > 1 ){ - $notExists = self::supportGroup_NotExists($name, $tag); + $notExists = self::supportGroup_EntryNotExists($name, $tag); if ( $notExists == "SUCCESS" ){ $sGroup = new self(); $sGroup->setName($name); @@ -56,7 +56,7 @@ class Support_Group{ } //check if group exists - public static function supportGroup_NotExists( $name, $tag) { + public static function supportGroup_EntryNotExists( $name, $tag) { $dbl = new DBLayer("lib"); //check if name is already used if( $dbl->execute("SELECT * FROM support_group WHERE Name = :name",array('name' => $name))->rowCount() ){ @@ -69,6 +69,19 @@ class Support_Group{ } } + + //check if group exists + public static function supportGroup_Exists( $id) { + $dbl = new DBLayer("lib"); + //check if supportgroup id exist + if( $dbl->execute("SELECT * FROM support_group WHERE SGroupId = :id",array('id' => $id ))->rowCount() ){ + return true; + }else{ + return false; + } + } + + //return constructed element based on SGroupId public static function constr_SGroupId( $id) { $instance = new self(); @@ -77,20 +90,50 @@ class Support_Group{ } //returns list of all users that are enlisted to a support group - public static function getAllUsersOfSupportGroup($id) { + public static function getAllUsersOfSupportGroup($group_id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_log INNER JOIN ticket_user ON ticket_log.Author = ticket_user.TUserId and ticket_log.Ticket=:id", array('id' => $ticket_id)); - $row = $statement->fetchAll(); + $statement = $dbl->execute("SELECT * FROM `in_support_group` INNER JOIN `ticket_user` ON ticket_user.TUserId = in_support_group.User WHERE in_support_group.Group=:id", array('id' => $group_id)); + $rows = $statement->fetchAll(); $result = Array(); - foreach($row as $log){ - $instance = new self(); - $instance->set($log); - $result[] = $instance; + foreach($rows as $row){ + $userInstance = new Ticket_User(); + $userInstance->setTUserId($row['TUserId']); + $userInstance->setPermission($row['Permission']); + $userInstance->setExternId($row['ExternId']); + $result[] = $userInstance; } return $result; } + + + //wrapper for adding user to a support group + public static function addUserToSupportGroup( $user_id, $group_id) { + //check if group id exists + if (self::supportGroup_Exists($group_id)){ + //check if user isn't in supportgroup yet + //if not, create entry and return SUCCESS + if(! In_Support_Group::userAlreadyInSGroup($user_id, $group_id) ){ + //create entry + $inSGroup = new In_Support_Group(); + $inSGroup->setUser($user_id); + $inSGroup->setGroup($group_id); + $inSGroup->create(); + return "SUCCESS"; + } + else{ + //else return ALREADY_ADDED + return "ALREADY_ADDED"; + } + + + }else{ + //return that group doesn't exist + return "GROUP_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 babd587e0..2578cdf7a 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 @@ -32,6 +32,10 @@ t_send = "Send reply" [show_queue] [show_sgroup] +add_to_group_success = "The user has been added to the group!" +user_already_added = "The user is already part of the group!" +group_not_existing = "The group doesn't exist!" +user_not_existing = "The user doesn't seem to exist" [sgroup_list] group_success = "The group has been created!" 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 c9d6d64c0..a62cc8004 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 @@ -32,6 +32,10 @@ t_send = "Envoyer la reponse" [show_queue] [show_sgroup] +add_to_group_success = "ce user est ajoute sur la groupe!" +user_already_added = "cet user est deja membre de la groupe!" +group_not_existing = "cet Groupe n' existe pas!" +user_not_existing = "cet user n'existe pas" [sgroup_list] group_success = "le group est cree!" diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/add_user_to_sgroup.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/add_user_to_sgroup.php new file mode 100644 index 000000000..10da9db8a --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/add_user_to_sgroup.php @@ -0,0 +1,37 @@ +getName(); - $result['grouplist'] = Gui_Elements::make_table(Support_Group::getGroups(), Array("getSGroupId","getName","getTag"), Array("sGroupId","name","tag")); + $result['userlist'] = Gui_Elements::make_table(Support_Group::getAllUsersOfSupportGroup($result['target_id']), Array("getTUserId","getPermission","getExternId"), Array("tUserId","permission","externId")); + $i = 0; + foreach( $result['userlist'] as $user){ + $result['userlist'][$i]['name'] = WebUsers::getUsername($user['externId']); + $i++; + } return $result; }else{ diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_admin.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_admin.tpl index 1e4e8ddf2..114f65dc5 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_admin.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_admin.tpl @@ -7,8 +7,9 @@
  • Users
  • Queues
  • -
  • Syncing
  • +
  • Support Groups
  • +
  • Syncing
  • Logout
  • {/block} diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/sgroup_list.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/sgroup_list.tpl index 75595f230..867c3b366 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/sgroup_list.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/sgroup_list.tpl @@ -47,15 +47,15 @@ {$group_success} {else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "NAME_TAKEN"} -
    +
    {$group_name_taken}
    {else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "TAG_TAKEN"} -
    +
    {$group_tag_taken}
    {else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "SIZE_ERROR"} -
    +
    {$group_size_error}
    {/if} diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_sgroup.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_sgroup.tpl index 7e7a3e413..936e61742 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_sgroup.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/show_sgroup.tpl @@ -11,7 +11,7 @@
    -
    + Add a user to the group '{$groupsname}' @@ -25,7 +25,8 @@
    - + +
    @@ -35,19 +36,19 @@ {if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "SUCCESS"}
    - {$group_success} + {$add_to_group_success}
    - {else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "NAME_TAKEN"} -
    - {$group_name_taken} + {else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "ALREADY_ADDED"} +
    + {$user_already_added}
    - {else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "TAG_TAKEN"} -
    - {$group_tag_taken} + {else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "GROUP_NOT_EXISTING"} +
    + {$group_not_existing}
    - {else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "SIZE_ERROR"} -
    - {$group_size_error} + {else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "USER_NOT_EXISTING"} +
    + {$user_not_existing}
    {/if} @@ -74,15 +75,15 @@ ID Name + Action - {foreach from=$grouplist item=group} + {foreach from=$userlist item=user} - {$group.sGroupId} - {$group.name} - {$group.tag} + {$user.tUserId} + {$user.name} Delete {/foreach}