Code

Updated listing classes
[gosa.git] / gosa-core / include / class_listing.inc
index 95a7290193c27c2b787e481ebb6c889bdeb51ba0..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();
@@ -848,11 +872,11 @@ function getObjectType($types, $classes)
         foreach ($ocs as $oc){
             if (preg_match('/^!(.*)$/', $oc, $match)) {
                 $oc= $match[1];
-                if (in_array($oc, $classes)) {
+                if (in_array_strict($oc, $classes)) {
                     $found= false;
                 }
             } else {
-                if (!in_array($oc, $classes)) {
+                if (!in_array_strict($oc, $classes)) {
                     $found= false;
                 }
             }
@@ -932,12 +956,12 @@ function filterActions($dn, $row, $classes)
             $objectclass= $action['objectclass'];
             if (preg_match('/^!(.*)$/', $objectclass, $m)){
                 $objectclass= $m[1];
-                if(in_array($objectclass, $classes)) {
+                if(in_array_strict($objectclass, $classes)) {
                     $result.= image('images/empty.png');
                     continue;
                 }
             } elseif (is_string($objectclass)) {
-                if(!in_array($objectclass, $classes)) {
+                if(!in_array_strict($objectclass, $classes)) {
                     $result.= image('images/empty.png');
                     continue;
                 }
@@ -998,7 +1022,14 @@ function filterLink()
 
     $row= func_get_arg(0);
     $pid= $this->pid;
-    $dn= LDAP::fix(func_get_arg(1));
+
+    // Prepare title attribute
+    $titleAttr = func_get_arg(1);
+    if(is_array($titleAttr) && isset($titleAttr[0])){
+        $titleAttr = $titleAttr[0];
+    }
+    $titleAttr = LDAP::fix($titleAttr);
+
     $params= array(func_get_arg(2));
 
     // Collect sprintf params
@@ -1014,7 +1045,7 @@ function filterLink()
     $result= "&nbsp;";
     $trans= call_user_func_array("sprintf", $params);
     if ($trans != "") {
-        return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='$dn'>".set_post($trans)."</a>");
+        return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_edit_$row' title='{$titleAttr}'>".set_post($trans)."</a>");
     }
 
     return $result;
@@ -1396,14 +1427,14 @@ function getDepartments()
 
     // Analyze list of departments
     foreach ($res as $department) {
-        if (!in_array($department['dn'], $validDepartments)) {
+        if (!in_array_strict($department['dn'], $validDepartments)) {
             continue;
         }
 
         // Add the attribute where we use for sorting
         $oc= null;
         foreach(array_keys($types) as $type) {
-            if (in_array($type, $department['objectClass'])) {
+            if (in_array_strict($type, $department['objectClass'])) {
                 $oc= $type;
                 break;
             }