Code

Updated iframe for unitTagging.
[gosa.git] / gosa-core / plugins / admin / departments / class_departmentGeneric.inc
index e76d4e38645124a79c864fe6655d8272e212b151..d0273c1e0e5421a9369e4dc807abd3ec9bfef8f7 100644 (file)
@@ -32,11 +32,13 @@ class department extends plugin
        var $businessCategory= "";
        var $telephoneNumber= "";
        var $facsimileTelephoneNumber= "";
-       var $orig_dn= "";
        var $is_administrational_unit= false;
        var $gosaUnitTag= "";
   var $view_logged = FALSE;
 
+  var $type ="ou";
+  var $namingAttr = "ou";
+
        /* Headpage attributes */
        var $last_dep_sorting= "invalid";
        var $departments= array();
@@ -59,7 +61,13 @@ class department extends plugin
                $this->ui= get_userinfo();
                $this->dn= $dn;
                $this->orig_dn= $dn;
-               $this->orig_ou= $this->ou;
+
+    /* Save current naming attribuet 
+     */
+    $nA      = $this->namingAttr;
+    $orig_nA = "orig_".$nA;
+    $this->$orig_nA = $this->$nA;
+
                $this->config= $config;
 
                /* Set base */
@@ -104,6 +112,15 @@ class department extends plugin
       $smarty->assign($name."ACL",$this->getacl($name));
     }
 
+    /* Hide base selector, if this object represents the base itself 
+     */
+    $smarty->assign("is_root_dse", FALSE);
+    if($this->dn == $this->config->current['BASE']){
+      $smarty->assign("is_root_dse", TRUE);
+      $nA = $this->namingAttr."ACL";
+      $smarty->assign($nA,$this->getacl($this->namingAttr,TRUE));
+    }
+
                /* Base select dialog */
                $once = true;
                foreach($_POST as $name => $value){
@@ -158,12 +175,27 @@ class department extends plugin
 
     /* Set admin unit flag */
     if ($this->is_administrational_unit) {
-      $smarty->assign("unitTag", "checked");
+      $smarty->assign("gosaUnitTag", "checked");
     } else {
-      $smarty->assign("unitTag", "");
+      $smarty->assign("gosaUnitTag", "");
     }
 
-               return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
+    $smarty->assign("dep_type",$this->type);
+    
+
+    $dep_types = departmentManagement::get_support_departments();
+    $tpl ="";
+    foreach($dep_types as $key => $data){
+      if($data['ATTR'] == $this->type){
+        $tpl = $data['TPL'];
+        break;
+      }
+    }
+    if($tpl == "") {
+      trigger_error("No template specified for container type '".$this->type."', please update epartmentManagement::get_support_departments().");
+      $tpl = "generic.tpl";
+    }
+               return($smarty->fetch (get_template_path($tpl, TRUE)));
        }
 
        function clear_fields()
