refactoring webusers.php
This commit is contained in:
parent
cee8bbc495
commit
528f6d858a
13 changed files with 94 additions and 47 deletions
|
@ -7,7 +7,7 @@ class Users{
|
||||||
* @takes $array with username,password and email
|
* @takes $array with username,password and email
|
||||||
* @return string Info: Returns a string, if input data is valid then "success" is returned, else an array with errors
|
* @return string Info: Returns a string, if input data is valid then "success" is returned, else an array with errors
|
||||||
*/
|
*/
|
||||||
public static function check_Register($values){
|
public function check_Register($values){
|
||||||
// check values
|
// check values
|
||||||
if ( isset( $values["Username"] ) and isset( $values["Password"] ) and isset( $values["ConfirmPass"] ) and isset( $values["Email"] ) ){
|
if ( isset( $values["Username"] ) and isset( $values["Password"] ) and isset( $values["ConfirmPass"] ) and isset( $values["Email"] ) ){
|
||||||
$user = Users::checkUser( $values["Username"] );
|
$user = Users::checkUser( $values["Username"] );
|
||||||
|
@ -156,7 +156,7 @@ class Users{
|
||||||
* @takes $email
|
* @takes $email
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static function checkEmail( $email )
|
public function checkEmail( $email )
|
||||||
{
|
{
|
||||||
if ( isset( $email ) ){
|
if ( isset( $email ) ){
|
||||||
if ( !Users::validEmail( $email ) ){
|
if ( !Users::validEmail( $email ) ){
|
||||||
|
|
|
@ -2,6 +2,28 @@
|
||||||
|
|
||||||
class WebUsers extends Users{
|
class WebUsers extends Users{
|
||||||
|
|
||||||
|
private $uId;
|
||||||
|
private $login;
|
||||||
|
private $email;
|
||||||
|
private $firstname;
|
||||||
|
private $lastname;
|
||||||
|
private $gender;
|
||||||
|
private $country;
|
||||||
|
|
||||||
|
function __construct($UId = 0) {
|
||||||
|
$this->uId = $UId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set($values){
|
||||||
|
$this->uId = $values['UId'];
|
||||||
|
$this->login = $values['Login'];
|
||||||
|
$this->email = $values['Email'];
|
||||||
|
$this->firstname = $values['FirstName'];
|
||||||
|
$this->lastname = $values['LastName'];
|
||||||
|
$this->gender = $values['Gender'];
|
||||||
|
$this->country = $values['Country'];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function checkUserNameExists
|
* Function checkUserNameExists
|
||||||
*
|
*
|
||||||
|
@ -46,32 +68,42 @@ class WebUsers extends Users{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId($username){
|
public static function getId($username){
|
||||||
$dbw = new DBLayer("web");
|
$dbw = new DBLayer("web");
|
||||||
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:username", array('username' => $username));
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:username", array('username' => $username));
|
||||||
$row = $statement->fetch();
|
$row = $statement->fetch();
|
||||||
return $row['UId'];
|
return $row['UId'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUsername($id){
|
public function getUsername(){
|
||||||
$dbw = new DBLayer("web");
|
$dbw = new DBLayer("web");
|
||||||
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id));
|
if(! isset($this->login) || $this->login == ""){
|
||||||
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId));
|
||||||
$row = $statement->fetch();
|
$row = $statement->fetch();
|
||||||
return $row['Login'];
|
$this->set($row);
|
||||||
|
}
|
||||||
|
return $this->login;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEmail($id){
|
public function getEmail(){
|
||||||
$dbw = new DBLayer("web");
|
$dbw = new DBLayer("web");
|
||||||
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id));
|
if(! isset($this->email) || $this->email == ""){
|
||||||
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId));
|
||||||
$row = $statement->fetch();
|
$row = $statement->fetch();
|
||||||
return $row['Email'];
|
$this->set($row);
|
||||||
|
}
|
||||||
|
return $this->email;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInfo($id){
|
public function getInfo(){
|
||||||
$dbw = new DBLayer("web");
|
$dbw = new DBLayer("web");
|
||||||
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id));
|
if(! (isset($this->firstname) && isset($this->lastname) && isset($this->gender) && isset($this->country) ) ||
|
||||||
|
$this->firstname == "" || $this->lastname == "" || $this->gender == "" || $this->country == ""){
|
||||||
|
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId));
|
||||||
$row = $statement->fetch();
|
$row = $statement->fetch();
|
||||||
$result = Array('FirstName' => $row['FirstName'], 'LastName' => $row['LastName'], 'Gender' => $row['Gender'], 'Country' => $row['Country']);
|
$this->set($row);
|
||||||
|
}
|
||||||
|
$result = Array('FirstName' => $this->firstname, 'LastName' => $this->lastname, 'Gender' => $this->gender, 'Country' => $this->country);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
function add_user(){
|
function add_user(){
|
||||||
|
|
||||||
$params = Array('Username' => $_POST["Username"], 'Password' => $_POST["Password"], 'ConfirmPass' => $_POST["ConfirmPass"], 'Email' => $_POST["Email"]);
|
$params = Array('Username' => $_POST["Username"], 'Password' => $_POST["Password"], 'ConfirmPass' => $_POST["ConfirmPass"], 'Email' => $_POST["Email"]);
|
||||||
$webUser = new WebUsers;
|
$webUser = new WebUsers();
|
||||||
$result = $webUser->check_Register($params);
|
$result = $webUser->check_Register($params);
|
||||||
|
|
||||||
// if all are good then create user
|
// if all are good then create user
|
||||||
|
|
|
@ -13,12 +13,13 @@ function change_info(){
|
||||||
if($_POST['target_id'] == $_SESSION['id']){
|
if($_POST['target_id'] == $_SESSION['id']){
|
||||||
$target_username = $_SESSION['user'];
|
$target_username = $_SESSION['user'];
|
||||||
}else{
|
}else{
|
||||||
$target_username = WebUsers::getUsername($_POST['target_id']);
|
$webUser = new WebUsers($_POST['target_id']);
|
||||||
|
$target_username = $webUser->getUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
$webUser = new WebUsers();
|
$webUser = new WebUsers($_POST['target_id']);
|
||||||
//use current info to check for changes
|
//use current info to check for changes
|
||||||
$current_info = $webUser->getInfo($_POST['target_id']);
|
$current_info = $webUser->getInfo();
|
||||||
|
|
||||||
|
|
||||||
$current_info['FirstName'] = filter_var($current_info['FirstName'], FILTER_SANITIZE_STRING);
|
$current_info['FirstName'] = filter_var($current_info['FirstName'], FILTER_SANITIZE_STRING);
|
||||||
|
|
|
@ -13,10 +13,11 @@ function change_mail(){
|
||||||
if($_POST['target_id'] == $_SESSION['id']){
|
if($_POST['target_id'] == $_SESSION['id']){
|
||||||
$target_username = $_SESSION['user'];
|
$target_username = $_SESSION['user'];
|
||||||
}else{
|
}else{
|
||||||
$target_username = WebUsers::getUsername($_POST['target_id']);
|
$webUser = new WebUsers($_POST['target_id']);
|
||||||
|
$target_username = $webUser->getUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
$webUser = new WebUsers();
|
$webUser = new WebUsers($_POST['target_id']);
|
||||||
$reply = $webUser->checkEmail($_POST['NewEmail']);
|
$reply = $webUser->checkEmail($_POST['NewEmail']);
|
||||||
|
|
||||||
global $SITEBASE;
|
global $SITEBASE;
|
||||||
|
|
|
@ -13,13 +13,14 @@ function change_password(){
|
||||||
if($_POST['target_id'] == $_SESSION['id']){
|
if($_POST['target_id'] == $_SESSION['id']){
|
||||||
$target_username = $_SESSION['user'];
|
$target_username = $_SESSION['user'];
|
||||||
}else{
|
}else{
|
||||||
$target_username = WebUsers::getUsername($_POST['target_id']);
|
$webUser = new WebUsers($_POST['target_id']);
|
||||||
|
$target_username = $webUser->getUsername();
|
||||||
//isAdmin is true when it's the admin, but the target_id != own id
|
//isAdmin is true when it's the admin, but the target_id != own id
|
||||||
$adminChangesOther = true;
|
$adminChangesOther = true;
|
||||||
$_POST["CurrentPass"] = "dummypass";
|
$_POST["CurrentPass"] = "dummypass";
|
||||||
}
|
}
|
||||||
|
|
||||||
$webUser = new WebUsers();
|
$webUser = new WebUsers($_POST['target_id']);
|
||||||
$params = Array( 'user' => $target_username, 'CurrentPass' => $_POST["CurrentPass"], 'NewPass' => $_POST["NewPass"], 'ConfirmNewPass' => $_POST["ConfirmNewPass"], 'adminChangesOther' => $adminChangesOther);
|
$params = Array( 'user' => $target_username, 'CurrentPass' => $_POST["CurrentPass"], 'NewPass' => $_POST["NewPass"], 'ConfirmNewPass' => $_POST["ConfirmNewPass"], 'adminChangesOther' => $adminChangesOther);
|
||||||
$result = $webUser->check_change_password($params);
|
$result = $webUser->check_change_password($params);
|
||||||
if ($result == "success"){
|
if ($result == "success"){
|
||||||
|
|
|
@ -10,17 +10,19 @@ function settings(){
|
||||||
header("Location: index.php?page=error");
|
header("Location: index.php?page=error");
|
||||||
exit;
|
exit;
|
||||||
}else{
|
}else{
|
||||||
$result = WebUsers::getInfo($_GET['id']);
|
$webUser = new Webusers($_GET['id']);
|
||||||
|
$result = $webUser->getInfo();
|
||||||
if(Ticket_User::isMod($_SESSION['ticket_user']) && ($_GET['id']!= $_SESSION['id'])){
|
if(Ticket_User::isMod($_SESSION['ticket_user']) && ($_GET['id']!= $_SESSION['id'])){
|
||||||
$result['changesOther'] = "TRUE";
|
$result['changesOther'] = "TRUE";
|
||||||
}
|
}
|
||||||
$result['target_id'] = $_GET['id'];
|
$result['target_id'] = $_GET['id'];
|
||||||
$result['current_mail'] = WebUsers::getEmail($_GET['id']);
|
$result['current_mail'] = $webUser->getEmail();
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
$result = WebUsers::getInfo($_SESSION['id']);
|
$webUser = new Webusers($_SESSION['id']);
|
||||||
|
$result = $webUser->getInfo();
|
||||||
$result['target_id'] = $_SESSION['id'];
|
$result['target_id'] = $_SESSION['id'];
|
||||||
$result['current_mail'] = WebUsers::getEmail($_SESSION['id']);
|
$result['current_mail'] = $webUser->getEmail();
|
||||||
|
|
||||||
//Sanitize Data
|
//Sanitize Data
|
||||||
$result['current_mail'] = filter_var($result['current_mail'], FILTER_SANITIZE_EMAIL);
|
$result['current_mail'] = filter_var($result['current_mail'], FILTER_SANITIZE_EMAIL);
|
||||||
|
|
|
@ -46,8 +46,10 @@ function show_queue(){
|
||||||
$result['tickets'] = Gui_Elements::make_table($queueArray, Array("getTId","getTitle","getTimestamp","getAuthor()->getExternId","getTicket_Category()->getName","getStatus","getStatusText","getAssigned","getForwardedGroupName","getForwardedGroupId"), Array("tId","title","timestamp","authorExtern","category","status","statusText","assigned","forwardedGroupName","forwardedGroupId"));
|
$result['tickets'] = Gui_Elements::make_table($queueArray, Array("getTId","getTitle","getTimestamp","getAuthor()->getExternId","getTicket_Category()->getName","getStatus","getStatusText","getAssigned","getForwardedGroupName","getForwardedGroupId"), Array("tId","title","timestamp","authorExtern","category","status","statusText","assigned","forwardedGroupName","forwardedGroupId"));
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach( $result['tickets'] as $ticket){
|
foreach( $result['tickets'] as $ticket){
|
||||||
$result['tickets'][$i]['author'] = WebUsers::getUsername($ticket['authorExtern']);
|
$web_author = new WebUsers($ticket['authorExtern']);
|
||||||
$result['tickets'][$i]['assignedText'] = WebUsers::getUsername($ticket['assigned']);
|
$result['tickets'][$i]['author'] = $web_author->getUsername();
|
||||||
|
$web_assigned = new WebUsers($ticket['assigned']);
|
||||||
|
$result['tickets'][$i]['assignedText'] = $web_assigned->getUsername();
|
||||||
$result['tickets'][$i]['timestamp_elapsed'] = Gui_Elements::time_elapsed_string($ticket['timestamp']);
|
$result['tickets'][$i]['timestamp_elapsed'] = Gui_Elements::time_elapsed_string($ticket['timestamp']);
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +60,8 @@ function show_queue(){
|
||||||
$result['teamlist'] = Gui_Elements::make_table(Ticket_User::getModsAndAdmins(), Array("getTUserId","getExternId"), Array("tUserId","externId"));
|
$result['teamlist'] = Gui_Elements::make_table(Ticket_User::getModsAndAdmins(), Array("getTUserId","getExternId"), Array("tUserId","externId"));
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach( $result['teamlist'] as $member){
|
foreach( $result['teamlist'] as $member){
|
||||||
$result['teamlist'][$i]['name'] = WebUsers::getUsername($member['externId']);
|
$web_teammember = new Webusers($member['externId']);
|
||||||
|
$result['teamlist'][$i]['name'] = $web_teammember->getUsername();
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
@ -25,7 +25,8 @@ function show_reply(){
|
||||||
$result['author_permission'] = $author->getPermission();
|
$result['author_permission'] = $author->getPermission();
|
||||||
$result['reply_content'] = $content->getContent();
|
$result['reply_content'] = $content->getContent();
|
||||||
$result['author'] = $author->getExternId();
|
$result['author'] = $author->getExternId();
|
||||||
$result['authorName'] = WebUsers::getUsername($author->getExternId());
|
$webUser = new WebUsers($author->getExternId());
|
||||||
|
$result['authorName'] = $webUser->getUsername();
|
||||||
if(Ticket_User::isMod($_SESSION['ticket_user'])){
|
if(Ticket_User::isMod($_SESSION['ticket_user'])){
|
||||||
$result['isMod'] = "TRUE";
|
$result['isMod'] = "TRUE";
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,8 @@ function show_sgroup(){
|
||||||
$result['userlist'] = Gui_Elements::make_table(Support_Group::getAllUsersOfSupportGroup($result['target_id']), Array("getTUserId","getPermission","getExternId"), Array("tUserId","permission","externId"));
|
$result['userlist'] = Gui_Elements::make_table(Support_Group::getAllUsersOfSupportGroup($result['target_id']), Array("getTUserId","getPermission","getExternId"), Array("tUserId","permission","externId"));
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach( $result['userlist'] as $user){
|
foreach( $result['userlist'] as $user){
|
||||||
$result['userlist'][$i]['name'] = WebUsers::getUsername($user['externId']);
|
$webuser = new Webusers($user['externId']);
|
||||||
|
$result['userlist'][$i]['name'] = $webuser->getUsername();
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
@ -50,12 +50,14 @@ function show_ticket(){
|
||||||
$result['ticket_statustext'] = $entire_ticket['ticket_obj']->getStatusText();
|
$result['ticket_statustext'] = $entire_ticket['ticket_obj']->getStatusText();
|
||||||
$result['ticket_lastupdate'] = Gui_Elements::time_elapsed_string(Ticket::getLatestReply($result['ticket_id'])->getTimestamp());
|
$result['ticket_lastupdate'] = Gui_Elements::time_elapsed_string(Ticket::getLatestReply($result['ticket_id'])->getTimestamp());
|
||||||
$result['ticket_category'] = $entire_ticket['ticket_obj']->getCategoryName();
|
$result['ticket_category'] = $entire_ticket['ticket_obj']->getCategoryName();
|
||||||
$result['ticket_assignedToText'] = WebUsers::getUsername(Assigned::getUserAssignedToTicket($result['ticket_tId']));
|
$webUser = new WebUsers(Assigned::getUserAssignedToTicket($result['ticket_tId']));
|
||||||
|
$result['ticket_assignedToText'] = $webUser->getUsername();
|
||||||
$result['ticket_assignedTo'] = Assigned::getUserAssignedToTicket($result['ticket_tId']);
|
$result['ticket_assignedTo'] = Assigned::getUserAssignedToTicket($result['ticket_tId']);
|
||||||
$result['ticket_replies'] = Gui_Elements::make_table($entire_ticket['reply_array'], Array("getTReplyId","getContent()->getContent","getTimestamp","getAuthor()->getExternId","getAuthor()->getPermission","getHidden"), Array("tReplyId","replyContent","timestamp","authorExtern","permission","hidden"));
|
$result['ticket_replies'] = Gui_Elements::make_table($entire_ticket['reply_array'], Array("getTReplyId","getContent()->getContent","getTimestamp","getAuthor()->getExternId","getAuthor()->getPermission","getHidden"), Array("tReplyId","replyContent","timestamp","authorExtern","permission","hidden"));
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach( $result['ticket_replies'] as $reply){
|
foreach( $result['ticket_replies'] as $reply){
|
||||||
$result['ticket_replies'][$i]['author'] = WebUsers::getUsername($reply['authorExtern']);
|
$webReplyUser = new WebUsers($reply['authorExtern']);
|
||||||
|
$result['ticket_replies'][$i]['author'] = $webReplyUser->getUsername();
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
if(Ticket_User::isMod($_SESSION['ticket_user'])){
|
if(Ticket_User::isMod($_SESSION['ticket_user'])){
|
||||||
|
|
|
@ -15,11 +15,13 @@ function show_ticket_log(){
|
||||||
$result['ticket_logs'] = Gui_Elements::make_table($ticket_logs, Array("getTLogId","getTimestamp","getAuthor()->getExternId","getAction","getArgument()"), Array("tLogId","timestamp","authorExtern","action","argument"));
|
$result['ticket_logs'] = Gui_Elements::make_table($ticket_logs, Array("getTLogId","getTimestamp","getAuthor()->getExternId","getAction","getArgument()"), Array("tLogId","timestamp","authorExtern","action","argument"));
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach( $result['ticket_logs'] as $log){
|
foreach( $result['ticket_logs'] as $log){
|
||||||
$author = WebUsers::getUsername($log['authorExtern']);
|
$webUser = new WebUsers($log['authorExtern']);
|
||||||
|
$author = $webUser->getUsername();
|
||||||
$result['ticket_logs'][$i]['author'] = $author;
|
$result['ticket_logs'][$i]['author'] = $author;
|
||||||
$query_backpart = "";
|
$query_backpart = "";
|
||||||
if($log['action'] == 2){
|
if($log['action'] == 2){
|
||||||
$query_backpart = WebUsers::getUsername($log['argument']);
|
$webUser2 = new WebUsers($log['argument']);
|
||||||
|
$query_backpart = $webUser2->getUsername();
|
||||||
}else if($log['action'] == 4){
|
}else if($log['action'] == 4){
|
||||||
$query_backpart = "<a href='index.php?page=show_reply&id=" . $log['argument'] . "'>ID#" . $log['argument'] . "</a>";
|
$query_backpart = "<a href='index.php?page=show_reply&id=" . $log['argument'] . "'>ID#" . $log['argument'] . "</a>";
|
||||||
}else if($log['action'] == 5){
|
}else if($log['action'] == 5){
|
||||||
|
|
|
@ -11,9 +11,10 @@ function show_user(){
|
||||||
}else{
|
}else{
|
||||||
$result['target_id'] = $_SESSION['id'];
|
$result['target_id'] = $_SESSION['id'];
|
||||||
}
|
}
|
||||||
$result['target_name'] = WebUsers::getUsername( $result['target_id']);
|
$webUser = new WebUsers($result['target_id']);
|
||||||
$result['mail'] = WebUsers::getEmail( $result['target_id']);
|
$result['target_name'] = $webUser->getUsername();
|
||||||
$info = WebUsers::getInfo($result['target_id']);
|
$result['mail'] = $webUser->getEmail();
|
||||||
|
$info = $webUser->getInfo();
|
||||||
$result['firstName'] = $info['FirstName'];
|
$result['firstName'] = $info['FirstName'];
|
||||||
$result['lastName'] = $info['LastName'];
|
$result['lastName'] = $info['LastName'];
|
||||||
$result['country'] = $info['Country'];
|
$result['country'] = $info['Country'];
|
||||||
|
|
Loading…
Reference in a new issue