Code

Updated opsi classes
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 20 Aug 2008 09:33:50 +0000 (09:33 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 20 Aug 2008 09:33:50 +0000 (09:33 +0000)
-You are now able to select products.

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12251 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/opsi/admin/opsi/class_opsi.inc
gosa-plugins/opsi/admin/opsi/class_opsi_generic.inc
gosa-plugins/opsi/admin/opsi/generic.tpl

index e41133b6d3209fd04d21972a3ca6b730dc791bbd..7be570879b615fb3d0d59d15014f40fe9c2ea8b8 100644 (file)
  */
 
 
+/********
+
+  __construct($config)
+  get_hosts_for_system_management()
+  get_netboot_products($host = "")
+  get_local_products($host = "")
+  get_product_properties()
+  set_product_properties()
+  get_client_hardware()
+  get_client_software()
+  list_clients()
+  del_client()
+  job_opsi_install_client()
+  add_client()
+  add_product_to_client()
+  del_product_from_client()
+
+ ********/
+
 
 /*! \brief  This is the opsi base class, it handles 
   .          gosa daemon requests and prepares data for opsi plugins.
@@ -83,10 +102,15 @@ class opsi extends gosaSupportDaemon
     $res    = $this->send_data("gosa_opsi_get_netboot_products",$this->target,$data,TRUE);
     $items  = array();
     if($res['XML']['ITEM']['PRODUCTID']){
-    foreach($res['XML']['ITEM']['PRODUCTID'] as $id => $name){
-        $items[$name]['NAME'] = $name;
-        $items[$name]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'][$id];
-      }
+      if(!is_array($res['XML']['ITEM']['PRODUCTID'])){
+        $items[$res['XML']['ITEM']['PRODUCTID']]['NAME'] = $res['XML']['ITEM']['PRODUCTID'];
+        $items[$res['XML']['ITEM']['PRODUCTID']]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'];
+      }else{
+        foreach($res['XML']['ITEM']['PRODUCTID'] as $id => $name){
+          $items[$name]['NAME'] = $name;
+          $items[$name]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'][$id];
+        }
+      } 
     }
     return($items);
   }
@@ -109,10 +133,15 @@ class opsi extends gosaSupportDaemon
     $res    = $this->send_data("gosa_opsi_get_local_products",$this->target,$data,TRUE);
     $items  = array();
     if($res['XML']['ITEM']['PRODUCTID']){
-    foreach($res['XML']['ITEM']['PRODUCTID'] as $id => $name){
-        $items[$name]['NAME'] = $name;
-        $items[$name]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'][$id];
-      }
+      if(!is_array($res['XML']['ITEM']['PRODUCTID'])){
+        $items[$res['XML']['ITEM']['PRODUCTID']]['NAME'] = $res['XML']['ITEM']['PRODUCTID'];
+        $items[$res['XML']['ITEM']['PRODUCTID']]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'];
+      }else{
+        foreach($res['XML']['ITEM']['PRODUCTID'] as $id => $name){
+          $items[$name]['NAME'] = $name;
+          $items[$name]['DESC'] = $res['XML']['ITEM']['DESCRIPTION'][$id];
+        }
+      } 
     }
     return($items);
   }
@@ -124,23 +153,28 @@ class opsi extends gosaSupportDaemon
     @param
     @return            
    */
-  public function get_product_properties()
+  public function get_product_properties($productId,$hostId = "")
   {
-    /*  <xml> 
-        <header>gosa_opsi_get_product_properties</header> 
-        <source>GOSA</source> 
-        <target>GOSA</target> 
-        <productId>firefox</productId>
-        </xml>
-        <xml> 
-        <header>gosa_opsi_get_product_properties</header> 
-        <source>GOSA</source> 
-        <target>GOSA</target> 
-        <productId>firefox</productId> 
-        <hostId>limux-cl-2.intranet.gonicus.de</hostId> 
-        </xml>
+    $data = array("productId" => $productId);
+
+    /* Append host attribute to query data 
      */
-    
+    if(!empty($hostId)){
+      $data['hostId'] = trim($hostId);
+    }
+   
+    /* Check parameter */ 
+    if(empty($productId)){
+      trigger_error("No valid product id given, check parameter 1.");
+      return(array());
+    }
+
+    /* Query SI server */
+    $res    = $this->send_data("gosa_opsi_get_product_properties",$this->target,$data,TRUE);
+    if(isset($res['XML']['ITEM'])){   
+      return($res['XML']['ITEM']);
+    }
+    return(array());
   }
 
 
@@ -217,9 +251,14 @@ class opsi extends gosaSupportDaemon
     $res    = $this->send_data("gosa_opsi_list_clients",$this->target,$data,TRUE);
     $items  = array();
     if(isset($res['XML']['ITEM'])){
-      foreach($res['XML']['ITEM'] as $type => $val){
-        foreach($val as $key => $value){
-          $items[$key][$type] = $value;
+      if(!is_array($res['XML']['ITEM']['NAME'])){
+        $obj = $res['XML']['ITEM'];
+        $items[$obj['NAME']] = $obj;
+      }else{
+        foreach($res['XML']['ITEM'] as $type => $val){
+          foreach($val as $key => $value){
+            $items[$key][$type] = $value;
+          }
         }
       }
     }
index 494df31c9e055be31c17e44e1f322ede4c9b23d7..a4013e4d52c3e3dc13bbef48213a9c45716f9b95 100644 (file)
 
 class opsi_generic extends plugin
 {
+  private $opsi;
+  private $hostId;  
+
+  /* Contains a list of all available netboot products 
+   */
+  private $a_availableNetbootProducts = array();
+  private $s_selectedNetbootProduct = "";  
+
+  /* Contains a list of all available local products
+   */
+  private $a_availableLocalProducts = array();
+  private $a_selectedLocalProducts = array();
+  
+  public function __construct($config,$hostId)
+  {
+    $this->opsi = new opsi($config); 
+    
+    /* Get hostId */
+    $this->hostId = preg_replace("/^opsi:=([^,]*),.*$/","\\1",$hostId);
+
+    /* Get product settings */     
+    $this->a_availableNetbootProducts = $this->opsi->get_netboot_products();
+    $this->a_availableLocalProducts   = $this->opsi->get_local_products();
+  
+    /* Get selected products */
+    $tmp = array_keys($this->opsi->get_netboot_products($this->hostId));  
+    $this->s_selectedNetbootProduct = $tmp;
+    $tmp = $this->opsi->get_local_products($this->hostId);  
+    $this->a_selectedLocalProducts = $tmp;
+
+    /* Load product configuration */
+    foreach($this->a_selectedLocalProducts as $name => $data){
+      $CFG = $this->opsi->get_product_properties($name,$this->hostId);
+      $this->a_selectedLocalProducts[$name]['CFG'] = $CFG;
+    }
+  }
 
   public function execute()
   {
     $smarty = get_smarty();
+    $divSLP = new divSelectBox();
+    $divALP = new divSelectBox();
+
+    /* Create list of available local products 
+     */
+    ksort($this->a_availableLocalProducts);
+    foreach($this->a_availableLocalProducts as $name => $data){
+      if(isset($this->a_selectedLocalProducts[$name])) continue;
+
+      $add_tab  = array("string"   => "<input type='image' src='images/back.png' name='add_lp_".$name."'>");
+      $name_tab = array("string"   => $name);
+      $desc_tab = array("string"   => "<div style='height: 14px;overflow:hidden;'>".$data['DESC']."</div>",
+                    "attach"   => "title='".$data['DESC']."' style='border-right:0px;'");
+      $divALP->AddEntry(array($add_tab,$name_tab,$desc_tab));
+    }
+
+    /* Create list of selected local products 
+     */
+    ksort($this->a_selectedLocalProducts);
+    foreach($this->a_selectedLocalProducts as $name => $data){
+      
+      $name_tab = array("string"   => $name);
+      $desc_tab = array(
+          "string" => "<div style='height: 14px;overflow:hidden;'>".$data['DESC']."</div>",
+          "attach" => "title='".$data['DESC']."'");
+
+      /* Only display edit button, if there is something to edit 
+       */
+      $edit = "<img src='images/empty.png' alt=' '>";
+      if(count($data['CFG'])){
+        $edit = "<input type='image' src='images/lists/edit.png' name='edit_lp_".$name."'>";
+      }
+      $del  = "<input type='image' src='images/lists/trash.png' name='del_lp_".$name."'>";  
+  
+      $opt_tab  = array("string" => $edit.$del,
+          "attach" => "style='border-right:0px; width: 40px; text-align:right;'");
+      $divSLP->AddEntry(array($name_tab,$desc_tab,$opt_tab));
+    }
+
+    $smarty->assign("divSLP", $divSLP->DrawList());
+    $smarty->assign("divALP", $divALP->DrawList());
+    $smarty->assign("SNP", $this->s_selectedNetbootProduct);
+    $smarty->assign("ANP", $this->a_availableNetbootProducts);
     return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
   }
+
+
+  public function save_object()
+  {
+    if(isset($_POST['opsi_generic'])){
+
+      if(isset($_POST['opsi_netboot_product'])){
+        $SNP = trim($_POST['opsi_netboot_product']);
+        if(isset($this->a_availableNetbootProducts[$SNP])){
+          $this->s_selectedNetbootProduct = $SNP;
+        }
+      }
+    
+      foreach($_POST as $name => $value){
+        if(preg_match("/^add_lp_/",$name)){
+          $product = preg_replace("/^add_lp_(.*)_.$/","\\1",$name);
+          if(isset($this->a_availableLocalProducts[$product]) && !isset($this->a_selectedLocalProducts[$product])){
+            $this->a_selectedLocalProducts[$product] = $this->a_availableLocalProducts[$product];
+            $CFG = $this->opsi->get_product_properties($product);
+            $this->a_selectedLocalProducts[$product]['CFG'] = $CFG;
+          }
+          break;
+        }
+        if(preg_match("/^del_lp_/",$name)){
+          $product = preg_replace("/^del_lp_(.*)_.$/","\\1",$name);
+          if(isset($this->a_selectedLocalProducts[$product])){
+            unset($this->a_selectedLocalProducts[$product]);
+          }
+          break;
+        }
+        if(preg_match("/^edit_lp_/",$name)){
+          $product = preg_replace("/^edit_lp_(.*)_.$/","\\1",$name);
+          $this->dialog = new opsi_product_config($product,$this->hostId);
+          break;
+        }
+      }   
+    }
+  }
 }
 
 
index 4f432ce6228d332f2391f8982502aaa0c5dc321f..abc2e862a7321e9b1a17a50dde1d4a1de3c54b74 100644 (file)
@@ -10,6 +10,9 @@
      <td>{t}Boot product{/t}</td>
      <td>
       <select name="opsi_netboot_product">
+               {foreach from=$ANP item=item key=key}
+                       <option {if $key == $SNP} selected {/if} value="{$key}">{$key}</option>
+               {/foreach}
       </select>
      </td>
     </tr>
  </tr>
  <tr>
   <td style="width:50%;"><h2>Installed products</h2>
-   <select size="10" multiple style="width:100%;">
-   </select>
+       {$divSLP}
   </td>
-  <td>&lt;</td>
   <td style="width:50%;"><h2>Available products</h2>
-   <select size="10" multiple style="width:100%;">
-   </select>
+       {$divALP}
   </td>
  </tr>
 </table> 
+<input type='hidden' name='opsi_generic' value='1'>