2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
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 /************************************************************************/
14 define('AT_INCLUDE_PATH', '../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 admin_authenticate(AT_ADMIN_PRIV_ADMIN);
18 if (isset($_POST['back'])) {
19 header('Location: error_logging.php');
23 if (isset($_POST['step2'])) { // e-mail bundle
25 if ($_POST['email_add'] == '') {
26 $msg->addError(array('EMPTY_FIELDS', _AT('recipient_address')));
28 header('Location: ' . $_SERVER['PHP_SELF']);
31 /* First lets check if they selected any profiles to bundle, run through $POST['file(\d)'] */
32 foreach($_POST as $elem => $val) {
33 if (strpos($elem, 'file') !== false) {
38 $date = substr($work, 0, strpos($work, ':'));
39 $id = substr($work, strpos($work, ':') + 1);
40 /* Parse the variable */
41 $profiles{$id} = $date;
45 if ($found === true) {
46 require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
47 require(AT_INCLUDE_PATH.'classes/zipfile.class.php');
49 $mail = new ATutorMailer;
51 $zipfile = new zipfile();
53 $dir_ = AT_CONTENT_DIR . 'logs';
55 foreach($profiles as $elem => $val) {
58 // read the dir where this profile and its associated log files are located
59 if (!($dir = opendir($dir_ . '/' . $val))) {
60 $msg->printNoLookupFeedback('Could not access /content/logs/' . $val . '. Check that the permission for the <strong>Server</string> user are r+w to it');
61 require(AT_INCLUDE_PATH.'footer.inc.php');
65 // Open a read pointer to run through each log date directory getting all the profiles
66 while (($file = readdir($dir)) !== false) {
68 if (($file == '.') || ($file == '..') || is_dir($file)) {
72 // any files mathcing the $elem key correspond to this profile
73 if (strpos($file, $elem) !== false) {
74 $store_some{$dir_ . '/'. $val . '/' . $file} = $file;
78 closedir($dir); // clean it up
80 // The dir pointer is closed lets add to the zip
81 foreach($store_some as $val_ => $e)
82 $zipfile->add_file(file_get_contents($val_), $e);
87 if ($file_handle = fopen($dir_ . '/bundle.log', "w")) {
88 if (!fwrite($file_handle, $zipfile->get_file())) { }
92 $mail->From = $_config['contact_email'];
93 $mail->addAddress($_POST['email_add']);
94 $mail->Subject = _AT('log_file_bundle');
95 $mail->Body = _AT('see_attached');
96 $mail->AddAttachment($dir_ . '/bundle.log');
98 // clean up the file at the redirection point
100 $msg->addError('SENDING_ERROR');
101 /* Make sure the tmp bundle file never exists past the lifetime of the bundle manager page */
102 unlink($dir_ . '/bundle.log');
103 header('Location: ' . $_SERVER['PHP_SELF']);
108 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
109 /* Make sure the tmp bundle file never exists past the lifetime of the bundle manager page */
110 unlink($dir_ . '/bundle.log');
111 header('Location: error_logging.php');
114 $msg->addError('NO_LOGS_SELECTED');
115 header('Location: ' . $_SERVER['PHP_SELF']);
120 require(AT_INCLUDE_PATH.'header.inc.php');
126 <h3><?php echo _AT('profile_bundle_select'); ?></h3>
128 <p><?php echo _AT('admin_bundle_instructions'); ?></p>
130 <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
131 <table class="data" summary="" rules="cols">
134 <th span="col"><?php echo _AT('profile'); ?></th>
135 <th span="col"><?php echo _AT('date'); ?></th>
136 <th span="col"><?php echo _AT('bug_count'); ?></th>
142 <label for="email" ><?php echo _AT('recipient_address'); ?></label><br />
143 <input type="text" id="email" name="email_add" value="" />
144 <input type="submit" name="step2" value="<?php echo _AT('send_bundle'); ?>" />
145 <input type="submit" name="back" value="<?php echo _AT('back_to_main'); ?>" />
152 $dir_ = AT_CONTENT_DIR . 'logs';
154 if (!($dir = opendir($dir_))) {
155 $msg->printNoLookupFeedback('Could not access /content/logs. Check that the permission for the <strong>Server</string> user are r+w to it');
156 require(AT_INCLUDE_PATH.'footer.inc.php');
162 * Run through the logs directory and lets get all the profiles of all the logs of all the dates, sort
163 * by primary key as date, secondary key is profile name
167 // loop through folder to get files and directory listing
168 while (($file = readdir($dir)) !== false) {
170 /* if the name is not a directory */
171 if( ($file == '.') || ($file == '..')) {
175 if (is_dir($dir_ . '/' . $file)) {
176 $logdirs{$file} = $file; // store the day log dir
179 closedir($dir); // clean it up
181 if (empty($logdirs)) { ?>
183 <td colspan="3"><?php echo _AT('none_found'); ?></td>
189 foreach ($logdirs as $row => $val) {
190 $log_profiles; // store all the profiles under the dir /content/logs/$val
191 $log_profiles_bug_count; // store the amount of bugs per profile
193 if (!($dir = opendir($dir_ . '/' . $val))) {
194 $msg->printNoLookupFeedback('Could not access /content/logs/' . $val . '. Check that the permission for the <strong>Server</string> user are r+w to it');
195 require(AT_INCLUDE_PATH.'footer.inc.php');
199 // Open a read pointer to run through each log date directory getting all the profiles
200 while (($file = readdir($dir)) !== false) {
202 if (($file == '.') || ($file == '..') || is_dir($file)) {
206 if (strpos($file, 'profile') !== false) { // found a profile, store its md5 key identifier
207 $tmp_ = substr($file, strpos($file, '_') + 1);
208 $tmp_ = substr($tmp_, 0, strpos($tmp_, '.log.php'));
209 $log_profiles{$file} = $tmp_;
213 closedir($dir); // clean it up
216 * Open a read pointer to run through each log date directory getting all the bugs associated
217 * all the profiles in $log_profiles
219 if (empty($log_profiles)) {
220 $msg->printNoLookupFeedback('Warning. No profile found in ' . $dir_ . '/' . $val);
221 require(AT_INCLUDE_PATH.'footer.inc.php');
226 foreach ($log_profiles as $elem => $val_) {
229 /* for each profile get the number of bugs associated with it */
230 if (!($dir = opendir($dir_ . '/' . $val))) {
231 $msg->printNoLookupFeedback('Could not access /content/logs' . $val . '. Check that the permission for the <strong>Server</string> user are r+w to it');
232 require(AT_INCLUDE_PATH.'footer.inc.php');
237 while (($file = readdir($dir)) !== false) {
239 // make sure we ignore profiles too!, just look at bug files
240 if( ($file == '.') || ($file == '..') || is_dir($file) || (strpos($file, 'profile') !== false)) {
244 // found a bug that maps to $val_ md5 profile identifer
245 if (strpos($file, $val_) !== false) {
251 // store the amount of bugs associated with profile
252 $log_profiles_bug_count{$val}[$val_] = $count;
254 $log_profiles = array();
257 * At this point ($log_profiles => key) = ($log_profiles_bug_count => key).
259 * Lets print out <td> rows corresponding to all profiles found in the following format:
261 * Profile name, profile date, profile bug count.
263 foreach ($log_profiles_bug_count as $day => $profile) :
264 foreach ($profile as $stamp => $total) :
266 <tr onmousedown="document.form1['<?php echo $stamp.$day; ?>'].checked = !document.form1['<?php echo $stamp.$day; ?>'].checked;">
267 <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>
268 <td><?php echo $day; ?></td>
269 <td><?php echo $total; ?></td>
282 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>