ok for movement, delete old entry and output

This commit is contained in:
JBthePenguin 2021-09-02 14:06:03 +02:00
parent 0b97418682
commit 27c9d653f7
30 changed files with 52 additions and 943 deletions

View file

@ -1,31 +1,37 @@
<?php
// edit a specific equipment
namespace Garradin;
require_once __DIR__ . '/_inc.php';
use Garradin\Plugin\Materiels\Equipment;
use Garradin\Plugin\Materiels\Category;
use Garradin\Utils;
require_once __DIR__ . '/_inc.php';
// get the equipment requested
$eqmt = new Equipment;
$eqmt_requested = $eqmt->get((int) qg('id'));
$eq = $eqmt->get((int) qg('id'));
if (!$eq) {
if (!$eqmt_requested) {
throw new UserException("Ce matériel n'existe pas.");
}
// get all categories and set the selected one
$cat = new Category;
$cats = $cat->listAll();
$selected_cat = $eq->category_id;
$selected_cat = $eqmt_requested->category_id;
$csrf_key = 'edit_equipment_' . $eq->id;
// check if edit form is submitted
$csrf_key = 'edit_equipment_' . $eqmt_requested->id;
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
{
// try to edit equipment selected and if error catched add it in form
try
{
$eqmt->edit($eq->id, [
$eqmt->edit($eqmt_requested->id, [
'category_id' => (int) f('category_id'),
'designation' => ucfirst(strtolower(f('designation'))),
]);
@ -45,6 +51,7 @@ if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
$cancel_link = PLUGIN_URL . 'index.php';
$tpl->assign(compact('eq', 'cats', 'selected_cat', 'csrf_key', 'cancel_link'));
// send all to template
$tpl->assign(compact('eqmt_requested', 'cats', 'selected_cat', 'csrf_key', 'cancel_link'));
$tpl->display(PLUGIN_ROOT . '/templates/modifier_materiel.tpl');