diff --git a/materiels.tar.gz b/materiels.tar.gz index 8d6b3e2..5f50f54 100644 Binary files a/materiels.tar.gz and b/materiels.tar.gz differ diff --git a/src/lib/Category.php b/src/lib/Category.php index 84562f1..3e89007 100644 --- a/src/lib/Category.php +++ b/src/lib/Category.php @@ -17,7 +17,6 @@ class Category $db->update('plugin_materiels_category', $data, $db->where('id', $id)); } - public function delete($id) { DB::getInstance()->delete('plugin_materiels_category', 'id = ' . $id); diff --git a/src/lib/Entry.php b/src/lib/Entry.php index 2eb8f03..eb4df77 100644 --- a/src/lib/Entry.php +++ b/src/lib/Entry.php @@ -34,11 +34,21 @@ class Entry return DB::getInstance()->first('SELECT * FROM plugin_materiels_entry WHERE id = ?;', $id); } + public function delete($id) + { + DB::getInstance()->delete('plugin_materiels_entry', 'id = ' . $id); + } + public function listAll() { return DB::getInstance()->get('SELECT * FROM plugin_materiels_entry ORDER BY entry_date DESC;'); } + public function listAllByEquipment($eqmt_id) + { + return DB::getInstance()->get('SELECT * FROM plugin_materiels_entry WHERE equipment_id = ? ORDER BY entry_date DESC;', $eqmt_id); + } + public function PossibilityRentEqmtEntry($id, $eqmt_number, $date) { $after_entry_dates = DB::getInstance()->get( diff --git a/src/lib/Equipment.php b/src/lib/Equipment.php index 98f9b21..53b6016 100644 --- a/src/lib/Equipment.php +++ b/src/lib/Equipment.php @@ -25,6 +25,11 @@ class Equipment return DB::getInstance()->first('SELECT * FROM plugin_materiels_equipment WHERE id = ?;', $id); } + public function delete($id) + { + DB::getInstance()->delete('plugin_materiels_equipment', 'id = ' . $id); + } + public function listAllByCategory() { $category = new Category; diff --git a/src/templates/entrees/supprimer_entree.tpl b/src/templates/entrees/supprimer_entree.tpl index 87c7502..8a660b2 100644 --- a/src/templates/entrees/supprimer_entree.tpl +++ b/src/templates/entrees/supprimer_entree.tpl @@ -5,7 +5,7 @@ {include file="%scommon/delete_form.tpl"|args:$plugin_tpl legend="Supprimer cette entrée de matériels ?" warning="Êtes-vous sûr de vouloir supprimer l'entrée de « %s » ?"|args:$entry_string - alert="Attention, la suppression de cette entrée supprimera le matériel « %s » du répertoire s'il n'est utilisé dans aucune autre entrée."|args:$eqmt_name + alert="Attention, la suppression de cette entrée supprimera le matériel « %s » du répertoire s'il n'a pas d'autre entrée."|args:$eqmt_name } {include file="admin/_foot.tpl"} diff --git a/src/www/admin/entrees/supprimer_entree.php b/src/www/admin/entrees/supprimer_entree.php index 535f7bb..c192b2e 100644 --- a/src/www/admin/entrees/supprimer_entree.php +++ b/src/www/admin/entrees/supprimer_entree.php @@ -9,23 +9,36 @@ require_once __DIR__ . '/../_inc.php'; $entry = new Entry; -$e = $entry->get((int) qg('id')); +$e_to_delete = $entry->get((int) qg('id')); $eqmt = new Equipment; -$equipment = $eqmt->get($e->equipment_id); -if (!$e) +if (!$e_to_delete) { throw new UserException("Cette entrée n'existe pas."); } -if ($entry->PossibilityDeleteEntry($e)) -{ - $csrf_key = 'delete_entry_' . $e->id; +$csrf_key = 'delete_entry_' . $e_to_delete->id; +if (f('delete') && $form->check($csrf_key) && !$form->hasErrors()) +{ + $entry->delete($e_to_delete->id); + try + { + $eqmt->delete($e_to_delete->equipment_id); + } + catch (\RuntimeException $e){ + } + Utils::redirect(PLUGIN_URL . 'entrees/index.php'); +} + +$equipment = $eqmt->get($e_to_delete->equipment_id); + +if ($entry->PossibilityDeleteEntry($e_to_delete)) +{ $cancel_link = PLUGIN_URL . 'entrees/index.php'; - $entry_string = (string) $e->equipment_number . " " . $equipment->designation . " à la date du " . date_create_from_format( - "Y-m-d", $e->entry_date)->format("d/m/y"); + $entry_string = (string) $e_to_delete->equipment_number . " " . $equipment->designation . " à la date du " . date_create_from_format( + "Y-m-d", $e_to_delete->entry_date)->format("d/m/y"); $eqmt_name = $equipment->designation; @@ -35,5 +48,5 @@ if ($entry->PossibilityDeleteEntry($e)) } else { throw new UserException( - "Cette entrée ne peut pas être supprimée car ça rendrait impossible l'historique des entrées et sorties de « " . $equipment->designation . " »."); + "Cette entrée ne peut pas être supprimée car ça rendrait impossible l'historique des entrées et sorties de « " . $equipment->designation . " ». --- plus de sorties que d'entrées ! ---"); }