Code

Updated license generic
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 25 Sep 2009 11:41:06 +0000 (11:41 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 25 Sep 2009 11:41:06 +0000 (11:41 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14348 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

index d1048ac17e895e17d74442519900cb9190ef63f1..b2cc4d6e1c6dee04ee35aa4eb5450af89b315eb4 100644 (file)
@@ -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
index 741ffcb0863c22ba2c31c45681922f3939a2f8d7..1f69db5779ca8c574eda01dde379a95b6b24d4e4 100644 (file)
@@ -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);
       }
index 2a6f6048d2e8ca5c3f6332f925f973a5d03943c0..284e80799f967406166922d2f58fc2f93fd65828 100644 (file)
@@ -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);
index 242365b3dde00a2e6a15efa0ddf4f69b5c6fb77d..e7fe63caa2af9e6dfea1e797b8a53f332dc1a342 100644 (file)
               {t}Model{/t}
             </td>
             <td>
-              <select name='licenseModel' onChange='document.mainform.submit();'>
-                {html_options options=$licenseModels values=$licenseModels selected=$licenseModel}
-              </select>
+              {if $initially_was_account}
+                <select name='dummy223' disabled>
+                  {html_options options=$licenseModels values=$licenseModels selected=$licenseModel}
+                </select>
+              {else}
+                <select name='licenseModel' onChange='document.mainform.submit();'>
+                  {html_options options=$licenseModels values=$licenseModels selected=$licenseModel}
+                </select>
+              {/if}
             </td>
           </tr>
         </table>
           <tr>
             <td colspan="2">
               <b>{t}Used by Host{/t}</b><br>
-              <select name='usedByHost[]' multiple size=4 style='width:100%;'>
+              <select name='selectedUsedHosts[]' multiple size=4 style='width:100%;'>
                 {html_options options=$usedByHost}
               </select><br>
               <select name='selectedHostToAdd'>