[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare API - Accounts manager for the contacts class * 4 * This file written by Miles Lott <milosch@groupwhere.org> * 5 * View and manipulate account records using the contacts class * 6 * Copyright (C) 2000, 2001 Miles Lott * 7 * -------------------------------------------------------------------------* 8 * This library is part of the eGroupWare API * 9 * http://www.egroupware.org/api * 10 * ------------------------------------------------------------------------ * 11 * This library is free software; you can redistribute it and/or modify it * 12 * under the terms of the GNU Lesser General Public License as published by * 13 * the Free Software Foundation; either version 2.1 of the License, * 14 * or any later version. * 15 * This library is distributed in the hope that it will be useful, but * 16 * WITHOUT ANY WARRANTY; without even the implied warranty of * 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 18 * See the GNU Lesser General Public License for more details. * 19 * You should have received a copy of the GNU Lesser General Public License * 20 * along with this library; if not, write to the Free Software Foundation, * 21 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 22 \**************************************************************************/ 23 24 /* $Id: class.accounts_contacts.inc.php 20295 2006-02-15 12:31:25Z $ */ 25 26 27 /* 28 THIS NEEDS WORK!!!!!!!!! - Milosch 29 But it is a lot closer now... 30 */ 31 $GLOBALS['egw_info']['server']['global_denied_users'] = array( 32 'root' => True, 'bin' => True, 'daemon' => True, 33 'adm' => True, 'lp' => True, 'sync' => True, 34 'shutdown' => True, 'halt' => True, 'ldap' => True, 35 'mail' => True, 'news' => True, 'uucp' => True, 36 'operator' => True, 'games' => True, 'gopher' => True, 37 'nobody' => True, 'xfs' => True, 'pgsql' => True, 38 'mysql' => True, 'postgres' => True, 'oracle' => True, 39 'ftp' => True, 'gdm' => True, 'named' => True, 40 'alias' => True, 'web' => True, 'sweep' => True, 41 'cvs' => True, 'qmaild' => True, 'qmaill' => True, 42 'qmaillog' => True, 'qmailp' => True, 'qmailq' => True, 43 'qmailr' => True, 'qmails' => True, 'rpc' => True, 44 'rpcuser' => True, 'amanda' => True, 'apache' => True, 45 'pvm' => True, 'squid' => True, 'ident' => True, 46 'nscd' => True, 'mailnull' => True, 'cyrus' => True, 47 'backup' => True 48 ); 49 50 $GLOBALS['egw_info']['server']['global_denied_groups'] = array( 51 'root' => True, 'bin' => True, 'daemon' => True, 52 'sys' => True, 'adm' => True, 'tty' => True, 53 'disk' => True, 'lp' => True, 'mem' => True, 54 'kmem' => True, 'wheel' => True, 'mail' => True, 55 'uucp' => True, 'man' => True, 'games' => True, 56 'dip' => True, 'ftp' => True, 'nobody' => True, 57 'floppy' => True, 'xfs' => True, 'console' => True, 58 'utmp' => True, 'pppusers' => True, 'popusers' => True, 59 'slipusers' => True, 'slocate' => True, 'mysql' => True, 60 'dnstools' => True, 'web' => True, 'named' => True, 61 'dba' => True, 'oinstall' => True, 'oracle' => True, 62 'gdm' => True, 'sweep' => True, 'cvs' => True, 63 'postgres' => True, 'qmail' => True, 'nofiles' => True, 64 'ldap' => True, 'backup' => True 65 ); 66 67 class accounts_ 68 { 69 var $db; 70 var $contacts; 71 var $account_id; 72 var $data; 73 var $debug = False; 74 var $qcols = array( 75 'fn' => 'fn', 76 'n_given' => 'n_given', 77 'n_family' => 'n_family', 78 'account_lastlogin' => 'account_lastlogin', 79 'account_lastloginfrom' => 'account_lastloginfrom', 80 'account_lastpwd_change' => 'account_lastpwd_change', 81 'account_status' => 'account_status', 82 'account_expires' => 'account_expires' 83 ); 84 85 function accounts_() 86 { 87 $this->db = $GLOBALS['egw']->db; 88 $this->contacts =& CreateObject('phpgwapi.contacts',0); 89 } 90 91 function makeobj() 92 { 93 if(!$this->contacts) 94 { 95 $this->contacts =& CreateObject('phpgwapi.contacts','0'); 96 } 97 } 98 99 function read_repository() 100 { 101 $this->makeobj(); 102 103 $allValues = $this->contacts->read_single_entry($this->account_id,$this->qcols); 104 105 /* Now dump it into the array */ 106 $this->data['userid'] = $allValues[0]['lid']; 107 $this->data['account_id'] = $allValues[0]['id']; 108 $this->data['account_lid'] = $allValues[0]['lid']; 109 $this->data['account_type'] = $allValues[0]['tid']; 110 $this->data['firstname'] = $allValues[0]['n_given']; 111 $this->data['lastname'] = $allValues[0]['n_family']; 112 $this->data['fullname'] = $allValues[0]['fn']; 113 $this->data['lastlogin'] = $allValues[0]['account_lastlogin']; 114 $this->data['lastloginfrom'] = $allValues[0]['account_lastloginfrom']; 115 $this->data['lastpasswd_change'] = $allValues[0]['account_lastpwd_change']; 116 $this->data['status'] = $allValues[0]['account_status']; 117 $this->data['expires'] = $allValues[0]['account_expires']; 118 119 return $this->data; 120 } 121 122 function save_repository() 123 { 124 $this->makeobj(); 125 126 $entry['id'] = $this->data['account_id']; 127 $entry['lid'] = $this->data['account_lid']; 128 $entry['tid'] = $this->data['account_type']; 129 $entry['fn'] = sprintf("%s %s", $this->data['firstname'], $this->data['lastname']); 130 $entry['n_family'] = $this->data['lastname']; 131 $entry['n_given'] = $this->data['firstname']; 132 $entry['account_lastlogin'] = $this->data['lastlogin']; 133 $entry['account_lastloginfrom'] = $this->data['lastloginfrom']; 134 $entry['account_lastpasswd_change'] = $this->data['lastpwd_change']; 135 $entry['account_status'] = $this->data['status']; 136 $entry['account_expires'] = $this->data['expires']; 137 138 if($this->debug) { echo '<br>Updating entry:<br>' . var_dump($entry); } 139 $this->contacts->update($entry['id'],0,$entry,'public','',$entry['tid']); 140 } 141 142 function add($account_name, $account_type, $first_name, $last_name, $passwd = False) 143 { 144 $this->create($account_name, $account_type, $first_name, $last_name, $passwd); 145 } 146 147 function delete($accountid = '') 148 { 149 $this->makeobj(); 150 151 if($this->debug) { echo '<br>Deleting entry:<br>' . $account_id; } 152 $account_id = get_account_id($accountid); 153 $this->contacts->delete($account_id); 154 } 155 156 function get_list($_type='both') 157 { 158 $this->makeobj(); 159 160 switch($_type) 161 { 162 case 'accounts': 163 $filter = 'tid=u'; 164 break; 165 case 'groups': 166 $filter = 'tid=g'; 167 break; 168 default: 169 $filter = 'tid=u,tid=g'; 170 } 171 172 $allValues = $this->contacts->read(0,0,$this->qcols,'',$filter); 173 174 /* get user information for each user/group */ 175 for($i=0;$i<count($allValues);$i++) 176 { 177 $accounts[] = Array( 178 'account_id' => $allValues[$i]['id'], 179 'account_lid' => $allValues[$i]['lid'], 180 'account_type' => $allValues[$i]['tid'], 181 'account_firstname' => $allValues[$i]['n_given'], 182 'account_lastname' => $allValues[$i]['n_family'], 183 'account_status' => $allValues[$i]['account_status'], 184 'account_expires' => $allValues[$i]['account_expires'] 185 ); 186 } 187 188 return $accounts; 189 } 190 191 function name2id($account_lid) 192 { 193 $qcols = array('id' => 'id'); 194 $this->makeobj(); 195 $allValues = $this->contacts->read(0,0,$qcols,'',"lid=".$account_lid); 196 197 if($allValues[0]['id']) 198 { 199 return (int)$allValues[0]['id']; 200 } 201 else 202 { 203 return False; 204 } 205 } 206 207 function id2name($account_id) 208 { 209 $this->makeobj(); 210 211 $allValues = $this->contacts->read_single_entry($account_id); 212 if($this->debug) { echo '<br>id2name: '.$allValues[0]['lid']; } 213 214 if($allValues[0]['lid']) 215 { 216 return $allValues[0]['lid']; 217 } 218 else 219 { 220 return False; 221 } 222 } 223 224 function get_type($accountid = '') 225 { 226 $this->makeobj(); 227 $account_id = get_account_id($accountid); 228 229 $allValues = $this->contacts->read_single_entry($account_id); 230 231 if ($allValues[0]['tid']) 232 { 233 return $allValues[0]['tid']; 234 } 235 else 236 { 237 return False; 238 } 239 } 240 241 function exists($account_lid) 242 { 243 $this->makeobj(); 244 if(is_int($account_lid)) 245 { 246 $account_id = $account_lid; 247 settype($account_lid,'string'); 248 $account_lid = $this->id2name($account_id); 249 } 250 251 $allValues = $this->contacts->read(0,0,array('n_given' => 'n_given'),'','lid='.$account_lid); 252 253 if ($allValues[0]['id']) 254 { 255 return True; 256 } 257 else 258 { 259 return False; 260 } 261 } 262 263 function create($account_info) 264 { 265 $this->makeobj(); 266 267 if (!$$account_info['account_id']) 268 { 269 $account_info['account_id'] = $this->get_nextid(); 270 } 271 $owner = $GLOBALS['egw_info']['user']['account_id']; 272 $entry['id'] = $account_info['account_id']; 273 $entry['lid'] = $account_info['account_lid']; 274 $entry['n_given'] = $account_info['account_firstname']; 275 $entry['n_family'] = $account_info['account_lastname']; 276 $entry['password'] = $account_info['account_passwd']; 277 $entry['account_status'] = $account_info['account_status']; 278 $entry['account_expires'] = $account_info['account_expires']; 279 280 if($this->debug) { echo '<br>Adding entry:<br>' . var_dump($entry); } 281 /* 'public' access, no category id, tid set to account_type */ 282 $this->contacts->add(0,$entry,'public','',$account_info['account_type']); 283 return; 284 } 285 286 function auto_add($accountname, $passwd, $default_prefs = False, $default_acls = False, $expiredate = 0, $account_status = 'A') 287 { 288 if (! $expiredate) 289 { 290 // expire in 30 days by default 291 $expiredate = time() + ( ( 60 * 60 ) * (30 * 24) ); 292 } 293 294 $default_group_id = $this->name2id($GLOBALS['egw_info']['server']['default_group_lid']); 295 if (!$default_group_id) 296 { 297 $default_group_id = (int) $this->name2id('Default'); 298 } 299 $primary_group = $GLOBALS['auto_create_acct']['primary_group'] && 300 $this->get_type((int)$GLOBALS['auto_create_acct']['primary_group']) == 'g' ? 301 (int) $GLOBALS['auto_create_acct']['primary_group'] : $default_group_id; 302 303 $acct_info = array( 304 'account_lid' => $accountname, 305 'account_type' => 'u', 306 'account_passwd' => $passwd, 307 'account_firstname' => $GLOBALS['auto_create_acct']['firstname'] ? $GLOBALS['auto_create_acct']['firstname'] : 'New', 308 'account_lastname' => $GLOBALS['auto_create_acct']['lastname'] ? $GLOBALS['auto_create_acct']['lastname'] : 'User', 309 'account_status' => $account_status, 310 'account_expires' => mktime(2,0,0,date('n',$expiredate), (int)date('d',$expiredate), date('Y',$expiredate)), 311 'account_primary_group' => $primary_group, 312 ); 313 if (isset($GLOBALS['auto_create_acct']['email']) == True && $GLOBALS['auto_create_acct']['email'] != '') 314 { 315 $acct_info['account_email'] = $GLOBALS['auto_create_acct']['email']; 316 } 317 elseif(isset($GLOBALS['egw_info']['server']['mail_suffix']) == True && $GLOBALS['egw_info']['server']['mail_suffix'] != '') 318 { 319 $acct_info['account_email'] = $accountname . '@' . $GLOBALS['egw_info']['server']['mail_suffix']; 320 } 321 322 $this->create($acct_info); 323 $accountid = $this->name2id($accountname); 324 325 if ($accountid) 326 { 327 /* If we have a primary_group, add it as "regular" eGW group (via ACL) too. */ 328 if ($primary_group) 329 { 330 $GLOBALS['egw']->acl->add_repository('phpgw_group', $primary_group,$accountid,1); 331 } 332 // call hook to notify other apps about the new account 333 $GLOBALS['hook_values']['account_lid'] = $acct_info['account_lid']; 334 $GLOBALS['hook_values']['account_id'] = $accountid; 335 $GLOBALS['hook_values']['new_passwd'] = $acct_info['account_passwd']; 336 $GLOBALS['hook_values']['account_status'] = $acct_info['account_status']; 337 $GLOBALS['hook_values']['account_firstname'] = $acct_info['account_firstname']; 338 $GLOBALS['hook_values']['account_lastname'] = $acct_info['account_lastname']; 339 $GLOBALS['egw']->hooks->process($GLOBALS['hook_values']+array( 340 'location' => 'addaccount' 341 ),False,True); /* called for every app now, not only enabled ones */ 342 } 343 return $accountid; 344 } 345 }
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 |