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

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

class operation_gen extends om_dbform {

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



    function setvalF($val) {
        //affectation valeur formulaire
        if (!is_numeric($val['operation'])) {
            $this->valF['operation'] = ""; // -> requis
        } else {
            $this->valF['operation'] = $val['operation'];
        }
        if ($val['numdossier'] == "") {
            $this->valF['numdossier'] = NULL;
        } else {
            $this->valF['numdossier'] = $val['numdossier'];
        }
        if ($val['date'] != "") {
            $this->valF['date'] = $this->dateDB($val['date']);
        } else {
            $this->valF['date'] = NULL;
        }
            $this->valF['heure'] = $val['heure'];
        if (!is_numeric($val['emplacement'])) {
            $this->valF['emplacement'] = NULL;
        } else {
            $this->valF['emplacement'] = $val['emplacement'];
        }
            $this->valF['societe_coordonnee'] = $val['societe_coordonnee'];
            $this->valF['pf_coordonnee'] = $val['pf_coordonnee'];
        if ($val['etat'] == "") {
            $this->valF['etat'] = NULL;
        } else {
            $this->valF['etat'] = $val['etat'];
        }
        if ($val['categorie'] == "") {
            $this->valF['categorie'] = NULL;
        } else {
            $this->valF['categorie'] = $val['categorie'];
        }
        if ($val['particulier'] == "") {
            $this->valF['particulier'] = NULL;
        } else {
            $this->valF['particulier'] = $val['particulier'];
        }
        if (!is_numeric($val['emplacement_transfert'])) {
            $this->valF['emplacement_transfert'] = NULL;
        } else {
            $this->valF['emplacement_transfert'] = $val['emplacement_transfert'];
        }
            $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("operation", "hidden");
            $form->setType("numdossier", "text");
            $form->setType("date", "date");
            $form->setType("heure", "text");
            if ($this->is_in_context_of_foreign_key("emplacement", $this->retourformulaire)) {
                $form->setType("emplacement", "selecthiddenstatic");
            } else {
                $form->setType("emplacement", "select");
            }
            $form->setType("societe_coordonnee", "textarea");
            $form->setType("pf_coordonnee", "textarea");
            $form->setType("etat", "text");
            $form->setType("categorie", "text");
            $form->setType("particulier", "text");
            if ($this->is_in_context_of_foreign_key("emplacement", $this->retourformulaire)) {
                $form->setType("emplacement_transfert", "selecthiddenstatic");
            } else {
                $form->setType("emplacement_transfert", "select");
            }
            $form->setType("observation", "textarea");
        }

        // MDOE MODIFIER
        if ($maj == 1 || $crud == 'update') {
            $form->setType("operation", "hiddenstatic");
            $form->setType("numdossier", "text");
            $form->setType("date", "date");
            $form->setType("heure", "text");
            if ($this->is_in_context_of_foreign_key("emplacement", $this->retourformulaire)) {
                $form->setType("emplacement", "selecthiddenstatic");
            } else {
                $form->setType("emplacement", "select");
            }
            $form->setType("societe_coordonnee", "textarea");
            $form->setType("pf_coordonnee", "textarea");
            $form->setType("etat", "text");
            $form->setType("categorie", "text");
            $form->setType("particulier", "text");
            if ($this->is_in_context_of_foreign_key("emplacement", $this->retourformulaire)) {
                $form->setType("emplacement_transfert", "selecthiddenstatic");
            } else {
                $form->setType("emplacement_transfert", "select");
            }
            $form->setType("observation", "textarea");
        }

        // MODE SUPPRIMER
        if ($maj == 2 || $crud == 'delete') {
            $form->setType("operation", "hiddenstatic");
            $form->setType("numdossier", "hiddenstatic");
            $form->setType("date", "hiddenstatic");
            $form->setType("heure", "hiddenstatic");
            $form->setType("emplacement", "selectstatic");
            $form->setType("societe_coordonnee", "hiddenstatic");
            $form->setType("pf_coordonnee", "hiddenstatic");
            $form->setType("etat", "hiddenstatic");
            $form->setType("categorie", "hiddenstatic");
            $form->setType("particulier", "hiddenstatic");
            $form->setType("emplacement_transfert", "selectstatic");
            $form->setType("observation", "hiddenstatic");
        }

        // MODE CONSULTER
        if ($maj == 3 || $crud == 'read') {
            $form->setType("operation", "static");
            $form->setType("numdossier", "static");
            $form->setType("date", "datestatic");
            $form->setType("heure", "static");
            $form->setType("emplacement", "selectstatic");
            $form->setType("societe_coordonnee", "textareastatic");
            $form->setType("pf_coordonnee", "textareastatic");
            $form->setType("etat", "static");
            $form->setType("categorie", "static");
            $form->setType("particulier", "static");
            $form->setType("emplacement_transfert", "selectstatic");
            $form->setType("observation", "textareastatic");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('operation','VerifNum(this)');
        $form->setOnchange('date','fdate(this)');
        $form->setOnchange('emplacement','VerifNum(this)');
        $form->setOnchange('emplacement_transfert','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("operation", 11);
        $form->setTaille("numdossier", 10);
        $form->setTaille("date", 12);
        $form->setTaille("heure", 8);
        $form->setTaille("emplacement", 11);
        $form->setTaille("societe_coordonnee", 80);
        $form->setTaille("pf_coordonnee", 80);
        $form->setTaille("etat", 10);
        $form->setTaille("categorie", 20);
        $form->setTaille("particulier", 10);
        $form->setTaille("emplacement_transfert", 11);
        $form->setTaille("observation", 80);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("operation", 11);
        $form->setMax("numdossier", 10);
        $form->setMax("date", 12);
        $form->setMax("heure", 8);
        $form->setMax("emplacement", 11);
        $form->setMax("societe_coordonnee", 6);
        $form->setMax("pf_coordonnee", 6);
        $form->setMax("etat", 6);
        $form->setMax("categorie", 20);
        $form->setMax("particulier", 3);
        $form->setMax("emplacement_transfert", 11);
        $form->setMax("observation", 6);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('operation',_('operation'));
        $form->setLib('numdossier',_('numdossier'));
        $form->setLib('date',_('date'));
        $form->setLib('heure',_('heure'));
        $form->setLib('emplacement',_('emplacement'));
        $form->setLib('societe_coordonnee',_('societe_coordonnee'));
        $form->setLib('pf_coordonnee',_('pf_coordonnee'));
        $form->setLib('etat',_('etat'));
        $form->setLib('categorie',_('categorie'));
        $form->setLib('particulier',_('particulier'));
        $form->setLib('emplacement_transfert',_('emplacement_transfert'));
        $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);
        // emplacement_transfert
        $this->init_select($form, $this->f->db, $maj, null, "emplacement_transfert", $sql_emplacement_transfert, $sql_emplacement_transfert_by_id, false);
    }


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

    function setValsousformulaire(&$form, $maj, $validation, $idxformulaire, $retourformulaire, $typeformulaire, &$dnu1 = null, $dnu2 = null) {
        $this->retourformulaire = $retourformulaire;
        if ($validation == 0 and $maj == 0) {
            if($this->is_in_context_of_foreign_key('emplacement', $this->retourformulaire))
                $form->setVal('emplacement', $idxformulaire);
            if($this->is_in_context_of_foreign_key('emplacement', $this->retourformulaire))
                $form->setVal('emplacement_transfert', $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 : operation_defunt
        $this->rechercheTable($this->f->db, "operation_defunt", "operation", $id);
    }


}

?>
