617b0226051b9220f54b12280d706f6e1687108a
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_plugin.inc 14584 2009-10-12 14:04:22Z 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 management
24 {
25 // Public
26 public $config = null;
27 public $ui = null;
29 public $plIcon = "";
30 public $plDescription = "";
31 public $plHeadline = "";
33 // Protected
34 protected $dn = "";
35 protected $dns = array();
37 protected $tabClass = "";
38 protected $tabType = "";
39 protected $aclCategory = "";
40 protected $objectName = "";
41 protected $tabObject = null;
43 protected $displayApplyBtn = "";
44 protected $cpHandler = null;
45 protected $cpPastingStarted = FALSE;
47 protected $snapHandler = null;
49 // Private
50 protected $plugname = "";
51 protected $headpage = null;
52 protected $filter = null;
53 protected $actions = array();
55 function __construct($config,$ui,$plugname, $headpage)
56 {
57 $this->plugname = $plugname;
58 $this->headpage = $headpage;
59 $this->ui = $ui;
60 $this->config = $config;
62 if($this->cpHandler) $this->headpage->setCopyPasteHandler($this->cpHandler);
63 if($this->snapHandler) $this->headpage->setSnapshotHandler($this->snapHandler);
65 if(empty($this->plIcon)){
66 $this->plIcon = "plugins/".$plugname."/images/plugin.png";
67 }
68 }
70 function execute()
71 {
72 // Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog.
73 $vars = array('/^act$/','/^listing/','/^PID$/','/^FILTER_PID$/');
74 session::set('LOCK_VARS_TO_USE',$vars);
76 /* Display the copy & paste dialog, if it is currently open */
77 $ret = $this->copyPasteHandler("",array());
78 if($ret){
79 return($this->getHeader().$ret);
80 }
82 // Handle actions (POSTs and GETs)
83 $str = $this->handleActions($this->detectPostActions());
84 if($str) return($this->getHeader().$str);
86 // Display tab object.
87 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
88 $this->tabObject->save_object();
89 $display = $this->tabObject->execute();
90 $display.= $this->_getTabFooter();
91 return($this->getHeader().$display);
92 }
94 $this->headpage->update();
95 $display = $this->headpage->render();
96 return($this->getHeader().$display);
97 }
99 protected function getHeader()
100 {
101 if (get_object_info() != ""){
102 $display= print_header(get_template_path($this->plIcon),_($this->plDescription),
103 "<img alt=\"\" class=\"center\" src=\"".get_template_path('images/lists/locked.png')."\">".
104 LDAP::fix(get_object_info()));
105 } else {
106 $display= print_header(get_template_path($this->plIcon),_($this->plDescription));
107 }
108 return($display);
109 }
112 protected function _getTabFooter()
113 {
114 if(!($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug)){
115 return("");
116 }
118 if($this->tabObject->by_object[$this->tabObject->current]){
119 $current = $this->tabObject->by_object[$this->tabObject->current];
120 if(is_object($current->dialog)){
121 return("");
122 }
123 }
125 $str = "";
126 if(isset($this->tabObject->read_only) && $this->tabObject->read_only == TRUE){
127 $str.= "<p style=\"text-align:right\">
128 <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
129 </p>";
130 return($str);
131 }else{
132 $str.= "<p style=\"text-align:right\">\n";
133 $str.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
134 $str.= " \n";
135 if($this->displayApplyBtn){
136 $str.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
137 $str.= " \n";
138 }
139 $str.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
140 $str.= "</p>";
141 }
142 return($str);
143 }
146 protected function removeEntryRequested($action,$entry,$all)
147 {
148 $disallowed = array();
149 $this->dns = array();
150 foreach($entry as $dn){
151 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
152 if(preg_match("/d/",$acl)){
153 $this->dns[] = $dn;
154 }else{
155 $disallowed[] = $dn;
156 }
157 }
159 if(count($disallowed)){
160 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
161 }
163 if(count($this->dns)){
165 /* Check locks */
166 if ($user= get_multiple_locks($this->dns)){
167 return(gen_locked_message($user,$this->dns));
168 }
170 $dns_names = array();
171 foreach($this->dns as $dn){
172 $dns_names[] =LDAP::fix($dn);
173 }
174 add_lock ($this->dns, $this->ui->dn);
176 /* Lock the current entry, so nobody will edit it during deletion */
177 $smarty = get_smarty();
178 $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
179 $smarty->assign("multiple", true);
180 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
181 }
182 }
185 protected function removeEntryConfirmed()
186 {
187 foreach($this->dns as $key => $dn){
189 /* Load permissions for selected 'dn' and check if
190 we're allowed to remove this 'dn' */
191 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
192 if(preg_match("/d/",$acl)){
194 /* Delete request is permitted, perform LDAP action */
195 $this->dn = $dn;
196 $tab = $this->tabClass;
197 $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$this->tabType], $this->dn, $this->aclCategory);
198 $this->tabObject->set_acl_base($this->dn);
199 $this->tabObject->delete ();
200 del_lock($this->dn);
201 } else {
203 /* Normally this shouldn't be reached, send some extra
204 logs to notify the administrator */
205 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
206 new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
207 }
208 }
210 $this->remove_lock();
211 $this->closeDialogs();
212 }
215 function detectPostActions()
216 {
217 $action= $this->headpage->getAction();
219 if(isset($_POST['edit_apply'])) $action['action'] = "apply";
220 if(isset($_POST['edit_finish'])) $action['action'] = "save";
221 if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";
222 if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";
224 return($action);
225 }
227 function handleActions($action)
228 {
229 // Start action
230 if(isset($this->actions[$action['action']])){
231 $func = $this->actions[$action['action']];
232 if(!isset($action['targets']))$action['targets']= array();
233 return($this->$func($action['action'],$action['targets'],$action));
234 }
235 }
237 function newEntry($action="",$target=array(),$all=array())
238 {
239 // Check locking & lock entry if required
240 $this->displayApplyBtn = FALSE;
241 $this->dn = "new";
242 $this->is_new = TRUE;
243 $this->is_single_edit = FALSE;
244 $this->is_multiple_edit = FALSE;
246 set_object_info($this->dn);
248 // Open object.
249 if(empty($this->tabClass) || empty($this->tabType)){
250 // No tab type defined
251 }else{
252 $tab = $this->tabClass;
253 $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$this->tabType], $this->dn, $this->aclCategory);
254 $this->tabObject->set_acl_base($this->headpage->getBase());
255 }
256 }
258 function editEntry($action,$target,$all)
259 {
260 if(count($target) == 0){
261 //nothing
262 }elseif(count($target) == 1){
264 // Check locking & lock entry if required
265 $this->displayApplyBtn = TRUE;
267 $this->is_new = FALSE;
268 $this->is_single_edit = TRUE;
269 $this->is_multiple_edit = FALSE;
271 $this->dn = array_pop($target);
272 set_object_info($this->dn);
273 $user = get_lock($this->dn);
274 if ($user != ""){
275 return(gen_locked_message ($user, $this->dn,TRUE));
276 }
277 add_lock ($this->dn, $this->ui->dn);
279 // Open object.
280 if(empty($this->tabClass) || empty($this->tabType)){
281 // No tab type defined
282 }else{
283 $tab = $this->tabClass;
284 $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$this->tabType], $this->dn,$this->aclCategory);
285 $this->tabObject->set_acl_base($this->dn);
286 }
287 }else{
289 $this->is_new = FALSE;
290 $this->is_singel_edit = FALSE;
291 $this->is_multiple_edit = TRUE;
293 $this->dns = $target;
294 $tmp = new multi_plug($this->config,$this->tabClass,$this->config->data['TABS'][$this->tabType],
295 $this->dns,$this->headpage->getBase(),$this->aclCategory);
296 if ($tmp->entries_locked()){
297 return($tmp->display_lock_message());
298 }
299 $tmp->lock_entries($this->ui->dn);
300 if($tmp->multiple_available()){
301 $this->tabObject = $tmp;
302 set_object_info($this->tabObject->get_object_info());
303 }
305 }
306 }
308 protected function saveChanges()
309 {
310 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
311 $this->tabObject->save_object();
312 $msgs = $this->tabObject->check();
313 if(count($msgs)){
314 msg_dialog::displayChecks($msgs);
315 return("");
316 }else{
317 $this->tabObject->save();
318 $this->remove_lock();
319 $this->closeDialogs();
320 }
321 }
322 }
324 protected function applyChanges()
325 {
326 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
327 $this->tabObject->save_object();
328 $msgs = $this->tabObject->check();
329 if(count($msgs)){
330 msg_dialog::displayChecks($msgs);
331 return("");
332 }else{
333 $this->tabObject->save();
334 $this->tabObject->re_init();
335 }
336 }
337 }
339 protected function closeDialogs()
340 {
341 $this->dn = "";
342 $this->dns = array();
343 $this->tabObject = null;
344 set_object_info();
345 }
347 protected function cancelEdit()
348 {
349 $this->remove_lock();
350 $this->closeDialogs();
351 }
356 function registerAction($action,$target)
357 {
358 $this->actions[$action] = $target;
359 }
361 function remove_lock()
362 {
363 if(!empty($this->dn) && $this->dn != "new"){
364 del_lock($this->dn);
365 }
366 if(count($this->dns)){
367 del_lock($this->dns);
368 }
369 }
371 function copyPasteHandler($s_action,$s_entry)
372 {
374 /* Check if Copy & Paste is disabled */
375 if(!is_object($this->cpHandler)){
376 return("");
377 }
379 $this->cpHandler->save_object();
381 /* Add entries to queue */
382 if($s_action == "copy" || $s_action == "cut"){
384 /* Cleanup object queue */
385 $this->cpHandler->cleanup_queue();
387 /* Add new entries to CP queue */
388 foreach($s_entry as $dn){
389 if($s_action == "copy" && $this->ui->is_copyable($dn,$this->aclCategory,$this->aclPlugin)){
390 $this->cpHandler->add_to_queue($dn,"copy",$this->tabClass,$this->tabType,$this->aclCategory);
391 }
392 if($s_action == "cut" && $this->ui->is_cutable($dn,$this->aclCategory,$this->aclPlugin)){
393 $this->cpHandler->add_to_queue($dn,"cut",$this->tabClass,$this->tabType,$this->aclCategory);
394 }
395 }
396 }
398 /* Start pasting entries */
399 if($s_action == "paste"){
400 $this->cpPastingStarted = TRUE;
401 }
403 /* Return C&P dialog */
404 if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
406 /* Get dialog */
407 $this->cpHandler->SetVar("base",$this->headpage->getBase());
408 $data = $this->cpHandler->execute();
410 /* Return dialog data */
411 if(!empty($data)){
412 return($data);
413 }
414 }
416 /* Automatically disable status for pasting */
417 if(!$this->cpHandler->entries_queued()){
418 $this->cpPastingStarted = FALSE;
419 }
420 return("");
421 }
424 function setDescription($str) {
425 $this->plDescription = $str;
426 }
427 function setHeadpage($str) {
428 $this->headpage = $str;
429 }
430 function setFilter($str) {
431 $this->filter = $str;
432 }
433 function setIcon($str) {
434 $this->plIcon = $str;
435 }
436 function setHeadline($str) {
437 $this->plHeadline = $str;
438 }
439 }
441 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
442 ?>