-
Notifications
You must be signed in to change notification settings - Fork 0
/
preferences.php
446 lines (417 loc) · 16 KB
/
preferences.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Preferences choice.
*
* Préferences contains the following groups:
* - Association: global parameters (logo, adress, etc.)
* - Galette: software usage preferences
* - Email: sender and responseto email adresses
* - Labels: labels format (margins, sizes, etc.)
* - Members cards: format for member cards
* - Admin account: super-admin parameters : only available for super-admin user
*
* PHP version 5
*
* Copyright © 2004-2014 The Galette Team
*
* This file is part of Galette (http://galette.tuxfamily.org).
*
* Galette is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Galette is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*
* @category Main
* @package Galette
*
* @author Frédéric Jaqcuot <unknown@unknow.com>
* @author Johan Cwiklinski <johan@x-tnd.be>
* @copyright 2004-2014 The Galette Team
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
* @version SVN: $Id$
* @link http://galette.tuxfamily.org
* @since Available since 0.62
*/
use Galette\Core;
use Analog\Analog;
/** @ignore */
require_once 'includes/galette.inc.php';
if ( !$login->isLogged() ) {
header('location: index.php');
die();
}
if ( !$login->isAdmin() && !$login->isStaff() ) {
header('location: voir_adherent.php');
die();
} elseif ( !$login->isAdmin() ) {
header('location: gestion_adherents.php');
die();
}
$print_logo = new Core\PrintLogo();
// flagging required fields
$required = array(
'pref_nom' => 1,
'pref_lang' => 1,
'pref_numrows' => 1,
'pref_log' => 1,
'pref_etiq_marges_v' => 1,
'pref_etiq_marges_h' => 1,
'pref_etiq_hspace' => 1,
'pref_etiq_vspace' => 1,
'pref_etiq_hsize' => 1,
'pref_etiq_vsize' => 1,
'pref_etiq_cols' => 1,
'pref_etiq_rows' => 1,
'pref_etiq_corps' => 1,
'pref_card_abrev' => 1,
'pref_card_strip' => 1,
'pref_card_marges_v' => 1,
'pref_card_marges_h' => 1,
'pref_card_hspace' => 1,
'pref_card_vspace' => 1
);
if ( $login->isSuperAdmin() ) {
$required['pref_admin_login'] = 1;
}
if ( GALETTE_MODE === 'DEMO' ) {
unset($required['pref_admin_login']);
}
$prefs_fields = $preferences->getFieldsNames();
// Validation
if ( isset($_POST['valid']) && $_POST['valid'] == '1' ) {
// verification de champs
$insert_values = array();
// obtain fields
foreach ($prefs_fields as $fieldname ) {
if (isset($_POST[$fieldname])) {
$value=trim($_POST[$fieldname]);
} else {
$value="";
}
// now, check validity
if ( $value != '' ) {
switch ( $fieldname ) {
case 'pref_email':
if ( GALETTE_MODE === 'DEMO' ) {
Analog::log(
'Trying to set pref_email while in DEMO.',
Analog::WARNING
);
} else {
if ( !Core\GaletteMail::isValidEmail($value) ) {
$error_detected[] = _T("- Non-valid E-Mail address!");
}
}
break;
case 'pref_admin_login':
if ( GALETTE_MODE === 'DEMO' ) {
Analog::log(
'Trying to set superadmin login while in DEMO.',
Analog::WARNING
);
} else {
if ( strlen($value) < 4 ) {
$error_detected[] = _T("- The username must be composed of at least 4 characters!");
} else {
//check if login is already taken
if ( $login->loginExists($value) ) {
$error_detected[] = _T("- This username is already in use, please choose another one!");
}
}
}
break;
case 'pref_numrows':
if ( !is_numeric($value) || $value < 0 ) {
$error_detected[] = "<li>"._T("- The numbers and measures have to be integers!")."</li>";
}
break;
case 'pref_etiq_marges_h':
case 'pref_etiq_marges_v':
case 'pref_etiq_hspace':
case 'pref_etiq_vspace':
case 'pref_etiq_hsize':
case 'pref_etiq_vsize':
case 'pref_etiq_cols':
case 'pref_etiq_rows':
case 'pref_etiq_corps':
case 'pref_card_marges_v':
case 'pref_card_marges_h':
case 'pref_card_hspace':
case 'pref_card_vspace':
// prevent division by zero
if ( $fieldname=='pref_numrows' && $value=='0' ) {
$value = '10';
}
if ( !is_numeric($value) || $value < 0 ) {
$error_detected[] = _T("- The numbers and measures have to be integers!");
}
break;
case 'pref_card_tcol':
// Set strip text color to white
if ( ! preg_match("/#([0-9A-F]{6})/i", $value) ) {
$value = '#FFFFFF';
}
break;
case 'pref_card_scol':
case 'pref_card_bcol':
case 'pref_card_hcol':
// Set strip background colors to black
if ( !preg_match("/#([0-9A-F]{6})/i", $value) ) {
$value = '#000000';
}
break;
case 'pref_admin_pass':
if ( GALETTE_MODE == 'DEMO' ) {
Analog::log(
'Trying to set superadmin pass while in DEMO.',
Analog::WARNING
);
} else {
if ( strlen($value) < 4 ) {
$error_detected[] = _T("- The password must be of at least 4 characters!");
}
}
break;
case 'pref_membership_ext':
if ( !is_numeric($value) || $value < 0 ) {
$error_detected[] = _T("- Invalid number of months of membership extension.");
}
break;
case 'pref_beg_membership':
$beg_membership = explode("/", $value);
if ( count($beg_membership) != 2 ) {
$error_detected[] = _T("- Invalid format of beginning of membership.");
} else {
$now = getdate();
if ( !checkdate($beg_membership[1], $beg_membership[0], $now['year']) ) {
$error_detected[] = _T("- Invalid date for beginning of membership.");
}
}
break;
}
}
// fill up pref structure (after $value's modifications)
$pref[$fieldname] = stripslashes($value);
$insert_values[$fieldname] = $value;
}
// missing relations
if ( GALETTE_MODE !== 'DEMO' && isset($insert_values['pref_mail_method']) ) {
if ( $insert_values['pref_mail_method'] > Core\GaletteMail::METHOD_DISABLED ) {
if ( !isset($insert_values['pref_email_nom'])
|| $insert_values['pref_email_nom'] == ''
) {
$error_detected[] = _T("- You must indicate a sender name for emails!");
}
if ( !isset($insert_values['pref_email'])
|| $insert_values['pref_email'] == ''
) {
$error_detected[] = _T("- You must indicate an email address Galette should use to send emails!");
}
if ( $insert_values['pref_mail_method'] == Core\GaletteMail::METHOD_SMTP ) {
if ( !isset($insert_values['pref_mail_smtp_host'])
|| $insert_values['pref_mail_smtp_host'] == ''
) {
$error_detected[] = _T("- You must indicate the SMTP server you want to use!");
}
}
if ( $insert_values['pref_mail_method'] == Core\GaletteMail::METHOD_GMAIL
|| ( $insert_values['pref_mail_method'] == Core\GaletteMail::METHOD_SMTP
&& $insert_values['pref_mail_smtp_auth'] )
) {
if ( !isset($insert_values['pref_mail_smtp_user'])
|| trim($insert_values['pref_mail_smtp_user']) == ''
) {
$error_detected[] = _T("- You must provide a login for SMTP authentication.");
}
if ( !isset($insert_values['pref_mail_smtp_password'])
|| ($insert_values['pref_mail_smtp_password']) == ''
) {
$error_detected[] = _T("- You must provide a password for SMTP authentication.");
}
}
}
}
if ( isset($insert_values['pref_beg_membership'])
&& $insert_values['pref_beg_membership'] != ''
&& isset($insert_values['pref_membership_ext'])
&& $insert_values['pref_membership_ext'] != ''
) {
$error_detected[] = _T("- Default membership extention and beginning of membership are mutually exclusive.");
}
// missing required fields?
while ( list($key, $val) = each($required) ) {
if ( !isset($pref[$key]) ) {
$error_detected[] = _T("- Mandatory field empty.")." ".$key;
} elseif ( isset($pref[$key]) ) {
if (trim($pref[$key])=='') {
$error_detected[] = _T("- Mandatory field empty.")." ".$key;
}
}
}
if (GALETTE_MODE !== 'DEMO' && $login->isSuperAdmin() ) {
// Check passwords. Hash will be done into the Preferences class
if ( strcmp(
$insert_values['pref_admin_pass'],
$_POST['pref_admin_pass_check']
) != 0 ) {
$error_detected[] = _T("Passwords mismatch");
}
}
//postal adress
if ( isset($insert_values['pref_postal_adress']) ) {
$value = $insert_values['pref_postal_adress'];
if ( $value == Core\Preferences::POSTAL_ADRESS_FROM_PREFS ) {
if ( isset($insert_values['pref_postal_staff_member']) ) {
unset($insert_values['pref_postal_staff_member']);
}
} else if ( $value == Core\Preferences::POSTAL_ADRESS_FROM_STAFF ) {
if ( !isset($value) || $value < 1 ) {
$error_detected[] = _T("You have to select a staff member");
}
}
}
if ( count($error_detected) == 0 ) {
// update preferences
while ( list($champ,$valeur) = each($insert_values) ) {
if ( $login->isSuperAdmin()
|| (!$login->isSuperAdmin()
&& ($champ != 'pref_admin_pass' && $champ != 'pref_admin_login'))
) {
if ( ($champ == "pref_admin_pass"
&& $_POST['pref_admin_pass'] != '')
|| ($champ != "pref_admin_pass")
) {
$preferences->$champ = $valeur;
}
}
}
//once all values has been updated, we can store them
if ( !$preferences->store() ) {
$error_detected[] = _T("An SQL error has occured while storing preferences. Please try again, and contact the administrator if the problem persists.");
} else {
$success_detected[] = _T("Preferences has been saved.");
}
// picture upload
if ( GALETTE_MODE !== 'DEMO' && isset($_FILES['logo']) ) {
if ( $_FILES['logo']['error'] === UPLOAD_ERR_OK ) {
if ( $_FILES['logo']['tmp_name'] !='' ) {
if ( is_uploaded_file($_FILES['logo']['tmp_name']) ) {
$res = $logo->store($_FILES['logo']);
if ( $res < 0 ) {
$error_detected[] = $logo->getErrorMessage($res);
} else {
$logo = new Core\Logo();
}
$session['logo'] = serialize($logo);
$tpl->assign('logo', $logo);
}
}
} else if ($_FILES['logo']['error'] !== UPLOAD_ERR_NO_FILE) {
Analog::log(
$logo->getPhpErrorMessage($_FILES['logo']['error']),
Analog::WARNING
);
$error_detected[] = $logo->getPhpErrorMessage(
$_FILES['logo']['error']
);
}
}
if ( GALETTE_MODE !== 'DEMO' && isset($_POST['del_logo']) ) {
if ( !$logo->delete() ) {
$error_detected[] = _T("Delete failed");
} else {
$logo = new Core\Logo(); //get default Logo
$session['logo'] = serialize($logo);
$tpl->assign('logo', $logo);
}
}
// Card logo upload
if ( GALETTE_MODE !== 'DEMO' && isset($_FILES['card_logo']) ) {
if ( $_FILES['card_logo']['error'] === UPLOAD_ERR_OK ) {
if ( $_FILES['card_logo']['tmp_name'] !='' ) {
if ( is_uploaded_file($_FILES['card_logo']['tmp_name']) ) {
$res = $print_logo->store($_FILES['card_logo']);
if ( $res < 0 ) {
$error_detected[] = $print_logo->getErrorMessage($res);
} else {
$print_logo = new Core\PrintLogo();
}
}
}
} else if ($_FILES['card_logo']['error'] !== UPLOAD_ERR_NO_FILE) {
Analog::log(
$print_logo->getPhpErrorMessage($_FILES['card_logo']['error']),
Analog::WARNING
);
$error_detected[] = $print_logo->getPhpErrorMessage(
$_FILES['card_logo']['error']
);
}
}
if ( GALETTE_MODE !== 'DEMO' && isset($_POST['del_card_logo']) ) {
if ( !$print_logo->delete() ) {
$error_detected[] = _T("Delete failed");
} else {
$print_logo = new Core\PrintLogo();
}
}
}
} else {
// collect data
foreach ( $prefs_fields as $fieldname ) {
$pref[$fieldname] = $preferences->$fieldname;
}
}
//List available themes
$themes = array();
$d = dir(GALETTE_TEMPLATES_PATH);
while ( ($entry = $d->read()) !== false ) {
$full_entry = GALETTE_TEMPLATES_PATH . $entry;
if ($entry != '.'
&& $entry != '..'
&& is_dir($full_entry)
&& file_exists($full_entry.'/page.tpl')
) {
$themes[] = $entry;
}
}
$d->close();
$m = new Galette\Repository\Members();
$tpl->assign('staff_members', $m->getStaffMembersList(true));
$tpl->assign('time', time());
$tpl->assign('pref', $pref);
$tpl->assign(
'pref_numrows_options',
array(
10 => '10',
20 => '20',
50 => '50',
100 => '100'
)
);
$tpl->assign('page_title', _T("Settings"));
$tpl->assign('print_logo', $print_logo);
$tpl->assign('required', $required);
$tpl->assign('languages', $i18n->getList());
$tpl->assign('themes', $themes);
$tpl->assign('error_detected', $error_detected);
$tpl->assign('warning_detected', $warning_detected);
$tpl->assign('success_detected', $success_detected);
$tpl->assign('require_tabs', true);
$tpl->assign('color_picker', true);
// page generation
$content = $tpl->fetch('preferences.tpl');
$tpl->assign('content', $content);
$tpl->display('page.tpl');
if ( isset($profiler) ) {
$profiler->stop();
}