diff --git a/materiels.tar.gz b/materiels.tar.gz
index fd267dd..73fa49a 100644
Binary files a/materiels.tar.gz and b/materiels.tar.gz differ
diff --git a/src/lib/Location.php b/src/lib/Location.php
new file mode 100644
index 0000000..0d3b7a9
--- /dev/null
+++ b/src/lib/Location.php
@@ -0,0 +1,43 @@
+ 'int',
+ 'name' => 'string',
+ ];
+
+ public function add($data = [])
+ {
+ DB::getInstance()->insert('plugin_materiels_location', $data);
+ }
+
+ public function edit($id, $data = [])
+ {
+ $db = DB::getInstance();
+ $db->update('plugin_materiels_location', $data, $db->where('id', $id));
+ }
+
+
+ public function delete($id)
+ {
+ DB::getInstance()->delete('plugin_materiels_location', 'id = ' . $id);
+ }
+
+ public function get($id)
+ {
+ return DB::getInstance()->first('SELECT * FROM plugin_materiels_location WHERE id = ?;', $id);
+ }
+
+ public function listAll()
+ {
+ return DB::getInstance()->get('SELECT * FROM plugin_materiels_location ORDER BY name;');
+ }
+}
diff --git a/src/templates/_nav.tpl b/src/templates/_nav.tpl
index 323a59a..151fd2f 100644
--- a/src/templates/_nav.tpl
+++ b/src/templates/_nav.tpl
@@ -2,6 +2,7 @@
+
+
+
+ Nom |
+ |
+
+
+ {foreach from=$list item="loc"}
+
+ {$loc.name} |
+
+ {linkbutton shape="upload" label="Liste des materiels" href="materiels_par_localisation.php?id=%d"|args:$loc.id}
+ {linkbutton shape="edit" label="Modifier" href="modifier_localisation.php?id=%d"|args:$loc.id}
+ {linkbutton shape="delete" label="Supprimer" href="supprimer_localisation.php?id=%d"|args:$loc.id}
+ |
+
+ {/foreach}
+
+
+
+{include file="admin/_foot.tpl"}
diff --git a/src/templates/localisations/materiels_par_localisation.tpl b/src/templates/localisations/materiels_par_localisation.tpl
new file mode 100644
index 0000000..f16a6db
--- /dev/null
+++ b/src/templates/localisations/materiels_par_localisation.tpl
@@ -0,0 +1,5 @@
+{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="localisations"}
+
+{include file="admin/_foot.tpl"}
diff --git a/src/templates/localisations/modifier_localisation.tpl b/src/templates/localisations/modifier_localisation.tpl
new file mode 100644
index 0000000..efd56cb
--- /dev/null
+++ b/src/templates/localisations/modifier_localisation.tpl
@@ -0,0 +1,20 @@
+{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="localisations"}
+
+
+
+{include file="admin/_foot.tpl"}
diff --git a/src/templates/localisations/supprimer_localisation.tpl b/src/templates/localisations/supprimer_localisation.tpl
new file mode 100644
index 0000000..a6a1bb1
--- /dev/null
+++ b/src/templates/localisations/supprimer_localisation.tpl
@@ -0,0 +1,11 @@
+{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="localisations"}
+
+{include file="%scommon/delete_form.tpl"|args:$plugin_tpl
+ legend="Supprimer cette localisation de matériels ?"
+ warning="Êtes-vous sûr de vouloir supprimer la localisation « %s » ?"|args:$l.name
+ alert="Attention, la localisation ne doit plus contenir de matériels pour pouvoir être supprimée."
+}
+
+{include file="admin/_foot.tpl"}
diff --git a/src/www/admin/categories/materiels_par_categorie.php b/src/www/admin/categories/materiels_par_categorie.php
index 0337b92..610d743 100644
--- a/src/www/admin/categories/materiels_par_categorie.php
+++ b/src/www/admin/categories/materiels_par_categorie.php
@@ -1,6 +1,7 @@
id;
+$csrf_key = 'edit_category_' . $c->id;
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
{
diff --git a/src/www/admin/categories/supprimer_categorie.php b/src/www/admin/categories/supprimer_categorie.php
index 73e609d..d59b8af 100644
--- a/src/www/admin/categories/supprimer_categorie.php
+++ b/src/www/admin/categories/supprimer_categorie.php
@@ -14,7 +14,7 @@ if (!$c) {
throw new UserException("Cette catégorie n'existe pas.");
}
-$csrf_key = 'delete_categorie_' . $c->id;
+$csrf_key = 'delete_category_' . $c->id;
if (f('delete') && $form->check($csrf_key) && !$form->hasErrors())
{
diff --git a/src/www/admin/localisations/index.php b/src/www/admin/localisations/index.php
new file mode 100644
index 0000000..416a923
--- /dev/null
+++ b/src/www/admin/localisations/index.php
@@ -0,0 +1,39 @@
+check($csrf_key) && !$form->hasErrors())
+{
+ try
+ {
+ $loc->add([
+ '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());
+ }
+ }
+}
+
+$list = $loc->listAll();
+
+$tpl->assign(compact('csrf_key', 'list'));
+
+$tpl->display(PLUGIN_ROOT . '/templates/localisations/index.tpl');
diff --git a/src/www/admin/localisations/materiels_par_localisation.php b/src/www/admin/localisations/materiels_par_localisation.php
new file mode 100644
index 0000000..10190e6
--- /dev/null
+++ b/src/www/admin/localisations/materiels_par_localisation.php
@@ -0,0 +1,20 @@
+get((int) qg('id'));
+
+if (!$l) {
+ throw new UserException("Cette localisation n'existe pas.");
+}
+
+$tpl->assign(compact('l'));
+
+$tpl->display(PLUGIN_ROOT . '/templates/localisations/materiels_par_localisation.tpl');
diff --git a/src/www/admin/localisations/modifier_localisation.php b/src/www/admin/localisations/modifier_localisation.php
new file mode 100644
index 0000000..fdf9d21
--- /dev/null
+++ b/src/www/admin/localisations/modifier_localisation.php
@@ -0,0 +1,44 @@
+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');
diff --git a/src/www/admin/localisations/supprimer_localisation.php b/src/www/admin/localisations/supprimer_localisation.php
new file mode 100644
index 0000000..5aa585f
--- /dev/null
+++ b/src/www/admin/localisations/supprimer_localisation.php
@@ -0,0 +1,36 @@
+get((int) qg('id'));
+
+if (!$l) {
+ throw new UserException("Cette localisation n'existe pas.");
+}
+
+$csrf_key = 'delete_location_' . $l->id;
+
+if (f('delete') && $form->check($csrf_key) && !$form->hasErrors())
+{
+ try
+ {
+ $loc->delete($l->id);
+ Utils::redirect(PLUGIN_URL . 'localisations/index.php');
+ }
+ catch (\RuntimeException $e)
+ {
+ $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/supprimer_localisation.tpl');