Code

Updated trunk, introduced gosa-core
[gosa.git] / plugins / admin / departments / class_departmentManagement.inc
index 8ba8550ea3147e7e7ec1b1a930c69c738f7d969e..e2db188d1d4ad28d260a66edc56c446634a3340e 100644 (file)
@@ -17,7 +17,6 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-require "tabs_department.inc";
 
 class departmentManagement extends plugin
 {
@@ -45,11 +44,11 @@ class departmentManagement extends plugin
   var $ObjectTaggingRequested   = false;    // Object must be tagged, an iframe will be shown. 
   var $RecursiveRemoveRequested = false;    // Is true, if this object must be moved, an iframe will be displayed in this case
 
-  function departmentManagement ($config, $ui)
+  function departmentManagement (&$config, &$ui)
   {
-    $this->ui= $ui;
+    $this->ui= &$ui;
     $this->dn= "";
-    $this->config= $config;
+    $this->config= &$config;
     $this->DivListDepartment = new divListDepartment($this->config,$this);
   }
 
@@ -64,7 +63,7 @@ class departmentManagement extends plugin
       Var init 
      ***************/
 
-    $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^dep_edit_.*/","/^dep_del_.*/");
+    $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^dep_edit_.*/","/^dep_del_.*/","/^item_selected/","/^remove_multiple_departments/");
 
     /* Reload departments */
     $smarty                                            = get_smarty();
@@ -92,10 +91,21 @@ class departmentManagement extends plugin
         $s_entry  = preg_replace("/_.*$/","",$s_entry);
         $s_entry  = base64_decode($s_entry);
         // Post for new
+      }elseif(preg_match("/^remove_multiple_departments/",$key)){
+        $s_action="del_multiple";
       }elseif(preg_match("/dep_new.*/",$key)){
         $s_action="new";
       }
+    }
+
+    /* Create options */
+    if(isset($_POST['menu_action']) && $_POST['menu_action'] == "dep_new"){
+      $s_action = "new";
+    }
 
+    /* handle remove from layers menu */
+    if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
+      $s_action = "del_multiple";
     }
 
 
@@ -137,6 +147,84 @@ class departmentManagement extends plugin
     }
 
 
+    /********************
+      Delete MULTIPLE entries requested, display confirm dialog
+     ********************/
+
+    if ($s_action=="del_multiple"){
+      $ids = $this->list_get_selected_items();
+
+
+      if(count($ids)){
+        foreach($ids as $id){
+          $id = base64_decode($id);
+          $dn = $this->config->departments[$id];
+  
+          if (($user= get_lock($dn)) != ""){
+            return(gen_locked_message ($user, $dn));
+          }
+          $this->dns[$id] = $dn;
+        }
+
+        $dns_names = "<br><pre>";
+        foreach($this->dns as $dn){
+          add_lock ($dn, $this->ui->dn);
+          $dns_names .= $dn."\n";
+        }
+        $dns_names .="</pre>";
+
+        /* Lock the current entry, so nobody will edit it during deletion */
+        if (count($this->dns) == 1){
+          $smarty->assign("info",     sprintf(_("You're about to delete the following entry %s"), @LDAP::fix($dns_names)));
+        } else {
+          $smarty->assign("info",     sprintf(_("You're about to delete the following entries %s"), @LDAP::fix($dns_names)));
+        }
+        $smarty->assign("multiple", true);
+        return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
+      }
+    }
+   
+
+    /********************
+      Delete MULTIPLE entries confirmed
+     ********************/
+
+    /* Confirmation for deletion has been passed. Users should be deleted. */
+    if (isset($_POST['delete_multiple_department_confirm'])){
+
+      /* Remove user by user and check acls before removeing them */
+      foreach($this->dns as $key => $dn){
+        $acl = $this->ui->get_permissions($dn,"department/department");
+        if (preg_match('/d/', $acl)){
+
+          /* Delete request is permitted, perform LDAP action */
+          $this->deptabs= new deptabs($this->config,$this->config->data['TABS']['DEPTABS'], $dn,"department");
+          $this->deptabs->set_acl_base();
+          $this->deptabs->delete ();
+          $this->deptabs = NULL;
+        } else {
+          print_red (_("You have no permission to remove this department."));
+        }
+        /* Remove lock file after successfull deletion */
+        del_lock ($dn);
+        unset($this->dns[$key]);
+      }
+    }
+
+    /********************
+      Delete MULTIPLE entries Canceled
+     ********************/
+
+    /* Remove lock */
+    if(isset($_POST['delete_multiple_department_cancel'])){
+      foreach($this->dns as $key => $dn){
+        del_lock ($dn);
+        unset($this->dns[$key]);
+      }
+    }
+
+
     /***************
       Delete entry 
      ***************/
