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 @@
- Nom |
- |
+ Nom |
+ |
{foreach from=$list item="cat"}
- {$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 @@
- Date |
- Type |
- Nombre |
- Matériel |
+ Date |
+ Type |
+ Nombre |
+ Matériel |
{foreach from=$entries item="entry"}
- {$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}
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 @@
- Nombre en stock |
- Categorie |
- Désignation |
+ Nombre |
+ Désignation |
+ Categorie |
+ |
{foreach from=$eqmts item="eqmt"}
- {$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}
+ |
{/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"}
+
+
+
+{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');
|