Code

Updated an error message. fixed server acl string
[gosa.git] / plugins / admin / systems / class_selectUserToPrinterDialog.inc
index 945d6f6b084c2153bba25746942fe592da37eb55..8f1c8eca2a56ca190b6ee79423b2894097994226 100644 (file)
@@ -18,8 +18,10 @@ class selectUserToPrinterDialog extends plugin
   var $searchObjects        = "";
   var $searchAttrs          = "";
   var $searchAppend         = "";
+  var $baseAddition         = "";
   var $type                 = "";
-  
+  var $search_cat           = ""; 
   function selectUserToPrinterDialog ($config, $dn= NULL,$type=false )
   {
     plugin::plugin ($config, $dn);
@@ -27,24 +29,32 @@ class selectUserToPrinterDialog extends plugin
 
     switch($type){
       case "AddUser" : 
-        $this->searchObjects = "(objectClass=person)(objectClass=inetOrgPerson)";
+        $this->searchObjects = "(objectClass=gosaAccount)(!(uid=*$))";
         $this->searchAttrs   = array("cn","uid");
         $this->searchAppend  = "uid"; 
+        $this->baseAddition  = get_people_ou(); 
+        $this->search_cat    = "users";
           ;break;
       case "AddGroup" :
         $this->searchObjects = "(objectClass=posixGroup)";
         $this->searchAttrs   = array("cn","description");
         $this->searchAppend  = "cn"; 
+        $this->baseAddition  = get_groups_ou(); 
+        $this->search_cat    = "groups";
           ;break;
       case "AddAdminUser" : 
-        $this->searchObjects = "(objectClass=person)(objectClass=inetOrgPerson)";
+        $this->searchObjects = "(objectClass=gosaAccount)(!(uid=*$))";
         $this->searchAttrs   = array("cn","uid");
         $this->searchAppend  = "uid"; 
+        $this->baseAddition  = get_people_ou(); 
+        $this->search_cat    = "users";
           ;break;
       case "AddAdminGroup" :
         $this->searchObjects = "(objectClass=posixGroup)";
         $this->searchAttrs   = array("cn","description");
         $this->searchAppend  = "cn"; 
+        $this->baseAddition  = get_groups_ou(); 
+        $this->search_cat    = "groups";
           ;break;
     }
     $this->type = $type;
@@ -53,6 +63,9 @@ class selectUserToPrinterDialog extends plugin
 
   function execute()
   {
+       /* Call parent execute */
+       plugin::execute();
+
     /* Fill templating stuff */
     $smarty= get_smarty();
     $display= "";
@@ -67,27 +80,62 @@ class selectUserToPrinterDialog extends plugin
       $this->regex=preg_replace("/\*\*/","*",$this->regex);
     }
 
-    $this->deplist=array_flip($this->config->departments);
 
+    /* Get all departments within this subtree */
+    $base = $this->config->current['BASE'];
+    $deps_res= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", array("users","groups"), $this->config->current['BASE'],
+                    array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
+
+    /* Load possible departments */
+    $ui     = get_userinfo();
+  
+    /* Allowed user departments */
+    $udeps  = $ui->get_module_departments("users");
+
+    /* Allowed groups department */
+    $gdeps  = $ui->get_module_departments("groups");
+
+    /* Combine both arrays */
+    $tdeps  = array_unique(array_merge($udeps,$gdeps));
+
+    /* Create usable departments array */
+    $ids = $this->config->idepartments;
+    $deps = array();
+    foreach($deps_res as $dep){
+      if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
+        $value = $ids[$dep['dn']];
+        $deps[$dep['dn']] = $value;
+      }
+    }
+    if(!isset($deps[$this->depselect])){
+      $this->depselect = key($deps);
+    }
+
+
+
+    $tmp_printers= $this->getPrinter();
+    natcasesort($tmp_printers);
     $smarty->assign("regexPrinter"        , $this->regex);
-    $smarty->assign("deplistPrinter"      , $this->deplist);
+    $smarty->assign("deplistPrinter"      , $deps);;//deplist);
     $smarty->assign("depselectPrinter"    , $this->depselect);
-    $smarty->assign("gotoPrinters"        , $this->getPrinter());
-    $smarty->assign("gotoPrinterKeys"     , array_flip($this->getPrinter()));
+    $smarty->assign("gotoPrinters"        , $tmp_printers);
+    $smarty->assign("gotoPrinterKeys"     , array_flip($tmp_printers));
     $smarty->assign("apply"               , apply_filter());
     $smarty->assign("alphabet"            , generate_alphabet());
     $smarty->assign("search_image"        , get_template_path('images/search.png'));
     $smarty->assign("tree_image"          , get_template_path('images/tree.png'));
     $smarty->assign("infoimage"           , get_template_path('images/info.png'));
-    $smarty->assign("launchimage"         , get_template_path('images/launch.png'));
-    $smarty->assign("deplist"             , $this->config->idepartments);
+    $smarty->assign("launchimage"         , get_template_path('images/small_filter.png'));
+    $smarty->assign("deplist"             , $deps);
 
     $display.= $smarty->fetch(get_template_path('selectUserToPrinterDialog.tpl', TRUE,dirname(__FILE__)));
     return($display);
   }
 
   function check(){
-    $message=array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
+
     if(empty($_POST['gotoPrinter'])){
       $message[] = _("Please select a printer or press cancel.");
     }
@@ -112,10 +160,14 @@ class selectUserToPrinterDialog extends plugin
   function getPrinter($detailed = false)
   {
     $a_return=array();
-    $ldap = $this->config->get_ldap_link();
-    $ldap->cd($this->depselect);
-    $ldap->search("(&".$this->searchObjects."(cn=".$this->regex."))",$this->searchAttrs);
-    while($printer = $ldap->fetch()){
+
+    $filter = "(&".$this->searchObjects."(cn=".$this->regex."))";
+    $base   = $this->baseAddition.$this->depselect;
+    $attrs  = $this->searchAttrs;
+    $cat    = $this->search_cat;
+
+    $res = get_list($filter,$cat,$base,$attrs);
+    foreach($res as $printer){
       if(($detailed ==true)){
         if(isset($printer[$this->searchAppend])){
           $a_return[$printer[$this->searchAppend][0]] = $printer;
@@ -134,9 +186,5 @@ class selectUserToPrinterDialog extends plugin
   }
 }
 
-
-
-
-
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>