<?php
//$Id$ 
//gen openMairie le 16/12/2015 11:14

require_once "../obj/om_dbform.class.php";

class autorisation_gen extends om_dbform {

    var $table = "autorisation";
    var $clePrimaire = "autorisation";
    var $typeCle = "N";
    var $required_field = array(
        "autorisation"
    );
    
    var $foreign_keys_extended = array(
        "emplacement" => array("emplacement", ),
        "titre_de_civilite" => array("titre_de_civilite", ),
    );



    function setvalF($val) {
        //affectation valeur formulaire
        if (!is_numeric($val['autorisation'])) {
            $this->valF['autorisation'] = ""; // -> requis
        } else {
            $this->valF['autorisation'] = $val['autorisation'];
        }
        if (!is_numeric($val['emplacement'])) {
            $this->valF['emplacement'] = NULL;
        } else {
            $this->valF['emplacement'] = $val['emplacement'];
        }
        if ($val['nature'] == "") {
            $this->valF['nature'] = NULL;
        } else {
            $this->valF['nature'] = $val['nature'];
        }
        if (!is_numeric($val['titre'])) {
            $this->valF['titre'] = NULL;
        } else {
            $this->valF['titre'] = $val['titre'];
        }
        if ($val['nom'] == "") {
            $this->valF['nom'] = NULL;
        } else {
            $this->valF['nom'] = $val['nom'];
        }
        if ($val['marital'] == "") {
            $this->valF['marital'] = NULL;
        } else {
            $this->valF['marital'] = $val['marital'];
        }
        if ($val['prenom'] == "") {
            $this->valF['prenom'] = NULL;
        } else {
            $this->valF['prenom'] = $val['prenom'];
        }
        if ($val['datenaissance'] != "") {
            $this->valF['datenaissance'] = $this->dateDB($val['datenaissance']);
        } else {
            $this->valF['datenaissance'] = NULL;
        }
        if ($val['adresse1'] == "") {
            $this->valF['adresse1'] = NULL;
        } else {
            $this->valF['adresse1'] = $val['adresse1'];
        }
        if ($val['adresse2'] == "") {
            $this->valF['adresse2'] = NULL;
        } else {
            $this->valF['adresse2'] = $val['adresse2'];
        }
        if ($val['cp'] == "") {
            $this->valF['cp'] = NULL;
        } else {
            $this->valF['cp'] = $val['cp'];
        }
        if ($val['ville'] == "") {
            $this->valF['ville'] = NULL;
        } else {
            $this->valF['ville'] = $val['ville'];
        }
        if ($val['telephone'] == "") {
            $this->valF['telephone'] = NULL;
        } else {
            $this->valF['telephone'] = $val['telephone'];
        }
        if ($val['dcd'] == 1 || $val['dcd'] == "t" || $val['dcd'] == "Oui") {
            $this->valF['dcd'] = true;
        } else {
            $this->valF['dcd'] = false;
        }
        if ($val['parente'] == "") {
            $this->valF['parente'] = NULL;
        } else {
            $this->valF['parente'] = $val['parente'];
        }
            $this->valF['observation'] = $val['observation'];
    }

    //=================================================
    //cle primaire automatique [automatic primary key]
    //==================================================

    function setId(&$dnu1 = null) {
    //numero automatique
        $this->valF[$this->clePrimaire] = $this->f->db->nextId(DB_PREFIXE.$this->table);
    }

    function setValFAjout($val) {
    //numero automatique -> pas de controle ajout cle primaire
    }

    function verifierAjout() {
    //numero automatique -> pas de verfication de cle primaire
    }

