mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-23 15:26:16 +00:00
It's now possible to add someone to a support group
This commit is contained in:
parent
f0da13a60e
commit
b0564d35d8
9 changed files with 197 additions and 33 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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() {
|
||||
|
|
|
@ -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!"
|
||||
|
|
|
@ -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!"
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,11 +6,16 @@ function show_sgroup(){
|
|||
if( WebUsers::isAdmin()){
|
||||
if( isset($_GET['id'])){
|
||||
|
||||
$id = filter_var($_GET['id'],FILTER_SANITIZE_STRING);
|
||||
|
||||
$group = Support_Group::getGroup($id);
|
||||
$result['target_id'] = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT);
|
||||
$group = Support_Group::getGroup($result['target_id']);
|
||||
|
||||
$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;
|
||||
|
||||
}else{
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
<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=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 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>
|
||||
{/block}
|
||||
|
||||
|
|
|
@ -47,15 +47,15 @@
|
|||
{$group_success}
|
||||
</div>
|
||||
{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}
|
||||
</div>
|
||||
{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}
|
||||
</div>
|
||||
{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}
|
||||
</div>
|
||||
{/if}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<div class="box-content">
|
||||
<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>
|
||||
|
||||
|
@ -25,7 +25,8 @@
|
|||
</div>
|
||||
|
||||
<input type="hidden" name="function" value="add_user_to_sgroup">
|
||||
|
||||
<input type="hidden" name="target_id" value="{$target_id}">
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label"></label>
|
||||
<div class="controls">
|
||||
|
@ -35,19 +36,19 @@
|
|||
|
||||
{if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "SUCCESS"}
|
||||
<div class="alert alert-success">
|
||||
{$group_success}
|
||||
{$add_to_group_success}
|
||||
</div>
|
||||
{else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "NAME_TAKEN"}
|
||||
<div class="alert alert-warning">
|
||||
{$group_name_taken}
|
||||
{else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "ALREADY_ADDED"}
|
||||
<div class="alert alert-error">
|
||||
{$user_already_added}
|
||||
</div>
|
||||
{else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "TAG_TAKEN"}
|
||||
<div class="alert alert-warning">
|
||||
{$group_tag_taken}
|
||||
{else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "GROUP_NOT_EXISTING"}
|
||||
<div class="alert alert-error">
|
||||
{$group_not_existing}
|
||||
</div>
|
||||
{else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "SIZE_ERROR"}
|
||||
<div class="alert alert-warning">
|
||||
{$group_size_error}
|
||||
{else if isset($RESULT_OF_ADDING) and $RESULT_OF_ADDING eq "USER_NOT_EXISTING"}
|
||||
<div class="alert alert-error">
|
||||
{$user_not_existing}
|
||||
</div>
|
||||
{/if}
|
||||
</form>
|
||||
|
@ -74,15 +75,15 @@
|
|||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Action</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach from=$grouplist item=group}
|
||||
{foreach from=$userlist item=user}
|
||||
<tr>
|
||||
<td>{$group.sGroupId}</td>
|
||||
<td><a href ="index.php?page=show_group&id={$group.sGroupId}">{$group.name}</a></td>
|
||||
<td class="center"><span class="label label-important" >{$group.tag}</span></td>
|
||||
<td>{$user.tUserId}</td>
|
||||
<td><a href ="index.php?page=show_user&id={$user.tUserId}">{$user.name}</a></td>
|
||||
<td class="center"><a class="btn btn-danger" href="#"><i class="icon-trash icon-white"></i> Delete</a></td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
|
|
Loading…
Reference in a new issue