diff --git a/admin/inc/class.boaccounts.inc.php b/admin/inc/class.boaccounts.inc.php index d2964e1185..d28e4340c2 100755 --- a/admin/inc/class.boaccounts.inc.php +++ b/admin/inc/class.boaccounts.inc.php @@ -14,6 +14,7 @@ var $public_functions = array( 'add_user' => True, 'delete_user' => True, + 'edit_group' => True, 'edit_user' => True ); @@ -24,9 +25,9 @@ $this->so = createobject('admin.soaccounts'); } - function account_total($query) + function account_total($account_type,$query='') { - return $this->so->account_total($query); + return $this->so->account_total($account_type,$query); } function delete_user() @@ -229,6 +230,166 @@ } } + function edit_group() + { + $account_id = ($GLOBALS['HTTP_POST_VARS']['account_id']?$GLOBALS['HTTP_POST_VARS']['account_id']:0); + $group_name = ($GLOBALS['HTTP_POST_VARS']['n_group']?$GLOBALS['HTTP_POST_VARS']['n_group']:''); + $group_permissions = ($GLOBALS['HTTP_POST_VARS']['n_group_permissions']?$GLOBALS['HTTP_POST_VARS']['n_group_permissions']:Array()); + $group_users = ($GLOBALS['HTTP_POST_VARS']['n_users']?$GLOBALS['HTTP_POST_VARS']['n_users']:Array()); + + $group = CreateObject('phpgwapi.accounts',intval($account_id)); + $group->read_repository(); + $old_group_name = $group->id2name($account_id); + + if($group_name != $old_group_name) + { + if ($group->exists($group_name)) + { + $error = lang('Sorry, that group name has already been taken.'); + $ui = createobject('admin.uiaccounts'); + $ui->edit_group($account_id,$errors); + $GLOBALS['phpgw']->common->phpgw_exit(); + } + } + + /* + if (preg_match ("/\D/", $account_file_space_number)) + { + $error = lang ('File space must be an integer'); + } + */ + + // Lock tables + $GLOBALS['phpgw']->db->lock( + Array( + 'phpgw_accounts', + 'phpgw_preferences', + 'phpgw_config', + 'phpgw_applications', + 'phpgw_hooks', + 'phpgw_sessions', + 'phpgw_acl' + ) + ); + + // Set group apps + $apps = CreateObject('phpgwapi.applications',intval($GLOBALS['HTTP_POST_VARS']['account_id'])); + $apps_before = $apps->read_account_specific(); + $apps->update_data(Array()); + $new_apps = Array(); + if(isset($group_permissions)) + { + reset($group_permissions); + while($app = each($group_permissions)) + { + if($app[1]) + { + $apps->add($app[0]); + if(!@$apps_before[$app[0]] || @$apps_before == False) + { + $new_apps[] = $app[0]; + } + } + } + } + $apps->save_repository(); + + // Set new account_lid, if needed + if($old_group_name <> $group_name) + { + $group->data['account_lid'] = $group_name; + } + + // Set group acl + $acl = CreateObject('phpgwapi.acl',$account_id); + $acl->read_repository(); + $old_group_list = $acl->get_ids_for_location($account_id,1,'phpgw_group'); + @reset($old_group_list); + while($old_group_list && $user_id = each($old_group_list)) + { + $acl->delete_repository('phpgw_group',$account_id,$user_id[1]); + } + + for ($i=0; $iadd_repository('phpgw_group',$account_id,$group_users[$i],1); + + // If the user is logged in, it will force a refresh of the session_info + $GLOBALS['phpgw']->db->query("update phpgw_sessions set session_action='' " + ."where session_lid='" . $GLOBALS['phpgw']->accounts->id2name(intval($group_users[$i])) + . '@' . $GLOBALS['phpgw_info']['user']['domain'] . "'",__LINE__,__FILE__); + + // The following sets any default preferences needed for new applications.. + // This is smart enough to know if previous preferences were selected, use them. + $docommit = False; + if($new_apps) + { + $GLOBALS['pref'] = CreateObject('phpgwapi.preferences',intval($group_users[$i])); + $t = $GLOBALS['pref']->read_repository(); + + for ($j=1;$jcommon->hook_single('add_def_pref', $new_apps[$j]); + $docommit = True; + } + } + } + if ($docommit) + { + $GLOBALS['pref']->save_repository(); + } + + // This is down here so we are sure to catch the acl changes + // for LDAP to update the memberuid attribute + $group->save_repository(); + } + + /* + // Update any other options here, since the above save_repository () depends + // on a group having users + $group->data['file_space'] = $GLOBALS['HTTP_POST_VARS']['account_file_space_number'] . "-" . $GLOBALS['HTTP_POST_VARS']['account_file_space_type']; + $group->save_repository(); + */ + + if ($old_group_name <> $group_name) + { + $basedir = $GLOBALS['phpgw_info']['server']['files_dir'] . SEP . 'groups' . SEP; + if (! @rename($basedir . $old_group_name, $basedir . $group_name)) + { + $cd = 39; + } + else + { + $cd = 33; + } + } + else + { + $cd = 33; + } + + $GLOBALS['phpgw']->db->unlock(); + + Header('Location: ' . $GLOBALS['phpgw']->link('/index.php', + Array( + 'menuaction' => 'admin.uiaccounts.list_groups', + 'cd' => $cd + ) + ) + ); + $GLOBALS['phpgw']->common->phpgw_exit(); + } + function edit_user() { if ($GLOBALS['HTTP_POST_VARS']['submit']) diff --git a/admin/inc/class.soaccounts.inc.php b/admin/inc/class.soaccounts.inc.php index cc6f08910b..0e0318eb2d 100755 --- a/admin/inc/class.soaccounts.inc.php +++ b/admin/inc/class.soaccounts.inc.php @@ -16,7 +16,7 @@ { } - function account_total($query) + function account_total($account_type,$query='') { if ($query) { @@ -24,7 +24,7 @@ . "'%$query%' OR account_lid LIKE '%$query%') "; } - $GLOBALS['phpgw']->db->query("SELECT COUNT(*) FROM phpgw_accounts WHERE account_type='u'".$querymethod,__LINE__,__FILE__); + $GLOBALS['phpgw']->db->query("SELECT COUNT(*) FROM phpgw_accounts WHERE account_type='".$account_type."'".$querymethod,__LINE__,__FILE__); $GLOBALS['phpgw']->db->next_record(); return $GLOBALS['phpgw']->db->f(0); diff --git a/admin/inc/class.uiaccounts.inc.php b/admin/inc/class.uiaccounts.inc.php index f9e20b2293..f397360ad4 100755 --- a/admin/inc/class.uiaccounts.inc.php +++ b/admin/inc/class.uiaccounts.inc.php @@ -14,9 +14,12 @@ var $public_functions = array( 'list_users' => True, + 'list_groups' => True, 'add_user' => True, + 'delete_group' => True, 'delete_user' => True, 'edit_user' => True, + 'edit_group' => True, 'view_user' => True ); @@ -59,19 +62,19 @@ $p->set_block('accounts','row','row'); $p->set_block('accounts','row_empty','row_empty'); - $total = $this->bo->account_total($query); + $total = $this->bo->account_total('u',$query); - $url = $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_users'); + $url = $GLOBALS['phpgw']->link('/index.php'); $var = Array( 'bg_color' => $GLOBALS['phpgw_info']['theme']['bg_color'], 'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'], - 'left_next_matchs' => $this->nextmatchs->left($url,$start,$total), + 'left_next_matchs' => $this->nextmatchs->left($url,$start,$total,'menuaction=admin.uiaccounts.list_users'), 'lang_user_accounts' => lang('user accounts'), - 'right_next_matchs' => $this->nextmatchs->right($url,$start,$total), - 'lang_loginid' => $this->nextmatchs->show_sort_order($sort,'account_lid',$order,$url,lang('LoginID')), - 'lang_lastname' => $this->nextmatchs->show_sort_order($sort,'account_lastname',$order,$url,lang('last name')), - 'lang_firstname' => $this->nextmatchs->show_sort_order($sort,'account_firstname',$order,$url,lang('first name')), + 'right_next_matchs' => $this->nextmatchs->right($url,$start,$total,'menuaction=admin.uiaccounts.list_users'), + 'lang_loginid' => $this->nextmatchs->show_sort_order($sort,'account_lid',$order,$url,lang('LoginID'),'menuaction=admin.uiaccounts.list_users'), + 'lang_lastname' => $this->nextmatchs->show_sort_order($sort,'account_lastname',$order,$url,lang('last name'),'menuaction=admin.uiaccounts.list_users'), + 'lang_firstname' => $this->nextmatchs->show_sort_order($sort,'account_firstname',$order,$url,lang('first name'),'menuaction=admin.uiaccounts.list_users'), 'lang_edit' => lang('edit'), 'lang_delete' => lang('delete'), 'lang_view' => lang('view'), @@ -162,11 +165,11 @@ { $cdid = $cd; settype($cd,'integer'); - $cd = ($GLOBALS['HTTP_GET_VARS']['cd']?$GLOBALS['HTTP_GET_VARS']['cd']:$cdid); + $cd = ($GLOBALS['HTTP_GET_VARS']['cd']?$GLOBALS['HTTP_GET_VARS']['cd']:intval($cdid)); $accountid = $account_id; settype($account_id,'integer'); - $account_id = ($GLOBALS['HTTP_GET_VARS']['account_id']?$GLOBALS['HTTP_GET_VARS']['account_id']:$accountid); + $account_id = ($GLOBALS['HTTP_GET_VARS']['account_id']?$GLOBALS['HTTP_GET_VARS']['account_id']:intval($accountid)); // todo // not needed if i use the same file for new users too @@ -581,5 +584,228 @@ echo $t->fp('out','form'); } + + function list_groups() + { + + if(!$param_cd) + { + $cd = $param_cd; + } + + unset($GLOBALS['phpgw_info']['flags']['noheader']); + unset($GLOBALS['phpgw_info']['flags']['nonavbar']); + $GLOBALS['phpgw']->common->phpgw_header(); + + $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); + $p->set_file( + array( + 'groups' => 'groups.tpl' + ) + ); + $p->set_block('groups','list','list'); + $p->set_block('groups','row','row'); + $p->set_block('groups','row_empty','row_empty'); + + $total = $this->bo->account_total('g',$query); + + $url = $GLOBALS['phpgw']->link('/index.php'); + + $var = Array( + 'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'], + 'left_next_matchs' => $this->nextmatchs->left('/index.php',$start,$total,'menuaction=admin.uiaccounts.list_groups'), + 'right_next_matchs' => $this->nextmatchs->right('/admin/groups.php',$start,$total,'menuaction=admin.uiaccounts.list_groups'), + 'lang_groups' => lang('user groups'), + 'sort_name' => $this->nextmatchs->show_sort_order($sort,'account_lid',$order,'/index.php',lang('name'),'menuaction=admin.uiaccounts.list_groups'), + 'header_edit' => lang('Edit'), + 'header_delete' => lang('Delete') + ); + $p->set_var($var); + + $account_info = $GLOBALS['phpgw']->accounts->get_list('groups',$start,$sort, $order, $query, $total); + + if (!count($account_info)) + { + $p->set_var('message',lang('No matchs found')); + $p->parse('rows','row_empty',True); + } + else + { + while (list($null,$account) = each($account_info)) + { + $tr_color = $this->nextmatchs->alternate_row_color($tr_color); + $var = Array( + 'tr_color' => $tr_color, + 'group_name' => (!$account['account_lid']?' ':$account['account_lid']), + 'edit_link' => $this->row_action('edit','group',$account['account_id']), + 'delete_link' => $this->row_action('delete','group',$account['account_id']) + ); + $p->set_var($var); + $p->parse('rows','row',True); + + } + } + $var = Array( + 'new_action' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.add_group'), + 'lang_add' => lang('add'), + 'search_action' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_groups'), + 'lang_search' => lang('search') + ); + $p->set_var($var); + $p->pparse('out','list'); + } + + function edit_group($cd='',$account_id='') + { + $cdid = $cd; + settype($cd,'integer'); + $cd = ($GLOBALS['HTTP_GET_VARS']['cd']?$GLOBALS['HTTP_GET_VARS']['cd']:intval($cdid)); + + $accountid = $account_id; + settype($account_id,'integer'); + $account_id = ($GLOBALS['HTTP_GET_VARS']['account_id']?$GLOBALS['HTTP_GET_VARS']['account_id']:intval($accountid)); + + // todo + // not needed if i use the same file for new users too + if (!$account_id) + { + Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_groups')); + } + else + { + $this->create_edit_group($account_id); + } + } + + function create_edit_group($account_id,$_errors='') + { + $apps_with_acl = Array( + 'addressbook' => True, + 'todo' => True, + 'calendar' => True, + 'notes' => True, + 'projects' => True, + 'phonelog' => True, + 'infolog' => True, + 'phpwebhosting' => True + ); + + $sbox = createobject('phpgwapi.sbox'); + + unset($GLOBALS['phpgw_info']['flags']['noheader']); + unset($GLOBALS['phpgw_info']['flags']['nonavbar']); + $GLOBALS['phpgw']->common->phpgw_header(); + + $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); + $p->set_file( + Array( + 'form' => 'group_form.tpl' + ) + ); + + $group_user = $GLOBALS['phpgw']->acl->get_ids_for_location($account_id,1,'phpgw_group'); + + if (!$group_user) { $group_user = array(); } + while ($user = each($group_user)) + { + $selected_users[intval($user[1])] = ' selected'; + } + + $apps = CreateObject('phpgwapi.applications',intval($account_id)); + $db_perms = $apps->read_account_specific(); + + $accounts = CreateObject('phpgwapi.accounts',$account_id); + $account_list = $accounts->get_list('accounts'); + $account_num = count($account_list); + + $user_list = ''; + while (list($key,$entry) = each($account_list)) + { + $user_list .= ''."\n"; + } + + $var = Array( + 'form_action' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.boaccounts.'.($account_id?'edit':'add').'_group'), + 'hidden_vars' => '', + 'lang_group_name' => lang('group name'), + 'group_name_value' => $GLOBALS['phpgw']->accounts->id2name($account_id), + 'lang_include_user' => lang('Select users for inclusion'), + 'error' => (!$_errors?'':'
'.$GLOBALS['phpgw']->common->error_list($_errors).'
'), + 'select_size' => ($account_num < 5?$account_num:5), + 'user_list' => $user_list, + 'lang_permissions' => lang('Permissions this group has') + ); + $p->set_var($var); + + $group_repository = $accounts->read_repository (); + if (!$group_repository['file_space']) + { + $group_repository['file_space'] = $GLOBALS['phpgw_info']['server']['vfs_default_account_size_number'] . "-" . $GLOBALS['phpgw_info']['server']['vfs_default_account_size_type']; + } + /* + $file_space_array = explode ("-", $group_repository['file_space']); + $account_file_space_types = array ('gb', 'mb', 'kb', 'b'); + while (list ($num, $type) = each ($account_file_space_types)) + { + $account_file_space_select .= ''."\n"; + } + $p->set_var ('lang_file_space', lang('File space')); + $p->set_var ('account_file_space', ''); + $p->set_var ('account_file_space_select',''."\n"); + */ + + $i = 0; + reset($GLOBALS['phpgw_info']['apps']); + $sorted_apps = $GLOBALS['phpgw_info']['apps']; + @asort($sorted_apps); + @reset($sorted_apps); + while ($permission = each($sorted_apps)) + { + if ($permission[1]['enabled'] && $permission[1]['status'] != 3) + { + $perm_display[$i][0] = $permission[0]; + $perm_display[$i][1] = $permission[1]['title']; + $i++; + } + } + + $perm_html = ''; + $tr_color = $GLOBALS['phpgw_info']['theme']['row_off']; + for ($i=0;$perm_display[$i][1];$i++) + { + $app = $perm_display[$i][0]; + if(!($i & 1)) + { + $tr_color = $this->nextmatchs->alternate_row_color(); + $perm_html .= ''; + } + $perm_html .= '' . lang($perm_display[$i][1]) . '' + . '' + .($apps_with_acl[$app]?''.lang('Grant Access').'':' ') + .''.($i & 1?'':''); + } + if($i & 1) + { + $perm_html .= ' '; + } + + $var = Array( + 'permissions_list' => $perm_html, + 'lang_submit_button' => lang('submit changes') + ); + $p->set_var($var); + $p->pfp('out','form'); + } + + function delete_group() + { + } } ?>