From 93e6cb8b2b4e60a82666170234cf4e5ac1ffd05a Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 20 Feb 2008 13:29:27 +0000 Subject: [PATCH] Updated gotomasses -Use an extra class for the target list dialog git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8987 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../gotomasses/events/class_DaemonEvent.inc | 157 ++---------- .../events/class_EventTargetAddList.inc | 230 ++++++++++++++++++ 2 files changed, 246 insertions(+), 141 deletions(-) create mode 100644 gosa-plugins/goto/addons/gotomasses/events/class_EventTargetAddList.inc diff --git a/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent.inc b/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent.inc index 88af593b7..90a6aecec 100644 --- a/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent.inc +++ b/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent.inc @@ -190,113 +190,28 @@ class DaemonEvent public function get_target_add_list() { $this->target_add_list_used = TRUE; - $smarty = get_smarty(); - if($this->target_divlist == NULL){ - $this->target_divlist = new MultiSelectWindow($this->config,"EventAddTargedtList","gotomasses"); - $this->target_divlist->SetSummary(_("Targets")); - $this->target_divlist->SetInformation(_("This dialog shows all available targets for your event, check the targets you want to add and use the 'Use' button to accept.")); - $this->target_divlist->EnableCloseButton(FALSE); - $this->target_divlist->EnableSaveButton(FALSE); - - - /* Toggle all selected / deselected */ - $chk = ""; - - $this->target_divlist->EnableAplhabet(TRUE); - - /* set Page header */ - $this->target_divlist->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'")); - $this->target_divlist->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'")); - $this->target_divlist->AddHeader(array("string"=>_("System / Department"))); - - //$name,$string,$value,$conn,$image="images/search.png") - $this->target_divlist->AddRegex("regex" ,"regex" ,"*" , TRUE); - $this->target_divlist->AddRegex("ipfrom","ipfrom" ,"0.0.0.0" , FALSE); - $this->target_divlist->AddRegex("ipto" ,"ipto" ,"255.255.255.255" , FALSE); - - $this->target_divlist->display_server = TRUE; - $this->target_divlist->display_workstation = TRUE; - $this->target_divlist->display_ogroup = TRUE; - $this->target_divlist->filter_iprange = FALSE; - $this->target_divlist->AddCheckBox("display_server","1" ,_("Display server"),TRUE); - $this->target_divlist->AddCheckBox("display_workstation","1",_("Display workstation"),TRUE); - $this->target_divlist->AddCheckBox("display_ogroup","1" ,_("Display object groups"),TRUE); - $this->target_divlist->AddCheckBox("filter_iprange","1" ,_("Filter by IP range"),FALSE); - - } - $this->target_divlist->ClearElementsList(); - - $modules = array("server","workstation"); - - /* Add base */ - $tmp = array(); - $base = $this->config->current['BASE']; - $tmp[] = array("dn"=>$this->config->current['BASE']); - $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $modules, $base, - array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH)); - - $deps = array(); - foreach($tmp as $tm){ - $deps[$tm['dn']] = $tm['dn']; + if(1 | $this->target_divlist == NULL){ + $this->target_divlist = new EventTargetAddList($this->config,$this); } - - $department = $departments = array(); - $ui= get_userinfo(); - $d = $ui->get_module_departments($modules); - foreach($d as $department){ - $departments[$department] = $department; - } - - /* Load possible departments */ - $ids = $this->config->idepartments; - $first = ""; - $found = FALSE; - $options = array(); - foreach($ids as $dep => $name){ - if(isset($deps[$dep]) && in_array_ics($dep, $departments)){ - - /* Keep first base dn in mind, we could need this - * info if no valid base was found - */ - if(empty($first)) { - $first = $dep['dn']; - } - - $value = $ids[$dep]; - if ($this->target_divlist->selectedBase == $dep){ - $found = TRUE; - $options.= ""; - } else { - $options.= ""; - } - } - } - - $listhead = $this->target_divlist->get_default_header(); - - /* Add base selection */ - $listhead .= _("Base")."  ". - "  "; - - $this->target_divlist->SetListHeader($listhead); - $this->target_divlist->AddDepartments($this->target_divlist->selectedBase,2,1); + $this->target_divlist->execute(); $_target_list = array(); if($this->target_divlist->display_server){ - $_target_list = array_merge($_target_list,get_list("(&(cn=".$this->target_divlist->regex.")(objectClass=goServer))", + $_target_list = array_merge($_target_list, + get_list("(&(cn=".$this->target_divlist->regex.")(objectClass=goServer))", "server",get_ou("serverou").$this->target_divlist->selectedBase, array("cn","objectClass","description","ipHostNumber","macAddress"),GL_NONE)); } if($this->target_divlist->display_workstation){ - $_target_list = array_merge($_target_list,get_list("(&(cn=".$this->target_divlist->regex.")(objectClass=gotoWorkstation))", + $_target_list = array_merge($_target_list, + get_list("(&(cn=".$this->target_divlist->regex.")(objectClass=gotoWorkstation))", "workstation",get_ou("workstationou").$this->target_divlist->selectedBase, array("cn","objectClass","description","ipHostNumber","macAddress"),GL_NONE)); } if($this->target_divlist->display_ogroup){ - $_target_list = array_merge($_target_list,get_list("(&(cn=".$this->target_divlist->regex.")(member=*)(objectClass=gosaGroupOfNames))", + $_target_list = array_merge($_target_list, + get_list("(&(cn=".$this->target_divlist->regex.")(member=*)(objectClass=gosaGroupOfNames))", "ogroups",get_ou("ogroupou").$this->target_divlist->selectedBase, array("cn","objectClass","description","member"),GL_NONE)); } @@ -307,58 +222,18 @@ class DaemonEvent $tmp[$key] = $object['cn'][0]; } natcasesort($tmp); - - foreach($tmp as $key => $dummy){ - - $obj = $this->_target_list[$key]; - - $name = $obj['cn'][0]; - if(isset($obj['description'])){ - $name .= " [".$obj['description'][0]."]"; - } - if(isset($obj['macAddress'])){ - $name .= " - ".$obj['macAddress'][0].""; - } - if(isset($obj['ipHostNumber'])){ - $name .= " - ".$obj['ipHostNumber'][0].""; - } - - $img =""; - if(in_array("goServer",$obj['objectClass'])){ - $img = 'S'; - - if($this->target_divlist->filter_iprange){ - if(!isset($obj['ipHostNumber']) || !tests::is_in_ip_range($this->target_divlist->ipfrom,$this->target_divlist->ipto,$obj['ipHostNumber'][0])) { - continue; - } - } - if(!isset($this->server_list[$obj['dn']])){ - continue; - } - }elseif(in_array("gotoWorkstation",$obj['objectClass'])){ - $img = 'W'; - if($this->target_divlist->filter_iprange){ - if(!isset($obj['ipHostNumber']) || !tests::is_in_ip_range($this->target_divlist->ipfrom,$this->target_divlist->ipto, $obj['ipHostNumber'][0])) { - continue; - } - } - if(!isset($this->workstation_list[$obj['dn']])){ - continue; - } - }elseif(in_array("gosaGroupOfNames",$obj['objectClass'])){ - $img = 'O'; - } - - $field1 = array("string" => ""); - $field2 = array("string" => $img); - $field3 = array("string" => $name , "attach" => "title='".$obj['dn']."'"); - $this->target_divlist->AddElement(array($field1,$field2,$field3)); + $tmp2 = array(); + foreach($tmp as $key => $sort){ + $tmp2[] = $this->_target_list[$key]; } - $smarty->assign("divlist",$this->target_divlist->Draw()); + $this->target_divlist->setEntries($tmp2); + $smarty = get_smarty(); + $smarty->assign("divlist",$this->target_divlist->Draw()); return($smarty->fetch(get_template_path('target_list.tpl', TRUE, dirname(__FILE__)))); } + public function save_object() { diff --git a/gosa-plugins/goto/addons/gotomasses/events/class_EventTargetAddList.inc b/gosa-plugins/goto/addons/gotomasses/events/class_EventTargetAddList.inc new file mode 100644 index 000000000..4d68d6233 --- /dev/null +++ b/gosa-plugins/goto/addons/gotomasses/events/class_EventTargetAddList.inc @@ -0,0 +1,230 @@ +parent = $parent; + $this->ui = get_userinfo(); + + + $this->target_divlist = new MultiSelectWindow($this->config,"EventAddTargedtList","gotomasses"); + $this->SetSummary(_("Targets")); + $this->EnableCloseButton(FALSE); + $this->EnableSaveButton(FALSE); + + $this->SetInformation(_("This dialog shows all available targets for your event, check the targets you want to add and use the 'Use' button to accept.")); + + /* Toggle all selected / deselected */ + $chk = ""; + + $this->EnableAplhabet(TRUE); + + /* 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"))); + + //$name,$string,$value,$conn,$image="images/search.png") + $this->AddRegex("regex" ,"regex" ,"*" , TRUE); + $this->AddRegex("ipfrom","ipfrom" ,"0.0.0.0" , FALSE); + $this->AddRegex("ipto" ,"ipto" ,"255.255.255.255" , FALSE); + + $this->AddCheckBox("display_server","1" ,_("Display server"),TRUE); + $this->AddCheckBox("display_workstation","1",_("Display workstation"),TRUE); + $this->AddCheckBox("display_ogroup","1" ,_("Display object groups"),TRUE); + $this->AddCheckBox("filter_iprange","1" ,_("Filter by IP range"),FALSE); + + + + /* Create a list of servers + */ + $tmp = get_sub_list("(&(macAddress=*)(objectClass=goServer))", + "server",get_ou("serverou"),$config->current['BASE'], + array("cn","objectClass","description","ipHostNumber","macAddress"),GL_SUBSEARCH); + foreach($tmp as $server){ + $this->server_list[$server['dn']] = $server; + } + + /* Create a list of workstations + */ + $tmp = get_sub_list("(&(macAddress=*)(objectClass=gotoWorkstation))", + "server",get_ou("workstationou"),$config->current['BASE'], + array("cn","objectClass","description","ipHostNumber","macAddress"),GL_SUBSEARCH); + foreach($tmp as $server){ + $this->workstation_list[$server['dn']] = $server; + } + + } + + + function execute() + { + $this->ClearElementsList(); + $this->AddDepartments($this->selectedBase,2,1); + $this->GenHeader(); + } + + + function GenHeader() + { + $modules = array("server","workstation"); + + /* Add base */ + $tmp = array(); + $base = $this->config->current['BASE']; + $tmp[] = array("dn"=>$this->config->current['BASE']); + $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $modules, $base, + array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH)); + + $deps = array(); + foreach($tmp as $tm){ + $deps[$tm['dn']] = $tm['dn']; + } + + $department = $departments = array(); + $ui= get_userinfo(); + $d = $ui->get_module_departments($modules); + foreach($d as $department){ + $departments[$department] = $department; + } + + /* Load possible departments */ + $ids = $this->config->idepartments; + $first = ""; + $found = FALSE; + $options = array(); + foreach($ids as $dep => $name){ + if(isset($deps[$dep]) && in_array_ics($dep, $departments)){ + + /* Keep first base dn in mind, we could need this + * info if no valid base was found + */ + if(empty($first)) { + $first = $dep['dn']; + } + + $value = $ids[$dep]; + if ($this->selectedBase == $dep){ + $found = TRUE; + $options.= ""; + } else { + $options.= ""; + } + } + } + + $listhead = $this->get_default_header(); + + /* Add base selection */ + $listhead .= _("Base")."  ". + "  "; + + $this->SetListHeader($listhead); + + } + + + function setEntries($list) + { + + + $_target_list = array(); + if($this->display_server){ + $_target_list = array_merge($_target_list, + get_list("(&(cn=".$this->regex.")(objectClass=goServer))", + "server",get_ou("serverou").$this->selectedBase, + array("cn","objectClass","description","ipHostNumber","macAddress"),GL_NONE)); + } + if($this->display_workstation){ + $_target_list = array_merge($_target_list, + get_list("(&(cn=".$this->regex.")(objectClass=gotoWorkstation))", + "workstation",get_ou("workstationou").$this->selectedBase, + array("cn","objectClass","description","ipHostNumber","macAddress"),GL_NONE)); + } + if($this->display_ogroup){ + $_target_list = array_merge($_target_list, + get_list("(&(cn=".$this->regex.")(member=*)(objectClass=gosaGroupOfNames))", + "ogroups",get_ou("ogroupou").$this->selectedBase, + array("cn","objectClass","description","member"),GL_NONE)); + } + $this->_target_list = $_target_list; + + $tmp = array(); + foreach($this->_target_list as $key => $object){ + $tmp[$key] = $object['cn'][0]; + } + natcasesort($tmp); + + foreach($tmp as $key => $obj){ + + $obj = $this->_target_list[$key]; + $name = $obj['cn'][0]; + if(isset($obj['description'])){ + $name .= " [".$obj['description'][0]."]"; + } + if(isset($obj['macAddress'])){ + $name .= " - ".$obj['macAddress'][0].""; + } + if(isset($obj['ipHostNumber'])){ + $name .= " - ".$obj['ipHostNumber'][0].""; + } + + $img =""; + if(in_array("goServer",$obj['objectClass'])){ + $img = 'S'; + + if($this->filter_iprange){ + if(!isset($obj['ipHostNumber']) || !tests::is_in_ip_range($this->ipfrom,$this->ipto, $obj['ipHostNumber'][0])) { + continue; + } + } + if(!isset($this->server_list[$obj['dn']])){ + continue; + } + }elseif(in_array("gotoWorkstation",$obj['objectClass'])){ + $img = 'W'; + if($this->filter_iprange){ + if(!isset($obj['ipHostNumber']) || !tests::is_in_ip_range($this->ipfrom,$this->ipto,$obj['ipHostNumber'][0])) { + continue; + } + } + if(!isset($this->workstation_list[$obj['dn']])){ + continue; + } + }elseif(in_array("gosaGroupOfNames",$obj['objectClass'])){ + $img = 'O'; + } + + $field1 = array("string" => "", + "attach" => "style='width:20px;'"); + $field2 = array("string" => $img, + "attach" => "style='width:20px;'"); + $field3 = array("string" => $name , "attach" => "title='".$obj['dn']."'"); + $this->AddElement(array($field1,$field2,$field3)); + } + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> -- 2.30.2