Code

Updated listing classes
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 15 Sep 2011 07:52:48 +0000 (07:52 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 15 Sep 2011 07:52:48 +0000 (07:52 +0000)
Backports from 2.7

git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.7@20984 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/include/class_ItemSelector.inc
gosa-core/include/class_listing.inc
gosa-core/include/class_sortableListing.inc

index f3eca46910af2515bac978b4e09c88a33c43b767..4b7d180b78dbe03916c2d17d4410389d20b1b476 100644 (file)
@@ -117,7 +117,7 @@ class ItemSelector {
         foreach ($bases as $path => $data) {
 
             // Build path style display
-            $this->pathMapping[$path]= $path == $this->releaseBase? '/' : $data['name'];
+            $this->pathMapping[$path]= preg_replace("/^".preg_quote($this->releaseBase,'/')."\/?/i", "/", $path);
             $this->releaseInfo[$path]['name'] = $data['name'];
             $this->releaseInfo[$path]['description'] = $data['desc'];
         }
@@ -138,13 +138,14 @@ class ItemSelector {
         if(isset($_REQUEST["BPID_{$this->pid}"]) && $_REQUEST["BPID_{$this->pid}"] == $this->pid) {
             if (isset($_POST['bs_rebase_'.$this->pid])) {
                 $new_base= base64_decode(get_post('bs_rebase_'.$this->pid));
-
-                if (isset($this->pathMapping[$new_base])) {
-                    $this->base= $new_base;
-                    $this->action= 'rebase';
-                } else {
-                    $this->lastState= false;
-                    return false;
+                if($new_base){
+                    if (isset($this->pathMapping[$new_base])) {
+                        $this->base= $new_base;
+                        $this->action= 'rebase';
+                    } else {
+                        $this->lastState= false;
+                        return false;
+                    }
                 }
             }else{
                 // Input field set?
@@ -234,6 +235,7 @@ class ItemSelector {
                     });";
         }
         $this->tree.= "</script>";
+        $selected= $this->base == $this->releaseBase?"Selected":"";
         $this->tree.= "<div class='treeList' 
                             style=' display:none;
                                     max-height:".$this->height."px' 
@@ -242,17 +244,25 @@ class ItemSelector {
                                     window.clearTimeout(rtimer);\" 
                             onmouseout=\"
                                     rtimer= Element.hide.delay(0.25, 'bs_".$this->pid."')\">
+                        <a                     class='treeList$selected' $link>/&nbsp;["._("Root")."]</a>
                         <ul class='treeList'>\n";
 
         $first= true;
         $last_indent= 1;
 
+        $baseDepth = 0;
         foreach ($this->pathMapping as $base => $dummy) {
 
+            // Do not render the base element
+            if($base == $this->releaseBase){
+                $baseDepth = 1;
+                continue;
+            }
+
             // Build path style display
             $elements= explode('/', substr($base, strlen($this->releaseBase), strlen($base)));
-            $indent= count($elements) ;
-      
+            $indent= count($elements) - $baseDepth ;
+        
             if (!$first && ($indent == $last_indent)) {
                 $this->tree.= "</li>\n";
             }
index 4e3ef82ccb5edec0f9cefdaa96587e9719a52eb9..5f04cdf3171a7afaec3a68837a978771564a0ba6 100644 (file)
@@ -29,6 +29,7 @@ class listing {
     var $departmentRootVisible= false;
     var $multiSelect= false;
     var $singleSelect= false;
+    var $noAclChecks= false;
     var $template;
     var $headline;
     var $base;
@@ -55,7 +56,7 @@ class listing {
     var $height= 0;
     var $scrollPosition= 0;
     var $baseSelector;
-
+    var $aclToObjectClass = array();
 
     function listing($source, $isString = FALSE)
     {
@@ -170,7 +171,7 @@ class listing {
         $this->xmlData= $this->xmlData["list"];
 
         // Load some definition values
-        foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect","singleSelect", "baseMode") as $token) {
+        foreach (array("departmentBrowser", "departmentRootVisible", "multiSelect","singleSelect", "baseMode", "noAclChecks") as $token) {
             if (isset($this->xmlData['definition'][$token]) &&
                     $this->xmlData['definition'][$token] == "true"){
                 $this->$token= true;
@@ -194,6 +195,10 @@ class listing {
                 $this->objectTypes[$tmp['objectClass']]= $tmp;
                 if (isset($this->xmlData['definition']['objectType'][$index]['category'])){
                     $this->categories[]= $otype['category'];
+
+                    if(isset($otype['category']) && isset($otype['class'])){
+                        $this->aclToObjectClass[$otype['category']."/".$otype['class']][] = $otype['objectClass'];
+                    }
                 }
             }
         }
@@ -302,7 +307,7 @@ class listing {
             $height= $this->height;
         }
 
-        $result.= "<div class='listContainer' id='d_scrollbody' style='min-height:".($height+25)."px;'>\n";
+        $result.= "<div class='listContainer' id='d_scrollbody' style='height:{$height}px; overflow: auto;min-height:".($height+25)."px;'>\n";
         $result.= "<table summary='$this->headline' style='width:100%;table-layout:fixed' cellspacing='0' cellpadding='0' id='t_scrolltable'>\n";
         $this->numColumns= count($this->colprops) + (($this->multiSelect|$this->singleSelect)?1:0);
 
@@ -385,6 +390,7 @@ class listing {
         }
 
         // Fill with contents, sort as configured
+        $ui = get_userinfo();
         foreach ($this->entries as $row => $entry) {
             $trow= "";
 
@@ -647,6 +653,24 @@ class listing {
         $this->filter->setBase($this->base);
         $this->entries= $this->filter->query();
 
+        // Check entry acls
+        if(!$this->noAclChecks){
+            foreach($this->entries as $row => $entry){
+                $acl = "";
+                $found = false;
+                foreach($this->aclToObjectClass as $category => $ocs){
+                    if(count(array_intersect($ocs, $entry['objectClass']))){
+                        $acl .= $ui->get_permissions($entry['dn'],$category, 0);
+                        $found = true;
+                    }
+                }
+                if(!preg_match("/r/", $acl) && $found){
+                    unset($this->entries[$row]);
+                    continue;
+                }
+            }
+        }
+
         // Fix filter if querie returns NULL
         if ($this->entries == null) {
             $this->entries= array();
index df89b48217e8e38d4b139b03233c2458e9789490..e6632b147c03dd1fdf35177fd269a39a2614f052 100644 (file)
@@ -54,7 +54,7 @@ class sortableListing {
     private $acl= "";
     private $modified= false;
 
-       
+
     public function sortableListing($data= array(), $displayData= null, $reorderable= false)
     {
         global $config;
@@ -101,17 +101,17 @@ class sortableListing {
         $this->sortColumn = $id;
     }
 
-       /*
-       
-       * Examples
-       * DatenARray ($data)
-       * @param: array( arbitrary object, arbitrary object)
-       * Datenarray will be manipulated by add, del and sort operations. According to this it will be returned from this widget.
-       * The index of a data entry must correspond to the entry of the "display array" following.
-       * DisplayArray ($displyData)
-       * @param: array("eins" array( "data"=> array("Uno", "2", "x" ) , "zwei" array( "data"=> array("Due", "3", "y" ))) ;
-       * label pointing on a list of columns that will be shown in the list.
-       */
+    /*
+     * 
+     * Examples
+     * DatenARray ($data)
+     * @param: array( arbitrary object, arbitrary object)
+     * Datenarray will be manipulated by add, del and sort operations. According to this it will be returned from this widget.
+     * The index of a data entry must correspond to the entry of the "display array" following.
+     * DisplayArray ($displyData)
+     * @param: array("eins" array( "data"=> array("Uno", "2", "x" ) , "zwei" array( "data"=> array("Due", "3", "y" ))) ;
+     * label pointing on a list of columns that will be shown in the list.
+     */
     public function setListData($data, $displayData= null)
     {
         // Save data to display
@@ -125,13 +125,13 @@ class sortableListing {
         $this->setDisplayData($displayData);
     }
 
-       //setting flat data 
+    //setting flat data 
     private function setData($data)
     {
         $this->data= $data;
     }
 
-       // collecting the display data -
+    // collecting the display data -
     private function setDisplayData($data)
     {
         if (!is_array($data)) {
@@ -229,7 +229,7 @@ class sortableListing {
 
 
     public function render()
-    {
+    {  
         $result= "<div class='sortableListContainer' id='scroll_".$this->id."' style='min-width:".$this->width.";height: ".$this->height."'>\n";
         $result.= "<table summary='"._("Sortable list")."' border='0' cellpadding='0' cellspacing='0' width='100%' style='width:100%' ".(!empty($this->cssclass)?" class='".$this->cssclass."'":"").">\n";
         $action_width= 0;
@@ -290,6 +290,7 @@ class sortableListing {
         // Render table body if we've read permission
         $result.= " <tbody id='".$this->id."'>\n";
         $reorderable= $this->reorderable?"":" style='cursor:default'";
+
         if (strpos($this->acl, 'r') !== false) {
             foreach ($this->mapping as $nr => $row) {
                 $editable= $this->editable?" onClick='$(\"edit_".$this->id."_$nr\").click()'":"";
@@ -426,6 +427,10 @@ class sortableListing {
             foreach ($_POST as $key => $value) {
                 $value = get_post($key);
                 if (preg_match('/^del_'.$this->id.'_([0-9]+)$/', $key, $matches)) {
+
+
+                    if(!isset($this->mapping[$matches[1]])) return;
+
                     $this->active_index= $this->mapping[$matches[1]];
 
                     // Ignore request if mode requests it
@@ -450,6 +455,9 @@ class sortableListing {
             foreach ($_POST as $key => $value) {
                 $value = get_post($key);
                 if (preg_match('/^edit_'.$this->id.'_([0-9]+)$/', $key, $matches)) {
+
+                    if(!isset($this->mapping[$matches[1]])) return;
+
                     $this->active_index= $this->mapping[$matches[1]];
 
                     // Ignore request if mode requests it
@@ -484,12 +492,20 @@ class sortableListing {
     }
 
 
-    private function deleteEntry($id)
+    public function deleteEntry($id)
     {
         // Remove mapping
         $index= array_search($id, $this->mapping);
         if ($index !== false) {
+            $target = $this->mapping[$index];
+            $key = $this->keys[$target];
+
             unset($this->mapping[$index]);
+            if(isset($this->displayData[$target])){
+                unset($this->displayData[$target]);
+                unset($this->data[$key]);
+                unset($this->keys[$target]);
+            }
             $this->mapping= array_values($this->mapping);
             $this->modified= true;
         }
@@ -531,11 +547,11 @@ class sortableListing {
 
         // Extract data
         $tmp= array();
-        foreach($this->displayData as $item) {
+        foreach($this->displayData as $key => $item) {
             if (isset($item[$this->sortColumn])){
-                $tmp[]= $item[$this->sortColumn];
+                $tmp[$key]= $item[$this->sortColumn];
             } else {
-                $tmp[]= "";
+                $tmp[$key]= "";
             }
         }
 
@@ -573,17 +589,16 @@ class sortableListing {
         }
 
         // Append to data and mapping
+        $this->displayData[]= $displayEntry['data'];
+        $this->mapping[]= max(array_keys($this->displayData));
+        $this->modified= true;
         if ($key) {
             $this->data[$key]= $entry;
             $this->keys[]= $key;
         } else {
             $this->data[]= $entry;
-            $this->keys[]= count($this->mapping);
+            $this->keys[]= max(array_keys($this->displayData));
         }
-        $this->displayData[]= $displayEntry['data'];
-        $this->mapping[]= count($this->mapping);
-        $this->modified= true;
-
         // Find the number of coluns
         reset($this->displayData);
         $first= current($this->displayData);