Code

Added "multiple action checkboxes" to object group list.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 18 Apr 2007 06:12:03 +0000 (06:12 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 18 Apr 2007 06:12:03 +0000 (06:12 +0000)
Remove multiple implemented too.

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6073 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/ogroups/class_divListOGroup.inc
plugins/admin/ogroups/class_ogroupManagement.inc
plugins/admin/ogroups/remove.tpl
plugins/admin/users/class_divListUsers.inc
plugins/admin/users/class_userManagement.inc

index ad23b1f3dd891d083ad125691a52bc8a7f7b16bf..5ac05bc7791c0596c10ad727188cb3e9bebe9a51 100755 (executable)
@@ -53,7 +53,12 @@ class divListOGroup 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='text-align:center;width:20px;'"));
     $this->AddHeader(array("string" => _("Name of object groups")." / "._("Departments"), "attach" => "style=''"));
     $this->AddHeader(array("string" => _("Properties"), "attach" => "style='width:136px;'"));
@@ -148,8 +153,13 @@ class divListOGroup extends MultiSelectWindow
     /* Add department selector */
     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
-      title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
-      "</div>";
+      title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
+
+    /* Multiple options */
+    $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
+        title='"._("Remove selected object groups")."' alt='"._("Remove object groups")."' name='remove_multiple_ogroups'>&nbsp;";
+
+    $listhead .="</div>";
 
     $this->SetListHeader($listhead);
   }
@@ -219,12 +229,15 @@ class divListOGroup extends MultiSelectWindow
       }else{
         $desc = " - [ ".$val['description'][0]." ]";
       }
+      /* Create each field */
+      $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
+                      "attach" => "style='width:20px;'");
       $field1 = array("string" => "<img src='images/list_ogroup.png' alt='"._("Object group")."' ".$title.">", "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, $this->parent->convert_list($val))."&nbsp;".$mail, "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 df051b4733936b8b2bb21eee776e581dc8eb9ed5..4f4317233f6c95f2afdd5808c064480a3db835c6 100644 (file)
@@ -59,7 +59,7 @@ class ogroupManagement extends plugin
       Variable intialisation && Check posts for commands  
      ****************/
 
-    $_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_ogroups/");
 
     $smarty     = get_smarty();
     $s_action   = "";
@@ -86,6 +86,8 @@ class ogroupManagement extends plugin
       }elseif(preg_match("/^cut_.*/",$key)){
         $s_action="cut";
         $s_entry  = preg_replace("/^cut_/i","",$key);
+      }elseif(preg_match("/^remove_multiple_ogroups/",$key)){
+        $s_action="del_multiple";
       }elseif(preg_match("/_group_edit_/",$key)){
         $type = preg_replace("/_group_edit_.*$/","",$key);
         $s_action="edit";
@@ -129,6 +131,84 @@ class ogroupManagement 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->ogrouplist[$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 object 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_ogroup_confirm'])){
+
+      /* Remove user by user and check acls before removeing them */
+      foreach($this->dns as $key => $dn){
+
+        $acl = $this->ui->get_permissions($dn, "ogroups");
+        if (preg_match('/d/', $acl)){
+
+          /* Delete request is permitted, perform LDAP action */
+          $this->ogroup= new ogrouptabs($this->config,$this->config->data['TABS']['OGROUPTABS'], $dn);
+          $this->ogroup->delete ();
+          gosa_log ("Object group'".$this->dn."' has been removed");
+          unset ($this->ogroup);
+          $this->ogroup= 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 object 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_ogroup_cancel'])){
+      foreach($this->dns as $key => $dn){
+        del_lock ($dn);
+        unset($this->dns[$key]);
+      }
+    }
+
+
     /****************
       Delete object group
      ****************/
@@ -152,6 +232,7 @@ class ogroupManagement 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 object group '%s'."), @LDAP::fix($this->dn)));
+        $smarty->assign("multiple", false);
         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
       } else {
 
@@ -321,7 +402,7 @@ class ogroupManagement extends plugin
 
     /* Add departments if subsearch is disabled */
     if(!$this->DivListOGroup->SubSearch){
-      $this->DivListOGroup->AddDepartments($this->DivListOGroup->selectedBase,4);
+      $this->DivListOGroup->AddDepartments($this->DivListOGroup->selectedBase,4,1);
     }
     $this->reload ();
     $this->DivListOGroup->setEntries($this->ogrouplist);
@@ -439,6 +520,19 @@ class ogroupManagement 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 copyPasteHandling($s_action,$s_entry)
   {
     if($this->CopyPasteHandler){
index fd14a5a671b2cc64e2920a78aa507bf499385490..720156b97792b42e358f8b48a4bf416f7978150c 100644 (file)
 </p>
 
 <p class="plugbottom">
-  <input type=submit name="delete_group_confirm" value="{t}Delete{/t}">
-  &nbsp;
-  <input type=submit name="delete_cancel" value="{t}Cancel{/t}">
+       {if $multiple}
+               <input type=submit name="delete_multiple_ogroup_confirm" value="{t}Delete{/t}">
+               &nbsp;
+               <input type=submit name="delete_multiple_ogroup_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>
 
index 177be0a36186be4914eb7ad77c679b5841b49b78..e5cec852ed47bcb8d3f472d32d6515e5bae98cdb 100644 (file)
@@ -138,7 +138,7 @@ class divListUsers extends MultiSelectWindow
   
     /* Multiple options */ 
     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
-        title='"._("Remove selected user")."' alt='"._("Remove user")."' name='remove_multiple_user'>&nbsp;";
+        title='"._("Remove selected user")."' alt='"._("Remove user")."' name='remove_multiple_users'>&nbsp;";
     
     $listhead .="</div>";;
     $this->SetListHeader($listhead);
index 9d24b558f2996da673e45c9a726be3b3c04f88ad..676e568b9ec5312f4693a596e4aafa3ca9cf21da 100644 (file)
@@ -79,7 +79,7 @@ class userManagement extends plugin
       foreach(array("del"       => "user_del",    "edit"      => "user_edit",
                     "new"       => "user_new",
                     "new_tpl"   => "user_tplnew",
-                    "del_multiple" => "^remove_multiple_user",
+                    "del_multiple" => "^remove_multiple_users",
                     "create_user_from_tpl"          => "userfrom_tpl",
                     "change_pw" => "user_chgpw", 
                     "editPaste" => "editPaste",   "copy"      => "copy",
@@ -305,8 +305,6 @@ class userManagement extends plugin
           $this->dns[$id] = $dn; 
         }
 
-
-
         $dns_names = "<br><pre>";
         foreach($this->dns as $dn){
           add_lock ($dn, $this->ui->dn);