5 ** This contains functions for manipulating user preferences
12 $prefs_are_cached = false;
13 $prefs_cache = array();
15 function cachePrefValues($data_dir, $username)
17 global $prefs_are_cached, $prefs_cache;
19 if ($prefs_are_cached)
22 $filename = $data_dir . $username . '.pref';
24 if (!file_exists($filename)) {
25 printf (_("Preference file, %s, does not exist. Log out, and log back in to create a default preference file."), $filename);
29 $file = fopen($filename, "r");
31 /** read in all the preferences **/
33 while (! feof($file)) {
34 $pref = trim(fgets($file, 1024));
35 $equalsAt = strpos($pref, '=');
38 $Key = substr($pref, 0, $equalsAt);
39 $Value = substr($pref, $equalsAt +
1);
40 if (substr($Key, 0, 9) == 'highlight')
42 $Key = 'highlight' . $highlight_num;
47 $prefs_cache[$Key] = $Value;
52 $prefs_are_cached = true;
56 /** returns the value for $string **/
57 function getPref($data_dir, $username, $string) {
60 cachePrefValues($data_dir, $username);
62 if (isset($prefs_cache[$string]))
63 return $prefs_cache[$string];
68 function savePrefValues($data_dir, $username)
72 $file = fopen($data_dir . $username . '.pref', "w");
73 foreach ($prefs_cache as $Key => $Value)
76 fwrite($file, $Key . '=' . $Value . "\n");
82 function removePref($data_dir, $username, $string) {
85 cachePrefValues($data_dir, $username);
87 if (isset($prefs_cache[$string]))
88 unset($prefs_cache[$string]);
90 savePrefValues($data_dir, $username);
93 /** sets the pref, $string, to $set_to **/
94 function setPref($data_dir, $username, $string, $set_to) {
97 cachePrefValues($data_dir, $username);
99 $prefs_cache[$string] = $set_to;
101 savePrefValues($data_dir, $username);
105 /** This checks if there is a pref file, if there isn't, it will
107 function checkForPrefs($data_dir, $username) {
108 $filename = "$data_dir$username.pref";
109 if (!file_exists($filename)) {
110 if (!copy("$data_dir" . "default_pref", $filename)) {
111 echo _("Error opening ") ."$filename";
118 /** Writes the Signature **/
119 function setSig($data_dir, $username, $string) {
120 $filename = "$data_dir$username.sig";
121 $file = fopen($filename, "w");
122 fwrite($file, $string);
128 /** Gets the signature **/
129 function getSig($data_dir, $username) {
130 $filename = "$data_dir$username.sig";
132 if (file_exists($filename)) {
133 $file = fopen($filename, "r");
134 while (!feof($file)) {
135 $sig .= fgets($file, 1024);