Ejemplo n.º 1
0
    });
}
$columns['ticket_contact'] = array('title' => 'Contact', 'callback' => function ($ticket) {
    echo module_user::link_open($ticket['user_id'], true, array(), true);
});
if (class_exists('module_faq', false) && module_config::c('ticket_show_product_list', 1)) {
    $columns['ticket_product'] = array('title' => 'Product', 'callback' => function ($ticket) {
        if ($ticket['faq_product_id']) {
            $faq_product = module_faq::get_faq_product($ticket['faq_product_id']);
            echo $faq_product && isset($faq_product['name']) ? htmlspecialchars($faq_product['name']) : '';
        }
    });
}
if (class_exists('module_envato', false)) {
    $columns['ticket_envato'] = array('title' => _l('Envato%s', module_config::c('envato_show_ticket_earning', 0) ? ' (' . dollar($envato_count * 0.7) . ')' : ''), 'callback' => function ($ticket) {
        $items = module_envato::get_items_by_ticket($ticket['ticket_id']);
        foreach ($items as $item) {
            echo '<a href="' . $item['url'] . '">' . htmlspecialchars($item['name']) . '</a> ';
        }
    });
}
if (class_exists('module_group', false) && module_config::c('ticket_enable_groups', 1) && module_group::groups_enabled()) {
    $columns['ticket_group'] = array('title' => 'Group', 'callback' => function ($ticket) {
        // find the groups for this customer.
        $groups = module_group::get_groups_search(array('owner_table' => 'ticket', 'owner_id' => $ticket['ticket_id']));
        $g = array();
        foreach ($groups as $group) {
            $g[] = $group['name'];
        }
        echo implode(', ', $g);
    });
Ejemplo n.º 2
0
 public static function get_ticket($ticket_id, $full = true)
 {
     $cache_key_args = func_get_args();
     $cache_key = self::_ticket_cache_key($ticket_id, $cache_key_args);
     $cache_timeout = module_config::c('cache_objects', 60);
     if ($cached_item = module_cache::get('ticket', $cache_key)) {
         return $cached_item;
     }
     $ticket_access = self::get_ticket_data_access();
     $ticket_id = (int) $ticket_id;
     $ticket = false;
     if ($ticket_id > 0) {
         //$ticket = get_single("ticket","ticket_id",$ticket_id);
         $sql = "SELECT * FROM `" . _DB_PREFIX . "ticket` t WHERE t.ticket_id = {$ticket_id} ";
         switch ($ticket_access) {
             case _TICKET_ACCESS_ALL:
                 break;
             case _TICKET_ACCESS_ASSIGNED:
                 // we only want tickets assigned to me.
                 //$sql .= " AND t.assigned_user_id = '".(int)module_security::get_loggedin_id()."'";
                 $sql .= " AND (t.assigned_user_id = '" . (int) module_security::get_loggedin_id() . "' OR t.assigned_user_id = 0)";
                 break;
             case _TICKET_ACCESS_CREATED:
                 // we only want tickets I created.
                 $sql .= " AND t.user_id = '" . (int) module_security::get_loggedin_id() . "'";
                 break;
             case _TICKET_ACCESS_CUSTOMER:
                 $valid_customer_ids = module_security::get_customer_restrictions();
                 if (is_array($valid_customer_ids) && count($valid_customer_ids)) {
                     $sql .= " AND ( ";
                     foreach ($valid_customer_ids as $valid_customer_id) {
                         $sql .= " t.customer_id = '" . (int) $valid_customer_id . "' OR ";
                     }
                     $sql = rtrim($sql, 'OR ');
                     $sql .= " )";
                 }
                 break;
         }
         $ticket = qa1($sql, false);
     }
     if ($full === 2) {
         module_cache::put('ticket', $cache_key, $ticket, $cache_timeout);
         return $ticket;
     }
     if (!$ticket) {
         $customer_id = $website_id = 0;
         $user_id = module_security::get_loggedin_id();
         if (isset($_REQUEST['customer_id']) && $_REQUEST['customer_id']) {
             //
             $customer_id = (int) $_REQUEST['customer_id'];
             $customer = module_customer::get_customer($customer_id);
             if (!$customer || $customer['customer_id'] != $customer_id) {
                 $customer_id = 0;
             } else {
                 $user_id = $customer['primary_user_id'];
             }
             // find default website id to use.
             if (isset($_REQUEST['website_id'])) {
                 $website_id = (int) $_REQUEST['website_id'];
                 $website = module_website::get_website($website_id);
                 if (!$website || $website['website_id'] != $website_id || $website['customer_id'] != $customer_id) {
                     $website_id = 0;
                 }
             } else {
                 $website_id = 0;
             }
         }
         $position = self::ticket_position();
         $ticket = array('ticket_id' => 'new', 'customer_id' => $customer_id, 'website_id' => $website_id, 'subject' => '', 'date_completed' => '', 'status_id' => _TICKET_STATUS_NEW_ID, 'user_id' => $user_id, 'assigned_user_id' => module_config::c('ticket_default_user_id', 1), 'ticket_account_id' => module_config::c('ticket_default_account_id', 0), 'last_message_timestamp' => 0, 'last_ticket_message_id' => 0, 'message_count' => 0, 'position' => $position['current'] + 1, 'priority' => 0, 'ticket_type_id' => module_config::c('ticket_type_id_default', 0), 'total_pending' => $position['total'] + 1, 'extra_data' => array(), 'invoice_id' => false, 'faq_product_id' => false);
     } else {
         // find the position of this ticket
         // the position is determined by the number of pending tickets
         // that have a last_message_timestamp earlier than this ticket.
         $position = self::ticket_position($ticket_id);
         $ticket['position'] = $position['current'];
         $ticket['total_pending'] = $position['total'];
         /*if($ticket['priority'] == _TICKET_PRIORITY_STATUS_ID){
               $ticket['position'] = self::ticket_count('priority',$ticket['last_message_timestamp'],$ticket['ticket_id'],$ticket['priority']);
           }else{
               $ticket['position'] = self::ticket_count('pending',$ticket['last_message_timestamp'],$ticket['ticket_id'],$ticket['priority']);
           }
           $ticket['total_pending'] = self::ticket_count('pending');*/
         $messages = self::get_ticket_messages($ticket_id, true);
         //$ticket['message_count'] = count($messages);
         $ticket['message_count'] = mysql_num_rows($messages);
         //end($messages);
         if ($ticket['message_count'] > 0) {
             mysql_data_seek($messages, $ticket['message_count'] - 1);
         }
         //$last_message = current($messages);
         $last_message = mysql_fetch_assoc($messages);
         $ticket['last_ticket_message_id'] = $last_message['ticket_message_id'];
         $ticket['last_message_was_private'] = isset($last_message['private_message']) && $last_message['private_message'];
         // for passwords and website addresses..
         $ticket['extra_data'] = self::get_ticket_extras($ticket_id);
         // hook into the envato module.
         // link any missing envato/faqproduct items together.
         if (class_exists('module_envato', false) && isset($_REQUEST['faq_product_envato_hack']) && (!$ticket['faq_product_id'] || $ticket['faq_product_id'] == $_REQUEST['faq_product_envato_hack'])) {
             $items = module_envato::get_items_by_ticket($ticket['ticket_id']);
             foreach ($items as $envato_item_id => $item) {
                 // see if this item is linked to a product.
                 if ($item['envato_item_id']) {
                     $sql = "SELECT * FROM `" . _DB_PREFIX . "faq_product` WHERE envato_item_ids REGEXP '[|]*" . $envato_item_id . "[|]*'";
                     $res = qa1($sql);
                     if ($res && $res['faq_product_id']) {
                         // found a product matching this one. link her up.
                         update_insert('ticket_id', $ticket_id, 'ticket', array('faq_product_id' => $res['faq_product_id']));
                         break;
                     }
                 }
             }
         }
     }
     module_cache::put('ticket', $cache_key, $ticket, $cache_timeout);
     return $ticket;
 }