<?
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------------+
// | <G a n e s h a> - Free Web Based Training System                           |
// +----------------------------------------------------------------------------+
// | <G a n e s h a> - Plate-forme de téléformation gratuite et en open source  |
// +----------------------------------------------------------------------------|
// | Copyright (C) 2001-2003  Anéma Formation  <http://www.anema.fr/>           |
// +----------------------------------------------------------------------------+
// |           Developer : Georges CALDEIRA <gcaldeira@anemalab.org>            |
// +----------------------------------------------------------------------------+
// |              Infos on project <http://anemalab.org/>                       |
// +----------------------------------------------------------------------------+
// | 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   |
// +----------------------------------------------------------------------------+

/**
* Page affichage des rqt SQL
*
* @author	Georges Caldeira <gcaldeira@anemalab.org>
* @package	GaneshaCommun
*/
	/**
	* include des fichiers + verification de la cnx
	*/
	include_once("anema.inc.php");

	$file_trace = urldecode($HTTP_GET_VARS['file_trace']);
	
	/**
	* Affiche la trace
	* @access	public
	*/	
	function displayTrace($item,$key) {
		$val = nl2br($item);
		$val = str_replace('<br />','',$val);
		$coul = 'black' ;
		$pos = strpos($val, 'DELETE');
		if (is_integer($pos)) {
			$coul = 'red' ;
		} else {
			$pos = strpos($val, 'UPDATE');
			if (is_integer($pos)) {
				$coul = 'orange' ;
			} else {
				$pos = strpos($val, 'INSERT');
				if (is_integer($pos)) {
					$coul = 'green' ;
				}else {
					$pos = strpos($val, 'SELECT');
					if (is_integer($pos)) {
						$coul = 'blue' ;
					}
				}
			}
		}

		$val = '&nbsp;&nbsp;<li type="square"><span style="font-family: arial; color:'.$coul.'; font-size: 12px" >'.$val.'</span></li><br />';
		put($val);
	}
	
	/**
	* Affiche le debug
	* @access	public
	*/	
	function displayDebug($item,$key) {
		$val = nl2br($item);
		$begin = false ;
		$val = str_replace('<br />','',$val);
		$coul = 'black' ;
		$pos = strpos($val, '[');
		if (is_integer($pos)) {
			$coul = 'blue' ;
			$begin = true ;
		} else {
			$pos = strpos($val, 'HTTP_');
			if (is_integer($pos)) {
				$coul = 'orange' ;
			} else {
				$pos = strpos($val, 'php');
				if (is_integer($pos)) {
					$coul = 'green' ;
				}else {
					$pos = strpos($val, '=>');
					if (is_integer($pos)) {
						$coul = 'black' ;
					}
				}
			}
		}
		if ( $begin ) {
			//$val = '&nbsp;&nbsp;<li type="square"><span style="font-family: arial; color:'.$coul.'; font-size: 12px" >'.$val.'</span></li><br />';
			$val = '<hr>&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: arial; color:'.$coul.'; font-size: 12px" >'.$val.'</span><br />';
		} else {
			$val = '&nbsp;&nbsp;&nbsp;&nbsp;<font style="font-family: arial; color:'.$coul.'; font-size: 12px" >'.$val.'<br>';
		}
		put($val);
	}
		
	if ( file_exists($file_trace) ){
		$contents = file($file_trace);
	} else {
		$contents[]  = '<b>File not found</b>';
	}
	
	InitPageHtml('Audit Ganesha',false)	;
	$titre = basename($file_trace);//"Debug..." ;
	put('
<table width="100%" border="0" cellspacing="0" cellpadding="0" >
  <tr bgcolor="'.$color2.'"><td align="middle"><p class="g_titre">'.$titre.'</p></td></tr>
</table>');
	BR(2);
	if ( $file_trace == RP_TRACE_FILE ) {
		array_walk($contents,'displayTrace');
	} else {
		// afficher le contenu du fichier...
		array_walk($contents,'displayDebug');
	}
	BR(2);
	CloseWindow();
	Footer();
	ClosePageHtml();

?>