<script language="javascript">
function majuserinterv(l1) {
  var t1 = document.getElementsByName("demandeur");   
  t1[0].value=l1.options[l1.selectedIndex].text;
}

function peuplerlisteinterv(t1) {
  var l2 = document.getElementsByName("iddemandeur");   
  var xhr_object = null;   
          
  if(window.XMLHttpRequest) // Firefox   
    xhr_object = new XMLHttpRequest();   
  else if(window.ActiveXObject) // Internet Explorer   
    xhr_object = new ActiveXObject("Microsoft.XMLHTTP");   
  else { // XMLHttpRequest non supporté par le navigateur   
    alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");   
    return;   
  }   
 
  var data = "nom="+escape(t1.value)+"&form="+f2.name+"&select=iddemandeur";

  xhr_object.open("POST", "../spg/dynselectutilisateur.php", true);   
     
  xhr_object.onreadystatechange = function() {   
    if(xhr_object.readyState == 4) {   
      eval(xhr_object.responseText);
     //alert("transfert fini"+l2(0).value);
     }   
  }   
  xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");   
  xhr_object.send(data);   
}

function fdateinterv(champ){
if(champ.value.lastIndexOf("/")==-1){
if (champ.value.substring(0,2)>32){
   champ.value="";
   alert("jour > 32")
   return
}
if (champ.value.substring(2,4)>13){
   champ.value="";
   alert("mois > 12")
   return
}
if(champ.value.length==6)
champ.value=champ.value.substring(0,2)+"/"+champ.value.substring(2,4)+"/19"+champ.value.substring(4,6);
if(champ.value.length==8)
champ.value=champ.value.substring(0,2)+"/"+champ.value.substring(2,4)+"/"+champ.value.substring(4,8);
}
}
</script>
<?php
/*
$Id: intervention.class.php,v 1.9 2008-05-26 08:14:36 fgiva Exp $
*/
require_once ("formulaireparc.class.php");
require_once ("dbformparc.class.php");

class intervention extends dbFormparc {

