<?PHP
/************************************************************************/
/* DUNE by NPDS                                                         */
/* ===========================                                          */
/*                                                                      */
/* NEO - 2007                                                           */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2008 by Philippe Brunier   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
function Access_Error () {
  include("admin/die.php");
}
if (!eregi("admin.php", $PHP_SELF)) { Access_Error(); }

global $language, $NPDS_Prefix;
$hlpfile = "manuels/".$language."/meta_lang.html";
$result = sql_query("select radminsuper from ".$NPDS_Prefix."authors where aid='$aid'");
list($radminsuper) = sql_fetch_row($result);
if ($radminsuper!=1) {
   Access_Error();
}

function go_back($label) {
   if (!$label)
      $label = "".adm_translate("Retour en arrière")."";
   echo "<script language=\"JavaScript\">\n";
   echo "function precedent()\n";
   echo "{\n";
   echo "   document.write('<form><input type=\"button\" value=\"".$label."\" onclick=\"history.back();\" class=\"bouton_standard\"></form>');\n";
   echo "}\n";
   echo "</script>\n";
   echo "<script language=\"JavaScript\">precedent()</script>\n";
}
function inc_head($title) {
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
   echo $title." META-MOT\n";
   echo "</td></tr></table>\n";
}
function list_meta($meta, $type_meta) {
   global $NPDS_Prefix;

   $list = "<select class=\"textbox_standard\" name=\"meta\" onChange='window.location=eval(\"this.options[this.selectedIndex].value\")'>\n";
   $list .= "<option value=\"".$url."\" style=\"font-weight:bold; text-align:center;\">META</option>\n";
   if (!empty($type_meta)) $Q = sql_query("SELECT def FROM ".$NPDS_Prefix."metalang WHERE type_meta = '".$type_meta."' ORDER BY type_meta, def ASC");
   else $Q = sql_query("SELECT def FROM ".$NPDS_Prefix."metalang ORDER BY 'def' ASC");
   while ($resultat = sql_fetch_row($Q))  {
      if ($meta == $resultat[0]) { $sel = "selected"; }
      $list .= "<option ".$sel." value=\"admin.php?op=Meta-LangAdmin&amp;meta=".$resultat[0]."\">".$resultat[0]."</option>\n";
      $sel = "";
   }
   sql_free_result($Q);
   $list .= "</select>\n";
   return ($list);
}
function list_meta_type($type_meta) {
   global $hlpfile;

   $list = "<select class=\"textbox_standard\" name=\"type_meta\" onChange='window.location=eval(\"this.options[this.selectedIndex].value\")'>\n";
   $list .= "<option value=\"\">Type</option>\n";
// <!-- NE PAS ACTIVER :-: Réservé absoluement à l'usage du CMS -->
// $list .= "<option value=\"admin.php?op=Creat_Meta_Lang&type_meta=docu\">Docu</option>\n";
// <!-- / NE PAS ACTIVER :-: Réservé absoluement à l'usage du CMS -->
   $list .= "<option value=\"admin.php?op=Creat_Meta_Lang&amp;type_meta=meta\">meta</option>\n";
   $list .= "<option value=\"admin.php?op=Creat_Meta_Lang&amp;type_meta=mot\">mot</option>\n";
   $list .= "<option value=\"admin.php?op=Creat_Meta_Lang&amp;type_meta=smil\">smil</option>\n";
   $list .= "<option value=\"admin.php?op=Creat_Meta_Lang&amp;type_meta=them\">them</option>\n";
   $list .= "</select>\n";
   return ($list);
}
function list_type_meta($type_meta) {
   global $NPDS_Prefix;

   $list = "<select class=\"textbox_standard\" name=\"type_meta\" onChange='window.location=eval(\"this.options[this.selectedIndex].value\")'>\n";
   $list .= "<option value=\"".$url."\" style=\"font-weight:bold; text-align:center;\">Type</option>\n";
   $Q = sql_query("SELECT type_meta FROM ".$NPDS_Prefix."metalang GROUP BY type_meta ORDER BY 'type_meta' ASC");
   while ($resultat = sql_fetch_row($Q))  {
      if ($type_meta == $resultat[0]) { $sel = "selected "; }
      $list .= "<option ".$sel." value=\"admin.php?op=Meta-LangAdmin&amp;type_meta=".$resultat[0]."\">".$resultat[0]."</option>\n";
      $sel = "";
   }
   sql_free_result($Q);
   $list .= "</select>\n";
   return $list;
}
function List_Meta_Lang() {
   global $NPDS_Prefix;
   global $hlpfile, $meta, $type_meta;

   $linked = "onMouseOver=\"this.className='LIGNB'; this.style.cursor='default';\" onMouseOut=\"this.className='LIGNA';\"";
   if (!empty($meta)) $Q = sql_query("SELECT def, content, type_meta, type_uri, uri, description, obligatoire FROM ".$NPDS_Prefix."metalang WHERE def = '".$meta."' ORDER BY type_meta, def ASC");
   else if (!empty($type_meta)) $Q = sql_query("SELECT def, content, type_meta, type_uri, uri, description, obligatoire FROM ".$NPDS_Prefix."metalang WHERE type_meta = '".$type_meta."' ORDER BY type_meta, def ASC");
   else $Q = sql_query("SELECT def, content, type_meta, type_uri, uri, description, obligatoire FROM ".$NPDS_Prefix."metalang ORDER BY 'type_meta','def' ASC");
   include ("header.php");
   GraphicAdmin($hlpfile);
   opentable();
   $title = "";
   inc_head($title);
   echo "<table border=\"0\" width=\"100%\" cellspacing=\"1\" cellpadding=\"2\">\n";
   echo "<form name=\"admin_meta_lang\" action=\"admin.php\" method=\"post\" onSubmit=\"return confirm('".adm_translate("Supprimer")." ?')\">\n";
   echo "<tr>\n";
   echo "<td align=\"left\" width=\"40%\"><a href=\"admin.php?op=Creat_Meta_Lang\">".adm_translate("Créer un nouveau")."</a></td>\n";
   echo "<td align=\"right\" width=\"60%\">".adm_translate("Recherche rapide")."&nbsp;:&nbsp;".list_meta($meta, $type_meta)."&nbsp;".list_type_meta($type_meta)."&nbsp;<a href=\"admin.php?op=Meta-LangAdmin\"><b>".adm_translate("Tous")."</b></a></td>\n";
   echo "</tr>\n";
   echo "</table>\n";
   echo "<table border=\"0\" width=\"100%\" align=\"center\" cellspacing=\"0\" cellpadding=\"2\">\n";
   echo "<tr>\n";
   echo "<td width=\"100%\" height=\"1\" align=\"center\" class=\"header\"></td>\n";
   echo "</tr>\n";
   echo "</table>\n";
   echo "<table border=\"0\" width=\"100%\" cellspacing=\"1\" cellpadding=\"2\">\n";
   echo "<tr valign=\"bottom\">\n";
   echo "<td width=\"15\" align=\"center\">";
   echo "<img src=\"images/admin/metalang/question.gif\" width=\"15\" height=\"15\" title=\"".adm_translate("Action")."\">\n";
   echo "<hr noshade=\"noshade\" class=\"ongl\" /></td>\n";
   echo "<td width=\"100\">";
   echo "<b>META";
   echo "&nbsp;&nbsp;<img src=\"images/admin/metalang/edit.gif\" width=\"14\" height=\"14\" title=\"".adm_translate("Modifier")."\">\n";
   echo "</b><hr noshade=\"noshade\" class=\"ongl\" /></td>\n";
   echo "<td width=\"30\"><b>Type</b><hr noshade=\"noshade\" class=\"ongl\" /></td>\n";
   echo "<td width=\"80%\"><b>".adm_translate("Description")."</b><hr noshade=\"noshade\" class=\"ongl\" /></td>\n";
   echo "</tr>\n";
   $cur_type=""; $ibid=0;
   while (list($def, $content, $type_meta, $type_uri, $uri, $description, $obligatoire)= sql_fetch_row($Q))    {
      if ($cur_type=="")
      $cur_type=$type_meta;
      if ($type_meta!=$cur_type) {
         echo "</tr>\n";
         echo "<tr>\n";
         echo "<td colspan=\"4\"><hr noshade=\"noshade\" class=\"ongl\"></td>\n";
         echo "</tr>";
         $cur_type=$type_meta;
      }
      echo "<tr class=\"ligna\" ".$linked.">\n";
      echo "<input type=\"hidden\" name=\"nbr\" value=\"".$ibid."\">\n";
      echo "<td>";
      if ($obligatoire == false) echo "<input type=\"checkbox\" name=\"action[$ibid]\" value=\"".$def."\">";
      else echo "<img src=\"images/admin/metalang/warning.gif\" width=\"22\" height=\"21\" border=\"0\" alt=\"".adm_translate("Meta obligatoire, ne pas le modifier ou le supprimer")."\" title=\"".adm_translate("Meta obligatoire, ne pas le modifier ou le supprimer")."\" />";
      echo "</td>\n";
      echo "<td><a href=\"admin.php?op=Edit_Meta_Lang&amp;ml=".$def."\" title=\"".adm_translate("Modifier")."\">".$def."</a></td>";
      echo "<td>".$type_meta."</td>";
      if ($type_meta=="smil") {
         eval($content);
         echo "<td>".$cmd."</td>\n";
         echo "</tr>";
      }
      else if ($type_meta=="mot") {
         echo "<td>".$content."</td>\n";
         echo "</tr>";
      }
      else {
         echo "<td>".aff_langue($description)."</td>\n";
         echo "</tr>";
      }
      $ibid++;
   }
   sql_free_result($Q);
   echo "<tr>\n";
   echo "<td colspan=\"4\">";
   echo "&nbsp;&nbsp;<img src=\"images/admin/metalang/parent.gif\" width=\"20\" height=\"16\">";
   echo "<input type=\"hidden\" name=\"op\" value=\"Kill_Meta_Lang\">";
   echo "&nbsp;&nbsp;<input type=\"image\" src=\"images/admin/metalang/delete.gif\" width=\"20\" height=\"16\" align=\"absmiddle\" border=\"0\" name=\"submit\" value=\"kill\" title=\"".adm_translate("Tout supprimer")."\">";
   echo "</td>\n";
   echo "</tr>\n";
   echo "<tr>\n";
   echo "<td colspan=\"4\" class=\"header\">==> ".$ibid." META(s)</td>\n";
   echo "</tr>\n";
   echo "</form>\n";
   echo "</table>\n";
   closetable();
   include ("footer.php");
}
function Edit_Meta_Lang() {
   global $NPDS_Prefix;
   global $hlpfile, $ml, $local_user_language, $language;

   $rowcolor = tablos();
   $Q = sql_query("SELECT def, content, type_meta, type_uri, uri, description, obligatoire FROM ".$NPDS_Prefix."metalang WHERE def = '".$ml."'");
   $Q = sql_fetch_assoc($Q);
   sql_free_result($Q);
   include ("header.php");
   GraphicAdmin($hlpfile);
   opentable();
   $title = adm_translate("Modifier un ");
   inc_head($title);
   echo "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"1\" class=\"header\">\n";
   echo "<tr ".$rowcolor.">\n";
   echo "<td>";
   opentable();
   echo "<table width=\"100%\" border=\"0\" cellpadding=\"8\" cellspacing=\"1\" class=\"lignb\">\n";
   echo "<tr ".$rowcolor.">\n";
   echo "<td colspan=\"2\" valign=\"top\"><b>".aff_local_langue("<b>".adm_translate("Langue de Prévisualisation")."</b> : ","","local_user_language")."<br /></td>\n";
   echo "</tr>\n";
   echo "<tr ".$rowcolor.">\n";
   echo "<td width=\"110\"><b>META</b> : </td><td>".$Q[def]."</td>\n";
   echo "</tr>\n";
   echo "<tr ".$rowcolor.">\n";
   echo "<td><b>Type</b> :</td><td>".$Q[type_meta]."</td>\n";
   echo "</tr>\n";
   echo "<tr ".$rowcolor.">\n";
   echo "<td><b>".adm_translate("Description")."</b></td>\n";
   if ($Q[type_meta]=="smil") {
      eval($Q[content]);
      echo "<td>".$cmd."</td>\n";
   }
   else {
      echo "<td>".preview_local_langue($local_user_language, $Q[description])."</td>\n";
   }
   echo "</tr>\n";
   if ($Q[type_meta]!="docu" and $Q[type_meta]!="them") {
      echo "<tr ".$rowcolor.">\n";
      echo "<td valign=\"top\"><b>".adm_translate("Script")."</b> :</td>\n";
      echo "<td>";
      echo "<textarea name=\"content\" class=\"textbox_standard\" rows=\"20\" style=\"width: 100%;\" readonly>\n";
      echo $Q[content];
      echo "</textarea>";
      echo "</td>\n";
      echo "</tr>\n";
   }
   echo "</table>\n";
   closetable();
   echo "</td>\n";
   echo "</tr>\n";
   echo "</table>\n";
   echo "<br />\n";

   if ($Q[obligatoire] != true) {
      opentable();
      echo "<table width=\"100%\" border=\"0\" cellpadding=\"8\" cellspacing=\"1\">\n";
      echo "<form name=\"edit_meta_lang\" action=\"admin.php\" method=\"post\">\n";
      echo "<tr>\n";
      echo "<td width=\"110\"><b>META</b> : </td>\n";
      echo "<td>";
      echo "<input class=\"textbox_standard\" type=\"text\" name=\"def\" value=\"".$Q[def]."\" size=\"50\" readonly></td>\n";
      echo "</tr>\n";
      echo "<tr>\n";
      echo "<td><b>".adm_translate("Type")."</b> :</td>\n";
      echo "<td>";
      echo "<input class=\"textbox_standard\" type=\"text\" name=\"type_meta\" value=\"".$Q[type_meta]."\" size=\"10\" maxlength=\"10\" readonly>";
      echo "</td>\n";
      echo "</tr>\n";
      echo "<tr>\n";
      echo "<td><b>".adm_translate("Description")."</b> :</td>\n";
      if ($Q[type_meta]=="smil") {
          eval($Q[content]);
          echo "<td>".$cmd."</td>\n";
      } else {
         echo "<td>";
         echo "<textarea class=\"textbox_standard\" name=\"desc\" wrap=\"virtual\" rows=\"7\" style=\"width: 100%;\" >";
         echo $Q[description];
         echo "</textarea>";
         echo "</td>\n";
      }
      echo "</tr>\n";
      if ($Q[type_meta]!="docu" and $Q[type_meta]!="them") {
         echo "<tr>\n";
         echo "<td valign=\"top\"><b>".adm_translate("Script")."</b> : </td>\n";
         echo "<td>";
         echo "<textarea class=\"textbox_standard\" name=\"content\" rows=\"20\" style=\"width: 100%;\" >\n";
         echo $Q[content];
         echo "</textarea>";
         echo "</td>\n";
         echo "</tr>\n";
      }
      echo "<tr>\n";
      echo "<td><b>".adm_translate("Restriction")." :</b></td>\n";
      echo "<td>";
      if ($Q[type_uri] == "+") {
         if ($Q[obligatoire] == true) {$sel1 = "selected";}
         else  {$sel1 = " selected";}
      }
      else {
         if ($Q[obligatoire] == true) {$sel0 = "selected";}
         else {$sel0 = " selected";}
      }
      echo "<select class=\"textbox_standard\" name=\"type_uri\">\n";
      echo "<option".$sel0." value=\"moins\">".adm_translate("Tous sauf pour ...")."</option>\n";
      echo "<option".$sel1." value=\"plus\">".adm_translate("Seulement pour ...")."</option>\n";
      echo "</select>\n";
      echo "&nbsp;...".adm_translate("les URLs que vous aurez renseignés ci-après&nbsp;<i>(ne renseigner que la racine de l'URI)</i>")."";
      echo "<br />".adm_translate("Exemple")." : index.php user.php forum.php static.php\n";
      echo "<br />".adm_translate("Par defaut, rien ou Tout sauf pour ... [aucune URI] = aucune restriction");
      echo "<br />\n";
      echo "<textarea class=\"textbox_standard\" name=\"uri\" wrap=\"virtual\" rows=\"7\" style=\"width: 100%;\" >";
      echo $Q[uri]."</textarea>";
      echo "</td>\n";
      echo "</tr>\n";
      echo "<tr>\n";
      echo "<td width=\"100%\" colspan=\"2\" align=\"center\">";
      echo "<input type=\"hidden\" name=\"Maj_Bdd_ML\" value=\"edit_meta\">";
      echo "<input type=\"hidden\" name=\"op\" value=\"Valid_Meta_Lang\">";
      echo "<input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Valider")."\">";
      echo "</td></tr>\n";
      echo "</table>\n";
      echo "</form>\n";
      closetable();
   } else {
      go_back("");
   }
   closetable();
   include ("footer.php");
}
function Creat_Meta_Lang() {
   global $NPDS_Prefix;
   global $hlpfile, $type_meta;

   include ("header.php");
   GraphicAdmin($hlpfile);
   opentable();
   $title = adm_translate("Créer un nouveau")."";
   inc_head($title);
   echo "<form name=\"creat_meta_lang\" action=\"admin.php\" method=\"post\">\n";
   echo "<table width=\"100%\" border=\"0\" cellpadding=\"8\" cellspacing=\"1\">\n";
   echo "<tr>\n";
   echo "<td valign=\"middle\">";
   if (!$type_meta)
      echo adm_translate("Veuillez choisir un type de META-MOT")." ";
   echo list_meta_type($type_meta)." :</td>\n";
   echo "<td class=\"titrea\"><b>".$type_meta."</b></td>\n";
   echo "</tr>\n";
   if ($type_meta) {
      echo "<tr>\n";
      echo "<td width=\"110\"><b>META-MOT</b> : </td>\n";
      echo "<td><input class=\"textbox_standard\" type=\"text\" name=\"def\" size=\"50\" maxlength=\"50\"></td>\n";
      echo "</tr>\n";
      if ($type_meta != "smil") {
         echo "<tr>\n";
         echo "<td><b>".adm_translate("Description")."</b> :</td>\n";
         echo "<td>";
         echo "<textarea class=\"textbox\" name=\"desc\" wrap=\"virtual\" rows=\"7\" style=\"width: 100%;\">[french]...[/french][english]...[/english]</textarea>";
         echo "</td>\n";
         echo "</tr>\n";
      }
      if ($type_meta != "them") {
         echo "<tr>\n";
         echo "<td valign=\"middle\"><b>".adm_translate("Script")."</b> :</td>\n";
         echo "<td>";
         if ($type_meta == "smil") {
            echo "".adm_translate("Chemin et nom de l'image du Smiley")."&nbsp;&nbsp;<span class=\"rouge\">Ex. : forum/smilies/pafmur.gif</span>";
            echo "<br /><input class=\"textbox\" type=\"text\" name=\"content\" maxlength=\"255\">";
         } else
            echo "<textarea class=\"textbox\" name=\"content\" rows=\"20\" style=\"width: 100%;\">";
            if ($type_meta=="meta") echo "function MM_XYZ (\$arg) {\n   global \$NPDS_Prefix;\n   \$arg = arg_filter(\$arg);\n\n   return(\$content);\n}";
            echo "</textarea>";
         echo "</td>\n";
         echo "</tr>\n";
      }
      echo "<tr>\n";
      echo "<td><b>".adm_translate("Restriction")." :</b></td>\n";
      echo "<td>";
      echo "<select class=\"textbox_standard\" name=\"type_uri\">\n";
      echo "<option".$sel." value=\"moins\">".adm_translate("Tous sauf pour ...")."</option>\n";
      echo "<option".$sel." value=\"plus\">".adm_translate("Seulement pour ...")."</option>\n";
      echo "</select>\n";
      echo "&nbsp;...".adm_translate("les URLs que vous aurez renseignés ci-après&nbsp;<i>(ne renseigner que la racine de l'URI)</i>")."";
      echo "<br />".adm_translate("Exemple")." : index.php user.php forum.php static.php\n";
      echo "<br />".adm_translate("Par defaut, rien ou Tout sauf pour ... [aucune URI] = aucune restriction");
      echo "<br />\n";
      echo "<textarea class=\"textbox\" name=\"uri\" wrap=\"virtual\" rows=\"7\" style=\"width: 100%;\"></textarea>";
      echo "</td>\n";
      echo "</tr>\n";
      echo "<tr>\n";
      echo "<td width=\"100%\" colspan=\"2\" align=\"center\">";
      echo "<input type=\"hidden\" name=\"type_meta\" value=\"".$type_meta."\">";
      echo "<input type=\"hidden\" name=\"Maj_Bdd_ML\" value=\"creat_meta\">";
      echo "<input type=\"hidden\" name=\"op\" value=\"Valid_Meta_Lang\">";
      echo "<input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Valider")."\">";
      echo "</td></tr>\n";
   }
   echo "</table>\n";
   echo "</form>\n";
   closetable();
   include ("footer.php");
}
function kill_Meta_Lang($nbr, $action) {
   global $NPDS_Prefix;
   $i=1;
   while($i <= $nbr) {
      if (!empty($action[$i])) {sql_query("DELETE FROM ".$NPDS_Prefix."metalang WHERE def='".$action[$i]."' ");}
      $i++;
   }
   Header("Location: admin.php?op=Meta-LangAdmin");
}
function meta_exist($def) {
    global $hlpfile, $language;
    include("header.php");
    GraphicAdmin($hlpfile);
    opentable();
    echo "<p align=\"center\"><br />";
    echo "<span class=\"rouge\"><b>";
    echo $def."</b></span><br /><br />";
    echo adm_translate("Ce META-MOT existe déjà");
    echo "<br /><br />".adm_translate("Veuillez nommer différement ce nouveau META-MOT").".";
    echo "<br /><br />";
    go_back("");
    closetable();
    include("footer.php");
}
function Maj_Bdd_ML($Maj_Bdd_ML, $def, $content, $type_meta, $type_uri, $uri, $desc) {
   global $NPDS_Prefix;

   if ($type_uri =="plus") {$type_uri = "+";} else {$type_uri = "-";}

   if ($Maj_Bdd_ML=="creat_meta") {
      $def=trim($def);
      $Q = sql_query("SELECT def FROM ".$NPDS_Prefix."metalang WHERE def='".$def."'");
      $Q = sql_fetch_assoc($Q);
      sql_free_result($Q);
      if ($Q[def]) {
         meta_exist($Q[def]);
      } else {
         if ($type_meta=="smil")
            $content="\$cmd=MM_img(\"$content\");";
         if ($def!="")
            sql_query("INSERT INTO ".$NPDS_Prefix."metalang SET def='".$def."', content='$content', type_meta='".$type_meta."', type_uri='".$type_uri."', uri='".$uri."', description='".$desc."', obligatoire='0'");
         Header("Location: admin.php?op=Meta-LangAdmin");
      }
   }
   if ($Maj_Bdd_ML=="edit_meta") {
      sql_query("UPDATE ".$NPDS_Prefix."metalang SET content='".$content."', type_meta='".$type_meta."', type_uri='".$type_uri."', uri='".$uri."', description='".$desc."' WHERE def='".$def."'");
      Header("Location: admin.php?op=Meta-LangAdmin");
   }
}
switch($op)
{
   case "List_Meta_Lang":
   List_Meta_Lang();
   break;
// <!--/-->
   case "Creat_Meta_Lang":
   Creat_Meta_Lang();
   break;
// <!--/-->
   case "Edit_Meta_Lang":
   Edit_Meta_Lang();
   break;
// <!--/-->
   case "Kill_Meta_Lang":
   kill_Meta_Lang($nbr, $action);
   break;
// <!--/-->
   case "Valid_Meta_Lang":
   Maj_Bdd_ML($Maj_Bdd_ML, $def, $content, $type_meta, $type_uri, $uri, $desc);
   break;
// <!--/-->
   default:
   List_Meta_Lang();
   break;
}
?>