|
ZenCart_Documentation
1.5.0
http://www.collinsharper.com
|
00001 <?php 00015 require ('includes/application_top.php'); 00016 00017 00018 // change destination here for path when using "save to file on server" 00019 if (! defined('DIR_FS_ADMIN_ACTIVITY_EXPORT')) define('DIR_FS_ADMIN_ACTIVITY_EXPORT', DIR_FS_ADMIN . 'backups/'); 00020 00021 $action = (isset($_GET['action']) ? $_GET['action'] : ''); 00022 $start = (isset($_GET['s']) ? (int)$_GET['s'] : 0); 00023 $perpage = (isset($_GET['p']) ? (int)$_GET['p'] : 50); 00024 $available_export_formats[0] = array('id' => '0' , 'text' => 'Export as HTML (ideal for on-screen viewing)', 'format' => 'HTML'); // review on screen 00025 $available_export_formats[1] = array('id' => '1' , 'text' => 'Export to CSV (ideal for importing to spreadsheets)', 'format' => 'CSV'); // export to CSV 00026 // $available_export_formats[2]=array('id' => '2', 'text' => 'Export to TXT', 'format' => 'TXT'); 00027 // $available_export_formats[3]=array('id' => '3', 'text' => 'Export to XML', 'format' => 'XML'); 00028 $save_to_file_checked = (isset($_POST['savetofile']) && zen_not_null($_POST['savetofile']) ? $_POST['savetofile'] : 0); 00029 $post_format = (isset($_POST['format']) && zen_not_null($_POST['format']) ? $_POST['format'] : 1); 00030 $format = $available_export_formats[$post_format]['format']; 00031 $file = (isset($_POST['filename']) ? preg_replace('/[^\w\.-]/', '', $_POST['filename']) : 'admin_activity_archive_' . date('Y-m-d_H-i-s') . '.csv'); 00032 00033 zen_set_time_limit(600); 00034 00035 if ($action != '') 00036 { 00037 $NL = "\n"; 00038 $limit = ''; 00039 if ($perpage > 0 || $start > 0) 00040 { 00041 $limit = ' LIMIT '; 00042 if ($start > 0) $limit .= (int)$start; 00043 if ($start > 0 && $perpage > 0) $limit .= ', '; 00044 if ($perpage > 0) $limit .= (int)$perpage; 00045 } 00046 $sort = ''; 00047 00048 switch ($action) 00049 { 00050 case 'save': 00051 global $db; 00052 if ($format == 'CSV') 00053 { 00054 $FIELDSTART = '"'; 00055 $FIELDEND = '"'; 00056 $FIELDSEPARATOR = ','; 00057 $LINESTART = ''; 00058 $LINEBREAK = "\n"; 00059 $sort = ' ASC '; 00060 $limit = ''; 00061 } 00062 if ($format == 'TXT') 00063 { 00064 $FIELDSTART = ''; 00065 $FIELDEND = ''; 00066 $FIELDSEPARATOR = "\t"; 00067 $LINESTART = ''; 00068 $LINEBREAK = "\n"; 00069 $sort = ' ASC '; 00070 } 00071 if ($format == 'HTML') 00072 { 00073 $FIELDSTART = '<td>'; 00074 $FIELDEND = '</td>'; 00075 $FIELDSEPARATOR = ""; 00076 $LINESTART = "<tr>"; 00077 $LINEBREAK = "</tr>" . $NL; 00078 $sort = ' DESC '; 00079 } 00080 $sql = "select a.access_date, a.admin_id, u.admin_name, a.ip_address, a.page_accessed, a.page_parameters, a.gzpost, a.flagged, a.attention 00081 FROM " . TABLE_ADMIN_ACTIVITY_LOG . " a LEFT OUTER JOIN " . TABLE_ADMIN . " u ON a.admin_id = u.admin_id ORDER BY access_date " . $sort . $limit; 00082 $result = $db->Execute($sql); 00083 $records = $result->RecordCount(); 00084 if ($records == 0) 00085 { 00086 $messageStack->add("No Records Found.", 'error'); 00087 } else 00088 { //process records 00089 $i = 0; 00090 // make a <table> tag if HTML output 00091 if ($format == "HTML") 00092 { 00093 $exporter_output .= '<table border="1">' . $NL; 00094 } 00095 // add column headers if CSV or HTML format 00096 if ($format == "CSV" || $format == "HTML") 00097 { 00098 $exporter_output .= $LINESTART; 00099 $exporter_output .= $FIELDSTART . "timestamp" . $FIELDEND; 00100 $exporter_output .= $FIELDSEPARATOR; 00101 $exporter_output .= $FIELDSTART . "admin_user" . $FIELDEND; 00102 $exporter_output .= $FIELDSEPARATOR; 00103 $exporter_output .= $FIELDSTART . "ip_address" . $FIELDEND; 00104 $exporter_output .= $FIELDSEPARATOR; 00105 $exporter_output .= $FIELDSTART . "page_accessed" . $FIELDEND; 00106 $exporter_output .= $FIELDSEPARATOR; 00107 $exporter_output .= $FIELDSTART . "parameters" . $FIELDEND; 00108 $exporter_output .= $FIELDSEPARATOR; 00109 $exporter_output .= $FIELDSTART . "flagged" . $FIELDEND; 00110 $exporter_output .= $FIELDSEPARATOR; 00111 $exporter_output .= $FIELDSTART . "attention" . $FIELDEND; 00112 $exporter_output .= $FIELDSEPARATOR; 00113 $exporter_output .= $FIELDSTART . "postdata" . $FIELDEND; 00114 $exporter_output .= $LINEBREAK; 00115 } 00116 // headers - XML 00117 if ($format == "XML") 00118 { 00119 $exporter_output .= '<?xml version="1.0" encoding="' . CHARSET . '"?>' . "\n"; 00120 } 00121 // output real data 00122 while (! $result->EOF) 00123 { 00124 $i ++; 00125 $postoutput = ''; 00126 if ($format == "XML") 00127 { 00128 $postoutput = nl2br(print_r(json_decode(@gzinflate($result->fields['gzpost'])), true)); 00129 $exporter_output .= "<admin_activity_log>\n"; 00130 $exporter_output .= " <row>\n"; 00131 $exporter_output .= " <access_date>" . $result->fields['access_date'] . "</access_date>\n"; 00132 $exporter_output .= " <admin_id>" . $result->fields['admin_id'] . "</admin_id>\n"; 00133 $exporter_output .= " <admin_name>" . htmlspecialchars($result->fields['admin_name']) . "</admin_name>\n"; 00134 $exporter_output .= " <ip_address>" . $result->fields['ip_address'] . "</ip_address>\n"; 00135 $exporter_output .= " <page_accessed>" . $result->fields['page_accessed'] . "</page_accessed>\n"; 00136 $exporter_output .= " <page_parameters>" . htmlspecialchars($result->fields['page_parameters']) . "</page_parameters>\n"; 00137 $exporter_output .= " <flagged>" . htmlspecialchars($result->fields['flagged']) . "</flagged>\n"; 00138 $exporter_output .= " <attention>" . htmlspecialchars($result->fields['attention']) . "</attention>\n"; 00139 $exporter_output .= " <postdata>" . $postoutput . "</postdata>\n"; 00140 $exporter_output .= " </row>\n"; 00141 } else 00142 { // output non-XML data-format 00143 $postoutput = print_r(json_decode(@gzinflate($result->fields['gzpost'])), true); 00144 if ($format == 'HTML') { 00145 $postoutput = nl2br(zen_output_string_protected($postoutput)); 00146 } else { 00147 $postoutput = nl2br($postoutput); 00148 } 00149 $exporter_output .= $LINESTART; 00150 $exporter_output .= $FIELDSTART . $result->fields['access_date'] . $FIELDEND; 00151 $exporter_output .= $FIELDSEPARATOR; 00152 $exporter_output .= $FIELDSTART . $result->fields['admin_id'] . ' ' . $result->fields['admin_name'] . $FIELDEND; 00153 $exporter_output .= $FIELDSEPARATOR; 00154 $exporter_output .= $FIELDSTART . $result->fields['ip_address'] . $FIELDEND; 00155 $exporter_output .= $FIELDSEPARATOR; 00156 $exporter_output .= $FIELDSTART . $result->fields['page_accessed'] . $FIELDEND; 00157 $exporter_output .= $FIELDSEPARATOR; 00158 $exporter_output .= $FIELDSTART . $result->fields['page_parameters'] . $FIELDEND; 00159 $exporter_output .= $FIELDSEPARATOR; 00160 $exporter_output .= $FIELDSTART . $result->fields['flagged'] . $FIELDEND; 00161 $exporter_output .= $FIELDSEPARATOR; 00162 $exporter_output .= $FIELDSTART . $result->fields['attention'] . $FIELDEND; 00163 $exporter_output .= $FIELDSEPARATOR; 00164 $exporter_output .= $FIELDSTART . $postoutput . $FIELDEND; 00165 $exporter_output .= $LINEBREAK; 00166 } 00167 $result->MoveNext(); 00168 } 00169 if ($format == "HTML") 00170 { 00171 $exporter_output .= $NL . "</table>"; 00172 } 00173 if ($format == "XML") 00174 { 00175 $exporter_output .= "</admin_activity_log>\n"; 00176 } 00177 // theoretically, $i should == $records at this point. 00178 // status message 00179 if ($format != "HTML") $messageStack->add($records . TEXT_PROCESSED, 'success'); 00180 // begin streaming file contents 00181 if ($save_to_file_checked != 1) 00182 { // not saving to a file, so do regular output 00183 if ($format == "CSV" || $format == "TXT" || $format == "XML") 00184 { 00185 if ($format == "CSV" || $format == "TXT") 00186 { 00187 $content_type = 'text/x-csv'; 00188 } elseif ($format == "XML") 00189 { 00190 $content_type = 'text/xml; charset=' . CHARSET; 00191 } 00192 if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) 00193 { 00194 header('Content-Type: application/octetstream'); 00195 // header('Content-Type: '.$content_type); 00196 // header('Content-Disposition: inline; filename="' . $file . '"'); 00197 header('Content-Disposition: attachment; filename=' . $file); 00198 header("Expires: Mon, 26 Jul 2001 05:00:00 GMT"); 00199 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 00200 header("Cache-Control: must_revalidate, post-check=0, pre-check=0"); 00201 header("Pragma: public"); 00202 header("Cache-control: private"); 00203 } else 00204 { 00205 header('Content-Type: application/x-octet-stream'); 00206 // header('Content-Type: '.$content_type); 00207 header('Content-Disposition: attachment; filename=' . $file); 00208 header("Expires: Mon, 26 Jul 2001 05:00:00 GMT"); 00209 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 00210 header("Pragma: no-cache"); 00211 } 00212 echo $exporter_output; 00213 exit(); 00214 } else 00215 { 00216 // HTML 00217 ?> 00218 <!doctype html> 00219 <html <?php echo HTML_PARAMS; ?>> 00220 <head> 00221 <meta charset="<?php echo CHARSET; ?>"> 00222 <title><?php echo TITLE; ?></title> 00223 <link rel="stylesheet" type="text/css" href="includes/stylesheet.css"> 00224 </head> 00225 <body> 00226 <?php 00227 echo $exporter_output; 00228 ?> 00229 </body> 00230 </html> 00231 <?php 00232 exit(); 00233 } 00234 } else 00235 { //write to file 00236 //open output file for writing 00237 $f = fopen(DIR_FS_ADMIN_ACTIVITY_EXPORT . $file, 'w'); 00238 if ($f) { 00239 fwrite($f, $exporter_output); 00240 fclose($f); 00241 //open output file for readback 00242 $readback = file_get_contents(DIR_FS_ADMIN_ACTIVITY_EXPORT . $file); 00243 } 00244 if ($readback !== FALSE && $readback == $exporter_output) { 00245 $messageStack->add_session(SUCCESS_EXPORT_ADMIN_ACTIVITY_LOG . $file, 'success'); 00246 } else { 00247 $messageStack->add_session(FAILURE_EXPORT_ADMIN_ACTIVITY_LOG . $file, 'error'); 00248 } 00249 unset($f); 00250 } // endif $save_to_file 00251 } //end if $records for processing not 0 00252 zen_redirect(zen_href_link(FILENAME_ADMIN_ACTIVITY)); 00253 break; 00254 00255 // clean out the admin_activity_log 00256 case 'clean_admin_activity_log': 00257 if (isset($_POST['confirm']) && $_POST['confirm'] == 'yes') 00258 { 00259 $db->Execute("truncate table " . TABLE_ADMIN_ACTIVITY_LOG); 00260 $admname = '{' . preg_replace('/[^\w]/', '*', zen_get_admin_name()) . '[' . (int)$_SESSION['admin_id'] . ']}'; 00261 $sql_data_array = array( 'access_date' => 'now()', 00262 'admin_id' => (isset($_SESSION['admin_id'])) ? (int)$_SESSION['admin_id'] : 0, 00263 'page_accessed' => 'Log reset by ' . $admname . '.', 00264 'page_parameters' => '', 00265 'ip_address' => substr($_SERVER['REMOTE_ADDR'],0,15) 00266 ); 00267 zen_db_perform(TABLE_ADMIN_ACTIVITY_LOG, $sql_data_array); 00268 $messageStack->add_session(SUCCESS_CLEAN_ADMIN_ACTIVITY_LOG, 'success'); 00269 unset($_SESSION['reset_admin_activity_log']); 00270 zen_redirect(zen_href_link(FILENAME_ADMIN_ACTIVITY)); 00271 } else { 00272 $confirmation_needed = TRUE; 00273 } 00274 break; 00275 00276 } //end switch / case 00277 } //endif $action 00278 ?> 00279 <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"> 00280 <html <?php 00281 echo HTML_PARAMS; 00282 ?>> 00283 <head> 00284 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>"> 00285 <title><?php echo TITLE; ?></title> 00286 <link rel="stylesheet" type="text/css" href="includes/stylesheet.css"> 00287 <link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS"> 00288 <script language="javascript" src="includes/menu.js"></script> 00289 <script language="javascript" src="includes/general.js"></script> 00290 <script type="text/javascript"> 00291 <!-- 00292 function init() 00293 { 00294 cssjsmenu('navbar'); 00295 if (document.getElementById) 00296 { 00297 var kill = document.getElementById('hoverJS'); 00298 kill.disabled = true; 00299 } 00300 } 00301 // --> 00302 </script> 00303 </head> 00304 <body onload="init()"> 00305 <!-- header //--> 00306 <?php 00307 require (DIR_WS_INCLUDES . 'header.php'); 00308 ?> 00309 <!-- header_eof //--> 00310 00311 <!-- body //--> 00312 <table border="0" width="100%" cellspacing="2" cellpadding="2"> 00313 <tr> 00314 <!-- body_text //--> 00315 <td width="100%" valign="top"> 00316 <table border="0" width="100%" cellspacing="0" cellpadding="0"> 00317 <tr> 00318 <td width="100%"> 00319 <table border="0" width="100%" cellspacing="0" cellpadding="0"> 00320 <tr> 00321 <td class="pageHeading"><?php echo HEADING_TITLE; ?></td> 00322 <td class="pageHeading" align="right"><?php echo zen_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td> 00323 </tr> 00324 </table> 00325 </td> 00326 </tr> 00327 <tr> 00328 <td><?php echo zen_draw_separator('pixel_trans.gif', '1', '10'); ?></td> 00329 </tr> 00330 00331 <?php if ($action == '') { ?> 00332 <tr><?php echo zen_draw_form('export', FILENAME_ADMIN_ACTIVITY, 'action=save', 'post'); //, 'onsubmit="return check_form(export);"'); ?> 00333 <td align="center"> 00334 <table border="0" cellspacing="0" cellpadding="2"> 00335 <tr><td><h2><?php echo HEADING_SUB1; ?></h2></td></tr> 00336 <tr> 00337 <td class="main" colspan="2"><?php echo TEXT_INSTRUCTIONS; ?></td> 00338 </tr> 00339 <tr> 00340 <td class="main"><strong><?php echo TEXT_ACTIVITY_EXPORT_FORMAT; ?></strong><br /><?php echo zen_draw_pull_down_menu('format', $available_export_formats, $format); ?></td> 00341 </tr> 00342 <tr> 00343 <td colspan="2"><?php echo zen_draw_separator('pixel_trans.gif', '1', '10'); ?></td> 00344 </tr> 00345 <tr> 00346 <td class="main"><strong><?php echo TEXT_ACTIVITY_EXPORT_FILENAME; ?></strong><br /><?php echo zen_draw_input_field('filename', htmlspecialchars($file, ENT_COMPAT, CHARSET, TRUE), ' size="60"'); ?></td> 00347 </tr> 00348 <tr> 00349 <td colspan="2"><?php echo zen_draw_separator('pixel_trans.gif', '1', '10'); ?></td> 00350 </tr> 00351 <tr> 00352 <td class="main"><?php echo zen_draw_checkbox_field('savetofile', '1', $save_to_file_checked); ?> <strong><?php echo TEXT_ACTIVITY_EXPORT_SAVETOFILE; ?></strong><br /> 00353 <strong><?php echo TEXT_ACTIVITY_EXPORT_DEST; ?></strong> <em><?php echo DIR_FS_ADMIN_ACTIVITY_EXPORT; ?></em> 00354 </td> 00355 </tr> 00356 <tr> 00357 <td class="main" align="right"><?php echo zen_image_submit('button_go.gif', IMAGE_GO) . ' <a href="' . zen_href_link(FILENAME_ADMIN_ACTIVITY) . '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; ?></td> 00358 </tr> 00359 </table> 00360 </td> 00361 </form> 00362 </tr> 00363 00364 <!-- bof: reset admin_activity_log --> 00365 <tr> 00366 <td align="center"><table border="0" cellspacing="0" cellpadding="2"> 00367 <tr><td><h2><?php echo HEADING_SUB2; ?></h2></td></tr> 00368 <tr> 00369 <td class=<?php echo ($_SESSION['reset_admin_activity_log'] == true ? "alert" : "main"); ?> align="left" valign="top"><?php echo TEXT_INFO_ADMIN_ACTIVITY_LOG; ?></td> 00370 <td class="main" align="right" valign="middle"><?php echo '<a href="' . zen_href_link(FILENAME_ADMIN_ACTIVITY, 'action=clean_admin_activity_log') . '">' . zen_image_button('button_reset.gif', IMAGE_RESET) . '</a>'; ?></td> 00371 </tr> 00372 </table></td> 00373 </tr> 00374 <!-- eof: reset admin_activity_log --> 00375 00376 <?php } elseif ($confirmation_needed) { ?> 00377 <tr><td><?php echo TEXT_ADMIN_LOG_PLEASE_CONFIRM_ERASE; ?><?php echo zen_draw_form('admin_activity_erase', FILENAME_ADMIN_ACTIVITY, 'action=clean_admin_activity_log'); echo zen_image_submit('button_reset.gif', IMAGE_RESET); ?><input type="hidden" name="confirm" value="yes" /></form></td></tr> 00378 00379 <?php } ?> 00380 <!-- body_text_eof //--> 00381 </table> 00382 <!-- body_eof //--> <!-- footer //--> 00383 <?php require (DIR_WS_INCLUDES . 'footer.php'); ?> 00384 <!-- footer_eof //--> <br /> 00385 00386 </body> 00387 </html> 00388 <?php require (DIR_WS_INCLUDES . 'application_bottom.php'); ?>