Code

Updated license management
[gosa.git] / gosa-plugins / opsi / admin / opsiLicenses / class_licenseGeneric.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 licenseGeneric extends plugin 
25 {
27   var $si = NULL;
28   var $data = array();
29   var $cn = "";
30   var $description = "";  
31   var $partner = "";
33   var $conclusionDate = "";
34   var $expirationDate = "";
35   var $notificationDate = "";
37   var $licenseModel = "";
38   var $licenseKey = "";
39   var $licensePoolId = "";
40   var $boundToHost= array(); // Reserved for Host.   
41   var $usedByHost = array(); // Used by Host.   
43   var $maximumInstallations = 0;
44   var $opsiHosts; 
45   
46   var $attributes = array("cn","description","partner","conclusionDate","expirationDate",
47         "notificationDate","licenseModel","licenseKey","maximumInstallations","licensePoolId");
49   function __construct(&$config, $license, $hosts = array())
50   {
51     $this->config = $config;
52     $this->data = $license;
53     $this->si = new opsiLicenceHandler($this->config);
54     $this->opsiHosts = $hosts;
56     // Detect account state.
57     if(count($this->data) == 0){
58       $this->initially_was_account = FALSE;
59     }else{
60       $this->initially_was_account = TRUE;
61     }
62     $this->is_account = TRUE;
64     // Extract pool name out of the fake dn.
65     $this->init();
66   }
68   
69   function init()
70   {
72     $map = array(
73         "BOUNDTOHOST"=> "boundToHost",
74         "EXPIRATIONDATE"=> "expirationDate",
75         "LICENSECONTRACTID"=> "contractId",
76         "LICENSEPOOIDS"=> "licensePoolId",
77         "LICENSETYPE"=> "licenseModel",
78         "MAXINSTALLATIONS"=> "maximumInstallations",
79         "SOFTWARELICENSEID"=> "cn");
81     foreach($map as $source => $target){
82       if(isset($this->data[$source][0]['VALUE'])){
83         $this->$target = $this->data[$source][0]['VALUE'];
84       }
85     }
87     // Get license key
88     if(isset($this->data['LICENSEKEYS'][0][strtoupper($this->licensePoolId)][0]['VALUE'])){
89       $this->licenseKey = $this->data['LICENSEKEYS'][0][strtoupper($this->licensePoolId)][0]['VALUE'];
90     }
92     // Get license usage
93     $this->usedByHost = array();
94     if(isset($this->data['HOSTIDS'])){
95       foreach($this->data['HOSTIDS'] as $host){
96         $this->usedByHost[] = $host['VALUE']; 
97       }
98     }
100     $this->init_successfull = TRUE;
101     return;    
102   }
105   function execute()
106   {
107     $this->init();
109     // Handle initialization failures.
110     if(isset($_POST['retry_init'])) $this->init();
111     if(!$this->init_successfull){
112       $smarty = get_smarty();
113       $smarty->assign("init_successfull", $this->init_successfull);
114       return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
115     }
117     $smarty = get_smarty();
119     // Assign ACls 
120     $plInfo = $this->plInfo();
121     foreach($plInfo['plProvidedAcls'] as $name => $desc){
122       $smarty->assign("{$name}ACL",$this->getacl($name));
123     }
124     foreach($this->attributes as $attr){
125       $smarty->assign($attr,$this->$attr);
126     }
128     $smarty->assign("licenseModels",array(
129           "RETAIL" => _("Retail"),
130           "OEM"=>_("OEM"),
131           "VOLUME" => _("Volume"),
132           "CONCURRENT" => _("Concurrent")));
135     $smarty->assign("init_successfull", $this->init_successfull);
136     $smarty->assign("initially_was_account", $this->initially_was_account);
137     $smarty->assign("hosts", $this->getHosts());
139     $smarty->assign("notUsedHosts", array_diff($this->getHosts(), $this->usedByHost));
140     $smarty->assign("usedByHost", $this->usedByHost);
141     $smarty->assign("boundToHost", $this->boundToHost);
142     return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
143   }
146   function getHosts()
147   {
148     $ret = array();
149     foreach($this->opsiHosts as $host){
150       $cn = $host['NAME'][0]['VALUE'];
151       $ret[$cn] = $cn;
152     }
153     return($ret);
154   }
157  
158   /* Save HTML inputs
159    */
160   function save_object()
161   {
162     if(isset($_POST['opsiLicensesPosted'])){
163       plugin::save_object();  
164     }
165   }  
168   /* Check user input and return a list of 'invalid input' messages.
169    */
170   function check()
171   {
172     $message = plugin::check();
173     return($message);
174   }
175   
177  
178   /* Removes the object from the opsi database
179    */ 
180   function remove_from_parent()
181   {
182   echo "missing remove.";
183 #   $this->si->deletePool($this->orig_cn);
184 #   if($this->si->is_error()){
185 #     msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG);
186 #   }else{
188 #     // Trigger remove signal
189 #     $this->handle_post_events("remove");
190 #   }
192 #   new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$this->si->get_error());
193   }
196   /* Saves object modifications
197    */  
198   function save()
199   {
201     echo "missing save";
202 #   plugin::save();
204 #   // Send modify/add events
205 #   $mode = "modify";
206 #   if($this->orig_dn == "new"){
207 #     $mode = "add";
208 #   }
210 #   $this->si->createPool($this->cn, $this->description,$this->productIds,$this->softwareIds);#
211 #   if($this->si->is_error()){
212 #     msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG);
213 #   }else{
214 #     $this->handle_post_events($mode);
215 #   }
217 #   // Log action
218 #   if($mode == "modify"){
219 #     new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$this->si->get_error());
220 #   }else{
221 #     new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$this->si->get_error());
222 #   }
224 #   return 0;
225   }
226  
227   static function plInfo()
228   {
229     return (array(
230           "plShortName"   => _("Generic"),
231           "plDescription" => _("License generic"),
232           "plSelfModify"  => FALSE,
233           "plDepends"     => array(),
234           "plPriority"    => 1,
235           "plSection"     => array("administration"),
236           "plCategory"    => array("opsi"),
237           "plProvidedAcls"=> array(
238             "cn"                => _("Name"),
239             "description" => _("Description"))
240           ));
241   }
245 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
246 ?>