<?php
/*
$Id $
*/
require_once ("formulaireparc.class.php");
require_once ("dbformparc.class.php");

class modelestation extends dbformparc {  
    var $table="modelestation";
    var $clePrimaire= "idmodelestation";
    var $typeCle= "N" ;

function modelestation($id,$db,$debug) {
parent::constructeur($id,$db,$debug);
} // fin constructeur

// cle automatique *************************************************************
function setId($db){
// id automatique nextid
$this->valF['idmodelestation'] = $db->nextId($this->table);
}
function verifierAjout(){
}
function setValFAjout($val){
}
// *****************************************************************************
function setvalF($val){
  $this->valF['libmodelestation'] = $val['libmodelestation'];
  $this->valF['idorganisme'] = $val['idorganisme'];
  $this->valF['idtypestation'] = $val['idtypestation'];
  $this->valF['idmodele'] = $val['idmodele'];
  $this->valF['idsysteme'] = $val['idsysteme'];
  $this->valF['idmarque'] = $val['idmarque'];
  if($val['dateachat']!="")
      $this->valF['dateachat'] = $this->dateDB($val['dateachat']); //==
  $this->valF['garantie'] = $val['garantie'];
  $this->valF['idfournisseur'] = $val['idfournisseur'];
  $this->valF['bc'] = $val['bc'];
  $this->valF['idscomp'] = $val['idscomp'];
  $this->valF['idslogi'] = $val['idslogi'];
  $this->valF['idsperi'] = $val['idsperi'];
}

function verifier(){
  $this->correct=True;
  // obligatoire
  if ($this->valF['libmodelestation']==""){
    $this->correct=false;
    $this->msg= $this->msg."Description obligatoire!<br>";
  } 
}//verifier

function setType(&$form,$maj) {
  if ($maj < 2) { //ajouter et modifier
    if ($maj==0){ //insert
      $form->setType('idmodelestation', 'hidden');
      $form->setType('station', 'select');
    } else { //modifier
      $form->setType('idmodelestation', 'hiddenstatic');
      $form->setType('station', 'hidden');
    }
//    $form->setType('libmodelestation', 'text');
    $form->setType('idorganisme', 'select');
    $form->setType('dateachat','date');
    $form->setType('garantie','select');
    $form->setType('idfournisseur','select');
    $form->setType('idmarque','select');
    $form->setType('idtypestation','select');
    $form->setType('idmodele','select');
    $form->setType('idsysteme','select');
//    $form->setType('bc','text');
    $form->setType('listenaturecomp', 'select');
    $form->setType('listecomp', 'selectliste');
    $form->setType('champcomp', 'selectlistemulti');
    $form->setType('listelogi', 'selectliste');
    $form->setType('champlogi', 'selectlistemulti');
    $form->setType('listenatureperi', 'select');
    $form->setType('listeperi', 'selectliste');
    $form->setType('champperi', 'selectlistemulti');
  } else {
    $form->setType('idmodelestation', 'hiddenstatic');
    $form->setType('libmodelestation', 'hiddenstatic');
    $form->setType('idorganisme', 'hidden');
    $form->setType('station', 'hidden');
    $form->setType('dateachat','hidden');
    $form->setType('garantie','hidden');
    $form->setType('idfournisseur','hidden');
    $form->setType('idmarque','hidden');
    $form->setType('idtypestation','hidden');
    $form->setType('idmodele','hidden');
    $form->setType('idsysteme','hidden');
    $form->setType('bc','hidden');
    $form->setType('listenaturecomp', 'hidden');
    $form->setType('listecomp', 'hidden');
    $form->setType('champcomp', 'hidden');
    $form->setType('listelogi', 'hidden');
    $form->setType('champlogi', 'hidden');
    $form->setType('listenatureperi', 'hidden');
    $form->setType('listeperi', 'hidden');
    $form->setType('champperi', 'hidden');
  }
  $form->setType('idscomp', 'hidden');  
  $form->setType('idslogi', 'hidden');   
  $form->setType('idsperi', 'hidden');  
}

function setSelect(&$form, $maj,&$db,$DEBUG) {
  include ("../dyn/connexion.php");
  include ("../sql/".$dsn['phptype']."/".$this->table.".form.inc");
  if($maj<2){
    $form->setSelect("idorganisme",$this->selectArray($db,$sql_organisme));
    $form->setSelect("idfournisseur",$this->selectArray($db,$sql_fournisseur,0," Choisir un fournisseur "));
    $form->setSelect("idmarque",$this->selectArray($db,$sql_marque,0," GENERIQUE "));
    $contenu=array();
    $contenu[0]=array('1','2','3','4','5');
    $contenu[1]=array('1','2','3','4','5');
    $form->setSelect("garantie",$contenu);
    $form->setSelect("idmodele",$this->selectArray($db,$sql_modele,0," Choisir un modèle "));
    $form->setSelect("idsysteme",$this->selectArray($db,$sql_systeme,0," Choisir un système "));
    $form->setSelect("idtypestation",$this->selectArray($db,$sql_typestation,0," Choisir un type "));
    $contenu=array();
    $contenu[0]=$naturecomposant[0];
    $contenu[1]=$naturecomposant[1];
    $form->setSelect("listenaturecomp",$contenu);
    $form->setSelect("listelogi",$this->selectArray($db,$sql_modelelogiciel));
    $contenu=array();
    $contenu[0]=$natureperipheriquestation[0];
    $contenu[1]=$natureperipheriquestation[1];
    $form->setSelect("listenatureperi",$contenu);
    if ($maj==1) {
      //setselect champ composants
      $contenu=array();
      $idscomp=$this->val[array_search("idscomp", $this->champs)]; 
      //peupler champ en fonction des ids
      if ($idscomp!='') {
        $idscomp=explode(",",$idscomp);
        $k=0;
        foreach ($idscomp as $idcomp) {
          $contenu[0][$k]=$idcomp;
          $contenu[1][$k]=$db->getOne("select libmodele from modeleelement where idmodele=$idcomp");
          $k++;
        }
      }
      $contenu[2] ="listecomp"; //liste utilisee pour remplissage
      $contenu[3] ="idscomp";  //chp cache pour liste id ajoutes
      $form->setSelect("champcomp",$contenu);
      //setselect champ logiciels
      $contenu=array();
      $idslogi=$this->val[array_search("idslogi", $this->champs)]; 
      //peupler champr en fonction des ids
      if ($idslogi=='') {
        $sql="";
      } else {
        $sql="select idmodele,libmodele from modeleelement where idmodele in ($idslogi) order by libmodele";
      }
      if ($sql) {
        $contenu=$this->selectArray($db,$sql);
      } 
      $contenu[2] ="listelogi"; //liste utilisee pour remplissage
      $contenu[3] ="idslogi";  //chp cache pour liste id ajoutes
      $form->setSelect("champlogi",$contenu);
      //setselect champ peripheriques
      $contenu=array();
      $idsperi=$this->val[array_search("idsperi", $this->champs)]; 
      //peupler champ en fonction des ids
      if ($idsperi=='') {
        $sql="";
      } else {
        $sql="select idmodele,libmodele from modeleelement where idmodele in ($idsperi) order by libmodele";
      }
      if ($sql) {
        $contenu=$this->selectArray($db,$sql);
      } 
      $contenu[2] ="listeperi"; //liste utilisee pour remplissage
      $contenu[3] ="idsperi";  //chp cache pour liste id ajoutes
      $form->setSelect("champperi",$contenu);
    } else {  //$maj==0
      $form->setSelect("station",$this->selectArray($db,$sql_station,0," Choisir une station pour modele "));
      $contenu="";
      $contenu[2] ="listecomp"; //liste utilisee pour remplissage
      $contenu[3] ="idscomp";  //chp cache pour liste id ajoutes
      $form->setSelect("champcomp",$contenu);
      $contenu="";
      $contenu[2] ="listelogi"; //liste utilisee pour remplissage
      $contenu[3] ="idslogi";  //chp cache pour liste id ajoutes
      $form->setSelect("champlogi",$contenu);
      $contenu="";
      $contenu[2] ="listeperi"; //liste utilisee pour remplissage
      $contenu[3] ="idsperi";  //chp cache pour liste id ajoutes
      $form->setSelect("champperi",$contenu);
    }
  }
}

function setTaille(&$form,$maj){
  $form->setTaille('champcomp',6);
  $form->setTaille('listecomp',6);
  $form->setTaille('champlogi',6);
  $form->setTaille('listelogi',6);
  $form->setTaille('champperi',6);
  $form->setTaille('listeperi',6);
}

function setMax(&$form,$maj){
  $form->setMax('champcomp',6);
  $form->setMax('listecomp',6);
  $form->setMax('champlogi',6);
  $form->setMax('listelogi',6);
  $form->setMax('champperi',6);
  $form->setMax('listeperi',6);
}

function setOnchange(&$form,$maj){
$form->setOnchange("listenaturecomp","peuplerliste(this,'comp')");
$form->setOnchange("listenatureperi","peuplerliste(this,'peri')");
$form->setOnchange("station","peuplerform(this)");
?>
<script language="javascript">
function peuplerliste(l1,s) {
  var l2 = document.getElementsByName("liste"+s);   
  var index = l1.selectedIndex;   
  if(index < 1)   
    l2[0].options.length = 0;   
  else {   
    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 = "theme="+escape(l1.options[index].value)+"&form="+f1.name+"&select=liste"+s;   

    xhr_object.open("POST", "../spg/dynselectinstances.php", true);   
       
    xhr_object.onreadystatechange = function() {   
      if(xhr_object.readyState == 4) {   
        eval(xhr_object.responseText);
       }   
    }   
    xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");   
    xhr_object.send(data);   
  }   
}

function peuplerform(l1) {
  var index = l1.selectedIndex;   
  if(index >0) {  
    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 = "idstation="+escape(l1.options[index].value)+"&form="+f1.name;

    xhr_object.open("POST", "../spg/dynselectmodelestation2.php", true);
       
    xhr_object.onreadystatechange = function() {   
      if(xhr_object.readyState == 4) {   
        eval(xhr_object.responseText);
       }   
    }   
    xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");   
    xhr_object.send(data);   
  }   
}
</script>
<?php
}

function setGroupe(&$form, $maj) {
  if ($maj<2) {
    $form->setGroupe('idmodelestation','D');
    $form->setGroupe('libmodelestation','G');
    $form->setGroupe('idorganisme','G');
    $form->setGroupe('station','F');
    $form->setGroupe('idmodele', 'D');
    $form->setGroupe('idmarque', 'F');
    $form->setGroupe('idtypestation', 'D');
    $form->setGroupe('idsysteme', 'F');
    $form->setGroupe('dateachat', 'D');
    $form->setGroupe('idfournisseur', 'F');
    $form->setGroupe('bc','D');
    $form->setGroupe('garantie','F');
    $form->setGroupe('listecomp','D');
    $form->setGroupe('champcomp','F');
    $form->setGroupe('listelogi','D');
    $form->setGroupe('champlogi','F');
    $form->setGroupe('listeperi','D');
    $form->setGroupe('champperi','F');
  }
}

function setRegroupe(&$form,$maj){
  if ($maj<2) {
    $form->setRegroupe('idmodele', 'D','Options');
    $form->setRegroupe('idmarque', 'G','');
    $form->setRegroupe('idtypestation', 'G','');
    $form->setRegroupe('idsysteme', 'G','');
    $form->setRegroupe('dateachat', 'G','');
    $form->setRegroupe('idfournisseur', 'G','');
    $form->setRegroupe('bc', 'G','');
    $form->setRegroupe('garantie', 'F','');
    $form->setRegroupe('listenaturecomp','D','Composants');
    $form->setRegroupe('listecomp','G','');
    $form->setRegroupe('champcomp','F','');
    $form->setRegroupe('listelogi','D','Logiciels');
    $form->setRegroupe('champlogi','F','');
    $form->setRegroupe('listenatureperi','D','Périphériques');
    $form->setRegroupe('listeperi','G','');
    $form->setRegroupe('champperi','F','');
  }
}

function setVal(&$form,$maj,$validation,&$db) {
  if ($validation==0 and $maj==0){

  }
}

function setLib(&$form,$maj) {
  $form->setLib('idmodelestation','ID');
  $form->setLib('libmodelestation',' ---   Modèle station');
  $form->setLib('idorganisme',' Organisme');
  $form->setLib('dateachat','Date achat');
  $form->setLib('idfournisseur','Fournisseur');
  $form->setLib('idmarque','Marque');
  $form->setLib('idtypestation','Type station');
  $form->setLib('idmodele','Modèle');
  $form->setLib('idsysteme','Sytème');
  $form->setLib('bc','Bon de commande');
  $form->setLib('listenaturecomp','Nature composant');
  $form->setLib('listenatureperi','Nature périphérique');
  $form->setLib('listecomp','');
  $form->setLib('champcomp','');
  $form->setLib('listelogi','');
  $form->setLib('champlogi','');
  $form->setLib('listeperi','');
  $form->setLib('champperi','');
}

}// fin de classe
?>