5 ** This contains functions for manipulating user preferences
10 if (defined('prefs_php'))
12 define('prefs_php', true);
14 global $prefs_are_cached, $prefs_cache;
15 $prefs_are_cached = false;
16 $prefs_cache = array();
18 function cachePrefValues($data_dir, $username)
20 global $prefs_are_cached, $prefs_cache;
22 if ($prefs_are_cached)
25 $filename = $data_dir . $username . '.pref';
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);
32 $file = fopen($filename, "r");
34 /** read in all the preferences **/
36 while (! feof($file)) {
37 $pref = trim(fgets($file, 1024));
38 $equalsAt = strpos($pref, '=');
41 $Key = substr($pref, 0, $equalsAt);
42 $Value = substr($pref, $equalsAt +
1);
43 if (substr($Key, 0, 9) == 'highlight')
45 $Key = 'highlight' . $highlight_num;
50 $prefs_cache[$Key] = $Value;
55 $prefs_are_cached = true;
59 /** returns the value for $string **/
60 function getPref($data_dir, $username, $string) {
63 cachePrefValues($data_dir, $username);
65 if (isset($prefs_cache[$string]))
66 return $prefs_cache[$string];
71 function savePrefValues($data_dir, $username)
75 $file = fopen($data_dir . $username . '.pref', "w");
76 foreach ($prefs_cache as $Key => $Value)
79 fwrite($file, $Key . '=' . $Value . "\n");
85 function removePref($data_dir, $username, $string) {
88 cachePrefValues($data_dir, $username);
90 if (isset($prefs_cache[$string]))
91 unset($prefs_cache[$string]);
93 savePrefValues($data_dir, $username);
96 /** sets the pref, $string, to $set_to **/
97 function setPref($data_dir, $username, $string, $set_to) {
100 cachePrefValues($data_dir, $username);
102 $prefs_cache[$string] = $set_to;
104 savePrefValues($data_dir, $username);
108 /** This checks if there is a pref file, if there isn't, it will
110 function checkForPrefs($data_dir, $username) {
111 $filename = "$data_dir$username.pref";
112 if (!file_exists($filename)) {
113 if (!copy("$data_dir" . "default_pref", $filename)) {
114 echo _("Error opening ") ."$filename";
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);
131 /** Gets the signature **/
132 function getSig($data_dir, $username) {
133 $filename = "$data_dir$username.sig";
135 if (file_exists($filename)) {
136 $file = fopen($filename, "r");
137 while (!feof($file)) {
138 $sig .= fgets($file, 1024);