move code up one directory
[atutor.git] / mods / _standard / statistics / course_stats.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
7 /* http://atutor.ca                                                                                             */
8 /*                                                              */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License  */
11 /* as published by the Free Software Foundation.                                */
12 /****************************************************************/
13 // $Id$
14
15 define('AT_INCLUDE_PATH', '../../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 authenticate(AT_PRIV_ADMIN, AT_PRIV_RETURN);
18
19 $year  = intval($_GET['year']);
20 $month = intval($_GET['month']);
21
22         if ($month == 0) {
23                 $month = date('m');
24                 $year  = date('Y');
25         }
26
27         $days   = array();
28         $sql    = "SELECT * FROM ".TABLE_PREFIX."course_stats WHERE course_id=$_SESSION[course_id] AND MONTH(login_date)=$month AND YEAR(login_date)=$year ORDER BY login_date ASC";
29         $result = mysql_query($sql, $db);
30         //$today  = 1; /* we start on the 1st of the month */
31         $max_total_logins = 0;
32         $min_total_logins = (int) 99999999;
33         $total_logins = 0;
34
35         $empty = true;
36         while ($row = mysql_fetch_array($result)) {
37                 $empty = false;
38                 $row_day = substr($row['login_date'], 8, 2);
39
40                 if (substr($row_day, 0,1) == '0') {
41                         $row_day = substr($row_day, 1, 1);
42                 }
43                 
44                 while ($today < $row_day-1) {
45                         $today++;
46                         $days[$today] = array(0, 0);
47                         $min_total_logins = 0;
48                 }
49
50                 $today = $row_day; /* skip this day in the fill-in-the-blanks-loop */
51                                 
52                 $days[$row_day] = array($row['guests'], $row['members']);
53
54                 if ($max_total_logins < $row['guests']+$row['members']) {
55                         $max_total_logins = $row['guests']+$row['members'];
56                 }
57
58                 if ($min_total_logins > $row['guests']+$row['members']) {
59                         $min_total_logins = $row['guests']+$row['members'];
60                 }
61
62                 $total_logins += $row['guests']+$row['members'];
63         }
64
65         /* add zeros to the end of the month, only if it isn't the current month */
66         $now_month = date('m');
67         $now_year  = date('Y');
68         if ( (($month < $now_month) && ($now_year == $year)) || ($now_year < $year) ) {
69                 $today++;
70                 while (checkdate($month, $today,$year)) {
71                         $days[$today] = array(0, 0);
72                         $today++;
73                 }
74         }
75         $num_days = count($days);
76
77         if ($total_logins > 0) {
78                 $avg_total_logins = $total_logins/$num_days;
79         } else {
80                 $avg_total_logins = 0;
81         }
82
83         $block_height           = 10;
84         $multiplyer_height  = 5; /* should be multiples of 5 */
85
86         if ($month == 12) {
87                 $next_month = 1;
88                 $next_year  = $year + 1;
89         } else {
90                 $next_month = $month + 1;
91                 $next_year  = $year;
92         }
93
94         if ($month == 1) {
95                 $last_month = 12;
96                 $last_year  = $year - 1;
97         } else {
98                 $last_month = $month - 1;
99                 $last_year  = $year;
100         }
101
102 require(AT_INCLUDE_PATH.'header.inc.php');
103
104 $savant->assign('last_month', $last_month);
105 $savant->assign('last_year', $last_year);
106 $savant->assign('month', $month);
107 $savant->assign('next_month', $next_month);
108 $savant->assign('next_year', $next_year);
109 $savant->assign('num_days', $num_days);
110 $savant->assign('empty', $empty);
111 $savant->assign('total_logins', $total_logins);
112 $savant->assign('min_total_logins', $min_total_logins);
113 $savant->assign('max_total_logins', $max_total_logins);
114 $savant->assign('avg_total_logins', $avg_total_logins);
115 $savant->assign('multiplyer_height', $multiplyer_height);
116 $savant->assign('block_height', $block_height);
117 $savant->assign('days', $days);
118 $savant->assign('result', $result);
119 $savant->assign('short_name', $short_name);
120 $savant->display('instructor/statistics/course_stats.tmpl.php');
121 require(AT_INCLUDE_PATH.'footer.inc.php'); ?>