-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat_month.php
executable file
·251 lines (224 loc) · 9.46 KB
/
stat_month.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
<?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_month.php
* DESCRIPTION : Monthly 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 month and the year to stat
$UserMonth = putslashes($_POST['month']);
$UserYear = putslashes($_POST['year']);
// Get the current week and year
$CurrentMonth = date("m");
$CurrentYear = date("Y");
// If the user specified a month and a year
if (($UserMonth != NULL) && ($UserYear != NULL))
{
$CurrentMonth = $UserMonth;
$CurrentYear = $UserYear;
}
// Test parameters validity
if ($CurrentYear == 0)
{
$_SESSION['message'] = "The year parameter is missing. <BR> Please try again. <BR>";
header("Location: stat.php");
exit();
}
else if (($CurrentMonth < 1) || ($CurrentMonth > 12))
{
$_SESSION['message'] = "The month parameter is missing or seems wrong. <BR> Please try again. <BR>";
header("Location: stat.php");
exit();
}
$PreviousMonth = ($CurrentMonth == 1 ? 12 : $CurrentMonth - 1);
$PreviousYear = ($PreviousMonth > $CurrentMonth ? $CurrentYear - 1: $CurrentYear);
$NextMonth = ($CurrentMonth == 12 ? 1 : $CurrentMonth + 1);
$NextYear = ($NextMonth < $CurrentMonth ? $CurrentYear + 1: $CurrentYear);
$Period = GetMonthPeriod($CurrentMonth, $CurrentYear);
$FirstDay = $Period['start'];
$LastDay = $Period['end'];
ShowSecureHeader("Monthly Statistics", "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
echo "
<BR/><BR/>
<TABLE BORDER='0'>
<TR>
<TD ALIGN='RIGHT'>
<B> Month :</B>
</TD>
<TD>
<TABLE>
<TR>
<FORM ACTION='stat_month.php' METHOD='POST' NAME='previous_stat_month'>
<TD>
<INPUT TYPE='HIDDEN' NAME='month' SIZE='2' MAXLENGTH ='2' VALUE='".htmlentities(sprintf("%02d", $PreviousMonth))."'>
<INPUT TYPE='HIDDEN' NAME='year' SIZE='4' MAXLENGTH ='4' VALUE='".htmlentities(sprintf("%04d", $PreviousYear))."'>
<INPUT TYPE='SUBMIT' NAME='stat' VALUE='<'>
</TD>
</FORM>
<FORM ACTION='stat_month.php' METHOD='POST' NAME='stat_month'>
<TD>
<INPUT TYPE='TEXT' NAME='month' SIZE='2' MAXLENGTH ='2' VALUE='".htmlentities(sprintf("%02d", $CurrentMonth))."'>
</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>
</FORM>
<FORM ACTION='stat_month.php' METHOD='POST' NAME='next_stat_month'>
<TD>
<INPUT TYPE='HIDDEN' NAME='month' SIZE='2' MAXLENGTH ='2' VALUE='".htmlentities(sprintf("%02d", $NextMonth))."'>
<INPUT TYPE='HIDDEN' NAME='year' SIZE='4' MAXLENGTH ='4' VALUE='".htmlentities(sprintf("%04d", $NextYear))."'>
<INPUT TYPE='SUBMIT' NAME='stat' VALUE='>'>
</TD>
</FORM>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
";
$TotalTime = GetSubProjectsCumulativeTime($_SESSION['uid'], 0, $FirstDay, $LastDay);
echo "The given month 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 < $CurrentMonth) && ($CurrentMonth < 13))
{
$SQL .= "AND MONTH(beginning) = '$CurrentMonth'
";
}
else
{
$_SESSION['message'] = "The month parameter is missing or seems wrong. <BR> Please try again. <BR>";
header("Location: stat_month.php");
break;
}
}
else
{
$_SESSION['message'] = "The year parameter is missing. <BR> Please try again. <BR>";
header("Location: stat_month.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();
?>