<?php
/************************************************************************/
/* DUNE by NPDS                                                         */
/* ===========================                                          */
/*                                                                      */
/* Based on PhpNuke 4.x source code                                     */
/*                                                                      */
/* NPDS Copyright (c) 2002-2013 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 (!stristr($_SERVER['PHP_SELF'],"admin.php")) { Access_Error(); }
global $NPDS_Prefix;

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

function groupe($groupe) {
   $les_groupes=explode(",",$groupe);
   $mX=liste_group();
   $nbg=0; $str="";
   while (list($groupe_id, $groupe_name)=each($mX)) {
      $selectionne=0;
      if ($les_groupes) {
         foreach ($les_groupes as $groupevalue) {
            if (($groupe_id==$groupevalue) and ($groupe_id!=0)) {$selectionne=1;}
         }
      }
      if ($selectionne==1) {
         $str.="<option value=\"$groupe_id\" selected=\"selected\">$groupe_name</option>";
      } else {
         $str.="<option value=\"$groupe_id\">$groupe_name</option>";
      }
      $nbg++;
   }
   if ($nbg>5) {$nbg=5;}
   return ("<select class=\"textbox_standard\" name=\"Mmember[]\" multiple size=\"$nbg\">".$str."</select>");
}

function droits_bloc($member) {
   echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr><td align=\"left\">";
   echo "<span class=\"rouge\">".adm_translate("Administrateurs")."</span> :";
   if ($member==-127) {$checked=" checked=\"checked\"";} else {$checked="";}
   echo "<input type=\"radio\" name=\"members\" value=\"-127\"$checked /></td><td align=\"center\">";
   echo "<span class=\"rouge\">".adm_translate("Anonymes")."</span> :";
   if ($member==-1) {$checked=" checked=\"checked\"";} else {$checked="";}
   echo "<input type=\"radio\" name=\"members\" value=\"-1\"$checked /></td><td align=\"right\">";
   echo "<span class=\"rouge\">".adm_translate("Membres")."</span> :";
   if ($member>0) {
      echo "<input type=\"radio\" name=\"members\" value=\"1\"  checked=\"checked\" />&nbsp;<b>=> ".adm_translate("Groupes")." :&nbsp;</b>";
      echo "</td><td align=\"left\">";
      echo groupe($member);
      echo "</td><td align=\"left\">";
      echo "<br /><input type=\"radio\" name=\"members\" value=\"0\" /><b>".adm_translate("Tous")."</b></td></tr></table>";
   } else {
      if ($member==0) {$checked=" checked=\"checked\"";} else {$checked="";}
      echo "<input type=\"radio\" name=\"members\" value=\"1\" />&nbsp;<b>=> ".adm_translate("Groupes")." :&nbsp;</b>";
      echo "</td><td align=\"left\">";
      echo groupe($member);
      echo "</td><td align=\"left\">";
      echo "<input type=\"radio\" name=\"members\" value=\"0\"$checked /><b>".adm_translate("Tous")."</b></td></tr></table>";
   }
}

function blocks() {
  global $hlpfile, $radminleft, $radminright, $radminsuper;
  global $NPDS_Prefix;
  include("header.php");
  include_once ("lib/togglediv.class.php");
  GraphicAdmin($hlpfile);
  opentable();
  if (($radminleft==1) or ($radminsuper==1)) {
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
   echo adm_translate("Edition des Blocs de gauche");
   echo "</td></tr></table>\n";
   $result = sql_query("select id, title, content, member, Lindex, cache, actif, aide, css from ".$NPDS_Prefix."lblocks order by Lindex ASC");
   $num_row=sql_num_rows($result);
   $toggle = new ToggleDiv($num_row);
   if ($num_row>0) {
      echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
      echo "<tr><td width=\"65%\" class=\"ongl\" align=\"left\">".adm_translate("Titre :")."</td><td width=\"10%\" class=\"ongl\" align=\"right\">".adm_translate("Actif(s)")." :</td><td width=\"10%\" class=\"ongl\" align=\"right\">Index :</td><td width=\"10%\" class=\"ongl\" align=\"right\"><span style=\"font-size: 10px;\">".adm_translate("rétention en secondes")."</span> :</td><td width=\"5%\" class=\"ongl\" align=\"right\"> ID :</td></tr>";
      while (list($id, $title, $content, $member, $Lindex, $Scache, $Sactif, $BLaide, $css) = sql_fetch_row($result)) {
         $rowcolor = tablos();
         $funct="";
         if ($title=="") {
            //$title=adm_translate("Sans nom");
            $pos_func=strpos($content,"function#");
            $pos_nl=strpos($content,chr(13),$pos_func);
            if ($pos_func!==false) {
               $funct="<span style=\"font-size: 10px;\"> (";
               if ($pos_nl!==false)
                  $funct.=substr($content,$pos_func, $pos_nl-$pos_func);
               else
                  $funct.=substr($content,$pos_func);
               $funct.=")</span>";
            }
            $funct=adm_translate("Sans nom").$funct;
         }
         echo "<tr $rowcolor><td align=\"left\">";
         echo $toggle->Img();
         echo aff_langue($title)."".$funct."</td>";
         if ($Sactif)
            echo "<td class=\"noir\" align=\"right\">".adm_translate("Oui")."</td>";
         else
            echo "<td class=\"rouge\" align=\"right\">".adm_translate("Non")."</td>";
         echo "<td align=\"right\">$Lindex</td><td align=\"right\">$Scache</td>";
         echo "<td align=\"right\">$id</td></tr>";

         echo "<tr><td colspan=\"5\">";
         echo $toggle->Begin();
         echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr $rowcolor><td>
         <table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><form action=\"admin.php\" method=\"post\">\n";
         echo "<tr $rowcolor><td width=\"70%\">\n";
         echo "<b>".adm_translate("Titre :")."</b> <input class=\"textbox_standard\" type=\"text\" name=\"title\" size=\"30\" maxlength=\"255\" value=\"$title\" /><br /><br /><b>Index : </b>";
         echo "<input class=\"textbox_standard\" type=\"text\" name=\"Lindex\" size=\"5\" maxlength=\"4\" value=\"$Lindex\" /></td><td valign=\"top\" rowspan=\"2\"><b>";
         echo adm_translate("rétention en secondes")." : </b><input class=\"textbox_standard\" type=\"text\" name=\"Scache\" size=\"6\" maxlength=\"5\" value=\"$Scache\" /><br />".adm_translate("Chaque bloc peut utiliser SuperCache.<br />La valeur du délai de rétention <b>0</b> indique que le bloc ne sera <b>pas caché</b> (obligatoire pour le bloc function#adminblock).")."<br /><br />";

         echo "<a href=\"javascript:void(0);\" onclick=\"window.open('autodoc.php?op=blocs', 'windocu', 'width=720, height=400, resizable=yes,menubar=no,location=no,directories=no,status=no,copyhistory=no,toolbar=no,scrollbars=yes');\" class=\"noir\">";
         echo adm_translate("Manuel en ligne")."</a>";
         echo "<br /><br />";

         echo adm_translate("Activer le Bloc")." : <input type=\"checkbox\" name=\"Sactif\" value=\"ON\" ";
         if ($Sactif) echo "checked=\"checked\"";
         echo "><br />";
         echo adm_translate("CSS Specifique")." : <input type=\"checkbox\" name=\"css\" value=\"1\" ";
         if ($css=="1") echo "checked=\"checked\"";
         echo "><br />";
         echo "</td></tr><tr><td>";
         echo "<b>".adm_translate("Contenu :")."</b>";
         echo "<br /><textarea class=\"textbox\" cols=\"70\" rows=\"5\" name=\"content\" style=\"width: 95%;\">$content</textarea>";
         echo "<br /><b>".adm_translate("Aide en ligne de ce bloc")." :</b><br /><textarea class=\"textbox\" cols=\"50\" rows=\"2\" name=\"BLaide\">$BLaide</textarea>";
         echo "</td></tr><tr><td colspan=\"2\" align=\"left\" valign=\"top\">";
         echo droits_bloc($member);
         echo "</td></tr>\n<tr><td colspan=\"2\">";
         echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
         echo "<select class=\"textbox_standard\" name=\"op\">";
         echo "<option value=\"changelblock\" selected=\"selected\">".adm_translate("Modifier un Bloc gauche")."</option>";
         echo "<option value=\"deletelblock\">".adm_translate("Effacer un Bloc gauche")."</option>";
         echo "<option value=\"droitelblock\">".adm_translate("Transférer à Droite")."</option>";
         echo "</select>";
         echo " <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Ok")."\" />";
         echo "</td></tr>\n</form></table>
         </td></tr></table><br />";
         echo $toggle->End();
         echo "</td></tr>";
      }
      echo "</table>";
   }

   echo "<br /><br />";
  }
  if (($radminright==1) or ($radminsuper==1)) {
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
   echo adm_translate("Edition des Blocs de droite");
   echo "</td></tr></table>\n";
   $result = sql_query("select id, title, content, member, Rindex, cache, actif, aide, css  from ".$NPDS_Prefix."rblocks order by Rindex ASC");
   $num_row=sql_num_rows($result);
   $toggle = new ToggleDiv($num_row);
   if ($num_row>0) {
      echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
      echo "<tr><td width=\"65%\" class=\"ongl\" align=\"left\">".adm_translate("Titre :")."</td><td width=\"10%\" class=\"ongl\" align=\"right\">".adm_translate("Actif(s)")." :</td><td  width=\"10%\" class=\"ongl\" align=\"right\">Index :</td><td width=\"10%\" class=\"ongl\" align=\"right\"><span style=\"font-size: 10px;\">".adm_translate("rétention en secondes")."</span> :</td><td width=\"5%\" class=\"ongl\" align=\"right\"> ID :</td></tr>";
      while (list($id, $title, $content, $member, $Rindex, $Scache, $Sactif, $BRaide, $css) = sql_fetch_row($result)) {
         $rowcolor = tablos();
         $funct="";
         if ($title=="") {
            //$title=adm_translate("Sans nom");
            $pos_func=strpos($content,"function#");
            $pos_nl=strpos($content,chr(13),$pos_func);
            if ($pos_func!==false) {
               $funct="<span style=\"font-size: 10px;\"> (";
               if ($pos_nl!==false)
                  $funct.=substr($content,$pos_func, $pos_nl-$pos_func);
               else
                  $funct.=substr($content,$pos_func);
               $funct.=")</span>";
            }
            $funct=adm_translate("Sans nom").$funct;
         }
         echo "<tr $rowcolor><td align=\"left\">";
         echo $toggle->Img();
         echo aff_langue($title)."".$funct."</td>";
         if ($Sactif)
            echo "<td class=\"noir\" align=\"right\">".adm_translate("Oui")."</td>";
         else
            echo "<td class=\"rouge\" align=\"right\">".adm_translate("Non")."</td>";
         echo "<td align=\"right\">$Rindex</td><td align=\"right\">$Scache</td>";
         echo "<td align=\"right\">$id</td></tr>";

         echo "<tr><td colspan=\"5\">";
         echo $toggle->Begin();
         echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr $rowcolor><td>
         <table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><form action=\"admin.php\" method=\"post\">\n";
         echo "<tr $rowcolor><td width=\"70%\">\n";
         echo "<b>".adm_translate("Titre :")."</b> <input class=\"textbox_standard\" type=\"text\" name=\"title\" size=\"50\" maxlength=\"255\" value=\"$title\" /><br /><br /><b>Index : </b>";
         echo "<input class=\"textbox_standard\" type=\"text\" name=\"Rindex\" size=\"5\" maxlength=\"4\" value=\"$Rindex\" /></td><td valign=\"top\" rowspan=\"2\"><b>";
         echo adm_translate("rétention en secondes")." : </b><input class=\"textbox_standard\" type=\"text\" name=\"Scache\" size=\"6\" maxlength=\"5\" value=\"$Scache\" /><br />".adm_translate("Chaque bloc peut utiliser SuperCache.<br />La valeur du délai de rétention <b>0</b> indique que le bloc ne sera <b>pas caché</b> (obligatoire pour le bloc function#adminblock).")."<br /><br />";

         echo "<a href=\"javascript:void(0);\" onclick=\"window.open('autodoc.php?op=blocs', 'windocu', 'width=720, height=400, resizable=yes,menubar=no,location=no,directories=no,status=no,copyhistory=no,toolbar=no,scrollbars=yes');\" class=\"noir\">";
         echo adm_translate("Manuel en ligne")."</a>";
         echo "<br /><br />";

         echo adm_translate("Activer le Bloc")." : <input type=\"checkbox\" name=\"Sactif\" value=\"ON\" ";
         if ($Sactif) echo "checked=\"checked\"";
         echo "><br />";

         echo adm_translate("CSS Specifique")." : <input type=\"checkbox\" name=\"css\" value=\"1\" ";
         if ($css=="1") echo "checked=\"checked\"";
         echo "><br />";

         echo "</td></tr><tr><td>";
         echo "<b>".adm_translate("Contenu :")."</b>";
         echo "<br /><textarea class=\"textbox\" cols=\"70\" rows=\"5\" name=\"content\" style=\"width: 95%;\">$content</textarea>";
         echo "<br /><b>".adm_translate("Aide en ligne de ce bloc")." :</b><br /><textarea class=\"textbox\" cols=\"50\" rows=\"2\" name=\"BRaide\">$BRaide</textarea>";
         echo "</td></tr><tr><td colspan=\"2\" align=\"left\" valign=\"top\">";
         echo droits_bloc($member);
         echo "</td></tr>\n<tr><td colspan=\"2\">";
         echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
         echo "<select class=\"textbox_standard\" name=\"op\">";
         echo "<option value=\"changerblock\" selected=\"selected\">".adm_translate("Modifier un Bloc droit")."</option>";
         echo "<option value=\"deleterblock\">".adm_translate("Effacer un Bloc droit")."</option>";
         echo "<option value=\"gaucherblock\">".adm_translate("Transférer à Gauche")."</option>";
         echo "</select>";
         echo " <input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Ok")."\" />";
         echo $toggle->End();
         echo "</td></tr>\n</form></table>
         </td></tr></table><br />";
         echo "</td></tr>";
      }
      echo "</table>";
   }
  }
  echo "<br /><hr noshade=\"noshade\" /><table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
  echo adm_translate("Créer un nouveau Bloc");
  echo "</td></tr></table>\n";
  echo "<form action=\"admin.php\" method=\"post\" name=\"adminForm\"><table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\">";
  echo "<tr><td width=\"70%\"><b>\n";
  echo adm_translate("Titre :")."</b> <input class=\"textbox_standard\" type=\"text\" name=\"title\" size=\"50\" maxlength=\"255\" /><br /><br /><b>Index : </b>";
  echo "<input class=\"textbox_standard\" type=\"text\" name=\"index\" size=\"5\" maxlength=\"4\" /></td><td valign=\"top\" rowspan=\"2\"><b>";
  echo adm_translate("rétention en secondes")." : </b><input class=\"textbox_standard\" type=\"text\" name=\"Scache\" size=\"6\" maxlength=\"5\" value=\"60\" /><br />".adm_translate("Chaque bloc peut utiliser SuperCache.<br />La valeur du délai de rétention <b>0</b> indique que le bloc ne sera <b>pas caché</b> (obligatoire pour le bloc function#adminblock).");
  echo "<br /><br />";
  echo "<a href=\"javascript:void(0);\" onclick=\"window.open('autodoc.php?op=blocs', 'windocu', 'width=720, height=400, resizable=yes,menubar=no,location=no,directories=no,status=no,copyhistory=no,toolbar=no,scrollbars=yes');\" class=\"noir\">";
  echo adm_translate("Manuel en ligne")."</a>";
  echo "<br /><br /><b class=\"rouge\">HTML :</b> <input type=\"checkbox\" name=\"SHTML\" value=\"ON\" /><br />
  <b class=\"rouge\">CSS :</b> <input type=\"checkbox\" name=\"CSS\" value=\"ON\">
  </td></tr>\n<tr><td>";
  echo "<b>".adm_translate("Contenu :")."</b><br />";
  echo "<textarea class=\"textbox\"  name=\"xtext\" cols=\"70\" rows=\"5\" style=\"width: 95%;\"></textarea>";
  echo "<br /><b>".adm_translate("Aide en ligne de ce bloc")." :</b><br /><textarea class=\"textbox\" cols=\"70\" rows=\"2\" name=\"Baide\"></textarea>";
  echo "</td></tr>\n<tr><td colspan=\"2\" align=\"left\">";
  echo droits_bloc("0");
  echo "</td></tr>\n<tr><td colspan=\"2\">";
  if (($radminleft==1) or ($radminsuper==1))
     echo "<input type=\"radio\" name=\"op\" value=\"makelblock\" checked=\"checked\" />".adm_translate("Créer un Bloc gauche")."&nbsp;&nbsp;";
  if (($radminright==1) or ($radminsuper==1))
     echo "<input type=\"radio\" name=\"op\" value=\"makerblock\" checked=\"checked\" />".adm_translate("Créer un Bloc droite")."&nbsp;&nbsp;";
  echo "<input class=\"bouton_standard\" type=\"submit\" value=\"".adm_translate("Valider")."\" /></td></tr></table>\n</form><br />";
  closetable();
  include("footer.php");
}

switch ($op) {
   case "blocks":
        blocks();
        break;
}
?>