Code

replaced <p> seperator style by <hr >
[gosa.git] / gosa-plugins / opsi / admin / opsiLicenses / class_licenseByProduct.inc
1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id: class_opsiLicenses.inc 13520 2009-03-09 14:54:13Z hickert $$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 */
24 class licenseByProduct extends plugin 
25 {
27   var $cn = "";
28   var $licenseUses = array();
29   var $init_successfull = FALSE;
32   function __construct(&$config,$dn)
33   {
34     $this->config = $config;
35     $this->dn = $this->orig_dn = $dn;
36     $this->si = new opsiLicenceHandler($this->config);
38     // Is this a new object? 
39     $this->is_account=TRUE;
40     if($this->dn == "new"){
41       $this->initially_was_account = FALSE;
42     }else{
43       $this->initially_was_account = TRUE;
44       
45       // Extract pool name out of the fake dn.
46       $this->cn = $this->orig_cn = preg_replace("/^opsi:cn=([^,]*),.*$/","\\1",$dn);
47     }
49     $this->init();
50   }
52   
53   function init()
54   {
55     $this->licenseUses = array();
56     if(!$this->initially_was_account){
57       $this->init_successfull = TRUE;
58     }else{
60       // Get license information for the current product.
61       $res = $this->si->getLicensesForProduct($this->cn);
62       if($this->si->is_error()){
63         $this->init_successfull = FALSE;
64         msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG);
65         return;
66       }
68       $this->licenseUses = $res;
69       $this->init_successfull = TRUE;
70     }
71   }
74   function execute()
75   {
76     // Handle initialization failures.
77     if(isset($_POST['retry_init'])) $this->init();
78     if(!$this->init_successfull){
79       $smarty = get_smarty();
80       $smarty->assign("init_successfull", $this->init_successfull);
81       return($smarty->fetch(get_template_path('licenseByProduct.tpl',TRUE,dirname(__FILE__))));
82     }
83     
84     // Create usage list
85     $list = new divSelectBox("licenseUsage");
86   
87     $ui = get_userinfo();
88     $readable = $ui->get_permissions($this->config->current['BASE'], "opsi/licenseByProduct","");
89     if($readable) {
90       foreach($this->licenseUses as $license){
91         $f1 = array("string" => $license['HOSTID'][0]['VALUE']);
92         $f2 = array("string" => $license['SOFTWARELICENSEID'][0]['VALUE']);
93         $f3 = array("string" => $license['LICENSEPOOLID'][0]['VALUE'],
94             "attach" => "style='border-right:0px;'");
95         $list->addEntry(array($f1,$f2,$f3));
96       } 
97     } 
99     $smarty = get_smarty();
101     // Assign ACls 
102     $plInfo = $this->plInfo();
103     $smarty->assign("licenseUses", $list->DrawList());
104     $smarty->assign("init_successfull", $this->init_successfull);
105     $smarty->assign("initially_was_account", $this->initially_was_account);
106     return($smarty->fetch(get_template_path('licenseByProduct.tpl',TRUE,dirname(__FILE__))));
107   }
109  
110   /* Save HTML inputs
111    */
112   function save_object()
113   {
114     if(isset($_POST['opsiLicenseUsagePosted'])){
115       plugin::save_object();  
116     }
117   }  
120   /* Check user input and return a list of 'invalid input' messages.
121    */
122   function check()
123   {
124     $message = plugin::check();
125     return($message);
126   }
127   
129   function save( ){}
130   function remove_from_parent(){ }
132  
133   static function plInfo()
134   {
135     return (array(
136           "plShortName"   => _("Usage by product"),
137           "plDescription" => _("License usage by product"),
138           "plSelfModify"  => FALSE,
139           "plDepends"     => array(),
140           "plPriority"    => 12,
141           "plSection"     => array("administration"),
142           "plCategory"    => array("opsi"),
143           "plProvidedAcls"=> array()));
144   }
148 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
149 ?>