2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto */
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 /************************************************************************/
15 define('AT_INCLUDE_PATH', '../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 admin_authenticate(AT_ADMIN_PRIV_ADMIN);
19 if (isset($_POST['back'])) {
20 header('Location: error_logging.php');
24 if (isset($_POST['step2'])) { // e-mail bundle
26 if ($_POST['email_add'] == '') {
27 $msg->addError(array('EMPTY_FIELDS', _AT('recipient_address')));
29 header('Location: ' . $_SERVER['PHP_SELF']);
32 /* First lets check if they selected any profiles to bundle, run through $POST['file(\d)'] */
33 foreach($_POST as $elem => $val) {
34 if (strpos($elem, 'file') !== false) {
39 $date = substr($work, 0, strpos($work, ':'));
40 $id = substr($work, strpos($work, ':') + 1);
41 /* Parse the variable */
42 $profiles{$id} = $date;
46 if ($found === true) {
47 require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
48 require(AT_INCLUDE_PATH.'classes/zipfile.class.php');
50 $mail = new ATutorMailer;
52 $zipfile = new zipfile();
54 $dir_ = AT_CONTENT_DIR . 'logs';
56 foreach($profiles as $elem => $val) {
59 // read the dir where this profile and its associated log files are located
60 if (!($dir = opendir($dir_ . '/' . $val))) {
61 $msg->printNoLookupFeedback('Could not access /content/logs/' . $val . '. Check that the permission for the <strong>Server</string> user are r+w to it');
62 require(AT_INCLUDE_PATH.'footer.inc.php');
66 // Open a read pointer to run through each log date directory getting all the profiles
67 while (($file = readdir($dir)) !== false) {
69 if (($file == '.') || ($file == '..') || is_dir($file)) {
73 // any files mathcing the $elem key correspond to this profile
74 if (strpos($file, $elem) !== false) {
75 $store_some{$dir_ . '/'. $val . '/' . $file} = $file;
79 closedir($dir); // clean it up
81 // The dir pointer is closed lets add to the zip
82 foreach($store_some as $val_ => $e)
83 $zipfile->add_file(file_get_contents($val_), $e);
88 if ($file_handle = fopen($dir_ . '/bundle.log', "w")) {
89 if (!fwrite($file_handle, $zipfile->get_file())) { }
93 $mail->From = $_config['contact_email'];
94 $mail->addAddress($_POST['email_add']);
95 $mail->Subject = _AT('log_file_bundle');
96 $mail->Body = _AT('see_attached');
97 $mail->AddAttachment($dir_ . '/bundle.log');
99 // clean up the file at the redirection point
101 $msg->addError('SENDING_ERROR');
102 /* Make sure the tmp bundle file never exists past the lifetime of the bundle manager page */
103 unlink($dir_ . '/bundle.log');
104 header('Location: ' . $_SERVER['PHP_SELF']);
109 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
110 /* Make sure the tmp bundle file never exists past the lifetime of the bundle manager page */
111 unlink($dir_ . '/bundle.log');
112 header('Location: error_logging.php');
115 $msg->addError('NO_LOGS_SELECTED');
116 header('Location: ' . $_SERVER['PHP_SELF']);
121 require(AT_INCLUDE_PATH.'header.inc.php');
127 <h3><?php echo _AT('profile_bundle_select'); ?></h3>
129 <p><?php echo _AT('admin_bundle_instructions'); ?></p>
131 <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
132 <table class="data" summary="" rules="cols">
135 <th span="col"><?php echo _AT('profile'); ?></th>
136 <th span="col"><?php echo _AT('date'); ?></th>
137 <th span="col"><?php echo _AT('bug_count'); ?></th>
143 <label for="email" ><?php echo _AT('recipient_address'); ?></label><br />
144 <input type="text" id="email" name="email_add" value="" />
145 <input type="submit" name="step2" value="<?php echo _AT('send_bundle'); ?>" />
146 <input type="submit" name="back" value="<?php echo _AT('back_to_main'); ?>" />
153 $dir_ = AT_CONTENT_DIR . 'logs';
155 if (!($dir = opendir($dir_))) {
156 $msg->printNoLookupFeedback('Could not access /content/logs. Check that the permission for the <strong>Server</string> user are r+w to it');
157 require(AT_INCLUDE_PATH.'footer.inc.php');
163 * Run through the logs directory and lets get all the profiles of all the logs of all the dates, sort
164 * by primary key as date, secondary key is profile name
168 // loop through folder to get files and directory listing
169 while (($file = readdir($dir)) !== false) {
171 /* if the name is not a directory */
172 if( ($file == '.') || ($file == '..')) {
176 if (is_dir($dir_ . '/' . $file)) {
177 $logdirs{$file} = $file; // store the day log dir
180 closedir($dir); // clean it up
182 if (empty($logdirs)) { ?>
184 <td colspan="3"><?php echo _AT('none_found'); ?></td>
190 foreach ($logdirs as $row => $val) {
191 $log_profiles; // store all the profiles under the dir /content/logs/$val
192 $log_profiles_bug_count; // store the amount of bugs per profile
194 if (!($dir = opendir($dir_ . '/' . $val))) {
195 $msg->printNoLookupFeedback('Could not access /content/logs/' . $val . '. Check that the permission for the <strong>Server</string> user are r+w to it');
196 require(AT_INCLUDE_PATH.'footer.inc.php');
200 // Open a read pointer to run through each log date directory getting all the profiles
201 while (($file = readdir($dir)) !== false) {
203 if (($file == '.') || ($file == '..') || is_dir($file)) {
207 if (strpos($file, 'profile') !== false) { // found a profile, store its md5 key identifier
208 $tmp_ = substr($file, strpos($file, '_') + 1);
209 $tmp_ = substr($tmp_, 0, strpos($tmp_, '.log.php'));
210 $log_profiles{$file} = $tmp_;
214 closedir($dir); // clean it up
217 * Open a read pointer to run through each log date directory getting all the bugs associated
218 * all the profiles in $log_profiles
220 if (empty($log_profiles)) {
221 $msg->printNoLookupFeedback('Warning. No profile found in ' . $dir_ . '/' . $val);
222 require(AT_INCLUDE_PATH.'footer.inc.php');
227 foreach ($log_profiles as $elem => $val_) {
230 /* for each profile get the number of bugs associated with it */
231 if (!($dir = opendir($dir_ . '/' . $val))) {
232 $msg->printNoLookupFeedback('Could not access /content/logs' . $val . '. Check that the permission for the <strong>Server</string> user are r+w to it');
233 require(AT_INCLUDE_PATH.'footer.inc.php');
238 while (($file = readdir($dir)) !== false) {
240 // make sure we ignore profiles too!, just look at bug files
241 if( ($file == '.') || ($file == '..') || is_dir($file) || (strpos($file, 'profile') !== false)) {
245 // found a bug that maps to $val_ md5 profile identifer
246 if (strpos($file, $val_) !== false) {
252 // store the amount of bugs associated with profile
253 $log_profiles_bug_count{$val}[$val_] = $count;
255 $log_profiles = array();
258 * At this point ($log_profiles => key) = ($log_profiles_bug_count => key).
260 * Lets print out <td> rows corresponding to all profiles found in the following format:
262 * Profile name, profile date, profile bug count.
264 foreach ($log_profiles_bug_count as $day => $profile) :
265 foreach ($profile as $stamp => $total) :
267 <tr onmousedown="document.form1['<?php echo $stamp.$day; ?>'].checked = !document.form1['<?php echo $stamp.$day; ?>'].checked;">
268 <td><input type="checkbox" id="<?php echo $stamp.$day; ?>" value="<?php echo $day.':'.$stamp; ?>" name="file<?php echo $count_; ?>" onmouseup="this.checked=!this.checked" /><?php echo $count_; ?></td>
269 <td><?php echo $day; ?></td>
270 <td><?php echo $total; ?></td>
283 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>