<?php
//$Id$ 
//gen openMairie le 10/04/2015 16:50

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

class adresse_postale_gen extends om_dbform {

    var $table = "adresse_postale";
    var $clePrimaire = "adresse_postale";
    var $typeCle = "N";
    var $required_field = array(
        "adresse_postale"
    );
    
    var $foreign_keys_extended = array(
        "rivoli" => array("rivoli", ),
    );



    function setvalF($val) {
        //affectation valeur formulaire
        if (!is_numeric($val['adresse_postale'])) {
            $this->valF['adresse_postale'] = ""; // -> requis
        } else {
            $this->valF['adresse_postale'] = $val['adresse_postale'];
        }
        if ($val['rivoli'] == "") {
            $this->valF['rivoli'] = NULL;
        } else {
            $this->valF['rivoli'] = $val['rivoli'];
        }
        if (!is_numeric($val['numero'])) {
            $this->valF['numero'] = NULL;
        } else {
            $this->valF['numero'] = $val['numero'];
        }
        if ($val['complement'] == "") {
            $this->valF['complement'] = NULL;
        } else {
            $this->valF['complement'] = $val['complement'];
        }
        if ($val['geom'] == "") {
            unset($this->valF['geom']);
        } else {
            $this->valF['geom'] = $val['geom'];
        }
        if ($val['geom_peri'] == "") {
            unset($this->valF['geom_peri']);
        } else {
            $this->valF['geom_peri'] = $val['geom_peri'];
        }
        if ($val['libelle'] == "") {
            $this->valF['libelle'] = NULL;
        } else {
            $this->valF['libelle'] = $val['libelle'];
        }
        if ($val['quartier'] == "") {
            $this->valF['quartier'] = NULL;
        } else {
            $this->valF['quartier'] = $val['quartier'];
        }
        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['insee'] == "") {
            $this->valF['insee'] = NULL;
        } else {
            $this->valF['insee'] = $val['insee'];
        }
        if ($val['ligne2'] == "") {
            $this->valF['ligne2'] = NULL;
        } else {
            $this->valF['ligne2'] = $val['ligne2'];
        }
        if ($val['ligne3'] == "") {
            $this->valF['ligne3'] = NULL;
        } else {
            $this->valF['ligne3'] = $val['ligne3'];
        }
        if ($val['ligne4'] == "") {
            $this->valF['ligne4'] = NULL;
        } else {
            $this->valF['ligne4'] = $val['ligne4'];
        }
        if ($val['ligne5'] == "") {
            $this->valF['ligne5'] = NULL;
        } else {
            $this->valF['ligne5'] = $val['ligne5'];
        }
        if ($val['ligne6'] == "") {
            $this->valF['ligne6'] = NULL;
        } else {
            $this->valF['ligne6'] = $val['ligne6'];
        }
        if (!is_numeric($val['voie'])) {
            $this->valF['voie'] = NULL;
        } else {
            $this->valF['voie'] = $val['voie'];
        }
        if (!is_numeric($val['couleur'])) {
            $this->valF['couleur'] = NULL;
        } else {
            $this->valF['couleur'] = $val['couleur'];
        }
    }

    //=================================================
    //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) {

        // MODE AJOUTER
        if ($maj == 0) {
            $form->setType("adresse_postale", "hidden");
            if ($this->is_in_context_of_foreign_key("rivoli", $this->retourformulaire)) {
                $form->setType("rivoli", "selecthiddenstatic");
            } else {
                $form->setType("rivoli", "select");
            }
            $form->setType("numero", "text");
            $form->setType("complement", "text");
            $form->setType("geom", "geom");
            $form->setType("geom_peri", "geom");
            $form->setType("libelle", "text");
            $form->setType("quartier", "text");
            $form->setType("cp", "text");
            $form->setType("ville", "text");
            $form->setType("insee", "text");
            $form->setType("ligne2", "text");
            $form->setType("ligne3", "text");
            $form->setType("ligne4", "text");
            $form->setType("ligne5", "text");
            $form->setType("ligne6", "text");
            $form->setType("voie", "text");
            $form->setType("couleur", "text");
        }

        // MDOE MODIFIER
        if ($maj == 1) {
            $form->setType("adresse_postale", "hiddenstatic");
            if ($this->is_in_context_of_foreign_key("rivoli", $this->retourformulaire)) {
                $form->setType("rivoli", "selecthiddenstatic");
            } else {
                $form->setType("rivoli", "select");
            }
            $form->setType("numero", "text");
            $form->setType("complement", "text");
            $form->setType("geom", "geom");
            $form->setType("geom_peri", "geom");
            $form->setType("libelle", "text");
            $form->setType("quartier", "text");
            $form->setType("cp", "text");
            $form->setType("ville", "text");
            $form->setType("insee", "text");
            $form->setType("ligne2", "text");
            $form->setType("ligne3", "text");
            $form->setType("ligne4", "text");
            $form->setType("ligne5", "text");
            $form->setType("ligne6", "text");
            $form->setType("voie", "text");
            $form->setType("couleur", "text");
        }

        // MODE SUPPRIMER
        if ($maj == 2) {
            $form->setType("adresse_postale", "hiddenstatic");
            $form->setType("rivoli", "selectstatic");
            $form->setType("numero", "hiddenstatic");
            $form->setType("complement", "hiddenstatic");
            $form->setType("geom", "geom");
            $form->setType("geom_peri", "geom");
            $form->setType("libelle", "hiddenstatic");
            $form->setType("quartier", "hiddenstatic");
            $form->setType("cp", "hiddenstatic");
            $form->setType("ville", "hiddenstatic");
            $form->setType("insee", "hiddenstatic");
            $form->setType("ligne2", "hiddenstatic");
            $form->setType("ligne3", "hiddenstatic");
            $form->setType("ligne4", "hiddenstatic");
            $form->setType("ligne5", "hiddenstatic");
            $form->setType("ligne6", "hiddenstatic");
            $form->setType("voie", "hiddenstatic");
            $form->setType("couleur", "hiddenstatic");
        }

        // MODE CONSULTER
        if ($maj == 3) {
            $form->setType("adresse_postale", "static");
            $form->setType("rivoli", "selectstatic");
            $form->setType("numero", "static");
            $form->setType("complement", "static");
            $form->setType("geom", "geom");
            $form->setType("geom_peri", "geom");
            $form->setType("libelle", "static");
            $form->setType("quartier", "static");
            $form->setType("cp", "static");
            $form->setType("ville", "static");
            $form->setType("insee", "static");
            $form->setType("ligne2", "static");
            $form->setType("ligne3", "static");
            $form->setType("ligne4", "static");
            $form->setType("ligne5", "static");
            $form->setType("ligne6", "static");
            $form->setType("voie", "static");
            $form->setType("couleur", "static");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('adresse_postale','VerifNum(this)');
        $form->setOnchange('numero','VerifNum(this)');
        $form->setOnchange('voie','VerifNum(this)');
        $form->setOnchange('couleur','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("adresse_postale", 11);
        $form->setTaille("rivoli", 10);
        $form->setTaille("numero", 6);
        $form->setTaille("complement", 10);
        $form->setTaille("geom", 30);
        $form->setTaille("geom_peri", 30);
        $form->setTaille("libelle", 10);
        $form->setTaille("quartier", 10);
        $form->setTaille("cp", 10);
        $form->setTaille("ville", 30);
        $form->setTaille("insee", 10);
        $form->setTaille("ligne2", 30);
        $form->setTaille("ligne3", 30);
        $form->setTaille("ligne4", 30);
        $form->setTaille("ligne5", 30);
        $form->setTaille("ligne6", 30);
        $form->setTaille("voie", 11);
        $form->setTaille("couleur", 11);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("adresse_postale", 11);
        $form->setMax("rivoli", 4);
        $form->setMax("numero", 6);
        $form->setMax("complement", -5);
        $form->setMax("geom", 551424);
        $form->setMax("geom_peri", 551444);
        $form->setMax("libelle", -5);
        $form->setMax("quartier", -5);
        $form->setMax("cp", 5);
        $form->setMax("ville", 32);
        $form->setMax("insee", 5);
        $form->setMax("ligne2", 38);
        $form->setMax("ligne3", 38);
        $form->setMax("ligne4", 38);
        $form->setMax("ligne5", 38);
        $form->setMax("ligne6", 38);
        $form->setMax("voie", 11);
        $form->setMax("couleur", 11);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('adresse_postale',_('adresse_postale'));
        $form->setLib('rivoli',_('rivoli'));
        $form->setLib('numero',_('numero'));
        $form->setLib('complement',_('complement'));
        $form->setLib('geom',_('geom'));
        $form->setLib('geom_peri',_('geom_peri'));
        $form->setLib('libelle',_('libelle'));
        $form->setLib('quartier',_('quartier'));
        $form->setLib('cp',_('cp'));
        $form->setLib('ville',_('ville'));
        $form->setLib('insee',_('insee'));
        $form->setLib('ligne2',_('ligne2'));
        $form->setLib('ligne3',_('ligne3'));
        $form->setLib('ligne4',_('ligne4'));
        $form->setLib('ligne5',_('ligne5'));
        $form->setLib('ligne6',_('ligne6'));
        $form->setLib('voie',_('voie'));
        $form->setLib('couleur',_('couleur'));
    }
    /**
     *
     */
    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";
        }

        // rivoli
        $this->init_select($form, $this->f->db, $maj, null, "rivoli", $sql_rivoli, $sql_rivoli_by_id, false);
        // geom
        if ($maj == 1 || $maj == 3) {
            $contenu = array();
            $contenu[0] = array("adresse_postale", $this->getParameter("idx"), "0");
            $form->setSelect("geom", $contenu);
        }
        // geom_peri
        if ($maj == 1 || $maj == 3) {
            $contenu = array();
            $contenu[0] = array("adresse_postale", $this->getParameter("idx"), "1");
            $form->setSelect("geom_peri", $contenu);
        }
    }


    //==================================
    // 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('rivoli', $this->retourformulaire))
                $form->setVal('rivoli', $idxformulaire);
        }// fin validation
        $this->set_form_default_values($form, $maj, $validation);
    }// fin setValsousformulaire

    //==================================
    // cle secondaire 
    //==================================
    

}

?>
