-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat_day.php
executable file
·240 lines (216 loc) · 9.28 KB
/
stat_day.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
<?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_day.php
* DESCRIPTION : Day to day 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
$UserFirstDay = putslashes($_POST['first_day']);
$UserFirstMonth = putslashes($_POST['first_month']);
$UserFirstYear = putslashes($_POST['first_year']);
$UserLastDay = putslashes($_POST['last_day']);
$UserLastMonth = putslashes($_POST['last_month']);
$UserLastYear = putslashes($_POST['last_year']);
// Get the current day, month and year
$CurrentDay = date("j");
$CurrentMonth = date("n");
$CurrentYear = date("Y");
// If the user did not specified any input values
if (($UserFirstDay == NULL) || ($UserFirstMonth == NULL) || ($UserFirstYear == NULL) || ($UserLastDay == NULL) || ($UserLastMonth == NULL) || ($UserLastYear == NULL))
{
// Use the current date instead
$UserFirstDay = $CurrentDay;
$UserFirstMonth = $CurrentMonth;
$UserFirstYear = $CurrentYear;
$UserLastDay = $CurrentDay;
$UserLastMonth = $CurrentMonth;
$UserLastYear = $CurrentYear;
}
// TODO : Test parameters validity (first < last, ...)
// Get the given first and last days
$FirstDay = mktime( 0, 0, 1, $UserFirstMonth, $UserFirstDay, $UserFirstYear);
$LastDay = mktime(23, 59, 59, $UserLastMonth, $UserLastDay, $UserLastYear);
ShowSecureHeader("Day to day Statistics", "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
echo "
<FORM ACTION='stat_day.php' METHOD='POST' NAME='stat_day'>
<BR/><BR/>
<TABLE BORDER='0'>
<TR>
<TD ALIGN='RIGHT'>
<B> First Day :</B>
</TD>
<TD>
<TABLE>
<TR>
<TD>
<INPUT TYPE='TEXT' NAME='first_day' SIZE='2' MAXLENGTH ='2' VALUE='".htmlentities(sprintf("%02d", $UserFirstDay))."'>
</TD>
<TD>
/
</TD>
<TD>
<INPUT TYPE='TEXT' NAME='first_month' SIZE='2' MAXLENGTH ='2' VALUE='".htmlentities(sprintf("%02d", $UserFirstMonth))."'>
</TD>
<TD>
/
</TD>
<TD>
<INPUT TYPE='TEXT' NAME='first_year' SIZE='4' MAXLENGTH ='4' VALUE='".htmlentities(sprintf("%04d", $UserFirstYear))."'>
</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD ALIGN='RIGHT'>
<B> Last Day :</B>
</TD>
<TD>
<TABLE>
<TR>
<TD>
<INPUT TYPE='TEXT' NAME='last_day' SIZE='2' MAXLENGTH ='2' VALUE='".htmlentities(sprintf("%02d", $UserLastDay))."'>
</TD>
<TD>
/
</TD>
<TD>
<INPUT TYPE='TEXT' NAME='last_month' SIZE='2' MAXLENGTH ='2' VALUE='".htmlentities(sprintf("%02d", $UserLastMonth))."'>
</TD>
<TD>
/
</TD>
<TD>
<INPUT TYPE='TEXT' NAME='last_year' SIZE='4' MAXLENGTH ='4' VALUE='".htmlentities(sprintf("%04d", $UserLastYear))."'>
</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD ALIGN='CENTER' COLSPAN='2'>
<INPUT TYPE='SUBMIT' NAME='stat' VALUE='Stat'>
</TD>
</TR>
</TABLE>
</FORM>
";
$TotalTime = GetSubProjectsCumulativeTime($_SESSION['uid'], 0, $FirstDay, $LastDay);
echo "The given period 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'
AND beginning > FROM_UNIXTIME('$FirstDay')
AND beginning < FROM_UNIXTIME('$LastDay')
";
}
$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();
?>