65b14f90 |
1 | <? |
2 | /** |
3 | ** prefs.php |
4 | ** |
5 | ** This contains functions for manipulating user preferences |
6 | **/ |
7 | |
8 | /** returns the value for $string **/ |
d0747e26 |
9 | function getPref($data_dir, $username, $string) { |
10 | $filename = "$data_dir$username.pref"; |
3021b626 |
11 | if (!file_exists($filename)) { |
32c7898c |
12 | echo _("Preference file ") . "\"$filename\"" . _(" not found. Exiting abnormally"); |
3021b626 |
13 | exit; |
14 | } |
15 | |
65b14f90 |
16 | $file = fopen($filename, "r"); |
17 | |
18 | /** read in all the preferences **/ |
19 | for ($i=0; !feof($file); $i++) { |
20 | $pref = fgets($file, 1024); |
21 | if (substr($pref, 0, strpos($pref, "=")) == $string) { |
22 | fclose($file); |
d3cdb279 |
23 | return trim(substr($pref, strpos($pref, "=")+1)); |
65b14f90 |
24 | } |
25 | } |
26 | fclose($file); |
27 | return ""; |
28 | } |
29 | |
30 | /** sets the pref, $string, to $set_to **/ |
d0747e26 |
31 | function setPref($data_dir, $username, $string, $set_to) { |
32 | $filename = "$data_dir$username.pref"; |
65b14f90 |
33 | $found = false; |
34 | if (!file_exists($filename)) { |
32c7898c |
35 | echo _("Preference file, ") . "\"$filename\"" . _(", does not exist. Log out, and log back in to create a default preference file. ") ."<BR>"; |
65b14f90 |
36 | exit; |
37 | } |
38 | $file = fopen($filename, "r"); |
39 | |
40 | /** read in all the preferences **/ |
41 | for ($i=0; !feof($file); $i++) { |
42 | $pref[$i] = fgets($file, 1024); |
43 | if (substr($pref[$i], 0, strpos($pref[$i], "=")) == $string) { |
44 | $found = true; |
45 | $pos = $i; |
46 | } |
47 | } |
48 | fclose($file); |
49 | |
50 | $file = fopen($filename, "w"); |
51 | if ($found == true) { |
52 | for ($i=0; $i < count($pref); $i++) { |
53 | if ($i == $pos) { |
54 | fwrite($file, "$string=$set_to\n", 1024); |
55 | } else { |
56 | fwrite($file, "$pref[$i]", 1024); |
57 | } |
58 | } |
59 | } else { |
60 | for ($i=0; $i < count($pref); $i++) { |
61 | fwrite($file, "$pref[$i]", 1024); |
62 | } |
63 | fwrite($file, "$string=$set_to\n", 1024); |
64 | } |
65 | |
66 | fclose($file); |
67 | } |
68 | |
f804972b |
69 | |
70 | |
71 | |
65b14f90 |
72 | /** This checks if there is a pref file, if there isn't, it will create it. **/ |
d0747e26 |
73 | function checkForPrefs($data_dir, $username) { |
74 | $filename = "$data_dir$username.pref"; |
65b14f90 |
75 | if (!file_exists($filename)) { |
8105d00f |
76 | if (!copy("$data_dir" . "default_pref", $filename)) { |
5f29dd3b |
77 | echo _("Error opening ") ."$filename"; |
65b14f90 |
78 | exit; |
79 | } |
80 | } |
81 | return; |
82 | } |
f804972b |
83 | |
84 | |
85 | |
86 | /** Writes the Signature **/ |
87 | function setSig($data_dir, $username, $string) { |
88 | $filename = "$data_dir$username.sig"; |
89 | $file = fopen($filename, "w"); |
90 | fwrite($file, $string); |
91 | fclose($file); |
92 | } |
93 | |
94 | |
95 | |
96 | /** Gets the signature **/ |
97 | function getSig($data_dir, $username) { |
98 | $filename = "$data_dir$username.sig"; |
99 | if (file_exists($filename)) { |
100 | $file = fopen($filename, "r"); |
101 | while (!feof($file)) { |
102 | $sig .= fgets($file, 1024); |
103 | } |
104 | fclose($file); |
105 | } else { |
5f29dd3b |
106 | echo _("Signature file not found."); |
f804972b |
107 | exit; |
108 | } |
109 | return $sig; |
110 | } |
5f29dd3b |
111 | ?> |