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>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 |
// 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\">Statistics Summary</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.pagestats"; |
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=\"scribe_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\">Freeform PageScribe Pages</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%%\">Page ID</td>\n"); |
250 |
printf("<td class=\"cellPlain\" width=\"70%%\">Page Title</td>\n"); |
251 |
printf("<td class=\"cellPlain\" align=\"center\" width=\"10%%\">Page Loads</td>\n"); |
252 |
printf("<td class=\"cellPlain\" align=\"center\" width=\"10%%\">Links Used</td>\n"); |
253 |
printf("</tr>\n"); |
254 |
|
255 |
|
256 |
$sql = "SELECT |
257 |
p.page_id, |
258 |
p.page_title, |
259 |
p.account_created, |
260 |
p.account_modified, |
261 |
p.date_created, |
262 |
p.date_modified, |
263 |
p.staff_coordinator |
264 |
|
265 |
FROM |
266 |
page p |
267 |
WHERE pagetype_id = 2 |
268 |
ORDER BY |
269 |
p.page_title"; |
270 |
|
271 |
|
272 |
$rs = mysql_query($sql, $con); |
273 |
|
274 |
// Initialize |
275 |
$rowcount = 0; |
276 |
$page_loads_total = 0; |
277 |
$element_uses_total = 0; |
278 |
|
279 |
while ($row = mysql_fetch_array ($rs)) { |
280 |
|
281 |
// Fetch the stuff |
282 |
$page_id = $row["page_id"]; |
283 |
$page_title = Trim($row["page_title"]); |
284 |
$date_created = substr($row["date_created"], 0, 10); |
285 |
$date_modified = substr($row["date_modified"], 0, 10); |
286 |
|
287 |
// Pull out any HTML |
288 |
$page_title = strip_tags($page_title); |
289 |
|
290 |
// New row |
291 |
if ($rowcount % 2 == 0) $color = " class=\"backLight\" "; |
292 |
else $color = ""; |
293 |
|
294 |
printf("<tr>\n"); |
295 |
printf("<td %s>%d</td>\n", $color, $page_id); |
296 |
printf("<td %s>%s</td>\n", $color, $page_title); |
297 |
|
298 |
|
299 |
// Pull out the page load stats for this page |
300 |
$stats_sql = "SELECT COUNT(*) as page_loads |
301 |
FROM libstats.pagestats |
302 |
WHERE page_id = " |
303 |
. $page_id |
304 |
. " AND visit_date >= '" |
305 |
. $start_stamp |
306 |
. "' AND visit_date <= '" |
307 |
. $end_stamp |
308 |
. "'"; |
309 |
$stats_rs = mysql_query($stats_sql, $con); |
310 |
$stats_row = mysql_fetch_array ($stats_rs); |
311 |
$page_loads = $stats_row["page_loads"]; |
312 |
|
313 |
printf("<td align=\"center\" %s>%d</td>\n", $color, $page_loads); |
314 |
|
315 |
// Pull out the stats for this page |
316 |
$stats_sql = "SELECT COUNT(*) as element_uses |
317 |
FROM libstats.elementstats |
318 |
WHERE page_id = " |
319 |
. $page_id |
320 |
. " AND visit_date >= '" |
321 |
. $start_stamp |
322 |
. "' AND visit_date <= '" |
323 |
. $end_stamp |
324 |
. "'"; |
325 |
|
326 |
$stats_rs = mysql_query($stats_sql, $con); |
327 |
$stats_row = mysql_fetch_array ($stats_rs); |
328 |
$element_uses = $stats_row["element_uses"]; |
329 |
|
330 |
|
331 |
// Encode the date limits |
332 |
$start = urlencode($start_stamp); |
333 |
$end = urlencode($end_stamp); |
334 |
|
335 |
printf("<td align=\"center\" %s>\n", $color); |
336 |
printf("<a href=\"scribe_stats_page.phtml?page_id=%d&start=%s&end=%s\">%d</a>", $page_id, $start, $end, $element_uses); |
337 |
printf("</td>\n"); |
338 |
|
339 |
// Close row |
340 |
printf("</tr>\n"); |
341 |
|
342 |
// Increment |
343 |
$rowcount++; |
344 |
$page_loads_total = $page_loads_total + $page_loads; |
345 |
$element_uses_total = $element_uses_total + $element_uses; |
346 |
|
347 |
} |
348 |
|
349 |
// Summary row |
350 |
printf("<tr><td colspan=\"2\"> </td>\n"); |
351 |
printf("<td class=\"backLight\"><b>Total:</b> %d</td>\n", $page_loads_total); |
352 |
printf("<td class=\"backLight\"><b>Total:</b> %d</td></tr>\n", $element_uses_total); |
353 |
|
354 |
printf("</table><br>\n"); |
355 |
|
356 |
|
357 |
/******************** |
358 |
** CourseLib Pages ** |
359 |
********************/ |
360 |
|
361 |
printf("<span class=\"bigDark\">CourseLib Pages</span><br><br>\n"); |
362 |
|
363 |
// Table and header row |
364 |
printf("<table width=\"95%%\" border=\"1\">\n"); |
365 |
printf("<tr>\n"); |
366 |
printf("<td class=\"cellPlain\" width=\"10%%\">Page ID</td>\n"); |
367 |
printf("<td class=\"cellPlain\" width=\"70%%\">Course Title</td>\n"); |
368 |
printf("<td class=\"cellPlain\" align=\"center\" width=\"10%%\">Page Loads</td>\n"); |
369 |
printf("<td class=\"cellPlain\" align=\"center\" width=\"10%%\">Links Used</td>\n"); |
370 |
printf("</tr>\n"); |
371 |
|
372 |
|
373 |
$sql = "SELECT |
374 |
p.page_id, |
375 |
p.page_title, |
376 |
p.account_created, |
377 |
p.account_modified, |
378 |
p.date_created, |
379 |
p.date_modified, |
380 |
p.staff_coordinator, |
381 |
c.course_concat, |
382 |
c.course_id |
383 |
|
384 |
FROM |
385 |
page p |
386 |
LEFT JOIN course c using (page_id) |
387 |
WHERE pagetype_id = 3 |
388 |
ORDER BY c.course_concat"; |
389 |
|
390 |
|
391 |
$rs = mysql_query($sql, $con); |
392 |
|
393 |
// Initialize |
394 |
$rowcount = 0; |
395 |
$page_loads_total = 0; |
396 |
$element_uses_total = 0; |
397 |
|
398 |
while ($row = mysql_fetch_array ($rs)) { |
399 |
|
400 |
// Fetch the stuff |
401 |
$page_id = $row["page_id"]; |
402 |
$page_title = Trim($row["page_title"]); |
403 |
$date_created = substr($row["date_created"], 0, 10); |
404 |
$date_modified = substr($row["date_modified"], 0, 10); |
405 |
$course_concat = Trim($row["course_concat"]); |
406 |
|
407 |
// Use full course name if this is a coursescribe page |
408 |
if (strlen($course_concat) > 0) $page_title = $course_concat; |
409 |
|
410 |
// Pull out any HTML |
411 |
$page_title = strip_tags($page_title); |
412 |
|
413 |
// New row |
414 |
if ($rowcount % 2 == 0) $color = " class=\"backLight\" "; |
415 |
else $color =""; |
416 |
|
417 |
printf("<tr>\n"); |
418 |
printf("<td %s>%d</td>\n", $color, $page_id); |
419 |
printf("<td %s>%s</td>\n", $color, $page_title); |
420 |
|
421 |
|
422 |
// Pull out the page load stats for this page |
423 |
$stats_sql = "SELECT COUNT(*) as page_loads |
424 |
FROM libstats.pagestats |
425 |
WHERE page_id = " |
426 |
. $page_id |
427 |
. " AND visit_date >= '" |
428 |
. $start_stamp |
429 |
. "' AND visit_date <= '" |
430 |
. $end_stamp |
431 |
. "'"; |
432 |
$stats_rs = mysql_query($stats_sql, $con); |
433 |
$stats_row = mysql_fetch_array ($stats_rs); |
434 |
$page_loads = $stats_row["page_loads"]; |
435 |
|
436 |
printf("<td align=\"center\" %s>%d</td>\n", $color, $page_loads); |
437 |
|
438 |
// Pull out the element stats for this page |
439 |
$stats_sql = "SELECT COUNT(*) as element_uses |
440 |
FROM libstats.elementstats |
441 |
WHERE page_id = " |
442 |
. $page_id |
443 |
. " AND visit_date >= '" |
444 |
. $start_stamp |
445 |
. "' AND visit_date <= '" |
446 |
. $end_stamp |
447 |
. "'"; |
448 |
$stats_rs = mysql_query($stats_sql, $con); |
449 |
$stats_row = mysql_fetch_array ($stats_rs); |
450 |
$element_uses = $stats_row["element_uses"]; |
451 |
|
452 |
// Encode the date limits |
453 |
$start = urlencode($start_stamp); |
454 |
$end = urlencode($end_stamp); |
455 |
|
456 |
printf("<td align=\"center\" %s>\n", $color); |
457 |
printf("<a href=\"scribe_stats_page.phtml?page_id=%d&start=%s&end=%s\">%d</a>", $page_id, $start, $end, $element_uses); |
458 |
printf("</td>\n"); |
459 |
|
460 |
// Close row |
461 |
printf("</tr>\n"); |
462 |
|
463 |
// Increment |
464 |
$rowcount++; |
465 |
$page_loads_total = $page_loads_total + $page_loads; |
466 |
$element_uses_total = $element_uses_total + $element_uses; |
467 |
|
468 |
} |
469 |
|
470 |
// Summary row |
471 |
printf("<tr><td colspan=\"2\"> </td>\n"); |
472 |
printf("<td class=\"backLight\"><b>Total:</b> %d</td>\n", $page_loads_total); |
473 |
printf("<td class=\"backLight\"><b>Total:</b> %d</td></tr>\n", $element_uses_total); |
474 |
|
475 |
printf("</table><br>\n"); |
476 |
|
477 |
|
478 |
|
479 |
// Link to return to admin console |
480 |
adminReturn($sess_access_level); |
481 |
|
482 |
|
483 |
printf("</center>\n"); |
484 |
|
485 |
|
486 |
} // logged in user |
487 |
|
488 |
// No access page |
489 |
else require_once ($GLOBAL_NO_ACCESS); |
490 |
|
491 |
|
492 |
// Page footer |
493 |
require_once ($GLOBAL_ADMIN_FOOTER); |
494 |
?> |
495 |
|
496 |
</body> |
497 |
</html> |