From: hickert Date: Wed, 18 Apr 2007 10:12:19 +0000 (+0000) Subject: Added remove multiple to systems X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8eff07a45d20a2e77fa60a6799da0ec2bb6938eb;p=gosa.git Added remove multiple to systems git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6085 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/include/functions_dns.inc b/include/functions_dns.inc index 4754d8228..f24ec3247 100644 --- a/include/functions_dns.inc +++ b/include/functions_dns.inc @@ -434,6 +434,13 @@ function getDNSHostEntriesDiff($config,$oldName,$newEntry,$newName) $del = array(); $move = array(); + /* Don't go further if there is nothing to do + * Is no account / was no account + */ + if(($newEntry['exists'] == false )&& ($oldEntry['exists'] == false)){ + return(array("move"=>$move,"add"=>$add,"del"=>$del)); + } + $zones = getAvailableZones($config); $specialAttributes = array("cNAMERecord","pTRRecord"); $newRecords = array(); // Used to remember which records are removed @@ -455,13 +462,6 @@ function getDNSHostEntriesDiff($config,$oldName,$newEntry,$newName) $newEntry['exists'] = false; } - /* Don't go further if there is nothing to do - * Is no account / was no account - */ - if(($newEntry['exists'] == false )&& ($oldEntry['exists'] == false)){ - return(array("move"=>$move,"add"=>$add,"del"=>$del)); - } - /* If account was edited prepare some * attributes & arrays ... if required add some * dns to $move diff --git a/plugins/admin/systems/class_divListSystem.inc b/plugins/admin/systems/class_divListSystem.inc index eca9aa779..5615a0bd2 100644 --- a/plugins/admin/systems/class_divListSystem.inc +++ b/plugins/admin/systems/class_divListSystem.inc @@ -58,7 +58,12 @@ class divListSystem extends MultiSelectWindow $action_col_size += 38; } + /* Toggle all selected / deselected */ + $chk = ""; + /* set Page header */ + $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'")); $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'")); $this->AddHeader(array("string"=>_("System / Department"))); $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'")); @@ -187,8 +192,14 @@ class divListSystem extends MultiSelectWindow /* Add base selection */ $listhead .= _("Base")."  ". "  ". - ""; + title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> "; + + /* Multiple options */ + $listhead .= "  "; + + $listhead .=""; + $this->SetListHeader($listhead); } @@ -331,10 +342,15 @@ class divListSystem extends MultiSelectWindow } $img = $this->parent->convert_list($val); + + /* Create each field */ + $field0 = array("string" => "" , + "attach" => "style='width:20px;'"); + $field1 = array("string" => sprintf($img['img'],$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" => preg_replace("/%KEY%/", "$key", $action2.$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)); } } diff --git a/plugins/admin/systems/class_systemManagement.inc b/plugins/admin/systems/class_systemManagement.inc index 17a371c19..39e09bdbf 100644 --- a/plugins/admin/systems/class_systemManagement.inc +++ b/plugins/admin/systems/class_systemManagement.inc @@ -54,7 +54,7 @@ class systems extends plugin /* Call parent execute */ plugin::execute(); - $_SESSION['LOCK_VARS_TO_USE'] = array("/^system_edit_/i","/^system_del_/","/^act/","/^id/"); + $_SESSION['LOCK_VARS_TO_USE'] = array("/^system_edit_/i","/^system_del_/","/^act/","/^id/","/^item_selected/","/^remove_multiple_systems/"); /******************** Check for functional posts, edit|delete|add|... system devices @@ -85,6 +85,8 @@ class systems extends plugin }elseif(preg_match("/gen_cd_.*/i",$key)){ $s_action="gen_cd"; $s_entry = preg_replace("/gen_cd_/i","",$key); + }elseif(preg_match("/^remove_multiple_systems/i",$key)){ + $s_action="del_multiple"; }elseif(preg_match("/newsystem_.*/i",$key)){ $s_action="newsystem"; $s_entry = preg_replace("/newsystem_/i","",$key); @@ -425,6 +427,118 @@ class systems 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->terminals[$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("warning", 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_system_confirm'])){ + + $ui = get_userinfo(); + $tabs = array( + "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"), + "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"), + "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"), + "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"), + "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"), + "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"), + "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric")); + + + /* Remove user by user and check acls before removeing them */ + foreach($this->dns as $key => $dn){ + + /* Get 'dn' from posted termlinst */ + $attrs = $this->terminals[$key]; + $type= $this->get_system_type($attrs['objectClass']); + + /* get object type */ + $tabtype = "termtabs"; + $tabobj = "TERMTABS"; + $tabacl = ""; + if(isset($tabs[$type])){ + $tabtype = $tabs[$type]['TABCLASS']; + $tabobj = $tabs[$type]['CLASS']; + $tabacl = $ui->get_permissions($dn,$tabs[$type]['ACL']); + + /* Load permissions for selected 'dn' and check if + we're allowed to remove this 'dn' */ + if(preg_match("/d/",$tabacl)){ + + /* Delete request is permitted, perform LDAP action */ + if($tabtype=="phonetabs"){ + $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type); + $this->systab->set_acl_base($dn); + $this->systab->by_object['phonegeneric']->remove_from_parent (); + }else{ + $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $dn,$type); + $this->systab->set_acl_base($dn); + $this->systab->delete(); + } + unset ($this->systab); + gosa_log ("System object'".$dn."' has been removed"); + $this->systab= 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 component!")); + gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ". + "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_system_cancel'])){ + foreach($this->dns as $key => $dn){ + del_lock ($dn); + unset($this->dns[$key]); + } + } + + /******************** Delete system, confirm dialog ********************/ @@ -471,6 +585,7 @@ class systems extends plugin /* Lock the current entry, so nobody will edit it during deletion */ add_lock ($this->dn, $this->ui->dn); $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn))); + $smarty->assign("multiple", false); return($smarty->fetch(get_template_path('remove.tpl', TRUE))); } else { @@ -699,7 +814,7 @@ class systems extends plugin /* Add departments if subsearch is disabled */ if(!$this->DivListSystem->SubSearch){ - $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase); + $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase,3,1); } $this->reload(); $this->DivListSystem->setEntries($this->terminals); @@ -1080,6 +1195,19 @@ class systems 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); + } + + /* !! Incoming dummy acls, required to defined acls for incoming objects */ function plInfo() diff --git a/plugins/admin/systems/remove.tpl b/plugins/admin/systems/remove.tpl index c92e3fb57..dc5dbb2bd 100644 --- a/plugins/admin/systems/remove.tpl +++ b/plugins/admin/systems/remove.tpl @@ -11,7 +11,13 @@

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