@@ -147,15 +235,23 @@ class departmentManagement extends plugin
     if ($s_action =="del"){
       $this->dn= $this->config->departments[trim($s_entry)];
 
-      /* Check locking */
-      if (($user= get_lock($this->dn)) != ""){
-        $_SESSION['dn']= $this->dn;
-        return(gen_locked_message($user, $this->dn));
-      } else {
-        add_lock ($this->dn, $this->ui->dn);
-        $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), @LDAP::fix($this->dn)));
-        $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
-        return ($display);
+      /* check acls */
+      $acl = $this->ui->get_permissions($this->dn,"department/department");
+      if(preg_match("/d/",$acl)){
+
+        /* Check locking */
+        if (($user= get_lock($this->dn)) != ""){
+          $_SESSION['dn']= $this->dn;
+          return(gen_locked_message($user, $this->dn));
+        } else {
+          add_lock ($this->dn, $this->ui->dn);
+          $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), @LDAP::fix($this->dn)));
+          $smarty->assign("multiple", false);
+          $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
+          return ($display);
+        }
+      }else{
+        print_red (_("You have no permission to remove this department."));
       }
     }
 
@@ -168,9 +264,11 @@ class departmentManagement extends plugin
      * Finally delete department 
      */
     if (isset($_POST['delete_department_confirm'])){
-      if($this->acl_is_removeable()){
+
+      /* check acls */
+      $acl = $this->ui->get_permissions($this->dn,"department/department");
+      if(preg_match("/d/",$acl)){
         $this->remove_from_parent();
-        gosa_log ("Department object'".$this->dn."' has been removed");
       } else {
         print_red (_("You have no permission to remove this department."));
       }
@@ -181,7 +279,18 @@ class departmentManagement extends plugin
       Edit department finished 
      ***************/
 
-    if ((isset($_POST['edit_finish'])) && (isset($this->deptabs->config))){
+    if ((isset($_POST['edit_finish'])) && (isset($this->deptabs->config)) && !isset($_POST['dep_move_confirm'])){
+      $this->deptabs->save_object();
+      $obj = $this->deptabs->by_object['department'];
+      if($obj->orig_dn != "new"){
+        if($obj->orig_ou != $obj->ou || $obj->base != $obj->orig_base){
+          return($smarty->fetch(get_template_path("dep_move_confirm.tpl",TRUE)));
+        }
+      }
+    }
+
+    /* Save changes */
+    if ((isset($_POST['edit_finish'])|| isset($_POST['dep_move_confirm'])) && (isset($this->deptabs->config))){
 
       /* Check tabs, will feed message array */
       $message= $this->deptabs->check();
@@ -190,7 +299,10 @@ class departmentManagement extends plugin
       if (count($message) == 0){
 
         $this->deptabs->save(true);
-        $this->deptabs->by_object['department']->save();     
+        global $config;
+        $config->get_departments();
+        $config->make_idepartments();
+        $this->config = $config;
 
         /* This object must be tagged, so set ObjectTaggingRequested to true */
         if($this->deptabs->by_object['department']->must_be_tagged()){
@@ -231,6 +343,7 @@ class departmentManagement extends plugin
     /* initiate recursive remove  (Is called from iframe, generates output)*/
     if(isset($_GET['PerformRecMove'])){
       $this->deptabs->by_object['department']->recursive_move("","",true);
+      $this->DivListDepartment->selectedBase = $this->deptabs->by_object['department']->dn;  
       exit();
     }
 
@@ -259,11 +372,11 @@ class departmentManagement extends plugin
        remove locks & save object tab & unset current object */
     if($this->ObjectInSaveMode && (!$this->RecursiveRemoveRequested) && (!$this->ObjectTaggingRequested)){
       $this->deptabs->save();
+      $this->config->get_departments();
       $this->ObjectInSaveMode = false;
       if ($this->dn != "new"){
         del_lock ($this->dn);
       }
-      gosa_log ("Department object'".$this->dn."' has been saved");
       unset ($this->deptabs);
       $this->deptabs= NULL;
       unset ($_SESSION['objectinfo']);
@@ -285,7 +398,7 @@ class departmentManagement extends plugin
     }
 
     /* Headpage or normal plugin screen? */
-    if ($this->deptabs != NULL){
+    if ($this->deptabs !== NULL){
 
       /* Show main page (tabs) */
       $display= $this->deptabs->execute();
@@ -327,7 +440,7 @@ class departmentManagement extends plugin
       if(empty($tmp2['dn'])){
         $tmp2['dn']="/";
       }
-      $tmp2    ['description'][0] = _("..");
+      $tmp2    ['description'][0] = ".. "._("Back");
       $result[$tmp[$base_back]]=$tmp2;
     }
 
@@ -386,6 +499,20 @@ class departmentManagement extends plugin
 
   }
 
+
+  function list_get_selected_items()
+  {
+    $ids = array();
+    foreach($_POST as $name => $value){
+      if(preg_match("/^item_selected_[a-z0-9\\/\=]*$/i",$name)){
+        $id   = preg_replace("/^item_selected_/","",$name);
+        $ids[$id] = $id;
+      }
+    }
+    return($ids);
+  }
+
+
   function remove_lock()
   {
     if (isset($this->dn)){