<?php
$p="<p>%1\$s</p>";
$format_ajax="<script type='text/javascript'> upload_ajax('%1\$s','%2\$s','%3\$s','%4\$s'); </script>";
$color=array("#d6d0b0","#666666","#3c6366","#664a66","#663760","#66265b");
$js=$js_fct=array("");
array_push($js_lib, "add_click_onload"); array_push($function_js_init, "add_click_onload('menu','navi');");
 ?>
	<div id="gauche">
		<div id="block_sommaire_gauche">
				<?php print '<h2>'.option_deplie('liste_navi_gab',GAB_EXISTANT,true).'</h2>';  ?>
				<div id='liste_navi_gab'  style="display:none;" ><?php echo NewFct('liste_navi',$_PX_config,$file_conf, "edit_template.php",""); ?></div>
				<?php print '<br /><h2>'.option_deplie('liste_navi_css',CSS_EXISTANT,true).'</h2>';  ?>
				<div id='liste_navi_css'  style="display:none;" ><?php echo NewFct('liste_navi',$_PX_config,$file_css, "edit_template.php",""); ?></div>
				<?php print '<br /><h2>'.option_deplie('liste_navi_box',BOX_EXISTANT,true).'</h2>';  ?>
				<div id='liste_navi_box'  style="display:none;" ><?php echo NewFct('liste_navi',$_PX_config,$file_box, "edit_template.php",""); ?></div>
		</div>
	</div>
	<div id="article">
		<div id="menu_inter" class="menu5"><nobr>
				<p>
				<?php  if   ( (defined('PX_CONFIG_MODULE_GABARIT'))AND (PX_CONFIG_MODULE_GABARIT=='true') AND((isset($_GET['file']))AND (eregi(".*(\.php)$",$_GET['file'])) )  )  print option_deplie('new_gab',BOX_NEW_GAB_HELP,true);
					if   ( (isset($_GET['file']))AND (eregi(".*(\.inc)$",$_GET['file'])) ) print option_deplie('new_box',BOX_NEW_BOX,true);

					print option_deplie('edit_gab_help',HELP_PAGE ,true).option_deplie('alertes',ALERTE,true);

					 if ( (defined('BO_MOD_BACKUP'))AND (_USER_PERSO__GRP<=2) ){
					## Si Module present
					 print "<a href='#' Onclick=\""
					   	."montre('form_ajax');montre('backgd'); upload_ajax('form_ajax_txt','include/modules/backup/functions.inc',' zip_template','".NOM_DU_THEME."',''); add_close('edit_template.php','".NEXT."', '' )"
					  ."\" >".BT_ZIPTEMPLATE."</a>";
					 };  ?>
				 </p>
			</nobr></div>
		<div id="contenu_article">
			<div class="i_box">
					<h1><?php echo FORMULAIRE_DE_MODIFICATION_DE_PAGE; ?></h1>
			</div>
			<?php

			if ( (!is_writable(ADD_PATH_ADMIN."template"))AND (OS_SERVEUR !='windows') ) print "<p class='erreur'>".THE_FOLDER.WRITE_NOT_POSSIBLE." : lossim/template/</p>";
		## Choix du template
			if (!isset($_GET['file'])) {
				print '<div id="edit_gab_help" style="display:none;" class="a_box"><h2>'.EDIT_GAB_HELP.'</h2><p>'.AFF_NOT_FILE_SELECTED.'</p></div>';

				?>
				<?php print '<h2>'.option_deplie('add_templ_in_lossim',ADD_TEMPLATE,true).'</h2>';  ?>
				<div id='add_templ_in_lossim'  style="display:none;" ><?php echo NewFct('upload',array('id'=>'add_templ_in_lossim','extract_zip'=>true,'force_folder'=>'template/')) ?></div>
				<?php print '<h2>'.option_deplie('add_templ_admin',ADD_TEMPLATE_ADMIN,true).'</h2>';  ?>
				<div id='add_templ_admin'  style="display:none;" ><?php echo NewFct('upload',array('id'=>'add_templ_admin','extract_zip'=>true,'force_folder'=>'admin/template/')) ?></div>

				<?php

				print '<div class="a_box">';
					choise_template();
				print '</div>';



		## edition file.php  le template
			      	} elseif ((isset($_GET['file']))AND (eregi(".*(\.php)$",$_GET['file'])) ) { ?>
				<div id='alertes'  style="display:none;" class="a_box">
					<h2><?php echo ALERTE ?></h2>
					<?php if  ( (!defined('PX_CONFIG_MODULE_GABARIT'))OR (PX_CONFIG_MODULE_GABARIT=='false') ) {
						print "<p class='alerte'>".MODULE_GABARIT_ABS."</p>";
						array_push($function_js_init,"montre('alertes');"); }?>
					<br />
				</div>
				<div id='edit_gab_help' style="display:none;" class="a_box"><h2><?php echo HELP_PAGE ?></h2><p><?php print EDIT_GAB_HELP_D ?></p></div>
				<?php	print '<div class="a_box" >';
				      array_push($function_js_init, "drag_init();"); array_push($js_lib, "drag_init");
				      print "<h2>".GABARIT_NAME.$_GET['file']."</h2>\n";
				       ?><br />
					<?php if   ( (defined('PX_CONFIG_MODULE_GABARIT'))AND (PX_CONFIG_MODULE_GABARIT=='true') )  dble_gabarit($_GET['file'],$file_conf); ?>
				<!-- FUNCTIONS-->
					<div id='function_dispo' ><h2><?php print BOX_DISPO ?></h2>
						<?php print '<p>'.option_deplie('function_dispo_help',BOX_DISPO_HELP,true).'</p>';  ?>
						<p id='function_dispo_help' style="display:none;"><?php print BOX_DISPO_HELP_D ?></p>
						<hr />
						<?php $js=box_dispo_sortie($js);?>
						<div id='function'></div>
					</div>
				<!-- TEMPALTE MINI-->
					<div id="block_mini_template" >
						<h2>hierarchie des boites</h2>
					<?php   $i=$j=$f=$h=0;
						$h=fopen($_GET['file'], "r");
						if (!$h)die( "pbs ouverture fichier :".$_GET['file']);
						while($l=fgets($h,4096)){
							$l=eregi_replace("(<!--.*)[^(-->)]|(-->)","",$l);
							$l=eregi_replace("\"|'",'',str_replace(">","___",str_replace("<","___",$l)));
							if (eregi("(___div).*id=([a-z0-9]*)(.*)[^(\">| >)]",$l, $reg)){
								$sortie_detail="<br />".@str_replace(array('___?','?___','___' ),array(''),$reg[3]);
								print "<div id='template_".$reg[2]."' style='border:1px solid white; margin:2px 5px;background:".$color[$f].";'><h1 style='border:1px solid red; font-size:8px; color:black' ".Toolip(TXT_DIV_D.$sortie_detail).">".$reg[2]."</h1><div id='el_template_".$reg[2]."'> <br /></div>\n";
									$format="Droppables.add(\"template_".$reg[2]."\",{ \n"
										."accept: \"draggable\",\n"
										."hoverclass:\"drophover\",\n"
										."onDrop: function(element){\n"
										."$('el_template_".$reg[2]."').innerHTML = \"<p id='\" + element.innerHTML + \"' class='draggable'> \" + element.innerHTML + \"</p>\";\n"
										." ajax_load('retour_ajax_txt'); montre('retour_ajax'); montre('backgd');  "
										."upload_ajax('retour_ajax_txt','include/lib/lib.edit_template.php', 'add_function_template',' \'".$_GET['file']."\',\'".$reg[2]."\', \''+element.innerHTML+'\'  ',  element.innerHTML )\n"
										."add_link_nav2('retour_ajax_nav','edit_template.php?file=".$_GET['file']."','".RETOUR."','' );"
										."}\n"
										."});\n";
								array_push($js_fct, sprintf($format,"template_".$reg[2]));
								$i++;$h++;
							}
							elseif (eregi("(___div).*[^(\"___\/div___| ___\/div___)]",$l, $reg)) {print "<div>"; $j++;$h++; }
							elseif (eregi("(___\/div___)",$l, $reg)) {print "</div>"; $j++;$h++; }
							elseif (eregi("(___\?php(.*)\?___)",$l, $reg)){
								$s=eregi_replace("\"|'| ",'',str_replace(">","&gt;",str_replace("<","&lt;",$reg[2])));
								if (eregi("NewFct[(]([a-z0-9_-]*)",$s,$reg)) {
									print "<p id='".$reg[1]."'   style='margin-left:20px; color:white;'>"
										."<img alt='Delete' name='".$reg[1]."' style='position:absolute;margin:0 0 0 -20px;' src=\"template/".TEMPLATE_ADMIN."/img/delete.png\"  Onclick=\""
											.ajax_droit_confirme(SUR,"include/lib/lib.edit_template.php", "supp_function_template"," \'".$_GET['file']."\',\'".$reg[1]."\'" ,"edit_template.php?file=".$_GET['file'],RETOUR,$reg[1])." ; \" />".$reg[1]."</p>";
								}
								elseif (eregi("include[(]([a-z0-9_/-]*)(\.[a-z]{3})",$s,$reg)){
									$color=(file_exists(ADD_PATH_ADMIN.$reg[1].$reg[2])||file_exists(ADD_PATH_ADMIN.'template/'.NOM_DU_THEME.'/'.$reg[1].$reg[2])) ? 'white':'red';
									print "<p id='".$reg[1]."'  style='margin-left:20px; color:".$color.";'>"
										."<img  name='".$reg[1]."' alt='Delete' style='position:absolute;margin:0 0 0 -20px;' src='template/".TEMPLATE_ADMIN."/img/delete.png'  Onclick=\""
											.ajax_droit_confirme(SUR,"include/lib/lib.edit_template.php", "supp_function_template"," \'".$_GET['file']."\',\'".$reg[1]."\'" ,"edit_template.php?file=".$_GET['file'],RETOUR,$reg[1])."; \" />".$reg[1]."</p>";
								}
							}
							$f=($i-$j);
						}
						fclose($h);

					print '</div><br style="clear:both;" /></div>';
				 } //  FIN de elseif ((isset($_GET['file']))AND (eregi(".*(\.php)$",$_GET['file'])) )
			elseif (isset($_GET['file'])){ // edition fichier
				 print '<div class="a_box"><h2>'.option_deplie('help_box',HELP_EDIT_BOX,true).'</h2>'
				 	."<div id='help_box'  style='display:none;' >".HELP_EDIT_BOX_D."</div>";
					dble_box($_GET['file'],$file_box);
				print "<div id='c_box'></div></div>";
				printf($format_ajax,'c_box','include/inc/edit_file_mini.inc','edit_file_mini'," \'edit_template.php\',\'".$_GET['file']."\',\'save_as\',\'\' ");
			       if (!empty($_POST['confirm'])) { // enreg box
					$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']),"" );
				}
				print "</div>";
			}
			 ?>
		</div>
	</div> <!-- Fin de articles -->
</div>