[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/HelpDesk/ -> HelpDeskHandler.php (source)

   1  <?php
   2  /*+***********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   *************************************************************************************/
  10  
  11  require_once  'modules/Emails/mail.php';
  12  
  13  class HelpDeskHandler extends VTEventHandler {
  14  
  15  	function handleEvent($eventName, $entityData) {
  16          global $log, $adb;
  17  
  18          if($eventName == 'vtiger.entity.aftersave.final') {
  19              $moduleName = $entityData->getModuleName();
  20              if ($moduleName == 'HelpDesk') {
  21                  $ticketId = $entityData->getId();
  22                  $adb->pquery('UPDATE vtiger_ticketcf SET from_portal=0 WHERE ticketid=?', array($ticketId));
  23              }
  24          }
  25      }
  26  }
  27  
  28  function HelpDesk_nofifyOnPortalTicketCreation($entityData) {
  29      global $HELPDESK_SUPPORT_NAME,$HELPDESK_SUPPORT_EMAIL_ID;
  30      $adb = PearDatabase::getInstance();
  31      $moduleName = $entityData->getModuleName();
  32      $wsId = $entityData->getId();
  33      $parts = explode('x', $wsId);
  34      $entityId = $parts[1];
  35  
  36      $ownerIdInfo = getRecordOwnerId($entityId);
  37      if(!empty($ownerIdInfo['Users'])) {
  38          $ownerId = $ownerIdInfo['Users'];
  39          $to_email = getUserEmailId('id',$ownerId);
  40      }
  41      if(!empty($ownerIdInfo['Groups'])) {
  42          $ownerId = $ownerIdInfo['Groups'];
  43          $to_email = implode(',', getDefaultAssigneeEmailIds($ownerId));
  44      }
  45      $wsParentId = $entityData->get('contact_id');
  46      $parentIdParts = explode('x', $wsParentId);
  47      $parentId = $parentIdParts[1];
  48  
  49      $subject = '[From Portal] ' .$entityData->get('ticket_no'). " [ Ticket Id : $entityId ] " .$entityData->get('ticket_title');
  50      $contents = ' Ticket No : '.$entityData->get('ticket_no'). '<br> Ticket ID : '.$entityId.'<br> Ticket Title : '.
  51                              $entityData->get('ticket_title').'<br><br>'.$entityData->get('description');
  52  
  53      //get the contact email id who creates the ticket from portal and use this email as from email id in email
  54      $result = $adb->pquery("SELECT email, concat (firstname,' ',lastname) as name FROM vtiger_contactdetails WHERE contactid=?", array($parentId));
  55      $contact_email = $adb->query_result($result,0,'email');
  56      $name = $adb->query_result($result, 0, 'name');
  57      $from_email = $contact_email;
  58  
  59      //send mail to assigned to user
  60      $mail_status = send_mail('HelpDesk',$to_email,$name,$HELPDESK_SUPPORT_EMAIL_ID,$subject,$contents);
  61  
  62      //send mail to the customer(contact who creates the ticket from portal)
  63      $mail_status = send_mail('Contacts',$contact_email,$HELPDESK_SUPPORT_NAME,$HELPDESK_SUPPORT_EMAIL_ID,$subject,$contents);
  64  }
  65  
  66  function HelpDesk_notifyOnPortalTicketComment($entityData) {
  67      $adb = PearDatabase::getInstance();
  68      $moduleName = $entityData->getModuleName();
  69      $wsId = $entityData->getId();
  70      $parts = explode('x', $wsId);
  71      $entityId = $parts[1];
  72  
  73      $ownerIdInfo = getRecordOwnerId($entityId);
  74  
  75      if(!empty($ownerIdInfo['Users'])) {
  76          $ownerId = $ownerIdInfo['Users'];
  77          $ownerName = getOwnerName($ownerId);
  78          $to_email = getUserEmailId('id',$ownerId);
  79      }
  80      if(!empty($ownerIdInfo['Groups'])) {
  81          $ownerId = $ownerIdInfo['Groups'];
  82          $groupInfo = getGroupName($ownerId);
  83          $ownerName = $groupInfo[0];
  84          $to_email = implode(',', getDefaultAssigneeEmailIds($ownerId));
  85      }
  86      $wsParentId = $entityData->get('contact_id');
  87      $parentIdParts = explode('x', $wsParentId);
  88      $parentId = $parentIdParts[1];
  89  
  90      $entityDelta = new VTEntityDelta();
  91      $oldComments = $entityDelta->getOldValue($entityData->getModuleName(), $entityId, 'comments');
  92      $newComments = $entityDelta->getCurrentValue($entityData->getModuleName(), $entityId, 'comments');
  93      $commentDiff = str_replace($oldComments, '', $newComments);
  94      $latestComment = strip_tags($commentDiff);
  95  
  96      //send mail to the assigned to user when customer add comment
  97      $subject = getTranslatedString('LBL_RESPONSE_TO_TICKET_NUMBER', $moduleName). ' : ' .$entityData->get('ticket_no'). ' ' .getTranslatedString('LBL_CUSTOMER_PORTAL', $moduleName);
  98      $contents = getTranslatedString('Dear', $moduleName)." ".$ownerName.","."<br><br>"
  99                          .getTranslatedString('LBL_CUSTOMER_COMMENTS', $moduleName)."<br><br>
 100                          <b>".$latestComment."</b><br><br>"
 101                          .getTranslatedString('LBL_RESPOND', $moduleName)."<br><br>"
 102                          .getTranslatedString('LBL_REGARDS', $moduleName)."<br>"
 103                          .getTranslatedString('LBL_SUPPORT_ADMIN', $moduleName);
 104  
 105      //get the contact email id who creates the ticket from portal and use this email as from email id in email
 106      $result = $adb->pquery("SELECT lastname, firstname, email FROM vtiger_contactdetails WHERE contactid=?", array($parentId));
 107      $customername = $adb->query_result($result,0,'firstname').' '.$adb->query_result($result,0,'lastname');
 108      $customername = decode_html($customername);//Fix to display the original UTF-8 characters in sendername instead of ascii characters
 109      $from_email = $adb->query_result($result,0,'email');
 110  
 111      send_mail('HelpDesk',$to_email,'',$from_email,$subject,$contents);
 112  }
 113  
 114  function HelpDesk_notifyParentOnTicketChange($entityData) {
 115      global $HELPDESK_SUPPORT_NAME,$HELPDESK_SUPPORT_EMAIL_ID;
 116      $adb = PearDatabase::getInstance();
 117      $moduleName = $entityData->getModuleName();
 118      $wsId = $entityData->getId();
 119      $parts = explode('x', $wsId);
 120      $entityId = $parts[1];
 121  
 122      $isNew = $entityData->isNew();
 123  
 124      if(!$isNew) {
 125          $reply = 'Re : ';
 126      } else {
 127          $reply = '';
 128      }
 129  
 130      $subject = $entityData->get('ticket_no') . " [ Ticket Id : $entityId ] " . $reply . $entityData->get('ticket_title');
 131      $emailoptout = 0;
 132      $wsContactId = $entityData->get('contact_id');
 133      $contactId = explode('x', $wsContactId);
 134      $wsAccountId = $entityData->get('parent_id');
 135      $accountId = explode('x', $wsAccountId);
 136      //To get the emailoptout vtiger_field value and then decide whether send mail about the tickets or not
 137      if(!empty($contactId[0])) {
 138          $result = $adb->pquery('SELECT email, emailoptout, lastname, firstname FROM vtiger_contactdetails WHERE
 139                          contactid=?', array($contactId[1]));
 140          $emailoptout = $adb->query_result($result,0,'emailoptout');
 141          $parent_email = $contact_mailid = $adb->query_result($result,0,'email');
 142          $parentname = $adb->query_result($result,0,'firstname').' '.$adb->query_result($result,0,'firstname');
 143  
 144          //Get the status of the vtiger_portal user. if the customer is active then send the vtiger_portal link in the mail
 145          if($parent_email != '') {
 146              $sql = "SELECT * FROM vtiger_portalinfo WHERE user_name=?";
 147              $isPortalUser = $adb->query_result($adb->pquery($sql, array($contact_mailid)),0,'isactive');
 148          }
 149      } elseif(!empty($accountId[0])) {
 150          $result = $adb->pquery("SELECT accountname, emailoptout, email1 FROM vtiger_account WHERE accountid=?",
 151                                      array($accountId[1]));
 152          $emailoptout = $adb->query_result($result,0,'emailoptout');
 153          $parent_email = $adb->query_result($result,0,'email1');
 154          $parentname = $adb->query_result($result,0,'accountname');
 155      }
 156      //added condition to check the emailoptout(this is for contacts and vtiger_accounts.)
 157      if($emailoptout == 0) {
 158          if($isPortalUser == 1) {
 159              $email_body = HelpDesk::getTicketEmailContents($entityData);
 160          } else {
 161              $email_body = HelpDesk::getTicketEmailContents($entityData);
 162          }
 163  
 164          if($isNew) {
 165              send_mail('HelpDesk',$parent_email,$HELPDESK_SUPPORT_NAME,$HELPDESK_SUPPORT_EMAIL_ID,$subject,$email_body);
 166          } else {
 167              $entityDelta = new VTEntityDelta();
 168              $statusHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'ticketstatus');
 169              $solutionHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'solution');
 170              $descriptionHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'description');
 171  
 172              if(($statusHasChanged && $entityData->get('ticketstatus') == "Closed") || $solutionHasChanged || $descriptionHasChanged) {
 173                  send_mail('HelpDesk',$parent_email,$HELPDESK_SUPPORT_NAME,$HELPDESK_SUPPORT_EMAIL_ID,$subject,$email_body);
 174              }
 175          }
 176      }
 177  }
 178  
 179  function HelpDesk_notifyOwnerOnTicketChange($entityData) {
 180      global $HELPDESK_SUPPORT_NAME,$HELPDESK_SUPPORT_EMAIL_ID;
 181  
 182      $moduleName = $entityData->getModuleName();
 183      $wsId = $entityData->getId();
 184      $parts = explode('x', $wsId);
 185      $entityId = $parts[1];
 186  
 187      $isNew = $entityData->isNew();
 188  
 189      if(!$isNew) {
 190          $reply = 'Re : ';
 191      } else {
 192          $reply = '';
 193      }
 194  
 195      $subject = getTranslatedString('LBL_TICKET_NUMBER', $moduleName). ' : ' .$entityData->get('ticket_no'). ' ' .$reply.$entityData->get('ticket_title');
 196  
 197      $email_body = HelpDesk::getTicketEmailContents($entityData, true);
 198      if(PerformancePrefs::getBoolean('NOTIFY_OWNER_EMAILS', true) === true){
 199          //send mail to the assigned to user and the parent to whom this ticket is assigned
 200          require_once ('modules/Emails/mail.php');
 201          $wsAssignedUserId = $entityData->get('assigned_user_id');
 202          $userIdParts = explode('x', $wsAssignedUserId);
 203          $ownerId = $userIdParts[1];
 204          $ownerType = vtws_getOwnerType($ownerId);
 205  
 206          if($ownerType == 'Users') {
 207              $to_email = getUserEmailId('id',$ownerId);
 208          }
 209          if($ownerType == 'Groups') {
 210              $to_email = implode(',', getDefaultAssigneeEmailIds($ownerId));
 211          }
 212          if($to_email != '') {
 213              if($isNew) {
 214                  $mail_status = send_mail('HelpDesk',$to_email,$HELPDESK_SUPPORT_NAME,$HELPDESK_SUPPORT_EMAIL_ID,$subject,$email_body);
 215              } else {
 216                  $entityDelta = new VTEntityDelta();
 217                  $statusHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'ticketstatus');
 218                  $solutionHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'solution');
 219                  $ownerHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'assigned_user_id');
 220                  $descriptionHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'description');
 221                  if(($statusHasChanged && $entityData->get('ticketstatus') == "Closed") || $solutionHasChanged || $ownerHasChanged || $descriptionHasChanged) {
 222                      $mail_status = send_mail('HelpDesk',$to_email,$HELPDESK_SUPPORT_NAME,$HELPDESK_SUPPORT_EMAIL_ID,$subject,$email_body);
 223                  }
 224              }
 225              $mail_status_str = $to_email."=".$mail_status."&&&";
 226  
 227          } else {
 228              $mail_status_str = "'".$to_email."'=0&&&";
 229          }
 230  
 231          if ($mail_status != '') {
 232              $mail_error_status = getMailErrorString($mail_status_str);
 233          }
 234      }
 235  }
 236  
 237  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1