From 07cda95e11ff319e0e37f6bc43a5883091e0bfb2 Mon Sep 17 00:00:00 2001 From: Quitta Date: Mon, 8 Jul 2013 14:49:03 +0200 Subject: [PATCH] updated install, added create_Ticket function as wrapper! --- .../ryzom_ams/ams_lib/autoload/ticket.php | 83 ++++++++++++++++++- .../ams_lib/autoload/ticket_category.php | 24 ++++-- .../ams_lib/autoload/ticket_content.php | 27 +++--- .../ams_lib/autoload/ticket_reply.php | 25 +++--- .../ams_lib/autoload/ticket_user.php | 41 ++++----- .../ryzom_ams/ams_lib/autoload/users.php | 6 +- .../ryzom_ams/www/html/func/add_user.php | 13 ++- .../ryzom_ams/www/html/func/create_ticket.php | 78 +++++++---------- .../server/ryzom_ams/www/html/sql/install.php | 2 +- 9 files changed, 192 insertions(+), 107 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket.php index c483c3e80..ec34ceaa3 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket.php @@ -10,6 +10,33 @@ class Ticket{ private $author; private $db; + ////////////////////////////////////////////Functions//////////////////////////////////////////////////// + + /*FUNCTION: create_Ticket() + * creates a ticket + first initial reply and fills in the content of it! + * + */ + public static function create_Ticket( $title, $content, $category, $author, $db_data) { + + $ticket = new Ticket($db_data); + $ticket->set($title,0,0,$category,$author); + $ticket->create(); + $ticket_id = $ticket->getTId(); + + + $ticket_content = new Ticket_Content($db_data); + $ticket_content->setContent($content); + $ticket_content->create(); + $content_id = $ticket_content->getTContentId(); + + + $ticket_reply = new Ticket_Reply($db_data); + $ticket_reply->set($ticket_id, $content_id, $author); + $ticket_reply->create(); + + } + + ////////////////////////////////////////////Methods//////////////////////////////////////////////////// public function __construct($db_data) { $this->db = $db_data; } @@ -55,13 +82,65 @@ class Ticket{ $statement = $dbl->execute($query, $values); } - //Getters + + ////////////////////////////////////////////Getters//////////////////////////////////////////////////// + public function getTId(){ return $this->tId; } - //setters + public function getTimestamp(){ + return $this->timestamp; + } + + public function getTitle(){ + return $this->title; + } + + public function getStatus(){ + return $this->status; + } + + public function getQueue(){ + return $this->queue; + } + + public function getTicket_Category(){ + return $this->ticket_category; + } + + public function getAuthor(){ + return $this->author; + } + + ////////////////////////////////////////////Setters//////////////////////////////////////////////////// + public function setTId($id){ $this->tId = $id; } + + public function setTimestamp($ts){ + $this->timestamp = $ts; + } + + public function setTitle($t){ + $this->title = $t; + } + + public function setStatus($s){ + $this->status = $s; + } + + public function setQueue($q){ + $this->queue = $q; + } + + public function setTicket_Category($tc){ + $this->ticket_category = $tc; + } + + public function setAuthor($a){ + $this->author = $a; + } + } \ No newline at end of file diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_category.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_category.php index ec4956097..1fe7227b7 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_category.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_category.php @@ -5,11 +5,9 @@ class Ticket_Category{ private $tCategoryId; private $name; - public function __construct($db_data) { - $this->db = $db_data; - } - - + ////////////////////////////////////////////Functions//////////////////////////////////////////////////// + + //Creates a ticket_Catergory in the DB public static function createTicketCategory( $name ,$db ) { $dbl = new DBLayer($db); @@ -41,7 +39,13 @@ class Ticket_Category{ } return $result; } + + ////////////////////////////////////////////Methods//////////////////////////////////////////////////// + + public function __construct($db_data) { + $this->db = $db_data; + } //return constructed element based on TCategoryId public function load_With_TCategoryId( $id) { @@ -61,7 +65,8 @@ class Ticket_Category{ $statement = $dbl->execute($query, $values); } - //Getters + ////////////////////////////////////////////Getters//////////////////////////////////////////////////// + public function getName(){ if ($this->name == ""){ $this->load_With_TCategoryId($this->tCategoryId); @@ -75,10 +80,15 @@ class Ticket_Category{ } - //setters + ////////////////////////////////////////////Setters//////////////////////////////////////////////////// + public function setName($n){ $this->name = $n; } + + public function setTCategoryId($id){ + $this->tCategoryId = $id; + } } \ No newline at end of file diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_content.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_content.php index dcb86bbd1..62130d1d9 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_content.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_content.php @@ -5,11 +5,23 @@ class Ticket_Content{ private $tContentId; private $content; + + ////////////////////////////////////////////Functions//////////////////////////////////////////////////// + + //return constructed element based on TCategoryId + public static function constr_TContentId( $id, $db_data) { + $instance = new self($db_data); + $instance->setTContentId($id); + return $instance; + } + + + ////////////////////////////////////////////Methods//////////////////////////////////////////////////// + public function __construct($db_data) { $this->db = $db_data; } - //Creates a ticket_content entry in the DB public function create() { $dbl = new DBLayer($this->db); @@ -18,13 +30,6 @@ class Ticket_Content{ $this->tContentId = $dbl->executeReturnId($query, $values); ; } - //return constructed element based on TCategoryId - public static function constr_TContentId( $id, $db_data) { - $instance = new self($db_data); - $instance->setTContentId($id); - return $instance; - } - //return constructed element based on TContentId public function load_With_TContentId( $id) { $dbl = new DBLayer($this->db); @@ -42,7 +47,8 @@ class Ticket_Content{ $statement = $dbl->execute($query, $values); } - //Getters + ////////////////////////////////////////////Getters//////////////////////////////////////////////////// + public function getContent(){ if ($this->content == ""){ $this->load_With_TContentId($this->tContentId); @@ -56,7 +62,8 @@ class Ticket_Content{ } - //setters + ////////////////////////////////////////////Setters//////////////////////////////////////////////////// + public function setContent($c){ $this->content = $c; } diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_reply.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_reply.php index efbf08295..8f14a9f5f 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_reply.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_reply.php @@ -8,7 +8,16 @@ class Ticket_Reply{ private $timestamp; private $db; - //////////////////////////////////Methods///////////////////////////////// + ////////////////////////////////////////////Functions//////////////////////////////////////////////////// + + //return constructed element based on TCategoryId + public static function constr_TReplyId( $id, $db_data) { + $instance = new self($db_data); + $instance->setTReplyId($id); + return $instance; + } + + ////////////////////////////////////////////Methods//////////////////////////////////////////////////// public function __construct($db_data) { $this->db = $db_data; @@ -29,13 +38,6 @@ class Ticket_Reply{ $values = Array('ticket' => $this->ticket, 'content' => $this->content, 'author' => $this->author); $dbl->execute($query, $values); } - - //return constructed element based on TCategoryId - public static function constr_TReplyId( $id, $db_data) { - $instance = new self($db_data); - $instance->setTReplyId($id); - return $instance; - } //return constructed element based on TId public function load_With_TReplyId( $id) { @@ -57,8 +59,8 @@ class Ticket_Reply{ $statement = $dbl->execute($query, $values); } - - //////////////////////////////////Getters///////////////////////////////// + ////////////////////////////////////////////Getters//////////////////////////////////////////////////// + public function getTicket(){ return $this->ticket; } @@ -82,7 +84,8 @@ class Ticket_Reply{ } - ///////////////////////////////////setters//////////////////////////////// + ////////////////////////////////////////////Setters//////////////////////////////////////////////////// + public function setTicket($t){ $this->ticket = $t; } diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_user.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_user.php index 7e1e95c5c..b61c99f68 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_user.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_user.php @@ -6,11 +6,8 @@ class Ticket_User{ private $externId; private $db; - public function __construct($db_data) { - $this->db = $db_data; - } - - + ////////////////////////////////////////////Functions//////////////////////////////////////////////////// + //Creates a ticket_user in the DB public static function createTicketUser( $extern_id, $permission,$db ) { $dbl = new DBLayer($db); @@ -29,18 +26,6 @@ class Ticket_User{ } - //return constructed element based on TUserId - public function load_With_TUserId( $id) { - $dbl = new DBLayer($this->db); - $statement = $dbl->execute("SELECT * FROM ticket_user WHERE TUserId=:id", array('id' => $id)); - $row = $statement->fetch(); - $instance->tUserId = $row['TUserId']; - $instance->permission = $row['Permission']; - $instance->externId = $row['ExternId']; - return $instance; - } - - //return constructed element based on ExternId public static function constr_ExternId( $id, $db_data ) { $instance = new self($db_data); @@ -55,6 +40,22 @@ class Ticket_User{ } + ////////////////////////////////////////////Methods//////////////////////////////////////////////////// + public function __construct($db_data) { + $this->db = $db_data; + } + + //return constructed element based on TUserId + public function load_With_TUserId( $id) { + $dbl = new DBLayer($this->db); + $statement = $dbl->execute("SELECT * FROM ticket_user WHERE TUserId=:id", array('id' => $id)); + $row = $statement->fetch(); + $instance->tUserId = $row['TUserId']; + $instance->permission = $row['Permission']; + $instance->externId = $row['ExternId']; + return $instance; + } + //update private data to DB. public function update(){ $dbl = new DBLayer($this->db); @@ -63,7 +64,8 @@ class Ticket_User{ $statement = $dbl->execute($query, $values); } - //Getters + ////////////////////////////////////////////Getters//////////////////////////////////////////////////// + public function getPermission(){ if ($this->permission == ""){ $this->load_With_TUserId($this->tUserId); @@ -85,7 +87,8 @@ class Ticket_User{ } - //setters + ////////////////////////////////////////////Setters//////////////////////////////////////////////////// + public function setPermission($perm){ $this->permission = $perm; } 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 b82f365a0..9ce16aa37 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 @@ -284,13 +284,13 @@ class Users{ * @takes $array with name,pass and mail * @return ok if it's get correctly added to the shard, else return lib offline and put in libDB, if libDB is also offline return liboffline. */ - public function createUser($values){ + public function createUser($values, $user_id){ try { //make connection with and put into shard db global $cfg; $dbs = new DBLayer($cfg['db']['shard']); $dbs->execute("INSERT INTO user (Login, Password, Email) VALUES (:name, :pass, :mail)",$values); - ticket_user::createTicketUser( WebUsers::getId($values["name"]), 1, $cfg['db']['lib'] ); + ticket_user::createTicketUser( $user_id , 1, $cfg['db']['lib'] ); return "ok"; } catch (PDOException $e) { @@ -299,7 +299,7 @@ class Users{ $dbl = new DBLayer($cfg['db']['lib']); $dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "createUser", "query" => json_encode(array($values["name"],$values["pass"],$values["mail"])))); - ticket_user::createTicketUser( WebUsers::getId($values["name"]), 1, $cfg['db']['lib'] ); + ticket_user::createTicketUser( $user_id , 1, $cfg['db']['lib'] ); return "shardoffline"; }catch (PDOException $e) { print_r($e); 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 06dc8bc85..e21e32d6a 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 @@ -45,18 +45,17 @@ function write_user($newUser){ 'pass' => $hashpass, 'mail' => $newUser["mail"] ); - - //Create the user on the shard + in case shard is offline put copy of query in query db - //returns: ok, shardoffline or liboffline - $result = WebUsers::createUser($params); - try{ global $cfg; //make connection with web db and put it in there $dbw = new DBLayer($cfg['db']['web']); - $dbw->execute("INSERT INTO ams_user (Login, Password, Email) VALUES (:name, :pass, :mail)",$params); - //ticket_user::createTicketUser( WebUsers::getId($newUser["name"]), 1, $cfg['db']['lib'] ); + $user_id = $dbw->executeReturnId("INSERT INTO ams_user (Login, Password, Email) VALUES (:name, :pass, :mail)",$params); + + //Create the user on the shard + in case shard is offline put copy of query in query db + //returns: ok, shardoffline or liboffline + $result = WebUsers::createUser($params, $user_id); + }catch (PDOException $e) { //go to error page or something, because can't access website db diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/create_ticket.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/create_ticket.php index 7a2e54bd6..8f8010889 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/func/create_ticket.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/create_ticket.php @@ -1,64 +1,48 @@ getTUserId(); }else{ $author= Ticket_User::constr_ExternId($_POST['target_id'], $cfg['db']['lib'])->getTUserId(); } - - $ticket = new Ticket($cfg['db']['lib']); - $ticket->set($title,0,0,$category,$author); - $ticket->create(); - $ticket_id = $ticket->getTId(); - - - $ticket_content = new Ticket_Content($cfg['db']['lib']); - $ticket_content->setContent($content); - $ticket_content->create(); - $content_id = $ticket_content->getTContentId(); - - - $ticket_reply = new Ticket_Reply($cfg['db']['lib']); - $ticket_reply->set($ticket_id, $content_id, $author); - $ticket_reply->create(); - - }else{ - //ERROR: permission denied! - $_SESSION['error_code'] = "403"; - header("Location: index.php?page=error"); + Ticket::create_Ticket($title, $content, $category, $author, $cfg['db']['lib'] ); + }catch (PDOException $e) { + //ERROR: LIB DB is not online! + header("Location: index.php"); exit; } - + }else{ - //ERROR: The form was not filled in correclty - header("Location: index.php?page=settings"); - exit; - } + //ERROR: permission denied! + $_SESSION['error_code'] = "403"; + header("Location: index.php?page=error"); + exit; + } + }else{ - //ERROR: user is not logged in - header("Location: index.php"); - exit; - } - - }catch (PDOException $e) { - //go to error page or something, because can't access website db - print_r($e); - exit; - } + //ERROR: The form was not filled in correclty + header("Location: index.php?page=settings"); + exit; + } + }else{ + //ERROR: user is not logged in + header("Location: index.php"); + exit; + } } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php b/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php index e233bb322..2101f80da 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php @@ -256,7 +256,7 @@ 'pass' => $hashpass, 'mail' => "admin@admin.com", ); - Users::createUser($params); + Users::createUser($params, 1); try{ $params['permission'] = 2; $dbw = new DBLayer($cfg['db']['web']);