Code

Added some comments.
[gosa.git] / gosa-core / plugins / admin / departments / class_departmentGeneric.inc
index eec9adf02ce43d5b9d99100d8578e65fd61ddef3..78e514f1e2af041e3b302cd4d85cb3c5cc4e9713 100644 (file)
@@ -36,7 +36,7 @@ class department extends plugin
        var $gosaUnitTag= "";
   var $view_logged = FALSE;
 
-  var $type ="ou";
+  var $type ="organizationalUnit";
   var $namingAttr = "ou";
 
        /* Headpage attributes */
@@ -47,14 +47,38 @@ class department extends plugin
        /* attribute list for save action */
        var $attributes= array("ou", "description", "businessCategory", "st", "l", "postalAddress",
                        "telephoneNumber", "facsimileTelephoneNumber", "gosaUnitTag");
-       var $objectclasses= array("top", "gosaDepartment", "organizationalUnit");
-  var $initially_was_tagged = false;
 
+  /* Do not append the structural object classes here, they are added dynamically in the constructor */
+       var $objectclasses= array("top", "gosaDepartment");
+  var $structuralOC = array("organizationalUnit");
+
+  var $initially_was_tagged = false;
   var $orig_base = "";
   var $orig_ou = "";
 
        function department (&$config, $dn)
        {
+    /* Add the default structural obejct class 'locality' if this is a new entry
+     */
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+    if($dn == "" || $dn == "new" || !$ldap->dn_exists($dn)){
+      $this->objectclasses = array_merge($this->structuralOC,$this->objectclasses);
+    }else{
+      $ldap->cat($dn, array("structuralObjectClass"));
+      $attrs= $ldap->fetch();
+      if(isset($attrs['structuralObjectClass']['count'])){
+        for($i = 0 ; $i < $attrs['structuralObjectClass']['count'] ; $i++){
+          $this->objectclasses[] = $attrs['structuralObjectClass'][$i];
+        }
+      }else{
+
+        /* Could not detect structural object class for this object, fall back to the default 'locality'
+         */
+        $this->objectclasses = array_merge($this->structuralOC,$this->objectclasses);
+      }
+    }
+    $this->objectclasses = array_unique($this->objectclasses);
 
                plugin::plugin($config, $dn);
                $this->is_account= TRUE;
@@ -107,18 +131,20 @@ class department extends plugin
                $this->config->make_idepartments();
                $smarty= get_smarty();
 
-    /* Hide base selector, if this object represents the base itself 
-     */
-    $smarty->assign("hide_base", FALSE);
-    if($this->dn == $this->config->current['BASE']){
-      $smarty->assign("hide_base", TRUE);
-    }
-
     $tmp = $this->plInfo();
     foreach($tmp['plProvidedAcls'] as $name => $translation){
       $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){
@@ -157,9 +183,8 @@ class department extends plugin
                }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)){
+        if(!preg_match("/".preg_quote($this->dn)."/",$dn)){
                                        $tmp[$dn]=$base;
                                }
                        }
@@ -173,9 +198,9 @@ 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", "");
     }
 
     $smarty->assign("dep_type",$this->type);
@@ -184,7 +209,7 @@ class department extends plugin
     $dep_types = departmentManagement::get_support_departments();
     $tpl ="";
     foreach($dep_types as $key => $data){
-      if($data['ATTR'] == $this->type){
+      if($data['OC'] == $this->type){
         $tpl = $data['TPL'];
         break;
       }
@@ -228,7 +253,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();
@@ -246,13 +276,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['is_administrational_unit'])){
           $this->is_administrational_unit= true;
         } else {
           $this->is_administrational_unit= false;
         }
       }
+
+      /* If this is the root directory service entry then avoid
+         changing the naming attribute of this entry.
+       */
+      if($this->dn == $this->config->current['BASE']){
+        $this->$nA = $old_nA;
+      }
     }
        }
 
@@ -355,20 +392,18 @@ class department extends plugin
     $this->skipTagging = TRUE;
     plugin::save();
 
-
     /* Remove tag information if needed */
     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("/^gosaAdministrativeUnitTag$/i", $oc)){
+          continue;
+        }
         if (!preg_match("/^gosaAdministrativeUnit$/i", $oc)){
           $tmp[]= $oc;
         }
-        if (preg_match("/^gosaAdministrativeUnitTag$/i", $oc)){
-          $has_unit_tag= true;
-        }
       }
       $this->attrs['objectClass']= $tmp;
       $this->attrs['gosaUnitTag']= array();
@@ -419,7 +454,7 @@ class department extends plugin
         </head>
         <body style="background: none; margin:4px;" id="body" >
         ';
-      echo "<h3>".sprintf(_("Tagging '%s'."),"<i>".@LDAP::fix($this->dn)."</i>")."</h3>";
+      echo "<h3>".sprintf(_("Tagging '%s'."),"<i>".LDAP::fix($this->dn)."</i>")."</h3>";
     }
 
     $add= $this->is_administrational_unit;
@@ -453,7 +488,7 @@ class department extends plugin
                    }
 
                    /* This one matches with the latter part. Break and don't fix this entry */
-                   if (preg_match('/(^|,)'.normalizePreg($key).'$/', $attrs['dn'])){
+                   if (preg_match('/(^|,)'.preg_quote($key, '/').'$/', $attrs['dn'])){
                            $fix= false;
                            break;
                    }
@@ -473,9 +508,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>" ;
     }
        }
@@ -496,7 +535,7 @@ class department extends plugin
       </head>
       <body style="background: none; margin:4px;" id="body" >
       ';
-    echo "<h3>".sprintf(_("Moving '%s' to '%s'"),"<i>".@LDAP::fix($src_dn)."</i>","<i>".@LDAP::fix($dst_dn)."</i>")."</h3>";
+    echo "<h3>".sprintf(_("Moving '%s' to '%s'"),"<i>".LDAP::fix($src_dn)."</i>","<i>".LDAP::fix($dst_dn)."</i>")."</h3>";
 
 
     /* Check if the destination entry exists */
@@ -505,9 +544,9 @@ class department extends plugin
     /* Check if destination exists - abort */
     $ldap->cat($dst_dn, array('dn'));
     if ($ldap->fetch()){
-      trigger_error("Recursive_move ".@LDAP::fix($dst_dn)." already exists.",
+      trigger_error("Recursive_move ".LDAP::fix($dst_dn)." already exists.",
           E_USER_WARNING);
-      echo sprintf("Recursive_move: '%s' already exists", @LDAP::fix($dst_dn))."<br>"; 
+      echo sprintf("Recursive_move: '%s' already exists", LDAP::fix($dst_dn))."<br>"; 
       return (FALSE);
     }
 
@@ -532,12 +571,12 @@ class department extends plugin
       $dst= preg_replace("/".str_replace("\\","\\\\",$src_dn)."$/", "$dst_dn", $object);
       $dst= str_replace($src_dn,$dst_dn,$object);
 
-      echo "<b>"._("Object").":</b> ".@LDAP::fix($src)."<br>";
+      echo "<b>"._("Object").":</b> ".LDAP::fix($src)."<br>";
 
       $this->update_acls($object, $dst,TRUE);
 
       if (!$this->copy($src, $dst)){
-        echo "<font color='#FF0000'><br>".sprintf(_("FAILED to copy %s, aborting operation"),@LDAP::fix($src))."</font>";
+        echo "<font color='#FF0000'><br>".sprintf(_("FAILED to copy %s, aborting operation"),LDAP::fix($src))."</font>";
         return (FALSE);
       }
       echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
@@ -572,21 +611,22 @@ class department extends plugin
                   "plSelfModify"  => FALSE,
                   "plPriority"    => 0,
                   "plDepends"     => array(),
-                  "plSection"     => array("admin"),
+                  "plSection"     => array("administration"),
                   "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"))
                   ));
   }
 
@@ -610,7 +650,7 @@ class department extends plugin
           }
 
           /* This one matches with the latter part. Break and don't fix this entry */
-          if (preg_match('/(^|,)'.normalizePreg($key).'$/', $dn)){
+          if (preg_match('/(^|,)'.preg_quote($key, '/').'$/', $dn)){
             @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "DEBUG: Possibly relevant: $key", "Tagging");
             $relevant[strlen($key)]= $ntag;
             continue;
@@ -637,14 +677,14 @@ class department extends plugin
       $attrs= $ldap->fetch();
       if(isset($attrs['gosaUnitTag'][0]) && $attrs['gosaUnitTag'][0] == $tag){
         if ($show) {
-          echo sprintf(_("Object '%s' is already tagged"), @LDAP::fix($dn))."<br>";
+          echo sprintf(_("Object '%s' is already tagged"), LDAP::fix($dn))."<br>";
           flush();
         }
         return;
       }
       if (count($attrs)){
         if ($show){
-          echo sprintf(_("Adding tag (%s) to object '%s'"), $tag, @LDAP::fix($dn))."<br>";
+          echo sprintf(_("Adding tag (%s) to object '%s'"), $tag, LDAP::fix($dn))."<br>";
           flush();
         }
         $nattrs= array("gosaUnitTag" => $tag);
@@ -676,7 +716,7 @@ class department extends plugin
       }
       if (count($attrs)){
         if ($show){
-          echo sprintf(_("Removing tag from object '%s'"), @LDAP::fix($dn))."<br>";
+          echo sprintf(_("Removing tag from object '%s'"), LDAP::fix($dn))."<br>";
           flush();
         }
         $nattrs= array("gosaUnitTag" => array());