From 35c88400b0b70652dc1b472bf29fde75cc8642fb Mon Sep 17 00:00:00 2001 From: JBthePenguin Date: Sat, 5 Jun 2021 16:45:03 +0200 Subject: [PATCH] ok to modify equipment --- src/lib/Entry.php | 6 +++ src/lib/Equipment.php | 6 +++ src/templates/categories/index.tpl | 6 +-- src/templates/entrees/definitives/index.tpl | 16 +++---- src/templates/index.tpl | 16 ++++--- src/templates/modifier_materiel.tpl | 28 ++++++++++++ src/www/admin/modifier_materiel.php | 50 +++++++++++++++++++++ 7 files changed, 111 insertions(+), 17 deletions(-) create mode 100644 src/templates/modifier_materiel.tpl create mode 100644 src/www/admin/modifier_materiel.php diff --git a/src/lib/Entry.php b/src/lib/Entry.php index 0984aa2..9766c0f 100644 --- a/src/lib/Entry.php +++ b/src/lib/Entry.php @@ -28,6 +28,12 @@ class Entry // entrées définitives DB::getInstance()->insert('plugin_materiels_entry', $data); } + public function edit($id, $data = []) + { + $db = DB::getInstance(); + $db->update('plugin_materiels_entry', $data, $db->where('id', $id)); + } + public function listAll() { return DB::getInstance()->get('SELECT * FROM plugin_materiels_entry ORDER BY date_of_entry DESC;'); diff --git a/src/lib/Equipment.php b/src/lib/Equipment.php index 3e0d3de..c8c2193 100644 --- a/src/lib/Equipment.php +++ b/src/lib/Equipment.php @@ -20,6 +20,12 @@ class Equipment return $db->lastInsertRowId(); } + public function edit($id, $data = []) + { + $db = DB::getInstance(); + $db->update('plugin_materiels_equipment', $data, $db->where('id', $id)); + } + public function get($id) { return DB::getInstance()->first('SELECT * FROM plugin_materiels_equipment WHERE id = ?;', $id); diff --git a/src/templates/categories/index.tpl b/src/templates/categories/index.tpl index 5fa2e28..ab08a26 100644 --- a/src/templates/categories/index.tpl +++ b/src/templates/categories/index.tpl @@ -18,13 +18,13 @@ - - + + {foreach from=$list item="cat"} - +
NomNom
{$cat.name}{$cat.name} {linkbutton shape="upload" label="Liste des matériels" href="materiels_par_categorie.php?id=%d"|args:$cat.id} {linkbutton shape="edit" label="Modifier" href="modifier_categorie.php?id=%d"|args:$cat.id} diff --git a/src/templates/entrees/definitives/index.tpl b/src/templates/entrees/definitives/index.tpl index a31691e..f09d0b5 100644 --- a/src/templates/entrees/definitives/index.tpl +++ b/src/templates/entrees/definitives/index.tpl @@ -10,18 +10,18 @@ - - - - + + + + {foreach from=$entries item="entry"} - - - - + + + + {/foreach} diff --git a/src/templates/index.tpl b/src/templates/index.tpl index acb3416..8caa002 100644 --- a/src/templates/index.tpl +++ b/src/templates/index.tpl @@ -4,16 +4,20 @@
DateTypeNombreMatérielDateTypeNombreMatériel
{$entry.date_of_entry}{$entry.kind}{$entry.number_of_equipments}{$entry.equipment.designation}{$entry.date_of_entry}{$entry.kind}{$entry.number_of_equipments}{$entry.equipment.designation}
- - - + + + + {foreach from=$eqmts item="eqmt"} - - - + + + + {/foreach} diff --git a/src/templates/modifier_materiel.tpl b/src/templates/modifier_materiel.tpl new file mode 100644 index 0000000..3bdaf6b --- /dev/null +++ b/src/templates/modifier_materiel.tpl @@ -0,0 +1,28 @@ +{include file="admin/_head.tpl" title="%s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id} + +{include file="%s_nav.tpl"|args:$plugin_tpl current="index"} + + + {form_errors} +
+ Modifier ce matériel +
+
(obligatoire)
+
+ +
+ {input type="text" name="designation" label="Désignation" required=true source=$eq maxlength="255"} +
+
+

+ {csrf_field key=$csrf_key} + {button type="submit" name="save" label="Enregistrer" shape="right" class="main"} + {linkbutton label="Annuler" shape="export" href=$cancel_link} +

+ + +{include file="admin/_foot.tpl"} diff --git a/src/www/admin/modifier_materiel.php b/src/www/admin/modifier_materiel.php new file mode 100644 index 0000000..d79dc31 --- /dev/null +++ b/src/www/admin/modifier_materiel.php @@ -0,0 +1,50 @@ +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');
Nombre en stockCategorieDésignationNombreDésignationCategorie
{$eqmt.number_of_equipments}{$eqmt.category.name}{$eqmt.designation}{$eqmt.number_of_equipments}{$eqmt.designation}{$eqmt.category.name} + {linkbutton shape="edit" label="Modifier" href="modifier_materiel.php?id=%d"|args:$eqmt.id} +