Code

We are now able to create, remove and modify pools
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 23 Sep 2009 08:16:00 +0000 (08:16 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 23 Sep 2009 08:16:00 +0000 (08:16 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14324 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/opsi/admin/opsiLicenses/class_divListLicenses.inc
gosa-plugins/opsi/admin/opsiLicenses/class_licenceGeneric.inc
gosa-plugins/opsi/admin/opsiLicenses/class_opsiLicenses.inc
gosa-plugins/opsi/admin/opsiLicenses/licenseGeneric.tpl
gosa-plugins/opsi/admin/opsiLicenses/main.inc

index 02e70d91fb48dea99587eed6162e1698715d25b3..c2076d9e35f9c6b28cf54acb064c8aec359d705c 100644 (file)
@@ -37,7 +37,7 @@ class divListLicense extends MultiSelectWindow
 
   function divListLicense (&$config,$parent)
   {
-    MultiSelectWindow::MultiSelectWindow($config, "Licenses", "licenses");
+    MultiSelectWindow::MultiSelectWindow($config, "opsi", "licenseGeneric");
     
     $this->parent       = $parent;
     $this->ui           = get_userinfo();
@@ -94,8 +94,8 @@ class divListLicense extends MultiSelectWindow
     $add_sep = false;
   
     /* Get copy & paste icon */
-    $acls  = $ui->get_permissions($this->selectedBase,"licenses/licenseGeneric");
-    $acl_all= $ui->has_complete_category_acls($this->selectedBase,"licenses");
+    $acls  = $ui->get_permissions($this->selectedBase,"opsi/licenseGeneric");
+    $acl_all= $ui->has_complete_category_acls($this->selectedBase,"opsi");
 
     /* Add default header */
     $listhead = MultiSelectWindow::get_default_header();
@@ -107,7 +107,7 @@ class divListLicense extends MultiSelectWindow
     if(preg_match("/c/",$acls)) {
       $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
         "&nbsp;"._("Create")."|\n";
-      $s.= "...|<input class='center' type='image' src='plugins/licensemanagement/images/new.png' alt=''>".
+      $s.= "...|<input class='center' type='image' src='plugins/opsiLicenses/images/new.png' alt=''>".
         "&nbsp;"._("License")."|license_new|\n";
     }
 
@@ -174,7 +174,7 @@ class divListLicense extends MultiSelectWindow
       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' 
           name='item_selected_".$key."'>" ,
           "attach" => "style='width:20px;'");
-      $field1 = array("string" => "<img src='plugins/licensemanagement/images/license.png' 
+      $field1 = array("string" => "<img src='plugins/opsiLicenses/images/license.png' 
           alt='"._("License")."' ".$title.">", 
           "attach" => "style='text-align:center;width: 20px;'");
       $field2 = array("string" => sprintf($editlink,$key,$display), 
@@ -192,7 +192,7 @@ class divListLicense extends MultiSelectWindow
     }
     $num_objs = count($list);
     $num_obj_str = _("Number of listed licenses");
-    $str = "<img class='center' src='plugins/licensemanagement/images/license.png'
+    $str = "<img class='center' src='plugins/opsiLicenses/images/license.png'
               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
     $this->set_List_Bottom_Info($str);
   }
index 7473f68fffa648163a89c07c0413817dd4203123..aaf9ff3ae63f05b60024379df27f77b1236ffada 100644 (file)
 class licenseGeneric extends plugin 
 {
 
+  var $cn = "";
+  var $orig_cn = "";
+  var $description = "";
+
   var $orig_dn    = "";
   var $data       = array();
   var $orig_data  = array();
 
   var $productIds = array();
   var $softwareIds= array();
+  var $licenses= array();
 
+  var $availableProductIds = array();
 
   var $attributes =array("cn","description");
 
+  var $si = NULL;
+
   function __construct(&$config,$dn)
   {
     $this->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:cn=([^,]*),.*$/","\\1",$dn);
+    }
+
     // Extract pool name out of the fake dn.
-    $this->cn = preg_replace("/^opsi:cn=([^,]*),.*$/","\\1",$dn);
     $this->init();
   }
 
   
   function init()
   {
-    $si = new opsiLicenceHandler($this->config);
-    $res = $si->getPool($this->cn);
-    if($si->is_error()){    
+    // Load local Boot Products 
+    $res = $this->si->get_local_products();
+    if($this->si->is_error()){
       $this->init_successfull = FALSE;
       return(FALSE);
+    }
+    $this->availableProductIds=array_keys($res);
+
+    // Load Pool
+    if(!$this->initially_was_account){
+      $this->init_successfull = TRUE;
     }else{
-      $this->data = $this->orig_data = $res;
-      $this->description = $this->data['description'][0];
 
-      // Load software IDs 
-      if(isset($this->data['softwareId'])){
-        for($i = 0; $i < $this->data['softwareId']['count']; $i++){
-          $this->softwareIds[] = $this->data['softwareId'][$i];
+      $res = $this->si->getPool($this->cn);
+      if($this->si->is_error()){    
+        $this->init_successfull = FALSE;
+        return(FALSE);
+      }else{
+        $this->data = $this->orig_data = $res;
+        $this->description = $this->data['description'][0];
+
+        // Load software IDs 
+        $this->softwareIds = array();
+        if(isset($this->data['softwareId'])){
+          for($i = 0; $i < $this->data['softwareId']['count']; $i++){
+            $this->softwareIds[] = $this->data['softwareId'][$i];
+          }
         }
-      }
 
-      // Load product IDs 
-      if(isset($this->data['productId'])){
-        for($i = 0; $i < $this->data['productId']['count']; $i++){
-          $this->productIds[] = $this->data['productId'][$i];
+        // Load product IDs 
+        $this->productIds = array();
+        if(isset($this->data['productId'])){
+          for($i = 0; $i < $this->data['productId']['count']; $i++){
+            $this->productIds[] = $this->data['productId'][$i];
+          }
         }
+        $this->init_successfull = TRUE;
+        return;
       }
-      $this->init_successfull = TRUE;
-      return;
     }
   }
 
@@ -97,9 +129,61 @@ class licenseGeneric extends plugin
     }
 
     $smarty->assign("init_successfull", $this->init_successfull);
+    $smarty->assign("availableProductIds", array_diff( $this->availableProductIds, $this->productIds));
+    $smarty->assign("productIds", $this->productIds);
+    $smarty->assign("softwareIds", $this->softwareIds);
+    $smarty->assign("licenses", $this->licenses);
+    $smarty->assign("initially_was_account", $this->initially_was_account);
     return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
   }
 
+  /* Save HTML inputs
+   */
+  function save_object()
+  {
+    if(isset($_POST['opsiLicensesPosted'])){
+      plugin::save_object();  
+
+      // Restore license cn, to avoid creating a copy...
+      if($this->initially_was_account) $this->cn = $this->orig_cn;
+
+      // We've to add prodcuts here 
+      if(isset($_POST['availableProduct']) && isset($_POST['addProduct'])){
+        $pro = get_post('availableProduct');
+        if(isset($this->availableProductIds[$pro]) && !in_array($this->availableProductIds[$pro], $this->productIds)){
+          $this->productIds[] =$this->availableProductIds[$pro];
+        }
+      }
+
+      // We've to remove products here
+      if(isset($_POST['productIds']) && isset($_POST['removeProduct'])){
+        foreach($_POST['productIds'] as $key){
+          if(isset($this->productIds[$key])){
+            unset($this->productIds[$key]);
+          }
+        }
+      }
+
+      // We've to add software here 
+      if(isset($_POST['newSoftwareId']) && isset($_POST['addSoftware'])){
+        $soft = trim(get_post('newSoftwareId'));
+        if(!empty($soft) && !in_array($soft, $this->softwareIds)){
+          $this->softwareIds[] = $soft;
+        }
+      }
+
+      // We've to remove software Ids here
+      if(isset($_POST['softwareIds']) && isset($_POST['removeSoftware'])){
+        foreach($_POST['softwareIds'] as $key){
+          if(isset($this->softwareIds[$key])){
+            unset($this->softwareIds[$key]);
+          }
+        }
+      }
+    }
+  }  
+
 
   /* Check user input and return a list of 'invalid input' messages.
    */
@@ -111,15 +195,20 @@ class licenseGeneric extends plugin
   
 
  
-  /* Removes the object from the ldap database
+  /* Removes the object from the opsi database
    */ 
   function remove_from_parent()
   {
-    // Log action.
-    new log("remove","licenses/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+    $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");
+    }
 
-    // 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());
   }
 
 
@@ -129,34 +218,29 @@ class licenseGeneric extends plugin
   {
     plugin::save();
 
-
     // Send modify/add events
     $mode = "modify";
     if($this->orig_dn == "new"){
       $mode = "add";
     }
 
-    $this->handle_post_events($mode);
+    $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),$ldap->get_error());
+      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),$ldap->get_error());
+      new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$this->si->get_error());
     }
 
     return 0;
   }
  
