summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fd9134f)
raw | patch | inline | side by side (parent: fd9134f)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 25 Sep 2009 09:37:02 +0000 (09:37 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 25 Sep 2009 09:37:02 +0000 (09:37 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14346 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 bba0c8ea30aa45a39086e251e10c37384df27ad7..0443d7f389bf3e578897a466a534bc325abbfe5c 100644 (file)
var $si = NULL;
var $data = array();
var $cn = "";
+ var $orig_cn = "";
var $description = "";
var $partner = "";
var $notificationDate = "";
var $licenseModel = "";
- var $licenseKey = "";
+ var $licenseKey = array();
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");
+ var $attributes = array(
+ "cn","description","partner","conclusionDate","expirationDate",
+ "notificationDate","licenseModel","licenseKey","maximumInstallations",
+ "licensePoolId", "usedByHost","boundToHost");
function __construct(&$config, $license, $hosts = array())
{
function init()
{
-
- $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->boundToHost = array('0'=>"");
+ $this->usedByHost = array('0'=>"");
+ $this->licenseKey = array('0'=>"");
+ if($this->initially_was_account){
+ foreach($this->attributes as $attr){
+ $this->$attr = $this->data[$attr];
}
}
+ $this->orig_cn = $this->cn;
$this->init_successfull = TRUE;
return;
}
function execute()
{
- $this->init();
-
// Handle initialization failures.
if(isset($_POST['retry_init'])) $this->init();
if(!$this->init_successfull){
$smarty->assign("hosts", $this->getHosts());
$smarty->assign("notUsedHosts", array_diff($this->getHosts(), $this->usedByHost));
- $smarty->assign("usedByHost", $this->usedByHost);
- $smarty->assign("boundToHost", $this->boundToHost);
+ $smarty->assign("boundToHost", $this->boundToHost[0]);
+ $smarty->assign("licenseKey", $this->licenseKey[0]);
return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
}
*/
function save_object()
{
+
if(isset($_POST['opsiLicensesPosted'])){
- plugin::save_object();
+ plugin::save_object();
+
+ // Force licenseKey to be of type array.
+ $this->licenseKey = array($this->licenseKey);
+
+ // BoundToHost maybe multiple too, later.
+ $this->boundToHost = array($this->boundToHost);
+
+ if($this->initially_was_account){
+ $this->cn = $this->orig_cn;
+ }
}
}
*/
function save()
{
-
- echo "missing save";
-# plugin::save();
-#
-# // Send modify/add events
-# $mode = "modify";
-# if($this->orig_dn == "new"){
-# $mode = "add";
-# }
-#
-# $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);
-# }
-#
-# // 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());
-# }
-#
-# return 0;
+ $data = array();
+ foreach($this->attributes as $target){
+ $data[$target] = $this->$target;
+ }
+ return($data);
}
static function plInfo()
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_licensePoolGeneric.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_licensePoolGeneric.inc
index 5f017604dcfe30bb2f26d7f7ab0dbe61d2ae50cc..741ffcb0863c22ba2c31c45681922f3939a2f8d7 100644 (file)
var $productIds = array();
var $softwareIds= array();
var $licenses = array();
+ var $orig_licenses = array();
var $availableProductIds = array();
var $attributes =array("cn","description");
var $opsiHosts = array();
+ var $licenseMap = array(
+ "BOUNDTOHOST"=> "boundToHost",
+ "HOSTIDS"=> "usedByHost",
+ "LICENSEPOOLIDS"=> "licensePoolId",
+ "LICENSETYPE"=> "licenseModel",
+ "LICENSEKEY"=> "licenseKey",
+ "MAXINSTALLATIONS"=> "maximumInstallations",
+ "EXPIRATIONDATE"=> "expirationDate",
+ "SOFTWARELICENSEID"=> "cn"
+ );
+
+ var $licenseContractMap = array(
+ "CONCLUSIONDATE"=> "conclusionDate",
+ "NOTIFICATIONDATE"=> "notificationDate",
+ "NOTES"=> "description",
+ "PARTNER"=> "partner"
+ );
+
function __construct(&$config,$dn)
{
$this->config = $config;
// Load Licences
$this->licenses = array();
if(isset($this->data['licenses'])){
- $this->licenses = $this->data['licenses'];
- unset($this->licenses['count']);
+ for($i =0; $i< $this->data['licenses']['count']; $i++){
+ $license = $this->data['licenses'][$i];
+
+ // Do not parse invalid licenses
+ if(!is_array($license) || !isset($license['LICENSEPOOLIDS'])){
+ echo "Invalid license";
+ continue;
+ }
+
+ // Prepare Software License Key(s)
+ $upper = strtoupper($license['LICENSEPOOLIDS'][0]['VALUE']);
+ $license['LICENSEKEYS'] = $license['LICENSEKEYS'][0][$upper];
+
+ $entry = array();
+ foreach($this->licenseMap as $source => $target){
+ $entry[$target] = "";
+ if(isset($license[$source])){
+ if(count($license[$source]) >= 2){
+ $entry[$target] = array();
+ foreach($license[$source] as $sub){
+ $entry[$target][] = $sub['VALUE'];
+ }
+ }elseif(isset($license[$source][0]['VALUE'])){
+ $entry[$target] = $license[$source][0]['VALUE'];
+ }
+ }
+ }
+
+ $lData= $license['LICENSECONTRACTDATA'][0];
+ foreach($this->licenseContractMap as $source => $target){
+ if(isset($lData[$source])){
+ if(count($lData[$source]) >= 2){
+ $entry[$target] = array();
+ foreach($lData[$source] as $sub){
+ $entry[$target][] = $sub['VALUE'];
+ }
+ }elseif(isset($lData[$source][0]['VALUE'])){
+ $entry[$target] = $lData[$source][0]['VALUE'];
+ }
+ }
+ }
+
+ // There are some multi value attributes - force them to be of type array.
+ foreach(array("boundToHost","usedByHost","licenseKey") as $attr){
+ if(!is_array($entry[$attr])){
+ $entry[$attr] = array($entry[$attr]);
+ }
+ }
+ $this->licenses[$entry['cn']] = $entry;
+ }
}
+
+ $this->orig_licenses = $this->licenses;
$this->init_successfull = TRUE;
return;
}
$list = new divSelectBox("test");
$list->setHeight(100);
foreach($this->licenses as $i => $license){
- $keys = "";
- foreach($license['LICENSEKEYS'] as $key_by_pool){
- foreach($key_by_pool as $key){
- $keys .= $key[0]['VALUE'].", ";
- }
- }
-
+ $keys = implode($license['licenseKey'],", ");
$link = "<input type='image' class='center' src='images/lists/edit.png' name='editLicense_{$i}'>";
$link.= "<input type='image' class='center' src='images/lists/trash.png' name='removeLicense_{$i}'>";
- $f1 = array("string" => $license['SOFTWARELICENSEID'][0]['VALUE'], "attach" => "");
- $f2 = array("string" => $license['LICENSETYPE'][0]['VALUE'], "attach" => "");
- $f3 = array("string" => $license['EXPIRATIONDATE'][0]['VALUE'], "attach" => "");
- $f4 = array("string" => $license['MAXINSTALLATIONS'][0]['VALUE'], "attach" => "");
+ $f1 = array("string" => $license['cn']);
+ $f2 = array("string" => $license['licenseModel']);
+ $f3 = array("string" => $license['expirationDate']);
+ $f4 = array("string" => $license['maximumInstallations']);
$f5 = array("string" => rtrim($keys,", "));
$f6 = array("string" => $link, "attach" => "style='border-right: 0px; width:32px;'");
// Save license modifications
if($this->dialog instanceOf plugin && isset($_POST['license_finish'])){
- echo "Save";
- $this->dialog = NULL;
+ $this->dialog->save_object();
+
+ $msgs = $this->dialog->check();
+ if(count($msgs)){
+ msg_dialog::displayChecks($msgs);
+ }else{
+ $attrs = $this->dialog->save();
+ $this->licenses[$attrs['cn']] = $attrs;
+ $this->dialog = NULL;
+ }
return;
}
}
}
+ // We've to create a new license
+ if(isset($_POST['addLicense'])){
+ $this->dialog = new licenseGeneric($this->config,array(), $this->opsiHosts);
+ $this->dialog->set_acl_base($this->config->current['BASE']);
+ }
+
// Search post for image button clicks.
foreach($_POST as $name => $value){
if(preg_match("/^editLicense_/",$name)){
- $id = preg_replace("/^editLicense_([^_]*)_.*$/","\\1",$name);
+ $id = preg_replace("/^editLicense_(.*)_.$/","\\1",$name);
if(isset($this->licenses[$id])){
$this->dialog = new licenseGeneric($this->config,$this->licenses[$id], $this->opsiHosts);
+ $this->dialog->set_acl_base($this->config->current['BASE']);
}
break;
}
if(preg_match("/^removeLicense_/",$name)){
- $id = preg_replace("/^removeLicense_([^_]*)_.*$/","\\1",$name);
+ $id = preg_replace("/^removeLicense_(.*)_.$/","\\1",$name);
if(isset($this->licenses[$id])){
unset($this->licenses[$id]);
}
$mode = "add";
}
+ // Create or update the pool
$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);
$this->handle_post_events($mode);
}
+ // Create, remove or update licenses
+ $add = array_diff_assoc($this->licenses,$this->orig_licenses);
+ $del = array_diff_assoc($this->orig_licenses,$this->licenses);
+
+ // Remove licenses
+ foreach($del as $license){
+ $this->si->removeLicenseFromPool($this->cn, $license['cn']);
+ if($this->si->is_error()){
+ msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG);
+ }
+ }
+
+ // Add / update licenses
+ foreach($add as $license){
+ $this->si->createLicense(
+ $this->cn, // Pool id
+ $license['cn'],
+ $license['licenseKey'][0],
+ $license['licenseModel'],
+ $license['partner'],
+ $license['conclusionDate'],
+ $license['notificationDate'],
+ $license['description'],
+ $license['cn'],
+ $license['maximumInstallations'],
+ $license['boundToHost'],
+ $license['expirationDate']);
+ 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());
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_licenseUsage.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_licenseUsage.inc
index c4fde8e6920edd2bc08f5bcb3f5862f76628ab62..fda4c732c2abd5bcd4ddd9f104aaa2cf1f301581 100644 (file)
}
// Extract pool name out of the fake dn.
- $this->init();
+# $this->init();
}
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc
index 7082a109360e79e79631671c65687ddcb2f777b5..2a6f6048d2e8ca5c3f6332f925f973a5d03943c0 100644 (file)
$notes = "",
$softwareLicenseId = "",
$maxInstallations = "",
- $boudToHost = "",
+ $boundToHost = "",
$expirationDate = "")
{
// Append optional attributes
foreach(array("partner","conclusionDate","notificationDate","notes","softwareLicenseId",
- "licenseTyp","maxInstallations","boudToHost","expirationDate") as $attr){
+ "licenseTyp","maxInstallations","boundToHost","expirationDate") as $attr){
if(!empty($$attr)){
$data[$attr] = $$attr;
}
}
+ print_a($data);
+
$res = $this->send_data("gosa_opsi_createLicense",$this->target,$data,TRUE);
if(isset($res['XML'][0]['ANSWER_OPSI_GETSOFTWARELICENSE_HASH'])){
return(TRUE);
return(FALSE);
}
+ /*
+ * @brief Removes a single license from a license pool
+ * Attention, the software license has to exists
+ * otherwise it will lead to an Opsi internal server error.
+ * @param softwareLicenseId
+ * @param licensePoolId
+ */
+ function removeLicenseFromPool($licensePoolId,$softwareLicenseId)
+ {
+ $data= array();
+ $data['licensePoolId'] = htmlentities($licensePoolId);
+ $data['softwareLicenseId'] = htmlentities($softwareLicenseId);
+ $res = $this->send_data("gosa_opsi_removeLicense",$this->target,$data,TRUE);
+ if(isset($res['XML'][0]['ANSWER_OPSI_REMOVELICENSE'])){
+ return(TRUE);
+ }
+ return(FALSE);
+ }
+
/*
* @brief Unassign all software licenses from a host
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl b/gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl
index 23fa57373b1308d63564c7fd30311b5770db0aaa..c375d2b24b55884ad04d59eeaed39a9e01d6e5b1 100644 (file)
{t}Name{/t}
</td>
<td>
- <input type='text' name='cn' value='{$cn}'>
+ {if $initially_was_account}
+ <input type='text' name='dummy12' disabled value='{$cn}'>
+ {else}
+ <input type='text' name='cn' value='{$cn}'>
+ {/if}
</td>
</tr>
<tr>
diff --git a/gosa-plugins/opsi/admin/opsiLicenses/licensePoolGeneric.tpl b/gosa-plugins/opsi/admin/opsiLicenses/licensePoolGeneric.tpl
index 3755e82f65ee289903782fd0baa7ac6dc6486f85..e67729f746cbc0ed836b2a9a2166df57155aa956 100644 (file)
<tr>
<td>
{$licenses}
+ <input type='submit' name='addLicense' value='{msgPool type=addButton}'>
</td>
</tr>
</table>