phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] admin inc/class.boaccounts.inc.php inc/class.ui...


From: Sigurd Nes
Subject: [Phpgroupware-cvs] admin inc/class.boaccounts.inc.php inc/class.ui...
Date: Tue, 21 Mar 2006 12:54:56 +0000

CVSROOT:        /sources/phpgroupware
Module name:    admin
Branch:         
Changes by:     Sigurd Nes <address@hidden>     06/03/21 12:54:56

Modified files:
        inc            : class.boaccounts.inc.php 
                         class.uiaccounts.inc.php 
        templates/base : groups.xsl 

Log message:
        Fix for edit group - and using acl2 for grants and permissions

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/admin/inc/class.boaccounts.inc.php.diff?tr1=1.42&tr2=1.43&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/admin/inc/class.uiaccounts.inc.php.diff?tr1=1.54&tr2=1.55&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/admin/templates/base/groups.xsl.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: admin/inc/class.boaccounts.inc.php
diff -u admin/inc/class.boaccounts.inc.php:1.42 
admin/inc/class.boaccounts.inc.php:1.43
--- admin/inc/class.boaccounts.inc.php:1.42     Mon Mar 20 08:30:25 2006
+++ admin/inc/class.boaccounts.inc.php  Tue Mar 21 12:54:56 2006
@@ -9,7 +9,7 @@
        *  Free Software Foundation; either version 2 of the License, or (at 
your  *
        *  option) any later version.                                           
   *
        
\**************************************************************************/
-       /* $Id: class.boaccounts.inc.php,v 1.42 2006/03/20 08:30:25 sigurdne 
Exp $ */
+       /* $Id: class.boaccounts.inc.php,v 1.43 2006/03/21 12:54:56 sigurdne 
Exp $ */
 
        class boaccounts
        {
@@ -100,120 +100,168 @@
                        if 
($GLOBALS['phpgw']->acl->check('group_access',16,'admin'))
                        {
                                $error[] = lang('no permission to create 
groups');
+                               
$GLOBALS['phpgw']->redirect_link('/index.php','menuaction=admin.uiaccounts.list_groups');
                        }
 
-                       $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']);
-
-                       $GLOBALS['phpgw']->db->lock(array('phpgw_accounts',
-                                                                               
          'phpgw_preferences',
-                                                                               
          'phpgw_config',
-                                                                               
          'phpgw_applications',
-                                                                               
          'phpgw_hooks',
-                                                                               
          'phpgw_sessions',
-                                                                               
          'phpgw_acl',
-                                                                               
          'phpgw_app_sessions'
-                                                                               
         ));
-
-                       if(!$values['account_id']) // add new group
+                       $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))
                        {
-                               $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);
+                               $account_user[$user_id] = ' selected';
                        }
-                       else //edit group
+                       @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))
                        {
-                               $new_group->save_repository();
+                               if($value)
+                               {
+                                       $account_apps[$key] = True;
+                               }
                        }
-                       $GLOBALS['phpgw']->db->unlock();                        
        
+                       @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
+                       );
+
+                       $this->validate_group($group_info);
+
+                       // Lock tables
+                       $GLOBALS['phpgw']->db->lock(
+                               Array(
+                                       'phpgw_accounts',
+                                       'phpgw_preferences',
+                                       'phpgw_config',
+                                       'phpgw_applications',
+                                       'phpgw_hooks',
+                                       'phpgw_sessions',
+                                       'phpgw_acl',
+                                       'phpgw_app_sessions',
+                                       'phpgw_lang'
+                               )
+                       );
 
-                       // 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)
+                       $group = 
CreateObject('phpgwapi.accounts',$group_info['account_id'],'g');
+                       $old_group_info = $group->read_repository();
+
+                       // 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']))
                        {
-                               if(!in_array($key, $old_apps))
+                               reset($group_info['account_apps']);
+                               while(list($app,$value) = 
each($group_info['account_apps']))
                                {
-                                       $new_apps[] = $key;
+                                       $apps->add($app);
+                                       if(address@hidden || @$apps_before == 
False)
+                                       {
+                                               $new_apps[] = $app;
+                                       }
                                }
                        }
 
-                       // set group applications
-                       $this->set_module_permissions($new_group->get_id(), 
$values['account_apps']);
+                       $apps->save_repository();
+
+                       // Set new account_lid, if needed
+                       if($group_info['account_name'] && 
$old_group_info['account_lid'] <> $group_info['account_name'])
+                       {
+                               $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;
+                               }
+                       }
+                       else
+                       {
+                               $cd = 33;
+                       }
 
