3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
10 * Copyright © 2007-2021 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
29 * @author Johan Cwiklinski <johan@x-tnd.be>
30 * @copyright 2007-2021 The Galette Team
31 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
32 * @link http://galette.tuxfamily.org
33 * @since Available since 0.7dev - 2007-10-14
36 namespace Galette\Core
;
38 use Galette\Entity\PaymentType
;
41 use Galette\Core\Galette
;
42 use Galette\Entity\Adherent
;
43 use Galette\Entity\Status
;
44 use Galette\IO\PdfMembersCards
;
45 use Galette\Repository\Members
;
48 * Preferences for galette
53 * @author Johan Cwiklinski <johan@x-tnd.be>
54 * @copyright 2007-2021 The Galette Team
55 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
56 * @link http://galette.tuxfamily.org
57 * @since Available since 0.7dev - 2007-10-14
59 * @property string $pref_admin_login Super admin login
60 * @property string $pref_admin_pass Super admin password
61 * @property string $pref_nom Association name
62 * @property string $pref_slogan Association slogan
63 * @property string $pref_adresse Address
64 * @property string $pref_adresse2 Address continuation
65 * @property string $pref_cp Association zipcode
66 * @property string $pref_ville Association town
67 * @property string $pref_pays Country
68 * @property integer $pref_postal_adress Postal adress to use, one of self::POSTAL_ADDRESS*
69 * @property integer $pref_postal_staff_member Staff member ID from which retrieve postal address
70 * @property string $pref_lang Default instance language
71 * @property integer $pref_numrows Default number of rows in lists
72 * @property integer $pref_log History, one of self::LOG_*
73 * @property integer $pref_statut Default status for new members
74 * @property string $pref_email_nom
75 * @property string $pref_email
76 * @property string $pref_email_newadh
77 * @property boolean $pref_bool_mailadh
78 * @property boolean $pref_bool_mailowner
79 * @property boolean $pref_editor_enabled
80 * @property integer $pref_mail_method Mail method, see GaletteMail::METHOD_*
81 * @property string $pref_mail_smtp
82 * @property string $pref_mail_smtp_host
83 * @property boolean $pref_mail_smtp_auth
84 * @property boolean $pref_mail_smtp_secure
85 * @property integer $pref_mail_smtp_port
86 * @property string $pref_mail_smtp_user
87 * @property string $pref_mail_smtp_password
88 * @property integer $pref_membership_ext
89 * @property string $pref_beg_membership
90 * @property integer $pref_membership_offermonths
91 * @property string $pref_email_reply_to
92 * @property string $pref_website
93 * @property integer $pref_etiq_marges_v
94 * @property string $pref_etiq_marges_h
95 * @property string $pref_etiq_hspace
96 * @property string $pref_etiq_vspace
97 * @property string $pref_etiq_hsize
98 * @property string $pref_etiq_vsize
99 * @property string $pref_etiq_cols
100 * @property string $pref_etiq_rows
101 * @property string $pref_etiq_corps
102 * @property string $pref_card_abrev
103 * @property string $pref_card_strip
104 * @property string $pref_card_tcol
105 * @property string $pref_card_scol
106 * @property string $pref_card_bcol
107 * @property string $pref_card_hcol
108 * @property string $pref_bool_display_title
109 * @property integer $pref_card_address
110 * @property string $pref_card_year
111 * @property integer $pref_card_marges_v
112 * @property integer $pref_card_marges_h
113 * @property integer $pref_card_vspace
114 * @property integer $pref_card_hspace
115 * @property string $pref_card_self
116 * @property string $pref_theme Prefered theme
117 * @property boolean $pref_bool_publicpages
118 * @property integer $pref_publicpages_visibility
119 * @property boolean $pref_bool_selfsubscribe
120 * @property string $pref_googleplus
121 * @property string $pref_facebook
122 * @property string $pref_twitter
123 * @property string $pref_viadeo
124 * @property string $pref_linkedin
125 * @property string $pref_mail_sign
126 * @property string $pref_new_contrib_script
127 * @property boolean $pref_bool_wrap_mails
128 * @property string $pref_rss_url
129 * @property boolean $pref_show_id
130 * @property string $pref_adhesion_form
131 * @property boolean $pref_mail_allow_unsecure
132 * @property string $pref_instance_uuid
133 * @property string $pref_registration_uuid
134 * @property string $pref_telemetry_date
135 * @property string $pref_registration_date
136 * @property string $pref_footer
137 * @property integer $pref_filter_account
138 * @property string $pref_galette_url
139 * @property integer $pref_redirect_on_create
140 * @property integer $pref_password_length
141 * @property boolean $pref_password_blacklist
142 * @property integer $pref_password_strength
143 * @property integer $pref_default_paymenttype
144 * @property boolean $pref_bool_create_member
145 * @property-read string $vpref_email_newadh Comma separated list of mail senders
151 private $errors = [];
153 public const TABLE
= 'preferences';
154 public const PK
= 'nom_pref';
156 /** Postal address will be the one given in the preferences */
157 public const POSTAL_ADDRESS_FROM_PREFS
= 0;
158 /** Postal address will be the one of the selected staff member */
159 public const POSTAL_ADDRESS_FROM_STAFF
= 1;
161 /** Public pages stuff */
162 /** Public pages are publically visibles */
163 public const PUBLIC_PAGES_VISIBILITY_PUBLIC
= 0;
164 /** Public pages are visibles for up to date members only */
165 public const PUBLIC_PAGES_VISIBILITY_RESTRICTED
= 1;
166 /** Public pages are visibles for admin and staff members only */
167 public const PUBLIC_PAGES_VISIBILITY_PRIVATE
= 2;
169 public const LOG_DISABLED
= 0;
170 public const LOG_ENABLED
= 1;
172 /** No password strength */
173 public const PWD_NONE
= 0;
174 /** Weak password strength */
175 public const PWD_WEAK
= 1;
176 /** Medium password strength */
177 public const PWD_MEDIUM
= 2;
178 /** Strong password strength */
179 public const PWD_STRONG
= 3;
180 /** Very strong password strength */
181 public const PWD_VERY_STRONG
= 4;
183 private static $fields = array(
188 private static $defaults = array(
189 'pref_admin_login' => 'admin',
190 'pref_admin_pass' => 'admin',
191 'pref_nom' => 'Galette',
193 'pref_adresse' => '-',
194 'pref_adresse2' => '',
198 'pref_postal_adress' => self
::POSTAL_ADDRESS_FROM_PREFS
,
199 'pref_postal_staff_member' => '',
200 'pref_lang' => I18n
::DEFAULT_LANG
,
201 'pref_numrows' => 30,
202 'pref_log' => self
::LOG_ENABLED
,
203 'pref_statut' => Status
::DEFAULT_STATUS
,
204 /* Preferences for emails */
205 'pref_email_nom' => 'Galette',
206 'pref_email' => 'mail@domain.com',
207 'pref_email_newadh' => 'mail@domain.com',
208 'pref_bool_mailadh' => false,
209 'pref_bool_mailowner' => false,
210 'pref_editor_enabled' => false,
211 'pref_mail_method' => GaletteMail
::METHOD_DISABLED
,
212 'pref_mail_smtp' => '',
213 'pref_mail_smtp_host' => '',
214 'pref_mail_smtp_auth' => false,
215 'pref_mail_smtp_secure' => false,
216 'pref_mail_smtp_port' => '',
217 'pref_mail_smtp_user' => '',
218 'pref_mail_smtp_password' => '',
219 'pref_membership_ext' => 12,
220 'pref_beg_membership' => '',
221 'pref_membership_offermonths' => 0,
222 'pref_email_reply_to' => '',
223 'pref_website' => '',
224 /* Preferences for labels */
225 'pref_etiq_marges_v' => 10,
226 'pref_etiq_marges_h' => 10,
227 'pref_etiq_hspace' => 10,
228 'pref_etiq_vspace' => 5,
229 'pref_etiq_hsize' => 90,
230 'pref_etiq_vsize' => 35,
231 'pref_etiq_cols' => 2,
232 'pref_etiq_rows' => 7,
233 'pref_etiq_corps' => 12,
234 /* Preferences for members cards */
235 'pref_card_abrev' => 'GALETTE',
236 'pref_card_strip' => 'Gestion d\'Adherents en Ligne Extrêmement Tarabiscotée',
237 'pref_card_tcol' => '#FFFFFF',
238 'pref_card_scol' => '#8C2453',
239 'pref_card_bcol' => '#53248C',
240 'pref_card_hcol' => '#248C53',
241 'pref_bool_display_title' => false,
242 'pref_card_address' => 1,
243 'pref_card_year' => '',
244 'pref_card_marges_v' => 15,
245 'pref_card_marges_h' => 20,
246 'pref_card_vspace' => 5,
247 'pref_card_hspace' => 10,
248 'pref_card_self' => 1,
249 'pref_theme' => 'default',
250 'pref_bool_publicpages' => true,
251 'pref_publicpages_visibility' => self
::PUBLIC_PAGES_VISIBILITY_RESTRICTED
,
252 'pref_bool_selfsubscribe' => true,
253 'pref_googleplus' => '',
254 'pref_facebook' => '',
255 'pref_twitter' => '',
257 'pref_linkedin' => '',
258 'pref_mail_sign' => "{NAME}\r\n\r\n{WEBSITE}\r\n{GOOGLEPLUS}\r\n{FACEBOOK}\r\n{TWITTER}\r\n{LINKEDIN}\r\n{VIADEO}",
259 /* New contribution script */
260 'pref_new_contrib_script' => '',
261 'pref_bool_wrap_mails' => true,
262 'pref_rss_url' => 'http://galette.eu/dc/index.php/feed/atom',
263 'pref_show_id' => false,
264 'pref_adhesion_form' => '\Galette\IO\PdfAdhesionForm',
265 'pref_mail_allow_unsecure' => false,
266 'pref_instance_uuid' => '',
267 'pref_registration_uuid' => '',
268 'pref_telemetry_date' => '',
269 'pref_registration_date' => '',
271 'pref_filter_account' => Members
::ALL_ACCOUNTS
,
272 'pref_galette_url' => '',
273 'pref_redirect_on_create' => Adherent
::AFTER_ADD_DEFAULT
,
274 /* Security related */
275 'pref_password_length' => 6,
276 'pref_password_blacklist' => false,
277 'pref_password_strength' => self
::PWD_NONE
,
278 'pref_default_paymenttype' => PaymentType
::CHECK
281 // flagging required fields
282 private $required = array(
287 'pref_etiq_marges_v',
288 'pref_etiq_marges_h',
298 'pref_card_marges_v',
299 'pref_card_marges_h',
305 * Default constructor
307 * @param Db $zdb Db instance
308 * @param boolean $load Automatically load preferences on load
312 public function __construct(Db
$zdb, $load = true)
317 $this->checkUpdate();
322 * Check if all fields referenced in the default array does exists,
327 private function checkUpdate()
331 foreach (self
::$defaults as $k => $v) {
332 if (!isset($this->prefs
[$k])) {
333 if ($k == 'pref_admin_pass' && $v == 'admin') {
334 $v = password_hash($v, PASSWORD_BCRYPT
);
336 $this->prefs
[$k] = $v;
338 'The field `' . $k . '` does not exists, Galette will attempt to create it.',
348 if ($proceed !== false) {
350 $insert = $this->zdb
->insert(self
::TABLE
);
353 'nom_pref' => ':nom_pref',
354 'val_pref' => ':val_pref'
357 $stmt = $this->zdb
->sql
->prepareStatementForSqlObject($insert);
359 foreach ($params as $p) {
362 'nom_pref' => $p['nom_pref'],
363 'val_pref' => $p['val_pref']
367 } catch (Throwable
$e) {
369 'Unable to add missing preferences.' . $e->getMessage(),
376 'Missing preferences were successfully stored into database.',
383 * Load current preferences from database.
387 public function load()
389 $this->prefs
= array();
392 $result = $this->zdb
->selectAll(self
::TABLE
);
393 foreach ($result as $pref) {
394 $this->prefs
[$pref->nom_pref
] = $pref->val_pref
;
397 } catch (Throwable
$e) {
399 'Preferences cannot be loaded. Galette should not work without ' .
400 'preferences. Exiting.',
408 * Set default preferences at install time
410 * @param string $lang language selected at install screen
411 * @param string $adm_login admin login entered at install time
412 * @param string $adm_pass admin password entered at install time
414 * @return boolean|\Exception
416 public function installInit($lang, $adm_login, $adm_pass)
419 //first, we drop all values
420 $delete = $this->zdb
->delete(self
::TABLE
);
421 $this->zdb
->execute($delete);
423 //we then replace default values with the ones user has selected
424 $values = self
::$defaults;
425 $values['pref_lang'] = $lang;
426 $values['pref_admin_login'] = $adm_login;
427 $values['pref_admin_pass'] = $adm_pass;
428 $values['pref_card_year'] = date('Y');
430 $insert = $this->zdb
->insert(self
::TABLE
);
433 'nom_pref' => ':nom_pref',
434 'val_pref' => ':val_pref'
437 $stmt = $this->zdb
->sql
->prepareStatementForSqlObject($insert);
439 foreach ($values as $k => $v) {
449 'Default preferences were successfully stored into database.',
453 } catch (Throwable
$e) {
455 'Unable to initialize default preferences.' . $e->getMessage(),
463 * Returns all preferences keys
467 public function getFieldsNames()
469 return array_keys($this->prefs
);
475 * @param array $values Values
476 * @param Login $login Logged in user
480 public function check(array $values, Login
$login)
482 $insert_values = array();
483 if ($login->isSuperAdmin() && GALETTE_MODE
!== Galette
::MODE_DEMO
) {
484 $this->required
[] = 'pref_admin_login';
488 foreach ($this->getFieldsNames() as $fieldname) {
489 if (isset($values[$fieldname])) {
490 $value = trim($values[$fieldname]);
495 $insert_values[$fieldname] = $value;
500 GALETTE_MODE
!== Galette
::MODE_DEMO
501 && isset($insert_values['pref_mail_method'])
503 if ($insert_values['pref_mail_method'] > GaletteMail
::METHOD_DISABLED
) {
505 !isset($insert_values['pref_email_nom'])
506 ||
$insert_values['pref_email_nom'] == ''
508 $this->errors
[] = _T("- You must indicate a sender name for emails!");
511 !isset($insert_values['pref_email'])
512 ||
$insert_values['pref_email'] == ''
514 $this->errors
[] = _T("- You must indicate an email address Galette should use to send emails!");
516 if ($insert_values['pref_mail_method'] == GaletteMail
::METHOD_SMTP
) {
518 !isset($insert_values['pref_mail_smtp_host'])
519 ||
$insert_values['pref_mail_smtp_host'] == ''
521 $this->errors
[] = _T("- You must indicate the SMTP server you want to use!");
525 $insert_values['pref_mail_method'] == GaletteMail
::METHOD_GMAIL
526 ||
($insert_values['pref_mail_method'] == GaletteMail
::METHOD_SMTP
527 && $insert_values['pref_mail_smtp_auth'])
530 !isset($insert_values['pref_mail_smtp_user'])
531 ||
trim($insert_values['pref_mail_smtp_user']) == ''
533 $this->errors
[] = _T("- You must provide a login for SMTP authentication.");
536 !isset($insert_values['pref_mail_smtp_password'])
537 ||
($insert_values['pref_mail_smtp_password']) == ''
539 $this->errors
[] = _T("- You must provide a password for SMTP authentication.");
546 isset($insert_values['pref_beg_membership'])
547 && $insert_values['pref_beg_membership'] != ''
548 && isset($insert_values['pref_membership_ext'])
549 && $insert_values['pref_membership_ext'] != ''
551 $this->errors
[] = _T("- Default membership extention and beginning of membership are mutually exclusive.");
555 isset($insert_values['pref_membership_offermonths'])
556 && (int)$insert_values['pref_membership_offermonths'] > 0
557 && isset($insert_values['pref_membership_ext'])
558 && $insert_values['pref_membership_ext'] != ''
560 $this->errors
[] = _T("- Offering months is only compatible with beginning of membership.");
563 // missing required fields?
564 foreach ($this->required
as $val) {
565 if (!isset($values[$val]) ||
isset($values[$val]) && trim($values[$val]) == '') {
566 $this->errors
[] = str_replace(
569 _T("- Mandatory field %field empty.")
574 if (GALETTE_MODE
!== Galette
::MODE_DEMO
&& isset($values['pref_admin_pass_check'])) {
575 // Check passwords. Hash will be done into the Preferences class
576 if (strcmp($insert_values['pref_admin_pass'], $values['pref_admin_pass_check']) != 0) {
577 $this->errors
[] = _T("Passwords mismatch");
582 if (isset($insert_values['pref_postal_adress'])) {
583 $value = $insert_values['pref_postal_adress'];
584 if ($value == Preferences
::POSTAL_ADDRESS_FROM_PREFS
) {
585 if (isset($insert_values['pref_postal_staff_member'])) {
586 unset($insert_values['pref_postal_staff_member']);
588 } elseif ($value == Preferences
::POSTAL_ADDRESS_FROM_STAFF
) {
589 if (!isset($value) ||
$value < 1) {
590 $this->errors
[] = _T("You have to select a staff member");
595 // update preferences
596 foreach ($insert_values as $champ => $valeur) {
598 $login->isSuperAdmin()
599 ||
(!$login->isSuperAdmin()
600 && ($champ != 'pref_admin_pass' && $champ != 'pref_admin_login'))
603 ($champ == "pref_admin_pass" && $_POST['pref_admin_pass'] != '')
604 ||
($champ != "pref_admin_pass")
606 $this->$champ = $valeur;
611 return 0 === count($this->errors
);
615 * Validate value of a field
617 * @param string $fieldname Field name
618 * @param mixed $value Value to be set
622 public function validateValue($fieldname, $value)
626 switch ($fieldname) {
628 case 'pref_email_newadh':
629 case 'pref_email_reply_to':
630 //check emails validity
631 //may be a comma separated list of valid emails identifiers:
632 //"The Name <mail@domain.com>,The Other <other@mail.com>" expect for reply_to.
634 if (trim($value) != '') {
635 if ($fieldname == 'pref_email_newadh') {
636 $addresses = explode(',', $value);
638 $addresses = [$value];
641 foreach ($addresses as $address) {
642 if (!GaletteMail
::isValidEmail($address)) {
643 $msg = str_replace('%s', $address, _T("Invalid E-Mail address: %s"));
644 Analog
::log($msg, Analog
::WARNING
);
645 $this->errors
[] = $msg;
649 case 'pref_admin_login':
650 if (GALETTE_MODE
=== Galette
::MODE_DEMO
) {
652 'Trying to set superadmin login while in DEMO.',
656 if (strlen($value) < 4) {
657 $this->errors
[] = _T("- The username must be composed of at least 4 characters!");
659 //check if login is already taken
660 if ($login->loginExists($value)) {
661 $this->errors
[] = _T("- This username is already used by another member !");
667 if (!is_numeric($value) ||
$value < 0) {
668 $this->errors
[] = _T("- The numbers and measures have to be integers!");
671 case 'pref_etiq_marges_h':
672 case 'pref_etiq_marges_v':
673 case 'pref_etiq_hspace':
674 case 'pref_etiq_vspace':
675 case 'pref_etiq_hsize':
676 case 'pref_etiq_vsize':
677 case 'pref_etiq_cols':
678 case 'pref_etiq_rows':
679 case 'pref_etiq_corps':
680 case 'pref_card_marges_v':
681 case 'pref_card_marges_h':
682 case 'pref_card_hspace':
683 case 'pref_card_vspace':
684 // prevent division by zero
685 if ($fieldname == 'pref_numrows' && $value == '0') {
688 if (!is_numeric($value) ||
$value < 0) {
689 $this->errors
[] = _T("- The numbers and measures have to be integers!");
692 case 'pref_card_tcol':
693 case 'pref_card_scol':
694 case 'pref_card_bcol':
695 case 'pref_card_hcol':
697 if (!preg_match("/^(#)?([0-9A-F]{6})$/i", $value, $matches)) {
698 // Set strip background colors to black or white (for tcol)
699 $value = ($fieldname == 'pref_card_tcol' ?
'#FFFFFF' : '#000000');
701 $value = '#' . $matches[2];
704 case 'pref_admin_pass':
705 if (GALETTE_MODE
== Galette
::MODE_DEMO
) {
707 'Trying to set superadmin pass while in DEMO.',
711 $pwcheck = new \Galette\Util\
Password($this);
712 $pwcheck->addPersonalInformation(['pref_admin_login' => $this->pref_admin_login
]);
713 if (!$pwcheck->isValid($value)) {
714 $this->errors
= array_merge(
716 $pwcheck->getErrors()
721 case 'pref_membership_ext':
722 if (!is_numeric($value) ||
$value < 0) {
723 $this->errors
[] = _T("- Invalid number of months of membership extension.");
726 case 'pref_beg_membership':
727 $beg_membership = explode("/", $value);
728 if (count($beg_membership) != 2) {
729 $this->errors
[] = _T("- Invalid format of beginning of membership.");
732 if (!checkdate($beg_membership[1], $beg_membership[0], $now['year'])) {
733 $this->errors
[] = _T("- Invalid date for beginning of membership.");
737 case 'pref_membership_offermonths':
738 if (!is_numeric($value) ||
$value < 0) {
739 $this->errors
[] = _T("- Invalid number of offered months.");
742 case 'pref_card_year':
743 if ($value !== 'DEADLINE' && !preg_match('/^(?:\d{4}|\d{2})(\D?)(?:\d{4}|\d{2})$/', $value)) {
744 $this->errors
[] = _T("- Invalid year for cards.");
753 * Will store all preferences in the database
757 public function store()
760 $this->zdb
->connection
->beginTransaction();
761 $update = $this->zdb
->update(self
::TABLE
);
764 'val_pref' => ':val_pref'
766 )->where
->equalTo('nom_pref', ':nom_pref');
768 $stmt = $this->zdb
->sql
->prepareStatementForSqlObject($update);
770 foreach (self
::$defaults as $k => $v) {
772 GALETTE_MODE
== Galette
::MODE_DEMO
773 && in_array($k, ['pref_admin_pass', 'pref_admin_login', 'pref_mail_method'])
777 Analog
::log('Storing ' . $k, Analog
::DEBUG
);
779 $value = $this->prefs
[$k];
780 //do not store pdf_adhesion_form, it's designed to be overriden by plugin
781 if ($k === 'pref_adhesion_form') {
782 if (trim($v) == '') {
783 //Reset to default, should not be empty
784 $v = self
::$defaults['pref_adhesion_form'];
791 'val_pref' => $value,
796 $this->zdb
->connection
->commit();
798 'Preferences were successfully stored into database.',
802 } catch (Throwable
$e) {
803 $this->zdb
->connection
->rollBack();
807 $messages[] = $e->getMessage();
808 } while ($e = $e->getPrevious());
811 'Unable to store preferences | ' . print_r($messages, true),
819 * Returns postal address
821 * @return string postal address
823 public function getPostalAddress()
834 $replacements = null;
836 if ($this->prefs
['pref_postal_adress'] == self
::POSTAL_ADDRESS_FROM_PREFS
) {
837 $_address = $this->prefs
['pref_adresse'];
838 if ($this->prefs
['pref_adresse2'] && $this->prefs
['pref_adresse2'] != '') {
839 $_address .= "\n" . $this->prefs
['pref_adresse2'];
841 $replacements = array(
842 $this->prefs
['pref_nom'],
845 $this->prefs
['pref_cp'],
846 $this->prefs
['pref_ville'],
847 $this->prefs
['pref_pays']
850 //get selected staff member address
851 $adh = new Adherent($this->zdb
, (int)$this->prefs
['pref_postal_staff_member']);
852 $_complement = preg_replace(
853 array('/%name/', '/%status/'),
854 array($this->prefs
['pref_nom'], $adh->sstatus
),
855 _T("%name association's %status")
857 $_address = $adh->address
;
858 if ($adh->address_continuation
&& $adh->address_continuation
!= '') {
859 $_address .= "\n" . $adh->address_continuation
;
861 $replacements = array(
862 $adh->sfullname
. "\n",
871 /*FIXME: i18n fails :/ */
875 _T("%name\n%complement\n%address\n%zip %town - %country")
880 "%name%complement%address\n%zip %town - %country"
886 * Are public pages visibles?
888 * @param Authentication $login Authenticaqtion instance
892 public function showPublicPages(Authentication
$login)
894 if ($this->prefs
['pref_bool_publicpages']) {
895 //if public pages are actives, let's check if we
896 //display them for curent call
897 switch ($this->prefs
['pref_publicpages_visibility']) {
898 case self
::PUBLIC_PAGES_VISIBILITY_PUBLIC
:
899 //pages are publically visibles
902 case self
::PUBLIC_PAGES_VISIBILITY_RESTRICTED
:
903 //pages should be displayed only for up to date members
914 case self
::PUBLIC_PAGES_VISIBILITY_PRIVATE
:
915 //pages should be displayed only for staff and admins
916 if ($login->isAdmin() ||
$login->isStaff()) {
923 //should never be there
933 * Global getter method
935 * @param string $name name of the property we want to retrive
937 * @return false|object the called property
939 public function __get($name)
941 $forbidden = array('defaults');
942 $virtuals = array('vpref_email_newadh');
944 if (!in_array($name, $forbidden) && isset($this->prefs
[$name])) {
946 GALETTE_MODE
=== Galette
::MODE_DEMO
947 && $name == 'pref_mail_method'
949 return GaletteMail
::METHOD_DISABLED
;
951 if ($name == 'pref_adhesion_form' && $this->prefs
[$name] == '') {
952 $this->prefs
[$name] = self
::$defaults['pref_adhesion_form'];
954 $value = $this->prefs
[$name];
955 if (TYPE_DB
=== \Galette\Core\Db
::PGSQL
) {
956 if ($value === 'f') {
961 if (in_array($name, ['pref_email_newadh'])) {
962 $values = explode(',', $value);
963 $value = $values[0]; //take first as default
968 } elseif (in_array($name, $virtuals)) {
969 $virtual = str_replace('vpref_', 'pref_', $name);
970 return explode(',', $this->prefs
[$virtual]);
973 'Preference `' . $name . '` is not set or is forbidden',
981 * Get default preferences
985 public function getDefaults()
987 return self
::$defaults;
991 * Global setter method
993 * @param string $name name of the property we want to assign a value to
994 * @param object $value a relevant value for the property
998 public function __set($name, $value)
1000 //does this pref exists ?
1001 if (!array_key_exists($name, self
::$defaults)) {
1003 'Trying to set a preference value which does not seem to exist ('
1011 $name == 'pref_email'
1012 ||
$name == 'pref_email_newadh'
1013 ||
$name == 'pref_email_reply_to'
1015 if (GALETTE_MODE
=== Galette
::MODE_DEMO
) {
1017 'Trying to set pref_email while in DEMO.',
1024 // now, check validity
1026 $value = $this->validateValue($name, $value);
1029 //some values need to be changed (eg. passwords)
1030 if ($name == 'pref_admin_pass') {
1031 $value = password_hash($value, PASSWORD_BCRYPT
);
1034 //okay, let's update value
1035 $this->prefs
[$name] = $value;
1039 * Get instance URL from configuration (if set) or guessed if not
1043 public function getURL()
1046 if (isset($this->prefs
['pref_galette_url']) && !empty($this->prefs
['pref_galette_url'])) {
1047 $url = $this->prefs
['pref_galette_url'];
1049 $url = $this->getDefaultURL();
1055 * Get default URL (when not set by user in preferences)
1059 public function getDefaultURL()
1061 $scheme = (isset($_SERVER['HTTPS']) ?
'https' : 'http');
1062 $uri = $scheme . '://' . $_SERVER['HTTP_HOST'];
1067 * Get last telemetry date
1071 public function getTelemetryDate(): string
1073 $rawdate = $this->prefs
['pref_telemetry_date'];
1075 $date = new \
DateTime($rawdate);
1076 return $date->format(_T('Y-m-d H:i:s'));
1083 * Get last telemetry date
1085 * @return string|null
1087 public function getRegistrationDate()
1089 $rawdate = $this->prefs
['pref_registration_date'];
1091 $date = new \
DateTime($rawdate);
1092 return $date->format(_T('Y-m-d H:i:s'));
1099 * Check member cards sizes
1100 * Always a A4/portrait
1104 public function checkCardsSizes()
1106 $warning_detected = [];
1110 $size = $this->pref_card_marges_h
* 2;
1112 $size +
= PdfMembersCards
::getWidth() * PdfMembersCards
::getCols();
1114 $size +
= $this->pref_card_hspace
* (PdfMembersCards
::getCols() - 1);
1116 $warning_detected[] = _T('Current cards configuration may exceed page width!');
1121 $size = $this->pref_card_marges_v
* 2;
1123 $size +
= PdfMembersCards
::getHeight() * PdfMembersCards
::getRows();
1125 $size +
= $this->pref_card_vspace
* (PdfMembersCards
::getRows() - 1);
1127 $warning_detected[] = _T('Current cards configuration may exceed page height!');
1130 return $warning_detected;
1138 public function getErrors()
1140 return $this->errors
;