ticket mail system basis works

--HG--
branch : quitta-gsoc-2013
This commit is contained in:
Quitta 2013-08-13 17:16:43 +02:00
parent 328351a4c5
commit 370653b11c
5 changed files with 100 additions and 51 deletions

View file

@ -12,41 +12,43 @@ class Mail_Handler{
} }
function get_email_by_user_id($id){ public static function send_ticketing_mail($ticketObj, $content, $type, $author) {
$user = new Ticket_User(); global $TICKET_MAILING_SUPPORT;
$user->load_With_TUserId($id); if($TICKET_MAILING_SUPPORT){
$webUser = new WebUsers($user->getExternId()); $txt = "";
return $webUser->getEmail(); $subject = "";
} if($type == "REPLY"){
$txt = "---------- Ticket #". $ticketObj->getTId() . " ----------\n You received a new reply on your ticket: " . $ticketObj->getTitle() .
function get_username_from_id($id){ "\n --------------------\n\n";
$user = new Ticket_User(); $subject = "New reply on [Ticket #" . $ticketObj->getTId() ."]";
$user->load_With_TUserId($id); $endTxt = "\n\n----------\nYou can reply on this message to answer directly on the ticket!";
$webUser = new WebUsers($user->getExternId()); $txt = $txt . $content . $endTxt;
return $webUser->getUsername(); self::send_mail($ticketObj->getAuthor(),$subject,$txt, $ticketObj->getTId(),$author);
} }else if($type == "NEW"){
$txt = "---------- Ticket #". $ticketObj->getTId() . " ----------\n Your ticket: " . $ticketObj->getTitle() . " is newly created";
if($ticketObj->getAuthor() != $author){
$txt = $txt . " by " . Ticket_User::get_username_from_id($author);
}else{
$author = $ticketObj->getAuthor();
}
$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());
}
}
}
function get_id_from_username($username){ public static function send_mail($recipient, $subject, $body, $ticket_id = 0, $from = 1) {
$externId = WebUsers::getId($username);
$user = Ticket_User::constr_ExternId($externId);
return $user->getTUserId();
}
function get_id_from_email($email){
$webUserId = WebUsers::getIdFromEmail($email);
$user = Ticket_User::constr_ExternId($webUserId);
return $user->getTUserId();
}
public static function send_mail($recipient, $subject, $body, $from = NULL) {
if(is_numeric($recipient)) { if(is_numeric($recipient)) {
$id_user = $recipient; $id_user = $recipient;
$recipient = NULL; $recipient = NULL;
} }
$query = "INSERT INTO email (Recipient,Subject,Body,Status,UserId,Sender) VALUES (:recipient, :subject, :body, :status, :id_user, :sender)"; $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', 'id_user' => $id_user, 'sender' => $from); $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 = new DBLayer("lib");
$db->execute($query, $values); $db->execute($query, $values);
@ -59,7 +61,7 @@ class Mail_Handler{
$inbox_username = $cfg['mail']['username']; $inbox_username = $cfg['mail']['username'];
$inbox_password = $cfg['mail']['password']; $inbox_password = $cfg['mail']['password'];
$inbox_host = $cfg['mail']['host']; $inbox_host = $cfg['mail']['host'];
$oms_reply_to = "OMS <oms@".$inbox_host.">"; $oms_reply_to = "Ryzom Ticketing Support <ticketing@".$inbox_host.">";
global $MAIL_DIR; global $MAIL_DIR;
// Deliver new mail // Deliver new mail
@ -101,12 +103,12 @@ class Mail_Handler{
//if recipient isn't given, then use the email of the id_user instead! //if recipient isn't given, then use the email of the id_user instead!
echo("Emailing {$email['Recipient']}\n"); echo("Emailing {$email['Recipient']}\n");
if(!$email['Recipient']) { if(!$email['Recipient']) {
$email['Recipient'] = self::get_email_by_user_id($email['UserId']); $email['Recipient'] = Ticket_User::get_email_by_user_id($email['UserId']);
} }
//create sending email adres based on the $sender id //create sending email adres based on the $sender id
if($email['Sender']) { if($email['Sender'] != 0) {
$username = self::get_username_from_id($email['Sender']); $username = Ticket_User::get_username_from_id($email['Sender']);
$from = "$username <$username@$inbox_host>"; $from = "$username <$username@$inbox_host>";
} else { } else {
$from = $oms_reply_to; $from = $oms_reply_to;
@ -171,7 +173,6 @@ class Mail_Handler{
} }
function get_ticket_id_from_subject($subject){ function get_ticket_id_from_subject($subject){
print('got it from subject!');
$startpos = strpos($subject, "[Ticket #"); $startpos = strpos($subject, "[Ticket #");
$tempString = substr($subject, $startpos+9); $tempString = substr($subject, $startpos+9);
$endpos = strpos($tempString, "]"); $endpos = strpos($tempString, "]");
@ -192,13 +193,11 @@ class Mail_Handler{
if(isset($header->references)){ if(isset($header->references)){
$pieces = explode(".", $header->references); $pieces = explode(".", $header->references);
if($pieces[0] == "<ams"){ if($pieces[0] == "<ams"){
print('got it from message-id');
$ticket_id = $pieces[2]; $ticket_id = $pieces[2];
}else{ }else{
$ticket_id = self::get_ticket_id_from_subject($subject); $ticket_id = self::get_ticket_id_from_subject($subject);
} }
}else{ }else{
print('elseeee');
$ticket_id = self::get_ticket_id_from_subject($subject); $ticket_id = self::get_ticket_id_from_subject($subject);
} }
@ -210,10 +209,22 @@ class Mail_Handler{
$to = $header->to[0]->mailbox; $to = $header->to[0]->mailbox;
$from = $header->from[0]->mailbox . '@' . $header->from[0]->host; $from = $header->from[0]->mailbox . '@' . $header->from[0]->host;
$txt = self::get_part($mbox, $i, "TEXT/PLAIN"); $txt = self::get_part($mbox, $i, "TEXT/PLAIN");
$html = self::get_part($mbox, $i, "TEXT/HTML"); //$html = self::get_part($mbox, $i, "TEXT/HTML");
//use the line ---------- Ticket # to make a distincton between the old message and the reply
$endpos = strpos($txt, ">---------- Ticket #");
if($endpos){
$txt = substr($txt, 0, $endpos);
}else{
$endpos = strpos($txt, "---------- Ticket #");
if($endpos){
$txt = substr($txt, 0, $endpos);
}
}
//get the id out of the email address of the person sending the email. //get the id out of the email address of the person sending the email.
if($from !== NULL && !is_numeric($from)) $from = self::get_id_from_email($from); if($from !== NULL && !is_numeric($from)) $from = Ticket_User::get_id_from_email($from);
$user = new Ticket_User(); $user = new Ticket_User();
$user->load_With_TUserId($from); $user->load_With_TUserId($from);
@ -221,15 +232,10 @@ class Mail_Handler{
$ticket->load_With_TId($ticket_id); $ticket->load_With_TId($ticket_id);
//if user has access to it! //if user has access to it!
if($user->isMod() or ($ticket->getAuthor() == $user->getTUserId())){ if((Ticket_User::isMod($user) or ($ticket->getAuthor() == $user->getTUserId())) and $txt != ""){
Ticket::createReply($txt, $user->getTUserId(), $ticket->getTId(), 0);
} }
/*print("================");
print("subj: ".$subject);
print("to: ".$to);
print("from: ".$from);
print("txt: " .$txt);
print("html: ".$html);*/
} }
} }

View file

@ -96,7 +96,8 @@ class Ticket{
}else{ }else{
Ticket_Log::createLogEntry( $ticket_id, $real_author, 2, $author); Ticket_Log::createLogEntry( $ticket_id, $real_author, 2, $author);
} }
Ticket_Reply::createReply($content, $author, $ticket_id, 0); Ticket_Reply::createReply($content, $author, $ticket_id, 0, $author);
Mail_Handler::send_ticketing_mail($ticket, $content, "NEW", $real_author);
return $ticket_id; return $ticket_id;
} }
@ -156,6 +157,13 @@ class Ticket{
//if status is not closed //if status is not closed
if($ticket->getStatus() != 3){ if($ticket->getStatus() != 3){
Ticket_Reply::createReply($content, $author, $ticket_id, $hidden, $ticket->getAuthor()); Ticket_Reply::createReply($content, $author, $ticket_id, $hidden, $ticket->getAuthor());
//notify ticket author that a new reply is added!
if($ticket->getAuthor() != $author){
Mail_Handler::send_ticketing_mail($ticket, $content, "REPLY", $author);
}
}else{ }else{
//TODO: Show error message that ticket is closed //TODO: Show error message that ticket is closed
} }
@ -215,7 +223,9 @@ class Ticket{
//Set ticket object //Set ticket object
public function set($values){ public function set($values){
$this->tId = $values['TId']; if(isset($values['TId'])){
$this->tId = $values['TId'];
}
$this->title = $values['Title']; $this->title = $values['Title'];
$this->status = $values['Status']; $this->status = $values['Status'];
$this->queue = $values['Queue']; $this->queue = $values['Queue'];

View file

@ -72,6 +72,37 @@ class Ticket_User{
$user->update(); $user->update();
} }
public static function get_email_by_user_id($id){
$user = new Ticket_User();
$user->load_With_TUserId($id);
$webUser = new WebUsers($user->getExternId());
return $webUser->getEmail();
}
public static function get_username_from_id($id){
$user = new Ticket_User();
$user->load_With_TUserId($id);
$webUser = new WebUsers($user->getExternId());
return $webUser->getUsername();
}
public static function get_id_from_username($username){
$externId = WebUsers::getId($username);
$user = Ticket_User::constr_ExternId($externId);
return $user->getTUserId();
}
public static function get_id_from_email($email){
$webUserId = WebUsers::getIdFromEmail($email);
$user = Ticket_User::constr_ExternId($webUserId);
return $user->getTUserId();
}
////////////////////////////////////////////Methods//////////////////////////////////////////////////// ////////////////////////////////////////////Methods////////////////////////////////////////////////////
public function __construct() { public function __construct() {
} }

View file

@ -33,7 +33,7 @@ $cfg['db']['ring']['pass'] = '';
$cfg['mail']['username'] = 'amsryzom@gmail.com'; $cfg['mail']['username'] = 'amsryzom@gmail.com';
$cfg['mail']['password'] = 'lol123bol'; $cfg['mail']['password'] = 'lol123bol';
$cfg['mail']['host'] = 'test.com'; $cfg['mail']['host'] = 'ryzomcore.com';
// To connect to an IMAP server running on port 143 on the local machine, // To connect to an IMAP server running on port 143 on the local machine,
// do the following: $mbox = imap_open("{localhost:143}INBOX", "user_id", "password"); // do the following: $mbox = imap_open("{localhost:143}INBOX", "user_id", "password");
@ -63,6 +63,7 @@ $DEFAULT_LANGUAGE = 'en';
$SITEBASE = dirname( __FILE__ ) . '/html/' ; $SITEBASE = dirname( __FILE__ ) . '/html/' ;
$TICKET_LOGGING = true; $TICKET_LOGGING = true;
$TICKET_MAILING_SUPPORT = true;
$TIME_FORMAT = "m-d-Y H:i:s"; $TIME_FORMAT = "m-d-Y H:i:s";
$INGAME_LAYOUT = "basic"; $INGAME_LAYOUT = "basic";
$MAIL_DIR = "/tmp"; $MAIL_DIR = "/tmp";

View file

@ -31,7 +31,8 @@ function reply_on_ticket(){
}catch (PDOException $e) { }catch (PDOException $e) {
//ERROR: LIB DB is not online! //ERROR: LIB DB is not online!
header("Location: index.php"); print_r($e);
//header("Location: index.php");
exit; exit;
} }