ok to validate delete entry, next delete output.

This commit is contained in:
JBthePenguin 2021-06-12 09:45:08 +02:00
parent d6a6ec9153
commit cb2c3f4565
6 changed files with 38 additions and 11 deletions

Binary file not shown.

View File

@ -17,7 +17,6 @@ class Category
$db->update('plugin_materiels_category', $data, $db->where('id', $id)); $db->update('plugin_materiels_category', $data, $db->where('id', $id));
} }
public function delete($id) public function delete($id)
{ {
DB::getInstance()->delete('plugin_materiels_category', 'id = ' . $id); DB::getInstance()->delete('plugin_materiels_category', 'id = ' . $id);

View File

@ -34,11 +34,21 @@ class Entry
return DB::getInstance()->first('SELECT * FROM plugin_materiels_entry WHERE id = ?;', $id); 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() public function listAll()
{ {
return DB::getInstance()->get('SELECT * FROM plugin_materiels_entry ORDER BY entry_date DESC;'); 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) public function PossibilityRentEqmtEntry($id, $eqmt_number, $date)
{ {
$after_entry_dates = DB::getInstance()->get( $after_entry_dates = DB::getInstance()->get(

View File

@ -25,6 +25,11 @@ class Equipment
return DB::getInstance()->first('SELECT * FROM plugin_materiels_equipment WHERE id = ?;', $id); 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() public function listAllByCategory()
{ {
$category = new Category; $category = new Category;

View File

@ -5,7 +5,7 @@
{include file="%scommon/delete_form.tpl"|args:$plugin_tpl {include file="%scommon/delete_form.tpl"|args:$plugin_tpl
legend="Supprimer cette entrée de matériels ?" legend="Supprimer cette entrée de matériels ?"
warning="Êtes-vous sûr de vouloir supprimer l'entrée de « %s » ?"|args:$entry_string 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"} {include file="admin/_foot.tpl"}

View File

@ -9,23 +9,36 @@ require_once __DIR__ . '/../_inc.php';
$entry = new Entry; $entry = new Entry;
$e = $entry->get((int) qg('id')); $e_to_delete = $entry->get((int) qg('id'));
$eqmt = new Equipment; $eqmt = new Equipment;
$equipment = $eqmt->get($e->equipment_id);
if (!$e) if (!$e_to_delete)
{ {
throw new UserException("Cette entrée n'existe pas."); throw new UserException("Cette entrée n'existe pas.");
} }
if ($entry->PossibilityDeleteEntry($e)) $csrf_key = 'delete_entry_' . $e_to_delete->id;
{
$csrf_key = 'delete_entry_' . $e->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'; $cancel_link = PLUGIN_URL . 'entrees/index.php';
$entry_string = (string) $e->equipment_number . " " . $equipment->designation . " à la date du " . date_create_from_format( $entry_string = (string) $e_to_delete->equipment_number . " " . $equipment->designation . " à la date du " . date_create_from_format(
"Y-m-d", $e->entry_date)->format("d/m/y"); "Y-m-d", $e_to_delete->entry_date)->format("d/m/y");
$eqmt_name = $equipment->designation; $eqmt_name = $equipment->designation;
@ -35,5 +48,5 @@ if ($entry->PossibilityDeleteEntry($e))
} else { } else {
throw new UserException( 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 ! ---");
} }