Fix for Support Ticketing System module: code excerpt from 6.x-1.x-dev support.module lines 2843 to 2941

  1. /**
  2.  * Search for an existing ticket to associate an incoming message with.
  3.  *
  4.  * @param &$client
  5.  *   Client object.
  6.  * @param &$message
  7.  *   Message being processed.
  8.  */
  9. function _support_identify_ticket(&$client, &$message) {
  10.   global $base_url;
  11.  
  12.   // A) Check for ticket number defined in the Subject.
  13.   $key = variable_get('support_key', 'tkt');
  14.   $tickets = array();
  15.   preg_match("/(\[$key:)([0-9]*)(\])/", $message['subject'], $tickets);
  16.   if (isset($tickets[2])) {
  17.     $message['nid'] = $tickets[2];
  18.     return TRUE;
  19.   }
  20.  
  21.   if (variable_get('support_thread_by_mail_headers', TRUE)) {
  22.     $id_right = preg_replace('|.+://([a-zA-Z0-9\._-]+).*|', '\1', $base_url);
  23.  
  24.     // Search In-Reply-To and References...
  25.     $check = '';
  26.     if (isset($message['headers']->in_reply_to)) {
  27.       $check .= $message['headers']->in_reply_to;
  28.     }
  29.     if (isset($message['headers']->references)) {
  30.       // Turn references header around.
  31.       $check .= implode(' ', array_reverse(explode(' ', $message['headers']->references)));
  32.     }
  33.     $message_ids = array();
  34.     preg_match_all("/<[^<^>]*/", $check, $message_ids);
  35.     foreach ($message_ids[0] as $message_id) {
  36.       $message_id .= '>';
  37.  
  38.       // B) Check for a reply to one of the messages generated by us.
  39.       $matches = array();
  40.       if (preg_match('/^<(\d+)\.(\d+)@' . $id_right . '>$/', $message_id, $matches)) {
  41.         $cid = $matches[1];
  42.         $nid = $matches[2];
  43.         // Reply was directly to node.
  44.         if (!$cid) {
  45.           // Check message id against our records.
  46.           if (db_result(db_query('SELECT 1 FROM {support_ticket} t WHERE t.nid = %d AND t.client = %d', $nid, $client->clid))) {
  47.             $message['nid'] = $nid;
  48.             return TRUE;
  49.           }
  50.         }
  51.         // Reply was to followup.
  52.         else {
  53.           // Check message id against our records.
  54.           if (db_result(db_query('SELECT 1 FROM {comments} c INNER JOIN {support_ticket_comment} t ON c.cid = t.cid WHERE c.cid = %d AND c.nid = %d AND t.client = %d', $cid, $nid, $client->clid))) {
  55.             $message['nid'] = $nid;
  56.             return TRUE;
  57.           }
  58.         }
  59.       }
  60.  
  61.       // C) Check for reply to the incoming message that created the ticket.
  62.       $nid = db_result(db_query("SELECT nid FROM {support_ticket} WHERE message_id = '%s'", $message_id));
  63.       if (isset($nid) && is_numeric($nid)) {
  64.         $message['nid'] = $nid;
  65.         return TRUE;
  66.       }
  67.  
  68.       // D) Check for reply to an incoming message that created a followup.
  69.       $nid = db_result(db_query("SELECT c.nid FROM {support_ticket_comment} j INNER JOIN {comments} c ON j.cid = c.cid WHERE j.message_id = '%s'", $message_id));
  70.       if (isset($nid) && is_numeric($nid)) {
  71.         $message['nid'] = $nid;
  72.         return TRUE;
  73.       }
  74.     }
  75.   }
  76.  
  77.   // E) Look for tickets with an identical subject.
  78.   if (!$client->thread_subject) {
  79.     $client->thread_subject = variable_get('support_thread_by_subject', 3);
  80.   }
  81.   switch ($client->thread_subject) {
  82.     case 1: // disabled
  83.       break;
  84.     case 2:
  85.       $message['nid'] = db_result(db_query_range("SELECT t.nid FROM {support_ticket} t LEFT JOIN {node} n ON t.nid = n.nid LEFT JOIN {support_states} s ON t.state = s.sid WHERE t.client = %d AND n.title = '%s' AND isdefault = 1 ORDER BY nid DESC", $client->clid, $message['subject'], 0, 1));
  86.       break;
  87.     case 3:
  88.       $message['nid'] = db_result(db_query_range("SELECT t.nid FROM {support_ticket} t LEFT JOIN {node} n ON t.nid = n.nid LEFT JOIN {support_states} s ON t.state = s.sid WHERE t.client = %d AND n.title = '%s' AND isclosed = 0 ORDER BY nid DESC", $client->clid, $message['subject'], 0, 1));
  89.       break;
  90.     case 4:
  91.       $message['nid'] = db_result(db_query_range("SELECT t.nid FROM {support_ticket} t LEFT JOIN {node} n ON t.nid = n.nid WHERE t.client = %d AND n.title = '%s' ORDER BY nid DESC", $client->clid, $message['subject'], 0, 1));
  92.       break;
  93.   }
  94.   return (boolean) $message['nid'];
  95. }
  96.  
  97. /**
  98.  *
  99.  */

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.