ok Add Modify Delete for location, next entry
This commit is contained in:
parent
a3c7a67660
commit
5b47a9d0ba
BIN
materiels.tar.gz
BIN
materiels.tar.gz
Binary file not shown.
43
src/lib/Location.php
Normal file
43
src/lib/Location.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Garradin\Plugin\Materiels;
|
||||||
|
|
||||||
|
use Garradin\DB;
|
||||||
|
|
||||||
|
class Location
|
||||||
|
{
|
||||||
|
protected $id;
|
||||||
|
protected $name;
|
||||||
|
|
||||||
|
protected $_types = [
|
||||||
|
'id' => 'int',
|
||||||
|
'name' => 'string',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function add($data = [])
|
||||||
|
{
|
||||||
|
DB::getInstance()->insert('plugin_materiels_location', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit($id, $data = [])
|
||||||
|
{
|
||||||
|
$db = DB::getInstance();
|
||||||
|
$db->update('plugin_materiels_location', $data, $db->where('id', $id));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function delete($id)
|
||||||
|
{
|
||||||
|
DB::getInstance()->delete('plugin_materiels_location', 'id = ' . $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get($id)
|
||||||
|
{
|
||||||
|
return DB::getInstance()->first('SELECT * FROM plugin_materiels_location WHERE id = ?;', $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listAll()
|
||||||
|
{
|
||||||
|
return DB::getInstance()->get('SELECT * FROM plugin_materiels_location ORDER BY name;');
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li class="{if $current == 'index'}current{/if}"><a href="{plugin_url}">Matériels en stock</a></li>
|
<li class="{if $current == 'index'}current{/if}"><a href="{plugin_url}">Matériels en stock</a></li>
|
||||||
<li class="{if $current == 'categories'}current{/if}"><a href="{plugin_url file="categories/index.php"}">Catégories</a></li>
|
<li class="{if $current == 'categories'}current{/if}"><a href="{plugin_url file="categories/index.php"}">Catégories</a></li>
|
||||||
|
<li class="{if $current == 'localisations'}current{/if}"><a href="{plugin_url file="localisations/index.php"}">Localisations</a></li>
|
||||||
<li class="{if $current == 'entrees_definitives'}current{/if}"><a href="{plugin_url file="entrees_definitives.php"}"><b>Entrées définitives</b></a></li>
|
<li class="{if $current == 'entrees_definitives'}current{/if}"><a href="{plugin_url file="entrees_definitives.php"}"><b>Entrées définitives</b></a></li>
|
||||||
<li class="{if $current == 'entrees_provisoires'}current{/if}"><a href="{plugin_url file="entrees_provisoires.php"}">Entrées provisoires</a></li>
|
<li class="{if $current == 'entrees_provisoires'}current{/if}"><a href="{plugin_url file="entrees_provisoires.php"}">Entrées provisoires</a></li>
|
||||||
<li class="{if $current == 'sorties_definitives'}current{/if}"><a href="{plugin_url file="sorties_definitives.php"}">Sorties définitives</a></li>
|
<li class="{if $current == 'sorties_definitives'}current{/if}"><a href="{plugin_url file="sorties_definitives.php"}">Sorties définitives</a></li>
|
||||||
|
38
src/templates/localisations/index.tpl
Normal file
38
src/templates/localisations/index.tpl
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
{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="localisations"}
|
||||||
|
|
||||||
|
<form method="post" action="{$self_url}">
|
||||||
|
<fieldset>
|
||||||
|
<legend>Ajouter une localisation</legend>
|
||||||
|
{form_errors}
|
||||||
|
<dl>
|
||||||
|
{input type="text" name="name" label="Nom" required=true}
|
||||||
|
</dl>
|
||||||
|
<p class="submit">
|
||||||
|
{csrf_field key=$csrf_key}
|
||||||
|
{button type="submit" name="save" label="Ajouter" shape="right" class="main"}
|
||||||
|
</p>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<table class="list">
|
||||||
|
<thead>
|
||||||
|
<th>Nom</th>
|
||||||
|
<td></td>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{foreach from=$list item="loc"}
|
||||||
|
<tr>
|
||||||
|
<th>{$loc.name}</th>
|
||||||
|
<td class="actions">
|
||||||
|
{linkbutton shape="upload" label="Liste des materiels" href="materiels_par_localisation.php?id=%d"|args:$loc.id}
|
||||||
|
{linkbutton shape="edit" label="Modifier" href="modifier_localisation.php?id=%d"|args:$loc.id}
|
||||||
|
{linkbutton shape="delete" label="Supprimer" href="supprimer_localisation.php?id=%d"|args:$loc.id}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/foreach}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{include file="admin/_foot.tpl"}
|
@ -0,0 +1,5 @@
|
|||||||
|
{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="localisations"}
|
||||||
|
|
||||||
|
{include file="admin/_foot.tpl"}
|
20
src/templates/localisations/modifier_localisation.tpl
Normal file
20
src/templates/localisations/modifier_localisation.tpl
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{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="localisations"}
|
||||||
|
|
||||||
|
<form method="post" action="{$self_url}" data-focus="1">
|
||||||
|
{form_errors}
|
||||||
|
<fieldset>
|
||||||
|
<legend>Modifier cette localisation</legend>
|
||||||
|
<dl>
|
||||||
|
{input type="text" name="name" label="Nom" required=true source=$l}
|
||||||
|
</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"}
|
11
src/templates/localisations/supprimer_localisation.tpl
Normal file
11
src/templates/localisations/supprimer_localisation.tpl
Normal 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="localisations"}
|
||||||
|
|
||||||
|
{include file="%scommon/delete_form.tpl"|args:$plugin_tpl
|
||||||
|
legend="Supprimer cette localisation de matériels ?"
|
||||||
|
warning="Êtes-vous sûr de vouloir supprimer la localisation « %s » ?"|args:$l.name
|
||||||
|
alert="Attention, la localisation ne doit plus contenir de matériels pour pouvoir être supprimée."
|
||||||
|
}
|
||||||
|
|
||||||
|
{include file="admin/_foot.tpl"}
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Garradin;
|
namespace Garradin;
|
||||||
|
|
||||||
use Garradin\Plugin\Materiels\Category;
|
use Garradin\Plugin\Materiels\Category;
|
||||||
use Garradin\Utils;
|
use Garradin\Utils;
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ if (!$c) {
|
|||||||
throw new UserException("Cette catégorie n'existe pas.");
|
throw new UserException("Cette catégorie n'existe pas.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$csrf_key = 'edit_categorie_' . $c->id;
|
$csrf_key = 'edit_category_' . $c->id;
|
||||||
|
|
||||||
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
|
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@ if (!$c) {
|
|||||||
throw new UserException("Cette catégorie n'existe pas.");
|
throw new UserException("Cette catégorie n'existe pas.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$csrf_key = 'delete_categorie_' . $c->id;
|
$csrf_key = 'delete_category_' . $c->id;
|
||||||
|
|
||||||
if (f('delete') && $form->check($csrf_key) && !$form->hasErrors())
|
if (f('delete') && $form->check($csrf_key) && !$form->hasErrors())
|
||||||
{
|
{
|
||||||
|
39
src/www/admin/localisations/index.php
Normal file
39
src/www/admin/localisations/index.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Garradin;
|
||||||
|
|
||||||
|
use Garradin\Plugin\Materiels\Location;
|
||||||
|
use Garradin\Utils;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../_inc.php';
|
||||||
|
|
||||||
|
$loc = new Location;
|
||||||
|
|
||||||
|
$csrf_key = 'loc_create';
|
||||||
|
|
||||||
|
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$loc->add([
|
||||||
|
'name' => ucfirst(f('name'))
|
||||||
|
]);
|
||||||
|
Utils::redirect(PLUGIN_URL . 'localisations/index.php');
|
||||||
|
}
|
||||||
|
catch (\RuntimeException $e)
|
||||||
|
{
|
||||||
|
if (strstr($e->getMessage(), 'UNIQUE constraint failed'))
|
||||||
|
{
|
||||||
|
$form->addError('Cette localisation existe déjà.');
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
$form->addError($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = $loc->listAll();
|
||||||
|
|
||||||
|
$tpl->assign(compact('csrf_key', 'list'));
|
||||||
|
|
||||||
|
$tpl->display(PLUGIN_ROOT . '/templates/localisations/index.tpl');
|
20
src/www/admin/localisations/materiels_par_localisation.php
Normal file
20
src/www/admin/localisations/materiels_par_localisation.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Garradin;
|
||||||
|
|
||||||
|
use Garradin\Plugin\Materiels\Location;
|
||||||
|
use Garradin\Utils;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../_inc.php';
|
||||||
|
|
||||||
|
$loc = new Location;
|
||||||
|
|
||||||
|
$l = $loc->get((int) qg('id'));
|
||||||
|
|
||||||
|
if (!$l) {
|
||||||
|
throw new UserException("Cette localisation n'existe pas.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$tpl->assign(compact('l'));
|
||||||
|
|
||||||
|
$tpl->display(PLUGIN_ROOT . '/templates/localisations/materiels_par_localisation.tpl');
|
44
src/www/admin/localisations/modifier_localisation.php
Normal file
44
src/www/admin/localisations/modifier_localisation.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Garradin;
|
||||||
|
use Garradin\Plugin\Materiels\Location;
|
||||||
|
use Garradin\Utils;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../_inc.php';
|
||||||
|
|
||||||
|
$loc = new Location;
|
||||||
|
|
||||||
|
$l = $loc->get((int) qg('id'));
|
||||||
|
|
||||||
|
if (!$l) {
|
||||||
|
throw new UserException("Cette localisation n'existe pas.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$csrf_key = 'edit_location_' . $l->id;
|
||||||
|
|
||||||
|
if (f('save') && $form->check($csrf_key) && !$form->hasErrors())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$loc->edit($l->id, [
|
||||||
|
'name' => ucfirst(f('name'))
|
||||||
|
]);
|
||||||
|
Utils::redirect(PLUGIN_URL . 'localisations/index.php');
|
||||||
|
}
|
||||||
|
catch (\RuntimeException $e)
|
||||||
|
{
|
||||||
|
if (strstr($e->getMessage(), 'UNIQUE constraint failed'))
|
||||||
|
{
|
||||||
|
$form->addError('Cette localisation existe déjà.');
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
$form->addError($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$cancel_link = PLUGIN_URL . 'localisations/index.php';
|
||||||
|
|
||||||
|
$tpl->assign(compact('l', 'csrf_key', 'cancel_link'));
|
||||||
|
|
||||||
|
$tpl->display(PLUGIN_ROOT . '/templates/localisations/modifier_localisation.tpl');
|
36
src/www/admin/localisations/supprimer_localisation.php
Normal file
36
src/www/admin/localisations/supprimer_localisation.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Garradin;
|
||||||
|
use Garradin\Plugin\Materiels\Location;
|
||||||
|
use Garradin\Utils;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../_inc.php';
|
||||||
|
|
||||||
|
$loc = new Location;
|
||||||
|
|
||||||
|
$l = $loc->get((int) qg('id'));
|
||||||
|
|
||||||
|
if (!$l) {
|
||||||
|
throw new UserException("Cette localisation n'existe pas.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$csrf_key = 'delete_location_' . $l->id;
|
||||||
|
|
||||||
|
if (f('delete') && $form->check($csrf_key) && !$form->hasErrors())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$loc->delete($l->id);
|
||||||
|
Utils::redirect(PLUGIN_URL . 'localisations/index.php');
|
||||||
|
}
|
||||||
|
catch (\RuntimeException $e)
|
||||||
|
{
|
||||||
|
$form->addError($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$cancel_link = PLUGIN_URL . 'localisations/index.php';
|
||||||
|
|
||||||
|
$tpl->assign(compact('l', 'csrf_key', 'cancel_link'));
|
||||||
|
|
||||||
|
$tpl->display(PLUGIN_ROOT . '/templates/localisations/supprimer_localisation.tpl');
|
Loading…
Reference in New Issue
Block a user