?> <?php if (module_config::c('ticket_turn_around_rate_show', 1)) { ?> <tr> <th class="width1"> <?php echo _l('Rate'); ?> </th> <td> <?php $rate = module_ticket::get_reply_rate(); echo _l('We are currently processing about %s tickets every 24 hours', $rate['daily']); ?> </td> </tr> <?php } ?> </tbody> </table> <?php } ?>
public function external_hook($hook) { switch ($hook) { case 'attachment': $ticket_id = isset($_REQUEST['t']) ? (int) $_REQUEST['t'] : false; $ticket_message_attachment_id = isset($_REQUEST['tma']) ? (int) $_REQUEST['tma'] : false; $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false; if ($ticket_id && $ticket_message_attachment_id && $hash) { $correct_hash = $this->link_open_attachment($ticket_id, $ticket_message_attachment_id, true); if ($correct_hash == $hash) { $attach = get_single('ticket_message_attachment', 'ticket_message_attachment_id', $ticket_message_attachment_id); if (file_exists('includes/plugin_ticket/attachments/' . $attach['ticket_message_attachment_id'])) { header("Content-type: application/octet-stream"); header('Content-Disposition: attachment; filename="' . $attach['file_name'] . '";'); $size = @readfile('includes/plugin_ticket/attachments/' . $attach['ticket_message_attachment_id']); if (!$size) { echo file_get_contents('includes/plugin_ticket/attachments/' . $attach['ticket_message_attachment_id']); } } else { echo 'File no longer exists'; } } } exit; break; case 'status': ob_start(); ?> <table class="wpetss wpetss_status"> <tbody> <tr> <th><?php _e('New/Pending Tickets'); ?> </th> <td> <?php $sql = "SELECT COUNT(ticket_id) AS c FROM `" . _DB_PREFIX . "ticket` WHERE status_id = 1 OR status_id = 2"; $res = qa1($sql); echo $res['c']; ?> </td> </tr> <tr> <th><?php _e('In Progress Tickets'); ?> </th> <td> <?php $sql = "SELECT COUNT(ticket_id) AS c FROM `" . _DB_PREFIX . "ticket` WHERE status_id = 3 OR status_id = " . _TICKET_STATUS_IN_PROGRESS_ID; $res = qa1($sql); echo $res['c']; ?> </td> </tr> <tr> <th><?php _e('Resolved Tickets'); ?> </th> <td> <?php $sql = "SELECT COUNT(ticket_id) AS c FROM `" . _DB_PREFIX . "ticket` WHERE status_id >= " . _TICKET_STATUS_RESOLVED_ID; $res = qa1($sql); echo $res['c']; ?> </td> </tr> <tr> <th><?php _e('Estimated Turn Around'); ?> </th> <td> <?php echo _l('We will reply within %s and %s %S', module_config::c('ticket_turn_around_days_min', 2), module_config::c('ticket_turn_around_days', 5), module_config::c('ticket_turn_around_period', 'days')); ?> </td> </tr> <tr> <th><?php _e('Current Reply Rate'); ?> </th> <td> <?php $rate = module_ticket::get_reply_rate(); echo _l('We are currently processing %s tickets every 24 hours', $rate['daily']); ?> </td> </tr> </tbody> </table> <?php echo preg_replace('/\\s+/', ' ', ob_get_clean()); exit; break; case 'public_new': $ticket_id = 'new'; $ticket_account_id = module_config::c('ticket_default_account_id', 0); //todo: set from a hashed variable in GET string. if ($ticket_account_id) { $ticket_account = self::get_ticket_account($ticket_account_id); } else { $ticket_account_id = 0; $ticket_account = array(); } if (!$ticket_account || $ticket_account['ticket_account_id'] != $ticket_account_id) { // dont support accounts yet. work out the default customer id etc.. from settings. $ticket_account = array('ticket_account_id' => 0, 'default_customer_id' => module_config::c('ticket_default_customer_id', 1), 'default_user_id' => module_config::c('ticket_default_user_id', 1), 'default_type' => module_config::c('ticket_type_id_default', 0)); } // hack to better support recaptcha errors. $save_public_ticket = false; $errors = array(); if (isset($_REQUEST['_process']) && $_REQUEST['_process'] == 'save_public_ticket') { // user is saving the ticket. // process it! $save_public_ticket = true; if (module_config::c('ticket_recaptcha', 1)) { if (!module_captcha::check_captcha_form()) { // captcha was wrong. $errors[] = _l('Sorry the captcha code you entered was incorrect. Please try again.'); if (isset($_FILES['attachment']) && isset($_FILES['attachment']['tmp_name']) && is_array($_FILES['attachment']['tmp_name'])) { foreach ($_FILES['attachment']['tmp_name'] as $key => $val) { if (is_uploaded_file($val)) { $errors[] = _l('Please select your file attachments again as well.'); break; } } } $save_public_ticket = false; } } } if ($save_public_ticket && isset($_POST['new_ticket_message']) && strlen($_POST['new_ticket_message']) > 1) { // this allows input variables to be added to our $_POST // like extra fields etc.. from envato module. handle_hook('ticket_create_post', $ticket_id); // we're posting from a public account. // check required fields. if (!trim($_POST['subject'])) { return false; } // check this user has a valid email address, find/create a user in the ticket user table. // see if this email address exists in the wp user table, and link that user there. $email = trim(strtolower($_POST['email'])); $name = trim($_POST['name']); if (strpos($email, '@')) { //todo - validate email. $sql = "SELECT * FROM `" . _DB_PREFIX . "user` u WHERE u.`email` LIKE '" . mysql_real_escape_string($email) . "'"; $from_user = qa1($sql); if ($from_user) { $from_user_id = $from_user['user_id']; // woo!! found a user. assign this customer to the ticket. if ($from_user['customer_id']) { $ticket_account['default_customer_id'] = $from_user['customer_id']; } } else { // create a user under this account customer. $default_customer_id = 0; if ($ticket_account && $ticket_account['default_customer_id']) { $default_customer_id = $ticket_account['default_customer_id']; } // create a new support user! go go! if (strlen($name)) { $bits = explode(' ', $name); $first_name = array_shift($bits); $last_name = implode(' ', $bits); } else { $first_name = $email; $last_name = ''; } $from_user = array('name' => $first_name, 'last_name' => $last_name, 'customer_id' => $default_customer_id, 'email' => $email, 'status_id' => 1, 'password' => substr(md5(time() . mt_rand(0, 600)), 3, 7)); global $plugins; $from_user_id = $plugins['user']->create_user($from_user); // todo: set the default role for this user // based on the settings /*}else{ echo 'Failed - no from accoutn set'; return; }*/ } if (!$from_user_id) { echo 'Failed - cannot find the from user id'; echo $email . ' to support<hr>'; return; } // what type of ticket is this? $public_types = $this->get_types(true); $ticket_type_id = $ticket_account['default_type']; if (isset($_POST['ticket_type_id']) && isset($public_types[$_POST['ticket_type_id']])) { $ticket_type_id = $_POST['ticket_type_id']; } // echo $ticket_type_id;exit; $ticket_data = array('user_id' => $from_user_id, 'force_logged_in_user_id' => $from_user_id, 'assigned_user_id' => $ticket_account['default_user_id'] ? $ticket_account['default_user_id'] : 0, 'ticket_type_id' => $ticket_type_id, 'customer_id' => $ticket_account['default_customer_id'], 'status_id' => 2, 'ticket_account_id' => $ticket_account_id, 'unread' => 1, 'subject' => $_POST['subject'], 'new_ticket_message' => $_POST['new_ticket_message'], 'ticket_extra' => isset($_POST['ticket_extra']) && is_array($_POST['ticket_extra']) ? $_POST['ticket_extra'] : array(), 'faq_product_id' => isset($_POST['faq_product_id']) ? (int) $_POST['faq_product_id'] : 0); if (isset($public_types[$ticket_type_id]) && isset($public_types[$ticket_type_id]['default_user_id']) && $public_types[$ticket_type_id]['default_user_id'] > 0) { $ticket_data['assigned_user_id'] = $public_types[$ticket_type_id]['default_user_id']; } if (module_config::c('ticket_allow_priority_selection', 0) && isset($_POST['priority'])) { $priorities = $this->get_ticket_priorities(); if (isset($priorities[$_POST['priority']])) { $ticket_data['priority'] = $_POST['priority']; } } $ticket_id = $this->save_ticket('new', $ticket_data); // check if they want a priority support if (isset($_POST['do_priority']) && $_POST['do_priority']) { // generate a "priority invoice" against this support ticket using the invoice module. // this will display the invoice in the sidebar and the user can pay. $this->generate_priority_invoice($ticket_id); } handle_hook('ticket_public_created', $ticket_id); // where to redirect? $url = module_config::c('ticket_public_new_redirect', ''); if (!$url) { $url = $this->link_public($ticket_id); } redirect_browser($url); } } $ticket = self::get_ticket($ticket_id); include 'public/ticket_customer_new.php'; break; case 'public_status': $ticket_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $new_status_id = isset($_REQUEST['s']) ? (int) $_REQUEST['s'] : false; $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false; if ($ticket_id && $new_status_id && $hash) { $correct_hash = $this->link_public_status($ticket_id, $new_status_id, true); if ($correct_hash == $hash) { // change the status. update_insert('ticket_id', $ticket_id, 'ticket', array('status_id' => $new_status_id)); module_template::init_template('ticket_status_change', '<h2>Ticket</h2> <p>Thank you. Your support ticket status has been adjusted.</p> <p>Please <a href="{TICKET_URL}">click here</a> to view your ticket.</p> ', 'Displayed after an external ticket status is changed.', 'code'); // correct! // load up the receipt template. $template = module_template::get_template_by_key('ticket_status_change'); $data = $this->get_ticket($ticket_id); $data['ticket_url'] = $this->link_public($ticket_id); $template->page_title = _l("Ticket"); $template->assign_values(self::get_replace_fields($ticket_id, $data)); $template->assign_values($data); echo $template->render('pretty_html'); } } exit; break; case 'public': $ticket_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false; if ($ticket_id && $hash) { $correct_hash = $this->link_public($ticket_id, true); if ($correct_hash == $hash) { // all good to print a receipt for this payment. $ticket = $this->get_ticket($ticket_id); if (isset($_POST['_process']) && $_POST['_process'] == 'send_public_ticket') { // user is saving the ticket. // process it! if (isset($_POST['new_ticket_message']) && strlen($_POST['new_ticket_message']) > 1) { // post a new reply to this message. // who are we replying to? // it's either a reply from the admin, or from the user via the web interface. $ticket_creator = $ticket['user_id']; $to_user_id = $ticket['assigned_user_id'] ? $ticket['assigned_user_id'] : module_config::c('ticket_default_user_id', 1); $ticket_message_id = $this->send_reply($ticket_id, $_POST['new_ticket_message'], $ticket_creator, $to_user_id, 'end_user'); /*$new_status_id = $ticket['status_id']; if($ticket['status_id']>=6){ // it's cancelled or resolved. }*/ $new_status_id = 5; if ($ticket_message_id) { // so we can track a history of ticket status changes update_insert("ticket_message_id", $ticket_message_id, "ticket_message", array('status_id' => $new_status_id)); } update_insert("ticket_id", $ticket_id, "ticket", array('unread' => 1, 'status_id' => $new_status_id)); } if (isset($_REQUEST['generate_priority_invoice'])) { $invoice_id = $this->generate_priority_invoice($ticket_id); redirect_browser(module_invoice::link_public($invoice_id)); } // where to redirect? $url = module_config::c('ticket_public_reply_redirect', ''); if (!$url) { $url = $this->link_public($ticket_id); } redirect_browser($url); } if ($ticket && $ticket['ticket_id'] == $ticket_id) { $admins_rel = self::get_ticket_staff_rel(); /*if(!isset($logged_in_user) || !$logged_in_user){ // we assume the user is on the public side. // use the creator id as the logged in id. $logged_in_user = module_security::get_loggedin_id(); }*/ // public hack, we are the ticket responder. $logged_in_user = $ticket['user_id']; $ticket_creator = $ticket['user_id']; if ($ticket_creator == $logged_in_user) { // we are sending a reply back to the admin, from the end user. $to_user_id = $ticket['assigned_user_id'] ? $ticket['assigned_user_id'] : module_config::c('ticket_default_user_id', 1); $from_user_id = $logged_in_user; } else { // we are sending a reply back to the ticket user. $to_user_id = $ticket['user_id']; $from_user_id = $logged_in_user; } $to_user_a = module_user::get_user($to_user_id, false); $from_user_a = module_user::get_user($from_user_id, false); if (isset($ticket['ticket_account_id']) && $ticket['ticket_account_id']) { $ticket_account = module_ticket::get_ticket_account($ticket['ticket_account_id']); } else { $ticket_account = false; } if ($ticket_account && $ticket_account['email']) { $reply_to_address = $ticket_account['email']; $reply_to_name = $ticket_account['name']; } else { // reply to creator. $reply_to_address = $from_user_a['email']; $reply_to_name = $from_user_a['name']; } if ($ticket_creator == $logged_in_user) { $send_as_name = $from_user_a['name']; $send_as_address = $from_user_a['email']; } else { $send_as_address = $reply_to_address; $send_as_name = $reply_to_name; } $admins_rel = self::get_ticket_staff_rel(); ob_start(); include 'public/ticket_customer_view.php'; $html = ob_get_clean(); module_template::init_template('external_ticket_public_view', '{TICKET_HTML}', 'Used when displaying the external view of a ticket to the customer.', 'code'); $template = module_template::get_template_by_key('external_ticket_public_view'); $template->assign_values(array('ticket_html' => $html)); $template->page_title = _l('Ticket: %s', module_ticket::ticket_number($ticket['ticket_id'])); echo $template->render('pretty_html'); exit; } else { _e('Permission Denied. Please logout and try again.'); } } } break; } }