Code

Fixed attachment for printer
[gosa.git] / plugins / admin / departments / class_departmentGeneric.inc
index b31594617dce3532a83f0624b9ba0bfd5e5bc22f..afa6e2744fa614fa12cdeccee17141b40c69b41e 100644 (file)
@@ -43,61 +43,84 @@ class department extends plugin
 
   function department ($config, $dn)
   {
-       plugin::plugin($config, $dn);
-       $this->is_account= TRUE;
-       $this->ui= get_userinfo();
-       $this->dn= $dn;
-       $this->orig_dn= $dn;
-       $this->config= $config;
-
-       /* Set base */
-        if ($this->dn == "new"){
-               $ui= get_userinfo();
-               $this->base= dn2base($ui->dn);
-       } else {
-                $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
-        }
+
+         plugin::plugin($config, $dn);
+         $this->is_account= TRUE;
+         $this->ui= get_userinfo();
+         $this->dn= $dn;
+         $this->orig_dn= $dn;
+         $this->config= $config;
+
+         /* Set base */
+         if ($this->dn == "new"){
+                 $ui= get_userinfo();
+                 if(isset($_SESSION['depfilter']['depselect'])){
+                         $this->base = $_SESSION['depfilter']['depselect'];
+                 }else{
+                         $this->base= dn2base($ui->dn);
+                 }
+         } else {
+                 $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
+         }
+         /* set permissions */
+         $ui= get_userinfo();
+         $acl= get_permissions ($ui->dn, $ui->subtreeACL);
+         $this->acl= get_module_permission($acl, "department", $ui->dn);
   }
 
   function execute()
   {
-       /* Reload departments */
-       $this->config->departments= get_departments($this->dn);
-       $this->config->make_idepartments();
-       $smarty= get_smarty();
-
-
-       /* Show main page */
-       $smarty->assign("bases", $this->config->idepartments);
-
-       foreach ($this->attributes as $val){
-               $smarty->assign("$val", $this->$val);
-               $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
-       }
-       $smarty->assign("bases", $this->config->idepartments);
-       $smarty->assign("base_select", $this->base);
-       return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
+         /* Call parent execute */
+         plugin::execute();
+
+         /* Reload departments */
+         $this->config->departments= get_departments($this->dn);
+         $this->config->make_idepartments();
+         $smarty= get_smarty();
+
+         /* Hide all departments, that are subtrees of this department */
+         $bases        = $this->config->idepartments;
+         if(($this->dn == "new")||($this->dn == "")){
+               $tmp = $bases;
+         }else{
+                 $tmp  = array();      
+                 foreach($bases as $dn=>$base){
+                         $fixed = str_replace("/","\\",$this->dn);
+                         /* Only attach departments which are not a subtree of this one */
+                         if(!preg_match("/".$fixed."/",$dn)){
+                                 $tmp[$dn]=$base;
+                         }
+                 }
+               }
+         $smarty->assign("bases", $tmp);
+
+         foreach ($this->attributes as $val){
+                 $smarty->assign("$val", $this->$val);
+                 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
+         }
+         $smarty->assign("base_select", $this->base);
+         return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
   }
 
   function clear_fields()
   {
-       $this->dn= "";
-       $this->base= "";
-       $this->acl= "#none#";
+         $this->dn= "";
+         $this->base= "";
+         $this->acl= "#none#";
 
-       foreach ($this->attributes as $val){
-               $this->$val= "";
-       }
+         foreach ($this->attributes as $val){
+                 $this->$val= "";
+         }
   }
 
 
   function remove_from_parent()
   {
-       $ldap= $this->config->get_ldap_link();
-       $ldap->cd ($this->dn);
-       $ldap->recursive_remove();
+         $ldap= $this->config->get_ldap_link();
+         $ldap->cd ($this->dn);
+         $ldap->recursive_remove();
 
-       /* Optionally execute a command after we're done */
+         /* Optionally execute a command after we're done */
        $this->handle_post_events('remove');
   }
 
@@ -122,10 +145,8 @@ class department extends plugin
        $message= array();
 
        /* Permissions for that base? */
-       $this->dn= "ou=$this->ou,".$this->base;
-       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
-       $acl= get_module_permission($acl, "department", $this->dn);
-       if (chkacl($acl, "create") != ""){
+//     $this->dn= "ou=$this->ou,".$this->base;
+       if (chkacl($this->acl, "create") != ""){
                $message[]= _("You have no permissions to create a department on this 'Base'.");
        }
 
@@ -151,7 +172,7 @@ class department extends plugin
                $message[]= _("The field 'Name' contains the reserved word 'incoming'.".
                                " Please choose another name.");
        }
-       if (preg_match ('/[,#+:=>\\\\]/', $this->ou)){
+       if (preg_match ('/[,#+:=>\\\\\/]/', $this->ou)){
                $message[]= _("The field 'Name' contains invalid characters.");
        }
        if (!is_phone_nr($this->telephoneNumber)){