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: Dave Hall
Subject: [Phpgroupware-cvs] admin inc/class.boaccounts.inc.php inc/class.ui...
Date: Sat, 25 Mar 2006 12:39:55 +0000

CVSROOT:        /cvsroot/phpgroupware
Module name:    admin
Branch:         
Changes by:     Dave Hall <address@hidden>      06/03/25 12:39:55

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

Log message:
        add working group manager functionality, only supports 1 manager per 
group atm, accounts classes need some mods to properly support it

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/admin/inc/class.boaccounts.inc.php.diff?tr1=1.44&tr2=1.45&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/admin/inc/class.uiaccounts.inc.php.diff?tr1=1.58&tr2=1.59&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/admin/templates/desktop/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.44 
admin/inc/class.boaccounts.inc.php:1.45
--- admin/inc/class.boaccounts.inc.php:1.44     Wed Mar 22 13:27:05 2006
+++ admin/inc/class.boaccounts.inc.php  Sat Mar 25 12:39:55 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.44 2006/03/22 13:27:05 skwashd Exp 
$ */
+       /* $Id: class.boaccounts.inc.php,v 1.45 2006/03/25 12:39:55 skwashd Exp 
$ */
 
        //FIXME define constants for rights so we can fuck all these magic 
numbers
        
@@ -99,6 +99,7 @@
 
                function edit_group($values)
                {
+                       //TODO switch to PHPGW_ACL_EDIT (4) for this test
                        if 
($GLOBALS['phpgw']->acl->check('group_access',16,'admin'))
                        {
                                $error[] = lang('no permission to create 
groups');
@@ -111,8 +112,9 @@
                        
                        $new_group =& CreateObject('phpgwapi.accounts', 
$values['account_id'], 'g');
                        $new_group->read_repository();
-                       $new_group->set_lid($values['account_name']);
+                       $new_group->firstname = $values['account_name'];
 
+                       //TODO Move to transactions?
                        $GLOBALS['phpgw']->db->lock(array('phpgw_accounts',
                                                                                
          'phpgw_preferences',
                                                                                
          'phpgw_config',
@@ -120,181 +122,109 @@
                                                                                
          'phpgw_hooks',
                                                                                
          'phpgw_sessions',
                                                                                
          'phpgw_acl',
-                                                                               
          'phpgw_app_sessions'
+                                                                               
          'phpgw_app_sessions',
+                                                                               
          'phpgw_lang' // why lang? no idea, ask sigurd :)
                                                                                
         ));
 
-                       $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))
+                       $id = $values['account_id'];
+                       if ( !$values['account_id'] ) // add new group?
                        {
-                               $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;
-                               }
+                               $new_group_values = array
+                                                                       (
+                                                                               
'type'                  => 'g',
+                                                                               
'account_lid'   => $values['account_name'],
+                                                                               
'passwd'                => '',
+                                                                               
'firstname'             => $values['account_name'],
+                                                                               
'lastname'              => 'Group',
+                                                                               
'status'                => 'A',
+                                                                               
'expires'               => -1
+                                                                       );
+                               $id = $new_group->create($new_group_values, 
false);
                        }
-                       @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'
-                               )
-                       );
-
-                       $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']))
+                       else //edit group
                        {
-                               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;
-                                       }
-                               }
+                               $new_group->save_repository();
                        }
+                       $GLOBALS['phpgw']->db->unlock();                        
                                                                                
                 
 
-                       $apps->save_repository();
-
-                       // Set new account_lid, if needed
-                       if($group_info['account_name'] && 
$old_group_info['account_lid'] <> $group_info['account_name'])
+                       // 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->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']))
+                               if(!in_array($key, $old_apps))
                                {
-                                       $cd = 39;
+                                       $new_apps[] = $key;
                                }
-                               else
-                               {
-                                       $cd = 33;
-                               }
-                       }
-                       else
-                       {
-                               $cd = 33;
                        }
-
-                       // set group applications
-                       $this->set_module_permissions($new_group->get_id(), 
$values['account_apps']);
+                       $this->set_module_permissions($new_group->account_id, 
$values['account_apps']);
 
                        // members handling
                        // Add new members to group
                        $acl =& CreateObject('phpgwapi.acl', 
$values['account_id']);
                        $old_group_list = $old_group->get_members();
-                       
-                       die ( '<pre>' . print_r($old_group_list, true) . 
'</pre>');
-                       
                        for($i = 0; $i < count($values['account_user']); $i++)
                        {
-                               @reset($old_group_list);
-                               while(list($key,$user_id) = 
each($old_group_list))
+                               $is_new = true;
+                               for($j = 0; $j < count($old_group_list); $j++)
                                {
-                                       
$acl->delete_repository('phpgw_group',$group_info['account_id'],$user_id);
-                                       
if(!$group_info['account_user'][$user_id])
+                                       if($values['account_user'][$i] == 
$old_group_list[$j])
                                        {
-                                               // 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);
+                                               unset($old_group_list[$j]);
+                                               $is_new = false;
+                                               break;
                                        }
                                }
-                       }
-
-                       @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)
+                               if($is_new)
                                {
-                                       $GLOBALS['pref'] = 
CreateObject('phpgwapi.preferences',$user_id);
-                                       $t = 
$GLOBALS['pref']->read_repository();
-                                       @reset($new_apps);
-                                       while(list($app_key,$app_name) = 
each($new_apps))
+                                       $acl->add_repository('phpgw_group', 
$new_group->account_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))
                                        {
-                                               if 
(!$t[($app_name=='admin'?'common':$app_name)])
+                                               $GLOBALS['pref'] =& 
CreateObject('phpgwapi.preferences', $values['account_user'][$i]);
+                                               $t = 
$GLOBALS['pref']->read_repository();
+                                               foreach ( $new_apps as 
$app_name)
                                                {
-                                                       
$GLOBALS['phpgw']->hooks->single('add_def_pref', $app_name);
-                                                       $docommit = True;
+                                                       if($app_name == 
'admin') //another workaround :-(
+                                                       {
+                                                               $app_name == 
'common';
+                                                       }
+                                                       
+                                                       if ( !$t[$app_name] )
+                                                       {
+                                                               
$GLOBALS['phpgw']->hooks->single('add_def_pref', $app_name);
+                                                               $docommit = 
true;
+                                                       }
                                                }
                                        }
-                               }
-                               if ($docommit)
-                               {
-                                       $GLOBALS['pref']->save_repository();
+                                       if ($docommit)
+                                       {
+                                               
$GLOBALS['pref']->save_repository();
+                                       }
                                }
                        }
-                       $group->save_repository();
-
-               /*
-                       // 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();
+                       // Remove members from group
+                       foreach($old_group_list as $key => $value)
+                       {
+                               
$acl->delete_repository('phpgw_group',$new_group->account_id, $value);
+                               
$this->refresh_session_data($values['account_user'][$i]);
+                       }
+                       
+                       //Add the group manager
+                       $acl->add_repository('phpgw_group', 
$new_group->account_id, $values['group_manager'], PHPGW_ACL_GROUP_MANAGERS);
 
-                       // FIXME Use the VFS class for this - skwashd Mar-2006
-                       if($old_group->get_lid() != $new_group->get_lid())
+                       // Things that have to change because of new group name
+                       // FIXME this needs to be changed to work with all VFS 
backends
+                       if($old_group->account_lid != $new_group->account_lid)
                        {
                                $basedir = 
$GLOBALS['phpgw_info']['server']['files_dir'] . SEP . 'groups' . SEP;
-                               @rename($basedir . $old_group->get_lid(), 
$basedir . $new_group->get_lid());
-                       }
-                       ExecMethod('admin.uiaccounts.list_groups');
-                       return False;
+                               @rename($basedir . $old_group->account_lid, 
$basedir . $new_group->account_lid);
+                       }                       
+                       return $id;
                }
 
                /**
Index: admin/inc/class.uiaccounts.inc.php
diff -u admin/inc/class.uiaccounts.inc.php:1.58 
admin/inc/class.uiaccounts.inc.php:1.59
--- admin/inc/class.uiaccounts.inc.php:1.58     Fri Mar 24 08:09:48 2006
+++ admin/inc/class.uiaccounts.inc.php  Sat Mar 25 12:39:55 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.58 2006/03/24 08:09:48 sigurdne 
Exp $ */
+       /* $Id: class.uiaccounts.inc.php,v 1.59 2006/03/25 12:39:55 skwashd Exp 
$ */
 
        class uiaccounts
        {
@@ -322,22 +322,16 @@
                                        {
                                                $values['account_apps'] = 
$account_apps;
                                        }
+                                       else
+                                       {
+                                               $values['account_apps'] = 
array();
+                                       }
                                        
                                        if ( $group_manager )
                                        {
                                                $values['group_manager'] = 
$group_manager;
                                        }
-
-                                       if ($values['account_id'])
-                                       {
-                                               $this->bo->edit_group($values);
-                                               $account_id = 
$values['account_id'];
-                                       }
-                                       else
-                                       {
-                                               $this->bo->edit_group($values);
-                                               
$GLOBALS['phpgw']->redirect_link('/index.php','menuaction=admin.uiaccounts.list_groups');
-                                       }
+                                       $account_id = 
$this->bo->edit_group($values);
                                }
                        }
                        
