<?php
	session_start();
	## The function Permet l'appel d'une fonction a partir de JS ou AJAX afin d'effectuer une operation en arriere plan
	require("include/lib/lib.general.php");
	require("../include/sys_config.php");
	require("config/sys_config.php");
	require("config/sys_path.php");
	var_config_cst($_PX_config,'');
	if (NewFct('verif_session')==false) die( "Reconnectez vous svp , session inactive ! <br /> Please, connect you. <a href='".URL_ADMIN."'>Connection</a>" );
	require_once ("../include/sys_config_modules.php");
	var_config_cst(module_actif_dyn($_PX_config_module),'PX_config_module');
	require("../include/sys_tbl_sql.php");
	var_config_cst($TBL,'');
	_prefix_chemin();
	require("config/sys_folder.php");
	var_config_cst($folder,'');
	require("../include/lib_ext.php");
	var_config_cst($LIB,'');
	require ('../'.TBL_CONFIG_GEN);
	var_config_cst($_Config_gen,'CG');
	require("include/inc/nett_acen.inc");
	require("include/class/class.files.php");
	require("include/class/class.HDAcache.php");
	require("../lib_partage/lib.form.php");
	## Appel du fichier perso de lutilisateur
	require ("config/users/".$_SESSION['hash_acces_utilisateur'].".inc");
	$_user_perso_= $_perso_; // reatributoin des droit utilisateur
	var_config_cst($_perso_,'_user_perso_');
	/* Tempalte admin */
	if (defined('_USER_PERSO__THEME') && file_exists('template/'._USER_PERSO__THEME))define('TEMPLATE_ADMIN',_USER_PERSO__THEME);
	else define('TEMPLATE_ADMIN',THEME_ADMIN);
	## Chargement des lement du theme graphiue et des icone en cst
	include(_BO_REP_THEME.TEMPLATE_ADMIN.'/inc/def_icon.inc');
	include("include/lib/lib.theme.php");
	var_config_cst($_PX_icons,'loss_icon');
	define_img();
	$lg=appel_lang();
	while($r=each($lg))
		if ($lg[$r['key']]['lang'] == _USER_PERSO__PREF_LANGUAGE){
			define('LANG_POST',$r['key']);
			define('LANG_ADMIN',$lg[$r['key']]['lang']);
		}

	define('AJAX_MODE','true');
?>
<script src="include/js/application.js" type="text/javascript"></script>
<?php
     	require("include/language/"._USER_PERSO__PREF_LANGUAGE.".php");
	## Chargement des modules de l'admin et librairie eventuel. appel des fichier d'entete head.php et consta,te du module du type BO_MOD_NOM_MODULE
	$var_module_wysing_add=array(); global $var_module_wysing_add;
	## Chargement des modules de l'admin et librairie eventuel. appel des fichier d'entete head.php et consta,te du module du type BO_MOD_NOM_MODULE
	$nom=NewFct('cstr_liste',_BO_REP_MOD);
	if(is_array($nom))while ($r=each($nom)){
		define('BO_MOD_'.strtoupper($r['value']), 'true');
		## charge fichier entete
		if (file_exists(_BO_REP_MOD.$r['value'].'/head.inc')) @include(_BO_REP_MOD.$r['value'].'/head.inc');
		## charge fichier module lang
		if (file_exists(_BO_REP_MOD.$r['value'].'/language/'._USER_PERSO__PREF_LANGUAGE.'.php')) @include(_BO_REP_MOD.$r['value'].'/language/'._USER_PERSO__PREF_LANGUAGE.'.php');
	}
	eregi("([a-z0-9/_-]*)lib\.([a-z0-9_-]*).([a-z0-9]{3})",$_POST['funct'],$regs);
	$dest = (!empty($regs[2])) ? $regs[2]:  '';
	if (empty($_POST['act'])) $_POST['act']= $_GET['act'];
	if (empty($_POST['funct'])) $_POST['funct'] = $_GET['funct'];
