From bcdd3c2bcbd7d8a2a404d70b1cd50d3549c20631 Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 25 Sep 2009 11:41:06 +0000 Subject: [PATCH] Updated license generic git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14348 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../opsiLicenses/class_licenseGeneric.inc | 47 ++++++++++++------- .../opsiLicenses/class_licensePoolGeneric.inc | 39 +++++++++++++-- .../opsiLicenses/class_opsiLicenseHandler.inc | 6 +-- .../admin/opsiLicenses/licenseGeneric.tpl | 14 ++++-- 4 files changed, 76 insertions(+), 30 deletions(-) diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_licenseGeneric.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_licenseGeneric.inc index d1048ac17..b2cc4d6e1 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/class_licenseGeneric.inc +++ b/gosa-plugins/opsi/admin/opsiLicenses/class_licenseGeneric.inc @@ -37,6 +37,7 @@ class licenseGeneric extends plugin var $licenseModel = ""; var $licenseKey = array(); + var $orig_licenseModel = ""; var $licensePoolId = ""; var $boundToHost= array(); // Reserved for Host. var $usedByHost = array(); // Used by Host. @@ -81,6 +82,7 @@ class licenseGeneric extends plugin } $this->orig_cn = $this->cn; + $this->orig_licenseModel = $this->licenseModel; $this->init_successfull = TRUE; return; } @@ -145,14 +147,37 @@ class licenseGeneric extends plugin if(isset($_POST['opsiLicensesPosted'])){ plugin::save_object(); + if(isset($_POST['addLicenseUsage']) && isset($_POST['selectedHostToAdd'])){ + $host = get_post('selectedHostToAdd'); + if(!empty($host) && + in_array($host,$this->getHosts()) && + !in_array($host, $this->usedByHost)){ + $this->usedByHost[] = $host; + } + } + + if(isset($_POST['removeLicenseUsage']) && isset($_POST['selectedUsedHosts'])){ + $todel = $_POST['selectedUsedHosts']; + foreach($todel as $host){ + if(isset($this->usedByHost[$host])){ + unset($this->usedByHost[$host]); + } + } + } + // Force licenseKey to be of type array. - $this->licenseKey = array($this->licenseKey); + if(!is_array($this->licenseKey)){ + $this->licenseKey = array($this->licenseKey); + } // BoundToHost maybe multiple too, later. - $this->boundToHost = array($this->boundToHost); + if(!is_array($this->boundToHost)){ + $this->boundToHost = array($this->boundToHost); + } if($this->initially_was_account){ $this->cn = $this->orig_cn; + $this->licenseModel = $this->orig_licenseModel; } } } @@ -182,31 +207,17 @@ class licenseGeneric extends plugin $message[] = msgPool::required(_("Name")); } - if(empty($this->licenseKey)){ + if(empty($this->licenseKey[0])){ $message[] = msgPool::required(_("License key")); } return($message); } - /* Removes the object from the opsi database */ - function remove_from_parent() - { - echo "missing remove."; -# $this->si->deletePool($this->orig_cn); -# if($this->si->is_error()){ -# msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG); -# }else{ -# -# // Trigger remove signal -# $this->handle_post_events("remove"); -# } -# -# new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$this->si->get_error()); - } + function remove_from_parent() {} /* Saves object modifications diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_licensePoolGeneric.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_licensePoolGeneric.inc index 741ffcb08..1f69db577 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/class_licensePoolGeneric.inc +++ b/gosa-plugins/opsi/admin/opsiLicenses/class_licensePoolGeneric.inc @@ -47,7 +47,7 @@ class licensePoolGeneric extends plugin "HOSTIDS"=> "usedByHost", "LICENSEPOOLIDS"=> "licensePoolId", "LICENSETYPE"=> "licenseModel", - "LICENSEKEY"=> "licenseKey", + "LICENSEKEYS"=> "licenseKey", "MAXINSTALLATIONS"=> "maximumInstallations", "EXPIRATIONDATE"=> "expirationDate", "SOFTWARELICENSEID"=> "cn" @@ -106,6 +106,7 @@ class licensePoolGeneric extends plugin }else{ $res = $this->si->getPool($this->cn); + if($this->si->is_error()){ $this->init_successfull = FALSE; return(FALSE); @@ -180,6 +181,7 @@ class licensePoolGeneric extends plugin $entry[$attr] = array($entry[$attr]); } } + $entry['MODIFIED'] = FALSE; $this->licenses[$entry['cn']] = $entry; } } @@ -277,6 +279,7 @@ class licensePoolGeneric extends plugin msg_dialog::displayChecks($msgs); }else{ $attrs = $this->dialog->save(); + $attrs['MODIFIED'] = TRUE; $this->licenses[$attrs['cn']] = $attrs; $this->dialog = NULL; } @@ -399,8 +402,9 @@ class licensePoolGeneric extends plugin } // Create, remove or update licenses - $add = array_diff_assoc($this->licenses,$this->orig_licenses); - $del = array_diff_assoc($this->orig_licenses,$this->licenses); + $add = array_diff_assoc($this->licenses,$this->orig_licenses); + $del = array_diff_assoc($this->orig_licenses,$this->licenses); + $update = array_intersect($this->licenses,$this->orig_licenses); // Remove licenses foreach($del as $license){ @@ -410,7 +414,7 @@ class licensePoolGeneric extends plugin } } - // Add / update licenses + // Add licenses foreach($add as $license){ $this->si->createLicense( $this->cn, // Pool id @@ -425,6 +429,33 @@ class licensePoolGeneric extends plugin $license['maximumInstallations'], $license['boundToHost'], $license['expirationDate']); + + if($this->si->is_error()){ + msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG); + } + } + + // Update licenses + foreach($update as $license){ + + // Do not save untouched licenses + if(!$license['MODIFIED']){ + continue; + } + + $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); } diff --git a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc index 2a6f6048d..284e80799 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc +++ b/gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc @@ -157,7 +157,7 @@ class opsiLicenceHandler extends opsi { * @param boundToHost The name of the client the license is bound to (optional). * @param expirationDate The date when the license is running down (optional). */ - function createLicense($poolId, $licenseId, $licenseKey,$licenseTyp = "", + function createLicense($poolId, $licenseId, $licenseKey,$licenseType = "", $partner = "", $conclusionDate = "", $notificationDate ="", @@ -175,14 +175,12 @@ class opsiLicenceHandler extends opsi { // Append optional attributes foreach(array("partner","conclusionDate","notificationDate","notes","softwareLicenseId", - "licenseTyp","maxInstallations","boundToHost","expirationDate") as $attr){ + "licenseType","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); diff --git a/gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl b/gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl index 242365b3d..e7fe63caa 100644 --- a/gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl +++ b/gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl @@ -108,9 +108,15 @@ {t}Model{/t} - + {if $initially_was_account} + + {else} + + {/if} @@ -166,7 +172,7 @@ {t}Used by Host{/t}
- {html_options options=$usedByHost}