Exemplo n.º 1
0
function show_budg_form($id_bibli, $id_bud = 0)
{
    global $dbh, $msg, $charset;
    global $budg_form, $bt_add_lig;
    global $ptab;
    global $lig_rub, $lig_rub_img;
    global $mnt_form, $sel_typ_form;
    //Récuperation du budget
    if ($id_bud) {
        $bud = new budgets($id_bud);
    }
    //Affichage exercices actifs
    $q = exercices::listByEntite($id_bibli, STA_EXE_ACT, 'statut desc, date_debut desc');
    $res = mysql_query($q, $dbh);
    if (!$id_bud) {
        //Nouveau budget ->choix exercice possible & choix type possible (affectation globale ou par lignes)
        $form_exer = "<select id='exer' name ='exer' >";
        while ($row = mysql_fetch_object($res)) {
            $form_exer .= "<option value='" . $row->id_exercice . "' >" . $row->libelle . "</option>";
        }
        $form_exer .= "</select>";
        $mnt = $mnt_form[0];
        $sel_typ = $sel_typ_form;
        $bouton_dup = "";
    } else {
        //Modification
        if ($bud->statut == STA_BUD_PRE || $bud->statut == STA_BUD_VAL && !budgets::hasLignes($id_bud)) {
            //Exercice modifiable si budget non activé ou pas de lignes d'actes affectées
            $form_exer = "<select id='exer' name ='exer' >";
            while ($row = mysql_fetch_object($res)) {
                $form_exer .= "<option value='" . $row->id_exercice . "' ";
                if ($bud->num_exercice == $row->id_exercice) {
                    $form_exer .= "selected='selected' ";
                }
                $form_exer .= ">" . $row->libelle . "</option>";
            }
            $form_exer .= "</select>";
        } else {
            // Exercice non modifiable si budget activé et non vide ou cloturé
            $exer = new exercices($bud->num_exercice);
            $form_exer = "<input type='hidden' id='exer' name='exer' value='" . $exer->id_exercice . "' />" . htmlentities($exer->libelle, ENT_QUOTES, $charset);
        }
        if ($bud->type_budget == TYP_BUD_RUB) {
            $mnt = $bud->montant_global;
        } else {
            $mnt = str_replace('!!mnt_bud!!', $bud->montant_global, $mnt_form[1]);
        }
        if (!$bud->type_budget) {
            $sel_typ = htmlentities($msg['acquisition_budg_aff_rub'], ENT_QUOTES, $charset);
        } else {
            $sel_typ = htmlentities($msg['acquisition_budg_aff_glo'], ENT_QUOTES, $charset);
        }
        $bouton_dup = $ptab[5];
    }
    //Affichage entete formulaire
    if (!$id_bud) {
        $budg_form = str_replace('!!form_title!!', htmlentities($msg[acquisition_ajout_budg], ENT_QUOTES, $charset), $budg_form);
        $budg_form = str_replace('!!libelle!!', '', $budg_form);
        $budg_form = str_replace('!!seuil!!', '100', $budg_form);
        $budg_form = str_replace('!!comment!!', '', $budg_form);
        $budg_form = str_replace('!!statut!!', htmlentities($msg[acquisition_budg_pre], ENT_QUOTES, $charset), $budg_form);
        $budg_form = str_replace('!!val_statut!!', '0', $budg_form);
    } else {
        $budg_form = str_replace('!!form_title!!', htmlentities($msg[acquisition_modif_budg], ENT_QUOTES, $charset), $budg_form);
        $budg_form = str_replace('!!libelle!!', htmlentities($bud->libelle, ENT_QUOTES, $charset), $budg_form);
        $budg_form = str_replace('!!seuil!!', $bud->seuil_alerte, $budg_form);
        $budg_form = str_replace('!!comment!!', htmlentities($bud->commentaires, ENT_QUOTES, $charset), $budg_form);
        switch ($bud->statut) {
            case STA_BUD_PRE:
                $budg_form = str_replace('!!statut!!', htmlentities($msg[acquisition_budg_pre], ENT_QUOTES, $charset), $budg_form);
                //Affichage du bouton d'activation
                $budg_form = str_replace('<!-- bouton_act -->', $ptab[2], $budg_form);
                break;
            case STA_BUD_VAL:
                $budg_form = str_replace('!!statut!!', htmlentities($msg[acquisition_statut_actif], ENT_QUOTES, $charset), $budg_form);
                //Affichage du bouton de cloture
                $budg_form = str_replace('<!-- bouton_clot -->', $ptab[0], $budg_form);
                break;
            case STA_BUD_CLO:
                $budg_form = str_replace('!!statut!!', htmlentities($msg[acquisition_statut_clot], ENT_QUOTES, $charset), $budg_form);
                break;
            default:
                $budg_form = str_replace('!!statut!!', htmlentities($msg[acquisition_budg_pre], ENT_QUOTES, $charset), $budg_form);
                //Affichage du bouton d'activation
                $budg_form = str_replace('<!-- bouton_act -->', $ptab[2], $budg_form);
                break;
        }
        $budg_form = str_replace('!!val_statut!!', $bud->statut, $budg_form);
        $budg_form = str_replace('<!-- bouton_sup -->', $ptab[1], $budg_form);
    }
    $budg_form = str_replace('!!montant!!', $mnt, $budg_form);
    $budg_form = str_replace('!!sel_typ!!', $sel_typ, $budg_form);
    $budg_form = str_replace('!!id!!', $id_bud, $budg_form);
    $budg_form = str_replace('!!libelle_suppr!!', addslashes($bud->libelle), $budg_form);
    $budg_form = str_replace('!!id_parent!!', 0, $budg_form);
    //Affichage rubriques budgetaires
    if (!$id_bud) {
        $budg_form = str_replace('!!lib_mnt!!', htmlentities($msg['acquisition_rub_mnt'], ENT_QUOTES, $charset), $budg_form);
        $budg_form = str_replace('<!-- rubriques -->', '', $budg_form);
    } else {
        if ($bud->type_budget == TYP_BUD_RUB) {
            $budg_form = str_replace('!!lib_mnt!!', htmlentities($msg['acquisition_rub_mnt'], ENT_QUOTES, $charset), $budg_form);
        } else {
            $budg_form = str_replace('!!lib_mnt!!', '&nbsp;', $budg_form);
        }
        $q = budgets::listRubriques($id_bud);
        $list_n1 = mysql_query($q, $dbh);
        while ($row = mysql_fetch_object($list_n1)) {
            $budg_form = str_replace('<!-- rubriques -->', $lig_rub[0] . '<!-- rubriques -->', $budg_form);
            $budg_form = str_replace('<!-- marge -->', '', $budg_form);
            if (rubriques::countChilds($row->id_rubrique)) {
                $budg_form = str_replace('<!-- img_plus -->', $lig_rub_img, $budg_form);
            } else {
                $budg_form = str_replace('<!-- img_plus -->', '', $budg_form);
            }
            $budg_form = str_replace('!!id_rub!!', $row->id_rubrique, $budg_form);
            $budg_form = str_replace('!!id_parent!!', $row->num_parent, $budg_form);
            $budg_form = str_replace('!!lib_rub!!', $row->libelle, $budg_form);
            if ($bud->type_budget == TYP_BUD_RUB) {
                $budg_form = str_replace('!!lib_mnt!!', htmlentities($msg['acquisition_rub_mnt'], ENT_QUOTES, $charset), $budg_form);
                $budg_form = str_replace('!!mnt!!', $row->montant, $budg_form);
            } else {
                $budg_form = str_replace('!!lib_mnt!!', '&nbsp;', $budg_form);
                $budg_form = str_replace('!!mnt!!', '&nbsp', $budg_form);
            }
            $budg_form = str_replace('!!ncp!!', $row->num_cp_compta, $budg_form);
            $budg_form = str_replace('<!-- sous_rub -->', '<!-- sous_rub' . $row->id_rubrique . ' -->', $budg_form);
            afficheSousRubriques($id_bud, $row->id_rubrique, $budg_form, 1);
        }
        if ($bud->statut != STA_BUD_CLO) {
            $budg_form = str_replace('<!-- bouton_lig -->', $bt_add_lig, $budg_form);
        }
    }
    $biblio = new entites($id_bibli);
    print "<div class='row'><label class='etiquette'>" . htmlentities($biblio->raison_sociale, ENT_QUOTES, $charset) . "</label></div>";
    $budg_form = str_replace('<!-- bouton_dup -->', $bouton_dup, $budg_form);
    $budg_form = str_replace('!!exer!!', $form_exer, $budg_form);
    $budg_form = str_replace('!!id_bibli!!', $id_bibli, $budg_form);
    $budg_form = str_replace('!!id_bud!!', $id_bud, $budg_form);
    $budg_form = str_replace('!!id_rub!!', 0, $budg_form);
    $budg_form = str_replace('!!id_parent!!', 0, $budg_form);
    print $budg_form;
    print confirmation_delete("./admin.php?categ=acquisition&sub=budget&action=del&id_bibli=" . $id_bibli . "&id_bud=");
}