-
Notifications
You must be signed in to change notification settings - Fork 10
/
action.php
237 lines (202 loc) · 7.46 KB
/
action.php
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
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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?php
/**
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Esther Brunner <[email protected]>
*/
class action_plugin_task extends DokuWiki_Action_Plugin {
/**
* register the eventhandlers
*/
function register(Doku_Event_Handler $contr) {
$contr->register_hook('ACTION_ACT_PREPROCESS',
'BEFORE',
$this,
'handle_act_preprocess',
array());
}
/**
* Checks if 'newentry' was given as action, if so we
* do handle the event our self and no further checking takes place
*/
function handle_act_preprocess(&$event, $param) {
if ($event->data != 'newtask' && $event->data != 'changetask') return;
// we can handle it -> prevent others
$event->stopPropagation();
switch($event->data) {
case 'newtask':
$event->data = $this->_newTask();
break;
case 'changetask':
$event->data = $this->_changeTask();
break;
}
}
/**
* Creates a new task page
*/
function _newTask() {
global $ID;
global $INFO;
$ns = cleanID($_REQUEST['ns']);
$title = str_replace(':', '', $_REQUEST['title']);
$back = $ID;
$ID = ($ns ? $ns.':' : '').cleanID($title);
$INFO = pageinfo();
// check if we are allowed to create this file
if ($INFO['perm'] >= AUTH_CREATE) {
//check if locked by anyone - if not lock for my self
if ($INFO['locked']) {
return 'locked';
} else {
lock($ID);
}
// prepare the new thread file with default stuff
if (!@file_exists($INFO['filepath'])) {
global $TEXT;
$user = $_REQUEST['user'];
$date = $_REQUEST['date'];
$priority = $_REQUEST['priority'];
// create wiki page
$data = array(
'id' => $ID,
'ns' => $ns,
'title' => $title,
'back' => $back,
'priority' => $priority,
'user' => $user,
'date' => $date,
);
$TEXT = $this->_pageTemplate($data);
return 'preview';
} else {
return 'edit';
}
} else {
return 'show';
}
}
/**
* Adapted version of pageTemplate() function
*/
function _pageTemplate($data) {
global $INFO;
$id = $data['id'];
$tpl = io_readFile(DOKU_PLUGIN.'task/_template.txt');
// standard replacements
$replace = array(
'@ID@' => $id,
'@NS@' => $data['ns'],
'@PAGE@' => strtr(noNS($id),'_',' '),
'@USER@' => $data['user'],
'@NAME@' => $INFO['userinfo']['name'],
'@MAIL@' => $INFO['userinfo']['mail'],
'@DATE@' => $data['date'],
);
// additional replacements
$replace['@BACK@'] = $data['back'];
$replace['@TITLE@'] = $data['title'];
$replace['@PRIORITY@'] = $data['priority'];
// tag if tag plugin is available
if ((@file_exists(DOKU_PLUGIN.'tag/syntax/tag.php')) && (!plugin_isdisabled('tag'))) {
$replace['@TAG@'] = "\n\n{{tag>}}";
} else {
$replace['@TAG@'] = '';
}
// discussion if discussion plugin is available
if ((@file_exists(DOKU_PLUGIN.'discussion/syntax/comments.php')) && (!plugin_isdisabled('discussion'))) {
$replace['@DISCUSSION@'] = "~~DISCUSSION~~";
} else {
$replace['@DISCUSSION@'] = '';
}
// do the replace
$tpl = str_replace(array_keys($replace), array_values($replace), $tpl);
return $tpl;
}
/**
* Changes the status of a task
*/
function _changeTask() {
global $ID;
global $INFO;
$status = $_REQUEST['status'];
$status = trim($status);
if (!is_numeric($status) || ($status < -1) || ($status > 4)) {
if ($this->getConf('show_error_msg')) {
$message = $this->getLang('msg_rcvd_invalid_status');
$message = str_replace('%status%', $status, $message);
msg($message, -1);
}
return 'show';
}
// load task data
if ($my =& plugin_load('helper', 'task')) {
$task = $my->readTask($ID);
} else {
if ($this->getConf('show_error_msg')) {
msg($this->getLang('msg_load_helper_failed'), -1);
}
return 'show';
}
if ($task['status'] == $status) {
// unchanged
if ($this->getConf('show_info_msg')) {
msg($this->getLang('msg_nothing_changed'));
}
return 'show';
}
$responsible = $my->_isResponsible($task['user']['name']);
// some additional checks if change not performed by an admin
// FIXME error messages?
if ($INFO['perm'] != AUTH_ADMIN) {
// responsible person can't verify her / his own tasks
if ($responsible && ($status == 4)) {
if ($this->getConf('show_info_msg')) {
msg ($this->getLang('msg_responsible_no_verify'));
}
return 'show';
}
// other persons can only accept or verify tasks
if (!$responsible && $status != 1 && $status != 4) {
if ($this->getConf('show_info_msg')) {
msg ($this->getLang('msg_other_accept_or_verify'));
}
return 'show';
}
}
// assign task to a user
if (!$task['user']['name']) {
// FIXME error message?
if (!$_SERVER['REMOTE_USER']) {
// no logged in user
if ($this->getConf('show_info_msg')) {
msg($this->getLang('msg_not_logged_in'));
}
return 'show';
}
$wiki = rawWiki($ID);
$summary = $this->getLang('mail_changedtask').': '.$this->getLang('accepted');
$new = preg_replace('/~~TASK:?/', '~~TASK:'.$INFO['userinfo']['name'], $wiki);
if ($new != $wiki) {
saveWikiText($ID, $new, $summary, true); // save as minor edit
}
$task['user'] = array(
'id' => $_SERVER['REMOTE_USER'],
'name' => $INFO['userinfo']['name'],
'mail' => $INFO['userinfo']['mail'],
);
}
// save .task meta file and clear xhtml cache
$oldstatus = $task['status'];
$task['status'] = $status;
$my->writeTask($ID, $task);
$_REQUEST['purge'] = true;
if ($this->getConf('show_success_msg')) {
$message = $this->getLang('msg_status_changed');
$message = str_replace('%status%', $my->statusLabel($status), $message);
$message = str_replace('%oldstatus%', $my->statusLabel($oldstatus), $message);
msg($message, 1);
}
return 'show';
}
}
// vim:ts=4:sw=4:et:enc=utf-8: