<?php
/*
$Id: imprimante.class.php,v 1.7 2008-04-08 09:56:58 fgiva Exp $
*/
require_once ("formulaireparc.class.php");
require_once ("peripherique.class.php");

class imprimante extends peripherique {

function imprimante($id,&$db,$DEBUG,$nature) {
  parent::constructeur($id,$db,$DEBUG);
  if (isset($nature)) $this->nature=$nature;
  else $this->nature='tout';
} // fin constructeur

function setvalF($val){
  parent::setvalF($val);
  $this->valF['numero'] = $val['numero'];  //ajout 
  $this->valF['nomelement'] = $val['nomelement'];
  $this->valF['idstation'] = $val['idstation'];
  $this->valF['idservice'] = $val['idservice'];          
  $this->valF['idbatiment'] = $val['idbatiment'];        
  $this->valF['boitierext'] = $val['boitierext'];
}

function setType(&$form,$maj) {
  parent::setType($form,$maj); 
  $form->setType('typeelement', 'hidden');
  if ($maj < 2) { //ajouter et modifier
    if ($maj==0)
      $form->setType('numero', 'text');
    else {
      if ($form->val['numero'])
         $form->setType('numero', 'hiddenstatic');
      else
         $form->setType('numero', 'text');
    }
    $form->setType('nomelement', 'text');
    $form->setType('idstation', 'select');
    $form->setType('idservice', 'select');
    $form->setType('idbatiment', 'select');
    $form->setType('boitierext', 'select');
  } else
    $form->setType('numero', 'hiddenstatic');
}

function setSelect(&$form, $maj,$db,$debug) {
  include ("../dyn/connexion.php");
  include ("../sql/".$dsn['phptype']."/".$this->table.".form.inc");
  parent::setSelect($form, $maj,$db,$debug);
  if($maj<2){
    $form->setSelect("idmodele",$this->selectArray($db,$sql_modele[get_class($this)],0," Choisir un modèle"));
    $form->setSelect("idstation",$this->selectArray($db,$sql_station,0," Aucune"));
    $form->setSelect("idservice",$this->selectArray($db,$sql_service,0," Aucun"));
    $form->setSelect("idbatiment",$this->selectArray($db,$sql_batiment,0," Aucun"));
    $contenu=array();
    $contenu[0]=array('f','v');
    $contenu[1]=array('Non','Oui');
    $form->setSelect("boitierext",$contenu);
  }
}

function setLib(&$form,$maj) {
  parent::setLib($form,$maj);
  $form->setLib('nomelement','Nom Réseau');
  $form->setLib('idstation','Station');
  $form->setLib('idservice','Service');
  $form->setLib('idbatiment','Batiment');
  $form->setLib('boitierext','Boitier Jet-Direct');
}

function verifier(&$db){
  include ("../dyn/connexion.php");
  include ("../sql/".$dsn['phptype']."/".$this->table.".form.inc");
  parent::verifier($db);
  if($this->valF['numserie']=="") { //en plus du numero imposé
    $this->correct=false;
    $this->msg= $this->msg."<br>NoSérie obligatoire";
  }
  if ($this->correct) {
    if ($this->valF['idetatelement']==1) { //affectation
      $this->correct=(($this->valF['idstation']>0 && $this->valF['idservice']==0 && $this->valF['idbatiment']==0) || ($this->valF['idstation']==0 && $this->valF['idservice']>0 && $this->valF['idbatiment']>0));
      if (!$this->correct) $this->msg= $this->msg."<br>Affectation à choisir:rattachement station ou service/batiment";
    } else { //non affectation
      $this->correct=($this->valF['idstation']==0 && $this->valF['idservice']==0 && $this->valF['idbatiment']==0);
      if (!$this->correct) $this->msg= $this->msg."<br>Vous avez choisi une affectation!";
    }
  }
}//verifier
 
function setRegroupe(&$form,$maj,&$db,$idx){
  parent::setRegroupe($form,$maj,$db,$idx);
  if ($maj<2) {
    $form->setRegroupe('idservice','D','Affectation');
    $form->setRegroupe('idbatiment','G','');
    $form->setRegroupe('idetatelement','G','');
    $form->setRegroupe('idstation','F','');
  }
}

}// fin de classe
?>