adaptation à la nouvelle gestion de la config
FossilOrigin-Name: 8021f28f6ba17ffafbb4a1e5ffb4cb8486c3b585a486afd6a24f61db0b64841c
This commit is contained in:
parent
b2885f3c01
commit
fcac139b89
7 changed files with 125 additions and 110 deletions
188
admin/config.php
188
admin/config.php
|
|
@ -7,114 +7,116 @@ use Paheko\Entities\Files\File;
|
|||
use Paheko\Plugin\RecusFiscaux\Utils;
|
||||
|
||||
$session->requireAccess($session::SECTION_CONFIG, $session::ACCESS_ADMIN);
|
||||
$art_sel = f('articlesCGI') ?: [];
|
||||
$taux_sel = f('tauxReduction') ?: [];
|
||||
$noms_sel = f('champsNom') ?: [];
|
||||
|
||||
// récupérer les champs des noms
|
||||
$champsNom = Utils::getChampsNom($config, $plugin);
|
||||
|
||||
if (f('save') && $form->check('recusfiscaux_config')) {
|
||||
try {
|
||||
// objet de l'association
|
||||
if ($plugin->getConfig('objet_asso') != trim(f('objet_asso'))) {
|
||||
$plugin->setConfig('objet_asso', trim(f('objet_asso')));
|
||||
}
|
||||
$csrf_key = 'recusfiscaux_config';
|
||||
|
||||
// articles du CGI
|
||||
$confArticles = $plugin->getConfig('articlesCGI');
|
||||
// effacer l'ancienne configuration
|
||||
for ($i = 0; $i < count($confArticles); ++$i) {
|
||||
$confArticles[$i]->valeur = false; // 0
|
||||
}
|
||||
// et copier la nouvelle
|
||||
foreach ($art_sel as $article) {
|
||||
$confArticles[$article]->valeur = true; // 1
|
||||
}
|
||||
$plugin->setConfig("articlesCGI", $confArticles);
|
||||
$form->runIf('save', function () use ($plugin, $champsNom) {
|
||||
// Objet de l'asso
|
||||
$plugin->setConfigProperty('objet_asso', trim(f('objet_asso')));
|
||||
|
||||
// taux de réduction
|
||||
$confTaux = $plugin->getConfig('reduction');
|
||||
// effacer l'ancienne configuration
|
||||
for ($i = 0; $i < count($confTaux); ++$i) {
|
||||
$confTaux[$i]->valeur = false; // 0
|
||||
}
|
||||
// et copier la nouvelle
|
||||
foreach ($taux_sel as $taux) {
|
||||
$confTaux[$taux]->valeur = true; // 1
|
||||
}
|
||||
$plugin->setConfig("reduction", $confTaux);
|
||||
|
||||
// Informations au sujet du responsable
|
||||
if ($plugin->getConfig('nom_responsable') != trim(f('nom_responsable'))) {
|
||||
$plugin->setConfig('nom_responsable', trim(f('nom_responsable')));
|
||||
}
|
||||
if ($plugin->getConfig('fonction_responsable') != trim(f('fonction_responsable'))) {
|
||||
$plugin->setConfig('fonction_responsable', trim(f('fonction_responsable')));
|
||||
}
|
||||
// ville
|
||||
if ($plugin->getConfig('ville_asso') != trim(f('ville_asso'))) {
|
||||
$plugin->setConfig('ville_asso', trim(f('ville_asso')));
|
||||
}
|
||||
// signature
|
||||
|
||||
if (isset($_SESSION['sig_file']) && count($_SESSION['sig_file']) > 0) {
|
||||
// supprimer la signature précédente, si besoin
|
||||
if (
|
||||
null !== $plugin->getConfig('signature') &&
|
||||
$plugin->getConfig('signature') != $_SESSION['sig_file'][0]->path
|
||||
) {
|
||||
$sig_file = \Paheko\Files\Files::get($plugin->getConfig('signature'));
|
||||
if (null !== $sig_file) {
|
||||
$sig_file->delete();
|
||||
}
|
||||
}
|
||||
// puis installer la nouvelle
|
||||
$plugin->setConfig('signature', $_SESSION['sig_file'][0]->path);
|
||||
}
|
||||
|
||||
// autres informations
|
||||
// numérotation des reçus
|
||||
$configNum = $plugin->getConfig('numerotation');
|
||||
$formNum = clone $configNum;
|
||||
if ($configNum->prefixe != trim(f('prefixe'))) {
|
||||
$formNum->prefixe = trim(f('prefixe'));
|
||||
}
|
||||
$formNum->annee = f('annee');
|
||||
$formNum->membre = f('membre');
|
||||
$formNum->sequentiel = f('sequentiel');
|
||||
$formNum->valeur_init = f('valeur_init');
|
||||
$plugin->setConfig('numerotation', $formNum);
|
||||
|
||||
// impression des adresses de courriel
|
||||
$plugin->setConfig('imprimerCourriel', f('imprimerCourriel'));
|
||||
|
||||
// champs pour le nom et prénom
|
||||
foreach ($champsNom as $nom => $champ) {
|
||||
$champ->position = 0;
|
||||
}
|
||||
$i = -count($noms_sel);
|
||||
foreach ($noms_sel as $nom) {
|
||||
$champsNom[$nom]->position = $i++;
|
||||
}
|
||||
$plugin->setConfig('champsNom', $champsNom);
|
||||
|
||||
\Paheko\Utils::redirect(PLUGIN_URL . 'config.php?ok');
|
||||
} catch (UserException $e) {
|
||||
$form->addError($e->getMessage());
|
||||
// Articles du CGI
|
||||
$confArticles = $plugin->getConfig('articlesCGI');
|
||||
// effacer l'ancienne configuration
|
||||
for ($i = 0; $i < count($confArticles); ++$i) {
|
||||
$confArticles[$i]->valeur = false;
|
||||
}
|
||||
}
|
||||
// et copier la nouvelle
|
||||
$art_sel = f('articlesCGI') ?: [];
|
||||
foreach ($art_sel as $article) {
|
||||
$confArticles[$article]->valeur = true;
|
||||
}
|
||||
$plugin->setConfigProperty('articlesCGI', $confArticles);
|
||||
|
||||
// Taux de réduction
|
||||
$confTaux = $plugin->getConfig('reduction');
|
||||
// effacer l'ancienne configuration
|
||||
for ($i = 0; $i < count($confTaux); ++$i) {
|
||||
$confTaux[$i]->valeur = false;
|
||||
}
|
||||
// et copier la nouvelle
|
||||
$taux_sel = f('tauxReduction') ?: [];
|
||||
foreach ($taux_sel as $taux) {
|
||||
$confTaux[$taux]->valeur = true;
|
||||
}
|
||||
$plugin->setConfigProperty("reduction", $confTaux);
|
||||
|
||||
// Informations au sujet du responsable
|
||||
$plugin->setConfigProperty('nom_responsable', trim(f('nom_responsable') ?: '') ?: null);
|
||||
$plugin->setConfigProperty('fonction_responsable', trim(f('fonction_responsable') ?: '') ?: null);
|
||||
$plugin->setConfigProperty('ville_asso', trim(f('ville_asso') ?: '') ?: null);
|
||||
|
||||
// signature
|
||||
if (isset($_SESSION['sig_file']) && count($_SESSION['sig_file']) > 0) {
|
||||
// supprimer la signature précédente, si besoin
|
||||
if (
|
||||
null !== $plugin->getConfig('signature')
|
||||
&&
|
||||
$plugin->getConfig('signature') != $_SESSION['sig_file'][0]->path
|
||||
) {
|
||||
$sig_file = \Paheko\Files\Files::get($plugin->getConfig('signature'));
|
||||
if (null !== $sig_file) {
|
||||
$sig_file->delete();
|
||||
}
|
||||
}
|
||||
// puis installer la nouvelle
|
||||
$plugin->setConfigProperty('signature', $_SESSION['sig_file'][0]->path);
|
||||
}
|
||||
|
||||
// Numérotation des reçus
|
||||
$configNum = $plugin->getConfig('numerotation');
|
||||
$formNum = clone $configNum;
|
||||
if ($configNum->prefixe != trim(f('prefixe'))) {
|
||||
$formNum->prefixe = trim(f('prefixe'));
|
||||
}
|
||||
$formNum->annee = f('annee');
|
||||
$formNum->membre = f('membre');
|
||||
$formNum->sequentiel = f('sequentiel');
|
||||
$formNum->valeur_init = f('valeur_init');
|
||||
$plugin->setConfigProperty('numerotation', $formNum);
|
||||
|
||||
// Impression des adresses de courriel
|
||||
$plugin->setConfigProperty('imprimerCourriel', trim(f('imprimerCourriel') ?: '') ?: null);
|
||||
|
||||
// champs pour le nom et prénom
|
||||
foreach ($champsNom as $nom => $champ) {
|
||||
$champ->position = 0;
|
||||
}
|
||||
$noms_sel = f('champsNom') ?: [];
|
||||
$i = -count($noms_sel);
|
||||
foreach ($noms_sel as $nom) {
|
||||
$champsNom[$nom]->position = $i++;
|
||||
}
|
||||
$plugin->setConfigProperty('champsNom', $champsNom);
|
||||
|
||||
// enregistrer la nouvelle config
|
||||
$plugin->save();
|
||||
}, $csrf_key, PLUGIN_ADMIN_URL . 'config.php?ok');
|
||||
|
||||
|
||||
// test fonctions fichiers : voir files.sor
|
||||
// $fichiers = Files::list('config');
|
||||
// error_log("fichiers config = " . print_r($fichiers, true));
|
||||
// $fichiers = Files::list('ext/recusfiscaux');
|
||||
// error_log("fichiers ext/recusfiscaux = " . print_r($fichiers, true));
|
||||
$sig_file = Files::get('ext/recusfiscaux/default_signature.png');
|
||||
// error_log("sig_file = " . print_r($sig_file, true));
|
||||
|
||||
//error_log("config.php::config=" . print_r($plugin->getConfig(), true));
|
||||
|
||||
|
||||
// trier les champs de nom pour l'affichage
|
||||
uasort($champsNom, function ($a, $b) {
|
||||
return $a->position - $b->position;
|
||||
});
|
||||
|
||||
$tpl->assign('ok', qg('ok') !== null);
|
||||
$path = qg('path') ?: File::CONTEXT_CONFIG;
|
||||
$tpl->assign('default_signature', \Paheko\WWW_URL . "plugin/recusfiscaux/default_signature.png");
|
||||
$tpl->assign('default_signature', '/' . 'ext/recusfiscaux/default_signature.png');
|
||||
// $tpl->assign('default_signature', \Paheko\WWW_URL . "plugin/recusfiscaux/default_signature.png");
|
||||
$tpl->assign('plugin_config', $plugin->getConfig());
|
||||
$tpl->assign('plugin_css', ['style.css']);
|
||||
$tpl->assign('numerotation', $plugin->getConfig('numerotation'));
|
||||
$tpl->assign(compact('path', 'champsNom'));
|
||||
$tpl->assign(compact('csrf_key', 'path', 'champsNom'));
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/config.tpl');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue