Code

Added acl filter to environment printer
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 6 Nov 2006 11:23:49 +0000 (11:23 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 6 Nov 2006 11:23:49 +0000 (11:23 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5017 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/personal/environment/class_selectPrinterDialog.inc

index 2400b2857909eb1b3fd9a89f33406f0c94de54d8..9b17dca8e99b4f85581fae1e937a37feba416878 100644 (file)
@@ -14,13 +14,45 @@ class selectPrinterDialog extends plugin
   var $AlreadyAssigned      = array();  
   var $regex                = "*";
   var $depselect            = "/";
-  var $deplist              = "/";
+  var $deplist              = array("/");
+  var $module               = array("printer");
+  var $ui                   = NULL;
 
   function selectPrinterDialog ($config, $dn= NULL,$alreadyused=array() )
   {
     $this->AlreadyAssigned = $alreadyused;
     plugin::plugin ($config, $dn);
-    $this->depselect = $this->config->current['BASE'];
+
+    /* Get all departments within this subtree */
+    $base = $this->config->current['BASE'];
+    $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
+                    array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
+
+    $tmp =array();
+    foreach($deps as $dep){
+      $tmp[$dep['dn']] = $dep;
+    }
+    $deps = $tmp;
+
+    /* Load possible departments */
+    $this->ui= get_userinfo();
+    $department = array();
+    foreach($this->module as $module){
+
+      $d = $this->ui->get_module_departments($module);
+      foreach($d as $department){
+        $departments[$department] = $department;
+      }
+    }
+    $ids = $this->config->idepartments;
+    $this->deplist = array();
+    foreach($deps as $dep){
+      if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $departments)){
+        $this->deplist[$dep['dn']] =  $ids[$dep['dn']];
+      }
+    }
+
+    $this->depselect = key($this->deplist);
   }
 
   function execute()
@@ -33,8 +65,11 @@ class selectPrinterDialog extends plugin
     $display= "";
 
     if(isset($_POST['dialogissubmitted'])){
-      $this->regex=$_POST['regexPrinter'];
-      $this->depselect = $_POST['depselectPrinter'];
+      foreach(array('regexPrinter' => 'regex','depselectPrinter'=>'depselect') as $attr => $name){
+        if(isset($_POST[$attr])){
+          $this->$name      =$_POST[$attr];
+        }
+      }
     }
 
     if((isset($_GET['search']))&&(!empty($_GET['search']))){
@@ -42,8 +77,6 @@ class selectPrinterDialog extends plugin
       $this->regex=preg_replace("/\*\*/","*",$this->regex);
     }
 
-    $this->deplist=$this->config->idepartments;
-
     $smarty->assign("regexPrinter"    ,$this->regex);
     $smarty->assign("deplistPrinter"  ,$this->deplist);
     $smarty->assign("depselectPrinter",$this->depselect);
@@ -83,10 +116,20 @@ class selectPrinterDialog extends plugin
   function getPrinter($detailed = false)
   {
     $a_return=array();
-    $ldap = $this->config->get_ldap_link();
-    $ldap->cd($this->depselect);
-    $ldap->search("(&(objectClass=gotoPrinter)(cn=".$this->regex."))",array("*"));
-    while($printer = $ldap->fetch()){
+
+
+    $filter = "(&(objectClass=gotoPrinter)(cn=".$this->regex."))";
+    $module = $this->module;
+    $base   = $this->depselect;
+    $attrs  = array("cn","description");
+    $res    = get_list($filter,$module,$base,$attrs);
+
+    foreach($res as $printer)  {
+
+      $acl = $this->ui->get_permissions($printer['dn'],"printer","gotoUserPrinter");
+      if(!preg_match("/w/",$acl)){
+        continue;
+      }
 
       if(isset($this->AlreadyAssigned[$printer['cn'][0]])) continue;