From e63d8eacd7cb9da5e6de2fe93f077161efad7ecc Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 24 Oct 2007 11:39:50 +0000 Subject: [PATCH] Updated gotomasses handling git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7638 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/class_hostActionQueue.inc | 98 ++++++++++++++++++- .../addons/gotomasses/class_divListMasses.inc | 12 ++- plugins/addons/gotomasses/class_goto_task.inc | 12 ++- .../addons/gotomasses/class_gotomasses.inc | 38 +++---- plugins/addons/gotomasses/goto_task.tpl | 5 +- 5 files changed, 128 insertions(+), 37 deletions(-) diff --git a/include/class_hostActionQueue.inc b/include/class_hostActionQueue.inc index d01d05511..a6aa4a697 100644 --- a/include/class_hostActionQueue.inc +++ b/include/class_hostActionQueue.inc @@ -40,6 +40,8 @@ class hostActionQueue { private $b_queue_loaded = false; private $i_fileversion = 0; + private $id_entry_map = array(); + public function __construct($config) { $this->o_config= $config; @@ -90,7 +92,9 @@ class hostActionQueue { $this->a_queue = array(); $comment = ""; $rows = split("\n",$data); - + + $used_ids = array(); + /* Walk trough rows and parse data */ foreach($rows as $row){ @@ -106,6 +110,29 @@ class hostActionQueue { continue; } + $entry_id = $taks_id= 0; + + /* Comment must be set correctly */ + if(empty($comment)){ + $desc = ""; + }else{ + $task_id =preg_replace("/^.*taskid:([0-9]*).*$/","\\1",$comment); + $entry_id=preg_replace("/^.*entryid:([0-9]*).*$/","\\1",$comment); + $desc =preg_replace("/^.*desc:(.*)$/","\\1",$comment); + } + if($task_id == 0 || !is_numeric($task_id)){ + $task_id = preg_replace("/[^0-9]*/","",microtime()); + } + if($entry_id == 0 || !is_numeric($entry_id)){ + $entry_id = preg_replace("/[^0-9]*/","",microtime()); + } + + /* Get unige id */ + while(in_array($entry_id,$used_ids)){ + $entry_id = preg_replace("/[^0-9]*/","",microtime()); + } + $used_ids[] = $entry_id; + /* Split row into minutes/ hours ...*/ $row = preg_replace('/[\t ]/umi'," ",$row); $row = preg_replace('/ */umi'," ",$row); @@ -116,6 +143,8 @@ class hostActionQueue { }else{ $entry = array(); + $entry['TASK_ID'] = $task_id; + $entry['ID'] = $entry_id; $entry['Minute'] = $parts[0]; $entry['Hour'] = $parts[1]; $entry['Day'] = $parts[2]; @@ -137,12 +166,19 @@ class hostActionQueue { $entry['Target'] = array(); }else{ $entry['Initial_Target'] = array(); - $entry['Target'] = split(";",$parts[7]); + $entry['Target'] = split(";",$parts[9]); } - $entry['Comment'] = $comment; + $entry['Comment'] = $desc; $this->a_queue[] = $entry; + } } + + /* Udpate ENTRY_ID -> id mapping */ + foreach($this->a_queue as $id => $entry){ + $this->id_entry_map[$entry['ID']] = $id; + } + return(TRUE); } @@ -172,7 +208,7 @@ class hostActionQueue { $str = "#GOsa generated file, please just modify if you really know what you do."; foreach($this->a_queue as $task){ - $str .= "\n#".trim($task['Comment']); + $str .= "\n#taskid:".trim($task['TASK_ID']).";entryid:".$task['ID'].";desc:".trim($task['Comment']); $str .= "\n"; if($task['Action'] == "initial_install"){ $str .= "* * * * * "; @@ -207,9 +243,61 @@ class hostActionQueue { return(TRUE); } - public function add($entry) + private function _add_entry($entry,$task_id = 0) { + if($task_id == 0 || !is_numeric($task_id) || !isset($entry['TASK_ID']) || !is_numeric($entry['TASK_ID'])){ + $task_id=preg_replace("/[^0-9]*/","",microtime()); + $entry['TASK_ID'] = $task_id; + } + if(!isset($entry['ID']) || !is_numeric($entry['ID'])){ + $entry['ID'] = preg_replace("/[^0-9]*/","",microtime()); + } $this->a_queue[] = $entry; + + return(true); + } + + public function get_entry($id) + { + if(isset($this->a_queue[$this->id_entry_map[$id]])){ + return($this->a_queue[$this->id_entry_map[$id]]); + }else{ + $this->set_error(sprintf(_("Entry with id '%s' not found."),$id)); + } + } + + public function update_entry($id,$entry) + { + if(isset($this->a_queue[$this->id_entry_map[$id]])){ + $this->a_queue[$this->id_entry_map[$id]] = $entry; + return($this->_save_data()); + }else{ + $this->set_error(sprintf(_("Could not update entry, entry with id '%s' not found."),$id)); + } + } + + public function id_exists($id) + { + return(isset($this->id_entry_map[$id])); + } + + + public function add($entry) + { + if(!$this->_add_entry($entry)){ + return(FALSE); + } + return($this->_save_data()); + } + + public function add_multiple($array) + { + $task_id = preg_replace("/[^0-9]*/","",microtime()); + foreach($array as $entry){ + if(!$this->_add_entry($entry,$task_id)){ + return(FALSE); + } + } return($this->_save_data()); } diff --git a/plugins/addons/gotomasses/class_divListMasses.inc b/plugins/addons/gotomasses/class_divListMasses.inc index 7c9f1da64..92bf31e35 100644 --- a/plugins/addons/gotomasses/class_divListMasses.inc +++ b/plugins/addons/gotomasses/class_divListMasses.inc @@ -78,7 +78,7 @@ class divListMasses extends MultiSelectWindow { /* Create edit link */ $plug = $_GET['plug']; - $edit_link = "
%str%
"; + $edit_link = "
%str%
"; /* Create action filter array, to sort out those actions we do not want to see */ $allowed_action = array(); @@ -94,16 +94,18 @@ class divListMasses extends MultiSelectWindow if(!in_array($task['Action'],$allowed_action)){ continue; } + + $id = $task['ID']; - $action = ""; + $action = ""; if($this->parent->acl_is_removeable()){ - $action.= ""; + $action.= ""; } /* Create each field */ - $field0 = array("string" => "" , + $field0 = array("string" => "" , "attach" => "style='width:20px;'"); - $field1 = array("string" => preg_replace(array("/%key%/","/%str%/"),array($key,$this->parent->target_to_string($task)),$edit_link)); + $field1 = array("string" => preg_replace(array("/%id%/","/%str%/"),array($id,$this->parent->target_to_string($task)),$edit_link)); $field2 = array("string" => $this->parent->time_to_string($task),"attach" => "style='width:100px;'"); $field3 = array("string" => $this->parent->action_to_string($task),"attach" => "style='width:80px;'"); $field4 = array("string" => $action,"attach" => "style='text-align:right;width:40px;border-right:0px;'"); diff --git a/plugins/addons/gotomasses/class_goto_task.inc b/plugins/addons/gotomasses/class_goto_task.inc index e081d8360..bbc58faed 100644 --- a/plugins/addons/gotomasses/class_goto_task.inc +++ b/plugins/addons/gotomasses/class_goto_task.inc @@ -28,7 +28,9 @@ class goto_task extends plugin var $Initial_Target = array(); var $Actions = array(); var $new = FALSE; - var $attributes = array("Zone","Section","OGroup","Minute","Hour","Day", + var $ID = 0; + var $TASK_ID =0; + var $attributes = array("ID","TASK_ID","Zone","Section","OGroup","Minute","Hour","Day", "Month","Weekday","Action","Comment","Target","Initial_Target"); var $configure_dhcp = FALSE; @@ -99,7 +101,7 @@ class goto_task extends plugin if($this->Action != "initial_install"){ /* Add target */ - if(isset($_POST['add_target']) && !empty($_POST['target_text'])){ + if($this->ID == 0 && isset($_POST['add_target']) && !empty($_POST['target_text'])){ $target = get_post("target_text"); if($this->is_valid_target($target) && !in_array($target,$this->Target)){ $this->Target[] = $target; @@ -108,7 +110,7 @@ class goto_task extends plugin }else{ /* Add target */ - if(isset($_POST['add_target']) && !empty($_POST['task_MAC'])){ + if($this->ID ==0 && isset($_POST['add_target']) && !empty($_POST['task_MAC'])){ $MAC = $_POST['task_MAC']; $NAME= ""; $IP = ""; @@ -133,7 +135,7 @@ class goto_task extends plugin } /* Add via csv */ - if(isset($_FILES['import_file'])){ + if($this->ID == 0 && isset($_FILES['import_file'])){ $file = $_FILES['import_file']['tmp_name']; if(file_exists($file) && is_readable($file)){ $str =""; @@ -240,6 +242,8 @@ class goto_task extends plugin $smarty->assign("Zones", $this->Zones); $smarty->assign("Sections", $this->Sections); + $smarty->assign("ID",$this->ID); + $smarty->assign("Zone", $this->Zone); $smarty->assign("Section", $this->Section); diff --git a/plugins/addons/gotomasses/class_gotomasses.inc b/plugins/addons/gotomasses/class_gotomasses.inc index 9fb3c9769..a71170fd7 100644 --- a/plugins/addons/gotomasses/class_gotomasses.inc +++ b/plugins/addons/gotomasses/class_gotomasses.inc @@ -96,10 +96,12 @@ class gotomasses extends plugin ************/ /* Edit selected entry */ - if($s_action == "edit" && isset($this->tasks[$s_entry])){ - $entry = $this->tasks[$s_entry]; - $this->dialog = new goto_task($this->config,$this,$entry); - $this->current = $s_entry; + if($s_action == "edit"){ + $entry = $this->o_queue->get_entry($s_entry); + if($entry){ + $this->dialog = new goto_task($this->config,$this,$entry); + $this->current = $s_entry; + } } /* New entry */ @@ -122,18 +124,20 @@ class gotomasses extends plugin foreach($msgs as $msg){ print_red($msg); } - }else{ - if(isset($this->tasks[$this->current]) && $this->current != -1){ - $this->tasks[$this->current] = $this->dialog->save(); + }else{ + + if($this->o_queue->id_exists($this->current)){ + $this->o_queue->update_entry($this->current,$this->dialog->save()); }else{ $tmp = $this->dialog->save(); - + $tmp2= array(); $targets =$tmp['Target']; foreach($targets as $target){ $tmp['Target'] = array($target); - if(!$this->o_queue->add($tmp)){ - print_red($this->o_queue->get_error()); - } + $tmp2[] = $tmp; + } + if(!$this->o_queue->add_multiple($tmp2)){ + print_red($this->o_queue->get_error()); } } if(!isset($_POST['apply_goto_task'])){ @@ -150,7 +154,6 @@ class gotomasses extends plugin return($this->dialog->execute()); } - /************ * Handle Divlist ************/ @@ -169,21 +172,12 @@ class gotomasses extends plugin } $ret = array(); while($entry = $this->o_queue->fetch()){ - $ret[] = $entry; + $ret[]= $entry; } return($ret); } - - - - - - - - - function target_to_string($data) { $ret = ""; diff --git a/plugins/addons/gotomasses/goto_task.tpl b/plugins/addons/gotomasses/goto_task.tpl index 0c93fcf56..f841a4fd8 100644 --- a/plugins/addons/gotomasses/goto_task.tpl +++ b/plugins/addons/gotomasses/goto_task.tpl @@ -78,6 +78,7 @@ {if $Action == "initial_install"} +{if $ID == 0}

 

@@ -145,7 +146,7 @@
- +{/if} {else}

 

@@ -189,6 +190,7 @@
+{if $ID == 0}

 

@@ -221,6 +223,7 @@
{/if} +{/if}

 

-- 2.30.2