From: hickert Date: Fri, 25 Sep 2009 15:08:48 +0000 (+0000) Subject: Fixed opsi host license ussage X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=415f1acde9de30a47dea71d6f9436bd8e1b98a00;p=gosa.git Fixed opsi host license ussage git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14353 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_licenseUsageByHost.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_licenseUsageByHost.inc index 866d6f28d..4618df364 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/class_licenseUsageByHost.inc +++ b/gosa-plugins/opsi/admin/opsiLicenses/class_licenseUsageByHost.inc @@ -54,10 +54,12 @@ class licenseUsageByHost extends plugin { $this->licenseUses = array(); $this->reservedLicenses = array(); + $this->init_reservedLicenses = array(); if(!$this->initially_was_account){ $this->init_successfull = TRUE; }else{ + // Get license usage $res = $this->si->getLicenseUsage($this->cn); if($this->si->is_error()){ $this->init_successfull = FALSE; @@ -65,17 +67,30 @@ class licenseUsageByHost extends plugin } $this->licenseUses = $res; + // Get reservations $res = $this->si->getReservedLicensesForHost($this->cn); if($this->si->is_error()){ $this->init_successfull = FALSE; return; } - $this->reservedLicenses = $res; - $this->init_reservedLicenses = $res; + foreach($res as $pool){ + $this->reservedLicenses[] = $pool['licensePoolId'][0]; + } + $this->init_reservedLicenses = $this->reservedLicenses; + + // Get list of license pools + $res = $this->si->listPools(); + if($this->si->is_error()){ + $this->init_successfull = FALSE; + return; + } + $this->availableLicenses = array(); + foreach($res as $pool){ + $this->availableLicenses[] = $pool['cn'][0]; + } + $this->init_successfull = TRUE; } - - $this->availableLicenses = array("Dummy","Schinken"); } @@ -105,13 +120,10 @@ class licenseUsageByHost extends plugin foreach($this->reservedLicenses as $key => $license){ $action = ""; - $f1 = array("string" => $license['licensePoolId'][0]); -# $f2 = array("string" => $license['licenseKey'][0]); - $f3 = array("string" => $license['softwareLicenseId'][0]); + $f1 = array("string" => $license); $f4 = array("string" => $action, - "attach" => "style='border-right:0px;'"); -# $list2->addEntry(array($f1,$f2,$f3, $f4)); - $list2->addEntry(array($f1,$f3, $f4)); + "attach" => "style='border-right:0px; width:16px;'"); + $list2->addEntry(array($f1,$f4)); } $smarty = get_smarty(); @@ -128,7 +140,7 @@ class licenseUsageByHost extends plugin $smarty->assign("licenseUses", $list->DrawList()); $smarty->assign("licenseReserved", $list2->DrawList()); $smarty->assign("init_successfull", $this->init_successfull); - $smarty->assign("availableLicenses", $this->availableLicenses); + $smarty->assign("availableLicenses", array_diff($this->availableLicenses, $this->reservedLicenses)); $smarty->assign("initially_was_account", $this->initially_was_account); return($smarty->fetch(get_template_path('licenseUsageByHost.tpl',TRUE,dirname(__FILE__)))); } @@ -154,7 +166,10 @@ class licenseUsageByHost extends plugin // Check if we've to add reservations if(isset($_POST['availableLicense']) && isset($_POST['addReservation'])){ - echo get_post('availableLicense'); + $id = get_post('availableLicense'); + if(isset($this->availableLicenses[$id])){ + $this->reservedLicenses[] = $this->availableLicenses[$id]; + } } } } @@ -169,7 +184,27 @@ class licenseUsageByHost extends plugin } - function save(){ } + function save() + { + $del = array_diff($this->init_reservedLicenses, $this->reservedLicenses); + $add = array_diff($this->reservedLicenses, $this->init_reservedLicenses); + + foreach($del as $pool){ + $this->si->removeLicenseFromHost($pool, $this->cn); + if($this->si->is_error()){ + msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG); + } + } + + foreach($add as $pool){ + $this->si->addLicenseToHost($pool, $this->cn); + if($this->si->is_error()){ + msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG); + } + } + } + + function remove_from_parent(){ } diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc index c90013698..0a99b2223 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc +++ b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc @@ -308,7 +308,7 @@ class opsiLicenceHandler extends opsi { { $data= array(); $data['licensePoolId'] = htmlentities($licensePoolId); - $data['hostId'] = htmlentities($hostid); + $data['hostId'] = htmlentities($hostId); $res = $this->send_data("gosa_opsi_unassignSoftwareLicenseFromHost",$this->target,$data,TRUE); if(isset($res['XML'][0]['ANSWER_OPSI_UNASSIGNSOFTWARELICENSEFROMHOST'])){ return(TRUE);