Code

Added multiple remove to group list
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 17 Apr 2007 13:47:02 +0000 (13:47 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 17 Apr 2007 13:47:02 +0000 (13:47 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6071 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/groups/class_divListGroup.inc
plugins/admin/groups/class_groupManagement.inc
plugins/admin/groups/remove.tpl

index 70070da433a4ec3b0c0effed8b46bb031dcd82cd..518e36740b90c3ccc8cf1d7189665373edad52c9 100644 (file)
@@ -50,7 +50,12 @@ class divListGroup extends MultiSelectWindow
       $action_col_size += 38;
     }
 
+    /* Toggle all selected / deselected */
+    $chk = "<input type='checkbox' id='select_all' name='select_all'
+               onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
+
     /* set Page header */
+    $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
     $this->AddHeader(array("string"=>_("Groupname / Department")));
     $this->AddHeader(array("string"=>_("Properties"),"attach"=>"style='width:136px;'"));
@@ -146,9 +151,13 @@ class divListGroup extends MultiSelectWindow
     /* Add department selection */
     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
       " <input type='image' class='center' src='images/list_submit.png' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").
-      "'>&nbsp;".
-      "</div>";
+      "'>&nbsp;";
+
+    /* Multiple options */
+    $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
+        title='"._("Remove selected groups")."' alt='"._("Remove groups")."' name='remove_multiple_groups'>&nbsp;";
 
+    $listhead .= "</div>";
     $this->SetListHeader($listhead);
   }
 
@@ -249,12 +258,15 @@ class divListGroup extends MultiSelectWindow
         $desc .= " (".$val['FAIrelease'][0].")";
       }
 
+      $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
+          "attach" => "style='width:20px;'");
+
       $field1 = array("string" => sprintf($userimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
       $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
       $field3 = array("string" => preg_replace("/%KEY%/", $key, $posix."&nbsp;".$enviro."&nbsp;".$mail."&nbsp;".$samba."&nbsp;".$appl."&nbsp;".$phone),     "attach" => "style='width:136px;'");
       $field4 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
 
-      $this->AddElement(array($field1,$field2,$field3,$field4));
+      $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
     }
   }
 
index 09c4bf058613b626d3bf6378f999de00e24c0497..a7376241df13bfcb148290db2455ef1dd884c937 100644 (file)
@@ -67,7 +67,7 @@ class groupManagement extends plugin
        plugin::execute();
 
     /* Store these posts if the current object is locked (used by somebody else)*/
-    $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^group_edit_/","/^group_del_/");
+    $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^group_edit_/","/^group_del_/","/^item_selected/","/^remove_multiple_groups/");
 
     /* Save data */
     $s_action   = "";
@@ -106,6 +106,8 @@ class groupManagement extends plugin
       }elseif(preg_match("/^cut_.*/",$key)){
         $s_action="cut";
         $s_entry  = preg_replace("/^cut_/i","",$key);
+      }elseif(preg_match("/^remove_multiple_groups/",$key)){
+        $s_action="del_multiple";
       }
     }
     $s_entry  = preg_replace("/_.$/","",$s_entry); 
