Location: PHPKode > scripts > objectStatus > objectstatus/objectstatus.class.php
<?php
// objectStatus 1.0
// Copyright (c) 2003 by Alexander Serbe. All rights reserved.
// ---------------------------------------------------------------------------------
// Version:        1.0
// Date:           24 May 2003
// ---------------------------------------------------------------------------------
// Author:         Alexander Serbe (hide@address.com)
// Contributor(s): 
// ---------------------------------------------------------------------------------
// Requirements:   PHP4
// ---------------------------------------------------------------------------------
// License:        GNU General Public License (http://www.gnu.org/licenses/gpl.html)
// ---------------------------------------------------------------------------------
// This program is free software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE.  See the GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along with this
// program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
// Suite 330, Boston, MA  02111-1307  USA.
// ---------------------------------------------------------------------------------
// Dieses Programm ist freie Software. Sie können es unter den Bedingungen der GNU
// General Public License, wie von der Free Software Foundation veröffentlicht,
// weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder (nach
// Ihrer Option) jeder späteren Version. 
// Die Veröffentlichung dieses Programms erfolgt in der Hoffnung, daß es Ihnen von
// Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne die implizite Garantie
// der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Details finden
// Sie in der GNU General Public License. 
// Sie sollten eine Kopie der GNU General Public License zusammen mit diesem Programm
// erhalten haben. Falls nicht, schreiben Sie an die Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
// ---------------------------------------------------------------------------------
// Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon les
// termes de la Licence Publique Générale GNU publiée par la Free Software
// Foundation (version 2 ou bien toute autre version ultérieure choisie par vous).
// Ce programme est distribué car potentiellement utile, mais SANS AUCUNE GARANTIE,
// ni explicite ni implicite, y compris les garanties de commercialisation ou
// d'adaptation dans un but spécifique. Reportez-vous à la Licence Publique Générale
// GNU pour plus de détails. 
// Vous devez avoir reçu une copie de la Licence Publique Générale GNU en même temps
// que ce programme ; si ce n'est pas le cas, écrivez à la Free Software Foundation,
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, États-Unis.
// ---------------------------------------------------------------------------------

class objectStatus
{
	// Initialize object variables -------------------------------------------------
	var $status;					// Array. Status messages.
	
	function objectStatus ()
	{ // 0.1; 0.2 ---------------------------------------------------- Constructor -
		$this->status = array ();
		$this->statusMessage ( "objectStatus", "", "Object initialized.", 1 );
	} // objectStatus -------------------------------------------------------- END -
	
	function sendStatus ( $recipient, $subject, $cc="", $bcc="" )
	{ // 0.2 -------------------------------------------------------------- Public -
		if ( count ( $this->status ) <= 0 )
			return false;
		
		$message = "Status log generated " . date ( 'd M Y, H:i:s' ) . ".\n\n";
		for ( $i=0; $i<count ( $this->status ); $i++ )
		{
			$message .= $this->status[$i][0] . ": ";
			$message .= $this->status[$i][1] . "; ";
			$message .= $this->status[$i][2];
			( $this->status[$i][3] ) ? $message .= "." . $this->status[$i][3] : 0;
			$message .= " - ";
			( $this->status[$i][4] ) ? $message .= $this->status[$i][4] . ". " : 0;
			( $this->status[$i][6] ) ? $message .= $this->status[$i][6] : 0;
			( $this->status[$i][5] ) ? $message .= " (" . $this->status[$i][5] . ")" : 0;
		}
		
		$headers = "";
		( $cc ) ? $headers .= "CC: $cc\r\n" : 0;
		( $bcc ) ? $headers .= "BCC: $bcc\r\n" : 0;
		
		$ret =  @mail ( $recipient, $subject, $message, $headers );
		
		return $ret;
	} // sendStatus ---------------------------------------------------------- END -
	
	function statusLog ( $file, $mode=1, $reset=0 )
	{ // 0.1; 0.2 --------------------------------------------------------- Public -
		if ( count ( $this->status ) <= 0 )
			return false;
		
		$status_content = $this->statusPrintout ( "csv" );
		
		( $mode == 1 ) ? $fp = fopen ( $file, "w" ) : $fp = fopen ( $file, "a" );
		$check = fputs ( $fp, $status_content );
		fclose ( $fp );
		
		( $reset == 1 ) ? $this->statusReset () : 0;
		
		return $check;
	} // statusLog ----------------------------------------------------------- END -
	
