From: hickert Date: Wed, 20 Aug 2008 13:56:54 +0000 (+0000) Subject: Update of opsi classes X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=22a19f31bf908867bd6657ae8c645152c8d1b01e;p=gosa.git Update of opsi classes - We are now able to add and remove products. - We can configure products. - BUT. I was able to add multiple netboot products.. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12254 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/opsi/admin/opsi/class_opsi.inc b/gosa-plugins/opsi/admin/opsi/class_opsi.inc index 7be570879..ebbbf5941 100644 --- a/gosa-plugins/opsi/admin/opsi/class_opsi.inc +++ b/gosa-plugins/opsi/admin/opsi/class_opsi.inc @@ -101,7 +101,7 @@ class opsi extends gosaSupportDaemon $res = $this->send_data("gosa_opsi_get_netboot_products",$this->target,$data,TRUE); $items = array(); - if($res['XML']['ITEM']['PRODUCTID']){ + if(isset($res['XML']['ITEM']['PRODUCTID'])){ 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']; @@ -182,30 +182,78 @@ class opsi extends gosaSupportDaemon @param @return */ - public function set_product_properties() + public function set_product_properties($productId,$cfg,$hostId = "") { - /* -
gosa_opsi_set_product_properties
- GOSA - 00:01:6c:9d:b9:fa - firefox - - askbeforeinst - false - -
- -
gosa_opsi_set_product_properties
- GOSA - 00:01:6c:9d:b9:fa - limux-cl-2.intranet.gonicus.de - firefox - - askbeforeinst - false - -
+ $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()); + } + + if(!count($cfg)) return; + + /* Add properties */ + $data['item'] = array(); + foreach($cfg as $name => $value){ + $data['item'][] = "".$name."".$value.""; + } + + /* Query SI server */ + $res = $this->send_data("gosa_opsi_set_product_properties",$this->target,$data,TRUE); + } + + + /*! \brief Adds a given product to a client. + @param + @return + */ + public function add_product_to_client($productId,$hostId) + { + $data = array("productId" => $productId,"hostId" => $hostId); + + /* Check parameter */ + if(empty($productId)){ + trigger_error("No valid product id given, check parameter 1."); + return; + } + if(empty($hostId)){ + trigger_error("No valid host id given, check parameter 2."); + return; + } + + /* Query SI server */ + $res = $this->send_data("gosa_opsi_add_product_to_client",$this->target,$data,TRUE); + } + + + /*! \brief Removes a given product from a client. + @param + @return + */ + public function del_product_from_client($productId,$hostId) + { + $data = array("productId" => $productId,"hostId" => $hostId); + + /* Check parameter */ + if(empty($productId)){ + trigger_error("No valid product id given, check parameter 1."); + return; + } + if(empty($hostId)){ + trigger_error("No valid host id given, check parameter 2."); + return; + } + + /* Query SI server */ + $res = $this->send_data("gosa_opsi_del_product_from_client",$this->target,$data,TRUE); } @@ -241,6 +289,8 @@ class opsi extends gosaSupportDaemon } + + /*! \brief Returns a list of all opsi clients. @param @return @@ -319,40 +369,6 @@ class opsi extends gosaSupportDaemon } - /*! \brief Adds a given product to a client. - @param - @return - */ - public function add_product_to_client() - { - /* -
gosa_opsi_add_product_to_client
- GOSA - 00:01:6c:9d:b9:fa - 00:11:25:4b:8c:e5 - limux-cl-2.intranet.gonicus.de - winxppro -
- */ - } - - - /*! \brief Removes a given product from a client. - @param - @return - */ - public function del_product_from_client() - { - /* -
gosa_opsi_del_product_from_client
- GOSA - 00:01:6c:9d:b9:fa - limux-cl-1.intranet.gonicus.de - 00:11:25:4b:8c:e5 - softprod -
- */ - } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/gosa-plugins/opsi/admin/opsi/class_opsi_generic.inc b/gosa-plugins/opsi/admin/opsi/class_opsi_generic.inc index a4013e4d5..65178cbc1 100644 --- a/gosa-plugins/opsi/admin/opsi/class_opsi_generic.inc +++ b/gosa-plugins/opsi/admin/opsi/class_opsi_generic.inc @@ -9,39 +9,101 @@ class opsi_generic extends plugin */ private $a_availableNetbootProducts = array(); private $s_selectedNetbootProduct = ""; + private $s_initial_selectedNetbootProduct = ""; /* Contains a list of all available local products */ private $a_availableLocalProducts = array(); private $a_selectedLocalProducts = array(); - + private $a_initial_selectedLocalProducts = array(); + + private $init_failed = FALSE; + public function __construct($config,$hostId) { $this->opsi = new opsi($config); - + $this->is_account =TRUE; + $this->initially_was_account = TRUE; + /* Get hostId */ $this->hostId = preg_replace("/^opsi:=([^,]*),.*$/","\\1",$hostId); + + /* Try to plugin */ + $this->init(); + } + + private function init() + { + $err = FALSE; + $this->init_failed = FALSE; /* Get product settings */ - $this->a_availableNetbootProducts = $this->opsi->get_netboot_products(); - $this->a_availableLocalProducts = $this->opsi->get_local_products(); - + if(!$err){ + $this->a_availableNetbootProducts = $this->opsi->get_netboot_products(); + $err |= $this->opsi->is_error(); + } + if(!$err) { + $this->a_availableLocalProducts = $this->opsi->get_local_products(); + $err |= $this->opsi->is_error(); + } + /* 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; + if(!$err) { + $tmp = array_keys($this->opsi->get_netboot_products($this->hostId)); + $this->s_selectedNetbootProduct = $tmp[0]; + $err |= $this->opsi->is_error(); + } + if(!$err) { + $tmp = $this->opsi->get_local_products($this->hostId); + $err |= $this->opsi->is_error(); + $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; + if(!$err) { + foreach($this->a_selectedLocalProducts as $name => $data){ + $CFG = $this->opsi->get_product_properties($name,$this->hostId); + $err |= $this->opsi->is_error(); + $this->a_selectedLocalProducts[$name]['CFG'] = $CFG; + } + } + + /* Check if everything went fine else reset everything and display a retry button + */ + if($err){ + $this->a_availableNetbootProducts = array(); + $this->s_selectedNetbootProduct = ""; + $this->s_initial_selectedNetbootProduct = ""; + $this->a_availableLocalProducts = array(); + $this->a_selectedLocalProducts = array(); + $this->a_initial_selectedLocalProducts = array(); + $this->init_failed = TRUE; + }else{ + + /* Remember initial settings */ + $this->a_initial_selectedLocalProducts = $this->a_selectedLocalProducts; + $this->s_initial_selectedNetbootProduct = $this->s_selectedNetbootProduct; } } public function execute() { + if($this->init_failed){ + + $smarty = get_smarty(); + $smarty->assign("init_failed",TRUE); + $smarty->assign("message",$this->opsi->get_error()); + return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__)))); + } + + + if(is_object($this->dialog)){ + $this->dialog->save_object(); + return($this->dialog->execute()); + } + $smarty = get_smarty(); + $smarty->assign("init_failed",FALSE); $divSLP = new divSelectBox(); $divALP = new divSelectBox(); @@ -54,7 +116,7 @@ class opsi_generic extends plugin $add_tab = array("string" => ""); $name_tab = array("string" => $name); $desc_tab = array("string" => "
".$data['DESC']."
", - "attach" => "title='".$data['DESC']."' style='border-right:0px;'"); + "attach" => "title='".$data['DESC']."' style='border-right:0px;'"); $divALP->AddEntry(array($add_tab,$name_tab,$desc_tab)); } @@ -62,7 +124,7 @@ class opsi_generic extends plugin */ ksort($this->a_selectedLocalProducts); foreach($this->a_selectedLocalProducts as $name => $data){ - + $name_tab = array("string" => $name); $desc_tab = array( "string" => "
".$data['DESC']."
", @@ -75,7 +137,7 @@ class opsi_generic extends plugin $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)); @@ -84,13 +146,65 @@ class opsi_generic extends plugin $smarty->assign("divSLP", $divSLP->DrawList()); $smarty->assign("divALP", $divALP->DrawList()); $smarty->assign("SNP", $this->s_selectedNetbootProduct); + + ksort($this->a_availableNetbootProducts); $smarty->assign("ANP", $this->a_availableNetbootProducts); return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__)))); } + public function save() + { + $add = array_diff_assoc($this->a_selectedLocalProducts,$this->a_initial_selectedLocalProducts); + $del = array_diff_assoc($this->a_initial_selectedLocalProducts,$this->a_selectedLocalProducts); + + foreach($del as $name => $data){ + $this->opsi->del_product_from_client($name,$this->hostId); + } + foreach($add as $name => $data){ + $this->opsi->add_product_to_client($name,$this->hostId); + $this->opsi->set_product_properties($name,$data['CFG'],$this->hostId); + } + + foreach($this->a_selectedLocalProducts as $name => $data){ + if(isset($del[$name]) || isset($add[$name])) continue; + $diff = array_diff($data['CFG'],$this->a_initial_selectedLocalProducts[$name]['CFG']); + if(count($diff)){ + $this->opsi->set_product_properties($name,$diff,$this->hostId); + } + } + + if($this->s_selectedNetbootProduct != $this->s_initial_selectedNetbootProduct){ + if(!empty($this->s_initial_selectedNetbootProduct)){ + $this->opsi->del_product_from_client($this->s_initial_selectedNetbootProduct,$this->hostId); + $this->opsi->add_product_to_client($this->s_selectedNetbootProduct,$this->hostId); + } + } + } + + public function remove_from_parent() + {} + + public function save_object() { + if(isset($_POST['reinit'])){ + $this->init(); + } + + if(isset($_POST['cancel_properties']) && is_object($this->dialog)){ + $this->dialog = NULL; + } + if(isset($_POST['save_properties']) && ($this->dialog instanceof opsi_product_config)){ + $this->dialog->save_object(); + $pro = $this->dialog->get_product(); + $CFG = $this->dialog->get_cfg(); + if(isset($this->a_selectedLocalProducts[$pro])){ + $this->a_selectedLocalProducts[$pro]['CFG'] = $CFG; + } + $this->dialog = NULL; + } + if(isset($_POST['opsi_generic'])){ if(isset($_POST['opsi_netboot_product'])){ @@ -99,7 +213,7 @@ class opsi_generic extends plugin $this->s_selectedNetbootProduct = $SNP; } } - + foreach($_POST as $name => $value){ if(preg_match("/^add_lp_/",$name)){ $product = preg_replace("/^add_lp_(.*)_.$/","\\1",$name); @@ -119,7 +233,8 @@ class opsi_generic extends plugin } if(preg_match("/^edit_lp_/",$name)){ $product = preg_replace("/^edit_lp_(.*)_.$/","\\1",$name); - $this->dialog = new opsi_product_config($product,$this->hostId); + $this->dialog = new opsi_product_config($this->config, + $product,$this->a_selectedLocalProducts[$product]['CFG'],$this->hostId); break; } } diff --git a/gosa-plugins/opsi/admin/opsi/class_opsi_product_config.inc b/gosa-plugins/opsi/admin/opsi/class_opsi_product_config.inc new file mode 100644 index 000000000..5a949bbe2 --- /dev/null +++ b/gosa-plugins/opsi/admin/opsi/class_opsi_product_config.inc @@ -0,0 +1,54 @@ +config = $config; + $this->product = $product; + $this->cfg = $cfg; + $this->hostId = $hostId; + } + + public function execute() + { + $smarty = get_smarty(); + $smarty->assign("cfg",$this->cfg); + return($smarty->fetch(get_template_path("properties.tpl",TRUE,dirname(__FILE__)))); + } + + public function save_object() + { + foreach($this->cfg as $name => $value){ + if(isset($_POST['value_'.$name])){ + $this->cfg[$name] = validate(get_post('value_'.$name)); + } + } + } + + public function get_cfg() + { + return($this->cfg); + } + + public function get_product() + { + return($this->product); + } + + public function get_hostId() + { + return($this->hostId); + } +} + + + + + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/opsi/admin/opsi/generic.tpl b/gosa-plugins/opsi/admin/opsi/generic.tpl index abc2e862a..6497c8e4c 100644 --- a/gosa-plugins/opsi/admin/opsi/generic.tpl +++ b/gosa-plugins/opsi/admin/opsi/generic.tpl @@ -1,6 +1,13 @@

Opsi host

+{if $init_failed} + +{msgPool type=siError p=$message} + + + +{else} @@ -29,3 +36,4 @@
+{/if} diff --git a/gosa-plugins/opsi/admin/opsi/properties.tpl b/gosa-plugins/opsi/admin/opsi/properties.tpl new file mode 100644 index 000000000..4c7a8e5ba --- /dev/null +++ b/gosa-plugins/opsi/admin/opsi/properties.tpl @@ -0,0 +1,16 @@ +

Opsi product properties

+ + +{foreach from=$cfg item=item key=key} + + + + +{/foreach} +
{$key}
+

 

+
+ +   + +