4 * Dependency injection configuration
8 * Copyright © 2003-2018 The Galette Team
10 * This file is part of Galette (http://galette.tuxfamily.org).
12 * Galette is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * Galette is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
28 * @author Frédéric Jacquot <unknown@unknow.com>
29 * @author Georges Khaznadar (password encryption, images) <unknown@unknow.com>
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2003-2018 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @link http://galette.tuxfamily.org
36 use Galette\Entity\PdfModel
;
37 use Slim\Event\SlimEventManager
;
38 use Slim\Views\SmartyPlugins
;
40 $container = $app->getContainer();
42 // -----------------------------------------------------------------------------
44 // -----------------------------------------------------------------------------
46 $container['errorHandler'] = function ($c) {
47 return new Galette\Handlers\
Error($c['view'], true);
50 $container['phpErrorHandler'] = function ($c) {
51 return new Galette\Handlers\
PhpError($c['view'], true);
54 $container['notFoundHandler'] = function ($c) {
55 return new Galette\Handlers\
NotFound($c['view']);
58 // -----------------------------------------------------------------------------
60 // -----------------------------------------------------------------------------
62 // Register Smarty View helper
63 $container['view'] = function ($c) {
64 $view = new \Slim\Views\
Smarty(
65 rtrim(GALETTE_ROOT
. GALETTE_TPL_SUBDIR
, DIRECTORY_SEPARATOR
),
67 'cacheDir' => rtrim(GALETTE_CACHE_DIR
, DIRECTORY_SEPARATOR
),
68 'compileDir' => rtrim(GALETTE_COMPILE_DIR
, DIRECTORY_SEPARATOR
),
70 GALETTE_ROOT
. 'includes/smarty_plugins'
75 // Add Slim specific plugins
76 $basepath = str_replace(
79 $c->get('request')->getUri()->getBasePath()
81 $smartyPlugins = new SmartyPlugins($c['router'], $basepath);
82 $view->registerPlugin('function', 'path_for', [$smartyPlugins, 'pathFor']);
83 $view->registerPlugin('function', 'base_url', [$smartyPlugins, 'baseUrl']);
85 $smarty = $view->getSmarty();
86 $smarty->inheritance_merge_compiled_includes
= false;
88 $smarty->assign('flash', $c->get('flash'));
90 $smarty->assign('login', $c->get('login'));
91 $smarty->assign('logo', $c->get('logo'));
92 $smarty->assign('tpl', $smarty);
93 $smarty->assign('headers', $c->get('plugins')->getTplHeaders());
94 $smarty->assign('plugin_actions', $c->get('plugins')->getTplAdhActions());
96 'plugin_batch_actions',
97 $c->get('plugins')->getTplAdhBatchActions()
100 'plugin_detailled_actions',
101 $c->get('plugins')->getTplAdhDetailledActions()
103 $smarty->assign('scripts_dir', 'js/');
104 $smarty->assign('jquery_dir', 'js/jquery/');
105 $smarty->assign('jquery_markitup_version', JQUERY_MARKITUP_VERSION
);
106 $smarty->assign('PAGENAME', basename($_SERVER['SCRIPT_NAME']));
107 $smarty->assign('galette_base_path', './');
108 $smarty->assign('GALETTE_VERSION', GALETTE_VERSION
);
109 $smarty->assign('GALETTE_MODE', GALETTE_MODE
);
110 $smarty->assign('GALETTE_DISPLAY_ERRORS', GALETTE_DISPLAY_ERRORS
);
111 $smarty->assign('_CURRENT_THEME_PATH', _CURRENT_THEME_PATH
);
113 /*if ($this->parserConfigDir) {
114 $instance->setConfigDir($this->parserConfigDir);
117 $smarty->assign('template_subdir', GALETTE_THEME
);
118 foreach ($c->get('plugins')->getTplAssignments() as $k => $v) {
119 $smarty->assign($k, $v);
121 /** galette_lang should be removed and languages used instead */
122 $smarty->assign('galette_lang', $c->get('i18n')->getAbbrev());
123 $smarty->assign('galette_lang_name', $c->get('i18n')->getName());
124 $smarty->assign('languages', $c->get('i18n')->getList());
125 $smarty->assign('i18n', $c->get('i18n'));
126 $smarty->assign('plugins', $c->get('plugins'));
127 $smarty->assign('preferences', $c->get('preferences'));
128 $smarty->assign('pref_slogan', $c->get('preferences')->pref_slogan
);
129 $smarty->assign('pref_theme', $c->get('preferences')->pref_theme
);
130 $smarty->assign('pref_statut', $c->get('preferences')->pref_statut
);
132 'pref_editor_enabled',
133 $c->preferences
->pref_editor_enabled
135 $smarty->assign('pref_mail_method', $c->get('preferences')->pref_mail_method
);
136 $smarty->assign('existing_mailing', $c->get('session')->mailing
!== null);
137 $smarty->assign('contentcls', null);
138 $smarty->assign('additionnal_html_class', null);
139 $smarty->assign('head_redirect', null);
140 $smarty->assign('error_detected', null);
141 $smarty->assign('warning_detected', null);
142 $smarty->assign('success_detected', null);
143 $smarty->assign('require_tree', null);
144 $smarty->assign('html_editor', null);
145 $smarty->assign('require_charts', null);
146 $smarty->assign('require_mass', null);
147 $smarty->assign('autocomplete', null);
148 if ($c->get('login')->isAdmin() && $c->get('preferences')->pref_telemetry_date
) {
149 $now = new \
DateTime();
150 $sent = new \
DateTime($c->get('preferences')->pref_telemetry_date
);
151 $sent->add(new \
DateInterval('P1Y')); // ask to resend telemetry after one year
152 if ($now > $sent && !$_COOKIE['renew_telemetry']) {
153 $smarty->assign('renew_telemetry', true);
157 foreach ($c->get('plugins')->getModules() as $module_id => $module) {
158 $smarty->addTemplateDir(
159 $module['root'] . '/templates/' . $c->get('preferences')->pref_theme
,
167 $container['flash'] = function ($c) {
168 return new \Slim\Flash\
Messages();
171 $container['plugins'] = function ($c) {
172 $plugins = new Galette\Core\
Plugins();
173 $i18n = $c->get('i18n');
174 $plugins->loadModules($c->get('preferences'), GALETTE_PLUGINS_PATH
, $i18n->getLongID());
178 $container['i18n'] = function ($c) {
179 $i18n = $c->get('session')->i18n
;
180 if (!$i18n ||
!$i18n->getId() ||
isset($_GET['ui_pref_lang']) && $_GET['ui_pref_lang']) {
181 $i18n = new Galette\Core\
I18n($_GET['ui_pref_lang'] ??
false);
182 $c->get('session')->i18n
= $i18n;
187 $container['zdb'] = function ($c) {
188 $zdb = new Galette\Core\
Db();
192 $container['preferences'] = function ($c) {
193 return new Galette\Core\
Preferences($c->get('zdb'));
196 $container['login'] = function ($c) {
197 $login = $c->get('session')->login
;
199 $login = new Galette\Core\
Login(
208 $container['session'] = function ($c) {
209 $session = new \RKA\
Session();
213 $container['logo'] = function ($c) {
214 return new Galette\Core\
Logo();
217 $container['print_logo'] = function ($c) {
218 return new Galette\Core\
PrintLogo();
222 $container['history'] = function ($c) {
223 return new Galette\Core\
History($c->get('zdb'), $c->get('login'));
226 $container['acls'] = function ($c) {
227 include_once GALETTE_ROOT
. 'includes/core_acls.php';
230 foreach ($c->get('plugins')->getModules() as $plugin) {
231 $acls[$plugin['route'] . 'Info'] = 'member';
234 //use + to be sure core ACLs are not overrided by plugins ones.
235 $acls = $acls +
$c->get('plugins')->getAcls();
237 //load user defined ACLs
238 if (file_exists(GALETTE_CONFIG_PATH
. 'local_acls.inc.php')) {
239 //use array_merge here, we want $local_acls to override core ones.
240 $acls = array_merge($acls, $local_acls);
246 $container['members_fields'] = function ($c) {
247 include_once GALETTE_ROOT
. 'includes/fields_defs/members_fields.php';
248 return $members_fields;
251 $container['members_form_fields'] = function ($c) {
252 $fields = $c->get('members_fields');
253 foreach ($fields as $k => $field) {
254 if ($field['position'] == -1) {
262 $container['members_fields_cats'] = function ($c) {
263 include_once GALETTE_ROOT
. 'includes/fields_defs/members_fields_cats.php';
264 return $members_fields_cats;
267 $container['pdfmodels_fields'] = function ($c) {
268 //include_once GALETTE_ROOT . 'includes/fields_defs/pdfmodels_fields.php';
269 $pdfmodels_fields = array(
271 'model_id' => PdfModel
::MAIN_MODEL
,
272 'model_name' => '_T("Main")',
273 'model_title' => null,
274 'model_type' => PdfModel
::MAIN_MODEL
,
275 'model_header' => '<table>
277 <td id="pdf_assoname"><strong id="asso_name">{ASSO_NAME}</strong><br/>{ASSO_SLOGAN}</td>
278 <td id="pdf_logo">{ASSO_LOGO}</td>
281 'model_footer' => '<div id="pdf_footer">
282 _T("Association") {ASSO_NAME} - {ASSO_ADDRESS}<br/>
285 'model_body' => null,
286 'model_styles' => 'div#pdf_title {
314 'model_parent' => null
317 'model_id' => PdfModel
::INVOICE_MODEL
,
318 'model_name' => '_T("Invoice")',
319 'model_title' => '_T("Invoice") {CONTRIBUTION_YEAR}-{CONTRIBUTION_ID}',
320 'model_type' => PdfModel
::INVOICE_MODEL
,
321 'model_header' => null,
322 'model_footer' => null,
323 'model_body' => '<table>
325 <td width="300"></td>
326 <td><strong>{NAME_ADH}</strong><br/>
328 <strong>{ZIP_ADH} {TOWN_ADH}</strong>
332 <td height="100"></td>
340 <th>_T("Amount")</th>
346 {CONTRIBUTION_LABEL} (_T("on") {CONTRIBUTION_DATE})<br/>
347 _T("from") {CONTRIBUTION_BEGIN_DATE} _T("to") {CONTRIBUTION_END_DATE}<br/>
348 {CONTRIBUTION_PAYMENT_TYPE}<br/>
349 {CONTRIBUTION_COMMENT}
351 <td>{CONTRIBUTION_AMOUNT}</td>
358 'model_styles' => null,
359 'model_parent' => PdfModel
::MAIN_MODEL
362 'model_id' => PdfModel
::RECEIPT_MODEL
,
363 'model_name' => '_T("Receipt")',
364 'model_title' => '_T("Receipt") {CONTRIBUTION_YEAR}-{CONTRIBUTION_ID}',
365 'model_type' => PdfModel
::RECEIPT_MODEL
,
366 'model_header' => null,
367 'model_footer' => null,
368 'model_body' => '<table>
370 <td width="300"></td>
371 <td><strong>{NAME_ADH}</strong><br/>
373 <strong>{ZIP_ADH} {TOWN_ADH}</strong>
377 <td height="100"></td>
385 <th>_T("Amount")</th>
391 {CONTRIBUTION_LABEL} (_T("on") {CONTRIBUTION_DATE})<br/>
392 _T("from") {CONTRIBUTION_BEGIN_DATE} _T("to") {CONTRIBUTION_END_DATE}<br/>
393 {CONTRIBUTION_PAYMENT_TYPE}<br/>
394 {CONTRIBUTION_COMMENT}
396 <td>{CONTRIBUTION_AMOUNT}</td>
403 'model_styles' => null,
404 'model_parent' => PdfModel
::MAIN_MODEL
407 'model_id' => PdfModel
::ADHESION_FORM_MODEL
,
408 'model_name' => '_T("Adhesion form")',
409 'model_title' => '_T("Adhesion form")',
410 'model_type' => PdfModel
::ADHESION_FORM_MODEL
,
411 'model_header' => null,
412 'model_footer' => null,
413 'model_body' => '<hr/>
414 <div class="infos">_T("Complete the following form and send it with your funds, in order to complete your subscription.")</div>
417 <td width="50%"></td>
418 <td width="50%">{ASSO_ADDRESS_MULTI}</td>
424 <td height="30"></td>
427 <td>_T("Required membership:")
429 <input type="radio" class="box" name="cotisation" value="none1">_T("Active member")
430 <input type="radio" class="box" name="cotisation" value="none2">_T("Benefactor member")
431 <input type="radio" class="box" name="cotisation" value="none3">_T("Donation")
432 <div class="infos">_T("The minimum contribution for each type of membership are defined on the website of the association. The amount of donations are free to be decided by the generous donor.") </div>
437 <td height="30"></td>
440 <table class="member">
442 <td class="label">_T("Politeness")</td>
443 <td class="input">{TITLE_ADH}</td>
446 <td class="label">_T("Name")</td>
447 <td class="input">{LAST_NAME_ADH}</td>
450 <td class="label">_T("First name")</td>
451 <td class="input">{FIRST_NAME_ADH}</td>
454 <td class="label">_T("Company name") *</td>
455 <td class="input">{COMPANY_ADH}</td>
458 <td class="label">_T("Address")</td>
459 <td class="input">{ADDRESS_ADH}</td>
462 <td class="label"></td>
463 <td class="input"></td>
466 <td class="label"></td>
467 <td class="input"></td>
470 <td class="label">_T("Zip Code")</td>
471 <td class="cpinput">{ZIP_ADH}</td>
472 <td class="label">_T("City")</td>
473 <td class="towninput">{TOWN_ADH}</td>
476 <td class="label">_T("Country")</td>
477 <td class="input">{COUNTRY_ADH}</td>
480 <td class="label">_T("Email address")</td>
481 <td class="input">{EMAIL_ADH}</td>
484 <td class="label">_T("Username") **</td>
485 <td class="input">{LOGIN_ADH}</td>
488 <td colspan="2" height="10"></td>
491 <td class="label">_T("Amount")</td>
492 <td class="input"></td>
495 <p>str_replace(\'%s\', \'{ASSO_NAME}\', \'_T("Hereby, I agree to comply to %s association statutes and its rules.")\')</p><p>_T("At ................................................")</p><p>_T("On .......... / .......... / .......... ")</p><p>_T("Signature")</p>
496 <p class="notes">_T("* Only for compagnies")<br/>_T("** Galette identifier, if applicable")</p>',
497 'model_styles' => 'td.label {
503 border-bottom: 1px dotted black;
508 border-bottom: 1px dotted black;
513 border-bottom: 1px dotted black;
529 'model_parent' => PdfModel
::MAIN_MODEL
532 return $pdfmodels_fields;
535 // -----------------------------------------------------------------------------
537 // -----------------------------------------------------------------------------
540 $container['logger'] = function ($c) {
541 $settings = $c->get('settings');
542 $logger = new \Monolog\
Logger($settings['logger']['name']);
543 $logger->pushProcessor(new \Monolog\Processor\
UidProcessor());
544 $logger->pushHandler(new \Monolog\Handler\
StreamHandler($settings['logger']['path'], $settings['logger']['level']));
548 $container['fields_config'] = function ($c) {
549 $fc = new Galette\Entity\
FieldsConfig(
551 Galette\Entity\Adherent
::TABLE
,
552 $c->get('members_fields'),
553 $c->get('members_fields_cats')
558 $container['lists_config'] = function ($c) {
559 $fc = new Galette\Entity\
ListsConfig(
561 Galette\Entity\Adherent
::TABLE
,
562 $c->get('members_fields'),
563 $c->get('members_fields_cats')
568 $container['cache'] = function ($c) {
570 if (function_exists('wincache_ucache_add')) {
571 //since APCu is not known to work on windows
572 $adapter = 'wincache';
573 } elseif (function_exists('apcu_fetch')) {
576 if ($adapter !== null) {
577 $uuid = $c->get('mode') !== 'INSTALL' ?
$c->get('preferences')->pref_instance_uuid
: '_install';
578 $cache = Laminas\Cache\StorageFactory
::factory([
579 'adapter' => $adapter,
581 'namespace' => str_replace(
582 ['%version', '%uuid'],
583 [GALETTE_VERSION
, $uuid],
584 'galette_%version_%uuid'
593 $container['translator'] = function ($c) {
594 $translator = new Galette\Core\
Translator();
596 $domains = ['galette'];
597 foreach ($domains as $domain) {
598 //load translation file for domain
599 $translator->addTranslationFilePattern(
601 GALETTE_ROOT
. '/lang/',
602 '/%s/LC_MESSAGES/' . $domain . '.mo',
606 //check if a local lang file exists and load it
607 $translator->addTranslationFilePattern(
609 GALETTE_ROOT
. '/lang/',
610 $domain . '_%s_local_lang.php',
615 $translator->setLocale($c->get('i18n')->getLongID());
616 if (!isset($container['mode']) ||
$c->get('mode') !== 'INSTALL' && $c->get('mode') !== 'NEED_UPDATE') {
617 $translator->setCache($c->get('cache'));
622 // Add Event manager to dependency.
623 $container['event_manager'] = function ($c) {
624 $emitter = new SlimEventManager();
628 //For bad existing globals can be used...
629 if (!isset($container['mode']) ||
$container['mode'] !== 'INSTALL' && $container['mode'] !== 'NEED_UPDATE') {
630 $zdb = $container->get('zdb');
631 $preferences = $container->get('preferences');
632 $login = $container->get('login');
633 $hist = $container->get('history');
635 $i18n = $container->get('i18n');
636 $translator = $container->get('translator');
637 $emitter = $container->get('event_manager');
639 require_once GALETTE_ROOT
. 'includes/i18n.inc.php';