5 ** This contains functions for manipulating user preferences
8 /** returns the value for $string **/
9 function getPref($data_dir, $username, $string) {
10 $filename = "$data_dir$username.pref";
11 if (!file_exists($filename)) {
12 echo "Preference file \"$filename\" not found. Exiting abnormally";
16 $file = fopen($filename, "r");
18 /** read in all the preferences **/
19 for ($i=0; !feof($file); $i++
) {
20 $pref = fgets($file, 1024);
21 if (substr($pref, 0, strpos($pref, "=")) == $string) {
23 return trim(substr($pref, strpos($pref, "=")+
1));
30 /** sets the pref, $string, to $set_to **/
31 function setPref($data_dir, $username, $string, $set_to) {
32 $filename = "$data_dir$username.pref";
34 if (!file_exists($filename)) {
35 echo "Preference file, $filename, does not exist. Log out, and log back in to create a default preference file.<BR>";
38 $file = fopen($filename, "r");
40 /** read in all the preferences **/
41 for ($i=0; !feof($file); $i++
) {
42 $pref[$i] = fgets($file, 1024);
43 if (substr($pref[$i], 0, strpos($pref[$i], "=")) == $string) {
50 $file = fopen($filename, "w");
52 for ($i=0; $i < count($pref); $i++
) {
54 fwrite($file, "$string=$set_to\n", 1024);
56 fwrite($file, "$pref[$i]", 1024);
60 for ($i=0; $i < count($pref); $i++
) {
61 fwrite($file, "$pref[$i]", 1024);
63 fwrite($file, "$string=$set_to\n", 1024);
72 /** This checks if there is a pref file, if there isn't, it will create it. **/
73 function checkForPrefs($data_dir, $username) {
74 $filename = "$data_dir$username.pref";
75 if (!file_exists($filename)) {
76 if (!copy("$data_dir" . "default_pref", $filename)) {
77 echo "Error opening $filename";
86 /** Writes the Signature **/
87 function setSig($data_dir, $username, $string) {
88 $filename = "$data_dir$username.sig";
89 $file = fopen($filename, "w");
90 fwrite($file, $string);
96 /** Gets the signature **/
97 function getSig($data_dir, $username) {
98 $filename = "$data_dir$username.sig";
99 if (file_exists($filename)) {
100 $file = fopen($filename, "r");
101 while (!feof($file)) {
102 $sig .= fgets($file, 1024);
106 echo "Signature file not found.";