[2] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare - account administration * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * -------------------------------------------- * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 7 | * under the terms of the GNU General Public License as published by the * |
---|
| 8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 9 | * option) any later version. * |
---|
| 10 | \**************************************************************************/ |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | class boaccounts |
---|
| 14 | { |
---|
| 15 | var $so; |
---|
| 16 | var $public_functions = array( |
---|
| 17 | 'add_group' => True, |
---|
| 18 | 'add_user' => True, |
---|
| 19 | 'delete_group' => True, |
---|
| 20 | 'delete_user' => True, |
---|
| 21 | 'edit_group' => True, |
---|
| 22 | 'edit_user' => True, |
---|
| 23 | 'set_group_managers' => True |
---|
| 24 | ); |
---|
| 25 | |
---|
| 26 | var $xml_functions = array(); |
---|
| 27 | |
---|
| 28 | var $soap_functions = array( |
---|
| 29 | 'add_user' => array( |
---|
| 30 | 'in' => array('int', 'struct'), |
---|
| 31 | 'out' => array() |
---|
| 32 | ) |
---|
| 33 | ); |
---|
| 34 | |
---|
| 35 | function boaccounts() |
---|
| 36 | { |
---|
| 37 | $this->so = createobject('admin.soaccounts'); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | function DONTlist_methods($_type='xmlrpc') |
---|
| 41 | { |
---|
| 42 | /* |
---|
| 43 | This handles introspection or discovery by the logged in client, |
---|
| 44 | in which case the input might be an array. The server always calls |
---|
| 45 | this function to fill the server dispatch map using a string. |
---|
| 46 | */ |
---|
| 47 | if (is_array($_type)) |
---|
| 48 | { |
---|
| 49 | $_type = $_type['type'] ? $_type['type'] : $_type[0]; |
---|
| 50 | } |
---|
| 51 | switch($_type) |
---|
| 52 | { |
---|
| 53 | case 'xmlrpc': |
---|
| 54 | $xml_functions = array( |
---|
| 55 | 'rpc_add_user' => array( |
---|
| 56 | 'function' => 'rpc_add_user', |
---|
| 57 | 'signature' => array(array(xmlrpcStruct,xmlrpcStruct)), |
---|
| 58 | 'docstring' => lang('Add a new account.') |
---|
| 59 | ), |
---|
| 60 | 'list_methods' => array( |
---|
| 61 | 'function' => 'list_methods', |
---|
| 62 | 'signature' => array(array(xmlrpcStruct,xmlrpcString)), |
---|
| 63 | 'docstring' => lang('Read this list of methods.') |
---|
| 64 | ) |
---|
| 65 | ); |
---|
| 66 | return $xml_functions; |
---|
| 67 | break; |
---|
| 68 | case 'soap': |
---|
| 69 | return $this->soap_functions; |
---|
| 70 | break; |
---|
| 71 | default: |
---|
| 72 | return array(); |
---|
| 73 | break; |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | function delete_group() |
---|
| 78 | { |
---|
| 79 | if (!@isset($_POST['account_id']) || !@$_POST['account_id'] || $GLOBALS['phpgw']->acl->check('group_access',32,'admin')) |
---|
| 80 | { |
---|
| 81 | ExecMethod('admin.uiaccounts.list_groups'); |
---|
| 82 | return False; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | $account_id = (int)$_POST['account_id']; |
---|
| 86 | |
---|
| 87 | $GLOBALS['phpgw']->db->lock( |
---|
| 88 | Array( |
---|
| 89 | 'phpgw_accounts', |
---|
| 90 | 'phpgw_app_sessions', |
---|
| 91 | 'phpgw_acl' |
---|
| 92 | ) |
---|
| 93 | ); |
---|
| 94 | |
---|
| 95 | $old_group_list = $GLOBALS['phpgw']->acl->get_ids_for_location($account_id,1,'phpgw_group'); |
---|
| 96 | |
---|
| 97 | @reset($old_group_list); |
---|
| 98 | while($old_group_list && $id = each($old_group_list)) |
---|
| 99 | { |
---|
| 100 | $GLOBALS['phpgw']->acl->delete_repository('phpgw_group',$account_id,(int)$id[1]); |
---|
| 101 | $GLOBALS['phpgw']->session->delete_cache((int)$id[1]); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | $GLOBALS['phpgw']->acl->delete_repository('%%','run',$account_id); |
---|
| 105 | |
---|
| 106 | if (! @rmdir($GLOBALS['phpgw_info']['server']['files_dir'].SEP.'groups'.SEP.$GLOBALS['phpgw']->accounts->id2name($account_id))) |
---|
| 107 | { |
---|
| 108 | $cd = 38; |
---|
| 109 | } |
---|
| 110 | else |
---|
| 111 | { |
---|
| 112 | $cd = 32; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | $GLOBALS['phpgw']->accounts->delete($account_id); |
---|
| 116 | |
---|
| 117 | $GLOBALS['phpgw']->db->unlock(); |
---|
| 118 | |
---|
| 119 | Header('Location: '.$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_groups')); |
---|
| 120 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | function delete_user() |
---|
| 124 | { |
---|
| 125 | if (isset($_POST['cancel']) || $GLOBALS['phpgw']->acl->check('account_access',32,'admin')) |
---|
| 126 | { |
---|
| 127 | ExecMethod('admin.uiaccounts.list_users'); |
---|
| 128 | return False; |
---|
| 129 | } |
---|
| 130 | elseif($_POST['delete_account']) |
---|
| 131 | { |
---|
| 132 | $accountid = $_POST['account_id']; |
---|
| 133 | settype($account_id,'integer'); |
---|
| 134 | $account_id = get_account_id($accountid); |
---|
| 135 | // make this information also in hook available |
---|
| 136 | $lid = $GLOBALS['phpgw']->accounts->id2name($account_id); |
---|
| 137 | |
---|
| 138 | $GLOBALS['hook_values']['account_id'] = $account_id; |
---|
| 139 | $GLOBALS['hook_values']['account_lid'] = $lid; |
---|
| 140 | |
---|
| 141 | $singleHookValues = $GLOBALS['hook_values']+array('location' => 'deleteaccount'); |
---|
| 142 | |
---|
| 143 | $db = $GLOBALS['phpgw']->db; |
---|
| 144 | $db->query('SELECT app_name,app_order FROM phpgw_applications WHERE app_enabled!=0 ORDER BY app_order',__LINE__,__FILE__); |
---|
| 145 | if($db->num_rows()) |
---|
| 146 | { |
---|
| 147 | while($db->next_record()) |
---|
| 148 | { |
---|
| 149 | $appname = $db->f('app_name'); |
---|
| 150 | |
---|
| 151 | if($appname <> 'admin' || $appname <> 'preferences') |
---|
| 152 | { |
---|
| 153 | $GLOBALS['phpgw']->hooks->single($singleHookValues, $appname); |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | $GLOBALS['phpgw']->hooks->single('deleteaccount','preferences'); |
---|
| 159 | $GLOBALS['phpgw']->hooks->single('deleteaccount','admin'); |
---|
| 160 | |
---|
| 161 | $basedir = $GLOBALS['phpgw_info']['server']['files_dir'] . SEP . 'users' . SEP; |
---|
| 162 | |
---|
| 163 | if (! @rmdir($basedir . $lid)) |
---|
| 164 | { |
---|
| 165 | $cd = 34; |
---|
| 166 | } |
---|
| 167 | else |
---|
| 168 | { |
---|
| 169 | $cd = 29; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | ExecMethod('admin.uiaccounts.list_users'); |
---|
| 173 | return False; |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | function add_group() |
---|
| 178 | { |
---|
| 179 | if ($GLOBALS['phpgw']->acl->check('group_access',4,'admin')) |
---|
| 180 | { |
---|
| 181 | ExecMethod('admin.uiaccounts.list_groups'); |
---|
| 182 | return False; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | $temp_users = ($_POST['account_user']?$_POST['account_user']:Array()); |
---|
| 186 | $account_user = Array(); |
---|
| 187 | @reset($temp_users); |
---|
| 188 | while(list($key,$user_id) = each($temp_users)) |
---|
| 189 | { |
---|
| 190 | $account_user[$user_id] = ' selected'; |
---|
| 191 | } |
---|
| 192 | @reset($account_user); |
---|
| 193 | |
---|
| 194 | $group_permissions = ($_POST['account_apps']?$_POST['account_apps']:Array()); |
---|
| 195 | $account_apps = Array(); |
---|
| 196 | @reset($group_permissions); |
---|
| 197 | while(list($key,$value) = each($group_permissions)) |
---|
| 198 | { |
---|
| 199 | if($value) |
---|
| 200 | { |
---|
| 201 | $account_apps[$key] = True; |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | @reset($account_apps); |
---|
| 205 | |
---|
| 206 | $group_info = Array( |
---|
| 207 | 'account_id' => ($_POST['account_id']?(int)$_POST['account_id']:0), |
---|
| 208 | 'account_name' => ($_POST['account_name']?$_POST['account_name']:''), |
---|
| 209 | 'account_user' => $account_user, |
---|
| 210 | 'account_apps' => $account_apps |
---|
| 211 | ); |
---|
| 212 | |
---|
| 213 | $this->validate_group($group_info); |
---|
| 214 | |
---|
| 215 | $GLOBALS['phpgw']->db->lock( |
---|
| 216 | Array( |
---|
| 217 | 'phpgw_accounts', |
---|
| 218 | 'phpgw_nextid', |
---|
| 219 | 'phpgw_preferences', |
---|
| 220 | 'phpgw_sessions', |
---|
| 221 | 'phpgw_acl', |
---|
| 222 | 'phpgw_applications', |
---|
| 223 | 'phpgw_app_sessions', |
---|
| 224 | 'phpgw_hooks' |
---|
| 225 | ) |
---|
| 226 | ); |
---|
| 227 | |
---|
| 228 | $group = CreateObject('phpgwapi.accounts',$group_info['account_id'],'g'); |
---|
| 229 | $group->acct_type = 'g'; |
---|
| 230 | $account_info = array( |
---|
| 231 | 'account_type' => 'g', |
---|
| 232 | 'account_lid' => $group_info['account_name'], |
---|
| 233 | 'account_passwd' => '', |
---|
| 234 | 'account_firstname' => $group_info['account_name'], |
---|
| 235 | 'account_lastname' => 'Group', |
---|
| 236 | 'account_status' => 'A', |
---|
| 237 | 'account_expires' => -1 |
---|
| 238 | // 'account_file_space' => $account_file_space_number . "-" . $account_file_space_type, |
---|
| 239 | ); |
---|
| 240 | $group_info['account_id'] = $group->create($account_info); |
---|
| 241 | // do the following only if we got an id - the create succided |
---|
| 242 | if ($group_info['account_id']) |
---|
| 243 | { |
---|
| 244 | $apps = CreateObject('phpgwapi.applications',$group_info['account_id']); |
---|
| 245 | $apps->update_data(Array()); |
---|
| 246 | reset($group_info['account_apps']); |
---|
| 247 | while(list($app,$value) = each($group_info['account_apps'])) |
---|
| 248 | { |
---|
| 249 | $apps->add($app); |
---|
| 250 | $new_apps[] = $app; |
---|
| 251 | } |
---|
| 252 | $apps->save_repository(); |
---|
| 253 | |
---|
| 254 | $acl = CreateObject('phpgwapi.acl',$group_info['account_id']); |
---|
| 255 | $acl->read_repository(); |
---|
| 256 | |
---|
| 257 | @reset($group_info['account_user']); |
---|
| 258 | while(list($user_id,$dummy) = each($group_info['account_user'])) |
---|
| 259 | { |
---|
| 260 | if(!$dummy) |
---|
| 261 | { |
---|
| 262 | continue; |
---|
| 263 | } |
---|
| 264 | $acl->add_repository('phpgw_group',$group_info['account_id'],$user_id,1); |
---|
| 265 | |
---|
| 266 | $docommit = False; |
---|
| 267 | $GLOBALS['pref'] = CreateObject('phpgwapi.preferences',$user_id); |
---|
| 268 | $t = $GLOBALS['pref']->read_repository(); |
---|
| 269 | @reset($new_apps); |
---|
| 270 | while(is_array($new_apps) && list($app_key,$app_name) = each($new_apps)) |
---|
| 271 | { |
---|
| 272 | if (!$t[($app_name=='admin'?'common':$app_name)]) |
---|
| 273 | { |
---|
| 274 | $GLOBALS['phpgw']->hooks->single('add_def_pref', $app_name); |
---|
| 275 | $docommit = True; |
---|
| 276 | } |
---|
| 277 | } |
---|
| 278 | if ($docommit) |
---|
| 279 | { |
---|
| 280 | $GLOBALS['pref']->save_repository(); |
---|
| 281 | } |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | $acl->save_repository(); |
---|
| 285 | |
---|
| 286 | $basedir = $GLOBALS['phpgw_info']['server']['files_dir'] . SEP . 'groups' . SEP; |
---|
| 287 | $cd = 31; |
---|
| 288 | umask(000); |
---|
| 289 | if (! @mkdir ($basedir . $group_info['account_name'], 0707)) |
---|
| 290 | { |
---|
| 291 | $cd = 37; |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | $GLOBALS['phpgw']->db->unlock(); |
---|
| 295 | } |
---|
| 296 | ExecMethod('admin.uiaccounts.list_groups'); |
---|
| 297 | |
---|
| 298 | return False; |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | function add_user() |
---|
| 302 | { |
---|
| 303 | if ($GLOBALS['phpgw']->acl->check('account_access',4,'admin')) |
---|
| 304 | { |
---|
| 305 | ExecMethod('admin.uiaccounts.list_users'); |
---|
| 306 | return False; |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | $accountPrefix = ''; |
---|
| 310 | if(isset($GLOBALS['phpgw_info']['server']['account_prefix'])) |
---|
| 311 | { |
---|
| 312 | $accountPrefix = $GLOBALS['phpgw_info']['server']['account_prefix']; |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | if ($_POST['submit']) |
---|
| 316 | { |
---|
| 317 | $userData = array( |
---|
| 318 | 'account_type' => 'u', |
---|
| 319 | 'account_lid' => $accountPrefix.$_POST['account_lid'], |
---|
| 320 | 'account_firstname' => $_POST['account_firstname'], |
---|
| 321 | 'account_lastname' => $_POST['account_lastname'], |
---|
| 322 | 'account_passwd' => $_POST['account_passwd'], |
---|
| 323 | 'status' => ($_POST['account_status'] ? 'A' : ''), |
---|
| 324 | 'account_status' => ($_POST['account_status'] ? 'A' : ''), |
---|
| 325 | 'old_loginid' => ($_GET['old_loginid']?rawurldecode($_GET['old_loginid']):''), |
---|
| 326 | 'account_id' => ($_GET['account_id']?$_GET['account_id']:0), |
---|
| 327 | 'account_primary_group' => $_POST['account_primary_group'], |
---|
| 328 | 'account_passwd_2' => $_POST['account_passwd_2'], |
---|
| 329 | 'account_groups' => $_POST['account_groups'], |
---|
| 330 | 'anonymous' => $_POST['anonymous'], |
---|
| 331 | 'changepassword' => $_POST['changepassword'], |
---|
| 332 | 'account_permissions' => $_POST['account_permissions'], |
---|
| 333 | 'homedirectory' => $_POST['homedirectory'], |
---|
| 334 | 'loginshell' => $_POST['loginshell'], |
---|
| 335 | 'account_expires_never' => $_POST['never_expires'], |
---|
| 336 | 'account_email' => $_POST['account_email'], |
---|
| 337 | /* 'file_space' => $_POST['account_file_space_number'] . "-" . $_POST['account_file_space_type'] */ |
---|
| 338 | ); |
---|
| 339 | |
---|
| 340 | // add the primary group, to the users other groups, if not already added |
---|
| 341 | if(is_array($userData['account_groups'])) |
---|
| 342 | { |
---|
| 343 | if(!in_array($userData['account_primary_group'],$userData['account_groups'])) |
---|
| 344 | { |
---|
| 345 | $userData['account_groups'][] = (int)$userData['account_primary_group']; |
---|
| 346 | } |
---|
| 347 | } |
---|
| 348 | else |
---|
| 349 | { |
---|
| 350 | $userData['account_groups'] = array((int)$userData['account_primary_group']); |
---|
| 351 | } |
---|
| 352 | |
---|
| 353 | // when does the account expire |
---|
| 354 | if ($_POST['expires'] !== '' && !$_POST['never_expires']) |
---|
| 355 | { |
---|
| 356 | $jscal = CreateObject('phpgwapi.jscalendar',False); |
---|
| 357 | $userData += $jscal->input2date($_POST['expires'],False,'account_expires_day','account_expires_month','account_expires_year'); |
---|
| 358 | } |
---|
| 359 | |
---|
| 360 | // do we have all needed data?? |
---|
| 361 | if (!($errors = $this->validate_user($userData)) && |
---|
| 362 | ($userData['account_id'] = $account_id = $this->so->add_user($userData))) // no error in the creation |
---|
| 363 | { |
---|
| 364 | if ($userData['anonymous']) |
---|
| 365 | { |
---|
| 366 | $GLOBALS['phpgw']->acl->add_repository('phpgwapi','anonymous',$account_id,1); |
---|
| 367 | } |
---|
| 368 | else |
---|
| 369 | { |
---|
| 370 | $GLOBALS['phpgw']->acl->delete_repository('phpgwapi','anonymous',$account_id); |
---|
| 371 | } |
---|
| 372 | // make this information for the hooks available |
---|
| 373 | $GLOBALS['hook_values'] = $userData + array('new_passwd' => $userData['account_passwd']); |
---|
| 374 | $GLOBALS['phpgw']->hooks->process($GLOBALS['hook_values']+array( |
---|
| 375 | 'location' => 'addaccount' |
---|
| 376 | ),False,True); // called for every app now, not only enabled ones |
---|
| 377 | |
---|
| 378 | ExecMethod('admin.uiaccounts.list_users'); |
---|
| 379 | return False; |
---|
| 380 | } |
---|
| 381 | else |
---|
| 382 | { |
---|
| 383 | $ui = createobject('admin.uiaccounts'); |
---|
| 384 | $ui->create_edit_user($userData['account_id'],$userData,$errors); |
---|
| 385 | } |
---|
| 386 | } |
---|
| 387 | else |
---|
| 388 | { |
---|
| 389 | ExecMethod('admin.uiaccounts.list_users'); |
---|
| 390 | return False; |
---|
| 391 | } |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | function edit_group() |
---|
| 395 | { |
---|
| 396 | if ($GLOBALS['phpgw']->acl->check('group_access',16,'admin')) |
---|
| 397 | { |
---|
| 398 | ExecMethod('admin.uiaccounts.list_groups'); |
---|
| 399 | return False; |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | $temp_users = ($_POST['account_user']?$_POST['account_user']:Array()); |
---|
| 403 | $account_user = Array(); |
---|
| 404 | @reset($temp_users); |
---|
| 405 | while($temp_users && list($key,$user_id) = each($temp_users)) |
---|
| 406 | { |
---|
| 407 | $account_user[$user_id] = ' selected'; |
---|
| 408 | } |
---|
| 409 | @reset($account_user); |
---|
| 410 | |
---|
| 411 | $group_permissions = ($_POST['account_apps']?$_POST['account_apps']:Array()); |
---|
| 412 | $account_apps = Array(); |
---|
| 413 | @reset($group_permissions); |
---|
| 414 | while(list($key,$value) = each($group_permissions)) |
---|
| 415 | { |
---|
| 416 | if($value) |
---|
| 417 | { |
---|
| 418 | $account_apps[$key] = True; |
---|
| 419 | } |
---|
| 420 | } |
---|
| 421 | @reset($account_apps); |
---|
| 422 | |
---|
| 423 | $group_info = Array( |
---|
| 424 | 'account_id' => ($_POST['account_id']?(int)$_POST['account_id']:0), |
---|
| 425 | 'account_name' => ($_POST['account_name']?$_POST['account_name']:''), |
---|
| 426 | 'account_user' => $account_user, |
---|
| 427 | 'account_apps' => $account_apps |
---|
| 428 | ); |
---|
| 429 | |
---|
| 430 | $this->validate_group($group_info); |
---|
| 431 | |
---|
| 432 | // Lock tables |
---|
| 433 | $GLOBALS['phpgw']->db->lock( |
---|
| 434 | Array( |
---|
| 435 | 'phpgw_accounts', |
---|
| 436 | 'phpgw_preferences', |
---|
| 437 | 'phpgw_config', |
---|
| 438 | 'phpgw_applications', |
---|
| 439 | 'phpgw_hooks', |
---|
| 440 | 'phpgw_sessions', |
---|
| 441 | 'phpgw_acl', |
---|
| 442 | 'phpgw_app_sessions' |
---|
| 443 | ) |
---|
| 444 | ); |
---|
| 445 | |
---|
| 446 | $group = CreateObject('phpgwapi.accounts',$group_info['account_id'],'g'); |
---|
| 447 | $old_group_info = $group->read_repository(); |
---|
| 448 | |
---|
| 449 | // Set group apps |
---|
| 450 | $apps = CreateObject('phpgwapi.applications',$group_info['account_id']); |
---|
| 451 | $apps_before = $apps->read_account_specific(); |
---|
| 452 | $apps->update_data(Array()); |
---|
| 453 | $new_apps = Array(); |
---|
| 454 | if(count($group_info['account_apps'])) |
---|
| 455 | { |
---|
| 456 | reset($group_info['account_apps']); |
---|
| 457 | while(list($app,$value) = each($group_info['account_apps'])) |
---|
| 458 | { |
---|
| 459 | $apps->add($app); |
---|
| 460 | if(!@$apps_before[$app] || @$apps_before == False) |
---|
| 461 | { |
---|
| 462 | $new_apps[] = $app; |
---|
| 463 | } |
---|
| 464 | } |
---|
| 465 | } |
---|
| 466 | $apps->save_repository(); |
---|
| 467 | |
---|
| 468 | // Set new account_lid, if needed |
---|
| 469 | if($group_info['account_name'] && $old_group_info['account_lid'] <> $group_info['account_name']) |
---|
| 470 | { |
---|
| 471 | $group->data['account_lid'] = $group_info['account_name']; |
---|
| 472 | $group->data['firstname'] = $group_info['account_name']; |
---|
| 473 | |
---|
| 474 | $basedir = $GLOBALS['phpgw_info']['server']['files_dir'] . SEP . 'groups' . SEP; |
---|
| 475 | if (! @rename($basedir . $old_group_info['account_lid'], $basedir . $group_info['account_name'])) |
---|
| 476 | { |
---|
| 477 | $cd = 39; |
---|
| 478 | } |
---|
| 479 | else |
---|
| 480 | { |
---|
| 481 | $cd = 33; |
---|
| 482 | } |
---|
| 483 | } |
---|
| 484 | else |
---|
| 485 | { |
---|
| 486 | $cd = 33; |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | // Set group acl |
---|
| 490 | $acl = CreateObject('phpgwapi.acl',$group_info['account_id']); |
---|
| 491 | $old_group_list = $acl->get_ids_for_location($group_info['account_id'],1,'phpgw_group'); |
---|
| 492 | @reset($old_group_list); |
---|
| 493 | while($old_group_list && list($key,$user_id) = each($old_group_list)) |
---|
| 494 | { |
---|
| 495 | $acl->delete_repository('phpgw_group',$group_info['account_id'],$user_id); |
---|
| 496 | if(!$group_info['account_user'][$user_id]) |
---|
| 497 | { |
---|
| 498 | // If the user is logged in, it will force a refresh of the session_info |
---|
| 499 | $GLOBALS['phpgw']->db->query("update phpgw_sessions set session_action='' " |
---|
| 500 | ."where session_lid='" . $GLOBALS['phpgw']->accounts->id2name($user_id) |
---|
| 501 | . '@' . $GLOBALS['phpgw_info']['user']['domain'] . "'",__LINE__,__FILE__); |
---|
| 502 | $GLOBALS['phpgw']->session->delete_cache($user_id); |
---|
| 503 | } |
---|
| 504 | } |
---|
| 505 | |
---|
| 506 | @reset($group_info['account_user']); |
---|
| 507 | while(list($user_id,$dummy) = each($group_info['account_user'])) |
---|
| 508 | { |
---|
| 509 | if(!$dummy) |
---|
| 510 | { |
---|
| 511 | continue; |
---|
| 512 | } |
---|
| 513 | $acl->add_repository('phpgw_group',$group_info['account_id'],$user_id,1); |
---|
| 514 | |
---|
| 515 | // If the user is logged in, it will force a refresh of the session_info |
---|
| 516 | $GLOBALS['phpgw']->db->query("update phpgw_sessions set session_action='' " |
---|
| 517 | ."where session_lid='" . $GLOBALS['phpgw']->accounts->id2name($user_id) |
---|
| 518 | . '@' . $GLOBALS['phpgw_info']['user']['domain'] . "'",__LINE__,__FILE__); |
---|
| 519 | |
---|
| 520 | $GLOBALS['phpgw']->session->delete_cache($user_id); |
---|
| 521 | |
---|
| 522 | // The following sets any default preferences needed for new applications.. |
---|
| 523 | // This is smart enough to know if previous preferences were selected, use them. |
---|
| 524 | $docommit = False; |
---|
| 525 | if($new_apps) |
---|
| 526 | { |
---|
| 527 | $GLOBALS['pref'] = CreateObject('phpgwapi.preferences',$user_id); |
---|
| 528 | $t = $GLOBALS['pref']->read_repository(); |
---|
| 529 | @reset($new_apps); |
---|
| 530 | while(list($app_key,$app_name) = each($new_apps)) |
---|
| 531 | { |
---|
| 532 | if (!$t[($app_name=='admin'?'common':$app_name)]) |
---|
| 533 | { |
---|
| 534 | $GLOBALS['phpgw']->hooks->single('add_def_pref', $app_name); |
---|
| 535 | $docommit = True; |
---|
| 536 | } |
---|
| 537 | } |
---|
| 538 | } |
---|
| 539 | if ($docommit) |
---|
| 540 | { |
---|
| 541 | $GLOBALS['pref']->save_repository(); |
---|
| 542 | } |
---|
| 543 | } |
---|
| 544 | |
---|
| 545 | // This is down here so we are sure to catch the acl changes |
---|
| 546 | // for LDAP to update the memberuid attribute |
---|
| 547 | $group->save_repository(); |
---|
| 548 | |
---|
| 549 | $GLOBALS['phpgw']->db->unlock(); |
---|
| 550 | |
---|
| 551 | ExecMethod('admin.uiaccounts.list_groups'); |
---|
| 552 | return False; |
---|
| 553 | } |
---|
| 554 | |
---|
| 555 | function edit_user() |
---|
| 556 | { |
---|
| 557 | if ($GLOBALS['phpgw']->acl->check('account_access',16,'admin')) |
---|
| 558 | { |
---|
| 559 | ExecMethod('admin.uiaccounts.list_users'); |
---|
| 560 | return False; |
---|
| 561 | } |
---|
| 562 | |
---|
| 563 | $accountPrefix = ''; |
---|
| 564 | if(isset($GLOBALS['phpgw_info']['server']['account_prefix'])) |
---|
| 565 | { |
---|
| 566 | $accountPrefix = $GLOBALS['phpgw_info']['server']['account_prefix']; |
---|
| 567 | } |
---|
| 568 | |
---|
| 569 | if ($_POST['submit']) |
---|
| 570 | { |
---|
| 571 | $userData = array( |
---|
| 572 | 'account_lid' => $accountPrefix.$_POST['account_lid'], |
---|
| 573 | 'firstname' => $_POST['account_firstname'], |
---|
| 574 | 'lastname' => $_POST['account_lastname'], |
---|
| 575 | 'account_passwd' => $_POST['account_passwd'], |
---|
| 576 | 'status' => ($_POST['account_status'] ? 'A' : ''), |
---|
| 577 | 'account_status' => ($_POST['account_status'] ? 'A' : ''), |
---|
| 578 | 'old_loginid' => ($_GET['old_loginid']?rawurldecode($_GET['old_loginid']):''), |
---|
| 579 | 'account_id' => ($_GET['account_id']?$_GET['account_id']:0), |
---|
| 580 | 'account_passwd_2' => $_POST['account_passwd_2'], |
---|
| 581 | 'account_groups' => $_POST['account_groups'], |
---|
| 582 | 'account_primary_group' => $_POST['account_primary_group'], |
---|
| 583 | 'anonymous' => $_POST['anonymous'], |
---|
| 584 | 'changepassword' => $_POST['changepassword'], |
---|
| 585 | 'account_permissions' => $_POST['account_permissions'], |
---|
| 586 | 'homedirectory' => $_POST['homedirectory'], |
---|
| 587 | 'loginshell' => $_POST['loginshell'], |
---|
| 588 | 'account_expires_never' => $_POST['never_expires'], |
---|
| 589 | 'email' => $_POST['account_email'], |
---|
| 590 | /* 'file_space' => $_POST['account_file_space_number'] . "-" . $_POST['account_file_space_type'] */ |
---|
| 591 | ); |
---|
| 592 | if ($userData['account_primary_group'] && (!isset($userData['account_groups']) || !in_array($userData['account_primary_group'],$userData['account_groups']))) |
---|
| 593 | { |
---|
| 594 | $userData['account_groups'][] = (int)$userData['account_primary_group']; |
---|
| 595 | } |
---|
| 596 | if ($_POST['expires'] !== '' && !$_POST['never_expires']) |
---|
| 597 | { |
---|
| 598 | $jscal = CreateObject('phpgwapi.jscalendar',False); |
---|
| 599 | $userData += $jscal->input2date($_POST['expires'],False,'account_expires_day','account_expires_month','account_expires_year'); |
---|
| 600 | } |
---|
| 601 | if (!$errors = $this->validate_user($userData)) |
---|
| 602 | { |
---|
| 603 | $this->save_user($userData); |
---|
| 604 | $GLOBALS['hook_values'] = $userData; |
---|
| 605 | $GLOBALS['phpgw']->hooks->process($GLOBALS['hook_values']+array( |
---|
| 606 | 'location' => 'editaccount' |
---|
| 607 | ),False,True); // called for every app now, not only enabled ones) |
---|
| 608 | |
---|
| 609 | // check if would create a menu |
---|
| 610 | // if we do, we can't return to the users list, because |
---|
| 611 | // there are also some other plugins |
---|
| 612 | if (!ExecMethod('admin.uimenuclass.createHTMLCode','edit_user')) |
---|
| 613 | { |
---|
| 614 | ExecMethod('admin.uiaccounts.list_users'); |
---|
| 615 | return False; |
---|
| 616 | } |
---|
| 617 | else |
---|
| 618 | { |
---|
| 619 | ExecMethod('admin.uiaccounts.edit_user',$_GET['account_id']); |
---|
| 620 | return False; |
---|
| 621 | } |
---|
| 622 | } |
---|
| 623 | else |
---|
| 624 | { |
---|
| 625 | $ui = createobject('admin.uiaccounts'); |
---|
| 626 | $ui->create_edit_user($userData['account_id'],$userData,$errors); |
---|
| 627 | } |
---|
| 628 | } |
---|
| 629 | } |
---|
| 630 | |
---|
| 631 | function set_group_managers() |
---|
| 632 | { |
---|
| 633 | if($GLOBALS['phpgw']->acl->check('group_access',16,'admin') || $_POST['cancel']) |
---|
| 634 | { |
---|
| 635 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_groups')); |
---|
| 636 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
| 637 | } |
---|
| 638 | elseif($_POST['submit']) |
---|
| 639 | { |
---|
| 640 | $acl = CreateObject('phpgwapi.acl',(int)$_POST['account_id']); |
---|
| 641 | |
---|
| 642 | $users = $GLOBALS['phpgw']->accounts->member($_POST['account_id']); |
---|
| 643 | @reset($users); |
---|
| 644 | while($managers && list($key,$user) = each($users)) |
---|
| 645 | { |
---|
| 646 | $acl->add_repository('phpgw_group',(int)$_POST['account_id'],$user['account_id'],1); |
---|
| 647 | } |
---|
| 648 | $managers = $_POST['managers']; |
---|
| 649 | @reset($managers); |
---|
| 650 | while($managers && list($key,$manager) = each($managers)) |
---|
| 651 | { |
---|
| 652 | $acl->add_repository('phpgw_group',(int)$_POST['account_id'],$manager,(1 + PHPGW_ACL_GROUP_MANAGERS)); |
---|
| 653 | } |
---|
| 654 | } |
---|
| 655 | $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_groups')); |
---|
| 656 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
| 657 | } |
---|
| 658 | |
---|
| 659 | function validate_group($group_info) |
---|
| 660 | { |
---|
| 661 | $errors = Array(); |
---|
| 662 | |
---|
| 663 | $group = CreateObject('phpgwapi.accounts',$group_info['account_id'],'g'); |
---|
| 664 | $group->read_repository(); |
---|
| 665 | |
---|
| 666 | if(!$group_info['account_name']) |
---|
| 667 | { |
---|
| 668 | $errors[] = lang('You must enter a group name.'); |
---|
| 669 | } |
---|
| 670 | |
---|
| 671 | if($group_info['account_name'] != $group->id2name($group_info['account_id'])) |
---|
| 672 | { |
---|
| 673 | if ($group->exists($group_info['account_name'])) |
---|
| 674 | { |
---|
| 675 | $errors[] = lang('Sorry, that group name has already been taken.'); |
---|
| 676 | } |
---|
| 677 | } |
---|
| 678 | |
---|
| 679 | /* |
---|
| 680 | if (preg_match ("/\D/", $account_file_space_number)) |
---|
| 681 | { |
---|
| 682 | $errors[] = lang ('File space must be an integer'); |
---|
| 683 | } |
---|
| 684 | */ |
---|
| 685 | if(count($errors)) |
---|
| 686 | { |
---|
| 687 | $ui = createobject('admin.uiaccounts'); |
---|
| 688 | $ui->create_edit_group($group_info,$errors); |
---|
| 689 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
| 690 | } |
---|
| 691 | } |
---|
| 692 | |
---|
| 693 | /* checks if the userdata are valid |
---|
| 694 | returns FALSE if the data are correct |
---|
| 695 | otherwise the error array |
---|
| 696 | */ |
---|
| 697 | function validate_user(&$_userData) |
---|
| 698 | { |
---|
| 699 | $totalerrors = 0; |
---|
| 700 | |
---|
| 701 | if ($GLOBALS['phpgw_info']['server']['account_repository'] == 'ldap' && |
---|
| 702 | (!$_userData['account_lastname'] && !$_userData['lastname'])) |
---|
| 703 | { |
---|
| 704 | $error[$totalerrors] = lang('You must enter a lastname'); |
---|
| 705 | $totalerrors++; |
---|
| 706 | } |
---|
| 707 | |
---|
| 708 | if (!$_userData['account_lid']) |
---|
| 709 | { |
---|
| 710 | $error[$totalerrors] = lang('You must enter a loginid'); |
---|
| 711 | $totalerrors++; |
---|
| 712 | } |
---|
| 713 | |
---|
| 714 | if(!in_array($_userData['account_primary_group'],$_userData['account_groups'])) |
---|
| 715 | { |
---|
| 716 | $error[$totalerrors] = lang('The groups must include the primary group'); |
---|
| 717 | $totalerrors++; |
---|
| 718 | } |
---|
| 719 | |
---|
| 720 | if ($_userData['old_loginid'] != $_userData['account_lid']) |
---|
| 721 | { |
---|
| 722 | if ($GLOBALS['phpgw']->accounts->exists($_userData['account_lid'])) |
---|
| 723 | { |
---|
| 724 | if ($GLOBALS['phpgw']->accounts->exists($_userData['account_lid']) && $GLOBALS['phpgw']->accounts->get_type($_userData['account_lid'])=='g') |
---|
| 725 | { |
---|
| 726 | $error[$totalerrors] = lang('There already is a group with this name. Userid\'s can not have the same name as a groupid'); |
---|
| 727 | } |
---|
| 728 | else |
---|
| 729 | { |
---|
| 730 | $error[$totalerrors] = lang('That loginid has already been taken'); |
---|
| 731 | } |
---|
| 732 | $totalerrors++; |
---|
| 733 | } |
---|
| 734 | } |
---|
| 735 | |
---|
| 736 | if ($_userData['account_passwd'] || $_userData['account_passwd_2']) |
---|
| 737 | { |
---|
| 738 | if ($_userData['account_passwd'] != $_userData['account_passwd_2']) |
---|
| 739 | { |
---|
| 740 | $error[$totalerrors] = lang('The two passwords are not the same'); |
---|
| 741 | $totalerrors++; |
---|
| 742 | } |
---|
| 743 | } |
---|
| 744 | |
---|
| 745 | if (!count($_userData['account_permissions']) && !count($_userData['account_groups'])) |
---|
| 746 | { |
---|
| 747 | $error[$totalerrors] = lang('You must add at least 1 permission or group to this account'); |
---|
| 748 | $totalerrors++; |
---|
| 749 | } |
---|
| 750 | |
---|
| 751 | if ($_userData['account_expires_month'] || $_userData['account_expires_day'] || $_userData['account_expires_year'] || $_userData['account_expires_never']) |
---|
| 752 | { |
---|
| 753 | if($_userData['account_expires_never']) |
---|
| 754 | { |
---|
| 755 | $_userData['expires'] = -1; |
---|
| 756 | $_userData['account_expires'] = $_userData['expires']; |
---|
| 757 | } |
---|
| 758 | else |
---|
| 759 | { |
---|
| 760 | if (! checkdate($_userData['account_expires_month'],$_userData['account_expires_day'],$_userData['account_expires_year'])) |
---|
| 761 | { |
---|
| 762 | $error[$totalerrors] = lang('You have entered an invalid expiration date'); |
---|
| 763 | $totalerrors++; |
---|
| 764 | } |
---|
| 765 | else |
---|
| 766 | { |
---|
| 767 | $_userData['expires'] = mktime(2,0,0,$_userData['account_expires_month'],$_userData['account_expires_day'],$_userData['account_expires_year']); |
---|
| 768 | $_userData['account_expires'] = $_userData['expires']; |
---|
| 769 | } |
---|
| 770 | } |
---|
| 771 | } |
---|
| 772 | else |
---|
| 773 | { |
---|
| 774 | $_userData['expires'] = -1; |
---|
| 775 | $_userData['account_expires'] = $_userData['expires']; |
---|
| 776 | } |
---|
| 777 | |
---|
| 778 | /* |
---|
| 779 | $check_account_file_space = explode ('-', $_userData['file_space']); |
---|
| 780 | if (preg_match ("/\D/", $check_account_file_space[0])) |
---|
| 781 | { |
---|
| 782 | $error[$totalerrors] = lang ('File space must be an integer'); |
---|
| 783 | $totalerrors++; |
---|
| 784 | } |
---|
| 785 | */ |
---|
| 786 | |
---|
| 787 | if ($totalerrors == 0) |
---|
| 788 | { |
---|
| 789 | return FALSE; |
---|
| 790 | } |
---|
| 791 | else |
---|
| 792 | { |
---|
| 793 | return $error; |
---|
| 794 | } |
---|
| 795 | } |
---|
| 796 | |
---|
| 797 | /* stores the userdata */ |
---|
| 798 | function save_user($_userData) |
---|
| 799 | { |
---|
| 800 | $account = CreateObject('phpgwapi.accounts',$_userData['account_id'],'u'); |
---|
| 801 | $account->update_data($_userData); |
---|
| 802 | $account->save_repository(); |
---|
| 803 | if ($_userData['account_passwd']) |
---|
| 804 | { |
---|
| 805 | $auth = CreateObject('phpgwapi.auth'); |
---|
| 806 | $auth->change_password($old_passwd, $_userData['account_passwd'], $_userData['account_id']); |
---|
| 807 | $GLOBALS['hook_values']['account_id'] = $_userData['account_id']; |
---|
| 808 | $GLOBALS['hook_values']['old_passwd'] = $old_passwd; |
---|
| 809 | $GLOBALS['hook_values']['new_passwd'] = $_userData['account_passwd']; |
---|
| 810 | |
---|
| 811 | $GLOBALS['phpgw']->hooks->process($GLOBALS['hook_values']+array( |
---|
| 812 | 'location' => 'changepassword' |
---|
| 813 | ),False,True); // called for every app now, not only enabled ones) |
---|
| 814 | } |
---|
| 815 | |
---|
| 816 | $apps = CreateObject('phpgwapi.applications',array((int)$_userData['account_id'],'u')); |
---|
| 817 | |
---|
| 818 | $apps->account_id = $_userData['account_id']; |
---|
| 819 | if ($_userData['account_permissions']) |
---|
| 820 | { |
---|
| 821 | while($app = each($_userData['account_permissions'])) |
---|
| 822 | { |
---|
| 823 | if($app[1]) |
---|
| 824 | { |
---|
| 825 | $apps->add($app[0]); |
---|
| 826 | } |
---|
| 827 | } |
---|
| 828 | } |
---|
| 829 | $apps->save_repository(); |
---|
| 830 | |
---|
| 831 | $account = CreateObject('phpgwapi.accounts',$_userData['account_id'],'u'); |
---|
| 832 | $allGroups = $account->get_list('groups'); |
---|
| 833 | |
---|
| 834 | if ($_userData['account_groups']) |
---|
| 835 | { |
---|
| 836 | reset($_userData['account_groups']); |
---|
| 837 | while (list($key,$value) = each($_userData['account_groups'])) |
---|
| 838 | { |
---|
| 839 | $newGroups[$value] = $value; |
---|
| 840 | } |
---|
| 841 | } |
---|
| 842 | |
---|
| 843 | $acl = CreateObject('phpgwapi.acl',$_userData['account_id']); |
---|
| 844 | |
---|
| 845 | reset($allGroups); |
---|
| 846 | while (list($key,$groupData) = each($allGroups)) |
---|
| 847 | { |
---|
| 848 | /* print "$key,". $groupData['account_id'] ."<br>";*/ |
---|
| 849 | /* print "$key,". $_userData['account_groups'][1] ."<br>"; */ |
---|
| 850 | |
---|
| 851 | if ($newGroups[$groupData['account_id']]) |
---|
| 852 | { |
---|
| 853 | $acl->add_repository('phpgw_group',$groupData['account_id'],$_userData['account_id'],1); |
---|
| 854 | } |
---|
| 855 | else |
---|
| 856 | { |
---|
| 857 | $acl->delete_repository('phpgw_group',$groupData['account_id'],$_userData['account_id']); |
---|
| 858 | } |
---|
| 859 | } |
---|
| 860 | if ($_userData['anonymous']) |
---|
| 861 | { |
---|
| 862 | $acl->add_repository('phpgwapi','anonymous',$_userData['account_id'],1); |
---|
| 863 | } |
---|
| 864 | else |
---|
| 865 | { |
---|
| 866 | $acl->delete_repository('phpgwapi','anonymous',$_userData['account_id']); |
---|
| 867 | } |
---|
| 868 | if ($_userData['changepassword']) |
---|
| 869 | { |
---|
| 870 | $GLOBALS['phpgw']->acl->add_repository('preferences','changepassword',$_userData['account_id'],1); |
---|
| 871 | } |
---|
| 872 | else |
---|
| 873 | { |
---|
| 874 | $GLOBALS['phpgw']->acl->delete_repository('preferences','changepassword',$_userData['account_id']); |
---|
| 875 | } |
---|
| 876 | $GLOBALS['phpgw']->session->delete_cache((int)$_userData['account_id']); |
---|
| 877 | } |
---|
| 878 | |
---|
| 879 | function load_group_users($account_id) |
---|
| 880 | { |
---|
| 881 | $temp_user = $GLOBALS['phpgw']->acl->get_ids_for_location($account_id,1,'phpgw_group'); |
---|
| 882 | if(!$temp_user) |
---|
| 883 | { |
---|
| 884 | return Array(); |
---|
| 885 | } |
---|
| 886 | else |
---|
| 887 | { |
---|
| 888 | $group_user = $temp_user; |
---|
| 889 | } |
---|
| 890 | $account_user = Array(); |
---|
| 891 | while (list($key,$user) = each($group_user)) |
---|
| 892 | { |
---|
| 893 | $account_user[$user] = ' selected'; |
---|
| 894 | } |
---|
| 895 | @reset($account_user); |
---|
| 896 | return $account_user; |
---|
| 897 | } |
---|
| 898 | |
---|
| 899 | function load_group_managers($account_id) |
---|
| 900 | { |
---|
| 901 | $temp_user = $GLOBALS['phpgw']->acl->get_ids_for_location($account_id,PHPGW_ACL_GROUP_MANAGERS,'phpgw_group'); |
---|
| 902 | if(!$temp_user) |
---|
| 903 | { |
---|
| 904 | return Array(); |
---|
| 905 | } |
---|
| 906 | else |
---|
| 907 | { |
---|
| 908 | $group_user = $temp_user; |
---|
| 909 | } |
---|
| 910 | $account_user = Array(); |
---|
| 911 | while (list($key,$user) = each($group_user)) |
---|
| 912 | { |
---|
| 913 | $account_user[$user] = ' selected'; |
---|
| 914 | } |
---|
| 915 | @reset($account_user); |
---|
| 916 | return $account_user; |
---|
| 917 | } |
---|
| 918 | |
---|
| 919 | function load_group_apps($account_id) |
---|
| 920 | { |
---|
| 921 | $apps = CreateObject('phpgwapi.applications',(int)$account_id); |
---|
| 922 | $app_list = $apps->read_account_specific(); |
---|
| 923 | $account_apps = Array(); |
---|
| 924 | while(list($key,$app) = each($app_list)) |
---|
| 925 | { |
---|
| 926 | $account_apps[$app['name']] = True; |
---|
| 927 | } |
---|
| 928 | @reset($account_apps); |
---|
| 929 | return $account_apps; |
---|
| 930 | } |
---|
| 931 | |
---|
| 932 | // xmlrpc functions |
---|
| 933 | |
---|
| 934 | function rpc_add_user($data) |
---|
| 935 | { |
---|
| 936 | exit; |
---|
| 937 | |
---|
| 938 | if (!$errors = $this->validate_user($data)) |
---|
| 939 | { |
---|
| 940 | $result = $this->so->add_user($data); |
---|
| 941 | } |
---|
| 942 | else |
---|
| 943 | { |
---|
| 944 | $result = $errors; |
---|
| 945 | } |
---|
| 946 | return $result; |
---|
| 947 | } |
---|
| 948 | } |
---|
| 949 | ?> |
---|