<?php
//$Id: elu.class.php,v 1.8 2009-06-06 09:22:24 fraynaud1 Exp $
include ("../dyn/var.inc");
require_once ($path_om."formulairedyn.class.php");
require_once ($path_om."dbformdyn.class.php");
//
class elu extends dbForm
{
    var $table = "elu";
    var $clePrimaire = "elu";
    var $typeCle = "A";

    function elu ($id, $db, $debug)
    {
        $this -> constructeur ($id, $db, $debug);

    } // param_elu ($id, $db, $debug)
    
    function setvalF($val){
    	//"elu","nom","prenom","nomjf","date_naissance","lieu_naissance",
        //      "adresse","cp","ville"
		$this->valF['nom'] = $val['nom'];
		$this->valF['prenom'] = $val['prenom'];
		$this->valF['nomjf'] = $val['nomjf'];
		if($val['date_naissance']!="")
    		$this->valF['date_naissance'] = $this->dateDB($val['date_naissance']);
    	$this->valF['lieu_naissance'] = $val['lieu_naissance'];
		$this->valF['adresse'] = $val['adresse'];
		$this->valF['cp'] = $val['cp'];
		$this->valF['ville'] = $val['ville'];
    }
    

    function setId($db){
    // id automatique nextid
    $temp=$db->nextId($this->table);
    $temp=str_pad($temp,6,"0", STR_PAD_LEFT);
    $this->valF['elu'] = "E".$temp;
    }

    function verifierAjout(){
    }

    function setValFAjout($val){
    }

    function verifier ()
    {
        $this -> correct = True;
        $imgv="";
        $f="&nbsp!&nbsp;&nbsp;&nbsp;&nbsp;";
        $imgv="<img src='../img/punaise.png' align='middle'  border='0'>";
        //if ($this -> valF ['elu'] == "")
        //{
        //    $this -> correct = false;
        //    $this -> msg = $this -> msg . $imgv." Code elu obligatoire !";
        //}
        if ($this -> valF ['nom'] == "")
        {
            $this -> correct = false;
            $this -> msg = $this -> msg . $imgv.$this->lang("nom")."&nbsp;".$this->lang("obligatoire").$f;
        }
        if ($this -> valF ['prenom'] == "")
        {
            $this -> correct = false;
            $this -> msg = $this -> msg . $imgv.$this->lang("prenom")."&nbsp;".$this->lang("obligatoire").$f;
        }
    } // verifier ()



    function setType (&$form, $maj) 
    {

        if ($maj < 2)
        {
            // Ajout
            $form -> setType ('date_naissance', 'date');
            $form -> setType ('elu', 'hidden');
            if ($maj == 1)
            {
                // Modification
                 $form -> setType ('elu', 'hiddenstatic');
            }
        }
        else
        {
             $form -> setType ('elu', 'hiddenstatic');
            // Suppression
        }
    } // setType (&$form, $maj) 

function setVal(&$form,$maj,$validation){
if ($validation==0) {
  if ($maj == 0){
    include ("../dyn/var.inc");
    $form->setVal('cp', $client_cp);
    $form->setVal('ville', $client_ville);
}}
}

function setOnchange(&$form,$maj){
$form->setOnchange("nom","this.value=this.value.toUpperCase()");
$form->setOnchange("ville","this.value=this.value.toUpperCase()");
}

function cleSecondaire($id,$db,$val,$debug) {
$this->rechercheAffectation($id,$db,$debug) ;
}

function rechercheAffectation($id,$db,$debug){
    $this->correct=True;
    $imgv="";
    $f="&nbsp!&nbsp;&nbsp;&nbsp;&nbsp;";
    $imgv="<img src='../img/punaise.png' align='middle'  border='0'>";
    $sql = "select * from affectation where elu ='".$id."'";
    $res = $db->query($sql);
    if($debug==1) echo $sql;
    if (DB :: isError($res))
       die($res->getMessage(). " => Echec  ".$sql);
    else{
        $nbligne=$res->numrows();
        $this->msg = $this->msg.$imgv."&nbsp;".$this->lang("il_y_a")."&nbsp;<font class='parametre'>&nbsp;".$nbligne."&nbsp;</font>&nbsp;".
        $this->lang("enregistrement")."&nbsp;".$this->lang("en_lien")."&nbsp;".$this->lang("avec")."&nbsp;".$this->lang("table")." \"affectation\" ".$this->lang("pour")."&nbsp;".$this->lang("l")."&nbsp;".$this->lang("elu")."&nbsp; [".
        $id."]".$f."<br>";
        $this->msg = $this->msg." il y a ".$nbligne.
        " enregistrement(s) en lien dans la table affectation pour l elu [".
        $id."]";
        if ($nbligne>0)
           $this->correct=false;
    }
}


}
?>