dc4599263eb104feb89beda44fb3093c93e244f1
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);
65 for ($i=0; $i < count($hlt); $i++
) {
66 fwrite($file, "highlight$i=$hlt[$i]");
72 /** sets the pref, $string, to $set_to **/
73 function setPref($data_dir, $username, $string, $set_to) {
74 $filename = "$data_dir$username.pref";
76 if (!file_exists($filename)) {
77 printf (_("Preference file, %s, does not exist. Log out, and log back in to create a default preference file."), $filename);
81 $file = fopen($filename, "r");
83 /** read in all the preferences **/
84 for ($i=0; !feof($file); $i++
) {
85 $pref[$i] = fgets($file, 1024);
86 if (substr($pref[$i], 0, strpos($pref[$i], "=")) == $string) {
93 $file = fopen($filename, "w");
95 for ($i=0; $i < count($pref); $i++
) {
97 fwrite($file, "$string=$set_to\n", 1024);
99 fwrite($file, "$pref[$i]", 1024);
103 for ($i=0; $i < count($pref); $i++
) {
104 fwrite($file, "$pref[$i]", 1024);
106 fwrite($file, "$string=$set_to\n", 1024);
115 /** This checks if there is a pref file, if there isn't, it will
117 function checkForPrefs($data_dir, $username) {
118 $filename = "$data_dir$username.pref";
119 if (!file_exists($filename)) {
120 if (!copy("$data_dir" . "default_pref", $filename)) {
121 echo _("Error opening ") ."$filename";
129 /** Writes the Signature **/
130 function setSig($data_dir, $username, $string) {
131 $filename = "$data_dir$username.sig";
132 $file = fopen($filename, "w");
133 fwrite($file, $string);
139 /** Gets the signature **/
140 function getSig($data_dir, $username) {
141 $filename = "$data_dir$username.sig";
142 if (file_exists($filename)) {
143 $file = fopen($filename, "r");
145 while (!feof($file)) {
146 $sig .= fgets($file, 1024);