phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] hrm/inc class.acl2.inc.php


From: Sigurd Nes
Subject: [Phpgroupware-cvs] hrm/inc class.acl2.inc.php
Date: Fri, 24 Feb 2006 13:23:54 +0000

CVSROOT:        /sources/phpgroupware
Module name:    hrm
Branch:         
Changes by:     Sigurd Nes <address@hidden>     06/02/24 13:23:54

Modified files:
        inc            : class.acl2.inc.php 

Log message:
        Added inheritance of rights

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/hrm/inc/class.acl2.inc.php.diff?tr1=1.7&tr2=1.8&r1=text&r2=text

Patches:
Index: hrm/inc/class.acl2.inc.php
diff -u hrm/inc/class.acl2.inc.php:1.7 hrm/inc/class.acl2.inc.php:1.8
--- hrm/inc/class.acl2.inc.php:1.7      Wed Feb 22 09:07:08 2006
+++ hrm/inc/class.acl2.inc.php  Fri Feb 24 13:23:54 2006
@@ -6,7 +6,7 @@
        * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General 
Public License
        * @package phpgwapi
        * @subpackage accounts
-       * @version $Id: class.acl2.inc.php,v 1.7 2006/02/22 09:07:08 sigurdne 
Exp $
+       * @version $Id: class.acl2.inc.php,v 1.8 2006/02/24 13:23:54 sigurdne 
Exp $
        */
 
        /**
@@ -62,6 +62,13 @@
                        $this->db->User = 
$GLOBALS['phpgw_info']['server']['db_user'];
                        $this->db->Password = 
$GLOBALS['phpgw_info']['server']['db_pass'];
 
+                       $this->db2 = CreateObject('phpgwapi.db');
+                       $this->db2->Host = 
$GLOBALS['phpgw_info']['server']['db_host'];
+                       $this->db2->Type = 
$GLOBALS['phpgw_info']['server']['db_type'];
+                       $this->db2->Database = 
$GLOBALS['phpgw_info']['server']['db_name'];
+                       $this->db2->User = 
$GLOBALS['phpgw_info']['server']['db_user'];
+                       $this->db2->Password = 
$GLOBALS['phpgw_info']['server']['db_pass'];
+
                        if (!($this->account_id = intval($account_id)))
                        {
                                $this->account_id = 
get_account_id($account_id,@$GLOBALS['phpgw_info']['user']['account_id']);
@@ -244,13 +251,39 @@
 
                function save_repository()
                {
-                       reset($this->data);
+                       $this->db->transaction_begin();
 
                        $sql = 'delete from hrm_acl where acl_account = '. 
intval($this->account_id);
                        $this->db->query($sql ,__LINE__,__FILE__);
 
-                       $count = count($this->data);
                        reset ($this->data);
+
+                       while(list($idx,$value) = each($this->data))
+                       {
+                               $sql = "SELECT id as location FROM 
hrm_acl_location WHERE id like '".$this->data[$idx]['location']."%' AND 
appname='" . $this->data[$idx]['appname'] . "' AND id != 
'".$this->data[$idx]['location'] . "'";
+                               $this->db->query($sql,__LINE__,__FILE__);
+                               while($this->db->next_record())
+                               {
+                                       $inherit_data[]= array(
+                                               'appname' => 
$this->data[$idx]['appname'],
+                                               'location' => 
$this->db->f('location'),
+                                               'account' => $this->account_id,
+                                               'rights' => 
$this->data[$idx]['rights'],
+                                               'grantor' => 
$this->data[$idx]['grantor'],
+                                               'type' => 
$this->data[$idx]['type'],
+                                               'account_type' => 
$this->data[$idx]['account_type'],            
+                                               );
+                               }
+                       }
+
+                       reset ($this->data);
+                       if(is_array($inherit_data))
+                       {
+                               $this->data = array_merge($this->data, 
$inherit_data);
+                       }
+                       
+                       array_unique($this->data);
+
                        while(list($idx,$value) = each($this->data))
                        {
                                if ($this->data[$idx]['account'] == 
$this->account_id)
@@ -267,8 +300,45 @@
                                        $this->db->query($sql 
,__LINE__,__FILE__);
                                }
                        }
-                       reset($this->data);
-                       return $this->data;
+                       
+                       /*remove duplicates*/
+
+                       $sql = "SELECT * FROM hrm_acl WHERE acl_account='" . 
$this->account_id . "' GROUP BY acl_appname, acl_location, acl_account, 
acl_rights,acl_grantor,acl_type";
+                       $this->db->query($sql,__LINE__,__FILE__);
+                       while($this->db->next_record())
+                       {
+                               $unique_data[]= array(
+                                       'appname' => 
$this->db->f('acl_appname'),
+                                       'location' => 
$this->db->f('acl_location'),
+                                       'account' => $this->account_id,
+                                       'rights' => $this->db->f('acl_rights'),
+                                       'grantor' => 
$this->db->f('acl_grantor'),
+                                       'type' => $this->db->f('acl_type')
+                                       );
+                       }
+
+                       if(is_array($unique_data))
+                       {
+                               $sql = 'delete from hrm_acl where acl_account = 
'. intval($this->account_id);
+                               $this->db->query($sql ,__LINE__,__FILE__);
+
+                               while(list($idx,$value) = each($unique_data))
+                               {
+                                       $sql = 'insert into hrm_acl 
(acl_appname, acl_location, acl_account, acl_rights,acl_grantor,acl_type)';
+                                       $sql .= " 
values('".$unique_data[$idx]['appname']."', '"
+                                               . 
$unique_data[$idx]['location']."', "
+                                               .$this->account_id.', '
+                                               . 
intval($unique_data[$idx]['rights']) . ', '
+                                               . 
($unique_data[$idx]['grantor']?$unique_data[$idx]['grantor']:'NULL')  . ', '
+                                               . 
intval($unique_data[$idx]['type'])
+                                               .')';
+
+                                       $this->db->query($sql 
,__LINE__,__FILE__);
+                               }
+                       }
+
+                       $this->db->transaction_commit();
+                       return $unique_data;
                }
 
 
@@ -517,10 +587,24 @@
                */
                function add_repository($app, $location, $account_id, $rights)
                {
+
                        $this->delete_repository($app, $location, $account_id);
-                       $sql = 'insert into hrm_acl (acl_appname, acl_location, 
acl_account, acl_rights,acl_grantor,acl_type)';
-                       $sql .= " values ('" . $app . "','" . $location . "','" 
. $account_id . "','" . $rights . ", NULL ,0')";
-                       $this->db->query($sql ,__LINE__,__FILE__);
+
+                       $inherit_location[] = $location; // in case the 
location is not found in the location table
+
+                       $sql = "SELECT id as location FROM hrm_acl_location 
WHERE id like '".$location."%' AND appname='" . $app . "' AND id != '" 
.$location . "'";
+                       $this->db->query($sql,__LINE__,__FILE__);
+                       while($this->db->next_record())
+                       {
+                               $inherit_location[] = $this->db->f('location'); 
+                       }
+                       
+                       foreach($inherit_location as $acl_location)
+                       {
+                               $sql = 'insert into hrm_acl (acl_appname, 
acl_location, acl_account, acl_rights,acl_grantor,acl_type)';
+                               $sql .= " values ('" . $app . "','" . 
$acl_location . "','" . $account_id . "','" . $rights . ", NULL ,0')";
+                               $this->db->query($sql ,__LINE__,__FILE__);
+                       }
                        return True;
                }
 
@@ -551,7 +635,7 @@
                                $account_sel = ' and acl_account=' . 
$account_id;
                        }
 
-                       $sql = "delete from hrm_acl where acl_appname like '" . 
$app . "' and acl_location like '" . $location . "'" . $account_sel;
+                       $sql = "delete from hrm_acl where acl_appname like '" . 
$app . "' and acl_location like '" . $location . "%'" . $account_sel;
                        $this->db->query($sql ,__LINE__,__FILE__);
                        return $this->db->num_rows();
                }
