5 ** This contains functions for manipulating user preferences
10 /** returns the value for $string **/
11 function getPref($data_dir, $username, $string) {
12 $filename = "$data_dir$username.pref";
13 if (!file_exists($filename)) {
14 echo _("Preference file ") . "\"$filename\"" . _(" not found. Exiting abnormally");
18 $file = fopen($filename, "r");
20 /** read in all the preferences **/
21 for ($i=0; !feof($file); $i++
) {
22 $pref = fgets($file, 1024);
23 if (substr($pref, 0, strpos($pref, "=")) == $string) {
25 return trim(substr($pref, strpos($pref, "=")+
1));
32 /** sets the pref, $string, to $set_to **/
33 function setPref($data_dir, $username, $string, $set_to) {
34 $filename = "$data_dir$username.pref";
36 if (!file_exists($filename)) {
37 echo _("Preference file, ") . "\"$filename\"" . _(", does not exist. Log out, and log back in to create a default preference file. ") ."<BR>";
40 $file = fopen($filename, "r");
42 /** read in all the preferences **/
43 for ($i=0; !feof($file); $i++
) {
44 $pref[$i] = fgets($file, 1024);
45 if (substr($pref[$i], 0, strpos($pref[$i], "=")) == $string) {
52 $file = fopen($filename, "w");
54 for ($i=0; $i < count($pref); $i++
) {
56 fwrite($file, "$string=$set_to\n", 1024);
58 fwrite($file, "$pref[$i]", 1024);
62 for ($i=0; $i < count($pref); $i++
) {
63 fwrite($file, "$pref[$i]", 1024);
65 fwrite($file, "$string=$set_to\n", 1024);
74 /** This checks if there is a pref file, if there isn't, it will
76 function checkForPrefs($data_dir, $username) {
77 $filename = "$data_dir$username.pref";
78 if (!file_exists($filename)) {
79 if (!copy("$data_dir" . "default_pref", $filename)) {
80 echo _("Error opening ") ."$filename";
89 /** Writes the Signature **/
90 function setSig($data_dir, $username, $string) {
91 $filename = "$data_dir$username.sig";
92 $file = fopen($filename, "w");
93 fwrite($file, $string);
99 /** Gets the signature **/
100 function getSig($data_dir, $username) {
101 $filename = "$data_dir$username.sig";
102 if (file_exists($filename)) {
103 $file = fopen($filename, "r");
104 while (!feof($file)) {
105 $sig .= fgets($file, 1024);
109 echo _("Signature file not found.");