phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] phpgwapi/inc class.acl.inc.php


From: Sigurd Nes
Subject: [Phpgroupware-cvs] phpgwapi/inc class.acl.inc.php
Date: Sun, 22 Oct 2006 19:59:44 +0000

CVSROOT:        /sources/phpgwapi
Module name:    phpgwapi
Changes by:     Sigurd Nes <sigurdne>   06/10/22 19:59:44

Modified files:
        inc            : class.acl.inc.php 

Log message:
        tuning and some fixes

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/phpgwapi/inc/class.acl.inc.php?cvsroot=phpgwapi&r1=1.95&r2=1.96

Patches:
Index: class.acl.inc.php
===================================================================
RCS file: /sources/phpgwapi/phpgwapi/inc/class.acl.inc.php,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -b -r1.95 -r1.96
--- class.acl.inc.php   11 Oct 2006 18:46:21 -0000      1.95
+++ class.acl.inc.php   22 Oct 2006 19:59:44 -0000      1.96
@@ -6,7 +6,7 @@
        * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General 
Public License
        * @package phpgwapi
        * @subpackage accounts
-       * @version $Id: class.acl.inc.php,v 1.95 2006/10/11 18:46:21 sigurdne 
Exp $
+       * @version $Id: class.acl.inc.php,v 1.96 2006/10/22 19:59:44 sigurdne 
Exp $
        */
 
        /**
@@ -273,11 +273,19 @@
                * @return array Array with ACL records
                */
                
