5 ** This contains functions for manipulating user preferences
8 /** returns the value for $string **/
9 function getPref($username, $string) {
10 $filename = "../data/$username.pref";
11 $file = fopen($filename, "r");
13 /** read in all the preferences **/
14 for ($i=0; !feof($file); $i++
) {
15 $pref = fgets($file, 1024);
16 if (substr($pref, 0, strpos($pref, "=")) == $string) {
18 return substr($pref, strpos($pref, "=")+
1);
25 /** sets the pref, $string, to $set_to **/
26 function setPref($username, $string, $set_to) {
27 $filename = "../data/$username.pref";
29 if (!file_exists($filename)) {
30 echo "Preference file, $filename, does not exist. Log out, and log back in to create a default preference file.<BR>";
33 $file = fopen($filename, "r");
35 /** read in all the preferences **/
36 for ($i=0; !feof($file); $i++
) {
37 $pref[$i] = fgets($file, 1024);
38 if (substr($pref[$i], 0, strpos($pref[$i], "=")) == $string) {
45 $file = fopen($filename, "w");
47 for ($i=0; $i < count($pref); $i++
) {
49 fwrite($file, "$string=$set_to\n", 1024);
51 fwrite($file, "$pref[$i]", 1024);
55 for ($i=0; $i < count($pref); $i++
) {
56 fwrite($file, "$pref[$i]", 1024);
58 fwrite($file, "$string=$set_to\n", 1024);
64 /** This checks if there is a pref file, if there isn't, it will create it. **/
65 function checkForPrefs($username) {
66 $filename = "../data/$username.pref";
67 if (!file_exists($filename)) {
68 if (!copy("../data/default_pref", $filename)) {
69 echo "Error opening $filename";