From: hickert Date: Thu, 24 Sep 2009 15:31:32 +0000 (+0000) Subject: Updated license management X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4636ac45979659ed8f5cd57405372dc96b10eab4;p=gosa.git Updated license management git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14343 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_licenseGeneric.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_licenseGeneric.inc index 726de0787..bba0c8ea3 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/class_licenseGeneric.inc +++ b/gosa-plugins/opsi/admin/opsiLicenses/class_licenseGeneric.inc @@ -25,12 +25,41 @@ class licenseGeneric extends plugin { var $si = NULL; + var $data = array(); + var $cn = ""; + var $description = ""; + var $partner = ""; + + var $conclusionDate = ""; + var $expirationDate = ""; + var $notificationDate = ""; + + var $licenseModel = ""; + var $licenseKey = ""; + var $licensePoolId = ""; + var $boundToHost= array(); // Reserved for Host. + var $usedByHost = array(); // Used by Host. + + var $maximumInstallations = 0; + var $opsiHosts; + + var $attributes = array("cn","description","partner","conclusionDate","expirationDate", + "notificationDate","licenseModel","licenseKey","maximumInstallations","licensePoolId"); - function __construct(&$config,$dn, $license) + function __construct(&$config, $license, $hosts = array()) { $this->config = $config; - $this->dn = $this->orig_dn = $dn; + $this->data = $license; $this->si = new opsiLicenceHandler($this->config); + $this->opsiHosts = $hosts; + + // Detect account state. + if(count($this->data) == 0){ + $this->initially_was_account = FALSE; + }else{ + $this->initially_was_account = TRUE; + } + $this->is_account = TRUE; // Extract pool name out of the fake dn. $this->init(); @@ -39,17 +68,44 @@ class licenseGeneric extends plugin function init() { - // Load local Boot Products - $res = $this->si->get_local_products(); - if($this->si->is_error()){ - $this->init_successfull = FALSE; - return(FALSE); + + $map = array( + "BOUNDTOHOST"=> "boundToHost", + "EXPIRATIONDATE"=> "expirationDate", + "LICENSECONTRACTID"=> "contractId", + "LICENSEPOOIDS"=> "licensePoolId", + "LICENSETYPE"=> "licenseModel", + "MAXINSTALLATIONS"=> "maximumInstallations", + "SOFTWARELICENSEID"=> "cn"); + + foreach($map as $source => $target){ + if(isset($this->data[$source][0]['VALUE'])){ + $this->$target = $this->data[$source][0]['VALUE']; + } + } + + // Get license key + if(isset($this->data['LICENSEKEYS'][0][strtoupper($this->licensePoolId)][0]['VALUE'])){ + $this->licenseKey = $this->data['LICENSEKEYS'][0][strtoupper($this->licensePoolId)][0]['VALUE']; + } + + // Get license usage + $this->usedByHost = array(); + if(isset($this->data['HOSTIDS'])){ + foreach($this->data['HOSTIDS'] as $host){ + $this->usedByHost[] = $host['VALUE']; + } } + + $this->init_successfull = TRUE; + return; } function execute() { + $this->init(); + // Handle initialization failures. if(isset($_POST['retry_init'])) $this->init(); if(!$this->init_successfull){ @@ -69,11 +125,35 @@ class licenseGeneric extends plugin $smarty->assign($attr,$this->$attr); } + $smarty->assign("licenseModels",array( + "RETAIL" => _("Retail"), + "OEM"=>_("OEM"), + "VOLUME" => _("Volume"), + "CONCURRENT" => _("Concurrent"))); + + $smarty->assign("init_successfull", $this->init_successfull); $smarty->assign("initially_was_account", $this->initially_was_account); + $smarty->assign("hosts", $this->getHosts()); + + $smarty->assign("notUsedHosts", array_diff($this->getHosts(), $this->usedByHost)); + $smarty->assign("usedByHost", $this->usedByHost); + $smarty->assign("boundToHost", $this->boundToHost); return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__)))); } + + function getHosts() + { + $ret = array(); + foreach($this->opsiHosts as $host){ + $cn = $host['NAME'][0]['VALUE']; + $ret[$cn] = $cn; + } + return($ret); + } + + /* Save HTML inputs */ diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_licensePoolGeneric.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_licensePoolGeneric.inc index 5cdd41f56..5f017604d 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/class_licensePoolGeneric.inc +++ b/gosa-plugins/opsi/admin/opsiLicenses/class_licensePoolGeneric.inc @@ -39,6 +39,8 @@ class licensePoolGeneric extends plugin var $attributes =array("cn","description"); var $si = NULL; + var $opsiHosts = array(); + function __construct(&$config,$dn) { $this->config = $config; @@ -63,12 +65,22 @@ class licensePoolGeneric extends plugin { // Load local Boot Products $res = $this->si->get_local_products(); + $this->availableProductIds=array(); if($this->si->is_error()){ $this->init_successfull = FALSE; return(FALSE); } $this->availableProductIds=array_keys($res); + // Load opsi hosts + $res = $this->si->list_clients(); + $this->opsiHosts=array(); + if($this->si->is_error()){ + $this->init_successfull = FALSE; + return(FALSE); + } + $this->opsiHosts=$res; + // Load Pool if(!$this->initially_was_account){ $this->init_successfull = TRUE; @@ -102,6 +114,7 @@ class licensePoolGeneric extends plugin $this->licenses = array(); if(isset($this->data['licenses'])){ $this->licenses = $this->data['licenses']; + unset($this->licenses['count']); } $this->init_successfull = TRUE; return; @@ -120,6 +133,20 @@ class licensePoolGeneric extends plugin return($smarty->fetch(get_template_path('licensePoolGeneric.tpl',TRUE,dirname(__FILE__)))); } + // Display dialogs! + if($this->dialog instanceOf plugin){ + $this->dialog->save_object(); + $display = $this->dialog->execute(); + $display.= + "

+   + +

"; + return($display); + } + $smarty = get_smarty(); // Assign ACls @@ -144,10 +171,7 @@ class licensePoolGeneric extends plugin { $list = new divSelectBox("test"); $list->setHeight(100); - for($i=0 ; $i<$this->licenses['count'] ; $i++){ - - $license = $this->licenses[$i]; - + foreach($this->licenses as $i => $license){ $keys = ""; foreach($license['LICENSEKEYS'] as $key_by_pool){ foreach($key_by_pool as $key){ @@ -175,7 +199,20 @@ class licensePoolGeneric extends plugin */ function save_object() { - if(isset($_POST['opsiLicensesPosted'])){ + // Close license edit dialogs. + if($this->dialog instanceOf plugin && isset($_POST['license_cancel'])){ + $this->dialog = NULL; + return; + } + + // Save license modifications + if($this->dialog instanceOf plugin && isset($_POST['license_finish'])){ + echo "Save"; + $this->dialog = NULL; + return; + } + + if(isset($_POST['opsiLicensePoolPosted'])){ plugin::save_object(); // Restore license cn, to avoid creating a copy... @@ -214,6 +251,24 @@ class licensePoolGeneric extends plugin } } } + + // Search post for image button clicks. + foreach($_POST as $name => $value){ + if(preg_match("/^editLicense_/",$name)){ + $id = preg_replace("/^editLicense_([^_]*)_.*$/","\\1",$name); + if(isset($this->licenses[$id])){ + $this->dialog = new licenseGeneric($this->config,$this->licenses[$id], $this->opsiHosts); + } + break; + } + if(preg_match("/^removeLicense_/",$name)){ + $id = preg_replace("/^removeLicense_([^_]*)_.*$/","\\1",$name); + if(isset($this->licenses[$id])){ + unset($this->licenses[$id]); + } + break; + } + } } } diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc index 30e983d38..7082a1093 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc +++ b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc @@ -85,11 +85,13 @@ class opsiLicenceHandler extends opsi { $data= array(); $data['licensePoolId'] = htmlentities($licensePoolId); $res = $this->send_data("gosa_opsi_getPool",$this->target,$data,TRUE); + if(isset($res['XML'][0]['ANSWER_OPSI_GETPOOL'])){ $item = array(); foreach(array("LICENSEPOOLID" => "cn", "DESCRIPTION" => "description", "LICENSES" => "licenses", + "LICENSECONTRACTDATA" => "contract", "WINDOWSSOFTWAREIDS" => "softwareId", "PRODUCTIDS" => "productId") as $source => $target){ if(isset($res['XML'][0][$source])){ @@ -155,7 +157,7 @@ class opsiLicenceHandler extends opsi { * @param boundToHost The name of the client the license is bound to (optional). * @param expirationDate The date when the license is running down (optional). */ - function createLicense($poolId, $licenseKey,$licenseTyp = "", + function createLicense($poolId, $licenseId, $licenseKey,$licenseTyp = "", $partner = "", $conclusionDate = "", $notificationDate ="", @@ -168,7 +170,8 @@ class opsiLicenceHandler extends opsi { $data= array(); $data['licensePoolId'] = htmlentities($poolId); - $data['licenseKey'] = htmlentities($licenseKey); + $data['licenseKey'] = htmlentities($licenseKey); + $data['licenseId'] = htmlentities($licenseId); // Append optional attributes foreach(array("partner","conclusionDate","notificationDate","notes","softwareLicenseId", diff --git a/gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl b/gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl index 4e3fe3ec4..23fa57373 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl +++ b/gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl @@ -7,91 +7,169 @@
{else} +

{t}License{/t}

- - -
- -

{t}Generic{/t}

+ + + - - -
+ - - + + - - + +
{t}Name{/t}
- {if $initially_was_account} - - {else} -{render acl=$cnACL} - -{/render} - {/if} + {t}Name{/t} + +
{t}Description{/t}
-{render acl=$descriptionACL} - -{/render} + {t}Partner{/t} + +
- -

{t}Licenses{/t}

- - + - - + + - -
+ + + +
+ {t}Description{/t} + - {$licenses} +
-

 

-

 

- -

{t}Applications{/t}

- - - + + +
-
- - - +
+ + + + + + + + +
+ {t}Conclusion date{/t} + + +
+ {t}Expiration date{/t} + +
+ +
+ + + + + + +
+ {t}Notification date{/t} + + +
+
-
- -

{t}Windows software IDs{/t}

- - - +

 

+ +
- + + + +
+ + + + +
+ {t}Model{/t} + + - - -
+ +
-
+ + +
+ + + + + + + + + + + + + + +
+ {t}License key{/t} + + +
+ {t}Maximum installations{/t} + + +
+ {t}Reserved for Host{/t} + + +
+ +
+ + + + + +
+ {t}Assigned to Host{/t}
+
+ + + +
+
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/licensePoolGeneric.tpl b/gosa-plugins/opsi/admin/opsiLicenses/licensePoolGeneric.tpl index 4e3fe3ec4..3755e82f6 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/licensePoolGeneric.tpl +++ b/gosa-plugins/opsi/admin/opsiLicenses/licensePoolGeneric.tpl @@ -37,7 +37,7 @@
+

{t}Licenses{/t}

@@ -75,7 +75,7 @@
+

{t}Windows software IDs{/t}

@@ -94,5 +94,5 @@
- + {/if} diff --git a/gosa-plugins/opsi/admin/opsiLicenses/licenseUsageByHost.tpl b/gosa-plugins/opsi/admin/opsiLicenses/licenseUsageByHost.tpl index fd7c57202..68eae0a0a 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/licenseUsageByHost.tpl +++ b/gosa-plugins/opsi/admin/opsiLicenses/licenseUsageByHost.tpl @@ -10,7 +10,7 @@ -
+

{t}Licenses used{/t}

{$licenseUses}