<?php
global $lg;
$lg=appel_lang();
if (!isset($_GET['choix_lang'])) {
	$code_lang=LANG_POST; $text_lang=_USER_PERSO__PREF_LANGUAGE;
}else {
	 $code_lang=$_GET['choix_lang']; $text_lang=$lg[$_GET['choix_lang']]['lang'];
	}
if (!isset($_GET['action'])) $_GET['action']='false'; ## extensiosn
$format_ajax="<script type='text/javascript'> upload_ajax('%1\$s','%2\$s','%3\$s','%4\$s'); </script>";
$file_conf_mod= array();$file_conf = array();
//  Couche JS Non intrusif pour oblige a enregistrer la pags si click ailleurs que dans element centraux form
array_push($js_lib, "add_click_onload"); array_push($function_js_init, "add_click_onload('menu','navi');");

	/* Recup des lement present, generer par langue et type */
	if ($_GET['action']=='ext'){
		/* Extensions*/
		$file_conf_mod=tep_array_file_sys($code_lang,$text_lang,'ext');
	}
	elseif ($_GET['action']=='false'){
		/* system */
		$file_conf=tep_array_file_sys($code_lang,$text_lang,'false');
	}
	?>
	<div id="gauche">
		<div id="block_sommaire_gauche" class="a_box">
			<?php choose_lang($code_lang); ?>
			 <h2><?php echo DOCUMENTS_EXISTANT.$text_lang ?></h2>
			 <?php if (count($file_conf)>0) echo NewFct('liste_navi',$_PX_config,$file_conf, "edit_file_lang.php","" );
			       if (count($file_conf_mod)>0) echo NewFct('liste_navi',$_PX_config,$file_conf_mod, "edit_file_lang.php","" );
			 	if (count($file_conf_mod)==0&&count($file_conf)==0) {
				print '<p><a href="edit_file_lang.php?choix_lang='.$code_lang.'">'.FILE_LANG_SYSTEM.'</a></p><br />';
				print '<p><a href="edit_file_lang.php?choix_lang='.$code_lang.'&amp;action=ext">'.FILE_LANG_EXTENSIONS.'</a></p><br />';
				}
			 ?>
		</div>
	</div>
	<div id="article">
		<div id="menu_inter" class="menu5">
			<p class="bottom"><a href="edit_file_lang.php?choix_lang=<?php echo $code_lang ?>&amp;action=add"><?php print ADD_LANG_SYSTEM ?></a></p>
		</div>
		<div id="contenu_article">
			<div class="i_box"><h1><?php echo FORMULAIRE_DE_MODIFICATION_DE_PAGE; ?></h1></div>
			<div id="contenu_article_central" class="a_box">
			<?php switch ($_GET['action']){
			       case 'add':
			       		echo "<h2>".ADD_LANG_SYSTEM."</h2><br/>";

					echo "<p>".NOTE_FORM_ADD_LANG."</p><br/>";
					print '<p><form method="post" action="edit_file_lang.php?choix_lang='.$code_lang.'&amp;action=add_exe">'
						.php_f_textField("new_code_lang",50,10,'fr','','')
						.php_f_textField("new_lang_text",50,10,'française','','')
						.php_f_textField("new_code_lang_long",50,10,'french','','')
						.php_f_button('submit',BT_ADD_LANG,'','')
						.'</form></p>';
			       break;
			       case 'add_exe':
			       		echo "<h2>".ADD_LANG_SYSTEM."</h2><br/>";
					/* Verifi structure rep  lossim */
					control_rep_lang($_POST['new_code_lang'],$_POST['new_code_lang_long']);
					recup_file_box($_POST['new_code_lang'],$_POST['new_code_lang_long']);
					/* Extensions*/
					$file_conf_mod=tep_array_file_sys($_POST['new_code_lang'],$_POST['new_code_lang_long'],'ext');
					/* system */
					$file_conf=tep_array_file_sys($_POST['new_code_lang'],$_POST['new_code_lang_long'],'false');
					/*Reindexation du fichier d'index des fichier de langues*/
					control_index_file_langue($file_conf,$file_conf_mod,$_POST['new_code_lang'],$_POST['new_code_lang_long']);

					add_lang_sql($_POST['new_code_lang'],$_POST['new_code_lang_long'],$_POST['new_lang_text']);
					print '<p><a href="edit_file_lang.php?choix_lang='.$_POST['new_code_lang'].'&amp;action=reindex">'.REINDEX_FILES.'</a></p><br />';
			       break;
			       case 'ext':
					echo "<h2>".CHOOSE_ACTION_LANGUE_EXT."</h2><br/>";
					print '<p><a href="edit_file_lang.php?choix_lang='.$code_lang.'">'.FILE_LANG_SYSTEM.'</a></p><br />';
					print '<p><a href="'.$_SERVER['REQUEST_URI'].'&amp;action=ext_up">'.RECUP_FILE_LANG.'</a></p><br />';
			       break;
				case 'reindex':
					echo "<h2>".REINDEX_TITRE."</h2><br/>";
					/* Extensions*/
					$file_conf_mod=tep_array_file_sys($code_lang,$text_lang,'ext');
					/* system */
					$file_conf=tep_array_file_sys($code_lang,$text_lang,'false');
					/*Reindexation du fichier d'index des fichier de langues*/
					control_index_file_langue($file_conf,$file_conf_mod,$code_lang,$text_lang);
					print '<p><a href="edit_file_lang.php?choix_lang='.$code_lang.'">'.FILE_LANG_SYSTEM.'</a></p><br />';
					print '<p><a href="edit_file_lang.php?choix_lang='.$code_lang.'&amp;action=ext">'.FILE_LANG_EXTENSIONS.'</a></p><br />';
			       break;
			       case 'ext_up':
				       /* Rciuperetaion des fichier de alngue manquant */
					echo "<h2>".CHOOSE_ACTION_LANGUE_EXT."</h2>";
					recup_file_box($code_lang,$text_lang);
					print '<p><a href="edit_file_lang.php?choix_lang='.$code_lang.'&amp;action=reindex">'.REINDEX_FILES.'</a></p><br />';
			       break;
			       default:
				if (!isset($_GET['file'])&&!isset($_GET['choix_lang'])) {
					echo "<h2>".CHOOSE_LANGUE."</h2>";
					echo "<p>".AFF_NOT_FILE_SELECTED."</p>";
					choose_lang($code_lang);
					/* Verifi structure rep  lossim */
					control_rep_lang($code_lang,$text_lang);
					## Reindexation du fichier d'index des fichier de langues
					control_index_file_langue($file_conf,$file_conf_mod,$code_lang,$text_lang);
				}
				elseif(!isset($_GET['file'])&&isset($_GET['choix_lang'])){
					echo "<h2>".CHOOSE_ACTION_LANGUE."</h2>";
					echo "<p>".AFF_NOT_FILE_SELECTED."</p>";
					/* Verifi structure rep  lossim */
					control_rep_lang($code_lang,$text_lang);
					/* Action extensions*/
					print '<p><a href="'.$_SERVER['REQUEST_URI'].'&amp;action=ext">'.FILE_LANG_EXTENSIONS.'</a></p><br />';
					print '<p><a href="'.$_SERVER['REQUEST_URI'].'&amp;action=ext_up">'.RECUP_FILE_LANG.'</a></p><br />';
				}
				elseif(isset($_GET['file'])){
					printf($format_ajax,'contenu_article_central','include/inc/edit_file_mini.inc','edit_file_mini'," \'edit_file_lang.php\',\'".$_GET['file']."\',\'false\',\'\' ");
				}
			}
			if ( (!empty($_POST['preview'])) OR (!empty($_POST['confirm'])) ){
				$name=eregi_replace("(.*/){0,5}","",$_GET['file']);
				$ch=eregi_replace("$name","",$_GET['file']);
				if($_PX_config['debug']) print "<br />name :$ch"."$name";
				 Newfct('op_files',$name,$ch,"ADD",addslashes($_POST['message']),"" );
			}
			?><br /></div>
		</div>
	</div> <!-- Fin de articles -->
	</div>