Code

Added remove multiple objects
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 18 Apr 2007 13:35:41 +0000 (13:35 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 18 Apr 2007 13:35:41 +0000 (13:35 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6093 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/gofax/blocklists/class_blocklistManagement.inc
plugins/gofax/blocklists/class_divListBlocklists.inc
plugins/gofax/blocklists/remove.tpl

index d3e7377803a8848f3105b9a1001675d145432a5d..a002dfcb8dac9cd1a3ca537dadaabc375ba451b1 100644 (file)
@@ -39,7 +39,7 @@ class blocklist extends plugin
     /* Call parent execute */
     plugin::execute();
 
-    $_SESSION['LOCK_VARS_TO_USE'] = array("/^goFaxBlocklist_/","/^act$/","/^id$/");
+    $_SESSION['LOCK_VARS_TO_USE'] = array("/^goFaxBlocklist_/","/^act$/","/^id$/","/^remove_multiple_blocklists/","/^item_selected/");
 
     /***************
       Init vars 
@@ -69,6 +69,8 @@ class blocklist extends plugin
         // Post for new
       }elseif(preg_match("/^goFaxBlocklist_new.*/",$key)){
         $s_action="new";
+      }elseif(preg_match("/^remove_multiple_blocklists/",$key)){
+        $s_action="del_multiple";
       }
     }
 
@@ -149,6 +151,76 @@ class blocklist extends plugin
     }
 
 
+    /********************
+      Delete MULTIPLE entries requested, display confirm dialog
+     ********************/
+
+    if ($s_action=="del_multiple"){
+
+      $this->dns = array();
+      $ids = $this->list_get_selected_items();
+
+      if(count($ids)){
+        foreach($ids as $id){
+          $dn = $this->blocklists[$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 blocklists(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_blocklist_confirm'])){
+
+      /* Remove user by user and check acls before removeing them */
+      foreach($this->dns as $key => $dn){
+        $acl = $this->ui->get_permissions($dn, "blocklist/blocklist");
+        if (preg_match('/d/', $acl)){
+          $this->dn = $dn;
+          $this->remove_from_parent();
+        } else {
+          print_red (sprintf(_("You are not allowed to delete the blocklist '%s'!"),$dn));
+        }
+        /* Remove lock file after successfull deletion */
+        del_lock ($dn);
+        unset($this->dns[$key]);
+      }
+      $this->reload();
+    }
+
+
+    /********************
+      Delete MULTIPLE entries Canceled
+     ********************/
+
+    /* Remove lock */
+    if(isset($_POST['delete_multiple_blocklist_cancel'])){
+      foreach($this->dns as $key => $dn){
+        del_lock ($dn);
+        unset($this->dns[$key]);
+      }
+    }
+
+
     /***************
       Remove blocklist
      ***************/
@@ -165,6 +237,7 @@ class blocklist extends plugin
         add_lock ($this->dn, $this->ui->dn);
 
         $smarty->assign("info", sprintf(_("You're about to delete the blocklist '%s'."), $this->dn));
+        $smarty->assign("multiple", false);
         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
       }
     }
@@ -351,7 +424,7 @@ class blocklist extends plugin
 
       /* Add departments if subsearch is disabled */
       if(!$this->DivListBlocklist->SubSearch){
-        $this->DivListBlocklist->AddDepartments($this->DivListBlocklist->selectedBase);
+        $this->DivListBlocklist->AddDepartments($this->DivListBlocklist->selectedBase,3,1);
       }
       $this->reload();
       $this->DivListBlocklist->setEntries($this->blocklists);
@@ -360,6 +433,19 @@ class blocklist 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);
+  }
+
+
   /* Return departments, that will be included within snapshot detection */
   function get_used_snapshot_bases()
   {
index f96f64c435a23f8262235269cbe7b7f9f9523ee9..02c616324a8ca285fd80ee9b7d540145e65d01a2 100755 (executable)
@@ -47,7 +47,12 @@ class divListBlocklist extends MultiSelectWindow
       $action_col_size += 20;
     }
 
+    /* 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" => _("Blocklist name")." / "._("Department"), "attach" => "style=''"));
     $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'" ));
@@ -114,8 +119,13 @@ class divListBlocklist extends MultiSelectWindow
     /* Append department selector */
     $listhead .= "&nbsp;"._("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 blocklists")."' alt='"._("Remove blocklists")."' name='remove_multiple_blocklists'>&nbsp;";
+
+    $listhead .="</div>";
 
     $this->SetListHeader($listhead);
   }
@@ -167,10 +177,15 @@ class divListBlocklist extends MultiSelectWindow
       }else{
         $display= $val["cn"][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" => sprintf($blockimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
       $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
-      $this->AddElement( array($field1,$field2,$field3));
+      $this->AddElement( array($field0,$field1,$field2,$field3));
     }
   }
 
index 6784741a48d2e688e3356cf4a9cb794d113c316f..ebea1e3ca9e8aa450846dd9567a5024660511295 100644 (file)
 </p>
 
 <p class="plugbottom">
-  <input type=submit name="delete_blocklist_confirm" value="{t}Delete{/t}">
-  &nbsp;
-  <input type=submit name="delete_blocklist_cancel" value="{t}Cancel{/t}">
+       {if $multiple}
+               <input type=submit name="delete_multiple_blocklist_confirm" value="{t}Delete{/t}">
+               &nbsp;
+               <input type=submit name="delete_multiple_blocklist_cancel" value="{t}Cancel{/t}">
+       {else}
+               <input type=submit name="delete_blocklist_confirm" value="{t}Delete{/t}">
+               &nbsp;
+               <input type=submit name="delete_blocklist_cancel" value="{t}Cancel{/t}">
+       {/if}
 </p>