1 | <?php |
---|
2 | /***************************************************************************\ |
---|
3 | * EGroupWare - EMailAdmin * |
---|
4 | * http://www.egroupware.org * |
---|
5 | * Written by : Lars Kneschke [lkneschke@egroupware.org] * |
---|
6 | * ------------------------------------------------- * |
---|
7 | * This program is free software; you can redistribute it and/or modify it * |
---|
8 | * under the terms of the GNU General Public License as published by the * |
---|
9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
10 | * option) any later version. * |
---|
11 | \***************************************************************************/ |
---|
12 | |
---|
13 | class so |
---|
14 | { |
---|
15 | function so() |
---|
16 | { |
---|
17 | $this->db = $GLOBALS['phpgw']->db; |
---|
18 | include(PHPGW_INCLUDE_ROOT.'/emailadmin/setup/tables_current.inc.php'); |
---|
19 | $this->tables = &$phpgw_baseline; |
---|
20 | unset($phpgw_baseline); |
---|
21 | $this->table = &$this->tables['phpgw_emailadmin']; |
---|
22 | } |
---|
23 | |
---|
24 | function updateProfile($_globalSettings, $_smtpSettings, $_imapSettings) |
---|
25 | { |
---|
26 | $profileID = intval($_globalSettings['profileID']); |
---|
27 | $fields = $values = $query = ''; |
---|
28 | |
---|
29 | foreach($_smtpSettings+$_globalSettings+$_imapSettings as $key => $value) |
---|
30 | { |
---|
31 | if($key == 'profileID') |
---|
32 | continue; |
---|
33 | |
---|
34 | if($fields != '') |
---|
35 | { |
---|
36 | $fields .= ','; |
---|
37 | $values .= ','; |
---|
38 | $query .= ','; |
---|
39 | } |
---|
40 | switch($this->table['fd'][$key]['type']) |
---|
41 | { |
---|
42 | case 'int': case 'auto': |
---|
43 | $value = intval($value); |
---|
44 | break; |
---|
45 | default: |
---|
46 | $value = $this->db->db_addslashes($value); |
---|
47 | break; |
---|
48 | } |
---|
49 | $fields .= "$key"; |
---|
50 | $values .= "'$value'"; |
---|
51 | $query .= "$key='$value'"; |
---|
52 | } |
---|
53 | if ($profileID) |
---|
54 | { |
---|
55 | $query = "update phpgw_emailadmin set $query where profileID=$profileID"; |
---|
56 | } |
---|
57 | else |
---|
58 | { |
---|
59 | $query = "insert into phpgw_emailadmin ($fields) values ($values)"; |
---|
60 | } |
---|
61 | $this->db->query($query,__LINE__,__FILE__); |
---|
62 | } |
---|
63 | |
---|
64 | function addProfile($_globalSettings, $_smtpSettings, $_imapSettings) |
---|
65 | { |
---|
66 | unset($_globalSettings['profileID']); // just in case |
---|
67 | |
---|
68 | $this->updateProfile($_globalSettings, $_smtpSettings, $_imapSettings); |
---|
69 | } |
---|
70 | |
---|
71 | function deleteProfile($_profileID) |
---|
72 | { |
---|
73 | $query = 'DELETE FROM phpgw_emailadmin WHERE profileID='.intval($_profileID); |
---|
74 | $this->db->query($query,__LINE__ , __FILE__); |
---|
75 | } |
---|
76 | |
---|
77 | function getProfile($_profileID, $_fieldNames) |
---|
78 | { |
---|
79 | $query = ''; |
---|
80 | foreach($_fieldNames as $key => $value) |
---|
81 | { |
---|
82 | if(!empty($query)) |
---|
83 | { |
---|
84 | $query .= ', '; |
---|
85 | } |
---|
86 | $query .= $value; |
---|
87 | } |
---|
88 | |
---|
89 | $query = "SELECT $query FROM phpgw_emailadmin WHERE profileID=".intval($_profileID); |
---|
90 | |
---|
91 | $this->db->query($query, __LINE__, __FILE__); |
---|
92 | |
---|
93 | if($this->db->next_record()) |
---|
94 | { |
---|
95 | foreach($_fieldNames as $key => $value) |
---|
96 | { |
---|
97 | $profileData[$value] = $this->db->f($key); |
---|
98 | } |
---|
99 | |
---|
100 | return $profileData; |
---|
101 | } |
---|
102 | |
---|
103 | return false; |
---|
104 | } |
---|
105 | |
---|
106 | function getProfileList($_profileID='') |
---|
107 | { |
---|
108 | if(intval($_profileID) > 0) |
---|
109 | { |
---|
110 | $query = 'SELECT profileID,smtpServer,smtpType,imapServer,imapType,description FROM phpgw_emailadmin WHERE profileID='.intval($_profileID); |
---|
111 | } |
---|
112 | else |
---|
113 | { |
---|
114 | $query = 'SELECT profileID,smtpServer,smtpType,imapServer,imapType,description FROM phpgw_emailadmin'; |
---|
115 | } |
---|
116 | $this->db->query($query); |
---|
117 | |
---|
118 | $i=0; |
---|
119 | while ($this->db->next_record()) |
---|
120 | { |
---|
121 | $serverList[$i]['profileID'] = $this->db->f(0); |
---|
122 | $serverList[$i]['smtpServer'] = $this->db->f(1); |
---|
123 | $serverList[$i]['smtpType'] = $this->db->f(2); |
---|
124 | $serverList[$i]['imapServer'] = $this->db->f(3); |
---|
125 | $serverList[$i]['imapType'] = $this->db->f(4); |
---|
126 | $serverList[$i]['description'] = $this->db->f(5); |
---|
127 | $i++; |
---|
128 | } |
---|
129 | |
---|
130 | if ($i>0) |
---|
131 | { |
---|
132 | return $serverList; |
---|
133 | } |
---|
134 | else |
---|
135 | { |
---|
136 | return false; |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | function getUserData($_accountID) |
---|
141 | { |
---|
142 | global $phpgw, $phpgw_info; |
---|
143 | |
---|
144 | $ldap = $phpgw->common->ldapConnect(); |
---|
145 | $filter = "(&(uidnumber=$_accountID))"; |
---|
146 | |
---|
147 | $sri = @ldap_search($ldap,$phpgw_info['server']['ldap_context'],$filter); |
---|
148 | if ($sri) |
---|
149 | { |
---|
150 | $allValues = ldap_get_entries($ldap, $sri); |
---|
151 | if ($allValues['count'] > 0) |
---|
152 | { |
---|
153 | #print "found something<br>"; |
---|
154 | $userData["mailLocalAddress"] = $allValues[0]["mail"][0]; |
---|
155 | $userData["mailAlternateAddress"] = $allValues[0]["mailalternateaddress"]; |
---|
156 | $userData["accountStatus"] = $allValues[0]["accountstatus"][0]; |
---|
157 | $userData["mailRoutingAddress"] = $allValues[0]["mailforwardingaddress"]; |
---|
158 | $userData["qmailDotMode"] = $allValues[0]["qmaildotmode"][0]; |
---|
159 | $userData["deliveryProgramPath"] = $allValues[0]["deliveryprogrampath"][0]; |
---|
160 | $userData["deliveryMode"] = $allValues[0]["deliverymode"][0]; |
---|
161 | |
---|
162 | unset($userData["mailAlternateAddress"]["count"]); |
---|
163 | unset($userData["mailRoutingAddress"]["count"]); |
---|
164 | |
---|
165 | return $userData; |
---|
166 | } |
---|
167 | } |
---|
168 | |
---|
169 | // if we did not return before, return false |
---|
170 | return false; |
---|
171 | } |
---|
172 | |
---|
173 | function saveUserData($_accountID, $_accountData) |
---|
174 | { |
---|
175 | $ldap = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
176 | // need to be fixed |
---|
177 | if(is_numeric($_accountID)) |
---|
178 | { |
---|
179 | $filter = "uidnumber=$_accountID"; |
---|
180 | } |
---|
181 | else |
---|
182 | { |
---|
183 | $filter = "uid=$_accountID"; |
---|
184 | } |
---|
185 | |
---|
186 | $sri = @ldap_search($ldap,$GLOBALS['phpgw_info']['server']['ldap_context'],$filter); |
---|
187 | if ($sri) |
---|
188 | { |
---|
189 | $allValues = ldap_get_entries($ldap, $sri); |
---|
190 | $accountDN = $allValues[0]['dn']; |
---|
191 | $uid = $allValues[0]['uid'][0]; |
---|
192 | $homedirectory = $allValues[0]['homedirectory'][0]; |
---|
193 | $objectClasses = $allValues[0]['objectclass']; |
---|
194 | |
---|
195 | unset($objectClasses['count']); |
---|
196 | } |
---|
197 | else |
---|
198 | { |
---|
199 | return false; |
---|
200 | } |
---|
201 | |
---|
202 | if(empty($homedirectory)) |
---|
203 | { |
---|
204 | $homedirectory = "/home/".$uid; |
---|
205 | } |
---|
206 | |
---|
207 | // the old code for qmail ldap |
---|
208 | $newData = array |
---|
209 | ( |
---|
210 | 'mail' => $_accountData["mailLocalAddress"], |
---|
211 | 'mailAlternateAddress' => $_accountData["mailAlternateAddress"], |
---|
212 | 'mailRoutingAddress' => $_accountData["mailRoutingAddress"], |
---|
213 | 'homedirectory' => $homedirectory, |
---|
214 | 'mailMessageStore' => $homedirectory."/Maildir/", |
---|
215 | 'gidnumber' => '1000', |
---|
216 | 'qmailDotMode' => $_accountData["qmailDotMode"], |
---|
217 | 'deliveryProgramPath' => $_accountData["deliveryProgramPath"] |
---|
218 | ); |
---|
219 | |
---|
220 | if(!in_array('qmailUser',$objectClasses) && |
---|
221 | !in_array('qmailuser',$objectClasses)) |
---|
222 | { |
---|
223 | $objectClasses[] = 'qmailuser'; |
---|
224 | } |
---|
225 | |
---|
226 | // the new code for postfix+cyrus+ldap |
---|
227 | $newData = array |
---|
228 | ( |
---|
229 | 'mail' => $_accountData["mailLocalAddress"], |
---|
230 | 'accountStatus' => $_accountData["accountStatus"], |
---|
231 | 'objectclass' => $objectClasses |
---|
232 | ); |
---|
233 | |
---|
234 | if(is_array($_accountData["mailAlternateAddress"])) |
---|
235 | { |
---|
236 | $newData['mailAlternateAddress'] = $_accountData["mailAlternateAddress"]; |
---|
237 | } |
---|
238 | else |
---|
239 | { |
---|
240 | $newData['mailAlternateAddress'] = array(); |
---|
241 | } |
---|
242 | |
---|
243 | if($_accountData["accountStatus"] == 'active') |
---|
244 | { |
---|
245 | $newData['accountStatus'] = 'active'; |
---|
246 | } |
---|
247 | else |
---|
248 | { |
---|
249 | $newData['accountStatus'] = 'disabled'; |
---|
250 | } |
---|
251 | |
---|
252 | if(!empty($_accountData["deliveryMode"])) |
---|
253 | { |
---|
254 | $newData['deliveryMode'] = $_accountData["deliveryMode"]; |
---|
255 | } |
---|
256 | else |
---|
257 | { |
---|
258 | $newData['deliveryMode'] = array(); |
---|
259 | } |
---|
260 | |
---|
261 | |
---|
262 | if(is_array($_accountData["mailRoutingAddress"])) |
---|
263 | { |
---|
264 | $newData['mailForwardingAddress'] = $_accountData["mailRoutingAddress"]; |
---|
265 | } |
---|
266 | else |
---|
267 | { |
---|
268 | $newData['mailForwardingAddress'] = array(); |
---|
269 | } |
---|
270 | |
---|
271 | #print "DN: $accountDN<br>"; |
---|
272 | ldap_mod_replace ($ldap, $accountDN, $newData); |
---|
273 | #print ldap_error($ldap); |
---|
274 | |
---|
275 | // also update the account_email field in phpgw_accounts |
---|
276 | // when using sql account storage |
---|
277 | if($GLOBALS['phpgw_info']['server']['account_repository'] == 'sql') |
---|
278 | { |
---|
279 | $this->db->update('phpgw_accounts',array( |
---|
280 | 'account_email' => $_accountData["mailLocalAddress"] |
---|
281 | ), |
---|
282 | array( |
---|
283 | 'account_id' => $_accountID |
---|
284 | ),__LINE__,__FILE__ |
---|
285 | ); |
---|
286 | } |
---|
287 | } |
---|
288 | } |
---|
289 | ?> |
---|