From 747e1deaeaf0ec847d3d9f5a44a9e63bd65908f5 Mon Sep 17 00:00:00 2001 From: Quitta Date: Mon, 19 Aug 2013 00:02:55 +0200 Subject: [PATCH] Users can specify if they want to receive or dont want to receive tickt updates! --- .../ams_lib/autoload/mail_handler.php | 40 ++++++++++------ .../tools/server/ryzom_ams/www/config.php | 10 ++-- .../ryzom_ams/www/html/autoload/webusers.php | 30 ++++++++++-- .../www/html/func/change_receivemail.php | 48 +++++++++++++++++++ .../ryzom_ams/www/html/inc/settings.php | 19 ++++---- .../server/ryzom_ams/www/html/sql/install.php | 1 + .../ryzom_ams/www/html/templates/settings.tpl | 35 ++++++++++++++ 7 files changed, 152 insertions(+), 31 deletions(-) create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/func/change_receivemail.php 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 cb101bfec..12553eb69 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 @@ -21,22 +21,32 @@ class Mail_Handler{ //if it is not forwarded (==public == which returns 0) then make it NULL which is needed to be placed in the DB. $sendingGroupId = NULL; } - if($type == "REPLY"){ - $txt = "---------- Ticket #". $ticketObj->getTId() . " ----------\n You received a new reply on your ticket: " . $ticketObj->getTitle() . - "\n --------------------\n\n"; - $subject = "New reply on [Ticket #" . $ticketObj->getTId() ."]"; - $endTxt = "\n\n----------\nYou can reply on this message to answer directly on the ticket!"; - $txt = $txt . $content . $endTxt; - self::send_mail($ticketObj->getAuthor(),$subject,$txt, $ticketObj->getTId(),$sendingGroupId); - }else if($type == "NEW"){ - $txt = "---------- Ticket #". $ticketObj->getTId() . " ----------\n Your ticket: " . $ticketObj->getTitle() . " is newly created"; - $txt = $txt . "\n --------------------\n\n"; - $subject = "New ticket created [Ticket #" . $ticketObj->getTId() ."]"; - $endTxt = "\n\n----------\nYou can reply on this message to answer directly on the ticket!"; - $txt = $txt . $content . $endTxt; - self::send_mail($ticketObj->getAuthor(),$subject,$txt, $ticketObj->getTId(), $sendingGroupId); - } + $author = $ticketObj->getAuthor(); + $webUser = new WebUsers($author); + //if the author of the ticket wants to receive mail, then send it! + if($webUser->getReceiveMail()){ + + switch($type){ + case "REPLY": + $txt = "---------- Ticket #". $ticketObj->getTId() . " ----------\n You received a new reply on your ticket: " . $ticketObj->getTitle() . + "\n --------------------\n\n"; + $subject = "New reply on [Ticket #" . $ticketObj->getTId() ."]"; + $endTxt = "\n\n----------\nYou can reply on this message to answer directly on the ticket!"; + $txt = $txt . $content . $endTxt; + self::send_mail($author,$subject,$txt, $ticketObj->getTId(),$sendingGroupId); + break; + + case "NEW": + $txt = "---------- Ticket #". $ticketObj->getTId() . " ----------\n Your ticket: " . $ticketObj->getTitle() . " is newly created"; + $txt = $txt . "\n --------------------\n\n"; + $subject = "New ticket created [Ticket #" . $ticketObj->getTId() ."]"; + $endTxt = "\n\n----------\nYou can reply on this message to answer directly on the ticket!"; + $txt = $txt . $content . $endTxt; + self::send_mail($author,$subject,$txt, $ticketObj->getTId(), $sendingGroupId); + break; + } + } } } diff --git a/code/ryzom/tools/server/ryzom_ams/www/config.php b/code/ryzom/tools/server/ryzom_ams/www/config.php index 247b2a961..d4b99a41c 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/config.php +++ b/code/ryzom/tools/server/ryzom_ams/www/config.php @@ -48,6 +48,11 @@ $cfg['mail']['default_username'] = 'amsryzom@gmail.com'; $cfg['mail']['default_password'] = 'lol123bol'; $cfg['mail']['host'] = "ryzomcore.com"; +//Defines mailing related stuff +$SUPPORT_GROUP_IMAP_CRYPTKEY = "azerty"; +$TICKET_MAILING_SUPPORT = true; +$MAIL_DIR = "/tmp"; + //----------------------------------------------------------------------------------------- // If true= the server will add automatically unknown user in the database // (in nel.user= nel.permission= ring.ring_user and ring.characters @@ -73,7 +78,4 @@ $TIME_FORMAT = "m-d-Y H:i:s"; //defines which ingame layout template should be used $INGAME_LAYOUT = "basic"; -//Defines mailing related stuff -$SUPPORT_GROUP_IMAP_CRYPTKEY = "azerty"; -$TICKET_MAILING_SUPPORT = true; -$MAIL_DIR = "/tmp"; + 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 3f49e5e88..d819c89c5 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 @@ -9,6 +9,7 @@ class WebUsers extends Users{ private $lastname; private $gender; private $country; + private $receiveMail; function __construct($UId = 0) { $this->uId = $UId; @@ -22,6 +23,7 @@ class WebUsers extends Users{ $this->lastname = $values['LastName']; $this->gender = $values['Gender']; $this->country = $values['Country']; + $this->receiveMail = $values['ReceiveMail']; } /** @@ -114,16 +116,26 @@ class WebUsers extends Users{ public function getInfo(){ $dbw = new DBLayer("web"); - if(! (isset($this->firstname) && isset($this->lastname) && isset($this->gender) && isset($this->country) ) || - $this->firstname == "" || $this->lastname == "" || $this->gender == "" || $this->country == ""){ + 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)); $row = $statement->fetch(); $this->set($row); } - $result = Array('FirstName' => $this->firstname, 'LastName' => $this->lastname, 'Gender' => $this->gender, 'Country' => $this->country); + $result = Array('FirstName' => $this->firstname, 'LastName' => $this->lastname, 'Gender' => $this->gender, 'Country' => $this->country, 'ReceiveMail' => $this->receiveMail); return $result; } + 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)); + $row = $statement->fetch(); + $this->set($row); + } + return $this->receiveMail; + } + public function isLoggedIn(){ if(isset($_SESSION['user'])){ return true; @@ -159,6 +171,18 @@ class WebUsers extends Users{ return $reply; } + public static function setReceiveMail($user, $receivemail){ + $values = Array('user' => $user, '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); + } + catch (PDOException $e) { + //ERROR: the web DB is offline + } + } + public function getUsers(){ $dbl = new DBLayer("web"); $data = $dbl->executeWithoutParams("SELECT * FROM ams_user"); diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/change_receivemail.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/change_receivemail.php new file mode 100644 index 000000000..85cbec965 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/change_receivemail.php @@ -0,0 +1,48 @@ +getInfo(); $result['target_id'] = $_SESSION['id']; - $result['current_mail'] = $webUser->getEmail(); - - //Sanitize Data - $result['current_mail'] = filter_var($result['current_mail'], FILTER_SANITIZE_EMAIL); - //$result['Login'] = filter_var($result['Login'], FILTER_SANITIZE_STRING); - $result['FirstName'] = filter_var($result['FirstName'], FILTER_SANITIZE_STRING); - $result['LastName'] = filter_var($result['LastName'], FILTER_SANITIZE_STRING); - $result['Country'] = filter_var($result['Country'], FILTER_SANITIZE_STRING); - $result['Gender'] = filter_var($result['Gender'], FILTER_SANITIZE_NUMBER_INT); + $result['current_mail'] = $webUser->getEmail(); + } + //Sanitize Data + $result['current_mail'] = filter_var($result['current_mail'], FILTER_SANITIZE_EMAIL); + //$result['Login'] = filter_var($result['Login'], FILTER_SANITIZE_STRING); + $result['FirstName'] = filter_var($result['FirstName'], FILTER_SANITIZE_STRING); + $result['LastName'] = filter_var($result['LastName'], FILTER_SANITIZE_STRING); + $result['Country'] = filter_var($result['Country'], FILTER_SANITIZE_STRING); + $result['Gender'] = filter_var($result['Gender'], FILTER_SANITIZE_NUMBER_INT); + $result['ReceiveMail'] = filter_var($result['ReceiveMail'], FILTER_SANITIZE_NUMBER_INT); $result['country_array'] = getCountryArray(); return $result; }else{ diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php b/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php index c593ec4ad..f72e0c8bf 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php @@ -25,6 +25,7 @@ `LastName` varchar(255) NOT NULL DEFAULT '', `Gender` tinyint(1) unsigned NOT NULL DEFAULT '0', `Country` char(2) NOT NULL DEFAULT '', + `ReceiveMail` int(1) NOT NULL DEFAULT 1, PRIMARY KEY (`UId`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='contains all users information for ryzom_ams'; diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/settings.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/settings.tpl index 0a7aa263c..599427946 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/settings.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/settings.tpl @@ -101,6 +101,7 @@ + {if isset($SUCCESS_MAIL) and $SUCCESS_MAIL eq "OK"}
The email has been changed! @@ -124,6 +125,40 @@
+
+

Ticket updates

+
+ + +
+
+
+
+
+ Ticket-Update Mail Settings + +
+ +
+ +
+ +
+ + + +
+ +
+ +
+
+
+
+