@@ -353,6 +347,10 @@
                        $group->member($account_id);
                        $group_members = $group->get_members();
                        $group_apps = $this->bo->load_group_apps($account_id);
+                       
+                       
+                       $group_manager = 
$GLOBALS['phpgw']->acl->get_ids_for_location($account_id, 
PHPGW_ACL_GROUP_MANAGERS, 'phpgw_group');
+                       $group_members = array_merge($group_members, 
$group_manager);
 
                        if ( !is_array($group_members) )
                        {
@@ -385,9 +383,13 @@
                        $accounts =& CreateObject('phpgwapi.accounts');
                        $account_list = $accounts->get_list('accounts');
                        $account_num = count($account_list);
-                       while (list($key,$entry) = each($account_list))
+                       
+                       $members = array();
+                       $user_list = array();
+                       $i = 0;
+                       foreach ( $account_list as $key => $entry )
                        {
-                               $user_list[] = array
+                               $user_list[$i] = array
                                (
                                        'account_id'   => $entry['account_id'],
                                        'account_name' => 
$GLOBALS['phpgw']->common->display_fullname($entry['account_lid'],
@@ -396,8 +398,29 @@
                                                                                
                                                                                
 ),
                                        'selected'              => 
in_array(intval($entry['account_id']), $group_members) ? ' selected' : ''
                                );
+                               if ( in_array( (int)$entry['account_id'], 
$group_members) )
+                               {
+                                       $user_list[$i]['selected'] = 'selected';
+                                       $members[$entry['account_id']] = 
$user_list[$i]['account_name'];
+                               }
+                               else
+                               {
+                                       $user_list[$i]['selected'] = '';
+                               } 
+                               ++$i;
                        }
 
+                       $manager_list = array();
+                       foreach ( $members as $id => $username )
+                       {
+                               $manager_list[] = array
+                               (
+                                       'account_id'    => $id,
+                                       'account_name'  => $username,
+                                       'selected'              => $id == 
$group_manager[0] ? 'selected' : ''
+                               );
+                       }
+                       
                        $apps = array_keys($GLOBALS['phpgw_info']['apps']);
                        asort($apps);
                        foreach ( $apps as $app )
@@ -439,7 +462,7 @@
                                'edit_url'                      => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.uiaccounts.edit_group',
                                                                                
                                                                                
        'account_id' => $account_id
                                                                                
                                                                                
   )),
-                               'group_manager'         => $group_members,
+                               'group_manager'         => $manager_list,
                                'guser_list'            => $user_list,
                                'img_close'                     => 
$GLOBALS['phpgw']->common->image('phpgwapi', 'stock_close', '.png', false),
                                'img_save'                      => 
$GLOBALS['phpgw']->common->image('phpgwapi', 'stock_save', '.png', false),
Index: admin/templates/desktop/groups.xsl
diff -u admin/templates/desktop/groups.xsl:1.1 
admin/templates/desktop/groups.xsl:1.2
--- admin/templates/desktop/groups.xsl:1.1      Wed Mar 22 13:02:56 2006
+++ admin/templates/desktop/groups.xsl  Sat Mar 25 12:39:55 2006
@@ -1,4 +1,4 @@
-<!-- $Id: groups.xsl,v 1.1 2006/03/22 13:02:56 skwashd Exp $ -->
+<!-- $Id: groups.xsl,v 1.2 2006/03/25 12:39:55 skwashd Exp $ -->
 
 <xsl:template name="groups">
        <xsl:choose>
