From 7b6cc3fcd2298d95bb246f950561efa69af62c7c Mon Sep 17 00:00:00 2001 From: cajus Date: Mon, 18 Jan 2010 16:43:10 +0000 Subject: [PATCH] Added data maintainance to sortable lists Added ACL git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@15184 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/class_sortableListing.inc | 104 +++++++++++++++----- 1 file changed, 82 insertions(+), 22 deletions(-) diff --git a/gosa-core/include/class_sortableListing.inc b/gosa-core/include/class_sortableListing.inc index b87136c61..9ea6d40ee 100644 --- a/gosa-core/include/class_sortableListing.inc +++ b/gosa-core/include/class_sortableListing.inc @@ -30,6 +30,7 @@ class sortableListing { private $id; private $data= array(); + private $displayData= array(); private $columns= 0; private $deleteable= false; private $editable= false; @@ -40,12 +41,23 @@ class sortableListing { private $current_mapping; private $active_index; - function sortableListing($data= array()) + private $acl= ""; + private $modified= false; + + function sortableListing($data= array(), $displayData= null) { global $config; // Save data to display $this->setData($data); + if (!$displayData) { + $displayData= array(); + foreach ($data as $value) { + $displayData[]= array($value); + } + } else { + $this->setDisplayData($displayData); + } // Generate instance wide unique ID $tmp= gettimeofday(); @@ -54,20 +66,27 @@ class sortableListing { function setData($data) + { + $this->data= $data; + } + + + function setDisplayData($data) { if (!is_array($data)) { die ("sortableList needs an array as data!"); } // Transfer information - $this->data= $data; + $this->displayData= $data; // Create initial mapping $this->mapping= array_keys($data); + $this->current_mapping= $this->mapping; // Find the number of coluns - reset($this->data); - $first= current($this->data); + reset($this->displayData); + $first= current($this->displayData); if (is_array($first)) { $this->columns= count($first); } else { @@ -129,8 +148,16 @@ class sortableListing { $result= "
\n"; $result.= "cssclass)?" class='".$this->cssclass."'":"").">\n"; $action_width= 0; - $edit_image= $this->editable?"":""; - $delete_image= $this->deleteable?"":""; + if (strpos($this->acl, 'w') === false) { + $edit_image= $this->editable?""._("Edit")."":""; + } else { + $edit_image= $this->editable?"":""; + } + if (strpos($this->acl, 'd') === false) { + $delete_image= $this->deleteable?""._("Delete")."":""; + } else { + $delete_image= $this->deleteable?"":""; + } // Do we need colspecs? $action_width= ($this->editable?20:0) + ($this->deleteable?20:0); @@ -159,18 +186,22 @@ class sortableListing { $result.= "\n \n \n"; } - // Render table body + // Render table body if we've read permission $result.= " \n"; - foreach ($this->mapping as $nr => $row) { - $result.= " \n"; - foreach ($this->data[$row] as $column) { - $result.= " \n"; - } - if ($action_width) { - $result.= ""; + if (strpos($this->acl, 'r') !== false) { + foreach ($this->mapping as $nr => $row) { + $result.= " \n"; + foreach ($this->displayData[$row] as $column) { + $result.= " \n"; + } + if ($action_width) { + $result.= ""; + } + $result.= " \n"; } - $result.= " \n"; + } else { + $result.= " \n"; } $result.= " \n
".htmlentities($column)."".str_replace('%ID', "edit_".$this->id."_$nr", $edit_image). - str_replace('%ID', "del_".$this->id."_$nr", $delete_image)."
".htmlentities($column)."".str_replace('%ID', "edit_".$this->id."_$nr", $edit_image). + str_replace('%ID', "del_".$this->id."_$nr", $delete_image)."
\n
\n"; @@ -194,8 +225,8 @@ class sortableListing { function update() { - // Do not do anything if we're not posted - if (isset($_POST['reorder_'.$this->id])){ + // Do not do anything if we're not posted - or have no permission + if (strpos($this->acl, 'w') !== false && isset($_POST['reorder_'.$this->id])){ // Move requested? $move= $_POST['reorder_'.$this->id]; @@ -208,10 +239,13 @@ class sortableListing { } $this->mapping= $tmp; $this->current_mapping= $matches[1]; + $this->modified= true; return; } + } - // Delete requested? + // Delete requested? + if (strpos($this->acl, 'd') !== false){ foreach ($_POST as $key => $value) { if (preg_match('/^del_'.$this->id.'_([0-9]+)_x.*$/', $key, $matches)) { $this->active_index= $this->mapping[$matches[1]]; @@ -221,15 +255,16 @@ class sortableListing { } } } + } - // Edit requested? + // Edit requested? + if (strpos($this->acl, 'w') !== false){ foreach ($_POST as $key => $value) { if (preg_match('/^edit_'.$this->id.'_([0-9]+)_x.*$/', $key, $matches)) { $this->active_index= $this->mapping[$matches[1]]; $this->action= "edit"; } } - } } @@ -255,12 +290,37 @@ class sortableListing { function deleteEntry($id) { + // Remove mapping $index= array_search($id, $this->mapping); if ($index !== false) { unset($this->mapping[$index]); - $this->mappings= array_values($this->mappings); + $this->mapping= array_values($this->mapping); + $this->modified= true; + } + } + + + function getMaintainedData() + { + $tmp= array(); + + foreach ($this->mapping as $src => $dst) { + $tmp[$src]= $this->data[$dst]; } + + return $tmp; } + function isModified() + { + return $this->modified; + } + + + function setAcl($acl) + { + $this->acl= $acl; + } + } -- 2.30.2