registerFunction("SaveMTemplate"); $xajax->registerFunction("DeleteTemplate"); $xajax->registerFunction("ClearTheData"); $xajax->registerFunction("DeleteLogs"); session_start(); $user = $_SESSION['user']; $in_xAjax = false; // This is the flag to let things know we are in an xAjax function $xAjax_objResponse; // The object that is returned from the xAjax function - MUST BE DEFINED GLOBALLY include('main_inc.htm'); include('user_inc.htm'); define('TEMPLATE_FILE', '/home/embedded/library/CoreService/dat/ARMTemplates'); define('TEMPLATE_FILE_T', '/home/embedded/library/CoreService/dat/ARMTemplatesT'); class CARMTemplate { var $name; var $range; var $at_bc; var $at_sn; var $at_at; var $group; var $sort; var $chart; var $type; var $selBy; function CARMTemplate( $name, $range, $at_bc, $at_sn, $at_at, $sort, $group, $selBy, $chart, $type ) { $this->name = $name; $this->range = $range; $this->attrib = $attrib; $this->sort = $sort; $this->group = $group; $this->chart = $chart; $this->type = $type; $this->selBy = $selBy;// Only used if Group is a Select By one } }; /////////////////////////////////////////////////////////////////// // Save the configration passed in to the tamplate name passed in /////////////////////////////////////////////////////////////////// function SaveMTemplate( $name, $SelTemplate ) { global $in_xAjax; global $xAjax_objResponse; $user = $_SESSION['user']; $xAjax_objResponse = new xajaxResponse(); $in_xAjax = true; error_log("Saving a new Template"); error_log("SelTemplate = ". print_r($SelTemplate, true) ); $fh = @fopen( TEMPLATE_FILE, 'a' ); if( $fh == false ) { error_log( "Could not open file for writing."); // error_back(); } else { $myArray = array(); $myArray[] = $name; error_log("name = ". $name ); error_log("$myArray[0] = ". $myArray[0] ); $myArray = array_merge($myArray, $SelTemplate); error_log("myArray = ". print_r($myArray,true) ); $myData = implode(",", $myArray); error_log("myData = ". $myData); $myData .= "\n"; error_log("Writting to file: ". $myData); $bytesWritten = fputs( $fh, $myData ); fclose($fh); } return $xAjax_objResponse; } /////////////////////////////////////////////////////////////////// // Delete the template passed in /////////////////////////////////////////////////////////////////// function DeleteTemplate( $name ) { global $in_xAjax; global $xAjax_objResponse; $user = $_SESSION['user']; $xAjax_objResponse = new xajaxResponse(); $in_xAjax = true; error_log("\n\n\Delete a Template"); $buffersize = 1*(256); // 256 char chunks $buffer = ''; // We need to have the system create the temp file so we can chmod it beofre using it. $sRet = system("/usr/bin/cmdwrap -NO_END_OF_FILE touch ".TEMPLATE_FILE_T, $iRet); error_log("Call to system (touch) returned a \"$iRet\" and the output was \"$sRet\""); $sRet = system("/usr/bin/cmdwrap -NO_END_OF_FILE chmod 666 ".TEMPLATE_FILE_T, $iRet); error_log("Call to system (chmod) returned a \"$iRet\" and the output was \"$sRet\""); error_log("We are using the following file names: ". TEMPLATE_FILE ." and ".TEMPLATE_FILE_T); $fh = @fopen( TEMPLATE_FILE, 'r' ); if( $fh == false ) { error_log( "Could not open file for reading."); error_back(0x0b); } else { $fhT = @fopen( TEMPLATE_FILE_T, 'w' ); if( $fhT == false ) { error_log( "Could not open file for writing."); error_back(0x0b); } $i = 0; $j = 0; while ( !feof( $fh ) ) { $buffer = fgets( $fh, $buffersize ); $tData = split(",", $buffer ); if( $tData[0] == "" ) continue; // The last one seems to be blank - pass it up bit let the loop end normally if( $tData[0] == $name ) { // This is the one we want to delete continue; } fwrite( $fhT, $buffer ); } fclose($fh); fclose($fhT); // Now delete the OLD and rename the new $sRet = system("/usr/bin/cmdwrap -NO_END_OF_FILE rm -f ".TEMPLATE_FILE, $iRet); error_log("Call to system (rm TEMPLATE_FILE) returned a \"$iRet\" and the output was \"$sRet\""); $sRet = system("/usr/bin/cmdwrap -NO_END_OF_FILE mv -f ".TEMPLATE_FILE_T." ".TEMPLATE_FILE, $iRet); error_log("Call to system (mv TEMPLATE_FILE_T) returned a \"$iRet\" and the output was \"$sRet\""); } return $xAjax_objResponse; } /////////////////////////////////////////////////////////////////////// // Clear the php data so the data will be read from scratch next load. /////////////////////////////////////////////////////////////////////// function ClearTheData() { global $in_xAjax; global $xAjax_objResponse; $user = $_SESSION['user']; $xAjax_objResponse = new xajaxResponse(); $in_xAjax = true; unset($_SESSION['ARM_psn']); return $xAjax_objResponse; } ///////////////////////////////////////////////////////////////////// // Delete all the Advanced reporting Data. // This will Delete all TApeAlertLog and DriveLog files and archives. // New blank files wil be create to accept new logs from this point. ///////////////////////////////////////////////////////////////////// function DeleteLogs() { global $in_xAjax; global $xAjax_objResponse; $user = $_SESSION['user']; $xAjax_objResponse = new xajaxResponse(); $in_xAjax = true; error_log("===================================================== Rolling the logs..."); // First roll the AR logs so the main one is empty roll_logs($user, false, true); // Now delete all the archive files. $sRet = system("/usr/bin/cmdwrap -NO_END_OF_FILE rm -f /home/embedded/library/CoreService/dat/DriveLog.*", $iRet); error_log("Call to system (rm DriveLog.*) returned a \"$iRet\" and the output was \"$sRet\""); $sRet = system("/usr/bin/cmdwrap -NO_END_OF_FILE rm -f /home/embedded/library/CoreService/dat/TapeAlertLog.*", $iRet); error_log("Call to system (rm DriveLog.*) returned a \"$iRet\" and the output was \"$sRet\""); return $xAjax_objResponse; } // This call must come AFTER ALL xajax functions have been defined. // This is what connects the php functions with the JavaScript functions. $xajax->processRequest(); include("ms_advanced_reporting_common.htm"); // Get the string and timestamp of the library's date so we use the library's clock even in JavaScript when needed. $sLibDate = date('m/d/Y',time()); $iLibDate = time(); error_log("Today is ".$sLibDate." (".$iLibDate.")" ); // A line of the file looks like: // 12/22/2007 12:56:59,12/22/2007 12:56:17,0,2,1210143187,rdt2,0,0,2,000158L3 ?>
$xajax->printJavascript(); ?>