<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* Toggle_Div Class Manipulation                                        */
/* Copyright (c) Ade (www.ade21.net) 2004                               */
/*                                                                      */
/* 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.       */
/************************************************************************/
//
// include_once ("lib/togglediv.class.php"); # description de l'objet et de ses methodes
// ToggleDiv = new ToggleDiv(nb de sections total); # Création des sections (y compris les sous-sections)
// ToggleDiv->All(); # Affiche Developper tout | Regrouper Tout de toutes les sections "ToggleDiv"
// ToggleDiv->Img(); # Affiche l'image qui permet de developper.
// ToggleDiv->Begin(); # Specifie le debut de la section associée au Img() précédent.
// ToggleDiv->End(); # Specifie la de la section associée au Img() précédent.

// - vous pouvez imbriquer une autre sous-section exclusivement entre un Begin() et End().
// - cette méthode utilise la fonction PHP "uniqid" qui génère un identifiant unique pour chaque objet ToggleDiv (lot de sections); ce qui permet de créer autant des sections rétractables souhaitées sur une page NPDS, et de d'utiliser le sections rétractables dans les modules sans se soucier des redéfinitions des fonctions !!javascript!!. Cette fontion peut etre remplacer dans le code par une autre qui fournit un identifiant unique sur page généré. uniqid est interressant car elle compatible PHP3/4
// - Les images peuvent être surchargées lors de la créations du ToggleDiv.

class ToggleDiv {
   var $id;
   var $count;
   var $max;
   var $imgtmpD;
   var $imgtmpR;

   function ToggleDiv($max) {
      $this->id  = uniqid("");
      $this->count = 0;
      $this->max = $max;
      if ($ibid=theme_image("replier.gif")) {$this->imgtmpR=$ibid;} else {$this->imgtmpR="images/replier.gif";}
      if ($ibid=theme_image("deplier.gif")) {$this->imgtmpD=$ibid;} else {$this->imgtmpD="images/deplier.gif";}

      echo "<style type=\"text/css\">\n";
      echo ".trigger".$this->id."0 { cursor: pointer; cursor: hand; }\n";
      for ($i = 1; $i<= $max; $i++) {
         echo ".trigger$this->id$i { cursor: pointer; cursor: hand; }\n";
         echo ".toggle$this->id$i  { display: none; }\n";
      }
      echo "</style>\n";
      echo "<script type=\"text/javascript\" language=\"javascript\">\n";
      echo "   var image_open = new Image();\n";
      echo "   image_open.src = \"".$this->imgtmpD."\";\n";
      echo "   var image_closed = new Image();\n";
      echo "   image_closed.src = \"".$this->imgtmpR."\";\n";

      echo "   function toggleall$this->id(type) {\n";
      echo "      if(document.all) {\n";
      for ($i=1; $i<=$max; $i++) {
         echo "            document.all[\"toggle_scr$this->id$i\"].style.display = type;\n";
         echo "            if(type==\"none\") {document.all[\"trigger_scr$this->id$i\"].src = image_closed.src;} else {document.all[\"trigger_scr$this->id$i\"].src = image_open.src;}";
      }
      echo "      }\n";
      echo "      else\n";
      echo "      {\n";
      for ($i=1; $i<=$max; $i++) {
         echo "         document.getElementById(\"toggle_scr$this->id$i\").style.display = type;\n";
         echo "         if(type==\"none\") {document.getElementById(\"trigger_scr$this->id$i\").src = image_closed.src;} else {document.getElementById(\"trigger_scr$this->id$i\").src = image_open.src;}";
      }
      echo "      }\n";
      echo "   }\n";

      echo "   function toggle$this->id(image, section) {\n";
      echo "      if(document.all) {\n";
      echo "        if(document.all[section].style.display == \"block\") {\n";
      echo "           document.all[section].style.display = \"none\";\n";
      echo "           document.all[image].src = image_closed.src;\n";
      echo "        }\n";
      echo "        else\n";
      echo "        {\n";
      echo "           document.all[section].style.display = \"block\";\n";
      echo "           document.all[image].src = image_open.src;\n";
      echo "        }\n";
      echo "      }\n";
      echo "      else\n";
      echo "      {\n";
      echo "      if(document.getElementById(section).style.display == \"block\") {\n";
      echo "         document.getElementById(section).style.display = \"none\";\n";
      echo "         document.getElementById(image).src = image_closed.src;\n";
      echo "         }\n";
      echo "      else\n";
      echo "         {\n";
      echo "         document.getElementById(section).style.display = \"block\";\n";
      echo "         document.getElementById(image).src = image_open.src;\n";
      echo "         }\n";
      echo "      }\n";
      echo "   }\n";
      echo "   </script>\n";
   }

   function All() {
       if ($ibid=theme_image("deplier_all.gif")) {$imgtmpDA=$ibid;} else {$imgtmpDA="images/deplier_all.gif";}
       if ($ibid=theme_image("replier_all.gif")) {$imgtmpRA=$ibid;} else {$imgtmpRA="images/replier_all.gif";}
       $ibid="<a href=\"#\" onclick=\"toggleall$this->id('block');\"><img border=\"0\" alt=\"\" class=\"trigger".$this->id."0\" align=\"middle\" id=\"trigger_scr".$this->id."0\" src=\"$imgtmpDA\" />";
       $ibid.=translate("All to develop")."</a>";
       $ibid.="&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;";
       $ibid.="<a href=\"#\"  onclick=\"toggleall$this->id('none');\"><img border=\"0\" alt=\"\" class=\"trigger".$this->id."0\" align=\"middle\" id=\"trigger_scr".$this->id."0\" src=\"$imgtmpRA\" />";
       $ibid.=translate("All to gather")."</a>\n";
       return($ibid);
   }

   function Img() {
       $this->count++;
       return("<img class=\"trigger$this->id$this->count\" align=\"middle\" id=\"trigger_scr$this->id$this->count\" src=\"".$this->imgtmpR."\" onclick=\"toggle$this->id('trigger_scr$this->id$this->count', 'toggle_scr$this->id$this->count');\" alt=\"\" />&nbsp;");
   }

   function Begin() {
       return("<div class=\"toggle$this->id$this->count\" id=\"toggle_scr$this->id$this->count\">\n");
   }

   function End() {
       return("</div>\n");
   }
}
?>