<?php
//$Id$ 
//gen openMairie le 05/05/2024 18:30

require_once PATH_OPENMAIRIE."om_dbform.class.php";

class om_tables_gen extends dbform {

    protected $_absolute_class_name = "om_tables";

    var $table = "om_tables";
    var $clePrimaire = "table_name";
    var $typeCle = "A";
    var $required_field = array(
        "table_name"
    );
    
    var $foreign_keys_extended = array(
    );
    
    /**
     *
     * @return string
     */
    function get_default_libelle() {
        return $this->getVal($this->clePrimaire)."&nbsp;".$this->getVal("libelle");
    }

    /**
     *
     * @return array
     */
    function get_var_sql_forminc__champs() {
        return array(
            "table_name",
            "table_schema",
            "table_type",
            "comment",
            "parametre",
            "libelle",
            "affichage",
            "nombre_colonne",
            "col1",
            "col2",
            "col3",
            "recherche",
        );
    }




    function setvalF($val = array()) {
        //affectation valeur formulaire
        $this->valF['table_name'] = $val['table_name'];
        if ($val['table_schema'] == "") {
            $this->valF['table_schema'] = NULL;
        } else {
            $this->valF['table_schema'] = $val['table_schema'];
        }
        if ($val['table_type'] == "") {
            $this->valF['table_type'] = NULL;
        } else {
            $this->valF['table_type'] = $val['table_type'];
        }
            $this->valF['comment'] = $val['comment'];
            $this->valF['parametre'] = $val['parametre'];
        if ($val['libelle'] == "") {
            $this->valF['libelle'] = NULL;
        } else {
            $this->valF['libelle'] = $val['libelle'];
        }
        if (!is_numeric($val['affichage'])) {
            $this->valF['affichage'] = NULL;
        } else {
            $this->valF['affichage'] = $val['affichage'];
        }
        if (!is_numeric($val['nombre_colonne'])) {
            $this->valF['nombre_colonne'] = NULL;
        } else {
            $this->valF['nombre_colonne'] = $val['nombre_colonne'];
        }
        if ($val['col1'] == "") {
            $this->valF['col1'] = NULL;
        } else {
            $this->valF['col1'] = $val['col1'];
        }
        if ($val['col2'] == "") {
            $this->valF['col2'] = NULL;
        } else {
            $this->valF['col2'] = $val['col2'];
        }
        if ($val['col3'] == "") {
            $this->valF['col3'] = NULL;
        } else {
            $this->valF['col3'] = $val['col3'];
        }
        if (!is_numeric($val['recherche'])) {
            $this->valF['recherche'] = NULL;
        } else {
            $this->valF['recherche'] = $val['recherche'];
        }
    }

