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 ("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>CLPS Statistics</title>\n"); |
16 |
printf("<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\">\n", $GLOBAL_ADMIN_CSS); |
17 |
printf("</HEAD>\n"); |
18 |
|
19 |
|
20 |
// Default access settings |
21 |
$sess_time_human = ""; |
22 |
$sess_staff_account = ""; |
23 |
$sess_staff_id = 0; |
24 |
$sess_access_level = 0; |
25 |
$sess_access = ""; |
26 |
$sess_last_name = ""; |
27 |
$sess_first_name = ""; |
28 |
|
29 |
|
30 |
// Page header |
31 |
require_once ($GLOBAL_ADMIN_HEADER); |
32 |
|
33 |
|
34 |
// Collect access information |
35 |
if (isset($libsession)) { |
36 |
|
37 |
// Fetch session information |
38 |
$sessionClass = new sessionClass("", $libsession, "", ""); |
39 |
$accessClass = new accessClass($sessionClass); |
40 |
|
41 |
// Load user session variables |
42 |
$sess_time_human = $sessionClass->time_human; |
43 |
$sess_staff_account = $sessionClass->staff_account; |
44 |
$sess_access_level = $accessClass->access_level; |
45 |
$sess_access = $accessClass->access; |
46 |
$sess_last_name = $accessClass->last_name; |
47 |
$sess_first_name = $accessClass->first_name; |
48 |
|
49 |
} |
50 |
|
51 |
// If the cookie is set and access level is appropriate |
52 |
if(isset($libsession) && $sess_access_level >= 20) { |
53 |
|
54 |
// Array of months |
55 |
$month_array = Array("0", "January", "February", "March", "April", "May", "June", |
56 |
"July", "August", "September", "October", "November", "December"); |
57 |
|
58 |
// Fetch today's date |
59 |
$today = getdate(); |
60 |
$mon = $today[mon]; |
61 |
$mday = $today[mday]; |
62 |
$year = $today[year]; |
63 |
|
64 |
|
65 |
// Back-fill in case we have single-digits. |
66 |
if (strlen($mday) < 2) $mday = "0" . $mday; |
67 |
if (strlen($mon) < 2) $mon = "0" . $mon; |
68 |
|
69 |
|
70 |
// Generate a mySQL-friendly datetime for today's stamp |
71 |
$today_stamp = $year . "-" . $mon . "-" . $mday; |
72 |
|
73 |
|
74 |
// Outer table & header row |
75 |
printf("<center>\n"); |
76 |
|
77 |
|
78 |
printf("<span class=\"bigDark\">Statistics Summary</span><br><br>\n"); |
79 |
|
80 |
printf("<table width=\"95%%\" class=\"backLight\" border =\"1\">\n"); |
81 |
printf("<tr><td colspan=\"2\" class=\"cellPlain\">\n"); |
82 |
printf("Dates"); |
83 |
printf("</td></tr>\n"); |
84 |
|
85 |
// Basic information |
86 |
printf("<tr><td width=\"35%%\" valign=\"middle\" >\n"); |
87 |
printf("<b>Today's Date:</b> %s<BR>\n", $today_stamp); |
88 |
|
89 |
$sql = "SELECT MIN(visit_date) as min_date, MAX(visit_date) as max_date |
90 |
FROM libstats.pagestats"; |
91 |
$rs = xx_tryquery($sql); |
92 |
$row = xx_fetch_array ($rs, xx_ASSOC); |
93 |
$min_date = $row["min_date"]; |
94 |
$max_date = $row["max_date"]; |
95 |
|
96 |
printf("<b>Earliest page load:</b> %s<BR>\n", $min_date); |
97 |
printf("<b>Most recent page load:</b> %s<BR><br>\n", $max_date); |
98 |
printf("</td>\n"); |
99 |
|
100 |
// Determine whether there are any incoming start/end limits. |
101 |
// If not, use today's date as the start and end date. |
102 |
if (strlen($start_year) < 1) $start_year = $year; |
103 |
if (strlen($start_month) < 1) $start_month = $mon; |
104 |
if (strlen($start_day) < 1) $start_day = $mday; |
105 |
|
106 |
|
107 |
// Determine whether there are any incoming end limits. |
108 |
// If not, use today's date as the end date. |
109 |
if (strlen($end_year) < 1) $end_year = $year; |
110 |
if (strlen($end_month) < 1) $end_month = $mon; |
111 |
if (strlen($end_day) < 1) $end_day = $mday; |
112 |
|
113 |
|
114 |
// Generate mySQL-friendly date-time based on current settings |
115 |
// Back-fill in case we have single-digits. |
116 |
if (strlen($start_year) < 1) $start_year = $year; |
117 |
if (strlen($start_month) < 2) $start_month = "0" . $start_month; |
118 |
if (strlen($start_day) < 2) $start_day = "0" . $start_day; |
119 |
|
120 |
|
121 |
if (strlen($end_year) < 1) $end_year = $year; |
122 |
if (strlen($end_month) < 2) $end_month = "0" . $end_month; |
123 |
if (strlen($end_day) < 2) $end_day = "0" . $end_day; |
124 |
|
125 |
|
126 |
|
127 |
// Generate high/low datetime stamps for SQL. |
128 |
$start_stamp = $start_year . "-" . $start_month . "-" . $start_day; |
129 |
$end_stamp = $end_year . "-" . $end_month . "-" . $end_day . " 23:59:59"; |
130 |
|
131 |
|
132 |
/******************** |
133 |
** Date range form ** |
134 |
********************/ |
135 |
|
136 |
printf("<td>\n"); |
137 |
printf("<b>Limit by date or range:</b><BR><BR>\n"); |
138 |
printf("<table border=\"0\">\n"); |
139 |
printf("<tr>\n"); |
140 |
printf("<form method =\"post\" action=\"scribe_stats.phtml\">\n"); |
141 |
|
142 |
|
143 |
// Start parameters |
144 |
|
145 |
|
146 |
// Start month |
147 |
printf("<td><b>Start Date:</b></td>"); |
148 |
printf("<td><select name=\"start_month\">\n"); |
149 |
for ($count = 1; $count < 13; $count++) { |
150 |
// Pad 0-9 with a 0. |
151 |
if ($count < 10) $count_value = "0" . $count; |
152 |
else $count_value = $count; |
153 |
printf("<option value=\"%s\"", $count); |
154 |
if ($count == $start_month) printf(" SELECTED "); |
155 |
printf(">%s</option>\n", $month_array[$count]); |
156 |
} |
157 |
|
158 |
printf("</select> "); |
159 |
|
160 |
|
161 |
// Start day |
162 |
printf("<select name=\"start_day\">\n"); |
163 |
for ($count = 1; $count < 32; $count++) { |
164 |
// Pad 0-9 with a 0. |
165 |
if ($count < 10) $count_value = "0" . $count; |
166 |
else $count_value = $count; |
167 |
printf("<option value=\"%s\"", $count); |
168 |
if ($count == $start_day) printf(" SELECTED "); |
169 |
printf(">%s</option>\n", $count_value); |
170 |
} |
171 |
|
172 |
printf("</select> "); |
173 |
|
174 |
// Start year -- allow previous three years as well |
175 |
$year_value = $year - 3; |
176 |
printf("<select name=\"start_year\">\n"); |
177 |
for ($count = 1; $count < 5; $count++) { |
178 |
printf("<option value=\"%s\"", $year_value); |
179 |
if ($year_value == $start_year) printf(" SELECTED "); |
180 |
printf(">%s</option>\n", $year_value); |
181 |
$year_value++; |
182 |
} |
183 |
|
184 |
printf("</select>\n"); |
185 |
printf("</td>\n"); |
186 |
|
187 |
// Blank cell |
188 |
printf("<td> </td>\n"); |
189 |
printf("</tr>\n"); |
190 |
|
191 |
|
192 |
// End parameters |
193 |
|
194 |
|
195 |
// End month |
196 |
printf("<tr>\n"); |
197 |
printf("<td><b>End Date:</b></td>"); |
198 |
printf("<td><select name=\"end_month\">\n"); |
199 |
for ($count = 1; $count < 13; $count++) { |
200 |
// Pad 0-9 with a 0. |
201 |
if ($count < 10) $count_value = "0" . $count; |
202 |
else $count_value = $count; |
203 |
|
204 |
printf("<option value=\"%s\"", $count_value); |
205 |
if ($count_value == $end_month) printf(" SELECTED "); |
206 |
printf(">%s</option>\n", $month_array[$count]); |
207 |
} |
208 |
|
209 |
printf("</select> "); |
210 |
|
211 |
|
212 |
// End day |
213 |
printf("<select name=\"end_day\">\n"); |
214 |
for ($count = 1; $count < 32; $count++) { |
215 |
// Pad 0-9 with a 0. |
216 |
if ($count < 10) $count_value = "0" . $count; |
217 |
else $count_value = $count; |
218 |
|
219 |
printf("<option value=\"%s\"", $count_value); |
220 |
if ($count_value == $end_day) printf(" SELECTED "); |
221 |
printf(">%s</option>\n", $count_value); |
222 |
} |
223 |
|
224 |
printf("</select> "); |
225 |
|
226 |
// End year -- allow previous three years as well |
227 |
$year_value = $year - 3; |
228 |
printf("<select name=\"end_year\">\n"); |
229 |
for ($count = 1; $count < 5; $count++) { |
230 |
printf("<option value=\"%s\"", $year_value); |
231 |
if ($year_value == $end_year) printf(" SELECTED "); |
232 |
printf(">%s</option>\n", $year_value); |
233 |
$year_value++; |
234 |
} |
235 |
|
236 |
printf("</select>\n"); |
237 |
printf("</td>\n"); |
238 |
printf("<td align = \"center\" ><input type=\"submit\" value=\"Limit By Dates\"></td>\n"); |
239 |
printf("</tr>\n"); |
240 |
printf("</form>"); |
241 |
printf("</table>\n"); |
242 |
|
243 |
|
244 |
// Outer table |
245 |
printf("</td></tr></table>\n"); |
246 |
printf("<BR>\n"); |
247 |
|
248 |
|
249 |
/********************* |
250 |
** PageScribe Pages ** |
251 |
*********************/ |
252 |
|
253 |
|
254 |
printf("<span class=\"bigDark\">Freeform PageScribe Pages</span><br><br>\n"); |
255 |
|
256 |
// Table and header row |
257 |
printf("<table width=\"95%%\" border=\"1\">\n"); |
258 |
printf("<tr>\n"); |
259 |
printf("<td class=\"cellPlain\" width=\"10%%\">Page ID</td>\n"); |
260 |
printf("<td class=\"cellPlain\" width=\"70%%\">Page Title</td>\n"); |
261 |
printf("<td class=\"cellPlain\" align=\"center\" width=\"10%%\">Page Loads</td>\n"); |
262 |
printf("<td class=\"cellPlain\" align=\"center\" width=\"10%%\">Links Used</td>\n"); |
263 |
printf("</tr>\n"); |
264 |
|
265 |
|
266 |
$sql = "SELECT |
267 |
p.page_id, |
268 |
p.page_title, |
269 |
p.account_created, |
270 |
p.account_modified, |
271 |
p.date_created, |
272 |
p.date_modified, |
273 |
p.staff_coordinator |
274 |
|
275 |
FROM |
276 |
page p |
277 |
WHERE pagetype_id = 2 |
278 |
ORDER BY |
279 |
p.page_title"; |
280 |
|
281 |
|
282 |
$rs = xx_tryquery($sql); |
283 |
|
284 |
// Initialize |
285 |
$rowcount = 0; |
286 |
$page_loads_total = 0; |
287 |
$element_uses_total = 0; |
288 |
|
289 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
290 |
|
291 |
// Fetch the stuff |
292 |
$page_id = $row["page_id"]; |
293 |
$page_title = Trim($row["page_title"]); |
294 |
$date_created = substr($row["date_created"], 0, 10); |
295 |
$date_modified = substr($row["date_modified"], 0, 10); |
296 |
|
297 |
// Pull out any HTML |
298 |
$page_title = strip_tags($page_title); |
299 |
|
300 |
// New row |
301 |
if ($rowcount % 2 == 0) $color = " class=\"backLight\" "; |
302 |
else $color = ""; |
303 |
|
304 |
printf("<tr>\n"); |
305 |
printf("<td %s>%d</td>\n", $color, $page_id); |
306 |
printf("<td %s>%s</td>\n", $color, $page_title); |
307 |
|
308 |
|
309 |
// Pull out the page load stats for this page |
310 |
$stats_sql = "SELECT COUNT(*) as page_loads |
311 |
FROM libstats.pagestats |
312 |
WHERE page_id = " |
313 |
. $page_id |
314 |
. " AND visit_date >= '" |
315 |
. $start_stamp |
316 |
. "' AND visit_date <= '" |
317 |
. $end_stamp |
318 |
. "'"; |
319 |
$stats_rs = xx_tryquery($stats_sql); |
320 |
$stats_row = xx_fetch_array ($stats_rs, xx_ASSOC); |
321 |
$page_loads = $stats_row["page_loads"]; |
322 |
|
323 |
printf("<td align=\"center\" %s>%d</td>\n", $color, $page_loads); |
324 |
|
325 |
// Pull out the stats for this page |
326 |
$stats_sql = "SELECT COUNT(*) as element_uses |
327 |
FROM libstats.elementstats |
328 |
WHERE page_id = " |
329 |
. $page_id |
330 |
. " AND visit_date >= '" |
331 |
. $start_stamp |
332 |
. "' AND visit_date <= '" |
333 |
. $end_stamp |
334 |
. "'"; |
335 |
|
336 |
$stats_rs = xx_tryquery($stats_sql); |
337 |
$stats_row = xx_fetch_array ($stats_rs, xx_ASSOC); |
338 |
$element_uses = $stats_row["element_uses"]; |
339 |
|
340 |
|
341 |
// Encode the date limits |
342 |
$start = urlencode($start_stamp); |
343 |
$end = urlencode($end_stamp); |
344 |
|
345 |
printf("<td align=\"center\" %s>\n", $color); |
346 |
printf("<a href=\"scribe_stats_page.phtml?page_id=%d&start=%s&end=%s\">%d</a>", $page_id, $start, $end, $element_uses); |
347 |
printf("</td>\n"); |
348 |
|
349 |
// Close row |
350 |
printf("</tr>\n"); |
351 |
|
352 |
// Increment |
353 |
$rowcount++; |
354 |
$page_loads_total = $page_loads_total + $page_loads; |
355 |
$element_uses_total = $element_uses_total + $element_uses; |
356 |
|
357 |
} |
358 |
|
359 |
// Summary row |
360 |
printf("<tr><td colspan=\"2\"> </td>\n"); |
361 |
printf("<td class=\"backLight\"><b>Total:</b> %d</td>\n", $page_loads_total); |
362 |
printf("<td class=\"backLight\"><b>Total:</b> %d</td></tr>\n", $element_uses_total); |
363 |
|
364 |
printf("</table><br>\n"); |
365 |
|
366 |
|
367 |
/******************** |
368 |
** CourseLib Pages ** |
369 |
********************/ |
370 |
|
371 |
printf("<span class=\"bigDark\">CourseLib Pages</span><br><br>\n"); |
372 |
|
373 |
// Table and header row |
374 |
printf("<table width=\"95%%\" border=\"1\">\n"); |
375 |
printf("<tr>\n"); |
376 |
printf("<td class=\"cellPlain\" width=\"10%%\">Page ID</td>\n"); |
377 |
printf("<td class=\"cellPlain\" width=\"70%%\">Course Title</td>\n"); |
378 |
printf("<td class=\"cellPlain\" align=\"center\" width=\"10%%\">Page Loads</td>\n"); |
379 |
printf("<td class=\"cellPlain\" align=\"center\" width=\"10%%\">Links Used</td>\n"); |
380 |
printf("</tr>\n"); |
381 |
|
382 |
|
383 |
$sql = "SELECT |
384 |
p.page_id, |
385 |
p.page_title, |
386 |
p.account_created, |
387 |
p.account_modified, |
388 |
p.date_created, |
389 |
p.date_modified, |
390 |
p.staff_coordinator, |
391 |
c.course_concat, |
392 |
c.course_id |
393 |
|
394 |
FROM |
395 |
page p |
396 |
LEFT JOIN course c using (page_id) |
397 |
WHERE pagetype_id = 3 |
398 |
ORDER BY c.course_concat"; |
399 |
|
400 |
|
401 |
$rs = xx_tryquery($sql); |
402 |
|
403 |
// Initialize |
404 |
$rowcount = 0; |
405 |
$page_loads_total = 0; |
406 |
$element_uses_total = 0; |
407 |
|
408 |
while ($row = xx_fetch_array ($rs, xx_ASSOC)) { |
409 |
|
410 |
// Fetch the stuff |
411 |
$page_id = $row["page_id"]; |
412 |
$page_title = Trim($row["page_title"]); |
413 |
$date_created = substr($row["date_created"], 0, 10); |
414 |
$date_modified = substr($row["date_modified"], 0, 10); |
415 |
$course_concat = Trim($row["course_concat"]); |
416 |
|
417 |
// Use full course name if this is a coursescribe page |
418 |
if (strlen($course_concat) > 0) $page_title = $course_concat; |
419 |
|
420 |
// Pull out any HTML |
421 |
$page_title = strip_tags($page_title); |
422 |
|
423 |
// New row |
424 |
if ($rowcount % 2 == 0) $color = " class=\"backLight\" "; |
425 |
else $color =""; |
426 |
|
427 |
printf("<tr>\n"); |
428 |
printf("<td %s>%d</td>\n", $color, $page_id); |
429 |
printf("<td %s>%s</td>\n", $color, $page_title); |
430 |
|
431 |
|
432 |
// Pull out the page load stats for this page |
433 |
$stats_sql = "SELECT COUNT(*) as page_loads |
434 |
FROM libstats.pagestats |
435 |
WHERE page_id = " |
436 |
. $page_id |
437 |
. " AND visit_date >= '" |
438 |
. $start_stamp |
439 |
. "' AND visit_date <= '" |
440 |
. $end_stamp |
441 |
. "'"; |
442 |
$stats_rs = xx_tryquery($stats_sql); |
443 |
$stats_row = xx_fetch_array ($stats_rs, xx_ASSOC); |
444 |
$page_loads = $stats_row["page_loads"]; |
445 |
|
446 |
printf("<td align=\"center\" %s>%d</td>\n", $color, $page_loads); |
447 |
|
448 |
// Pull out the element stats for this page |
449 |
$stats_sql = "SELECT COUNT(*) as element_uses |
450 |
FROM libstats.elementstats |
451 |
WHERE page_id = " |
452 |
. $page_id |
453 |
. " AND visit_date >= '" |
454 |
. $start_stamp |
455 |
. "' AND visit_date <= '" |
456 |
. $end_stamp |
457 |
. "'"; |
458 |
$stats_rs = xx_tryquery($stats_sql); |
459 |
$stats_row = xx_fetch_array ($stats_rs, xx_ASSOC); |
460 |
$element_uses = $stats_row["element_uses"]; |
461 |
|
462 |
// Encode the date limits |
463 |
$start = urlencode($start_stamp); |
464 |
$end = urlencode($end_stamp); |
465 |
|
466 |
printf("<td align=\"center\" %s>\n", $color); |
467 |
printf("<a href=\"scribe_stats_page.phtml?page_id=%d&start=%s&end=%s\">%d</a>", $page_id, $start, $end, $element_uses); |
468 |
printf("</td>\n"); |
469 |
|
470 |
// Close row |
471 |
printf("</tr>\n"); |
472 |
|
473 |
// Increment |
474 |
$rowcount++; |
475 |
$page_loads_total = $page_loads_total + $page_loads; |
476 |
$element_uses_total = $element_uses_total + $element_uses; |
477 |
|
478 |
} |
479 |
|
480 |
// Summary row |
481 |
printf("<tr><td colspan=\"2\"> </td>\n"); |
482 |
printf("<td class=\"backLight\"><b>Total:</b> %d</td>\n", $page_loads_total); |
483 |
printf("<td class=\"backLight\"><b>Total:</b> %d</td></tr>\n", $element_uses_total); |
484 |
|
485 |
printf("</table><br>\n"); |
486 |
|
487 |
|
488 |
|
489 |
// Link to return to admin console |
490 |
adminReturn($sess_access_level); |
491 |
|
492 |
|
493 |
printf("</center>\n"); |
494 |
|
495 |
|
496 |
} // logged in user |
497 |
|
498 |
// No access page |
499 |
else require_once ($GLOBAL_NO_ACCESS); |
500 |
|
501 |
|
502 |
// Page footer |
503 |
require_once ($GLOBAL_ADMIN_FOOTER); |
504 |
?> |
505 |
|
506 |
</body> |
507 |
</html> |