Advertisement
bobbyw

Untitled

Jan 27th, 2016
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 32.96 KB | None | 0 0
  1. <?php
  2. /*
  3.  * Easy Custom Fields. OsTicket 1.9.4
  4.  * For Information See http://www.andrewbennett.com.au/?p=487
  5.  * tickets.inc.php file from /include/staff/tickets.inc.php
  6.  *
  7.  * Instructions:
  8.  * 1) Copy this gist to a new tickets.inc.php
  9.  * 2) Fill out the field ID (which can be found via the database or via using Firebug/Web Inspector). See http://www.andrewbennett.com.au/?p=487 for more info.
  10.  * 3) Backup your current file /include/staff/tickets.inc.php
  11.  * 4) Upload your new tickets.inc.php to /include/staff/tickets.inc.php
  12.  */
  13. $ab_list['field_id']=implode(",", array('XX')); //ID from from _form_field table , now you can set a lot of fields
  14. $ab_list['heading'] = "XXXXX"; //Name displayed to front end users.
  15. if(!defined('OSTSCPINC') || !$thisstaff || !@$thisstaff->isStaff()) die('Access Denied');
  16. $qstr='&'; //Query string collector
  17. if($_REQUEST['status']) { //Query string status has nothing to do with the real status used below; gets overloaded.
  18.     $qstr.='status='.urlencode($_REQUEST['status']);
  19. }
  20. //See if this is a search
  21. $search=($_REQUEST['a']=='search');
  22. $searchTerm='';
  23. //make sure the search query is 3 chars min...defaults to no query with warning message
  24. if($search) {
  25.   $searchTerm=$_REQUEST['query'];
  26.   if( ($_REQUEST['query'] && strlen($_REQUEST['query'])<3)
  27.       || (!$_REQUEST['query'] && isset($_REQUEST['basic_search'])) ){ //Why do I care about this crap...
  28.       $search=false; //Instead of an error page...default back to regular query..with no search.
  29.       $errors['err']=__('Search term must be more than 3 chars');
  30.       $searchTerm='';
  31.   }
  32. }
  33. $showoverdue=$showanswered=false;
  34. $staffId=0; //Nothing for now...TODO: Allow admin and manager to limit tickets to single staff level.
  35. $showassigned= true; //show Assigned To column - defaults to true
  36. //Get status we are actually going to use on the query...making sure it is clean!
  37. $status=null;
  38. switch(strtolower($_REQUEST['status'])){ //Status is overloaded
  39.     case 'open':
  40.         $status='open';
  41.         $results_type=__('Open Tickets');
  42.         break;
  43.     case 'closed':
  44.         $status='closed';
  45.         $results_type=__('Closed Tickets');
  46.         $showassigned=true; //closed by.
  47.         break;
  48.     case 'overdue':
  49.         $status='open';
  50.         $showoverdue=true;
  51.         $results_type=__('Overdue Tickets');
  52.         break;
  53.     case 'assigned':
  54.         $status='open';
  55.         $staffId=$thisstaff->getId();
  56.         $results_type=__('My Tickets');
  57.         break;
  58.     case 'answered':
  59.         $status='open';
  60.         $showanswered=true;
  61.         $results_type=__('Answered Tickets');
  62.         break;
  63.     default:
  64.         if (!$search && !isset($_REQUEST['advsid'])) {
  65.             $_REQUEST['status']=$status='open';
  66.             $results_type=__('Open Tickets');
  67.         }
  68. }
  69. $qwhere ='';
  70. /*
  71.    STRICT DEPARTMENTS BASED PERMISSION!
  72.    User can also see tickets assigned to them regardless of the ticket's dept.
  73. */
  74. $depts=$thisstaff->getDepts();
  75. $qwhere =' WHERE ( '
  76.         .'  ( ticket.staff_id='.db_input($thisstaff->getId())
  77.         .' AND status.state="open") ';
  78. if(!$thisstaff->showAssignedOnly())
  79.     $qwhere.=' OR ticket.dept_id IN ('.($depts?implode(',', db_input($depts)):0).')';
  80. if(($teams=$thisstaff->getTeams()) && count(array_filter($teams)))
  81.     $qwhere.=' OR (ticket.team_id IN ('.implode(',', db_input(array_filter($teams)))
  82.             .') AND status.state="open") ';
  83. $qwhere .= ' )';
  84. //STATUS to states
  85. $states = array(
  86.     'open' => array('open'),
  87.     'closed' => array('closed'));
  88. if($status && isset($states[$status])) {
  89.     $qwhere.=' AND status.state IN (
  90.                '.implode(',', db_input($states[$status])).' ) ';
  91. }
  92. if (isset($_REQUEST['uid']) && $_REQUEST['uid']) {
  93.     $qwhere .= ' AND (ticket.user_id='.db_input($_REQUEST['uid'])
  94.             .' OR collab.user_id='.db_input($_REQUEST['uid']).') ';
  95.     $qstr .= '&uid='.urlencode($_REQUEST['uid']);
  96. }
  97. //Queues: Overloaded sub-statuses  - you've got to just have faith!
  98. if($staffId && ($staffId==$thisstaff->getId())) { //My tickets
  99.     $results_type=__('Assigned Tickets');
  100.     $qwhere.=' AND ticket.staff_id='.db_input($staffId);
  101.     $showassigned=false; //My tickets...already assigned to the staff.
  102. }elseif($showoverdue) { //overdue
  103.     $qwhere.=' AND ticket.isoverdue=1 ';
  104. }elseif($showanswered) { ////Answered
  105.     $qwhere.=' AND ticket.isanswered=1 ';
  106. }elseif(!strcasecmp($status, 'open') && !$search) { //Open queue (on search OPEN means all open tickets - regardless of state).
  107.     //Showing answered tickets on open queue??
  108.     if(!$cfg->showAnsweredTickets())
  109.         $qwhere.=' AND ticket.isanswered=0 ';
  110.     /* Showing assigned tickets on open queue?
  111.        Don't confuse it with show assigned To column -> F'it it's confusing - just trust me!
  112.      */
  113.     if(!($cfg->showAssignedTickets() || $thisstaff->showAssignedTickets())) {
  114.         $qwhere.=' AND ticket.staff_id=0 '; //XXX: NOT factoring in team assignments - only staff assignments.
  115.         $showassigned=false; //Not showing Assigned To column since assigned tickets are not part of open queue
  116.     }
  117. }
  118. //Search?? Somebody...get me some coffee
  119. $deep_search=false;
  120. $order_by=$order=null;
  121. if($search):
  122.     $qstr.='&a='.urlencode($_REQUEST['a']);
  123.     $qstr.='&t='.urlencode($_REQUEST['t']);
  124.     //query
  125.     if($searchTerm){
  126.         $qstr.='&query='.urlencode($searchTerm);
  127.         $queryterm=db_real_escape($searchTerm,false); //escape the term ONLY...no quotes.
  128.         if (is_numeric($searchTerm)) {
  129.             $qwhere.=" AND ticket.`number` LIKE '$queryterm%'";
  130.         } elseif (strpos($searchTerm,'@') && Validator::is_email($searchTerm)) {
  131.             //pulling all tricks!
  132.             # XXX: What about searching for email addresses in the body of
  133.            #      the thread message
  134.            $qwhere.=" AND email.address='$queryterm'";
  135.         } else {//Deep search!
  136.             //This sucks..mass scan! search anything that moves!
  137.             require_once(INCLUDE_DIR.'ajax.tickets.php');
  138.             $tickets = TicketsAjaxApi::_search(array('query'=>$queryterm));
  139.             if (count($tickets)) {
  140.                 $ticket_ids = implode(',',db_input($tickets));
  141.                 $qwhere .= ' AND ticket.ticket_id IN ('.$ticket_ids.')';
  142.                 $order_by = 'FIELD(ticket.ticket_id, '.$ticket_ids.')';
  143.                 $order = ' ';
  144.             }
  145.             else
  146.                 // No hits -- there should be an empty list of results
  147.                 $qwhere .= ' AND false';
  148.         }
  149.    }
  150. endif;
  151. if ($_REQUEST['advsid'] && isset($_SESSION['adv_'.$_REQUEST['advsid']])) {
  152.     $ticket_ids = implode(',', db_input($_SESSION['adv_'.$_REQUEST['advsid']]));
  153.     $qstr.='advsid='.$_REQUEST['advsid'];
  154.     $qwhere .= ' AND ticket.ticket_id IN ('.$ticket_ids.')';
  155.     // Thanks, http://stackoverflow.com/a/1631794
  156.     $order_by = 'FIELD(ticket.ticket_id, '.$ticket_ids.')';
  157.     $order = ' ';
  158. }
  159. $sortOptions=array('date'=>'effective_date','ID'=>'ticket.`number`*1',
  160.     'pri'=>'pri.priority_urgency','name'=>'user.name','subj'=>'cdata.subject',
  161.     'status'=>'status.name','assignee'=>'assigned','staff'=>'staff',
  162.     'dept'=>'dept.dept_name',
  163.     'custom1'=>'Custom1'); //AB Added
  164. $orderWays=array('DESC'=>'DESC','ASC'=>'ASC');
  165. //Sorting options...
  166. $queue = isset($_REQUEST['status'])?strtolower($_REQUEST['status']):$status;
  167. if($_REQUEST['sort'] && $sortOptions[$_REQUEST['sort']])
  168.     $order_by =$sortOptions[$_REQUEST['sort']];
  169. elseif($sortOptions[$_SESSION[$queue.'_tickets']['sort']]) {
  170.     $_REQUEST['sort'] = $_SESSION[$queue.'_tickets']['sort'];
  171.     $_REQUEST['order'] = $_SESSION[$queue.'_tickets']['order'];
  172.     $order_by = $sortOptions[$_SESSION[$queue.'_tickets']['sort']];
  173.     $order = $_SESSION[$queue.'_tickets']['order'];
  174. }
  175. if($_REQUEST['order'] && $orderWays[strtoupper($_REQUEST['order'])])
  176.     $order=$orderWays[strtoupper($_REQUEST['order'])];
  177. //Save sort order for sticky sorting.
  178. if($_REQUEST['sort'] && $queue) {
  179.     $_SESSION[$queue.'_tickets']['sort'] = $_REQUEST['sort'];
  180.     $_SESSION[$queue.'_tickets']['order'] = $_REQUEST['order'];
  181. }
  182. //Set default sort by columns.
  183. if(!$order_by ) {
  184.     if($showanswered)
  185.         $order_by='ticket.lastresponse, ticket.created'; //No priority sorting for answered tickets.
  186.     elseif(!strcasecmp($status,'closed'))
  187.         $order_by='ticket.closed, ticket.created'; //No priority sorting for closed tickets.
  188.     elseif($showoverdue) //priority> duedate > age in ASC order.
  189.         $order_by='pri.priority_urgency ASC, ISNULL(ticket.duedate) ASC, ticket.duedate ASC, effective_date ASC, ticket.created';
  190.     else //XXX: Add due date here?? No -
  191.         $order_by='pri.priority_urgency ASC, effective_date DESC, ticket.created';
  192. }
  193. $order=$order?$order:'DESC';
  194. if($order_by && strpos($order_by,',') && $order)
  195.     $order_by=preg_replace('/(?<!ASC|DESC),/', " $order,", $order_by);
  196. $sort=$_REQUEST['sort']?strtolower($_REQUEST['sort']):'pri.priority_urgency'; //Urgency is not on display table.
  197. $x=$sort.'_sort';
  198. $$x=' class="'.strtolower($order).'" ';
  199. if($_GET['limit'])
  200.     $qstr.='&limit='.urlencode($_GET['limit']);
  201. $qselect ='SELECT ticket.ticket_id,tlock.lock_id,ticket.`number`,ticket.dept_id,ticket.staff_id,ticket.team_id '
  202.     .' ,user.name'
  203.     .' ,email.address as email, dept.dept_name, status.state '
  204.          .' ,status.name as status,ticket.source,ticket.isoverdue,ticket.isanswered,ticket.created ';
  205. $qfrom=' FROM '.TICKET_TABLE.' ticket '.
  206.        ' LEFT JOIN '.TICKET_STATUS_TABLE. ' status
  207.            ON (status.id = ticket.status_id) '.
  208.        ' LEFT JOIN '.USER_TABLE.' user ON user.id = ticket.user_id'.
  209.        ' LEFT JOIN '.USER_EMAIL_TABLE.' email ON user.id = email.user_id'.
  210.        ' LEFT JOIN '.DEPT_TABLE.' dept ON ticket.dept_id=dept.dept_id ';
  211. if ($_REQUEST['uid'])
  212.     $qfrom.=' LEFT JOIN '.TICKET_COLLABORATOR_TABLE.' collab
  213.        ON (ticket.ticket_id = collab.ticket_id )';
  214. $sjoin='';
  215. if($search && $deep_search) {
  216.     $sjoin.=' LEFT JOIN '.TICKET_THREAD_TABLE.' thread ON (ticket.ticket_id=thread.ticket_id )';
  217. }
  218. //get ticket count based on the query so far..
  219. $total=db_count("SELECT count(DISTINCT ticket.ticket_id) $qfrom $sjoin $qwhere");
  220. $qwhere.=' AND field_id IN ('.$ab_list['field_id'].') ';
  221. //pagenate
  222. $pagelimit=($_GET['limit'] && is_numeric($_GET['limit']))?$_GET['limit']:PAGE_LIMIT;
  223. $page=($_GET['p'] && is_numeric($_GET['p']))?$_GET['p']:1;
  224. $pageNav=new Pagenate($total,$page,$pagelimit);
  225. $pageNav->setURL('tickets.php',$qstr.'&sort='.urlencode($_REQUEST['sort']).'&order='.urlencode($_REQUEST['order']));
  226. //ADD attachment,priorities, lock and other crap
  227. $qselect.=' ,IF(ticket.duedate IS NULL,IF(sla.id IS NULL, NULL, DATE_ADD(ticket.created, INTERVAL sla.grace_period HOUR)), ticket.duedate) as duedate '
  228.          .' ,CAST(GREATEST(IFNULL(ticket.lastmessage, 0), IFNULL(ticket.closed, 0), IFNULL(ticket.reopened, 0), ticket.created) as datetime) as effective_date '
  229.          .' ,ticket.created as ticket_created, CONCAT_WS(" ", staff.firstname, staff.lastname) as staff, team.name as team '
  230.          .' ,IF(staff.staff_id IS NULL,team.name,CONCAT_WS(" ", staff.lastname, staff.firstname)) as assigned '
  231.          .' ,IF(ptopic.topic_pid IS NULL, topic.topic, CONCAT_WS(" / ", ptopic.topic, topic.topic)) as helptopic '
  232.          .' ,cdata.priority as priority_id, cdata.subject, pri.priority_desc, pri.priority_color'
  233.          .' ,fentry_val.value as Custom1' //AB - Custom 1
  234.          ;
  235. $qfrom.=' LEFT JOIN '.TICKET_LOCK_TABLE.' tlock ON (ticket.ticket_id=tlock.ticket_id AND tlock.expire>NOW()
  236.               AND tlock.staff_id!='.db_input($thisstaff->getId()).') '
  237.        .' LEFT JOIN '.STAFF_TABLE.' staff ON (ticket.staff_id=staff.staff_id) '
  238.        .' LEFT JOIN '.TEAM_TABLE.' team ON (ticket.team_id=team.team_id) '
  239.        .' LEFT JOIN '.SLA_TABLE.' sla ON (ticket.sla_id=sla.id AND sla.isactive=1) '
  240.        .' LEFT JOIN '.TOPIC_TABLE.' topic ON (ticket.topic_id=topic.topic_id) '
  241.        .' LEFT JOIN '.TOPIC_TABLE.' ptopic ON (ptopic.topic_id=topic.topic_pid) '
  242.        .' LEFT JOIN '.TABLE_PREFIX.'ticket__cdata cdata ON (cdata.ticket_id = ticket.ticket_id) '
  243.        .' LEFT JOIN '.TABLE_PREFIX.'form_entry fentry ON (fentry.object_id=ticket.ticket_id)'
  244.        .' LEFT JOIN '.TABLE_PREFIX.'form_entry_values fentry_val ON (fentry_val.entry_id = fentry.id)'
  245.        .' LEFT JOIN '.PRIORITY_TABLE.' pri ON (pri.priority_id = cdata.priority)';
  246. TicketForm::ensureDynamicDataView();
  247. $query="$qselect $qfrom $qwhere ORDER BY $order_by $order LIMIT ".$pageNav->getStart().",".$pageNav->getLimit();
  248. //echo $query;
  249. $hash = md5($query);
  250. $_SESSION['search_'.$hash] = $query;
  251. $res = db_query($query);
  252. $showing=db_num_rows($res)? ' &mdash; '.$pageNav->showing():"";
  253. if(!$results_type)
  254.     $results_type = sprintf(__('%s Tickets' /* %s will be a status such as 'open' */),
  255.         mb_convert_case($status, MB_CASE_TITLE));
  256. if($search)
  257.     $results_type.= ' ('.__('Search Results').')';
  258. $negorder=$order=='DESC'?'ASC':'DESC'; //Negate the sorting..
  259. // Fetch the results
  260. $results = array();
  261. while ($row = db_fetch_array($res)) {
  262.     $results[$row['ticket_id']] = $row;
  263. }
  264. // Fetch attachment and thread entry counts
  265. if ($results) {
  266.     $counts_sql = 'SELECT ticket.ticket_id,
  267.        count(DISTINCT attach.attach_id) as attachments,
  268.        count(DISTINCT thread.id) as thread_count,
  269.        count(DISTINCT collab.id) as collaborators
  270.        FROM '.TICKET_TABLE.' ticket
  271.        LEFT JOIN '.TICKET_ATTACHMENT_TABLE.' attach ON (ticket.ticket_id=attach.ticket_id) '
  272.      .' LEFT JOIN '.TICKET_THREAD_TABLE.' thread ON ( ticket.ticket_id=thread.ticket_id) '
  273.      .' LEFT JOIN '.TICKET_COLLABORATOR_TABLE.' collab
  274.            ON ( ticket.ticket_id=collab.ticket_id) '
  275.      .' WHERE ticket.ticket_id IN ('.implode(',', db_input(array_keys($results))).')
  276.        GROUP BY ticket.ticket_id';
  277.     $ids_res = db_query($counts_sql);
  278.     while ($row = db_fetch_array($ids_res)) {
  279.         $results[$row['ticket_id']] += $row;
  280.     }
  281. }
  282. //YOU BREAK IT YOU FIX IT.
  283. ?>
  284. <!-- SEARCH FORM START -->
  285. <div id='basic_search'>
  286.     <form action="tickets.php" method="get">
  287.     <?php csrf_token(); ?>
  288.     <input type="hidden" name="a" value="search">
  289.     <table>
  290.         <tr>
  291.             <td><input type="text" id="basic-ticket-search" name="query" size=30 value="<?php echo Format::htmlchars($_REQUEST['query']); ?>"
  292.                 autocomplete="off" autocorrect="off" autocapitalize="off"></td>
  293.             <td><input type="submit" name="basic_search" class="button" value="<?php echo __('Search'); ?>"></td>
  294.             <td>&nbsp;&nbsp;<a href="#" id="go-advanced">[<?php echo __('advanced'); ?>]</a>&nbsp;<i class="help-tip icon-question-sign" href="#advanced"></i></td>
  295.         </tr>
  296.     </table>
  297.     </form>
  298. </div>
  299. <!-- SEARCH FORM END -->
  300. <div class="clear"></div>
  301. <div style="margin-bottom:20px; padding-top:10px;">
  302. <div>
  303.         <div class="pull-left flush-left">
  304.             <h2><a href="<?php echo Format::htmlchars($_SERVER['REQUEST_URI']); ?>"
  305.                 title="<?php echo __('Refresh'); ?>"><i class="icon-refresh"></i> <?php echo
  306.                 $results_type.$showing; ?></a></h2>
  307.         </div>
  308.         <div class="pull-right flush-right">
  309.  
  310.             <?php
  311.             if ($thisstaff->canDeleteTickets()) { ?>
  312.             <a id="tickets-delete" class="action-button pull-right tickets-action"
  313.                 href="#tickets/status/delete"><i
  314.             class="icon-trash"></i> <?php echo __('Delete'); ?></a>
  315.             <?php
  316.             } ?>
  317.             <?php
  318.             if ($thisstaff->canManageTickets()) {
  319.                 echo TicketStatus::status_options();
  320.             }
  321.             ?>
  322.         </div>
  323. </div>
  324. <div class="clear" style="margin-bottom:10px;"></div>
  325. <form action="tickets.php" method="POST" name='tickets' id="tickets">
  326. <?php csrf_token(); ?>
  327.  <input type="hidden" name="a" value="mass_process" >
  328.  <input type="hidden" name="do" id="action" value="" >
  329.  <input type="hidden" name="status" value="<?php echo Format::htmlchars($_REQUEST['status']); ?>" >
  330.  <table class="list" border="0" cellspacing="1" cellpadding="2" width="940">
  331.     <thead>
  332.         <tr>
  333.             <?php if($thisstaff->canManageTickets()) { ?>
  334.             <th width="8px">&nbsp;</th>
  335.             <?php } ?>
  336.             <th width="70">
  337.                 <a <?php echo $id_sort; ?> href="tickets.php?sort=ID&order=<?php echo $negorder; ?><?php echo $qstr; ?>"
  338.                     title="<?php echo sprintf(__('Sort by %s %s'), __('Ticket ID'), __($negorder)); ?>"><?php echo __('Ticket'); ?></a></th>
  339.             <th width="70">
  340.                 <a  <?php echo $date_sort; ?> href="tickets.php?sort=date&order=<?php echo $negorder; ?><?php echo $qstr; ?>"
  341.                     title="<?php echo sprintf(__('Sort by %s %s'), __('Date'), __($negorder)); ?>"><?php echo __('Date'); ?></a></th>
  342.             <th width="280">
  343.                  <a <?php echo $subj_sort; ?> href="tickets.php?sort=subj&order=<?php echo $negorder; ?><?php echo $qstr; ?>"
  344.                     title="<?php echo sprintf(__('Sort by %s %s'), __('Subject'), __($negorder)); ?>"><?php echo __('Subject'); ?></a></th>
  345.             <th width="170">
  346.                 <a <?php echo $name_sort; ?> href="tickets.php?sort=name&order=<?php echo $negorder; ?><?php echo $qstr; ?>"
  347.                      title="<?php echo sprintf(__('Sort by %s %s'), __('Name'), __($negorder)); ?>"><?php echo __('From');?></a></th>
  348.             <?php
  349.             if($search && !$status) { ?>
  350.                 <th width="60">
  351.                     <a <?php echo $status_sort; ?> href="tickets.php?sort=status&order=<?php echo $negorder; ?><?php echo $qstr; ?>"
  352.                         title="<?php echo sprintf(__('Sort by %s %s'), __('Status'), __($negorder)); ?>"><?php echo __('Status');?></a></th>
  353.             <?php
  354.             } else { ?>
  355.                 <th width="60" <?php echo $pri_sort;?>>
  356.                     <a <?php echo $pri_sort; ?> href="tickets.php?sort=pri&order=<?php echo $negorder; ?><?php echo $qstr; ?>"
  357.                         title="<?php echo sprintf(__('Sort by %s %s'), __('Priority'), __($negorder)); ?>"><?php echo __('Priority');?></a></th>
  358.             <?php
  359.             }
  360.             if($showassigned ) {
  361.                 //Closed by
  362.                 if(!strcasecmp($status,'closed')) { ?>
  363.                     <th width="150">
  364.                         <a <?php echo $staff_sort; ?> href="tickets.php?sort=staff&order=<?php echo $negorder; ?><?php echo $qstr; ?>"
  365.                             title="<?php echo sprintf(__('Sort by %s %s'), __("Closing Agent's Name"), __($negorder)); ?>"><?php echo __('Closed By'); ?></a></th>
  366.                 <?php
  367.                 } else { //assigned to ?>
  368.                     <th width="150">
  369.                         <a <?php echo $assignee_sort; ?> href="tickets.php?sort=assignee&order=<?php echo $negorder; ?><?php echo $qstr; ?>"
  370.                             title="<?php echo sprintf(__('Sort by %s %s'), __('Assignee'), __($negorder)); ?>"><?php echo __('Assigned To'); ?></a></th>
  371.                 <?php
  372.                 }
  373.             } else { ?>
  374.                 <th width="150">
  375.                     <a <?php echo $dept_sort; ?> href="tickets.php?sort=dept&order=<?php echo $negorder;?><?php echo $qstr; ?>"
  376.                         title="<?php echo sprintf(__('Sort by %s %s'), __('Department'), __($negorder)); ?>"><?php echo __('Department');?></a></th>
  377.             <?php
  378.             } ?>
  379.             <!-- AB – Custom Col 1 -->
  380.             <th width="60" >
  381.             <a <?php echo $custom1_sort; ?> href="tickets.php?sort=custom1&order=<?php echo $negorder; ?><?php echo $qstr; ?>"
  382.             title="Sort By <?php echo $ab_list['heading']; ?> <?php echo $negorder; ?>"><?php echo $ab_list['heading']; ?></a></th>
  383.             <!-- AB – Custom Col 1 -->
  384.         </tr>
  385.      </thead>
  386.      <tbody>
  387.         <?php
  388.         // Setup Subject field for display
  389.         $subject_field = TicketForm::objects()->one()->getField('subject');
  390.         $class = "row1";
  391.         $total=0;
  392.         if($res && ($num=count($results))):
  393.             $ids=($errors && $_POST['tids'] && is_array($_POST['tids']))?$_POST['tids']:null;
  394.             foreach ($results as $row) {
  395.                 $tag=$row['staff_id']?'assigned':'openticket';
  396.                 $flag=null;
  397.                 if($row['lock_id'])
  398.                     $flag='locked';
  399.                 elseif($row['isoverdue'])
  400.                     $flag='overdue';
  401.                 $lc='';
  402.                 if($showassigned) {
  403.                     if($row['staff_id'])
  404.                         $lc=sprintf('<span class="Icon staffAssigned">%s</span>',Format::truncate($row['staff'],40));
  405.                     elseif($row['team_id'])
  406.                         $lc=sprintf('<span class="Icon teamAssigned">%s</span>',Format::truncate($row['team'],40));
  407.                     else
  408.                         $lc=' ';
  409.                 }else{
  410.                     $lc=Format::truncate($row['dept_name'],40);
  411.                 }
  412.                 $tid=$row['number'];
  413.                 $subject = Format::truncate($subject_field->display(
  414.                     $subject_field->to_php($row['subject']) ?: $row['subject']
  415.                 ), 40);
  416.                 $threadcount=$row['thread_count'];
  417.                 if(!strcasecmp($row['state'],'open') && !$row['isanswered'] && !$row['lock_id']) {
  418.                     $tid=sprintf('<b>%s</b>',$tid);
  419.                 }
  420.                 ?>
  421.             <tr id="<?php echo $row['ticket_id']; ?>">
  422.                 <?php if($thisstaff->canManageTickets()) {
  423.                     $sel=false;
  424.                     if($ids && in_array($row['ticket_id'], $ids))
  425.                         $sel=true;
  426.                     ?>
  427.                 <td align="center" class="nohover">
  428.                     <input class="ckb" type="checkbox" name="tids[]"
  429.                         value="<?php echo $row['ticket_id']; ?>" <?php echo $sel?'checked="checked"':''; ?>>
  430.                 </td>
  431.                 <?php } ?>
  432.                 <td title="<?php echo $row['email']; ?>" nowrap>
  433.                   <a class="Icon <?php echo strtolower($row['source']); ?>Ticket ticketPreview" title="Preview Ticket"
  434.                     href="tickets.php?id=<?php echo $row['ticket_id']; ?>"><?php echo $tid; ?></a></td>
  435.                 <td align="center" nowrap><?php echo Format::db_datetime($row['effective_date']); ?></td>
  436.                 <td><a <?php if ($flag) { ?> class="Icon <?php echo $flag; ?>Ticket" title="<?php echo ucfirst($flag); ?> Ticket" <?php } ?>
  437.                     href="tickets.php?id=<?php echo $row['ticket_id']; ?>"><?php echo $subject; ?></a>
  438.                      <?php
  439.                         if ($threadcount>1)
  440.                             echo "<small>($threadcount)</small>&nbsp;".'<i
  441.                                class="icon-fixed-width icon-comments-alt"></i>&nbsp;';
  442.                         if ($row['collaborators'])
  443.                             echo '<i class="icon-fixed-width icon-group faded"></i>&nbsp;';
  444.                         if ($row['attachments'])
  445.                             echo '<i class="icon-fixed-width icon-paperclip"></i>&nbsp;';
  446.                     ?>
  447.                 </td>
  448.                 <td nowrap>&nbsp;<?php echo Format::htmlchars(
  449.                         Format::truncate($row['name'], 22, strpos($row['name'], '@'))); ?>&nbsp;</td>
  450.                 <?php
  451.                 if($search && !$status){
  452.                     $displaystatus=ucfirst($row['status']);
  453.                     if(!strcasecmp($row['state'],'open'))
  454.                         $displaystatus="<b>$displaystatus</b>";
  455.                     echo "<td>$displaystatus</td>";
  456.                 } else { ?>
  457.                 <td class="nohover" align="center" style="background-color:<?php echo $row['priority_color']; ?>;">
  458.                     <?php echo $row['priority_desc']; ?></td>
  459.                 <?php
  460.                 }
  461.                 ?>
  462.                 <td nowrap>&nbsp;<?php echo $lc; ?></td>
  463.                 <!-- AB – Custom Col 1 -->
  464.                 <td nowrap>&nbsp;<?php echo $row['Custom1']; ?>&nbsp;</td>
  465.                 <!-- AB – Custom Col 1 -->
  466.             </tr>
  467.             <?php
  468.             } //end of while.
  469.         else: //not tickets found!! set fetch error.
  470.             $ferror=__('There are no tickets matching your criteria.');
  471.         endif; ?>
  472.     </tbody>
  473.     <tfoot>
  474.      <tr>
  475.         <td colspan="8">
  476.             <?php if($res && $num && $thisstaff->canManageTickets()){ ?>
  477.             <?php echo __('Select');?>:&nbsp;
  478.             <a id="selectAll" href="#ckb"><?php echo __('All');?></a>&nbsp;&nbsp;
  479.             <a id="selectNone" href="#ckb"><?php echo __('None');?></a>&nbsp;&nbsp;
  480.             <a id="selectToggle" href="#ckb"><?php echo __('Toggle');?></a>&nbsp;&nbsp;
  481.             <?php }else{
  482.                 echo '<i>';
  483.                 echo $ferror?Format::htmlchars($ferror):__('Query returned 0 results.');
  484.                 echo '</i>';
  485.             } ?>
  486.         </td>
  487.      </tr>
  488.     </tfoot>
  489.     </table>
  490.     <?php
  491.     if($num>0){ //if we actually had any tickets returned.
  492.         echo '<div>&nbsp;'.__('Page').':'.$pageNav->getPageLinks().'&nbsp;';
  493.         echo '<a class="export-csv no-pjax" href="?a=export&h='
  494.             .$hash.'&status='.$_REQUEST['status'] .'">'.__('Export').'</a>&nbsp;<i class="help-tip icon-question-sign" href="#export"></i></div>';
  495.     } ?>
  496.     </form>
  497. </div>
  498.  
  499. <div style="display:none;" class="dialog" id="confirm-action">
  500.     <h3><?php echo __('Please Confirm');?></h3>
  501.     <a class="close" href=""><i class="icon-remove-circle"></i></a>
  502.     <hr/>
  503.     <p class="confirm-action" style="display:none;" id="mark_overdue-confirm">
  504.         <?php echo __('Are you sure want to flag the selected tickets as <font color="red"><b>overdue</b></font>?');?>
  505.     </p>
  506.     <div><?php echo __('Please confirm to continue.');?></div>
  507.     <hr style="margin-top:1em"/>
  508.     <p class="full-width">
  509.         <span class="buttons pull-left">
  510.             <input type="button" value="<?php echo __('No, Cancel');?>" class="close">
  511.         </span>
  512.         <span class="buttons pull-right">
  513.             <input type="button" value="<?php echo __('Yes, Do it!');?>" class="confirm">
  514.         </span>
  515.      </p>
  516.     <div class="clear"></div>
  517. </div>
  518.  
  519. <div class="dialog" style="display:none;" id="advanced-search">
  520.     <h3><?php echo __('Advanced Ticket Search');?></h3>
  521.     <a class="close" href=""><i class="icon-remove-circle"></i></a>
  522.     <hr/>
  523.     <form action="tickets.php" method="post" id="search" name="search">
  524.         <input type="hidden" name="a" value="search">
  525.         <fieldset class="query">
  526.             <input type="input" id="query" name="query" size="20" placeholder="<?php echo __('Keywords') . ' &mdash; ' . __('Optional'); ?>">
  527.         </fieldset>
  528.         <fieldset class="span6">
  529.             <label for="statusId"><?php echo __('Statuses');?>:</label>
  530.             <select id="statusId" name="statusId">
  531.                  <option value="">&mdash; <?php echo __('Any Status');?> &mdash;</option>
  532.                 <?php
  533.                 foreach (TicketStatusList::getStatuses(
  534.                             array('states' => array('open', 'closed'))) as $s) {
  535.                     echo sprintf('<option data-state="%s" value="%d">%s</option>',
  536.                             $s->getState(), $s->getId(), __($s->getName()));
  537.                 }
  538.                 ?>
  539.             </select>
  540.         </fieldset>
  541.         <fieldset class="span6">
  542.             <label for="deptId"><?php echo __('Departments');?>:</label>
  543.             <select id="deptId" name="deptId">
  544.                 <option value="">&mdash; <?php echo __('All Departments');?> &mdash;</option>
  545.                 <?php
  546.                 if(($mydepts = $thisstaff->getDepts()) && ($depts=Dept::getDepartments())) {
  547.                     foreach($depts as $id =>$name) {
  548.                         if(!in_array($id, $mydepts)) continue;
  549.                         echo sprintf('<option value="%d">%s</option>', $id, $name);
  550.                     }
  551.                 }
  552.                 ?>
  553.             </select>
  554.         </fieldset>
  555.         <fieldset class="span6">
  556.             <label for="flag"><?php echo __('Flags');?>:</label>
  557.             <select id="flag" name="flag">
  558.                  <option value="">&mdash; <?php echo __('Any Flags');?> &mdash;</option>
  559.                  <?php
  560.                  if (!$cfg->showAnsweredTickets()) { ?>
  561.                  <option data-state="open" value="answered"><?php echo __('Answered');?></option>
  562.                  <?php
  563.                  } ?>
  564.                  <option data-state="open" value="overdue"><?php echo __('Overdue');?></option>
  565.             </select>
  566.         </fieldset>
  567.         <fieldset class="owner span6">
  568.             <label for="assignee"><?php echo __('Assigned To');?>:</label>
  569.             <select id="assignee" name="assignee">
  570.                 <option value="">&mdash; <?php echo __('Anyone');?> &mdash;</option>
  571.                 <option value="0">&mdash; <?php echo __('Unassigned');?> &mdash;</option>
  572.                 <option value="s<?php echo $thisstaff->getId(); ?>"><?php echo __('Me');?></option>
  573.                 <?php
  574.                 if(($users=Staff::getStaffMembers())) {
  575.                     echo '<OPTGROUP label="'.sprintf(__('Agents (%d)'),count($users)).'">';
  576.                     foreach($users as $id => $name) {
  577.                         $k="s$id";
  578.                         echo sprintf('<option value="%s">%s</option>', $k, $name);
  579.                     }
  580.                     echo '</OPTGROUP>';
  581.                 }
  582.                 if(($teams=Team::getTeams())) {
  583.                     echo '<OPTGROUP label="'.__('Teams').' ('.count($teams).')">';
  584.                     foreach($teams as $id => $name) {
  585.                         $k="t$id";
  586.                         echo sprintf('<option value="%s">%s</option>', $k, $name);
  587.                     }
  588.                     echo '</OPTGROUP>';
  589.                 }
  590.                 ?>
  591.             </select>
  592.         </fieldset>
  593.         <fieldset class="span6">
  594.             <label for="topicId"><?php echo __('Help Topics');?>:</label>
  595.             <select id="topicId" name="topicId">
  596.                 <option value="" selected >&mdash; <?php echo __('All Help Topics');?> &mdash;</option>
  597.                 <?php
  598.                 if($topics=Topic::getHelpTopics()) {
  599.                     foreach($topics as $id =>$name)
  600.                         echo sprintf('<option value="%d" >%s</option>', $id, $name);
  601.                 }
  602.                 ?>
  603.             </select>
  604.         </fieldset>
  605.         <fieldset class="owner span6">
  606.             <label for="staffId"><?php echo __('Closed By');?>:</label>
  607.             <select id="staffId" name="staffId">
  608.                 <option value="0">&mdash; <?php echo __('Anyone');?> &mdash;</option>
  609.                 <option value="<?php echo $thisstaff->getId(); ?>"><?php echo __('Me');?></option>
  610.                 <?php
  611.                 if(($users=Staff::getStaffMembers())) {
  612.                     foreach($users as $id => $name)
  613.                         echo sprintf('<option value="%d">%s</option>', $id, $name);
  614.                 }
  615.                 ?>
  616.             </select>
  617.         </fieldset>
  618.         <fieldset class="date_range">
  619.             <label><?php echo __('Date Range').' &mdash; '.__('Create Date');?>:</label>
  620.             <input class="dp" type="input" size="20" name="startDate">
  621.             <span class="between"><?php echo __('TO');?></span>
  622.             <input class="dp" type="input" size="20" name="endDate">
  623.         </fieldset>
  624.         <?php
  625.         $tform = TicketForm::objects()->one();
  626.         echo $tform->getForm()->getMedia();
  627.         foreach ($tform->getInstance()->getFields() as $f) {
  628.             if (!$f->hasData())
  629.                 continue;
  630.             elseif (!$f->getImpl()->hasSpecialSearch())
  631.                 continue;
  632.             ?><fieldset class="span6">
  633.             <label><?php echo $f->getLabel(); ?>:</label><div><?php
  634.                      $f->render('search'); ?></div>
  635.             </fieldset>
  636.         <?php } ?>
  637.         <hr/>
  638.         <div id="result-count" class="clear"></div>
  639.         <p>
  640.             <span class="buttons pull-right">
  641.                 <input type="submit" value="<?php echo __('Search');?>">
  642.             </span>
  643.             <span class="buttons pull-left">
  644.                 <input type="reset" value="<?php echo __('Reset');?>">
  645.                 <input type="button" value="<?php echo __('Cancel');?>" class="close">
  646.             </span>
  647.             <span class="spinner">
  648.                 <img src="./images/ajax-loader.gif" width="16" height="16">
  649.             </span>
  650.         </p>
  651.     </form>
  652. </div>
  653. <script type="text/javascript">
  654. $(function() {
  655.     $(document).off('.tickets');
  656.     $(document).on('click.tickets', 'a.tickets-action', function(e) {
  657.         e.preventDefault();
  658.         var count = checkbox_checker($('form#tickets'), 1);
  659.         if (count) {
  660.             var url = 'ajax.php/'
  661.             +$(this).attr('href').substr(1)
  662.             +'?count='+count
  663.             +'&_uid='+new Date().getTime();
  664.             $.dialog(url, [201], function (xhr) {
  665.                 window.location.href = window.location.href;
  666.              });
  667.         }
  668.         return false;
  669.     });
  670. });
  671. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement