3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
10 * Copyright © 2007-2014 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-2014 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
;
40 use Galette\Entity\Adherent
;
41 use Galette\Entity\Status
;
43 use Galette\IO\PdfMembersCards
;
44 use Galette\Repository\Members
;
47 * Preferences for galette
52 * @author Johan Cwiklinski <johan@x-tnd.be>
53 * @copyright 2007-2014 The Galette Team
54 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
55 * @link http://galette.tuxfamily.org
56 * @since Available since 0.7dev - 2007-10-14
58 * @property string $pref_admin_login Super admin login
59 * @property string $pref_admin_pass Super admin password
60 * @property string $pref_nom Association name
61 * @property string $pref_slogan Association slogan
62 * @property string $pref_adresse Address
63 * @property string $pref_adresse2 Address continuation
64 * @property string $pref_cp Association zipcode
65 * @property string $pref_ville Association town
66 * @property string $pref_pays Country
67 * @property integer $pref_postal_adress Postal adress to use, one of self::POSTAL_ADDRESS*
68 * @property integer $pref_postal_staff_member Staff member ID from which retrieve postal address
69 * @property string $pref_lang Default instance language
70 * @property integer $pref_numrows Default number of rows in lists
71 * @property integer $pref_log History, one of self::LOG_*
72 * @property interger $pref_statut Default status for new members
73 * @property string $pref_email_nom
74 * @property string $pref_email
75 * @property string $pref_email_newadh
76 * @property boolean $pref_bool_mailadh
77 * @property boolean $pref_editor_enabled
78 * @property integer $pref_mail_method Mail method, see GaletteMail::METHOD_*
79 * @property string $pref_mail_smtp
80 * @property string $pref_mail_smtp_host
81 * @property boolean $pref_mail_smtp_auth
82 * @property boolean $pref_mail_smtp_secure
83 * @property integer $pref_mail_smtp_port
84 * @property string $pref_mail_smtp_user
85 * @property string $pref_mail_smtp_password
86 * @property integer $pref_membership_ext
87 * @property string $pref_beg_membership
88 * @property integer $pref_membership_offermonths
89 * @property string $pref_email_reply_to
90 * @property string $pref_website
91 * @property integer $pref_etiq_marges_v
92 * @property string $pref_etiq_marges_h
93 * @property string $pref_etiq_hspace
94 * @property string $pref_etiq_vspace
95 * @property string $pref_etiq_hsize
96 * @property string $pref_etiq_vsize
97 * @property string $pref_etiq_cols
98 * @property string $pref_etiq_rows
99 * @property string $pref_etiq_corps
100 * @property string $pref_card_abrev
101 * @property string $pref_card_strip
102 * @property string $pref_card_tcol
103 * @property string $pref_card_scol
104 * @property string $pref_card_bcol
105 * @property string $pref_card_hcol
106 * @property string $pref_bool_display_title
107 * @property integer $pref_card_address
108 * @property string $pref_card_year
109 * @property integer $pref_card_marges_v
110 * @property integer $pref_card_marges_h
111 * @property integer $pref_card_vspace
112 * @property integer $pref_card_hspace
113 * @property string $pref_card_self
114 * @property string $pref_theme Prefered theme
115 * @property boolean $pref_bool_publicpages
116 * @property integer $pref_publicpages_visibility
117 * @property boolean $pref_bool_selfsubscribe
118 * @property string $pref_googleplus
119 * @property string $pref_facebook
120 * @property string $pref_twitter
121 * @property string $pref_viadeo
122 * @property string $pref_linkedin
123 * @property string $pref_mail_sign
124 * @property string $pref_new_contrib_script
125 * @property boolean $pref_bool_wrap_mails
126 * @property string $pref_rss_url
127 * @property boolean $pref_show_id
128 * @property string $pref_adhesion_form
129 * @property boolean $pref_mail_allow_unsecure
130 * @property string $pref_instance_uuid
131 * @property string $pref_registration_uuid
132 * @property string $pref_telemetry_date
133 * @property string $pref_registration_date
134 * @property string $pref_footer
135 * @property integer $pref_filter_account
136 * @property string $pref_galette_url
137 * @property integer $pref_redirect_on_create
138 * @property integer $pref_password_length
139 * @property boolean $pref_password_blacklist
140 * @property integer $pref_password_strength
141 * @property-read string $vpref_email_newadh Comma separated list of mail senders
147 private $errors = [];
149 public const TABLE
= 'preferences';
150 public const PK
= 'nom_pref';
152 /** Postal address will be the one given in the preferences */
153 public const POSTAL_ADDRESS_FROM_PREFS
= 0;
154 /** Postal address will be the one of the selected staff member */
155 public const POSTAL_ADDRESS_FROM_STAFF
= 1;
157 /** Public pages stuff */
158 /** Public pages are publically visibles */
159 public const PUBLIC_PAGES_VISIBILITY_PUBLIC
= 0;
160 /** Public pages are visibles for up to date members only */
161 public const PUBLIC_PAGES_VISIBILITY_RESTRICTED
= 1;
162 /** Public pages are visibles for admin and staff members only */
163 public const PUBLIC_PAGES_VISIBILITY_PRIVATE
= 2;
165 public const LOG_DISABLED
= 0;
166 public const LOG_ENABLED
= 1;
168 /** No password strength */
169 public const PWD_NONE
= 0;
170 /** Weak password strength */
171 public const PWD_WEAK
= 1;
172 /** Medium password strength */
173 public const PWD_MEDIUM
= 2;
174 /** Strong password strength */
175 public const PWD_STRONG
= 3;
176 /** Very strong password strength */
177 public const PWD_VERY_STRONG
= 4;
179 private static $fields = array(
184 private static $defaults = array(
185 'pref_admin_login' => 'admin',
186 'pref_admin_pass' => 'admin',
187 'pref_nom' => 'Galette',
189 'pref_adresse' => '-',
190 'pref_adresse2' => '',
194 'pref_postal_adress' => self
::POSTAL_ADDRESS_FROM_PREFS
,
195 'pref_postal_staff_member' => '',
196 'pref_lang' => I18n
::DEFAULT_LANG
,
197 'pref_numrows' => 30,
198 'pref_log' => self
::LOG_ENABLED
,
199 'pref_statut' => Status
::DEFAULT_STATUS
,
200 /* Preferences for emails */
201 'pref_email_nom' => 'Galette',
202 'pref_email' => 'mail@domain.com',
203 'pref_email_newadh' => 'mail@domain.com',
204 'pref_bool_mailadh' => false,
205 'pref_editor_enabled' => false,
206 'pref_mail_method' => GaletteMail
::METHOD_DISABLED
,
207 'pref_mail_smtp' => '',
208 'pref_mail_smtp_host' => '',
209 'pref_mail_smtp_auth' => false,
210 'pref_mail_smtp_secure' => false,
211 'pref_mail_smtp_port' => '',
212 'pref_mail_smtp_user' => '',
213 'pref_mail_smtp_password' => '',
214 'pref_membership_ext' => 12,
215 'pref_beg_membership' => '',
216 'pref_membership_offermonths' => 0,
217 'pref_email_reply_to' => '',
218 'pref_website' => '',
219 /* Preferences for labels */
220 'pref_etiq_marges_v' => 10,
221 'pref_etiq_marges_h' => 10,
222 'pref_etiq_hspace' => 10,
223 'pref_etiq_vspace' => 5,
224 'pref_etiq_hsize' => 90,
225 'pref_etiq_vsize' => 35,
226 'pref_etiq_cols' => 2,
227 'pref_etiq_rows' => 7,
228 'pref_etiq_corps' => 12,
229 /* Preferences for members cards */
230 'pref_card_abrev' => 'GALETTE',
231 'pref_card_strip' => 'Gestion d\'Adherents en Ligne Extrêmement Tarabiscotée',
232 'pref_card_tcol' => '#FFFFFF',
233 'pref_card_scol' => '#8C2453',
234 'pref_card_bcol' => '#53248C',
235 'pref_card_hcol' => '#248C53',
236 'pref_bool_display_title' => false,
237 'pref_card_address' => 1,
238 'pref_card_year' => '',
239 'pref_card_marges_v' => 15,
240 'pref_card_marges_h' => 20,
241 'pref_card_vspace' => 5,
242 'pref_card_hspace' => 10,
243 'pref_card_self' => 1,
244 'pref_theme' => 'default',
245 'pref_bool_publicpages' => true,
246 'pref_publicpages_visibility' => self
::PUBLIC_PAGES_VISIBILITY_RESTRICTED
,
247 'pref_bool_selfsubscribe' => true,
248 'pref_googleplus' => '',
249 'pref_facebook' => '',
250 'pref_twitter' => '',
252 'pref_linkedin' => '',
253 'pref_mail_sign' => "{NAME}\r\n\r\n{WEBSITE}\r\n{GOOGLEPLUS}\r\n{FACEBOOK}\r\n{TWITTER}\r\n{LINKEDIN}\r\n{VIADEO}",
254 /* New contribution script */
255 'pref_new_contrib_script' => '',
256 'pref_bool_wrap_mails' => true,
257 'pref_rss_url' => 'http://galette.eu/dc/index.php/feed/atom',
258 'pref_show_id' => false,
259 'pref_adhesion_form' => '\Galette\IO\PdfAdhesionForm',
260 'pref_mail_allow_unsecure' => false,
261 'pref_instance_uuid' => '',
262 'pref_registration_uuid' => '',
263 'pref_telemetry_date' => '',
264 'pref_registration_date' => '',
266 'pref_filter_account' => Members
::ALL_ACCOUNTS
,
267 'pref_galette_url' => '',
268 'pref_redirect_on_create' => Adherent
::AFTER_ADD_DEFAULT
,
269 /* Security related */
270 'pref_password_length' => 6,
271 'pref_password_blacklist' => false,
272 'pref_password_strength' => self
::PWD_NONE
275 // flagging required fields
276 private $required = array(
281 'pref_etiq_marges_v',
282 'pref_etiq_marges_h',
292 'pref_card_marges_v',
293 'pref_card_marges_h',
299 * Default constructor
301 * @param Db $zdb Db instance
302 * @param boolean $load Automatically load preferences on load
306 public function __construct(Db
$zdb, $load = true)
311 $this->checkUpdate();
316 * Check if all fields referenced in the default array does exists,
321 private function checkUpdate()
325 foreach (self
::$defaults as $k => $v) {
326 if (!isset($this->prefs
[$k])) {
327 $this->prefs
[$k] = $v;
329 'The field `' . $k . '` does not exists, Galette will attempt to create it.',
339 if ($proceed !== false) {
341 $insert = $this->zdb
->insert(self
::TABLE
);
344 'nom_pref' => ':nom_pref',
345 'val_pref' => ':val_pref'
348 $stmt = $this->zdb
->sql
->prepareStatementForSqlObject($insert);
350 foreach ($params as $p) {
353 'nom_pref' => $p['nom_pref'],
354 'val_pref' => $p['val_pref']
358 } catch (Throwable
$e) {
360 'Unable to add missing preferences.' . $e->getMessage(),
367 'Missing preferences were successfully stored into database.',
374 * Load current preferences from database.
378 public function load()
380 $this->prefs
= array();
383 $result = $this->zdb
->selectAll(self
::TABLE
);
384 foreach ($result as $pref) {
385 $this->prefs
[$pref->nom_pref
] = $pref->val_pref
;
388 } catch (Throwable
$e) {
390 'Preferences cannot be loaded. Galette should not work without ' .
391 'preferences. Exiting.',
399 * Set default preferences at install time
401 * @param string $lang language selected at install screen
402 * @param string $adm_login admin login entered at install time
403 * @param string $adm_pass admin password entered at install time
405 * @return boolean|\Exception
407 public function installInit($lang, $adm_login, $adm_pass)
410 //first, we drop all values
411 $delete = $this->zdb
->delete(self
::TABLE
);
412 $this->zdb
->execute($delete);
414 //we then replace default values with the ones user has selected
415 $values = self
::$defaults;
416 $values['pref_lang'] = $lang;
417 $values['pref_admin_login'] = $adm_login;
418 $values['pref_admin_pass'] = $adm_pass;
419 $values['pref_card_year'] = date('Y');
421 $insert = $this->zdb
->insert(self
::TABLE
);
424 'nom_pref' => ':nom_pref',
425 'val_pref' => ':val_pref'
428 $stmt = $this->zdb
->sql
->prepareStatementForSqlObject($insert);
430 foreach ($values as $k => $v) {
440 'Default preferences were successfully stored into database.',
444 } catch (Throwable
$e) {
446 'Unable to initialize default preferences.' . $e->getMessage(),
454 * Returns all preferences keys
458 public function getFieldsNames()
460 return array_keys($this->prefs
);
466 * @param array $values Values
467 * @param Login $login Logged in user
471 public function check(array $values, Login
$login)
473 $insert_values = array();
474 if ($login->isSuperAdmin() && GALETTE_MODE
!== 'DEMO') {
475 $this->required
[] = 'pref_admin_login';
479 foreach ($this->getFieldsNames() as $fieldname) {
480 if (isset($values[$fieldname])) {
481 $value = trim($values[$fieldname]);
486 $insert_values[$fieldname] = $value;
491 GALETTE_MODE
!== 'DEMO'
492 && isset($insert_values['pref_mail_method'])
494 if ($insert_values['pref_mail_method'] > GaletteMail
::METHOD_DISABLED
) {
496 !isset($insert_values['pref_email_nom'])
497 ||
$insert_values['pref_email_nom'] == ''
499 $this->errors
[] = _T("- You must indicate a sender name for emails!");
502 !isset($insert_values['pref_email'])
503 ||
$insert_values['pref_email'] == ''
505 $this->errors
[] = _T("- You must indicate an email address Galette should use to send emails!");
507 if ($insert_values['pref_mail_method'] == GaletteMail
::METHOD_SMTP
) {
509 !isset($insert_values['pref_mail_smtp_host'])
510 ||
$insert_values['pref_mail_smtp_host'] == ''
512 $this->errors
[] = _T("- You must indicate the SMTP server you want to use!");
516 $insert_values['pref_mail_method'] == GaletteMail
::METHOD_GMAIL
517 ||
($insert_values['pref_mail_method'] == GaletteMail
::METHOD_SMTP
518 && $insert_values['pref_mail_smtp_auth'])
521 !isset($insert_values['pref_mail_smtp_user'])
522 ||
trim($insert_values['pref_mail_smtp_user']) == ''
524 $this->errors
[] = _T("- You must provide a login for SMTP authentication.");
527 !isset($insert_values['pref_mail_smtp_password'])
528 ||
($insert_values['pref_mail_smtp_password']) == ''
530 $this->errors
[] = _T("- You must provide a password for SMTP authentication.");
537 isset($insert_values['pref_beg_membership'])
538 && $insert_values['pref_beg_membership'] != ''
539 && isset($insert_values['pref_membership_ext'])
540 && $insert_values['pref_membership_ext'] != ''
542 $this->errors
[] = _T("- Default membership extention and beginning of membership are mutually exclusive.");
546 isset($insert_values['pref_membership_offermonths'])
547 && (int)$insert_values['pref_membership_offermonths'] > 0
548 && isset($insert_values['pref_membership_ext'])
549 && $insert_values['pref_membership_ext'] != ''
551 $this->errors
[] = _T("- Offering months is only compatible with beginning of membership.");
554 // missing required fields?
555 foreach ($this->required
as $val) {
556 if (!isset($values[$val]) ||
isset($values[$val]) && trim($values[$val]) == '') {
557 $this->errors
[] = str_replace(
560 _T("- Mandatory field %field empty.")
565 if (GALETTE_MODE
!== 'DEMO' && isset($values['pref_admin_pass_check'])) {
566 // Check passwords. Hash will be done into the Preferences class
567 if (strcmp($insert_values['pref_admin_pass'], $values['pref_admin_pass_check']) != 0) {
568 $this->errors
[] = _T("Passwords mismatch");
573 if (isset($insert_values['pref_postal_adress'])) {
574 $value = $insert_values['pref_postal_adress'];
575 if ($value == Preferences
::POSTAL_ADDRESS_FROM_PREFS
) {
576 if (isset($insert_values['pref_postal_staff_member'])) {
577 unset($insert_values['pref_postal_staff_member']);
579 } elseif ($value == Preferences
::POSTAL_ADDRESS_FROM_STAFF
) {
580 if (!isset($value) ||
$value < 1) {
581 $this->errors
[] = _T("You have to select a staff member");
586 // update preferences
587 foreach ($insert_values as $champ => $valeur) {
589 $login->isSuperAdmin()
590 ||
(!$login->isSuperAdmin()
591 && ($champ != 'pref_admin_pass' && $champ != 'pref_admin_login'))
594 ($champ == "pref_admin_pass" && $_POST['pref_admin_pass'] != '')
595 ||
($champ != "pref_admin_pass")
597 $this->$champ = $valeur;
602 return 0 === count($this->errors
);
606 * Validate value of a field
608 * @param string $fieldname Field name
609 * @param mixed $value Value to be set
613 public function validateValue($fieldname, $value)
617 switch ($fieldname) {
619 case 'pref_email_newadh':
620 case 'pref_email_reply_to':
621 //check emails validity
622 //may be a comma separated list of valid emails identifiers:
623 //"The Name <mail@domain.com>,The Other <other@mail.com>" expect for reply_to.
625 if (trim($value) != '') {
626 if ($fieldname == 'pref_email_newadh') {
627 $addresses = explode(',', $value);
629 $addresses = [$value];
632 foreach ($addresses as $address) {
633 if (!GaletteMail
::isValidEmail($address)) {
634 $msg = str_replace('%s', $address, _T("Invalid E-Mail address: %s"));
635 Analog
::log($msg, Analog
::WARNING
);
636 $this->errors
[] = $msg;
640 case 'pref_admin_login':
641 if (GALETTE_MODE
=== 'DEMO') {
643 'Trying to set superadmin login while in DEMO.',
647 if (strlen($value) < 4) {
648 $this->errors
[] = _T("- The username must be composed of at least 4 characters!");
650 //check if login is already taken
651 if ($login->loginExists($value)) {
652 $this->errors
[] = _T("- This username is already used by another member !");
658 if (!is_numeric($value) ||
$value < 0) {
659 $this->errors
[] = _T("- The numbers and measures have to be integers!");
662 case 'pref_etiq_marges_h':
663 case 'pref_etiq_marges_v':
664 case 'pref_etiq_hspace':
665 case 'pref_etiq_vspace':
666 case 'pref_etiq_hsize':
667 case 'pref_etiq_vsize':
668 case 'pref_etiq_cols':
669 case 'pref_etiq_rows':
670 case 'pref_etiq_corps':
671 case 'pref_card_marges_v':
672 case 'pref_card_marges_h':
673 case 'pref_card_hspace':
674 case 'pref_card_vspace':
675 // prevent division by zero
676 if ($fieldname == 'pref_numrows' && $value == '0') {
679 if (!is_numeric($value) ||
$value < 0) {
680 $this->errors
[] = _T("- The numbers and measures have to be integers!");
683 case 'pref_card_tcol':
684 case 'pref_card_scol':
685 case 'pref_card_bcol':
686 case 'pref_card_hcol':
688 if (!preg_match("/^(#)?([0-9A-F]{6})$/i", $value, $matches)) {
689 // Set strip background colors to black or white (for tcol)
690 $value = ($fieldname == 'pref_card_tcol' ?
'#FFFFFF' : '#000000');
692 $value = '#' . $matches[2];
695 case 'pref_admin_pass':
696 if (GALETTE_MODE
== 'DEMO') {
698 'Trying to set superadmin pass while in DEMO.',
702 $pwcheck = new \Galette\Util\
Password($this);
703 $pwcheck->addPersonalInformation(['pref_admin_login' => $this->pref_admin_login
]);
704 if (!$pwcheck->isValid($value)) {
705 $this->errors
= array_merge(
707 $pwcheck->getErrors()
712 case 'pref_membership_ext':
713 if (!is_numeric($value) ||
$value < 0) {
714 $this->errors
[] = _T("- Invalid number of months of membership extension.");
717 case 'pref_beg_membership':
718 $beg_membership = explode("/", $value);
719 if (count($beg_membership) != 2) {
720 $this->errors
[] = _T("- Invalid format of beginning of membership.");
723 if (!checkdate($beg_membership[1], $beg_membership[0], $now['year'])) {
724 $this->errors
[] = _T("- Invalid date for beginning of membership.");
728 case 'pref_membership_offermonths':
729 if (!is_numeric($value) ||
$value < 0) {
730 $this->errors
[] = _T("- Invalid number of offered months.");
733 case 'pref_card_year':
734 if ($value !== 'DEADLINE' && !preg_match('/^(?:\d{4}|\d{2})(\D?)(?:\d{4}|\d{2})$/', $value)) {
735 $this->errors
[] = _T("- Invalid year for cards.");
744 * Will store all preferences in the database
748 public function store()
751 $this->zdb
->connection
->beginTransaction();
752 $update = $this->zdb
->update(self
::TABLE
);
755 'val_pref' => ':val_pref'
757 )->where
->equalTo('nom_pref', ':nom_pref');
759 $stmt = $this->zdb
->sql
->prepareStatementForSqlObject($update);
761 foreach (self
::$defaults as $k => $v) {
763 GALETTE_MODE
== 'DEMO'
764 && in_array($k, ['pref_admin_pass', 'pref_admin_login', 'pref_mail_method'])
768 Analog
::log('Storing ' . $k, Analog
::DEBUG
);
770 $value = $this->prefs
[$k];
771 //do not store pdf_adhesion_form, it's designed to be overriden by plugin
772 if ($k === 'pref_adhesion_form') {
773 if (trim($v) == '') {
774 //Reset to default, should not be empty
775 $v = self
::$defaults['pref_adhesion_form'];
782 'val_pref' => $value,
787 $this->zdb
->connection
->commit();
789 'Preferences were successfully stored into database.',
793 } catch (Throwable
$e) {
794 $this->zdb
->connection
->rollBack();
798 $messages[] = $e->getMessage();
799 } while ($e = $e->getPrevious());
802 'Unable to store preferences | ' . print_r($messages, true),
810 * Returns postal address
812 * @return string postal address
814 public function getPostalAddress()
825 $replacements = null;
827 if ($this->prefs
['pref_postal_adress'] == self
::POSTAL_ADDRESS_FROM_PREFS
) {
828 $_address = $this->prefs
['pref_adresse'];
829 if ($this->prefs
['pref_adresse2'] && $this->prefs
['pref_adresse2'] != '') {
830 $_address .= "\n" . $this->prefs
['pref_adresse2'];
832 $replacements = array(
833 $this->prefs
['pref_nom'],
836 $this->prefs
['pref_cp'],
837 $this->prefs
['pref_ville'],
838 $this->prefs
['pref_pays']
841 //get selected staff member address
842 $adh = new Adherent($this->zdb
, (int)$this->prefs
['pref_postal_staff_member']);
843 $_complement = preg_replace(
844 array('/%name/', '/%status/'),
845 array($this->prefs
['pref_nom'], $adh->sstatus
),
846 _T("%name association's %status")
848 $_address = $adh->address
;
849 if ($adh->address_continuation
&& $adh->address_continuation
!= '') {
850 $_address .= "\n" . $adh->address_continuation
;
852 $replacements = array(
853 $adh->sfullname
. "\n",
862 /*FIXME: i18n fails :/ */
866 _T("%name\n%complement\n%address\n%zip %town - %country")
871 "%name%complement%address\n%zip %town - %country"
877 * Are public pages visibles?
879 * @param Authentication $login Authenticaqtion instance
883 public function showPublicPages(Authentication
$login)
885 if ($this->prefs
['pref_bool_publicpages']) {
886 //if public pages are actives, let's check if we
887 //display them for curent call
888 switch ($this->prefs
['pref_publicpages_visibility']) {
889 case self
::PUBLIC_PAGES_VISIBILITY_PUBLIC
:
890 //pages are publically visibles
893 case self
::PUBLIC_PAGES_VISIBILITY_RESTRICTED
:
894 //pages should be displayed only for up to date members
905 case self
::PUBLIC_PAGES_VISIBILITY_PRIVATE
:
906 //pages should be displayed only for staff and admins
907 if ($login->isAdmin() ||
$login->isStaff()) {
914 //should never be there
924 * Global getter method
926 * @param string $name name of the property we want to retrive
928 * @return false|object the called property
930 public function __get($name)
932 $forbidden = array('defaults');
933 $virtuals = array('vpref_email_newadh');
935 if (!in_array($name, $forbidden) && isset($this->prefs
[$name])) {
937 GALETTE_MODE
=== 'DEMO'
938 && $name == 'pref_mail_method'
940 return GaletteMail
::METHOD_DISABLED
;
942 if ($name == 'pref_adhesion_form' && $this->prefs
[$name] == '') {
943 $this->prefs
[$name] = self
::$defaults['pref_adhesion_form'];
945 $value = $this->prefs
[$name];
946 if (TYPE_DB
=== \Galette\Core\Db
::PGSQL
) {
947 if ($value === 'f') {
952 if (in_array($name, ['pref_email_newadh'])) {
953 $values = explode(',', $value);
954 $value = $values[0]; //take first as default
959 } elseif (in_array($name, $virtuals)) {
960 $virtual = str_replace('vpref_', 'pref_', $name);
961 return explode(',', $this->prefs
[$virtual]);
964 'Preference `' . $name . '` is not set or is forbidden',
972 * Get default preferences
976 public function getDefaults()
978 return self
::$defaults;
982 * Global setter method
984 * @param string $name name of the property we want to assign a value to
985 * @param object $value a relevant value for the property
989 public function __set($name, $value)
991 //does this pref exists ?
992 if (!array_key_exists($name, self
::$defaults)) {
994 'Trying to set a preference value which does not seem to exist ('
1002 $name == 'pref_email'
1003 ||
$name == 'pref_email_newadh'
1004 ||
$name == 'pref_email_reply_to'
1006 if (GALETTE_MODE
=== 'DEMO') {
1008 'Trying to set pref_email while in DEMO.',
1015 // now, check validity
1017 $value = $this->validateValue($name, $value);
1020 //some values need to be changed (eg. passwords)
1021 if ($name == 'pref_admin_pass') {
1022 $value = password_hash($value, PASSWORD_BCRYPT
);
1025 //okay, let's update value
1026 $this->prefs
[$name] = $value;
1030 * Get instance URL from configuration (if set) or guessed if not
1034 public function getURL()
1037 if (isset($this->prefs
['pref_galette_url']) && !empty($this->prefs
['pref_galette_url'])) {
1038 $url = $this->prefs
['pref_galette_url'];
1040 $url = $this->getDefaultURL();
1046 * Get default URL (when not setted by user in preferences)
1050 public function getDefaultURL()
1052 $scheme = (isset($_SERVER['HTTPS']) ?
'https' : 'http');
1053 $uri = $scheme . '://' . $_SERVER['HTTP_HOST'];
1058 * Check member cards sizes
1059 * Always a A4/portrait
1063 public function checkCardsSizes()
1065 $warning_detected = [];
1069 $size = $this->pref_card_marges_h
* 2;
1071 $size +
= PdfMembersCards
::getWidth() * PdfMembersCards
::getCols();
1073 $size +
= $this->pref_card_hspace
* (PdfMembersCards
::getCols() - 1);
1075 $warning_detected[] = _T('Current cards configuration may exceed page width!');
1080 $size = $this->pref_card_marges_v
* 2;
1082 $size +
= PdfMembersCards
::getHeight() * PdfMembersCards
::getRows();
1084 $size +
= $this->pref_card_vspace
* (PdfMembersCards
::getRows() - 1);
1086 $warning_detected[] = _T('Current cards configuration may exceed page height!');
1089 return $warning_detected;
1097 public function getErrors()
1099 return $this->errors
;