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 $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();
48 }
51 function init()
52 {
53 $this->licenseUses = array();
54 if(!$this->initially_was_account){
55 $this->init_successfull = TRUE;
56 }else{
58 $res = $this->si->getLicensesForProduct($this->cn);
59 if($this->si->is_error() || !$res){
60 $this->init_successfull = FALSE;
61 msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG);
62 return;
63 }
65 if(isset($res['USEDBY'])){
66 foreach($res['USEDBY'] as $host){
67 $data = $res;
68 $data['HOST'][0] = $host;
69 $this->licenseUses[] = $data;
70 }
71 }
72 $this->init_successfull = TRUE;
73 }
74 }
77 function execute()
78 {
79 // Handle initialization failures.
80 if(isset($_POST['retry_init'])) $this->init();
81 if(!$this->init_successfull){
82 $smarty = get_smarty();
83 $smarty->assign("init_successfull", $this->init_successfull);
84 return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
85 }
87 // Create usage list
88 $list = new divSelectBox("licenseUsage");
90 foreach($this->licenseUses as $license){
91 $f1 = array("string" => $license['HOST'][0]['VALUE']);
92 $f3 = array("string" => $license['LICENSEPOOLID'][0]['VALUE'],
93 "attach" => "style='border-right:0px;'");
94 $list->addEntry(array($f1,$f3));
95 }
97 $smarty = get_smarty();
99 // Assign ACls
100 $plInfo = $this->plInfo();
101 foreach($plInfo['plProvidedAcls'] as $name => $desc){
102 $smarty->assign("{$name}ACL",$this->getacl($name));
103 }
104 foreach($this->attributes as $attr){
105 $smarty->assign($attr,$this->$attr);
106 }
108 $smarty->assign("licenseUses", $list->DrawList());
109 $smarty->assign("init_successfull", $this->init_successfull);
110 $smarty->assign("initially_was_account", $this->initially_was_account);
111 return($smarty->fetch(get_template_path('licenseUsage.tpl',TRUE,dirname(__FILE__))));
112 }
115 /* Save HTML inputs
116 */
117 function save_object()
118 {
119 if(isset($_POST['opsiLicenseUsagePosted'])){
120 plugin::save_object();
121 }
122 }
125 /* Check user input and return a list of 'invalid input' messages.
126 */
127 function check()
128 {
129 $message = plugin::check();
130 return($message);
131 }
134 function save( ){}
135 function remove_from_parent(){ }
138 static function plInfo()
139 {
140 return (array(
141 "plShortName" => _("Usage"),
142 "plDescription" => _("License usage"),
143 "plSelfModify" => FALSE,
144 "plDepends" => array(),
145 "plPriority" => 1,
146 "plSection" => array("administration"),
147 "plCategory" => array("opsi"),
148 "plProvidedAcls"=> array(
149 "cn" => _("Name"),
150 "description" => _("Description"))
151 ));
152 }
153 }
156 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
157 ?>