-
Notifications
You must be signed in to change notification settings - Fork 8
/
listItems.inc.php
508 lines (437 loc) · 19.7 KB
/
listItems.inc.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
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
<?php
require_once 'headerDB.inc.php';
if ($_SESSION['debug']['debug']) include_once 'header.inc.php';
//GET URL VARIABLES
$values = array();
$filter = array();
/* --------------------------------------------------------------------------
* set $filter
*
* NB the values for filter are assigned in alphabetic order,
* to try to assure consistency, as we'll be using the filter as the index-key
* to link to the right Perspective
*
* I've used getVarFromGetPost instead of $_REQUEST,
* because I want $_GET to have higher priority than $_POST.
*/
$filter['categoryId'] =getVarFromGetPost('categoryId',NULL);
if ($filter['categoryId']==='0') $filter['categoryId']=NULL;
$filter['completed'] =getVarFromGetPost('completed'); //status:true/false (completed/pending)
$filter['contextId'] =getVarFromGetPost('contextId',NULL);
if ($filter['contextId']==='0') $filter['contextId']=NULL;
$filter['dueonly'] =getVarFromGetPost('dueonly'); //has due date:true/empty
$filter['everything'] =getVarFromGetPost('everything'); //overrides filter:true/empty
$filter['liveparents'] =getVarFromGetPost('liveparents');
$filter['needle'] =getVarFromGetPost('needle'); //search string (plain text)
$filter['nextonly'] =getVarFromGetPost('nextonly'); //next actions only: true/empty
$filter['notcategory'] =getVarFromGetPost('notcategory');
$filter['notspacecontext']=getVarFromGetPost('notspacecontext');
$filter['nottimecontext'] =getVarFromGetPost('nottimecontext');
$filter['parentId'] =getVarFromGetPost('parentId');
$filter['repeatingonly'] =getVarFromGetPost('repeatingonly'); //is repeating:true/empty
$filter['someday'] =getVarFromGetPost('someday'); //someday/maybe:true/empty
$filter['tags'] =strtolower(getVarFromGetPost('tags'));
$filter['tickler'] =getVarFromGetPost('tickler'); //suppressed (tickler file): true/false
$filter['timeframeId'] =getVarFromGetPost('timeframeId',NULL);
if ($filter['timeframeId']==='0') $filter['timeframeId']=NULL;
$filter['type'] =getVarFromGetPost('type','a');
if ($filter['type']==='s') {
$filter['someday']=true;
$filter['type']='p';
}
$quickfind=isset($_GET['quickfind']);
if ($quickfind) {
$filter['everything']='true';
$filter['type']='*';
}
// pass filters in referrer
$referrer = "{$pagename}.php?";
foreach($filter as $filterkey=>$filtervalue)
if ($filtervalue!='') $referrer .= "{$filterkey}={$filtervalue}&";
/* end of setting $filter
--------------------------------------------------------------------------
*/
log_value('listitems filter',$filter);
$values['type'] =$filter['type'];
$values['parentId'] =$filter['parentId'];
$values['contextId'] =$filter['contextId'];
$values['categoryId'] =$filter['categoryId'];
$values['timeframeId'] =$filter['timeframeId'];
$values['needle'] =$filter['needle'];
$values['tags'] =$filter['tags'];
//SQL CODE
$values['filterquery']='';
$taglisttemp=query('gettags',$values);
$taglist=array();
if ($taglisttemp) foreach ($taglisttemp as $tag) $taglist[]=makeclean($tag['tagname']);
//create type-filter for timecontext select boxes
$values['timefilterquery'] = ($_SESSION['config']['useTypesForTimeContexts'] && $values['type']!=='*')?" WHERE ".sqlparts("timetype",$values):'';
//create select boxes for category, context, time:
$cashtml=str_replace('--','(any)',categoryselectbox ($values));
$cshtml =str_replace('--','(any)',contextselectbox ($values));
$tshtml =str_replace('--','(any)',timecontextselectbox($values));
/*
* -------------------------------------------------------------------
* determine the values of those variables that influence the columns displayed
*/
$trimlength=$_SESSION['config']['trimLength'];
if($trimlength) {
$descriptionField='shortdesc';
$outcomeField='shortoutcome';
} else {
$descriptionField='description';
$outcomeField='desiredOutcome';
}
//determine item and parent labels,
$typename=getTypes($values['type']);
$parenttypes=getParentType($values['type']);
if (empty($parenttypes)) {
$values['ptype']=$parentname='';
} else {
$values['ptype']=$parenttypes[0];
$parentname=getTypes($values['ptype']);
}
/*
===================================================================
setting $show/$dispArray values
*/
// default list of fields
$dispArray=array(
'parent'=>'Parents'
,'type'=>'type'
,'flags'=>'!'
,'NA'=>'NA'
,'title'=>$typename.'s'
,$descriptionField=>'Description'
,$outcomeField=>'Desired Outcome'
,'category'=>'Category'
,'context'=>'Space Context'
,'timeframe'=>'Time Context'
,'deadline'=>'Deadline'
,'recurdesc'=>'Repeat'
,'tickledate'=>'Suppress until'
,'dateCreated'=>'Date Created'
,'lastModified'=>'Last Modified'
,'dateCompleted'=>'Date Completed'
,'checkbox'=>'Complete'
,'tags'=>'Tags'
,'assignType'=>'Process inbox'
);
$show=array();
foreach ($dispArray as $key=>$dummy)
$show[$key]=false;
$testuri=sha1($referrer);
//$perspectivefilter=' WHERE '.sqlparts('perspectiveuri',array('uri'=>$testuri));
//$displayoptions=query('selectperspective',array('filterquery'=>$perspectivefilter));
//}
if (false && $displayoptions) { // disabling this for now
// we have a saved perspective setting out how pages with this filter should be displayed.
$dispCopy=$dispArray;
$dispArray=array();
foreach (explode(',',$displayoptions[0]['columns']) as $field)
$dispArray[$field]=$dispCopy[$field];
$mainsort=safeIntoDB($displayoptions[0]['sort']);
if (!empty($mainsort))
$sort=array('getitemsandparent'=>$mainsort.','.$_SESSION['sort']['getitemsandparent']);
foreach (explode(',',$displayoptions[0]['show']) as $field)
$show[$field]=true;
$checkchildren=array_key_exists('flags',$dispArray);
} else {
// manually calculating which columns to show
// set default table column display options
$sort=false;
$showalltypes=false;
//page display options array--- can put defaults in preferences table/config/session and load into $show array as defaults...
$show['parent']=TRUE;
$show['title']=TRUE;
$show[$descriptionField]=TRUE;
$show['category']=TRUE;
$show['context']=TRUE;
$show['timeframe']=TRUE;
$show['deadline']=TRUE;
$show['recurdesc']=TRUE;
$show['checkbox']=TRUE;
switch ($values['type']) {
case "*" : $show['type']=TRUE; $show['checkbox']=FALSE; $show['recurdesc']=FALSE; $show['dateCreated']=TRUE; $show['deadline']=FALSE; $show['desiredOutcome']=TRUE; $show['category']=FALSE; $show['context']=FALSE; $show['timeframe']=FALSE; $checkchildren=FALSE; $showalltypes=TRUE; break;
case "m" : $show['parent']=FALSE; $show['checkbox']=FALSE; $show['recurdesc']=FALSE; $show['dateCreated']=TRUE; $show['deadline']=FALSE; $show['desiredOutcome']=TRUE; $show['context']=FALSE; $show['timeframe']=FALSE; $checkchildren=TRUE; break;
case "v" : $show['checkbox']=FALSE; $show['recurdesc']=FALSE; $show['dateCreated']=TRUE; $show['deadline']=FALSE; $show['desiredOutcome']=TRUE; $show['context']=FALSE; $show['timeframe']=FALSE; $checkchildren=TRUE; break;
case "o" : $show['checkbox']=FALSE; $show['recurdesc']=FALSE; $show['deadline']=FALSE; $show['desiredOutcome']=TRUE; $show['context']=FALSE; $show['timeframe']=FALSE; $checkchildren=TRUE; break;
case "g" : $show['desiredOutcome']=TRUE; $show['context']=FALSE; $checkchildren=TRUE; break;
case "p" : $show['context']=FALSE; $show['timeframe']=FALSE; $checkchildren=TRUE; break;
case "a" : $show['parent']=TRUE; $show['NA']=TRUE; $show['category']=FALSE; $checkchildren=FALSE; break;
case "w" : $show['parent']=TRUE; $show['NA']=TRUE; $checkchildren=FALSE; break;
case "r" : $show['parent']=TRUE; $show['category']=FALSE; $show['context']=FALSE; $show['timeframe']=FALSE; $show['checkbox']=FALSE; $show['recurdesc']=FALSE; $show['dateCreated']=TRUE; $checkchildren=FALSE; break;
case "i" : $show['parent']=FALSE; $show['category']=FALSE; $show['context']=FALSE; $show['timeframe']=FALSE; $show['deadline']=FALSE; $show['dateCreated']=TRUE; $show['recurdesc']=FALSE; $show['assignType']=TRUE; $afterTypeChange='listItems.php?type=i';$checkchildren=FALSE; break;
case "L" : // as case 'C', so deliberately flows through
case "C" : $show['parent']=TRUE; $show['category']=TRUE; $show['context']=FALSE; $show['timeframe']=FALSE; $show['deadline']=FALSE; $show['dateCreated']=FALSE; $show['recurdesc']=FALSE; $show['checkbox']=FALSE; $checkchildren=TRUE; break;
case "T" : $show['parent']=TRUE; $show['category']=FALSE; $show['context']=FALSE; $show['timeframe']=FALSE; $show['deadline']=FALSE; $show['dateCreated']=TRUE; $show['recurdesc']=FALSE; $checkchildren=FALSE; break;
default : $typename="Item"; $parentname=$values['ptype']=""; $checkchildren=FALSE;
}
$show['flags']=$checkchildren; // temporary measure; to be made user-configurable later
if ($filter['someday']=="true") {
$show['dateCreated']=TRUE;
$show['context']=FALSE;
$show['recurdesc']=FALSE;
$show['NA']=FALSE;
$show['deadline']=FALSE;
$show['timeframe']=FALSE;
$checkchildren=FALSE;
}
if ($filter['tickler']=="true") $show['tickledate']=TRUE;
if ($filter['dueonly']=="true") $show['deadline']=TRUE;
if ($filter['repeatingonly']=="true") {
$show['deadline']=TRUE;
$show['recurdesc']=TRUE;
}
if ($filter['completed']=="true") {
$show['NA']=FALSE;
$show['flags']=FALSE;
$show['tickledate']=FALSE;
$show['dateCreated']=TRUE;
$show['deadline']=FALSE;
$show['recurdesc']=FALSE;
$show['dateCompleted']=TRUE;
$show['checkbox']=FALSE;
$checkchildren=FALSE;
}
if ($filter['everything']=="true") {
$show['type']=$showalltypes;
$show['isSomeday']=TRUE;
$show['tickledate']=TRUE;
$show['dateCreated']=TRUE;
$show['lastModified']=TRUE;
$show['deadline']=TRUE;
$show['dateCompleted']=TRUE;
$show['checkbox']=FALSE;
}
if ($filter['tags'] !=NULL) $show['tags']=true;
if (!$checkchildren) $show['flags']=FALSE;
if (!$show['assignType'])
unset($dispArray['assignType']);
// end of manually calculating which columns to show
}
/*
end of setting $show/$dispArray values
===================================================================
build the query
*/
//set query fragments based on filters
$values['childfilterquery'] = '';
//type filter
if ($values['type']!=='*')
$values['childfilterquery'] .= " AND ".sqlparts("typefilter",$values);
// search string
if ($filter['needle']!=='')
$values['childfilterquery'] .= " AND ".sqlparts("matchall",$values);
$linkfilter='';
if ($checkchildren) {
$values['filterquery'] = sqlparts("checkchildren",$values);
$values['extravarsfilterquery'] = sqlparts("countchildren",$values);;
} else $values['filterquery']=$values['extravarsfilterquery']='';
if ($filter['tags'] !=NULL) {
// now put into array, to count
$values['childfilterquery'] .= " AND " .sqlparts("hastags",$values);
}
/* Only use filter selections if $filter['everything'] is not true;
i.e. if we are not forcing the listing of *all* items
*/
if ($filter['everything']!="true") {
if ($values['parentId']!='')
$values['filterquery'] .= " WHERE ".sqlparts("hasparent",$values);
else switch ($filter['liveparents']) {
case 'false': // show only children of completed / suppressed / someday parents
$values['filterquery'] .= ' WHERE NOT ( '.sqlparts("liveparents",$values).' )';
break;
case '*': // don't filter on completion status of parents
break;
case 'true': //Filter out items with completed/suppressed/someday parents - deliberately flows through to default case
default:
$values['filterquery'] .= ' WHERE '.sqlparts("liveparents",$values);
break;
}
//filter box filters
if ($filter['categoryId'] != NULL && $filter['notcategory']=="true")
$values['childfilterquery'] .= " AND ".sqlparts("notcategoryfilter",$values);
elseif($filter['categoryId'] != NULL || $filter['notcategory']=="true") {
$values['childfilterquery'] .= " AND ".sqlparts("categoryfilter",$values);
$linkfilter .= '&categoryId='.$values['categoryId'];
}
if ($filter['contextId'] != NULL && $filter['notspacecontext']=="true")
$values['childfilterquery'] .= " AND ".sqlparts("notcontextfilter",$values);
elseif ($filter['contextId'] != NULL || $filter['notspacecontext']=="true") {
$values['childfilterquery'] .= " AND ".sqlparts("contextfilter",$values);
$linkfilter .= '&contextId='.$values['contextId'];
}
if ($filter['timeframeId'] != NULL && $filter['nottimecontext']=="true")
$values['childfilterquery'] .= " AND ".sqlparts("nottimeframefilter",$values);
elseif ($filter['timeframeId'] != NULL || $filter['nottimecontext']=="true") {
$values['childfilterquery'] .= " AND ".sqlparts("timeframefilter",$values);
$linkfilter .= '&timeframeId='.$values['timeframeId'];
}
$values['childfilterquery'] .= ' AND '.sqlparts(
($filter['completed']=='true') ? 'completeditems' : 'pendingitems'
,$values );
$values['isSomeday'] = ($filter['someday']=='true') ? 'y' : 'n';
$values['childfilterquery'] .= ' AND '.sqlparts('issomeday',$values);
if ($filter['tickler']=="true") {
$linkfilter .='&tickler=true';
$values['childfilterquery'] .= " AND ".sqlparts("suppresseditems",$values);
} else {
$values['childfilterquery'] .= " AND ".sqlparts("activeitems",$values);
}
if ($filter['repeatingonly']=="true") $values['childfilterquery'] .= " AND " .sqlparts("repeating",$values);
if ($filter['dueonly']=="true") $values['childfilterquery'] .= " AND " .sqlparts("due",$values);
if ($filter['nextonly']=='true')
$values['childfilterquery'] .= ' AND '.sqlparts("isNAonly",$values);
}
if ($values['childfilterquery'] !== '') {
$values['childfilterquery']=preg_replace('/^ AND/','WHERE',$values['childfilterquery']);
}
/*
Section Heading
*/
$link="item.php?type=".$values['type'];
if($filter['everything']=="true")
$title = '';
else {
$link .= $linkfilter;
if ($filter['completed']=="true")
$title = 'Completed ';
elseif ($filter['dueonly']=="true")
$title = 'Due ';
else $title ='';
if ($filter['repeatingonly']=="true")
$title .= 'Repeating ';
if ($filter['someday']=="true") {
$title .= 'Someday/Maybe ';
$link.='&someday=true';
}
if ($filter['nextonly']=="true") {
$title .= 'Next ';
$link .='&nextonly=true';
}
}
$title .= $typename;
/*
===================================================================
main query: build array of items
===================================================================
*/
if ($quickfind)
$maintable=0;
else
$maintable=query("getitemsandparent",$values,$sort);
//$maintable=array();
$allids=array();
if ($maintable) {
$nonext=FALSE;
$nochildren=FALSE;
$wasNAonEntry=array(); // stash this in case we introduce marking actions as next actions onto this screen
$max=count($maintable);
for ($thisrow=0;$thisrow<$max;$thisrow++) {
$row=&$maintable[$thisrow];
$allids[]=$row['itemId'];
$nochildren=false;
$nonext=false;
if ($checkchildren) {
$nochildren=!$row['numChildren'];
$nonext=($row['type']=='p' && !$row['numNA']);
}
if (isset($row['nextaction']) && $row['nextaction']==='y') {
/* TODO - test what happens when AJAX off, and showing complete
* and incomplete items, and user completes 1 and submits it.
* Fortunately, this is not an issue at present, because the completion
* checkboxes aren't displayed, if the list includes completed items
*/
array_push($wasNAonEntry,$row['itemId']); // TOFIX need to do something similar with completed items
$row['NA'] =true;
} else $row['NA']=false;
$row['class'] = ($nonext || $nochildren)?'noNextAction':'';
$row['nextaction']==='y';
if ($row['parentId']=='') {
$row['parent.class']='noparent';
$row['ptitle']='';
} else {
$row['ptitle']=$row['ptitle'];
}
// add markers to indicate if this is a next action, or a project with no next actions, or an item with no childern
if ($nochildren)
$row['flags'] = 'noChild';
elseif ($nonext)
$row['flags'] = 'noNA';
else
$row['flags'] = '';
//item title
if (!($row['type']=="a" || $row['type']==="r" || $row['type']==="w" || $row['type']==="i"))
$row['doreport']=true;
$cleantitle=makeclean($row['title']);
$row['title.class'] = 'maincolumn';
$row['checkboxtitle']= 'Complete';
$row['checkboxname']= 'isMarked[]';
$row['checkboxvalue']=$row['itemId'];
if (!empty($row['dateCompleted']))
$row['NAdisabled']=$row['checkboxchecked']=$row['checkboxdisabled']=true;
$row[$descriptionField] = $row['description'];
$row[$outcomeField] = $row['desiredOutcome'];
$row['category'] =makeclean($row['category']);
$row['context'] = makeclean($row['cname']);
$row['timeframe'] = makeclean($row['timeframe']);
$childType=array();
$childType=getChildType($row['type']);
if (count($childType)) $row['childtype'] =$childType[0];
if($row['deadline']) {
$deadline=prettyDueDate($row['deadline'],$row['daysdue']);
$row['deadline'] =$deadline['date'];
if (empty($row['dateCompleted'])) {
$row['deadline.class']=$deadline['class'];
$row['deadline.title']=$deadline['title'];
}
} else $row['deadline']='';
} // end of: for
log_value('values to print:',$maintable);
unset($row);
} else $maintable=array(); // end of: if($maintable)
/*
===================================================================
end of main query: finished building array of items
===================================================================
*/
$_SESSION['idlist-'.$values['type']]=$allids;
$numrows=count($maintable);
if ($numrows!==1) $title.='s';
if ($filter['tickler']=="true" && $filter['everything']!="true") {
$title .= ' in Tickler File';
$link .= '&suppress=true';
}
if ($quickfind)
$title=' ';
elseif($filter['everything']=="true") {
switch ($numrows) {
case 0:
$title = 'There are no '.$title;
break;
case 1:
$title = 'There is one '.$title;
break;
default:
$title = "All $numrows $title";
break;
}
} else
$title = $numrows.' '.$title;
if($numrows || $quickfind)
$endmsg='';
else {
$endmsg=array('header'=>"You have no {$typename}s remaining.");
if ($filter['completed']!="true" && $values['type']!="t" && $values['type']!="*") {
$endmsg['prompt']="Create a new {$typename}";
$endmsg['link']=$link;
}
}
if (($filter['completed']!="true" || $filter['everything']=="true") && $filter['type']!=='*')
$sectiontitle = "<a title='Add new' href='$link'>$title</a>";
else
$sectiontitle =$title;
$_SESSION['lastfilter'.$values['type']]=$referrer;
$showsubmit=($show['NA'] || $show['checkbox']) && count($maintable);
// php closing tag has been omitted deliberately, to avoid unwanted blank lines being sent to the browser