-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathprocessPreferences.php
89 lines (70 loc) · 2.97 KB
/
processPreferences.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
<?php
function cleanpref($field) {
return str_replace(array("\\","\x00","\n","\r","'",'"',"\x1a"),'',$field);
}
$_SESSION['config']['title']='Updating preferences'; // force it to be non-blank to avoid unnecessary options retrieval in headerDB
require_once 'headerDB.inc.php';
ignore_user_abort(true);
if (isset($_REQUEST['restoredefaults'])) {
$_SESSION['message'][]= (importOldConfig())
? 'Reverted to default preferences'
: 'Failed to find default preferences in either config.php or defaultconfig.inc.php';
nextScreen('preferences.php');
exit;
}
$newPrefs=$_POST;
unset($newPrefs['submit']);
// for each checkbox: if value is set at all, set to TRUE, otherwise set to FALSE
$checkboxes=explode(',',$newPrefs['checkboxes']);
unset($newPrefs['checkboxes']);
array_pop($checkboxes);
foreach ($checkboxes as $val)
$newPrefs[$val]=(isset($newPrefs[$val]));
// some variables are stored as cookies locally, rather than in the db
$cookievars=array('theme','useLiveEnhancements');
foreach ($cookievars as $key) {
$val=$_SESSION[$key]=$newPrefs[$key];
setcookie($key,$val,time()+160000000); // = roughly 4 years to cookie expiry
}
if ($_SESSION['debug']['debug']) {
include 'headerHtml.inc.php';
echo '</head><body>';
log_array('$_POST','$_SESSION');
$html=true;
} else $html=false;
$_SESSION['addons']=$_SESSION['debug']=$_SESSION['sort']=$_SESSION['keys']=
$_SESSION['config']=array();
/* -------------------------------------------------------------------
apply the preferences to this session
*/
foreach ($newPrefs as $key=>$val) {
switch (substr($key,0,4)) {
case 'addo': // addon activated
if ($val) getEvents(substr($key,6));
break;
case 'debu': // set one of the debug controls
$_SESSION['debug'][substr($key,5)]=$val;
break;
case 'keys': // assign a shortcut key
if (!empty($val))
$_SESSION['keys'][$_POST["l$key"]]=$val;
break;
case 'lkey': // value is used when assigning keys, no processing needed here
break;
case 'sort': // sorting tables in listItems, reportContext, etc
$_SESSION['sort'][substr($key,4)]=cleanpref($val);
break;
default: // standard config item
$_SESSION['config'][$key]=$val;
break;
}
}
$_SESSION['config']['separator']=cleanpref($_SESSION['config']['separator']);
if (strtolower($_SESSION['config']['charset'])==='utf-8') checkUTF8();
checkConfigFields();
log_value('Changed preferences stored in session:',$_SESSION);
$result=saveConfig(); // store preferences in the table
$_SESSION['message'][]= ($result) ? 'Preferences updated' : 'No changes made to preferences stored in database';
nextScreen('index.php');
if ($html) echo '</body></html>';
// php closing tag has been omitted deliberately, to avoid unwanted blank lines being sent to the browser