59177427 |
1 | <?php |
65b14f90 |
2 | /** |
3 | ** prefs.php |
4 | ** |
5 | ** This contains functions for manipulating user preferences |
6 | **/ |
7 | |
d068c0ec |
8 | $prefs_php = true; |
9 | |
65b14f90 |
10 | /** returns the value for $string **/ |
d0747e26 |
11 | function getPref($data_dir, $username, $string) { |
12 | $filename = "$data_dir$username.pref"; |
3021b626 |
13 | if (!file_exists($filename)) { |
32c7898c |
14 | echo _("Preference file ") . "\"$filename\"" . _(" not found. Exiting abnormally"); |
3021b626 |
15 | exit; |
16 | } |
17 | |
65b14f90 |
18 | $file = fopen($filename, "r"); |
19 | |
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) { |
24 | fclose($file); |
d3cdb279 |
25 | return trim(substr($pref, strpos($pref, "=")+1)); |
65b14f90 |
26 | } |
27 | } |
28 | fclose($file); |
29 | return ""; |
30 | } |
31 | |
44f642f5 |
32 | function removePref($data_dir, $username, $string) { |
33 | $filename = "$data_dir$username.pref"; |
34 | $found = false; |
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>"; |
37 | exit; |
38 | } |
39 | $file = fopen($filename, "r"); |
40 | |
41 | for ($i=0; !feof($file); $i++) { |
42 | $pref[$i] = fgets($file, 1024); |
43 | if (substr($pref[$i], 0, strpos($pref[$i], "=")) == $string) { |
44 | $i--; |
45 | } |
46 | } |
47 | fclose($file); |
48 | |
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); |
52 | $j++; |
53 | } |
54 | } |
55 | |
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); |
60 | } |
61 | } |
62 | for ($i=0; $i < count($hlt); $i++) { |
63 | fwrite($file, "highlight$i=$hlt[$i]"); |
64 | } |
65 | |
66 | fclose($file); |
67 | } |
68 | |
65b14f90 |
69 | /** sets the pref, $string, to $set_to **/ |
d0747e26 |
70 | function setPref($data_dir, $username, $string, $set_to) { |
71 | $filename = "$data_dir$username.pref"; |
65b14f90 |
72 | $found = false; |
73 | if (!file_exists($filename)) { |
32c7898c |
74 | echo _("Preference file, ") . "\"$filename\"" . _(", does not exist. Log out, and log back in to create a default preference file. ") ."<BR>"; |
65b14f90 |
75 | exit; |
76 | } |
77 | $file = fopen($filename, "r"); |
78 | |
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) { |
83 | $found = true; |
84 | $pos = $i; |
85 | } |
86 | } |
87 | fclose($file); |
88 | |
89 | $file = fopen($filename, "w"); |
90 | if ($found == true) { |
91 | for ($i=0; $i < count($pref); $i++) { |
92 | if ($i == $pos) { |
93 | fwrite($file, "$string=$set_to\n", 1024); |
94 | } else { |
95 | fwrite($file, "$pref[$i]", 1024); |
96 | } |
97 | } |
98 | } else { |
99 | for ($i=0; $i < count($pref); $i++) { |
100 | fwrite($file, "$pref[$i]", 1024); |
101 | } |
102 | fwrite($file, "$string=$set_to\n", 1024); |
103 | } |
104 | |
105 | fclose($file); |
106 | } |
107 | |
f804972b |
108 | |
109 | |
110 | |
d068c0ec |
111 | /** This checks if there is a pref file, if there isn't, it will |
112 | create it. **/ |
d0747e26 |
113 | function checkForPrefs($data_dir, $username) { |
114 | $filename = "$data_dir$username.pref"; |
65b14f90 |
115 | if (!file_exists($filename)) { |
8105d00f |
116 | if (!copy("$data_dir" . "default_pref", $filename)) { |
5f29dd3b |
117 | echo _("Error opening ") ."$filename"; |
65b14f90 |
118 | exit; |
119 | } |
120 | } |
65b14f90 |
121 | } |
f804972b |
122 | |
123 | |
124 | |
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); |
130 | fclose($file); |
131 | } |
132 | |
133 | |
134 | |
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"); |
7aaa81fc |
140 | $sig = ""; |
f804972b |
141 | while (!feof($file)) { |
142 | $sig .= fgets($file, 1024); |
143 | } |
144 | fclose($file); |
f804972b |
145 | } |
146 | return $sig; |
147 | } |
5f29dd3b |
148 | ?> |