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 printf (_("Preference file %s not found. Exiting abnormally"), $filename);
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 function removePref($data_dir, $username, $string) {
33 $filename = "$data_dir$username.pref";
35 if (!file_exists($filename)) {
36 printf (_("Preference file, %s, does not exist. Log out, and log back in to create a default preference file."), $filename);
40 $file = fopen($filename, "r");
42 for ($i=0; !feof($file); $i++
) {
43 $pref[$i] = fgets($file, 1024);
44 if (substr($pref[$i], 0, strpos($pref[$i], "=")) == $string) {
50 for ($i=0,$j=0; $i < count($pref); $i++
) {
51 if (substr($pref[$i], 0, 9) == "highlight") {
52 $hlt[$j] = substr($pref[$i], strpos($pref[$i], "=")+
1);
57 $file = fopen($filename, "w");
58 for ($i=0; $i < count($pref); $i++
) {
59 if (substr($pref[$i], 0, 9) != "highlight") {
60 fwrite($file, "$pref[$i]", 1024);
63 for ($i=0; $i < count($hlt); $i++
) {
64 fwrite($file, "highlight$i=$hlt[$i]");
70 /** sets the pref, $string, to $set_to **/
71 function setPref($data_dir, $username, $string, $set_to) {
72 $filename = "$data_dir$username.pref";
74 if (!file_exists($filename)) {
75 printf (_("Preference file, %s, does not exist. Log out, and log back in to create a default preference file."), $filename);
79 $file = fopen($filename, "r");
81 /** read in all the preferences **/
82 for ($i=0; !feof($file); $i++
) {
83 $pref[$i] = fgets($file, 1024);
84 if (substr($pref[$i], 0, strpos($pref[$i], "=")) == $string) {
91 $file = fopen($filename, "w");
93 for ($i=0; $i < count($pref); $i++
) {
95 fwrite($file, "$string=$set_to\n", 1024);
97 fwrite($file, "$pref[$i]", 1024);
101 for ($i=0; $i < count($pref); $i++
) {
102 fwrite($file, "$pref[$i]", 1024);
104 fwrite($file, "$string=$set_to\n", 1024);
113 /** This checks if there is a pref file, if there isn't, it will
115 function checkForPrefs($data_dir, $username) {
116 $filename = "$data_dir$username.pref";
117 if (!file_exists($filename)) {
118 if (!copy("$data_dir" . "default_pref", $filename)) {
119 echo _("Error opening ") ."$filename";
127 /** Writes the Signature **/
128 function setSig($data_dir, $username, $string) {
129 $filename = "$data_dir$username.sig";
130 $file = fopen($filename, "w");
131 fwrite($file, $string);
137 /** Gets the signature **/
138 function getSig($data_dir, $username) {
139 $filename = "$data_dir$username.sig";
140 if (file_exists($filename)) {
141 $file = fopen($filename, "r");
143 while (!feof($file)) {
144 $sig .= fgets($file, 1024);