It's now possible to add someone to a support group

This commit is contained in:
Quitta 2013-07-16 04:58:54 +02:00
parent f0da13a60e
commit b0564d35d8
9 changed files with 197 additions and 33 deletions

View file

@ -0,0 +1,69 @@
<?php
class In_Support_Group{
private $user;
private $group;
////////////////////////////////////////////Functions////////////////////////////////////////////////////
//check if user is in in_support_group
public static function userAlreadyInSGroup( $user_id, $group_id) {
$dbl = new DBLayer("lib");
//check if name is already used
if( $dbl->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;
}
}

View file

@ -38,7 +38,7 @@ class Support_Group{
public static function createSupportGroup( $name, $tag) { public static function createSupportGroup( $name, $tag) {
if(strlen($name) < 21 && strlen($name) > 4 &&strlen($tag) < 8 && strlen($tag) > 1 ){ 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" ){ if ( $notExists == "SUCCESS" ){
$sGroup = new self(); $sGroup = new self();
$sGroup->setName($name); $sGroup->setName($name);
@ -56,7 +56,7 @@ class Support_Group{
} }
//check if group exists //check if group exists
public static function supportGroup_NotExists( $name, $tag) { public static function supportGroup_EntryNotExists( $name, $tag) {
$dbl = new DBLayer("lib"); $dbl = new DBLayer("lib");
//check if name is already used //check if name is already used
if( $dbl->execute("SELECT * FROM support_group WHERE Name = :name",array('name' => $name))->rowCount() ){ 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 //return constructed element based on SGroupId
public static function constr_SGroupId( $id) { public static function constr_SGroupId( $id) {
$instance = new self(); $instance = new self();
@ -77,20 +90,50 @@ class Support_Group{
} }
//returns list of all users that are enlisted to a 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"); $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)); $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));
$row = $statement->fetchAll(); $rows = $statement->fetchAll();
$result = Array(); $result = Array();
foreach($row as $log){ foreach($rows as $row){
$instance = new self(); $userInstance = new Ticket_User();
$instance->set($log); $userInstance->setTUserId($row['TUserId']);
$result[] = $instance; $userInstance->setPermission($row['Permission']);
$userInstance->setExternId($row['ExternId']);
$result[] = $userInstance;
} }
return $result; 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//////////////////////////////////////////////////// ////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct() { public function __construct() {

View file

@ -32,6 +32,10 @@ t_send = "Send reply"
[show_queue] [show_queue]
[show_sgroup] [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] [sgroup_list]
group_success = "The group has been created!" group_success = "The group has been created!"

View file

@ -32,6 +32,10 @@ t_send = "Envoyer la reponse"
[show_queue] [show_queue]
[show_sgroup] [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] [sgroup_list]
group_success = "le group est cree!" group_success = "le group est cree!"

View file

@ -0,0 +1,37 @@
<?php
function add_user_to_sgroup(){
if(WebUsers::isLoggedIn()){
if( WebUsers::isAdmin() && isset($_POST['target_id'])){
$name = filter_var($_POST['Name'],FILTER_SANITIZE_STRING);
$id = filter_var($_POST['target_id'],FILTER_SANITIZE_NUMBER_INT);
$user_id = WebUsers::getId($name);
if ($user_id != ""){
$result['RESULT_OF_ADDING'] = Support_Group::addUserToSupportGroup($user_id, $id);
}else{
$result['RESULT_OF_ADDING'] = "USER_NOT_EXISTING";
}
$result['permission'] = $_SESSION['permission'];
$result['no_visible_elements'] = 'FALSE';
$result['username'] = $_SESSION['user'];
global $SITEBASE;
require_once($SITEBASE . 'inc/show_sgroup.php');
$result= array_merge($result, show_sgroup());
helpers :: loadtemplate( 'show_sgroup', $result);
exit;
}else{
//ERROR: No access!
$_SESSION['error_code'] = "403";
header("Location: index.php?page=error");
exit;
}
}else{
//ERROR: not logged in!
header("Location: index.php");
exit;
}
}

View file

@ -6,11 +6,16 @@ function show_sgroup(){
if( WebUsers::isAdmin()){ if( WebUsers::isAdmin()){
if( isset($_GET['id'])){ if( isset($_GET['id'])){
$id = filter_var($_GET['id'],FILTER_SANITIZE_STRING); $result['target_id'] = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT);
$group = Support_Group::getGroup($result['target_id']);
$group = Support_Group::getGroup($id);
$result['groupsname'] = $group->getName(); $result['groupsname'] = $group->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; return $result;
}else{ }else{

View file

@ -7,8 +7,9 @@
<li class="nav-header hidden-tablet">Admin</li> <li class="nav-header hidden-tablet">Admin</li>
<li style="margin-left: -2px;"><a class="ajax-link" href="index.php?page=userlist"><i class="icon-th-list"></i><span class="hidden-tablet"> Users</span></a></li> <li style="margin-left: -2px;"><a class="ajax-link" href="index.php?page=userlist"><i class="icon-th-list"></i><span class="hidden-tablet"> Users</span></a></li>
<li style="margin-left: -2px;"><a class="ajax-link" href="index.php?page=show_queue&get=all_open"><i class="icon-th-list"></i><span class="hidden-tablet"> Queues</span></a></li> <li style="margin-left: -2px;"><a class="ajax-link" href="index.php?page=show_queue&get=all_open"><i class="icon-th-list"></i><span class="hidden-tablet"> Queues</span></a></li>
<li style="margin-left: -2px;"><a class="ajax-link" href="index.php?page=libuserlist"><i class="icon-th-list"></i><span class="hidden-tablet"> Syncing</span></a></li> <li style="margin-left: -2px;"><a class="ajax-link" href="index.php?page=sgroup_list"><i class="icon-briefcase"></i><span class="hidden-tablet"> Support Groups</span></a></li>
<li class="nav-header hidden-tablet">Actions</li> <li class="nav-header hidden-tablet">Actions</li>
<li style="margin-left: -2px;"><a class="ajax-link" href="index.php?page=libuserlist"><i class="icon-th-list"></i><span class="hidden-tablet"> Syncing</span></a></li>
<li style="margin-left: -2px;"><a href="?page=logout"><i class="icon-off"></i><span class="hidden-tablet"> Logout </span></a></li> <li style="margin-left: -2px;"><a href="?page=logout"><i class="icon-off"></i><span class="hidden-tablet"> Logout </span></a></li>
{/block} {/block}

View file

@ -47,15 +47,15 @@
{$group_success} {$group_success}
</div> </div>
{else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "NAME_TAKEN"} {else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "NAME_TAKEN"}
<div class="alert alert-warning"> <div class="alert alert-error">
{$group_name_taken} {$group_name_taken}
</div> </div>
{else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "TAG_TAKEN"} {else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "TAG_TAKEN"}
<div class="alert alert-warning"> <div class="alert alert-error">
{$group_tag_taken} {$group_tag_taken}
</div> </div>
{else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "SIZE_ERROR"} {else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "SIZE_ERROR"}
<div class="alert alert-warning"> <div class="alert alert-error">
{$group_size_error} {$group_size_error}
</div> </div>
{/if} {/if}

View file

@ -11,7 +11,7 @@
<div class="box-content"> <div class="box-content">
<div class="row-fluid"> <div class="row-fluid">
<form id="addSGroup" class="form-vertical" method="post" action="index.php"> <form id="addSGroup" class="form-vertical" method="post" action="index.php?page=show_sgroup&id={$target_id}">
<legend>Add a user to the group '{$groupsname}'</legend> <legend>Add a user to the group '{$groupsname}'</legend>
@ -25,6 +25,7 @@
</div> </div>
<input type="hidden" name="function" value="add_user_to_sgroup"> <input type="hidden" name="function" value="add_user_to_sgroup">
<input type="hidden" name="target_id" value="{$target_id}">
<div class="control-group"> <div class="control-group">
<label class="control-label"></label> <label class="control-label"></label>
@ -35,19 +36,19 @@
{if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "SUCCESS"} {if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "SUCCESS"}
<div class="alert alert-success"> <div class="alert alert-success">
{$group_success} {$add_to_group_success}
</div> </div>
{else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "NAME_TAKEN"} {else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "ALREADY_ADDED"}
<div class="alert alert-warning"> <div class="alert alert-error">
{$group_name_taken} {$user_already_added}
</div> </div>
{else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "TAG_TAKEN"} {else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "GROUP_NOT_EXISTING"}
<div class="alert alert-warning"> <div class="alert alert-error">
{$group_tag_taken} {$group_not_existing}
</div> </div>
{else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "SIZE_ERROR"} {else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "USER_NOT_EXISTING"}
<div class="alert alert-warning"> <div class="alert alert-error">
{$group_size_error} {$user_not_existing}
</div> </div>
{/if} {/if}
</form> </form>
@ -74,15 +75,15 @@
<tr> <tr>
<th>ID</th> <th>ID</th>
<th>Name</th> <th>Name</th>
<th>Action</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{foreach from=$grouplist item=group} {foreach from=$userlist item=user}
<tr> <tr>
<td>{$group.sGroupId}</td> <td>{$user.tUserId}</td>
<td><a href ="index.php?page=show_group&id={$group.sGroupId}">{$group.name}</a></td> <td><a href ="index.php?page=show_user&id={$user.tUserId}">{$user.name}</a></td>
<td class="center"><span class="label label-important" >{$group.tag}</span></td>
<td class="center"><a class="btn btn-danger" href="#"><i class="icon-trash icon-white"></i> Delete</a></td> <td class="center"><a class="btn btn-danger" href="#"><i class="icon-trash icon-white"></i> Delete</a></td>
</tr> </tr>
{/foreach} {/foreach}