<?php
 /* Return un fichier à mosssil sur les bug rencontrée
 le niveau defini le niveau des information renvoyé.
 Dans tous les cas ne renvoye aucun mot de passe ou acces enregistré type sql, ftp, etc..
 Demande d'un completement d'info
 return uniquyment touts les include, require, contante et les vars (POST, GET, ... ) + le nom de la page et l'action en cours + detail
 niv: 	0 > normal tous les retours
	1 > Sans Post
	2 > Sans constante, Require , Post */
function signal_bug($niv=2,$screen=false,$comment=false) {
	$sortie=array();
	$laso='';
	$aff='';
	$br='<br />';
	$file=REP_TMP.'bug_'.date("YmdHis").'.bug';
	$g=fopen(ADD_PATH_ADMIN.$file,'w');
	## PARAMETRE GENERAUX
		$z = ' /* ---------------------------- Les SERVER ---------------------------- */ '."\n";
		 if ($screen !=false) echo $z;
		 fwrite($g, $z);
		if ($screen !=false)   echo $br;
		 $e=$_SERVER;
		if ($screen !=false)    echo count($e)."\n";
		if ($screen !=false)   echo $br;
		while ($r = each($e))
			fwrite($g, ' $BUG[\'SERVER\'][\''.$r['key'].'\'] = \''.$r['value'].'\' ;'."\n");

		$z = ' /* ---------------------------- Les SERVER ARGV---------------------------- */ '."\n";
		if ($screen !=false) echo $z;
		 fwrite($g, $z);
		if ($screen !=false)   echo $br;
		 $e=$_SERVER['argv'];
		if ($screen !=false)    echo count($e)."\n";
		if ($screen !=false)   echo $br;
		while ($r = each($e))
			fwrite($g, ' $BUG[\'SERVER_ARGV\'][\''.$r['key'].'\'] = \''.addslashes($r['value']).'\' ;'."\n");

	if ($niv<2) {
		$z = ' /* ---------------------------- Les Constantes ---------------------------- */ '."\n";
		if ($screen !=false) echo $z;
		 fwrite($g, $z);
		if ($screen !=false)   echo $br;
		 $e=get_defined_constants();
		if ($screen !=false)    echo count($e)."\n";
		if ($screen !=false)   echo $br;
		while ($r = each($e)){
			$laso .= ' $BUG[\'CONSTANTE\'][\''.$r['key'].'\'] = \''.addslashes($r['value']).'\' ;'."<br />";
			fwrite($g, ' $BUG[\'CONSTANTE\'][\''.$r['key'].'\'] = \''.addslashes($r['value']).'\' ;'."\n" );
		}
	}
	if ($niv<2) {
		## Toutes les EREUIRE+INCLUDE
		$z = ' /* ---------------------------- Les REQUIRE ---------------------------- */ '."\n";
		if ($screen !=false) echo $z;
		 fwrite($g, $z);
		 echo $br;
		 $e=get_required_files();
		if ($screen !=false)    echo count($e)."\n";
		if ($screen !=false)   echo $br;
		while ($r = each($e))
			fwrite($g, ' $BUG[\'REQUIRE\'][\''.$r['key'].'\'] = \''.addslashes($r['value']).'\' ;'."\n");
	}

	if ($niv<1) {
		$z = ' /* ---------------------------- Les POST ---------------------------- */ '."\n";
		if ($screen !=false) echo $z;
		 fwrite($g, $z);
		if ($screen !=false)   echo $br;
		 $e=$_POST;
		if ($screen !=false)    echo count($e)."\n";
		if ($screen !=false)   echo $br;
		while ($r = each($e))
			fwrite($g, ' $BUG[\'POST\'][\''.$r['key'].'\'] = \''.addslashes($r['value']).'\' ;'."\n");
	}

		$z = ' /* ---------------------------- Les GET ---------------------------- */ '."\n";
		if ($screen !=false) echo $z;
		 fwrite($g, $z);
		if ($screen !=false)   echo $br;
		 $e=$_GET;
		if ($screen !=false)    echo count($e)."\n";
		if ($screen !=false)   echo $br;
		while ($r = each($e))
			fwrite($g, ' $BUG[\'GET\'][\''.$r['key'].'\'] = \''.addslashes($r['value']).'\' ;'."\n");


		$z = ' /* ---------------------------- Les EXTENTION ---------------------------- */ '."\n";
		if ($screen !=false) echo $z;
		 fwrite($g, $z);
		if ($screen !=false)   echo $br;
		 $e=get_loaded_extensions();
		if ($screen !=false)    echo count($e)."\n";
		if ($screen !=false)   echo $br;
		while ($r = each($e))
			fwrite($g, ' $BUG[\'EXTENTION\'][\''.$r['key'].'\'] = \''.addslashes($r['value']).'\' ;'."\n");

		$z = ' /* ---------------------------- Les GLOBAL ---------------------------- */ '."\n";
		if ($screen !=false) echo $z;
		 fwrite($g, $z);
		if ($screen !=false)   echo $br;
		 $e=$GLOBALS;
		if ($screen !=false)    echo count($e)."\n";
		if ($screen !=false)   echo $br;
		while ($r = each($e))
			fwrite($g, ' $BUG[\'GLOBAL\'][\''.$r['key'].'\'] = \''.$r['value'].'\' ;'."\n");

		$z = ' /* ---------------------------- Les _REQUEST ---------------------------- */ '."\n";
		if ($screen !=false) echo $z;
		 fwrite($g, $z);
		if ($screen !=false)   echo $br;
		 $e=$_REQUEST;
		if ($screen !=false)    echo count($e)."\n";
		if ($screen !=false)   echo $br;
		while ($r = each($e))
			fwrite($g, ' $BUG[\'_REQUEST\'][\''.$r['key'].'\'] = \''.$r['value'].'\' ;'."\n");

		$z = ' /* ---------------------------- Les _ENV ---------------------------- */ '."\n";
		if ($screen !=false) echo $z;
		 fwrite($g, $z);
		if ($screen !=false)   echo $br;
		 $e=$_ENV;
		if ($screen !=false)    echo count($e)."\n";
		if ($screen !=false)   echo $br;
		while ($r = each($e))
			fwrite($g, ' $BUG[\'_ENV\'][\''.$r['key'].'\'] = \''.$r['value'].'\' ;'."\n");

		$z = ' /* ---------------------------- Les _COOKIE ---------------------------- */ '."\n";
		if ($screen !=false) echo $z;
		 fwrite($g, $z);
		if ($screen !=false)   echo $br;
		 $e=$_COOKIE;
		if ($screen !=false)    echo count($e)."\n";
		if ($screen !=false)   echo $br;
		while ($r = each($e))
			fwrite($g, ' $BUG[\'_COOKIE\'][\''.$r['key'].'\'] = \''.$r['value'].'\' ;'."\n");

		$z = ' /* ---------------------------- Les _COOKIE ---------------------------- */ '."\n";
		if ($screen !=false) echo $z;
		 fwrite($g, $z);
		if ($screen !=false)   echo $br;
		 $e=$_COOKIE;
		if ($screen !=false)    echo count($e)."\n";
		if ($screen !=false)   echo $br;
		while ($r = each($e))
			fwrite($g, ' $BUG[\'_COOKIE\'][\''.$r['key'].'\'] = \''.$r['value'].'\' ;'."\n");


		$z = ' /* ---------------------------- Les headers ---------------------------- */ '."\n";
		if ($screen !=false) echo $z;
		 fwrite($g, $z);
		if ($screen !=false)   echo $br;
		$e= (function_exists('@getallheaders')) ?@getallheaders() : array();
		if ($screen !=false)    echo count($e)."\n";
		if ($screen !=false)   echo $br;
		while ($r = each($e))
			fwrite($g, ' $BUG[\'HEADERS\'][\''.$r['key'].'\'] = \''.$r['value'].'\' ;'."\n");

	fclose($g);
	tep_links('link_bug', URL_DU_SITE.$file ,'link',TXT_LINK_FILE_BUG, true,'_blank').'<br />';
	print '<div style="width:100%; height:200px; overflow: auto;">'.$laso.'</div>'.$br;
	if ( ($screen !=false) AND ($comment !=false) ) {
	tep_links('link_bug', URL_DU_SITE.$file ,'link',TXT_LINK_FILE_BUG, true,'_blank').$br;
// 	tep_form ($dest_form,$session_id,$arg_form,$name_form,$meth_form="POST",false)
	print '<p>'.ADD_CONTENT_MAIL_BUG.'</p>';
	print '<textarea rows="5" cols="5" ></textarea>'.$br;
	print '<input type="submit"  name="envoi_bug" value="'.SUBMIT_ENVOYER.'" />';
	}
 }
?>