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:=([^,]*),.*$/","\\1",$dn); } // Extract pool name out of the fake dn. $this->init(); } function init() { $this->licenseUses = array(); if(!$this->initially_was_account){ $this->init_successfull = TRUE; }else{ $res = $this->si->getLicenseUsage($this->cn); if($this->si->is_error()){ $this->init_successfull = FALSE; return; } $this->licenseUses = $res; $this->reservedLicenses = $res; $this->init_reservedLicenses = $res; $this->init_successfull = TRUE; } $this->availableLicenses = array("Dummy","Schinken"); } function execute() { // Handle initialization failures. if(isset($_POST['retry_init'])) $this->init(); if(!$this->init_successfull){ $smarty = get_smarty(); $smarty->assign("init_successfull", $this->init_successfull); return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__)))); } // Create usage list $list = new divSelectBox("licenseUsage"); $list->setHeight(150); foreach($this->licenseUses as $license){ $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){ $action = ""; $f1 = array("string" => $license['licensePoolId'][0]); $f2 = array("string" => $license['licenseKey'][0]); $f3 = array("string" => $license['softwareLicenseId'][0]); $f4 = array("string" => $action, "attach" => "style='border-right:0px;'"); $list2->addEntry(array($f1,$f2,$f3, $f4)); } $smarty = get_smarty(); // Assign ACls $plInfo = $this->plInfo(); foreach($plInfo['plProvidedAcls'] as $name => $desc){ $smarty->assign("{$name}ACL",$this->getacl($name)); } foreach($this->attributes as $attr){ $smarty->assign($attr,$this->$attr); } $smarty->assign("licenseUses", $list->DrawList()); $smarty->assign("licenseReserved", $list2->DrawList()); $smarty->assign("init_successfull", $this->init_successfull); $smarty->assign("availableLicenses", $this->availableLicenses); $smarty->assign("initially_was_account", $this->initially_was_account); return($smarty->fetch(get_template_path('licenseUsageByHost.tpl',TRUE,dirname(__FILE__)))); } /* Save HTML inputs */ function save_object() { if(isset($_POST['opsiLicenseUsagePosted'])){ plugin::save_object(); // 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'])){ echo get_post('availableLicense'); } } } /* Check user input and return a list of 'invalid input' messages. */ function check() { $message = plugin::check(); return($message); } function save(){ } function remove_from_parent(){ } static function plInfo() { return (array( "plShortName" => _("Usage"), "plDescription" => _("License usage"), "plSelfModify" => FALSE, "plDepends" => array(), "plPriority" => 1, "plSection" => array("administration"), "plCategory" => array("opsi"), "plProvidedAcls"=> array( "cn" => _("Name"), "description" => _("Description")) )); } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?>