From: hickert Date: Wed, 20 Feb 2008 09:53:33 +0000 (+0000) Subject: Gotomasses X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e2634158f499af217a02b0c30c92e03eb9d2ef8f;p=gosa.git Gotomasses -Added new Target list. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8981 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/goto/addons/gotomasses/events/DaemonEvent_wakeup.tpl b/gosa-plugins/goto/addons/gotomasses/events/DaemonEvent_wakeup.tpl index 27c4f8d0b..7caf5f448 100644 --- a/gosa-plugins/goto/addons/gotomasses/events/DaemonEvent_wakeup.tpl +++ b/gosa-plugins/goto/addons/gotomasses/events/DaemonEvent_wakeup.tpl @@ -9,10 +9,7 @@ -
- 00:00:00:00:00:00 -
- + {$target_list} diff --git a/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent.inc b/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent.inc index d62f9014e..940077145 100644 --- a/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent.inc +++ b/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent.inc @@ -22,20 +22,26 @@ trigger_action_rescan class DaemonEvent { + /* Menu Strings */ + protected $s_Menu_Name = "s_Menu_Name not set"; // Diplayed in the ActionsMenu->CreateNew + protected $s_Event_Name = "s_Event_Name not set"; // Will be displayed in the Management list. + protected $s_Menu_Image = "images/empty.png"; // The deamon command name. - protected $s_Menu_Name = ""; // Diplayed in the ActionsMenu->CreateNew - protected $s_Event_Name = ""; // Will be displayed in the Management list. - protected $s_action = ""; // The deamon command name. - protected $s_Menu_Image = "images/empty.png"; // The deamon command name. + protected $target_add_list_used = FALSE; // Indicates that the target add list was used. + protected $time_select_used = FALSE; // Indicates that we have used the timestamp select boxes. + protected $target_list_used = FALSE; // Target list was diaplayed? + protected $target_divlist = NULL; // The divlist used by the target add dialog protected $config; // GOsa configuration file protected $data; // The event data - protected $timestamp = 0; // Event execution time; - protected $time_select_used = FALSE; // Indicates that we have used the timestamp select boxes. - protected $target_list_used = FALSE; // Indicates that the target list was used. - - protected $target_divlist = FALSE; // The divlist used by the target add dialog + protected $s_action = ""; // The deamon command name. + protected $a_targets = array(); // The list of assigned Targets + protected $timestamp = 0; // Event execution time; + protected $id = -1; // The Table ID + protected $status = "unknown";// The current event status + protected $is_new = TRUE; // Is TRUE if this is a new event + protected $_target_list = array(); // Object Cache of those objects displayed in the target add dialog public function __construct($config,$data = array()) { @@ -43,11 +49,17 @@ class DaemonEvent $this->config = $config; timezone::get_default_timezone(); $this->timestamp = time(); + + /* Load values from given data */ + if(count($data)){ + $this->is_new = FALSE; + } } public function execute() { $this->time_select_used = FALSE; + $this->target_list_used = FALSE; $str = "

"._("This event has no template.")."

"; $str.= "

"; @@ -67,7 +79,7 @@ class DaemonEvent public function get_footer() { - if($this->target_list_used){ + if($this->target_add_list_used){ return(""); } $str = "

"; @@ -142,16 +154,181 @@ class DaemonEvent public function get_target_list() { $this->target_list_used = TRUE; + $divlist = new divSelectBox("EventTargets"); + foreach($this->a_targets as $key => $target){ + $divlist->AddEntry(array( + array("string" => $target), + array("string" => "", + "attach" => "style='width:20px; border-right:0px;'") + )); + } + $list_footer = ""; + return($divlist->DrawList().$list_footer); + } + + public function get_target_add_list() + { + $this->target_add_list_used = TRUE; $smarty = get_smarty(); - if(!$this->target_divlist){ - $this->target_divlist = new MultiSelectWindow($this->config,"EventTargets","gotomasses"); + 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); + $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']; + } + + $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); + + $_target_list = array(); + if($this->target_divlist->display_server){ + $_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))", + "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.")(objectClass=gosaGroupOfNames))", + "ogroups",get_ou("ogroupou").$this->target_divlist->selectedBase, + array("cn","objectClass","description"),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 => $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; + } + } + + }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; + } + } + + }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)); + } + $smarty->assign("divlist",$this->target_divlist->Draw()); return($smarty->fetch(get_template_path('target_list.tpl', TRUE, dirname(__FILE__)))); @@ -160,20 +337,26 @@ class DaemonEvent public function save_object() { if(isset($_POST['open_target_list'])){ - $this->target_list_used =TRUE; + $this->target_add_list_used =TRUE; } - if($this->target_divlist){ + if($this->target_divlist != NULL){ $this->target_divlist->save_object(); } - if($this->target_list_used){ + if($this->target_add_list_used){ if(isset($_POST['abort_target_dialog'])){ - $this->target_list_used =FALSE; - $this->target_divlist = FALSE; + $this->target_add_list_used =FALSE; + $this->target_divlist = NULL; } if(isset($_POST['save_target_dialog'])){ - $this->target_list_used =FALSE; - echo "Targets auslesen"; - $this->target_divlist = FALSE; + $this->target_add_list_used =FALSE; + foreach($this->list_get_selected_items() as $id){ + if(isset($this->_target_list[$id]['macAddress'][0])){ + $this->a_targets[] = $this->_target_list[$id]['macAddress'][0]; + }else{ + $this->a_targets[] = $this->_target_list[$id]['cn'][0]; + } + } + $this->target_divlist = NULL; } } @@ -192,6 +375,18 @@ class DaemonEvent $_POST['time_year']); } } + + if($this->target_list_used){ + foreach($_POST as $name => $value){ + if(preg_match("/^del_target_/",$name)){ + $id = preg_replace("/^del_target_([0-9]*)_.*/","\\1",$name); + if(isset($this->a_targets[$id])){ + unset($this->a_targets[$id]); + } + break; + } + } + } } public function _event_to_timestamp($str) @@ -210,7 +405,7 @@ class DaemonEvent $data =array(); $data['NAME'] = get_class($this); $data['MenuName'] = $this->s_Menu_Name; - $data['EventName'] = $this->s_Event_Name; + $data['EventName'] = $this->s_Event_Name; $data['Action'] = $this->s_action; $data['MenuImage'] = "".$this->s_Menu_Name.""; return($data); @@ -219,7 +414,7 @@ class DaemonEvent protected function is_target_list_open() { - return($this->target_list_used); + return($this->target_add_list_used); } @@ -235,6 +430,20 @@ class DaemonEvent } return($list); } + + + protected 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); + } + } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: diff --git a/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_wakeup.inc b/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_wakeup.inc index 7456b9b2c..02ff35dae 100644 --- a/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_wakeup.inc +++ b/gosa-plugins/goto/addons/gotomasses/events/class_DaemonEvent_wakeup.inc @@ -19,10 +19,11 @@ class DaemonEvent_wakeup extends DaemonEvent /* Check if target add dialog is open */ if($this->is_target_list_open()){ - $display .= $this->get_target_list(); + $display .= $this->get_target_add_list(); }else{ $smarty = get_smarty(); - $smarty->assign("timestamp",$this->get_time_select()); + $smarty->assign("target_list" , $this->get_target_list()); + $smarty->assign("timestamp" , $this->get_time_select()); $display.= $smarty->fetch(get_template_path('DaemonEvent_wakeup.tpl', TRUE, dirname(__FILE__))); }