 <?php
//$Id$ 
//gen openMairie le 30/08/2017 14:47

require_once PATH_OPENMAIRIE."../gen/obj/num_dossier.class.php";

class num_dossier extends num_dossier_gen {

    function __construct($id, &$dnu1 = null, $dnu2 = null) {
        $this->constructeur($id);
    }
    
    function init_class_actions() {
        parent::init_class_actions();
        
        // Interdiction de l'ajout direct
        $this->class_actions[0] = array();
        
        // ACTION - 004 - copier
        //
        $this->class_actions[4] = array(
            "identifier" => "copier",
            "portlet" => array(
                "type" => "action-direct-with-confirmation",
                "libelle" => __("Dupliquer le dossier"),
                "order" => 1,
                //"class" => "copy-16",
            ),
            "view" => "formulaire",
            "method" => "copier",
            "button" => "copier",
            "permission_suffix" => "copier",
        );
        
    }

    /* surcharge */
    function setType(&$form, $maj) {
        // héritage 
        parent::setType($form, $maj);
        
        // Récupération du mode de l'action
        $crud = $this->get_action_crud($maj);

        // MDOE MODIFIER, par défaut on verrouille tout
        if ($maj == 1 || $crud == 'update') {
            $form->setType("id", "hiddenstatic");
            $form->setType("ref", "hiddenstatic");
            $form->setType("code", "hiddenstatic");
            $form->setType("petition", "hiddenstatic");
            $form->setType("total_pages", "hiddenstatic");
            $form->setType("pa3a4", "hiddenstatic");
            $form->setType("pa0", "hiddenstatic");
            $form->setType("date_depot", "hiddenstaticdate");
            $form->setType("num_bordereau", "selecthiddenstatic");
            $form->setType("datenum", "hiddenstaticdate");
            $form->setType("num_commande", "hiddenstatic");
        }

    }

            
    function copier($val = array(), &$dnu1 = null, $dnu2 = null) {
        // Begin
        $this->begin_treatment(__METHOD__);

        // Récuperation de la valeur de la cle primaire de l'objet
        $id = $this->getVal($this->clePrimaire);
        // Récupération des valeurs de l'objet
        $this->setValFFromVal();
        // Maj des valeur de l'objet à copier
        $this->valF[$this->clePrimaire]=null;
        $this->valF["num_bordereau"]=null;
        $this->valF["datenum"]=null;
        
        //
        $ret = $this->ajouter($this->valF);
        // Si le traitement ne s'est pas déroulé correctement
        if ($ret !== true) {
            // Return
            return $this->end_treatment(__METHOD__, false);
        }

        // Message
        $this->addToMessage(__("L'élément a été correctement dupliqué."));
        // Return
        return $this->end_treatment(__METHOD__, true);
    }

    function setLayout(&$form, $maj) {
            $form->setBloc('num_dossier','D',"", "col_7");
                $form->setFieldset('num_dossier','D',' '.__('identification').' ', "");
                $form->setFieldset('code','F',' ');
                 
                $form->setFieldset('petition','D',' '.__('détail').' ', "collapsible");
                $form->setFieldset('date_depot','F');
                
                $form->setFieldset('num_bordereau','D',' '.__('traitement').' ', "collapsible");
                $form->setFieldset('num_commande','F');
            $form->setBloc('num_commande','F');
    }
    
    /**
     * Surcharge pour modifier libellé et ordre 
     * @return string
     */
    function get_var_sql_forminc__sql_num_bordereau() {
        return str_replace( 
                 "ORDER BY num_bordereau.libelle ASC"
                ,"ORDER BY num_bordereau.libelle DESC"
                , parent::get_var_sql_forminc__sql_num_bordereau());
    }

}