@@ -217,6 +219,121 @@ class groupManagement 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){
+          $dn = $this->grouplist[$id]['dn'];
+          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 */
+        $smarty->assign("info",     sprintf(_("You're about to delete the following group(s) %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_group_confirm'])){
+
+        /* Remove user by user and check acls before removeing them */
+        foreach($this->dns as $key => $dn){
+
+          $acl = $this->ui->get_permissions($dn, "users/user");
+          if (preg_match('/d/', $acl)){
+
+            /* Delete request is permitted, perform LDAP action */
+            $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
+            $this->usertab->set_acl_base();
+            $this->usertab->delete ();
+            gosa_log ("User object '".$dn."' has been removed");
+            unset ($this->usertab);
+            $this->usertab= NULL;
+          } else {
+            print_red (sprintf(_("You are not allowed to delete the user '%s'!"),$dn));
+            if(isset($this->ui->uid)){
+              gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
+            }
+          }
+          /* Remove lock file after successfull deletion */
+          del_lock ($dn);
+          unset($this->dns[$key]);
+      }
+    }
+
+
+    /********************
+      Delete MULTIPLE entries confirmed
+     ********************/
+
+      /* Confirmation for deletion has been passed. Users should be deleted. */
+      if (isset($_POST['delete_multiple_groups_confirm'])){
+
+        /* Remove user by user and check acls before removeing them */
+        foreach($this->dns as $key => $dn){
+
+          /* Load permissions for selected 'dn' and check if
+             we're allowed to remove this 'dn' */
+          $acl = $this->ui->get_permissions($this->dn,"groups/group");
+          if(preg_match("/d/",$acl)){
+
+            /* Delete request is permitted, perform LDAP action */
+            $this->grouptab= new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $this->dn);
+            $this->grouptab->set_acl_base($this->dn);
+            $this->grouptab->delete ();
+            gosa_log ("Group object'".$this->dn."' has been removed");
+            unset ($this->grouptab);
+            $this->grouptab= NULL;
+
+          } else {
+
+            /* Normally this shouldn't be reached, send some extra
+               logs to notify the administrator */
+            print_red (_("You are not allowed to delete this group!"));
+            gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
+          }
+          /* Remove lock file after successfull deletion */
+          del_lock ($dn);
+          unset($this->dns[$key]);
+        }
+      }
+
+
+      /********************
+        Delete MULTIPLE entries Canceled
+       ********************/
+
+      /* Remove lock */
+    if(isset($_POST['delete_multiple_user_cancel'])){
+      foreach($this->dns as $key => $dn){
+        del_lock ($dn);
+        unset($this->dns[$key]);
+      }
+    }
+
+
     /********************
       Delete group 
      ********************/
@@ -241,6 +358,7 @@ class groupManagement extends plugin
         /* Lock the current entry, so nobody will edit it during deletion */
         add_lock ($this->dn, $this->ui->dn);
         $smarty->assign("info", sprintf(_("You're about to delete the group '%s'."), @LDAP::fix($this->dn)));
+        $smarty->assign("multiple", false);
         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
 
       } else {
@@ -352,7 +470,7 @@ class groupManagement extends plugin
 
     /* Add departments if subsearch is disabled */
     if(!$this->DivListGroup->SubSearch){
-      $this->DivListGroup->AddDepartments($this->DivListGroup->selectedBase,4);
+      $this->DivListGroup->AddDepartments($this->DivListGroup->selectedBase,4,1);
     }
     $this->reload ();
     $this->DivListGroup->setEntries($this->grouplist);
@@ -367,6 +485,18 @@ class groupManagement extends plugin
   }
 
 
+  function list_get_selected_items()
+  {
+    $ids = array();
+    foreach($_POST as $name => $value){
+      if(preg_match("/^item_selected_[0-9]*$/",$name)){
+        $id   = preg_replace("/^item_selected_/","",$name);
+        $ids[$id] = $id;
+      }
+    }
+    return($ids);
+  }
+
 
   function reload($CreatePosixsList=false)
   {
index 1f3ff8b96601a3be4e701029b07255133c8f1d31..c91b28f7f564072b87626241cb4648584a7270e5 100644 (file)
 </p>
 
 <p class="plugbottom">
+
+  {if $multiple}
+  <input type=submit name="delete_multiple_group_confirm" value="{t}Delete{/t}">
+  &nbsp;
+  <input type=submit name="delete_multiple_group_cancel" value="{t}Cancel{/t}">
+  {else}
   <input type=submit name="delete_group_confirm" value="{t}Delete{/t}">
   &nbsp;
   <input type=submit name="delete_cancel" value="{t}Cancel{/t}">
+  {/if}
+
+
 </p>