Code

Updated license edit
[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 $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; 
46   
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   }
71   
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   }
139  
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();
167     // Very simple date input checks
168     if(!empty($this->expirationDate) && 
169        !preg_match("/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/",$this->expirationDate)){
170       $message[] = msgPool::invalid(_("Expiration date"),$this->expirationDate,"","2009-02-23");
171     }
172     if(!empty($this->conclusionDate) && 
173        !preg_match("/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/",$this->conclusionDate)){
174       $message[] = msgPool::invalid(_("Expiration date"),$this->conclusionDate,"","2009-02-23");
175     }
176     if(!empty($this->notificationDate) && 
177        !preg_match("/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/",$this->notificationDate)){
178       $message[] = msgPool::invalid(_("Expiration date"),$this->notificationDate,"","2009-02-23");
179     }
181     if(empty($this->cn)){
182       $message[] = msgPool::required(_("Name"));
183     }
185     if(empty($this->licenseKey)){
186       $message[] = msgPool::required(_("License key"));
187     }
189     return($message);
190   }
191   
193  
194   /* Removes the object from the opsi database
195    */ 
196   function remove_from_parent()
197   {
198   echo "missing remove.";
199 #   $this->si->deletePool($this->orig_cn);
200 #   if($this->si->is_error()){
201 #     msg_dialog::display(_("Error"),msgPool::siError($this->si->get_error()),ERROR_DIALOG);
202 #   }else{
204 #     // Trigger remove signal
205 #     $this->handle_post_events("remove");
206 #   }
208 #   new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$this->si->get_error());
209   }
212   /* Saves object modifications
213    */  
214   function save()
215   {
216     $data = array();
217     foreach($this->attributes as $target){
218       $data[$target] = $this->$target;
219     }
220     return($data);
221   }
222  
223   static function plInfo()
224   {
225     return (array(
226           "plShortName"   => _("Generic"),
227           "plDescription" => _("License generic"),
228           "plSelfModify"  => FALSE,
229           "plDepends"     => array(),
230           "plPriority"    => 1,
231           "plSection"     => array("administration"),
232           "plCategory"    => array("opsi"),
233           "plProvidedAcls"=> array(
234             "cn"                => _("Name"),
235             "description" => _("Description"))
236           ));
237   }
241 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
242 ?>