-  /* Save HTML inputs
-   */
-  function save_object()
-  {
-    plugin::save_object();  
-  }  
-
   static function plInfo()
   {
     return (array(
index 69d28d08b303e18e08a029acc74b70dc486cae85..e029e9641bd61679645485e08c3854dbe7735922 100644 (file)
@@ -94,6 +94,9 @@ class opsiLicenses extends plugin
       if($_POST['menu_action'] == "remove_multiple_licenses"){
         $s_action = "remove_multiple";
       }
+      if($_POST['menu_action'] == "license_new"){
+        $s_action = "new";
+      }
     }
 
 
index 2f3c3e70613613ceb1398b929385a56da7d0d390..9b9252eefe44e0dbd46c59442badb5d5f79fcf59 100644 (file)
 
 <table width="100%">
   <tr> 
-    <td>
+    <td colspan="3">
         <!-- GENERIC -->
         <h2>{t}Generic{/t}</h2>
         <table>
           <tr> 
             <td>{t}Name{/t}</td>
             <td>
+              {if $initially_was_account}
+                <input type='text' value='{$cn}' disabled>
+              {else}
 {render acl=$cnACL}
               <input type='text' value='{$cn}' name='cn'>
 {/render}
+              {/if}
             </td>
           </tr>
           <tr> 
 
     </td>
   </tr>
+  <tr>
+    <td colspan="3">
+      <p class='separator'>&nbsp;</p>
+    </td>
+  </tr>
   <tr> 
-    <td>
+    <td style='width:33%'>
         <!-- LICENSES -->
         <h2>{t}Licenses{/t}</h2>
-        <table>
+        <table style='width:100%;'>
           <tr> 
-            <td></td>
+            <td>
+              <select name='licenses[]' multiple size=4 style="width:100%;">
+                {html_options options=$licenses}
+              </select>
+            </td>
           </tr>
         </table>
 
     </td>
-  </tr>
-  <tr> 
-    <td>
+    <td style='width:33%'>
         <!-- APPLICATIONS -->
         <h2>{t}Applications{/t}</h2>
-        <table>
+        <table style='width:100%;'>
           <tr> 
-            <td></td>
+            <td>
+              <select name='productIds[]' multiple size=4 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>
           </tr>
         </table>
 
     </td>
-  </tr>
-  <tr> 
     <td>
         <!-- SOFTWARE -->
         <h2>{t}Windows software IDs{/t}</h2>
-        <table>
+        <table style='width:100%;'>
           <tr> 
-            <td></td>
+            <td>
+              <select name='softwareIds[]' multiple size=4 style="width:100%;">
+                {html_options options=$softwareIds}
+              </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>
-
+<input name='opsiLicensesPosted' value='1' type='hidden'>
 {/if}
index f139c4fb3a55e4de8e5b2ffe3b4839323c05339b..84a4dac8ff632f4c01d0896dcceda64f17c9df9c 100644 (file)
@@ -49,12 +49,12 @@ if ( $cleanup ){
 
   /* Page header*/
   if (get_object_info() != ""){
-    $display= print_header(get_template_path('plugins/licensemanagement/images/plugin.png'),
+    $display= print_header(get_template_path('plugins/opsiLicenses/images/plugin.png'),
         _("Licenses"),
         "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/locked.png')."\"> ".
         LDAP::fix(get_object_info()));
   } else {
-    $display= print_header(get_template_path('plugins/licensemanagement/images/plugin.png'), _("License management"));
+    $display= print_header(get_template_path('plugins/opsiLicenses/images/plugin.png'), _("License management"));
   }
 
   $display.= $output;