-               function save_repository()
+               function save_repository($appname = False, $location='')
                {
+                       if ($appname == False)
+                       {
+                               settype($appname,'string');
+                               $appname = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       }
+                       
+                       $location_filter = ($location?" AND acl_location 
$this->like '" . $location . "%'":'');
+
                        $this->db->transaction_begin();
 
-                       $sql = 'DELETE FROM phpgw_acl WHERE acl_account = '. 
(int) $this->account_id;
+                       $sql = 'DELETE FROM phpgw_acl WHERE acl_account = '. 
(int) $this->account_id . " AND acl_appname = '$appname'" . $location_filter;
                        $this->db->query($sql ,__LINE__,__FILE__);
 
                        $inherit_data = array();
@@ -285,11 +293,13 @@
                        {
                                reset ($this->data[$this->account_id]);         
        
 
+                               if($location)
+                               {
                                while(list($idx,$value) = 
each($this->data[$this->account_id]))
                                {
-                                       if ( 
is_array($this->data[$this->account_id][$idx]) && 
count($this->data[$this->account_id][$idx]) )
+                                               if ( 
is_array($this->data[$this->account_id][$idx]) && 
count($this->data[$this->account_id][$idx]) && 
strpos($this->data[$this->account_id][$idx]['location'],$location)===0)
                                        {
-                                               $sql = "SELECT id as location 
FROM phpgw_acl_location WHERE id $this->like 
'".$this->data[$this->account_id][$idx]['location']."%' AND appname='" . 
$this->data[$this->account_id][$idx]['appname'] . "' AND id != 
'".$this->data[$this->account_id][$idx]['location'] . "'";
+                                                       $sql = "SELECT id as 
location FROM phpgw_acl_location WHERE id $this->like '" . $location . "%' AND 
appname='" . $this->data[$this->account_id][$idx]['appname'] . "' AND id != '" 
. $location . "'";
                                                
$this->db->query($sql,__LINE__,__FILE__);
                                                while($this->db->next_record())
                                                {
@@ -306,6 +316,7 @@
                                                }
                                        }
                                }
+                               }
        
                                reset ($this->data[$this->account_id]);
                                if(count($inherit_data)>0)
@@ -318,7 +329,10 @@
                                while(list($idx,$value) = 
each($this->data[$this->account_id]))
                                {
                                        if ( 
isset($this->data[$this->account_id][$idx]['account'])
-                                               && 
$this->data[$this->account_id][$idx]['account'] == $this->account_id)
+                                               && 
$this->data[$this->account_id][$idx]['account'] == $this->account_id
+                                               && 
(($this->data[$this->account_id][$idx]['appname'] == $appname
+                                               && 
strpos($this->data[$this->account_id][$idx]['location'],$location)===0)
+                                               || (!$location && 
$this->data[$this->account_id][$idx]['location']=='run')))
                                        {
                                                $sql = 'insert into phpgw_acl 
(acl_appname, acl_location, acl_account, acl_rights,acl_grantor,acl_type)';
                                                $sql .= " 
values('".$this->data[$this->account_id][$idx]['appname']."', '"
@@ -335,7 +349,7 @@
                        }
                        /*remove duplicates*/
 
-                       $sql = "SELECT * FROM phpgw_acl WHERE acl_account='" . 
$this->account_id . "' GROUP BY acl_appname, acl_location, acl_account, 
acl_rights,acl_grantor,acl_type";
+                       $sql = "SELECT * FROM phpgw_acl WHERE acl_account='" . 
$this->account_id . "' AND acl_appname = '$appname'" . $location_filter . " 
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())
                        {
@@ -349,9 +363,9 @@
                                        );
                        }
 
-                       if(is_array($unique_data))
+                       if(isset($unique_data) && is_array($unique_data))
                        {
-                               $sql = 'delete from phpgw_acl where acl_account 
= '. intval($this->account_id);
+                               $sql = "DELETE FROM phpgw_acl where acl_account 
= '" . intval($this->account_id) . "' AND acl_appname = '$appname'" . 
$location_filter;
                                $this->db->query($sql ,__LINE__,__FILE__);
 
                                while(list($idx,$value) = each($unique_data))
@@ -373,13 +387,14 @@
 
                        if($this->load_from_shm)
                        {
-                               
$GLOBALS['phpgw']->shm->delete_key($GLOBALS['phpgw_info']['user']['domain'] . 
'acl_data_' . $this->account_id);
+                               
$GLOBALS['phpgw']->shm->delete_key($GLOBALS['phpgw_info']['user']['domain'] . 
'acl_data_groups_' . $this->account_id);
+                               
$GLOBALS['phpgw']->shm->delete_key($GLOBALS['phpgw_info']['user']['domain'] . 
'acl_data_accounts_' . $this->account_id);
+                               
$GLOBALS['phpgw']->shm->delete_key($GLOBALS['phpgw_info']['user']['domain'] . 
'acl_data_both_' . $this->account_id);
                        }
 
-                       return $unique_data;
+//                     return $unique_data;
                }
 
-
                // These are the non-standard $account_id specific functions
 
 
@@ -406,11 +421,31 @@
                        {
                                if($this->load_from_shm)
                                {
-                                       if(!$this->data[$this->account_id] = 
$GLOBALS['phpgw']->shm->get_value($GLOBALS['phpgw_info']['user']['domain'] . 
'acl_data_' . $this->account_id))
+                                       $this->data[$this->account_id] = 
$GLOBALS['phpgw']->shm->get_value($GLOBALS['phpgw_info']['user']['domain'] . 
'acl_data_' . $account_type . '_' . $this->account_id);
+                                       
if((is_array($this->data[$this->account_id]) && 
count($this->data[$this->account_id])==0) || $this->data[$this->account_id] == 
'empty')
+                                       {
+                                               $this->data[$this->account_id] 
= array();
+                                       }
+                                       else
+                                       {
+                                               
$this->read_repository($account_type);
+
+                                               
if(is_array($this->data[$this->account_id]) && 
count($this->data[$this->account_id])>0)
+                                               {
+                                                       
$GLOBALS['phpgw']->shm->store_value($GLOBALS['phpgw_info']['user']['domain'] . 
'acl_data_' . $account_type . '_' . 
$this->account_id,$this->data[$this->account_id]);                              
             
+                                               }
+                                               else
+                                               {
+                                               
$GLOBALS['phpgw']->shm->store_value($GLOBALS['phpgw_info']['user']['domain'] . 
'acl_data_' . $account_type . '_' . $this->account_id,'empty');                 
                         
+                                               }
+                                       }
+
+/*                                     if(!$this->data[$this->account_id] = 
$GLOBALS['phpgw']->shm->get_value($GLOBALS['phpgw_info']['user']['domain'] . 
'acl_data_' . $account_type . '_' . $this->account_id))
                                        {
                                                
$this->read_repository($account_type);
-                                               
$GLOBALS['phpgw']->shm->store_value($GLOBALS['phpgw_info']['user']['domain'] . 
'acl_data_' . $this->account_id,$this->data[$this->account_id]);
+                                               
$GLOBALS['phpgw']->shm->store_value($GLOBALS['phpgw_info']['user']['domain'] . 
'acl_data_' . $account_type . '_' . 
$this->account_id,$this->data[$this->account_id]);
                                        }
+*/
                                }
                                else
                                {
@@ -448,7 +483,7 @@
                                                {
                                                        if 
($this->data[$this->account_id][$idx]['type'] == $type)
                                                        {
-                                                               if($grantor)
+                                                               if($grantor || 
$this->data[$this->account_id][$idx]['grantor'])
                                                                {
                                                                        if 
($this->data[$this->account_id][$idx]['grantor'] == $grantor)
                                                                        {
@@ -510,13 +545,14 @@
                */
                function check_brutto($location, $required, $appname = 
False,$grantor=False,$type=false,$account_type='')
                {
-                       if(is_array($account_type))
+                       if(is_array($account_type)) //This is only for setting 
new rights / grants
                        {
                                $continue = true;
                                while ($continue && list(,$entry) = 
each($account_type))
                                {
                                        $this->data[$this->account_id]=array();
                                        $rights = 
$this->get_rights($location,$appname,$grantor,$type,$entry);
+
                                        if(!!($rights & $required)>0)
                                        {
                                                $continue = False;
@@ -1160,4 +1196,42 @@
                        }
                        return $this->data;
                }
+
+               /**
+               * Reads ACL accounts from database and return array with 
accounts that have rights - this is used to minimize workload when 
adding/removing acl-data
+               *
+               * @param string $appname Application name, defaults to 
$GLOBALS['phpgw_info']['flags']['currentapp']
+               * @param string $location location within Application name
+               * @param integer $grantor : check if this is grants or ordinary 
rights/mask
+               * @param integer $type mask or right (1 means mask , 0 means 
right) to check against
+
+               * @return array Array with accounts
+               */
+               function get_accounts_at_location($appname = '', $location ='', 
$grantor=0 ,$type ='')
+               {
+                       $acl_accounts = array();
+                       if (!$appname)
+                       {
+                               settype($appname,'string');
+                               $appname = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       }
+                       
+                       if($grantor > 0)
+                       {
+                               $filter_grants = ' AND acl_grantor IS NOT NULL';
+                       }
+                       else
+                       {
+                               $filter_grants = ' AND acl_grantor IS NULL';
+                       }
+                       $sql = "SELECT acl_account from phpgw_acl WHERE 
acl_appname = '$appname' AND acl_location $this->like '$location%' 
$filter_grants AND acl_type = '$type' GROUP BY acl_account";
+                       $this->db->query($sql,__LINE__,__FILE__);
+
+                       while ($this->db->next_record())
+                       {
+                               $acl_accounts[$this->db->f('acl_account')] = 
true;
+                       }
+
+                       return $acl_accounts;
+               }
        }




reply via email to

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