diff --git a/templates/_form.tpl b/templates/_form.tpl
new file mode 100644
index 0000000..e557e2f
--- /dev/null
+++ b/templates/_form.tpl
@@ -0,0 +1,221 @@
+{form_errors}
+
+
+
+{include file="%s/templates/_js.tpl"|args:$plugin_root}
diff --git a/templates/facture_ajouter.tpl b/templates/facture_ajouter.tpl
index 9aa9471..6e6ae58 100644
--- a/templates/facture_ajouter.tpl
+++ b/templates/facture_ajouter.tpl
@@ -1,232 +1,7 @@
{include file="admin/_head.tpl" title="Créer un document — %s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id js=1}
{include file="%s/templates/_menu.tpl"|args:$plugin_root current="facture"}
-{form_errors}
-
-
+{include file="%s/templates/_form.tpl"|args:$plugin_root}
{include file="%s/templates/_js.tpl"|args:$plugin_root}
diff --git a/templates/facture_modifier.tpl b/templates/facture_modifier.tpl
index 195753d..a738782 100644
--- a/templates/facture_modifier.tpl
+++ b/templates/facture_modifier.tpl
@@ -1,226 +1,6 @@
{include file="admin/_head.tpl" title="Modifier un document — %s"|args:$plugin.nom current="plugin_%s"|args:$plugin.id js=1}
{include file="%s/templates/_menu.tpl"|args:$plugin_root current="index"}
-{form_errors}
-
-
-
-{include file="%s/templates/_js.tpl"|args:$plugin_root}
+{include file="%s/templates/_form.tpl"|args:$plugin_root}
{include file="admin/_foot.tpl"}
diff --git a/www/admin/facture_ajouter.php b/www/admin/facture_ajouter.php
index 903d6f3..880d2a0 100644
--- a/www/admin/facture_ajouter.php
+++ b/www/admin/facture_ajouter.php
@@ -14,14 +14,19 @@ $db = DB::getInstance();
$step = $radio = false;
$liste = [];
+$csrf_key = 'ajout_facture';
$fields = $facture->recu_fields;
-$tpl->assign('moyens_paiement', $facture->listMoyensPaiement());
+$moyens_paiement = $facture->listMoyensPaiement(true);
+
+$doc = null;
+
+$tpl->assign('moyens_paiement', $moyens_paiement);
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES');
if (f('add'))
{
- $form->check('ajout_facture', [
+ $form->check($csrf_key, [
'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]),
'numero_facture' => 'required|string',
'date_emission' => 'required|date_format:d/m/Y',
@@ -31,7 +36,7 @@ if (f('add'))
'base_receveur' => 'required|in:membre,client',
// 'client' => '',
// 'membre' => '',
- 'moyen_paiement' => 'required|in:' . implode(',', array_keys($facture->listMoyensPaiement())),
+ 'moyen_paiement' => 'required|in:' . implode(',', array_keys($moyens_paiement)),
'designation' => 'array|required',
'prix' => 'array|required'
]);
@@ -214,7 +219,7 @@ $date = new \DateTime;
$date->setTimestamp(time());
$tpl->assign('date', $date->format('d/m/Y'));
-$tpl->assign(compact('designations', 'prix', 'from_user', 'identite'));
+$tpl->assign(compact('designations', 'prix', 'from_user', 'identite', 'csrf_key', 'doc'));
$tpl->assign('membres', $db->getAssoc('SELECT id, '.$identite.' FROM membres WHERE id_category != -2 NOT IN (SELECT id FROM users_categories WHERE hidden = 1);'));
$tpl->assign('clients', $db->getAssoc('SELECT id, nom FROM plugin_facturation_clients;'));
diff --git a/www/admin/facture_modifier.php b/www/admin/facture_modifier.php
index 013be9e..b0d34f6 100644
--- a/www/admin/facture_modifier.php
+++ b/www/admin/facture_modifier.php
@@ -13,9 +13,9 @@ $db = DB::getInstance();
$step = false;
$liste = [];
-$fields = $facture->recu_fields;
+$moyens_paiement = $facture->listMoyensPaiement(true);
-$tpl->assign('moyens_paiement', $facture->listMoyensPaiement());
+$tpl->assign('moyens_paiement', $moyens_paiement);
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES');
qv(['id' => 'required|numeric']);
@@ -26,11 +26,13 @@ if (!$f = $facture->get($id))
throw new UserException("Ce document n'existe pas.");
}
+$csrf_key = 'modifier_facture';
+
// Traitement
if(f('save'))
{
- $form->check('modifier_facture', [
+ $form->check($csrf_key, [
'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]),
'numero_facture' => 'required|string',
'date_emission' => 'required|date_format:d/m/Y',
@@ -40,7 +42,7 @@ if(f('save'))
'base_receveur' => 'required|in:membre,client',
// 'client' => '',
// 'membre' => '',
- 'moyen_paiement' => 'required|in:' . implode(',', array_keys($facture->listMoyensPaiement())),
+ 'moyen_paiement' => 'required|in:' . implode(',', array_keys($moyens_paiement)),
'designation' => 'array|required',
'prix' => 'array|required'
]);
@@ -193,7 +195,6 @@ if ($step)
// Affichage
-$doc['moyens_paiement'] = $facture->listMoyensPaiement(true);
// $doc['moyen_paiement'] = $doc['moyens_paiement'][$f->moyen_paiement];
$doc['moyen_paiement'] = $f->moyen_paiement;
$doc['type'] = $f->type_facture;
@@ -253,7 +254,7 @@ if ($f->type_facture != COTIS)
}
-$tpl->assign(compact('designations', 'prix', 'from_user', 'identite'));
+$tpl->assign(compact('designations', 'prix', 'from_user', 'identite', 'csrf_key'));
$tpl->assign('membres', $db->getAssoc('SELECT id, '.$identite.' FROM membres WHERE id_category != -2 NOT IN (SELECT id FROM users_categories WHERE hidden = 1);'));
$tpl->assign('clients', $db->getAssoc('SELECT id, nom FROM plugin_facturation_clients;'));