Example #1
0
 /**
  * Standard modular run function for change_detection hooks. They see if their own something has changed in comparison to sample data.
  *
  * @param  string			The sample data, serialised and then MD5'd
  * @return boolean		Whether the something has changed
  */
 function run($data)
 {
     if (get_param('type', 'misc') == 'misc') {
         require_code('tickets');
         require_code('tickets2');
         $ticket_type = get_param_integer('ticket_type', NULL);
         $tickets = get_tickets(get_member(), $ticket_type);
         return md5(serialize($tickets)) != $data;
     }
     $id = get_param('id', NULL);
     require_code('tickets');
     require_code('tickets2');
     $forum = 0;
     $topic_id = 0;
     $ticket_type = 0;
     $_comments = get_ticket_posts($id, $forum, $topic_id, $ticket_type);
     return md5(serialize($_comments)) != $data;
 }
Example #2
0
 /**
  * Actualise ticket creation/reply, then show the ticket again.
  *
  * @return tempcode		The UI
  */
 function do_update_ticket()
 {
     $title = get_page_title('SUPPORT_TICKETS');
     $id = get_param('id');
     $_title = post_param('title');
     $post = post_param('post');
     if ($post == '') {
         warn_exit(do_lang_tempcode('NO_PARAMETER_SENT', 'post'));
     }
     $ticket_type = post_param_integer('ticket_type', -1);
     $this->check_id($id);
     $staff_only = post_param_integer('staff_only', 0) == 1;
     // Update
     $_home_url = build_url(array('page' => '_SELF', 'type' => 'ticket', 'id' => $id, 'redirect' => NULL), '_SELF', NULL, false, true, true);
     $home_url = $_home_url->evaluate();
     $email = '';
     if ($ticket_type != -1) {
         $type_string = get_translated_text($ticket_type);
         $ticket_type_details = get_ticket_type($ticket_type);
         //$_title=$type_string.' ('.$_title.')';
         if (!has_category_access(get_member(), 'tickets', $type_string)) {
             access_denied('I_ERROR');
         }
         // Check FAQ search results first
         if ($ticket_type_details['search_faq'] && post_param_integer('faq_searched', 0) == 0) {
             $results = $this->do_search($title, $id, $post);
             if (!is_null($results)) {
                 return $results;
             }
         }
         $new_post = new ocp_tempcode();
         $new_post->attach(do_lang('THIS_WITH_COMCODE', do_lang('TICKET_TYPE'), $type_string) . "\n\n");
         $email = trim(post_param('email', ''));
         if ($email != '') {
             $body = '> ' . str_replace(chr(10), chr(10) . '> ', $post);
             if (substr($body, -2) == '> ') {
                 $body = substr($body, 0, strlen($body) - 2);
             }
             $new_post->attach('[email subject="Re: ' . comcode_escape(post_param('title')) . ' [' . get_site_name() . ']" body="' . comcode_escape($body) . '"]' . $email . '[/email]' . "\n\n");
         } elseif (is_guest() && $ticket_type_details['guest_emails_mandatory']) {
             // Error if the e-mail address is required for this ticket type
             warn_exit(do_lang_tempcode('ERROR_GUEST_EMAILS_MANDATORY'));
         }
         $new_post->attach($post);
         $post = $new_post->evaluate();
     }
     if (addon_installed('captcha')) {
         if (get_option('captcha_on_feedback') == '1') {
             require_code('captcha');
             enforce_captcha();
         }
     }
     ticket_add_post(get_member(), $id, $ticket_type, $_title, $post, $home_url, $staff_only);
     // Find true ticket title
     $_forum = 1;
     $_topic_id = 1;
     $_ticket_type = 1;
     // These will be returned by reference
     $posts = get_ticket_posts($id, $_forum, $_topic_id, $_ticket_type);
     if (!is_array($posts)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $__title = $_title;
     foreach ($posts as $ticket_post) {
         $__title = $ticket_post['title'];
         if ($__title != '') {
             break;
         }
     }
     // Send email
     if (!$staff_only) {
         if ($email == '') {
             $email = $GLOBALS['FORUM_DRIVER']->get_member_email_address(get_member());
         }
         send_ticket_email($id, $__title, $post, $home_url, $email, $ticket_type);
     }
     $url = build_url(array('page' => '_SELF', 'type' => 'ticket', 'id' => $id), '_SELF');
     if (is_guest()) {
         $url = build_url(array('page' => '_SELF'), '_SELF');
     }
     if (get_param('redirect', '') != '') {
         $url = make_string_tempcode(get_param('redirect'));
     }
     return redirect_screen($title, $url, do_lang_tempcode('TICKET_STARTED'));
 }
Example #3
0
/**
 * Update the cache of ticket type lead times (average time taken for a response to tickets of that type) in the database.
 * This is a query-intensive function, so should only be run occasionally.
 */
function update_ticket_type_lead_times()
{
    require_code('feedback');
    $ticket_types = $GLOBALS['SITE_DB']->query_select('ticket_types', NULL);
    foreach ($ticket_types as $ticket_type) {
        $total_lead_time = 0;
        $tickets_counted = 0;
        $tickets = $GLOBALS['SITE_DB']->query_select('tickets', NULL, array('ticket_type' => $ticket_type['ticket_type']));
        foreach ($tickets as $ticket) {
            $max_rows = 0;
            $topic = $GLOBALS['FORUM_DRIVER']->show_forum_topics($ticket['forum_id'], 1, 0, $max_rows, $ticket['ticket_id'], true, 'lasttime', false, do_lang('SUPPORT_TICKET') . ': #' . $ticket['ticket_id']);
            if (is_null($topic)) {
                continue;
            }
            $topic = $topic[0];
            // We need to have two posts for new-style tickets, or three for old-style tickets (with spacers)
            if ($topic['num'] < 2 || $topic['firstusername'] == do_lang('SYSTEM') && $topic['num'] < 3) {
                continue;
            }
            $ticket_id = extract_topic_identifier($topic['description']);
            $_forum = 1;
            $_topic_id = 1;
            $_ticket_type = 1;
            // These will be returned by reference
            $posts = get_ticket_posts($ticket_id, $_forum, $_topic_id, $_ticket_type);
            // Differentiate between old- and new-style tickets
            if ($topic['firstusername'] == do_lang('SYSTEM')) {
                $first_key = 1;
            } else {
                $first_key = 0;
            }
            // Find the first post by someone other than the ticket owner
            $i = $first_key + 1;
            while (array_key_exists($i, $posts) && $posts[$i]['user'] != $posts[$first_key]['user']) {
                $i++;
            }
            if (array_key_exists($i, $posts)) {
                $total_lead_time += $posts[$i]['date'] - $posts[$first_key]['date'];
                $tickets_counted++;
            }
        }
        /* Calculate the new lead time and store it in the DB */
        if ($tickets_counted > 0) {
            $GLOBALS['SITE_DB']->query_update('ticket_types', array('cache_lead_time' => $total_lead_time / $tickets_counted), array('ticket_type' => $ticket_type['ticket_type']), '', 1);
        }
    }
}