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 | |
32 | /** sets the pref, $string, to $set_to **/ |
d0747e26 |
33 | function setPref($data_dir, $username, $string, $set_to) { |
34 | $filename = "$data_dir$username.pref"; |
65b14f90 |
35 | $found = false; |
36 | if (!file_exists($filename)) { |
32c7898c |
37 | echo _("Preference file, ") . "\"$filename\"" . _(", does not exist. Log out, and log back in to create a default preference file. ") ."<BR>"; |
65b14f90 |
38 | exit; |
39 | } |
40 | $file = fopen($filename, "r"); |
41 | |
42 | /** read in all the preferences **/ |
43 | for ($i=0; !feof($file); $i++) { |
44 | $pref[$i] = fgets($file, 1024); |
45 | if (substr($pref[$i], 0, strpos($pref[$i], "=")) == $string) { |
46 | $found = true; |
47 | $pos = $i; |
48 | } |
49 | } |
50 | fclose($file); |
51 | |
52 | $file = fopen($filename, "w"); |
53 | if ($found == true) { |
54 | for ($i=0; $i < count($pref); $i++) { |
55 | if ($i == $pos) { |
56 | fwrite($file, "$string=$set_to\n", 1024); |
57 | } else { |
58 | fwrite($file, "$pref[$i]", 1024); |
59 | } |
60 | } |
61 | } else { |
62 | for ($i=0; $i < count($pref); $i++) { |
63 | fwrite($file, "$pref[$i]", 1024); |
64 | } |
65 | fwrite($file, "$string=$set_to\n", 1024); |
66 | } |
67 | |
68 | fclose($file); |
69 | } |
70 | |
f804972b |
71 | |
72 | |
73 | |
d068c0ec |
74 | /** This checks if there is a pref file, if there isn't, it will |
75 | create it. **/ |
d0747e26 |
76 | function checkForPrefs($data_dir, $username) { |
77 | $filename = "$data_dir$username.pref"; |
65b14f90 |
78 | if (!file_exists($filename)) { |
8105d00f |
79 | if (!copy("$data_dir" . "default_pref", $filename)) { |
5f29dd3b |
80 | echo _("Error opening ") ."$filename"; |
65b14f90 |
81 | exit; |
82 | } |
83 | } |
65b14f90 |
84 | } |
f804972b |
85 | |
86 | |
87 | |
88 | /** Writes the Signature **/ |
89 | function setSig($data_dir, $username, $string) { |
90 | $filename = "$data_dir$username.sig"; |
91 | $file = fopen($filename, "w"); |
92 | fwrite($file, $string); |
93 | fclose($file); |
94 | } |
95 | |
96 | |
97 | |
98 | /** Gets the signature **/ |
99 | function getSig($data_dir, $username) { |
100 | $filename = "$data_dir$username.sig"; |
101 | if (file_exists($filename)) { |
102 | $file = fopen($filename, "r"); |
103 | while (!feof($file)) { |
104 | $sig .= fgets($file, 1024); |
105 | } |
106 | fclose($file); |
107 | } else { |
5f29dd3b |
108 | echo _("Signature file not found."); |
f804972b |
109 | exit; |
110 | } |
111 | return $sig; |
112 | } |
5f29dd3b |
113 | ?> |