From 528f6d858addf3dab40d8df720028f779c65a986 Mon Sep 17 00:00:00 2001 From: Quitta Date: Mon, 5 Aug 2013 17:31:36 +0200 Subject: [PATCH] refactoring webusers.php --- .../ryzom_ams/ams_lib/autoload/users.php | 4 +- .../ryzom_ams/www/html/autoload/webusers.php | 74 +++++++++++++------ .../ryzom_ams/www/html/func/add_user.php | 2 +- .../ryzom_ams/www/html/func/change_info.php | 7 +- .../ryzom_ams/www/html/func/change_mail.php | 5 +- .../www/html/func/change_password.php | 5 +- .../ryzom_ams/www/html/inc/settings.php | 10 ++- .../ryzom_ams/www/html/inc/show_queue.php | 9 ++- .../ryzom_ams/www/html/inc/show_reply.php | 3 +- .../ryzom_ams/www/html/inc/show_sgroup.php | 3 +- .../ryzom_ams/www/html/inc/show_ticket.php | 6 +- .../www/html/inc/show_ticket_log.php | 6 +- .../ryzom_ams/www/html/inc/show_user.php | 7 +- 13 files changed, 94 insertions(+), 47 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php index f13b09d67..d5ba0963a 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php @@ -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 ) ){ diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/autoload/webusers.php b/code/ryzom/tools/server/ryzom_ams/www/html/autoload/webusers.php index e1a4b4501..fe21ec7fc 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/autoload/webusers.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/autoload/webusers.php @@ -1,6 +1,28 @@ 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(){ diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/add_user.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/add_user.php index 501628368..7e81b2751 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/func/add_user.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/add_user.php @@ -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 diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/change_info.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/change_info.php index 12d82bfa4..311935e9c 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/func/change_info.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/change_info.php @@ -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); diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/change_mail.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/change_mail.php index 9a7f76a69..ac24fa5b0 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/func/change_mail.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/change_mail.php @@ -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; diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/change_password.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/change_password.php index a2ae8691c..b3971202d 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/func/change_password.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/change_password.php @@ -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"){ diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/settings.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/settings.php index 4d572ddaf..d8ee51a16 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/settings.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/settings.php @@ -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); diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_queue.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_queue.php index 49adc0d46..2c2c1a2fa 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_queue.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_queue.php @@ -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; diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_reply.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_reply.php index d158107b2..1640c5938 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_reply.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_reply.php @@ -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"; } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_sgroup.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_sgroup.php index e68e8d96d..f4f5edd64 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_sgroup.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_sgroup.php @@ -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; diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_ticket.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_ticket.php index dee370655..6cc3f1676 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_ticket.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_ticket.php @@ -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'])){ diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_ticket_log.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_ticket_log.php index 4ce581234..5d4cbb76b 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_ticket_log.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_ticket_log.php @@ -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 = "ID#" . $log['argument'] . ""; }else if($log['action'] == 5){ diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_user.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_user.php index 3893b842c..a8774ba83 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_user.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/show_user.php @@ -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'];