Newer
Older
<?php
/*********************************************************************
ajax.tasks.php
AJAX interface for tasks
Peter Rotich <peter@osticket.com>
Copyright (c) 20014 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:
**********************************************************************/
if(!defined('INCLUDE_DIR')) die('403');
include_once(INCLUDE_DIR.'class.ticket.php');
require_once(INCLUDE_DIR.'class.ajax.php');
require_once(INCLUDE_DIR.'class.task.php');
class TasksAjaxAPI extends AjaxController {
function preview($tid) {
global $thisstaff;
// TODO: check staff's access.
if(!$thisstaff || !($task=Task::lookup($tid)))
Http::response(404, __('No such task'));
include STAFFINC_DIR . 'templates/task-preview.tmpl.php';
}
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
120
121
122
123
124
125
126
function edit($tid) {
global $thisstaff;
// TODO: check staff's access.
if(!$thisstaff || !($task=Task::lookup($tid)))
Http::response(404, __('No such task'));
$info = $errors = array();
$forms = DynamicFormEntry::forObject($task->getId(),
ObjectModel::OBJECT_TYPE_TASK);
if ($_POST) {
$info = Format::htmlchars($_POST);
$info['error'] = $errors['err'] ?: __('Coming soon!');
}
include STAFFINC_DIR . 'templates/task-edit.tmpl.php';
}
function transfer($tid) {
global $thisstaff;
// TODO: check staff's access.
if(!$thisstaff || !($task=Task::lookup($tid)))
Http::response(404, __('No such task'));
$info = $errors = array();
if ($_POST) {
if ($task->transfer($_POST, $errors)) {
Http::response(201, $task->getId());
}
$info = Format::htmlchars($_POST);
$info['error'] = $errors['err'] ?: __('Unable to transfer task');
}
include STAFFINC_DIR . 'templates/task-transfer.tmpl.php';
}
function assign($tid) {
global $thisstaff;
// TODO: check staff's access.
if(!$thisstaff || !($task=Task::lookup($tid)))
Http::response(404, __('No such task'));
$info = $errors = array();
if ($_POST) {
if ($task->assign($_POST, $errors)) {
Http::response(201, $task->getId());
}
$info = Format::htmlchars($_POST);
$info['error'] = $errors['err'] ?: __('Unable to assign task');
}
include STAFFINC_DIR . 'templates/task-assign.tmpl.php';
}
function delete($tid) {
global $thisstaff;
// TODO: check staff's access.
if(!$thisstaff || !($task=Task::lookup($tid)))
Http::response(404, __('No such task'));
$info = $errors = array();
if ($_POST) {
if ($task->delete($_POST, $errors)) {
Http::response(201, 0);
}
$info = Format::htmlchars($_POST);
$info['error'] = $errors['err'] ?: __('Unable to delete task');
}
$info['placeholder'] = sprintf(__(
'Optional reason for deleting %s'),
__('this task'));
$info['warn'] = sprintf(__(
'Are you sure you want to DELETE %s?'),
__('this task'));
$info['extra'] = sprintf('<strong>%s</strong>',
__('Deleted tasks CANNOT be recovered, including any associated attachments.')
);
include STAFFINC_DIR . 'templates/task-delete.tmpl.php';
}
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
function task($tid) {
global $thisstaff;
// TODO: check staff's access.
if (!$thisstaff || !($task=Task::lookup($tid)))
Http::response(404, __('No such task'));
$info=$errors=array();
$task_note_form = new Form(array(
'attachments' => new FileUploadField(array('id'=>'attach',
'name'=>'attach:note',
'configuration' => array('extensions'=>'')))
));
if ($_POST) {
switch ($_POST['a']) {
case 'postnote':
$vars = $_POST;
$attachments = $task_note_form->getField('attachments')->getClean();
$vars['cannedattachments'] = array_merge(
$vars['cannedattachments'] ?: array(), $attachments);
if(($note=$task->postNote($vars, $errors, $thisstaff))) {
$msg=__('Note posted successfully');
// Clear attachment list
$task_note_form->setSource(array());
$task_note_form->getField('attachments')->reset();
Draft::deleteForNamespace('task.note.'.$task->getId(),
$thisstaff->getId());
} else {
if(!$errors['err'])
$errors['err'] = __('Unable to post the note - missing or invalid data.');
}
break;
default:
$errors['err'] = __('Unknown action');
}
}
include STAFFINC_DIR . 'templates/task-view.tmpl.php';
}
}
?>