function loadTicketList($userid) { $this->tickets = new SupportTickets(); $this->tickets->limitstart = 0; $this->tickets->limit = 250; $status_list = FSS_Ticket_Helper::GetStatusIDs("is_closed", true); // Get all open ticket status if (count($status_list) < 1) { $status_list[] = 0; } $this->tickets->loadTicketsByQuery(array("t.admin_id = " . $userid, "t.ticket_status_id IN (" . implode(", ", $status_list) . ")")); }
function loadHandlerTickets() { $ids = array(); foreach ($this->handler_details as $handler) { $ids[] = $handler->id; } if (count($ids) < 1) { return; } $status_list = FSS_Ticket_Helper::GetStatusIDs("is_closed", true); // Get all open ticket status if (count($status_list) < 1) { return; } // load all open status counts $qry = "SELECT admin_id, count(*) as cnt FROM #__fss_ticket_ticket WHERE "; $qry .= " admin_id IN (" . implode(", ", $ids) . ")"; $qry .= " AND ticket_status_id IN (" . implode(", ", $status_list) . ")"; $qry .= " GROUP BY admin_id"; $db = JFactory::getDBO(); $db->setQuery($qry); $data = $db->loadObjectList("admin_id"); foreach ($this->handler_details as $handler) { if (array_key_exists($handler->id, $data)) { $handler->open_tickets = $data[$handler->id]->cnt; } } // load specific status counts $qry = "SELECT admin_id, count(*) as cnt FROM #__fss_ticket_ticket WHERE "; $qry .= " admin_id IN (" . implode(", ", $ids) . ")"; $qry .= " AND ticket_status_id = " . (int) $this->status; $qry .= " GROUP BY admin_id"; $db = JFactory::getDBO(); $db->setQuery($qry); $data = $db->loadObjectList("admin_id"); foreach ($this->handler_details as $handler) { if (array_key_exists($handler->id, $data)) { $handler->status_count = $data[$handler->id]->cnt; } } }
static function GetStatusByID($id) { FSS_Ticket_Helper::GetStatusList(); if ($id == "open") { $ids = FSS_Ticket_Helper::GetStatusIDs("def_open"); if (count($ids) > 0) { return FSS_Ticket_Helper::GetStatusByID($ids[0]); } } foreach (FSS_Ticket_Helper::$status_list as $status) { if ($status->id == $id) { return $status; } } return null; }
static function &getTicketCount($foradmin = true, $current_handler_only = false) { $key = 0; if ($foradmin) { $key += 1; } if ($current_handler_only) { $key += 2; } if (empty(self::$counts)) { self::$counts = array(); } if (!array_key_exists($key, self::$counts)) { $db = JFactory::getDBO(); $query = "SELECT count( * ) AS count, ticket_status_id FROM #__fss_ticket_ticket as t WHERE 1 "; $query .= " AND " . SupportUsers::getAdminWhere(); if ($foradmin) { $query .= " AND " . SupportSource::admin_list_sql(); } else { $query .= " AND " . SupportSource::user_list_sql(); } if ($current_handler_only) { $query .= " AND admin_id = " . JFactory::getUser()->id; } $query .= " GROUP BY ticket_status_id"; $db->setQuery($query); $rows = $db->loadAssocList(); $out = array(); FSS_Ticket_Helper::GetStatusList(); foreach (FSS_Ticket_Helper::$status_list as $status) { $out[$status->id] = 0; } if (count($rows) > 0) { foreach ($rows as $row) { $out[$row['ticket_status_id']] = $row['count']; } } // work out counts for allopen, closed, all, archived $archived = FSS_Ticket_Helper::GetStatusID("def_archive"); $out['archived'] = 0; if (array_key_exists($archived, $out)) { $out['archived'] = $out[$archived]; } $allopen = FSS_Ticket_Helper::GetStatusIDs("is_closed", true); $out['allopen'] = 0; foreach ($allopen as $id) { if (array_key_exists($id, $out)) { $out['allopen'] += $out[$id]; } } $allclosed = FSS_Ticket_Helper::GetClosedStatus(); $out['allclosed'] = 0; foreach ($allclosed as $id) { if (array_key_exists($id, $out)) { $out['allclosed'] += $out[$id]; } } $all = FSS_Ticket_Helper::GetStatusIDs("def_archive", true); $out['all'] = 0; foreach ($all as $id) { if (array_key_exists($id, $out)) { $out['all'] += $out[$id]; } } self::$counts[$key] = $out; } return self::$counts[$key]; }
function Execute($aparams) { $debug = 0; $this->Log("Auto closing tickets"); $db = JFactory::getDBO(); $can_close = FSS_Ticket_Helper::GetStatusIDs('can_autoclose'); $def_close = FSS_Ticket_Helper::GetStatusID('def_closed'); if ($debug) { $this->Log("Can Close : " . implode(", ", $can_close)); } if ($debug) { $this->Log("Close To : " . $def_close); } $now = FSS_Helper::CurDate(); // if no audit log to be created, then can just close all tickets in a single query, this is quicker! if (!$aparams['addaudit'] && !$aparams['emailuser']) { if ($debug) { echo "No audit required, just closing<br>"; } $qry = "UPDATE #__fss_ticket_ticket SET closed = '{$now}', ticket_status_id = {$def_close} WHERE DATE_ADD(`lastupdate` ,INTERVAL " . FSSJ3Helper::getEscaped($db, $aparams['closeinterval']) . " DAY) < '{$now}' AND ticket_status_id IN (" . implode(", ", $can_close) . ")"; $db->setQuery($qry); $db->Query(); // UNCOMMENT $rows = $db->getAffectedRows(); if ($debug) { $this->Log($qry); } // COMMENT $this->Log("Auto closed {$rows} tickets"); return; } $qry = "SELECT * FROM #__fss_ticket_ticket WHERE DATE_ADD(`lastupdate` ,INTERVAL " . FSSJ3Helper::getEscaped($db, $aparams['closeinterval']) . " DAY) < '{$now}' AND ticket_status_id IN (" . implode(", ", $can_close) . ")"; $db->setQuery($qry); if ($debug) { $this->Log($qry); } $rows = $db->loadAssocList(); $this->Log("Found " . count($rows) . " tickets to close"); if (count($rows) == 0) { return; } $ids = array(); $auditrows = array(); foreach ($rows as $row) { $ids[] = FSSJ3Helper::getEscaped($db, $row['id']); if ($aparams['addaudit']) { // add audit log to the ticket $auditqry[] = "(" . FSSJ3Helper::getEscaped($db, $row['id']) . ", 'Audit Message', 'Ticket auto-closed after " . FSSJ3Helper::getEscaped($db, $aparams['closeinterval']) . " days of inactivity', 0, 3, '{$now}')"; } if ($aparams['emailuser']) { FSS_EMail::Admin_AutoClose($row); } } if ($aparams['addaudit']) { $qry = "INSERT INTO #__fss_ticket_messages (ticket_ticket_id, subject, body, user_id, admin, posted) VALUES \n"; $qry .= implode(",\n ", $auditqry); if ($debug) { $this->Log("Saving Audit Messages"); } if ($debug) { $this->Log($qry); } $db->setQuery($qry); $db->Query(); } $qry = "UPDATE #__fss_ticket_ticket SET closed = '{$now}', ticket_status_id = {$def_close} WHERE id IN (" . implode(", ", $ids) . ")"; if ($debug) { $this->Log("Closing Tickets"); } if ($debug) { $this->Log($qry); } $db->setQuery($qry); $db->Query(); $this->Log("Closed " . count($rows) . " tickets"); /*echo "<pre style='background-color:white;'>"; echo $qry; echo "</pre>";*/ }
function &getTicketCount() { $user = JFactory::getUser(); $userid = $user->get('id'); if (empty(self::$ticket_counts)) { self::$ticket_counts = array(); } if (array_key_exists($userid, self::$ticket_counts)) { $this->_counts = self::$ticket_counts[$userid]; return $this->_counts; } $uidlist = $this->getUIDS($userid); $tidlist = $this->getTIDS($userid); $db = JFactory::getDBO(); $query = "SELECT count( * ) AS count, ticket_status_id FROM #__fss_ticket_ticket WHERE (user_id IN (" . implode(", ", $uidlist) . ") OR id IN ( " . implode(", ", $tidlist) . ")) "; $query .= " AND " . SupportSource::user_list_sql(); $query .= " GROUP BY ticket_status_id"; $db->setQuery($query); $rows = $db->loadAssocList(); $out = array(); FSS_Ticket_Helper::GetStatusList(); foreach (FSS_Ticket_Helper::$status_list as $status) { $out[$status->id] = 0; } if (count($rows) > 0) { foreach ($rows as $row) { $out[$row['ticket_status_id']] = $row['count']; } } // work out counts for allopen, closed, all, archived $archived = FSS_Ticket_Helper::GetStatusID("def_archive"); if (array_key_exists($archived, $out)) { $out['archived'] = $out[$archived]; } else { $out['archived'] = 0; } $allopen = FSS_Ticket_Helper::GetStatusIDs("is_closed", true); $out['open'] = 0; foreach ($allopen as $id) { if (array_key_exists($id, $out)) { $out['open'] += $out[$id]; } } $allclosed = FSS_Ticket_Helper::GetClosedStatus(); $out['closed'] = 0; foreach ($allclosed as $id) { if (array_key_exists($id, $out)) { $out['closed'] += $out[$id]; } } $all = FSS_Ticket_Helper::GetStatusIDs("def_archive"); $out['all'] = 0; foreach ($rows as $row) { if ($row['ticket_status_id'] != $all) { $out['all'] += $row['count']; } } $this->_counts = $out; self::$ticket_counts[$userid] = $out; return $this->_counts; }