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_licenseManagement.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 */
23 class opsiLicenses extends plugin
24 {
25 /* Definitions */
26 var $plHeadline= "Opsi";
27 var $plDescription= "Opsi licenses";
29 // The headpage list handler.
30 var $DivListLicenses = NULL;
32 // A list of currently visible licenses
33 var $licenses = array();
35 // A list of currently edited/removed/aso licenses.
36 var $dns = array();
38 // Permission modules to use.
39 var $acl_module = array("opsi");
41 // Construct and initialize the plugin
42 function __construct (&$config, $dn= NULL)
43 {
44 // Include config object
45 $this->config= &$config;
46 $this->ui= get_userinfo();
48 // Initialize the corresponding list class.
49 $this->DivListLicenses = new divListLicense($this->config,$this);
50 }
53 function execute()
54 {
55 // Call parent execute
56 plugin::execute();
58 // Variables to restore after 'entry locked' warning was displayed
59 session::set('LOCK_VARS_TO_USE',array('/^license_/','/^act/',
60 '/^id/','/^menu_action/','/^item/'));
62 $smarty = get_smarty();
64 /***************
65 * Handle _POST/_GET variables
66 ***************/
68 // Get entry related posts
69 $s_action = "";
70 $s_entry = "";
71 foreach($_POST as $name => $value){
72 if(preg_match("/^license_edit_/",$name)){
73 $s_action = "edit";
74 $s_entry = preg_replace("/^license_edit_([0-9]*)_.*$/","\\1",$name);
75 break;
76 }
77 if(preg_match("/^license_del_/",$name)){
78 $s_action = "remove";
79 $s_entry = preg_replace("/^license_del_([0-9]*)_.*$/","\\1",$name);
80 break;
81 }
82 }
84 if(isset($_GET['act']) && $_GET['act'] == "edit_entry" && isset($_GET['id'])){
85 $id = $_GET['id'];
86 if(isset($this->licenses[$id])){
87 $s_action = "edit";
88 $s_entry = $id;
89 }
90 }
92 // Get menu related posts
93 if(isset($_POST['menu_action'])) {
94 if($_POST['menu_action'] == "remove_multiple_licenses"){
95 $s_action = "remove_multiple";
96 }
97 }
101 /***************
102 * Remove handling
103 ***************/
105 if($s_action == "remove_multiple" || $s_action == "remove"){
107 if($s_action == "remove_multiple"){
108 $ids = $this->list_get_selected_items();
109 }else{
110 $ids = array($s_entry);
111 }
113 if(count($ids)){
114 $this->dns = array();
115 $disallowed = array();
116 foreach($ids as $id){
117 $dn = $this->licenses[$id]['dn'];
118 $acl = $this->ui->get_permissions($dn, "opsi/licenseGeneric");
119 if(preg_match("/d/",$acl)){
120 $this->dns[$id] = $dn;
121 }else{
122 $disallowed[] = $dn;
123 }
124 }
126 if(count($disallowed)){
127 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
128 }
130 if(count($this->dns)){
131 $smarty->assign("info", msgPool::deleteInfo($dns_names,_("License")));
132 $smarty->assign("multiple", true);
133 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
134 }
135 }
136 }
139 /* Remove lock */
140 if(isset($_POST['delete_multiple_licenses_cancel'])){
142 /* Remove lock file after successfull deletion */
143 $this->remove_lock();
144 $this->dns = array();
145 }
148 /* Confirmation for deletion has been passed. Users should be deleted. */
149 if (isset($_POST['delete_multiple_licenses_confirm'])){
151 /* Remove user by user and check acls before removeing them */
152 foreach($this->dns as $key => $dn){
154 $acl = $this->ui->get_permissions($dn, "opsi/licenseGeneric");
155 if (preg_match('/d/', $acl)){
157 /* Delete request is permitted, perform LDAP action */
158 $this->dialog= new licensetabs($this->config,$this->config->data['TABS']['LICENSETABS'], $dn);
159 $this->dialog->delete();
160 $this->dialog= NULL;
161 } else {
163 /* Normally this shouldn't be reached, send some extra
164 logs to notify the administrator */
165 msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
166 new log("security","opsi/".get_class($this),$dn,array(),"Tried to trick deletion.");
167 }
168 }
170 /* Remove lock file after successfull deletion */
171 $this->remove_lock();
172 $this->dns = array();
173 }
176 /***************
177 * New handling
178 ***************/
180 if($s_action == "new" && !$this->dialog instanceOf tabs){
181 $this->dialog = new licensetabs($this->config, $this->config->data['TABS']['LICENSETABS'], "new");
182 $this->dialog->set_acl_base($this->config->current['BASE']);
183 }
185 /***************
186 * Edit handling
187 ***************/
189 if($s_action == "edit" && !$this->dialog instanceOf tabs){
190 if(!isset($this->licenses[$s_entry])){
191 trigger_error("Unknown entry!");
192 }else{
194 $entry = $this->licenses[$s_entry];
195 $this->dn = $entry['dn'];
197 /* Open the dialog */
198 $this->dialog = new licensetabs($this->config, $this->config->data['TABS']['LICENSETABS'],
199 $entry['dn'], "opsi");
200 $this->dialog->set_acl_base($this->config->current['BASE']);
201 set_object_info($this->dn);
202 }
203 }
206 /***************
207 * Dialog handling
208 ***************/
210 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && $this->dialog instanceOf tabs){
211 $this->dialog->save_object();
212 $msgs = $this->dialog->check();
213 if(count($msgs)){
214 msg_dialog::displayChecks($msgs);
215 }else{
216 $this->dialog->save();
217 if (!isset($_POST['edit_apply'])){
218 $this->remove_lock();
219 $this->dialog= NULL;
220 set_object_info();
221 }else{
222 $this->dialog->re_init();
223 }
224 }
225 }
227 if (isset($_POST['edit_cancel']) && $this->dialog instanceOf tabs){
228 $this->remove_lock();
229 $this->dialog= NULL;
230 set_object_info();
231 }
233 if($this->dialog instanceOf tabs){
234 $display= $this->dialog->execute();
236 $dialog_opened = ($this->dialog->by_object[$this->dialog->current]->dialog instanceOf plugin);
238 if(!$dialog_opened){
239 if($this->dialog->read_only == TRUE){
240 $display.= "<p style=\"text-align:right\">
241 <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
242 </p>";
243 }else{
245 $display.= "<p style=\"text-align:right\">\n";
246 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\"
247 value=\"".msgPool::okButton(). "\">\n";
248 $display.= " \n";
249 if ($this->dn != "new"){
250 $display.= "<input type=submit name=\"edit_apply\"
251 value=\"".msgPool::applyButton()."\">\n";
252 $display.= " \n";
253 }
254 $display.= "<input type=submit name=\"edit_cancel\"
255 value=\"".msgPool::cancelButton()."\">\n";
256 $display.= "</p>";
257 }
258 }
259 return ($display);
260 }
263 /***************
264 * List handling
265 ***************/
267 // Display dialog with group list
268 $this->DivListLicenses->parent = $this;
269 $this->DivListLicenses->execute();
270 $this->reload ();
271 $this->DivListLicenses->setEntries($this->licenses);
272 return($this->DivListLicenses->Draw());
273 }
276 // Refreshes the list of known license objects.
277 function reload()
278 {
280 // Get current ldap base and filter settings.
281 $base = $this->DivListLicenses->selectedBase;
282 $Regex = $this->DivListLicenses->Regex;
284 // Search and fetch all matching license objects.
285 $this->licenses = array();
286 }
289 /* \brief Returns a list of selected entry ids.
290 * E.g. remove multiple entries.
291 * @return Array A list of entry IDs
292 */
293 function list_get_selected_items()
294 {
295 $ids = array();
296 foreach($_POST as $name => $value){
297 if(preg_match("/^item_selected_[0-9]*$/",$name)){
298 $id = preg_replace("/^item_selected_/","",$name);
299 $ids[$id] = $id;
300 }
301 }
302 return($ids);
303 }
306 function remove_lock()
307 {
308 if (isset($this->dialog->dn)){
309 del_lock ($this->dialog->dn);
310 }elseif(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
311 del_lock($this->dn);
312 }
313 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
314 del_lock($this->dns);
315 }
316 }
319 function save_object()
320 {
321 $this->DivListLicenses->save_object();
322 }
323 }
325 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
326 ?>