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 $orig_dn = "";
28 var $data = array();
29 var $orig_data = array();
31 var $productIds = array();
32 var $softwareIds= array();
35 var $attributes =array("cn","description");
37 function __construct(&$config,$dn)
38 {
39 $this->config = $config;
40 $this->dn = $this->orig_dn = $dn;
42 // Extract pool name out of the fake dn.
43 $this->cn = preg_replace("/^opsi:cn=([^,]*),.*$/","\\1",$dn);
44 $this->init();
45 }
48 function init()
49 {
50 $si = new opsiLicenceHandler($this->config);
51 $res = $si->getPool($this->cn);
52 if($si->is_error()){
53 $this->init_successfull = FALSE;
54 return(FALSE);
55 }else{
56 $this->data = $this->orig_data = $res;
57 $this->description = $this->data['description'][0];
59 // Load software IDs
60 if(isset($this->data['softwareId'])){
61 for($i = 0; $i < $this->data['softwareId']['count']; $i++){
62 $this->softwareIds[] = $this->data['softwareId'][$i];
63 }
64 }
66 // Load product IDs
67 if(isset($this->data['productId'])){
68 for($i = 0; $i < $this->data['productId']['count']; $i++){
69 $this->productIds[] = $this->data['productId'][$i];
70 }
71 }
72 $this->init_successfull = TRUE;
73 return;
74 }
75 }
78 function execute()
79 {
80 // Handle initialization failures.
81 if(isset($_POST['retry_init'])) $this->init();
82 if(!$this->init_successfull){
83 $smarty = get_smarty();
84 $smarty->assign("init_successfull", $this->init_successfull);
85 return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
86 }
88 $smarty = get_smarty();
90 // Assign ACls
91 $plInfo = $this->plInfo();
92 foreach($plInfo['plProvidedAcls'] as $name => $desc){
93 $smarty->assign("{$name}ACL",$this->getacl($name));
94 }
95 foreach($this->attributes as $attr){
96 $smarty->assign($attr,$this->$attr);
97 }
99 $smarty->assign("init_successfull", $this->init_successfull);
100 return($smarty->fetch(get_template_path('licenseGeneric.tpl',TRUE,dirname(__FILE__))));
101 }
104 /* Check user input and return a list of 'invalid input' messages.
105 */
106 function check()
107 {
108 $message = plugin::check();
109 return($message);
110 }
114 /* Removes the object from the ldap database
115 */
116 function remove_from_parent()
117 {
118 // Log action.
119 new log("remove","licenses/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
121 // Trigger remove signal
122 $this->handle_post_events("remove");
123 }
126 /* Saves object modifications
127 */
128 function save()
129 {
130 plugin::save();
133 // Send modify/add events
134 $mode = "modify";
135 if($this->orig_dn == "new"){
136 $mode = "add";
137 }
139 $this->handle_post_events($mode);
141 // Log action
142 if($mode == "modify"){
143 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
144 }else{
145 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
146 }
148 return 0;
149 }
152 /* Save HTML inputs
153 */
154 function save_object()
155 {
156 plugin::save_object();
157 }
160 static function plInfo()
161 {
162 return (array(
163 "plShortName" => _("Generic"),
164 "plDescription" => _("License generic"),
165 "plSelfModify" => FALSE,
166 "plDepends" => array(),
167 "plPriority" => 1,
168 "plSection" => array("administration"),
169 "plCategory" => array("opsi"),
170 "plProvidedAcls"=> array(
171 "cn" => _("Name"),
172 "description" => _("Description"))
173 ));
174 }
175 }
178 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
179 ?>