@@ -133,30 +133,38 @@
        <xsl:variable name="account_id" select="account_id" />
        <xsl:variable name="select_size" select="select_size" />
        <form action="{$edit_url}" method="post">
-               <input type="hidden" name="values[account_id]" 
value="{$account_id}" class="hidden" /><br />
+               <input type="hidden" name="values[account_id]"
+                       value="{$account_id}" class="hidden" />
+               <br />
 
                <label for="account_name">
                        <xsl:value-of select="lang_account_name" />
                </label>
-               <input type="text" name="values[account_name]" 
id="account_name">
+               <input type="text" name="values[account_name]"
+                       id="account_name">
                        <xsl:attribute name="value">
                                <xsl:value-of select="value_account_name" />
                        </xsl:attribute>
-               </input><br />
+               </input>
+               <br />
 
                <label for="account_user">
                        <xsl:value-of select="lang_include_user" />
                </label>
-               <select id="account_user" name="account_user[]" 
multiple="multiple" size="{$select_size}" onchange="updateManager()">
+               <select id="account_user" name="account_user[]"
+                       multiple="multiple" size="{$select_size}"
+                       onchange="updateManager()">
                        <xsl:apply-templates select="guser_list" />
-               </select><br />
+               </select>
+               <br />
 
                <label for="group_manager">
                        <xsl:value-of select="lang_group_manager" />
                </label>
                <select id="group_manager" name="group_manager">
                        <xsl:apply-templates select="group_manager" />
-               </select><br />
+               </select>
+               <br />
 
                <label for="quota">
                        <xsl:value-of select="lang_file_space" />
@@ -167,18 +175,22 @@
                </span>
                <ul class="admin_apps_list">
                        <li class="th">
-                               <span><xsl:value-of select="lang_application" 
/></span>
+                               <span>
+                                       <xsl:value-of select="lang_application" 
/>
+                               </span>
                                <xsl:value-of select="lang_acl" />
                        </li>
                        <xsl:apply-templates select="app_list" />
                </ul>
                <div class="btngrp">
-                       <button type="submit" name="values[cancel]" 
onclick="this.value=1;">
+                       <button type="submit" name="values[cancel]"
+                               onclick="this.value=1;">
                                <img src="{img_close}" alt="{lang_close}" />
                                <xsl:value-of select="lang_close" />
                        </button>
-                       
-                       <button type="submit" name="values[save]" 
onclick="this.value=1;">
+
+                       <button type="submit" name="values[save]"
+                               onclick="this.value=1;">
                                <img src="{img_save}" alt="{lang_save}" />
                                <xsl:value-of select="lang_save" />
                        </button>
@@ -223,7 +235,7 @@
                        <xsl:choose>
                                <xsl:when test="@class">
                                        <xsl:value-of select="@class" />
-                                       <xsl:text> even</xsl:text>
+                                       <xsl:text>even</xsl:text>
                                </xsl:when>
                                <xsl:when test="position() mod 2 = 0">
                                        <xsl:text>row_off even</xsl:text>
@@ -238,10 +250,13 @@
                </label>
                <xsl:choose>
                        <xsl:when test="checked != ''">
-                               <input type="checkbox" id="app_{app_name}" 
name="{checkbox_name}" value="1" checked="checked" class="cbStyled" />
+                               <input type="checkbox" id="app_{app_name}"
+                                       name="{checkbox_name}" value="1" 
checked="checked"
+                                       class="cbStyled" />
                        </xsl:when>
                        <xsl:otherwise>
-                               <input type="checkbox" id="app_{app_name}" 
name="{checkbox_name}" value="1" class="cbStyled" />
+                               <input type="checkbox" id="app_{app_name}"
+                                       name="{checkbox_name}" value="1" 
class="cbStyled" />
                        </xsl:otherwise>
                </xsl:choose>
                <xsl:choose>
@@ -254,6 +269,14 @@
                                </a>
                        </xsl:when>
                </xsl:choose>
+               <xsl:choose>
+                       <xsl:when test="grant_url != ''">
+                               <a href="{grant_url}">
+                                       <img src="{acl_img}" 
alt="{grant_img_name}" />
+                               </a>
+                       </xsl:when>
+               </xsl:choose>
+
                <br />
        </li>
 </xsl:template>




reply via email to

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