Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
$tasks = TaskModel::objects();
$date_header = $date_col = false;
// Figure out REFRESH url — which might not be accurate after posting a
// response
list($path,) = explode('?', $_SERVER['REQUEST_URI'], 2);
$args = array();
parse_str($_SERVER['QUERY_STRING'], $args);
// Remove commands from query
unset($args['id']);
unset($args['a']);
$refresh_url = $path . '?' . http_build_query($args);
$queue_name = strtolower($_GET['status'] ?: $_GET['a']); //Status is overloaded
switch ($queue_name) {
case 'closed':
$status='closed';
$results_type=__('Closed Tasks');
$showassigned=true; //closed by.
break;
case 'overdue':
$status='open';
$results_type=__('Overdue Tasks');
$tasks->filter(array('isoverdue'=>1));
break;
case 'assigned':
$status='open';
$staffId=$thisstaff->getId();
$results_type=__('My Tasks');
$tasks->filter(array('staff_id'=>$thisstaff->getId()));
break;
default:
case 'search':
// Consider basic search
if ($_REQUEST['query']) {
$results_type=__('Search Results');
$tasks = $tasks->filter(Q::any(array(
'number__startswith' => $_REQUEST['query'],
'cdata__title__contains' => $_REQUEST['query'],
)));
} elseif (isset($_SESSION['advsearch'])) {
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// XXX: De-duplicate and simplify this code
$form = $search->getFormFromSession('advsearch');
$form->loadState($_SESSION['advsearch']);
$tasks = $search->mangleQuerySet($tasks, $form);
$results_type=__('Advanced Search')
. '<a class="action-button" href="?clear_filter"><i class="icon-ban-circle"></i> <em>' . __('clear') . '</em></a>';
break;
}
// Fall-through and show open tickets
case 'open':
$status='open';
$results_type=__('Open Tasks');
break;
}
// Apply filters
$filters = array();
$SQ = new Q(array('flags__hasbit' => TaskModel::ISOPEN));
if ($status && !strcasecmp($status, 'closed'))
$SQ->negate();
$filters[] = $SQ;
$tasks->filter($filters);
// Impose visibility constraints
// ------------------------------------------------------------
// -- Open and assigned to me
$visibility = array(
new Q(array('flags__hasbit' => TaskModel::ISOPEN, 'staff_id' => $thisstaff->getId()))
);
// -- Routed to a department of mine
if (!$thisstaff->showAssignedOnly() && ($depts=$thisstaff->getDepts()))
$visibility[] = new Q(array('dept_id__in' => $depts));
// -- Open and assigned to a team of mine
if (($teams = $thisstaff->getTeams()) && count(array_filter($teams)))
$visibility[] = new Q(array(
'team_id__in' => array_filter($teams),
'flags__hasbit' => TaskModel::ISOPEN
));
$tasks->filter(Q::any($visibility));
// Add in annotations
$tasks->annotate(array(
'collab_count' => SqlAggregate::COUNT('thread__collaborators', true),
'attachment_count' => SqlAggregate::COUNT(SqlCase::N()
->when(new SqlField('thread__entries__attachments__inline'), null)
->otherwise(new SqlField('thread__entries__attachments')),
true
),
'thread_count' => SqlAggregate::COUNT(SqlCase::N()
->when(
new Q(array('thread__entries__flags__hasbit'=>ThreadEntry::FLAG_HIDDEN)),
null)
->otherwise(new SqlField('thread__entries__id')),
true
),
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
));
$tasks->values('id', 'number', 'created', 'staff_id', 'team_id',
'staff__firstname', 'staff__lastname', 'team__name',
'dept__name', 'cdata__title', 'flags');
// Apply requested quick filter
// Apply requested sorting
$queue_sort_key = sprintf(':Q:%s:sort', $queue_name);
if (isset($_GET['sort']))
$_SESSION[$queue_sort_key] = $_GET['sort'];
switch ($_SESSION[$queue_sort_key]) {
case 'number':
$tasks->extra(array(
'order_by'=>array(SqlExpression::times(new SqlField('number'), 1))
));
break;
case 'priority,due':
$tasks->order_by('cdata__:priority__priority_urgency');
// Fall through to add in due date filter
case 'due':
$date_header = __('Due Date');
$date_col = 'est_duedate';
$tasks->values('est_duedate');
$tasks->filter(array('est_duedate__isnull'=>false));
$tasks->order_by('est_duedate');
break;
case 'updated':
$tasks->order_by('cdata__:priority__priority_urgency', '-lastupdate');
break;
case 'created':
default:
$tasks->order_by('-created');
break;
}
// Apply requested pagination
$page=($_GET['p'] && is_numeric($_GET['p']))?$_GET['p']:1;
$pageNav=new Pagenate($tasks->count(), $page, PAGE_LIMIT);
$pageNav->setURL('tasks.php', $args);
$tasks = $pageNav->paginate($tasks);
TaskForm::ensureDynamicDataView();
// Save the query to the session for exporting
$_SESSION[':Q:tasks'] = $tasks;
// Mass actions
$actions = array();
if ($thisstaff->hasPerm(Task::PERM_ASSIGN)) {
$actions += array(
'assign' => array(
'icon' => 'icon-user',
'action' => __('Assign Tasks')
));
}
if ($thisstaff->hasPerm(Task::PERM_TRANSFER)) {
$actions += array(
'transfer' => array(
'icon' => 'icon-share',
'action' => __('Transfer Tasks')
));
}
if ($thisstaff->hasPerm(Task::PERM_DELETE)) {
$actions += array(
'delete' => array(
'icon' => 'icon-trash',
'action' => __('Delete Tasks')
));
}
?>
<!-- SEARCH FORM START -->
<div id='basic_search'>
<form action="tasks.php" method="get">
<input type="hidden" name="a" value="search">
<table>
<tr>
<td><input type="text" id="basic-ticket-search" name="query"
size=30 value="<?php echo Format::htmlchars($_REQUEST['query'],
true); ?>"
autocomplete="off" autocorrect="off" autocapitalize="off"></td>
<td><input type="submit" class="button" value="<?php echo __('Search'); ?>"></td>
<td> <a href="#" onclick="javascript:
$.dialog('ajax.php/tasks/search', 201);"
>[<?php echo __('advanced'); ?>]</a> <i class="help-tip icon-question-sign" href="#advanced"></i></td>
</tr>
</table>
</form>
</div>
<!-- SEARCH FORM END -->
<div class="clear"></div>
<div style="margin-bottom:20px; padding-top:10px;">
<div>
<div class="pull-left flush-left">
<h2><a href="<?php echo $refresh_url; ?>"
title="<?php echo __('Refresh'); ?>"><i class="icon-refresh"></i> <?php echo
$results_type.$showing; ?></a></h2>
</div>
<div class="pull-right flush-right">
<span style="display:inline-block">
<span style="vertical-align: baseline">Sort:</span>
<select name="sort" onchange="javascript:addSearchParam('sort', $(this).val());">
<?php foreach (array(
'created' => __('Most Recently Created'),
'updated' => __('Most Recently Updated'),
'due' => __('Due Soon'),
'priority,due' => __('Priority + Due Soon'),
'number' => __('Task Number'),
) as $mode => $desc) { ?>
<option value="<?php echo $mode; ?>" <?php if ($mode == $_SESSION[$queue_sort_key]) echo 'selected="selected"'; ?>><?php echo $desc; ?></option>
<?php } ?>
</select>
</span>
<?php
Task::getAgentActions($thisstaff, array('status' => $status));
?>
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<form action="tasks.php" method="POST" name='tasks' id="tasks">
<?php csrf_token(); ?>
<input type="hidden" name="a" value="mass_process" >
<input type="hidden" name="do" id="action" value="" >
<input type="hidden" name="status" value="<?php echo
Format::htmlchars($_REQUEST['status'], true); ?>" >
<table class="list" border="0" cellspacing="1" cellpadding="2" width="940">
<thead>
<tr>
<?php if ($thisstaff->canManageTickets()) { ?>
<th width="8px"> </th>
<?php } ?>
<th width="70">
<?php echo __('Number'); ?></th>
<th width="70">
<?php echo $date_header ?: __('Date'); ?></th>
<th width="280">
<?php echo __('Title'); ?></th>
<th width="250">
<?php echo __('Department');?></th>
<th width="250">
<?php echo __('Assignee');?></th>
</tr>
</thead>
<tbody>
<?php
// Setup Subject field for display
$total=0;
$title_field = TaskForm::getInstance()->getField('title');
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
$ids=($errors && $_POST['tids'] && is_array($_POST['tids']))?$_POST['tids']:null;
foreach ($tasks as $T) {
$T['isopen'] = ($T['flags'] & TaskModel::ISOPEN != 0); //XXX:
$total += 1;
$tag=$T['staff_id']?'assigned':'openticket';
$flag=null;
if($T['lock__staff_id'] && $T['lock__staff_id'] != $thisstaff->getId())
$flag='locked';
elseif($T['isoverdue'])
$flag='overdue';
$assignee = '';
$dept = Dept::getLocalById($T['dept_id'], 'name', $T['dept__name']);
$assinee ='';
if ($T['staff_id']) {
$staff = new PersonsName($T['staff__firstname'].' '.$T['staff__lastname']);
$assignee = sprintf('<span class="Icon staffAssigned">%s</span>',
Format::truncate((string) $staff, 40));
} elseif($T['team_id']) {
$assignee = sprintf('<span class="Icon teamAssigned">%s</span>',
Format::truncate(Team::getLocalById($T['team_id'], 'name', $T['team__name']),40));
}
$threadcount=$T['thread_count'];
$number = $T['number'];
if ($T['isopen'])
$number = sprintf('<b>%s</b>', $number);
$title = Format::truncate($title_field->display($title_field->to_php($T['cdata__title'])), 40);
?>
<tr id="<?php echo $T['id']; ?>">
<?php
if ($thisstaff->canManageTickets()) {
$sel = false;
if ($ids && in_array($T['id'], $ids))
$sel = true;
?>
<td align="center" class="nohover">
<input class="ckb" type="checkbox" name="tids[]"
value="<?php echo $T['id']; ?>" <?php echo $sel?'checked="checked"':''; ?>>
</td>
<?php } ?>
<td nowrap>
<a class="preview"
href="tasks.php?id=<?php echo $T['id']; ?>"
data-preview="#tasks/<?php echo $T['id']; ?>/preview"
><?php echo $number; ?></a></td>
<td align="center" nowrap><?php echo
Format::datetime($T[$date_col ?: 'created']); ?></td>
<td><a <?php if ($flag) { ?> class="Icon <?php echo $flag; ?>Ticket" title="<?php echo ucfirst($flag); ?> Ticket" <?php } ?>
href="tasks.php?id=<?php echo $T['id']; ?>"><?php
echo $title; ?></a>
<?php
if ($threadcount>1)
echo "<small>($threadcount)</small> ".'<i
class="icon-fixed-width icon-comments-alt"></i> ';
if ($T['collab_count'])
echo '<i class="icon-fixed-width icon-group faded"></i> ';
if ($T['attachment_count'])
echo '<i class="icon-fixed-width icon-paperclip"></i> ';
?>
</td>
<td nowrap> <?php echo Format::truncate($dept, 40); ?></td>
<td nowrap> <?php echo $assignee; ?></td>
</tr>
<?php
} //end of foreach
if (!$total)
$ferror=__('There are no tickets matching your criteria.');
?>
</tbody>
<tfoot>
<tr>
<td colspan="6">
<?php if($total && $thisstaff->canManageTickets()){ ?>
<?php echo __('Select');?>:
<a id="selectAll" href="#ckb"><?php echo __('All');?></a>
<a id="selectNone" href="#ckb"><?php echo __('None');?></a>
<a id="selectToggle" href="#ckb"><?php echo __('Toggle');?></a>
<?php }else{
echo '<i>';
echo $ferror?Format::htmlchars($ferror):__('Query returned 0 results.');
echo '</i>';
} ?>
</td>
</tr>
</tfoot>
</table>
<?php
if ($total>0) { //if we actually had any tickets returned.
echo '<div> '.__('Page').':'.$pageNav->getPageLinks().' ';
echo sprintf('<a class="export-csv no-pjax" href="?%s">%s</a>',
Http::build_query(array(
'a' => 'export', 'h' => $hash,
'status' => $_REQUEST['status'])),
__('Export'));
echo ' <i class="help-tip icon-question-sign" href="#export"></i></div>';
} ?>
</form>
</div>
<div style="display:none;" class="dialog" id="confirm-action">
<h3><?php echo __('Please Confirm');?></h3>
<a class="close" href=""><i class="icon-remove-circle"></i></a>
<hr/>
<p class="confirm-action" style="display:none;" id="mark_overdue-confirm">
<?php echo __('Are you sure want to flag the selected tickets as <font color="red"><b>overdue</b></font>?');?>
</p>
<div><?php echo __('Please confirm to continue.');?></div>
<hr style="margin-top:1em"/>
<p class="full-width">
<span class="buttons pull-left">
<input type="button" value="<?php echo __('No, Cancel');?>" class="close">
</span>
<span class="buttons pull-right">
<input type="button" value="<?php echo __('Yes, Do it!');?>" class="confirm">
</span>
</p>
<div class="clear"></div>
</div>
<script type="text/javascript">
$(function() {
$(document).off('.tasks');
$(document).on('click.tasks', 'a.tasks-action', function(e) {
e.preventDefault();
var count = checkbox_checker($('form#tasks'), 1);
if (count) {
var url = 'ajax.php/'
+$(this).attr('href').substr(1)
+'?count='+count
+'&_uid='+new Date().getTime();
$.dialog(url, [201], function (xhr) {
$.pjax.reload('#pjax-container');
});
}
return false;
});
$(document).off('.task-action');
$(document).on('click.task-action', 'a.task-action', function(e) {
e.preventDefault();
var url = 'ajax.php/'
+$(this).attr('href').substr(1)
+'?_uid='+new Date().getTime();
var $options = $(this).data('dialog');
var $redirect = $(this).data('redirect');
$.dialog(url, [201], function (xhr) {
if ($redirect)
window.location.href = $redirect;
else
$.pjax.reload('#pjax-container');
}, $options);
return false;
});