[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] admin/inc/class.boaccounts.inc.php, 1.36
From: |
nomail |
Subject: |
[Phpgroupware-cvs] admin/inc/class.boaccounts.inc.php, 1.36 |
Date: |
Thu, 29 Jul 2004 13:41:51 +0200 |
Update of /admin/inc
Modified Files:
Branch:
class.boaccounts.inc.php
date: 2004/07/29 11:41:51; author: fipsfuchs; state: Exp; lines: +118 -261
Log Message:
refactoring and bug fixes for view/edit/add group
=====================================================================
Index: admin/inc/class.boaccounts.inc.php
diff -u admin/inc/class.boaccounts.inc.php:1.35
admin/inc/class.boaccounts.inc.php:1.36
--- admin/inc/class.boaccounts.inc.php:1.35 Fri Jun 25 12:28:18 2004
+++ admin/inc/class.boaccounts.inc.php Thu Jul 29 11:41:51 2004
@@ -16,12 +16,12 @@
var $so;
var $public_functions = array
(
- 'add_group' => True,
- 'delete_group' => True,
- 'delete_user' => True,
- 'edit_group' => True,
- 'save_user' => True,
- 'set_group_managers' => True
+ 'add_group' => true,
+ 'delete_group' => true,
+ 'delete_user' => true,
+ 'edit_group' => true,
+ 'save_user' => true,
+ 'set_group_managers' => true
);
var $xml_functions = array();
@@ -95,118 +95,6 @@
return False;
}
-
- function add_group($values)
- {
- $temp_users =
($values['account_user']?$values['account_user']:Array());
- $account_user = Array();
- @reset($temp_users);
- while(list($key,$user_id) = each($temp_users))
- {
- $account_user[$user_id] = ' selected';
- }
- @reset($account_user);
-
- $group_permissions =
($values['account_apps']?$values['account_apps']:Array());
- $account_apps = Array();
- @reset($group_permissions);
- while(list($key,$value) = each($group_permissions))
- {
- if($value)
- {
- $account_apps[$key] = True;
- }
- }
- @reset($account_apps);
-
- $group_info = Array
- (
- 'account_id' =>
($values['account_id']?intval($values['account_id']):0),
- 'account_name' =>
($values['account_name']?$values['account_name']:''),
- 'account_user' => $account_user,
- 'account_apps' => $account_apps
- );
-
- $GLOBALS['phpgw']->db->lock(array
- (
- 'phpgw_accounts',
- 'phpgw_nextid',
- 'phpgw_preferences',
- 'phpgw_sessions',
- 'phpgw_acl',
- 'phpgw_applications',
- 'phpgw_app_sessions',
- 'phpgw_hooks'
- ));
-
- $group =
CreateObject('phpgwapi.accounts',$group_info['account_id'],'g');
- $group->acct_type = 'g';
- $account_info = array
- (
- 'account_type' => 'g',
- 'account_lid' =>
$group_info['account_name'],
- 'account_passwd' => '',
- 'account_firstname' =>
$group_info['account_name'],
- 'account_lastname' => 'Group',
- 'account_status' => 'A',
- 'account_expires' => -1
-// 'account_file_space' =>
$account_file_space_number . "-" . $account_file_space_type,
- );
- $group->create($account_info);
- $group_info['account_id'] =
$GLOBALS['phpgw']->accounts->name2id($group_info['account_name']);
-
- $apps =
CreateObject('phpgwapi.applications',$group_info['account_id']);
- $apps->update_data(Array());
- reset($group_info['account_apps']);
- while(list($app,$value) =
each($group_info['account_apps']))
- {
- $apps->add($app);
- $new_apps[] = $app;
- }
- $apps->save_repository();
-
- $acl =
CreateObject('phpgwapi.acl',$group_info['account_id']);
- $acl->read_repository();
-
- @reset($group_info['account_user']);
- while(list($user_id,$dummy) =
each($group_info['account_user']))
- {
- if(!$dummy)
- {
- continue;
- }
-
$acl->add_repository('phpgw_group',$group_info['account_id'],$user_id,1);
-
- $docommit = False;
- $GLOBALS['pref'] =
CreateObject('phpgwapi.preferences',$user_id);
- $t = $GLOBALS['pref']->read_repository();
- @reset($new_apps);
- while(list($app_key,$app_name) =
each($new_apps))
- {
- if
(!$t[($app_name=='admin'?'common':$app_name)])
- {
-
$GLOBALS['phpgw']->hooks->single('add_def_pref', $app_name);
- $docommit = True;
- }
- }
- if ($docommit)
- {
- $GLOBALS['pref']->save_repository();
- }
- }
-
- $acl->save_repository();
-
- $basedir =
$GLOBALS['phpgw_info']['server']['files_dir'] . SEP . 'groups' . SEP;
- $cd = 31;
- umask(000);
- if (! @mkdir ($basedir . $group_info['account_name'],
0707))
- {
- $cd = 37;
- }
- $GLOBALS['phpgw']->db->unlock();
- }
-
function edit_group($values)
{
if
($GLOBALS['phpgw']->acl->check('group_access',16,'admin'))
@@ -214,162 +102,118 @@
$error[] = lang('no permission to create
groups');
}
- $temp_users =
($values['account_user']?$values['account_user']:Array());
- $account_user = Array();
- @reset($temp_users);
- while($temp_users && list($key,$user_id) =
each($temp_users))
- {
- $account_user[$user_id] = ' selected';
- }
- @reset($account_user);
-
- $group_permissions =
($values['account_apps']?$values['account_apps']:Array());
- $account_apps = Array();
- @reset($group_permissions);
- while(list($key,$value) = each($group_permissions))
- {
- if($value)
- {
- $account_apps[$key] = True;
- }
- }
- @reset($account_apps);
-
- $group_info = Array(
- 'account_id' =>
($values['account_id']?intval($values['account_id']):0),
- 'account_name' =>
($values['account_name']?$values['account_name']:''),
- 'account_user' => $account_user,
- 'account_apps' => $account_apps
- );
-
- // Lock tables
- $GLOBALS['phpgw']->db->lock(
- Array(
- 'phpgw_accounts',
- 'phpgw_preferences',
- 'phpgw_config',
- 'phpgw_applications',
- 'phpgw_hooks',
- 'phpgw_sessions',
- 'phpgw_acl',
- 'phpgw_app_sessions'
- )
- );
-
- $group =
CreateObject('phpgwapi.accounts',$group_info['account_id'],'g');
- $old_group_info = $group->read_repository();
+ $old_group = CreateObject('phpgwapi.accounts',
$values['account_id'], 'g');
+ $old_group->read_repository();
+ $old_group->member($old_group->get_id());
+
+ $new_group = CreateObject('phpgwapi.accounts',
$values['account_id'], 'g');
+ $new_group->read_repository();
+ $new_group->set_lid($values['account_name']);
- // Set group apps
- $apps =
CreateObject('phpgwapi.applications',$group_info['account_id']);
- $apps_before = $apps->read_account_specific();
- $apps->update_data(Array());
- $new_apps = Array();
- if(count($group_info['account_apps']))
- {
- reset($group_info['account_apps']);
- while(list($app,$value) =
each($group_info['account_apps']))
- {
- $apps->add($app);
- if(address@hidden || @$apps_before ==
False)
- {
- $new_apps[] = $app;
- }
- }
- }
- $apps->save_repository();
+ $GLOBALS['phpgw']->db->lock(array('phpgw_accounts',
+ 'phpgw_preferences',
+ 'phpgw_config',
+ 'phpgw_applications',
+ 'phpgw_hooks',
+ 'phpgw_sessions',
+ 'phpgw_acl',
+ 'phpgw_app_sessions'
+ ));
- // Set new account_lid, if needed
- if($group_info['account_name'] &&
$old_group_info['account_lid'] <> $group_info['account_name'])
+ if(!$values['account_id']) // add new group
{
- $group->data['account_lid'] =
$group_info['account_name'];
-
- $basedir =
$GLOBALS['phpgw_info']['server']['files_dir'] . SEP . 'groups' . SEP;
- if (! @rename($basedir .
$old_group_info['account_lid'], $basedir . $group_info['account_name']))
- {
- $cd = 39;
- }
- else
- {
- $cd = 33;
- }
+ $new_group_values = array('type' => 'g',
+ 'account_lid' =>
$values['account_name'],
+ 'passwd' => '',
+ 'firstname' =>
$values['account_name'],
+ 'lastname' =>
'Group',
+ 'status' => 'A',
+ 'expires' => -1
+ );
+ $new_group->create($new_group_values, false);
}
- else
+ else //edit group
{
- $cd = 33;
+ $new_group->save_repository();
}
+ $GLOBALS['phpgw']->db->unlock();
- // Set group acl
- $acl =
CreateObject('phpgwapi.acl',$group_info['account_id']);
-// $acl->read_repository();
- $old_group_list =
$acl->get_ids_for_location($group_info['account_id'],1,'phpgw_group');
- @reset($old_group_list);
- while($old_group_list && list($key,$user_id) =
each($old_group_list))
+ // get all new applications for this group
+ $apps = CreateObject('phpgwapi.applications',
$values['account_id']);
+ $old_apps = array_keys($apps->read());
+ foreach($values['account_apps'] as $key => $value)
{
-
$acl->delete_repository('phpgw_group',$group_info['account_id'],$user_id);
- if(!$group_info['account_user'][$user_id])
+ if(!in_array($key, $old_apps))
{
- // 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($user_id)
- . '@' .
$GLOBALS['phpgw_info']['user']['domain'] . "'",__LINE__,__FILE__);
-
$GLOBALS['phpgw']->session->delete_cache($user_id);
+ $new_apps[] = $key;
}
}
-// $acl->save_repository();
-// $acl->read_repository();
+ // set group applications
+ $this->set_module_permissions($new_group->get_id(),
$values['account_apps']);
- @reset($group_info['account_user']);
- while(list($user_id,$dummy) =
each($group_info['account_user']))
+ // members handling
+ // Add new members to group
+ $acl = CreateObject('phpgwapi.acl',
$values['account_id']);
+ $old_group_list = $old_group->get_members();
+ for($i = 0; $i < count($values['account_user']); $i++)
{
- if(!$dummy)
+ $is_new = true;
+ for($j = 0; $j < count($old_group_list); $j++)
{
- continue;
+ if($values['account_user'][$i] ==
$old_group_list[$j])
+ {
+ unset($old_group_list[$j]);
+ $is_new = false;
+ break;
+ }
}
-
$acl->add_repository('phpgw_group',$group_info['account_id'],$user_id,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($user_id)
- . '@' .
$GLOBALS['phpgw_info']['user']['domain'] . "'",__LINE__,__FILE__);
+ if($is_new)
+ {
+ $acl->add_repository('phpgw_group',
$new_group->get_id(), $values['account_user'][$i], 1);
+
$this->refresh_session_data($values['account_user'][$i]);
-
$GLOBALS['phpgw']->session->delete_cache($user_id);
-
- // 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',$user_id);
- $t =
$GLOBALS['pref']->read_repository();
- @reset($new_apps);
- while(list($app_key,$app_name) =
each($new_apps))
+ // 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(count($new_apps))
{
- if
(!$t[($app_name=='admin'?'common':$app_name)])
+ $GLOBALS['pref'] =
CreateObject('phpgwapi.preferences', $values['account_user'][$i]);
+ $t =
$GLOBALS['pref']->read_repository();
+ while(list($app_key,$app_name)
= each($new_apps))
+ for($j = 0; $j <
count($new_apps); $j++)
{
-
$GLOBALS['phpgw']->hooks->single('add_def_pref', $app_name);
- $docommit = True;
+ if($new_apps[$i] ==
'admin') //another workaround :-(
+ {
+ $new_apps[$i]
== 'common';
+ }
+
+ if (!$t[$new_apps[$i]])
+ {
+
$GLOBALS['phpgw']->hooks->single('add_def_pref', $new_apps[$i]);
+ $docommit =
true;
+ }
}
}
+ if ($docommit)
+ {
+
$GLOBALS['pref']->save_repository();
+ }
}
- 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();
+ }
+ // Remove members from group
+ foreach($old_group_list as $key => $value)
+ {
+
$acl->delete_repository('phpgw_group',$new_group->get_id(), $value);
+
$this->refresh_session_data($values['account_user'][$i]);
}
- /*
- // 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();
- */
-
- $GLOBALS['phpgw']->db->unlock();
+ // Things that have to change because of new group name
+ if($old_group->get_lid() != $new_group->get_lid())
+ {
+ $basedir =
$GLOBALS['phpgw_info']['server']['files_dir'] . SEP . 'groups' . SEP;
+ @rename($basedir . $old_group->get_lid(),
$basedir . $new_group->get_lid());
+ }
}
/**
@@ -726,19 +570,21 @@
function load_group_apps($account_id)
{
- $apps =
CreateObject('phpgwapi.applications',intval($account_id));
- $app_list = $apps->read_account_specific();
- $account_apps = Array();
- while(list($key,$app) = each($app_list))
+ $account_apps = array();
+ if($account_id)
{
- $account_apps[$app['name']] = True;
+ $apps =
CreateObject('phpgwapi.applications',intval($account_id));
+ $app_list = $apps->read_account_specific();
+
+ while(list($key,$app) = each($app_list))
+ {
+ $account_apps[$app['name']] = True;
+ }
+ @reset($account_apps);
}
- @reset($account_apps);
return $account_apps;
}
- // xmlrpc functions
-
function rpc_add_user($data)
{
exit;
@@ -756,7 +602,7 @@
function set_module_permissions($id, $modules)
{
- if ($modules)
+ if($id)
{
$apps = CreateObject('phpgwapi.applications',
intval($id));
while($app = each($modules))
@@ -795,6 +641,17 @@
}
}
}
-
+
+ function refresh_session_data($id)
+ {
+ // If the user is logged in, it will force a refresh of
the session_info
+
+ // This can't work - just imaging session data in php4
+ // $GLOBALS['phpgw']->db->query("update phpgw_sessions
set session_action='' "
+ // ."where session_lid='" .
$GLOBALS['phpgw']->accounts->id2name($id)
+ // . '@' . $GLOBALS['phpgw_info']['user']['domain'] .
"'",__LINE__,__FILE__);
+
+ $GLOBALS['phpgw']->session->delete_cache($id);
+ }
}
?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] admin/inc/class.boaccounts.inc.php, 1.36,
nomail <=