diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_licenseUsageByHost.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_licenseUsageByHost.inc
index 10d9a2074900fa63366d96cdfef82597f02962c6..c89e762b28a9d2065afe3ae7c1051cf34c1ba82b 100644 (file)
var $cn = "";
var $licenseUses = array();
+ var $reservedLicenses = array();
var $init_successfull = FALSE;
+ var $availableLicenses = array();
function __construct(&$config,$dn)
{
$this->initially_was_account = FALSE;
}else{
$this->initially_was_account = TRUE;
- $this->cn = $this->orig_cn = preg_replace("/^opsi:cn=([^,]*),.*$/","\\1",$dn);
+ $this->cn = $this->orig_cn = preg_replace("/^opsi:=([^,]*),.*$/","\\1",$dn);
}
// Extract pool name out of the fake dn.
function init()
{
$this->licenseUses = array();
+ $this->reservedLicenses = array();
+ $this->init_reservedLicenses = array();
if(!$this->initially_was_account){
$this->init_successfull = TRUE;
}else{
- $res = $this->si->getLicenseUsage("", $this->cn);
+ // Get license usage
+ $res = $this->si->getLicenseUsage($this->cn);
if($this->si->is_error()){
+ msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG);
$this->init_successfull = FALSE;
return;
}
-
$this->licenseUses = $res;
+
+ // Get reservations
+ $res = $this->si->getReservedLicensesForHost($this->cn);
+ if($this->si->is_error()){
+ msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG);
+ $this->init_successfull = FALSE;
+ return;
+ }
+ foreach($res as $pool){
+ $l = $pool['softwareLicenseId'][0];
+ $this->reservedLicenses[$l] = $l;
+ }
+ $this->init_reservedLicenses = $this->reservedLicenses;
+
+ // Get list of license pools
+ $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();
+ foreach($res as $license){
+ if(!isset($license['licensePoolId'])) $license['licensePoolId'][0] = '-';
+ $this->availableLicenses[$license['softwareLicenseId'][0]] = $license;
+ }
+
$this->init_successfull = TRUE;
}
}
function execute()
{
+ plugin::execute();
+
// Handle initialization failures.
if(isset($_POST['retry_init'])) $this->init();
if(!$this->init_successfull){
// Create usage list
$list = new divSelectBox("licenseUsage");
+ $list->setHeight(150);
foreach($this->licenseUses as $license){
+ if(preg_match("/r/i",$this->getacl('hostId'))){
+ $f3 = array("string" => $license['licenseKey'][0]);
+ $f2 = array("string" => $license['licensePoolId'][0]);
+ $f4 = array("string" => $license['softwareLicenseId'][0]);
+ $list->addEntry(array($f2,$f3,$f4));
+ }
+ }
+
+ // Create reserved list
+ $list2 = new divSelectBox("reservedLicenses");
+ $list2->setHeight(150);
+ foreach($this->reservedLicenses as $key => $license){
+ if(preg_match("/r/i",$this->getacl('boundToHost'))){
- $f1 = array("string" => $license['hostId'][0]);
- $f2 = array("string" => $license['licenseKey'][0]);
- $f3 = array("string" => $license['licensePoolId'][0]);
- $f4 = array("string" => $license['softwareLicenseId'][0],
- "attach" => "style='border-right:0px;'");
- $list->addEntry(array($f1,$f2,$f3,$f4));
+ $l = $this->availableLicenses[$key];
+
+ // Display remove button in case of write permissions
+ $action = "";
+ if(preg_match("/w/i",$this->getacl('boundToHost'))){
+ $action = "<input class='center' type='image' src='images/lists/trash.png'
+ name='removeReservation_{$key}'>";
+ }
+
+ $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));
+ }
}
$smarty = get_smarty();
$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", $licenses);
$smarty->assign("initially_was_account", $this->initially_was_account);
- return($smarty->fetch(get_template_path('licenseUsage.tpl',TRUE,dirname(__FILE__))));
+ return($smarty->fetch(get_template_path('licenseUsageByHost.tpl',TRUE,dirname(__FILE__))));
}
{
if(isset($_POST['opsiLicenseUsagePosted'])){
plugin::save_object();
+
+ if(preg_match("/w/i",$this->getacl('boundToHost'))){
+
+ // Check if we've to remove reservations
+ foreach($_POST as $name => $value){
+ if(preg_match("/^removeReservation_/", $name)){
+ $id = preg_replace("/^removeReservation_(.*)_.$/", "\\1" ,$name);
+ if(isset($this->reservedLicenses[$id])) {
+ unset($this->reservedLicenses[$id]);
+ }
+ break;
+ }
+ }
+
+ // Check if we've to add reservations
+ 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[$id] = $this->availableLicenses[$id]['softwareLicenseId'][0];
+ }
+ }
+ }
}
}
}
- /* Saves object modifications
- */
function save()
{
- plugin::save();
-
- // Send modify/add events
- $mode = "modify";
- if($this->orig_dn == "new"){
- $mode = "add";
- }
+ $del = array_diff($this->init_reservedLicenses, $this->reservedLicenses);
+ $add = array_diff($this->reservedLicenses, $this->init_reservedLicenses);
- $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);
+ foreach($del as $license){
+ $this->si->removeLicenseReservationFromHost($license, $this->cn);
+ if($this->si->is_error()){
+ msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG);
+ }
}
- // Log action
- if($mode == "modify"){
- 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),$this->si->get_error());
+ foreach($add as $license){
+ $this->si->reserverLicenseForHost($license, $this->cn);
+ if($this->si->is_error()){
+ msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG);
+ }
}
-
- return 0;
}
-
- function remove_from_parent(){ return; }
+
+ function remove_from_parent(){ }
static function plInfo()
{
return (array(
- "plShortName" => _("Usage"),
- "plDescription" => _("License usage"),
+ "plShortName" => _("Usage by host"),
+ "plDescription" => _("License usage by host"),
"plSelfModify" => FALSE,
"plDepends" => array(),
- "plPriority" => 1,
+ "plPriority" => 13,
"plSection" => array("administration"),
"plCategory" => array("opsi"),
"plProvidedAcls"=> array(
- "cn" => _("Name"),
- "description" => _("Description"))
+ "hostId" => _("Used by"),
+ "boundToHost" => _("License reservation"))
));
}
}