	function statusMessage ( $object, $method="", $msg="", $type=1, $error_num="" )
	{ // 0.1; 0.2 --------------------------------------------------------- Public -
		$ip = getenv ( "REMOTE_ADDR" );
		$x = explode ( " ", microtime () );
		$ms = $x[0];
		$time = $x[1];
		$y = date ( 'd M Y, H:i:s', $time );
		$z = $y . substr ( $ms, 1, 7 );
		$this->status[] = array ( $z, $ip, $object, $method, $msg, $type, $error_num );
	} // statusMessage ------------------------------------------------------- END -
	
	function statusPrintout ( $type="table", $reset=0, $template="" )
	{ // 0.1; 0.2 --------------------------------------------------------- Public -
		if ( count ( $this->status ) <= 0 )
			return false;
		
		if ( $type == "table" )
		{
			if ( $template )
			{
				if ( !file_exists ( $template ) )
					return false;
				$fp = fopen ( $template, "r" );
				$html = fread ( $fp, filesize ( $template ) );
				fclose ( $fp );
				if ( strlen ( $html ) <= 0 )
					return false;
				preg_match ( "/<!-- rs:start -->(.*?)<!-- rs:end -->/si", $html, $rs );
				$recordset = $rs[2];
				if ( strlen ( $recordset ) <= 9 )
					return false;
				$records = "";
				for ( $i=0; $i<count ( $this->status ); $i++ )
				{
					$x = $recordset;
					$x = str_replace ( "<!-- time -->", $this->status[$i][0], $x );
					$x = str_replace ( "<!-- ip -->", $this->status[$i][1], $x );
					$x = str_replace ( "<!-- object -->", $this->status[$i][2], $x );
					$x = str_replace ( "<!-- method -->", $this->status[$i][3], $x );
					( $this->status[$i][5] == 1 ) ? $msg_line = $this->status[$i][4] : 0;
					( $this->status[$i][5] == 2 ) ? $msg_line = "Error: " . $this->status[$i][4] : 0;
					( $this->status[$i][5] == 3 ) ? $msg_line = "Warning: " . $this->status[$i][4] : 0;
					( $this->status[$i][5] == 2 && $this->status[$i][6] ) ? $msg_line .= " (" . $this->status[$i][6] . ")" : 0;
					$x = str_replace ( "<!-- messgage -->", $msg_line, $x );
					$records .= $x;
				}
				$html = str_replace ( $recordset, $x, $html );
				preg_match_all ( "/<!--(.*?)-->/si", $html, $f );
				foreach ( $f[0] as $tmp )
					$html = str_replace ( $tmp, "", $html );
				( $reset == 1 ) ? $this->statusReset () : 0;
				return $html;
			}
			else
			{
				$html = '<table border="1" cellpadding="3" cellspacing="2">';
				$html .= '<tr><th>Time</th><th>IP</th><th>Object</th><th>Method</th><th>Message</th></tr>';
				for ( $i=0; $i<count ( $this->status ); $i++ )
				{
					( $this->status[$i][5] == 1 ) ? $msg_line = $this->status[$i][4] : 0;
					( $this->status[$i][5] == 2 ) ? $msg_line = "Error: " . $this->status[$i][4] : 0;
					( $this->status[$i][5] == 3 ) ? $msg_line = "Warning: " . $this->status[$i][4] : 0;
					( $this->status[$i][5] == 2 && $this->status[$i][6] ) ? $msg_line .= " (" . $this->status[$i][6] . ")" : 0;
					
					$html .= '<tr><td>' . $this->status[$i][0] . '</td>';
					$html .= '<td>' . $this->status[$i][1] . '</td>';
					$html .= '<td>' . $this->status[$i][2] . '</td>';
					$html .= '<td>' . $this->status[$i][3] . '</td>';
					$html .= '<td>' . $msg_line .'</td></tr>';
				}
				$html .= '</table>';
				( $reset == 1 ) ? $this->statusReset () : 0;
				return $html;
			}
			return false;
		}
		elseif ( $type == "csv" )
		{
			$csv = "";
			for ( $i=0; $i<count ( $this->status ); $i++ )
			{
				$csv .= $this->status[$i][0] . ";";
				$csv .= $this->status[$i][1] . ";";
				$csv .= $this->status[$i][2] . ";";
				$csv .= $this->status[$i][3] . ";";
				$csv .= $this->status[$i][4] . ";";
				$csv .= $this->status[$i][5] . ";";
				$csv .= $this->status[$i][6] . "\n";
			}
			( $reset == 1 ) ? $this->statusReset () : 0;
			return $csv;
		}
		
		return false;
	} // statusPrintout ------------------------------------------------------ END -
	
	function statusReset ()
	{ // 0.1 ------------------------------------------------------------- Private -
		$this->status = array ();
	} // statusReset --------------------------------------------------------- END -
}
?>
Return current item: objectStatus