51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Garradin;
|
||
|
use Garradin\Plugin\Materiels\Equipment;
|
||
|
use Garradin\Plugin\Materiels\Category;
|
||
|
use Garradin\Utils;
|
||
|
|
||
|
require_once __DIR__ . '/_inc.php';
|
||
|
|
||
|
$eqmt = new Equipment;
|
||
|
|
||
|
$eq = $eqmt->get((int) qg('id'));
|
||
|
|
||
|
if (!$eq) {
|
||
|
throw new UserException("Ce matériel n'existe pas.");
|
||
|
}
|
||
|
|
||
|
$cat = new Category;
|
||
|
$cats = $cat->listAll();
|
||
|
$selected_cat = $eq->category_id;
|
||
|
|
||
|
$csrf_key = 'edit_equipment_' . $eq->id;
|
||
|
|
||
|
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
$eqmt->edit($eq->id, [
|
||
|
'category_id' => (int) f('category_id'),
|
||
|
'designation' => ucfirst(strtolower(f('designation'))),
|
||
|
]);
|
||
|
Utils::redirect(PLUGIN_URL . 'index.php');
|
||
|
}
|
||
|
catch (\RuntimeException $e)
|
||
|
{
|
||
|
if (strstr($e->getMessage(), 'UNIQUE constraint failed'))
|
||
|
{
|
||
|
$form->addError('Ce matériel avec cette désignation existe déjà.');
|
||
|
} else
|
||
|
{
|
||
|
$form->addError($e->getMessage());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$cancel_link = PLUGIN_URL . 'index.php';
|
||
|
|
||
|
$tpl->assign(compact('eq', 'cats', 'selected_cat', 'csrf_key', 'cancel_link'));
|
||
|
|
||
|
$tpl->display(PLUGIN_ROOT . '/templates/modifier_materiel.tpl');
|