6
* Copyright (c) 1999-2003 The SquirrelMail Project Team
6
* Copyright (c) 1999-2005 The SquirrelMail Project Team
7
7
* Licensed under the GNU GPL. For full terms see the file COPYING.
9
9
* This contains functions for manipulating user preferences in files
11
* $Id: file_prefs.php,v 1.29 2003/10/28 21:27:46 tassium Exp $
11
* @version $Id: file_prefs.php,v 1.26.2.8 2004/12/27 15:03:43 kink Exp $
12
12
* @package squirrelmail
21
21
function cachePrefValues($data_dir, $username) {
22
22
global $prefs_are_cached, $prefs_cache;
24
sqgetGlobalVar('prefs_are_cached', $prefs_are_cached, SQ_SESSION );
24
25
if ( isset($prefs_are_cached) && $prefs_are_cached) {
26
sqgetGlobalVar('prefs_cache', $prefs_cache, SQ_SESSION );
28
30
sqsession_unregister('prefs_cache');
29
31
sqsession_unregister('prefs_are_cached');
31
33
/* Calculate the filename for the user's preference file */
32
34
$filename = getHashedFile($username, $data_dir, "$username.pref");
92
94
$result = do_hook_function('get_pref_override',array($username,$string));
94
cachePrefValues($data_dir, $username);
95
if (isset($prefs_cache[$string])) {
96
$result = $prefs_cache[$string];
98
$result = do_hook_function('get_pref', array($username,$string));
96
cachePrefValues($data_dir, $username);
97
if (isset($prefs_cache[$string])) {
98
$result = $prefs_cache[$string];
100
$result = do_hook_function('get_pref', array($username,$string));
104
106
return ($result);
110
112
function savePrefValues($data_dir, $username) {
111
113
global $prefs_cache;
113
115
$filename = getHashedFile($username, $data_dir, "$username.pref");
115
117
/* Open the file for writing, or else display an error to the user. */
121
123
foreach ($prefs_cache as $Key => $Value) {
122
124
if (isset($Value)) {
123
if ( @fwrite($file, $Key . '=' . $Value . "\n") === FALSE ) {
125
if ( sq_fwrite($file, $Key . '=' . $Value . "\n") === FALSE ) {
124
126
logout_error( sprintf( _("Preference file, %s, could not be written. Contact your system administrator to resolve this issue.") , $filename . '.tmp') );
143
145
global $prefs_cache;
145
147
cachePrefValues($data_dir, $username);
147
149
if (isset($prefs_cache[$string])) {
148
150
unset($prefs_cache[$string]);
151
153
savePrefValues($data_dir, $username);
183
185
/* Then, check if the file exists. */
184
186
if (!@file_exists($filename) ) {
185
/* First, check the $data_dir for the default preference file. */
188
/* If it does not exist, check for default_prefs */
190
/* First, check legacy locations: data dir */
186
191
if(substr($data_dir,-1) != '/') {
187
192
$data_dir .= '/';
189
194
$default_pref = $data_dir . 'default_pref';
191
/* If it is not there, check the internal data directory. */
196
/* or legacy location: internal data dir */
192
197
if (!@file_exists($default_pref)) {
193
198
$default_pref = SM_PATH . 'data/default_pref';
201
/* If no legacies, check where we'd expect it to be located:
203
if (!@file_exists($default_pref)) {
204
$default_pref = SM_PATH . 'config/default_pref';
196
207
/* Otherwise, report an error. */
197
208
$errTitle = sprintf( _("Error opening %s"), $default_pref );
198
209
if (!is_readable($default_pref)) {
199
$errString = $errTitle . "<br>\n" .
200
_("Default preference file not found or not readable!") . "<br>\n" .
201
_("Please contact your system administrator and report this error.") . "<br>\n";
210
$errString = $errTitle . "<br />\n" .
211
_("Default preference file not found or not readable!") . "<br />\n" .
212
_("Please contact your system administrator and report this error.") . "<br />\n";
202
213
logout_error( $errString, $errTitle );
204
215
} else if (!@copy($default_pref, $filename)) {
207
218
$user_data = posix_getpwuid(posix_getuid());
208
219
$uid = $user_data['name'];
210
$errString = $errTitle . '<br>' .
211
_("Could not create initial preference file!") . "<br>\n" .
221
$errString = $errTitle . '<br />' .
222
_("Could not create initial preference file!") . "<br />\n" .
212
223
sprintf( _("%s should be writable by user %s"), $data_dir, $uid ) .
213
"<br>\n" . _("Please contact your system administrator and report this error.") . "<br>\n";
224
"<br />\n" . _("Please contact your system administrator and report this error.") . "<br />\n";
214
225
logout_error( $errString, $errTitle );
221
232
* Write the User Signature.
223
234
function setSig($data_dir, $username, $number, $value) {
235
// Limit signature size to 64KB (database BLOB limit)
236
if (strlen($value)>65536) {
237
error_option_save(_("Signature is too big."));
224
240
$filename = getHashedFile($username, $data_dir, "$username.si$number");
225
241
/* Open the file for writing, or else display an error to the user. */
226
242
if(!$file = @fopen("$filename.tmp", 'w')) {
227
243
logout_error( sprintf( _("Signature file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename . '.tmp') );
230
if ( @fwrite($file, $value) === FALSE ) {
246
if ( sq_fwrite($file, $value) === FALSE ) {
231
247
logout_error( sprintf( _("Signature file, %s, could not be written. Contact your system administrator to resolve this issue.") , $filename . '.tmp'));