Code

Added remove multiple entries to macro list
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 19 Apr 2007 06:59:03 +0000 (06:59 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 19 Apr 2007 06:59:03 +0000 (06:59 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6108 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/gofon/macro/class_divListMacros.inc
plugins/gofon/macro/class_gofonMacroManagement.inc
plugins/gofon/macro/remove.tpl

index 0a78660d299b0b8f198531f7f2460be52c131fa6..d3712660b052f5545ee997596fc8a70e4ecea7e3 100755 (executable)
@@ -42,12 +42,17 @@ class divListMacro extends MultiSelectWindow
     $this->EnableSaveButton (false);
 
     /* Dynamic action col, depending on snapshot icons */
-    $action_col_size = 50;
+    $action_col_size = 60;
     if($this->parent->snapshotEnabled()){
       $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" => _("Macro name")." / "._("Department"), "attach" => "style=''"));
     $this->AddHeader(array("string" => _("Visible"), "attach" => "style='width:50px;'"));
@@ -105,9 +110,13 @@ class divListMacro extends MultiSelectWindow
     }
     $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 macros")."' alt='"._("Remove macros")."' name='remove_multiple_macros'>&nbsp;";
 
+    $listhead .="</div>";
     $this->SetListHeader($listhead);
   }
 
@@ -127,7 +136,7 @@ class divListMacro extends MultiSelectWindow
     $editlink   = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
 
     /* Dynamic action col, depending on snapshot icons */
-    $action_col_size = 50;
+    $action_col_size = 60;
     if($this->parent->snapshotEnabled()){
       $action_col_size += 20;
     }
@@ -172,13 +181,15 @@ class divListMacro extends MultiSelectWindow
         $display .= "&nbsp;[".$desc."]";
       }
 
-
+      /* 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($macroimg,$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" => $pic1, "attach" => "style='width:50px;'");
       $field4 = 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,$field4));
+      $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
     }
   }
 
index b3ba05728e85842e808ffb0a116ee69ca10579f5..8f670bb89564fc6b88100de70202b5b59987457d 100755 (executable)
@@ -45,7 +45,7 @@ class gofonMacro extends plugin
     /* Call parent execute */
     plugin::execute();
 
-    $_SESSION['LOCK_VARS_TO_USE'] = array("/^goFonMacro_/","/^act$/","/^id$/");
+    $_SESSION['LOCK_VARS_TO_USE'] = array("/^goFonMacro_/","/^act$/","/^id$/","/^item_selected/","/^remove_multiple_macros/");
 
     /*****************
       Variable initialisation
@@ -74,6 +74,8 @@ class gofonMacro extends plugin
         // Post for new
       }elseif(preg_match("/^goFonMacro_new/",$key)){
         $s_action="new";
+      }elseif(preg_match("/^remove_multiple_macros/",$key)){
+        $s_action="del_multiple";
       }
     }
     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
@@ -180,10 +182,88 @@ class gofonMacro 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->macros[$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("intro",     sprintf(_("You're about to delete the following user(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_macro_confirm'])){
+
+      /* Remove user by user and check acls before removeing them */
+      foreach($this->dns as $key => $dn){
+
+        $acl = $this->ui->get_permissions($dn,"gofonmacro/macro");
+        if(preg_match("/d/",$acl)){
+
+          /* Delete request is permitted, perform LDAP action */
+          $this->macrotabs= new macrotabs($this->config,$this->config->data['TABS']['MACROTABS'], $dn,"gofonmacro");
+          $this->macrotabs->delete ();
+          gosa_log ("macro object'".$dn."' has been removed");
+          unset ($this->macrotabs);
+          $this->macrotabs= NULL;
+
+        } else {
+          print_red (_("You are not allowed to delete this macro!"));
+        }
+
+        /* Remove lock file after successfull deletion */
+        del_lock ($dn);
+        unset($this->dns[$key]);
+      }
+    }
+
+
+    /********************
+      Delete MULTIPLE entries Canceled
+     ********************/
+
+    /* Remove lock */
+    if(isset($_POST['delete_multiple_macro_cancel'])){
+      foreach($this->dns as $key => $dn){
+        del_lock ($dn);
+        unset($this->dns[$key]);
+      }
+    }
+
+
     /*****************
       Remove macro
      *****************/
-    
+
     /* Remove user was requested */
     if ($s_action=="del"){
 
@@ -284,7 +364,7 @@ class gofonMacro extends plugin
 
     /* Add departments if subsearch is disabled */
     if(!$this->DivListMacro->SubSearch){
-      $this->DivListMacro->AddDepartments($this->DivListMacro->selectedBase,4);
+      $this->DivListMacro->AddDepartments($this->DivListMacro->selectedBase,4,1);
     }
     $this->reload();
     $this->DivListMacro->setEntries($this->macros);
@@ -340,6 +420,19 @@ class gofonMacro 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 adapt_from_template($dn)  { }
   function check() { }
 }
index d38ef8c366e7470b77419ffbaa8a4f3e57892342..4dbd248c545d6a329e79419beb8b38027c987964 100755 (executable)
 </p>
 
 <p class="plugbottom">
- <input type=submit name="delete_macro_confirm" value="{t}Delete{/t}">
- &nbsp;
- <input type=submit name="delete_cancel" value="{t}Cancel{/t}">
+       {if $multiple}
+               <input type=submit name="delete_multiple_macro_confirm" value="{t}Delete{/t}">
+               &nbsp;
+               <input type=submit name="delete_multiple_macro_cancel" value="{t}Cancel{/t}">
+       {else}
+               <input type=submit name="delete_macro_confirm" value="{t}Delete{/t}">
+               &nbsp;
+               <input type=submit name="delete_cancel" value="{t}Cancel{/t}">
+       {/if}
 </p>