[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] [18386] acl now using an array computed just once
From: |
Pascal Vilarem |
Subject: |
[Phpgroupware-cvs] [18386] acl now using an array computed just once |
Date: |
Mon, 10 Dec 2007 21:41:55 +0000 |
Revision: 18386
http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=18386
Author: maat
Date: 2007-12-10 21:41:55 +0000 (Mon, 10 Dec 2007)
Log Message:
-----------
acl now using an array computed just once
new acls to allow manage a project without having admin rights
Modified Paths:
--------------
trunk/ged/inc/class.ged_dm.inc.php
Modified: trunk/ged/inc/class.ged_dm.inc.php
===================================================================
--- trunk/ged/inc/class.ged_dm.inc.php 2007-12-10 21:33:51 UTC (rev 18385)
+++ trunk/ged/inc/class.ged_dm.inc.php 2007-12-10 21:41:55 UTC (rev 18386)
@@ -64,7 +64,7 @@
// TODO define this using the (future) admin boards (hooks ?)
$this->datadir=$GLOBALS['phpgw_info']['server']['files_dir']."/ged-data";
-
+
if ( ! is_dir ( $this->datadir ))
mkdir ( $this->datadir);
@@ -99,21 +99,43 @@
// TODO : statuses restrictions
// (willneed a
find_versions(element_id, $statuses))
- $the_id=$this->db->f('element_id');
-
$this->acl[$the_id]['read']=$this->db->f('aclread');
-
$this->acl[$the_id]['write']=$this->db->f('aclwrite');
-
$this->acl[$the_id]['delete']=$this->db->f('acldelete');
-
$this->acl[$the_id]['changeacl']=$this->db->f('aclchangeacl');
-
-
$the_statuses=$this->db->f('aclstatuses');
- if ( ! empty ( $the_statuses ) )
+ $the_id=$this->db->f('element_id');
+ if ( isset($this->acl[$the_id]))
{
-
$this->acl[$the_id]['statuses']=unserialize($the_statuses);
+
$this->acl[$the_id]['read']=max($this->acl[$the_id]['read'],
$this->db->f('aclread'));
+
$this->acl[$the_id]['write']=max($this->acl[$the_id]['write'],
$this->db->f('aclwrite'));
+
$this->acl[$the_id]['delete']=max($this->acl[$the_id]['delete'],
$this->db->f('acldelete'));
+
$this->acl[$the_id]['changeacl']=max($this->acl[$the_id]['changeacl'],
$this->db->f('aclchangeacl'));
+
+
$the_temp_statuses=$this->db->f('aclstatuses');
+ if ( ! empty (
$the_temp_statuses ) && ! empty ( $this->acl[$the_id]['statuses'] ))
+ {
+
$this->acl[$the_id]['statuses']=array_merge($this->acl[$the_id]['statuses'],
unserialize($the_statuses));
+ }
+ else
+ {
+
$this->acl[$the_id]['statuses']=array();
+ }
}
else
{
-
$this->acl[$the_id]['statuses']=array();
- }
+
$this->acl[$the_id]['read']=$this->db->f('aclread');
+
$this->acl[$the_id]['write']=$this->db->f('aclwrite');
+
$this->acl[$the_id]['delete']=$this->db->f('acldelete');
+
$this->acl[$the_id]['changeacl']=$this->db->f('aclchangeacl');
+
+
$the_statuses=$this->db->f('aclstatuses');
+ if ( ! empty ( $the_statuses ) )
+ {
+
$this->acl[$the_id]['statuses']=unserialize($the_statuses);
+ }
+ else
+ {
+
$this->acl[$the_id]['statuses']=array();
+ }
+ }
+ //DEBUG
+ //_debug_array($this->acl[$the_id]);
}
$this->db->unlock();
@@ -326,7 +348,7 @@
print ( "update_file: end.<br>\n");
}
-
+
function set_project ($element_id, $project_name,
$the_root_element_id=null)
{
if ( $the_root_element_id == null )
@@ -437,75 +459,75 @@
$minor=$new_version['minor'];
if ( $major < $last_version['major'] || $major ==
$last_version['major'] && $minor < $last_version['minor'] )
- {
+ {
$major=$last_version['major'];
$minor=$last_version['minor']+1;
- }
-
+ }
+
// MEMO gestion du stored_name pour eviter les ecrasements.
-
- $basename=basename($new_version['file_name']);
- $candidate_name=$basename;
-
- $extension=$this->get_file_extention($basename);
-
- $i=0;
-
- while (file_exists($this->datadir."/".$candidate_name))
+
+ $basename=basename($new_version['file_name']);
+ $candidate_name=$basename;
+
+ $extension=$this->get_file_extention($basename);
+
+ $i=0;
+
+ while (file_exists($this->datadir."/".$candidate_name))
+ {
+ $i ++;
+ $candidate_name="v".$i."_".$basename;
+ }
+
+ $new_name=$this->datadir."/".$candidate_name;
+
+ if (move_uploaded_file($new_version['file_tmp_name'],
$new_name))
+ {
+
+ $download_result='OK';
+
+ }
+ else
+ return "PB download";
+
+ // MEMO attention que if $new_version['status'] est current il
faut rendre obsol�te la "vieille"
+
+ if ($download_result=='OK')
+ {
+
+ $sql_model1="INSERT INTO %s ( size, file_name,
stored_name, file_extension, creator_id, creation_date, status, element_id,
description, major, minor ) VALUES ";
+ $sql_model1.=" ( %d, '%s', '%s', '%s', %d, %d, '%s',
%d, '%s', %d, %d ) ";
+
+ $sql1=sprintf($sql_model1, $this->tables['versions'],
$new_version['file_size'], addslashes($new_version['file_name']),
addslashes($candidate_name), $extension,
$GLOBALS['phpgw_info']['user']['account_id'], time(), 'working',
$new_version['element_id'], $this->cleanstr($new_version['description']),
$major, $minor);
+
+ //print ("<br/>".$sql1);
+
+ $this->db->query($sql1, __LINE__, __FILE__);
+
+
$my_new_version_id=$new_element_id=$this->db->get_last_insert_id($this->tables['versions'],
'version_id');
+
+ $this->db->unlock();
+
+ $this->store_history ('new version',
$this->cleanstr($new_version['description']), $my_new_version_id);
+
+ }
+
+ // AJOUT des relations
+ if ( is_array($new_version['relations']))
+ {
+ foreach ( $new_version['relations'] as $relation )
{
- $i ++;
- $candidate_name="v".$i."_".$basename;
- }
-
- $new_name=$this->datadir."/".$candidate_name;
-
- if (move_uploaded_file($new_version['file_tmp_name'],
$new_name))
- {
-
- $download_result='OK';
-
- }
- else
- return "PB download";
-
- // MEMO attention que if $new_version['status'] est
current il faut rendre obsol�te la "vieille"
-
- if ($download_result=='OK')
- {
-
- $sql_model1="INSERT INTO %s ( size, file_name,
stored_name, file_extension, creator_id, creation_date, status, element_id,
description, major, minor ) VALUES ";
- $sql_model1.=" ( %d, '%s', '%s', '%s', %d, %d,
'%s', %d, '%s', %d, %d ) ";
-
- $sql1=sprintf($sql_model1,
$this->tables['versions'], $new_version['file_size'],
addslashes($new_version['file_name']), addslashes($candidate_name), $extension,
$GLOBALS['phpgw_info']['user']['account_id'], time(), 'working',
$new_version['element_id'], $this->cleanstr($new_version['description']),
$major, $minor);
-
- //print ("<br/>".$sql1);
-
- $this->db->query($sql1, __LINE__, __FILE__);
-
-
$my_new_version_id=$new_element_id=$this->db->get_last_insert_id($this->tables['versions'],
'version_id');
-
+ $sql3="INSERT INTO ged_relations (
linked_version_id, linking_version_id, relation_type) values (
".$relation['linked_version_id'].",".$my_new_version_id.",'".$relation['relation_type']."'
);";
+ $this->db->query($sql3, __LINE__, __FILE__);
$this->db->unlock();
-
- $this->store_history ('new version',
$this->cleanstr($new_version['description']), $my_new_version_id);
-
}
-
- // AJOUT des relations
- if ( is_array($new_version['relations']))
- {
- foreach ( $new_version['relations'] as
$relation )
- {
- $sql3="INSERT INTO ged_relations (
linked_version_id, linking_version_id, relation_type) values (
".$relation['linked_version_id'].",".$my_new_version_id.",'".$relation['relation_type']."'
);";
- $this->db->query($sql3, __LINE__,
__FILE__);
- $this->db->unlock();
- }
- }
-
- if ( $this->debug('add_version') )
- print ( "add_version: end.<br>\n");
-
- return "OK";
+ }
+
+ if ( $this->debug('add_version') )
+ print ( "add_version: end.<br>\n");
+ return "OK";
+
}
function update_version($amended_version)
@@ -513,13 +535,13 @@
$me_version=$this->get_version_info($amended_version['version_id']);
$first_version=$this->get_first_version($amended_version['element_id']);
-
+
// MEMO gestion des numeros de versions
$major=$amended_version['major'];
$minor=$amended_version['minor'];
-
+
if ( $me_version['version_id'] != $first_version['version_id'] )
- {
+ {
$previous_version=$this->get_previous_version($amended_version['version_id']);
@@ -528,84 +550,84 @@
//die();
if ( $major < $previous_version['major'] || ($major ==
$previous_version['major'] && $minor <= $previous_version['minor']))
- {
+ {
$major=$previous_version['major'];
$minor=$previous_version['minor']+1;
- }
}
+ }
+
+ // MEMO gestion du stored_name pour eviter les ecrasements.
- // MEMO gestion du stored_name pour eviter les ecrasements.
-
- if ($amended_version['file_name'] !="")
+ if ($amended_version['file_name'] !="")
+ {
+
+ $old_name=$this->datadir."/".$me_version['stored_name'];
+
+ if (!unlink($old_name))
+ return ("cannot erase old file");
+
+ $basename=basename($amended_version['file_name']);
+ $candidate_name=$basename;
+
+ $extension=$this->get_file_extention($basename);
+
+ $i=0;
+
+ while (file_exists($this->datadir."/".$candidate_name))
{
-
-
$old_name=$this->datadir."/".$me_version['stored_name'];
-
- if (!unlink($old_name))
- return ("cannot erase old file");
-
-
$basename=basename($amended_version['file_name']);
- $candidate_name=$basename;
-
- $extension=$this->get_file_extention($basename);
-
- $i=0;
-
- while
(file_exists($this->datadir."/".$candidate_name))
- {
- $i ++;
- $candidate_name="v".$i."_".$basename;
- }
-
- $new_name=$this->datadir."/".$candidate_name;
-
- if
(move_uploaded_file($amended_version['file_tmp_name'], $new_name))
- {
- $download_result='OK';
- }
- else
- {
- $download_result='';
- return "PB download";
- }
+ $i ++;
+ $candidate_name="v".$i."_".$basename;
}
- else
- $download_result='';
-
- // MEMO attention que if $new_version['status'] est
current il faut rendre obsol�te la "vieille"
-
- if ($download_result=='OK')
+
+ $new_name=$this->datadir."/".$candidate_name;
+
+ if
(move_uploaded_file($amended_version['file_tmp_name'], $new_name))
{
- $sql_model1="UPDATE %s set size=%d,
file_name='%s', stored_name='%s', file_extension='%s', ";
- $sql_model1.="status='%s', description='%s',
major=%d, minor=%d ";
- $sql_model1.="WHERE version_id=%d";
-
- $sql1=sprintf($sql_model1, $this->tables['versions'],
$amended_version['file_size'], $amended_version['file_name'],
$this->cleanstr($candidate_name), $extension, $me_version['status'],
$this->cleanstr($amended_version['description']), $major, $minor,
$amended_version['version_id']);
+ $download_result='OK';
}
else
{
- $sql_model1="UPDATE %s set ";
- $sql_model1.="status='%s', description='%s',
major=%d, minor=%d ";
- $sql_model1.="WHERE version_id=%d";
-
- $sql1=sprintf($sql_model1, $this->tables['versions'],
$me_version['status'], $this->cleanstr($amended_version['description']),
$major, $minor, $amended_version['version_id']);
+ $download_result='';
+ return "PB download";
}
-
- $this->db->query($sql1, __LINE__, __FILE__);
- $this->db->unlock();
-
- //$this->store_history ('updated',
$amended_version['description'], $amended_version['version_id']);
-
- // Gestion des relations
- if ( is_array($amended_version['relations']))
- {
-
$this->set_relations($amended_version['version_id'],$amended_version['relations']);
- }
- else
- {
-
$this->erase_relations($amended_version['version_id']);
- }
+ }
+ else
+ $download_result='';
+ // MEMO attention que if $new_version['status'] est current il
faut rendre obsol�te la "vieille"
+
+ if ($download_result=='OK')
+ {
+ $sql_model1="UPDATE %s set size=%d, file_name='%s',
stored_name='%s', file_extension='%s', ";
+ $sql_model1.="status='%s', description='%s', major=%d,
minor=%d ";
+ $sql_model1.="WHERE version_id=%d";
+
+ $sql1=sprintf($sql_model1, $this->tables['versions'],
$amended_version['file_size'], $amended_version['file_name'],
$this->cleanstr($candidate_name), $extension, $me_version['status'],
$this->cleanstr($amended_version['description']), $major, $minor,
$amended_version['version_id']);
+ }
+ else
+ {
+ $sql_model1="UPDATE %s set ";
+ $sql_model1.="status='%s', description='%s', major=%d,
minor=%d ";
+ $sql_model1.="WHERE version_id=%d";
+
+ $sql1=sprintf($sql_model1, $this->tables['versions'],
$me_version['status'], $this->cleanstr($amended_version['description']),
$major, $minor, $amended_version['version_id']);
+ }
+
+ $this->db->query($sql1, __LINE__, __FILE__);
+ $this->db->unlock();
+
+ //$this->store_history ('updated',
$amended_version['description'], $amended_version['version_id']);
+
+ // Gestion des relations
+ if ( is_array($amended_version['relations']))
+ {
+
$this->set_relations($amended_version['version_id'],$amended_version['relations']);
+ }
+ else
+ {
+ $this->erase_relations($amended_version['version_id']);
+ }
+
return "OK";
}
@@ -743,7 +765,7 @@
}
else
$out="";
-
+
if ($element_id == 0)
{
$out['element_id']=$element_id;
@@ -858,7 +880,7 @@
{
if ( $this->debug('get_last_version') )
print ( "get_last_version: entering with
element_id=".$element_id."<br>\n");
-
+
if ( ! $this->can_read($element_id))
die("argh 2 : cannot read ".$element_id);
@@ -959,7 +981,7 @@
$version['mime_type']=$this->get_mime_type($version['file_extension']);
return $version;
-
+
}
function get_current_version($element_id)
@@ -1566,31 +1588,31 @@
{
$result=true;
}
-
+
return ($result );
}
function can_write($element_id)
{
$result=false;
-
+
if ( (isset($this->acl[$element_id]) &&
$this->acl[$element_id]['write'] == 1) || $this->admin == true )
{
$result=true;
}
-
+
return ($result );
}
-
+
function can_change_acl($element_id)
{
$result=false;
-
+
if ( (isset($this->acl[$element_id]) &&
$this->acl[$element_id]['changeacl'] == 1) || $this->admin == true )
{
$result=true;
}
-
+
return ($result );
}
@@ -1613,15 +1635,15 @@
if ( ! $this->can_read($parent_id))
die("argh 4");
- $sql="SELECT * FROM ".$this->tables['elements']." ";
- $sql.="WHERE parent_id=".$parent_id." ";
- $sql.="AND element_id !=parent_id ";
- if ($type !="" )
- $sql.="AND type='".$type."'";
- $sql.="ORDER by type desc, name asc";
+ $sql="SELECT * FROM ".$this->tables['elements']." ";
+ $sql.="WHERE parent_id=".$parent_id." ";
+ $sql.="AND element_id !=parent_id ";
+ if ($type !="" )
+ $sql.="AND type='".$type."'";
+ $sql.="ORDER by type desc, name asc";
+
+ $this->db->query($sql, __LINE__, __FILE__);
- $this->db->query($sql, __LINE__, __FILE__);
-
//print ( $sql );
$elements=Array();
@@ -1632,23 +1654,23 @@
$the_element_id=$this->db->f('element_id');
$the_element_type=$this->db->f('type');
$go=false;
-
+
if ( ! $this->can_read($the_element_id) )
{
$go=false;
}
elseif ( $the_element_type == "folder" )
+ {
+ $go=true;
+ }
+ elseif ( $the_element_type == "file" )
+ {
+ if ( $this->can_write($the_element_id) )
{
$go=true;
}
- elseif ( $the_element_type == "file" )
+ else
{
- if ( $this->can_write($the_element_id) )
- {
- $go=true;
- }
- else
- {
$the_version_statuses=$this->get_versions_statuses($the_element_id);
//DEBUG
@@ -1661,13 +1683,13 @@
if (
in_array($granted_status,$the_version_statuses))
{
$go=true;
+ }
+ }
}
- }
- }
else
- {
- $go=true;
- }
+ {
+ $go=true;
+ }
}
}
@@ -1703,23 +1725,23 @@
function list_versions($element_id)
{
$versions=null;
-
+
if ( ! $this->can_read($element_id))
die("argh 5");
-
- if ( $this->debug('list_version') )
+
+ if ( $this->debug('list_version') )
echo "list_versions: entering with
element_id=".$element_id."<br/>\n";
- $sql1="SELECT ALL ";
- $sql1.="version_id, element_id, description,
creation_date, ";
- $sql1.="status, major, minor, size, ";
- $sql1.="creator_id, validation_date, file_extension, ";
- $sql1.="file_name, stored_name ";
-
- $sql1.="FROM ".$this->tables['versions']." ";
- $sql1.="WHERE element_id=".$element_id." ";
- $sql1.="ORDER BY version_id ";
+ $sql1="SELECT ALL ";
+ $sql1.="version_id, element_id, description, creation_date, ";
+ $sql1.="status, major, minor, size, ";
+ $sql1.="creator_id, validation_date, file_extension, ";
+ $sql1.="file_name, stored_name ";
+ $sql1.="FROM ".$this->tables['versions']." ";
+ $sql1.="WHERE element_id=".$element_id." ";
+ $sql1.="ORDER BY version_id ";
+
if ( $this->debug('list_version') )
print ("list_versions: SQL ".$sql1."<br/>\n");
@@ -1733,10 +1755,10 @@
{
$the_version_id=$this->db->f('version_id');
$the_status=$this->db->f('status');
-
+
if ( $this->debug('list_version') )
print ("list_versions: parsing version
".$the_version_id."<br/>\n");
-
+
//DEBUG
//print ( $the_status);
//_debug_array($this->acl[$element_id]);
@@ -1970,7 +1992,7 @@
//print ( "<br/>");
$element_acl=$this->get_element_acl ( $element_id );
-
+
if ( isset($element_acl[$account_id]) &&
is_array($element_acl[$account_id]) )
{
//print ( "<pre>");
@@ -2020,7 +2042,7 @@
$aclread="null";
else
$aclread=1;
-
+
if (empty($aclstatuses) || $aclstatuses=="null" )
$sql_aclstatuses="NULL";
elseif(is_array($aclstatuses))
@@ -2036,7 +2058,7 @@
$aclread=1;
$aclwrite=1;
}
-
+
if ($acldelete=="" || $acldelete=="null")
$acldelete="null";
else
@@ -2068,7 +2090,7 @@
if (
is_array($child_element_acl_for_account) )
{
$this->set_acl($child_element_acl_for_account['acl_id'], $aclread,
$aclstatuses, $aclwrite, $acldelete, $aclchangeacl, true, false);
-
}
+ }
else
{
$this->new_acl($child_element['element_id'], $account_id, $aclread,
$aclstatuses, $aclwrite, $acldelete, $aclchangeacl, true, false);
@@ -2104,16 +2126,16 @@
// Full droits au createur (presque huhu)
// Heritage des droits du parent
function set_default_acl($element_id)
- {
+ {
//ihnerit acl from parent
$parent_id=$this->get_parent_id($element_id);
$parent_acl=$this->get_element_acl ( $parent_id );
if ( is_array($parent_acl))
- foreach ( $parent_acl as $ac )
- {
+ foreach ( $parent_acl as $ac )
+ {
$this->new_acl($element_id, $ac['account_id'],
$ac['read'], $ac['statuses'], $ac['write'], $ac['delete'], $ac['changeacl']);
- }
+ }
}
function set_acl($acl_id, $aclread, $aclstatuses, $aclwrite,
$acldelete, $aclchangeacl, $recursive=false, $check_read_on_path=true)
@@ -2600,7 +2622,7 @@
$element_id=$this->db->f('element_id');
$version_id=$this->db->f('version_id');
$version_status=$this->db->f('status');
-
+
if ( $this->can_read($element_id) )
{
if ( !
isset($this->acl[$element_id]['statuses']) )
@@ -2621,18 +2643,18 @@
}
if ( $go==true )
- {
- $docs[$i]['element_id']=$element_id;
- $docs[$i]['name']=$this->db->f('name');
- $docs[$i]['status']=$version_status;
-
$docs[$i]['reference']=$this->db->f('reference');
- $docs[$i]['minor']=$this->db->f('minor');
- $docs[$i]['major']=$this->db->f('major');
-
$docs[$i]['description']=$this->db->f('description');
- $i ++;
+ {
+ $docs[$i]['element_id']=$element_id;
+ $docs[$i]['name']=$this->db->f('name');
+ $docs[$i]['status']=$version_status;
+
$docs[$i]['reference']=$this->db->f('reference');
+
$docs[$i]['minor']=$this->db->f('minor');
+
$docs[$i]['major']=$this->db->f('major');
+
$docs[$i]['description']=$this->db->f('description');
+ $i ++;
+ }
}
}
- }
$this->db->unlock();
@@ -2819,36 +2841,36 @@
$sql="SELECT ".$this->tables['history'].".*,
".$this->tables['versions'].".status finalstatus,
".$this->tables['versions'].".major, ".$this->tables['versions'].".minor FROM
".$this->tables['history']." INNER JOIN ".$this->tables['versions']." ";
$sql.="ON ".$this->tables['history'].".version_id =
".$this->tables['versions'].".version_id ";
$sql.="WHERE
".$this->tables['history'].".element_id=".$element_id." ";
- $sql.="ORDER BY ".$this->tables['history'].".logdate
ASC";
-
- $this->db->query($sql);
-
- $i=0;
- while ($this->db->next_record())
- {
+ $sql.="ORDER BY ".$this->tables['history'].".logdate
ASC";
+
+ $this->db->query($sql);
+
+ $i=0;
+ while ($this->db->next_record())
+ {
$finalstatus=$this->db->f('finalstatus');
$status=$this->db->f('status');
if ( empty($this->acl[$element_id]['statuses'])
|| (in_array($finalstatus,$this->acl[$element_id]['statuses']) &&
in_array($status,$this->acl[$element_id]['statuses'])))
{
- $history[$i]['element_id']=$element_id;
- $history[$i]['version_id']=$this->db->f('version_id');
+ $history[$i]['element_id']=$element_id;
+
$history[$i]['version_id']=$this->db->f('version_id');
$history[$i]['status']=$status;
- $history[$i]['logdate']=$this->db->f('logdate');
- $history[$i]['action']=$this->db->f('action');
- $history[$i]['account_id']=$this->db->f('account_id');
- $history[$i]['comment']=$this->db->f('comment');
- $history[$i]['ip']=$this->db->f('ip');
- $history[$i]['agent']=$this->db->f('agent');
- $history[$i]['major']=$this->db->f('major');
- $history[$i]['minor']=$this->db->f('minor');
-
- $i++;
+
$history[$i]['logdate']=$this->db->f('logdate');
+
$history[$i]['action']=$this->db->f('action');
+
$history[$i]['account_id']=$this->db->f('account_id');
+
$history[$i]['comment']=$this->db->f('comment');
+ $history[$i]['ip']=$this->db->f('ip');
+
$history[$i]['agent']=$this->db->f('agent');
+
$history[$i]['major']=$this->db->f('major');
+
$history[$i]['minor']=$this->db->f('minor');
+
+ $i++;
}
+ }
+
+ $this->db->unlock();
}
-
- $this->db->unlock();
- }
if ( isset($history))
return ($history);
else
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] [18386] acl now using an array computed just once,
Pascal Vilarem <=