ok Add Modify Delete for location, next entry
This commit is contained in:
parent
a3c7a67660
commit
5b47a9d0ba
14 changed files with 260 additions and 2 deletions
44
src/www/admin/localisations/modifier_localisation.php
Normal file
44
src/www/admin/localisations/modifier_localisation.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Garradin;
|
||||
use Garradin\Plugin\Materiels\Location;
|
||||
use Garradin\Utils;
|
||||
|
||||
require_once __DIR__ . '/../_inc.php';
|
||||
|
||||
$loc = new Location;
|
||||
|
||||
$l = $loc->get((int) qg('id'));
|
||||
|
||||
if (!$l) {
|
||||
throw new UserException("Cette localisation n'existe pas.");
|
||||
}
|
||||
|
||||
$csrf_key = 'edit_location_' . $l->id;
|
||||
|
||||
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
|
||||
{
|
||||
try
|
||||
{
|
||||
$loc->edit($l->id, [
|
||||
'name' => ucfirst(f('name'))
|
||||
]);
|
||||
Utils::redirect(PLUGIN_URL . 'localisations/index.php');
|
||||
}
|
||||
catch (\RuntimeException $e)
|
||||
{
|
||||
if (strstr($e->getMessage(), 'UNIQUE constraint failed'))
|
||||
{
|
||||
$form->addError('Cette localisation existe déjà.');
|
||||
} else
|
||||
{
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$cancel_link = PLUGIN_URL . 'localisations/index.php';
|
||||
|
||||
$tpl->assign(compact('l', 'csrf_key', 'cancel_link'));
|
||||
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/localisations/modifier_localisation.tpl');
|
||||
Loading…
Add table
Add a link
Reference in a new issue