Ejemplo n.º 1
0
 /**
  * Send email to super administrator and user
  *
  * @param object $row The message object
  * @param object $ticket The ticket object
  * @param object $config
  */
 public static function sendNewTicketNotificationEmails($row, $config)
 {
     $app = JFactory::getApplication();
     if ($app->isAdmin()) {
         $Itemid = HelpdeskProHelper::getItemid();
     } else {
         $Itemid = JRequest::getInt('Itemid');
     }
     $jconfig = new JConfig();
     $db = JFactory::getDbo();
     $siteUrl = JURI::root();
     if ($config->from_email) {
         $fromEmail = $config->from_email;
     } else {
         $fromEmail = $jconfig->mailfrom;
     }
     if ($config->from_name) {
         $fromName = $config->from_name;
     } else {
         $fromName = $jconfig->fromname;
     }
     $sql = 'SELECT title FROM #__helpdeskpro_categories WHERE id=' . $row->category_id;
     $db->setQuery($sql);
     $categoryTitle = $db->loadResult();
     $replaces = array();
     $replaces['ticket_id'] = $row->id;
     $replaces['ticket_subject'] = $row->subject;
     $replaces['name'] = $row->name;
     $replaces['ticket_message'] = $row->message;
     $replaces['frontend_link'] = $siteUrl . 'index.php?option=com_helpdeskpro&view=ticket&cid[]=' . $row->id . '&Itemid=' . $Itemid;
     $replaces['backend_link'] = $siteUrl . 'administrator/index.php?option=com_helpdeskpro&view=ticket&cid[]=' . $row->id . '&Itemid=' . $Itemid;
     $replaces['frontend_link_without_login'] = $siteUrl . 'index.php?option=com_helpdeskpro&view=ticket&ticket_code=' . $row->ticket_code . '&Itemid=' . $Itemid;
     $replaces['category_title'] = $categoryTitle;
     $sql = 'SELECT managers FROM #__helpdeskpro_categories WHERE id=' . $row->category_id;
     $db->setQuery($sql);
     $managers = $db->loadResult();
     $managers = trim($managers);
     if ($managers) {
         $managers = explode(',', $managers);
         for ($i = 0, $n = count($managers); $i < $n; $i++) {
             $managers[$i] = trim($managers[$i]);
         }
         $sql = 'SELECT email FROM #__users WHERE username IN ("' . implode('","', $managers) . '")';
         $db->setQuery($sql);
         $emails = $db->loadResultArray();
     } else {
         //Send email to general notification emails
         $emails = explode(',', $config->notification_emails);
         for ($i = 0, $n = count($emails); $i < $n; $i++) {
             $emails[$i] = trim($emails[$i]);
         }
     }
     //Send message to administrators/managers
     $subject = $config->new_ticket_admin_email_subject;
     $body = $config->new_ticket_admin_email_body;
     foreach ($replaces as $key => $value) {
         $key = strtoupper($key);
         $body = str_replace("[{$key}]", $value, $body);
         $subject = str_replace("[{$key}]", $value, $subject);
     }
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $j3 = true;
         $mailer = new JMail();
     } else {
         $j3 = false;
     }
     foreach ($emails as $email) {
         if ($email) {
             if ($j3) {
                 $mailer->sendMail($fromEmail, $fromName, $email, $subject, $body, 1);
             } else {
                 JUtility::sendMail($fromEmail, $fromName, $email, $subject, $body, 1);
             }
         }
     }
     //Send email to user
     $subject = $config->new_ticket_user_email_subject;
     $body = $config->new_ticket_user_email_body;
     foreach ($replaces as $key => $value) {
         $key = strtoupper($key);
         $body = str_replace("[{$key}]", $value, $body);
         $subject = str_replace("[{$key}]", $value, $subject);
     }
     if ($j3) {
         $mailer->sendMail($fromEmail, $fromName, $row->email, $subject, $body, 1);
     } else {
         JUtility::sendMail($fromEmail, $fromName, $row->email, $subject, $body, 1);
     }
 }