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 function removePref($data_dir, $username, $string) {
33 $filename = "$data_dir$username.pref";
35 if (!file_exists($filename)) {
36 echo _("Preference file, ") . "\"$filename\"" . _(", does not exist. Log out, and log back in to create a default preference file. ") ."<BR>";
39 $file = fopen($filename, "r");
41 for ($i=0; !feof($file); $i++
) {
42 $pref[$i] = fgets($file, 1024);
43 if (substr($pref[$i], 0, strpos($pref[$i], "=")) == $string) {
49 for ($i=0,$j=0; $i < count($pref); $i++
) {
50 if (substr($pref[$i], 0, 9) == "highlight") {
51 $hlt[$j] = substr($pref[$i], strpos($pref[$i], "=")+
1);
56 $file = fopen($filename, "w");
57 for ($i=0; $i < count($pref); $i++
) {
58 if (substr($pref[$i], 0, 9) != "highlight") {
59 fwrite($file, "$pref[$i]", 1024);
62 for ($i=0; $i < count($hlt); $i++
) {
63 fwrite($file, "highlight$i=$hlt[$i]");
69 /** sets the pref, $string, to $set_to **/
70 function setPref($data_dir, $username, $string, $set_to) {
71 $filename = "$data_dir$username.pref";
73 if (!file_exists($filename)) {
74 echo _("Preference file, ") . "\"$filename\"" . _(", does not exist. Log out, and log back in to create a default preference file. ") ."<BR>";
77 $file = fopen($filename, "r");
79 /** read in all the preferences **/
80 for ($i=0; !feof($file); $i++
) {
81 $pref[$i] = fgets($file, 1024);
82 if (substr($pref[$i], 0, strpos($pref[$i], "=")) == $string) {
89 $file = fopen($filename, "w");
91 for ($i=0; $i < count($pref); $i++
) {
93 fwrite($file, "$string=$set_to\n", 1024);
95 fwrite($file, "$pref[$i]", 1024);
99 for ($i=0; $i < count($pref); $i++
) {
100 fwrite($file, "$pref[$i]", 1024);
102 fwrite($file, "$string=$set_to\n", 1024);
111 /** This checks if there is a pref file, if there isn't, it will
113 function checkForPrefs($data_dir, $username) {
114 $filename = "$data_dir$username.pref";
115 if (!file_exists($filename)) {
116 if (!copy("$data_dir" . "default_pref", $filename)) {
117 echo _("Error opening ") ."$filename";
125 /** Writes the Signature **/
126 function setSig($data_dir, $username, $string) {
127 $filename = "$data_dir$username.sig";
128 $file = fopen($filename, "w");
129 fwrite($file, $string);
135 /** Gets the signature **/
136 function getSig($data_dir, $username) {
137 $filename = "$data_dir$username.sig";
138 if (file_exists($filename)) {
139 $file = fopen($filename, "r");
140 while (!feof($file)) {
141 $sig .= fgets($file, 1024);
145 echo _("Signature file not found.");