// 	if (empty($_POST['vars'])) $_POST['funct'] = $_GET['vars'];
	## chargement des parametre linguistique de la page appelé.
	if (file_exists("include/language/french/".$regs[2].".php")) include_once ("include/language/"._USER_PERSO__PREF_LANGUAGE."/".$regs[2].".php");

	switch($_POST['act']){
		case 'url':
			## Dans le cas d'une url par iframe, les var dans $_POST['vars'] definiossent le style
			print '<iframe id="iframe_ajax" src="'.$_POST['funct'].'" style="'.$_POST['vars'].'"></iframe>';
		break;
		case 'include':
			require ("".$_POST['funct']."");
			include_once ("".$_POST['vars']."");
		break;
		case 'upload':
			include_once (CHEMIN_ABS.CHEMIN_DU_SITE.'lib_partage/lib.image.php');

			if (empty($_POST['extract_zip'])) $_POST['extract_zip']= $_GET['extract_zip'];
			if (empty($_POST['extract_zip_name'])) $_POST['extract_zip_name'] = $_GET['extract_zip_name'];

			require ("".$_POST['funct']."");
			for ($t=0;$t<count($_FILES['up_file']['tmp_name']);$t++){
				$name=(is_array($_FILES['up_file']['tmp_name'])) ? each($_FILES['up_file']['name']) : array('value'=>$_FILES['up_file']['name']);
				$type=(is_array($_FILES['up_file']['tmp_name'])) ?each($_FILES['up_file']['type']): array('value'=>$_FILES['up_file']['type']);
				$tmp_name=(is_array($_FILES['up_file']['tmp_name'])) ? each($_FILES['up_file']['tmp_name']): array('value'=>$_FILES['up_file']['tmp_name']);

				echo $la_clef_champ=$tmp_name['key'];
			  	$tmp_file = $tmp_name['value'];
			  	$file_name = $name['value'];
				$file_type = $type['value'];

			    	if (version_compare(phpversion(),'4.2.0','>=')) {
					$error=(is_array($_FILES['up_file']['tmp_name'])) ?  each($_FILES['up_file']['tmp_name']): array('value'=>$_FILES['up_file']['tmp_name']);

					$upd_error =$error['value'];
				} else $upd_error = 0;

				if ($upd_error != 0) {
					switch ($upd_error) {
						case 1:
						case 2: echo ERROR.THE_SIZE_OF_THE_FILE_EXCESS_THE_MAXIMUM_SIZE; break;
						case 3:echo ERROR.THE_FILE_NOT_FULLY_TRANFERED; break;
						case 4:echo ERROR.NO_FILE; break;
					}
				} elseif(!file_exists($tmp_file)) { echo ERROR.NO_FILE;
				} elseif(filesize($tmp_file) > MAX_UPLOAD_SIZE) {echo ERROR.THE_SIZE_OF_THE_FILE_EXCESS_THE_MAXIMUM_SIZE;
				} else {
				/* No error traitement */
					$file_name = preg_replace( '#(\s+)#', '_', $file_name);

					if(!isFileSafe($file_name)) {
					echo ERROR.INVALID_TYPE_OR_NAME_FILE;
					} else {

					    $cu=(isset($_POST['force_folder'])) ? $_POST['force_folder'] : REP_IMG;
					    $cu=ADD_PATH_ADMIN.$cu;
					    if (copy($tmp_file,$cu.$file_name)) {
						tep_file($cu.$file_name);
						if (eregi("/",$file_name))unlink(ADD_PATH_ADMIN.REP_IMG.$file_name);

						if ($_POST['extract_zip']=='true'){
						## Extrcation des ZIp
							if ($_POST['new_folder_for_zip']=='true'){
								$rep=($_POST['extract_zip_name']!='')? $_POST['extract_zip_name']:eregi_replace("\.zip",'',$file_name) ;
								$rep_final=$cu.$rep;
								tep_mkdir($rep_final);
							}
							else $rep_final=$cu;

							NewFct('zip_extractTo',$cu.$file_name,$rep_final,TRUE);
							@unlink($rep_final.$file_name);
						} else {
							## traitement des image et creat mini
							if (eregi("^(image)",$file_type)) {
								if (!isset($widht)) $widht='';
								if (!isset($height)) $height='';
								creat_img_mini($cu, $file_name, '', $widht, $height);
							}
						}
					    } else echo ERROR_OCCURED_DURING_THE_TRANSFER;
					}
				}

				/* OPeration post upload */
				if (isset($_GET['vars'])) {
					print('VARS '.$_GET['vars']);

					$tabl=explode('|||',urldecode($_GET['vars']));
					print_r($tabl);
					while($r=each($tabl)){
						$l=strlen($r['value']);
						$p=strpos($r['value'],'=-');
						echo $col=substr($r['value'],0,$p);
						echo $val=str_replace('=-','',substr($r['value'],$p,$l));
						switch(trim($col)) {
						/* option qui permet de retourner dans le champs image correposondant l'url de l'image telechargé */
						case 'upload_input_js_img':
							print "<script type=\"text/javascript\"> window.parent.document.getElementById('".ltrim(rtrim($val))."').value='".URL_DU_SITE.REP_IMG.$cu.$file_name."';</script>";
						break;
						default:
						}
					}
				}
			}
		break;
		default:
		## APPPEL GENERIC
		include ("".$_POST['funct']."");
		$fct= $_POST['act'];
		$vars= (isset($_POST['vars'])) ? nett_acen(stripslashes(urldecode($_POST['vars']))): '';
		if(test_const('DEBUG')) echo "".$fct."(".addslashes($vars).")";
		## evaluation de l'appel de la fonction
		print nett_acen($a=eval("\$ret = $fct($vars);"));
		## Sortie si actif
		if ( (isset($_POST['sortie']))AND(tep_not_null($_POST['sortie']))AND ($_POST['sortie'] !=false)AND ($_POST['sortie'] !='undefined')AND ($_POST['sortie'] !='false') ) {
			if( (!empty($a)) AND (($a =='false') OR ($a==false)) ) print "".ERROR;
			elseif( (!empty($a)) AND(eregi("error|erreur",$a))) print "".$a;
			else print nett_acen($_POST['sortie']);
		}
	}
?>