<script language="javascript">
//declaration des fonctions java en debut de fichier pour implementation ajax grace a include
//sinon fonctions non visibles
function vdate(champ)
{
if(fenetreouverte==true)
 pfenetre.close();
 pfenetre=window.open("../spg/calendrier.php?origine="+champ,"calendrier","width=310,height=230,top=120,left=120");
 fenetreouverte=true;
}
   function refresh_ids(champ,champ3) {
     var tids=document.f1.elements[champ3];
     var lids=document.f1.elements[champ];
     tids.value="";
     if (lids.options.length>0) {
        for (i=0;i<lids.options.length;i++) 
          if (lids.options[i].value) tids.value+=lids.options[i].value+",";
        tids.value=tids.value.substring(0,tids.value.length-1);
     }
   }
   function addlist(champ,champ2,champ3) {
      var linst=document.f1.elements[champ2];
      var lids=document.f1.elements[champ];
      if (linst.selectedIndex>=0) {
        lids.options[lids.options.length]=new Option(linst.options[linst.selectedIndex].text,linst.options[linst.selectedIndex].value);  
        refresh_ids(champ,champ3);
      }
   }
/*   function addalllist(champ,champ2) {
      var linst=document.f1.elements[champ2];
      var lids=document.f1.elements[champ];
      lids.options.length=0;
      for (i=0;i<linst.options.length;i++)
        lids.options[lids.options.length]=new Option(linst.options[i].text,linst.options[i].value);
      document.f1.elements["champ3"].value='all';
      document.f1.elements["_unselect+champ"].disabled=true;
      document.f1.elements["_select+champ"].disabled=true;
   }*/
   function removelist(champ,champ3) {
      var lids=document.f1.elements[champ];
      if (lids.selectedIndex>=0) {
        lids.remove(lids.selectedIndex);  
        refresh_ids(champ,champ3);
      }                    
   }
   function removealllist(champ,champ3) {
      var lids=document.f1.elements[champ];
      lids.options.length=0;
      refresh_ids(champ,champ3);
      document.f1.elements["_unselect+champ"].disabled=false;
      document.f1.elements["_select+champ"].disabled=false;
   }
</script>
<?php
require_once ("formulaire.class.php");

