5 ** This contains functions for manipulating user preferences
12 /** returns the value for $string **/
13 function getPref($data_dir, $username, $string) {
14 $filename = "$data_dir$username.pref";
15 if (!file_exists($filename)) {
16 printf (_("Preference file %s not found. Exiting abnormally"), $filename);
20 $file = fopen($filename, "r");
22 /** read in all the preferences **/
23 for ($i=0; !feof($file); $i++
) {
24 $pref = fgets($file, 1024);
25 if (substr($pref, 0, strpos($pref, "=")) == $string) {
27 return trim(substr($pref, strpos($pref, "=")+
1));
34 function removePref($data_dir, $username, $string) {
35 $filename = "$data_dir$username.pref";
37 if (!file_exists($filename)) {
38 printf (_("Preference file, %s, does not exist. Log out, and log back in to create a default preference file."), $filename);
42 $file = fopen($filename, "r");
44 for ($i=0; !feof($file); $i++
) {
45 $pref[$i] = fgets($file, 1024);
46 if (substr($pref[$i], 0, strpos($pref[$i], "=")) == $string) {
52 for ($i=0,$j=0; $i < count($pref); $i++
) {
53 if (substr($pref[$i], 0, 9) == "highlight") {
54 $hlt[$j] = substr($pref[$i], strpos($pref[$i], "=")+
1);
59 $file = fopen($filename, "w");
60 for ($i=0; $i < count($pref); $i++
) {
61 if (substr($pref[$i], 0, 9) != "highlight") {
62 fwrite($file, "$pref[$i]", 1024);
66 for ($i=0; $i < count($hlt); $i++
) {
67 fwrite($file, "highlight$i=$hlt[$i]");
73 /** sets the pref, $string, to $set_to **/
74 function setPref($data_dir, $username, $string, $set_to) {
75 $filename = "$data_dir$username.pref";
77 if (!file_exists($filename)) {
78 printf (_("Preference file, %s, does not exist. Log out, and log back in to create a default preference file."), $filename);
82 $file = fopen($filename, "r");
84 /** read in all the preferences **/
85 for ($i=0; !feof($file); $i++
) {
86 $pref[$i] = fgets($file, 1024);
87 if (substr($pref[$i], 0, strpos($pref[$i], "=")) == $string) {
94 $file = fopen($filename, "w");
96 for ($i=0; $i < count($pref); $i++
) {
98 fwrite($file, "$string=$set_to\n", 1024);
100 fwrite($file, "$pref[$i]", 1024);
104 for ($i=0; $i < count($pref); $i++
) {
105 fwrite($file, "$pref[$i]", 1024);
107 fwrite($file, "$string=$set_to\n", 1024);
116 /** This checks if there is a pref file, if there isn't, it will
118 function checkForPrefs($data_dir, $username) {
119 $filename = "$data_dir$username.pref";
120 if (!file_exists($filename)) {
121 if (!copy("$data_dir" . "default_pref", $filename)) {
122 echo _("Error opening ") ."$filename";
130 /** Writes the Signature **/
131 function setSig($data_dir, $username, $string) {
132 $filename = "$data_dir$username.sig";
133 $file = fopen($filename, "w");
134 fwrite($file, $string);
140 /** Gets the signature **/
141 function getSig($data_dir, $username) {
142 $filename = "$data_dir$username.sig";
144 if (file_exists($filename)) {
145 $file = fopen($filename, "r");
146 while (!feof($file)) {
147 $sig .= fgets($file, 1024);