refactoring webusers.php

--HG--
branch : quitta-gsoc-2013
This commit is contained in:
Quitta 2013-08-05 17:31:36 +02:00
parent 5b4c13f8d3
commit 99ad1504e3
13 changed files with 94 additions and 47 deletions

View file

@ -7,7 +7,7 @@ class Users{
* @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
*/
public static function check_Register($values){
public function check_Register($values){
// check values
if ( isset( $values["Username"] ) and isset( $values["Password"] ) and isset( $values["ConfirmPass"] ) and isset( $values["Email"] ) ){
$user = Users::checkUser( $values["Username"] );
@ -156,7 +156,7 @@ class Users{
* @takes $email
* @return
*/
public static function checkEmail( $email )
public function checkEmail( $email )
{
if ( isset( $email ) ){
if ( !Users::validEmail( $email ) ){

View file

@ -1,6 +1,28 @@
<?php
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
@ -46,33 +68,43 @@ class WebUsers extends Users{
}
}
public function getId($username){
$dbw = new DBLayer("web");
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:username", array('username' => $username));
$row = $statement->fetch();
return $row['UId'];
public static function getId($username){
$dbw = new DBLayer("web");
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:username", array('username' => $username));
$row = $statement->fetch();
return $row['UId'];
}
public function getUsername($id){
$dbw = new DBLayer("web");
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id));
$row = $statement->fetch();
return $row['Login'];
public function getUsername(){
$dbw = new DBLayer("web");
if(! isset($this->login) || $this->login == ""){
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId));
$row = $statement->fetch();
$this->set($row);
}
return $this->login;
}
public function getEmail($id){
$dbw = new DBLayer("web");
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id));
$row = $statement->fetch();
return $row['Email'];
public function getEmail(){
$dbw = new DBLayer("web");
if(! isset($this->email) || $this->email == ""){
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId));
$row = $statement->fetch();
$this->set($row);
}
return $this->email;
}
public function getInfo($id){
$dbw = new DBLayer("web");
$statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id));
$row = $statement->fetch();
$result = Array('FirstName' => $row['FirstName'], 'LastName' => $row['LastName'], 'Gender' => $row['Gender'], 'Country' => $row['Country']);
return $result;
public function getInfo(){
$dbw = new DBLayer("web");
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();
$this->set($row);
}
$result = Array('FirstName' => $this->firstname, 'LastName' => $this->lastname, 'Gender' => $this->gender, 'Country' => $this->country);
return $result;
}
public function isLoggedIn(){

View file

@ -3,7 +3,7 @@
function add_user(){
$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);
// if all are good then create user

View file

@ -13,12 +13,13 @@ function change_info(){
if($_POST['target_id'] == $_SESSION['id']){
$target_username = $_SESSION['user'];
}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
$current_info = $webUser->getInfo($_POST['target_id']);
$current_info = $webUser->getInfo();
$current_info['FirstName'] = filter_var($current_info['FirstName'], FILTER_SANITIZE_STRING);

View file

@ -13,10 +13,11 @@ function change_mail(){
if($_POST['target_id'] == $_SESSION['id']){
$target_username = $_SESSION['user'];
}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']);
global $SITEBASE;

View file

@ -13,13 +13,14 @@ function change_password(){
if($_POST['target_id'] == $_SESSION['id']){
$target_username = $_SESSION['user'];
}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
$adminChangesOther = true;
$_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);
$result = $webUser->check_change_password($params);
if ($result == "success"){

View file

@ -10,17 +10,19 @@ function settings(){
header("Location: index.php?page=error");
exit;
}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'])){
$result['changesOther'] = "TRUE";
}
$result['target_id'] = $_GET['id'];
$result['current_mail'] = WebUsers::getEmail($_GET['id']);
$result['current_mail'] = $webUser->getEmail();
}
}else{
$result = WebUsers::getInfo($_SESSION['id']);
$webUser = new Webusers($_SESSION['id']);
$result = $webUser->getInfo();
$result['target_id'] = $_SESSION['id'];
$result['current_mail'] = WebUsers::getEmail($_SESSION['id']);
$result['current_mail'] = $webUser->getEmail();
//Sanitize Data
$result['current_mail'] = filter_var($result['current_mail'], FILTER_SANITIZE_EMAIL);

View file

@ -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"));
$i = 0;
foreach( $result['tickets'] as $ticket){
$result['tickets'][$i]['author'] = WebUsers::getUsername($ticket['authorExtern']);
$result['tickets'][$i]['assignedText'] = WebUsers::getUsername($ticket['assigned']);
$web_author = new WebUsers($ticket['authorExtern']);
$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']);
$i++;
}
@ -58,7 +60,8 @@ function show_queue(){
$result['teamlist'] = Gui_Elements::make_table(Ticket_User::getModsAndAdmins(), Array("getTUserId","getExternId"), Array("tUserId","externId"));
$i = 0;
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++;
}
return $result;

View file

@ -25,7 +25,8 @@ function show_reply(){
$result['author_permission'] = $author->getPermission();
$result['reply_content'] = $content->getContent();
$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'])){
$result['isMod'] = "TRUE";
}

View file

@ -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"));
$i = 0;
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++;
}
return $result;

View file

@ -50,12 +50,14 @@ function show_ticket(){
$result['ticket_statustext'] = $entire_ticket['ticket_obj']->getStatusText();
$result['ticket_lastupdate'] = Gui_Elements::time_elapsed_string(Ticket::getLatestReply($result['ticket_id'])->getTimestamp());
$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_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;
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++;
}
if(Ticket_User::isMod($_SESSION['ticket_user'])){

View file

@ -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"));
$i = 0;
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;
$query_backpart = "";
if($log['action'] == 2){
$query_backpart = WebUsers::getUsername($log['argument']);
$webUser2 = new WebUsers($log['argument']);
$query_backpart = $webUser2->getUsername();
}else if($log['action'] == 4){
$query_backpart = "<a href='index.php?page=show_reply&id=" . $log['argument'] . "'>ID#" . $log['argument'] . "</a>";
}else if($log['action'] == 5){

View file

@ -11,9 +11,10 @@ function show_user(){
}else{
$result['target_id'] = $_SESSION['id'];
}
$result['target_name'] = WebUsers::getUsername( $result['target_id']);
$result['mail'] = WebUsers::getEmail( $result['target_id']);
$info = WebUsers::getInfo($result['target_id']);
$webUser = new WebUsers($result['target_id']);
$result['target_name'] = $webUser->getUsername();
$result['mail'] = $webUser->getEmail();
$info = $webUser->getInfo();
$result['firstName'] = $info['FirstName'];
$result['lastName'] = $info['LastName'];
$result['country'] = $info['Country'];