ok to modify equipment
This commit is contained in:
parent
c3eb06ce0d
commit
35c88400b0
7 changed files with 111 additions and 17 deletions
50
src/www/admin/modifier_materiel.php
Normal file
50
src/www/admin/modifier_materiel.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?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');
|
||||
Loading…
Add table
Add a link
Reference in a new issue