Code

Added acls for printer glpi
[gosa.git] / plugins / admin / departments / class_departmentGeneric.inc
index 56476efcbf6138529ccc373e26cec58b12aee72d..3b6daee52d8093460ba9b38e69918c1bd64a7a11 100644 (file)
@@ -48,6 +48,7 @@ class department extends plugin
        var $attributes= array("ou", "description", "businessCategory", "st", "l", "postalAddress",
                        "telephoneNumber", "facsimileTelephoneNumber", "gosaUnitTag");
        var $objectclasses= array("top", "gosaDepartment", "organizationalUnit");
+  var $initially_was_tagged = false;
 
        function department ($config, $dn)
        {
@@ -71,14 +72,10 @@ class department extends plugin
                        $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);
-
                /* Is administrational Unit? */
                if ($dn != "new" && in_array_ics('gosaAdministrativeUnit', $this->attrs['objectClass'])){
                        $this->is_administrational_unit= true;
+      $this->initially_was_tagged = true;
                }
        }
 
@@ -92,12 +89,24 @@ class department extends plugin
                $this->config->make_idepartments();
                $smarty= get_smarty();
 
+    /* Assign base ACL */
+    $baseACL = $this->getacl("base");
+    if(!$this->acl_is_moveable()) {
+      $baseACL = preg_replace("/w/","",$baseACL);
+    }
+    $smarty->assign("baseACL",          $baseACL);
+
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $name => $translation){
+      $smarty->assign($name."ACL",$this->getacl($name));
+    }
+
                /* Base select dialog */
                $once = true;
                foreach($_POST as $name => $value){
-                       if(preg_match("/^chooseBase/",$name) && $once){
+                       if((preg_match("/^chooseBase/",$name) && $once) && ($this->acl_is_moveable())){
                                $once = false;
-                               $this->dialog = new baseSelectDialog($this->config,$this);
+                               $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
                                $this->dialog->setCurrentBase($this->base);
                        }
                }
@@ -118,7 +127,7 @@ class department extends plugin
                }
 
                /* Hide all departments, that are subtrees of this department */
-               $bases  = $this->config->idepartments;
+    $bases = $this->get_allowed_bases();
                if(($this->dn == "new")||($this->dn == "")){
                        $tmp = $bases;
                }else{
@@ -135,9 +144,7 @@ class department extends plugin
 
                foreach ($this->attributes as $val){
                        $smarty->assign("$val", $this->$val);
-                       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
                }
-    $smarty->assign("baseACL", chkacl($this->acl,"base"));
                $smarty->assign("base_select", $this->base);
 
                /* Set admin unit flag */
@@ -146,16 +153,14 @@ class department extends plugin
                } else {
                        $smarty->assign("unitTag", "");
                }
-               $smarty->assign("unitTag"."ACL", chkacl($this->acl, "unitTag"));
 
                return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
        }
 
        function clear_fields()
        {
-               $this->dn= "";
-               $this->base= "";
-               $this->acl= "#none#";
+               $this->dn   = "";
+               $this->base = "";
 
                foreach ($this->attributes as $val){
                        $this->$val= "";
@@ -187,16 +192,16 @@ class department extends plugin
        /* Save data to object */
        function save_object()
        {
-               if (isset($_POST['base'])){
+               if (isset($_POST['dep_generic_posted'])){
                        plugin::save_object();
 
                        /* Save base, since this is no LDAP attribute */
-                       if (chkacl($this->acl, "create") == ""){
+      if($this->acl_is_moveable() && isset($_POST['base'])){
                                $this->base= $_POST['base'];
                        }
 
                        /* Save tagging flag */
-                       if (chkacl($this->acl, "unitTag") == ""){
+                       if ($this->acl_is_writeable("unitTag")){
                                if (isset($_POST['unitTag'])){
                                        $this->is_administrational_unit= true;
                                } else {
@@ -215,7 +220,7 @@ class department extends plugin
 
                /* Permissions for that base? */
                //      $this->dn= "ou=$this->ou,".$this->base;
-               if (chkacl($this->acl, "create") != ""){
+               if ($this->acl_is_createable() && $this->dn == "new"){
                        $message[]= _("You have no permissions to create a department on this 'Base'.");
                }
 
@@ -261,9 +266,15 @@ class department extends plugin
 
                /* Add tag objects if needed */
                if ($this->is_administrational_unit){
-      if(!in_array_ics("gosaAdministrativeUnit",$this->objectclasses)){
+
+      /* If this wasn't tagged before add oc an reset unit tag */
+      if(!$this->initially_was_tagged){
                        $this->objectclasses[]= "gosaAdministrativeUnit";
                          $this->gosaUnitTag= "";
+
+        /* It seams that this method is called twice, 
+            set this to true. to avoid adding this oc twice */
+        $this->initially_was_tagged = true;
       }
 
                        if ($this->gosaUnitTag == ""){
@@ -311,6 +322,7 @@ class department extends plugin
                        if(!$has_unit_tag && isset($this->attrs['gosaUnitTag'])){
                                $this->attrs['gosaUnitTag']= array();
                        }
+      $this->gosaUnitTag = "";
                }
 
                /* Write back to ldap */
@@ -513,19 +525,31 @@ class department extends plugin
        }
 
 
+  /* Return plugin informations for acl handling */ 
   function plInfo()
   {
-    return (array("plDescription" => _("Departments"),
-                  "plSelfModify" => FALSE,
-                  "plDepends" => array("objectClass" => "gosaDepartment", "description" => _("Departments")),
-                  "description" => _("Description"),
-                  "c" => _("Country"),
-                  "l" => _("Location"),
-                  "telephoneNumber" => _("Telephone"),
-                  "ou" => _("Department name") ));
+    return (array("plShortName"   => _("Generic"),
+                  "plDescription" => _("Departments"),
+                  "plSelfModify"  => FALSE,
+                  "plPriority"    => 0,
+                  "plDepends"     => array(),
+                  "plSection"     => array("admin"),
+                  "plCategory"    => array("department" => array("objectClass" => "gosaDepartment", "description" => _("Departments"))),
+            
+                  "plProvidedAcls" => array(
+                    "description"       => _("Description"),
+                    "c"                 => _("Country"),
+                    "base"              => _("Base"),
+                    "l"                 => _("Location"),
+                    "telephoneNumber"   => _("Telephone"),
+                    "ou"                => _("Department name"),
+                    "businessCategory"  => _("Category"),
+                    "st"                => _("State"),
+                    "postalAddress"     => _("Address"),
+                    "gosaUnitTag"       => _("Administrative settings"),
+                    "facsimileTelephoneNumber" => _("Fax"))
+                  ));
   }
-
-
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>