<?php
/**
* report generation Class
*/
class report {
/**
* Class Constructor
* @param string $date Full date in 'Ymd' format
* @param string $year Year in 'Y' format
* @param string $year month in 'm' format
* @param string $day month in 'd' format
* @param string $reportDir Final Reports Directory
* @param string $filename Report Filename
* @param string $config_reports_basedir Top Level Reports Directory
*/
public function __construct($config_reports_basedir, $filename, $reportDir, $serverIp) {
$this->log = ADLog::getInstance();
// Set some variables for file and folder creation
$this->date = date('Ymd');
$this->year = date('Y');
$this->month = date('M');
$this->day = date('d');
$this->reportDate = date('D d M Y');
$this->reportDir = $reportDir;
$this->filename = $filename;
$this->reportFolder = $config_reports_basedir . $reportDir . "/";
$this->fullReportPath = $config_reports_basedir . $reportDir . "/". $filename;
$this->serverIp = $serverIp;
}
/**
* create File method
*
*/
public function createFile() {
if($this->existsFile()){
$this->deleteFile();
}
$handle = fopen($this->fullReportPath, 'w');
if(!$handle){
$this->log->Fatal("Cannot open file Func: createFile(): ".$this->fullReportPath."(File: ".$_SERVER['PHP_SELF'].")");
}
}
/**
* delete File method
*
*/
private function deleteFile() {
unlink($this->fullReportPath);
}
/**
* check if File exists method
*
*/
private function existsFile() {
if(file_exists($this->fullReportPath)){
return true;
}
}
/**
* Close File method
*
*/
private function closeFile($handle) {
fclose($handle);
}
/**
* create File HTML header method
*
*/
public function header($title, $reportName, $scriptName, $taskid, $taskStartTime) {
$handle = fopen($this->fullReportPath, 'a');
if(!$handle){
$this->log->Fatal("Cannot open file Func:header() : ".$this->fullReportPath."(File: ".$_SERVER['PHP_SELF'].")");
}
$reportCss = file_get_contents('/home/rconfig/www/css/reportstyle.css');
$compareTableCss = file_get_contents('/home/rconfig/www/css/compareTable.css');
$logo = 'http://'.$this->serverIp.'/images/logos/rconfig96.png';
$data = <<<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>$title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type='text/css'>
$reportCss
$compareTableCss
</style>
</head>
<body>
<div id="wrapper">
<div id="header">
<h1><span id="title">rconfig $title</span></h1>
</div>
<div id="content">
<div style="float: left;" id="summDiv">
<b>Report Name:</b><br/>
<b>Report Date:</b><br/>
<b>ScriptName:</b><br/>
<b>Task ID:</b><br/>
<b>Task Start Time:</b><br/>
<b>Task End Time:</b><br/>
<b>Task Run Time:</b><br/>
</div>
<div style="float: left;" id="summDiv">
$reportName<br/>
$this->reportDate<br/>
$scriptName<br/>
$taskid<br/>
$taskStartTime<br/>
<taskEndTime><br/>
<taskRunTime><br/>
</div>
<div style="float: right;" id="summDiv"><img src="$logo" alt="rConfig" title="rConfig"></div>
<div style="clear:both"> </div>
<hr/>
EOF;
fwrite($handle, $data);
$this->closeFile($handle);
}
/**
* create File body method
*
*/
public function eachData($deviceName, $status, $data) {
$handle = fopen($this->fullReportPath, 'a');
if(!$handle){
$this->log->Fatal("Cannot open file Func:eachData() : ".$this->fullReportPath."(File: ".$_SERVER['PHP_SELF'].")");
}
$data = <<<EOF
<!-- BEGIN DATA APPEND -->
<div>
<table id="hor-zebra" summary="Report Data">
<thead>
<tr>
<th scope="col" colspan="4">Device Name: $deviceName</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Status:</td>
<td colspan="3">$status</td>
</tr>
<tr>
<td>Notice:</td>
<td colspan="3">$data</td>
</tr>
</tbody>
</table>
</div>
<!-- END DATA APPEND -->
EOF;
fwrite($handle, $data);
$this->closeFile($handle);
}
/**
* create File footer HTML method
*
*/
public function footer() {
$handle = fopen($this->fullReportPath, 'a');
if(!$handle){
$this->log->Fatal("Cannot open file Func:footer() : ".$this->fullReportPath."(File: ".$_SERVER['PHP_SELF'].")");
}
$data = <<<EOF
<!-- BEGIN FOOTER APPEND -->
</div>
<div style="clear:both;"></div>
<div id="footer">
End Report - © rConfig
</div>
</div>
</body>
</html>
EOF;
fwrite($handle, $data);
$this->closeFile($handle);
}
public function findReplace($tag1, $tag2) {
$data = file_get_contents($this->fullReportPath);
// do tag replacements or whatever you want
$data = str_replace($tag1, $tag2, $data);
//save it back:
file_put_contents($this->fullReportPath, $data);
}
}
?>