-                       // 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++)
+                       // Set group acl
+                       $acl = 
CreateObject('phpgwapi.acl',$group_info['account_id']);
+                       $old_group_list = 
$acl->get_ids_for_location($group_info['account_id'],1,'phpgw_group');
+                       if ($old_group_list)
                        {
-                               $is_new = true;
-                               for($j = 0; $j < count($old_group_list); $j++)
+                               @reset($old_group_list);
+                               while(list($key,$user_id) = 
each($old_group_list))
                                {
-                                       if($values['account_user'][$i] == 
$old_group_list[$j])
+                                       
$acl->delete_repository('phpgw_group',$group_info['account_id'],$user_id);
+                                       
if(!$group_info['account_user'][$user_id])
                                        {
-                                               unset($old_group_list[$j]);
-                                               $is_new = false;
-                                               break;
+                                               // 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);
                                        }
                                }
-                               if($is_new)
+                       }
+
+                       @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);
+
+                               // 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);
+
+                               // 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)
                                {
-                                       $acl->add_repository('phpgw_group', 
$new_group->get_id(), $values['account_user'][$i], 1);
-                                       
$this->refresh_session_data($values['account_user'][$i]);
-                                       
-                                       // 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))
+                                       $GLOBALS['pref'] = 
CreateObject('phpgwapi.preferences',$user_id);
+                                       $t = 
$GLOBALS['pref']->read_repository();
+                                       @reset($new_apps);
+                                       while(list($app_key,$app_name) = 
each($new_apps))
                                        {
-                                               $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++)
+                                               if 
(!$t[($app_name=='admin'?'common':$app_name)])
                                                {
-                                                       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;
-                                                       }
+                                                       
$GLOBALS['phpgw']->hooks->single('add_def_pref', $app_name);
+                                                       $docommit = True;
                                                }
                                        }
-                                       if ($docommit)
-                                       {
-                                               
$GLOBALS['pref']->save_repository();
-                                       }
+                               }
+                               if ($docommit)
+                               {
+                                       $GLOBALS['pref']->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]);
-                       }
+                       $group->save_repository();
 
-                       // 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());
-                       }
+               /*
+                       // Update any other options here, since the above 
save_repository () depends
+                       // on a group having users
+                       $group->data['file_space'] = 
$values['account_file_space_number'] . "-" . $values['account_file_space_type'];
+                       $group->save_repository();
+               */
+
+                       $GLOBALS['phpgw']->db->unlock();
+
+                       ExecMethod('admin.uiaccounts.list_groups');
+                       return False;
                }
 
                /**
Index: admin/inc/class.uiaccounts.inc.php
diff -u admin/inc/class.uiaccounts.inc.php:1.54 
admin/inc/class.uiaccounts.inc.php:1.55
--- admin/inc/class.uiaccounts.inc.php:1.54     Mon Mar 20 09:23:18 2006
+++ admin/inc/class.uiaccounts.inc.php  Tue Mar 21 12:54:56 2006
@@ -9,7 +9,7 @@
        *  Free Software Foundation; either version 2 of the License, or (at 
your  *
        *  option) any later version.                                           
   *
        
\**************************************************************************/
-       /* $Id: class.uiaccounts.inc.php,v 1.54 2006/03/20 09:23:18 sigurdne 
Exp $ */
+       /* $Id: class.uiaccounts.inc.php,v 1.55 2006/03/21 12:54:56 sigurdne 
Exp $ */
 
        class uiaccounts
        {
@@ -358,23 +358,26 @@
                        // this information should be provided by the app itself
                        $apps_with_acl = array
                        (
-                               'addressbook'   => True,
-                               'bookmarks'             => True,
-                               'calendar'              => True,
-                               'filemanager'   => True,
-                               'img'                   => True,
-                               'infolog'               => True,
-                               'inv'                   => True,
-                               'netsaint'              => True,
-                               'notes'                 => True,
-                               'phonelog'              => True,
-                               'phpwebhosting' => True,
-                               'projects'              => True,
-                               'todo'                  => True,
-                               'tts'                   => True
+                               'addressbook'           => array('top_grant' 
=>True),
+                               'bookmarks'             => array('top_grant' 
=>True),
+                               'calendar'              => array('top_grant' 
=>True),
+                               'filemanager'           => array('top_grant' 
=>True),
+                               'hrm'                   => array('top_grant' 
=>False),
+                               'img'                   => array('top_grant' 
=>True),
+                               'infolog'               => array('top_grant' 
=>True),
+                               'inv'                   => array('top_grant' 
=>True),
+                               'netsaint'              => array('top_grant' 
=>True),
+                               'notes'                 => array('top_grant' 
=>True),
+                               'phonelog'              => array('top_grant' 
=>True),
+                               'phpwebhosting'         => array('top_grant' 
=>True),
+                               'projects'              => array('top_grant' 
=>True),
+                               'property'              => array('top_grant' 
=>False),
+                               'todo'                  => array('top_grant' 
=>True),
+                               'tts'                   => array('top_grant' 
=>True),
                        );
 
-
+                       $GLOBALS['phpgw']->acl->verify_location($apps_with_acl);
+                       
                        $accounts =& CreateObject('phpgwapi.accounts');
                        $account_list = $accounts->get_list('accounts');
                        $account_num = count($account_list);
@@ -402,10 +405,12 @@
                                                'app_name'      => 
$permission[1]['title'],
                                                'checkbox_name' => 
'account_apps[' . $permission[0] . ']',
                                                'checked'       => 
$group_apps[$permission[0]] ? 'checked' : '',
-                                               'acl_url'       => 
($apps_with_acl[$permission[0]] && $account_id) ? 
$GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uiaclprefs.index&acl_app='.$permission[0].'&owner='.$account_id)
 : '',
+
+                                               'acl_url'       => 
($apps_with_acl[$permission[0]] && $account_id) ? 
$GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uiadmin_acl.list_acl&acl_app='.$permission[0]
 . '&granting_group='.$account_id) : '',
                                                'acl_img'             => 
