ok to modify equipment
This commit is contained in:
parent
c3eb06ce0d
commit
35c88400b0
@ -28,6 +28,12 @@ class Entry // entrées définitives
|
||||
DB::getInstance()->insert('plugin_materiels_entry', $data);
|
||||
}
|
||||
|
||||
public function edit($id, $data = [])
|
||||
{
|
||||
$db = DB::getInstance();
|
||||
$db->update('plugin_materiels_entry', $data, $db->where('id', $id));
|
||||
}
|
||||
|
||||
public function listAll()
|
||||
{
|
||||
return DB::getInstance()->get('SELECT * FROM plugin_materiels_entry ORDER BY date_of_entry DESC;');
|
||||
|
@ -20,6 +20,12 @@ class Equipment
|
||||
return $db->lastInsertRowId();
|
||||
}
|
||||
|
||||
public function edit($id, $data = [])
|
||||
{
|
||||
$db = DB::getInstance();
|
||||
$db->update('plugin_materiels_equipment', $data, $db->where('id', $id));
|
||||
}
|
||||
|
||||
public function get($id)
|
||||
{
|
||||
return DB::getInstance()->first('SELECT * FROM plugin_materiels_equipment WHERE id = ?;', $id);
|
||||
|
@ -18,13 +18,13 @@
|
||||
|
||||
<table class="list">
|
||||
<thead>
|
||||
<th>Nom</th>
|
||||
<td></td>
|
||||
<th><b>Nom</b></th>
|
||||
<th></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach from=$list item="cat"}
|
||||
<tr>
|
||||
<th>{$cat.name}</th>
|
||||
<td>{$cat.name}</td>
|
||||
<td class="actions">
|
||||
{linkbutton shape="upload" label="Liste des matériels" href="materiels_par_categorie.php?id=%d"|args:$cat.id}
|
||||
{linkbutton shape="edit" label="Modifier" href="modifier_categorie.php?id=%d"|args:$cat.id}
|
||||
|
@ -10,18 +10,18 @@
|
||||
|
||||
<table class="list">
|
||||
<thead>
|
||||
<th>Date</th>
|
||||
<td>Type</td>
|
||||
<td>Nombre</td>
|
||||
<td>Matériel</td>
|
||||
<th><b>Date</b></th>
|
||||
<th><b>Type</b></th>
|
||||
<th><b>Nombre</b></th>
|
||||
<th><b>Matériel</b></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach from=$entries item="entry"}
|
||||
<tr>
|
||||
<th>{$entry.date_of_entry}</th>
|
||||
<th>{$entry.kind}</th>
|
||||
<th>{$entry.number_of_equipments}</th>
|
||||
<th>{$entry.equipment.designation}</th>
|
||||
<td>{$entry.date_of_entry}</td>
|
||||
<td>{$entry.kind}</td>
|
||||
<td>{$entry.number_of_equipments}</td>
|
||||
<td>{$entry.equipment.designation}</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
|
@ -4,16 +4,20 @@
|
||||
|
||||
<table class="list">
|
||||
<thead>
|
||||
<th>Nombre en stock</th>
|
||||
<td>Categorie</td>
|
||||
<td>Désignation</td>
|
||||
<th><b>Nombre</b></th>
|
||||
<th><b>Désignation</b></th>
|
||||
<th><b>Categorie</b></th>
|
||||
<th></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach from=$eqmts item="eqmt"}
|
||||
<tr>
|
||||
<th>{$eqmt.number_of_equipments}</th>
|
||||
<th>{$eqmt.category.name}</th>
|
||||
<th>{$eqmt.designation}</th>
|
||||
<td>{$eqmt.number_of_equipments}</td>
|
||||
<td>{$eqmt.designation}</td>
|
||||
<td>{$eqmt.category.name}</td>
|
||||
<td class="actions">
|
||||
{linkbutton shape="edit" label="Modifier" href="modifier_materiel.php?id=%d"|args:$eqmt.id}
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
|
28
src/templates/modifier_materiel.tpl
Normal file
28
src/templates/modifier_materiel.tpl
Normal file
@ -0,0 +1,28 @@
|
||||
{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="index"}
|
||||
|
||||
<form method="post" action="{$self_url}" data-focus="1">
|
||||
{form_errors}
|
||||
<fieldset>
|
||||
<legend>Modifier ce matériel</legend>
|
||||
<dl>
|
||||
<dt><label for="f_cat">Catégorie</label> <b>(obligatoire)</b></dt>
|
||||
<dd>
|
||||
<select name="category_id" id="f_cat">
|
||||
{foreach from=$cats item="cat"}
|
||||
<option value="{$cat.id}"{if $selected_cat == $cat.id} selected="selected"{/if}>{$cat.name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</dd>
|
||||
{input type="text" name="designation" label="Désignation" required=true source=$eq maxlength="255"}
|
||||
</dl>
|
||||
</fieldset>
|
||||
<p class="submit">
|
||||
{csrf_field key=$csrf_key}
|
||||
{button type="submit" name="save" label="Enregistrer" shape="right" class="main"}
|
||||
{linkbutton label="Annuler" shape="export" href=$cancel_link}
|
||||
</p>
|
||||
</form>
|
||||
|
||||
{include file="admin/_foot.tpl"}
|
50
src/www/admin/modifier_materiel.php
Normal file
50
src/www/admin/modifier_materiel.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Garradin;
|
||||
use Garradin\Plugin\Materiels\Equipment;
|
||||
use Garradin\Plugin\Materiels\Category;
|
||||
use Garradin\Utils;
|
||||
|
||||
require_once __DIR__ . '/_inc.php';
|
||||
|
||||
$eqmt = new Equipment;
|
||||
|
||||
$eq = $eqmt->get((int) qg('id'));
|
||||
|
||||
if (!$eq) {
|
||||
throw new UserException("Ce matériel n'existe pas.");
|
||||
}
|
||||
|
||||
$cat = new Category;
|
||||
$cats = $cat->listAll();
|
||||
$selected_cat = $eq->category_id;
|
||||
|
||||
$csrf_key = 'edit_equipment_' . $eq->id;
|
||||
|
||||
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
|
||||
{
|
||||
try
|
||||
{
|
||||
$eqmt->edit($eq->id, [
|
||||
'category_id' => (int) f('category_id'),
|
||||
'designation' => ucfirst(strtolower(f('designation'))),
|
||||
]);
|
||||
Utils::redirect(PLUGIN_URL . 'index.php');
|
||||
}
|
||||
catch (\RuntimeException $e)
|
||||
{
|
||||
if (strstr($e->getMessage(), 'UNIQUE constraint failed'))
|
||||
{
|
||||
$form->addError('Ce matériel avec cette désignation existe déjà.');
|
||||
} else
|
||||
{
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$cancel_link = PLUGIN_URL . 'index.php';
|
||||
|
||||
$tpl->assign(compact('eq', 'cats', 'selected_cat', 'csrf_key', 'cancel_link'));
|
||||
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/modifier_materiel.tpl');
|
Loading…
Reference in New Issue
Block a user