Artifact 566d206828da849eec20b7d9933cb88e826efb86:


<?php
namespace Garradin;

require_once __DIR__ . '/../_inc.php';

$session->requireAccess('compta', Membres::DROIT_ADMIN);

$e = new Compta\Exercices;

$exercice = $e->get((int)qg('id'));

if (!$exercice)
{
	throw new UserException('Exercice inconnu.');
}

if ($exercice->cloture)
{
    throw new UserException('Impossible de modifier un exercice clôturé.');
}

if ($form('edit'))
{
    $form->check('compta_modif_exercice_' . $exercice->id, [
        'libelle' => 'required',
        'fin'     => 'required|date',
        'debut'   => 'required|date',
    ]);

    if (!$form->hasErrors())
    {
        try
        {
            $id = $e->edit($exercice->id, [
                'libelle'   =>  f('libelle'),
                'debut'     =>  f('debut'),
                'fin'       =>  f('fin'),
            ]);

            Utils::redirect(ADMIN_URL . 'compta/exercices/');
        }
        catch (UserException $e)
        {
            $form->addError($e->getMessage());
        }
    }
}

$tpl->assign('exercice', $exercice);

$tpl->display('admin/compta/exercices/modifier.tpl');