-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTasks.php
310 lines (292 loc) · 11 KB
/
Tasks.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
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
<?php
class TasksPlugin extends MantisPlugin {
public string $nonce;
function register() {
$this->name = 'Tasks';
$this->description = lang_get( 'tasks_plugin_desc' );
$this->version = '3.32';
$this->requires = array('MantisCore' => '2.0.0',);
$this->author = 'Cas Nuy';
$this->contact = 'Cas-at-nuy.info';
$this->url = 'https://github.com/mantisbt-plugins/Tasks';
$this->page = 'config';
$this->nonce = crypto_generate_uri_safe_nonce( 16 );
}
function init() {
event_declare('EVENT_MYVIEW');
event_declare('EVENT_VIEW_BUG_DETAILS2');
event_declare('EVENT_RESOLVE_BUG');
event_declare('EVENT_CLOSE_BUG');
plugin_event_hook( 'EVENT_VIEW_BUG_EXTRA', 'tasks_form1' );
// plugin_event_hook( 'EVENT_VIEW_BUG_DETAILS2', 'tasks_form1' );
plugin_event_hook( 'EVENT_REPORT_BUG', 'CreateTasks' );
plugin_event_hook( 'EVENT_UPDATE_BUG', 'CreateTasks2' );
plugin_event_hook( 'EVENT_RESOLVE_BUG', 'CheckTasks' );
plugin_event_hook( 'EVENT_CLOSE_BUG', 'CheckTasks' );
plugin_event_hook( 'EVENT_BUG_DELETED', 'DeleteTasks' );
$showmenu = plugin_config_get( 'tasks_show_menu' );
if (ON === $showmenu){
plugin_event_hook( 'EVENT_MENU_MAIN', 'tasks_menu1' );
} else {
plugin_event_hook( 'EVENT_MYVIEW', 'tasks_view' );
}
plugin_event_hook( 'EVENT_MENU_MANAGE', 'tasks_menu2' );
}
function schema() {
return array(
array( 'CreateTableSQL', array( plugin_table( 'autodefined' ), "
autotask_id I NOTNULL UNSIGNED AUTOINCREMENT PRIMARY,
project_id I DEFAULT NULL,
category_id I DEFAULT NULL,
autotask_handler I DEFAULT NULL,
autotaskcat_id I DEFAULT NULL,
autotask_title C(50) ,
autotask_desc C(250) ,
autotask_due I DEFAULT NULL,
autotask_status I2 NOTNULL DEFAULT '10'
" ) ),
array( 'CreateTableSQL', array( plugin_table( 'defined' ), "
task_id I NOTNULL UNSIGNED AUTOINCREMENT PRIMARY,
bug_id I DEFAULT NULL,
task_user I DEFAULT NULL,
task_handler I DEFAULT NULL,
taskcat_id I DEFAULT NULL,
task_title C(250) ,
task_desc C(250) ,
task_response C(250) ,
task_created T DEFAULT NULL,
task_changed T DEFAULT NULL,
task_due T NOTNULL DEFAULT '0000-00-00 00:00:00',
task_completed T NOTNULL DEFAULT '0000-00-00 00:00:00',
task_completed_by I DEFAULT NULL,
task_group I DEFAULT NULL,
task_time D(15,2) DEFAULT NULL
" ) ),
array( 'CreateTableSQL', array( plugin_table( 'cat' ), "
taskcat_id I NOTNULL UNSIGNED AUTOINCREMENT PRIMARY,
project_id I DEFAULT NULL,
taskcat_title C(50)
" ) ),
);
}
function config() {
return array(
'tasks_delete_threshold' => ADMINISTRATOR,
'tasks_edit_threshold' => ADMINISTRATOR,
'tasks_finish_threshold' => DEVELOPER,
'tasks_update_threshold' => DEVELOPER,
'tasks_add_threshold' => DEVELOPER,
'tasks_allocate_threshold' => DEVELOPER,
'tasks_view_threshold' => VIEWER,
'tasks_admin_threshold' => ADMINISTRATOR,
'tasks_mail' => OFF,
'tasks_history' => OFF,
'tasks_mail_finish' => OFF,
'tasks_show_menu' => ON,
'tasks_check' => OFF,
'tasks_auto_start_status' => NEW_,
'tasks_update_bug' => ON,
'tasks_assign_group' => OFF,
'tasks_hour_rate' => '50',
);
}
function tasks_form1() {
include 'plugins/Tasks/pages/tasks_form.php';
}
function tasks_menu1() {
$links = array();
$links[] = array(
'title' => lang_get("plugin_tasks_mytasks"),
'url' => plugin_page("my_tasks.php", true)
);
return $links;
}
function tasks_menu2() {
return array('<a href="'. plugin_page( 'all_tasks.php' ) . '">' . lang_get( 'plugin_tasks_alltasks' ) . '</a>' );
}
function tasks_view() {
include 'plugins/Tasks/pages/myview_tasks.php';
}
function CreateTasks($p_event,$p_bug_data,$p_bug_id) {
$project = $p_bug_data->project_id ;
$category = $p_bug_data->category_id ;
$status = $p_bug_data->status ;
// do we have tasks for this project/category/status combination ??
$query = "select * from {plugin_Tasks_autodefined} where project_id=$project and category_id=$category and autotask_status = $status";
$result = db_query($query);
$count = db_num_rows($result) ;
// if not, do we have tasks for this project/Status ??
if ($count <1){
$query ="select * from {plugin_Tasks_autodefined} where project_id=$project and category_id=0 and autotask_status = $status";
$result = db_query($query);
$count = db_num_rows($result) ;
// if not, do we have tasks in general for this status ??
if ($count <1){
$query ="select * from {plugin_Tasks_autodefined} where project_id=0 and category_id=0 and autotask_status = $status";
$result = db_query($query);
$count = db_num_rows($result) ;
}
}
if ($count >0){
# $user = admin account
$user=1;
# retrieve bug_id
$bug_id = $p_bug_id;
# should event be logged in the project
$create_his = config_get( 'plugin_Tasks_tasks_history' );
# should mail be send to assignee
$create_mail = config_get( 'plugin_Tasks_tasks_mail' );
// Create tasks
while ($row = db_fetch_array($result)) {
// step 0 sanitize data
$desc = htmlentities(html_entity_decode($row['autotask_desc'] ),ENT_COMPAT,'UTF-8');
$save_desc = db_prepare_string($desc);
$title = htmlentities(html_entity_decode($row['autotask_title']),ENT_COMPAT,'UTF-8');
// step 1 do we already have this task for this issue
$sql = "select * from {plugin_Tasks_defined} where bug_id =$bug_id and task_title ='$title' ";
$result_sql = db_query($sql);
$count_sql = db_num_rows($result_sql) ;
if ($count_sql>0){
continue;
}
// step2 calculate duedate
$days= $row['autotask_due'];
$bookdate = mktime(0, 0, 0, date('m'),date('d'),date('Y'));
$i = 1;
while ($i <= $days) {
$bookdate += 86400; // Add a day.
$date_info = getdate( $bookdate );
if (($date_info["wday"] == 0) or ($date_info["wday"] == 6) ) {
$bookdate += 86400; // Add a day.
continue;
}
$i++;
}
$bookdate2 = date("Y", $bookdate);
$bookdate2 .= "-";
$bookdate2 .= date("m", $bookdate);
$bookdate2 .= "-";
$bookdate2 .= date("d", $bookdate);
// save the task
$handler=$row['autotask_handler'];
$taskcat_id=$row['autotaskcat_id'];
$query = "INSERT INTO {plugin_Tasks_defined} ( bug_id,task_user, task_handler,taskcat_id,task_title,task_desc,task_created,task_due,task_changed )
VALUES ( '$bug_id',$user, '$handler','$taskcat_id', '$title', '$save_desc', NOW(), '$bookdate2', NOW())";
if(!db_query($query)){
trigger_error( 'ERROR_DB_QUERY_FAILED', ERROR );
}
if ( ON == $create_his ) {
history_log_event_direct( $bug_id, 'Tasks',$title, "Added", $user );
}
# email send to handler of task
if ( ON == $create_mail ) {
$body = lang_get( 'tasks_body' ). " \n\n";
$body .= $title. " \n\n";
$body .= lang_get( 'tasks_date' ). " \n\n";
$body .= $bookdate2;
$resultmail = email_bug_reminder( $handler,$bug_id, $body );
}
}
}
}
function CreateTasks2($p_event,$p_bug_data,$p_bug_data2) {
$project = $p_bug_data2->project_id ;
$category = $p_bug_data2->category_id ;
$status = $p_bug_data2->status ;
$p_bug_id = $p_bug_data2->id ;
// do we have tasks for this project/category/status combination ??
$query = "select * from {plugin_Tasks_autodefined} where project_id=$project and category_id=$category and autotask_status = $status";
$result = db_query($query);
$count = db_num_rows($result) ;
// if not, do we have tasks for this project/Status ??
if ($count <1){
$query ="select * from {plugin_Tasks_autodefined} where project_id=$project and category_id=0 and autotask_status = $status";
$result = db_query($query);
$count = db_num_rows($result) ;
// if not, do we have tasks in general for this status ??
if ($count <1){
$query ="select * from {plugin_Tasks_autodefined} where project_id=0 and category_id=0 and autotask_status = $status";
$result = db_query($query);
$count = db_num_rows($result) ;
}
}
if ($count >0){
# $user = admin account
$user=1;
# retrieve bug_id
$bug_id = $p_bug_id;
# should event be logged in the project
$create_his = config_get( 'plugin_Tasks_tasks_history' );
# should mail be send to assignee
$create_mail = config_get( 'plugin_Tasks_tasks_mail' );
// Create tasks
while ($row = db_fetch_array($result)) {
// step 0 sanitize data
$desc = htmlentities(html_entity_decode($row['autotask_desc'] ),ENT_COMPAT,'UTF-8');
$save_desc = db_prepare_string($desc);
$title = htmlentities(html_entity_decode($row['autotask_title']),ENT_COMPAT,'UTF-8');
// step 1 do we already have this task for this issue
$sql = "select * from {plugin_Tasks_defined} where bug_id =$bug_id and task_title ='$title' ";
$result_sql = db_query($sql);
$count_sql = db_num_rows($result_sql) ;
if ($count_sql>0){
continue;
}
// step2 calculate duedate
$days= $row['autotask_due'];
$bookdate = mktime(0, 0, 0, date('m'),date('d'),date('Y'));
$i = 1;
while ($i <= $days) {
$bookdate += 86400; // Add a day.
$date_info = getdate( $bookdate );
if (($date_info["wday"] == 0) or ($date_info["wday"] == 6) ) {
$bookdate += 86400; // Add a day.
continue;
}
$i++;
}
$bookdate2 = date("Y", $bookdate);
$bookdate2 .= "-";
$bookdate2 .= date("m", $bookdate);
$bookdate2 .= "-";
$bookdate2 .= date("d", $bookdate);
// save the task
$handler=$row['autotask_handler'];
$taskcat_id=$row['taskcat_id'];
$query = "INSERT INTO {plugin_Tasks_defined} ( bug_id,task_user, task_handler,taskcat_id,task_title,task_desc,task_created,task_due,task_changed )
VALUES ( '$bug_id',$user, '$handler','$taskcat_id', '$title', '$save_desc', NOW(), '$bookdate2', NOW())";
if(!db_query($query)){
trigger_error( 'ERROR_DB_QUERY_FAILED', ERROR );
}
if ( ON == $create_his ) {
history_log_event_direct( $bug_id, 'Tasks',$title, "Added", $user );
}
# email send to handler of task
if ( ON == $create_mail ) {
$body = lang_get( 'tasks_body' ). " \n\n";
$body .= $title. " \n\n";
$body .= lang_get( 'tasks_date' ). " \n\n";
$body .= $bookdate2;
$resultmail = email_bug_reminder( $handler,$bug_id, $body );
}
}
}
}
function CheckTasks($p_event,$p_bug_id) {
$checktasks = plugin_config_get( 'tasks_check' );
if (ON == $checktasks){
$query = "select * from {plugin_Tasks_defined} where bug_id=$p_bug_id and task_completed = '0000-00-00 00:00:00' " ;
$results = db_query($query) ;
$count= db_num_rows($results);
if ($count>0){
trigger_error( 'ERROR_BUG_OPEN_TASKS', ERROR );
}
}
return;
}
function DeleteTasks($p_event,$p_bug_id) {
$query = "delete from {plugin_Tasks_defined} where bug_id=$p_bug_id" ;
$results = db_query($query) ;
return;
}
}