-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat_week.php
executable file
·329 lines (290 loc) · 11 KB
/
stat_week.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
<?PHP
/*
*******************************************************************************
* Chronologist - web-based time tracking database
* Copyright (C) 2003 by Sylvain LAFRASSE.
*******************************************************************************
* LICENSE:
* This file is part of Chronologist.
*
* Chronologist is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Chronologist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Chronologist; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*******************************************************************************
* FILE NAME : stat_week.php
* DESCRIPTION : Weekly statistics form and script.
* AUTHORS : Sylvain LAFRASSE.
*******************************************************************************
*/
require_once("design.inc.php");
require_once("task.inc.php");
require_once("project.inc.php");
require_once("stat.inc.php");
// Retrieve the the week, the year and the week part to stat
$UserWeek = putslashes($_POST['week']);
$UserYear = putslashes($_POST['year']);
$UserWeekPart = putslashes($_POST['week_part']);
// Get the current week and year
$CurrentWeek = date("W");
$CurrentYear = date("Y");
$CurrentWeekPart = "whole";
// If the user specified a week and a year
if (($UserWeek != NULL) && ($UserYear != NULL))
{
// Use the given parameters instead of the default ones
$CurrentWeek = $UserWeek;
$CurrentYear = $UserYear;
$CurrentWeekPart = $UserWeekPart;
}
// Test parameters validity
if ($CurrentYear == 0)
{
$_SESSION['message'] = "The year parameter is missing. <BR> Please try again. <BR>";
header("Location: stat.php");
break;
}
else if (($CurrentWeek < 1) || ($CurrentWeek > 53))
{
$_SESSION['message'] = "The week parameter is missing or seems wrong. <BR> Please try again. <BR>";
header("Location: stat.php");
break;
}
// TODO : check CurrentWeekPart in {beginning, whole, end}
// Get the given week start and end dates
//$WeekPeriod = GetWeekPeriod($CurrentWeek, $CurrentYear);
//$WeekPeriod = get_lundi_dimanche_from_week($CurrentWeek, $CurrentYear);
$WeekPeriod = MyWeek($CurrentWeek, $CurrentYear);
$FirstDay = $WeekPeriod['start'];
$LastDay = $WeekPeriod['end'];
// If the given week runs over 2 different monthes
$BeginningMonth = date("m", $WeekPeriod['start']);
$EndMonth = date("m", $WeekPeriod['end']);
if ($BeginningMonth != $EndMonth)
{
// Get the week's beginning month period to retrieve the month's last day date
$BeginningMonthPeriod = GetMonthPeriod($BeginningMonth, $CurrentYear);
$BeginningMonthLastDay = $BeginningMonthPeriod['end'];
// Get the week's end month period to retrieve the month's first day date
$EndMonthPeriod = GetMonthPeriod($EndMonth, $CurrentYear);
$EndMonthFirstDay = $EndMonthPeriod['start'];
// According to user choice
switch ($CurrentWeekPart)
{
// week first part, running from given week first day to beginning month last day
case "beginning":
$LastDay = $BeginningMonthLastDay;
break;
// whole week, running from given week first day to the given week last day
case "whole":
break;
// week last part, running from the end month first day to the given week last day
case "end":
$FirstDay = $EndMonthFirstDay;
break;
default:
$_SESSION['message'] = "Assertion failed: wrong week part selected. <BR> Please try again. <BR>";
header("Location: stat.php");
break;
}
}
ShowSecureHeader("Weekly Statistics", "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
echo "
<FORM ACTION='stat_week.php' METHOD='POST' NAME='stat_week'>
<BR/><BR/>
<TABLE BORDER='0'>
<TR>
<TD ALIGN='RIGHT'>
<B> Week :</B>
</TD>
<TD>
<TABLE>
<TR>
<TD>
<INPUT TYPE='TEXT' NAME='week' SIZE='2' MAXLENGTH ='2' VALUE='".htmlentities(sprintf("%02d", $CurrentWeek))."'>
</TD>
<TD>
/
</TD>
<TD>
<INPUT TYPE='TEXT' NAME='year' SIZE='4' MAXLENGTH ='4' VALUE='".htmlentities(sprintf("%04d", $CurrentYear))."'>
</TD>
<TD>
<INPUT TYPE='SUBMIT' NAME='stat' VALUE='Stat'>
</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD ALIGN='RIGHT'>
<B> Week beginning :</B>
</TD>
<TD>
<INPUT TYPE='RADIO' VALUE='beginning' NAME='week_part'";
// If the given week part is the 'beginnig' one
if ($CurrentWeekPart == "beginning")
{
// Chect it
echo " CHECKED";
}
echo ">
</TD>
</TR>
<TR>
<TD ALIGN='RIGHT'>
<B> Whole week :</B>
</TD>
<TD>
<INPUT TYPE='RADIO' VALUE='whole' NAME='week_part'";
// If the given week part is the 'whole' one
if ($CurrentWeekPart == "whole")
{
// Chect it
echo " CHECKED";
}
echo ">
</TD>
</TR>
<TR>
<TD ALIGN='RIGHT'>
<B> Week end :</B>
</TD>
<TD>
<INPUT TYPE='RADIO' VALUE='end' NAME='week_part'";
// If the given week part is the 'end' one
if ($CurrentWeekPart == "end")
{
// Chect it
echo " CHECKED";
}
echo ">
</TD>
</TR>
</TABLE>
</FORM>
";
$TotalTime = GetSubProjectsCumulativeTime($_SESSION['uid'], 0, $FirstDay, $LastDay);
echo "The given week starts on ".GetFormattedDate($FirstDay)." and ends on ".GetFormattedDate($LastDay)."
<BR/> <BR/> <B> Total : </B> ".htmlentities(DurationLabel($TotalTime))." <BR/> <BR/>";
if ($TotalTime != 0)
{
echo "
<TABLE BORDER='1'>
<TR ALIGN='CENTER'>
<TD>
<B> Project </B>
</TD>
<TD>
<B> Duration </B>
</TD>
<TD>
<B> Cumulative </B>
</TD>
<TD>
<B> Percentage </B>
</TD>
</TR>
";
// Gets all the projects from the database
// TODO : handle manager type user to return all their managed projects
$Array = GetSubProjects();
foreach($Array as $PID => $ProjectLabel)
{
if (ConnectedUserBelongsToAdminGroup() == TRUE) // If an administrator is logged
{
// Gets all the projects duration from the database
$SQL = "SELECT SUM(duration) as length
FROM `tasks`
AND pid = '$PID'
";
}
else if (ConnectedUserBelongsToManagerGroup() == TRUE) // If a manager is logged
{
// TODO : Only show the managed project duration
// Gets all the projects duration from the database
/*
$SQL = "SELECT pid, label, SUM(duration) as length
FROM `tasks`
GROUP BY `pid`
ORDER BY label
";
*/
}
else // If a user is logged
{
// Gets the user projects duration from the database
$SQL = "SELECT SUM(duration) as length
FROM `tasks`
WHERE uid = '$_SESSION[uid]'
AND pid = '$PID'
";
if ($CurrentYear != 0)
{
$SQL .= "AND YEAR(beginning) = '$CurrentYear'
";
if ((0 < $CurrentWeek) && ($CurrentWeek < 54))
{
$SQL .= "AND WEEK(beginning) = '$CurrentWeek'
";
}
else
{
$_SESSION['message'] = "The week parameter is missing or seems wrong. <BR> Please try again. <BR>";
header("Location: stat.php");
break;
}
}
else
{
$_SESSION['message'] = "The year parameter is missing. <BR> Please try again. <BR>";
header("Location: stat.php");
break;
}
}
$Result = mysqli_query($Connection, $SQL)
or die("Could not execute the '$SQL' request.");
// For each projects
while ($Row = mysqli_fetch_array($Result))
{
// Displays its label and total duration
$Duration = $Row['length'];
$Cumulative = $Duration + GetSubProjectsCumulativeTime($_SESSION['uid'], $PID, $FirstDay, $LastDay);
if ($Cumulative != 0)
{
$Percentage = round((($Cumulative / $TotalTime) * 100), 2);
echo "
<TR>
<TD ALIGN='LEFT'>
".htmlentities($ProjectLabel)."
</TD>
<TD>
".htmlentities(DurationLabel($Duration))."
</TD>
<TD>
".htmlentities(DurationLabel($Cumulative))."
</TD>
<TD>
".htmlentities($Percentage)."%
</TD>
</TR>
";
}
}
mysqli_free_result($Result);
}
echo "
</TABLE>
";
}
ShowFooter();
?>