Code

Updated dhcp handling
[gosa.git] / plugins / admin / departments / class_departmentGeneric.inc
index 2b99b312ff93ba572d3fdf45d0a027a970f7f2e8..9aecbccdff2cb3d39578dc59596a449b74e37625 100644 (file)
@@ -137,6 +137,7 @@ class department extends plugin
                        $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 */
@@ -213,15 +214,14 @@ class department extends plugin
                $message= plugin::check();
 
                /* Permissions for that base? */
-               //      $this->dn= "ou=$this->ou,".$this->base;
                if (chkacl($this->acl, "create") != ""){
                        $message[]= _("You have no permissions to create a department on this 'Base'.");
                }
 
                /* Check for presence of this department */
                $ldap= $this->config->get_ldap_link();
-               $attrs= $ldap->cat ($this->dn, array('dn'));
-               if ($this->orig_dn == "new" && !($attrs === FALSE)){
+    $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.");
@@ -235,19 +235,11 @@ class department extends plugin
                        $message[]= _("Required field 'Description' is not set.");
                }
 
-               /* Validate and modify - or: spaghetti rules! */
-               $SkipNames = array(     "incoming","apps","systems","fai","config",     
-                               preg_replace("/ou=(.*),/","\\1",get_people_ou()),
-                               preg_replace("/ou=(.*),/","\\1",get_groups_ou())
-                               );      
-               foreach($SkipNames as $name){
-                       if ($this->ou == $name){
-                               $message[]= sprintf(_("The field 'Name' contains the reserved word '%s'. Please choose another name."),$name);
-                       }
-               }
-
+    if(is_department_name_reserved($this->ou,$this->base)){
+      $message[]= sprintf(_("The field 'Name' contains the reserved word '%s'. Please choose another name."),$this->ou);
+    }
 
-               if (preg_match ('/[#+:=>\\\\\/]/', $this->ou)){
+               if (preg_match ('/["+>\\\\]/', $this->ou)){
                        $message[]= _("The field 'Name' contains invalid characters.");
                }
                if (!is_phone_nr($this->telephoneNumber)){
@@ -270,7 +262,9 @@ class department extends plugin
                if ($this->is_administrational_unit){
       if(!in_array_ics("gosaAdministrativeUnit",$this->objectclasses)){
                        $this->objectclasses[]= "gosaAdministrativeUnit";
+                         $this->gosaUnitTag= "";
       }
+
                        if ($this->gosaUnitTag == ""){
 
                                /* It's unlikely, but check if already used... */
@@ -293,8 +287,6 @@ class department extends plugin
                                }
                                $this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec);
                        }
-               } else {
-                       $this->gosaUnitTag= "";
                }
 
                plugin::save();
@@ -304,13 +296,18 @@ class department extends plugin
                        $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;
-                       if(isset($this->attrs['gosaUnitTag'])){
+
+                       if(!$has_unit_tag && isset($this->attrs['gosaUnitTag'])){
                                $this->attrs['gosaUnitTag']= array();
                        }
                }
@@ -335,6 +332,11 @@ class department extends plugin
     /* The parameter forces only to set must_be_tagged, and don't touch any objects 
         This will be done later */
     $this->tag_objects(true);
+
+    /* Fix tagging if needed */
+    if (!$this->is_administrational_unit){
+      $this->handle_object_tagging();
+    }
     
     /* Optionally execute a command after we're done */
                $this->postcreate();
@@ -345,7 +347,7 @@ class department extends plugin
   function ShowMoveFrame()
   {
     $smarty = get_smarty();
-    $smarty->assign("src","?plug=".$_GET['plug']."&PerformRecMove");
+    $smarty->assign("src","?plug=".$_GET['plug']."&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);
@@ -354,7 +356,7 @@ class department extends plugin
   function ShowTagFrame()
   {
     $smarty = get_smarty();
-    $smarty->assign("src","?plug=".$_GET['plug']."&TagDepartment");
+    $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);
@@ -365,8 +367,18 @@ class department extends plugin
        {
     if(!$OnlySetTagFlag){
       $smarty= get_smarty();
-      echo "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
-      echo "<body style='background-image:none;margin:3px;color:black'>";
+
+      /* Print out html introduction */
+      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-image:none;margin:3px;color:black" id="body" >
+        ';
+
       echo "<h3>".sprintf(_("Tagging '%s'."),"<i>".@LDAP::fix($this->dn)."</i>")."</h3>";
     }
 
@@ -380,6 +392,7 @@ class department extends plugin
                } else {
                        $ldap->search('objectClass=gosaAdministrativeUnitTag', array('dn'));
                }
+
                while ($attrs= $ldap->fetch()){
 
                        /* Skip self */
@@ -409,6 +422,7 @@ 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){
@@ -441,11 +455,19 @@ class department extends plugin
 
                        /* Print header to have styles included */
                        $smarty= get_smarty();
-                       echo "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
-                       echo "<body style='background-image:none;margin:3px;color:black'>";
 
-                       echo "<h3>".sprintf(_("Moving '%s' to '%s'"),"<i>".$src_dn."</i>","<i>".$dst_dn."</i>")."</h3>";
+      /* Print out html introduction */
+      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();
@@ -453,9 +475,9 @@ class department extends plugin
                        /* Check if destination exists - abort */
                        $ldap->cat($dst_dn, array('dn'));
                        if ($ldap->fetch()){
-                               trigger_error("Recursive_move $dst_dn already exists.",
+                               trigger_error("Recursive_move ".@LDAP::fix($dst_dn)." already exists.",
                                                E_USER_WARNING);
-                               echo sprintf("Recursive_move: '%s' already exists", $dst_dn)."<br>"; 
+                               echo sprintf("Recursive_move: '%s' already exists", @LDAP::fix($dst_dn))."<br>"; 
                                return (FALSE);
                        }
 
@@ -474,19 +496,18 @@ class department extends plugin
 
                        /* 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);
 
-                               echo "<b>"._("Object").":</b> $src<br>";
+                               echo "<b>"._("Object").":</b> ".@LDAP::fix($src)."<br>";
 
-                               if (!$this->copy($src, $dst)){
-                                       echo "<font color='#FF0000'><br>".sprintf(_("FAILED to copy %s, aborting operation"),$src)."</font>";
+        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();
                        }
 
@@ -502,6 +523,7 @@ class department extends plugin
                                <br><input type='submit' name='back' value='"._("Continue")."'>
                                </form></div>";
 
+      echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
                        echo "</body></html>";
 
                        return (TRUE);