From 5e641509cb96017dac296770e32e32b08e77a31f Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 23 Sep 2009 08:16:00 +0000 Subject: [PATCH] We are now able to create, remove and modify pools git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14324 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../opsiLicenses/class_divListLicenses.inc | 12 +- .../opsiLicenses/class_licenceGeneric.inc | 154 ++++++++++++++---- .../admin/opsiLicenses/class_opsiLicenses.inc | 3 + .../admin/opsiLicenses/licenseGeneric.tpl | 53 ++++-- gosa-plugins/opsi/admin/opsiLicenses/main.inc | 4 +- 5 files changed, 169 insertions(+), 57 deletions(-) diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_divListLicenses.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_divListLicenses.inc index 02e70d91f..c2076d9e3 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/class_divListLicenses.inc +++ b/gosa-plugins/opsi/admin/opsiLicenses/class_divListLicenses.inc @@ -37,7 +37,7 @@ class divListLicense extends MultiSelectWindow function divListLicense (&$config,$parent) { - MultiSelectWindow::MultiSelectWindow($config, "Licenses", "licenses"); + MultiSelectWindow::MultiSelectWindow($config, "opsi", "licenseGeneric"); $this->parent = $parent; $this->ui = get_userinfo(); @@ -94,8 +94,8 @@ class divListLicense extends MultiSelectWindow $add_sep = false; /* Get copy & paste icon */ - $acls = $ui->get_permissions($this->selectedBase,"licenses/licenseGeneric"); - $acl_all= $ui->has_complete_category_acls($this->selectedBase,"licenses"); + $acls = $ui->get_permissions($this->selectedBase,"opsi/licenseGeneric"); + $acl_all= $ui->has_complete_category_acls($this->selectedBase,"opsi"); /* Add default header */ $listhead = MultiSelectWindow::get_default_header(); @@ -107,7 +107,7 @@ class divListLicense extends MultiSelectWindow if(preg_match("/c/",$acls)) { $s .= "..|". " "._("Create")."|\n"; - $s.= "...|". + $s.= "...|". " "._("License")."|license_new|\n"; } @@ -174,7 +174,7 @@ class divListLicense extends MultiSelectWindow $field0 = array("string" => "" , "attach" => "style='width:20px;'"); - $field1 = array("string" => " ""._("License")."", "attach" => "style='text-align:center;width: 20px;'"); $field2 = array("string" => sprintf($editlink,$key,$display), @@ -192,7 +192,7 @@ class divListLicense extends MultiSelectWindow } $num_objs = count($list); $num_obj_str = _("Number of listed licenses"); - $str = "".$num_obj_str." ".$num_objs."    "; $this->set_List_Bottom_Info($str); } diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_licenceGeneric.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_licenceGeneric.inc index 7473f68ff..aaf9ff3ae 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/class_licenceGeneric.inc +++ b/gosa-plugins/opsi/admin/opsiLicenses/class_licenceGeneric.inc @@ -24,53 +24,85 @@ class licenseGeneric extends plugin { + var $cn = ""; + var $orig_cn = ""; + var $description = ""; + var $orig_dn = ""; var $data = array(); var $orig_data = array(); var $productIds = array(); var $softwareIds= array(); + var $licenses= array(); + var $availableProductIds = array(); var $attributes =array("cn","description"); + var $si = NULL; + function __construct(&$config,$dn) { $this->config = $config; $this->dn = $this->orig_dn = $dn; + $this->si = new opsiLicenceHandler($this->config); + + $this->is_account=TRUE; + if($this->dn == "new"){ + $this->initially_was_account = FALSE; + }else{ + $this->initially_was_account = TRUE; + $this->cn = $this->orig_cn = preg_replace("/^opsi:cn=([^,]*),.*$/","\\1",$dn); + } + // Extract pool name out of the fake dn. - $this->cn = preg_replace("/^opsi:cn=([^,]*),.*$/","\\1",$dn); $this->init(); } function init() { - $si = new opsiLicenceHandler($this->config); - $res = $si->getPool($this->cn); - if($si->is_error()){ + // Load local Boot Products + $res = $this->si->get_local_products(); + if($this->si->is_error()){ $this->init_successfull = FALSE; return(FALSE); + } + $this->availableProductIds=array_keys($res); + + // Load Pool + if(!$this->initially_was_account){ + $this->init_successfull = TRUE; }else{ - $this->data = $this->orig_data = $res; - $this->description = $this->data['description'][0]; - // Load software IDs - if(isset($this->data['softwareId'])){ - for($i = 0; $i < $this->data['softwareId']['count']; $i++){ - $this->softwareIds[] = $this->data['softwareId'][$i]; + $res = $this->si->getPool($this->cn); + if($this->si->is_error()){ + $this->init_successfull = FALSE; + return(FALSE); + }else{ + $this->data = $this->orig_data = $res; + $this->description = $this->data['description'][0]; + + // Load software IDs + $this->softwareIds = array(); + if(isset($this->data['softwareId'])){ + for($i = 0; $i < $this->data['softwareId']['count']; $i++){ + $this->softwareIds[] = $this->data['softwareId'][$i]; + } } - } - // Load product IDs - if(isset($this->data['productId'])){ - for($i = 0; $i < $this->data['productId']['count']; $i++){ - $this->productIds[] = $this->data['productId'][$i]; + // Load product IDs + $this->productIds = array(); + if(isset($this->data['productId'])){ + for($i = 0; $i < $this->data['productId']['count']; $i++){ + $this->productIds[] = $this->data['productId'][$i]; + } } + $this->init_successfull = TRUE; + return; } - $this->init_successfull = TRUE; - return; } } @@ -97,9 +129,61 @@ class licenseGeneric extends plugin } $smarty->assign("init_successfull", $this->init_successfull); + $smarty->assign("availableProductIds", array_diff( $this->availableProductIds, $this->productIds)); + $smarty->assign("productIds", $this->productIds); + $smarty->assign("softwareIds", $this->softwareIds); + $smarty->assign("licenses", $this->licenses); + $smarty->assign("initially_was_account", $this->initially_was_account); return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__)))); } + + /* Save HTML inputs + */ + function save_object() + { + if(isset($_POST['opsiLicensesPosted'])){ + plugin::save_object(); + + // Restore license cn, to avoid creating a copy... + if($this->initially_was_account) $this->cn = $this->orig_cn; + + // We've to add prodcuts here + if(isset($_POST['availableProduct']) && isset($_POST['addProduct'])){ + $pro = get_post('availableProduct'); + if(isset($this->availableProductIds[$pro]) && !in_array($this->availableProductIds[$pro], $this->productIds)){ + $this->productIds[] =$this->availableProductIds[$pro]; + } + } + + // We've to remove products here + if(isset($_POST['productIds']) && isset($_POST['removeProduct'])){ + foreach($_POST['productIds'] as $key){ + if(isset($this->productIds[$key])){ + unset($this->productIds[$key]); + } + } + } + + // We've to add software here + if(isset($_POST['newSoftwareId']) && isset($_POST['addSoftware'])){ + $soft = trim(get_post('newSoftwareId')); + if(!empty($soft) && !in_array($soft, $this->softwareIds)){ + $this->softwareIds[] = $soft; + } + } + + // We've to remove software Ids here + if(isset($_POST['softwareIds']) && isset($_POST['removeSoftware'])){ + foreach($_POST['softwareIds'] as $key){ + if(isset($this->softwareIds[$key])){ + unset($this->softwareIds[$key]); + } + } + } + } + } + /* Check user input and return a list of 'invalid input' messages. */ @@ -111,15 +195,20 @@ class licenseGeneric extends plugin - /* Removes the object from the ldap database + /* Removes the object from the opsi database */ function remove_from_parent() { - // Log action. - new log("remove","licenses/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + $this->si->deletePool($this->orig_cn); + if($this->si->is_error()){ + msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG); + }else{ + + // Trigger remove signal + $this->handle_post_events("remove"); + } - // Trigger remove signal - $this->handle_post_events("remove"); + new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$this->si->get_error()); } @@ -129,34 +218,29 @@ class licenseGeneric extends plugin { plugin::save(); - // Send modify/add events $mode = "modify"; if($this->orig_dn == "new"){ $mode = "add"; } - $this->handle_post_events($mode); + $this->si->createPool($this->cn, $this->description,$this->productIds,$this->softwareIds);# + if($this->si->is_error()){ + msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG); + }else{ + $this->handle_post_events($mode); + } // Log action if($mode == "modify"){ - new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$this->si->get_error()); }else{ - new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$this->si->get_error()); } return 0; } - - /* Save HTML inputs - */ - function save_object() - { - plugin::save_object(); - } - - static function plInfo() { return (array( diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenses.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenses.inc index 69d28d08b..e029e9641 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenses.inc +++ b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenses.inc @@ -94,6 +94,9 @@ class opsiLicenses extends plugin if($_POST['menu_action'] == "remove_multiple_licenses"){ $s_action = "remove_multiple"; } + if($_POST['menu_action'] == "license_new"){ + $s_action = "new"; + } } diff --git a/gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl b/gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl index 2f3c3e706..9b9252eef 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl +++ b/gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl @@ -10,16 +10,20 @@ -
+

{t}Generic{/t}

@@ -34,42 +38,63 @@ + + + - - - - - -
{t}Name{/t} + {if $initially_was_account} + + {else} {render acl=$cnACL} {/render} + {/if}
+

 

+
+

{t}Licenses{/t}

- +
- +
+ +
+

{t}Applications{/t}

- +
- +
+
+ + + +

{t}Windows software IDs{/t}

- +
- +
+ + + + +
- + {/if} diff --git a/gosa-plugins/opsi/admin/opsiLicenses/main.inc b/gosa-plugins/opsi/admin/opsiLicenses/main.inc index f139c4fb3..84a4dac8f 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/main.inc +++ b/gosa-plugins/opsi/admin/opsiLicenses/main.inc @@ -49,12 +49,12 @@ if ( $cleanup ){ /* Page header*/ if (get_object_info() != ""){ - $display= print_header(get_template_path('plugins/licensemanagement/images/plugin.png'), + $display= print_header(get_template_path('plugins/opsiLicenses/images/plugin.png'), _("Licenses"), "\"\" ". LDAP::fix(get_object_info())); } else { - $display= print_header(get_template_path('plugins/licensemanagement/images/plugin.png'), _("License management")); + $display= print_header(get_template_path('plugins/opsiLicenses/images/plugin.png'), _("License management")); } $display.= $output; -- 2.30.2