ok for template to delete entry, next validate form for that

This commit is contained in:
JBthePenguin 2021-06-11 23:48:53 +02:00
parent 4aacfb204f
commit d6a6ec9153
5 changed files with 74 additions and 0 deletions

Binary file not shown.

View File

@ -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);
}
}
}

View File

@ -17,6 +17,7 @@
<th><b>Nombre</b></th>
<th><b>Matériel</b></th>
<th><b>Remarques</b></th>
<th></th>
</thead>
<tbody>
{foreach from=$entries item="entry"}
@ -26,6 +27,9 @@
<td>{$entry.equipment_number}</td>
<td>{$entry.equipment}</td>
<td>{$entry.additional_comment}</td>
<td class="actions">
{linkbutton shape="delete" label="Supprimer" href="supprimer_entree.php?id=%d"|args:$entry.id}
</td>
</tr>
{/foreach}
</tbody>

View File

@ -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"}

View File

@ -0,0 +1,39 @@
<?php
namespace Garradin;
use Garradin\Plugin\Materiels\Entry;
use Garradin\Plugin\Materiels\Equipment;
use Garradin\Utils;
require_once __DIR__ . '/../_inc.php';
$entry = new Entry;
$e = $entry->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 . " ».");
}