    //==========================
    // 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("table_name", "text");
            $form->setType("table_schema", "text");
            $form->setType("table_type", "text");
            $form->setType("comment", "textarea");
            $form->setType("parametre", "textarea");
            $form->setType("libelle", "text");
            $form->setType("affichage", "text");
            $form->setType("nombre_colonne", "text");
            $form->setType("col1", "text");
            $form->setType("col2", "text");
            $form->setType("col3", "text");
            $form->setType("recherche", "text");
        }

        // MDOE MODIFIER
        if ($maj == 1 || $crud == 'update') {
            $form->setType("table_name", "hiddenstatic");
            $form->setType("table_schema", "text");
            $form->setType("table_type", "text");
            $form->setType("comment", "textarea");
            $form->setType("parametre", "textarea");
            $form->setType("libelle", "text");
            $form->setType("affichage", "text");
            $form->setType("nombre_colonne", "text");
            $form->setType("col1", "text");
            $form->setType("col2", "text");
            $form->setType("col3", "text");
            $form->setType("recherche", "text");
        }

        // MODE SUPPRIMER
        if ($maj == 2 || $crud == 'delete') {
            $form->setType("table_name", "hiddenstatic");
            $form->setType("table_schema", "hiddenstatic");
            $form->setType("table_type", "hiddenstatic");
            $form->setType("comment", "hiddenstatic");
            $form->setType("parametre", "hiddenstatic");
            $form->setType("libelle", "hiddenstatic");
            $form->setType("affichage", "hiddenstatic");
            $form->setType("nombre_colonne", "hiddenstatic");
            $form->setType("col1", "hiddenstatic");
            $form->setType("col2", "hiddenstatic");
            $form->setType("col3", "hiddenstatic");
            $form->setType("recherche", "hiddenstatic");
        }

        // MODE CONSULTER
        if ($maj == 3 || $crud == 'read') {
            $form->setType("table_name", "static");
            $form->setType("table_schema", "static");
            $form->setType("table_type", "static");
            $form->setType("comment", "textareastatic");
            $form->setType("parametre", "textareastatic");
            $form->setType("libelle", "static");
            $form->setType("affichage", "static");
            $form->setType("nombre_colonne", "static");
            $form->setType("col1", "static");
            $form->setType("col2", "static");
            $form->setType("col3", "static");
            $form->setType("recherche", "static");
        }

    }


    function setOnchange(&$form, $maj) {
    //javascript controle client
        $form->setOnchange('affichage','VerifNum(this)');
        $form->setOnchange('nombre_colonne','VerifNum(this)');
        $form->setOnchange('recherche','VerifNum(this)');
    }
    /**
     * Methode setTaille
     */
    function setTaille(&$form, $maj) {
        $form->setTaille("table_name", 30);
        $form->setTaille("table_schema", 30);
        $form->setTaille("table_type", 30);
        $form->setTaille("comment", 80);
        $form->setTaille("parametre", 80);
        $form->setTaille("libelle", 30);
        $form->setTaille("affichage", 11);
        $form->setTaille("nombre_colonne", 11);
        $form->setTaille("col1", 30);
        $form->setTaille("col2", 30);
        $form->setTaille("col3", 30);
        $form->setTaille("recherche", 11);
    }

    /**
     * Methode setMax
     */
    function setMax(&$form, $maj) {
        $form->setMax("table_name", 40);
        $form->setMax("table_schema", 40);
        $form->setMax("table_type", 40);
        $form->setMax("comment", 6);
        $form->setMax("parametre", 6);
        $form->setMax("libelle", 40);
        $form->setMax("affichage", 11);
        $form->setMax("nombre_colonne", 11);
        $form->setMax("col1", 40);
        $form->setMax("col2", 40);
        $form->setMax("col3", 40);
        $form->setMax("recherche", 11);
    }


    function setLib(&$form, $maj) {
    //libelle des champs
        $form->setLib('table_name', __('table_name'));
        $form->setLib('table_schema', __('table_schema'));
        $form->setLib('table_type', __('table_type'));
        $form->setLib('comment', __('comment'));
        $form->setLib('parametre', __('parametre'));
        $form->setLib('libelle', __('libelle'));
        $form->setLib('affichage', __('affichage'));
        $form->setLib('nombre_colonne', __('nombre_colonne'));
        $form->setLib('col1', __('col1'));
        $form->setLib('col2', __('col2'));
        $form->setLib('col3', __('col3'));
        $form->setLib('recherche', __('recherche'));
    }
    /**
     *
     */
    function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) {

    }


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

    function setValsousformulaire(&$form, $maj, $validation, $idxformulaire, $retourformulaire, $typeformulaire, &$dnu1 = null, $dnu2 = null) {
        $this->retourformulaire = $retourformulaire;
        $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 : om_actions
        $this->rechercheTable($this->f->db, "om_actions", "table_name", $id);
        // Verification de la cle secondaire : om_contraintes
        $this->rechercheTable($this->f->db, "om_contraintes", "table_name", $id);
        // Verification de la cle secondaire : om_etat
        $this->rechercheTable($this->f->db, "om_etat", "table_name", $id);
        // Verification de la cle secondaire : om_forms
        $this->rechercheTable($this->f->db, "om_forms", "table_name", $id);
        // Verification de la cle secondaire : om_requete
        $this->rechercheTable($this->f->db, "om_requete", "table_name", $id);
        // Verification de la cle secondaire : om_sousetat
        $this->rechercheTable($this->f->db, "om_sousetat", "table_name", $id);
        // Verification de la cle secondaire : om_triggers
        $this->rechercheTable($this->f->db, "om_triggers", "event_object_table", $id);
    }


}
