It's now possible to add someone to a support group
--HG-- branch : quitta-gsoc-2013hg/feature/sse2
parent
ac5c8378bc
commit
465c9c531a
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue