added capability to detect if imap server supports searching on specific
[squirrelmail.git] / functions / prefs.php
CommitLineData
59177427 1<?php
65b14f90 2 /**
3 ** prefs.php
4 **
5 ** This contains functions for manipulating user preferences
245a6892 6 **
7 ** $Id$
65b14f90 8 **/
9
d068c0ec 10 $prefs_php = true;
11
65b14f90 12 /** returns the value for $string **/
d0747e26 13 function getPref($data_dir, $username, $string) {
14 $filename = "$data_dir$username.pref";
3021b626 15 if (!file_exists($filename)) {
2ad42ea3 16 printf (_("Preference file %s not found. Exiting abnormally"), $filename);
3021b626 17 exit;
18 }
19
65b14f90 20 $file = fopen($filename, "r");
21
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) {
26 fclose($file);
d3cdb279 27 return trim(substr($pref, strpos($pref, "=")+1));
65b14f90 28 }
29 }
30 fclose($file);
31 return "";
32 }
33
44f642f5 34 function removePref($data_dir, $username, $string) {
35 $filename = "$data_dir$username.pref";
36 $found = false;
37 if (!file_exists($filename)) {
2ad42ea3 38 printf (_("Preference file, %s, does not exist. Log out, and log back in to create a default preference file."), $filename);
39 echo "<br>\n";
44f642f5 40 exit;
41 }
42 $file = fopen($filename, "r");
43
44 for ($i=0; !feof($file); $i++) {
45 $pref[$i] = fgets($file, 1024);
46 if (substr($pref[$i], 0, strpos($pref[$i], "=")) == $string) {
47 $i--;
48 }
49 }
50 fclose($file);
51
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);
55 $j++;
56 }
57 }
58
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);
63 }
64 }
65 for ($i=0; $i < count($hlt); $i++) {
66 fwrite($file, "highlight$i=$hlt[$i]");
67 }
68
69 fclose($file);
70 }
71
65b14f90 72 /** sets the pref, $string, to $set_to **/
d0747e26 73 function setPref($data_dir, $username, $string, $set_to) {
74 $filename = "$data_dir$username.pref";
65b14f90 75 $found = false;
76 if (!file_exists($filename)) {
2ad42ea3 77 printf (_("Preference file, %s, does not exist. Log out, and log back in to create a default preference file."), $filename);
78 echo "\n<br>\n";
65b14f90 79 exit;
80 }
81 $file = fopen($filename, "r");
82
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) {
87 $found = true;
88 $pos = $i;
89 }
90 }
91 fclose($file);
92
93 $file = fopen($filename, "w");
94 if ($found == true) {
95 for ($i=0; $i < count($pref); $i++) {
96 if ($i == $pos) {
97 fwrite($file, "$string=$set_to\n", 1024);
98 } else {
99 fwrite($file, "$pref[$i]", 1024);
100 }
101 }
102 } else {
103 for ($i=0; $i < count($pref); $i++) {
104 fwrite($file, "$pref[$i]", 1024);
105 }
106 fwrite($file, "$string=$set_to\n", 1024);
107 }
108
109 fclose($file);
110 }
111
f804972b 112
113
114
d068c0ec 115 /** This checks if there is a pref file, if there isn't, it will
116 create it. **/
d0747e26 117 function checkForPrefs($data_dir, $username) {
118 $filename = "$data_dir$username.pref";
65b14f90 119 if (!file_exists($filename)) {
8105d00f 120 if (!copy("$data_dir" . "default_pref", $filename)) {
5f29dd3b 121 echo _("Error opening ") ."$filename";
65b14f90 122 exit;
123 }
124 }
65b14f90 125 }
f804972b 126
127
128
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);
134 fclose($file);
135 }
136
137
138
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");
7aaa81fc 144 $sig = "";
f804972b 145 while (!feof($file)) {
146 $sig .= fgets($file, 1024);
147 }
148 fclose($file);
f804972b 149 }
150 return $sig;
151 }
5f29dd3b 152?>