diff --git a/materiels.tar.gz b/materiels.tar.gz index 4ed84ab..8d6b3e2 100644 Binary files a/materiels.tar.gz and b/materiels.tar.gz differ diff --git a/src/lib/Entry.php b/src/lib/Entry.php index 41a2270..2eb8f03 100644 --- a/src/lib/Entry.php +++ b/src/lib/Entry.php @@ -4,6 +4,7 @@ namespace Garradin\Plugin\Materiels; use Garradin\DB; use Garradin\Plugin\Materiels\Equipment; +use Garradin\Plugin\Materiels\Output; class Entry { @@ -28,6 +29,11 @@ class Entry $db->update('plugin_materiels_entry', $data, $db->where('id', $id)); } + public function get($id) + { + return DB::getInstance()->first('SELECT * FROM plugin_materiels_entry WHERE id = ?;', $id); + } + public function listAll() { return DB::getInstance()->get('SELECT * FROM plugin_materiels_entry ORDER BY entry_date DESC;'); @@ -52,4 +58,18 @@ class Entry } return true; } + + public function PossibilityDeleteEntry($entry) + { + $output = new Output; + if ($entry->kind == 'Location / Prêt') + { + return $output->PossibilityNoOwnedEqmtOutput( + $entry->equipment_id, $entry->equipment_number, $entry->entry_date); + } else + { + return $output->PossibilityOwnedEqmtOutput( + $entry->equipment_id, $entry->equipment_number, $entry->entry_date); + } + } } diff --git a/src/templates/entrees/index.tpl b/src/templates/entrees/index.tpl index c78908c..04eec52 100644 --- a/src/templates/entrees/index.tpl +++ b/src/templates/entrees/index.tpl @@ -17,6 +17,7 @@ Nombre Matériel Remarques + {foreach from=$entries item="entry"} @@ -26,6 +27,9 @@ {$entry.equipment_number} {$entry.equipment} {$entry.additional_comment} + + {linkbutton shape="delete" label="Supprimer" href="supprimer_entree.php?id=%d"|args:$entry.id} + {/foreach} diff --git a/src/templates/entrees/supprimer_entree.tpl b/src/templates/entrees/supprimer_entree.tpl new file mode 100644 index 0000000..87c7502 --- /dev/null +++ b/src/templates/entrees/supprimer_entree.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="entrees"} + +{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 +} + +{include file="admin/_foot.tpl"} diff --git a/src/www/admin/entrees/supprimer_entree.php b/src/www/admin/entrees/supprimer_entree.php new file mode 100644 index 0000000..535f7bb --- /dev/null +++ b/src/www/admin/entrees/supprimer_entree.php @@ -0,0 +1,39 @@ +get((int) qg('id')); +$eqmt = new Equipment; +$equipment = $eqmt->get($e->equipment_id); + +if (!$e) +{ + throw new UserException("Cette entrée n'existe pas."); +} + +if ($entry->PossibilityDeleteEntry($e)) +{ + $csrf_key = 'delete_entry_' . $e->id; + + $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"); + + $eqmt_name = $equipment->designation; + + $tpl->assign(compact('entry_string', 'eqmt_name', 'csrf_key', 'cancel_link')); + + $tpl->display(PLUGIN_ROOT . '/templates/entrees/supprimer_entree.tpl'); + +} 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 . " »."); +}