From d3f80960913a0e707b78d05de8b1f25bfd164629 Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 29 Sep 2009 07:56:29 +0000 Subject: [PATCH] Updated host usage git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14381 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../opsiLicenses/class_licenseUsageByHost.inc | 32 +++++++++----- .../opsiLicenses/class_opsiLicenseHandler.inc | 44 +++++++++++++++++++ 2 files changed, 66 insertions(+), 10 deletions(-) diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_licenseUsageByHost.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_licenseUsageByHost.inc index 60ba6d6f8..21a81c777 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/class_licenseUsageByHost.inc +++ b/gosa-plugins/opsi/admin/opsiLicenses/class_licenseUsageByHost.inc @@ -76,23 +76,22 @@ class licenseUsageByHost extends plugin return; } foreach($res as $pool){ - $this->reservedLicenses[] = $pool['licensePoolId'][0]; + $l = $pool['softwareLicenseId'][0]; + $this->reservedLicenses[$l] = $l; } $this->init_reservedLicenses = $this->reservedLicenses; // Get list of license pools - $res = $this->si->listPools(); + $res = $this->si->listLicenses(); if($this->si->is_error()){ msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG); $this->init_successfull = FALSE; return; } $this->availableLicenses = array(); - - echo "We require Licenses here not Pools"; - - foreach($res as $pool){ - $this->availableLicenses[] = $pool['cn'][0]; + foreach($res as $license){ + if(!isset($license['licensePoolId'])) $license['licensePoolId'][0] = '-'; + $this->availableLicenses[$license['softwareLicenseId'][0]] = $license; } $this->init_successfull = TRUE; @@ -102,6 +101,7 @@ class licenseUsageByHost extends plugin function execute() { + // Handle initialization failures. if(isset($_POST['retry_init'])) $this->init(); if(!$this->init_successfull){ @@ -128,13 +128,17 @@ class licenseUsageByHost extends plugin foreach($this->reservedLicenses as $key => $license){ if(preg_match("/r/i",$this->getacl('boundToHost'))){ + $l = $this->availableLicenses[$key]; + // Display remove button in case of write permissions $action = ""; if(preg_match("/w/i",$this->getacl('boundToHost'))){ $action = ""; } - $f1 = array("string" => $license); + + $f1 = array("string" => $l['softwareLicenseId'][0]); + $f2 = array("string" => $l['licensePoolId'][0]); $f4 = array("string" => $action, "attach" => "style='border-right:0px; width:16px;'"); $list2->addEntry(array($f1,$f4)); @@ -152,10 +156,18 @@ class licenseUsageByHost extends plugin $smarty->assign($attr,$this->$attr); } + // build up a available licenses list. + $licenses = array(); + foreach($this->availableLicenses as $key => $license){ + if(!in_array($license['softwareLicenseId'][0], $this->reservedLicenses)){ + $licenses[$key] = $license['softwareLicenseId'][0]." [".$license['licensePoolId'][0]."]"; + } + } + $smarty->assign("licenseUses", $list->DrawList()); $smarty->assign("licenseReserved", $list2->DrawList()); $smarty->assign("init_successfull", $this->init_successfull); - $smarty->assign("availableLicenses", array_diff($this->availableLicenses, $this->reservedLicenses)); + $smarty->assign("availableLicenses", $licenses); $smarty->assign("initially_was_account", $this->initially_was_account); return($smarty->fetch(get_template_path('licenseUsageByHost.tpl',TRUE,dirname(__FILE__)))); } @@ -185,7 +197,7 @@ class licenseUsageByHost extends plugin if(isset($_POST['availableLicense']) && isset($_POST['addReservation'])){ $id = get_post('availableLicense'); if(isset($this->availableLicenses[$id]) && !in_array($this->availableLicenses[$id],$this->reservedLicenses)){ - $this->reservedLicenses[] = $this->availableLicenses[$id]; + $this->reservedLicenses[$id] = $this->availableLicenses[$id]['softwareLicenseId'][0]; } } } diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc index 45a5bce36..39eb2ece8 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc +++ b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc @@ -140,6 +140,50 @@ class opsiLicenceHandler extends opsi { * LICENSES *******************/ + + function listLicenses() + { + $data= array(); + $res = $this->send_data("gosa_opsi_getAllSoftwareLicenses",$this->target,$data,TRUE); + if(isset($res['XML'][0]['ANSWER_OPSI_GETALLSOFTWARELICENSES'])){ + + $licenses = array(); + if(isset($res['XML'][0]['LICENSES'][0]['HIT'])){ + foreach($res['XML'][0]['LICENSES'][0]['HIT'] as $entry){ + + $item = array(); + + // License keys are indexed by the pool id, map it here. + if(isset($entry['LICENSEPOOLIDS'][0]['VALUE'])){ + $n = strtoupper($entry['LICENSEPOOLIDS'][0]['VALUE']); + $entry['LICENSEKEYS'] = $entry['LICENSEKEYS'][0][$n]; + } + + // Now fake an ldap like result + foreach(array( + "BOUNDTOHOST" => "boundToHost", + "LICENSEKEYS" => "licenseKey", + "LICENSEPOOLIDS" => "licensePoolId", + "LICENSETYPE" => "licenseType", + "SOFTWARELICENSEID" => "softwareLicenseId") as $source => $target){ + if(isset($entry[$source])){ + $item[$target] = array('count' => 0); + foreach($entry[$source] as $data){ + $item[$target][] = $data['VALUE']; + } + $item[$target]['count'] = count($item[$target]) -1 ; + } + } + + $licenses[] = $item; + } + } + return($licenses); + } + return(FALSE); + } + + /* * @brief * Create a license contract, create a software -- 2.30.2