Code

Updated ACL checks.
[gosa.git] / gosa-core / plugins / admin / departments / class_departmentGeneric.inc
index 390db7341d2ce0ad547a3571962b65d367a9633a..b3c8819e37d164da25dcdc2e26b0e6ed5a9ef8ee 100644 (file)
@@ -36,14 +36,10 @@ class department extends plugin
        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 ? 
 
        /* Headpage attributes */
        var $last_dep_sorting= "invalid";
        var $departments= array();
-
   var $must_be_tagged = false;
 
        /* attribute list for save action */
@@ -199,12 +195,6 @@ class department extends plugin
                return $this->must_be_tagged;
        }
 
-       function am_i_moved()
-       {
-               return $this->rec_cpy;
-       }
-
-
        /* Save data to object */
        function save_object()
        {
@@ -248,17 +238,15 @@ class department extends plugin
     $ldap->ls ("(&(ou=".$this->ou.")(objectClass=organizationalUnit))", $this->base, array('dn'));
     if ($this->orig_dn == "new" && $ldap->count()){
                        $message[]= msgPool::duplicated(_("Name"));
-               } elseif ($this->orig_dn != $this->dn && !($attrs === FALSE)){
+               } 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"));
                }
 
@@ -324,32 +312,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();
-    } else {
-      $this->attrs['gosaUnitTag']= $this->gosaUnitTag;
+      $this->gosaUnitTag = "";
     }
 
+
                /* Write back to ldap */
                $ldap->cat($this->dn, array('dn'));
                $ldap->cd($this->dn);
@@ -378,24 +361,6 @@ class department extends plugin
        }
 
 
-  function ShowMoveFrame()
-  {
-    $smarty = get_smarty();
-    $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);
-  }
-
-  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)
        {
@@ -458,13 +423,17 @@ 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")."'>
+        </form></div>";
+      echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
     }
        }
 
@@ -472,101 +441,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>";
+    /* 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 the destination entry exists */
-                       $ldap= $this->config->get_ldap_link();
+    /* 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);
+    }
 
-                       /* 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);
-                       }
+    /* Sort objects by indent level */
+    asort($objects);
+    reset($objects);
 
-                       /* 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);
-                       }
+    /* Copy objects from small to big indent levels by replacing src_dn by dst_dn */
+    foreach ($objects as $object => $len){
 
-                       /* 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){
+      $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>";
 
-                               $src= str_replace("\\","\\\\",$object);
-                               $dst= preg_replace("/".str_replace("\\","\\\\",$src_dn)."$/", "$dst_dn", $object);
-                               $dst= str_replace($src_dn,$dst_dn,$object);
+      $this->update_acls($object, $dst,TRUE);
 
-                               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>";
+        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->orig_dn  = $this->dn = $dst_dn;
+    $this->orig_base= $this->base;     
+    $this->entryCSN = getEntryCSN($this->dn);
 
-                       /* 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;
+    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 */ 
@@ -701,7 +653,47 @@ class department extends plugin
         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not removing tag ($tag) $dn - seems to have moved away", "Tagging");
       }
     }
+  }
+
+
+  
+  /*! \brief    Returns a list of all available departments for this object.
+                If this object is new, all departments we are allowed to create a new user in are returned.
+                If this is an existing object, return all deps. we are allowed to move tis object too.
+
+      @return   Array [dn] => "..name"  // All deps. we are allowed to act on.
+  */
+  function get_allowed_bases()
+  {
+    $ui = get_userinfo();
+    $deps = array();
+
+    /* Is this a new object ? Or just an edited existing object */
+    if(!$this->initially_was_account && $this->is_account){
+      $new = true;
+    }else{
+      $new = false;
+    }
+
+    $ideps = $this->config->idepartments;
+    if(!isset($ideps[$this->base])){
+      $ideps[$this->base] = ".";
+    }
+    foreach($deps as $dn => $name){
+      if($new && $this->acl_is_createable($dn)){
+        $deps[$dn] = $name;
+      }elseif(!$new && $this->acl_is_moveable($dn)){
+        $deps[$dn] = $name;
+      }
+    }
 
+    /* Add current base */
+    if(isset($this->base) && isset($ideps[$this->base])){
+      $deps[$this->base] = $ideps[$this->base];
+    }else{
+      trigger_error("Cannot return list of departments, no default base found in class ".get_class($this).". ".$this->base);
+    }
+    return($deps);
   }
 
 }