This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
forked from sjsrey/gtd-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreportContext.inc.php
141 lines (130 loc) · 5.47 KB
/
reportContext.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
<?php
include_once 'headerDB.inc.php';
function makeContextRow($row) {
$rowout=array();
$rowout['itemId']=$row['itemId'];
$rowout['type']='a';
$rowout['description']=$row['description'];
$rowout['recurdesc'] = ($row['recurdesc']=="0")?' ':$row['recurdesc'];
if($row['deadline']) {
$deadline=prettyDueDate($row['deadline'],$row['daysdue']);
$rowout['deadline'] =$deadline['date'];
$rowout['deadline.class']=$deadline['class'];
$rowout['deadline.title']=$deadline['title'];
} else $rowout['deadline']='';
$rowout['title']=$row['title'];
$rowout['title.title']='Edit';
$rowout['ptitle']=$row['ptitle'];
$rowout['parentId']=$row['parentId'];
if ($row['parentId']=='') $rowout['parent.class']='noparent';
$rowout['checkboxname']='isMarked[]';
$rowout['checkbox.title']='Mark as complete';
$rowout['checkboxvalue']=$row['itemId'];
$rowout['NA'] = $row['nextaction']==='y';
return $rowout;
}
function makeContextTable($maintable,$dispArray,$show,$trimlength) {
@ob_start();
require 'displayItems.inc.php';
$out=ob_get_contents();
ob_end_clean();
return $out;
}
$values=array();
//SQL CODE AREA
//obtain all contexts
$contextResults = query("getspacecontexts",$values);
$contextNames=array(0=>'none');
if ($contextResults)
foreach ($contextResults as $row)
$contextNames[(int) $row['contextId']]=$row['name'];
//obtain all timeframes
$values['type']='a';
$values['timefilterquery'] = ($_SESSION['config']['useTypesForTimeContexts'])?" WHERE ".sqlparts("timetype",$values):'';
$timeframeResults = query("gettimecontexts",$values);
$timeframeNames=array(0=>'none');
$timeframeDesc=array(0=>'none');
if ($timeframeResults) foreach($timeframeResults as $row) {
$timeframeNames[(int) $row['timeframeId']]=$row['timeframe'];
$timeframeDesc[(int) $row['timeframeId']]=$row['description'];
}
$values['extravarsfilterquery'] ='';
$dispArray=array('parent'=>'Project'
,'NA'=>'NA'
,'title'=>'Action'
,'description'=>'Description'
,'deadline'=>'Deadline'
,'recurdesc'=>'Repeat'
,'checkbox'=>'Complete');
$show=array();
foreach ($dispArray as $key=>$val) $show[$key]=true;
$wasNAonEntry=array();
$trimlength=$_SESSION['config']['trimLength'];
$values['type'] = "a";
$values['isSomeday'] = "n";
$values['childfilterquery'] = " WHERE ".sqlparts("typefilter",$values)
." AND ".sqlparts("activeitems",$values)
." AND ".sqlparts("issomeday",$values)
." AND ".sqlparts("pendingitems",$values);
if ($_SESSION['config']["contextsummary"])
$values['childfilterquery'] .= ' AND '.sqlparts('isNAonly',$values);
$values['filterquery'] =' WHERE '.sqlparts("liveparents",$values);;
$tstsort=array('getitemsandparent'=>'cname ASC,timeframeId ASC,'.$_SESSION['sort']['getitemsandparent']);
$result = query("getitemsandparent",$values,$tstsort);
$grandtot=count($result);
$index=0;
$lostitems=array();
//Item listings by context and timeframe
foreach ($contextNames as $cid=>$dummy1) {
foreach ($timeframeNames as $tid=>$dummy2) {
$maintable=array();
$wasNAonEntry[$cid][$tid]=array();
while ($index<$grandtot
&& ( !array_key_exists((int) $result[$index]['contextId'],$contextNames)
|| !array_key_exists((int) $result[$index]['timeframeId'],$timeframeNames))) {
array_push($lostitems,$result[$index++]);
}
while ($index<$grandtot &&
(int) $result[$index]['contextId']===$cid &&
(int) $result[$index]['timeframeId']===$tid ) {
$row=$result[$index];
if ($row['nextaction']==='y') array_push($wasNAonEntry[$cid][$tid],$row['itemId']);
array_push($maintable,makeContextRow($row));
$index++;
}
$matrixcount[$cid][$tid]=count($maintable);
if (count($maintable))
$matrixout[$cid][$tid]=makeContextTable($maintable,$dispArray,$show,$trimlength);
}
}
$_SESSION['lastfilterp']=$_SESSION['lastfiltera']="{$pagename}.php";
if (count($lostitems)) {
$cid='-1';
$tid=0;
$wasNAonEntry[$cid][$tid]=array();
foreach ($timeframeNames as $thistid=>$dummy2) $matrixcount[$cid][$thistid]=0;
$contextNames[$cid]="ERROR: Failed to find context";
$maintable=array();
$dispArray['spatialcontext']='Context Id';
$dispArray['timeframe']='Timeframe Id';
$show['spatialcontext']=true;
$show['timeframe']=true;
foreach ($lostitems as $row) {
$rowout=makeContextRow($row);
$thisCname=(array_key_exists($row['contextId'],$contextNames))
? $contextNames[$row['contextId']]
: 'ERROR unknown space context id='.$row['contextId'];
$thisTname=(array_key_exists($row['timeframeId'],$timeframeNames))
? $timeframeNames[$row['timeframeId']]
: 'ERROR unknown time context id='.$row['timeframeId'];
$rowout['spatialcontext'] =$thisCname;
$rowout['spatialcontextId'] =$row['contextId'];
$rowout['timeframe'] =$thisTname;
$rowout['timeframeId'] =$row['timeframeId'];
array_push($maintable,$rowout);
if ($rowout['NA']) array_push($wasNAonEntry[$cid][$tid],$row['itemId']);
}
$matrixcount[$cid][$tid]=count($maintable);
$matrixout[$cid][$tid]=makeContextTable($maintable,$dispArray,$show,$trimlength);
}
// php closing tag has been omitted deliberately, to avoid unwanted blank lines being sent to the browser