} break; /* Large text box */ /* Large text box */ case 'textarea': $size = explode('#', $v['value']); $size[0] = empty($size[0]) ? 5 : intval($size[0]); $size[1] = empty($size[1]) ? 30 : intval($size[1]); $k_value = hesk_msgToPlain($k_value, 0, 0); echo $v['name'] . ': <textarea name="' . $k . '" rows="' . $size[0] . '" cols="' . $size[1] . '">' . $k_value . '</textarea>'; break; /* Default text input */ /* Default text input */ default: if (strlen($k_value) != 0) { $k_value = hesk_msgToPlain($k_value, 0, 0); $v['value'] = $k_value; } echo $v['name'] . ': <input type="text" name="' . $k . '" size="40" maxlength="' . $v['maxlen'] . '" value="' . $v['value'] . '" />'; } } } ?> </div><!-- end edit-post-info-table --> </div> <?php } ?> <div class="form-inline"> <label class="col-sm-2"><?php
function forgot_tid() { global $hesk_settings, $hesklang; require HESK_PATH . 'inc/email_functions.inc.php'; $email = hesk_validateEmail(hesk_POST('email'), 'ERR', 0) or hesk_process_messages($hesklang['enter_valid_email'], 'ticket.php?remind=1'); if (isset($_POST['open_only'])) { $hesk_settings['open_only'] = $_POST['open_only'] == 1 ? 1 : 0; } /* Prepare ticket statuses */ $my_status = array(0 => $hesklang['open'], 1 => $hesklang['wait_staff_reply'], 2 => $hesklang['wait_cust_reply'], 3 => $hesklang['closed'], 4 => $hesklang['in_progress'], 5 => $hesklang['on_hold']); /* Get ticket(s) from database */ hesk_load_database_functions(); hesk_dbConnect(); // Get tickets from the database $res = hesk_dbQuery('SELECT * FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'tickets` FORCE KEY (`statuses`) WHERE ' . ($hesk_settings['open_only'] ? "`status` IN ('0','1','2','4','5') AND " : '') . ' ' . hesk_dbFormatEmail($email) . ' ORDER BY `status` ASC, `lastchange` DESC '); $num = hesk_dbNumRows($res); if ($num < 1) { if ($hesk_settings['open_only']) { hesk_process_messages($hesklang['noopen'], 'ticket.php?remind=1&e=' . $email); } else { hesk_process_messages($hesklang['tid_not_found'], 'ticket.php?remind=1&e=' . $email); } } $tid_list = ''; $name = ''; $email_param = $hesk_settings['email_view_ticket'] ? '&e=' . rawurlencode($email) : ''; while ($my_ticket = hesk_dbFetchAssoc($res)) { $name = $name ? $name : hesk_msgToPlain($my_ticket['name'], 1, 0); $tid_list .= "\n{$hesklang['trackID']}: " . $my_ticket['trackid'] . "\n{$hesklang['subject']}: " . hesk_msgToPlain($my_ticket['subject'], 1, 0) . "\n{$hesklang['status']}: " . $my_status[$my_ticket['status']] . "\n{$hesk_settings['hesk_url']}/ticket.php?track={$my_ticket['trackid']}{$email_param}\n"; } /* Get e-mail message for customer */ $msg = hesk_getEmailMessage('forgot_ticket_id', '', 0, 0, 1); $msg = str_replace('%%NAME%%', $name, $msg); $msg = str_replace('%%NUM%%', $num, $msg); $msg = str_replace('%%LIST_TICKETS%%', $tid_list, $msg); $msg = str_replace('%%SITE_TITLE%%', hesk_msgToPlain($hesk_settings['site_title'], 1), $msg); $msg = str_replace('%%SITE_URL%%', $hesk_settings['site_url'], $msg); $subject = hesk_getEmailSubject('forgot_ticket_id'); /* Send e-mail */ hesk_mail($email, $subject, $msg); /* Show success message */ $tmp = '<b>' . $hesklang['tid_sent'] . '!</b>'; $tmp .= '<br /> <br />' . $hesklang['tid_sent2'] . '.'; $tmp .= '<br /> <br />' . $hesklang['check_spambox']; hesk_process_messages($tmp, 'ticket.php?e=' . $email, 'SUCCESS'); exit; }
} else { // Get user data from the database $res = hesk_dbQuery("SELECT `id`, `name`, `pass` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` WHERE `email` LIKE '" . hesk_dbEscape($email) . "' LIMIT 1"); if (hesk_dbNumRows($res) != 1) { hesk_process_messages($hesklang['noace'], 'NOREDIRECT'); } else { $row = hesk_dbFetchAssoc($res); $hash = sha1(microtime() . $_SERVER['REMOTE_ADDR'] . mt_rand() . $row['id'] . $row['name'] . $row['pass']); // Insert the verification hash into the database hesk_dbQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "reset_password` (`user`, `hash`, `ip`) VALUES (" . intval($row['id']) . ", '{$hash}', '" . hesk_dbEscape($_SERVER['REMOTE_ADDR']) . "') "); // Prepare and send email require HESK_PATH . 'inc/email_functions.inc.php'; // Get the email message $msg = hesk_getEmailMessage('reset_password', array(), 1, 0, 1); // Replace message special tags $msg = str_replace('%%NAME%%', hesk_msgToPlain($row['name'], 1, 1), $msg); $msg = str_replace('%%SITE_URL%%', $hesk_settings['site_url'], $msg); $msg = str_replace('%%SITE_TITLE%%', $hesk_settings['site_title'], $msg); $msg = str_replace('%%PASSWORD_RESET%%', $hesk_settings['hesk_url'] . '/' . $hesk_settings['admin_dir'] . '/password.php?h=' . $hash, $msg); // Send email hesk_mail($email, $hesklang['reset_password'], $msg); // Show success hesk_process_messages($hesklang['pemls'], 'NOREDIRECT', 'SUCCESS'); } } } elseif (isset($_GET['h'])) { // Get the hash $hash = preg_replace('/[^a-zA-Z0-9]/', '', $_GET['h']); // Connect to database hesk_load_database_functions(); hesk_dbConnect();
<Cell ss:StyleID="s62"><Data ss:Type="DateTime">' . $ticket['dt'] . '</Data></Cell> <Cell ss:StyleID="s62"><Data ss:Type="DateTime">' . $ticket['lastchange'] . '</Data></Cell> <Cell><Data ss:Type="String"><![CDATA[' . hesk_msgToPlain($ticket['name'], 1) . ']]></Data></Cell> <Cell><Data ss:Type="String"><![CDATA[' . $ticket['email'] . ']]></Data></Cell> <Cell><Data ss:Type="String"><![CDATA[' . $my_cat[$ticket['category']] . ']]></Data></Cell> <Cell><Data ss:Type="String"><![CDATA[' . $ticket['priority'] . ']]></Data></Cell> <Cell><Data ss:Type="String"><![CDATA[' . $ticket['status'] . ']]></Data></Cell> <Cell><Data ss:Type="String"><![CDATA[' . $ticket['subject'] . ']]></Data></Cell> <Cell><Data ss:Type="String"><![CDATA[' . $ticket['message'] . ']]></Data></Cell> <Cell><Data ss:Type="String"><![CDATA[' . $ticket['owner'] . ']]></Data></Cell> <Cell><Data ss:Type="String"><![CDATA[' . $ticket['time_worked'] . ']]></Data></Cell> '; // Add custom fields foreach ($hesk_settings['custom_fields'] as $k => $v) { if ($v['use']) { $tmp .= '<Cell><Data ss:Type="String"><![CDATA[' . hesk_msgToPlain($ticket[$k], 1) . ']]></Data></Cell> ' . "\n"; } } $tmp .= "</Row>\n"; // Write every 100 rows into the file if ($this_round >= $save_after) { file_put_contents($save_to, $tmp, FILE_APPEND); $this_round = 0; $tmp = ''; usleep(1); } $tickets_exported++; $this_round++; } // End of while loop // Append any remaining rows into the file
function hesk_email2ticket($results, $pop3 = 0, $set_category = 1, $set_priority = -1) { global $hesk_settings, $hesklang, $hesk_db_link, $ticket; // Process "Reply-To:" or "From:" email $tmpvar['email'] = isset($results['reply-to'][0]['address']) ? hesk_validateEmail($results['reply-to'][0]['address'], 'ERR', 0) : hesk_validateEmail($results['from'][0]['address'], 'ERR', 0); // Email missing, invalid or banned? if (!$tmpvar['email'] || hesk_isBannedEmail($tmpvar['email'])) { return hesk_cleanExit(); } // Process "Reply-To:" or "From:" name, convert to UTF-8, set to "[Customer]" if not set if (isset($results['reply-to'][0]['name']) && strlen($results['reply-to'][0]['name'])) { $tmpvar['name'] = $results['reply-to'][0]['name']; if (!empty($results['reply-to'][0]['encoding'])) { $tmpvar['name'] = hesk_encodeUTF8($tmpvar['name'], $results['reply-to'][0]['encoding']); } } else { $tmpvar['name'] = isset($results['from'][0]['name']) ? $results['from'][0]['name'] : $hesklang['pde']; if (!empty($results['from'][0]['encoding'])) { $tmpvar['name'] = hesk_encodeUTF8($tmpvar['name'], $results['from'][0]['encoding']); } } $tmpvar['name'] = hesk_input($tmpvar['name'], '', '', 1, 50) or $tmpvar['name'] = $hesklang['pde']; // Process "To:" email (not yet implemented, for future use) // $tmpvar['to_email'] = hesk_validateEmail($results['to'][0]['address'],'ERR',0); // Process email subject, convert to UTF-8, set to "[Piped email]" if none set $tmpvar['subject'] = isset($results['subject']) ? $results['subject'] : $hesklang['pem']; if (!empty($results['subject_encoding'])) { $tmpvar['subject'] = hesk_encodeUTF8($tmpvar['subject'], $results['subject_encoding']); } $tmpvar['subject'] = hesk_input($tmpvar['subject'], '', '', 1, 70) or $tmpvar['subject'] = $hesklang['pem']; // Process email message, convert to UTF-8 $tmpvar['message'] = isset($results['message']) ? $results['message'] : ''; if (!empty($results['encoding'])) { $tmpvar['message'] = hesk_encodeUTF8($tmpvar['message'], $results['encoding']); } $tmpvar['message'] = hesk_input($tmpvar['message'], '', '', 1); // Message missing? if (strlen($tmpvar['message']) == 0) { // Message required? Ignore this email. if ($hesk_settings['eml_req_msg']) { return hesk_cleanExit(); } // Message not required? Assign a default message $tmpvar['message'] = $hesklang['def_msg']; // Track duplicate emails based on subject $message_hash = md5($tmpvar['subject']); } else { $message_hash = md5($tmpvar['message']); } // Strip quoted reply from email $tmpvar['message'] = hesk_stripQuotedText($tmpvar['message']); // Convert URLs to links, change newlines to <br /> $tmpvar['message'] = hesk_makeURL($tmpvar['message']); $tmpvar['message'] = nl2br($tmpvar['message']); # For debugging purposes # die( bin2hex($tmpvar['message']) ); # die($tmpvar['message']); // Try to detect "delivery failed" and "noreply" emails - ignore if detected if (hesk_isReturnedEmail($tmpvar)) { return hesk_cleanExit(); } // Check for email loops if (hesk_isEmailLoop($tmpvar['email'], $message_hash)) { return hesk_cleanExit(); } // OK, everything seems OK. Now determine if this is a reply to a ticket or a new ticket if (preg_match('/\\[#([A-Z0-9]{3}\\-[A-Z0-9]{3}\\-[A-Z0-9]{4})\\]/', str_replace(' ', '', $tmpvar['subject']), $matches)) { // We found a possible tracking ID $tmpvar['trackid'] = $matches[1]; // Does it match one in the database? $res = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` WHERE `trackid`='" . hesk_dbEscape($tmpvar['trackid']) . "' LIMIT 1"); if (hesk_dbNumRows($res)) { $ticket = hesk_dbFetchAssoc($res); // Do email addresses match? if (strpos(strtolower($ticket['email']), strtolower($tmpvar['email'])) === false) { $tmpvar['trackid'] = ''; } // Is this ticket locked? Force create a new one if it is if ($ticket['locked']) { $tmpvar['trackid'] = ''; } } else { $tmpvar['trackid'] = ''; } } // If tracking ID is empty, generate a new one if (empty($tmpvar['trackid'])) { $tmpvar['trackid'] = hesk_createID(); $is_reply = 0; } else { $is_reply = 1; } // Process attachments $tmpvar['attachmment_notices'] = ''; $tmpvar['attachments'] = ''; $num = 0; if ($hesk_settings['attachments']['use'] && isset($results['attachments'][0])) { foreach ($results['attachments'] as $k => $v) { // Clean attachment names $myatt['real_name'] = hesk_cleanFileName($v['orig_name']); // Check number of attachments, delete any over max number if ($num >= $hesk_settings['attachments']['max_number']) { $tmpvar['attachmment_notices'] .= sprintf($hesklang['attnum'], $myatt['real_name']) . "\n"; continue; } // Check file extension $ext = strtolower(strrchr($myatt['real_name'], ".")); if (!in_array($ext, $hesk_settings['attachments']['allowed_types'])) { $tmpvar['attachmment_notices'] .= sprintf($hesklang['atttyp'], $myatt['real_name']) . "\n"; continue; } // Check file size $myatt['size'] = $v['size']; if ($myatt['size'] > $hesk_settings['attachments']['max_size']) { $tmpvar['attachmment_notices'] .= sprintf($hesklang['attsiz'], $myatt['real_name']) . "\n"; continue; } // Generate a random file name $useChars = 'AEUYBDGHJLMNPQRSTVWXZ123456789'; $tmp = $useChars[mt_rand(0, 29)]; for ($j = 1; $j < 10; $j++) { $tmp .= $useChars[mt_rand(0, 29)]; } $myatt['saved_name'] = substr($tmpvar['trackid'] . '_' . md5($tmp . $myatt['real_name']), 0, 200) . $ext; // Rename the temporary file rename($v['stored_name'], HESK_PATH . $hesk_settings['attach_dir'] . '/' . $myatt['saved_name']); // Insert into database hesk_dbQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "attachments` (`ticket_id`,`saved_name`,`real_name`,`size`) VALUES ('" . hesk_dbEscape($tmpvar['trackid']) . "','" . hesk_dbEscape($myatt['saved_name']) . "','" . hesk_dbEscape($myatt['real_name']) . "','" . intval($myatt['size']) . "')"); $tmpvar['attachments'] .= hesk_dbInsertID() . '#' . $myatt['real_name'] . ','; $num++; } if (strlen($tmpvar['attachmment_notices'])) { $tmpvar['message'] .= "<br /><br />" . hesk_input($hesklang['attrem'], '', '', 1) . "<br />" . nl2br(hesk_input($tmpvar['attachmment_notices'], '', '', 1)); } } // Delete the temporary files deleteAll($results['tempdir']); // If this is a reply add a new reply if ($is_reply) { // Set last replier name to customer name $ticket['lastreplier'] = $tmpvar['name'] == $hesklang['pde'] ? $tmpvar['email'] : $tmpvar['name']; // If staff hasn't replied yet, keep ticket status "New", otherwise set it to "Waiting reply from staff" $ticket['status'] = $ticket['status'] ? 1 : 0; // Update ticket as necessary hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `lastchange`=NOW(),`status`='{$ticket['status']}',`replies`=`replies`+1,`lastreplier`='0' WHERE `id`='" . intval($ticket['id']) . "' LIMIT 1"); // If customer replied, we assume staff replies have been read (no way to be sure if ticket.php hasn't been opened) hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "replies` SET `read` = '1' WHERE `replyto` = '" . intval($ticket['id']) . "' AND `staffid` != '0' "); // Insert reply into database hesk_dbQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "replies` (`replyto`,`name`,`message`,`dt`,`attachments`) VALUES ('" . intval($ticket['id']) . "','" . hesk_dbEscape($ticket['lastreplier']) . "','" . hesk_dbEscape($tmpvar['message']) . "',NOW(),'" . hesk_dbEscape($tmpvar['attachments']) . "')"); // --> Prepare reply message // 1. Generate the array with ticket info that can be used in emails $info = array('email' => $ticket['email'], 'category' => $ticket['category'], 'priority' => $ticket['priority'], 'owner' => $ticket['owner'], 'trackid' => $ticket['trackid'], 'status' => $ticket['status'], 'name' => $ticket['name'], 'lastreplier' => $ticket['lastreplier'], 'subject' => $ticket['subject'], 'message' => stripslashes($tmpvar['message']), 'attachments' => $tmpvar['attachments'], 'dt' => hesk_date($ticket['dt'], true), 'lastchange' => hesk_date($ticket['lastchange'], true), 'id' => $ticket['id']); // 2. Add custom fields to the array foreach ($hesk_settings['custom_fields'] as $k => $v) { $info[$k] = $v['use'] ? $ticket[$k] : ''; } // 3. Make sure all values are properly formatted for email $ticket = hesk_ticketToPlain($info, 1, 0); // --> Process custom fields before sending foreach ($hesk_settings['custom_fields'] as $k => $v) { $ticket[$k] = $v['use'] ? hesk_msgToPlain($ticket[$k], 1) : ''; } // --> If ticket is assigned just notify the owner if ($ticket['owner']) { hesk_notifyAssignedStaff(false, 'new_reply_by_customer', 'notify_reply_my'); } else { hesk_notifyStaff('new_reply_by_customer', "`notify_reply_unassigned`='1'"); } return $ticket['trackid']; } // END REPLY // Not a reply, but a new ticket. Add it to the database $tmpvar['category'] = $set_category; $tmpvar['priority'] = $set_priority < 0 ? hesk_getCategoryPriority($tmpvar['category']) : $set_priority; $_SERVER['REMOTE_ADDR'] = $hesklang['unknown']; // Auto assign tickets if aplicable $tmpvar['owner'] = 0; $tmpvar['history'] = $pop3 ? sprintf($hesklang['thist16'], hesk_date()) : sprintf($hesklang['thist11'], hesk_date()); $tmpvar['openedby'] = $pop3 ? -2 : -1; $autoassign_owner = hesk_autoAssignTicket($tmpvar['category']); #print_r($autoassign_owner); if ($autoassign_owner) { $tmpvar['owner'] = $autoassign_owner['id']; $tmpvar['history'] .= sprintf($hesklang['thist10'], hesk_date(), $autoassign_owner['name'] . ' (' . $autoassign_owner['user'] . ')'); } // Custom fields will be empty as there is no reliable way of detecting them foreach ($hesk_settings['custom_fields'] as $k => $v) { $tmpvar[$k] = ''; } // Insert ticket to database $ticket = hesk_newTicket($tmpvar); // Notify the customer if ($hesk_settings['notify_new']) { $possible_SPAM = false; // Do we need to check subject for SPAM tags? if ($hesk_settings['notify_skip_spam']) { foreach ($hesk_settings['notify_spam_tags'] as $tag) { if (strpos($tmpvar['subject'], $tag) !== false) { $possible_SPAM = true; break; } } } // SPAM tags not found or not checked, send email if ($possible_SPAM === false) { hesk_notifyCustomer(); } } // Need to notify staff? // --> From autoassign? if ($tmpvar['owner'] && $autoassign_owner['notify_assigned']) { hesk_notifyAssignedStaff($autoassign_owner, 'ticket_assigned_to_you'); } elseif (!$tmpvar['owner']) { hesk_notifyStaff('new_ticket_staff', " `notify_new_unassigned` = '1' "); } return $ticket['trackid']; }
function mail_send() { global $hesk_settings, $hesklang; /* A security check */ hesk_token_check('POST'); $hesk_error_buffer = ''; /* Recipient */ $_SESSION['mail']['to'] = intval(hesk_POST('to')); /* Valid recipient? */ if (empty($_SESSION['mail']['to'])) { $hesk_error_buffer .= '<li>' . $hesklang['m_rec'] . '</li>'; } elseif ($_SESSION['mail']['to'] == $_SESSION['id']) { $hesk_error_buffer .= '<li>' . $hesklang['m_inr'] . '</li>'; } else { $res = hesk_dbQuery("SELECT `name`,`email`,`notify_pm` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` WHERE `id`='" . intval($_SESSION['mail']['to']) . "' LIMIT 1"); $num = hesk_dbNumRows($res); if (!$num) { $hesk_error_buffer .= '<li>' . $hesklang['m_inr'] . '</li>'; } else { $pm_recipient = hesk_dbFetchAssoc($res); } } /* Subject */ $_SESSION['mail']['subject'] = hesk_input(hesk_POST('subject')) or $hesk_error_buffer .= '<li>' . $hesklang['m_esu'] . '</li>'; /* Message */ $_SESSION['mail']['message'] = hesk_input(hesk_POST('message')) or $hesk_error_buffer .= '<li>' . $hesklang['enter_message'] . '</li>'; /* Any errors? */ if (strlen($hesk_error_buffer)) { $_SESSION['hide']['list'] = 1; $hesk_error_buffer = $hesklang['rfm'] . '<br /><br /><ul>' . $hesk_error_buffer . '</ul>'; hesk_process_messages($hesk_error_buffer, 'NOREDIRECT'); } else { $_SESSION['mail']['message'] = hesk_makeURL($_SESSION['mail']['message']); $_SESSION['mail']['message'] = nl2br($_SESSION['mail']['message']); hesk_dbQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "mail` (`from`,`to`,`subject`,`message`,`dt`,`read`) VALUES ('" . intval($_SESSION['id']) . "','" . intval($_SESSION['mail']['to']) . "','" . hesk_dbEscape($_SESSION['mail']['subject']) . "','" . hesk_dbEscape($_SESSION['mail']['message']) . "',NOW(),'0')"); /* Notify receiver via e-mail? */ if (isset($pm_recipient) && $pm_recipient['notify_pm']) { $pm_id = hesk_dbInsertID(); $pm = array('name' => hesk_msgToPlain(addslashes($_SESSION['name']), 1, 1), 'subject' => hesk_msgToPlain($_SESSION['mail']['subject'], 1, 1), 'message' => hesk_msgToPlain($_SESSION['mail']['message'], 1, 1), 'id' => $pm_id); /* Format email subject and message for recipient */ $subject = hesk_getEmailSubject('new_pm', $pm, 0); $message = hesk_getEmailMessage('new_pm', $pm, 1, 0); /* Send e-mail */ hesk_mail($pm_recipient['email'], $subject, $message); } unset($_SESSION['mail']); hesk_process_messages($hesklang['m_pms'], './mail.php', 'SUCCESS'); } }
function edit_article() { global $hesk_settings, $hesklang, $listBox; $hesk_error_buffer = array(); $id = intval(hesk_GET('id')) or hesk_process_messages($hesklang['kb_art_id'], './manage_knowledgebase.php'); /* Get article details */ $result = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_articles` WHERE `id`='" . intval($id) . "' LIMIT 1"); if (hesk_dbNumRows($result) != 1) { hesk_process_messages($hesklang['kb_art_id'], './manage_knowledgebase.php'); } $article = hesk_dbFetchAssoc($result); if ($hesk_settings['kb_wysiwyg'] || $article['html']) { $article['content'] = hesk_htmlspecialchars($article['content']); } else { $article['content'] = hesk_msgToPlain($article['content']); } $catid = $article['catid']; if (isset($_SESSION['edit_article'])) { $_SESSION['edit_article'] = hesk_stripArray($_SESSION['edit_article']); $article['type'] = $_SESSION['edit_article']['type']; $article['html'] = $_SESSION['edit_article']['html']; $article['subject'] = $_SESSION['edit_article']['subject']; $article['content'] = $_SESSION['edit_article']['content']; $article['keywords'] = $_SESSION['edit_article']['keywords']; $article['catid'] = $_SESSION['edit_article']['catid']; $article['sticky'] = $_SESSION['edit_article']['sticky']; } /* Get categories */ $result = hesk_dbQuery('SELECT * FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'kb_categories` ORDER BY `parent` ASC, `cat_order` ASC'); $kb_cat = array(); while ($cat = hesk_dbFetchAssoc($result)) { $kb_cat[] = $cat; if ($cat['id'] == $article['catid']) { $this_cat = $cat; $this_cat['parent'] = $article['catid']; } } /* Translate main category "Knowledgebase" if needed */ $kb_cat[0]['name'] = $hesklang['kb_text']; require HESK_PATH . 'inc/treemenu/TreeMenu.php'; $icon = HESK_PATH . 'img/folder.gif'; $expandedIcon = HESK_PATH . 'img/folder-expanded.gif'; $menu = new HTML_TreeMenu(); $thislevel = array('0'); $nextlevel = array(); $i = 1; $j = 1; while (count($kb_cat) > 0) { foreach ($kb_cat as $k => $cat) { if (in_array($cat['parent'], $thislevel)) { $up = $cat['parent']; $my = $cat['id']; $type = $cat['type'] ? '*' : ''; $text_short = $cat['name'] . $type . ' (' . $cat['articles'] . ', ' . $cat['articles_private'] . ', ' . $cat['articles_draft'] . ')'; if (isset($node[$up])) { $node[$my] =& $node[$up]->addItem(new HTML_TreeNode(array('hesk_parent' => $this_cat['parent'], 'text' => 'Text', 'text_short' => $text_short, 'hesk_catid' => $cat['id'], 'hesk_select' => 'option' . $j, 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => true))); } else { $node[$my] = new HTML_TreeNode(array('hesk_parent' => $this_cat['parent'], 'text' => 'Text', 'text_short' => $text_short, 'hesk_catid' => $cat['id'], 'hesk_select' => 'option' . $j, 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => true)); } $nextlevel[] = $cat['id']; $j++; unset($kb_cat[$k]); } } $thislevel = $nextlevel; $nextlevel = array(); /* Break after 20 recursions to avoid hang-ups in case of any problems */ if ($i > 20) { break; } $i++; } $menu->addItem($node[1]); // Create the presentation class $listBox =& ref_new(new HTML_TreeMenu_Listbox($menu)); /* Print header */ require_once HESK_PATH . 'inc/header.inc.php'; /* Print main manage users page */ require_once HESK_PATH . 'inc/show_admin_nav.inc.php'; ?> <div class="container new-manage-kb-title"><a href="manage_knowledgebase.php" class="smaller"><b><?php echo $hesklang['kb']; ?> </a></b> > <a href="manage_knowledgebase.php?a=manage_cat&catid=<?php echo $catid; ?> " class="smaller"><?php echo $hesklang['kb_cat_man']; ?> </a> > <?php echo $hesklang['kb_art_edit']; ?> </div> <?php /* This will handle error, success and notice messages */ hesk_handle_messages(); ?> <div> <?php echo '<div class="container kb_art_edit_title">' . $hesklang['kb_art_edit'] . '</div>'; ?> <?php if ($hesk_settings['kb_wysiwyg']) { ?> <script type="text/javascript"> tinyMCE.init({ mode : "exact", elements : "content", theme : "advanced", convert_urls : false, gecko_spellcheck: true, theme_advanced_buttons1 : "cut,copy,paste,|,undo,redo,|,formatselect,fontselect,fontsizeselect,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull", theme_advanced_buttons2 : "sub,sup,|,charmap,|,bullist,numlist,|,outdent,indent,insertdate,inserttime,preview,|,forecolor,backcolor,|,hr,removeformat,visualaid,|,link,unlink,anchor,image,cleanup,code", theme_advanced_buttons3 : "", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom", theme_advanced_resizing : true }); </script> <?php } ?> <div class="container kb_art_edit_title_form"> <br/> <form action="manage_knowledgebase.php" method="post" name="form1" enctype="multipart/form-data"> <div class="form-inline"> <span class="col-sm-2"><b><?php echo $hesklang['kb_cat']; ?> :</b></span> <span><select name="catid"><?php $listBox->printMenu(); ?> </select></span> </div> <br/> <div class="form-inline"> <span class="col-sm-2"><b><?php echo $hesklang['kb_type']; ?> :</b></span> <div class="form-group"> <label><input type="radio" name="type" value="0" <?php if ($article['type'] == 0) { echo 'checked="checked"'; } ?> /> <b><i><?php echo $hesklang['kb_published']; ?> </i></b></label><br /> <span><?php echo $hesklang['kb_published2']; ?> </span><br /> <br/> <label><input type="radio" name="type" value="1" <?php if ($article['type'] == 1) { echo 'checked="checked"'; } ?> /> <b><i><?php echo $hesklang['kb_private']; ?> </i></b></label><br /> <span><?php echo $hesklang['kb_private2']; ?> </span><br /> <br/> <label><input type="radio" name="type" value="2" <?php if ($article['type'] == 2) { echo 'checked="checked"'; } ?> /> <b><i><?php echo $hesklang['kb_draft']; ?> </i></b></label><br /> <span><?php echo $hesklang['kb_draft2']; ?> </span> </div> </div> <br/> <div class="form-inline"> <span class="col-sm-2"><b><?php echo $hesklang['kb_subject']; ?> :</b></span> <span><input class="form-control" type="text" name="subject" size="70" maxlength="255" value="<?php echo $article['subject']; ?> " /></span> </div> <br/> <div class="form-inline"> <span class="col-sm-2"><b><?php echo $hesklang['opt']; ?> :</b></span> <div class="form-group"> <label><input type="checkbox" name="sticky" value="Y" <?php if ($article['sticky']) { echo 'checked="checked"'; } ?> /> <i><?php echo $hesklang['sticky']; ?> </i></label> [<a href="javascript:void(0)" onclick="javascript:alert('<?php echo hesk_makeJsString($hesklang['saa']); ?> ')"><b>?</b></a>]<br /> <label><input type="checkbox" name="resetviews" value="Y" <?php if (isset($_SESSION['edit_article']['resetviews']) && $_SESSION['edit_article']['resetviews'] == 'Y') { echo 'checked="checked"'; } ?> /> <i><?php echo $hesklang['rv']; ?> </i></label><br /> <label><input type="checkbox" name="resetvotes" value="Y" <?php if (isset($_SESSION['edit_article']['resetvotes']) && $_SESSION['edit_article']['resetvotes'] == 'Y') { echo 'checked="checked"'; } ?> /> <i><?php echo $hesklang['rr']; ?> </i></label> </div> </div> <br/> <div class="form-inline"> <?php $displayType = $hesk_settings['kb_wysiwyg'] ? 'none' : 'block'; $displayWarn = $article['html'] ? 'block' : 'none'; ?> <span class="col-sm-2"><b><?php echo $hesklang['kb_content']; ?> :</b></span> <span id="contentType" style="display:<?php echo $displayType; ?> "> <label><input type="radio" name="html" value="0" <?php if (!$article['html']) { echo 'checked="checked"'; } ?> onclick="javascript:document.getElementById('kblinks').style.display = 'none'" /> <?php echo $hesklang['kb_dhtml']; ?> </label><br /> <label><input type="radio" name="html" value="1" <?php if ($article['html']) { echo 'checked="checked"'; } ?> onclick="javascript:document.getElementById('kblinks').style.display = 'block'" /> <?php echo $hesklang['kb_ehtml']; ?> </label> <span id="kblinks" style="display:<?php echo $displayWarn; ?> "><i><?php echo $hesklang['kb_links']; ?> </i></span> </span> <textarea name="content" rows="25" cols="70" id="content" style="width:48.9%; height:300px"><?php echo $article['content']; ?> </textarea> </div> <br/> <div class="form-inline"> <span class="col-sm-2"><?php echo $hesklang['kw']; ?> :</b></span> <div class="form-group textarea-kw"> <span><textarea class="form-control" name="keywords" rows="3" cols="70" id="keywords"><?php echo $article['keywords']; ?> </textarea></span><br/> <span><?php echo $hesklang['kw1']; ?> </span> </div> </div> <br/> <div class="form-inline"> <span class="col-sm-2"><b><?php echo $hesklang['attachments']; ?> </b></span> <div class="form-group"> <?php if (!empty($article['attachments'])) { $att = explode(',', substr($article['attachments'], 0, -1)); foreach ($att as $myatt) { list($att_id, $att_name) = explode('#', $myatt); $tmp = 'White'; $style = 'class="option' . $tmp . 'OFF" onmouseover="this.className=\'option' . $tmp . 'ON\'" onmouseout="this.className=\'option' . $tmp . 'OFF\'"'; echo '<a href="manage_knowledgebase.php?a=remove_kb_att&id=' . $id . '&kb_att=' . $att_id . '&token=' . hesk_token_echo(0) . '" onclick="return hesk_confirmExecute(\'' . hesk_makeJsString($hesklang['delatt']) . '\');"><img src="../img/delete.png" width="16" height="16" alt="' . $hesklang['dela'] . '" title="' . $hesklang['dela'] . '" ' . $style . ' /></a> '; echo '<a href="../download_attachment.php?kb_att=' . $att_id . '"><img src="../img/clip.png" width="16" height="16" alt="' . $hesklang['dnl'] . ' ' . $att_name . '" title="' . $hesklang['dnl'] . ' ' . $att_name . '" ' . $style . ' /></a> '; echo '<a href="../download_attachment.php?kb_att=' . $att_id . '">' . $att_name . '</a><br />'; } echo '<br />'; } ?> <div id="chooseFile-addReply"><input type="file" name="attachment[1]" size="50" /></div> <div id="chooseFile-addReply"><input type="file" name="attachment[2]" size="50" /></div> <div id="chooseFile-addReply"><input type="file" name="attachment[3]" size="50" /></div> <span>(<a href="Javascript:void(0)" onclick="Javascript:hesk_window('../file_limits.php',250,500);return false;"><?php echo $hesklang['ful']; ?> </a>)</span> </div> </div> <br/> <div class="container"> <input type="hidden" name="a" value="save_article" /> <input type="hidden" name="id" value="<?php echo $id; ?> " /> <input type="hidden" name="old_type" value="<?php echo $article['type']; ?> " /> <input type="hidden" name="old_catid" value="<?php echo $catid; ?> " /> <input type="hidden" name="token" value="<?php hesk_token_echo(); ?> " /> <input type="submit" value="<?php echo $hesklang['kb_save']; ?> " class="btn btn-default save-article-btn" /> <a href="manage_knowledgebase.php?a=manage_cat&catid=<?php echo $catid; ?> "><input type="submit" value="<?php echo $hesklang['cancel']; ?> " class="btn btn-default cancel-article-btn" /></a> </div> </form> <br/> </div> </div> <div class="container revision-history-title"><?php echo $hesklang['revhist']; ?> </div> <div class="revision-history"> <br/> <ul><?php echo $article['history']; ?> </ul> <br/> </div> <?php /* Clean unneeded session variables */ hesk_cleanSessionVars('edit_article'); require_once HESK_PATH . 'inc/footer.inc.php'; exit; }
function hesk_processMessage($msg, $ticket, $is_admin, $is_ticket, $just_message, $isForHtml = 0) { global $hesk_settings, $hesklang, $modsForHesk_settings; /* Return just the message without any processing? */ if ($just_message) { return $msg; } // Convert any entities in site title to plain text $hesk_settings['site_title'] = hesk_msgToPlain($hesk_settings['site_title'], 1); /* If it's not a ticket-related mail (like "a new PM") just process quickly */ if (!$is_ticket) { $trackingURL = $hesk_settings['hesk_url'] . '/' . $hesk_settings['admin_dir'] . '/mail.php?a=read&id=' . intval($ticket['id']); $msg = str_replace('%%NAME%%', $ticket['name'], $msg); $msg = str_replace('%%SUBJECT%%', $ticket['subject'], $msg); $msg = str_replace('%%TRACK_URL%%', $trackingURL, $msg); $msg = str_replace('%%SITE_TITLE%%', $hesk_settings['site_title'], $msg); $msg = str_replace('%%SITE_URL%%', $hesk_settings['site_url'], $msg); if (isset($ticket['message'])) { if ($isForHtml) { $htmlMessage = nl2br($ticket['message']); return str_replace('%%MESSAGE%%', $htmlMessage, $msg); } return str_replace('%%MESSAGE%%', $ticket['message'], $msg); } else { return $msg; } } // Is email required to view ticket (for customers only)? $hesk_settings['e_param'] = $hesk_settings['email_view_ticket'] ? '&e=' . rawurlencode($ticket['email']) : ''; /* Generate the ticket URLs */ $trackingURL = $hesk_settings['hesk_url']; $trackingURL .= $is_admin ? '/' . $hesk_settings['admin_dir'] . '/admin_ticket.php' : '/ticket.php'; $trackingURL .= '?track=' . $ticket['trackid'] . ($is_admin ? '' : $hesk_settings['e_param']) . '&Refresh=' . rand(10000, 99999); /* Set category title */ $ticket['category'] = hesk_msgToPlain(hesk_getCategoryName($ticket['category']), 1); /* Set priority title */ switch ($ticket['priority']) { case 0: $ticket['priority'] = $hesklang['critical']; break; case 1: $ticket['priority'] = $hesklang['high']; break; case 2: $ticket['priority'] = $hesklang['medium']; break; default: $ticket['priority'] = $hesklang['low']; } /* Get owner name */ $ticket['owner'] = hesk_msgToPlain(hesk_getOwnerName($ticket['owner']), 1); /* Set status */ $statusRs = hesk_dbQuery("SELECT `Key` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` WHERE `ID` = " . $ticket['status']); $row = hesk_dbFetchAssoc($statusRs); $ticket['status'] = $hesklang[$row['Key']]; /* Replace all special tags */ $msg = str_replace('%%NAME%%', $ticket['name'], $msg); $msg = str_replace('%%SUBJECT%%', $ticket['subject'], $msg); $msg = str_replace('%%TRACK_ID%%', $ticket['trackid'], $msg); $msg = str_replace('%%TRACK_URL%%', $trackingURL, $msg); $msg = str_replace('%%SITE_TITLE%%', $hesk_settings['site_title'], $msg); $msg = str_replace('%%SITE_URL%%', $hesk_settings['site_url'], $msg); $msg = str_replace('%%CATEGORY%%', $ticket['category'], $msg); $msg = str_replace('%%PRIORITY%%', $ticket['priority'], $msg); $msg = str_replace('%%OWNER%%', $ticket['owner'], $msg); $msg = str_replace('%%STATUS%%', $ticket['status'], $msg); $msg = str_replace('%%EMAIL%%', $ticket['email'], $msg); $msg = str_replace('%%CREATED%%', $ticket['dt'], $msg); $msg = str_replace('%%UPDATED%%', $ticket['lastchange'], $msg); $msg = str_replace('%%ID%%', $ticket['id'], $msg); /* All custom fields */ foreach ($hesk_settings['custom_fields'] as $k => $v) { if ($v['use']) { if ($v['type'] == 'checkbox') { $ticket[$k] = str_replace("<br />", "\n", $ticket[$k]); } $msg = str_replace('%%' . strtoupper($k) . '%%', stripslashes($ticket[$k]), $msg); } else { $msg = str_replace('%%' . strtoupper($k) . '%%', '', $msg); } } // Is message tag in email template? if (strpos($msg, '%%MESSAGE%%') !== false) { // Replace message if ($isForHtml) { $htmlMessage = nl2br($ticket['message']); $msg = str_replace('%%MESSAGE%%', $htmlMessage, $msg); } else { $msg = str_replace('%%MESSAGE%%', $ticket['message'], $msg); } // Add direct links to any attachments at the bottom of the email message OR add them as attachments, depending on the settings // if ($modsForHesk_settings['attachments'] == 'inline' (other is 'attachment') {...} if ($hesk_settings['attachments']['use'] && isset($ticket['attachments']) && strlen($ticket['attachments'])) { if (!$modsForHesk_settings['attachments']) { if ($isForHtml) { $msg .= "<br><br><br>" . $hesklang['fatt']; } else { $msg .= "\n\n\n" . $hesklang['fatt']; } $att = explode(',', substr($ticket['attachments'], 0, -1)); foreach ($att as $myatt) { list($att_id, $att_name, $saved_name) = explode('#', $myatt); if ($isForHtml) { $msg .= "<br><br>" . $att_name . "<br>"; } else { $msg .= "\n\n" . $att_name . "\n"; } $msg .= $hesk_settings['hesk_url'] . '/download_attachment.php?att_id=' . $att_id . '&track=' . $ticket['trackid'] . $hesk_settings['e_param']; } } // If attachments setting is set to 1, we'll add the attachments separately later; otherwise we'll duplicate the number of attachments. } // For customer notifications: if we allow email piping/pop 3 fetching and // stripping quoted replies add an "reply above this line" tag if (!$is_admin && ($hesk_settings['email_piping'] || $hesk_settings['pop3']) && $hesk_settings['strip_quoted']) { $msg = $hesklang['EMAIL_HR'] . "\n\n" . $msg; } } return $msg; }
if (isset($_POST['save'])) { // A security check hesk_token_check('POST'); // Get message $tmpvar['message'] = nl2br(hesk_makeURL(hesk_input(hesk_POST('message')))); // If we have message or attachments do the update if (strlen($tmpvar['message']) || strlen($note['attachments'])) { hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` SET `message`='" . hesk_dbEscape($tmpvar['message']) . "' WHERE `id`={$noteID}"); hesk_process_messages($hesklang['ednote2'], 'admin_ticket.php?track=' . $trackingID . '&Refresh=' . mt_rand(10000, 99999), 'SUCCESS'); } else { hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "notes` WHERE `id`={$noteID}"); header('Location: admin_ticket.php?track=' . $trackingID . '&Refresh=' . mt_rand(10000, 99999)); exit; } } $note['message'] = hesk_msgToPlain($note['message'], 0, 0); /* Print header */ require_once HESK_PATH . 'inc/header.inc.php'; /* Print admin navigation */ require_once HESK_PATH . 'inc/show_admin_nav.inc.php'; ?> <!-- </td> </tr>--> <!-- start in this page end somewhere... <tr> <td> -->
function forgot_tid() { global $hesk_settings, $hesklang; require HESK_PATH . 'inc/email_functions.inc.php'; $email = hesk_validateEmail(hesk_POST('email'), 'ERR', 0) or hesk_process_messages($hesklang['enter_valid_email'], 'ticket.php?remind=1'); /* Prepare ticket statuses */ $my_status = array(0 => $hesklang['open'], 1 => $hesklang['wait_staff_reply'], 2 => $hesklang['wait_cust_reply'], 3 => $hesklang['closed'], 4 => $hesklang['in_progress'], 5 => $hesklang['on_hold']); /* Get ticket(s) from database */ hesk_load_database_functions(); hesk_dbConnect(); // Get tickets from the database $res = hesk_dbQuery('SELECT * FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'tickets` FORCE KEY (`statuses`) WHERE ' . ($hesk_settings['open_only'] ? "`status` IN ('0','1','2','4','5') AND " : '') . ' ' . hesk_dbFormatEmail($email) . ' ORDER BY `status` ASC, `lastchange` DESC '); $num = hesk_dbNumRows($res); if ($num < 1) { if ($hesk_settings['open_only']) { hesk_process_messages($hesklang['noopen'], 'ticket.php?remind=1&e=' . $email); } else { hesk_process_messages($hesklang['tid_not_found'], 'ticket.php?remind=1&e=' . $email); } } $tid_list = ''; $name = ''; $email_param = $hesk_settings['email_view_ticket'] ? '&e=' . rawurlencode($email) : ''; while ($my_ticket = hesk_dbFetchAssoc($res)) { $name = $name ? $name : hesk_msgToPlain($my_ticket['name'], 1, 0); $tid_list .= "\r\n{$hesklang['trackID']}: " . $my_ticket['trackid'] . "\r\n{$hesklang['subject']}: " . hesk_msgToPlain($my_ticket['subject'], 1, 0) . "\r\n{$hesklang['status']}: " . $my_status[$my_ticket['status']] . "\r\n{$hesk_settings['hesk_url']}/ticket.php?track={$my_ticket['trackid']}{$email_param}\r\n"; } /* Get e-mail message for customer */ $msg = hesk_getEmailMessage('forgot_ticket_id', '', 0, 0, 1); $msg = str_replace('%%NAME%%', $name, $msg); $msg = str_replace('%%NUM%%', $num, $msg); $msg = str_replace('%%LIST_TICKETS%%', $tid_list, $msg); $msg = str_replace('%%SITE_TITLE%%', hesk_msgToPlain($hesk_settings['site_title'], 1), $msg); $msg = str_replace('%%SITE_URL%%', $hesk_settings['site_url'], $msg); $subject = hesk_getEmailSubject('forgot_ticket_id'); /* Send e-mail */ hesk_mail($email, $subject, $msg); /* Show success message */ $tmp = '<b>' . $hesklang['tid_sent'] . '!</b>'; $tmp .= '<br /> <br />' . $hesklang['tid_sent2'] . '.'; $tmp .= '<br /> <br />' . $hesklang['check_spambox']; hesk_process_messages($tmp, 'ticket.php?e=' . $email, 'SUCCESS'); exit; /* Print header */ $hesk_settings['tmp_title'] = $hesk_settings['hesk_title'] . ' - ' . $hesklang['tid_sent']; require_once HESK_PATH . 'inc/header.inc.php'; ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="3"><img src="img/headerleftsm.jpg" width="3" height="25" alt="" /></td> <td class="headersm"><?php hesk_showTopBar($hesklang['tid_sent']); ?> </td> <td width="3"><img src="img/headerrightsm.jpg" width="3" height="25" alt="" /></td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="3"> <tr> <td><span class="smaller"><a href="<?php echo $hesk_settings['site_url']; ?> " class="smaller"><?php echo $hesk_settings['site_title']; ?> </a> > <a href="<?php echo $hesk_settings['hesk_url']; ?> " class="smaller"><?php echo $hesk_settings['hesk_title']; ?> </a> > <?php echo $hesklang['tid_sent']; ?> </span></td> </tr> </table> </td> </tr> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="7" height="7"><img src="img/roundcornerslt.jpg" width="7" height="7" alt="" /></td> <td class="roundcornerstop"></td> <td><img src="img/roundcornersrt.jpg" width="7" height="7" alt="" /></td> </tr> <tr> <td class="roundcornersleft"> </td> <td> <p> </p> <p align="center"><?php echo $hesklang['tid_sent2']; ?> </p> <p align="center"><b><?php echo $hesklang['check_spambox']; ?> </b></p> <p> </p> <p align="center"><a href="<?php echo $hesk_settings['hesk_url']; ?> "><?php echo $hesk_settings['hesk_title']; ?> </a></p> <p> </p> </td> <td class="roundcornersright"> </td> </tr> <tr> <td><img src="img/roundcornerslb.jpg" width="7" height="7" alt="" /></td> <td class="roundcornersbottom"></td> <td width="7" height="7"><img src="img/roundcornersrb.jpg" width="7" height="7" alt="" /></td> </tr> </table> <?php }
function hesk_ticketToPlain($ticket, $specialchars = 0, $strip = 1) { if (is_array($ticket)) { foreach ($ticket as $key => $value) { $ticket[$key] = is_array($ticket[$key]) ? hesk_ticketToPlain($value, $specialchars, $strip) : hesk_msgToPlain($value, $specialchars, $strip); } return $ticket; } else { return hesk_msgToPlain($ticket, $specialchars, $strip); } }
function hesk_getEmailMessage($eml_file, $ticket, $is_admin = 0, $is_ticket = 1, $just_message = 0) { global $hesk_settings, $hesklang; // Demo mode if (defined('HESK_DEMO')) { return ''; } /* Get list of valid emails */ $valid_emails = hesk_validEmails(); /* Verify this is a valid email include */ if (!isset($valid_emails[$eml_file])) { hesk_error($hesklang['inve']); } /* Get email template */ $eml_file = 'language/' . $hesk_settings['languages'][$hesk_settings['language']]['folder'] . '/emails/' . $eml_file . '.txt'; if (file_exists(HESK_PATH . $eml_file)) { $msg = file_get_contents(HESK_PATH . $eml_file); } else { hesk_error($hesklang['emfm'] . ': ' . $eml_file); } /* Return just the message without any processing? */ if ($just_message) { return $msg; } // Convert any entities in site title to plain text $hesk_settings['site_title'] = hesk_msgToPlain($hesk_settings['site_title'], 1); /* If it's not a ticket-related mail (like "a new PM") just process quickly */ if (!$is_ticket) { $trackingURL = $hesk_settings['hesk_url'] . '/' . $hesk_settings['admin_dir'] . '/mail.php?a=read&id=' . intval($ticket['id']); $msg = str_replace('%%NAME%%', $ticket['name'], $msg); $msg = str_replace('%%SUBJECT%%', $ticket['subject'], $msg); $msg = str_replace('%%TRACK_URL%%', $trackingURL, $msg); $msg = str_replace('%%SITE_TITLE%%', $hesk_settings['site_title'], $msg); $msg = str_replace('%%SITE_URL%%', $hesk_settings['site_url'], $msg); if (isset($ticket['message'])) { return str_replace('%%MESSAGE%%', $ticket['message'], $msg); } else { return $msg; } } // Is email required to view ticket (for customers only)? $hesk_settings['e_param'] = $hesk_settings['email_view_ticket'] ? '&e=' . rawurlencode($ticket['email']) : ''; /* Generate the ticket URLs */ $trackingURL = $hesk_settings['hesk_url']; $trackingURL .= $is_admin ? '/' . $hesk_settings['admin_dir'] . '/admin_ticket.php' : '/ticket.php'; $trackingURL .= '?track=' . $ticket['trackid'] . ($is_admin ? '' : $hesk_settings['e_param']) . '&Refresh=' . rand(10000, 99999); /* Set category title */ $ticket['category'] = hesk_msgToPlain(hesk_getCategoryName($ticket['category']), 1); /* Set priority title */ switch ($ticket['priority']) { case 0: $ticket['priority'] = $hesklang['critical']; break; case 1: $ticket['priority'] = $hesklang['high']; break; case 2: $ticket['priority'] = $hesklang['medium']; break; default: $ticket['priority'] = $hesklang['low']; } /* Get owner name */ $ticket['owner'] = hesk_msgToPlain(hesk_getOwnerName($ticket['owner']), 1); /* Set status */ switch ($ticket['status']) { case 1: $ticket['status'] = $hesklang['wait_reply']; break; case 2: $ticket['status'] = $hesklang['replied']; break; case 3: $ticket['status'] = $hesklang['closed']; break; case 4: $ticket['status'] = $hesklang['in_progress']; break; case 5: $ticket['status'] = $hesklang['on_hold']; break; default: $ticket['status'] = $hesklang['open']; } /* Replace all special tags */ $msg = str_replace('%%NAME%%', $ticket['name'], $msg); $msg = str_replace('%%SUBJECT%%', $ticket['subject'], $msg); $msg = str_replace('%%TRACK_ID%%', $ticket['trackid'], $msg); $msg = str_replace('%%TRACK_URL%%', $trackingURL, $msg); $msg = str_replace('%%SITE_TITLE%%', $hesk_settings['site_title'], $msg); $msg = str_replace('%%SITE_URL%%', $hesk_settings['site_url'], $msg); $msg = str_replace('%%CATEGORY%%', $ticket['category'], $msg); $msg = str_replace('%%PRIORITY%%', $ticket['priority'], $msg); $msg = str_replace('%%OWNER%%', $ticket['owner'], $msg); $msg = str_replace('%%STATUS%%', $ticket['status'], $msg); $msg = str_replace('%%EMAIL%%', $ticket['email'], $msg); $msg = str_replace('%%CREATED%%', $ticket['dt'], $msg); $msg = str_replace('%%UPDATED%%', $ticket['lastchange'], $msg); $msg = str_replace('%%ID%%', $ticket['id'], $msg); /* All custom fields */ foreach ($hesk_settings['custom_fields'] as $k => $v) { if ($v['use']) { if ($v['type'] == 'checkbox') { $ticket[$k] = str_replace("<br />", "\n", $ticket[$k]); } $msg = str_replace('%%' . strtoupper($k) . '%%', stripslashes($ticket[$k]), $msg); } else { $msg = str_replace('%%' . strtoupper($k) . '%%', '', $msg); } } // Is message tag in email template? if (strpos($msg, '%%MESSAGE%%') !== false) { // Replace message $msg = str_replace('%%MESSAGE%%', $ticket['message'], $msg); // Add direct links to any attachments at the bottom of the email message if ($hesk_settings['attachments']['use'] && isset($ticket['attachments']) && strlen($ticket['attachments'])) { $msg .= "\n\n\n" . $hesklang['fatt']; $att = explode(',', substr($ticket['attachments'], 0, -1)); foreach ($att as $myatt) { list($att_id, $att_name) = explode('#', $myatt); $msg .= "\n\n" . $att_name . "\n" . $hesk_settings['hesk_url'] . '/download_attachment.php?att_id=' . $att_id . '&track=' . $ticket['trackid'] . $hesk_settings['e_param']; } } // For customer notifications: if we allow email piping/pop 3 fetching and // stripping quoted replies add an "reply above this line" tag if (!$is_admin && ($hesk_settings['email_piping'] || $hesk_settings['pop3']) && $hesk_settings['strip_quoted']) { $msg = $hesklang['EMAIL_HR'] . "\n\n" . $msg; } } return $msg; }
function processEmail($msg, $name, $num, $tid_list) { global $hesk_settings; $msg = str_replace('%%NAME%%', $name, $msg); $msg = str_replace('%%NUM%%', $num, $msg); $msg = str_replace('%%LIST_TICKETS%%', $tid_list, $msg); $msg = str_replace('%%SITE_TITLE%%', hesk_msgToPlain($hesk_settings['site_title'], 1), $msg); $msg = str_replace('%%SITE_URL%%', $hesk_settings['site_url'], $msg); return $msg; }