[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
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 /* $Id: class.so.inc.php 21290 2006-04-09 04:28:30Z lkneschke $ */ 13 14 class so 15 { 16 var $db; 17 var $table = 'egw_emailadmin'; 18 var $db_cols = array( 19 'ea_profile_id' => 'profileID', 20 'ea_smtp_server' => 'smtpServer', 21 'ea_smtp_type' => 'smtpType', 22 'ea_smtp_port' => 'smtpPort', 23 'ea_smtp_auth' => 'smtpAuth', 24 'ea_editforwardingaddress' => 'editforwardingaddress', 25 'ea_smtp_ldap_server' => 'smtpLDAPServer', 26 'ea_smtp_ldap_basedn' => 'smtpLDAPBaseDN', 27 'ea_smtp_ldap_admindn' => 'smtpLDAPAdminDN', 28 'ea_smtp_ldap_adminpw' => 'smtpLDAPAdminPW', 29 'ea_smtp_ldap_use_default' => 'smtpLDAPUseDefault', 30 'ea_imap_server' => 'imapServer', 31 'ea_imap_type' => 'imapType', 32 'ea_imap_port' => 'imapPort', 33 'ea_imap_login_type' => 'imapLoginType', 34 'ea_imap_tsl_auth' => 'imapTLSAuthentication', 35 'ea_imap_tsl_encryption' => 'imapTLSEncryption', 36 'ea_imap_enable_cyrus' => 'imapEnableCyrusAdmin', 37 'ea_imap_admin_user' => 'imapAdminUsername', 38 'ea_imap_admin_pw' => 'imapAdminPW', 39 'ea_imap_enable_sieve' => 'imapEnableSieve', 40 'ea_imap_sieve_server' => 'imapSieveServer', 41 'ea_imap_sieve_port' => 'imapSievePort', 42 'ea_description' => 'description', 43 'ea_default_domain' => 'defaultDomain', 44 'ea_organisation_name' => 'organisationName', 45 'ea_user_defined_accounts' => 'userDefinedAccounts', 46 'ea_imapoldcclient' => 'imapoldcclient', 47 'ea_order' => 'ea_order', 48 'ea_group' => 'ea_group', 49 'ea_appname' => 'ea_appname', 50 ); 51 52 function so() 53 { 54 if (is_object($GLOBALS['egw_setup']->db)) 55 { 56 $this->db = clone($GLOBALS['egw_setup']->db); 57 } 58 else 59 { 60 $this->db = clone($GLOBALS['egw']->db); 61 } 62 $this->db->set_app('emailadmin'); 63 } 64 65 /** 66 * Convert array with internal values/names to db-column-names 67 * 68 * @param array $vals 69 * @return array 70 */ 71 function vals2db($vals) 72 { 73 $cols = array(); 74 foreach($vals as $key => $val) 75 { 76 if (($k = array_search($key,$this->db_cols)) === false) $k = $key; 77 78 $cols[$k] = $val; 79 } 80 return $cols; 81 } 82 83 /** 84 * Convert array with db-columns/-values to internal names 85 * 86 * @param array $vals 87 * @return array 88 */ 89 function db2vals($cols) 90 { 91 $vals = array(); 92 foreach($cols as $key => $val) 93 { 94 if (isset($this->db_cols[$key])) $key = $this->db_cols[$key]; 95 96 $vals[$key] = $val; 97 } 98 return $vals; 99 } 100 101 function updateProfile($_globalSettings, $_smtpSettings=array(), $_imapSettings=array()) 102 { 103 $profileID = (int) $_globalSettings['profileID']; 104 unset($_globalSettings['profileID']); 105 106 $where = $profileID ? array('ea_profile_id' => $profileID) : false; 107 108 $this->db->insert($this->table,$this->vals2db($_smtpSettings+$_globalSettings+$_imapSettings),$where,__LINE__,__FILE__); 109 110 return $profileID ? $profileID : $this->db->get_last_insert_id($this->table,'ea_profile_id'); 111 } 112 113 function addProfile($_globalSettings, $_smtpSettings, $_imapSettings) 114 { 115 unset($_globalSettings['profileID']); // just in case 116 117 return $this->updateProfile($_globalSettings, $_smtpSettings, $_imapSettings); 118 } 119 120 function deleteProfile($_profileID) 121 { 122 $this->db->delete($this->table,array('ea_profile_id' => $_profileID),__LINE__ , __FILE__); 123 } 124 125 function getProfile($_profileID, $_fieldNames) 126 { 127 $_fieldNames = array_keys($this->vals2db(array_flip($_fieldNames))); 128 $this->db->select($this->table,$_fieldNames,array('ea_profile_id' => $_profileID), __LINE__, __FILE__); 129 130 if (($data = $this->db->row(true))) 131 { 132 return $this->db2vals($data); 133 } 134 return $data; 135 } 136 137 function getUserProfile($_appName, $_groups) 138 { 139 if(empty($_appName) || !is_array($_groups)) 140 return false; 141 142 $where = $this->db->expression( 143 $this->table,'(', 144 array('ea_appname'=>$_appName), 145 ' OR ea_appname IS NULL or ea_appname = \'\') and ', 146 '(', 147 array('ea_group'=>$_groups), 148 ' OR ea_group IS NULL or ea_group = \'\' or ea_group = \'0\')' 149 ); 150 151 $this->db->select($this->table,'ea_profile_id',$where, __LINE__, __FILE__, false, 'ORDER BY ea_order', false, 1); 152 153 if (($data = $this->db->row(true))) 154 { 155 return $this->getProfile($data['ea_profile_id'], $this->db_cols); 156 } 157 return false; 158 } 159 160 161 function getProfileList($_profileID=0,$_defaultProfile=false) 162 { 163 $where = false; 164 if ((int) $_profileID) 165 { 166 $where = array('ea_profile_id' => $_profileID); 167 } 168 elseif ($_defaultProfile) 169 { 170 $where['ea_appname'] = ''; 171 $where['ea_group'] = 0; 172 } 173 $this->db->select($this->table,'*',$where, __LINE__,__FILE__,false,(int) $_profileID ? '' : 'ORDER BY ea_order'); 174 175 $serverList = false; 176 while (($row = $this->db->row(true))) 177 { 178 $serverList[] = $this->db2vals($row); 179 } 180 return $serverList; 181 } 182 183 function getUserData($_accountID) 184 { 185 $ldap = $GLOBALS['egw']->common->ldapConnect(); 186 187 if (($sri = @ldap_search($ldap,$GLOBALS['egw_info']['server']['ldap_context'],"(uidnumber=$_accountID)"))) 188 { 189 $allValues = ldap_get_entries($ldap, $sri); 190 if ($allValues['count'] > 0) 191 { 192 #print "found something<br>"; 193 $userData["mailLocalAddress"] = $allValues[0]["mail"][0]; 194 $userData["mailAlternateAddress"] = $allValues[0]["mailalternateaddress"]; 195 $userData["accountStatus"] = $allValues[0]["accountstatus"][0]; 196 $userData["mailRoutingAddress"] = $allValues[0]["mailforwardingaddress"]; 197 $userData["qmailDotMode"] = $allValues[0]["qmaildotmode"][0]; 198 $userData["deliveryProgramPath"] = $allValues[0]["deliveryprogrampath"][0]; 199 $userData["deliveryMode"] = $allValues[0]["deliverymode"][0]; 200 201 unset($userData["mailAlternateAddress"]["count"]); 202 unset($userData["mailRoutingAddress"]["count"]); 203 204 return $userData; 205 } 206 } 207 208 // if we did not return before, return false 209 return false; 210 } 211 212 function saveUserData($_accountID, $_accountData) 213 { 214 $ldap = $GLOBALS['egw']->common->ldapConnect(); 215 // need to be fixed 216 if(is_numeric($_accountID)) 217 { 218 $filter = "uidnumber=$_accountID"; 219 } 220 else 221 { 222 $filter = "uid=$_accountID"; 223 } 224 225 $sri = @ldap_search($ldap,$GLOBALS['egw_info']['server']['ldap_context'],$filter); 226 if ($sri) 227 { 228 $allValues = ldap_get_entries($ldap, $sri); 229 $accountDN = $allValues[0]['dn']; 230 $uid = $allValues[0]['uid'][0]; 231 $homedirectory = $allValues[0]['homedirectory'][0]; 232 $objectClasses = $allValues[0]['objectclass']; 233 234 unset($objectClasses['count']); 235 } 236 else 237 { 238 return false; 239 } 240 241 if(empty($homedirectory)) 242 { 243 $homedirectory = "/home/".$uid; 244 } 245 246 // the old code for qmail ldap 247 $newData = array 248 ( 249 'mail' => $_accountData["mailLocalAddress"], 250 'mailAlternateAddress' => $_accountData["mailAlternateAddress"], 251 'mailRoutingAddress' => $_accountData["mailRoutingAddress"], 252 'homedirectory' => $homedirectory, 253 'mailMessageStore' => $homedirectory."/Maildir/", 254 'gidnumber' => '1000', 255 'qmailDotMode' => $_accountData["qmailDotMode"], 256 'deliveryProgramPath' => $_accountData["deliveryProgramPath"] 257 ); 258 259 if(!in_array('qmailUser',$objectClasses) && 260 !in_array('qmailuser',$objectClasses)) 261 { 262 $objectClasses[] = 'qmailuser'; 263 } 264 265 // the new code for postfix+cyrus+ldap 266 $newData = array 267 ( 268 'mail' => $_accountData["mailLocalAddress"], 269 'accountStatus' => $_accountData["accountStatus"], 270 'objectclass' => $objectClasses 271 ); 272 273 if(is_array($_accountData["mailAlternateAddress"])) 274 { 275 $newData['mailAlternateAddress'] = $_accountData["mailAlternateAddress"]; 276 } 277 else 278 { 279 $newData['mailAlternateAddress'] = array(); 280 } 281 282 if($_accountData["accountStatus"] == 'active') 283 { 284 $newData['accountStatus'] = 'active'; 285 } 286 else 287 { 288 $newData['accountStatus'] = 'disabled'; 289 } 290 291 if(!empty($_accountData["deliveryMode"])) 292 { 293 $newData['deliveryMode'] = $_accountData["deliveryMode"]; 294 } 295 else 296 { 297 $newData['deliveryMode'] = array(); 298 } 299 300 301 if(is_array($_accountData["mailRoutingAddress"])) 302 { 303 $newData['mailForwardingAddress'] = $_accountData["mailRoutingAddress"]; 304 } 305 else 306 { 307 $newData['mailForwardingAddress'] = array(); 308 } 309 310 #print "DN: $accountDN<br>"; 311 ldap_mod_replace ($ldap, $accountDN, $newData); 312 #print ldap_error($ldap); 313 314 // also update the account_email field in egw_accounts 315 // when using sql account storage 316 if($GLOBALS['egw_info']['server']['account_repository'] == 'sql') 317 { 318 $this->db->update('egw_accounts',array( 319 'account_email' => $_accountData["mailLocalAddress"] 320 ), 321 array( 322 'account_id' => $_accountID 323 ),__LINE__,__FILE__ 324 ); 325 } 326 return true; 327 } 328 329 function setOrder($_order) 330 { 331 foreach($_order as $order => $profileID) 332 { 333 $this->db->update($this->table,array( 334 'ea_order' => $order, 335 ),array( 336 'ea_profile_id' => $profileID, 337 ),__LINE__, __FILE__); 338 } 339 } 340 } 341 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |