Code

Removed debug output
[gosa.git] / plugins / admin / departments / class_departmentGeneric.inc
index 790f787c455cb32cc28c3da3320cf016eadf7144..c1ef6e11d3f79cbe72d45c8c033c54e1bf3be0cc 100644 (file)
@@ -97,7 +97,7 @@ class department extends plugin
                foreach($_POST as $name => $value){
                        if(preg_match("/^chooseBase/",$name) && $once){
                                $once = false;
-                               $this->dialog = new baseSelectDialog($this->config);
+                               $this->dialog = new baseSelectDialog($this->config,$this);
                                $this->dialog->setCurrentBase($this->base);
                        }
                }
@@ -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 */
@@ -161,17 +162,27 @@ class department extends plugin
                }
        }
 
-
        function remove_from_parent()
        {
                $ldap= $this->config->get_ldap_link();
                $ldap->cd ($this->dn);
                $ldap->recursive_remove();
+    show_ldap_error($ldap->get_error(), sprintf(_("Removing of department with dn '%s' failed."),$this->dn));
 
                /* Optionally execute a command after we're done */
                $this->handle_post_events('remove');
        }
 
+       function must_be_tagged()
+       {
+               return $this->must_be_tagged;
+       }
+
+       function am_i_moved()
+       {
+               return $this->rec_cpy;
+       }
+
 
        /* Save data to object */
        function save_object()
@@ -210,8 +221,8 @@ class department extends plugin
 
                /* 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.");
@@ -225,17 +236,9 @@ 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)){
                        $message[]= _("The field 'Name' contains invalid characters.");
@@ -258,7 +261,11 @@ class department extends plugin
 
                /* Add tag objects if needed */
                if ($this->is_administrational_unit){
-                       $this->objectclasses[]= "gosaAdministrativeUnit";
+      if(!in_array_ics("gosaAdministrativeUnit",$this->objectclasses)){
+                       $this->objectclasses[]= "gosaAdministrativeUnit";
+                         $this->gosaUnitTag= "";
+      }
+
                        if ($this->gosaUnitTag == ""){
 
                                /* It's unlikely, but check if already used... */
@@ -281,8 +288,6 @@ class department extends plugin
                                }
                                $this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec);
                        }
-               } else {
-                       $this->gosaUnitTag= "";
                }
 
                plugin::save();
@@ -292,13 +297,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();
                        }
                }
@@ -318,26 +328,51 @@ class department extends plugin
                        $ldap->add($this->attrs);
                        $this->handle_post_events('add');
                }
-               show_ldap_error($ldap->get_error());
+    show_ldap_error($ldap->get_error(), sprintf(_("Saving of department with dn '%s' failed."),$this->dn));
+
+    /* 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();
+    return(true);
+       }
+
 
-    $this->must_be_tagged =true;
+  function ShowMoveFrame()
+  {
     $smarty = get_smarty();
-    $smarty->assign("src","?plug=".$_GET['plug']."&Tag");
-    $display=  $smarty->fetch(get_template_path("iframe.tpl",TRUE));
+    $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);
-    exit();
-
-       }
+  }
 
+  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()
+       function tag_objects($OnlySetTagFlag = false)
        {
+    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'>";
+      echo "<h3>".sprintf(_("Tagging '%s'."),"<i>".@LDAP::fix($this->dn)."</i>")."</h3>";
+    }
+
                $add= $this->is_administrational_unit;
                $len= strlen($this->dn);
                $ldap= $this->config->get_ldap_link();
@@ -348,6 +383,7 @@ class department extends plugin
                } else {
                        $ldap->search('objectClass=gosaAdministrativeUnitTag', array('dn'));
                }
+
                while ($attrs= $ldap->fetch()){
 
                        /* Skip self */
@@ -370,32 +406,36 @@ class department extends plugin
                                }
                        }
 
-                       /* Fix entry if needed */
-                       if ($fix){
-
-                               $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag);
+      /* Fix entry if needed */
+      if ($fix){
+        if($OnlySetTagFlag){
+          $this->must_be_tagged =true;
+          return;
+        }
+                               $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag, TRUE );
                        }
                }
+    if(!$OnlySetTagFlag){
+      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>";
+    }
        }
 
 
        /* 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;
-
-                       $smarty = get_smarty();
-
-                       $smarty->assign("src","?plug=".$_GET['plug']."&PerformRecMove");
-
-                       $display=  $smarty->fetch(get_template_path("recursive_move.tpl",TRUE));
-                       return($display);
-
                }else{
+
+      /* If this is called, but not wanted, abort */
                        if(!$this->rec_cpy){ 
                                return;
                        }
@@ -408,7 +448,7 @@ class department extends plugin
                        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>";
+                       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 */
@@ -417,9 +457,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);
                        }
 
@@ -444,10 +484,10 @@ 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> $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>";
+                                       echo "<font color='#FF0000'><br>".sprintf(_("FAILED to copy %s, aborting operation"),@LDAP::fix($src))."</font>";
                                        return (FALSE);
                                }
 
@@ -471,113 +511,6 @@ class department extends plugin
                        return (TRUE);
                }
        }
-
-       function must_be_tagged()
-       {
-               return $this->must_be_tagged;
-       }
-
-       function am_i_moved()
-       {
-               return $this->rec_cpy;
-       }
-
-       function handle_object_tagging($dn= "", $tag= "")
-       {
-               //FIXME: How to optimize this? We have at least two
-               //       LDAP accesses per object. It would be a good
-               //       idea to have it integrated.
-
-               /* No dn? Self-operation... */
-               if ($dn == ""){
-                       $dn= $this->dn;
-
-                       /* No tag? Find it yourself... */
-                       if ($tag == ""){
-                               $len= strlen($dn);
-
-                               echo sprintf(_("No tag for %s - looking for one..."),$dn);
-                               $relevant= array();
-                               foreach ($this->config->adepartments as $key => $ntag){
-
-                                       /* This one is bigger than our dn, its not relevant... */
-                                       if ($len <= strlen($key)){
-                                               continue;
-                                       }
-
-                                       /* This one matches with the latter part. Break and don't fix this entry */
-                                       if (preg_match('/(^|,)'.normalizePreg($key).'$/', $dn)){
-                                               echo sprintf(_("Possibly relevant: %s"),$key);
-                                               $relevant[strlen($key)]= $ntag;
-                                               continue;
-                                       }
-
-                               }
-                               if (count($relevant)){
-                                       ksort($relevant);
-                                       $tmp= array_keys($relevant);
-                                       $idx= end($tmp);
-                                       $tag= $relevant[$idx];
-                                       $this->gosaUnitTag= $tag;
-                               }
-                       }
-               }
-
-
-               /* Set tag? */
-               if ($tag != ""){
-                       /* Set objectclass and attribute */
-                       $ldap= $this->config->get_ldap_link();
-                       $ldap->cat($dn, array('gosaUnitTag', 'objectClass'));
-                       $attrs= $ldap->fetch();
-                       if(isset($attrs['gosaUnitTag'][0]) && $attrs['gosaUnitTag'][0] == $tag){
-                               echo sprintf(_("%s is already tagged"),$dn);
-                               return;
-                       }
-                       if (count($attrs)){
-                               echo sprintf(_("Add tagging (%s) to %s"),$tag,$dn);
-                               $nattrs= array("gosaUnitTag" => $this->gosaUnitTag);
-                               $nattrs['objectClass']= array();
-                               for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
-                                       $oc= $attrs['objectClass'][$i];
-                                       if ($oc != "gosaAdministrativeUnitTag"){
-                                               $nattrs['objectClass'][]= $oc;
-                                       }
-                               }
-                               $nattrs['objectClass'][]= "gosaAdministrativeUnitTag";
-                               $ldap->cd($dn);
-                               $ldap->modify($nattrs);
-                       } else {
-                               echo sprintf(_("Not tagging (%s) %s - seems to have moved away"),$tag,$dn);
-                       }
-
-               } else {
-                       /* Remove objectclass and attribute */
-                       $ldap= $this->config->get_ldap_link();
-                       $ldap->cat($dn, array('gosaUnitTag', 'objectClass'));
-                       $attrs= $ldap->fetch();
-                       if (isset($attrs['objectClass']) && !in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass'])){
-                               echo sprintf(_("%s is not tagged"),$dn);
-                               return;
-                       }
-                       if (count($attrs)){
-                               echo sprintf(_("Remove tagging from %s"),$dn);
-                               $nattrs= array("gosaUnitTag" => array());
-                               $nattrs['objectClass']= array();
-                               for ($i= 0; $i<$attrs['objectClass']['count']; $i++){
-                                       $oc= $attrs['objectClass'][$i];
-                                       if ($oc != "gosaAdministrativeUnitTag"){
-                                               $nattrs['objectClass'][]= $oc;
-                                       }
-                               }
-                               $ldap->cd($dn);
-                               $ldap->modify($nattrs);
-                               show_ldap_error($ldap->get_error());
-                       } else {
-                               echo sprintf(_("Not removing tag (%s) %s - seems to have moved away"),$tag,$dn);
-                       }
-               }
-       }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>