Code

Updated iframe for unitTagging.
[gosa.git] / gosa-core / plugins / admin / departments / class_departmentGeneric.inc
index a59500df8e2a5b76d6282611f8a75d2217320580..d0273c1e0e5421a9369e4dc807abd3ec9bfef8f7 100644 (file)
@@ -1,21 +1,23 @@
 <?php
 /*
-  This code is part of GOsa (https://gosa.gonicus.de)
-  Copyright (C) 2003  Cajus Pollmeier
-
-  This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software
-  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * This code is part of GOsa (http://www.gosa-project.org)
+ * Copyright (C) 2003-2008 GONICUS GmbH
+ *
+ * ID: $$Id$$
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 class department extends plugin
@@ -30,18 +32,16 @@ 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 $rec_dst=false;     // Destination for recursive move
-       var $rec_src=false;     // Source for recursive move 
-       var $rec_cpy=false;     // Is recursive move requested ? 
+
+  var $type ="ou";
+  var $namingAttr = "ou";
 
        /* Headpage attributes */
        var $last_dep_sorting= "invalid";
        var $departments= array();
-
   var $must_be_tagged = false;
 
        /* attribute list for save action */
@@ -61,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 */
@@ -106,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){
@@ -160,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()
@@ -182,9 +212,11 @@ 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());
-    show_ldap_error($ldap->get_error(), sprintf(_("Removing of department with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
+    }
 
                /* Optionally execute a command after we're done */
                $this->handle_post_events('remove');
@@ -195,16 +227,15 @@ class department extends plugin
                return $this->must_be_tagged;
        }
 
-       function am_i_moved()
-       {
-               return $this->rec_cpy;
-       }
-
-
        /* 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();
@@ -222,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;
+      }
     }
        }
 
@@ -243,34 +281,42 @@ class department extends plugin
                $ldap= $this->config->get_ldap_link();
     $ldap->ls ("(&(ou=".$this->ou.")(objectClass=organizationalUnit))", $this->base, array('dn'));
     if ($this->orig_dn == "new" && $ldap->count()){
-                       $message[]= _("Department with that 'Name' already exists.");
-               } elseif ($this->orig_dn != $this->dn && !($attrs === FALSE)){
-                       $message[]= _("Department with that 'Name' already exists.");
+                       $message[]= msgPool::duplicated(_("Name"));
+               } elseif ($this->orig_dn != $this->dn && $ldap->count()){
+                       $message[]= msgPool::duplicated(_("Name"));
                }
 
                /* All required fields are set? */
                if ($this->ou == ""){
-                       $message[]= _("Required field 'Name' is not set.");
+                       $message[]= msgPool::required(_("Name"));
                }
                if ($this->description == ""){
-                       $message[]= _("Required field 'Description' is not set.");
+                       $message[]= msgPool::required(_("Description"));
                }
 
     if(tests::is_department_name_reserved($this->ou,$this->base)){
-      $message[]= sprintf(_("The field 'Name' contains the reserved word '%s'. Please choose another name."),$this->ou);
+      $message[]= msgPool::reserved(_("Name"));
     }
 
                if (preg_match ('/[#+:=>\\\\\/]/', $this->ou)){
-                       $message[]= _("The field 'Name' contains invalid characters.");
+                       $message[]= msgPool::invalid(_("Name"), $this->ou, "/[^#+:=>\\\\\/]/");
                }
                if (!tests::is_phone_nr($this->telephoneNumber)){
-                       $message[]= _("The field 'Phone' contains an invalid phone number.");
+                       $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
                }
                if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
-                       $message[]= _("The field 'Fax' contains an invalid phone number.");
+                       $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;
        }
 
 
@@ -279,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){
 
@@ -315,12 +366,12 @@ class department extends plugin
         $this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec);
       }
     }
+    $this->skipTagging = TRUE;
     plugin::save();
 
-    $this->attrs['gosaUnitTag'] = $this->gosaUnitTag;
 
     /* 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 */
@@ -334,20 +385,16 @@ class department extends plugin
         }
       }
       $this->attrs['objectClass']= $tmp;
-
-      if(!$has_unit_tag && isset($this->attrs['gosaUnitTag'])){
-        $this->attrs['gosaUnitTag']= array();
-      }
+      $this->attrs['gosaUnitTag']= array();
       $this->gosaUnitTag = "";
     }
 
+
                /* Write back to ldap */
-               $ldap= $this->config->get_ldap_link();
                $ldap->cat($this->dn, array('dn'));
-               $a= $ldap->fetch();
                $ldap->cd($this->dn);
 
-               if (count($a)){
+               if ($ldap->count()){
                        $this->cleanup();
                        $ldap->modify ($this->attrs); 
       new log("modify","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
@@ -357,7 +404,9 @@ class department extends plugin
                        $this->handle_post_events('add');
       new log("create","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
                }
-    show_ldap_error($ldap->get_error(), sprintf(_("Saving of department with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
+    }
 
     /* The parameter forces only to set must_be_tagged, and don't touch any objects 
        This will be done later */
@@ -369,24 +418,6 @@ class department extends plugin
        }
 
 
-  function ShowMoveFrame()
-  {
-    $smarty = get_smarty();
-    $smarty->assign("src","?plug=".$_GET['plug']."&amp;PerformRecMove");
-    $smarty->assign("message","As soon as the move operation has finished, you can scroll down to end of the page and press the 'Continue' button to continue with the department management dialog.");
-    $display=  $smarty->fetch(get_template_path("dep_iframe.tpl",TRUE));
-    return($display);
-  }
-
-  function ShowTagFrame()
-  {
-    $smarty = get_smarty();
-    $smarty->assign("src","?plug=".$_GET['plug']."&TagDepartment");
-    $smarty->assign("message","As soon as the tag operation has finished, you can scroll down to end of the page and press the 'Continue' button to continue with the department management dialog.");
-    $display=  $smarty->fetch(get_template_path("dep_iframe.tpl",TRUE));
-    return($display);
-  }
-
        /* Tag objects to have the gosaAdministrativeUnitTag */
        function tag_objects($OnlySetTagFlag = false)
        {
@@ -416,7 +447,11 @@ class department extends plugin
            $ldap->search('objectClass=gosaAdministrativeUnitTag', array('dn'));
     }
 
+    $objects = array();
     while ($attrs= $ldap->fetch()){
+      $objects[] = $attrs;
+    }
+    foreach($objects as $attrs){
 
            /* Skip self */
            if ($attrs['dn'] == $this->dn){
@@ -445,13 +480,21 @@ class department extends plugin
                            return;
                    }
                    $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag, TRUE );
+        echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
            }
     }
+    
     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>" ;
     }
        }
 
@@ -459,101 +502,84 @@ class department extends plugin
        /* Move/Rename complete trees */
        function recursive_move($src_dn, $dst_dn,$force = false)
        {
-    /* If force == false prepare to recursive move this object from src to dst 
-        on the next call. */
-               if(!$force){
-                       $this->rec_cpy  = true;
-                       $this->rec_src  = $src_dn;
-                       $this->rec_dst  = $dst_dn;
-               }else{
-
-      /* If this is called, but not wanted, abort */
-                       if(!$this->rec_cpy){ 
-                               return;
-                       }
-
-                       $src_dn = $this->rec_src;
-                       $dst_dn = $this->rec_dst;
-
-                       /* Print header to have styles included */
-                       $smarty= get_smarty();
-
-      echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
-        <html>
-        <head>
-        <title></title>
-        <style type="text/css">@import url("themes/default/style.css");</style>
-        <script language="javascript" src="include/focus.js" type="text/javascript"></script>
-        </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>";
-
-
-                       /* Check if the destination entry exists */
-                       $ldap= $this->config->get_ldap_link();
+    /* Print header to have styles included */
+    $smarty= get_smarty();
+
+    echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+      <html>
+      <head>
+      <title></title>
+      <style type="text/css">@import url("themes/default/style.css");</style>
+      <script language="javascript" src="include/focus.js" type="text/javascript"></script>
+      </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>";
+
+
+    /* Check if the destination entry exists */
+    $ldap= $this->config->get_ldap_link();
 
-                       /* Check if destination exists - abort */
-                       $ldap->cat($dst_dn, array('dn'));
-                       if ($ldap->fetch()){
-                               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>"; 
-                               return (FALSE);
-                       }
+    /* Check if destination exists - abort */
+    $ldap->cat($dst_dn, array('dn'));
+    if ($ldap->fetch()){
+      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>"; 
+      return (FALSE);
+    }
 
-                       /* Perform a search for all objects to be moved */
-                       $objects= array();
-                       $ldap->cd($src_dn);
-                       $ldap->search("(objectClass=*)", array("dn"));
-                       while($attrs= $ldap->fetch()){
-                               $dn= $attrs['dn'];
-                               $objects[$dn]= strlen($dn);
-                       }
+    /* Perform a search for all objects to be moved */
+    $objects= array();
+    $ldap->cd($src_dn);
+    $ldap->search("(objectClass=*)", array("dn"));
+    while($attrs= $ldap->fetch()){
+      $dn= $attrs['dn'];
+      $objects[$dn]= strlen($dn);
+    }
 
-                       /* Sort objects by indent level */
-                       asort($objects);
-                       reset($objects);
+    /* Sort objects by indent level */
+    asort($objects);
+    reset($objects);
 
-                       /* Copy objects from small to big indent levels by replacing src_dn by dst_dn */
-                       foreach ($objects as $object => $len){
+    /* Copy objects from small to big indent levels by replacing src_dn by dst_dn */
+    foreach ($objects as $object => $len){
 
 
-                               $src= str_replace("\\","\\\\",$object);
-                               $dst= preg_replace("/".str_replace("\\","\\\\",$src_dn)."$/", "$dst_dn", $object);
-                               $dst= str_replace($src_dn,$dst_dn,$object);
+      $src= str_replace("\\","\\\\",$object);
+      $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);
+      $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>";
-                                       return (FALSE);
-                               }
-        echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
-                               flush();
-                       }
+      if (!$this->copy($src, $dst)){
+        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>" ;
+      flush();
+    }
 
-                       /* Remove src_dn */
-                       $ldap->cd($src_dn);
-                       $ldap->recursive_remove();
-      $this->dn = $this->rec_dst;
-                       $this->rec_src = $this->rec_dst = "";
-                       $this->rec_cpy =false;
+    /* Remove src_dn */
+    $ldap->cd($src_dn);
+    $ldap->recursive_remove();
+    $this->orig_dn  = $this->dn = $dst_dn;
+    $this->orig_base= $this->base;     
+    $this->entryCSN = getEntryCSN($this->dn);
 
-                       echo '<p class="seperator">&nbsp;</p>';
+    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")."'>
+      </form></div>";
 
-      echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
-                       echo "</body></html>";
+    echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
+    echo "</body></html>";
 
-                       return (TRUE);
-               }
-       }
+    return (TRUE);
+  }
 
 
   /* Return plugin informations for acl handling */ 
@@ -568,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"))
                   ));
   }
 
@@ -650,7 +677,9 @@ class department extends plugin
         $nattrs['objectClass'][]= "gosaAdministrativeUnitTag";
         $ldap->cd($dn);
         $ldap->modify($nattrs);
-        show_ldap_error($ldap->get_error(), sprintf(_("Handle object tagging with dn '%s' failed."),$dn));
+        if (!$ldap->success()){
+          msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()));
+        }
       } else {
         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not tagging ($tag) $dn - seems to have moved away", "Tagging");
       }
@@ -679,12 +708,13 @@ class department extends plugin
         }
         $ldap->cd($dn);
         $ldap->modify($nattrs);
-        show_ldap_error($ldap->get_error(), sprintf(_("Handle object tagging with dn '%s' failed."),$dn));
+        if (!$ldap->success()){
+          msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()));
+        }
       } else {
         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not removing tag ($tag) $dn - seems to have moved away", "Tagging");
       }
     }
-
   }
 
 }