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;
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();
51 // Prepare lists
52 $this->usageList = new sortableListing();
53 $this->usageList->setDeleteable(false);
54 $this->usageList->setEditable(false);
55 $this->usageList->setWidth("100%");
56 $this->usageList->setHeight("300px");
57 $this->usageList->setHeader(array(_("Host"),_("Key"),_("Pool"), _("License")));
58 $this->usageList->setDefaultSortColumn(1);
59 }
62 function init()
63 {
64 $this->licenseUses = array();
65 if(!$this->initially_was_account){
66 $this->init_successfull = TRUE;
67 }else{
69 // Get license information for the current product.
70 $res = $this->si->getLicensesForProduct($this->cn);
71 if($this->si->is_error()){
72 $this->init_successfull = FALSE;
73 msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG);
74 return;
75 }
77 $this->licenseUses = $res;
78 $this->init_successfull = TRUE;
79 }
80 }
83 function execute()
84 {
85 plugin::execute();
86 // Handle initialization failures.
87 if(isset($_POST['retry_init'])) $this->init();
88 if(!$this->init_successfull){
89 $smarty = get_smarty();
90 $smarty->assign("init_successfull", $this->init_successfull);
91 return($smarty->fetch(get_template_path('licenseByProduct.tpl',TRUE,dirname(__FILE__))));
92 }
94 $ui = get_userinfo();
95 $readable = $ui->get_permissions($this->config->current['BASE'], "opsi/licenseByProduct","");
96 $data = array();
97 $this->usageList->setAcl($readable);
98 foreach($this->licenseUses as $license){
99 $data[] = array('data'=> array($license['HOSTID'][0]['VALUE'],
100 $license['SOFTWARELICENSEID'][0]['VALUE'],
101 $license['LICENSEPOOLID'][0]['VALUE']));
102 }
103 $this->usageList->setListData($data,$data);
104 $this->usageList->update();
107 $smarty = get_smarty();
109 // Assign ACls
110 $plInfo = $this->plInfo();
111 $smarty->assign("licenseUses", $this->usageList->render());
112 $smarty->assign("init_successfull", $this->init_successfull);
113 $smarty->assign("initially_was_account", $this->initially_was_account);
114 return($smarty->fetch(get_template_path('licenseByProduct.tpl',TRUE,dirname(__FILE__))));
115 }
118 /* Save HTML inputs
119 */
120 function save_object()
121 {
122 if(isset($_POST['opsiLicenseUsagePosted'])){
123 plugin::save_object();
124 }
125 }
128 /* Check user input and return a list of 'invalid input' messages.
129 */
130 function check()
131 {
132 $message = plugin::check();
133 return($message);
134 }
137 function save( ){}
138 function remove_from_parent(){ }
141 static function plInfo()
142 {
143 return (array(
144 "plShortName" => _("Usage by product"),
145 "plDescription" => _("License usage by product"),
146 "plSelfModify" => FALSE,
147 "plDepends" => array(),
148 "plPriority" => 12,
149 "plSection" => array("administration"),
150 "plCategory" => array("opsi"),
151 "plProvidedAcls"=> array()));
152 }
153 }
156 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
157 ?>