<?php
//$Id: poste.class.php,v 1.4 2008-07-29 14:00:45 jbastide Exp $
include ("../dyn/var.inc");
require_once ($path_om."formulairedyn.class.php");
require_once ($path_om."dbformdyn.class.php");
//
class poste extends dbForm
{
    var $table = "poste";
    var $clePrimaire = "poste";
    var $typeCle = "A";

    function poste ($id, $db, $debug)
    {
        $this -> constructeur ($id, $db, $debug);
    } // grade ($id, $db, $debug)

    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 ['poste'] == ""){
            $this -> correct = false;
            $this -> msg = $this -> msg .$imgv.$this->lang("poste")."&nbsp;".$this->lang("obligatoire").$f;
        }
        if ($this -> valF ['nature'] == ""){
            $this -> correct = false;
            $this -> msg = $this -> msg .$imgv.$this->lang("nature")."&nbsp;".$this->lang("obligatoire").$f;
        }
    } // verifier ()



    function setType (&$form, $maj) 
    {
        if ($maj < 2){
            // Ajout
            $form -> setType ('nature', 'select');
            if ($maj == 1){
                $form -> setType ('poste', 'hiddenstatic');
                // Modification
            }
        }else{
            $form -> setType ('poste', 'hiddenstatic');
            // Suppression
        }
    } // setType (&$form, $maj) 


function setSelect(&$form, $maj,$db,$debug) {
// nature
$contenu=array();
$contenu[0]=array('candidature','affectation');
$contenu[1]=array('candidature agent','affectation elu');
$form->setSelect("nature",$contenu);
}

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


function cleSecondaire($id,&$db,$val,$debug) {
$this->correct=True;
$this->rechercheCandidature($id,$db,$debug) ;
$this->rechercheAffectation($id,$db,$debug) ;
$this->controletraitement($id,$db,$debug) ;
}


function rechercheCandidature($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 candidature where poste ='".$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")." \"candidature\" ".$this->lang("pour")."&nbsp;".$this->lang("le")."&nbsp;".$this->lang("poste")."&nbsp; [".
        $id."]".$f."<br>";
        if ($nbligne>0)
           $this->correct=false;
    }
}
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 poste ='".$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("le")."&nbsp;".$this->lang("poste")."&nbsp; [".
        $id."]".$f."<br>";
        if ($nbligne>0)
           $this->correct=false;
    }
}

function controletraitement($id,&$db,$debug){
$this -> correct = True;
$imgv="";
$f="&nbsp!&nbsp;&nbsp;&nbsp;&nbsp;";
$imgv="<img src='../img/punaise.png' align='middle'  border='0'>";
if($id == 'PRESIDENT' or $id == 'PRESIDENT SUPPLEANT' or $id== 'SECRETAIRE'
 or $id == 'AGENT CENTRALISATION' or $id == 'ASSESSEUR SUPPLEANT' or $id== 'ASSESSEUR TITULAIRE'
 or $id == 'DELEGUE SUPPLEANT' or $id== 'DELEGUE TITULAIRE' ){
        $this->msg = $this->msg.$imgv."&nbsp;".$this->lang("vous_ne_pouvez_pas_supprimer")."&nbsp;".$this->lang("pour")."&nbsp;".$this->lang("le")."&nbsp;".$this->lang("poste")." [".
        $id."] ("."&nbsp;".$this->lang("poste")."&nbsp;".$this->lang("utilise")."&nbsp;".$this->lang("dans")."&nbsp;".$this->lang("les")."&nbsp;".$this->lang("traitement").$this->lang("pluriel")."&nbsp)".$f;
        $this->correct=false;
}
}
}
?>