From bf72dec8f41a875fb9bd743d0a500baafc968016 Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 20 Aug 2008 09:33:50 +0000 Subject: [PATCH] Updated opsi classes -You are now able to select products. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12251 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-plugins/opsi/admin/opsi/class_opsi.inc | 91 ++++++++++---- .../opsi/admin/opsi/class_opsi_generic.inc | 117 ++++++++++++++++++ gosa-plugins/opsi/admin/opsi/generic.tpl | 11 +- 3 files changed, 188 insertions(+), 31 deletions(-) diff --git a/gosa-plugins/opsi/admin/opsi/class_opsi.inc b/gosa-plugins/opsi/admin/opsi/class_opsi.inc index e41133b6d..7be570879 100644 --- a/gosa-plugins/opsi/admin/opsi/class_opsi.inc +++ b/gosa-plugins/opsi/admin/opsi/class_opsi.inc @@ -18,6 +18,25 @@ */ +/******** + + __construct($config) + get_hosts_for_system_management() + get_netboot_products($host = "") + get_local_products($host = "") + get_product_properties() + set_product_properties() + get_client_hardware() + get_client_software() + list_clients() + del_client() + job_opsi_install_client() + add_client() + add_product_to_client() + del_product_from_client() + + ********/ + /*! \brief This is the opsi base class, it handles . gosa daemon requests and prepares data for opsi plugins. @@ -83,10 +102,15 @@ class opsi extends gosaSupportDaemon $res = $this->send_data("gosa_opsi_get_netboot_products",$this->target,$data,TRUE); $items = array(); if($res['XML']['ITEM']['PRODUCTID']){ - foreach($res['XML']['ITEM']['PRODUCTID'] as $id => $name){ - $items[$name]['NAME'] = $name; - $items[$name]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'][$id]; - } + if(!is_array($res['XML']['ITEM']['PRODUCTID'])){ + $items[$res['XML']['ITEM']['PRODUCTID']]['NAME'] = $res['XML']['ITEM']['PRODUCTID']; + $items[$res['XML']['ITEM']['PRODUCTID']]['DESC'] = $res['XML']['ITEM']['DESCRIPTION']; + }else{ + foreach($res['XML']['ITEM']['PRODUCTID'] as $id => $name){ + $items[$name]['NAME'] = $name; + $items[$name]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'][$id]; + } + } } return($items); } @@ -109,10 +133,15 @@ class opsi extends gosaSupportDaemon $res = $this->send_data("gosa_opsi_get_local_products",$this->target,$data,TRUE); $items = array(); if($res['XML']['ITEM']['PRODUCTID']){ - foreach($res['XML']['ITEM']['PRODUCTID'] as $id => $name){ - $items[$name]['NAME'] = $name; - $items[$name]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'][$id]; - } + if(!is_array($res['XML']['ITEM']['PRODUCTID'])){ + $items[$res['XML']['ITEM']['PRODUCTID']]['NAME'] = $res['XML']['ITEM']['PRODUCTID']; + $items[$res['XML']['ITEM']['PRODUCTID']]['DESC'] = $res['XML']['ITEM']['DESCRIPTION']; + }else{ + foreach($res['XML']['ITEM']['PRODUCTID'] as $id => $name){ + $items[$name]['NAME'] = $name; + $items[$name]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'][$id]; + } + } } return($items); } @@ -124,23 +153,28 @@ class opsi extends gosaSupportDaemon @param @return */ - public function get_product_properties() + public function get_product_properties($productId,$hostId = "") { - /* -
gosa_opsi_get_product_properties
- GOSA - GOSA - firefox -
- -
gosa_opsi_get_product_properties
- GOSA - GOSA - firefox - limux-cl-2.intranet.gonicus.de -
+ $data = array("productId" => $productId); + + /* Append host attribute to query data */ - + if(!empty($hostId)){ + $data['hostId'] = trim($hostId); + } + + /* Check parameter */ + if(empty($productId)){ + trigger_error("No valid product id given, check parameter 1."); + return(array()); + } + + /* Query SI server */ + $res = $this->send_data("gosa_opsi_get_product_properties",$this->target,$data,TRUE); + if(isset($res['XML']['ITEM'])){ + return($res['XML']['ITEM']); + } + return(array()); } @@ -217,9 +251,14 @@ class opsi extends gosaSupportDaemon $res = $this->send_data("gosa_opsi_list_clients",$this->target,$data,TRUE); $items = array(); if(isset($res['XML']['ITEM'])){ - foreach($res['XML']['ITEM'] as $type => $val){ - foreach($val as $key => $value){ - $items[$key][$type] = $value; + if(!is_array($res['XML']['ITEM']['NAME'])){ + $obj = $res['XML']['ITEM']; + $items[$obj['NAME']] = $obj; + }else{ + foreach($res['XML']['ITEM'] as $type => $val){ + foreach($val as $key => $value){ + $items[$key][$type] = $value; + } } } } diff --git a/gosa-plugins/opsi/admin/opsi/class_opsi_generic.inc b/gosa-plugins/opsi/admin/opsi/class_opsi_generic.inc index 494df31c9..a4013e4d5 100644 --- a/gosa-plugins/opsi/admin/opsi/class_opsi_generic.inc +++ b/gosa-plugins/opsi/admin/opsi/class_opsi_generic.inc @@ -2,12 +2,129 @@ class opsi_generic extends plugin { + private $opsi; + private $hostId; + + /* Contains a list of all available netboot products + */ + private $a_availableNetbootProducts = array(); + private $s_selectedNetbootProduct = ""; + + /* Contains a list of all available local products + */ + private $a_availableLocalProducts = array(); + private $a_selectedLocalProducts = array(); + + public function __construct($config,$hostId) + { + $this->opsi = new opsi($config); + + /* Get hostId */ + $this->hostId = preg_replace("/^opsi:=([^,]*),.*$/","\\1",$hostId); + + /* Get product settings */ + $this->a_availableNetbootProducts = $this->opsi->get_netboot_products(); + $this->a_availableLocalProducts = $this->opsi->get_local_products(); + + /* Get selected products */ + $tmp = array_keys($this->opsi->get_netboot_products($this->hostId)); + $this->s_selectedNetbootProduct = $tmp; + $tmp = $this->opsi->get_local_products($this->hostId); + $this->a_selectedLocalProducts = $tmp; + + /* Load product configuration */ + foreach($this->a_selectedLocalProducts as $name => $data){ + $CFG = $this->opsi->get_product_properties($name,$this->hostId); + $this->a_selectedLocalProducts[$name]['CFG'] = $CFG; + } + } public function execute() { $smarty = get_smarty(); + $divSLP = new divSelectBox(); + $divALP = new divSelectBox(); + + /* Create list of available local products + */ + ksort($this->a_availableLocalProducts); + foreach($this->a_availableLocalProducts as $name => $data){ + if(isset($this->a_selectedLocalProducts[$name])) continue; + + $add_tab = array("string" => ""); + $name_tab = array("string" => $name); + $desc_tab = array("string" => "
".$data['DESC']."
", + "attach" => "title='".$data['DESC']."' style='border-right:0px;'"); + $divALP->AddEntry(array($add_tab,$name_tab,$desc_tab)); + } + + /* Create list of selected local products + */ + ksort($this->a_selectedLocalProducts); + foreach($this->a_selectedLocalProducts as $name => $data){ + + $name_tab = array("string" => $name); + $desc_tab = array( + "string" => "
".$data['DESC']."
", + "attach" => "title='".$data['DESC']."'"); + + /* Only display edit button, if there is something to edit + */ + $edit = " "; + if(count($data['CFG'])){ + $edit = ""; + } + $del = ""; + + $opt_tab = array("string" => $edit.$del, + "attach" => "style='border-right:0px; width: 40px; text-align:right;'"); + $divSLP->AddEntry(array($name_tab,$desc_tab,$opt_tab)); + } + + $smarty->assign("divSLP", $divSLP->DrawList()); + $smarty->assign("divALP", $divALP->DrawList()); + $smarty->assign("SNP", $this->s_selectedNetbootProduct); + $smarty->assign("ANP", $this->a_availableNetbootProducts); return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__)))); } + + + public function save_object() + { + if(isset($_POST['opsi_generic'])){ + + if(isset($_POST['opsi_netboot_product'])){ + $SNP = trim($_POST['opsi_netboot_product']); + if(isset($this->a_availableNetbootProducts[$SNP])){ + $this->s_selectedNetbootProduct = $SNP; + } + } + + foreach($_POST as $name => $value){ + if(preg_match("/^add_lp_/",$name)){ + $product = preg_replace("/^add_lp_(.*)_.$/","\\1",$name); + if(isset($this->a_availableLocalProducts[$product]) && !isset($this->a_selectedLocalProducts[$product])){ + $this->a_selectedLocalProducts[$product] = $this->a_availableLocalProducts[$product]; + $CFG = $this->opsi->get_product_properties($product); + $this->a_selectedLocalProducts[$product]['CFG'] = $CFG; + } + break; + } + if(preg_match("/^del_lp_/",$name)){ + $product = preg_replace("/^del_lp_(.*)_.$/","\\1",$name); + if(isset($this->a_selectedLocalProducts[$product])){ + unset($this->a_selectedLocalProducts[$product]); + } + break; + } + if(preg_match("/^edit_lp_/",$name)){ + $product = preg_replace("/^edit_lp_(.*)_.$/","\\1",$name); + $this->dialog = new opsi_product_config($product,$this->hostId); + break; + } + } + } + } } diff --git a/gosa-plugins/opsi/admin/opsi/generic.tpl b/gosa-plugins/opsi/admin/opsi/generic.tpl index 4f432ce62..abc2e862a 100644 --- a/gosa-plugins/opsi/admin/opsi/generic.tpl +++ b/gosa-plugins/opsi/admin/opsi/generic.tpl @@ -10,6 +10,9 @@ {t}Boot product{/t} @@ -18,13 +21,11 @@

Installed products

- + {$divSLP} - <

Available products

- + {$divALP} + -- 2.30.2