$GLOBALS['phpgw']->common->image('admin','dot'),
-                                               'img_name'      => lang('Grant 
Access')
-                                       );
+                                               'acl_img_name'      => 
lang('Permissions'),
+                                               'grant_url'       => 
($apps_with_acl[$permission[0]] && $account_id) ? 
$GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uiadmin_acl.aclprefs&acl_app='.$permission[0]
 . '&granting_group='.$account_id) : '',
+                                               'grant_img_name'      => 
lang('Grant Access')                                   );
                                }
                        }
 
@@ -416,9 +421,7 @@
                        (
                                'account_id'         => $account_id,
                                'msgbox_data'        => $error_list,
-                               'edit_url'           => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.uiaccounts.edit_group',
-                                                                               
                                                                                
        'account_id' => $account_id
-                                                                               
                                                                                
   )),
+                               'edit_url'           => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.uiaccounts.edit_group','account_id' => $account_id)),
                                'lang_account_name'  => lang('group name'),
                                'value_account_name' => 
$GLOBALS['phpgw']->accounts->id2name($account_id),//$group->get_lid(),
                                'lang_include_user'  => lang('select users for 
inclusion'),
@@ -426,6 +429,7 @@
                                'lang_permissions'   => lang('permissions this 
group has'),
                                'lang_application'   => lang('application'),
                                'lang_acl'           => lang('acl'),
+                               'lang_grant'            => lang('grant'),
                                'lang_cancel'          => lang('cancel'),
                                'lang_save'              => lang('save'),
                                'app_list'           => $app_list,
Index: admin/templates/base/groups.xsl
diff -u admin/templates/base/groups.xsl:1.1 admin/templates/base/groups.xsl:1.2
--- admin/templates/base/groups.xsl:1.1 Tue Feb 14 09:47:27 2006
+++ admin/templates/base/groups.xsl     Tue Mar 21 12:54:56 2006
@@ -1,4 +1,4 @@
-<!-- $Id: groups.xsl,v 1.1 2006/02/14 09:47:27 skwashd Exp $ -->
+<!-- $Id: groups.xsl,v 1.2 2006/03/21 12:54:56 sigurdne Exp $ -->
 
        <xsl:template name="groups">
                <xsl:choose>
@@ -169,6 +169,7 @@
                                                                                
<td><xsl:value-of select="lang_application"/></td>
                                                                                
<td>&nbsp;</td>
                                                                                
<td><xsl:value-of select="lang_acl"/></td>
+                                                                               
<td><xsl:value-of select="lang_grant"/></td>
                                                                        </tr>
                                                                                
<xsl:apply-templates select="app_list"/>
                                                                </table>
@@ -235,8 +236,18 @@
                                        <xsl:when test="acl_url != ''">
                                                <xsl:variable name="acl_url" 
select="acl_url"/>
                                                <xsl:variable name="acl_img" 
select="acl_img"/>
-                                               <xsl:variable name="img_name" 
select="img_name"/>
-                                               <a href="{$acl_url}"><img 
src="{$acl_img}" border="0" hspace="3" align="absmiddle" alt="{$img_name}" 
name="{$img_name}"/></a>
+                                               <xsl:variable 
name="acl_img_name" select="acl_img_name"/>
+                                               <a href="{$acl_url}"><img 
src="{$acl_img}" border="0" hspace="3" align="absmiddle" alt="{$acl_img_name}" 
name="{$acl_img_name}"/></a>
+                                       </xsl:when>
+                               </xsl:choose>
+                       </td>
+                       <td width="5%" align="center">
+                               <xsl:choose>
+                                       <xsl:when test="grant_url != ''">
+                                               <xsl:variable name="grant_url" 
select="grant_url"/>
+                                               <xsl:variable name="acl_img" 
select="acl_img"/>
+                                               <xsl:variable 
name="grant_img_name" select="grant_img_name"/>
+                                               <a href="{$grant_url}"><img 
src="{$acl_img}" border="0" hspace="3" align="absmiddle" 
alt="{$grant_img_name}" name="{$grant_img_name}"/></a>
                                        </xsl:when>
                                </xsl:choose>
                        </td>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]