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);
|
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()
|
public function listAll()
|
||||||
{
|
{
|
||||||
return DB::getInstance()->get('SELECT * FROM plugin_materiels_entry ORDER BY date_of_entry DESC;');
|
return DB::getInstance()->get('SELECT * FROM plugin_materiels_entry ORDER BY date_of_entry DESC;');
|
||||||
|
@ -20,6 +20,12 @@ class Equipment
|
|||||||
return $db->lastInsertRowId();
|
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)
|
public function get($id)
|
||||||
{
|
{
|
||||||
return DB::getInstance()->first('SELECT * FROM plugin_materiels_equipment WHERE id = ?;', $id);
|
return DB::getInstance()->first('SELECT * FROM plugin_materiels_equipment WHERE id = ?;', $id);
|
||||||
|
@ -18,13 +18,13 @@
|
|||||||
|
|
||||||
<table class="list">
|
<table class="list">
|
||||||
<thead>
|
<thead>
|
||||||
<th>Nom</th>
|
<th><b>Nom</b></th>
|
||||||
<td></td>
|
<th></th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{foreach from=$list item="cat"}
|
{foreach from=$list item="cat"}
|
||||||
<tr>
|
<tr>
|
||||||
<th>{$cat.name}</th>
|
<td>{$cat.name}</td>
|
||||||
<td class="actions">
|
<td class="actions">
|
||||||
{linkbutton shape="upload" label="Liste des matériels" href="materiels_par_categorie.php?id=%d"|args:$cat.id}
|
{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}
|
{linkbutton shape="edit" label="Modifier" href="modifier_categorie.php?id=%d"|args:$cat.id}
|
||||||
|
@ -10,18 +10,18 @@
|
|||||||
|
|
||||||
<table class="list">
|
<table class="list">
|
||||||
<thead>
|
<thead>
|
||||||
<th>Date</th>
|
<th><b>Date</b></th>
|
||||||
<td>Type</td>
|
<th><b>Type</b></th>
|
||||||
<td>Nombre</td>
|
<th><b>Nombre</b></th>
|
||||||
<td>Matériel</td>
|
<th><b>Matériel</b></th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{foreach from=$entries item="entry"}
|
{foreach from=$entries item="entry"}
|
||||||
<tr>
|
<tr>
|
||||||
<th>{$entry.date_of_entry}</th>
|
<td>{$entry.date_of_entry}</td>
|
||||||
<th>{$entry.kind}</th>
|
<td>{$entry.kind}</td>
|
||||||
<th>{$entry.number_of_equipments}</th>
|
<td>{$entry.number_of_equipments}</td>
|
||||||
<th>{$entry.equipment.designation}</th>
|
<td>{$entry.equipment.designation}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -4,16 +4,20 @@
|
|||||||
|
|
||||||
<table class="list">
|
<table class="list">
|
||||||
<thead>
|
<thead>
|
||||||
<th>Nombre en stock</th>
|
<th><b>Nombre</b></th>
|
||||||
<td>Categorie</td>
|
<th><b>Désignation</b></th>
|
||||||
<td>Désignation</td>
|
<th><b>Categorie</b></th>
|
||||||
|
<th></th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{foreach from=$eqmts item="eqmt"}
|
{foreach from=$eqmts item="eqmt"}
|
||||||
<tr>
|
<tr>
|
||||||
<th>{$eqmt.number_of_equipments}</th>
|
<td>{$eqmt.number_of_equipments}</td>
|
||||||
<th>{$eqmt.category.name}</th>
|
<td>{$eqmt.designation}</td>
|
||||||
<th>{$eqmt.designation}</th>
|
<td>{$eqmt.category.name}</td>
|
||||||
|
<td class="actions">
|
||||||
|
{linkbutton shape="edit" label="Modifier" href="modifier_materiel.php?id=%d"|args:$eqmt.id}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</tbody>
|
</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