@@ -180,7 +212,7 @@ class department extends plugin
        {
                $ldap= $this->config->get_ldap_link();
                $ldap->cd ($this->dn);
-               $ldap->recursive_remove();
+               $ldap->rmdir_recursive($this->dn);
     new log("remove","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
     if (!$ldap->success()){
       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
@@ -198,7 +230,12 @@ class department extends plugin
        /* Save data to object */
        function save_object()
        {
-               if (isset($_POST['dep_generic_posted'])){
+    if (isset($_POST['dep_generic_posted'])){
+
+      $nA = $this->namingAttr;
+      $old_nA = $this->$nA;
+
+
 
       /* Create a base backup and reset the
          base directly after calling plugin::save_object();
@@ -216,13 +253,20 @@ class department extends plugin
       }
 
       /* Save tagging flag */
-      if ($this->acl_is_writeable("unitTag")){
-        if (isset($_POST['unitTag'])){
+      if ($this->acl_is_writeable("gosaUnitTag")){
+        if (isset($_POST['gosaUnitTag'])){
           $this->is_administrational_unit= true;
         } else {
           $this->is_administrational_unit= false;
         }
       }
+
+      /* If this is the root directory service entry (rootDSE)
+         then avoid changing the naming attribute of this entry.
+       */
+      if($this->dn == $this->config->current['BASE']){
+        $this->$nA = $old_nA;
+      }
     }
        }
 
@@ -264,7 +308,15 @@ class department extends plugin
                        $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
                }
 
-               return $message;
+    /* Check if we are allowed to create or move this object
+     */
+    if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
+      $message[] = msgPool::permCreate();
+    }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
+      $message[] = msgPool::permMove();
+    }
+
+    return $message;
        }
 
 
@@ -273,6 +325,11 @@ class department extends plugin
        {
                $ldap= $this->config->get_ldap_link();
 
+    /* Ensure that ou is saved too, it is required by objectClass gosaDepartment 
+     */
+    $nA = $this->namingAttr;
+    $this->ou = $this->$nA;
+
     /* Add tag objects if needed */
     if ($this->is_administrational_unit){
 
@@ -312,33 +369,27 @@ class department extends plugin
     $this->skipTagging = TRUE;
     plugin::save();
 
+
     /* Remove tag information if needed */
-    if (!$this->is_administrational_unit){
+    if (!$this->is_administrational_unit && $this->initially_was_tagged){
       $tmp= array();
 
       /* Remove gosaAdministrativeUnit from this plugin */
+      $has_unit_tag= false;
       foreach($this->attrs['objectClass'] as $oc){
         if (!preg_match("/^gosaAdministrativeUnit$/i", $oc)){
           $tmp[]= $oc;
         }
+        if (preg_match("/^gosaAdministrativeUnitTag$/i", $oc)){
+          $has_unit_tag= true;
+        }
       }
       $this->attrs['objectClass']= $tmp;
-    }
-
-    /* Do we need to remove the tag itself? */
-    $has_unit_tag= false;
-    foreach($this->attrs['objectClass'] as $oc){
-      if (preg_match("/^gosaAdministrativeUnitTag$/i", $oc)){
-        $has_unit_tag= true;
-      }
-    }
-    if ($has_unit_tag == false && $this->is_administrational_unit == false){
       $this->attrs['gosaUnitTag']= array();
       $this->gosaUnitTag = "";
-    } else {
-      $this->attrs['gosaUnitTag']= $this->gosaUnitTag;
     }
 
+
                /* Write back to ldap */
                $ldap->cat($this->dn, array('dn'));
                $ldap->cd($this->dn);
@@ -436,9 +487,13 @@ class department extends plugin
     if(!$OnlySetTagFlag){
       $this->must_be_tagged = FALSE;
            echo '<p class="seperator">&nbsp;</p>';
-      echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
-        <br><input type='submit' name='back' value='"._("Continue")."'>
-        </form></div>";
+      echo "<div style='width:100%;text-align:right;'>".
+        "<form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>".
+        "<br>".
+        "<input type='submit' name='back' value='"._("Continue")."'>".
+        "<input type='hidden' name='php_c_check' value='1'>".
+        "</form>".
+        "</div>";
       echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
     }
        }
@@ -539,17 +594,18 @@ class department extends plugin
                   "plCategory"    => array("department" => array("objectClass" => "gosaDepartment", "description" => _("Departments"))),
             
                   "plProvidedAcls" => array(
-                    "description"       => _("Description"),
-                    "c"                 => _("Country"),
-                    "base"              => _("Base"),
-                    "l"                 => _("Location"),
-                    "telephoneNumber"   => _("Telephone"),
                     "ou"                => _("Department name"),
+                    "description"       => _("Description"),
                     "businessCategory"  => _("Category"),
+                    "base"              => _("Base"),
+
                     "st"                => _("State"),
+                    "l"                 => _("Location"),
                     "postalAddress"     => _("Address"),
-                    "gosaUnitTag"       => _("Administrative settings"),
-                    "facsimileTelephoneNumber" => _("Fax"))
+                    "telephoneNumber"   => _("Telephone"),
+                    "facsimileTelephoneNumber" => _("Fax"),
+
+                    "gosaUnitTag"       => _("Administrative settings"))
                   ));
   }
 
@@ -659,7 +715,6 @@ class department extends plugin
         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not removing tag ($tag) $dn - seems to have moved away", "Tagging");
       }
     }
-
   }
 
 }