move code up one directory
[atutor.git] / admin / error_logging_details.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 if (!isset($_POST['data'])) {
19         $msg->addError('NO_PROFILE_SELECTED');
20         header('Location: error_logging.php');
21         exit;
22 } // else we have a profile we can work with
23
24 if (isset($_POST['delete'])) {
25
26         $key = substr($_POST['data'], 0, strpos($_POST['data'], ':'));
27         $date = substr($_POST['data'], strpos($_POST['data'], ':') + 1);
28         $dir_ = AT_CONTENT_DIR . 'logs/' . $date;
29         $delete_store;
30         
31         if (!($dir = opendir($dir_))) {
32                         $msg->printNoLookupFeedback('Could not access /content/logs/' . $date . '. Check that the permission for the <strong>Server</string> user are r+w to it');
33                         require(AT_INCLUDE_PATH.'footer.inc.php'); 
34                         
35                         exit;
36                 }
37         
38         $cnt = 0;       
39         // Open a read pointer to run through each log date directory getting all the profiles
40         while (($file = readdir($dir)) !== false) {
41                 
42                 if (($file == '.') || ($file == '..') || is_dir($file)) {
43                         continue;
44                 }
45                 
46                 if (strpos($file, $key) !== false) { // found a bug associated with our profile key
47                         $delete_store{$file} = $file;
48                 } else {
49                         $cnt++;
50                 }
51                                         
52         }
53         closedir($dir); // clean it up
54         
55         if (count($delete_store) > 0) {
56                 // Now run through the files and unlink them all
57                 foreach($delete_store as $elem => $val) 
58                         unlink($dir_ . '/' . $elem);
59         }
60                 
61         // remove the directory as well if there are no oother profiles in it
62         if ($cnt == 0) {
63                 rmdir($dir_);
64         }
65         
66         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
67         header('Location: error_logging.php');
68         exit;
69
70
71 require(AT_INCLUDE_PATH.'header.inc.php');
72
73 if (isset($_POST['view'])) {
74         // Grab all the bugs associated with this $_POST['data'] corresponding md5 key
75         $key = substr($_POST['data'], 0, strpos($_POST['data'], ':'));
76         $date = substr($_POST['data'], strpos($_POST['data'], ':') + 1);
77         $dir_ = AT_CONTENT_DIR . 'logs/' . $date;
78         $log_profiles_bugs;
79                 
80         ?>
81
82         <form name="form" method="post" action="<?php echo 'admin/error_logging_view.php'; ?>">
83         
84         <table class="data" summary="" rules="cols">
85         <thead>
86         <tr>
87                 <th scope="col"><?php echo _AT('bug_identifier'); ?></th>
88                 <th scope="col"><?php echo _AT('timestamp');      ?></th>
89         </tr>
90         </thead>
91         <tfoot>
92         <tr>
93                 <td colspan="2">
94                         <input type="hidden" name="profile_id" value="<?php echo $key; ?>"/>
95                         <input type="hidden" name="profile_date" value="<?php echo $date; ?>"/>
96                         <input type="submit" name="view" value="<?php echo _AT('view_selected_bugs'); ?>" />
97                         <input type="submit" name="back" value="<?php echo _AT('back_to_main'); ?>" />
98                 </td>
99         </tr>
100         </tfoot>
101         <tbody>
102         <?php
103                 if (!($dir = opendir($dir_))) {
104                         $msg->printNoLookupFeedback('Could not access /content/logs/' . $date . '. Check that the permission for the <strong>Server</string> user are r+w to it');
105                         require(AT_INCLUDE_PATH.'footer.inc.php'); 
106                         
107                         exit;
108                 }
109                 
110                 // Open a read pointer to run through each log date directory getting all the profiles
111                 while (($file = readdir($dir)) !== false) {
112                 
113                         if (($file == '.') || ($file == '..') || is_dir($file) || (strpos($file, 'profile')     !== false)) {
114                                 continue;
115                         }
116                 
117                         if (strpos($file, $key) !== false) { // found a bug associated with our profile key
118                                 $log_profile_bugs{$file} = $file;
119                         }
120                                         
121                 }
122                 closedir($dir); // clean it up          
123                 
124                 if (empty($log_profile_bugs)) { ?>
125                         <tr>
126                                 <td align="center" colspan="2"><small><?php echo _AT('none_found'); ?></small></td>
127                         </tr>
128                         <tr><td height="1" class="row2" colspan="2"></td></tr>
129                 <?php
130                 } else {
131                         $count = 0;
132                         
133                         $id_cnt = 1; // give each bug an easier to understand id onscreen
134                         foreach ($log_profile_bugs as $elem => $lm) {
135                                 // construct timestamp from millis since epoch in bug identifier
136                                 $timestamp = substr($lm, strpos($lm, '_') + 1);
137                                 $timestamp = substr($timestamp, 0, strpos($lm, '_') + 2);
138                         
139                                 $timestamp = AT_Date(_AT('inbox_date_format'), $timestamp, AT_DATE_UNIX_TIMESTAMP);
140                         
141                                 $str_prefix = substr($lm, 0, strpos($lm, '_'));
142                         ?>
143                                 <tr onmousedown="document.form['q<?php echo $lm; ?>'].checked = !document.form['q<?php echo $lm; ?>'].checked;">
144                                         <td><input type="checkbox" value="<?php echo $date . '/' . $lm; ?>" name="file<?php echo $count; ?>" id="q<?php echo $lm; ?>" onmouseup="this.checked=!this.checked" /><?php echo $id_cnt . '_' . $str_prefix; ?></td>
145                                         <td><?php echo $timestamp; ?></td>
146                                 </tr>
147                                 <?php $count++; $id_cnt++;
148                         }
149                 }
150                 ?>
151                 </tbody>
152                 </table>
153
154                 </form>
155         <?php
156         require(AT_INCLUDE_PATH.'footer.inc.php');
157         exit;
158                 
159 } else if (isset($_POST['delete'])) {
160         $key = substr($_POST['data'], 0, strpos($_POST['data'], ':'));
161         $date = substr($_POST['data'], strpos($_POST['data'], ':') + 1);
162         $dir_ = AT_CONTENT_DIR . 'logs/' . $date;
163         $delete_store;
164         
165         if (!($dir = opendir($dir_))) {
166                         $msg->printNoLookupFeedback('Could not access /content/logs/' . $date . '. Check that the permission for the <strong>Server</string> user are r+w to it');
167                         require(AT_INCLUDE_PATH.'footer.inc.php'); 
168                         
169                         exit;
170                 }
171                 
172         // Open a read pointer to run through each log date directory getting all the profiles
173         while (($file = readdir($dir)) !== false) {
174                 
175                 if (($file == '.') || ($file == '..') || is_dir($file)) {
176                         continue;
177                 }
178                 
179                 if (strpos($file, $key) !== false) { // found a bug associated with our profile key
180                         $delete_store{$file} = $file;
181                 }
182                                         
183         }
184         closedir($dir); // clean it up
185         
186         // Now run through the files and unlink them all
187         foreach($delete_store as $elem => $val) 
188                 unlink($dir_ . '/' . $elem);
189                 
190         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
191         header('Location: ' . $_SERVER['PHP_SELF']);
192 }
193 ?>