Code

Updated license management
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 24 Sep 2009 15:31:32 +0000 (15:31 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 24 Sep 2009 15:31:32 +0000 (15:31 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14343 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/opsi/admin/opsiLicenses/class_licenseGeneric.inc
gosa-plugins/opsi/admin/opsiLicenses/class_licensePoolGeneric.inc
gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenseHandler.inc
gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl
gosa-plugins/opsi/admin/opsiLicenses/licensePoolGeneric.tpl
gosa-plugins/opsi/admin/opsiLicenses/licenseUsageByHost.tpl

index 726de07873385ccbfef315fdfba4b9ca576bea30..bba0c8ea30aa45a39086e251e10c37384df27ad7 100644 (file)
@@ -25,12 +25,41 @@ class licenseGeneric extends plugin
 {
 
   var $si = NULL;
+  var $data = array();
+  var $cn = "";
+  var $description = "";  
+  var $partner = "";
+
+  var $conclusionDate = "";
+  var $expirationDate = "";
+  var $notificationDate = "";
+
+  var $licenseModel = "";
+  var $licenseKey = "";
+  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");
 
-  function __construct(&$config,$dn, $license)
+  function __construct(&$config, $license, $hosts = array())
   {
     $this->config = $config;
-    $this->dn = $this->orig_dn = $dn;
+    $this->data = $license;
     $this->si = new opsiLicenceHandler($this->config);
+    $this->opsiHosts = $hosts;
+
+    // Detect account state.
+    if(count($this->data) == 0){
+      $this->initially_was_account = FALSE;
+    }else{
+      $this->initially_was_account = TRUE;
+    }
+    $this->is_account = TRUE;
 
     // Extract pool name out of the fake dn.
     $this->init();
@@ -39,17 +68,44 @@ class licenseGeneric extends plugin
   
   function init()
   {
-    // Load local Boot Products 
-    $res = $this->si->get_local_products();
-    if($this->si->is_error()){
-      $this->init_successfull = FALSE;
-      return(FALSE);
+
+    $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->init_successfull = TRUE;
+    return;    
   }
 
 
   function execute()
   {
+    $this->init();
+
     // Handle initialization failures.
     if(isset($_POST['retry_init'])) $this->init();
     if(!$this->init_successfull){
@@ -69,11 +125,35 @@ class licenseGeneric extends plugin
       $smarty->assign($attr,$this->$attr);
     }
 
+    $smarty->assign("licenseModels",array(
+          "RETAIL" => _("Retail"),
+          "OEM"=>_("OEM"),
+          "VOLUME" => _("Volume"),
+          "CONCURRENT" => _("Concurrent")));
+
+
     $smarty->assign("init_successfull", $this->init_successfull);
     $smarty->assign("initially_was_account", $this->initially_was_account);
+    $smarty->assign("hosts", $this->getHosts());
+
+    $smarty->assign("notUsedHosts", array_diff($this->getHosts(), $this->usedByHost));
+    $smarty->assign("usedByHost", $this->usedByHost);
+    $smarty->assign("boundToHost", $this->boundToHost);
     return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
   }
 
+
+  function getHosts()
+  {
+    $ret = array();
+    foreach($this->opsiHosts as $host){
+      $cn = $host['NAME'][0]['VALUE'];
+      $ret[$cn] = $cn;
+    }
+    return($ret);
+  }
+
+
  
   /* Save HTML inputs
    */
index 5cdd41f562c9f704de541560e5dfb01a91cec1ea..5f017604dcfe30bb2f26d7f7ab0dbe61d2ae50cc 100644 (file)
@@ -39,6 +39,8 @@ class licensePoolGeneric extends plugin
   var $attributes =array("cn","description");
   var $si = NULL;
 
+  var $opsiHosts = array();
+
   function __construct(&$config,$dn)
   {
     $this->config = $config;
@@ -63,12 +65,22 @@ class licensePoolGeneric extends plugin
   {
     // Load local Boot Products 
     $res = $this->si->get_local_products();
+    $this->availableProductIds=array();
     if($this->si->is_error()){
       $this->init_successfull = FALSE;
       return(FALSE);
     }
     $this->availableProductIds=array_keys($res);
 
+    // Load opsi hosts
+    $res = $this->si->list_clients();
+    $this->opsiHosts=array();
+    if($this->si->is_error()){
+      $this->init_successfull = FALSE;
+      return(FALSE);
+    }
+    $this->opsiHosts=$res;
+
     // Load Pool
     if(!$this->initially_was_account){
       $this->init_successfull = TRUE;
@@ -102,6 +114,7 @@ class licensePoolGeneric extends plugin
         $this->licenses = array();
         if(isset($this->data['licenses'])){
           $this->licenses = $this->data['licenses'];
+          unset($this->licenses['count']);
         }
         $this->init_successfull = TRUE;
         return;
@@ -120,6 +133,20 @@ class licensePoolGeneric extends plugin
       return($smarty->fetch(get_template_path('licensePoolGeneric.tpl',TRUE,dirname(__FILE__))));
     }
 
+    // Display dialogs! 
+    if($this->dialog instanceOf plugin){
+      $this->dialog->save_object();
+      $display = $this->dialog->execute();
+      $display.= 
+        "<p style=\"text-align:right\">
+        <input type=submit name=\"license_finish\" style=\"width:80px\"
+        value=\"".msgPool::okButton(). "\">&nbsp;
+      <input type=submit name=\"license_cancel\"
+        value=\"".msgPool::cancelButton()."\">
+        </p>";
+      return($display);
+    }
+
     $smarty = get_smarty();
 
     // Assign ACls 
@@ -144,10 +171,7 @@ class licensePoolGeneric extends plugin
   {
     $list = new divSelectBox("test");
     $list->setHeight(100);
-    for($i=0 ; $i<$this->licenses['count'] ; $i++){
-    
-      $license = $this->licenses[$i];
-
+    foreach($this->licenses as $i => $license){
       $keys = "";
       foreach($license['LICENSEKEYS'] as $key_by_pool){
         foreach($key_by_pool as $key){
@@ -175,7 +199,20 @@ class licensePoolGeneric extends plugin
    */
   function save_object()
   {
-    if(isset($_POST['opsiLicensesPosted'])){
+    // Close license edit dialogs.
+    if($this->dialog instanceOf plugin && isset($_POST['license_cancel'])){
+      $this->dialog = NULL;
+      return;
+    }
+
+    // Save license modifications
+    if($this->dialog instanceOf plugin && isset($_POST['license_finish'])){
+      echo "Save";
+      $this->dialog = NULL;
+      return;
+    }
+
+    if(isset($_POST['opsiLicensePoolPosted'])){
       plugin::save_object();  
 
       // Restore license cn, to avoid creating a copy...
@@ -214,6 +251,24 @@ class licensePoolGeneric extends plugin
           }
         }
       }
+
+      // Search post for image button clicks.
+      foreach($_POST as $name => $value){
+        if(preg_match("/^editLicense_/",$name)){
+          $id = preg_replace("/^editLicense_([^_]*)_.*$/","\\1",$name);
+          if(isset($this->licenses[$id])){
+            $this->dialog = new licenseGeneric($this->config,$this->licenses[$id], $this->opsiHosts);
+          }
+          break;
+        }
+        if(preg_match("/^removeLicense_/",$name)){
+          $id = preg_replace("/^removeLicense_([^_]*)_.*$/","\\1",$name);
+          if(isset($this->licenses[$id])){
+            unset($this->licenses[$id]);
+          }
+          break;
+        }
+      }
     }
   }  
 
index 30e983d38dcf446952ab8a7f1fc999d9d18cb6c6..7082a109360e79e79631671c65687ddcb2f777b5 100644 (file)
@@ -85,11 +85,13 @@ class opsiLicenceHandler extends opsi  {
     $data= array();
     $data['licensePoolId'] = htmlentities($licensePoolId);
     $res = $this->send_data("gosa_opsi_getPool",$this->target,$data,TRUE);
+    
     if(isset($res['XML'][0]['ANSWER_OPSI_GETPOOL'])){
       $item = array();
       foreach(array("LICENSEPOOLID"       => "cn", 
                     "DESCRIPTION"         => "description",
                     "LICENSES"            => "licenses",
+                    "LICENSECONTRACTDATA" => "contract",
                     "WINDOWSSOFTWAREIDS"  => "softwareId",
                     "PRODUCTIDS"          => "productId") as $source => $target){
         if(isset($res['XML'][0][$source])){
@@ -155,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, $licenseKey,$licenseTyp = "",  
+  function createLicense($poolId, $licenseId, $licenseKey,$licenseTyp = "",  
         $partner = "",
         $conclusionDate = "",
         $notificationDate ="",
@@ -168,7 +170,8 @@ class opsiLicenceHandler extends opsi  {
 
     $data= array();
     $data['licensePoolId']    = htmlentities($poolId);
-    $data['licenseKey']        = htmlentities($licenseKey);
+    $data['licenseKey']       = htmlentities($licenseKey);
+    $data['licenseId']        = htmlentities($licenseId);
 
     // Append optional attributes 
     foreach(array("partner","conclusionDate","notificationDate","notes","softwareLicenseId",
index 4e3fe3ec43712db1b0a673d8a6e6f26724148e18..23fa57373b1308d63564c7fd30311b5770db0aaa 100644 (file)
 <br>
 {else}
 
+<h2>{t}License{/t}</h2>
 
-<table width="100%">
-  <tr> 
-    <td style='vertical-align:top;'>
-        <!-- GENERIC -->
-        <h2>{t}Generic{/t}</h2>
+<table style='width:100%'>
+  <tr>
+    <td style='width:50%; border-right: solid 1px #AAA; padding: 5px; vertical-align:top;'>
+        
         <table>
-          <tr> 
-            <td>{t}Name{/t}</td>
+          <tr>
             <td>
-              {if $initially_was_account}
-                <input type='text' value='{$cn}' disabled>
-              {else}
-{render acl=$cnACL}
-              <input type='text' value='{$cn}' name='cn'>
-{/render}
-              {/if}
+              {t}Name{/t}
+            </td>
+            <td>
+              <input type='text' name='cn' value='{$cn}'>
             </td>
           </tr>
-          <tr> 
-            <td>{t}Description{/t}</td>
+          <tr>
             <td>
-{render acl=$descriptionACL}
-              <input type='text' value='{$description}' name='description'>
-{/render}
+              {t}Partner{/t}
+            </td>
+            <td>
+              <input type='text' name='partner' value='{$partner}'>
             </td>
           </tr>
         </table>
 
     </td>
-    <td style='width:50%; border-left: 1px solid #888888;padding: 5px;'>
-        <!-- LICENSES -->
-        <h2>{t}Licenses{/t}</h2>
-        <table style='width:100%;'>
-          <tr> 
+    <td style='padding: 5px; vertical-align:top;'>
+
+        <table>
+          <tr>
+            <td>
+              {t}Description{/t}
+            </td>
             <td>
-              {$licenses}
+              <input type='text' name='description' value='{$description}'>
             </td>
           </tr>
         </table>
 
     </td>
   </tr>
-  <tr> 
-    <td colspan="2">
-      <p class='separator'>&nbsp;</p>
-    </td>
+  <tr>
+    <td colspan="2"><p class='separator'>&nbsp;</p></td>
   </tr>
   <tr>
-    <td style='width:50%'>
-        <!-- APPLICATIONS -->
-        <h2>{t}Applications{/t}</h2>
-        <table style='width:100%;'>
-          <tr> 
-            <td>
-              <select name='productIds[]' multiple size="6" style="width:100%;">
-                {html_options options=$productIds}
-              </select><br>
-              <select name='availableProduct'>
-                {html_options options=$availableProductIds}
-              </select>
-              <input type='submit' name='addProduct' value='{msgPool type='addButton'}'>
-              <input type='submit' name='removeProduct' value='{msgPool type='delButton'}'>
+    <td style='border-right: solid 1px #AAA; padding: 5px; vertical-align:top;'>
+    
+        <table>
+          <tr>
+            <td>
+              {t}Conclusion date{/t}
+            </td>
+            <td>
+              <input type='text' name='conclusionDate' value='{$conclusionDate}'>
+            </td>
+          </tr>
+          <tr>
+            <td>
+              {t}Expiration date{/t}
+            </td>
+            <td>
+              <input type='text' name='expirationDate' value='{$expirationDate}'>
             </td>
           </tr>
         </table>
+    </td> 
+    <td style='border-right: solid 1px #AAA; padding: 5px; vertical-align:bottom;'>
+   
+        <table>
+          <tr>
+            <td>
+              {t}Notification date{/t}
+            </td>
+            <td>
+              <input type='text' name='notificationDate' value='{$notificationDate}'>
+            </td>
+          </tr>
+        </table>
+    </td> 
+  </tr>
+</table>
 
-    </td>
-    <td style="border-left: 1px solid #888888; padding: 5px;">
-        <!-- SOFTWARE -->
-        <h2>{t}Windows software IDs{/t}</h2>
-        <table style='width:100%;'>
-          <tr> 
-            <td>
-              <select name='softwareIds[]' multiple size="6" style="width:100%;">
-                {html_options options=$softwareIds}
+<p class='separator'>&nbsp;</p>
+
+<h2>{t}License model{/t}</h2>
+
+<table width="100%">
+  <tr>
+    <td style='width:50%;border-right: solid 1px #AAA; padding: 5px; vertical-align:top;'>
+    
+        <table>
+          <tr>
+            <td>
+              {t}Model{/t}
+            </td>
+            <td>
+              <select name='licenseModel'>
+                {html_options options=$licenseModels values=$licenseModels selected=$licenseModel}
               </select>
-              <input type='text' name='newSoftwareId' value='' size=10>
-              <input type='submit' name='addSoftware' value='{msgPool type='addButton'}'>
-              <input type='submit' name='removeSoftware' value='{msgPool type='delButton'}'>
             </td>
           </tr>
         </table>
+    </td> 
+  </tr>
+</table>
 
-    </td>
+<p class='separator'>&nbsp;</p>
+
+<table width="100%">
+  <tr>
+    <td style='border-right: solid 1px #AAA; padding: 5px; vertical-align:top;'>
+    
+        <table>
+          <tr>
+            <td>
+              {t}License key{/t}
+            </td>
+            <td>
+              <input type='text' name='licenseKey' value='{$licenseKey}'>
+            </td>
+          </tr>
+          <tr>
+            <td>
+              {t}Maximum installations{/t}
+            </td>
+            <td>
+              <input type='text' name='maximumInstallations' value='{$maximumInstallations}'>
+            </td>
+          </tr>
+          <tr>
+            <td>
+              {t}Reserved for Host{/t}
+            </td>
+            <td>
+              <select name='boundToHost'>
+                <option value="">{t}none{/t}</option>
+                {html_options options=$hosts selected=$boundToHost}
+              </select>
+            </td>
+          </tr>
+        </table>
+    </td> 
+    <td style='border-right: solid 1px #AAA; padding: 5px; vertical-align:bottom;'>
+   
+        <table width="100%">
+          <tr>
+            <td colspan="2">
+              <b>{t}Assigned to Host{/t}</b><br>
+              <select name='usedByHost[]' multiple size=4 style='width:100%;'>
+                {html_options options=$usedByHost}
+              </select><br>
+              <select name='selectedHostToAdd'>
+                {html_options options=$notUsedHosts}
+              </select>
+              <input type="submit" name="addLicenseUsage" value="{msgPool type='addButton'}">
+              <input type="submit" name="removeLicenseUsage" value="{msgPool type='delButton'}">
+            </td>
+          </tr>
+        </table>
+    </td> 
   </tr>
 </table>
 <input name='opsiLicensesPosted' value='1' type='hidden'>
index 4e3fe3ec43712db1b0a673d8a6e6f26724148e18..3755e82f65ee289903782fd0baa7ac6dc6486f85 100644 (file)
@@ -37,7 +37,7 @@
         </table>
 
     </td>
-    <td style='width:50%; border-left: 1px solid #888888;padding: 5px;'>
+    <td style='width:50%; border-left: 1px solid #AAA;padding: 5px;'>
         <!-- LICENSES -->
         <h2>{t}Licenses{/t}</h2>
         <table style='width:100%;'>
@@ -75,7 +75,7 @@
         </table>
 
     </td>
-    <td style="border-left: 1px solid #888888; padding: 5px;">
+    <td style="border-left: 1px solid #AAA; padding: 5px;">
         <!-- SOFTWARE -->
         <h2>{t}Windows software IDs{/t}</h2>
         <table style='width:100%;'>
@@ -94,5 +94,5 @@
     </td>
   </tr>
 </table>
-<input name='opsiLicensesPosted' value='1' type='hidden'>
+<input name='opsiLicensePoolPosted' value='1' type='hidden'>
 {/if}
index fd7c572027e440b0d860e59dd10dcdfb743ee615..68eae0a0a7ae0036ae63511e4afb4b16142a4e4b 100644 (file)
@@ -10,7 +10,7 @@
 
 <table width="100%">
   <tr>
-    <td style='vertical-align:top;width: 50%; padding: 5px; border-right: solid 1px #888888; '>
+    <td style='vertical-align:top;width: 50%; padding: 5px; border-right: solid 1px #AAA; '>
         <h2>{t}Licenses used{/t}</h2>
         {$licenseUses}
     </td>