04b266dd6310a2b623be90e282f635a6a8de54fb
[atutor.git] / docs / admin / error_logging.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* Inclusive Design Institute                                           */
7 /* http://atutor.ca                                                     */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12 // $Id$
13
14 define('AT_INCLUDE_PATH', '../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 admin_authenticate(AT_ADMIN_PRIV_ADMIN);
17
18 require(AT_INCLUDE_PATH.'header.inc.php');
19
20 ?>
21
22 <form name="form" method="post" action="admin/error_logging_details.php">
23 <table class="data" summary="" rules="cols">
24 <thead>
25 <tr>
26         <th><?php echo _AT('profile');   ?></th>
27         <th><?php echo _AT('date');      ?></th>
28         <th><?php echo _AT('bug_count'); ?></th>
29 </tr>
30 </thead>
31 <tfoot>
32 <tr>
33         <td colspan="3">
34                 <input type="submit" name="view" value="<?php echo _AT('view_profile_bugs'); ?>" /> 
35                 <input type="submit" name="delete" value="<?php echo _AT('delete_profile'); ?>" />
36         </td>
37 </tr>
38 </tfoot>
39 <tbody>
40 <?php
41                 
42                 $dir_ = AT_CONTENT_DIR . 'logs';
43                 if (!is_dir($dir_)) {
44                         mkdir($dir_);
45                 }
46
47                 if (!($dir = @opendir($dir_))) {
48                         $msg->printNoLookupFeedback('Could not access /content/logs. Check that the permission for the <strong>Server</string> user are r+w to it');
49                         require(AT_INCLUDE_PATH.'footer.inc.php'); 
50                         
51                         exit;
52                 }
53                 
54                 /**
55                  * Run through the logs directory and lets get all the profiles of all the logs of all the dates, sort
56                  * by primary key as date, secondary key is profile name
57                  */ 
58                 $logdirs;
59                  
60                 // loop through folder to get files and directory listing
61                 while (($file = readdir($dir)) !== false) {
62
63                         /* if the name is not a directory */
64                         if( ($file == '.') || ($file == '..')) {
65                                 continue;
66                         }
67
68                         if (is_dir($dir_ . '/' . $file)) {
69                                 $logdirs{$file} = $file; // store the day log dir
70                         }
71                 }
72                 closedir($dir); // clean it up
73
74                 if (empty($logdirs)) { ?>
75                         <tr>
76                                 <td colspan="3"><?php echo _AT('none_found'); ?></td>
77                         </tr>
78                 <?php
79                 } else {
80                 
81                         $count_ = 1;
82                         foreach ($logdirs as $row => $val) {
83                                 $log_profiles; // store all the profiles under the dir /content/logs/$val
84                                 $log_profiles_bug_count; // store the amount of bugs per profile
85                                 
86                                 if (!($dir = opendir($dir_ . '/' . $val))) {
87                                         $msg->printNoLookupFeedback('Could not access /content/logs/' . $val . '. Check that the permission for the <strong>Server</string> user are r+w to it');
88                                         require(AT_INCLUDE_PATH.'footer.inc.php'); 
89                         
90                                         exit;
91                                 }
92                                 // Open a read pointer to run through each log date directory getting all the profiles
93                                 while (($file = readdir($dir)) !== false) {
94                 
95                                         if (($file == '.') || ($file == '..') || is_dir($file)) {
96                                                 continue;
97                                         }
98                 
99                                         if (strpos($file, 'profile')    !== false) { // found a profile, store its md5 key identifier
100                                                 $tmp_ = substr($file, strpos($file, '_') + 1);
101                                                 $tmp_ = substr($tmp_, 0, strpos($tmp_, '.log.php'));
102                                                 $log_profiles{$file} = $tmp_;
103                                         }
104                                         
105                                 }
106                                 closedir($dir); // clean it up
107                                 
108                                 /**
109                                  * Open a read pointer to run through each log date directory getting all the bugs associated
110                                  * all the profiles in $log_profiles
111                                  */
112                                 if (empty($log_profiles)) { 
113                                         $msg->printNoLookupFeedback('Warning. No profile found in ' . $dir_ . '/' . $val);
114                                         require(AT_INCLUDE_PATH.'footer.inc.php'); 
115                         
116                                         exit;
117                                 }
118                         
119                                 foreach ($log_profiles as $elem => $val_) {
120                                         $count = 0;
121                                         
122                                         /* for each profile get the number of bugs associated with it */
123                                         if (!($dir = opendir($dir_ . '/' . $val))) {
124                                                 $msg->printNoLookupFeedback('Could not access /content/logs' . $val . '. Check that the permission for the <strong>Server</string> user are r+w to it');
125                                                 require(AT_INCLUDE_PATH.'footer.inc.php'); 
126                         
127                                                 exit;
128                                         }
129                                         
130                                         while (($file = readdir($dir)) !== false) {
131                         
132                                                 // make sure we ignore profiles too!, just look at bug files
133                                                 if( ($file == '.') || ($file == '..') || is_dir($file) || (strpos($file, 'profile') !== false)) {
134                                                         continue;
135                                                 }
136
137                                                 // found a bug that maps to $val_ md5 profile identifer
138                                                 if (strpos($file, $val_)        !== false) { 
139                                                         $count++;
140                                                 }
141                                         }
142                                         closedir($dir);
143
144                                         // store the amount of bugs associated with profile
145                                         $log_profiles_bug_count{$val}[$val_] = $count;
146                                 }
147                                 $log_profiles = array();
148                         }
149                         /**
150                          * At this point ($log_profiles => key) = ($log_profiles_bug_count => key).
151                          *
152                          * Lets print out <td> rows corresponding to all profiles found in the following format:
153                          *
154                          * Profile name, profile date, profile bug count. 
155                          */             
156                         foreach ($log_profiles_bug_count as $day => $profile) :
157                                  foreach ($profile as $stamp => $total) :
158                         ?>
159                                         <tr onmousedown="document.form['<?php echo $stamp.$day; ?>'].checked = true;rowselect(this);" id="r_<?php echo $stamp.$day; ?>">
160                                                 <td><input type="radio" id="<?php echo $stamp.$day; ?>" value="<?php echo $stamp.':'.$day; ?>" name="data" /><label for="<?php echo $stamp.$day; ?>"><?php echo $count_; ?></label></td>
161                                                 <td><?php echo $day; ?></td>
162                                                 <td><?php echo $total; ?></td>
163                                         </tr>
164                         <?php
165                                         $count_++;
166                                 endforeach;
167                         endforeach;
168                 }
169         
170 ?>
171 </tbody>
172 </table>
173 </form>
174
175 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>