static function &ParseTemplate($template, &$ticket, $subject, $body, $ishtml, $foruser = false) { $handler = self::GetHandler($ticket['admin_id'], $template['tmpl']); $custrec = self::GetUser($ticket['user_id']); $subject = trim(str_ireplace("re:", "", $subject)); $vars[] = self::BuildVar('subject', $subject); $body = FSS_Helper::ParseBBCode($body, null, false, false, $foruser); $body = str_replace("<", "XXXLTXXX", $body); $body = str_replace(">", "XXXGTXXX", $body); $vars[] = self::BuildVar('body', $body); $vars[] = self::BuildVar('reference', $ticket['reference']); $vars[] = self::BuildVar('password', $ticket['password']); foreach (self::$extra_vars as $key => $value) { $vars[] = self::BuildVar($key, $value); } if ($ticket['user_id'] == 0) { $vars[] = self::BuildVar('user_name', $ticket['unregname']); $vars[] = self::BuildVar('user_username', JText::_("UNREGISTERED")); $vars[] = self::BuildVar('user_email', $ticket['email']); } else { $vars[] = self::BuildVar('user_name', $custrec['name']); $vars[] = self::BuildVar('user_username', $custrec['username']); $vars[] = self::BuildVar('user_email', $custrec['email']); } $vars[] = self::BuildVar('handler_name', $handler['name']); $vars[] = self::BuildVar('handler_username', $handler['username']); $vars[] = self::BuildVar('handler_email', $handler['email']); $vars[] = self::BuildVar('ticket_id', $ticket['id']); if ($foruser) { $statuss = SupportHelper::getStatuss(false); $status = $statuss[$ticket['ticket_status_id']]; if ($status->combine_with > 0) { $status = $statuss[$status->combine_with]; } FSS_Translate_Helper::TrO($status); $text = $status->title; if ($status->userdisp) { $text = $status->userdisp; } $vars[] = self::BuildVar('status', $text); } else { $vars[] = self::BuildVar('status', self::GetStatus($ticket['ticket_status_id'])); } $vars[] = self::BuildVar('priority', self::GetPriority($ticket['ticket_pri_id'])); $vars[] = self::BuildVar('category', self::GetCategory($ticket['ticket_cat_id'])); $vars[] = self::BuildVar('department', self::GetDepartment($ticket['ticket_dept_id'])); $vars[] = self::BuildVar('department_desc', strip_tags(self::GetDepartment($ticket['ticket_dept_id'], 'description'))); $vars[] = self::BuildVar('department_desc_html', self::GetDepartment($ticket['ticket_dept_id'], 'description')); $vars[] = self::BuildVar('product', self::GetProduct($ticket['prod_id'])); $vars[] = self::BuildVar('product_desc', strip_tags(self::GetProduct($ticket['prod_id'], 'description'))); $vars[] = self::BuildVar('product_desc_html', self::GetProduct($ticket['prod_id'], 'description')); if (strpos($template['body'], "{messagehistory}") > 0) { $messages = self::GetMessageHist($ticket['id']); $text = self::ParseMessageRows($messages, $ishtml, $foruser); $vars[] = self::BuildVar('messagehistory', $text); } $uri = JURI::getInstance(); $baseUrl = FSS_Settings::get('support_email_no_domain') ? "" : $uri->toString(array('scheme', 'host', 'port')); if (in_array(FSS_Settings::get('support_unreg_type'), array(0, 1))) { $vars[] = self::BuildVar('haspassword', 1); } else { $vars[] = self::BuildVar('haspassword', 0); } // choose which user link to generate if ($ticket['user_id'] < 1) { // unregistered user $url = 'index.php?option=com_fss&t=' . $ticket['id'] . "&p=" . $ticket['password']; if (FSS_Settings::get('support_email_link_unreg') > 0) { // add fixed item id if needed $url .= "&Itemid=" . FSS_Settings::get('support_email_link_unreg'); } $vars[] = self::BuildVar('ticket_link', $baseUrl . JRoute::_($url, false)); } else { // registered user $url = 'index.php?option=com_fss&view=ticket&layout=view&ticketid=' . $ticket['id']; if (FSS_Settings::get('support_email_include_autologin')) { $url .= "&login={login_code}"; } if (FSS_Settings::get('support_email_link_reg') > 0) { // add fixed item id if needed $url .= "&Itemid=" . FSS_Settings::get('support_email_link_reg'); } $vars[] = self::BuildVar('ticket_link', $baseUrl . JRoute::_($url, false)); } // ticket admin link $url = 'index.php?option=com_fss&view=admin_support&layout=ticket&ticketid=' . $ticket['id']; if (FSS_Settings::get('support_email_link_admin') > 0) { // add fixed item id if needed $url .= "&Itemid=" . FSS_Settings::get('support_email_link_admin'); } $vars[] = self::BuildVar('admin_link', $baseUrl . JRoute::_($url, false)); // email pending link $url = 'index.php?option=com_fss&view=admin_support&layout=emails'; if (FSS_Settings::get('support_email_link_pending') > 0) { // add fixed item id if needed $url .= "&Itemid=" . FSS_Settings::get('support_email_link_pending'); } $vars[] = self::BuildVar('email_pending_link', $baseUrl . JRoute::_($url, false)); $vars[] = self::BuildVar('websitetitle', FSS_Helper::getSiteName()); // need to add the tickets custom fields to the output here $fields = FSSCF::GetAllCustomFields(true); $values = FSSCF::GetTicketValues($ticket['id'], $ticket); foreach ($fields as $fid => &$field) { $name = "custom_" . $fid; $value = ""; if (array_key_exists($fid, $values)) { $value = (string) $values[$fid]['value']; } $fieldvalues = array(); $fieldvalues[0]['field_id'] = $fid; $fieldvalues[0]['value'] = $value; // only do area output processing if we are in html mode if ($field['type'] != "area" || $ishtml) { $newvalue = FSSCF::FieldOutput($field, $fieldvalues, ''); if ($newvalue) { $value = $newvalue; } } $vars[] = self::BuildVar($name, $value); $vars[] = self::BuildVar("custom_" . $field['alias'], $value); } $email['subject'] = self::ParseText($template['subject'], $vars); $email['body'] = self::ParseText($template['body'], $vars); self::$last_vars = $vars; if ($template['ishtml']) { $email['body'] = FSS_Helper::MaxLineLength($email['body']); } else { $email['body'] = str_replace("<br />", "\n", $email['body']); $email['body'] = html_entity_decode($email['body']); $email['body'] = preg_replace_callback("/(&#[0-9]+;)/", array("FSS_Helper", "email_decode_utf8"), $email['body']); $email['body'] = strip_tags($email['body']); } $email['body'] = str_replace("XXXLTXXX", "<", $email['body']); $email['body'] = str_replace("XXXGTXXX", ">", $email['body']); return $email; }