    //==========================
    // Formulaire  [form]
    //==========================
    /**
     *
     */
    function setType(&$form, $maj) {
        // Récupération du mode de l'action
        $crud = $this->get_action_crud($maj);

        // MODE AJOUTER
        if ($maj == 0 || $crud == 'create') {
            $form->setType("autorisation", "hidden");
            if ($this->is_in_context_of_foreign_key("emplacement", $this->retourformulaire)) {
                $form->setType("emplacement", "selecthiddenstatic");
            } else {
                $form->setType("emplacement", "select");
            }
            $form->setType("nature", "text");
            if ($this->is_in_context_of_foreign_key("titre_de_civilite", $this->retourformulaire)) {
                $form->setType("titre", "selecthiddenstatic");
            } else {
                $form->setType("titre", "select");
            }
            $form->setType("nom", "text");
            $form->setType("marital", "text");
            $form->setType("prenom", "text");
            $form->setType("datenaissance", "date");
            $form->setType("adresse1", "text");
            $form->setType("adresse2", "text");
            $form->setType("cp", "text");
            $form->setType("ville", "text");
            $form->setType("telephone", "text");
            $form->setType("dcd", "checkbox");
            $form->setType("parente", "text");
            $form->setType("observation", "textarea");
        }

        // MDOE MODIFIER
        if ($maj == 1 || $crud == 'update') {
            $form->setType("autorisation", "hiddenstatic");
            if ($this->is_in_context_of_foreign_key("emplacement", $this->retourformulaire)) {
                $form->setType("emplacement", "selecthiddenstatic");
            } else {
                $form->setType("emplacement", "select");
            }
            $form->setType("nature", "text");
            if ($this->is_in_context_of_foreign_key("titre_de_civilite", $this->retourformulaire)) {
                $form->setType("titre", "selecthiddenstatic");
            } else {
                $form->setType("titre", "select");
            }
            $form->setType("nom", "text");
            $form->setType("marital", "text");
            $form->setType("prenom", "text");
            $form->setType("datenaissance", "date");
            $form->setType("adresse1", "text");
            $form->setType("adresse2", "text");
            $form->setType("cp", "text");
            $form->setType("ville", "text");
            $form->setType("telephone", "text");
            $form->setType("dcd", "checkbox");
            $form->setType("parente", "text");
            $form->setType("observation", "textarea");
        }

        // MODE SUPPRIMER
        if ($maj == 2 || $crud == 'delete') {
            $form->setType("autorisation", "hiddenstatic");
            $form->setType("emplacement", "selectstatic");
            $form->setType("nature", "hiddenstatic");
            $form->setType("titre", "selectstatic");
            $form->setType("nom", "hiddenstatic");
            $form->setType("marital", "hiddenstatic");
            $form->setType("prenom", "hiddenstatic");
            $form->setType("datenaissance", "hiddenstatic");
            $form->setType("adresse1", "hiddenstatic");
            $form->setType("adresse2", "hiddenstatic");
            $form->setType("cp", "hiddenstatic");
            $form->setType("ville", "hiddenstatic");
            $form->setType("telephone", "hiddenstatic");
            $form->setType("dcd", "hiddenstatic");
            $form->setType("parente", "hiddenstatic");
            $form->setType("observation", "hiddenstatic");
        }

        // MODE CONSULTER
        if ($maj == 3 || $crud == 'read') {
            $form->setType("autorisation", "static");
            $form->setType("emplacement", "selectstatic");
            $form->setType("nature", "static");
            $form->setType("titre", "selectstatic");
            $form->setType("nom", "static");
            $form->setType("marital", "static");
            $form->setType("prenom", "static");
            $form->setType("datenaissance", "datestatic");
            $form->setType("adresse1", "static");
            $form->setType("adresse2", "static");
            $form->setType("cp", "static");
            $form->setType("ville", "static");
            $form->setType("telephone", "static");
            $form->setType("dcd", "checkboxstatic");
            $form->setType("parente", "static");
            $form->setType("observation", "textareastatic");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('autorisation','VerifNum(this)');
        $form->setOnchange('emplacement','VerifNum(this)');
        $form->setOnchange('titre','VerifNum(this)');
        $form->setOnchange('datenaissance','fdate(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("autorisation", 11);
        $form->setTaille("emplacement", 11);
        $form->setTaille("nature", 15);
        $form->setTaille("titre", 11);
        $form->setTaille("nom", 30);
        $form->setTaille("marital", 30);
        $form->setTaille("prenom", 30);
        $form->setTaille("datenaissance", 12);
        $form->setTaille("adresse1", 30);
        $form->setTaille("adresse2", 30);
        $form->setTaille("cp", 10);
        $form->setTaille("ville", 30);
        $form->setTaille("telephone", 15);
        $form->setTaille("dcd", 1);
        $form->setTaille("parente", 30);
        $form->setTaille("observation", 80);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("autorisation", 11);
        $form->setMax("emplacement", 11);
        $form->setMax("nature", 15);
        $form->setMax("titre", 11);
        $form->setMax("nom", 40);
        $form->setMax("marital", 40);
        $form->setMax("prenom", 40);
        $form->setMax("datenaissance", 12);
        $form->setMax("adresse1", 40);
        $form->setMax("adresse2", 40);
        $form->setMax("cp", 5);
        $form->setMax("ville", 50);
        $form->setMax("telephone", 15);
        $form->setMax("dcd", 1);
        $form->setMax("parente", 100);
        $form->setMax("observation", 6);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('autorisation',_('autorisation'));
        $form->setLib('emplacement',_('emplacement'));
        $form->setLib('nature',_('nature'));
        $form->setLib('titre',_('titre'));
        $form->setLib('nom',_('nom'));
        $form->setLib('marital',_('marital'));
        $form->setLib('prenom',_('prenom'));
        $form->setLib('datenaissance',_('datenaissance'));
        $form->setLib('adresse1',_('adresse1'));
        $form->setLib('adresse2',_('adresse2'));
        $form->setLib('cp',_('cp'));
        $form->setLib('ville',_('ville'));
        $form->setLib('telephone',_('telephone'));
        $form->setLib('dcd',_('dcd'));
        $form->setLib('parente',_('parente'));
        $form->setLib('observation',_('observation'));
    }
    /**
     *
     */
    function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) {

        // Inclusion du fichier de requêtes
        if (file_exists("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc.php")) {
            include "../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc.php";
        } elseif (file_exists("../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc")) {
            include "../sql/".OM_DB_PHPTYPE."/".$this->table.".form.inc";
        }

        // emplacement
        $this->init_select($form, $this->f->db, $maj, null, "emplacement", $sql_emplacement, $sql_emplacement_by_id, false);
        // titre
        $this->init_select($form, $this->f->db, $maj, null, "titre", $sql_titre, $sql_titre_by_id, true);
    }


    //==================================
    // sous Formulaire 
    //==================================
    

    function setValsousformulaire(&$form, $maj, $validation, $idxformulaire, $retourformulaire, $typeformulaire, &$dnu1 = null, $dnu2 = null) {
        $this->retourformulaire = $retourformulaire;
        if($validation == 0) {
            if($this->is_in_context_of_foreign_key('emplacement', $this->retourformulaire))
                $form->setVal('emplacement', $idxformulaire);
            if($this->is_in_context_of_foreign_key('titre_de_civilite', $this->retourformulaire))
                $form->setVal('titre', $idxformulaire);
        }// fin validation
        $this->set_form_default_values($form, $maj, $validation);
    }// fin setValsousformulaire

    //==================================
    // cle secondaire 
    //==================================
    
    /**
     * Methode clesecondaire
     */
    function cleSecondaire($id, &$dnu1 = null, $val = array(), $dnu2 = null) {
        // On appelle la methode de la classe parent
        parent::cleSecondaire($id);
        // Verification de la cle secondaire : courrier
        $this->rechercheTable($this->f->db, "courrier", "destinataire", $id);
    }


}

?>
