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
;
39 use Galette\Entity\Adherent
;
40 use Galette\Entity\Status
;
42 use Galette\IO\PdfMembersCards
;
43 use Galette\Repository\Members
;
46 * Preferences for galette
51 * @author Johan Cwiklinski <johan@x-tnd.be>
52 * @copyright 2007-2014 The Galette Team
53 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
54 * @link http://galette.tuxfamily.org
55 * @since Available since 0.7dev - 2007-10-14
57 * @property string $pref_admin_login Super admin login
58 * @property string $pref_admin_pass Super admin password
59 * @property string $pref_nom Association name
60 * @property string $pref_slogan Association slogan
61 * @property string $pref_adresse Address
62 * @property string $pref_adresse2 Address continuation
63 * @property string $pref_cp Association zipcode
64 * @property string $pref_ville Association town
65 * @property string $pref_pays Country
66 * @property integer $pref_postal_adress Postal adress to use, one of self::POSTAL_ADDRESS*
67 * @property integer $pref_postal_staff_member Staff member ID from which retrieve postal address
68 * @property string $pref_lang Default instance language
69 * @property integer $pref_numrows Default number of rows in lists
70 * @property integer $pref_log History, one of self::LOG_*
71 * @property interger $pref_statut Default status for new members
72 * @property string $pref_email_nom
73 * @property string $pref_email
74 * @property string $pref_email_newadh
75 * @property boolean $pref_bool_mailadh
76 * @property boolean $pref_editor_enabled
77 * @property integer $pref_mail_method Mail method, see GaletteMail::METHOD_*
78 * @property string $pref_mail_smtp
79 * @property string $pref_mail_smtp_host
80 * @property boolean $pref_mail_smtp_auth
81 * @property boolean $pref_mail_smtp_secure
82 * @property integer $pref_mail_smtp_port
83 * @property string $pref_mail_smtp_user
84 * @property string $pref_mail_smtp_password
85 * @property integer $pref_membership_ext
86 * @property string $pref_beg_membership
87 * @property integer $pref_membership_offermonths
88 * @property string $pref_email_reply_to
89 * @property string $pref_website
90 * @property integer $pref_etiq_marges_v
91 * @property string $pref_etiq_marges_h
92 * @property string $pref_etiq_hspace
93 * @property string $pref_etiq_vspace
94 * @property string $pref_etiq_hsize
95 * @property string $pref_etiq_vsize
96 * @property string $pref_etiq_cols
97 * @property string $pref_etiq_rows
98 * @property string $pref_etiq_corps
99 * @property string $pref_card_abrev
100 * @property string $pref_card_strip
101 * @property string $pref_card_tcol
102 * @property string $pref_card_scol
103 * @property string $pref_card_bcol
104 * @property string $pref_card_hcol
105 * @property string $pref_bool_display_title
106 * @property integer $pref_card_address
107 * @property string $pref_card_year
108 * @property integer $pref_card_marges_v
109 * @property integer $pref_card_marges_h
110 * @property integer $pref_card_vspace
111 * @property integer $pref_card_hspace
112 * @property string $pref_card_self
113 * @property string $pref_theme Prefered theme
114 * @property boolean $pref_bool_publicpages
115 * @property integer $pref_publicpages_visibility
116 * @property boolean $pref_bool_selfsubscribe
117 * @property string $pref_googleplus
118 * @property string $pref_facebook
119 * @property string $pref_twitter
120 * @property string $pref_viadeo
121 * @property string $pref_linkedin
122 * @property string $pref_mail_sign
123 * @property string $pref_new_contrib_script
124 * @property boolean $pref_bool_wrap_mails
125 * @property string $pref_rss_url
126 * @property boolean $pref_show_id
127 * @property string $pref_adhesion_form
128 * @property boolean $pref_mail_allow_unsecure
129 * @property string $pref_instance_uuid
130 * @property string $pref_registration_uuid
131 * @property string $pref_telemetry_date
132 * @property string $pref_registration_date
133 * @property string $pref_footer
134 * @property integer $pref_filter_account
135 * @property string $pref_galette_url
136 * @property integer $pref_redirect_on_create
137 * @property integer $pref_password_length
138 * @property boolean $pref_password_blacklist
139 * @property integer $pref_password_strength
140 * @property-read string $vpref_email_newadh Comma separated list of mail senders
146 private $errors = [];
148 public const TABLE
= 'preferences';
149 public const PK
= 'nom_pref';
151 /** Postal address will be the one given in the preferences */
152 public const POSTAL_ADDRESS_FROM_PREFS
= 0;
153 /** Postal address will be the one of the selected staff member */
154 public const POSTAL_ADDRESS_FROM_STAFF
= 1;
156 /** Public pages stuff */
157 /** Public pages are publically visibles */
158 public const PUBLIC_PAGES_VISIBILITY_PUBLIC
= 0;
159 /** Public pages are visibles for up to date members only */
160 public const PUBLIC_PAGES_VISIBILITY_RESTRICTED
= 1;
161 /** Public pages are visibles for admin and staff members only */
162 public const PUBLIC_PAGES_VISIBILITY_PRIVATE
= 2;
164 public const LOG_DISABLED
= 0;
165 public const LOG_ENABLED
= 1;
167 /** No password strength */
168 public const PWD_NONE
= 0;
169 /** Weak password strength */
170 public const PWD_WEAK
= 1;
171 /** Medium password strength */
172 public const PWD_MEDIUM
= 2;
173 /** Strong password strength */
174 public const PWD_STRONG
= 3;
175 /** Very strong password strength */
176 public const PWD_VERY_STRONG
= 4;
178 private static $fields = array(
183 private static $defaults = array(
184 'pref_admin_login' => 'admin',
185 'pref_admin_pass' => 'admin',
186 'pref_nom' => 'Galette',
188 'pref_adresse' => '-',
189 'pref_adresse2' => '',
193 'pref_postal_adress' => self
::POSTAL_ADDRESS_FROM_PREFS
,
194 'pref_postal_staff_member' => '',
195 'pref_lang' => I18n
::DEFAULT_LANG
,
196 'pref_numrows' => 30,
197 'pref_log' => self
::LOG_ENABLED
,
198 'pref_statut' => Status
::DEFAULT_STATUS
,
199 /* Preferences for emails */
200 'pref_email_nom' => 'Galette',
201 'pref_email' => 'mail@domain.com',
202 'pref_email_newadh' => 'mail@domain.com',
203 'pref_bool_mailadh' => false,
204 'pref_editor_enabled' => false,
205 'pref_mail_method' => GaletteMail
::METHOD_DISABLED
,
206 'pref_mail_smtp' => '',
207 'pref_mail_smtp_host' => '',
208 'pref_mail_smtp_auth' => false,
209 'pref_mail_smtp_secure' => false,
210 'pref_mail_smtp_port' => '',
211 'pref_mail_smtp_user' => '',
212 'pref_mail_smtp_password' => '',
213 'pref_membership_ext' => 12,
214 'pref_beg_membership' => '',
215 'pref_membership_offermonths' => 0,
216 'pref_email_reply_to' => '',
217 'pref_website' => '',
218 /* Preferences for labels */
219 'pref_etiq_marges_v' => 10,
220 'pref_etiq_marges_h' => 10,
221 'pref_etiq_hspace' => 10,
222 'pref_etiq_vspace' => 5,
223 'pref_etiq_hsize' => 90,
224 'pref_etiq_vsize' => 35,
225 'pref_etiq_cols' => 2,
226 'pref_etiq_rows' => 7,
227 'pref_etiq_corps' => 12,
228 /* Preferences for members cards */
229 'pref_card_abrev' => 'GALETTE',
230 'pref_card_strip' => 'Gestion d\'Adherents en Ligne Extrêmement Tarabiscotée',
231 'pref_card_tcol' => 'FFFFFF',
232 'pref_card_scol' => '8C2453',
233 'pref_card_bcol' => '53248C',
234 'pref_card_hcol' => '248C53',
235 'pref_bool_display_title' => false,
236 'pref_card_address' => 1,
237 'pref_card_year' => '',
238 'pref_card_marges_v' => 15,
239 'pref_card_marges_h' => 20,
240 'pref_card_vspace' => 5,
241 'pref_card_hspace' => 10,
242 'pref_card_self' => 1,
243 'pref_theme' => 'default',
244 'pref_bool_publicpages' => true,
245 'pref_publicpages_visibility' => self
::PUBLIC_PAGES_VISIBILITY_RESTRICTED
,
246 'pref_bool_selfsubscribe' => true,
247 'pref_googleplus' => '',
248 'pref_facebook' => '',
249 'pref_twitter' => '',
251 'pref_linkedin' => '',
252 'pref_mail_sign' => "{NAME}\r\n\r\n{WEBSITE}\r\n{GOOGLEPLUS}\r\n{FACEBOOK}\r\n{TWITTER}\r\n{LINKEDIN}\r\n{VIADEO}",
253 /* New contribution script */
254 'pref_new_contrib_script' => '',
255 'pref_bool_wrap_mails' => true,
256 'pref_rss_url' => 'http://galette.eu/dc/index.php/feed/atom',
257 'pref_show_id' => false,
258 'pref_adhesion_form' => '\Galette\IO\PdfAdhesionForm',
259 'pref_mail_allow_unsecure' => false,
260 'pref_instance_uuid' => '',
261 'pref_registration_uuid' => '',
262 'pref_telemetry_date' => '',
263 'pref_registration_date' => '',
265 'pref_filter_account' => Members
::ALL_ACCOUNTS
,
266 'pref_galette_url' => '',
267 'pref_redirect_on_create' => Adherent
::AFTER_ADD_DEFAULT
,
268 /* Security related */
269 'pref_password_length' => 6,
270 'pref_password_blacklist' => false,
271 'pref_password_strength' => self
::PWD_NONE
274 // flagging required fields
275 private $required = array(
280 'pref_etiq_marges_v',
281 'pref_etiq_marges_h',
291 'pref_card_marges_v',
292 'pref_card_marges_h',
298 * Default constructor
300 * @param Db $zdb Db instance
301 * @param boolean $load Automatically load preferences on load
305 public function __construct(Db
$zdb, $load = true)
310 $this->checkUpdate();
315 * Check if all fields referenced in the default array does exists,
320 private function checkUpdate()
324 foreach (self
::$defaults as $k => $v) {
325 if (!isset($this->prefs
[$k])) {
326 $this->prefs
[$k] = $v;
328 'The field `' . $k . '` does not exists, Galette will attempt to create it.',
338 if ($proceed !== false) {
340 $insert = $this->zdb
->insert(self
::TABLE
);
343 'nom_pref' => ':nom_pref',
344 'val_pref' => ':val_pref'
347 $stmt = $this->zdb
->sql
->prepareStatementForSqlObject($insert);
349 foreach ($params as $p) {
352 'nom_pref' => $p['nom_pref'],
353 'val_pref' => $p['val_pref']
357 } catch (\Exception
$e) {
359 'Unable to add missing preferences.' . $e->getMessage(),
366 'Missing preferences were successfully stored into database.',
373 * Load current preferences from database.
377 public function load()
379 $this->prefs
= array();
382 $result = $this->zdb
->selectAll(self
::TABLE
);
383 foreach ($result as $pref) {
384 $this->prefs
[$pref->nom_pref
] = $pref->val_pref
;
387 } catch (\Exception
$e) {
389 'Preferences cannot be loaded. Galette should not work without ' .
390 'preferences. Exiting.',
398 * Set default preferences at install time
400 * @param string $lang language selected at install screen
401 * @param string $adm_login admin login entered at install time
402 * @param string $adm_pass admin password entered at install time
404 * @return boolean|\Exception
406 public function installInit($lang, $adm_login, $adm_pass)
409 //first, we drop all values
410 $delete = $this->zdb
->delete(self
::TABLE
);
411 $this->zdb
->execute($delete);
413 //we then replace default values with the ones user has selected
414 $values = self
::$defaults;
415 $values['pref_lang'] = $lang;
416 $values['pref_admin_login'] = $adm_login;
417 $values['pref_admin_pass'] = $adm_pass;
418 $values['pref_card_year'] = date('Y');
420 $insert = $this->zdb
->insert(self
::TABLE
);
423 'nom_pref' => ':nom_pref',
424 'val_pref' => ':val_pref'
427 $stmt = $this->zdb
->sql
->prepareStatementForSqlObject($insert);
429 foreach ($values as $k => $v) {
439 'Default preferences were successfully stored into database.',
443 } catch (\Exception
$e) {
445 'Unable to initialize default preferences.' . $e->getMessage(),
453 * Returns all preferences keys
457 public function getFieldsNames()
459 return array_keys($this->prefs
);
465 * @param array $values Values
466 * @param Login $login Logged in user
470 public function check(array $values, Login
$login)
472 $insert_values = array();
473 if ($login->isSuperAdmin() && GALETTE_MODE
!== 'DEMO') {
474 $this->required
[] = 'pref_admin_login';
478 foreach ($this->getFieldsNames() as $fieldname) {
479 if (isset($values[$fieldname])) {
480 $value = trim($values[$fieldname]);
485 // now, check validity
487 switch ($fieldname) {
488 case 'pref_admin_login':
489 if (GALETTE_MODE
=== 'DEMO') {
491 'Trying to set superadmin login while in DEMO.',
495 if (strlen($value) < 4) {
496 $this->errors
[] = _T("- The username must be composed of at least 4 characters!");
498 //check if login is already taken
499 if ($login->loginExists($value)) {
500 $this->errors
[] = _T("- This username is already used by another member !");
506 if (!is_numeric($value) ||
$value < 0) {
507 $this->errors
[] = _T("- The numbers and measures have to be integers!");
510 case 'pref_etiq_marges_h':
511 case 'pref_etiq_marges_v':
512 case 'pref_etiq_hspace':
513 case 'pref_etiq_vspace':
514 case 'pref_etiq_hsize':
515 case 'pref_etiq_vsize':
516 case 'pref_etiq_cols':
517 case 'pref_etiq_rows':
518 case 'pref_etiq_corps':
519 case 'pref_card_marges_v':
520 case 'pref_card_marges_h':
521 case 'pref_card_hspace':
522 case 'pref_card_vspace':
523 // prevent division by zero
524 if ($fieldname == 'pref_numrows' && $value == '0') {
527 if (!is_numeric($value) ||
$value < 0) {
528 $this->errors
[] = _T("- The numbers and measures have to be integers!");
531 case 'pref_card_tcol':
532 // Set strip text color to white
533 if (!preg_match("/#([0-9A-F]{6})/i", $value)) {
537 case 'pref_card_scol':
538 case 'pref_card_bcol':
539 case 'pref_card_hcol':
540 // Set strip background colors to black
541 if (!preg_match("/#([0-9A-F]{6})/i", $value)) {
545 case 'pref_admin_pass':
546 if (GALETTE_MODE
== 'DEMO') {
548 'Trying to set superadmin pass while in DEMO.',
552 $pwcheck = new \Galette\Util\
Password($this);
553 $pwcheck->addPersonalInformation(['pref_admin_login' => $this->pref_admin_login
]);
554 if (!$pwcheck->isValid($value)) {
555 $this->errors
= array_merge(
557 $pwcheck->getErrors()
562 case 'pref_membership_ext':
563 if (!is_numeric($value) ||
$value < 0) {
564 $this->errors
[] = _T("- Invalid number of months of membership extension.");
567 case 'pref_beg_membership':
568 $beg_membership = explode("/", $value);
569 if (count($beg_membership) != 2) {
570 $this->errors
[] = _T("- Invalid format of beginning of membership.");
573 if (!checkdate($beg_membership[1], $beg_membership[0], $now['year'])) {
574 $this->errors
[] = _T("- Invalid date for beginning of membership.");
578 case 'pref_membership_offermonths':
579 if (!is_numeric($value) ||
$value < 0) {
580 $this->errors
[] = _T("- Invalid number of offered months.");
583 case 'pref_card_year':
584 if ($value !== 'DEADLINE' && !preg_match('/^(?:\d{4}|\d{2})(\D?)(?:\d{4}|\d{2})$/', $value)) {
585 $this->errors
[] = _T("- Invalid year for cards.");
591 $insert_values[$fieldname] = $value;
596 GALETTE_MODE
!== 'DEMO'
597 && isset($insert_values['pref_mail_method'])
599 if ($insert_values['pref_mail_method'] > GaletteMail
::METHOD_DISABLED
) {
601 !isset($insert_values['pref_email_nom'])
602 ||
$insert_values['pref_email_nom'] == ''
604 $this->errors
[] = _T("- You must indicate a sender name for emails!");
607 !isset($insert_values['pref_email'])
608 ||
$insert_values['pref_email'] == ''
610 $this->errors
[] = _T("- You must indicate an email address Galette should use to send emails!");
612 if ($insert_values['pref_mail_method'] == GaletteMail
::METHOD_SMTP
) {
614 !isset($insert_values['pref_mail_smtp_host'])
615 ||
$insert_values['pref_mail_smtp_host'] == ''
617 $this->errors
[] = _T("- You must indicate the SMTP server you want to use!");
621 $insert_values['pref_mail_method'] == GaletteMail
::METHOD_GMAIL
622 ||
($insert_values['pref_mail_method'] == GaletteMail
::METHOD_SMTP
623 && $insert_values['pref_mail_smtp_auth'])
626 !isset($insert_values['pref_mail_smtp_user'])
627 ||
trim($insert_values['pref_mail_smtp_user']) == ''
629 $this->errors
[] = _T("- You must provide a login for SMTP authentication.");
632 !isset($insert_values['pref_mail_smtp_password'])
633 ||
($insert_values['pref_mail_smtp_password']) == ''
635 $this->errors
[] = _T("- You must provide a password for SMTP authentication.");
642 isset($insert_values['pref_beg_membership'])
643 && $insert_values['pref_beg_membership'] != ''
644 && isset($insert_values['pref_membership_ext'])
645 && $insert_values['pref_membership_ext'] != ''
647 $this->errors
[] = _T("- Default membership extention and beginning of membership are mutually exclusive.");
651 isset($insert_values['pref_membership_offermonths'])
652 && (int)$insert_values['pref_membership_offermonths'] > 0
653 && isset($insert_values['pref_membership_ext'])
654 && $insert_values['pref_membership_ext'] != ''
656 $this->errors
[] = _T("- Offering months is only compatible with beginning of membership.");
659 // missing required fields?
660 foreach ($this->required
as $val) {
661 if (!isset($values[$val]) ||
isset($values[$val]) && trim($values[$val]) == '') {
662 $this->errors
[] = str_replace(
665 _T("- Mandatory field %field empty.")
670 if (GALETTE_MODE
!== 'DEMO' && isset($values['pref_admin_pass_check'])) {
671 // Check passwords. Hash will be done into the Preferences class
672 if (strcmp($insert_values['pref_admin_pass'], $values['pref_admin_pass_check']) != 0) {
673 $this->errors
[] = _T("Passwords mismatch");
678 if (isset($insert_values['pref_postal_adress'])) {
679 $value = $insert_values['pref_postal_adress'];
680 if ($value == Preferences
::POSTAL_ADDRESS_FROM_PREFS
) {
681 if (isset($insert_values['pref_postal_staff_member'])) {
682 unset($insert_values['pref_postal_staff_member']);
684 } elseif ($value == Preferences
::POSTAL_ADDRESS_FROM_STAFF
) {
685 if (!isset($value) ||
$value < 1) {
686 $this->errors
[] = _T("You have to select a staff member");
691 // update preferences
692 foreach ($insert_values as $champ => $valeur) {
694 $login->isSuperAdmin()
695 ||
(!$login->isSuperAdmin()
696 && ($champ != 'pref_admin_pass' && $champ != 'pref_admin_login'))
699 ($champ == "pref_admin_pass" && $_POST['pref_admin_pass'] != '')
700 ||
($champ != "pref_admin_pass")
702 $this->$champ = $valeur;
707 return 0 === count($this->errors
);
711 * Will store all preferences in the database
715 public function store()
718 $this->zdb
->connection
->beginTransaction();
719 $update = $this->zdb
->update(self
::TABLE
);
722 'val_pref' => ':val_pref'
724 )->where
->equalTo('nom_pref', ':nom_pref');
726 $stmt = $this->zdb
->sql
->prepareStatementForSqlObject($update);
728 foreach (self
::$defaults as $k => $v) {
730 GALETTE_MODE
== 'DEMO'
731 && in_array($k, ['pref_admin_pass', 'pref_admin_login', 'pref_mail_method'])
735 Analog
::log('Storing ' . $k, Analog
::DEBUG
);
737 $value = $this->prefs
[$k];
738 //do not store pdf_adhesion_form, it's designed to be overriden by plugin
739 if ($k === 'pref_adhesion_form') {
740 if (trim($v) == '') {
741 //Reset to default, should not be empty
742 $v = self
::$defaults['pref_adhesion_form'];
749 'val_pref' => $value,
754 $this->zdb
->connection
->commit();
756 'Preferences were successfully stored into database.',
760 } catch (\Exception
$e) {
761 $this->zdb
->connection
->rollBack();
765 $messages[] = $e->getMessage();
766 } while ($e = $e->getPrevious());
769 'Unable to store preferences | ' . print_r($messages, true),
777 * Returns postal address
779 * @return string postal address
781 public function getPostalAddress()
792 $replacements = null;
794 if ($this->prefs
['pref_postal_adress'] == self
::POSTAL_ADDRESS_FROM_PREFS
) {
795 $_address = $this->prefs
['pref_adresse'];
796 if ($this->prefs
['pref_adresse2'] && $this->prefs
['pref_adresse2'] != '') {
797 $_address .= "\n" . $this->prefs
['pref_adresse2'];
799 $replacements = array(
800 $this->prefs
['pref_nom'],
803 $this->prefs
['pref_cp'],
804 $this->prefs
['pref_ville'],
805 $this->prefs
['pref_pays']
808 //get selected staff member address
809 $adh = new Adherent($this->zdb
, (int)$this->prefs
['pref_postal_staff_member']);
810 $_complement = preg_replace(
811 array('/%name/', '/%status/'),
812 array($this->prefs
['pref_nom'], $adh->sstatus
),
813 _T("%name association's %status")
815 $_address = $adh->address
;
816 if ($adh->address_continuation
&& $adh->address_continuation
!= '') {
817 $_address .= "\n" . $adh->address_continuation
;
819 $replacements = array(
820 $adh->sfullname
. "\n",
829 /*FIXME: i18n fails :/ */
833 _T("%name\n%complement\n%address\n%zip %town - %country")
838 "%name%complement%address\n%zip %town - %country"
844 * Are public pages visibles?
846 * @param Authentication $login Authenticaqtion instance
850 public function showPublicPages(Authentication
$login)
852 if ($this->prefs
['pref_bool_publicpages']) {
853 //if public pages are actives, let's check if we
854 //display them for curent call
855 switch ($this->prefs
['pref_publicpages_visibility']) {
856 case self
::PUBLIC_PAGES_VISIBILITY_PUBLIC
:
857 //pages are publically visibles
860 case self
::PUBLIC_PAGES_VISIBILITY_RESTRICTED
:
861 //pages should be displayed only for up to date members
872 case self
::PUBLIC_PAGES_VISIBILITY_PRIVATE
:
873 //pages should be displayed only for staff and admins
874 if ($login->isAdmin() ||
$login->isStaff()) {
881 //should never be there
891 * Global getter method
893 * @param string $name name of the property we want to retrive
895 * @return false|object the called property
897 public function __get($name)
899 $forbidden = array('defaults');
900 $virtuals = array('vpref_email_newadh');
902 if (!in_array($name, $forbidden) && isset($this->prefs
[$name])) {
904 GALETTE_MODE
=== 'DEMO'
905 && $name == 'pref_mail_method'
907 return GaletteMail
::METHOD_DISABLED
;
909 if ($name == 'pref_adhesion_form' && $this->prefs
[$name] == '') {
910 $this->prefs
[$name] = self
::$defaults['pref_adhesion_form'];
912 $value = $this->prefs
[$name];
913 if (TYPE_DB
=== \Galette\Core\Db
::PGSQL
) {
914 if ($value === 'f') {
919 if (in_array($name, ['pref_email_newadh'])) {
920 $values = explode(',', $value);
921 $value = $values[0]; //take first as default
926 } elseif (in_array($name, $virtuals)) {
927 $virtual = str_replace('vpref_', 'pref_', $name);
928 return explode(',', $this->prefs
[$virtual]);
931 'Preference `' . $name . '` is not set or is forbidden',
939 * Get default preferences
943 public function getDefaults()
945 return self
::$defaults;
949 * Global setter method
951 * @param string $name name of the property we want to assign a value to
952 * @param object $value a relevant value for the property
956 public function __set($name, $value)
958 //does this pref exists ?
959 if (!array_key_exists($name, self
::$defaults)) {
961 'Trying to set a preference value which does not seem to exist ('
969 $name == 'pref_email'
970 ||
$name == 'pref_email_newadh'
971 ||
$name == 'pref_email_reply_to'
973 if (GALETTE_MODE
=== 'DEMO') {
975 'Trying to set pref_email while in DEMO.',
981 //check emails validity
982 //may be a comma separated list of valid emails identifiers:
983 //"The Name <mail@domain.com>,The Other <other@mail.com>" expect for reply_to.
985 if (trim($value) != '') {
986 if ($name == 'pref_email_newadh') {
987 $addresses = explode(',', $value);
989 $addresses = [$value];
992 foreach ($addresses as $address) {
993 if (!GaletteMail
::isValidEmail($address)) {
994 $msg = str_replace('%s', $address, _T("Invalid E-Mail address: %s"));
995 Analog
::log($msg, Analog
::WARNING
);
996 $this->errors
[] = $msg;
1001 //some values need to be changed (eg. passwords)
1002 if ($name == 'pref_admin_pass') {
1003 $value = password_hash($value, PASSWORD_BCRYPT
);
1006 //okay, let's update value
1007 $this->prefs
[$name] = $value;
1011 * Get instance URL from configuration (if set) or guessed if not
1015 public function getURL()
1018 if (isset($this->prefs
['pref_galette_url']) && !empty($this->prefs
['pref_galette_url'])) {
1019 $url = $this->prefs
['pref_galette_url'];
1021 $url = $this->getDefaultURL();
1027 * Get default URL (when not setted by user in preferences)
1031 public function getDefaultURL()
1033 $scheme = (isset($_SERVER['HTTPS']) ?
'https' : 'http');
1034 $uri = $scheme . '://' . $_SERVER['HTTP_HOST'];
1039 * Check member cards sizes
1040 * Always a A4/portrait
1044 public function checkCardsSizes()
1046 $warning_detected = [];
1050 $size = $this->pref_card_marges_h
* 2;
1052 $size +
= PdfMembersCards
::getWidth() * PdfMembersCards
::getCols();
1054 $size +
= $this->pref_card_hspace
* (PdfMembersCards
::getCols() - 1);
1056 $warning_detected[] = _T('Current cards configuration may exceed page width!');
1061 $size = $this->pref_card_marges_v
* 2;
1063 $size +
= PdfMembersCards
::getHeight() * PdfMembersCards
::getRows();
1065 $size +
= $this->pref_card_vspace
* (PdfMembersCards
::getRows() - 1);
1067 $warning_detected[] = _T('Current cards configuration may exceed page height!');
1070 return $warning_detected;
1078 public function getErrors()
1080 return $this->errors
;