From 0ba0523d6581cbaa52ec203f04a1823650512f4c Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 19 Apr 2007 06:59:03 +0000 Subject: [PATCH] Added remove multiple entries to macro list git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6108 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/gofon/macro/class_divListMacros.inc | 23 +++-- .../macro/class_gofonMacroManagement.inc | 99 ++++++++++++++++++- plugins/gofon/macro/remove.tpl | 12 ++- 3 files changed, 122 insertions(+), 12 deletions(-) diff --git a/plugins/gofon/macro/class_divListMacros.inc b/plugins/gofon/macro/class_divListMacros.inc index 0a78660d2..d3712660b 100755 --- a/plugins/gofon/macro/class_divListMacros.inc +++ b/plugins/gofon/macro/class_divListMacros.inc @@ -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 = ""; + /* set Page header */ + $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'")); $this->AddHeader(array("string" => " ", "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")." ". "  ". - ""; + title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> "; + + /* Multiple options */ + $listhead .= "  "; + $listhead .=""; $this->SetListHeader($listhead); } @@ -127,7 +136,7 @@ class divListMacro extends MultiSelectWindow $editlink = "%s"; /* 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 .= " [".$desc."]"; } - + /* Create each field */ + $field0 = array("string" => "" , + "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('/ /', ' ', @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)); } } diff --git a/plugins/gofon/macro/class_gofonMacroManagement.inc b/plugins/gofon/macro/class_gofonMacroManagement.inc index b3ba05728..8f670bb89 100755 --- a/plugins/gofon/macro/class_gofonMacroManagement.inc +++ b/plugins/gofon/macro/class_gofonMacroManagement.inc @@ -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 = "
";
+        foreach($this->dns as $dn){
+          add_lock ($dn, $this->ui->dn);
+          $dns_names .= $dn."\n";
+        }
+        $dns_names .="
"; + + /* 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() { } } diff --git a/plugins/gofon/macro/remove.tpl b/plugins/gofon/macro/remove.tpl index d38ef8c36..4dbd248c5 100755 --- a/plugins/gofon/macro/remove.tpl +++ b/plugins/gofon/macro/remove.tpl @@ -10,8 +10,14 @@

- -   - + {if $multiple} + +   + + {else} + +   + + {/if}

-- 2.30.2