<?php
/**
 * Ce script définit la classe 'dossier'.
 *
 * @package opencimetiere
 * @version SVN : $Id$
 */

require_once "../gen/obj/dossier.class.php";

/**
 * Définition de la classe 'dossier' (om_dbform).
 */
class dossier extends dossier_gen {


    function get_collectivite() {
        $inst_emplacement = $this->f->get_inst__om_dbform(array("obj" => "emplacement", "idx" => $this->getVal("emplacement")));
        // XXX
        if ($inst_emplacement === null) {
            return -1;
        }
        // XXX
        if ($inst_emplacement->exists() !== true) {
            return -1;
        }
        return $inst_emplacement->get_collectivite();
    }

    /**
     * Définition des actions disponibles sur la classe.
     *
     * @return void
     */
    function init_class_actions() {
        parent::init_class_actions();
        
        // ACTION - 01 - modifier
        //
        $this->class_actions[1]["condition"] = array("is_user_from_allowed_collectivite");
        
        // ACTION - 02 - supprimer
        //
        $this->class_actions[2]["condition"] = array("is_user_from_allowed_collectivite");
        
        // ACTION - 03 - consulter
        //
        $this->class_actions[3]["condition"] = array("is_user_from_allowed_collectivite");
    }

    /**
     * GETTER_FORMINC - champs.
     *
     * @return array
     */
    function get_var_sql_forminc__champs() {
        return array(
            "dossier",
            "emplacement",
            "fichier",
            "typedossier",
            "datedossier",
            "observation",
        );
    }

    /**
     * SETTER_FORM - setType.
     *
     * @return void
     */
    function setType(&$form, $maj) {
        parent::setType($form, $maj);
        //
        $form->setType('emplacement','hidden');
        //
        if ($maj==0 || $maj == 1) {
                $form->setType('typedossier','select');
        }else{
                $form->setType('typedossier','selectstatic');
        }
        // Gestion du champ fichier
        if ($maj == 0 || $maj == 1) {
            $form->setType('fichier', 'upload2');
        } elseif ($maj == 3) {
            $form->setType('fichier', 'file');
        } else {
            $form->setType('fichier', 'filestatic');
        }
    }

    /**
     * SETTER_FORM - setSelect.
     *
     * @return void
     */
    function setSelect(&$form, $maj, &$dnu1 = null, $dnu2 = null) {
        //parent::setSelect($form, $maj);
        //
        $contenu=array();
        $contenu[0]=array('dossier','photo');
        $contenu[1]=array(__('dossier'),__('photo'));
        $form->setSelect("typedossier",$contenu);
    }

    /**
     * SETTER_FORM - setLib.
     *
     * @return void
     */
    function setLib(&$form, $maj) {
        parent::setLib($form, $maj);
        //
        $form->setLib($this->clePrimaire, __("id"));
    }

    /**
     * SETTER_FORM - setValsousformulaire (setVal).
     *
     * @return void
     */
    function setValsousformulaire(&$form, $maj, $validation, $idxformulaire, $retourformulaire, $typeformulaire, &$dnu1 = null, $dnu2 = null) {
        parent::setValsousformulaire($form, $maj, $validation, $idxformulaire, $retourformulaire, $typeformulaire);
        //
        if ($validation==0) {
            if ($maj == 0){
                $form->setVal('dossier', "[...]");
                $form->setVal('emplacement', $idxformulaire);
            }
        }
    }

    /**
     * SETTER_FORM - setLayout.
     *
     * @return void
     */
    function setLayout(&$form, $maj) {
        parent::setLayout($form, $maj);
        //

        // CONTAINER GLOBAL - START
        $this->form->setBloc("dossier", "D", "", "emplacement-form dossier-form form-action-".$maj);

            // LIGNE ID - START
            $this->form->setBloc("dossier", "D", "", "emplacement-bloc emplacement-bloc-identification");
                $this->form->setBloc("dossier", "DF", "", "span6");
                $this->form->setBloc("emplacement", "DF", "", "span6");
            $this->form->setBloc("emplacement", "F");
            // LIGNE ID - END

            // LIGNE DOSSIER - START
            $this->form->setBloc("fichier", "D", _("Informations sur le dossier"), "emplacement-bloc emplacement-bloc-infos emplacement-bloc-personne");
                //// BLOC DOSSIER - START
                $this->form->setBloc("fichier", "DF", "", "span12");
                $this->form->setBloc("typedossier", "DF", "", "span6");
                $this->form->setBloc("datedossier", "DF", "", "span6");
            $this->form->setBloc("datedossier", "F");
            //// LIGNE DOSSIER- END


            $this->form->setBloc("observation", "DF", _("observations"), "no-label span12");
        // CONTAINER GLOBAL - END
        $this->form->setBloc("observation", "F");

    }
}