class formulaireparc extends formulaire{

var $onkeyup;    // javascrpt en cas de keyup
var $onclick;    // javascrpt en cas de clic

function formulaireparc($a, $validation,$maj, $champs, $val,$max) {
  parent::formulaire($a, $validation,$maj, $champs, $val,$max);
         // onkeyup
         for($i=0;$i<count($champs);$i++){
             $this->onkeyup[$champs[$i]]="";
             $this->onclick[$champs[$i]]="";
         }
}

function recupererPostvarsousform($champs,$validation,$postVar,$DEBUG){
  for($i=0;$i<count($champs);$i++){
    if ($validation>0){
      //  magic_quotes_gpc est initialisé dans php.ini (mise automatique de
      //  quote quand il y a un ", \ , '.
      if($this->type[$champs[$i]]!="textdisabled" and $this->type[$champs[$i]]!="static"){
        if (!get_magic_quotes_gpc()) { // magic_quotes_gpc = Off
          $this->val[$champs[$i]] = strtr($postVar[$champs[$i]],chr(34),"'");
        }else{  // magic_quotes_gpc = On
          $this->val[$champs[$i]] = strtr(stripslashes($postVar[$champs[$i]]),chr(34),"'");
        }
      }else
        $this->val[$champs[$i]] ="";
      $this->val[$champs[$i]] = utf8_decode($this->val[$champs[$i]]);
    } //else  //validation=0
  }
}

function recupererPostvar($champs,$validation,$postVar,$DEBUG){  //surcharge pour test si variable postée existe
for($i=0;$i<count($champs);$i++){                                //avant affectation à $this->val[$champs[$i]]
     if ($validation>0){
        //  magic_quotes_gpc est initialisé dans php.ini (mise automatique de
        //  quote quand il y a un ", \ , '.
        if($this->type[$champs[$i]]!="textdisabled" and $this->type[$champs[$i]]!="static" and array_key_exists($champs[$i],$postVar)){
            if (!get_magic_quotes_gpc()) { // magic_quotes_gpc = Off
                $this->val[$champs[$i]] = strtr($postVar[$champs[$i]],chr(34),"'");
            }else{  // magic_quotes_gpc = On
                $this->val[$champs[$i]] = strtr(stripslashes($postVar[$champs[$i]]),chr(34),"'");
            }
        }else
            $this->val[$champs[$i]] ="";
        }
//$this->val[$champs[$i]]=utf8_decode($this->val[$champs[$i]]);
}
}

function date($champ,$validation,$DEBUG){
     if ($this->val[$champ]!="" and $validation==0){
         $this->val[$champ]=$this->dateAff($this->val[$champ]);
     }
 if(!$this->correct) {
      echo "<INPUT type='text' name='".$champ.
      "' value='".$this->val[$champ]."' size='".$this->taille[$champ].
       "' maxlength='10' onchange=\"".
      $this->onchange[$champ]."\" class='champFormulaire' >";

?><a href="javascript:vdate('<?php echo($champ);?>');"><?php
 // * custom *
       if(file_exists("../dyn/custom/img/ico_calendrier.png")) {
          echo "<img src='../dyn/custom/img/ico_calendrier.png' align='middle' border='0' vspace='0' hspace='10'>";
       }
       else {
         echo "<img src='../img/calendrier.gif' align='middle' border='0' vspace='0' hspace='10'>";
       }
       //*
echo "</a>";
/*?>*/
/*<?php*/
echo "";
   }else{
        echo "<INPUT type='text' name=".$champ.
      "' value='".$this->val[$champ]."'  size='".$this->taille[$champ].
       "' maxlength='10'class='champFormulaire' disabled>";
  }
}

function text($champ,$validation,$DEBUG){
  //surcharge pour evenements onkeyup et onclick
 if(!$this->correct) {
   echo "<INPUT type=".$this->type[$champ]." name='".
   $champ."' value=\"".
   $this->val[$champ]."\" size=".$this->taille[$champ].
   " maxlength=".$this->max[$champ]." class='champFormulaire' ";
   if ($this->onchange!="")
       echo "onchange=\"".$this->onchange[$champ]."\" ";
   if ($this->onkeyup!="")
       echo "onkeyup=\"".$this->onkeyup[$champ]."\" ";
   if ($this->onclick!="")
       echo "onclick=\"".$this->onclick[$champ]."\" ";
   echo ">";
 }else{
    echo "<INPUT type=".$this->type[$champ]." name='".
       $champ."' value=\"".
       $this->val[$champ]."\" size=".$this->taille[$champ].
       " maxlength=".$this->max[$champ]." class='champFormulaire' disabled>";
}}

// ***************************************************************************
// SELECTLISTE (liste)
// affichage de table
//select['nomduchamp'][0]= value de l option
//select['nomduchamp'][1]= affichage
// ****************************************************************************
function selectliste($champ,$validation,$DEBUG){
  if(!$this->correct) {
    echo "<select name='".$champ."' size='".$this->taille[$champ].
       "' class='champFormulaire' ";
    if($this->onchange[$champ]!="")
      echo "onchange=\"".$this->onchange[$champ]."\" ";  
    if($this->onclick[$champ]!="")
      echo "onclick=\"".$this->onclick[$champ]."\" ";  
    echo ">";
   }else
      echo "<select name='".$champ."' size='".$this->taille[$champ].
       "' class='champFormulaire' disabled >";
   $k=0;
   foreach($this->select[$champ] as $elem)
     //  $nOption++;
        while ($k <count($elem)) {
          if(!$this->correct) {
               if ($this->val[$champ]==$this->select[$champ][0][$k])
                 echo "<option selected value=\"".$this->select[$champ][0][$k].
                 "\">".$this->select[$champ][1][$k]."</option>";
               else
                 echo "<option value=\"".$this->select[$champ][0][$k].
                 "\">".$this->select[$champ][1][$k]."</option>";
                 $k++;

          }else{
             if ($this->val[$champ]==$this->select[$champ][0][$k]){
                 echo "<option selected value=\"".$this->select[$champ][0][$k].
                 "\" >".$this->select[$champ][1][$k]."</option>";
                 $k =count($elem);
             }
          $k++;
          }
          }
   echo "</select>";

}

// ***************************************************************************
// SELECTLISTEMULTI (liste)
// affichage de table
//select['nomduchamp'][0]= value de l option
//select['nomduchamp'][1]= affichage
//select['nomduchamp'][2]= autre select dont la value peut etre ajoutée
//select['nomduchamp'][3]= champ caché des values ajoutées ex: 45,12,32
// ****************************************************************************
function selectlistemulti($champ,$validation,$DEBUG){
// colones = taille
// lignes = max
   echo "<table><tr><td>";
   if(!$this->correct) {
    $champ2=$this->select[$champ][2];
    $champ3=$this->select[$champ][3];
    echo "<table border=1 ><tr><td>";
    echo "<input type='button' name='_select$champ' onclick='addlist(\"$champ\",\"$champ2\",\"$champ3\")' value='->' class='boutonmulti'> ";
    echo "</td></tr><tr><td>";
    echo "<input type='button' name='_unselect$champ' onclick='removelist(\"$champ\",\"$champ3\")' value='<-' class='boutonmulti'> ";
    echo "</td></tr><tr><td>";
    echo "<input type='button' name='_unselectall$champ' onclick='removealllist(\"$champ\",\"$champ3\")' value='<<' class='boutonmulti'> ";
//    echo "</td></tr><tr><td>";
//    echo "<input type='button' name='_selectall$champ' onclick='addalllist(\"$champ\",\"$champ2\")' value='>>' class='boutonmulti'> ";
    echo "</td></tr></table></td><td>";
    echo "<select name='".$champ."' size='".$this->taille[$champ].
       "' class='champFormulaire' ";
    if($this->onchange[$champ]!="")
      echo "onchange=\"".$this->onchange[$champ]."\" ";  
    if($this->onclick[$champ]!="")
      echo "onclick=\"".$this->onclick[$champ]."\" ";  
    echo ">";
   }else 
      echo "<select name='".$champ."' size='".$this->taille[$champ].
       "' class='champFormulaire' disabled >";
   $k=0;
   foreach($this->select[$champ] as $elem)
     //  $nOption++;
        while ($k <count($elem)) {
          if(!$this->correct) {
               if ($this->val[$champ]==$this->select[$champ][0][$k])
                 echo "<option selected value=\"".$this->select[$champ][0][$k].
                 "\">".$this->select[$champ][1][$k]."</option>";
               else
                 echo "<option value=\"".$this->select[$champ][0][$k].
                 "\">".$this->select[$champ][1][$k]."</option>";
                 $k++;
/*   ?>
   <script type="text/javascript">
   </script>
   <?php */
          }else{
             if ($this->val[$champ]==$this->select[$champ][0][$k]){
                 echo "<option selected value=\"".$this->select[$champ][0][$k].
                 "\" >".$this->select[$champ][1][$k]."</option>";
                 $k =count($elem);
             }
          $k++;
          }
          }
   echo "</select>";
   echo "</td></tr></table>";
}

function setOnkeyup($champ,$contenu){
// javascript
$this->onkeyup[$champ]=$contenu;
}

function setOnclick($champ,$contenu){
// javascript
$this->onclick[$champ]=$contenu;
}

} // fin de classe
?>