    var $table="intervention";
    var $clePrimaire= "idintervention";
    var $typeCle= "N" ;
    var $champidx;
    var $idx; 

function intervention($id,&$db,$DEBUG) {
$this->constructeur($id,$db,$DEBUG);
}

function message($val){ //surcharge pour test val(numero) wmi
  if (strstr($val["station"],"WMI"))
    $this->msg.="<br>Saisie d'intervention interdite pour les stations sans numéro Mairie!";
  parent::message();
}

function bouton($maj,$val){ //surcharge pour test val(numero) wmi
if(file_exists("../dyn/custom/var.inc")) {
   include("../dyn/custom/var.inc");
}
else {
  include("../dyn/var.inc");
}
//*
if (!$this->correct){
   if ($maj == 2) //supprimer
       $bouton = "Supprimer";
   else
       if ($maj == 1) // modifier   
           $bouton = "Modifier";
       else // ajouter
           $bouton = "Ajouter";
   echo "<tr><td><br></td></tr><tr><td colspan=2><center><input type='submit' value='".
        $bouton." ".ucwords($this->table)."' style=".$styleBouton;
   if (!strstr($val["station"],"WMI"))
     echo " >";
   else
     echo " disabled=true >";
}}

function setvalF($val){
$this->valF['idintervention'] = $val['idintervention'];
$this->valF['idstation'] = $val['idstation'];
$this->valF['idperipherique'] = $val['idperipherique'];
$this->valF['idtype'] = $val['idtype'];
$this->valF['iddemandeur'] = $val['iddemandeur'];
$this->valF['idintervenant'] = $val['idintervenant'];
$this->valF['observations'] = $val['observations'];
$this->valF['idetatintervention'] = $val['idetatintervention'];
if($val['dateouverture']!="")
    $this->valF['dateouverture'] = $this->dateDB($val['dateouverture']);
if($val['datecloture']!="")
    $this->valF['datecloture'] = $this->dateDB($val['datecloture']);
}

// NE SURTOUT PAS EFFACER SINON HERITAGE DES FONCTIONS DE CLASSE DBFORM DIFFERENTES
// pas d initialisation valF pour la cle primaire
function setValFAjout($val){  //pas de récupération cleprim car non fixe encore
}
// initialisation valF pour la cle primaire
function verifierAjout(){   //pas de verif cleprim car non fixee encore
}

function setId($db){ //affectation de l'identifiant composant
// id automatique nextid
$this->valF['idintervention'] = $db->nextId($this->table);
}

function verifier(){
$this->correct=True;
// obligatoire
if ($this->valF['dateouverture']==""){
   $this->correct=false;
   $this->msg= $this->msg."<br>Date ouverture obligatoire";
}
if ($this->valF['iddemandeur']=="0" || $this->valF['iddemandeur']==""){ 
//peut etre = 0 si saisie dynamique infructueuse
   $this->correct=false;
   $this->msg= $this->msg."<br>Demandeur obligatoire";
}
if ($this->valF['idtype']==""){
   $this->correct=false;
   $this->msg= $this->msg."<br>Type obligatoire";
}
if ($this->valF['observations']==""){
   $this->correct=false;
   $this->msg= $this->msg."<br>Description obligatoire";
}
}//verifier

function setType(&$form,$maj) {
  if ($maj < 2) { //ajouter et modifier
    if ($maj == 0) {
        $form->setType('idintervention', 'hidden');
    } else {   //maj==1  modifier  
        $form->setType('idintervention', 'hiddenstatic');
    }
    $form->setType('idtype', 'select');
    $form->setType('idstation', 'hidden');
    if ($this->champidx=="idperipherique") {  //interv de periph
      $form->setType('idperipherique', 'hiddenstatic');
      $form->setType('station', 'hidden');
    }else{  //interv de station
      $form->setType('idperipherique', 'select');
      $form->setType('station', 'hiddenstatic');
    }
    $form->setType('dateouverture', 'date');
    $form->setType('demandeur', 'text');  //select
    $form->setType('iddemandeur', 'selectliste');
    $form->setType('idintervenant', 'select');
    $form->setType('datecloture', 'date');
    $form->setType('observations', 'textarea');
    $form->setType('idetatintervention', 'select');
  }else{ // supprimer
    $form->setType('idintervention', 'hiddenstatic');
    $form->setType('idtype', 'hidden');
    $form->setType('idstation', 'hidden');
    if ($this->champidx=="idperipherique") {  //interv de periph
      $form->setType('idperipherique', 'hiddenstatic');
      $form->setType('station', 'hidden');
    }else{  //interv de station
      $form->setType('idperipherique', 'hidden');
      $form->setType('station', 'hiddenstatic');
    }
    $form->setType('dateouverture', 'hiddenstaticdate');
    $form->setType('demandeur', 'hidden');
    $form->setType('iddemandeur', 'hidden');
    $form->setType('idintervenant', 'hidden');
    $form->setType('datecloture', 'hidden');
    $form->setType('observations', 'hidden');
    $form->setType('idetatintervention', 'hidden');
  }
  $form->setType('naturestation', 'hidden');
}

function setTaille(&$form,$maj){
  $form->setTaille('iddemandeur', 3);
  $form->setTaille('demandeur', 30);
  $form->setTaille('observations', 70);
}

function setMax(&$form,$maj){
  $form->setMax('observations', 4);
}

function setValsousformulaire(&$form,$maj,$validation,$idxformulaire,$retourformulaire,$typeformulaire,&$db){
  include ("../dyn/connexion.php");
  include ("../sql/".$dsn['phptype']."/".$this->table.".form.inc");
//  if (strstr($retourformulaire,"station"))
  if ($retourformulaire=="station")
    $this->champidx="idstation";
  else
    $this->champidx="idperipherique";
  if ($validation==0) {
    if ($maj == 0){
      $form->setVal($this->champidx, $idxformulaire);
      if ($this->champidx=="idstation")
        $form->setVal('numero', $db->getOne("select numero from station where idstation=$idxformulaire"));
      $form->setVal('dateouverture', date("Y-m-d")); 
      $form->setVal('idtype', 11);  //bureautique
      if ($this->champidx=="idstation")
        $demandeur=$db->getOne("select idutilisateur from station where idstation=$idxformulaire");
      else
        $demandeur=$db->getOne("select idutilisateur from element where idelement=$idxformulaire");
      if (!is_null($demandeur))
        $form->setVal('iddemandeur', $demandeur);  
    }    //idstation ou idelement 
  }
  $this->idx=$idxformulaire;
//  $form->setVal('naturestation', $retourformulaire);
}

/*function retoursousformulaire($idxformulaire,$retourformulaire,$val,$objsf,$premiersf){
// $retourformulaire= stationmairie, ...interco, ...ecoles, ...copieur
// zone cle = idstation ou idperipherique
if (!$this->correct){
     echo "<a href=\"form.php?obj=".
     $retourformulaire."&idx=".$val[$this->champidx]."&objsf=".$objsf."&premiersf=".$premiersf."\">"; // specifique
     // * custom *
    if(file_exists("../dyn/custom/img/retour.png")) {
       echo "<img src='../dyn/custom/img/retour.png' align='top' hspace='10' border='0'>";
    }
    else {
       echo"<img src='../img/retour.png' align='top' hspace='10' border='0'>";
    }
    //*
    echo "</a></center></td> </tr>";
}else{
     echo "<tr><td><br></td></tr><tr><td colspan=2><center><a href=\"form.php?obj=".
     $retourformulaire."&idx=".$val[$this->champidx]."&objsf=".$objsf."&premiersf=".$premiersf."\">"; // specifique
     // * custom *
    if(file_exists("../dyn/custom/img/retour.png")) {
       echo "<img src='../dyn/custom/img/retour.png' align='top'  border='0'>";
    }
    else {
       echo"<img src='../img/retour.png' align='top'  border='0'>";
    }
    //*
    echo "</a></center></td> </tr>";
}}*/

function setSelect(&$form, $maj,$db,$debug) {
  include ("../dyn/connexion.php");
  include ("../sql/".$dsn['phptype']."/".$this->table.".form.inc");
  if($maj<2){
    if ($this->champidx!="idperipherique") {
      $sql_peripherique= $sql_peripherique.$this->idx;
      $form->setSelect("idperipherique",$this->selectArray($db,$sql_peripherique,"0","Station"));
    }
    $form->setSelect("idtype",$this->selectArray($db,$sql_type,"","Choisir un type"));
    $form->setSelect("idintervenant",$this->selectArray($db,$sql_intervenant,"","Choisir un intervenant"));
    $form->setSelect("idetatintervention",$this->selectArray($db,$sql_etatintervention));
    if ($maj==1) {
      $iddemandeur=$this->val[array_search("iddemandeur",$this->champs)];
      if ($iddemandeur) {
        $sql_demandeur.=$iddemandeur;
        $form->setSelect("iddemandeur",$this->selectArray($db,$sql_demandeur));
      }
    }
  }
}

//function setGroupe(&$form,$maj){
//$form->setGroupe('nature','D');
//}

function setLib(&$form,$maj) {
$form->setLib('idperipherique','Périphérique');
$form->setLib('idtype','Type');
$form->setLib('iddemandeur','');
$form->setLib('idintervenant','Intervenant');
$form->setLib('dateouverture','Date ouverture');
$form->setLib('datecloture','Date cloture');
$form->setLib('idetatintervention','Etat intervention');
}              

function setOnkeyup(&$form,$maj) {
$form->setOnkeyup("demandeur","peuplerlisteinterv(this)");
}

function setOnclick(&$form,$maj){
$form->setOnclick("iddemandeur","majuserinterv(this)");
}

//
function setOnchange(&$form,$maj){
// mise en majuscule ***********************************************************
//$form->setOnchange("nom","this.value=this.value.toUpperCase()");

// nature change la zone taille ************************************************
//$form->setOnchange("nature","changetaille()");

// saisie de la date de naissance *********************************
// si vide et 6 caractères => 211082 = 21/10/1982
// si vide et 8 caractères => 21101982 = 21/10/1982
// controle 31 max pour jour et 12 max pour mois
// ****************************************************************
$form->setOnchange("dateouverture","fdateinterv(this)");
$form->setOnchange("datecloture","fdateinterv(this)");
}

}// fin de classe
?>