1 |
<?php |
2 |
// Load globals |
3 |
require_once ("global_vars.php"); |
4 |
|
5 |
// Includes |
6 |
require_once ($GLOBAL_ADMIN_INC."sessionClass.php"); |
7 |
require_once ($GLOBAL_ADMIN_INC."accessClass.php"); |
8 |
require_once ($GLOBAL_ADMIN_INC."db_connect.php"); |
9 |
require_once ($GLOBAL_ADMIN_INC."app_controls.php"); |
10 |
|
11 |
|
12 |
// HTML header |
13 |
printf("<HTML>\n"); |
14 |
printf("<HEAD>\n"); |
15 |
printf("<title>RQS Subject Statistics</title>\n"); |
16 |
printf("<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\">\n", $GLOBAL_ADMIN_CSS); |
17 |
printf("</HEAD>\n"); |
18 |
|
19 |
|
20 |
// Page header |
21 |
require_once ($GLOBAL_ADMIN_HEADER); |
22 |
|
23 |
|
24 |
// Collect access information |
25 |
if (isset($libsession)) { |
26 |
|
27 |
// Fetch session information |
28 |
$sessionClass = new sessionClass("", $libsession, "", ""); |
29 |
$accessClass = new accessClass($sessionClass); |
30 |
|
31 |
// Load user session variables |
32 |
$sess_time_human = $sessionClass->time_human; |
33 |
$sess_staff_account = $sessionClass->staff_account; |
34 |
$sess_access_level = $accessClass->access_level; |
35 |
$sess_access = $accessClass->access; |
36 |
$sess_last_name = $accessClass->last_name; |
37 |
$sess_first_name = $accessClass->first_name; |
38 |
|
39 |
} |
40 |
|
41 |
// If the cookie is set and access level is appropriate |
42 |
if(isset($libsession) && $sess_access_level >= 20) { |
43 |
|
44 |
// Array of months |
45 |
$month_array = Array("0", "January", "February", "March", "April", "May", "June", |
46 |
"July", "August", "September", "October", "November", "December"); |
47 |
|
48 |
// Fetch today's date |
49 |
$today = getdate(); |
50 |
$mon = $today[mon]; |
51 |
$mday = $today[mday]; |
52 |
$year = $today[year]; |
53 |
|
54 |
|
55 |
// Back-fill in case we have single-digits. |
56 |
if (strlen($mday) < 2) $mday = "0" . $mday; |
57 |
if (strlen($mon) < 2) $mon = "0" . $mon; |
58 |
|
59 |
|
60 |
// Generate a mySQL-friendly datetime for today's stamp |
61 |
$today_stamp = $year . "-" . $mon . "-" . $mday; |
62 |
|
63 |
|
64 |
// Outer table & header row |
65 |
printf("<center>\n"); |
66 |
|
67 |
|
68 |
printf("<span class=\"bigDark\">Research QuickStart Subject Page Load Statistics</span><br><br>\n"); |
69 |
|
70 |
printf("<table width=\"95%%\" class=\"backLight\" border =\"1\">\n"); |
71 |
printf("<tr><td colspan=\"2\" class=\"cellPlain\">\n"); |
72 |
printf("Dates"); |
73 |
printf("</td></tr>\n"); |
74 |
|
75 |
// Basic information |
76 |
printf("<tr><td width=\"35%%\" valign=\"middle\" >\n"); |
77 |
printf("<b>Today's Date:</b> %s<BR>\n", $today_stamp); |
78 |
|
79 |
$sql = "SELECT MIN(visit_date) as min_date, MAX(visit_date) as max_date |
80 |
FROM libstats.substats"; |
81 |
$rs = mysql_query($sql, $con); |
82 |
$row = mysql_fetch_array ($rs); |
83 |
$min_date = $row["min_date"]; |
84 |
$max_date = $row["max_date"]; |
85 |
|
86 |
printf("<b>Earliest page load:</b> %s<BR>\n", $min_date); |
87 |
printf("<b>Most recent page load:</b> %s<BR><br>\n", $max_date); |
88 |
printf("</td>\n"); |
89 |
|
90 |
// Determine whether there are any incoming start/end limits. |
91 |
// If not, use today's date as the start and end date. |
92 |
if (strlen($start_year) < 1) $start_year = $year; |
93 |
if (strlen($start_month) < 1) $start_month = $mon; |
94 |
if (strlen($start_day) < 1) $start_day = $mday; |
95 |
|
96 |
|
97 |
// Determine whether there are any incoming end limits. |
98 |
// If not, use today's date as the end date. |
99 |
if (strlen($end_year) < 1) $end_year = $year; |
100 |
if (strlen($end_month) < 1) $end_month = $mon; |
101 |
if (strlen($end_day) < 1) $end_day = $mday; |
102 |
|
103 |
|
104 |
// Generate mySQL-friendly date-time based on current settings |
105 |
// Back-fill in case we have single-digits. |
106 |
if (strlen($start_year) < 1) $start_year = $year; |
107 |
if (strlen($start_month) < 2) $start_month = "0" . $start_month; |
108 |
if (strlen($start_day) < 2) $start_day = "0" . $start_day; |
109 |
|
110 |
|
111 |
if (strlen($end_year) < 1) $end_year = $year; |
112 |
if (strlen($end_month) < 2) $end_month = "0" . $end_month; |
113 |
if (strlen($end_day) < 2) $end_day = "0" . $end_day; |
114 |
|
115 |
|
116 |
|
117 |
// Generate high/low datetime stamps for SQL. |
118 |
$start_stamp = $start_year . "-" . $start_month . "-" . $start_day; |
119 |
$end_stamp = $end_year . "-" . $end_month . "-" . $end_day . " 23:59:59"; |
120 |
|
121 |
|
122 |
/******************** |
123 |
** Date range form ** |
124 |
********************/ |
125 |
|
126 |
printf("<td>\n"); |
127 |
printf("<b>Limit by date or range:</b><BR><BR>\n"); |
128 |
printf("<table border=\"0\">\n"); |
129 |
printf("<tr>\n"); |
130 |
printf("<form method =\"post\" action=\"subject_stats.phtml\">\n"); |
131 |
|
132 |
|
133 |
// Start parameters |
134 |
|
135 |
|
136 |
// Start month |
137 |
printf("<td><b>Start Date:</b></td>"); |
138 |
printf("<td><select name=\"start_month\">\n"); |
139 |
for ($count = 1; $count < 13; $count++) { |
140 |
// Pad 0-9 with a 0. |
141 |
if ($count < 10) $count_value = "0" . $count; |
142 |
else $count_value = $count; |
143 |
printf("<option value=\"%s\"", $count); |
144 |
if ($count == $start_month) printf(" SELECTED "); |
145 |
printf(">%s</option>\n", $month_array[$count]); |
146 |
} |
147 |
|
148 |
printf("</select> "); |
149 |
|
150 |
|
151 |
// Start day |
152 |
printf("<select name=\"start_day\">\n"); |
153 |
for ($count = 1; $count < 32; $count++) { |
154 |
// Pad 0-9 with a 0. |
155 |
if ($count < 10) $count_value = "0" . $count; |
156 |
else $count_value = $count; |
157 |
printf("<option value=\"%s\"", $count); |
158 |
if ($count == $start_day) printf(" SELECTED "); |
159 |
printf(">%s</option>\n", $count_value); |
160 |
} |
161 |
|
162 |
printf("</select> "); |
163 |
|
164 |
// Start year -- allow previous three years as well |
165 |
$year_value = $year - 3; |
166 |
printf("<select name=\"start_year\">\n"); |
167 |
for ($count = 1; $count < 5; $count++) { |
168 |
printf("<option value=\"%s\"", $year_value); |
169 |
if ($year_value == $start_year) printf(" SELECTED "); |
170 |
printf(">%s</option>\n", $year_value); |
171 |
$year_value++; |
172 |
} |
173 |
|
174 |
printf("</select>\n"); |
175 |
printf("</td>\n"); |
176 |
|
177 |
// Blank cell |
178 |
printf("<td> </td>\n"); |
179 |
printf("</tr>\n"); |
180 |
|
181 |
|
182 |
// End parameters |
183 |
|
184 |
|
185 |
// End month |
186 |
printf("<tr>\n"); |
187 |
printf("<td><b>End Date:</b></td>"); |
188 |
printf("<td><select name=\"end_month\">\n"); |
189 |
for ($count = 1; $count < 13; $count++) { |
190 |
// Pad 0-9 with a 0. |
191 |
if ($count < 10) $count_value = "0" . $count; |
192 |
else $count_value = $count; |
193 |
|
194 |
printf("<option value=\"%s\"", $count_value); |
195 |
if ($count_value == $end_month) printf(" SELECTED "); |
196 |
printf(">%s</option>\n", $month_array[$count]); |
197 |
} |
198 |
|
199 |
printf("</select> "); |
200 |
|
201 |
|
202 |
// End day |
203 |
printf("<select name=\"end_day\">\n"); |
204 |
for ($count = 1; $count < 32; $count++) { |
205 |
// Pad 0-9 with a 0. |
206 |
if ($count < 10) $count_value = "0" . $count; |
207 |
else $count_value = $count; |
208 |
|
209 |
printf("<option value=\"%s\"", $count_value); |
210 |
if ($count_value == $end_day) printf(" SELECTED "); |
211 |
printf(">%s</option>\n", $count_value); |
212 |
} |
213 |
|
214 |
printf("</select> "); |
215 |
|
216 |
// End year -- allow previous three years as well |
217 |
$year_value = $year - 3; |
218 |
printf("<select name=\"end_year\">\n"); |
219 |
for ($count = 1; $count < 5; $count++) { |
220 |
printf("<option value=\"%s\"", $year_value); |
221 |
if ($year_value == $end_year) printf(" SELECTED "); |
222 |
printf(">%s</option>\n", $year_value); |
223 |
$year_value++; |
224 |
} |
225 |
|
226 |
printf("</select>\n"); |
227 |
printf("</td>\n"); |
228 |
printf("<td align = \"center\" ><input type=\"submit\" value=\"Limit By Dates\"></td>\n"); |
229 |
printf("</tr>\n"); |
230 |
printf("</form>"); |
231 |
printf("</table>\n"); |
232 |
|
233 |
|
234 |
// Outer table |
235 |
printf("</td></tr></table>\n"); |
236 |
printf("<BR>\n"); |
237 |
|
238 |
|
239 |
/********************* |
240 |
** PageScribe Pages ** |
241 |
*********************/ |
242 |
|
243 |
|
244 |
printf("<span class=\"bigDark\">Research QuickStart Subjects</span><br><br>\n"); |
245 |
|
246 |
// Table and header row |
247 |
printf("<table width=\"95%%\" border=\"1\">\n"); |
248 |
printf("<tr>\n"); |
249 |
printf("<td class=\"cellPlain\" width=\"10%%\">Subject ID</td>\n"); |
250 |
printf("<td class=\"cellPlain\" width=\"70%%\">Subject</td>\n"); |
251 |
printf("<td class=\"cellPlain\" align=\"center\" width=\"20%%\">RQS Subject Loads</td>\n"); |
252 |
printf("</tr>\n"); |
253 |
|
254 |
|
255 |
$sql = "SELECT |
256 |
s.subject_id, |
257 |
s.subject |
258 |
FROM subject s |
259 |
WHERE s.subject_id > 1 |
260 |
ORDER BY s.subject"; |
261 |
|
262 |
$rs = mysql_query($sql, $con); |
263 |
|
264 |
// Initialize |
265 |
$rowcount = 0; |
266 |
$sub_loads_total = 0; |
267 |
|
268 |
while ($row = mysql_fetch_array ($rs)) { |
269 |
|
270 |
// Fetch the stuff |
271 |
$subject_id = $row["subject_id"]; |
272 |
$subject = Trim($row["subject"]); |
273 |
// $date_created = substr($row["date_created"], 0, 10); |
274 |
// $date_modified = substr($row["date_modified"], 0, 10); |
275 |
|
276 |
// Pull out any HTML |
277 |
$subject = strip_tags($subject); |
278 |
|
279 |
// New row |
280 |
if ($rowcount % 2 == 0) $color = " class=\"backLight\" "; |
281 |
else $color = ""; |
282 |
|
283 |
printf("<tr>\n"); |
284 |
printf("<td %s>%d</td>\n", $color, $subject_id); |
285 |
printf("<td %s>%s</td>\n", $color, $subject); |
286 |
|
287 |
|
288 |
// Pull out the page load stats for this page |
289 |
$stats_sql = "SELECT COUNT(*) as sub_loads |
290 |
FROM libstats.substats |
291 |
WHERE subject_id = " |
292 |
. $subject_id |
293 |
. " AND visit_date >= '" |
294 |
. $start_stamp |
295 |
. "' AND visit_date <= '" |
296 |
. $end_stamp |
297 |
. "'"; |
298 |
$stats_rs = mysql_query($stats_sql, $con); |
299 |
$stats_row = mysql_fetch_array ($stats_rs); |
300 |
$sub_loads = $stats_row["sub_loads"]; |
301 |
|
302 |
printf("<td align=\"center\" %s>%d</td>\n", $color, $sub_loads); |
303 |
|
304 |
// Encode the date limits |
305 |
$start = urlencode($start_stamp); |
306 |
$end = urlencode($end_stamp); |
307 |
|
308 |
// Close row |
309 |
printf("</tr>\n"); |
310 |
|
311 |
// Increment |
312 |
$rowcount++; |
313 |
$sub_loads_total = $sub_loads_total + $sub_loads; |
314 |
|
315 |
} |
316 |
|
317 |
// Summary row |
318 |
printf("<tr><td colspan=\"2\"> </td>\n"); |
319 |
printf("<td class=\"backLight\"><b>Total:</b> %d</td>\n", $sub_loads_total); |
320 |
|
321 |
printf("</table><br>\n"); |
322 |
|
323 |
|
324 |
// Link to return to admin console |
325 |
adminReturn($sess_access_level); |
326 |
|
327 |
|
328 |
printf("</center>\n"); |
329 |
|
330 |
|
331 |
} // logged in user |
332 |
|
333 |
// No access page |
334 |
else require_once ($GLOBAL_NO_ACCESS); |
335 |
|
336 |
|
337 |
// Page footer |
338 |
require_once ($GLOBAL_ADMIN_FOOTER); |
339 |
?> |
340 |
|
341 |
</body> |
342 |
</html> |