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 licenseUsage 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 $this->is_account=TRUE;
39 if($this->dn == "new"){
40 $this->initially_was_account = FALSE;
41 }else{
42 $this->initially_was_account = TRUE;
43 $this->cn = $this->orig_cn = preg_replace("/^opsi:cn=([^,]*),.*$/","\\1",$dn);
44 }
46 // Extract pool name out of the fake dn.
47 $this->init();
49 // Prepare lists
50 $this->usageList = new sortableListing();
51 $this->usageList->setDeleteable(false);
52 $this->usageList->setEditable(false);
53 $this->usageList->setWidth("100%");
54 $this->usageList->setHeight("300px");
55 $this->usageList->setHeader(array(_("Host"),_("Key"),_("Pool"), _("License")));
56 $this->usageList->setDefaultSortColumn(1);
57 }
60 function init()
61 {
62 $this->licenseUses = array();
63 if(!$this->initially_was_account){
64 $this->init_successfull = TRUE;
65 }else{
67 $res = $this->si->getLicenseUsage("", $this->cn);
68 if($this->si->is_error()){
69 $this->init_successfull = FALSE;
70 msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG);
71 return;
72 }
74 $this->licenseUses = $res;
75 $this->init_successfull = TRUE;
76 }
77 }
80 function execute()
81 {
82 plugin::execute();
84 $ui = get_userinfo();
85 $readable = $ui->get_permissions($this->config->current['BASE'], "opsi/licenseUsage","");
86 $this->usageList->setAcl($readable);
88 // Handle initialization failures.
89 if(isset($_POST['retry_init'])) $this->init();
90 if(!$this->init_successfull){
91 $smarty = get_smarty();
92 $smarty->assign("init_successfull", $this->init_successfull);
93 return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
94 }
96 // Create usage list
97 $data = array();
98 if($readable) {
99 foreach($this->licenseUses as $license){
100 $data[] = array('data'=>array(
101 $license['hostId'][0],
102 $license['licenseKey'][0],
103 $license['licensePoolId'][0],
104 $license['softwareLicenseId'][0]));
105 }
106 }
107 $this->usageList->setListData($data,$data);
108 $smarty = get_smarty();
110 // Assign ACls
111 $plInfo = $this->plInfo();
112 foreach($plInfo['plProvidedAcls'] as $name => $desc){
113 $smarty->assign("{$name}ACL",$this->getacl($name));
114 }
115 foreach($this->attributes as $attr){
116 $smarty->assign($attr,$this->$attr);
117 }
119 $smarty->assign("licenseUses", $this->usageList->render());
120 $smarty->assign("init_successfull", $this->init_successfull);
121 $smarty->assign("initially_was_account", $this->initially_was_account);
122 return($smarty->fetch(get_template_path('licenseUsage.tpl',TRUE,dirname(__FILE__))));
123 }
126 /* Save HTML inputs
127 */
128 function save_object()
129 {
130 if(isset($_POST['opsiLicenseUsagePosted'])){
131 plugin::save_object();
132 }
133 }
136 /* Check user input and return a list of 'invalid input' messages.
137 */
138 function check()
139 {
140 $message = plugin::check();
141 return($message);
142 }
145 /* Saves object modifications
146 */
147 function save() { }
148 function remove_from_parent(){ return; }
151 static function plInfo()
152 {
153 return (array(
154 "plShortName" => _("License usage"),
155 "plDescription" => _("License usage"),
156 "plSelfModify" => FALSE,
157 "plDepends" => array(),
158 "plPriority" => 11,
159 "plSection" => array("administration"),
160 "plCategory" => array("opsi"),
161 "plProvidedAcls"=> array()));
162 }
163 }
166 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
167 ?>