creating new tickets over email works
This commit is contained in:
parent
70fdf0dc74
commit
993973441a
8 changed files with 72 additions and 35 deletions
|
@ -42,7 +42,7 @@ class Mail_Handler{
|
|||
}
|
||||
|
||||
|
||||
public static function send_mail($recipient, $subject, $body, $ticket_id = 0, $from = 1) {
|
||||
public static function send_mail($recipient, $subject, $body, $ticket_id = 0, $from = NULL) {
|
||||
if(is_numeric($recipient)) {
|
||||
$id_user = $recipient;
|
||||
$recipient = NULL;
|
||||
|
@ -134,6 +134,7 @@ class Mail_Handler{
|
|||
// Check mail
|
||||
$sGroups = Support_Group::getGroups();
|
||||
$defaultGroup = new Support_Group();
|
||||
$defaultGroup->setSGroupId(0);
|
||||
$defaultGroup->setGroupEmail($default_groupemail);
|
||||
$defaultGroup->setIMAP_MailServer($cfg['mail']['default_mailserver']);
|
||||
$defaultGroup->setIMAP_Username($cfg['mail']['default_username']);
|
||||
|
@ -148,7 +149,7 @@ class Mail_Handler{
|
|||
for ($i = 1; $i <= $message_count; ++$i) {
|
||||
|
||||
//return task ID
|
||||
self::incoming_mail_handler($mbox, $i);
|
||||
self::incoming_mail_handler($mbox, $i,$group);
|
||||
$tid = 1; //self::ams_create_email($from, $subject, $txt, $html, $to, $from);
|
||||
|
||||
if($tid) {
|
||||
|
@ -182,19 +183,36 @@ class Mail_Handler{
|
|||
|
||||
function get_ticket_id_from_subject($subject){
|
||||
$startpos = strpos($subject, "[Ticket #");
|
||||
if($startpos){
|
||||
$tempString = substr($subject, $startpos+9);
|
||||
$endpos = strpos($tempString, "]");
|
||||
if($endpos){
|
||||
$ticket_id = substr($tempString, 0, $endpos);
|
||||
}else{
|
||||
$ticket_id = 0;
|
||||
}
|
||||
}else{
|
||||
$ticket_id = 0;
|
||||
}
|
||||
return $ticket_id;
|
||||
}
|
||||
|
||||
|
||||
function incoming_mail_handler($mbox,$i){
|
||||
function incoming_mail_handler($mbox,$i,$group){
|
||||
|
||||
$header = imap_header($mbox, $i);
|
||||
$subject = self::decode_utf8($header->subject);
|
||||
$entire_email = imap_fetchheader($mbox, $i) . imap_body($mbox, $i);
|
||||
$subject = self::decode_utf8($header->subject);
|
||||
$to = $header->to[0]->mailbox;
|
||||
$from = $header->from[0]->mailbox . '@' . $header->from[0]->host;
|
||||
$txt = self::get_part($mbox, $i, "TEXT/PLAIN");
|
||||
//$html = self::get_part($mbox, $i, "TEXT/HTML");
|
||||
|
||||
print_r($header);
|
||||
//get the id out of the email address of the person sending the email.
|
||||
if($from !== NULL && !is_numeric($from)){
|
||||
$from = Ticket_User::get_id_from_email($from);
|
||||
}
|
||||
|
||||
//get ticket_id out of the message-id or else out of the subject line
|
||||
$ticket_id = 0;
|
||||
|
@ -209,16 +227,9 @@ class Mail_Handler{
|
|||
$ticket_id = self::get_ticket_id_from_subject($subject);
|
||||
}
|
||||
|
||||
//if ticket id is found
|
||||
//if ticket id is found, that means it is a reply on an existing ticket
|
||||
if($ticket_id){
|
||||
|
||||
$entire_email = imap_fetchheader($mbox, $i) . imap_body($mbox, $i);
|
||||
$subject = self::decode_utf8($header->subject);
|
||||
$to = $header->to[0]->mailbox;
|
||||
$from = $header->from[0]->mailbox . '@' . $header->from[0]->host;
|
||||
$txt = self::get_part($mbox, $i, "TEXT/PLAIN");
|
||||
//$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){
|
||||
|
@ -230,10 +241,8 @@ class Mail_Handler{
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//get the id out of the email address of the person sending the email.
|
||||
if($from !== NULL && !is_numeric($from)) $from = Ticket_User::get_id_from_email($from);
|
||||
|
||||
//if email is sent from an existing email address in the db (else it will give an error while loading the user object)
|
||||
if($from != "FALSE"){
|
||||
$user = new Ticket_User();
|
||||
$user->load_With_TUserId($from);
|
||||
$ticket = new Ticket();
|
||||
|
@ -243,6 +252,22 @@ class Mail_Handler{
|
|||
if((Ticket_User::isMod($user) or ($ticket->getAuthor() == $user->getTUserId())) and $txt != ""){
|
||||
Ticket::createReply($txt, $user->getTUserId(), $ticket->getTId(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
//if ticket_id isn't found, create a new ticket!
|
||||
|
||||
//if an existing email address mailed the ticket
|
||||
if($from != "FALSE"){
|
||||
|
||||
$newTicketId = Ticket::create_Ticket($subject, $txt,1, $from, $from);
|
||||
|
||||
//if not default group, then forward it!
|
||||
if($group->getSGroupId()){
|
||||
Ticket::forwardTicket(0, $newTicketId, $group->getSGroupId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -197,12 +197,15 @@ class Ticket{
|
|||
public static function forwardTicket($user_id, $ticket_id, $group_id){
|
||||
if(self::ticketExists($ticket_id)){
|
||||
if(isset($group_id) && $group_id != ""){
|
||||
//unassign the ticket incase the ticket is assined to yourself
|
||||
self::unAssignTicket($user_id, $ticket_id);
|
||||
//forward the ticket
|
||||
$returnvalue = Forwarded::forwardTicket($group_id, $ticket_id);
|
||||
|
||||
if($user_id != 0){
|
||||
//unassign the ticket incase the ticket is assined to yourself
|
||||
self::unAssignTicket($user_id, $ticket_id);
|
||||
//make a log entry of this action
|
||||
Ticket_Log::createLogEntry( $ticket_id, $user_id, 8, $group_id);
|
||||
}
|
||||
return $returnvalue;
|
||||
}else{
|
||||
return "INVALID_SGROUP";
|
||||
|
|
|
@ -98,8 +98,12 @@ class Ticket_User{
|
|||
|
||||
public static function get_id_from_email($email){
|
||||
$webUserId = WebUsers::getIdFromEmail($email);
|
||||
if($webUserId != "FALSE"){
|
||||
$user = Ticket_User::constr_ExternId($webUserId);
|
||||
return $user->getTUserId();
|
||||
}else{
|
||||
return "FALSE";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ $cfg['mail']['default_groupemail'] = 'support@ryzomcore.com';
|
|||
$cfg['mail']['default_groupname'] = 'Ryzomcore Support';
|
||||
$cfg['mail']['default_username'] = 'amsryzom@gmail.com';
|
||||
$cfg['mail']['default_password'] = 'lol123bol';
|
||||
$cfg['mail']['host'] = "ryzomcore.com";
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
// If true= the server will add automatically unknown user in the database
|
||||
|
|
|
@ -81,7 +81,11 @@ class WebUsers extends Users{
|
|||
$dbw = new DBLayer("web");
|
||||
$statement = $dbw->execute("SELECT * FROM ams_user WHERE Email=:email", array('email' => $email));
|
||||
$row = $statement->fetch();
|
||||
if($row !== "FALSE"){
|
||||
return $row['UId'];
|
||||
}else{
|
||||
return "FALSE";
|
||||
}
|
||||
}
|
||||
|
||||
public function getUId(){
|
||||
|
|
|
@ -273,7 +273,7 @@
|
|||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
INSERT IGNORE INTO `" . $cfg['db']['lib']['name'] ."`.`ticket_category` (`Name`) VALUES ('Hacking'),('Ingame-Bug'),('Website-Bug'),('Installation');
|
||||
INSERT IGNORE INTO `" . $cfg['db']['lib']['name'] ."`.`ticket_category` (`Name`) VALUES ('Uncategorized'),('Hacking'),('Ingame-Bug'),('Website-Bug'),('Installation');
|
||||
|
||||
|
||||
|
||||
|
@ -374,7 +374,7 @@
|
|||
CONSTRAINT `fk_email_support_group1`
|
||||
FOREIGN KEY (`Sender` )
|
||||
REFERENCES `" . $cfg['db']['lib']['name'] ."`.`support_group` (`SGroupId` )
|
||||
ON DELETE NO ACTION
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
|
|
@ -310,7 +310,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`email` (
|
|||
`Status` VARCHAR(45) NULL ,
|
||||
`Attempts` VARCHAR(45) NULL DEFAULT 0 ,
|
||||
`UserId` INT(10) UNSIGNED NOT NULL ,
|
||||
`MessageId` VARCHAR(45) NOT NULL ,
|
||||
`MessageId` VARCHAR(45) NULL ,
|
||||
`TicketId` INT UNSIGNED NOT NULL ,
|
||||
`Sender` INT(10) UNSIGNED NULL ,
|
||||
PRIMARY KEY (`MailId`) ,
|
||||
|
@ -330,7 +330,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`email` (
|
|||
CONSTRAINT `fk_email_support_group1`
|
||||
FOREIGN KEY (`Sender` )
|
||||
REFERENCES `mydb`.`support_group` (`SGroupId` )
|
||||
ON DELETE NO ACTION
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue