<?php
/*
Copyright (C) 2008 by oscim   Project lossim  [ 15.09.2009, 09:17:59] @oscim
// kate: replace-trailing-space-save true; space-indent on; indent-width 2; mixedindent off; indent-mode cstyle; word-wrap-marker-color #41C2A4
ENCODE UTF-8
*/

function txt_base($url,$table){
$menu=str_replace("&",'',$url);
print "<p style='text-align:center;'><a href='menu.php?conf=new".$url."' title='' Onclick= \"".ajax_action ("include/lib/lib.menu.php", "aff_menu_name_form","'$menu','$table','true'","menu.php?".$url)."return false;\" >".ADD_NEW_ENTREE_MENU."</a></p>";
}
/* Suppression d'un menu secondaires */
function supp_menu($nom_menu){
	if (@unlink(ADD_PATH_ADMIN.REP_MENU_SUPLL.$nom_menu.".inc")) return "<p class='ok'>".WRITE_MODIF_OK."</p>";
	else return "<p class='erreur'>".WRITE_NOT_POSSIBLE."</p>";
}
/* Creat fichier base menu (table) */
function create_file_menu($nom_menu){
  $handle= ADD_PATH_ADMIN.REP_MENU_SUPLL.$nom_menu.".inc";
  if (!tep_file($handle)) {
    $handle=fopen($handle, "w+");
    @fputs($handle, "<?php /* Fichier de menu creation auto */ ?>");
    @fclose($handle);
    print "<p class='ok'>".CREATE_NEW_MENU_OK."</p>";
    return true;
  } else {
    print "<p class='erreur'>".CREATE_NEW_MENU_NOT_OK."</p>";
    return false;
  }
}
function ajax_droit($lib_dest, $funct_dest,$var_dest,$dest_ret,$lib_ret,$funct_ret,$var_ret,$txt_ret){
$format_ajax_inline="upload_ajax('%1\$s','%2\$s','%3\$s','%4\$s')";
$s = 	"{  "
	.sprintf($format_ajax_inline,"form_ajax_txt",$lib_dest,$funct_dest, $var_dest)
	."; add_link_nav2('form_ajax_nav','".$dest_ret."','".$txt_ret."','"
	.addslashes(sprintf($format_ajax_inline,"form_ajax_nav",$lib_ret,$funct_ret, $var_ret))
	."' ); montre('backgd'); montre('form_ajax'); return false; "
	." } ";
return $s;
}

