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['l10n'] = function ($c) {
188 $l10n = new Galette\Core\
L10n(
195 $container['zdb'] = function ($c) {
196 $zdb = new Galette\Core\
Db();
200 $container['preferences'] = function ($c) {
201 return new Galette\Core\
Preferences($c->get('zdb'));
204 $container['login'] = function ($c) {
205 $login = $c->get('session')->login
;
207 $login = new Galette\Core\
Login(
216 $container['session'] = function ($c) {
217 $session = new \RKA\
Session();
221 $container['logo'] = function ($c) {
222 return new Galette\Core\
Logo();
225 $container['print_logo'] = function ($c) {
226 return new Galette\Core\
PrintLogo();
230 $container['history'] = function ($c) {
231 return new Galette\Core\
History($c->get('zdb'), $c->get('login'));
234 $container['acls'] = function ($c) {
235 include_once GALETTE_ROOT
. 'includes/core_acls.php';
238 foreach ($c->get('plugins')->getModules() as $plugin) {
239 $acls[$plugin['route'] . 'Info'] = 'member';
242 //use + to be sure core ACLs are not overrided by plugins ones.
243 $acls = $acls +
$c->get('plugins')->getAcls();
245 //load user defined ACLs
246 if (file_exists(GALETTE_CONFIG_PATH
. 'local_acls.inc.php')) {
247 //use array_merge here, we want $local_acls to override core ones.
248 $acls = array_merge($acls, $local_acls);
254 $container['members_fields'] = function ($c) {
255 include_once GALETTE_ROOT
. 'includes/fields_defs/members_fields.php';
256 return $members_fields;
259 $container['members_form_fields'] = function ($c) {
260 $fields = $c->get('members_fields');
261 foreach ($fields as $k => $field) {
262 if ($field['position'] == -1) {
270 $container['members_fields_cats'] = function ($c) {
271 include_once GALETTE_ROOT
. 'includes/fields_defs/members_fields_cats.php';
272 return $members_fields_cats;
275 $container['pdfmodels_fields'] = function ($c) {
276 //include_once GALETTE_ROOT . 'includes/fields_defs/pdfmodels_fields.php';
277 $pdfmodels_fields = array(
279 'model_id' => PdfModel
::MAIN_MODEL
,
280 'model_name' => '_T("Main")',
281 'model_title' => null,
282 'model_type' => PdfModel
::MAIN_MODEL
,
283 'model_header' => '<table>
285 <td id="pdf_assoname"><strong id="asso_name">{ASSO_NAME}</strong><br/>{ASSO_SLOGAN}</td>
286 <td id="pdf_logo">{ASSO_LOGO}</td>
289 'model_footer' => '<div id="pdf_footer">
290 _T("Association") {ASSO_NAME} - {ASSO_ADDRESS}<br/>
293 'model_body' => null,
294 'model_styles' => 'div#pdf_title {
322 'model_parent' => null
325 'model_id' => PdfModel
::INVOICE_MODEL
,
326 'model_name' => '_T("Invoice")',
327 'model_title' => '_T("Invoice") {CONTRIBUTION_YEAR}-{CONTRIBUTION_ID}',
328 'model_type' => PdfModel
::INVOICE_MODEL
,
329 'model_header' => null,
330 'model_footer' => null,
331 'model_body' => '<table>
333 <td width="300"></td>
334 <td><strong>{NAME_ADH}</strong><br/>
336 <strong>{ZIP_ADH} {TOWN_ADH}</strong>
340 <td height="100"></td>
348 <th>_T("Amount")</th>
354 {CONTRIBUTION_LABEL} (_T("on") {CONTRIBUTION_DATE})<br/>
355 _T("from") {CONTRIBUTION_BEGIN_DATE} _T("to") {CONTRIBUTION_END_DATE}<br/>
356 {CONTRIBUTION_PAYMENT_TYPE}<br/>
357 {CONTRIBUTION_COMMENT}
359 <td>{CONTRIBUTION_AMOUNT}</td>
366 'model_styles' => null,
367 'model_parent' => PdfModel
::MAIN_MODEL
370 'model_id' => PdfModel
::RECEIPT_MODEL
,
371 'model_name' => '_T("Receipt")',
372 'model_title' => '_T("Receipt") {CONTRIBUTION_YEAR}-{CONTRIBUTION_ID}',
373 'model_type' => PdfModel
::RECEIPT_MODEL
,
374 'model_header' => null,
375 'model_footer' => null,
376 'model_body' => '<table>
378 <td width="300"></td>
379 <td><strong>{NAME_ADH}</strong><br/>
381 <strong>{ZIP_ADH} {TOWN_ADH}</strong>
385 <td height="100"></td>
393 <th>_T("Amount")</th>
399 {CONTRIBUTION_LABEL} (_T("on") {CONTRIBUTION_DATE})<br/>
400 _T("from") {CONTRIBUTION_BEGIN_DATE} _T("to") {CONTRIBUTION_END_DATE}<br/>
401 {CONTRIBUTION_PAYMENT_TYPE}<br/>
402 {CONTRIBUTION_COMMENT}
404 <td>{CONTRIBUTION_AMOUNT}</td>
411 'model_styles' => null,
412 'model_parent' => PdfModel
::MAIN_MODEL
415 'model_id' => PdfModel
::ADHESION_FORM_MODEL
,
416 'model_name' => '_T("Adhesion form")',
417 'model_title' => '_T("Adhesion form")',
418 'model_type' => PdfModel
::ADHESION_FORM_MODEL
,
419 'model_header' => null,
420 'model_footer' => null,
421 'model_body' => '<hr/>
422 <div class="infos">_T("Complete the following form and send it with your funds, in order to complete your subscription.")</div>
425 <td width="50%"></td>
426 <td width="50%">{ASSO_ADDRESS_MULTI}</td>
432 <td height="30"></td>
435 <td>_T("Required membership:")
437 <input type="radio" class="box" name="cotisation" value="none1">_T("Active member")
438 <input type="radio" class="box" name="cotisation" value="none2">_T("Benefactor member")
439 <input type="radio" class="box" name="cotisation" value="none3">_T("Donation")
440 <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>
445 <td height="30"></td>
448 <table class="member">
450 <td class="label">_T("Politeness")</td>
451 <td class="input">{TITLE_ADH}</td>
454 <td class="label">_T("Name")</td>
455 <td class="input">{LAST_NAME_ADH}</td>
458 <td class="label">_T("First name")</td>
459 <td class="input">{FIRST_NAME_ADH}</td>
462 <td class="label">_T("Company name") *</td>
463 <td class="input">{COMPANY_ADH}</td>
466 <td class="label">_T("Address")</td>
467 <td class="input">{ADDRESS_ADH}</td>
470 <td class="label"></td>
471 <td class="input"></td>
474 <td class="label"></td>
475 <td class="input"></td>
478 <td class="label">_T("Zip Code")</td>
479 <td class="cpinput">{ZIP_ADH}</td>
480 <td class="label">_T("City")</td>
481 <td class="towninput">{TOWN_ADH}</td>
484 <td class="label">_T("Country")</td>
485 <td class="input">{COUNTRY_ADH}</td>
488 <td class="label">_T("Email address")</td>
489 <td class="input">{EMAIL_ADH}</td>
492 <td class="label">_T("Username") **</td>
493 <td class="input">{LOGIN_ADH}</td>
496 <td colspan="2" height="10"></td>
499 <td class="label">_T("Amount")</td>
500 <td class="input"></td>
503 <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>
504 <p class="notes">_T("* Only for compagnies")<br/>_T("** Galette identifier, if applicable")</p>',
505 'model_styles' => 'td.label {
511 border-bottom: 1px dotted black;
516 border-bottom: 1px dotted black;
521 border-bottom: 1px dotted black;
537 'model_parent' => PdfModel
::MAIN_MODEL
540 return $pdfmodels_fields;
543 // -----------------------------------------------------------------------------
545 // -----------------------------------------------------------------------------
548 $container['logger'] = function ($c) {
549 $settings = $c->get('settings');
550 $logger = new \Monolog\
Logger($settings['logger']['name']);
551 $logger->pushProcessor(new \Monolog\Processor\
UidProcessor());
552 $logger->pushHandler(new \Monolog\Handler\
StreamHandler($settings['logger']['path'], $settings['logger']['level']));
556 $container['fields_config'] = function ($c) {
557 $fc = new Galette\Entity\
FieldsConfig(
559 Galette\Entity\Adherent
::TABLE
,
560 $c->get('members_fields'),
561 $c->get('members_fields_cats')
566 $container['lists_config'] = function ($c) {
567 $fc = new Galette\Entity\
ListsConfig(
569 Galette\Entity\Adherent
::TABLE
,
570 $c->get('members_fields'),
571 $c->get('members_fields_cats')
576 $container['cache'] = function ($c) {
578 if (function_exists('wincache_ucache_add')) {
579 //since APCu is not known to work on windows
580 $adapter = 'wincache';
581 } elseif (function_exists('apcu_fetch')) {
584 if ($adapter !== null) {
585 $uuid = $c->get('mode') !== 'INSTALL' ?
$c->get('preferences')->pref_instance_uuid
: '_install';
586 $cache = Laminas\Cache\StorageFactory
::factory([
587 'adapter' => $adapter,
589 'namespace' => str_replace(
590 ['%version', '%uuid'],
591 [GALETTE_VERSION
, $uuid],
592 'galette_%version_%uuid'
601 $container['translator'] = function ($c) {
602 $translator = new Galette\Core\
Translator();
604 $domains = ['galette'];
605 foreach ($domains as $domain) {
606 //load translation file for domain
607 $translator->addTranslationFilePattern(
609 GALETTE_ROOT
. '/lang/',
610 '/%s/LC_MESSAGES/' . $domain . '.mo',
614 //check if a local lang file exists and load it
615 $translator->addTranslationFilePattern(
617 GALETTE_ROOT
. '/lang/',
618 $domain . '_%s_local_lang.php',
623 $translator->setLocale($c->get('i18n')->getLongID());
624 if (!isset($container['mode']) ||
$c->get('mode') !== 'INSTALL' && $c->get('mode') !== 'NEED_UPDATE') {
625 $translator->setCache($c->get('cache'));
630 // Add Event manager to dependency.
631 $container['event_manager'] = function ($c) {
632 $emitter = new SlimEventManager();
634 $emitter->useListenerProvider(
635 new Galette\Events\
MemberListener(
636 $c->get('preferences'),
645 $emitter->useListenerProvider(
646 new Galette\Events\
ContribListener(
647 $c->get('preferences'),
660 //For bad existing globals can be used...
661 if (!isset($container['mode']) ||
($container['mode'] !== 'INSTALL' && $container['mode'] !== 'NEED_UPDATE')) {
662 $zdb = $container->get('zdb');
663 $preferences = $container->get('preferences');
664 $login = $container->get('login');
665 $hist = $container->get('history');
667 $l10n = $container->get('l10n');
668 $emitter = $container->get('event_manager');
670 global $translator, $i18n;
671 $i18n = $container->get('i18n');
672 $translator = $container->get('translator');
674 require_once GALETTE_ROOT
. 'includes/i18n.inc.php';