Newer
Older
<?php
/*************************************************************************
tasks.php
Copyright (c) 2006-2013 osTicket
http://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
require('staff.inc.php');
require_once(INCLUDE_DIR.'class.task.php');
$page = '';
$task = null; //clean start.
if ($_REQUEST['id']) {
if (!($task=Task::lookup($_REQUEST['id'])))
$errors['err'] = sprintf(__('%s: Unknown or invalid ID.'), __('task'));
elseif (!$task->checkStaffPerm($thisstaff)) {
$errors['err'] = __('Access denied. Contact admin if you believe this is in error');
$task = null;
}
}
// Configure form for file uploads
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'attachments' => new FileUploadField(array('id'=>'attach',
'name'=>'attach:note',
'configuration' => array('extensions'=>'')))
));
//At this stage we know the access status. we can process the post.
if($_POST && !$errors):
if ($task) {
//More coffee please.
$errors=array();
$role = $thisstaff->getRole($task->getDeptId());
switch(strtolower($_POST['a'])):
case 'postnote': /* Post Internal Note */
$vars = $_POST;
$attachments = $note_form->getField('attachments')->getClean();
$vars['cannedattachments'] = array_merge(
$vars['cannedattachments'] ?: array(), $attachments);
$wasOpen = ($task->isOpen());
if(($note=$task->postNote($vars, $errors, $thisstaff))) {
$msg=__('Internal note posted successfully');
// Clear attachment list
$note_form->setSource(array());
$note_form->getField('attachments')->reset();
if($wasOpen && $task->isClosed())
$task = null; //Going back to main listing.
else
// Ticket is still open -- clear draft for the note
Draft::deleteForNamespace('task.note.'.$task->getId(),
$thisstaff->getId());
} else {
if(!$errors['err'])
$errors['err'] = __('Unable to post internal note - missing or invalid data.');
$errors['postnote'] = __('Unable to post the note. Correct the error(s) below and try again!');
}
break;
default:
$errors['err']=__('Unknown action');
endswitch;
}
if(!$errors)
$thisstaff->resetStats(); //We'll need to reflect any changes just made!
endif;
/*... Quick stats ...*/
$stats= $thisstaff->getTasksStats();
// Clear advanced search upon request
if (isset($_GET['clear_filter']))
unset($_SESSION['advsearch']);
//Navigation
$nav->setTabActive('tasks');
$open_name = _P('queue-name',
/* This is the name of the open tasks queue */
'Open');
$nav->addSubMenu(array('desc'=>$open_name.' ('.number_format($stats['open']).')',
'title'=>__('Open Tasks'),
'href'=>'tasks.php?status=open',
'iconclass'=>'Ticket'),
((!$_REQUEST['status'] && !isset($_SESSION['advsearch'])) || $_REQUEST['status']=='open'));
if ($stats['assigned']) {
$nav->addSubMenu(array('desc'=>__('My Tasks').' ('.number_format($stats['assigned']).')',
'title'=>__('Assigned Tasks'),
'href'=>'tasks.php?status=assigned',
'iconclass'=>'assignedTickets'),
($_REQUEST['status']=='assigned'));
}
if ($stats['overdue']) {
$nav->addSubMenu(array('desc'=>__('Overdue').' ('.number_format($stats['overdue']).')',
'title'=>__('Stale Tasks'),
'href'=>'tasks.php?status=overdue',
'iconclass'=>'overdueTickets'),
($_REQUEST['status']=='overdue'));
if(!$sysnotice && $stats['overdue']>10)
$sysnotice=sprintf(__('%d overdue tasks!'), $stats['overdue']);
}
if ($stats['closed']) {
$nav->addSubMenu(array('desc' => __('Completed').' ('.number_format($stats['closed']).')',
'title'=>__('Completed Tasks'),
'href'=>'tasks.php?status=closed',
'iconclass'=>'closedTickets'),
($_REQUEST['status']=='closed'));
}
if (isset($_SESSION['advsearch'])) {
// XXX: De-duplicate and simplify this code
$search = SavedSearch::create();
$form = $search->getFormFromSession('advsearch');
$form->loadState($_SESSION['advsearch']);
$tasks = Task::objects();
$tasks = $search->mangleQuerySet($tasks, $form);
$count = $tasks->count();
$nav->addSubMenu(array('desc' => __('Search').' ('.number_format($count).')',
'title'=>__('Advanced Task Search'),
'href'=>'tasks.php?status=search',
'iconclass'=>'Ticket'),
(!$_REQUEST['status'] || $_REQUEST['status']=='search'));
}
if ($thisstaff->hasPerm(TaskModel::PERM_CREATE)) {
$nav->addSubMenu(array('desc'=>__('New Task'),
'title'=> __('Open a New Task'),
'href'=>'#tasks/add',
'iconclass'=>'newTicket task-action',
'id' => 'new-task',
'attr' => array(
'data-dialog' => '{"size":"large"}'
)
),
($_REQUEST['a']=='open'));
}
$ost->addExtraHeader('<script type="text/javascript" src="js/ticket.js"></script>');
$ost->addExtraHeader('<meta name="tip-namespace" content="tasks.queue" />',
"$('#content').data('tipNamespace', 'tasks.queue');");
if($task) {
$ost->setPageTitle(sprintf(__('Task #%s'),$task->getNumber()));
$nav->setActiveSubMenu(-1);
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
if ($_REQUEST['a']=='edit'
&& $task->checkStaffPerm($thisstaff, TaskModel::PERM_EDIT)) {
$inc = 'task-edit.inc.php';
if (!$forms) $forms=DynamicFormEntry::forObject($task->getId(), 'A');
// Auto add new fields to the entries
foreach ($forms as $f) $f->addMissingFields();
} elseif($_REQUEST['a'] == 'print' && !$task->pdfExport($_REQUEST['psize']))
$errors['err'] = __('Internal error: Unable to export the task to PDF for print.');
} else {
$inc = 'tasks.inc.php';
if ($_REQUEST['a']=='open' &&
$thisstaff->hasPerm(Task::PERM_CREATE))
$inc = 'task-open.inc.php';
elseif($_REQUEST['a'] == 'export') {
$ts = strftime('%Y%m%d');
if (!($query=$_SESSION[':Q:tasks']))
$errors['err'] = __('Query token not found');
elseif (!Export::saveTasks($query, "tasks-$ts.csv", 'csv'))
$errors['err'] = __('Internal error: Unable to dump query results');
}
//Clear active submenu on search with no status
if($_REQUEST['a']=='search' && !$_REQUEST['status'])
$nav->setActiveSubMenu(-1);
//set refresh rate if the user has it configured
if(!$_POST && !$_REQUEST['a'] && ($min=$thisstaff->getRefreshRate())) {
$js = "clearTimeout(window.task_refresh);
window.task_refresh = setTimeout($.refreshTaskView,"
.($min*60000).");";
$ost->addExtraHeader('<script type="text/javascript">'.$js.'</script>',
$js);
}
}
require_once(STAFFINC_DIR.'header.inc.php');
require_once(STAFFINC_DIR.$inc);
require_once(STAFFINC_DIR.'footer.inc.php');