@@ -701,12 +785,6 @@
                                $cache_accountid[$accountid] = $account_id;
                        }
 
-                       $this->db2 = CreateObject('phpgwapi.db');
-                       $this->db2->Host = 
$GLOBALS['phpgw_info']['server']['db_host'];
-                       $this->db2->Type = 
$GLOBALS['phpgw_info']['server']['db_type'];
-                       $this->db2->Database = 
$GLOBALS['phpgw_info']['server']['db_name'];
-                       $this->db2->User = 
$GLOBALS['phpgw_info']['server']['db_user'];
-                       $this->db2->Password = 
$GLOBALS['phpgw_info']['server']['db_pass'];
 
        //              $db2 = $this->db;
                        $memberships = 
$GLOBALS['phpgw']->accounts->membership($account_id);
@@ -719,25 +797,25 @@
                                $security .= ','.$group[1]['account_id'];
                        }
                        $security .= ')';
-                       $db2->query($sql . $security ,__LINE__,__FILE__);
+                       $this->db2->query($sql . $security ,__LINE__,__FILE__);
 
-                       if ($db2->num_rows() == 0)
+                       if ($this->db2->num_rows() == 0)
                        {
                                return False;
                        }
-                       while ($db2->next_record())
+                       while ($this->db2->next_record())
                        {
-                               if(isset($apps[$db2->f('acl_appname')]))
+                               if(isset($apps[$this->db2->f('acl_appname')]))
                                {
-                                       $rights = $apps[$db2->f('acl_appname')];
+                                       $rights = 
$apps[$this->db2->f('acl_appname')];
                                }
                                else
                                {
                                        $rights = 0;
-                                       $apps[$db2->f('acl_appname')] = 0;
+                                       $apps[$this->db2->f('acl_appname')] = 0;
                                }
-                               $rights |= $db2->f('acl_rights');
-                               $apps[$db2->f('acl_appname')] |= $rights;
+                               $rights |= $this->db2->f('acl_rights');
+                               $apps[$this->db2->f('acl_appname')] |= $rights;
                        }
                        return $apps;
                }
@@ -772,12 +850,6 @@
                */
                function get_grants_type($app='',$location='',$type = '')
                {
-                       $db2 = CreateObject('phpgwapi.db');
-                       $db2->Host = 
$GLOBALS['phpgw_info']['server']['db_host'];
-                       $db2->Type = 
$GLOBALS['phpgw_info']['server']['db_type'];
-                       $db2->Database = 
$GLOBALS['phpgw_info']['server']['db_name'];
-                       $db2->User = 
$GLOBALS['phpgw_info']['server']['db_user'];
-                       $db2->Password = 
$GLOBALS['phpgw_info']['server']['db_pass'];
 
 //                     $db2 = $this->db;
 
@@ -802,18 +874,18 @@
                                $security .= ",'" . $group['account_id'] . "'";
                        }
                        $security .= ')';
-                       $db2->query($sql . $security ,__LINE__,__FILE__);
+                       $this->db2->query($sql . $security ,__LINE__,__FILE__);
                        $rights = 0;
                        $accounts = Array();
-                       if ($db2->num_rows() == 0 && $type==0)
+                       if ($this->db2->num_rows() == 0 && $type==0)
                        {
                                
$grants[$GLOBALS['phpgw_info']['user']['account_id']] = 31;
                                return $grants;
                        }
-                       while ($db2->next_record())
+                       while ($this->db2->next_record())
                        {
-                               $grantor = $db2->f('acl_grantor');
-                               $rights = $db2->f('acl_rights');
+                               $grantor = $this->db2->f('acl_grantor');
+                               $rights = $this->db2->f('acl_rights');
                                if(!isset($accounts[$grantor]))
                                // cache the group-members for performance
                                {




reply via email to

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