/* constructeur de liste de menu seocndaire */
function list_menu_supp_elements (){
	$nom=NewFct('cstr_liste',ADD_PATH_ADMIN.REP_MENU_SUPLL,"") ;
	$ss=$me=array('');
	if (is_array($nom))while ( $rows =each($nom)){
		$r=eregi_replace("([.][a-z]{3})","",$rows['value']);
		if (eregi("_ss_rubrique", $r))  array_push($ss,$r);
		else array_push($me,$r);
	}
	return array("rubriques"=>$ss,"menus"=>$me);
}
/* Nvigateur des menu secondaires */
function list_menu_supp ($url=''){
	$nom=list_menu_supp_elements ();
	$ss=$me='';
	if (is_array($nom)) {
		while ( $rows =each($nom['rubriques'])){
		$r=eregi_replace("([.][a-z]{3})","",$rows['value']);
		if($r !='')$ss .= sprintf("  <a href='menu.php?menu=%1\$s' >%2\$s</a>  \n", $r, $r);
		}
		while ( $rows =each($nom['menus'])){
		$r=eregi_replace("([.][a-z]{3})","",$rows['value']);
		if($r !='') $me .= sprintf("  <a href='menu.php?menu=%1\$s' >%2\$s</a>  \n", $r, $r);
		 }
	}
	print "<p><a href='menu.php?conf=new_menu' onclick=\"".ajax_action ("include/lib/lib.menu.php", "aff_menu_name","'true'","menu.php?".$url)." return false;\" >".ADD_NEW_MENU."</a><a href='menu.php?conf=supp_menu'  onclick=\" " .ajax_confirm(TITRE_CONFIRM.CONFIRM_SUPP_SS_MENU,"include/lib/lib.menu.php", "supp_ss_menu_form"," '".$url."', true ","menu.php".$url, RETOUR) ."\"  >".SUP_SS_MENU."</a></p>";
	print "<p>".tep_links('', 'menu.php',MENU_P,MENU_P, false,'', '','',1)."</p>";
	if ($me!='')print "<p>".F_MENUS." <a href='menu.php' >".MENU_P."</a> ".$me."</p>";
	if ($ss!='')print "<p>".F_SS_RUB. $ss ."</p>";
	if ( ($me =='') AND ($ss =='') ) print "<p>". MENU_SUPPLEMENTAIRES_EMPTY . "</p>";
}
function supp_ss_menu_form ($url,$type_s=false){
	$p="<p>%1\$s</p>";
	$s=sprintf("<h2>%1\$s</h2>",SUPP_TITRE_FORM);
	$s.=tep_form ("menu.php",'',"conf=supp_menu".$url,"post","POST",false," onsubmit=\"return checkForm(this)\"" );
	$nom=list_menu_supp_elements ();
	$ss=$me='';
	if (is_array($nom)) {
		while ( $rows =each($nom['rubriques'])){
			$r=eregi_replace("([.][a-z]{3})","",$rows['value']);
			if($r !='')$s.=sprintf($p,php_f_radio("r_menu_supp", $rows['value'], '',10,'').$r);
		}
		while ( $rows =each($nom['menus'])){
			$r=eregi_replace("([.][a-z]{3})","",$rows['value']);
			if($r !='') $s.=sprintf($p,php_f_radio("r_menu_supp", $rows['value'], '',10,'').$r);
		 }
	}
	$s.=sprintf($p,tep_bts_form('','','SE','SR','','','',true));
	$s.="</form>\n";

	if (!$type_s) return $s;
	else print $s;
}


/* function de suppression d'une entre complete dns un menu*/
function supp_entry_menu($table,$menu_key){
	$s=NewFct('barre_h_box_ajax',MENU,FORM_TITRE_ADD_CONF_MENU,'',false);
	$s.="<div id=\"form_ajax_txt_box_scroll\">\n";
	$s.="<div id=\"form_ajax_txt_box_center\">\n";
	if (empty($menu_key)) die('function supp_entry_menu key null');
	if (empty($table)) die('function supp_entry_menu $table null');

	$query ='DELETE FROM '.$table.' WHERE  id = \''.$menu_key.'\'';
	$s .= sql ('',ADD_PATH_ADMIN.$table,'menu_auto',$query,'');

	$s.="</div>\n</div>\n";
	print $s;
}

/* Test dispo du nom du nouveau menu */
function aff_menu_name($type_s=false){
	$p="<p>%1\$s</p>";
	$s=NewFct('barre_h_box_ajax',MENU,ADD_TITRE_FORM,'',false);
// 	$s.="<div id=\"form_ajax_txt_box_scroll\">\n";
	$s.="<div id=\"form_ajax_txt_box_center\">\n";
	$s.=tep_form ("menu.php",'',"conf=new_menu&amp;name=ok","post","POST",false," onsubmit=\"return checkForm(this)\"" );
	$s.=sprintf($p,php_f_textField("menu_name",50,50,ADD_NAME_ENTREE,'',"onblur=\"if (this.value == '') {this.value = '".ADD_NAME_ENTREE."';}\" onfocus=\"if (this.value == '".ADD_NAME_ENTREE."') {this.value = '';}\"").FORM_CHAMPS_OBLIGATOIRE);
	$s.=sprintf($p,FORM_CHAMPS_OBLIGATOIRE_TXT);
	$s.=sprintf($p,tep_bts_form('','','SE','SR','','','',true));
	$s.="</form>\n";
	$s.="</div>\n";

	if (!$type_s) return $s;
	else print $s;
}
?>