fixed bug that didn't display folders with spaces in the name
[squirrelmail.git] / functions / prefs.php
CommitLineData
59177427 1<?php
65b14f90 2 /**
3 ** prefs.php
4 **
5 ** This contains functions for manipulating user preferences
245a6892 6 **
7 ** $Id$
65b14f90 8 **/
9
f435778e 10 if (defined('prefs_php'))
11 return;
12 define('prefs_php', true);
13
14 global $prefs_are_cached, $prefs_cache;
31ac7db8 15 $prefs_are_cached = false;
16 $prefs_cache = array();
17
18 function cachePrefValues($data_dir, $username)
19 {
20 global $prefs_are_cached, $prefs_cache;
21
22 if ($prefs_are_cached)
23 return;
24
25 $filename = $data_dir . $username . '.pref';
26
27 if (!file_exists($filename)) {
28 printf (_("Preference file, %s, does not exist. Log out, and log back in to create a default preference file."), $filename);
29 exit;
30 }
31
32 $file = fopen($filename, "r");
33
34 /** read in all the preferences **/
35 $highlight_num = 0;
36 while (! feof($file)) {
37 $pref = trim(fgets($file, 1024));
38 $equalsAt = strpos($pref, '=');
39 if ($equalsAt > 0)
40 {
41 $Key = substr($pref, 0, $equalsAt);
42 $Value = substr($pref, $equalsAt + 1);
43 if (substr($Key, 0, 9) == 'highlight')
44 {
45 $Key = 'highlight' . $highlight_num;
46 $highlight_num ++;
47 }
48
49 if ($Value != '')
50 $prefs_cache[$Key] = $Value;
51 }
52 }
53 fclose($file);
54
55 $prefs_are_cached = true;
56 }
57
58
65b14f90 59 /** returns the value for $string **/
d0747e26 60 function getPref($data_dir, $username, $string) {
31ac7db8 61 global $prefs_cache;
62
63 cachePrefValues($data_dir, $username);
64
65 if (isset($prefs_cache[$string]))
66 return $prefs_cache[$string];
67 return '';
65b14f90 68 }
69
44f642f5 70
31ac7db8 71 function savePrefValues($data_dir, $username)
72 {
73 global $prefs_cache;
74
75 $file = fopen($data_dir . $username . '.pref', "w");
76 foreach ($prefs_cache as $Key => $Value)
77 {
78 if (isset($Value))
79 fwrite($file, $Key . '=' . $Value . "\n");
44f642f5 80 }
81 fclose($file);
31ac7db8 82 }
44f642f5 83
44f642f5 84
31ac7db8 85 function removePref($data_dir, $username, $string) {
86 global $prefs_cache;
87
88 cachePrefValues($data_dir, $username);
89
90 if (isset($prefs_cache[$string]))
91 unset($prefs_cache[$string]);
92
93 savePrefValues($data_dir, $username);
44f642f5 94 }
95
65b14f90 96 /** sets the pref, $string, to $set_to **/
d0747e26 97 function setPref($data_dir, $username, $string, $set_to) {
31ac7db8 98 global $prefs_cache;
99
100 cachePrefValues($data_dir, $username);
101
102 $prefs_cache[$string] = $set_to;
65b14f90 103
31ac7db8 104 savePrefValues($data_dir, $username);
65b14f90 105 }
106
f804972b 107
d068c0ec 108 /** This checks if there is a pref file, if there isn't, it will
109 create it. **/
d0747e26 110 function checkForPrefs($data_dir, $username) {
111 $filename = "$data_dir$username.pref";
65b14f90 112 if (!file_exists($filename)) {
8105d00f 113 if (!copy("$data_dir" . "default_pref", $filename)) {
5f29dd3b 114 echo _("Error opening ") ."$filename";
65b14f90 115 exit;
116 }
117 }
65b14f90 118 }
f804972b 119
120
f804972b 121 /** Writes the Signature **/
122 function setSig($data_dir, $username, $string) {
123 $filename = "$data_dir$username.sig";
124 $file = fopen($filename, "w");
125 fwrite($file, $string);
126 fclose($file);
127 }
128
129
130
131 /** Gets the signature **/
132 function getSig($data_dir, $username) {
133 $filename = "$data_dir$username.sig";
a7ea7540 134 $sig = "";
f804972b 135 if (file_exists($filename)) {
136 $file = fopen($filename, "r");
137 while (!feof($file)) {
138 $sig .= fgets($file, 1024);
139 }
140 fclose($file);
f804972b 141 }
142 return $sig;
143 }
5f29dd3b 144?>