Code

Updated opsi classes
[gosa.git] / gosa-plugins / opsi / admin / opsi / class_opsi_generic.inc
1 <?php
3 class opsi_generic extends plugin
4 {
5   private $opsi;
6   private $hostId;  
8   /* Contains a list of all available netboot products 
9    */
10   private $a_availableNetbootProducts = array();
11   private $s_selectedNetbootProduct = "";  
13   /* Contains a list of all available local products
14    */
15   private $a_availableLocalProducts = array();
16   private $a_selectedLocalProducts = array();
17   
18   public function __construct($config,$hostId)
19   {
20     $this->opsi = new opsi($config); 
21     
22     /* Get hostId */
23     $this->hostId = preg_replace("/^opsi:=([^,]*),.*$/","\\1",$hostId);
25     /* Get product settings */     
26     $this->a_availableNetbootProducts = $this->opsi->get_netboot_products();
27     $this->a_availableLocalProducts   = $this->opsi->get_local_products();
28   
29     /* Get selected products */
30     $tmp = array_keys($this->opsi->get_netboot_products($this->hostId));  
31     $this->s_selectedNetbootProduct = $tmp;
32     $tmp = $this->opsi->get_local_products($this->hostId);  
33     $this->a_selectedLocalProducts = $tmp;
35     /* Load product configuration */
36     foreach($this->a_selectedLocalProducts as $name => $data){
37       $CFG = $this->opsi->get_product_properties($name,$this->hostId);
38       $this->a_selectedLocalProducts[$name]['CFG'] = $CFG;
39     }
40   }
42   public function execute()
43   {
44     $smarty = get_smarty();
45     $divSLP = new divSelectBox();
46     $divALP = new divSelectBox();
48     /* Create list of available local products 
49      */
50     ksort($this->a_availableLocalProducts);
51     foreach($this->a_availableLocalProducts as $name => $data){
52       if(isset($this->a_selectedLocalProducts[$name])) continue;
54       $add_tab  = array("string"   => "<input type='image' src='images/back.png' name='add_lp_".$name."'>");
55       $name_tab = array("string"   => $name);
56       $desc_tab = array("string"   => "<div style='height: 14px;overflow:hidden;'>".$data['DESC']."</div>",
57                     "attach"   => "title='".$data['DESC']."' style='border-right:0px;'");
58       $divALP->AddEntry(array($add_tab,$name_tab,$desc_tab));
59     }
61     /* Create list of selected local products 
62      */
63     ksort($this->a_selectedLocalProducts);
64     foreach($this->a_selectedLocalProducts as $name => $data){
65       
66       $name_tab = array("string"   => $name);
67       $desc_tab = array(
68           "string" => "<div style='height: 14px;overflow:hidden;'>".$data['DESC']."</div>",
69           "attach" => "title='".$data['DESC']."'");
71       /* Only display edit button, if there is something to edit 
72        */
73       $edit = "<img src='images/empty.png' alt=' '>";
74       if(count($data['CFG'])){
75         $edit = "<input type='image' src='images/lists/edit.png' name='edit_lp_".$name."'>";
76       }
77       $del  = "<input type='image' src='images/lists/trash.png' name='del_lp_".$name."'>";  
78   
79       $opt_tab  = array("string" => $edit.$del,
80           "attach" => "style='border-right:0px; width: 40px; text-align:right;'");
81       $divSLP->AddEntry(array($name_tab,$desc_tab,$opt_tab));
82     }
84     $smarty->assign("divSLP", $divSLP->DrawList());
85     $smarty->assign("divALP", $divALP->DrawList());
86     $smarty->assign("SNP", $this->s_selectedNetbootProduct);
87     $smarty->assign("ANP", $this->a_availableNetbootProducts);
88     return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
89   }
92   public function save_object()
93   {
94     if(isset($_POST['opsi_generic'])){
96       if(isset($_POST['opsi_netboot_product'])){
97         $SNP = trim($_POST['opsi_netboot_product']);
98         if(isset($this->a_availableNetbootProducts[$SNP])){
99           $this->s_selectedNetbootProduct = $SNP;
100         }
101       }
102     
103       foreach($_POST as $name => $value){
104         if(preg_match("/^add_lp_/",$name)){
105           $product = preg_replace("/^add_lp_(.*)_.$/","\\1",$name);
106           if(isset($this->a_availableLocalProducts[$product]) && !isset($this->a_selectedLocalProducts[$product])){
107             $this->a_selectedLocalProducts[$product] = $this->a_availableLocalProducts[$product];
108             $CFG = $this->opsi->get_product_properties($product);
109             $this->a_selectedLocalProducts[$product]['CFG'] = $CFG;
110           }
111           break;
112         }
113         if(preg_match("/^del_lp_/",$name)){
114           $product = preg_replace("/^del_lp_(.*)_.$/","\\1",$name);
115           if(isset($this->a_selectedLocalProducts[$product])){
116             unset($this->a_selectedLocalProducts[$product]);
117           }
118           break;
119         }
120         if(preg_match("/^edit_lp_/",$name)){
121           $product = preg_replace("/^edit_lp_(.*)_.$/","\\1",$name);
122           $this->dialog = new opsi_product_config($product,$this->hostId);
123           break;
124         }
125       }   
126     }
127   }
131 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
132 ?>