From 23c0a8bc24486b99488eefe0c96a89269ff9180a Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Sun, 25 May 2014 15:03:20 +0530 Subject: [PATCH 02/36] CRUD layer for AMS --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ryzom_ams/ams_lib/autoload/dblayer.php | 112 +++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/dblayer.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/dblayer.php index 58ea7b80e..b095b4dc7 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/dblayer.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/dblayer.php @@ -81,5 +81,113 @@ class DBLayer{ $this->PDO->commit(); return $lastId; } - -} \ No newline at end of file + /** + * + * Select function using prepared statement + * @param string $tb_name Table Name to Select + * @param array $data Associative array + * @param string $where where to select + * @return array Array containing fetched data + */ + public function select($query, $data) + { + try{ + $sth = $this->PDO->prepare($query); + $this->PDO->beginTransaction(); + $sth->execute(array($data)); + $this->PDO->commit(); + }catch(Exception $e) + { + $this->PDO->rollBack(); + throw new Exception("error selection"); + return false; + } + return $sth; + } + + /** + * + * Update function with prepared statement + * @param string $tb_name name of the table + * @param array $data associative array with values + * @param string $where where part + * @throws Exception error in updating + */ + public function update($tb_name, $data, $where) + { + $field_option_values=null; + foreach ($data as $key => $value) + { + $field_option_values.=",$key".'=:'.$value; + } + $field_option_values = ltrim($field_option_values,','); + try { + $sth = $this->PDO->prepare("UPDATE $tb_name SET $field_option_values WHERE $where "); + + foreach ($data as $key => $value) + { + $sth->bindValue(":$key", $value); + } + $this->PDO->beginTransaction(); + $sth->execute(); + $this->PDO->commit(); + }catch (Exception $e) + { + $this->PDO->rollBack(); + throw new Exception('error in updating'); + } + } + /** + * + * insert function using prepared statements + * @param string $tb_name Name of the table to insert in + * @param array $data Associative array of data to insert + */ + + public function insert($tb_name, $data) + { + $field_values =':'. implode(',:', array_keys($data)); + $field_options = implode(',', array_keys($data)); + try{ + $sth = $this->PDO->prepare("INSERT INTO $tb_name ($field_options) VALUE ($field_values)"); + foreach ($data as $key => $value ) + { + + $sth->bindValue(":$key", $value); + } + $this->PDO->beginTransaction(); + //execution + $sth->execute(); + $this->PDO->commit(); + + }catch (Exception $e) + { + //for rolling back the changes during transaction + $this->PDO->rollBack(); + throw new Exception("error in inseting"); + } + } + + /** + * + * Delete database entery using prepared statement + * @param string $tb_name + * @param string $where + * @throws error in deleting + */ + public function delete($tb_name, $where) + { + try { + $sth = $this->prepare("DELETE FROM $tb_name WHERE $where"); + $this->PDO->beginTransaction(); + $sth->execute(); + $this->PDO->commit(); + } + catch (Exception $e) + { + $this->rollBack(); + throw new Exception("error in deleting"); + } + + } +} From a92f32c1c434ee17e2516f5b156eafee840c6c0b Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Tue, 27 May 2014 14:19:37 +0530 Subject: [PATCH 03/36] few more changes to the CRUD layer in ams --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ryzom_ams/ams_lib/autoload/dblayer.php | 69 +++++++++++++++---- 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/dblayer.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/dblayer.php index b095b4dc7..b82e7ea8f 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/dblayer.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/dblayer.php @@ -67,34 +67,74 @@ class DBLayer{ return $statement; } - /** + /** * execute a query (an insertion query) that has parameters and return the id of it's insertion * @param $query the mysql query * @param $params the parameters that are being used by the query * @return returns the id of the last inserted element. */ - public function executeReturnId($query,$params){ - $statement = $this->PDO->prepare($query); - $this->PDO->beginTransaction(); - $statement->execute($params); - $lastId =$this->PDO->lastInsertId(); - $this->PDO->commit(); - return $lastId; + public function executeReturnId($tb_name,$data){ + $field_values =':'. implode(',:', array_keys($data)); + $field_options = implode(',', array_keys($data)); + try{ + $sth = $this->PDO->prepare("INSERT INTO $tb_name ($field_options) VALUE ($field_values)"); + foreach ($data as $key => $value ) + { + $sth->bindValue(":$key", $value); + } + $this->PDO->beginTransaction(); + //execution + $sth->execute(); + $lastId =$this->PDO->lastInsertId(); + $this->PDO->commit(); + }catch (Exception $e) + { + //for rolling back the changes during transaction + $this->PDO->rollBack(); + throw new Exception("error in inseting"); + } + return $lastId; } - /** + + + /** * * Select function using prepared statement * @param string $tb_name Table Name to Select * @param array $data Associative array * @param string $where where to select - * @return array Array containing fetched data + * @return statement object */ - public function select($query, $data) - { + public function selectWithParameter($param, $tb_name, $data, $where) + { + try{ + $sth = $this->PDO->prepare("SELECT $param FROM $tb_name WHERE $where"); + $this->PDO->beginTransaction(); + $sth->execute($data); + $this->PDO->commit(); + }catch(Exception $e) + { + $this->PDO->rollBack(); + throw new Exception("error selection"); + return false; + } + return $sth; + } + + /** + * + * Select function using prepared statement + * @param string $tb_name Table Name to Select + * @param array $data Associative array + * @param string $where where to select + * @return statement object + */ + public function select($tb_name, $data ,$where) + { try{ - $sth = $this->PDO->prepare($query); + $sth = $this->PDO->prepare("SELECT * FROM $tb_name WHERE $where"); $this->PDO->beginTransaction(); - $sth->execute(array($data)); + $sth->execute($data); $this->PDO->commit(); }catch(Exception $e) { @@ -152,7 +192,6 @@ class DBLayer{ $sth = $this->PDO->prepare("INSERT INTO $tb_name ($field_options) VALUE ($field_values)"); foreach ($data as $key => $value ) { - $sth->bindValue(":$key", $value); } $this->PDO->beginTransaction(); From 8a28b3583a6d49d19b95a11c70b28a5cc47f6152 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Wed, 28 May 2014 03:48:44 +0530 Subject: [PATCH 04/36] restructuring of AMS database functions to work with CRUD --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ryzom_ams/ams_lib/autoload/assigned.php | 16 +++---- .../ryzom_ams/ams_lib/autoload/forwarded.php | 14 +++--- .../ryzom_ams/ams_lib/autoload/helpers.php | 2 +- .../ams_lib/autoload/in_support_group.php | 12 ++--- .../ams_lib/autoload/mail_handler.php | 9 +--- .../ryzom_ams/ams_lib/autoload/querycache.php | 8 ++-- .../ams_lib/autoload/support_group.php | 24 ++++------ .../ryzom_ams/ams_lib/autoload/sync.php | 25 ++++++----- .../ryzom_ams/ams_lib/autoload/ticket.php | 14 +++--- .../ams_lib/autoload/ticket_category.php | 15 +++---- .../ams_lib/autoload/ticket_content.php | 12 ++--- .../ams_lib/autoload/ticket_info.php | 18 ++++---- .../ryzom_ams/ams_lib/autoload/ticket_log.php | 16 +++---- .../ams_lib/autoload/ticket_reply.php | 12 ++--- .../ams_lib/autoload/ticket_user.php | 17 +++---- .../ryzom_ams/ams_lib/autoload/users.php | 36 +++++++-------- .../ryzom_ams/www/html/autoload/webusers.php | 44 +++++++++---------- .../ryzom_ams/www/html/func/add_user.php | 11 +++-- 18 files changed, 129 insertions(+), 176 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/assigned.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/assigned.php index 8de17a9e2..d9d730c8e 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/assigned.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/assigned.php @@ -80,9 +80,9 @@ class Assigned{ $dbl = new DBLayer("lib"); //check if ticket is already assigned - if($user_id == 0 && $dbl->execute(" SELECT * FROM `assigned` WHERE `Ticket` = :ticket_id", array('ticket_id' => $ticket_id) )->rowCount() ){ + if($user_id == 0 && $dbl->select("`assigned`", array('ticket_id' => $ticket_id), "`Ticket` = :ticket_id")->rowCount() ){ return true; - }else if( $dbl->execute(" SELECT * FROM `assigned` WHERE `Ticket` = :ticket_id and `User` = :user_id", array('ticket_id' => $ticket_id, 'user_id' => $user_id) )->rowCount()){ + }else if( $dbl->select("`assigned`", array('ticket_id' => $ticket_id, 'user_id' => $user_id), "`Ticket` = :ticket_id and `User` = :user_id")->rowCount() ){ return true; }else{ return false; @@ -115,9 +115,7 @@ class Assigned{ */ public function create() { $dbl = new DBLayer("lib"); - $query = "INSERT INTO `assigned` (`User`,`Ticket`) VALUES (:user, :ticket)"; - $values = Array('user' => $this->getUser(), 'ticket' => $this->getTicket()); - $dbl->execute($query, $values); + $dbl->insert("`assigned`", Array('User' => $this->getUser(), 'Ticket' => $this->getTicket()); } @@ -127,9 +125,7 @@ class Assigned{ */ public function delete() { $dbl = new DBLayer("lib"); - $query = "DELETE FROM `assigned` WHERE `User` = :user_id and `Ticket` = :ticket_id"; - $values = array('user_id' => $this->getUser() ,'ticket_id' => $this->getTicket()); - $dbl->execute($query, $values); + $dbl->delete("`assigned`", array('user_id' => $this->getUser() ,'ticket_id' => $this->getTicket(), "`User` = :user_id and `Ticket` = :ticket_id"); } /** @@ -139,7 +135,7 @@ class Assigned{ */ public function load($ticket_id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM `assigned` WHERE `Ticket` = :ticket_id", Array('ticket_id' => $ticket_id)); + $statement = $dbl->select("`assigned`", Array('ticket_id' => $ticket_id), "`Ticket` = :ticket_id"); $row = $statement->fetch(); $this->set($row); } @@ -181,4 +177,4 @@ class Assigned{ } -} \ No newline at end of file +} diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/forwarded.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/forwarded.php index 54fece58c..ccba764e6 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/forwarded.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/forwarded.php @@ -55,7 +55,7 @@ class Forwarded{ */ public static function isForwarded( $ticket_id) { $dbl = new DBLayer("lib"); - if( $dbl->execute(" SELECT * FROM `forwarded` WHERE `Ticket` = :ticket_id", array('ticket_id' => $ticket_id))->rowCount()){ + if( $dbl->select("`forwarded`", array('ticket_id' => $ticket_id), "`Ticket` = :ticket_id")->rowCount() ){ return true; }else{ return false; @@ -90,9 +90,7 @@ class Forwarded{ */ public function create() { $dbl = new DBLayer("lib"); - $query = "INSERT INTO `forwarded` (`Group`,`Ticket`) VALUES (:group, :ticket)"; - $values = Array('group' => $this->getGroup(), 'ticket' => $this->getTicket()); - $dbl->execute($query, $values); + $dbl->insert("`forwarded`", Array('Group' => $this->getGroup(), 'Ticket' => $this->getTicket())); } @@ -102,9 +100,7 @@ class Forwarded{ */ public function delete() { $dbl = new DBLayer("lib"); - $query = "DELETE FROM `forwarded` WHERE `Group` = :group_id and `Ticket` = :ticket_id"; - $values = array('group_id' => $this->getGroup() ,'ticket_id' => $this->getTicket()); - $dbl->execute($query, $values); + $dbl->delete("`forwarded`", array('group_id' => $this->getGroup() ,'ticket_id' => $this->getTicket(), "`Group` = :group_id and `Ticket` = :ticket_id"); } @@ -115,7 +111,7 @@ class Forwarded{ */ public function load( $ticket_id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM `forwarded` WHERE `Ticket` = :ticket_id", Array('ticket_id' => $ticket_id)); + $statement = $dbl->select("`forwarded`", Array('ticket_id' => $ticket_id), "`Ticket` = :ticket_id"); $row = $statement->fetch(); $this->set($row); } @@ -156,4 +152,4 @@ class Forwarded{ } -} \ No newline at end of file +} diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php index 40a96f6c1..2d26f3c21 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php @@ -206,7 +206,7 @@ class Helpers{ $dbr = new DBLayer("ring"); if (isset($_GET['UserId']) && isset($_COOKIE['ryzomId'])){ $id = $_GET['UserId']; - $statement = $dbr->execute("SELECT * FROM ring_users WHERE user_id=:id AND cookie =:cookie", array('id' => $id, 'cookie' => $_COOKIE['ryzomId'])); + $statement = $dbr->select("ring_users", array('id' => $id, 'cookie' => $_COOKIE['ryzomId']), "user_id=:id AND cookie =:cookie"); if ($statement->rowCount() ){ $entry = $statement->fetch(); //print_r($entry); diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/in_support_group.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/in_support_group.php index bf10d3d9a..86c678cd3 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/in_support_group.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/in_support_group.php @@ -21,7 +21,7 @@ class In_Support_Group{ public static function userExistsInSGroup( $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() ){ + if( $dbl->select("in_support_group", array('user_id' => $user_id, 'group_id' => $group_id), "`User` = :user_id and `Group` = :group_id")->rowCount() ){ return true; }else{ return false; @@ -54,9 +54,7 @@ class In_Support_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); + $dbl->insert("`in_support_group`", Array('User' => $this->user, 'Group' => $this->group); } @@ -66,9 +64,7 @@ class In_Support_Group{ */ public function delete() { $dbl = new DBLayer("lib"); - $query = "DELETE FROM `in_support_group` WHERE `User` = :user_id and `Group` = :group_id"; - $values = array('user_id' => $this->getUser() ,'group_id' => $this->getGroup()); - $dbl->execute($query, $values); + $dbl->delete("`in_support_group`", array('user_id' => $this->getUser() ,'group_id' => $this->getGroup(), "`User` = :user_id and `Group` = :group_id"); } /* @@ -118,4 +114,4 @@ class In_Support_Group{ } -} \ No newline at end of file +} diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/mail_handler.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/mail_handler.php index dde8d4e02..66cb0f95d 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/mail_handler.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/mail_handler.php @@ -118,12 +118,7 @@ class Mail_Handler{ $id_user = $recipient; $recipient = NULL; } - - $query = "INSERT INTO email (Recipient,Subject,Body,Status,Attempts,Sender,UserId,MessageId,TicketId) VALUES (:recipient, :subject, :body, :status, :attempts, :sender, :id_user, :messageId, :ticketId)"; - $values = array('recipient' => $recipient, 'subject' => $subject, 'body' => $body, 'status' => 'NEW', 'attempts'=> 0, 'sender' => $from,'id_user' => $id_user, 'messageId' => 0, 'ticketId'=> $ticket_id); - $db = new DBLayer("lib"); - $db->execute($query, $values); - + $db->insert("email", array('Recipient' => $recipient, 'Subject' => $subject, 'Body' => $body, 'Status' => 'NEW', 'Attempts'=> 0, 'Sender' => $from,'UserId' => $id_user, 'MessageId' => 0, 'TicketId'=> $ticket_id)); } @@ -173,7 +168,7 @@ class Mail_Handler{ //select all new & failed emails & try to send them //$emails = db_query("select * from email where status = 'NEW' or status = 'FAILED'"); - $statement = $this->db->executeWithoutParams("select * from email where Status = 'NEW' or Status = 'FAILED'"); + $statement = $this->db->select("email",array(null), "Status = 'NEW' or Status = 'FAILED'"); $emails = $statement->fetchAll(); foreach($emails as $email) { diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/querycache.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/querycache.php index 3da0887c9..6f0c0dca6 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/querycache.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/querycache.php @@ -47,7 +47,7 @@ class Querycache{ */ public function load_With_SID( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ams_querycache WHERE SID=:id", array('id' => $id)); + $statement = $dbl->select("ams_querycache", array('id' => $id), "SID=:id"); $row = $statement->fetch(); $this->set($row); } @@ -58,9 +58,7 @@ class Querycache{ */ public function update(){ $dbl = new DBLayer("lib"); - $query = "UPDATE ams_querycache SET type= :t, query = :q, db = :d WHERE SID=:id"; - $values = Array('id' => $this->getSID(), 't' => $this->getType(), 'q' => $this->getQuery(), 'd' => $this->getDb()); - $statement = $dbl->execute($query, $values); + $dbl->update("ams_querycache", Array('type' => $this->getType(), 'query' => $this->getQuery(), 'db' => $this->getDb(), "SID=$this->getSID()" ); } ////////////////////////////////////////////Getters//////////////////////////////////////////////////// @@ -127,4 +125,4 @@ class Querycache{ $this->db= $d; } -} \ No newline at end of file +} diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/support_group.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/support_group.php index c42d12efb..7b8a864d4 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/support_group.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/support_group.php @@ -24,7 +24,7 @@ class Support_Group{ */ public static function getGroup($id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM support_group WHERE SGroupId = :id", array('id' => $id)); + $statement = $dbl->select("support_group", array('id' => $id), "SGroupId = :id"); $row = $statement->fetch(); $instanceGroup = new self(); $instanceGroup->set($row); @@ -102,10 +102,10 @@ class Support_Group{ public static function supportGroup_EntryNotExists( $name, $tag) { $dbl = new DBLayer("lib"); //check if name is already used - if( $dbl->execute("SELECT * FROM support_group WHERE Name = :name",array('name' => $name))->rowCount() ){ + if( $dbl->select("support_group", array('name' => $name), "Name = :name")->rowCount() ){ return "NAME_TAKEN"; } - else if( $dbl->execute("SELECT * FROM support_group WHERE Tag = :tag",array('tag' => $tag))->rowCount() ){ + else if( $dbl->select("support_group", array('tag' => $tag), "Tag = :tag")->rowCount() ){ return "TAG_TAKEN"; }else{ return "SUCCESS"; @@ -121,7 +121,7 @@ class Support_Group{ public static function supportGroup_Exists( $id) { $dbl = new DBLayer("lib"); //check if supportgroup id exist - if( $dbl->execute("SELECT * FROM support_group WHERE SGroupId = :id",array('id' => $id ))->rowCount() ){ + if( $dbl->select("support_group", array('id' => $id ), "SGroupId = :id")->rowCount() ){ return true; }else{ return false; @@ -305,9 +305,7 @@ class Support_Group{ */ public function create() { $dbl = new DBLayer("lib"); - $query = "INSERT INTO support_group (Name, Tag, GroupEmail, IMAP_MailServer, IMAP_Username, IMAP_Password) VALUES (:name, :tag, :groupemail, :imap_mailserver, :imap_username, :imap_password)"; - $values = Array('name' => $this->getName(), 'tag' => $this->getTag(), 'groupemail' => $this->getGroupEmail(), 'imap_mailserver' => $this->getIMAP_MailServer(), 'imap_username' => $this->getIMAP_Username(), 'imap_password' => $this->getIMAP_Password()); - $dbl->execute($query, $values); + $dbl->insert("support_group", Array('Name' => $this->getName(), 'Tag' => $this->getTag(), 'GroupEmail' => $this->getGroupEmail(), 'IMAP_MailServer' => $this->getIMAP_MailServer(), 'IMAP_Username' => $this->getIMAP_Username(), 'IMAP_Password' => $this->getIMAP_Password()); } @@ -318,7 +316,7 @@ class Support_Group{ */ public function load_With_SGroupId( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM `support_group` WHERE `SGroupId` = :id", array('id' => $id)); + $statement = $dbl->select("`support_group`", array('id' => $id), "`SGroupId` = :id"); $row = $statement->fetch(); $this->set($row); } @@ -329,9 +327,7 @@ class Support_Group{ */ public function update(){ $dbl = new DBLayer("lib"); - $query = "UPDATE `support_group` SET `Name` = :name, `Tag` = :tag, `GroupEmail` = :groupemail, `IMAP_MailServer` = :mailserver, `IMAP_Username` = :username, `IMAP_Password` = :password WHERE `SGroupId` = :id"; - $values = Array('id' => $this->getSGroupId(), 'name' => $this->getName(), 'tag' => $this->getTag(), 'groupemail' => $this->getGroupEmail(), 'mailserver' => $this->getIMAP_MailServer(), 'username' => $this->getIMAP_Username(), 'password' => $this->getIMAP_Password() ); - $statement = $dbl->execute($query, $values); + $dbl->update("`support_group`", Array('Name' => $this->getName(), 'Tag' => $this->getTag(), 'GroupEmail' => $this->getGroupEmail(), 'IMAP_MailServer' => $this->getIMAP_MailServer(), 'IMAP_Username' => $this->getIMAP_Username(), 'IMAP_password' => $this->getIMAP_Password(), "`SGroupId` = $this->getSGroupId()"); } @@ -341,9 +337,7 @@ class Support_Group{ */ public function delete(){ $dbl = new DBLayer("lib"); - $query = "DELETE FROM `support_group` WHERE `SGroupId` = :id"; - $values = Array('id' => $this->getSGroupId()); - $statement = $dbl->execute($query, $values); + $dbl->delete("`support_group`", Array('id' => $this->getSGroupId(), "`SGroupId` = :id"); } ////////////////////////////////////////////Getters//////////////////////////////////////////////////// @@ -453,4 +447,4 @@ class Support_Group{ public function setIMAP_Password($p){ $this->iMap_Password = $p; } -} \ No newline at end of file +} diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/sync.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/sync.php index e9d4c8748..a79ef8b83 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/sync.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/sync.php @@ -42,34 +42,37 @@ class Sync{ $decode = json_decode($record['query']); $values = array('username' => $decode[0]); //make connection with and put into shard db & delete from the lib - $sth = $db->execute("SELECT UId FROM user WHERE Login= :username;", $values); + $sth=$db->selectWithParameter("UId", "user", $values, "Login= :username" ); $result = $sth->fetchAll(); foreach ($result as $UId) { - $ins_values = array('id' => $UId['UId']); - $db->execute("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES (:id, 'r2', 'OPEN');", $ins_values); - $db->execute("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES (:id , 'ryzom_open', 'OPEN');", $ins_values); + $ins_values = array('UId' => $UId['UId']); + $ins_values['ClientApplication'] = "r2"; + $ins_values['AccessPrivilege'] = "OPEN"; + $db->insert("permission", $ins_values); + $ins_values['ClientApplication'] = 'ryzom_open'; + $db->insert("permission",$ins_values); } break; case 'change_pass': $decode = json_decode($record['query']); - $values = array('user' => $decode[0], 'pass' => $decode[1]); + $values = array('Password' => $decode[1]); //make connection with and put into shard db & delete from the lib - $db->execute("UPDATE user SET Password = :pass WHERE Login = :user",$values); + $db->update("user", $values, "Login = $decode[0]"); break; case 'change_mail': $decode = json_decode($record['query']); - $values = array('user' => $decode[0], 'mail' => $decode[1]); + $values = array('Email' => $decode[1]); //make connection with and put into shard db & delete from the lib - $db->execute("UPDATE user SET Email = :mail WHERE Login = :user",$values); + $db->update("user", $values, "Login = $decode[0]"); break; case 'createUser': $decode = json_decode($record['query']); - $values = array('login' => $decode[0], 'pass' => $decode[1], 'mail' => $decode[2] ); + $values = array('Login' => $decode[0], 'Password' => $decode[1], 'Email' => $decode[2] ); //make connection with and put into shard db & delete from the lib - $db->execute("INSERT INTO user (Login, Password, Email) VALUES (:login, :pass, :mail)",$values); + $db->insert("user", $values); break; } - $dbl->execute("DELETE FROM ams_querycache WHERE SID=:SID",array('SID' => $record['SID'])); + $dbl->delete("ams_querycache", array('SID' => $record['SID']), "SID=:SID"); } if ($display == true) { print('Syncing completed'); 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 21e2614d5..51f987e5a 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 @@ -27,7 +27,7 @@ class Ticket{ public static function ticketExists($id) { $dbl = new DBLayer("lib"); //check if ticket exists - if( $dbl->execute(" SELECT * FROM `ticket` WHERE `TId` = :ticket_id", array('ticket_id' => $id) )->rowCount() ){ + if( $dbl->select("`ticket`", array('ticket_id' => $id), "`TId` = :ticket_id")->rowCount() ){ return true; }else{ return false; @@ -343,9 +343,7 @@ class Ticket{ */ public function create(){ $dbl = new DBLayer("lib"); - $query = "INSERT INTO ticket (Timestamp, Title, Status, Queue, Ticket_Category, Author, Priority) VALUES (now(), :title, :status, :queue, :tcat, :author, :priority)"; - $values = Array('title' => $this->title, 'status' => $this->status, 'queue' => $this->queue, 'tcat' => $this->ticket_category, 'author' => $this->author, 'priority' => $this->priority); - $this->tId = $dbl->executeReturnId($query, $values); ; + $this->tId = $dbl->executeReturnId("ticket", Array('Timestamp'=>now(), 'Title' => $this->title, 'Status' => $this->status, 'Queue' => $this->queue, 'Ticket_Category' => $this->ticket_category, 'Author' => $this->author, 'Priority' => $this->priority)); } @@ -356,7 +354,7 @@ class Ticket{ */ public function load_With_TId( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket WHERE TId=:id", array('id' => $id)); + $statement = $dbl->select("ticket", array('id' => $id), "TId=:id"); $row = $statement->fetch(); $this->tId = $row['TId']; $this->timestamp = $row['Timestamp']; @@ -374,9 +372,7 @@ class Ticket{ */ public function update(){ $dbl = new DBLayer("lib"); - $query = "UPDATE ticket SET Timestamp = :timestamp, Title = :title, Status = :status, Queue = :queue, Ticket_Category = :tcat, Author = :author, Priority = :priority WHERE TId=:id"; - $values = Array('id' => $this->tId, 'timestamp' => $this->timestamp, 'title' => $this->title, 'status' => $this->status, 'queue' => $this->queue, 'tcat' => $this->ticket_category, 'author' => $this->author, 'priority' => $this->priority); - $statement = $dbl->execute($query, $values); + $dbl->update("ticket", Array('Timestamp' => $this->timestamp, 'Title' => $this->title, 'Status' => $this->status, 'Queue' => $this->queue, 'Ticket_Category' => $this->ticket_category, 'Author' => $this->author, 'Priority' => $this->priority), "TId=$this->tId"); } @@ -575,4 +571,4 @@ class Ticket{ $this->priority = $p; } -} \ 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 92e603d12..f6941febe 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 @@ -16,10 +16,7 @@ class Ticket_Category{ */ public static function createTicketCategory( $name) { $dbl = new DBLayer("lib"); - $query = "INSERT INTO ticket_category (Name) VALUES (:name)"; - $values = Array('name' => $name); - $dbl->execute($query, $values); - + $dbl->insert("ticket_category", Array('Name' => $name)); } @@ -40,7 +37,7 @@ class Ticket_Category{ */ public static function getAllCategories() { $dbl = new DBLayer("lib"); - $statement = $dbl->executeWithoutParams("SELECT * FROM ticket_category"); + $statement = $dbl->select("ticket_category", array(null), "1"); $row = $statement->fetchAll(); $result = Array(); foreach($row as $category){ @@ -70,7 +67,7 @@ class Ticket_Category{ */ public function load_With_TCategoryId( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_category WHERE TCategoryId=:id", array('id' => $id)); + $statement = $dbl->select("ticket_category", array('id' => $id), "TCategoryId=:id"); $row = $statement->fetch(); $this->tCategoryId = $row['TCategoryId']; $this->name = $row['Name']; @@ -82,9 +79,7 @@ class Ticket_Category{ */ public function update(){ $dbl = new DBLayer("lib"); - $query = "UPDATE ticket_category SET Name = :name WHERE TCategoryId=:id"; - $values = Array('id' => $this->tCategoryId, 'name' => $this->name); - $statement = $dbl->execute($query, $values); + $dbl->update("ticket_category", Array('Name' => $this->name), "TCategoryId = $this->tCategoryId"); } ////////////////////////////////////////////Getters//////////////////////////////////////////////////// @@ -126,4 +121,4 @@ class Ticket_Category{ } -} \ 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 445cad867..8b7787f8e 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 @@ -43,9 +43,7 @@ class Ticket_Content{ */ public function create() { $dbl = new DBLayer("lib"); - $query = "INSERT INTO ticket_content (Content) VALUES (:content)"; - $values = Array('content' => $this->content); - $this->tContentId = $dbl->executeReturnId($query, $values); ; + $this->tContentId = $dbl->executeReturnId("ticket_content", Array('Content' => $this->content)); } @@ -56,7 +54,7 @@ class Ticket_Content{ */ public function load_With_TContentId( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_content WHERE TContentId=:id", array('id' => $id)); + $statement = $dbl->select("ticket_content", array('id' => $id), "TContentId=:id"); $row = $statement->fetch(); $this->tContentId = $row['TContentId']; $this->content = $row['Content']; @@ -67,9 +65,7 @@ class Ticket_Content{ */ public function update(){ $dbl = new DBLayer("lib"); - $query = "UPDATE ticket_content SET Content = :content WHERE TContentId=:id"; - $values = Array('id' => $this->tContentId, 'content' => $this->content); - $statement = $dbl->execute($query, $values); + $dbl->update("ticket_content", Array('Content' => $this->content), "TContentId = $this->tContentId"); } ////////////////////////////////////////////Getters//////////////////////////////////////////////////// @@ -110,4 +106,4 @@ class Ticket_Content{ $this->tContentId = $c; } -} \ No newline at end of file +} diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_info.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_info.php index fc852d093..eb7c8ebc5 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_info.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_info.php @@ -52,7 +52,7 @@ class Ticket_Info{ public static function TicketHasInfo($ticket_id) { $dbl = new DBLayer("lib"); //check if ticket is already assigned - if( $dbl->execute(" SELECT * FROM `ticket_info` WHERE `Ticket` = :ticket_id", array('ticket_id' => $ticket_id) )->rowCount() ){ + if( $dbl->select("`ticket_info`", array('ticket_id' => $ticket_id), "`Ticket` = :ticket_id")->rowCount() ){ return true; }else{ return false; @@ -102,7 +102,7 @@ class Ticket_Info{ */ public function load_With_TInfoId( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_info WHERE TInfoId=:id", array('id' => $id)); + $statement = $dbl->select("ticket_info", array('id' => $id), "TInfoId=:id"); $row = $statement->fetch(); $this->set($row); } @@ -115,7 +115,7 @@ class Ticket_Info{ */ public function load_With_Ticket( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_info WHERE Ticket=:id", array('id' => $id)); + $statement = $dbl->select("ticket_info", array('id' => $id), "Ticket=:id"); $row = $statement->fetch(); $this->set($row); } @@ -127,12 +127,10 @@ class Ticket_Info{ */ public function create() { $dbl = new DBLayer("lib"); - $query = "INSERT INTO ticket_info ( Ticket, ShardId, UserPosition,ViewPosition, ClientVersion, PatchVersion,ServerTick, ConnectState, LocalAddress, Memory, OS, -Processor, CPUID, CpuMask, HT, NeL3D, UserId) VALUES ( :ticket, :shardid, :userposition, :viewposition, :clientversion, :patchversion, :servertick, :connectstate, :localaddress, :memory, :os, :processor, :cpuid, :cpu_mask, :ht, :nel3d, :user_id )"; - $values = Array('ticket' => $this->getTicket(), 'shardid' => $this->getShardId(), 'userposition' => $this->getUser_Position(), 'viewposition' => $this->getView_Position(), 'clientversion' => $this->getClient_Version(), -'patchversion' => $this->getPatch_Version(), 'servertick' => $this->getServer_Tick(), 'connectstate' => $this->getConnect_State(), 'localaddress' => $this->getLocal_Address(), 'memory' => $this->getMemory(), 'os'=> $this->getOS(), 'processor' => $this->getProcessor(), 'cpuid' => $this->getCPUId(), -'cpu_mask' => $this->getCpu_Mask(), 'ht' => $this->getHT(), 'nel3d' => $this->getNel3D(), 'user_id' => $this->getUser_Id()); - $dbl->execute($query, $values); + $values = Array('Ticket' => $this->getTicket(), 'ShardId' => $this->getShardId(), 'UserPosition' => $this->getUser_Position(), 'ViewPosition' => $this->getView_Position(), 'ClientVersion' => $this->getClient_Version(), +'PatchVersion' => $this->getPatch_Version(), 'ServerTick' => $this->getServer_Tick(), 'ConnectState' => $this->getConnect_State(), 'LocalAddress' => $this->getLocal_Address(), 'Memory' => $this->getMemory(), 'OS'=> $this->getOS(), 'Processor' => $this->getProcessor(), 'CPUID' => $this->getCPUId(), +'CpuMask' => $this->getCpu_Mask(), 'HT' => $this->getHT(), 'NeL3D' => $this->getNel3D(), 'UserId' => $this->getUser_Id()); + $dbl->insert("ticket_info",$values); } @@ -411,4 +409,4 @@ Processor, CPUID, CpuMask, HT, NeL3D, UserId) VALUES ( :ticket, :shardid, :user } -} \ No newline at end of file +} diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_log.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_log.php index 8c7439bc0..6693fe3ce 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_log.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/ticket_log.php @@ -82,9 +82,8 @@ class Ticket_Log{ global $TICKET_LOGGING; if($TICKET_LOGGING){ $dbl = new DBLayer("lib"); - $query = "INSERT INTO ticket_log (Timestamp, Query, Ticket, Author) VALUES (now(), :query, :ticket, :author )"; - $values = Array('ticket' => $ticket_id, 'author' => $author_id, 'query' => json_encode(array($action,$arg))); - $dbl->execute($query, $values); + $values = Array('Timestamp'=>now(), 'Query' => json_encode(array($action,$arg)), 'Ticket' => $ticket_id, 'Author' => $author_id); + $dbl->insert("ticket_log", $values); } } @@ -148,7 +147,7 @@ class Ticket_Log{ */ public function load_With_TLogId( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_log WHERE TLogId=:id", array('id' => $id)); + $dbl->select("ticket_log", array('id' => $id), "TLogId=:id"); $row = $statement->fetch(); $this->set($row); } @@ -159,9 +158,10 @@ class Ticket_Log{ */ public function update(){ $dbl = new DBLayer("lib"); - $query = "UPDATE ticket_log SET Timestamp = :timestamp, Query = :query, Author = :author, Ticket = :ticket WHERE TLogId=:id"; - $values = Array('id' => $this->getTLogId(), 'timestamp' => $this->getTimestamp(), 'query' => $this->getQuery(), 'author' => $this->getAuthor(), 'ticket' => $this->getTicket() ); - $statement = $dbl->execute($query, $values); + + $values = Array('timestamp' => $this->getTimestamp(), 'query' => $this->getQuery(), 'author' => $this->getAuthor(), 'ticket' => $this->getTicket() ); + $dbl->update("ticket_log", $values, "TLogId = $this->getTLogId()"); + } ////////////////////////////////////////////Getters//////////////////////////////////////////////////// @@ -273,4 +273,4 @@ class Ticket_Log{ } -} \ No newline at end of file +} 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 8e784543d..2675fcfbe 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 @@ -123,9 +123,7 @@ class Ticket_Reply{ */ public function create(){ $dbl = new DBLayer("lib"); - $query = "INSERT INTO ticket_reply (Ticket, Content, Author, Timestamp, Hidden) VALUES (:ticket, :content, :author, now(), :hidden)"; - $values = Array('ticket' => $this->ticket, 'content' => $this->content, 'author' => $this->author, 'hidden' => $this->hidden); - $this->tReplyId = $dbl->executeReturnId($query, $values); + $this->tReplyId = $dbl->executeReturnId("ticket_reply", Array('Ticket' => $this->ticket, 'Content' => $this->content, 'Author' => $this->author,'Timestamp'=>now(), 'Hidden' => $this->hidden)); } /** @@ -135,7 +133,7 @@ class Ticket_Reply{ */ public function load_With_TReplyId( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_reply WHERE TReplyId=:id", array('id' => $id)); + $statement = $dbl->select("ticket_reply", array('id' => $id), "TReplyId=:id"); $row = $statement->fetch(); $this->tReplyId = $row['TReplyId']; $this->ticket = $row['Ticket']; @@ -150,9 +148,7 @@ class Ticket_Reply{ */ public function update(){ $dbl = new DBLayer("lib"); - $query = "UPDATE ticket SET Ticket = :ticket, Content = :content, Author = :author, Timestamp = :timestamp, Hidden = :hidden WHERE TReplyId=:id"; - $values = Array('id' => $this->tReplyId, 'timestamp' => $this->timestamp, 'ticket' => $this->ticket, 'content' => $this->content, 'author' => $this->author, 'hidden' => $this->hidden); - $statement = $dbl->execute($query, $values); + $dbl->update("ticket", Array('Ticket' => $this->ticket, 'Content' => $this->content, 'Author' => $this->author, 'Timestamp' => $this->timestamp, 'Hidden' => $this->hidden), "TReplyId=$this->tReplyId, "); } ////////////////////////////////////////////Getters//////////////////////////////////////////////////// @@ -249,4 +245,4 @@ class Ticket_Reply{ public function setHidden($h){ $this->hidden = $h; } -} \ No newline at end of file +} 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 46125e284..0937b48b0 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 @@ -21,10 +21,7 @@ class Ticket_User{ */ public static function createTicketUser( $extern_id, $permission) { $dbl = new DBLayer("lib"); - $query = "INSERT INTO ticket_user (Permission, ExternId) VALUES (:perm, :ext_id)"; - $values = Array('perm' => $permission, 'ext_id' => $extern_id); - $dbl->execute($query, $values); - + $dbl->insert("ticket_user",array('Permission' => $permission, 'ExternId' => $extern_id)); } @@ -73,7 +70,7 @@ class Ticket_User{ */ public static function getModsAndAdmins() { $dbl = new DBLayer("lib"); - $statement = $dbl->executeWithoutParams("SELECT * FROM `ticket_user` WHERE `Permission` > 1"); + $statement = $dbl->select("ticket_user", array(null), "`Permission` > 1" ); $rows = $statement->fetchAll(); $result = Array(); foreach($rows as $user){ @@ -93,7 +90,7 @@ class Ticket_User{ public static function constr_ExternId( $id) { $instance = new self(); $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_user WHERE ExternId=:id", array('id' => $id)); + $statement = $dbl->select("ticket_user" ,array('id'=>$id) ,"ExternId=:id"); $row = $statement->fetch(); $instance->tUserId = $row['TUserId']; $instance->permission = $row['Permission']; @@ -196,7 +193,7 @@ class Ticket_User{ */ public function load_With_TUserId( $id) { $dbl = new DBLayer("lib"); - $statement = $dbl->execute("SELECT * FROM ticket_user WHERE TUserId=:id", array('id' => $id)); + $statement = $dbl->select("ticket_user" ,array('id'=>$id), "TUserId=:id" ); $row = $statement->fetch(); $this->tUserId = $row['TUserId']; $this->permission = $row['Permission']; @@ -209,9 +206,7 @@ class Ticket_User{ */ public function update(){ $dbl = new DBLayer("lib"); - $query = "UPDATE ticket_user SET Permission = :perm, ExternId = :ext_id WHERE TUserId=:id"; - $values = Array('id' => $this->tUserId, 'perm' => $this->permission, 'ext_id' => $this->externId); - $statement = $dbl->execute($query, $values); + $dbl->update("ticket_user" ,array('Permission' => $this->permission, 'ExternId' => $this->externId) ,"TUserId=$this->tUserId"); } ////////////////////////////////////////////Getters//////////////////////////////////////////////////// @@ -266,4 +261,4 @@ class Ticket_User{ } -} \ No newline at end of file +} 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 f83f46576..e9463b0b0 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 @@ -291,9 +291,10 @@ class Users{ //make connection with and put into shard db $values['user_id']= $user_id; $dbs = new DBLayer("shard"); - $dbs->execute("INSERT INTO user (Login, Password, Email) VALUES (:name, :pass, :mail)",$values); + $dbs->insert("user", $values); $dbr = new DBLayer("ring"); - $dbr->execute("INSERT INTO ring_users (user_id, user_name, user_type) VALUES (:user_id, :name, 'ut_pioneer')",$values); + $values['user_type'] = 'ut_pioneer'; + $dbr->insert("ring_users", $values); ticket_user::createTicketUser( $user_id, 1); return "ok"; } @@ -301,7 +302,7 @@ class Users{ //oh noooz, the shard is offline! Put in query queue at ams_lib db! try { $dbl = new DBLayer("lib"); - $dbl->execute("INSERT INTO ams_querycache (type, query, db) VALUES (:type, :query, :db)",array("type" => "createUser", + $dbl->insert("ams_querycache", array("type" => "createUser", "query" => json_encode(array($values["name"],$values["pass"],$values["mail"])), "db" => "shard")); ticket_user::createTicketUser( $user_id , 1 ); return "shardoffline"; @@ -323,21 +324,20 @@ class Users{ try { $values = array('username' => $pvalues[0]); $dbs = new DBLayer("shard"); - $sth = $dbs->execute("SELECT UId FROM user WHERE Login= :username;", $values); + $sth = $dbs->selectWithParameter("UId", "user", $values, "Login= :username"); $result = $sth->fetchAll(); foreach ($result as $UId) { - $ins_values = array('id' => $UId['UId']); - $dbs->execute("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES (:id, 'r2', 'OPEN');", $ins_values); - $dbs->execute("INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES (:id , 'ryzom_open', 'OPEN');", $ins_values); + $ins_values = array('UId' => $UId['UId'], 'clientApplication' => 'r2', 'AccessPrivilege' => 'OPEN'); + $dbs->insert("permission", $ins_values); + $ins_values['clientApplication'] = 'ryzom_open'; + $dbs->insert("permission", $ins_values); } } catch (PDOException $e) { //oh noooz, the shard is offline! Put it in query queue at ams_lib db! $dbl = new DBLayer("lib"); - $dbl->execute("INSERT INTO ams_querycache (type, query, db) VALUES (:type, :query, :db)",array("type" => "createPermissions", - "query" => json_encode(array($pvalues[0])), "db" => "shard")); - - + $dbl->insert("ams_querycache", array("type" => "createPermissions", + "query" => json_encode(array($pvalues[0])), "db" => "shard")); } return true; } @@ -421,19 +421,19 @@ class Users{ */ protected static function setAmsPassword($user, $pass){ - $values = Array('user' => $user, 'pass' => $pass); + $values = Array('Password' => $pass); try { //make connection with and put into shard db $dbs = new DBLayer("shard"); - $dbs->execute("UPDATE user SET Password = :pass WHERE Login = :user ",$values); + $dbs->update("user", $values, "Login = $user"); return "ok"; } catch (PDOException $e) { //oh noooz, the shard is offline! Put in query queue at ams_lib db! try { $dbl = new DBLayer("lib"); - $dbl->execute("INSERT INTO ams_querycache (type, query, db) VALUES (:type, :query, :db)",array("type" => "change_pass", + $dbl->insert("ams_querycache", array("type" => "change_pass", "query" => json_encode(array($values["user"],$values["pass"])), "db" => "shard")); return "shardoffline"; }catch (PDOException $e) { @@ -451,19 +451,19 @@ class Users{ */ protected static function setAmsEmail($user, $mail){ - $values = Array('user' => $user, 'mail' => $mail); + $values = Array('Email' => $mail); try { //make connection with and put into shard db $dbs = new DBLayer("shard"); - $dbs->execute("UPDATE user SET Email = :mail WHERE Login = :user ",$values); + $dbs->update("user", $values, "Login = $user"); return "ok"; } catch (PDOException $e) { //oh noooz, the shard is offline! Put in query queue at ams_lib db! try { $dbl = new DBLayer("lib"); - $dbl->execute("INSERT INTO ams_querycache (type, query, db) VALUES (:type, :query, :db)",array("type" => "change_mail", + $dbl->insert("ams_querycache", array("type" => "change_mail", "query" => json_encode(array($values["user"],$values["mail"])), "db" => "shard")); return "shardoffline"; }catch (PDOException $e) { @@ -474,4 +474,4 @@ class Users{ } - \ No newline at end of file + 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 d8e59d1f9..78916e606 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 @@ -53,7 +53,7 @@ class WebUsers extends Users{ */ protected function checkUserNameExists($username){ $dbw = new DBLayer("web"); - return $dbw->execute("SELECT * FROM ams_user WHERE Login = :name",array('name' => $username))->rowCount(); + return $dbw->select("ams_user", array('name' => $username), "Login = :name")->rowCount(); } @@ -65,7 +65,7 @@ class WebUsers extends Users{ */ protected function checkEmailExists($email){ $dbw = new DBLayer("web"); - return $dbw->execute("SELECT * FROM ams_user WHERE Email = :email",array('email' => $email))->rowCount(); + return $dbw->select("ams_user" ,array('email' => $email),"Email = :email")->rowCount(); } @@ -78,7 +78,7 @@ class WebUsers extends Users{ public static function checkLoginMatch($username,$password){ $dbw = new DBLayer("web"); - $statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:user", array('user' => $username)); + $statement = $dbw->select("ams_user", array('value' => $value),"Login=:value OR Email=:value"); $row = $statement->fetch(); $salt = substr($row['Password'],0,2); $hashed_input_pass = crypt($password, $salt); @@ -97,7 +97,7 @@ class WebUsers extends Users{ */ public static function getId($username){ $dbw = new DBLayer("web"); - $statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:username", array('username' => $username)); + $statement = $dbw->select("ams_user", array('username' => $username), "Login=:username"); $row = $statement->fetch(); return $row['UId']; } @@ -110,7 +110,7 @@ class WebUsers extends Users{ */ public static function getIdFromEmail($email){ $dbw = new DBLayer("web"); - $statement = $dbw->execute("SELECT * FROM ams_user WHERE Email=:email", array('email' => $email)); + $statement = $dbw->select("ams_user", array('email' => $email), "Email=:email"); $row = $statement->fetch(); if(!empty($row)){ return $row['UId']; @@ -134,7 +134,7 @@ class WebUsers extends Users{ 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)); + $statement = $dbw->select("ams_user", array('id' => $this->uId), "UId=:id"); $row = $statement->fetch(); $this->set($row); } @@ -148,7 +148,7 @@ class WebUsers extends Users{ 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)); + $statement = $dbw->select("ams_user", array('id' => $this->uId), "UId=:id"); $row = $statement->fetch(); $this->set($row); } @@ -160,7 +160,7 @@ class WebUsers extends Users{ */ public function getHashedPass(){ $dbw = new DBLayer("web"); - $statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId)); + $statement = $dbw->select("ams_user", array('id' => $this->uId), "UId=:id"); $row = $statement->fetch(); return $row['Password']; } @@ -174,7 +174,7 @@ class WebUsers extends Users{ $dbw = new DBLayer("web"); if(! (isset($this->firstname) && isset($this->lastname) && isset($this->gender) && isset($this->country) && isset($this->receiveMail) ) || $this->firstname == "" || $this->lastname == "" || $this->gender == "" || $this->country == "" || $this->receiveMail == ""){ - $statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId)); + $statement = $dbw->select("ams_user", array('id' => $this->uId), "UId=:id"); $row = $statement->fetch(); $this->set($row); } @@ -189,7 +189,7 @@ class WebUsers extends Users{ public function getReceiveMail(){ $dbw = new DBLayer("web"); if(! isset($this->receiveMail) || $this->receiveMail == ""){ - $statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId)); + $statement = $dbw->select("ams_user", array('id' => $this->uId), "UId=:id"); $row = $statement->fetch(); $this->set($row); } @@ -203,7 +203,7 @@ class WebUsers extends Users{ public function getLanguage(){ $dbw = new DBLayer("web"); if(! isset($this->language) || $this->language == ""){ - $statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId)); + $statement = $dbw->select("ams_user", array('id' => $this->uId), "UId=:id"); $row = $statement->fetch(); $this->set($row); } @@ -234,11 +234,11 @@ class WebUsers extends Users{ $hashpass = crypt($pass, WebUsers::generateSALT()); $reply = WebUsers::setAmsPassword($user, $hashpass); - $values = Array('user' => $user, 'pass' => $hashpass); + $values = Array('pass' => $hashpass); try { //make connection with and put into shard db $dbw = new DBLayer("web"); - $dbw->execute("UPDATE ams_user SET Password = :pass WHERE Login = :user ",$values); + $dbw->update("ams_user", $values,"Login = $user"); } catch (PDOException $e) { //ERROR: the web DB is offline @@ -256,11 +256,11 @@ class WebUsers extends Users{ */ public static function setEmail($user, $mail){ $reply = WebUsers::setAmsEmail($user, $mail); - $values = Array('user' => $user, 'mail' => $mail); + $values = Array('Email' => $mail); try { //make connection with and put into shard db $dbw = new DBLayer("web"); - $dbw->execute("UPDATE ams_user SET Email = :mail WHERE Login = :user ",$values); + $dbw->update("ams_user", $values, "Login = $user"); } catch (PDOException $e) { //ERROR: the web DB is offline @@ -276,11 +276,11 @@ class WebUsers extends Users{ * @param $receivemail the receivemail setting . */ public static function setReceiveMail($user, $receivemail){ - $values = Array('user' => $user, 'receivemail' => $receivemail); + $values = Array('Receivemail' => $receivemail); try { //make connection with and put into shard db $dbw = new DBLayer("web"); - $dbw->execute("UPDATE ams_user SET ReceiveMail = :receivemail WHERE UId = :user ",$values); + $dbw->update("ams_user", $values, "UId = $user" ); } catch (PDOException $e) { //ERROR: the web DB is offline @@ -295,11 +295,11 @@ class WebUsers extends Users{ * @param $language the new language value. */ public static function setLanguage($user, $language){ - $values = Array('user' => $user, 'language' => $language); + $values = Array('Language' => $language); try { //make connection with and put into shard db $dbw = new DBLayer("web"); - $dbw->execute("UPDATE ams_user SET Language = :language WHERE UId = :user ",$values); + $dbw->update("ams_user", $values, "UId = $user"); } catch (PDOException $e) { //ERROR: the web DB is offline @@ -344,15 +344,15 @@ class WebUsers extends Users{ $lang = $DEFAULT_LANGUAGE; } - $values = Array('name' => $name, 'pass' => $pass, 'mail' => $mail, 'lang' => $lang); + $values = Array('Login' => $name, 'Password' => $pass, 'Email' => $mail, 'Language' => $lang); try { $dbw = new DBLayer("web"); - return $dbw->executeReturnId("INSERT INTO ams_user (Login, Password, Email, Language) VALUES (:name, :pass, :mail, :lang)",$values); + return $dbw->executeReturnId("ams_user", $values); } catch (PDOException $e) { //ERROR: the web DB is offline } } -} \ No newline at end of file +} 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 fa08ef1a5..a40e22450 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 @@ -66,15 +66,14 @@ function write_user($newUser){ $hashpass = crypt($newUser["pass"], WebUsers::generateSALT()); $params = array( - 'name' => $newUser["name"], - 'pass' => $hashpass, - 'mail' => $newUser["mail"] + 'Login' => $newUser["name"], + 'Password' => $hashpass, + 'Email' => $newUser["mail"] ); - try{ //make new webuser - $user_id = WebUsers::createWebuser($params['name'], $params['pass'], $params['mail']); - + $user_id = WebUsers::createWebuser($params['Login'], $params['Password'], $params['Email']); + //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); From c4ff97cefd48b36fe3d655346e0ee4353885e0cc Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Mon, 2 Jun 2014 01:05:37 +0530 Subject: [PATCH 05/36] template for plugins in AMS --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ams_lib/autoload/plugincache.php | 262 ++++++++++++++++++ .../ryzom_ams/ams_lib/translations/en.ini | 10 + .../server/ryzom_ams/www/html/inc/plugins.php | 45 +++ .../ryzom_ams/www/html/installer/libsetup.php | 15 + .../ryzom_ams/www/html/templates/plugins.tpl | 89 ++++++ 5 files changed, 421 insertions(+) create mode 100644 code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/inc/plugins.php create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php new file mode 100644 index 000000000..df3af960c --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php @@ -0,0 +1,262 @@ + +setId($values['PluginId']); + + $this->setPluginName($values['PluginName']); + + $this->setPluginVersion($values['PluginVersion']); + + $this->setPluginPermission($values['PluginPermission']); + + $this->setIsActive($values['IsActive']); + + } + + + + + + /** + + * loads the object's attributes. + + */ + + public function load_With_SID( ) { + + $dbl = new DBLayer("lib"); + + $statement = $dbl->executeWithoutParams("SELECT * FROM plugins"); + + $row = $statement->fetch(); + + $this->set($row); + + } + + + + + + /** + + * updates the entry. + + */ + + public function update(){ + + $dbl = new DBLayer("lib"); + + $query = "UPDATE plugins SET PluginPermission= :t, PluginVersion = :q, IsActive = :d WHERE PluginName=:p_n"; + + $values = Array('p_n' => $this->getPluginName(), 't' => $this->getPluginPermission(), 'q' => $this->getPluginVersion(), 'd' => $this->getIsActive()); + + $statement = $dbl->execute($query, $values); + + } + + + + + + public function getId(){ + + return $this->Id; + + } + + + + /** + + * get plugin permission attribute of the object. + + */ + + public function getPluginPermission(){ + + return $this->plugin_permission; + + } + + + + /** + + * get plugin version attribute of the object. + + */ + + public function getPluginVersion(){ + + return $this->plugin_version; + + } + + + + /** + + * get plugin is active attribute of the object. + + */ + + public function getIsActive(){ + + return $this->plugin_isactive; + + } + + + + /** + + * get plugin name attribute of the object. + + */ + + public function getPluginName(){ + + return $this->plugin_name; + + } + + + + + + + + /** + + * set plugin id attribute of the object. + + * @param $s integer id + + */ + + public function setId($s){ + + $this->Id = $s; + + } + + + + /** + + * set plugin permission attribute of the object. + + * @param $t type of the query, set permission + + */ + + public function setPluginPermission($t){ + + + + $this->plugin_permission = $t; + + } + + + + /** + + * set plugin version attribute of the object. + + * @param $q string to set plugin version + + */ + + public function setPluginVersion($q){ + + $this->plugin_version= $q; + + } + + + + /** + + * set plugin is active attribute of the object. + + * @param $d tinyint to set plugin is active or not . + + */ + + public function setIsActive($d){ + + $this->plugin_isactive= $d; + + } + + + + /** + + * set plugin name attribute of the object. + + * @param $p_n string to set plugin name. + + */ + + public function setPluginName($p_n){ + + $this->plugin_name= $p_n; + + } + + + +} + + diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini index 586d49241..0d1b9cfb6 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini @@ -53,6 +53,16 @@ name = "Name" email = "Email" action = "Action" +[plugins] +plugin_title = "Plugin List" +plugin_info = "Here you can see the entire list of plugins . You can easily remove plugins ,activate them and add permissions" +plugins= "Plugins" +plugin_id = "ID" +plugin_name = "Name" +plugin_version= "Version" +plugin_permission= "Owner/Access Permission" +plugin_is_active= "On/Off" + [show_ticket] t_title = "Ticket" title = "Title" diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/plugins.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/plugins.php new file mode 100644 index 000000000..61bdb0278 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/plugins.php @@ -0,0 +1,45 @@ +init(); + print_r(plugin::$plugins);**/ + + $pagination = new Pagination("SELECT * FROM plugins","lib",5,"Plugincache"); + $pageResult['plug']= Gui_Elements::make_table($pagination->getElements() , Array ("getId","getPluginName","getPluginVersion","getPluginPermission","getIsActive"), Array("id","plugin_name","plugin_version","plugin_permission","plugin_isactive")); + $pageResult['links'] = $pagination->getLinks(5); + $pageResult['lastPage'] = $pagination->getLast(); + $pageResult['currentPage'] = $pagination->getCurrent(); + + global $INGAME_WEBPATH; + $pageResult['ingame_webpath'] = $INGAME_WEBPATH; + + //check if shard is online + try{ + $dbs = new DBLayer("shard"); + $pageResult['shard'] = "online"; + }catch(PDOException $e){ + $pageResult['shard'] = "offline"; + } + return( $pageResult); + }else{ + //ERROR: No access! + $_SESSION['error_code'] = "403"; + header("Location: index.php?page=error"); + exit; + } + +} + + diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php b/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php index 932d6d2db..5aea5c200 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php @@ -154,6 +154,21 @@ ENGINE = InnoDB; + -- ----------------------------------------------------- + -- Table `" . $cfg['db']['lib']['name'] ."`.`plugins` + -- ----------------------------------------------------- + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`plugins` ; + + CREATE TABLE IF NOT EXISTS `" . $cfg['db']['lib']['name'] ."`.`plugins` ( + `PluginId` INT(10) NOT NULL AUTO_INCREMENT, + `PluginName` VARCHAR(11) NOT NULL, + `PluginPermission` VARCHAR(5) NOT NULL, + `PluginVersion` INT(11) NOT NULL, + `IsActive` TINYINT(1) NOT NULL, + PRIMARY KEY (`PluginId`) ) + ENGINE = InnoDB; + + -- ----------------------------------------------------- -- Table `" . $cfg['db']['lib']['name'] ."`.`ticket` -- ----------------------------------------------------- diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl new file mode 100644 index 000000000..4d4703875 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl @@ -0,0 +1,89 @@ + +{block name=content} +
+
+
+

{$plugin_title}

+
+ + + +
+
+
+

{$plugin_info}

+ + + + + + + + + + + + + {foreach from=$plug item=element} + + + + + + + + {/foreach} + + +
{$plugin_id}{$plugin_permission}{$plugin_name}{$plugin_version}{$plugin_is_active}
{$element.id}{$element.plugin_permission}{$element.plugin_name}{$element.plugin_version}{$element.plugin_isactive}
+
+
    +
  • «
  • + {foreach from=$links item=link} +
  • {$link}
  • + {/foreach} +
  • »
  • +
+
+
+ +
+
+
+

Actions

+
+ + +
+
+
+
+
+ + +
+
+
+
+ +
+{/block} \ No newline at end of file From bf47b07fe000a3e1ce1a58b432f3db3e7a7f69ff Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Sun, 1 Jun 2014 19:52:54 +0000 Subject: [PATCH 06/36] changes indentation and extra spaces --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ams_lib/autoload/plugincache.php | 157 +----------------- 1 file changed, 9 insertions(+), 148 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php index df3af960c..2d9e5de06 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php @@ -1,262 +1,123 @@ - -setId($values['PluginId']); - $this->setPluginName($values['PluginName']); - $this->setPluginVersion($values['PluginVersion']); - $this->setPluginPermission($values['PluginPermission']); - - $this->setIsActive($values['IsActive']); - + $this->setIsActive($values['IsActive']); } - - - - /** - * loads the object's attributes. - */ - public function load_With_SID( ) { - $dbl = new DBLayer("lib"); - $statement = $dbl->executeWithoutParams("SELECT * FROM plugins"); - $row = $statement->fetch(); - $this->set($row); - } - - - - /** - * updates the entry. - */ - public function update(){ - $dbl = new DBLayer("lib"); - - $query = "UPDATE plugins SET PluginPermission= :t, PluginVersion = :q, IsActive = :d WHERE PluginName=:p_n"; - - $values = Array('p_n' => $this->getPluginName(), 't' => $this->getPluginPermission(), 'q' => $this->getPluginVersion(), 'd' => $this->getIsActive()); - - $statement = $dbl->execute($query, $values); - + $values = Array('t' => $this->getPluginPermission(), 'q' => $this->getPluginVersion(), 'd' => $this->getIsActive()); + $dbl->update("plugins", $values, "PluginName= $this->getPluginName()"); } - - - - public function getId(){ - return $this->Id; - } - - /** - * get plugin permission attribute of the object. - */ - public function getPluginPermission(){ - - return $this->plugin_permission; - + return $this->plugin_permission; } - - /** - * get plugin version attribute of the object. - */ - public function getPluginVersion(){ - return $this->plugin_version; - } - - /** - * get plugin is active attribute of the object. - */ - public function getIsActive(){ - return $this->plugin_isactive; - } - - /** - * get plugin name attribute of the object. - */ - public function getPluginName(){ - return $this->plugin_name; - } - - - - - - /** - * set plugin id attribute of the object. - * @param $s integer id - */ public function setId($s){ - $this->Id = $s; - } - - /** - * set plugin permission attribute of the object. - * @param $t type of the query, set permission - */ - public function setPluginPermission($t){ - - - $this->plugin_permission = $t; - } - - /** - * set plugin version attribute of the object. - * @param $q string to set plugin version - */ - public function setPluginVersion($q){ - $this->plugin_version= $q; - } - - /** - * set plugin is active attribute of the object. - * @param $d tinyint to set plugin is active or not . - */ - public function setIsActive($d){ - $this->plugin_isactive= $d; - } - - - + /** - * set plugin name attribute of the object. - * @param $p_n string to set plugin name. - */ - public function setPluginName($p_n){ - $this->plugin_name= $p_n; - } - - - -} - - +} \ No newline at end of file From 2f023e0bdc24d6f9082d9ae061a988037130293c Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Tue, 10 Jun 2014 12:11:34 +0530 Subject: [PATCH 07/36] Database CREATE TABLE IF NOT EXISTS . ( --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ryzom_ams/www/html/installer/libsetup.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php b/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php index 5aea5c200..43b262b74 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php @@ -160,12 +160,16 @@ DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`plugins` ; CREATE TABLE IF NOT EXISTS `" . $cfg['db']['lib']['name'] ."`.`plugins` ( - `PluginId` INT(10) NOT NULL AUTO_INCREMENT, - `PluginName` VARCHAR(11) NOT NULL, - `PluginPermission` VARCHAR(5) NOT NULL, - `PluginVersion` INT(11) NOT NULL, - `IsActive` TINYINT(1) NOT NULL, - PRIMARY KEY (`PluginId`) ) + `Id` INT(10) NOT NULL AUTO_INCREMENT, + `FileName VARCHAR(255) NOT NULL, + `Name` VARCHAR(11) NOT NULL, + `Type` VARCHAR(12) NOT NULL, + `Owner` VARCHAR(25) NOT NULL, + `Permission` VARCHAR(5) NOT NULL, + `Status` INT(11) NOT NULL DEFAULT 0, + `Weight` INT(11) NOT NULL DEFAULT 0, + `Info` BLOB NULL DEFAULT NULL, + PRIMARY KEY (`Id`) ) ENGINE = InnoDB; From c558b92bf57500733c8a46e4a95878b50a9e78d5 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Wed, 11 Jun 2014 11:52:57 +0530 Subject: [PATCH 08/36] plugin interaction files --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ams_lib/autoload/plugincache.php | 356 ++++++------------ .../server/ryzom_ams/www/html/inc/plugins.php | 62 ++- 2 files changed, 150 insertions(+), 268 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php index df3af960c..1b0dc873d 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php @@ -1,262 +1,150 @@ - setId($values['PluginId']); - - $this->setPluginName($values['PluginName']); - - $this->setPluginVersion($values['PluginVersion']); - - $this->setPluginPermission($values['PluginPermission']); - - $this->setIsActive($values['IsActive']); - - } - - - + * A constructor. + * Empty constructor + */ + + public function __construct() { + } + + public function set( $values ) { + $this -> setId( $values['Id'] ); + $this -> setPluginName( $values['Name'] ); + $this -> setPluginType( $values['Type'] ); + $this -> setPluginPermission( $values['Permission'] ); + $this -> setPluginStatus( $values['Status'] ); + $this -> setPluginInfo( $values['Info'] ); + } - /** - - * loads the object's attributes. - - */ - - public function load_With_SID( ) { - - $dbl = new DBLayer("lib"); - - $statement = $dbl->executeWithoutParams("SELECT * FROM plugins"); - - $row = $statement->fetch(); - - $this->set($row); - - } - + * loads the object's attributes. + */ + public function load_With_SID() { + $dbl = new DBLayer( "lib" ); + $statement = $dbl -> executeWithoutParams( "SELECT * FROM plugins" ); + $row = $statement -> fetch(); + $this -> set( $row ); + } - + /** + * get plugin id attribute of the object. + * + * @return integer id + */ + public function getId() { + return $this -> Id; + } - /** - - * updates the entry. - - */ - - public function update(){ - - $dbl = new DBLayer("lib"); - - $query = "UPDATE plugins SET PluginPermission= :t, PluginVersion = :q, IsActive = :d WHERE PluginName=:p_n"; - - $values = Array('p_n' => $this->getPluginName(), 't' => $this->getPluginPermission(), 'q' => $this->getPluginVersion(), 'd' => $this->getIsActive()); - - $statement = $dbl->execute($query, $values); - - } - + * get plugin permission attribute of the object. + */ + public function getPluginPermission() { + return $this -> plugin_permission; + } - + /** + * get plugin Type attribute of the object. + */ + public function getPluginType() { + return $this -> plugin_version; + } - - public function getId(){ - - return $this->Id; - - } - - - /** - - * get plugin permission attribute of the object. - - */ - - public function getPluginPermission(){ - - return $this->plugin_permission; - - } - + * get plugin status attribute of the object. + */ + public function getPluginStatus() { + return $this -> plugin_status; + } - /** - - * get plugin version attribute of the object. - - */ - - public function getPluginVersion(){ - - return $this->plugin_version; - - } - + * get plugin name attribute of the object. + */ + public function getPluginName() { + return $this -> plugin_name; + } - /** - - * get plugin is active attribute of the object. - - */ - - public function getIsActive(){ - - return $this->plugin_isactive; - - } - - - + * get plugin info array attribute of the object. + */ + public function getPluginInfo() { + return $this -> plugin_info; + } + /** - - * get plugin name attribute of the object. - - */ - - public function getPluginName(){ - - return $this->plugin_name; - - } - - - + * set plugin id attribute of the object. + * + * @param $s integer id + */ + public function setId( $s ) { + $this -> Id = $s; + } - + /** + * set plugin permission attribute of the object. + * + * @param $t type of the query, set permission + */ + public function setPluginPermission( $t ) { + $this -> plugin_permission = $t; + } - /** - - * set plugin id attribute of the object. - - * @param $s integer id - - */ - - public function setId($s){ - - $this->Id = $s; - - } - - - + * set plugin version attribute of the object. + * + * @param $q string to set plugin version + */ + public function setPluginType( $q ) { + $this -> plugin_version = $q; + } + /** - - * set plugin permission attribute of the object. - - * @param $t type of the query, set permission - - */ - - public function setPluginPermission($t){ - - - - $this->plugin_permission = $t; - - } - + * set plugin status attribute of the object. + * + * @param $d status code type int + */ + public function setPluginStatus( $d ) { + $this -> plugin_status = $d; + } - /** - - * set plugin version attribute of the object. - - * @param $q string to set plugin version - - */ - - public function setPluginVersion($q){ - - $this->plugin_version= $q; - - } - + * get plugin name attribute of the object. + */ + public function getPluginName() { + return $this -> plugin_name; + } - /** - - * set plugin is active attribute of the object. - - * @param $d tinyint to set plugin is active or not . - - */ - - public function setIsActive($d){ - - $this->plugin_isactive= $d; - - } - - - + * set plugin name attribute of the object. + * + * @param $p_n string to set plugin name. + */ + public function setPluginName( $p_n ) { + $this -> plugin_name = $p_n; + } + /** - - * set plugin name attribute of the object. - - * @param $p_n string to set plugin name. - - */ - - public function setPluginName($p_n){ - - $this->plugin_name= $p_n; - - } - + * set plugin info attribute array of the object. + * + * @param $p_n array + */ + public function setPluginInfo( $p_n ) { + $this -> plugin_info = $p_n; + } - -} - - + } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/plugins.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/plugins.php index 61bdb0278..1118b556f 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/plugins.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/plugins.php @@ -1,45 +1,39 @@ init(); - print_r(plugin::$plugins);**/ - - $pagination = new Pagination("SELECT * FROM plugins","lib",5,"Plugincache"); - $pageResult['plug']= Gui_Elements::make_table($pagination->getElements() , Array ("getId","getPluginName","getPluginVersion","getPluginPermission","getIsActive"), Array("id","plugin_name","plugin_version","plugin_permission","plugin_isactive")); - $pageResult['links'] = $pagination->getLinks(5); - $pageResult['lastPage'] = $pagination->getLast(); - $pageResult['currentPage'] = $pagination->getCurrent(); + { + if ( Ticket_User :: isMod( unserialize( $_SESSION['ticket_user'] ) ) ) { + + $pagination = new Pagination( "SELECT * FROM plugins", "lib", 5, "Plugincache" ); + $pageResult['plug'] = Gui_Elements :: make_table( $pagination -> getElements(), Array( "getId", "getPluginName", "getPluginType", "getPluginPermission", "getPluginStatus", "getPluginInfo" ), Array( "id", "plugin_name", "plugin_type", "plugin_permission", "plugin_status", "plugin_info" ) ); + $pageResult['links'] = $pagination -> getLinks( 5 ); + $pageResult['lastPage'] = $pagination -> getLast(); + $pageResult['currentPage'] = $pagination -> getCurrent(); - global $INGAME_WEBPATH; - $pageResult['ingame_webpath'] = $INGAME_WEBPATH; + global $INGAME_WEBPATH; + $pageResult['ingame_webpath'] = $INGAME_WEBPATH; - //check if shard is online - try{ - $dbs = new DBLayer("shard"); - $pageResult['shard'] = "online"; - }catch(PDOException $e){ + // check if shard is online + try { + $dbs = new DBLayer( "shard" ); + $pageResult['shard'] = "online"; + } + catch( PDOException $e ) { $pageResult['shard'] = "offline"; - } - return( $pageResult); - }else{ - //ERROR: No access! + } + return( $pageResult ); + } else { + // ERROR: No access! $_SESSION['error_code'] = "403"; - header("Location: index.php?page=error"); - exit; + header( "Location: index.php?page=error" ); + exit; + } + } - -} - - From a15462c863fb2c761cbf521e46d1c21ac6020f53 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Wed, 11 Jun 2014 15:57:07 +0530 Subject: [PATCH 09/36] plugin installer functionality --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ams_lib/autoload/plugincache.php | 13 +- .../ryzom_ams/ams_lib/translations/en.ini | 21 +- .../www/html/func/install_plugin.php | 94 ++++++++ .../tools/server/ryzom_ams/www/html/index.php | 208 +++++++++--------- .../ryzom_ams/www/html/installer/libsetup.php | 6 +- .../www/html/templates/install_plugin.tpl | 34 +++ .../ryzom_ams/www/html/templates/plugins.tpl | 67 ++---- 7 files changed, 274 insertions(+), 169 deletions(-) create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/templates/install_plugin.tpl diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php index 1b0dc873d..bba6e3fb1 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php @@ -2,7 +2,7 @@ /** * API for loading and interacting with plugins - * contains getters and setters + * contains getters and setters * * @author shubham meena mentored by Matthew Lagoe */ @@ -29,7 +29,7 @@ class Plugincache { $this -> setPluginType( $values['Type'] ); $this -> setPluginPermission( $values['Permission'] ); $this -> setPluginStatus( $values['Status'] ); - $this -> setPluginInfo( $values['Info'] ); + $this -> setPluginInfo( json_decode( $values['Info'] ) ); } /** @@ -122,13 +122,6 @@ class Plugincache { $this -> plugin_status = $d; } - /** - * get plugin name attribute of the object. - */ - public function getPluginName() { - return $this -> plugin_name; - } - /** * set plugin name attribute of the object. * @@ -147,4 +140,4 @@ class Plugincache { $this -> plugin_info = $p_n; } - } + } diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini index 0d1b9cfb6..0164abbee 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini @@ -56,12 +56,21 @@ action = "Action" [plugins] plugin_title = "Plugin List" plugin_info = "Here you can see the entire list of plugins . You can easily remove plugins ,activate them and add permissions" -plugins= "Plugins" -plugin_id = "ID" +plugins = "Plugins" plugin_name = "Name" -plugin_version= "Version" -plugin_permission= "Owner/Access Permission" -plugin_is_active= "On/Off" +plugin_version = "Version" +plugin_description = "Description" +plugin_type = "Type" +plugin_permission = "Access Permission" +plugin_status = "Status" +ip_success = "Plugin added succesfully." + +[install_plugin] +ip_title = "Install a new Plugin" +ip_message = "For example: name.zip from your local computer" +ip_support = "Upload the plugin archieve to install.
The following file extension is supported: zip." +ip_error = "Please select the format with zip extension" +ip_info_nfound = "Info file not found in the Plugin.Please recheck" [show_ticket] t_title = "Ticket" @@ -252,4 +261,4 @@ email_body_forgot_password_header = "A request to reset your account's password email_body_forgot_password_footer = " ---------- If you didn't make this request, please ignore this message." -;=========================================================================== \ No newline at end of file +;=========================================================================== diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php new file mode 100644 index 000000000..64cb66a30 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php @@ -0,0 +1,94 @@ + 0 ) && ( $_FILES["file"]["type"] == 'application/zip' ) ) + { + $fileName = $_FILES["file"]["name"]; //the files name takes from the HTML form + $fileTmpLoc = $_FILES["file"]["tmp_name"]; //file in the PHP tmp folder + $dir = trim( $_FILES["file"]["name"], ".zip" ); + $target_path = "../../ams_lib/plugins/$dir"; //path in which the zip extraction is to be done + $destination = "../../ams_lib/plugins/"; + + if ( move_uploaded_file( $fileTmpLoc, $destination . $fileName ) ) { + // zip object to handle zip archieves + $zip = new ZipArchive(); + $x = $zip -> open( $destination . $fileName ); + if ( $x === true ) { + $zip -> extractTo( $destination ); // change this to the correct site path + $zip -> close(); + + // removing the uploaded zip file + unlink( $destination . $fileName ); + + // check for the info file + if ( file_exists( $target_path . "/.info" ) ) + { + // read the details of the plugin through the info file + $file_handle = fopen( $target_path . "/.info", "r" ); + $result = array(); + while ( !feof( $file_handle ) ) { + + $line_of_text = fgets( $file_handle ); + $parts = array_map( 'trim', explode( '=', $line_of_text, 2 ) ); + @$result[$parts[0]] = $parts[1]; + + } + + fclose( $file_handle ); + + // sending all info to the database + $install_result = array(); + $install_result['FileName'] = $target_path; + $install_result['Name'] = $result['PluginName']; + $install_result['Type'] = $result['type']; + + if ( Ticket_User :: isMod( unserialize( $_SESSION['ticket_user'] ) ) ) + { + $install_result['Permission'] = 'admin'; + } + else + { + $install_result['Permission'] = 'user'; + } + + $install_result['Info'] = json_encode( $result ); + + // connection with the database + $dbr = new DBLayer( "lib" ); + $dbr -> insert( "plugins", $install_result ); + + header( "Location: index.php?page=plugins&result=1" ); + exit; + + } + else + { + rmdir( $target_path ); + header( "Location: index.php?page=install_plugin&result=2" ); + exit; + + } + + } + } + + header( "Location: index.php?page=plugins" ); + exit; + } + else + { + header( "Location: index.php?page=install_plugin&result=1" ); + exit; + } + } + } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/index.php b/code/ryzom/tools/server/ryzom_ams/www/html/index.php index faf3488c6..f01eab3e4 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/index.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/index.php @@ -1,126 +1,130 @@ getPermission(); -}else{ - //default permission - $return['permission'] = 0; -} -//hide sidebar + topbar in case of login/register -if($page == 'login' || $page == 'register' || $page == 'logout' || $page == 'forgot_password' || $page == 'reset_password'){ - $return['no_visible_elements'] = 'TRUE'; -}else{ - $return['no_visible_elements'] = 'FALSE'; -} +// Set permission +if ( isset( $_SESSION['ticket_user'] ) ) { + $return['permission'] = unserialize( $_SESSION['ticket_user'] ) -> getPermission(); + } else { + // default permission + $return['permission'] = 0; + } + + +// hide sidebar + topbar in case of login/register +if ( $page == 'login' || $page == 'register' || $page == 'logout' || $page == 'forgot_password' || $page == 'reset_password' ) { + $return['no_visible_elements'] = 'TRUE'; + } else { + $return['no_visible_elements'] = 'FALSE'; + } -//handle error page -if($page == 'error'){ - $return['permission'] = 0; +// handle error page +if ( $page == 'error' ) { + $return['permission'] = 0; $return['no_visible_elements'] = 'FALSE'; -} + } -//load the template with the variables in the $return array +// load the template with the variables in the $return array helpers :: loadTemplate( $page , $return ); diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php b/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php index 43b262b74..a590e6d7d 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php @@ -160,15 +160,15 @@ DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`plugins` ; CREATE TABLE IF NOT EXISTS `" . $cfg['db']['lib']['name'] ."`.`plugins` ( - `Id` INT(10) NOT NULL AUTO_INCREMENT, - `FileName VARCHAR(255) NOT NULL, + `Id` INT(10) NOT NULL AUTO_INCREMENT, + `FileName VARCHAR(255) NOT NULL, `Name` VARCHAR(11) NOT NULL, `Type` VARCHAR(12) NOT NULL, `Owner` VARCHAR(25) NOT NULL, `Permission` VARCHAR(5) NOT NULL, `Status` INT(11) NOT NULL DEFAULT 0, `Weight` INT(11) NOT NULL DEFAULT 0, - `Info` BLOB NULL DEFAULT NULL, + `Info` TEXT NULL DEFAULT NULL, PRIMARY KEY (`Id`) ) ENGINE = InnoDB; diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/install_plugin.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/install_plugin.tpl new file mode 100644 index 000000000..52fdb3820 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/install_plugin.tpl @@ -0,0 +1,34 @@ +{block name=content} + +
+
+
+

{$ip_title}

+
+ + + + +
+
+
+
+

{$ip_support}

+
+
+    +
+ {if isset($smarty.get.result) and $smarty.get.result eq "1"}

{$ip_error}

{/if} + {if isset($smarty.get.result) and $smarty.get.result eq "2"}

{$ip_info_nfound}

{/if} +
+
+ {$ip_message} +
+
+
+
+
+ + + +{/block} diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl index 4d4703875..99f382c5c 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl @@ -1,4 +1,3 @@ - {block name=content}
@@ -10,27 +9,35 @@
+ {if isset($smarty.get.result) and $smarty.get.result eq "1"}

{$ip_success}

{/if}

{$plugin_info}

- +
+ + + + +
- - - + + - + + + {foreach from=$plug item=element} - - + - - + + + + {/foreach} @@ -48,42 +55,6 @@ -
-
-

Actions

-
- - -
-
-
-
-
- - -
-
-
-
- -{/block} \ No newline at end of file +{/block} + From ad2ed4dfa4c42d15e614c5fe2c84c7b5edf56ee3 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Fri, 13 Jun 2014 16:40:27 +0530 Subject: [PATCH 10/36] Plugin installation first upload t{block name=content} --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ryzom_ams/ams_lib/translations/en.ini | 13 +- .../www/html/func/install_plugin.php | 150 +++++++++++++----- .../www/html/templates/install_plugin.tpl | 9 +- .../ryzom_ams/www/html/templates/layout.tpl | 44 +++++ .../ryzom_ams/www/html/templates/plugins.tpl | 26 +-- 5 files changed, 189 insertions(+), 53 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini index 0164abbee..4c8b545ec 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini @@ -61,16 +61,23 @@ plugin_name = "Name" plugin_version = "Version" plugin_description = "Description" plugin_type = "Type" -plugin_permission = "Access Permission" +plugin_permission = "Access
Permission" plugin_status = "Status" -ip_success = "Plugin added succesfully." +ip_success = "Plugin added succesfuly." +plugin_actions = "Actions" +dp_success = "Plugin deleted successfuly" +dp_error = "Error in deleting plugin.Please try again later" +ac_success = "Plugin Activated successfuly" +ac_error = "Plugin facing some error in activating. Please try again later" +dc_success = "Plugin de-Activated successfuly" +dc_error = "Plugin facing some error in de-activating. Please try again later" [install_plugin] ip_title = "Install a new Plugin" ip_message = "For example: name.zip from your local computer" ip_support = "Upload the plugin archieve to install.
The following file extension is supported: zip." -ip_error = "Please select the format with zip extension" ip_info_nfound = "Info file not found in the Plugin.Please recheck" +ip_file_nfnd="Please upload a plugin before clicking on install button" [show_ticket] t_title = "Ticket" diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php index 64cb66a30..5376dfd02 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php @@ -11,7 +11,18 @@ function install_plugin() { // if logged in if ( WebUsers :: isLoggedIn() ) { - if ( ( isset( $_FILES["file"] ) ) && ( $_FILES["file"]["size"] > 0 ) && ( $_FILES["file"]["type"] == 'application/zip' ) ) + // path of temporary folder for storing files + $temp_path = "../../ams_lib/temp"; + + // create a temp directory if not exist + // temp folder where we first store all uploaded plugins before install + if ( !file_exists( "$temp_path" ) ) + { + mkdir( $temp_path ); + } + + // checking the server if file is uploaded or not + if ( ( isset( $_FILES["file"] ) ) && ( $_FILES["file"]["size"] > 0 ) ) { $fileName = $_FILES["file"]["name"]; //the files name takes from the HTML form $fileTmpLoc = $_FILES["file"]["tmp_name"]; //file in the PHP tmp folder @@ -19,40 +30,44 @@ function install_plugin() { $target_path = "../../ams_lib/plugins/$dir"; //path in which the zip extraction is to be done $destination = "../../ams_lib/plugins/"; - if ( move_uploaded_file( $fileTmpLoc, $destination . $fileName ) ) { - // zip object to handle zip archieves - $zip = new ZipArchive(); - $x = $zip -> open( $destination . $fileName ); - if ( $x === true ) { - $zip -> extractTo( $destination ); // change this to the correct site path - $zip -> close(); - - // removing the uploaded zip file - unlink( $destination . $fileName ); - - // check for the info file + // checking for the command to install plugin is given or not + if ( !isset( $_POST['install_plugin'] ) ) + { + if ( ( $_FILES["file"]["type"] == 'application/zip' ) ) + { + if ( move_uploaded_file( $fileTmpLoc, $temp_path . "/" . $fileName ) ) { + echo "$fileName upload is complete."; + exit(); + } + else + { + echo "Error in uploading file."; + exit(); + } + } + else + { + echo "Please select a file with .zip extension to upload."; + exit(); + } + } + else + { + + // calling function to unzip archives + if ( zipExtraction( $temp_path . "/" . $fileName , $destination ) ) + { if ( file_exists( $target_path . "/.info" ) ) { - // read the details of the plugin through the info file - $file_handle = fopen( $target_path . "/.info", "r" ); - $result = array(); - while ( !feof( $file_handle ) ) { - - $line_of_text = fgets( $file_handle ); - $parts = array_map( 'trim', explode( '=', $line_of_text, 2 ) ); - @$result[$parts[0]] = $parts[1]; - - } - - fclose( $file_handle ); + $result = array(); + $result = readPluginFile( ".info", $target_path ); // sending all info to the database $install_result = array(); $install_result['FileName'] = $target_path; $install_result['Name'] = $result['PluginName']; - $install_result['Type'] = $result['type']; - - if ( Ticket_User :: isMod( unserialize( $_SESSION['ticket_user'] ) ) ) + // $install_result['Type'] = $result['type']; + if ( Ticket_User :: isMod( unserialize( $_SESSION['ticket_user'] ) ) ) { $install_result['Permission'] = 'admin'; } @@ -67,28 +82,87 @@ function install_plugin() { $dbr = new DBLayer( "lib" ); $dbr -> insert( "plugins", $install_result ); - header( "Location: index.php?page=plugins&result=1" ); + // if everything is successfull redirecting to the plugin template + header( "Location: index.php?page=plugins&result=1" ); exit; - } else { + // file .info not exists rmdir( $target_path ); header( "Location: index.php?page=install_plugin&result=2" ); exit; - } - } + } else + { + // extraction failed + header( "Location: index.php?page=install_plugin&result=0" ); + exit; + } } - - header( "Location: index.php?page=plugins" ); - exit; + } + else + { + echo "Please Browse for a file before clicking the upload button"; + exit(); + } + } + } + +/** + * function to unzip the zipped files + * + * @param $target_path path to the target zipped file + * @param $destination path to the destination + * @return boolean + */ +function zipExtraction( $target_path, $destination ) + { + $zip = new ZipArchive(); + $x = $zip -> open( $target_path ); + if ( $x === true ) { + if ( $zip -> extractTo( $destination ) ) + { + $zip -> close(); + return true; } else { - header( "Location: index.php?page=install_plugin&result=1" ); - exit; + $zip -> close(); + return false; } } - } + } + +/** + * function to read text files and extract + * the information into an array + * + * ----------------------------------------------------------- + * format: + * ----------------------------------------------------------- + * PluginName = Name of the plugin + * Version = version of the plugin + * Type = type of the plugin + * Description = Description of the plugin ,it's functionality + * ----------------------------------------------------------- + * + * reads only files with name .info + * + * @param $fileName file to read + * @param $targetPath path to the folder containing .info file + * @return array containing above information in array(value => key) + */ +function readPluginFile( $fileName, $target_path ) + { + $file_handle = fopen( $target_path . "/" . $fileName, "r" ); + $result = array(); + while ( !feof( $file_handle ) ) { + $line_of_text = fgets( $file_handle ); + $parts = array_map( 'trim', explode( '=', $line_of_text, 2 ) ); + @$result[$parts[0]] = $parts[1]; + } + fclose( $file_handle ); + return $result; + } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/install_plugin.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/install_plugin.tpl index 52fdb3820..27a4cec49 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/install_plugin.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/install_plugin.tpl @@ -15,12 +15,15 @@

{$ip_support}

- +   
- {if isset($smarty.get.result) and $smarty.get.result eq "1"}

{$ip_error}

{/if} +
+
+

+ {if isset($smarty.get.result) and $smarty.get.result eq "0"}

{$ip_file_nfnd}

{/if} {if isset($smarty.get.result) and $smarty.get.result eq "2"}

{$ip_info_nfound}

{/if} -
+
{$ip_message}
diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout.tpl index fa97211d7..e66d952b8 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout.tpl @@ -192,6 +192,50 @@ } + + + diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl index 99f382c5c..cac67147a 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl @@ -10,23 +10,28 @@ {if isset($smarty.get.result) and $smarty.get.result eq "1"}

{$ip_success}

{/if} + {if isset($smarty.get.result) and $smarty.get.result eq "0"}

{$dp_error}

{/if} + {if isset($smarty.get.result) and $smarty.get.result eq "2"}

{$dp_success}

{/if} + {if isset($smarty.get.result) and $smarty.get.result eq "3"}

{$ac_success}

{/if} + {if isset($smarty.get.result) and $smarty.get.result eq "4"}

{$ac_error}

{/if} + {if isset($smarty.get.result) and $smarty.get.result eq "5"}

{$dc_success}

{/if} + {if isset($smarty.get.result) and $smarty.get.result eq "6"}

{$dc_error}

{/if}
{$plugin_id}{$plugin_permission}{$plugin_name}{$plugin_status}{$plugin_name} {$plugin_version}{$plugin_is_active}{$plugin_description}{$plugin_type}{$plugin_permission}
{$element.id}{$element.plugin_permission} {$element.plugin_name}{$element.plugin_version}{$element.plugin_isactive}{$element.plugin_info->Version}{$element.plugin_info->Description}{$element.plugin_type}{$element.plugin_permission}
- + - - + + + @@ -38,6 +43,9 @@ + {/foreach} From 59a6c6b8c3d868443ba2ad8b4acb849244a29ad0 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Fri, 13 Jun 2014 17:21:49 +0530 Subject: [PATCH 11/36] deleting plugin from ams --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ryzom_ams/www/html/func/delete_plugin.php | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/func/delete_plugin.php diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/delete_plugin.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/delete_plugin.php new file mode 100644 index 000000000..53af36157 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/delete_plugin.php @@ -0,0 +1,68 @@ + selectWithParameter( "FileName", "plugins", array( 'id' => $id ), "Id=:id" ); + $name = $sth -> fetch(); + + if ( is_dir( "$name[FileName]" ) ) + { + // removing plugin directory from the code base + if ( rrmdir( "$name[FileName]" ) ) + { + $db -> delete( 'plugins', array( 'id' => $id ), "Id=:id" ); + + header( "Location: index.php?page=plugins&result=2" ); + exit; + + } + else + { + header( "Location: index.php?page=plugins&result=0" ); + exit; + } + } + } + else + { + header( "Location: index.php?page=plugins&result=0" ); + exit; + } + } + } + +/** + * function to remove a non empty directory + * + * @param $dir directory address + * @return boolean + */ +function rrmdir( $dir ) { + if ( is_dir( $dir ) ) { + $objects = scandir( $dir ); + foreach ( $objects as $object ) { + if ( $object != "." && $object != ".." ) { + if ( filetype( $dir . "/" . $object ) == "dir" ) rmdir( $dir . "/" . $object ); + else unlink( $dir . "/" . $object ); + } + } + reset( $objects ); + return rmdir( $dir ); + } + } + From 2f81e3c1b94d0068aa65cab075bd3244f5be280b Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Sun, 15 Jun 2014 09:42:09 +0530 Subject: [PATCH 12/36] activating a plugin in ams --HG-- branch : Gsoc14-ryzomAppImprovements --- .../www/html/func/activate_plugin.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/func/activate_plugin.php diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/activate_plugin.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/activate_plugin.php new file mode 100644 index 000000000..930ed15f1 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/activate_plugin.php @@ -0,0 +1,35 @@ + update( "plugins", array( 'Status' => '1' ), "Id = $id" ); + if ( $result ) + { + header( "Location: index.php?page=plugins&result=3" ); + exit; + } + else + { + header( "Location: index.php?page=plugins&result=4" ); + exit; + } + } + else + { + header( "Location: index.php?page=plugins&result=4" ); + exit; + } + } + } From cebfde66f7f73245cb1cdd16d2e1d283478d873a Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Sun, 15 Jun 2014 09:45:00 +0530 Subject: [PATCH 13/36] deactivating a plugin in ams --HG-- branch : Gsoc14-ryzomAppImprovements --- .../www/html/func/deactivate_plugin.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/func/deactivate_plugin.php diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/deactivate_plugin.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/deactivate_plugin.php new file mode 100644 index 000000000..a4b6120b1 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/deactivate_plugin.php @@ -0,0 +1,37 @@ + update( "plugins", array( 'Status' => '0' ), "Id = $id" ); + if ( $result ) + { + header( "Location: index.php?page=plugins&result=5" ); + exit; + } + else + { + header( "Location: index.php?page=plugins&result=6" ); + exit; + + } + } + else + { + header( "Location: index.php?page=plugins&result=6" ); + exit; + } + } + } From 678cc254ee29b2a7a80e5843f900d495be06b5de Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Wed, 18 Jun 2014 15:10:31 +0530 Subject: [PATCH 14/36] updating functionality with some error fixes --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ryzom_ams/ams_lib/autoload/dblayer.php | 383 +++++++++--------- .../ams_lib/autoload/plugincache.php | 34 +- .../ryzom_ams/ams_lib/translations/en.ini | 27 +- .../www/html/func/install_plugin.php | 118 +++++- .../www/html/templates/install_plugin.tpl | 3 +- .../ryzom_ams/www/html/templates/plugins.tpl | 2 +- 6 files changed, 360 insertions(+), 207 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/dblayer.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/dblayer.php index b82e7ea8f..63b6bfc81 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/dblayer.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/dblayer.php @@ -1,232 +1,245 @@ PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC - ); - $this->PDO = new PDO($dsn,$cfg['db'][$db]['user'],$cfg['db'][$db]['pass'], $opt); - } else { + $dsn = "mysql:"; + $dsn .= "host=" . $cfg['db'][$db]['host'] . ";"; + $dsn .= "dbname=" . $cfg['db'][$db]['name'] . ";"; + $dsn .= "port=" . $cfg['db'][$db]['port'] . ";"; + + $opt = array( + PDO :: ATTR_ERRMODE => PDO :: ERRMODE_EXCEPTION, + PDO :: ATTR_DEFAULT_FETCH_MODE => PDO :: FETCH_ASSOC + ); + $this -> PDO = new PDO( $dsn, $cfg['db'][$db]['user'], $cfg['db'][$db]['pass'], $opt ); + } else { global $cfg; - $dsn = "mysql:"; - $dsn .= "host=". $cfg['db'][$dbn]['host'].";"; - $dsn .= "port=". $cfg['db'][$dbn]['port'].";"; + $dsn = "mysql:"; + $dsn .= "host=" . $cfg['db'][$dbn]['host'] . ";"; + $dsn .= "port=" . $cfg['db'][$dbn]['port'] . ";"; + + $opt = array( + PDO :: ATTR_ERRMODE => PDO :: ERRMODE_EXCEPTION, + PDO :: ATTR_DEFAULT_FETCH_MODE => PDO :: FETCH_ASSOC + ); + $this -> PDO = new PDO( $dsn, $_POST['Username'], $_POST['Password'], $opt ); + } - $opt = array( - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC - ); - $this->PDO = new PDO($dsn,$_POST['Username'],$_POST['Password'], $opt); - } - - } + } /** - * execute a query that doesn't have any parameters - * @param $query the mysql query - * @return returns a PDOStatement object - */ - public function executeWithoutParams($query){ - $statement = $this->PDO->prepare($query); - $statement->execute(); - return $statement; - } + * execute a query that doesn't have any parameters + * + * @param $query the mysql query + * @return returns a PDOStatement object + */ + public function executeWithoutParams( $query ) { + $statement = $this -> PDO -> prepare( $query ); + $statement -> execute(); + return $statement; + } /** - * execute a query that has parameters - * @param $query the mysql query - * @param $params the parameters that are being used by the query - * @return returns a PDOStatement object - */ - public function execute($query,$params){ - $statement = $this->PDO->prepare($query); - $statement->execute($params); - return $statement; - } + * execute a query that has parameters + * + * @param $query the mysql query + * @param $params the parameters that are being used by the query + * @return returns a PDOStatement object + */ + public function execute( $query, $params ) { + $statement = $this -> PDO -> prepare( $query ); + $statement -> execute( $params ); + return $statement; + } - /** - * execute a query (an insertion query) that has parameters and return the id of it's insertion - * @param $query the mysql query - * @param $params the parameters that are being used by the query - * @return returns the id of the last inserted element. - */ - public function executeReturnId($tb_name,$data){ - $field_values =':'. implode(',:', array_keys($data)); - $field_options = implode(',', array_keys($data)); - try{ - $sth = $this->PDO->prepare("INSERT INTO $tb_name ($field_options) VALUE ($field_values)"); - foreach ($data as $key => $value ) - { - $sth->bindValue(":$key", $value); - } - $this->PDO->beginTransaction(); - //execution - $sth->execute(); - $lastId =$this->PDO->lastInsertId(); - $this->PDO->commit(); - }catch (Exception $e) - { - //for rolling back the changes during transaction - $this->PDO->rollBack(); - throw new Exception("error in inseting"); - } - return $lastId; - } - - /** + * execute a query (an insertion query) that has parameters and return the id of it's insertion * + * @param $query the mysql query + * @param $params the parameters that are being used by the query + * @return returns the id of the last inserted element. + */ + public function executeReturnId( $tb_name, $data ) { + $field_values = ':' . implode( ',:', array_keys( $data ) ); + $field_options = implode( ',', array_keys( $data ) ); + try { + $sth = $this -> PDO -> prepare( "INSERT INTO $tb_name ($field_options) VALUE ($field_values)" ); + foreach ( $data as $key => $value ) + { + $sth -> bindValue( ":$key", $value ); + } + $this -> PDO -> beginTransaction(); + $sth -> execute(); + $lastId = $this -> PDO -> lastInsertId(); + $this -> PDO -> commit(); + } + catch ( Exception $e ) + { + // for rolling back the changes during transaction + $this -> PDO -> rollBack(); + throw new Exception( "error in inseting" ); + } + return $lastId; + } + + /** * Select function using prepared statement + * * @param string $tb_name Table Name to Select * @param array $data Associative array * @param string $where where to select * @return statement object */ - public function selectWithParameter($param, $tb_name, $data, $where) - { - try{ - $sth = $this->PDO->prepare("SELECT $param FROM $tb_name WHERE $where"); - $this->PDO->beginTransaction(); - $sth->execute($data); - $this->PDO->commit(); - }catch(Exception $e) - { - $this->PDO->rollBack(); - throw new Exception("error selection"); - return false; - } + public function selectWithParameter( $param, $tb_name, $data, $where ) + { + try { + $sth = $this -> PDO -> prepare( "SELECT $param FROM $tb_name WHERE $where" ); + $this -> PDO -> beginTransaction(); + $sth -> execute( $data ); + $this -> PDO -> commit(); + } + catch( Exception $e ) + { + $this -> PDO -> rollBack(); + throw new Exception( "error selection" ); + return false; + } return $sth; - } - + } + /** - * * Select function using prepared statement + * * @param string $tb_name Table Name to Select * @param array $data Associative array * @param string $where where to select * @return statement object */ - public function select($tb_name, $data ,$where) - { - try{ - $sth = $this->PDO->prepare("SELECT * FROM $tb_name WHERE $where"); - $this->PDO->beginTransaction(); - $sth->execute($data); - $this->PDO->commit(); - }catch(Exception $e) - { - $this->PDO->rollBack(); - throw new Exception("error selection"); - return false; - } + public function select( $tb_name, $data , $where ) + { + try { + $sth = $this -> PDO -> prepare( "SELECT * FROM $tb_name WHERE $where" ); + $this -> PDO -> beginTransaction(); + $sth -> execute( $data ); + $this -> PDO -> commit(); + } + catch( Exception $e ) + { + $this -> PDO -> rollBack(); + throw new Exception( "error selection" ); + return false; + } return $sth; - } - + } + /** - * * Update function with prepared statement + * * @param string $tb_name name of the table * @param array $data associative array with values * @param string $where where part * @throws Exception error in updating */ - public function update($tb_name, $data, $where) - { - $field_option_values=null; - foreach ($data as $key => $value) - { - $field_option_values.=",$key".'=:'.$value; - } - $field_option_values = ltrim($field_option_values,','); - try { - $sth = $this->PDO->prepare("UPDATE $tb_name SET $field_option_values WHERE $where "); - - foreach ($data as $key => $value) - { - $sth->bindValue(":$key", $value); - } - $this->PDO->beginTransaction(); - $sth->execute(); - $this->PDO->commit(); - }catch (Exception $e) - { - $this->PDO->rollBack(); - throw new Exception('error in updating'); - } - } + public function update( $tb_name, $data, $where ) + { + $field_option_values = null; + foreach ( $data as $key => $value ) + { + $field_option_values .= ",$key" . '=:' . $key; + } + $field_option_values = ltrim( $field_option_values, ',' ); + try { + $sth = $this -> PDO -> prepare( "UPDATE $tb_name SET $field_option_values WHERE $where " ); + + foreach ( $data as $key => $value ) + { + $sth -> bindValue( ":$key", $value ); + } + $this -> PDO -> beginTransaction(); + $sth -> execute(); + $this -> PDO -> commit(); + } + catch ( Exception $e ) + { + $this -> PDO -> rollBack(); + throw new Exception( 'error in updating' ); + return false; + } + return true; + } + /** - * * insert function using prepared statements + * * @param string $tb_name Name of the table to insert in * @param array $data Associative array of data to insert */ - - public function insert($tb_name, $data) - { - $field_values =':'. implode(',:', array_keys($data)); - $field_options = implode(',', array_keys($data)); - try{ - $sth = $this->PDO->prepare("INSERT INTO $tb_name ($field_options) VALUE ($field_values)"); - foreach ($data as $key => $value ) - { - $sth->bindValue(":$key", $value); - } - $this->PDO->beginTransaction(); - //execution - $sth->execute(); - $this->PDO->commit(); - - }catch (Exception $e) - { - //for rolling back the changes during transaction - $this->PDO->rollBack(); - throw new Exception("error in inseting"); - } - } - + public function insert( $tb_name, $data ) + { + $field_values = ':' . implode( ',:', array_keys( $data ) ); + $field_options = implode( ',', array_keys( $data ) ); + try { + $sth = $this -> PDO -> prepare( "INSERT INTO $tb_name ($field_options) VALUE ($field_values)" ); + foreach ( $data as $key => $value ) + { + + $sth -> bindValue( ":$key", $value ); + } + $this -> PDO -> beginTransaction(); + // execution + $sth -> execute(); + $this -> PDO -> commit(); + + } + catch ( Exception $e ) + { + // for rolling back the changes during transaction + $this -> PDO -> rollBack(); + throw new Exception( "error in inseting" ); + } + } + /** - * * Delete database entery using prepared statement - * @param string $tb_name - * @param string $where + * + * @param string $tb_name + * @param string $where * @throws error in deleting */ - public function delete($tb_name, $where) - { + public function delete( $tb_name, $data, $where ) + { try { - $sth = $this->prepare("DELETE FROM $tb_name WHERE $where"); - $this->PDO->beginTransaction(); - $sth->execute(); - $this->PDO->commit(); - } - catch (Exception $e) - { - $this->rollBack(); - throw new Exception("error in deleting"); - } - - } -} + $sth = $this -> PDO -> prepare( "DELETE FROM $tb_name WHERE $where" ); + $this -> PDO -> beginTransaction(); + $sth -> execute( $data ); + $this -> PDO -> commit(); + } + catch ( Exception $e ) + { + $this -> rollBack(); + throw new Exception( "error in deleting" ); + } + + } + } diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php index bba6e3fb1..1f0ef9bf6 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php @@ -26,10 +26,10 @@ class Plugincache { public function set( $values ) { $this -> setId( $values['Id'] ); $this -> setPluginName( $values['Name'] ); - $this -> setPluginType( $values['Type'] ); - $this -> setPluginPermission( $values['Permission'] ); - $this -> setPluginStatus( $values['Status'] ); - $this -> setPluginInfo( json_decode( $values['Info'] ) ); + $this -> setPluginType( $values['Type'] ); + $this -> setPluginPermission( $values['Permission'] ); + $this -> setPluginStatus( $values['Status'] ); + $this -> setPluginInfo( json_decode( $values['Info'] ) ); } /** @@ -140,4 +140,30 @@ class Plugincache { $this -> plugin_info = $p_n; } + + /** + * some more plugin function that requires during plugin operations + * + * / + * + * + * /** + * function to remove a non empty directory + * + * @param $dir directory address + * @return boolean + */ + public static function rrmdir( $dir ) { + if ( is_dir( $dir ) ) { + $objects = scandir( $dir ); + foreach ( $objects as $object ) { + if ( $object != "." && $object != ".." ) { + if ( filetype( $dir . "/" . $object ) == "dir" ) rmdir( $dir . "/" . $object ); + else unlink( $dir . "/" . $object ); + } + } + reset( $objects ); + return rmdir( $dir ); + } + } } diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini index 4c8b545ec..548b2ea06 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini @@ -5,6 +5,9 @@ login_info = "Please enter your MySQL Username and Password to install the database.
This is being loaded because the is_installed file is missing.
This process will take about 30 seconds." login_here = "here" +[ams_content] +ams_title="Ryzom Account Mangement System" + [dashboard] home_title = "Introduction" home_info = "Welcome to the Ryzom Core - Account Management System" @@ -66,11 +69,12 @@ plugin_status = "Status" ip_success = "Plugin added succesfuly." plugin_actions = "Actions" dp_success = "Plugin deleted successfuly" -dp_error = "Error in deleting plugin.Please try again later" -ac_success = "Plugin Activated successfuly" -ac_error = "Plugin facing some error in activating. Please try again later" -dc_success = "Plugin de-Activated successfuly" -dc_error = "Plugin facing some error in de-activating. Please try again later" +dp_error = "Error in deleting plugin.Please try again later." +ac_success = "Plugin Activated successfuly." +ac_error = "Plugin facing some error in activating. Please try again later." +dc_success = "Plugin de-Activated successfuly." +dc_error = "Plugin facing some error in de-activating. Please try again later." +up_success = "Update added successfully. Go to Updates page for installing updates." [install_plugin] ip_title = "Install a new Plugin" @@ -79,6 +83,15 @@ ip_support = "Upload the plugin archieve to install.
The following file exte ip_info_nfound = "Info file not found in the Plugin.Please recheck" ip_file_nfnd="Please upload a plugin before clicking on install button" +[plugins_update] +up_title = "Updates for Plugins" +up_info = "Here you can see the entire list of available updates for plugins." +up_serial = "Serial No." +plugin_name = "Name" +plugin_version = "Version" +up_updated_version = "New Version" +up_action = "Actions" + [show_ticket] t_title = "Ticket" title = "Title" @@ -152,8 +165,8 @@ go_home = "Go Home" userlist_info = "welcome to the userlist" [login] -login_info = "Please login with your Username and Password." -login_error_message = "The username/password were not correct!" +login_info = "Please login with your Email/Username and Password." +login_error_message = "The Email/username/password were not correct!" login_register_message ="Register If you don't have an account yet, create one" login_here = "here" login_forgot_password_message = "In case you forgot your password, click" diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php index 5376dfd02..1383dea8a 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php @@ -8,7 +8,9 @@ */ function install_plugin() { - // if logged in + $result = array(); + + // if logged in if ( WebUsers :: isLoggedIn() ) { // path of temporary folder for storing files @@ -30,13 +32,32 @@ function install_plugin() { $target_path = "../../ams_lib/plugins/$dir"; //path in which the zip extraction is to be done $destination = "../../ams_lib/plugins/"; - // checking for the command to install plugin is given or not + // scanning plugin folder if plugin with same name is already exists or not + $x = checkForUpdate( $dir, $destination, $fileTmpLoc, $temp_path ); + if ( $x == '1' ) + { + echo "update found"; + exit(); + } + else if ( $x == '2' ) + { + echo "Plugin already exists with same name ."; + exit(); + } + else if ( $x == '3' ) + { + echo "Update info is not present in the update"; + exit(); + } + + + // checking for the command to install plugin is given or not if ( !isset( $_POST['install_plugin'] ) ) { if ( ( $_FILES["file"]["type"] == 'application/zip' ) ) { if ( move_uploaded_file( $fileTmpLoc, $temp_path . "/" . $fileName ) ) { - echo "$fileName upload is complete."; + echo "$fileName upload is complete.
" . "
"; exit(); } else @@ -59,15 +80,14 @@ function install_plugin() { { if ( file_exists( $target_path . "/.info" ) ) { - $result = array(); - $result = readPluginFile( ".info", $target_path ); + $result = readPluginFile( ".info", $target_path ); // sending all info to the database $install_result = array(); $install_result['FileName'] = $target_path; $install_result['Name'] = $result['PluginName']; - // $install_result['Type'] = $result['type']; - if ( Ticket_User :: isMod( unserialize( $_SESSION['ticket_user'] ) ) ) + $install_result['Type'] = $result['Type']; + if ( Ticket_User :: isMod( unserialize( $_SESSION['ticket_user'] ) ) ) { $install_result['Permission'] = 'admin'; } @@ -165,4 +185,86 @@ function readPluginFile( $fileName, $target_path ) } fclose( $file_handle ); return $result; - } + } + +/** + * function to check for updates or + * if the same plugin already exists + * also, if the update founds ,check for the update info in the .info file. + * Update is saved in the temp direcotry with pluginName_version.zip + * + * @param $fileName file which is uploaded in .zip extension + * @param $findPath where we have to look for the installed plugins + * @param $tempFile path for the temporary file + * @param $tempPath path where we have to store the update + * @return 2 if plugin already exists and update not found + * @return 3 if update info tag not found in .info file + */ +function checkForUpdate( $fileName, $findPath, $tempFile, $tempPath ) + { + // check for plugin if exists + $file = scandir( $findPath ); + foreach( $file as $key => $value ) + { + if ( strcmp( $value, $fileName ) == 0 ) + { + if ( !file_exists( $tempPath . "/test" ) ) + { + mkdir( $tempPath . "/test" ); + } + if ( zipExtraction( $tempFile, $tempPath . "/test/" ) ) + { + $result = readPluginFile( ".info", $tempPath . "/test/" . $fileName ); + + // check for the version for the plugin + $db = new DBLayer( "lib" ); + $sth = $db -> select( "plugins", array( ':name' => $result['PluginName'] ), "Name = :name" ); + $info = $sth -> fetch(); + $info['Info'] = json_decode( $info['Info'] ); + + // the two versions from main plugin and the updated part + $new_version = explode( '.', $result['Version'] ); + $pre_version = explode( '.', $info['Info'] -> Version ); + + // For all plugins we have used semantic versioning + // Format: X.Y.Z ,X->Major, Y->Minor, Z->Patch + // change in the X Y & Z values refer the type of change in the plugin. + // for initial development only Minor an Patch MUST be 0. + // if there is bug fix then there MUST be an increment in the Z value. + // if there is change in the functionality or addition of new functionality + // then there MUST be an increment in the Y value. + // When there is increment in the X value , Y and Z MUST be 0. + // comparing if there is some change + if ( !array_intersect( $new_version , $pre_version ) ) + { + // removing the uploaded file + Plugincache :: rrmdir( $tempPath . "/test/" . $fileName ); + return '2'; + } + else + { + // check for update info if exists + if ( !array_key_exists( 'UpdateInfo', $result ) ) + { + return '3'; //update info tag not found + } + else + { + // storing update in the temp directory + // format of update save + if ( move_uploaded_file( $tempFile, $tempPath . "/" . trim( $fileName, ".zip" ) . "_" . $result['Version'] . ".zip" ) ) { + // setting update information in the database + $dbr = new DBLayer( "lib" ); + $update['PluginId'] = $info['Id']; + $update['UpdatePath'] = $tempPath . "/" . trim( $fileName, ".zip" ) . "_" . $result['Version'] . ".zip"; + $update['UpdateInfo'] = json_encode( $result ); + $dbr -> insert( "updates", $update ); + header( "Location: index.php?page=plugins&result=7" ); + exit; + } + } + } + } + } + } + } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/install_plugin.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/install_plugin.tpl index 27a4cec49..968d6cec4 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/install_plugin.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/install_plugin.tpl @@ -22,8 +22,7 @@

{if isset($smarty.get.result) and $smarty.get.result eq "0"}

{$ip_file_nfnd}

{/if} - {if isset($smarty.get.result) and $smarty.get.result eq "2"}

{$ip_info_nfound}

{/if} -
+ {if isset($smarty.get.result) and $smarty.get.result eq "2"}

{$ip_info_nfound}

{/if} {$ip_message} diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl index cac67147a..4aa6e7e3b 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl @@ -16,6 +16,7 @@ {if isset($smarty.get.result) and $smarty.get.result eq "4"}

{$ac_error}

{/if} {if isset($smarty.get.result) and $smarty.get.result eq "5"}

{$dc_success}

{/if} {if isset($smarty.get.result) and $smarty.get.result eq "6"}

{$dc_error}

{/if} + {if isset($smarty.get.result) and $smarty.get.result eq "7"}

{$up_success}

{/if}

{$plugin_info}

@@ -65,4 +66,3 @@
{/block} - From 4d1d52fc73a0488dac22d95fc9dd76ff52dedcf6 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Thu, 19 Jun 2014 14:53:49 +0530 Subject: [PATCH 15/36] check functionality for existing updates --HG-- branch : Gsoc14-ryzomAppImprovements --- .../www/html/func/install_plugin.php | 60 +++++++++++++++---- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php index 1383dea8a..1ea950d38 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php @@ -212,6 +212,8 @@ function checkForUpdate( $fileName, $findPath, $tempFile, $tempPath ) { mkdir( $tempPath . "/test" ); } + + // extracting the update if ( zipExtraction( $tempFile, $tempPath . "/test/" ) ) { $result = readPluginFile( ".info", $tempPath . "/test/" . $fileName ); @@ -246,25 +248,59 @@ function checkForUpdate( $fileName, $findPath, $tempFile, $tempPath ) // check for update info if exists if ( !array_key_exists( 'UpdateInfo', $result ) ) { - return '3'; //update info tag not found + return '3'; //update info tag not found } else { - // storing update in the temp directory - // format of update save - if ( move_uploaded_file( $tempFile, $tempPath . "/" . trim( $fileName, ".zip" ) . "_" . $result['Version'] . ".zip" ) ) { - // setting update information in the database - $dbr = new DBLayer( "lib" ); - $update['PluginId'] = $info['Id']; - $update['UpdatePath'] = $tempPath . "/" . trim( $fileName, ".zip" ) . "_" . $result['Version'] . ".zip"; - $update['UpdateInfo'] = json_encode( $result ); - $dbr -> insert( "updates", $update ); - header( "Location: index.php?page=plugins&result=7" ); - exit; + // check if update already exists + if ( pluginUpdateExists( $info['Id'], $tempPath . "/" . trim( $fileName, ".zip" ) . "_" . $result['Version'] . ".zip" ) ) + { + echo "Update already exists"; + exit; } + else { + // removing the preivous update + $dbr = new DBLayer( "lib" ); + $dbr -> delete( "updates", array( 'id' => $info['Id'] ), "PluginId=:id" ); + // storing update in the temp directory + // format of update save + if ( move_uploaded_file( $tempFile, $tempPath . "/" . trim( $fileName, ".zip" ) . "_" . $result['Version'] . ".zip" ) ) { + // setting update information in the database + $update['PluginId'] = $info['Id']; + $update['UpdatePath'] = $tempPath . "/" . trim( $fileName, ".zip" ) . "_" . $result['Version'] . ".zip"; + $update['UpdateInfo'] = json_encode( $result ); + $dbr -> insert( "updates", $update ); + header( "Location: index.php?page=plugins&result=7" ); + exit; + } + } } } } } } + } + +/** + * Function to check for the update of a plugin already exists + * + * @param $pluginId id of the plugin for which update is available + * @param $updatePath path of the new update + * @return boolean if update for a plugin already exists or + * if update of same version is uploading + */ +function PluginUpdateExists( $pluginId, $updatePath ) + { + $db = new DBLayer( 'lib' ); + $sth = $db -> selectWithParameter( "UpdatePath", "updates", array( 'pluginid' => $pluginId ), "PluginId=:pluginid" ); + $row = $sth -> fetch(); + if ( $updatePath == $row['UpdatePath'] ) + { + return true; + } + else + { + rmdir( $row['UpdatePath'] ); + return false; + } } From f09e4e48a542ce42a09940a422b497c19234ef49 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Thu, 19 Jun 2014 17:11:10 +0530 Subject: [PATCH 16/36] template for updates of plugins --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ams_lib/autoload/plugincache.php | 41 ++++++++++++++----- .../ryzom_ams/ams_lib/translations/en.ini | 4 +- .../ryzom_ams/www/html/inc/plugins_update.php | 36 ++++++++++++++++ 3 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/inc/plugins_update.php diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php index 1f0ef9bf6..09bd942b3 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php @@ -14,7 +14,7 @@ class Plugincache { private $plugin_permission; private $plugin_status; private $plugin_info = array(); - + private $update_info = array(); /** * A constructor. * Empty constructor @@ -26,15 +26,17 @@ class Plugincache { public function set( $values ) { $this -> setId( $values['Id'] ); $this -> setPluginName( $values['Name'] ); - $this -> setPluginType( $values['Type'] ); - $this -> setPluginPermission( $values['Permission'] ); - $this -> setPluginStatus( $values['Status'] ); - $this -> setPluginInfo( json_decode( $values['Info'] ) ); + $this -> setPluginType( $values['Type'] ); + $this -> setPluginPermission( $values['Permission'] ); + $this -> setPluginStatus( $values['Status'] ); + $this -> setPluginInfo( json_decode( $values['Info'] ) ); + @$this -> setUpdateInfo( json_decode( $values['UpdateInfo'] ) ); } /** * loads the object's attributes. */ + public function load_With_SID() { $dbl = new DBLayer( "lib" ); $statement = $dbl -> executeWithoutParams( "SELECT * FROM plugins" ); @@ -140,14 +142,33 @@ class Plugincache { $this -> plugin_info = $p_n; } + /** + * functionalities for plugin updates + */ /** - * some more plugin function that requires during plugin operations - * - * / + * set update info attribute array of the object. * + * @param $p_n array + */ + public function setUpdateInfo( $p_n ) { + $this -> update_info = $p_n; + } + + /** + * get update info array attribute of the object. + */ + public function getUpdateInfo() { + return $this -> update_info; + } + + + /** + * some more plugin function that requires during plugin operations * - * /** + */ + + /** * function to remove a non empty directory * * @param $dir directory address @@ -166,4 +187,4 @@ class Plugincache { return rmdir( $dir ); } } - } + } diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini index 548b2ea06..d324acb3a 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini @@ -86,11 +86,11 @@ ip_file_nfnd="Please upload a plugin before clicking on install button" [plugins_update] up_title = "Updates for Plugins" up_info = "Here you can see the entire list of available updates for plugins." -up_serial = "Serial No." +up_description = "Updates Info" plugin_name = "Name" plugin_version = "Version" up_updated_version = "New Version" -up_action = "Actions" +up_actions = "Actions" [show_ticket] t_title = "Ticket" diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/plugins_update.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/plugins_update.php new file mode 100644 index 000000000..89d547860 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/plugins_update.php @@ -0,0 +1,36 @@ + getElements(), Array( "getId", "getPluginName", "getPluginInfo", "getUpdateInfo" ), Array( "id", "plugin_name", "plugin_info", "update_info" ) ); + $pageResult['links'] = $pagination -> getLinks( 5 ); + $pageResult['lastPage'] = $pagination -> getLast(); + $pageResult['currentPage'] = $pagination -> getCurrent(); + + global $INGAME_WEBPATH; + $pageResult['ingame_webpath'] = $INGAME_WEBPATH; + + // check if shard is online + try { + $dbs = new DBLayer( "shard" ); + $pageResult['shard'] = "online"; + } + catch( PDOException $e ) { + $pageResult['shard'] = "offline"; + } + return( $pageResult ); + } else { + // ERROR: No access! + $_SESSION['error_code'] = "403"; + header( "Location: index.php?page=error" ); + exit; + } + } From ae7503df36ca01e076b80b7ff385dbd21824f643 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Thu, 19 Jun 2014 17:16:24 +0530 Subject: [PATCH 17/36] template with list of updates --HG-- branch : Gsoc14-ryzomAppImprovements --- .../www/html/templates/plugins_update.tpl | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins_update.tpl diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins_update.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins_update.tpl new file mode 100644 index 000000000..afa93d80f --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins_update.tpl @@ -0,0 +1,50 @@ +{block name=content} +
+
+
+

{$up_title}

+
+ + + +
+
+
+

{$up_info}

+
{$plugin_status}{$plugin_name}{$plugin_name} {$plugin_version}{$plugin_description}{$plugin_type}{$plugin_description}{$plugin_type} {$plugin_permission}{$plugin_actions}
{$element.plugin_info->Description} {$element.plugin_type} {$element.plugin_permission} + {if ($element.plugin_status) eq "0"}{/if} + {if ($element.plugin_status) eq "1"}{/if}
+ + + + + + + + + + + {foreach from=$plug item=element} + + + + + + + {/foreach} + + +
{$plugin_name}{$plugin_version}{$up_updated_version}{$up_description}{$up_actions}
{$element.plugin_name}{$element.plugin_info->Version}{$element.update_info->Version}{$element.update_info->UpdateInfo} +
+
+
    +
  • «
  • + {foreach from=$links item=link} +
  • {$link}
  • + {/foreach} +
  • »
  • +
+
+
+ + + +{/block} From e7e4b8874710319eb366f56992328ee713baf5b6 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Mon, 23 Jun 2014 14:36:29 +0530 Subject: [PATCH 18/36] function to install update in the plugin --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ryzom_ams/ams_lib/translations/en.ini | 1 + .../ryzom_ams/www/html/func/update_plugin.php | 35 +++++++++++++++++++ .../ryzom_ams/www/html/templates/plugins.tpl | 1 + 3 files changed, 37 insertions(+) create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/func/update_plugin.php diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini index d324acb3a..f2a21d2ab 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini @@ -75,6 +75,7 @@ ac_error = "Plugin facing some error in activating. Please try again later." dc_success = "Plugin de-Activated successfuly." dc_error = "Plugin facing some error in de-activating. Please try again later." up_success = "Update added successfully. Go to Updates page for installing updates." +up_install_success = "Update installed successfully." [install_plugin] ip_title = "Install a new Plugin" diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/update_plugin.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/update_plugin.php new file mode 100644 index 000000000..ddf4b0abf --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/update_plugin.php @@ -0,0 +1,35 @@ + executeWithoutParams( "SELECT * FROM plugins INNER JOIN updates ON plugins.Id=updates.PluginId Where plugins.Id=$id" ); + $row = $sth -> fetch(); + print_r( $row ); + + // replacing update in the database + Plugincache :: rrmdir( $row['FileName'] ); + Plugincache :: zipExtraction( $row['UpdatePath'], rtrim( $row['FileName'], strtolower( $row['Name'] ) ) ); + + $db -> update( "plugins", array( 'Info' => $row['UpdateInfo'] ), "Id=$row[Id]" ); + + // deleting the previous update + $db -> delete( "updates", array( 'id' => $row['s.no'] ), "s.no=:id" ); + + header( "Location: index.php?page=plugins&result=8" ); + exit; + + } + } + } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl index 4aa6e7e3b..73f88d1a2 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl @@ -17,6 +17,7 @@ {if isset($smarty.get.result) and $smarty.get.result eq "5"}

{$dc_success}

{/if} {if isset($smarty.get.result) and $smarty.get.result eq "6"}

{$dc_error}

{/if} {if isset($smarty.get.result) and $smarty.get.result eq "7"}

{$up_success}

{/if} + {if isset($smarty.get.result) and $smarty.get.result eq "8"}

{$up_install_success}

{/if}

{$plugin_info}

From 1ef330b076f13ffdfd4a482c2fd2582bec4534ab Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Thu, 3 Jul 2014 16:44:37 +0530 Subject: [PATCH 19/36] hook functionality --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ryzom_ams/ams_lib/autoload/dblayer.php | 2 +- .../ryzom_ams/ams_lib/autoload/helpers.php | 407 +++++++++--------- .../ams_lib/autoload/plugincache.php | 89 +++- .../ryzom_ams/www/html/func/update_plugin.php | 1 - .../tools/server/ryzom_ams/www/html/index.php | 16 +- .../www/html/templates/layout_admin.tpl | 2 + .../www/html/templates/layout_plugin.tpl | 12 + 7 files changed, 322 insertions(+), 207 deletions(-) create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_plugin.tpl diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/dblayer.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/dblayer.php index 63b6bfc81..43282789e 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/dblayer.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/dblayer.php @@ -237,7 +237,7 @@ class DBLayer { } catch ( Exception $e ) { - $this -> rollBack(); + $this -> PDO -> rollBack(); throw new Exception( "error in deleting" ); } diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php index 2d26f3c21..3410cf602 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php @@ -1,224 +1,241 @@ setCompileDir($SITEBASE.'/templates_c/'); - $smarty->setCacheDir($SITEBASE.'/cache/'); - $smarty -> setConfigDir($SITEBASE . '/configs/' ); + $smarty -> setCompileDir( $SITEBASE . '/templates_c/' ); + $smarty -> setCacheDir( $SITEBASE . '/cache/' ); + $smarty -> setConfigDir( $SITEBASE . '/configs/' ); // turn smarty debugging on/off - $smarty -> debugging = false; + $smarty -> debugging = false; // caching must be disabled for multi-language support - $smarty -> caching = false; + $smarty -> caching = false; $smarty -> cache_lifetime = 5; - - //needed by smarty. - helpers :: create_folders (); - global $FORCE_INGAME; - - //if ingame, then use the ingame templates - if ( helpers::check_if_game_client() or $FORCE_INGAME ){ - $smarty -> template_dir = $AMS_LIB . '/ingame_templates/'; + + // needed by smarty. + helpers :: create_folders (); + global $FORCE_INGAME; + + // if ingame, then use the ingame templates + if ( helpers :: check_if_game_client() or $FORCE_INGAME ) { + $smarty -> template_dir = $AMS_LIB . '/ingame_templates/'; $smarty -> setConfigDir( $AMS_LIB . '/configs' ); $variables = parse_ini_file( $AMS_LIB . '/configs/ingame_layout.ini', true ); - foreach ( $variables[$INGAME_LAYOUT] as $key => $value ){ - $smarty -> assign( $key, $value ); - } - }else{ - $smarty -> template_dir = $SITEBASE . '/templates/'; + foreach ( $variables[$INGAME_LAYOUT] as $key => $value ) { + $smarty -> assign( $key, $value ); + } + } else { + $smarty -> template_dir = $SITEBASE . '/templates/'; $smarty -> setConfigDir( $SITEBASE . '/configs' ); - } - - foreach ( $vars as $key => $value ){ - $smarty -> assign( $key, $value ); - } - - //load page specific variables that are language dependent - $variables = Helpers::handle_language(); - foreach ( $variables[$template] as $key => $value ){ - $smarty -> assign( $key, $value ); - } - - //smarty inheritance for loading the matching wrapper layout (with the matching menu bar) - if( isset($vars['permission']) && $vars['permission'] == 3 ){ - $inherited = "extends:layout_admin.tpl|"; - }else if( isset($vars['permission']) && $vars['permission'] == 2){ - $inherited = "extends:layout_mod.tpl|"; - }else if( isset($vars['permission']) && $vars['permission'] == 1){ - $inherited = "extends:layout_user.tpl|"; - }else{ - $inherited =""; - } - - //if $returnHTML is set to true, return the html by fetching the template else display the template. - if($returnHTML == true){ - return $smarty ->fetch($inherited . $template . '.tpl' ); - }else{ - $smarty -> display( $inherited . $template . '.tpl' ); - } - } - - - /** - * creates the folders that are needed for smarty. - * @todo for the drupal module it might be possible that drupal_mkdir needs to be used instead of mkdir, also this should be in the install.php instead. - */ - static public function create_folders(){ - global $AMS_LIB; + } + + foreach ( $vars as $key => $value ) { + $smarty -> assign( $key, $value ); + } + + // load page specific variables that are language dependent + $variables = Helpers :: handle_language(); + if ( $template != 'layout_plugin' ) + { + foreach ( $variables[$template] as $key => $value ) { + $smarty -> assign( $key, $value ); + } + } + // load ams content variables that are language dependent + foreach ( $variables['ams_content'] as $key => $value ) { + $smarty -> assign( $key, $value ); + } + + // smarty inheritance for loading the matching wrapper layout (with the matching menu bar) + if ( isset( $vars['permission'] ) && $vars['permission'] == 3 ) { + $inherited = "extends:layout_admin.tpl|"; + } else if ( isset( $vars['permission'] ) && $vars['permission'] == 2 ) { + $inherited = "extends:layout_mod.tpl|"; + } else if ( isset( $vars['permission'] ) && $vars['permission'] == 1 ) { + $inherited = "extends:layout_user.tpl|"; + } else { + $inherited = ""; + } + + // if $returnHTML is set to true, return the html by fetching the template else display the template. + if ( $returnHTML == true ) { + return $smarty -> fetch( $inherited . $template . '.tpl' ); + } else { + $smarty -> display( $inherited . $template . '.tpl' ); + } + } + + + /** + * creates the folders that are needed for smarty. + * + * @todo for the drupal module it might be possible that drupal_mkdir needs to be used instead of mkdir, also this should be in the install.php instead. + */ + static public function create_folders() { + global $AMS_LIB; global $SITEBASE; $arr = array( $AMS_LIB . '/ingame_templates/', $AMS_LIB . '/configs', - //$AMS_LIB . '/cache', - $SITEBASE . '/cache/', + // $AMS_LIB . '/cache', + $SITEBASE . '/cache/', $SITEBASE . '/templates/', $SITEBASE . '/templates_c/', $SITEBASE . '/configs' ); - foreach ( $arr as & $value ){ - - if ( !file_exists( $value ) ){ - print($value); - mkdir($value); - } - } - - } - - - /** + foreach ( $arr as &$value ) { + + if ( !file_exists( $value ) ) { + print( $value ); + mkdir( $value ); + } + } + + } + + + /** * check if the http request is sent ingame or not. + * * @return returns true in case it's sent ingame, else false is returned. */ - static public function check_if_game_client() - { - // if HTTP_USER_AGENT is not set then its ryzom core - global $FORCE_INGAME; - if ( ( isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'],"Ryzom") === 0)) || $FORCE_INGAME || ! isset($_SERVER['HTTP_USER_AGENT']) ){ - return true; - }else{ - return false; - } - } - - - /** + static public function check_if_game_client() + { + // if HTTP_USER_AGENT is not set then its ryzom core + global $FORCE_INGAME; + if ( ( isset( $_SERVER['HTTP_USER_AGENT'] ) && ( strpos( $_SERVER['HTTP_USER_AGENT'], "Ryzom" ) === 0 ) ) || $FORCE_INGAME || ! isset( $_SERVER['HTTP_USER_AGENT'] ) ) { + return true; + } else { + return false; + } + } + + + /** * Handles the language specific aspect. * The language can be changed by setting the $_GET['Language'] & $_GET['setLang'] together. This will also change the language entry of the user in the db. * Cookies are also being used in case the user isn't logged in. + * * @return returns the parsed content of the language .ini file related to the users language setting. */ - static public function handle_language(){ - global $DEFAULT_LANGUAGE; - global $AMS_TRANS; - - //if user wants to change the language - if(isset($_GET['Language']) && isset($_GET['setLang'])){ - //The ingame client sometimes sends full words, derive those! - switch($_GET['Language']){ - - case "English": - $lang = "en"; - break; - - case "French": - $lang = "fr"; - break; - - default: - $lang = $_GET['Language']; - } - //if the file exists en the setLang = true - if( file_exists( $AMS_TRANS . '/' . $lang . '.ini' ) && $_GET['setLang'] == "true"){ - //set a cookie & session var and incase logged in write it to the db! - setcookie( 'Language', $lang , time() + 60*60*24*30 ); - $_SESSION['Language'] = $lang; - if(WebUsers::isLoggedIn()){ - WebUsers::setLanguage($_SESSION['id'],$lang); - } - }else{ - $_SESSION['Language'] = $DEFAULT_LANGUAGE; - } - }else{ - //if the session var is not set yet - if(!isset($_SESSION['Language'])){ - //check if a cookie already exists for it - if ( isset( $_COOKIE['Language'] ) ) { - $_SESSION['Language'] = $_COOKIE['Language']; - //else use the default language - }else{ - $_SESSION['Language'] = $DEFAULT_LANGUAGE; - } - } - } - - if ($_SESSION['Language'] == ""){ - $_SESSION['Language'] = $DEFAULT_LANGUAGE; - } - return parse_ini_file( $AMS_TRANS . '/' . $_SESSION['Language'] . '.ini', true ); - - } - + static public function handle_language() { + global $DEFAULT_LANGUAGE; + global $AMS_TRANS; + + // if user wants to change the language + if ( isset( $_GET['Language'] ) && isset( $_GET['setLang'] ) ) { + // The ingame client sometimes sends full words, derive those! + switch ( $_GET['Language'] ) { + + case "English": + $lang = "en"; + break; + + case "French": + $lang = "fr"; + break; + + default: + $lang = $_GET['Language']; + } + // if the file exists en the setLang = true + if ( file_exists( $AMS_TRANS . '/' . $lang . '.ini' ) && $_GET['setLang'] == "true" ) { + // set a cookie & session var and incase logged in write it to the db! + setcookie( 'Language', $lang , time() + 60 * 60 * 24 * 30 ); + $_SESSION['Language'] = $lang; + if ( WebUsers :: isLoggedIn() ) { + WebUsers :: setLanguage( $_SESSION['id'], $lang ); + } + } else { + $_SESSION['Language'] = $DEFAULT_LANGUAGE; + } + } else { + // if the session var is not set yet + if ( !isset( $_SESSION['Language'] ) ) { + // check if a cookie already exists for it + if ( isset( $_COOKIE['Language'] ) ) { + $_SESSION['Language'] = $_COOKIE['Language']; + // else use the default language + } else { + $_SESSION['Language'] = $DEFAULT_LANGUAGE; + } + } + } - /** - * Time output function for handling the time display. - * @return returns the time in the format specified in the $TIME_FORMAT global variable. - */ - static public function outputTime($time, $str = 1){ - global $TIME_FORMAT; - if($str){ - return date($TIME_FORMAT,strtotime($time)); - }else{ - return date($TIME_FORMAT,$time); - } - } - - /** - * Auto login function for ingame use. - * This function will allow users who access the website ingame, to log in without entering the username and password. It uses the COOKIE entry in the open_ring db. - * it checks if the cookie sent by the http request matches the one in the db. This cookie in the db is changed everytime the user relogs. - * @return returns "FALSE" if the cookies didn't match, else it returns an array with the user's id and name. - */ - static public function check_login_ingame(){ - if ( helpers :: check_if_game_client () or $forcelibrender = false ){ - $dbr = new DBLayer("ring"); - if (isset($_GET['UserId']) && isset($_COOKIE['ryzomId'])){ - $id = $_GET['UserId']; - $statement = $dbr->select("ring_users", array('id' => $id, 'cookie' => $_COOKIE['ryzomId']), "user_id=:id AND cookie =:cookie"); - if ($statement->rowCount() ){ - $entry = $statement->fetch(); - //print_r($entry); - return array('id' => $entry['user_id'], 'name' => $entry['user_name']); - }else{ - return "FALSE"; - } - }else{ - return "FALSE"; - } - }else{ - return "FALSE"; - } - } +if ( $_SESSION['Language'] == "" ) { + $_SESSION['Language'] = $DEFAULT_LANGUAGE; + } +return parse_ini_file( $AMS_TRANS . '/' . $_SESSION['Language'] . '.ini', true ); + + } + + +/** + * Time output function for handling the time display. + * + * @return returns the time in the format specified in the $TIME_FORMAT global variable. + */ +static public function outputTime( $time, $str = 1 ) { +global $TIME_FORMAT; + if ( $str ) { + return date( $TIME_FORMAT, strtotime( $time ) ); + } else { + return date( $TIME_FORMAT, $time ); + } +} + +/** + * Auto login function for ingame use. + * This function will allow users who access the website ingame, to log in without entering the username and password. It uses the COOKIE entry in the open_ring db. + * it checks if the cookie sent by the http request matches the one in the db. This cookie in the db is changed everytime the user relogs. + * + * @return returns "FALSE" if the cookies didn't match, else it returns an array with the user's id and name. + */ +static public function check_login_ingame() { +if ( helpers :: check_if_game_client () or $forcelibrender = false ) { + $dbr = new DBLayer( "ring" ); + if ( isset( $_GET['UserId'] ) && isset( $_COOKIE['ryzomId'] ) ) { + $id = $_GET['UserId']; + + $statement = $dbr -> select( "ring_users", array( 'id' => $id, 'cookie' => $_COOKIE['ryzomId'] ), "user_id=:id AND cookie =:cookie" ); + + // $statement = $dbr->execute("SELECT * FROM ring_users WHERE user_id=:id AND cookie =:cookie", array('id' => $id, 'cookie' => $_COOKIE['ryzomId'])); + + if ( $statement -> rowCount() ) { + $entry = $statement -> fetch(); + // print_r($entry); + return array( 'id' => $entry['user_id'], 'name' => $entry['user_name'] ); + } else { + return "FALSE"; + } + } else { + return "FALSE"; + } + } else { + return "FALSE"; + } +} } diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php index 09bd942b3..42bdda045 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php @@ -156,18 +156,17 @@ class Plugincache { } /** - * get update info array attribute of the object. + * get plugin info array attribute of the object. */ public function getUpdateInfo() { return $this -> update_info; } - /** * some more plugin function that requires during plugin operations * */ - + /** * function to remove a non empty directory * @@ -187,4 +186,86 @@ class Plugincache { return rmdir( $dir ); } } - } + + /** + * function to unzip the zipped files + * + * @param $target_path path to the target zipped file + * @param $destination path to the destination + * @return boolean + */ + public static function zipExtraction( $target_path, $destination ) + { + $zip = new ZipArchive(); + $x = $zip -> open( $target_path ); + if ( $x === true ) { + if ( $zip -> extractTo( $destination ) ) + { + $zip -> close(); + return true; + } + else + { + $zip -> close(); + return false; + } + } + } + + /** + * returns plugin information with respect to the id + * + * @param id $ plugin id + * @return field info for the plugin + */ + public static function pluginInfoUsingId( $id, $fieldName ) + { + $db = new DBLayer( 'lib' ); + $sth = $db -> selectWithParameter( $fieldName, 'plugins', array( 'id' => $id ), 'Id=:id' ); + $row = $sth -> fetch(); + return $row[$fieldName]; + } + + /** + * function provides list of active plugins + * + * @return $ac_plugins list of active plugins + */ + public static function activePlugins() + { + $db = new DBLayer( 'lib' ); + $sth = $db -> selectWithParameter( 'Id', 'plugins', array( 'status' => 1 ), 'Status=:status' ); + $row = $sth -> fetchAll(); + return $row; + } + + /** + * function to load hooks for the active plugins + * and return the contents in the hooks in an array + * + * @return $content content available in hooks + */ + public static function loadHooks() + { + $content = array(); + $ac_arr = Plugincache :: activePlugins(); + foreach( $ac_arr as $key => $value ) + { + $plugin_path = Plugincache :: pluginInfoUsingId( $value['Id'], 'FileName' ); + $pluginName = Plugincache :: pluginInfoUsingId( $value['Id'], 'Name' ); + + // calling hooks in the $pluginName.php + include $plugin_path . '/' . strtolower( $pluginName ) . '.php'; + $arr = get_defined_functions(); + + foreach( $arr['user'] as $key => $value ) + { + if ( stristr( $value, strtolower( $pluginName ) ) == true ) + { + $content['hook_info'][$pluginName] = call_user_func( $value ); + } + } + } + return $content; + } + } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/update_plugin.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/update_plugin.php index ddf4b0abf..1420572b1 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/func/update_plugin.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/update_plugin.php @@ -16,7 +16,6 @@ function update_plugin() { $db = new DBLayer( 'lib' ); $sth = $db -> executeWithoutParams( "SELECT * FROM plugins INNER JOIN updates ON plugins.Id=updates.PluginId Where plugins.Id=$id" ); $row = $sth -> fetch(); - print_r( $row ); // replacing update in the database Plugincache :: rrmdir( $row['FileName'] ); diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/index.php b/code/ryzom/tools/server/ryzom_ams/www/html/index.php index f01eab3e4..e87c5dcd5 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/index.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/index.php @@ -14,7 +14,6 @@ // load required pages and turn error reporting on/off error_reporting( E_ALL ); ini_set( 'display_errors', 'on' ); -require_once( '../../ams_lib/libinclude.php' ); if ( !file_exists( '../is_installed' ) ) { // if is_installed doesnt exist run setup require( 'installer/libsetup.php' ); @@ -25,9 +24,10 @@ if ( !file_exists( '../is_installed' ) ) { // if config exists then include it require( '../config.php' ); } +require_once( $AMS_LIB . '/libinclude.php' ); session_start(); -// Running Cron? +// Running Cron if ( isset( $_GET["cron"] ) ) { if ( $_GET["cron"] == "true" ) { Sync :: syncdata( false ); @@ -39,6 +39,7 @@ Sync :: syncdata( false ); // Decide what page to load if ( ! isset( $_GET["page"] ) ) { + if ( isset( $_SESSION['user'] ) ) { if ( Ticket_User :: isMod( unserialize( $_SESSION['ticket_user'] ) ) ) { $page = 'dashboard'; @@ -101,9 +102,6 @@ if ( isset( $_SESSION['user'] ) ) { $return['username'] = $_SESSION['user']; } - - - // Set permission if ( isset( $_SESSION['ticket_user'] ) ) { $return['permission'] = unserialize( $_SESSION['ticket_user'] ) -> getPermission(); @@ -112,7 +110,6 @@ if ( isset( $_SESSION['ticket_user'] ) ) { $return['permission'] = 0; } - // hide sidebar + topbar in case of login/register if ( $page == 'login' || $page == 'register' || $page == 'logout' || $page == 'forgot_password' || $page == 'reset_password' ) { $return['no_visible_elements'] = 'TRUE'; @@ -126,5 +123,12 @@ if ( $page == 'error' ) { $return['no_visible_elements'] = 'FALSE'; } +// call to load hooks for the active plugins +$hook_content = Plugincache :: loadHooks(); +foreach( $hook_content as $key => $value ) + { + $return[$key] = $value; + } + // load the template with the variables in the $return array helpers :: loadTemplate( $page , $return ); diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_admin.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_admin.tpl index c50c1c20d..a0d1e49ef 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_admin.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_admin.tpl @@ -9,6 +9,8 @@
  • Queues
  • Support Groups
  • +
  • Plugins
  • + {if isset($hook_info)} {foreach from=$hook_info item=element}
  • {$element.menu_display}
  • {/foreach}{/if}
  • Syncing
  • Logout
  • {/block} diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_plugin.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_plugin.tpl new file mode 100644 index 000000000..5bc5938c4 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_plugin.tpl @@ -0,0 +1,12 @@ +{block name=content} +
    +{if isset($hook_info)} +{foreach from=$hook_info item=element} +{if $element.menu_display eq $smarty.get.name} +{include file=$element.template_path} +{/if} +{/foreach} +{/if} +
    +{/block} + From d59b6cc642b3675ce2a7eadfd639d5d81a5c3f56 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Sat, 5 Jul 2014 13:01:56 +0530 Subject: [PATCH 20/36] updates database --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ryzom_ams/www/html/installer/libsetup.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php b/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php index a590e6d7d..e8ca6d57a 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php @@ -172,6 +172,26 @@ PRIMARY KEY (`Id`) ) ENGINE = InnoDB; + -- ----------------------------------------------------- + -- Table `" . $cfg['db']['lib']['name'] ."`.`updates` + -- ----------------------------------------------------- + DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`updates` ; + + CREATE TABLE IF NOT EXISTS `" . $cfg['db']['lib']['name'] ."`.`updates` ( + `s.no` int(10) NOT NULL AUTO_INCREMENT, + `PluginId` int(10) DEFAULT NULL, + `UpdatePath` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `UpdateInfo` text COLLATE utf8_unicode_ci, + PRIMARY KEY (`s.no`), + KEY `PluginId` (`PluginId`)) + ENGINE=InnoDB; + + -- ----------------------------------------- + -- Constraints for table `updates` + -- ----------------------------------------- + ALTER TABLE `" . $cfg['db']['lib']['name'] ."`.`updates` + ADD CONSTRAINT `updates_ibfk_1` FOREIGN KEY (`PluginId`) REFERENCES `plugins` (`Id`); + -- ----------------------------------------------------- -- Table `" . $cfg['db']['lib']['name'] ."`.`ticket` From 931d18323b62b440dcf804d83659b653cb65a961 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Mon, 7 Jul 2014 01:48:42 +0530 Subject: [PATCH 21/36] removed merged conflicts --HG-- branch : Gsoc14-ryzomAppImprovements --- .../tools/server/ryzom_ams/ams_lib/autoload/plugincache.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php index 42bdda045..b056c02bb 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php @@ -6,7 +6,6 @@ * * @author shubham meena mentored by Matthew Lagoe */ - class Plugincache { private $id; private $plugin_name; @@ -268,4 +267,4 @@ class Plugincache { } return $content; } - } + } \ No newline at end of file From 4c0d3e53fc0aaddc378b14575dcd855537bc35f8 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Mon, 7 Jul 2014 13:56:58 +0530 Subject: [PATCH 22/36] fixed few bugs --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ams_lib/autoload/plugincache.php | 20 ++++---- .../ryzom_ams/ams_lib/autoload/users.php | 12 ++--- .../ryzom_ams/www/html/func/delete_plugin.php | 23 +-------- .../ryzom_ams/www/html/installer/libsetup.php | 47 ++++++++++--------- .../www/html/templates/layout_user.tpl | 1 + 5 files changed, 39 insertions(+), 64 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php index 7c43e1877..ae8f1129c 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php @@ -173,17 +173,13 @@ class Plugincache { * @return boolean */ public static function rrmdir( $dir ) { - if ( is_dir( $dir ) ) { - $objects = scandir( $dir ); - foreach ( $objects as $object ) { - if ( $object != "." && $object != ".." ) { - if ( filetype( $dir . "/" . $object ) == "dir" ) rmdir( $dir . "/" . $object ); - else unlink( $dir . "/" . $object ); - } - } - reset( $objects ); - return rmdir( $dir ); - } + $result=array_diff(scandir($dir),array('.','..')); + foreach($result as $item) + { + if(!@unlink($dir.'/'.$item)) + Plugincache::rrmdir($dir.'/'.$item); + } + return rmdir($dir); } /** @@ -267,4 +263,4 @@ class Plugincache { } return $content; } - } \ No newline at end of file + } 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 e9463b0b0..b398270e4 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 @@ -289,12 +289,13 @@ class Users{ public static function createUser($values, $user_id){ try { //make connection with and put into shard db - $values['user_id']= $user_id; $dbs = new DBLayer("shard"); $dbs->insert("user", $values); $dbr = new DBLayer("ring"); - $values['user_type'] = 'ut_pioneer'; - $dbr->insert("ring_users", $values); + $valuesRing['user_id'] =$user_id; + $valuesRing['user_name'] = $values['Login']; + $valuesRing['user_type'] = 'ut_pioneer'; + $dbr->insert("ring_users", $valuesRing); ticket_user::createTicketUser( $user_id, 1); return "ok"; } @@ -303,7 +304,7 @@ class Users{ try { $dbl = new DBLayer("lib"); $dbl->insert("ams_querycache", array("type" => "createUser", - "query" => json_encode(array($values["name"],$values["pass"],$values["mail"])), "db" => "shard")); + "query" => json_encode(array($values["Login"],$values["Password"],$values["Email"])), "db" => "shard")); ticket_user::createTicketUser( $user_id , 1 ); return "shardoffline"; }catch (PDOException $e) { @@ -472,6 +473,3 @@ class Users{ } } } - - - diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/delete_plugin.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/delete_plugin.php index 53af36157..f3dc0311a 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/func/delete_plugin.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/delete_plugin.php @@ -23,7 +23,7 @@ function delete_plugin() { if ( is_dir( "$name[FileName]" ) ) { // removing plugin directory from the code base - if ( rrmdir( "$name[FileName]" ) ) + if ( Plugincache::rrmdir( "$name[FileName]" ) ) { $db -> delete( 'plugins', array( 'id' => $id ), "Id=:id" ); @@ -45,24 +45,3 @@ function delete_plugin() { } } } - -/** - * function to remove a non empty directory - * - * @param $dir directory address - * @return boolean - */ -function rrmdir( $dir ) { - if ( is_dir( $dir ) ) { - $objects = scandir( $dir ); - foreach ( $objects as $object ) { - if ( $object != "." && $object != ".." ) { - if ( filetype( $dir . "/" . $object ) == "dir" ) rmdir( $dir . "/" . $object ); - else unlink( $dir . "/" . $object ); - } - } - reset( $objects ); - return rmdir( $dir ); - } - } - diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php b/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php index 492f67549..d020f1644 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php @@ -184,37 +184,38 @@ DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`plugins` ; CREATE TABLE IF NOT EXISTS `" . $cfg['db']['lib']['name'] ."`.`plugins` ( - `Id` INT(10) NOT NULL AUTO_INCREMENT, - `FileName VARCHAR(255) NOT NULL, + `Id` INT(10) NOT NULL AUTO_INCREMENT, + `FileName` VARCHAR(255) NOT NULL, `Name` VARCHAR(11) NOT NULL, `Type` VARCHAR(12) NOT NULL, `Owner` VARCHAR(25) NOT NULL, `Permission` VARCHAR(5) NOT NULL, `Status` INT(11) NOT NULL DEFAULT 0, `Weight` INT(11) NOT NULL DEFAULT 0, - `Info` TEXT NULL DEFAULT NULL, + `Info` TEXT NULL DEFAULT NULL, PRIMARY KEY (`Id`) ) ENGINE = InnoDB; + -- ----------------------------------------------------- -- Table `" . $cfg['db']['lib']['name'] ."`.`updates` -- ----------------------------------------------------- DROP TABLE IF EXISTS `" . $cfg['db']['lib']['name'] ."`.`updates` ; CREATE TABLE IF NOT EXISTS `" . $cfg['db']['lib']['name'] ."`.`updates` ( - `s.no` int(10) NOT NULL AUTO_INCREMENT, - `PluginId` int(10) DEFAULT NULL, - `UpdatePath` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `UpdateInfo` text COLLATE utf8_unicode_ci, - PRIMARY KEY (`s.no`), - KEY `PluginId` (`PluginId`)) - ENGINE=InnoDB; - - -- ----------------------------------------- - -- Constraints for table `updates` - -- ----------------------------------------- - ALTER TABLE `" . $cfg['db']['lib']['name'] ."`.`updates` - ADD CONSTRAINT `updates_ibfk_1` FOREIGN KEY (`PluginId`) REFERENCES `plugins` (`Id`); + `s.no` int(10) NOT NULL AUTO_INCREMENT, + `PluginId` int(10) DEFAULT NULL, + `UpdatePath` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `UpdateInfo` text COLLATE utf8_unicode_ci, + PRIMARY KEY (`s.no`), + KEY `PluginId` (`PluginId`)) + ENGINE=InnoDB; + + -- ----------------------------------------- + -- Constraints for table `updates` + -- ----------------------------------------- + ALTER TABLE `" . $cfg['db']['lib']['name'] ."`.`updates` + ADD CONSTRAINT `updates_ibfk_1` FOREIGN KEY (`PluginId`) REFERENCES `plugins` (`Id`); -- ----------------------------------------------------- @@ -1772,14 +1773,14 @@ //Now create an admin account! $hashpass = crypt("admin", Users::generateSALT()); $params = array( - 'name' => "admin", - 'pass' => $hashpass, - 'mail' => "admin@admin.com", + 'Login' => "admin", + 'Password' => $hashpass, + 'Email' => "admin@admin.com", ); try{ - $user_id = WebUsers::createWebuser($params['name'], $params['pass'],$params['mail']); + $user_id = WebUsers::createWebuser($params['Login'], $params['Password'],$params['Email']); $result = Webusers::createUser($params, $user_id); - Users::createPermissions(array($params['name'])); + Users::createPermissions(array($params['Login'])); $dbl = new DBLayer("lib"); $dbl->execute("UPDATE ticket_user SET Permission = 3 WHERE TUserId = :user_id",array('user_id' => $user_id)); print "The admin account is created, you can login with id: admin, pass: admin!"; @@ -1802,5 +1803,5 @@ print "There was an error while installing"; print_r($e); } - } - + } + diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_user.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_user.tpl index 301af12b6..4b452962a 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_user.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_user.tpl @@ -5,6 +5,7 @@
  • Settings
  • Create New Ticket
  • + {if isset($hook_info)} {foreach from=$hook_info item=element}
  • {$element.menu_display}
  • {/foreach}{/if}
  • Logout
  • {/block} From 3b3a595903407cc3a1e00b6a4a7e3e817f8d5935 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Sat, 26 Jul 2014 00:27:57 +0530 Subject: [PATCH 23/36] bug fix: added template path option in .info file --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ams_lib/autoload/plugincache.php | 39 ++++++++++--------- .../www/html/templates/layout_admin.tpl | 2 +- .../www/html/templates/layout_mod.tpl | 1 + .../www/html/templates/layout_plugin.tpl | 4 +- .../www/html/templates/layout_user.tpl | 2 +- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php index ae8f1129c..c90665bc1 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/plugincache.php @@ -1,8 +1,8 @@ - $value ) { $plugin_path = Plugincache :: pluginInfoUsingId( $value['Id'], 'FileName' ); - $pluginName = Plugincache :: pluginInfoUsingId( $value['Id'], 'Name' ); + $template_path = json_decode( Plugincache :: pluginInfoUsingId( $value['Id'], 'Info' ) ) -> TemplatePath; + $plugin_name = explode( '/', $plugin_path )[4]; // calling hooks in the $pluginName.php - include $plugin_path . '/' . strtolower( $pluginName ) . '.php'; + include $plugin_path . '/' . $plugin_name . '.php'; $arr = get_defined_functions(); foreach( $arr['user'] as $key => $value ) { - if ( stristr( $value, strtolower( $pluginName ) ) == true ) + if ( stristr( $value, $plugin_name ) == true ) { - $content['hook_info'][$pluginName] = call_user_func( $value ); + $content['hook_info'][$plugin_name] = call_user_func( $value ); } } - } + // path for the template + $content['hook_info'][$plugin_name]['TemplatePath'] = $template_path; + } + return $content; } - } + } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_admin.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_admin.tpl index a0d1e49ef..db83dc8be 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_admin.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_admin.tpl @@ -10,7 +10,7 @@
  • Support Groups
  • Plugins
  • - {if isset($hook_info)} {foreach from=$hook_info item=element}
  • {$element.menu_display}
  • {/foreach}{/if} + {if isset($hook_info)} {foreach from=$hook_info key=arrkey item=element}
  • {$element.menu_display}
  • {/foreach}{/if}
  • Syncing
  • Logout
  • {/block} diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_mod.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_mod.tpl index e0a77d99a..cffdfdb5a 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_mod.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_mod.tpl @@ -6,6 +6,7 @@
  • Settings
  • Users
  • + {if isset($hook_info)} {foreach from=$hook_info key=arrkey item=element}
  • {$element.menu_display}
  • {/foreach}{/if}
  • Queues
  • Support Groups
  • diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_plugin.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_plugin.tpl index 5bc5938c4..9fb68400a 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_plugin.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_plugin.tpl @@ -1,8 +1,8 @@ {block name=content}
    {if isset($hook_info)} -{foreach from=$hook_info item=element} -{if $element.menu_display eq $smarty.get.name} +{foreach from=$hook_info key=arrkey item=element} +{if $arrkey eq $smarty.get.name} {include file=$element.template_path} {/if} {/foreach} diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_user.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_user.tpl index 4b452962a..57aad4c8b 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_user.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_user.tpl @@ -5,7 +5,7 @@
  • Settings
  • Create New Ticket
  • - {if isset($hook_info)} {foreach from=$hook_info item=element}
  • {$element.menu_display}
  • {/foreach}{/if} + {if isset($hook_info)} {foreach from=$hook_info key=arrkey item=element}
  • {$element.menu_display}
  • {/foreach}{/if}
  • Logout
  • {/block} From ce53f5f26c083d828abd60fd4a66d568d3209309 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Fri, 1 Aug 2014 16:01:35 +0530 Subject: [PATCH 24/36] API key management calender --HG-- branch : Gsoc14-ryzomAppImprovements --- .../server/ryzom_ams/www/html/templates/layout.tpl | 11 ++++++++++- .../ryzom_ams/www/html/templates/layout_plugin.tpl | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout.tpl index 9cd01cda8..69b99dbac 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout.tpl @@ -235,7 +235,16 @@ _("status").innerHTML = "upload Aborted"; } - + + + + + + diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_plugin.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_plugin.tpl index 9fb68400a..1a84ff3bf 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_plugin.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_plugin.tpl @@ -3,7 +3,7 @@ {if isset($hook_info)} {foreach from=$hook_info key=arrkey item=element} {if $arrkey eq $smarty.get.name} -{include file=$element.template_path} +{include file=$element.TemplatePath} {/if} {/foreach} {/if} From 204a5b8a184e0ee651af48dcdbb52a14859d7708 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Mon, 4 Aug 2014 14:05:11 +0530 Subject: [PATCH 25/36] rest api using curl --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ryzom_ams/ams_lib/autoload/rest_api.php | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/rest_api.php diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/rest_api.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/rest_api.php new file mode 100644 index 000000000..8dba944b5 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/rest_api.php @@ -0,0 +1,52 @@ + Date: Mon, 11 Aug 2014 22:57:08 +0530 Subject: [PATCH 26/36] Adding activated plugins to the main options list --HG-- branch : Gsoc14-ryzomAppImprovements --- .../server/ryzom_ams/www/html/templates/layout_admin.tpl | 2 +- .../tools/server/ryzom_ams/www/html/templates/layout_mod.tpl | 2 +- .../tools/server/ryzom_ams/www/html/templates/layout_user.tpl | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_admin.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_admin.tpl index db83dc8be..54307b5bc 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_admin.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_admin.tpl @@ -4,13 +4,13 @@
  • Dashboard
  • Profile
  • Settings
  • + {if isset($hook_info)} {foreach from=$hook_info key=arrkey item=element}
  • {$element.menu_display}
  • {/foreach}{/if}
  • Users
  • Queues
  • Support Groups
  • Plugins
  • - {if isset($hook_info)} {foreach from=$hook_info key=arrkey item=element}
  • {$element.menu_display}
  • {/foreach}{/if}
  • Syncing
  • Logout
  • {/block} diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_mod.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_mod.tpl index cffdfdb5a..e4fbdcc69 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_mod.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_mod.tpl @@ -4,9 +4,9 @@
  • Dashboard
  • Profile
  • Settings
  • + {if isset($hook_info)} {foreach from=$hook_info key=arrkey item=element}
  • {$element.menu_display}
  • {/foreach}{/if}
  • Users
  • - {if isset($hook_info)} {foreach from=$hook_info key=arrkey item=element}
  • {$element.menu_display}
  • {/foreach}{/if}
  • Queues
  • Support Groups
  • diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_user.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_user.tpl index 57aad4c8b..e70b7c164 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_user.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_user.tpl @@ -3,9 +3,9 @@
  • Profile
  • Settings
  • - -
  • Create New Ticket
  • {if isset($hook_info)} {foreach from=$hook_info key=arrkey item=element}
  • {$element.menu_display}
  • {/foreach}{/if} + +
  • Create New Ticket
  • Logout
  • {/block} From 70e8310fff9fd8ca01e72f9a087f7ffe5f1c4a71 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Tue, 12 Aug 2014 00:23:48 +0530 Subject: [PATCH 27/36] added API key mangement and Achievements plugin during installation of ams --HG-- branch : Gsoc14-ryzomAppImprovements --- .../tools/server/ryzom_ams/www/html/installer/libsetup.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php b/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php index d020f1644..c93310c55 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php @@ -196,6 +196,10 @@ PRIMARY KEY (`Id`) ) ENGINE = InnoDB; + INSERT INTO `plugins` (`Id`, `FileName`, `Name`, `Type`, `Owner`, `Permission`, `Status`, `Weight`, `Info`) VALUES +(1, '../../ams_lib/plugins/API_key_management', 'API_key_management', 'automatic', '', 'admin', 1, 0, '{\"PluginName\":\"API Key Management\",\"Description\":\"Provides public access to the API''s by generating access tokens.\",\"Version\":\"1.0.0\",\"Type\":\"automatic\",\"TemplatePath\":\"..\\/..\\/..\\/ams_lib\\/plugins\\/API_key_management\\/templates\\/index.tpl\",\"\":null}'), +(2, '../../ams_lib/plugins/Achievements', 'Achievements', 'Manual', '', 'admin', 1, 0, '{\"PluginName\":\"Achievements\",\"Description\":\"Returns the achivements of a user with respect to the character =.\",\"Version\":\"1.0.0\",\"TemplatePath\":\"..\\/..\\/..\\/ams_lib\\/plugins\\/Achievements\\/templates\\/index.tpl\",\"Type\":\"Manual\",\"\":null}'); + -- ----------------------------------------------------- -- Table `" . $cfg['db']['lib']['name'] ."`.`updates` @@ -1804,4 +1808,3 @@ print_r($e); } } - From 0d8fe2b7aa92c6b4117ded01177e906d8e9386cf Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Tue, 12 Aug 2014 00:33:11 +0530 Subject: [PATCH 28/36] Achievements plugin integrated with ams --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ams_lib/plugins/Achievements/.info | 8 + .../plugins/Achievements/Achievements.php | 142 ++++++++++++++++++ .../plugins/Achievements/templates/index.tpl | 73 +++++++++ 3 files changed, 223 insertions(+) create mode 100644 code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/.info create mode 100644 code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/Achievements.php create mode 100644 code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/templates/index.tpl diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/.info b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/.info new file mode 100644 index 000000000..238e98922 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/.info @@ -0,0 +1,8 @@ +PluginName = Achievements +Description = Returns the achivements of a user with respect to the character =. +Version = 1.0.0 +TemplatePath = ../../../ams_lib/plugins/Achievements/templates/index.tpl +Type = Manual + + + diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/Achievements.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/Achievements.php new file mode 100644 index 000000000..943981680 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/Achievements.php @@ -0,0 +1,142 @@ + select( 'ams_api_keys', $data , 'User = :User AND UserCharacter = :UserCharacter' ); + $row = $sth -> fetchAll(); + + return $row; + + } + +/** + * Local Hook to set variables which contains + * the content to use during the plugin functionality. + */ +function hook_variable_set() + { + global $var_set; + $var_set['character'] = $_POST['Character']; + + // get db content for variable set + $row = hook_get_db_content( array( 'User' => $_SESSION['user'], 'UserCharacter' => $var_set['character'] ) ); + + // access key automatically taken from the database wrt user and character + @$var_set['app_key'] = $row['AccessToken']; + + // here you can set the host where this plugin is set + $var_set['host'] = 'localhost'; + + // here you can set what you are looking for + // when you are requesting encoded in json + @$var_set['items'] = json_encode( array( 'Task' => 'Achievements', 'Character' => $var_set['character'] ) ); + + // url where we have to make request for achievements + // it sends get parameter search(what to search) and format(in which format data exchange takes place) + $var_set['url'] = 'app.domain.org?search=' . $var_set['items'] . '&&format=json'; + + } + +/** + * Global Hook to interact with the REST api + * Pass the variables in the REST object to + * make request + * + * variables REST object expects + * url --> on which request is to be made + * appkey --> app key for authentication + * host --> host from which request have been sent + * + * @return $return_set global array returns the template data + */ +function achievements_hook_call_rest() + { + // defined the variables + global $var_set; + global $return_set; + + if ( isset( $_POST['get_data'] ) ) + { + hook_variable_set(); + + $rest_api = new Rest_Api(); + $ach_data = $rest_api -> request( $var_set['url'], $var_set['app_key'], $var_set['host'] ); + print_r( $ach_data ); + + $return_set['char_achievements'] = json_decode( $ach_data ); + } + } + +/** + * Global Hook to return global variables which contains + * the content to use in the smarty templates extracted from + * the database + * + * @return $return_set global array returns the template data + */ +function achievements_hook_get_db() + { + global $return_set; + + $db = new DBLayer( 'lib' ); + + // getting content for selecting characters + $sth = $db -> selectWithParameter( 'UserCharacter', 'ams_api_keys', array( 'User' => $_SESSION['user'] ) , 'User = :User' ); + $row = $sth -> fetchAll(); + $retur_set['Character'] = $row; + + } + +/** + * Global Hook to return global variables which contains + * the content to use in the smarty templates + * + * @return $return_set global array returns the template data + */ +function achievements_hook_return_global() + { + global $return_set; + return $return_set; + + } diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/templates/index.tpl b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/templates/index.tpl new file mode 100644 index 000000000..a83acd359 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/templates/index.tpl @@ -0,0 +1,73 @@ +{block name=content} + +{if isset($smarty.get.plugin_action) and $smarty.get.plugin_action eq 'get_achievements'} +
    +
    +
    +

    Achievements

    +
    + + + +
    +
    + + {if isset($smarty.get.success) and $smarty.get.success eq '1'}

    Key added successfully

    {/if} + {if isset($smarty.get.success) and $smarty.get.success eq '2'}

    Key deleted successfully

    {/if} +
    +
    + {$hook_info.Achievements.char_achievements} +
    +
    +
    +
    +{else} +
    +
    +
    +

    Achievements

    +
    + + + +
    +
    +
    +
    +

    Select your Character

    +
    + + +
    +
    +
    +
    + + +
    +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    +
    +
    +
    +
    + + {/if} +{/block} From acb4f26f1a29c86c5f430f817bd24c469cebdd47 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Tue, 12 Aug 2014 00:33:58 +0530 Subject: [PATCH 29/36] API key management plugin for ams --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ams_lib/plugins/API_key_management/.info | 8 + .../API_key_management/API_key_management.php | 206 ++++++++++++++++++ .../API_key_management/generate_key.php | 53 +++++ .../API_key_management/templates/gen_key.tpl | 46 ++++ .../API_key_management/templates/index.tpl | 133 +++++++++++ 5 files changed, 446 insertions(+) create mode 100644 code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/.info create mode 100644 code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/API_key_management.php create mode 100644 code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/generate_key.php create mode 100644 code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/templates/gen_key.tpl create mode 100644 code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/templates/index.tpl diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/.info b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/.info new file mode 100644 index 000000000..b185a31db --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/.info @@ -0,0 +1,8 @@ +PluginName = API Key Management +Description = Provides public access to the API's by generating access tokens. +Version = 1.0.0 +Type = automatic +TemplatePath = ../../../ams_lib/plugins/API_key_management/templates/index.tpl + + + diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/API_key_management.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/API_key_management.php new file mode 100644 index 000000000..1676f243a --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/API_key_management.php @@ -0,0 +1,206 @@ + executeWithoutParams( $sql ); + } + +/** + * Hook to store data to database which is sent as post + * method from the forms in this plugin + * It also calls the local hook + */ +function api_key_management_hook_store_db() + { + global $var_set; + global $return_set; + + // if the form been submited move forward + if ( @hook_validate( $_POST['gen_key'] ) ) { + + // local hook to validate the POST variables + hook_variables(); + + // if validation successfull move forward + if ( $return_set['gen_key_validate'] == 'true' && $_GET['plugin_action'] == 'generate_key' ) + { + // this part generated the access token + include 'generate_key.php'; + $var_set['AccessToken'] = generate_key :: randomToken( 56, false, true, false ); + + // database connection + $db = new DBLayer( 'lib' ); + // insert the form data to the database + $db -> insert( 'ams_api_keys', $var_set ); + + // redirect to the the main page with success code + // 1 refers to the successfull addition of key to the database + header( "Location: index.php?page=layout_plugin&&name=API_key_management&&success=1" ); + exit; + } + } + } + +/** + * Global Hook to load the data from db and set it + * into the global array to return it to the template + */ +function api_key_management_hook_load_db() + { + global $var_set; + global $return_set; + + $db = new DBLayer( 'lib' ); + + // returns the regestered keys + $sth = $db -> select( 'ams_api_keys', array( 'user' => $_SESSION['user'] ), 'User = :user' ); + $row = $sth -> fetchAll(); + $return_set['api_keys'] = $row; + + // returns the characters with respect to the user id in the ring_tool->characters + $db = new DBLayer( 'ring' ); + $sth = $db -> selectWithParameter( 'char_name', 'characters' , array(), '1' ); + $row = $sth -> fetchAll(); + $return_set['characters'] = $row; + + } + +/** + * Global Hook to update or delete the data from db + */ +function api_key_management_hook_update_db() + { + global $var_set; + global $return_set; + + $db = new DBLayer( 'lib' ); + if ( isset( $_GET['delete_id'] ) ) + { + // removes the registered key using get variable which contains the id of the registered key + $db -> delete( 'ams_api_keys', array( 'SNo' => $_GET['delete_id'] ), 'SNo = :SNo' ); + + // redirecting to the API_key_management plugins template with success code + // 2 refers to the succssfull delete condition + header( "Location: index.php?page=layout_plugin&&name=API_key_management&&success=2" ); + exit; + } + + } + +/** + * Global Hook to return global variables which contains + * the content to use in the smarty templates + * + * @return $return_set global array returns the template data + */ +function api_key_management_hook_return_global() + { + global $return_set; + return $return_set; + + } diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/generate_key.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/generate_key.php new file mode 100644 index 000000000..1ddfab7ed --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/generate_key.php @@ -0,0 +1,53 @@ + 2, 2 => 8, 3 => 10, 4 => 16, 5 => 10 ); + if ( !is_array( $chars ) ) { + $chars = array_unique( str_split( $chars ) ); + } + if ( $standardChars ) { + $chars = array_merge( $chars, range( 48, 57 ), range( 65, 90 ), range( 97, 122 ) ); + } + if ( $specialChars ) { + $chars = array_merge( $chars, range( 33, 47 ), range( 58, 64 ), range( 91, 96 ), range( 123, 126 ) ); + } + array_walk( $chars, function( &$val ) { + if ( !is_int( $val ) ) { + $val = ord( $val ); } + } + ); + if ( is_int( $len ) ) { + while ( $len ) { + $tmp = ord( openssl_random_pseudo_bytes( 1 ) ); + if ( in_array( $tmp, $chars ) ) { + if ( !$output || !in_array( $output, range( 1, 5 ) ) || $output == 3 || $output == 5 ) { + $out .= ( $output == 3 ) ? $tmp : chr( $tmp ); + } + else { + $based = base_convert( $tmp, 10, $outputMap[$output] ); + $out .= ( ( ( $output == 1 ) ? '00' : ( ( $output == 4 ) ? '0x' : '' ) ) . ( ( $output == 2 ) ? sprintf( '%03d', $based ) : $based ) ); + } + $len--; + } + } + } + return ( empty( $out ) ) ? false : $out; + } + } diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/templates/gen_key.tpl b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/templates/gen_key.tpl new file mode 100644 index 000000000..1ab283449 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/templates/gen_key.tpl @@ -0,0 +1,46 @@ +
    +
    +
    +

    API KEY management

    +
    + + + +
    +
    +
    +
    +

    Generate Access Key

    +
    + + +
    +
    +
    +
    +
    + Generate Key + +
    + +
    +
    + + +
    +
    +
    +
    + +
    + +
    +
    +
    +
    +
    +
    +
    +
    + + diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/templates/index.tpl b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/templates/index.tpl new file mode 100644 index 000000000..eac902aae --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/templates/index.tpl @@ -0,0 +1,133 @@ +{block name=content} + +{if isset($smarty.get.plugin_action) and $smarty.get.plugin_action eq 'generate_key'} +
    +
    +
    +

    API KEY management

    +
    + + + +
    +
    +
    +
    +

    Generate Access Key

    +
    + + +
    +
    +
    +
    +
    + Generate Key + +
    + +
    +
    + + +
    +
    +
    + +
    + +
    + +
    +
    +
    + +
    + +
    +
    + +
    + +
    +
    + + +
    +
    +
    + +
    + +
    + +
    +
    +
    +
    +
    +
    +
    +
    +{else} +
    +
    +
    +

    API KEY management

    +
    + + + +
    +
    + + + {if isset($hook_info.API_key_management['gen_key_validate']) and $hook_info.API_key_management['gen_key_validate'] eq 'false' }

    Please enter all the fields

    {/if} + {if isset($smarty.get.success) and $smarty.get.success eq '1'}

    Key added successfully

    {/if} + {if isset($smarty.get.success) and $smarty.get.success eq '2'}

    Key deleted successfully

    {/if} +
    + +
    +
    +
    +

    All the keys you have generated will be shown and you can customize from here.

    + + + + + + + + + + + + + + {foreach from=$hook_info.API_key_management.api_keys item=element} + + + + + + + + {/foreach} + + + +
    NameTypeCharacterAccess KeyExpiresActions
    {$element.FrName}{$element.UserType}{$element.UserCharacter}{$element.AccessToken}{$element.ExpiryDate} +
    +
    +
    +
    +
    + {/if} +{/block} From 0e4b004978aa32504a7a88c15b5ded556b36adb2 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Tue, 12 Aug 2014 12:46:22 +0530 Subject: [PATCH 30/36] Bug Fix: delete plugin option available for inactive plugins --HG-- branch : Gsoc14-ryzomAppImprovements --- .../tools/server/ryzom_ams/www/html/templates/plugins.tpl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl index 73f88d1a2..6d864c818 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/plugins.tpl @@ -45,8 +45,10 @@ {$element.plugin_info->Description} {$element.plugin_type} {$element.plugin_permission} - - {if ($element.plugin_status) eq "0"}{/if} + + {if ($element.plugin_status) eq "0"} + + {/if} {if ($element.plugin_status) eq "1"}{/if} {/foreach} From ac980adcc70cede5f806df693ae502d8b495e052 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Wed, 13 Aug 2014 12:57:30 +0530 Subject: [PATCH 31/36] Added few more options in REST api --HG-- branch : Gsoc14-ryzomAppImprovements --- .../ryzom_ams/ams_lib/autoload/rest_api.php | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/rest_api.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/rest_api.php index 8dba944b5..91607292c 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/rest_api.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/rest_api.php @@ -43,10 +43,27 @@ class Rest_Api { // Execute cURL on the session handle $response = curl_exec( $session ); - return $response; + if ( curl_errno( $session ) ) { + // if request is not sent + die( 'Couldn\'t send request: ' . curl_error( $session ) ); + } else { + // check the HTTP status code of the request + $resultStatus = curl_getinfo( $session, CURLINFO_HTTP_CODE ); + if ( $resultStatus == 200 ) { + // everything went fine return response + return $response; + + } else { + // the request did not complete as expected. common errors are 4xx + // (not found, bad request, etc.) and 5xx (usually concerning + // errors/exceptions in the remote script execution) + die( 'Request failed: HTTP status code: ' . $resultStatus ); + } + } + curl_close( $session ); } else { return null; } } - } + } From 5fd2615f0e07ee2d205dcb968752d6dffa873ef2 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Wed, 13 Aug 2014 18:32:13 +0530 Subject: [PATCH 32/36] small bug fix: support group missing brackets at end --HG-- branch : Gsoc14-ryzomAppImprovements --- .../server/ryzom_ams/ams_lib/autoload/support_group.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/support_group.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/support_group.php index 7b8a864d4..d482a842f 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/support_group.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/support_group.php @@ -305,7 +305,7 @@ class Support_Group{ */ public function create() { $dbl = new DBLayer("lib"); - $dbl->insert("support_group", Array('Name' => $this->getName(), 'Tag' => $this->getTag(), 'GroupEmail' => $this->getGroupEmail(), 'IMAP_MailServer' => $this->getIMAP_MailServer(), 'IMAP_Username' => $this->getIMAP_Username(), 'IMAP_Password' => $this->getIMAP_Password()); + $dbl->insert("support_group", Array('Name' => $this->getName(), 'Tag' => $this->getTag(), 'GroupEmail' => $this->getGroupEmail(), 'IMAP_MailServer' => $this->getIMAP_MailServer(), 'IMAP_Username' => $this->getIMAP_Username(), 'IMAP_Password' => $this->getIMAP_Password())); } @@ -327,7 +327,7 @@ class Support_Group{ */ public function update(){ $dbl = new DBLayer("lib"); - $dbl->update("`support_group`", Array('Name' => $this->getName(), 'Tag' => $this->getTag(), 'GroupEmail' => $this->getGroupEmail(), 'IMAP_MailServer' => $this->getIMAP_MailServer(), 'IMAP_Username' => $this->getIMAP_Username(), 'IMAP_password' => $this->getIMAP_Password(), "`SGroupId` = $this->getSGroupId()"); + $dbl->update("`support_group`", Array('Name' => $this->getName(), 'Tag' => $this->getTag(), 'GroupEmail' => $this->getGroupEmail(), 'IMAP_MailServer' => $this->getIMAP_MailServer(), 'IMAP_Username' => $this->getIMAP_Username(), 'IMAP_password' => $this->getIMAP_Password(), "`SGroupId` = $this->getSGroupId()")); } @@ -337,7 +337,7 @@ class Support_Group{ */ public function delete(){ $dbl = new DBLayer("lib"); - $dbl->delete("`support_group`", Array('id' => $this->getSGroupId(), "`SGroupId` = :id"); + $dbl->delete("`support_group`", Array('id' => $this->getSGroupId(), "`SGroupId` = :id")); } ////////////////////////////////////////////Getters//////////////////////////////////////////////////// From f8a92326edc0b3a4c885523c8c2929db367a0511 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Thu, 14 Aug 2014 22:20:05 +0530 Subject: [PATCH 33/36] BugFixes: achievements and API key management plugins --HG-- branch : Gsoc14-ryzomAppImprovements --- .../API_key_management/API_key_management.php | 47 +++--- .../API_key_management/templates/index.tpl | 2 +- .../plugins/Achievements/Achievements.php | 146 ++++++++++++------ .../plugins/Achievements/templates/index.tpl | 8 +- .../ryzom_ams/www/html/installer/libsetup.php | 2 +- 5 files changed, 134 insertions(+), 71 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/API_key_management.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/API_key_management.php index 1676f243a..27613e18b 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/API_key_management.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/API_key_management.php @@ -11,11 +11,13 @@ * @author shubham meena mentored by Matthew Lagoe */ - -// Global variables to store the data +// Global variable to store the data which is +// returned to the templates $return_set = array(); -$var_set = array(); +// Local variable to store data during +// functionalities of the hooks +$var_set = array(); /** * Display hook for api key management @@ -28,7 +30,7 @@ function api_key_management_hook_display() } /** - * Hook to validate the posted data + * Local Hook to validate the posted data */ function hook_validate( $var ) { @@ -70,9 +72,9 @@ function hook_variables() /** * Global Hook to create table of the API_key_management - * if not created.Contains the sql code + * if not created. + * Contains the sql code */ - function api_key_management_hook_create_tb() { $dbl = new DBLayer( "lib" ); @@ -157,18 +159,25 @@ function api_key_management_hook_load_db() $db = new DBLayer( 'lib' ); - // returns the regestered keys - $sth = $db -> select( 'ams_api_keys', array( 'user' => $_SESSION['user'] ), 'User = :user' ); - $row = $sth -> fetchAll(); - $return_set['api_keys'] = $row; - - // returns the characters with respect to the user id in the ring_tool->characters - $db = new DBLayer( 'ring' ); - $sth = $db -> selectWithParameter( 'char_name', 'characters' , array(), '1' ); - $row = $sth -> fetchAll(); - $return_set['characters'] = $row; - - } + if ( isset( $_SESSION['user'] ) ) + { + // returns the registered keys + $sth = $db -> select( 'ams_api_keys', array( 'user' => $_SESSION['user'] ), 'User = :user' ); + $row = $sth -> fetchAll(); + $return_set['api_keys'] = $row; + + // fetch the character from the array to compare + $com = array_column( $return_set['api_keys'], 'UserCharacter' ); + + // returns the characters with respect to the user id in the ring_tool->characters + $db = new DBLayer( 'ring' ); + $sth = $db -> selectWithParameter( 'char_name', 'characters' , array(), '1' ); + $row = $sth -> fetch(); + + // loop through the character list and remove the character if already have an api key + $return_set['characters'] = array_diff( $row, $com ); + } + } /** * Global Hook to update or delete the data from db @@ -189,7 +198,6 @@ function api_key_management_hook_update_db() header( "Location: index.php?page=layout_plugin&&name=API_key_management&&success=2" ); exit; } - } /** @@ -202,5 +210,4 @@ function api_key_management_hook_return_global() { global $return_set; return $return_set; - } diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/templates/index.tpl b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/templates/index.tpl index eac902aae..1f6fea336 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/templates/index.tpl +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/API_key_management/templates/index.tpl @@ -48,7 +48,7 @@
    diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/Achievements.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/Achievements.php index 943981680..79c117893 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/Achievements.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/Achievements.php @@ -15,10 +15,13 @@ */ -// Global variables to store the data +// Global variable to store the data which is +// returned to the templates $return_set = array(); -$var_set = array(); +// Local variable to store data during +// functionalities of the hooks +$var_set = array(); /** * Display hook for Achievements plugin @@ -28,26 +31,64 @@ function achievements_hook_display() global $return_set; // to display plugin name in menu bar $return_set['menu_display'] = 'Achievements'; - } + } /** * Local Hook to get database content * which is called by the global hook * by passing a parameter * + * This hook returns the api keys registerd with + * the logged in user + * * @param $data array with respective information * @return $row extracted db content wrt $data */ function hook_get_db_content( $data ) { - $db = new DBLayer( 'lib' ); - $sth = $db -> select( 'ams_api_keys', $data , 'User = :User AND UserCharacter = :UserCharacter' ); $row = $sth -> fetchAll(); - return $row; - + } + +/** + * Local Hook to get database content + * which is called by the global hook + * by passing a parameter + * + * This hook returns the id of the character + * whose achivements we have to get + * + * @param $data array with respective information + * @return $row extracted db content wrt $data + */ +function hook_get_char_id( $data ) + { + // returns the character id with respect to the character name in the ring_tool->characters + $db = new DBLayer( 'ring' ); + $sth = $db -> selectWithParameter( 'char_id', 'characters' , array( 'char_name' => $data ), 'char_name=:char_name' ); + $row = $sth -> fetch(); + return $row['char_id']; + } + +/** + * Local Hook to get database content + * which is called by the global hook + * by passing a parameter + * + * Hook to get the player stats of the character + * + * @param $data array with respective information + * @return $row extracted db content wrt $data + */ +function hook_get_player_stat( $data ) + { + // returns the character id with respect to the character name in the ring_tool->characters + $db = new DBLayer( 'webig' ); + $sth = $db -> select( 'players' , array( 'name' => $data ), 'name=:name' ); + $row = $sth -> fetch(); + return $row; } /** @@ -56,27 +97,44 @@ function hook_get_db_content( $data ) */ function hook_variable_set() { - global $var_set; - $var_set['character'] = $_POST['Character']; - - // get db content for variable set - $row = hook_get_db_content( array( 'User' => $_SESSION['user'], 'UserCharacter' => $var_set['character'] ) ); - - // access key automatically taken from the database wrt user and character - @$var_set['app_key'] = $row['AccessToken']; - - // here you can set the host where this plugin is set - $var_set['host'] = 'localhost'; - - // here you can set what you are looking for - // when you are requesting encoded in json - @$var_set['items'] = json_encode( array( 'Task' => 'Achievements', 'Character' => $var_set['character'] ) ); - - // url where we have to make request for achievements - // it sends get parameter search(what to search) and format(in which format data exchange takes place) - $var_set['url'] = 'app.domain.org?search=' . $var_set['items'] . '&&format=json'; - - } + global $return_set; + global $var_set; + if ( isset( $_POST['Character'] ) && !empty( $_POST['Character'] ) ) + { + $var_set['character'] = $_POST['Character']; + + // get char id from ring_open table + if ( $var_set['character'] != 'All Characters' ) + { + $var_set['char_id'] = hook_get_char_id( $var_set['character'] ); + + } + + // get db content for variable set + $row = hook_get_db_content( array( 'User' => $_SESSION['user'], 'UserCharacter' => $var_set['character'] ) ); + + // access key automatically taken from the database wrt user and character + @$var_set['app_key'] = $row['AccessToken']; + + // here you can set the host where this plugin is set + $var_set['host'] = 'localhost'; + + // here we get the stats of the character + $ref_set = hook_get_player_stat( $var_set['character'] ); + + // here we have set items that are required to get the achivements + // these are player stats from webig->players table + @$var_set['items'] = json_encode( array( 'dev_shard' => $ref_set['dev_shard'] , 'name' => $ref_set['name'] , 'cid' => $ref_set['cid'] , 'lang' => 'en' , 'translater_mode' => '', 'last_played_date' => $ref_set['last_login'] ) ); + + // url where we have to make request for achievements + // it sends get parameter search(what to search) and format(in which format data exchange takes place) + $var_set['url'] = 'http://localhost6/?search=achievements&&format=json'; + } + else + { + $return_set['no_char'] = "Please Generate key for a character before requesting for achievements"; + } + } /** * Global Hook to interact with the REST api @@ -99,12 +157,11 @@ function achievements_hook_call_rest() if ( isset( $_POST['get_data'] ) ) { hook_variable_set(); - - $rest_api = new Rest_Api(); - $ach_data = $rest_api -> request( $var_set['url'], $var_set['app_key'], $var_set['host'] ); - print_r( $ach_data ); - - $return_set['char_achievements'] = json_decode( $ach_data ); + // here we make the REST connection + $rest_api = new Rest_Api(); + $ach_data = $rest_api -> request( $var_set['url'], $var_set['app_key'], $var_set['host'], $var_set['items'] ); + // here we store the response we get from the server + $return_set['char_achievements'] = $ach_data ; } } @@ -119,14 +176,16 @@ function achievements_hook_get_db() { global $return_set; - $db = new DBLayer( 'lib' ); - - // getting content for selecting characters - $sth = $db -> selectWithParameter( 'UserCharacter', 'ams_api_keys', array( 'User' => $_SESSION['user'] ) , 'User = :User' ); - $row = $sth -> fetchAll(); - $retur_set['Character'] = $row; - - } + if ( isset( $_SESSION['user'] ) ) + { + $db = new DBLayer( 'lib' ); + + // getting content for selecting characters + $sth = $db -> selectWithParameter( 'UserCharacter', 'ams_api_keys', array( 'User' => $_SESSION['user'] ) , 'User = :User' ); + $row = $sth -> fetch(); + $return_set['Character'] = $row; + } + } /** * Global Hook to return global variables which contains @@ -138,5 +197,4 @@ function achievements_hook_return_global() { global $return_set; return $return_set; - - } + } diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/templates/index.tpl b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/templates/index.tpl index a83acd359..e33ac3590 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/templates/index.tpl +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/plugins/Achievements/templates/index.tpl @@ -11,10 +11,8 @@
    - - {if isset($smarty.get.success) and $smarty.get.success eq '1'}

    Key added successfully

    {/if} - {if isset($smarty.get.success) and $smarty.get.success eq '2'}

    Key deleted successfully

    {/if}
    + {if isset($hook_info.Achievements.no_char)}

    {$hook_info.Achievements.no_char}

    {/if}
    {$hook_info.Achievements.char_achievements}
    @@ -49,8 +47,8 @@
    diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php b/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php index c93310c55..6fb5981d3 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php @@ -198,7 +198,7 @@ INSERT INTO `plugins` (`Id`, `FileName`, `Name`, `Type`, `Owner`, `Permission`, `Status`, `Weight`, `Info`) VALUES (1, '../../ams_lib/plugins/API_key_management', 'API_key_management', 'automatic', '', 'admin', 1, 0, '{\"PluginName\":\"API Key Management\",\"Description\":\"Provides public access to the API''s by generating access tokens.\",\"Version\":\"1.0.0\",\"Type\":\"automatic\",\"TemplatePath\":\"..\\/..\\/..\\/ams_lib\\/plugins\\/API_key_management\\/templates\\/index.tpl\",\"\":null}'), -(2, '../../ams_lib/plugins/Achievements', 'Achievements', 'Manual', '', 'admin', 1, 0, '{\"PluginName\":\"Achievements\",\"Description\":\"Returns the achivements of a user with respect to the character =.\",\"Version\":\"1.0.0\",\"TemplatePath\":\"..\\/..\\/..\\/ams_lib\\/plugins\\/Achievements\\/templates\\/index.tpl\",\"Type\":\"Manual\",\"\":null}'); +(2, '../../ams_lib/plugins/Achievements', 'Achievements', 'Manual', '', 'admin', 0, 0, '{\"PluginName\":\"Achievements\",\"Description\":\"Returns the achivements of a user with respect to the character =.\",\"Version\":\"1.0.0\",\"TemplatePath\":\"..\\/..\\/..\\/ams_lib\\/plugins\\/Achievements\\/templates\\/index.tpl\",\"Type\":\"Manual\",\"\":null}'); -- ----------------------------------------------------- From 750ded21bd66ed56e6baabe3f8cd88d5936732b9 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Thu, 14 Aug 2014 22:25:16 +0530 Subject: [PATCH 34/36] added option for posting data in REST api --HG-- branch : Gsoc14-ryzomAppImprovements --- .../server/ryzom_ams/ams_lib/autoload/rest_api.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/rest_api.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/rest_api.php index 91607292c..74281c6f6 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/rest_api.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/rest_api.php @@ -20,7 +20,7 @@ class Rest_Api { * @param $host host for the website * @return URL response. */ - public function request( $url , $applicationKey, $host ) + public function request( $url , $applicationKey, $host , $data ) { // Check the referer is the host website $referer = $_SERVER['HTTP_REFERER']; @@ -36,10 +36,13 @@ class Rest_Api { // Set the HTTP request authentication headers $headers = array( 'AppKey: ' . $applicationKey, - 'Timestamp: ' . date( 'Ymd H:i:s', time() ) + 'Timestamp: ' . date( 'Ymd H:i:s', time() ), + 'Accept: application/json', + 'Content-Type: application/json' ); curl_setopt( $session, CURLOPT_HTTPHEADER, $headers ); - + curl_setopt( $session, CURLOPT_CUSTOMREQUEST, "POST" ); + curl_setopt( $session, CURLOPT_POSTFIELDS, $data ); // Execute cURL on the session handle $response = curl_exec( $session ); @@ -66,4 +69,4 @@ class Rest_Api { return null; } } - } + } From a01e331639f7b5bde20ccaa61b2e7d274bd1ee37 Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Fri, 15 Aug 2014 00:13:00 +0530 Subject: [PATCH 35/36] bug fix in plugin installation --HG-- branch : Gsoc14-ryzomAppImprovements --- .../tools/server/ryzom_ams/www/html/func/install_plugin.php | 6 +++--- .../tools/server/ryzom_ams/www/html/installer/libsetup.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php index 1ea950d38..052d4f14b 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/install_plugin.php @@ -220,7 +220,7 @@ function checkForUpdate( $fileName, $findPath, $tempFile, $tempPath ) // check for the version for the plugin $db = new DBLayer( "lib" ); - $sth = $db -> select( "plugins", array( ':name' => $result['PluginName'] ), "Name = :name" ); + $sth = $db -> select( "plugins", array( 'Name' => $result['PluginName'] ), "Name = :Name" ); $info = $sth -> fetch(); $info['Info'] = json_decode( $info['Info'] ); @@ -237,11 +237,11 @@ function checkForUpdate( $fileName, $findPath, $tempFile, $tempPath ) // then there MUST be an increment in the Y value. // When there is increment in the X value , Y and Z MUST be 0. // comparing if there is some change - if ( !array_intersect( $new_version , $pre_version ) ) + if ( !array_diff( $new_version , $pre_version ) ) { // removing the uploaded file Plugincache :: rrmdir( $tempPath . "/test/" . $fileName ); - return '2'; + return '2'; //plugin already exists } else { diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php b/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php index 6fb5981d3..77a5269f7 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/installer/libsetup.php @@ -186,7 +186,7 @@ CREATE TABLE IF NOT EXISTS `" . $cfg['db']['lib']['name'] ."`.`plugins` ( `Id` INT(10) NOT NULL AUTO_INCREMENT, `FileName` VARCHAR(255) NOT NULL, - `Name` VARCHAR(11) NOT NULL, + `Name` VARCHAR(56) NOT NULL, `Type` VARCHAR(12) NOT NULL, `Owner` VARCHAR(25) NOT NULL, `Permission` VARCHAR(5) NOT NULL, From ee6db8ef7f67fb9935f9554953d428e3ba72ee0a Mon Sep 17 00:00:00 2001 From: shubham_meena Date: Fri, 15 Aug 2014 00:24:31 +0530 Subject: [PATCH 36/36] code modified to accept request through Rest and sending achievments in response --HG-- branch : Gsoc14-ryzomAppImprovements --- code/web/app/app_achievements/index.php | 230 ++++++++++++++---------- 1 file changed, 139 insertions(+), 91 deletions(-) diff --git a/code/web/app/app_achievements/index.php b/code/web/app/app_achievements/index.php index 90ce612bb..9db5b991f 100644 --- a/code/web/app/app_achievements/index.php +++ b/code/web/app/app_achievements/index.php @@ -1,110 +1,158 @@ isIG()) { - require_once("include/ach_render_ig.php"); -} -else { - require_once("include/ach_render_web.php"); -} -require_once("include/ach_render_common.php"); - -require_once("class/DLL_class.php"); -#require_once("class/InDev_trait.php"); -require_once("class/Node_abstract.php"); -require_once("class/AVLTree_class.php"); -require_once("class/Parentum_abstract.php"); -require_once("class/AchList_abstract.php"); -require_once("class/Tieable_inter.php"); -require_once("class/NodeIterator_class.php"); - - -require_once("class/AchMenu_class.php"); -require_once("class/AchMenuNode_class.php"); -require_once("class/AchSummary_class.php"); -require_once("class/AchCategory_class.php"); -require_once("class/AchAchievement_class.php"); -require_once("class/AchTask_class.php"); -require_once("class/AchObjective_class.php"); - -#require_once("fb/facebook.php"); // Update user acces on Db -#$DBc = ryDB::getInstance(APP_NAME."_test"); -$DBc = ryDB::getInstance(APP_NAME); +// $DBc = ryDB::getInstance(APP_NAME."_test"); +$DBc = ryDB :: getInstance( APP_NAME ); + + +// if getting request using REST +if ( isset( $_GET['search'] ) && isset( $_GET['format'] ) ) + { + // if the format is json + if ( $_GET['format'] == 'json' ) + { + // getting the headers when the request is sent + $header = getallheaders(); + + // this block is to get the posted data + $fp = fopen( 'php://input', 'r' ); + $rawData = stream_get_contents( $fp ); + $userd = json_decode( $rawData, true ); + + // authenticate the user using data we get from server + appAuthenticateRest( $user, $userd ); + + // create a ryzom user object whose achievements we have to send in response + $_USER = new RyzomUser( $user ); + + require_once( "include/ach_render_web.php" ); + $c .= ach_render(); + $response = $c; + // sending the response + echo( $response ); + exit; + + } + } +else + { + echo 'Invalid response'; + exit; + } + + + + +// Ask to authenticate user (using ingame or session method) and fill $user with all information +ryzom_app_authenticate( $user, true ); + + +// echo var_export($user,true); +// $user['id'] = $user['char_id']; +// $user['name'] = $user['char_name']; +/** + * $user = array(); + * $user['cid'] = 1; + * $user['lang'] = 'en'; + * $user['name'] = 'Talvela'; + * $user['race'] = "r_matis"; + * $user['civilization'] = "c_neutral"; + * $user['cult'] = "c_neutral"; + * $user['ig'] = ($_REQUEST['ig']==1); + * #$user['ig'] = true; + */ + +$_USER = new RyzomUser( $user ); + + +if ( $_USER -> isIG() ) { + require_once( "include/ach_render_ig.php" ); + } +else { + require_once( "include/ach_render_web.php" ); + } + +// require_once("fb/facebook.php"); $c = ""; -if(!$_USER->isIG()) { - /*$facebook = new Facebook(array( - 'appId' => $_CONF['fb_id'], - 'secret' => $_CONF['fb_secret'], - 'cookie' => true - )); - - #code taken from facebook tutorial - - // Get the url to redirect for login to facebook - // and request permission to write on the user's wall. - $login_url = $facebook->getLoginUrl( - array('scope' => 'publish_stream') - ); - - // If not authenticated, redirect to the facebook login dialog. - // The $login_url will take care of redirecting back to us - // after successful login. - if (! $facebook->getUser()) { - $c .= ';'; - } - else { - $DBc->sqlQuery("INSERT INTO ach_fb_token (aft_player,aft_token,aft_date,aft_allow) VALUES ('".$_USER->getID()."','".$DBc->sqlEscape($facebook->getAccessToken())."','".time()."','1') ON DUPLICATE KEY UPDATE aft_token='".$DBc->sqlEscape($facebook->getAccessToken())."', aft_date='".time()."'"); - }*/ - - -} - -if(!$_USER->isIG && $_CONF['enable_webig'] == false) { - $c .= ach_render_forbidden(false); -} -elseif($_USER->isIG && $_CONF['enable_offgame'] == false) { - $c .= ach_render_forbidden(true); -} +if ( !$_USER -> isIG() ) { + /** + * $facebook = new Facebook(array( + * 'appId' => $_CONF['fb_id'], + * 'secret' => $_CONF['fb_secret'], + * 'cookie' => true + * )); + * + * #code taken from facebook tutorial + * + * // Get the url to redirect for login to facebook + * // and request permission to write on the user's wall. + * $login_url = $facebook->getLoginUrl( + * array('scope' => 'publish_stream') + * ); + * + * // If not authenticated, redirect to the facebook login dialog. + * // The $login_url will take care of redirecting back to us + * // after successful login. + * if (! $facebook->getUser()) { + * $c .= ';'; + * } + * else { + * $DBc->sqlQuery("INSERT INTO ach_fb_token (aft_player,aft_token,aft_date,aft_allow) VALUES ('".$_USER->getID()."','".$DBc->sqlEscape($facebook->getAccessToken())."','".time()."','1') ON DUPLICATE KEY UPDATE aft_token='".$DBc->sqlEscape($facebook->getAccessToken())."', aft_date='".time()."'"); + * } + */ + + + } + +if ( !$_USER -> isIG && $_CONF['enable_webig'] == false ) { + $c .= ach_render_forbidden( false ); + + } +elseif ( $_USER -> isIG && $_CONF['enable_offgame'] == false ) { + $c .= ach_render_forbidden( true ); + + } else { - $c .= ach_render(); -} + $c .= ach_render(); + } -echo ryzom_app_render(strtoupper(get_translation('ach_app_name',$_USER->getLang())), $c, $_USER->isIG()); +echo ryzom_app_render( strtoupper( get_translation( 'ach_app_name', $_USER -> getLang() ) ), $c, $_USER -> isIG() ); ?>