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 licenseGeneric extends plugin
25 {
27 var $si = NULL;
28 var $data = array();
29 var $cn = "";
30 var $orig_cn = "";
31 var $description = "";
32 var $partner = "";
34 var $conclusionDate = "";
35 var $expirationDate = "";
36 var $notificationDate = "";
38 var $licenseModel = "";
39 var $licenseKey = array();
40 var $licensePoolId = "";
41 var $boundToHost= array(); // Reserved for Host.
42 var $usedByHost = array(); // Used by Host.
44 var $maximumInstallations = 0;
45 var $opsiHosts;
47 var $attributes = array(
48 "cn","description","partner","conclusionDate","expirationDate",
49 "notificationDate","licenseModel","licenseKey","maximumInstallations",
50 "licensePoolId", "usedByHost","boundToHost");
52 function __construct(&$config, $license, $hosts = array())
53 {
54 $this->config = $config;
55 $this->data = $license;
56 $this->si = new opsiLicenceHandler($this->config);
57 $this->opsiHosts = $hosts;
59 // Detect account state.
60 if(count($this->data) == 0){
61 $this->initially_was_account = FALSE;
62 }else{
63 $this->initially_was_account = TRUE;
64 }
65 $this->is_account = TRUE;
67 // Extract pool name out of the fake dn.
68 $this->init();
69 }
72 function init()
73 {
74 $this->boundToHost = array('0'=>"");
75 $this->usedByHost = array('0'=>"");
76 $this->licenseKey = array('0'=>"");
77 if($this->initially_was_account){
78 foreach($this->attributes as $attr){
79 $this->$attr = $this->data[$attr];
80 }
81 }
83 $this->orig_cn = $this->cn;
84 $this->init_successfull = TRUE;
85 return;
86 }
89 function execute()
90 {
91 // Handle initialization failures.
92 if(isset($_POST['retry_init'])) $this->init();
93 if(!$this->init_successfull){
94 $smarty = get_smarty();
95 $smarty->assign("init_successfull", $this->init_successfull);
96 return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
97 }
99 $smarty = get_smarty();
101 // Assign ACls
102 $plInfo = $this->plInfo();
103 foreach($plInfo['plProvidedAcls'] as $name => $desc){
104 $smarty->assign("{$name}ACL",$this->getacl($name));
105 }
106 foreach($this->attributes as $attr){
107 $smarty->assign($attr,$this->$attr);
108 }
110 $smarty->assign("licenseModels",array(
111 "RETAIL" => _("Retail"),
112 "OEM"=>_("OEM"),
113 "VOLUME" => _("Volume"),
114 "CONCURRENT" => _("Concurrent")));
117 $smarty->assign("init_successfull", $this->init_successfull);
118 $smarty->assign("initially_was_account", $this->initially_was_account);
119 $smarty->assign("hosts", $this->getHosts());
121 $smarty->assign("notUsedHosts", array_diff($this->getHosts(), $this->usedByHost));
122 $smarty->assign("boundToHost", $this->boundToHost[0]);
123 $smarty->assign("licenseKey", $this->licenseKey[0]);
124 return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
125 }
128 function getHosts()
129 {
130 $ret = array();
131 foreach($this->opsiHosts as $host){
132 $cn = $host['NAME'][0]['VALUE'];
133 $ret[$cn] = $cn;
134 }
135 return($ret);
136 }
140 /* Save HTML inputs
141 */
142 function save_object()
143 {
145 if(isset($_POST['opsiLicensesPosted'])){
146 plugin::save_object();
148 // Force licenseKey to be of type array.
149 $this->licenseKey = array($this->licenseKey);
151 // BoundToHost maybe multiple too, later.
152 $this->boundToHost = array($this->boundToHost);
154 if($this->initially_was_account){
155 $this->cn = $this->orig_cn;
156 }
157 }
158 }
161 /* Check user input and return a list of 'invalid input' messages.
162 */
163 function check()
164 {
165 $message = plugin::check();
166 return($message);
167 }
171 /* Removes the object from the opsi database
172 */
173 function remove_from_parent()
174 {
175 echo "missing remove.";
176 # $this->si->deletePool($this->orig_cn);
177 # if($this->si->is_error()){
178 # msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG);
179 # }else{
180 #
181 # // Trigger remove signal
182 # $this->handle_post_events("remove");
183 # }
184 #
185 # new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$this->si->get_error());
186 }
189 /* Saves object modifications
190 */
191 function save()
192 {
193 $data = array();
194 foreach($this->attributes as $target){
195 $data[$target] = $this->$target;
196 }
197 return($data);
198 }
200 static function plInfo()
201 {
202 return (array(
203 "plShortName" => _("Generic"),
204 "plDescription" => _("License generic"),
205 "plSelfModify" => FALSE,
206 "plDepends" => array(),
207 "plPriority" => 1,
208 "plSection" => array("administration"),
209 "plCategory" => array("opsi"),
210 "plProvidedAcls"=> array(
211 "cn" => _("Name"),
212 "description" => _("Description"))
213 ));
214 }
215 }
218 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
219 ?>