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 // The plugin description
30 public $plugname = "unconfigured";
31 public $plIcon = "unconfigured";
32 public $plDescription = "unconfigured";
33 public $plHeadline = "unconfigured";
35 // The currently used object(s) (e.g. in edit, removal)
36 protected $dn = "";
37 protected $dns = array();
39 // The last used object(s).
40 protected $last_dn = "";
41 protected $last_dns = array();
43 // The common places the displayed objects are stored in. (e.g. array("ou=groups,",".."))
44 protected $storagePoints = array();
46 // The tab definitions to use for the current object.
47 protected $tabClass = ""; // e.g. usertabs
48 protected $tabType = ""; // e.g. USERTABS
49 protected $aclCategory = ""; // e.g. users
50 protected $objectName = ""; // e.g. users
52 // The opened object.
53 protected $tabObject = null;
54 protected $dialogObject = null;
56 // The last opened object.
57 protected $last_tabObject = null;
58 protected $last_dialogObject = null;
60 // Whether to display the apply button or not
61 protected $displayApplyBtn = "";
63 // Copy&Paste handler
64 protected $cpHandler = null;
66 // Indicates that we want to paste objects right now.
67 protected $cpPastingStarted = FALSE;
69 // The Snapshot handler class.
70 protected $snapHandler = null;
72 // The listing handlers
73 protected $headpage = null;
74 protected $filter = null;
76 // A list of configured actions/events
77 protected $actions = array();
79 function __construct($config,$ui,$plugname, $headpage)
80 {
81 $this->plugname = $plugname;
82 $this->headpage = $headpage;
83 $this->ui = $ui;
84 $this->config = $config;
86 if($this->cpHandler) $this->headpage->setCopyPasteHandler($this->cpHandler);
87 if($this->snapHandler) $this->headpage->setSnapshotHandler($this->snapHandler);
89 if(empty($this->plIcon)){
90 $this->plIcon = "plugins/".$plugname."/images/plugin.png";
91 }
93 // Register default actions
94 $this->registerAction("new", "newEntry");
95 $this->registerAction("edit", "editEntry");
96 $this->registerAction("apply", "applyChanges");
97 $this->registerAction("save", "saveChanges");
98 $this->registerAction("cancel", "cancelEdit");
99 $this->registerAction("cancelDelete", "cancelEdit");
100 $this->registerAction("remove", "removeEntryRequested");
101 $this->registerAction("removeConfirmed", "removeEntryConfirmed");
103 $this->registerAction("copy", "copyPasteHandler");
104 $this->registerAction("cut", "copyPasteHandler");
105 $this->registerAction("paste", "copyPasteHandler");
107 $this->registerAction("snapshot", "createSnapshotDialog");
108 $this->registerAction("restore", "restoreSnapshotDialog");
109 $this->registerAction("saveSnapshot","saveSnapshot");
110 $this->registerAction("restoreSnapshot","restoreSnapshot");
111 $this->registerAction("cancelSnapshot","closeDialogs");
112 }
114 /*! \brief Execute this plugin
115 * Handle actions/events, locking, snapshots, dialogs, tabs,...
116 */
117 function execute()
118 {
119 // Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog.
120 $vars = array('/^act$/','/^listing/','/^PID$/','/^FILTER_PID$/');
121 session::set('LOCK_VARS_TO_USE',$vars);
123 /* Display the copy & paste dialog, if it is currently open */
124 $ret = $this->copyPasteHandler("",array());
125 if($ret){
126 return($this->getHeader().$ret);
127 }
129 // Update filter
130 if ($this->filter) {
131 $this->filter->update();
132 session::global_set(get_class($this)."_filter", $this->filter);
133 session::set('autocomplete', $this->filter);
134 if (!$this->filter->isValid()){
135 msg_dialog::display(_("Filter error"), _("The filter is incomplete!"), ERROR_DIALOG);
136 }
137 }
139 // Handle actions (POSTs and GETs)
140 $str = $this->handleActions($this->detectPostActions());
141 if($str) return($this->getHeader().$str);
143 // Open single dialog objects
144 if(is_object($this->dialogObject)){
145 if(method_exists($this->dialogObject,'save_object')) $this->dialogObject->save_object();
146 if(method_exists($this->dialogObject,'execute')){
147 $display = $this->dialogObject->execute();
148 $display.= $this->_getTabFooter();
149 return($this->getHeader().$display);
150 }
151 }
153 // Display tab object.
154 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
155 $this->tabObject->save_object();
156 $display = $this->tabObject->execute();
157 $display.= $this->_getTabFooter();
158 return($this->getHeader().$display);
159 }
161 // Set current restore base for snapshot handling.
162 if(is_object($this->snapHandler)){
163 $bases = array();
164 foreach($this->storagePoints as $sp){
165 $bases[] = $sp.$this->headpage->getBase();
166 }
167 $this->snapHandler->setSnapshotBases($bases);
168 }
170 $this->headpage->update();
171 $display = $this->headpage->render();
172 return($this->getHeader().$display);
173 }
177 /*! \brief Generates the plugin header which is displayed whenever a tab object is
178 * opened.
179 */
180 protected function getHeader()
181 {
182 if (get_object_info() != ""){
183 $display= print_header(get_template_path($this->plIcon),_($this->plDescription),
184 "<img alt=\"\" class=\"center\" src=\"".get_template_path('images/lists/locked.png')."\">".
185 LDAP::fix(get_object_info()));
186 } else {
187 $display= print_header(get_template_path($this->plIcon),_($this->plDescription));
188 }
189 return($display);
190 }
193 /*! \brief Generates the footer which is used whenever a tab object is
194 * displayed.
195 */
196 protected function _getTabFooter()
197 {
198 // Do not display tab footer for non tab objects
199 if(!($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug)){
200 return("");
201 }
203 // Check if there is a dialog opened - We don't need any buttons in this case.
204 if($this->tabObject->by_object[$this->tabObject->current]){
205 $current = $this->tabObject->by_object[$this->tabObject->current];
206 if(is_object($current->dialog)){
207 return("");
208 }
209 }
211 // In case an of locked entry, we may have opened a read-only tab.
212 $str = "";
213 if(isset($this->tabObject->read_only) && $this->tabObject->read_only == TRUE){
214 $str.= "<p style=\"text-align:right\">
215 <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
216 </p>";
217 return($str);
218 }else{
220 // Display ok, (apply) and cancel buttons
221 $str.= "<p style=\"text-align:right\">\n";
222 $str.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
223 $str.= " \n";
224 if($this->displayApplyBtn){
225 $str.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
226 $str.= " \n";
227 }
228 $str.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
229 $str.= "</p>";
230 }
231 return($str);
232 }
235 /*! \brief Initiates the removal for the given entries
236 * and displays a confirmation dialog.
237 *
238 * @param String 'action' The name of the action which was the used as trigger.
239 * @param Array 'target' A list of object dns, which should be affected by this method.
240 * @param Array 'all' A combination of both 'action' and 'target'.
241 */
242 protected function removeEntryRequested($action="",$target=array(),$all=array())
243 {
244 $disallowed = array();
245 $this->dns = array();
247 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
249 // Check permissons for each target
250 foreach($target as $dn){
251 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
252 if(preg_match("/d/",$acl)){
253 $this->dns[] = $dn;
254 }else{
255 $disallowed[] = $dn;
256 }
257 }
258 if(count($disallowed)){
259 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
260 }
262 // We've at least one entry to delete.
263 if(count($this->dns)){
265 // check locks
266 if ($user= get_multiple_locks($this->dns)){
267 return(gen_locked_message($user,$this->dns));
268 }
270 // Add locks
271 $dns_names = array();
272 foreach($this->dns as $dn){
273 $dns_names[] =LDAP::fix($dn);
274 }
275 add_lock ($this->dns, $this->ui->dn);
277 // Display confirmation dialog.
278 $smarty = get_smarty();
279 $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
280 $smarty->assign("multiple", true);
281 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
282 }
283 }
286 /*! \brief Object removal was confirmed, now remove the requested entries.
287 *
288 * @param String 'action' The name of the action which was the used as trigger.
289 * @param Array 'target' A list of object dns, which should be affected by this method.
290 * @param Array 'all' A combination of both 'action' and 'target'.
291 */
292 function removeEntryConfirmed($action="",$target=array(),$all=array(),
293 $altTabClass="",$altTabType="",$altAclCategory="")
294 {
295 $tabType = $this->tabType;
296 $tabClass = $this->tabClass;
297 $aclCategory = $this->aclCategory;
298 if(!empty($altTabClass)) $tabClass = $altTabClass;
299 if(!empty($altTabType)) $tabType = $altTabType;
300 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
302 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
304 foreach($this->dns as $key => $dn){
306 // Check permissions, are we allowed to remove this object?
307 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
308 if(preg_match("/d/",$acl)){
310 // Delete the object
311 $this->dn = $dn;
312 $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
313 $this->tabObject->set_acl_base($this->dn);
314 $this->tabObject->delete ();
316 // Remove the lock for the current object.
317 del_lock($this->dn);
318 } else {
319 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
320 new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
321 }
322 }
324 // Cleanup
325 $this->remove_lock();
326 $this->closeDialogs();
327 }
330 /*! \brief Detects actions/events send by the ui
331 * and the corresponding targets.
332 */
333 function detectPostActions()
334 {
335 $action= $this->headpage->getAction();
336 if(isset($_POST['edit_apply'])) $action['action'] = "apply";
337 if(isset($_POST['edit_finish'])) $action['action'] = "save";
338 if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";
339 if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";
340 if(isset($_POST['delete_cancel'])) $action['action'] = "cancelDelete";
342 // Detect Snapshot actions
343 if(isset($_POST['CreateSnapshot'])) $action['action'] = "saveSnapshot";
344 if(isset($_POST['CancelSnapshot'])) $action['action'] = "cancelSnapshot";
345 foreach($_POST as $name => $value){
346 $once =TRUE;
347 if(preg_match("/^RestoreSnapShot_/",$name) && $once){
348 $once = FALSE;
349 $entry = base64_decode(preg_replace("/^RestoreSnapShot_([^_]*)_[xy]$/i","\\1",$name));
350 $action['action'] = "restoreSnapshot";
351 $action['targets'] = array($entry);
352 }
353 }
355 return($action);
356 }
359 /*! \brief Calls the registered method for a given action/event.
360 */
361 function handleActions($action)
362 {
363 // Start action
364 if(isset($this->actions[$action['action']])){
365 $func = $this->actions[$action['action']];
366 if(!isset($action['targets']))$action['targets']= array();
367 return($this->$func($action['action'],$action['targets'],$action));
368 }
369 }
372 /*! \brief Opens the snapshot creation dialog for the given target.
373 *
374 * @param String 'action' The name of the action which was the used as trigger.
375 * @param Array 'target' A list of object dns, which should be affected by this method.
376 * @param Array 'all' A combination of both 'action' and 'target'.
377 */
378 function createSnapshotDialog($action="",$target=array(),$all=array())
379 {
380 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!");
382 foreach($target as $entry){
383 if(!empty($entry) && $this->ui->allow_snapshot_create($entry,$this->aclCategory)){
384 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
385 $this->dialogObject->aclCategories = array($this->aclCategory);
387 }else{
388 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$entry),
389 ERROR_DIALOG);
390 }
391 }
392 }
395 /*! \brief Creates a snapshot new entry - This method is called when the somebody
396 * clicks 'save' in the "Create snapshot dialog" (see ::createSnapshotDialog).
397 *
398 * @param String 'action' The name of the action which was the used as trigger.
399 * @param Array 'target' A list of object dns, which should be affected by this method.
400 * @param Array 'all' A combination of both 'action' and 'target'.
401 */
402 function saveSnapshot($action="",$target=array(),$all=array())
403 {
404 $this->dialogObject->save_object();
405 $msgs = $this->dialogObject->check();
406 if(count($msgs)){
407 foreach($msgs as $msg){
408 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
409 }
410 }else{
411 $this->dn = $this->dialogObject->dn;
412 $this->snapHandler->create_snapshot( $this->dn,$this->dialogObject->CurrentDescription);
413 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot created!");
414 $this->closeDialogs();
415 }
416 }
419 /*! \brief Restores a snapshot object.
420 * The dn of the snapshot entry has to be given as ['target'] parameter.
421 *
422 * @param String 'action' The name of the action which was the used as trigger.
423 * @param Array 'target' A list of object dns, which should be affected by this method.
424 * @param Array 'all' A combination of both 'action' and 'target'.
425 */
426 function restoreSnapshot($action="",$target=array(),$all=array())
427 {
428 $entry = array_pop($target);
429 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
430 $this->snapHandler->restore_snapshot($entry);
431 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot restored!");
432 $this->closeDialogs();
433 }else{
434 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
435 ERROR_DIALOG);
436 }
437 }
440 /*! \brief Displays the "Restore snapshot dialog" for a given target.
441 * If no target is specified, open the restore removed object
442 * dialog.
443 * @param String 'action' The name of the action which was the used as trigger.
444 * @param Array 'target' A list of object dns, which should be affected by this method.
445 * @param Array 'all' A combination of both 'action' and 'target'.
446 */
447 function restoreSnapshotDialog($action="",$target=array(),$all=array())
448 {
449 // Set current restore base for snapshot handling.
450 if(is_object($this->snapHandler)){
451 $bases = array();
452 foreach($this->storagePoints as $sp){
453 $bases[] = $sp.$this->headpage->getBase();
454 }
455 }
457 // No target, open the restore removed object dialog.
458 if(!count($target)){
459 $entry = $this->headpage->getBase();
460 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
461 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
462 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
463 $this->dialogObject->set_snapshot_bases($bases);
464 $this->dialogObject->display_all_removed_objects = true;
465 $this->dialogObject->display_restore_dialog = true;
466 }else{
467 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
468 ERROR_DIALOG);
469 }
470 }else{
472 // Display the restore points for a given object.
473 $entry = array_pop($target);
474 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
475 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
476 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
477 $this->dialogObject->set_snapshot_bases($bases);
478 $this->dialogObject->display_restore_dialog = true;
479 }else{
480 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
481 ERROR_DIALOG);
482 }
483 }
484 }
487 /*! \brief This method intiates the object creation.
488 *
489 * @param String 'action' The name of the action which was the used as trigger.
490 * @param Array 'target' A list of object dns, which should be affected by this method.
491 * @param Array 'all' A combination of both 'action' and 'target'.
492 */
493 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
494 {
495 /* To handle mutliple object types overload this method.
496 * ...
497 * registerAction('newUser', 'newEntry');
498 * registerAction('newGroup','newEntry');
499 * ...
500 *
501 * function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
502 * {
503 * switch($action){
504 * case 'newUser' : {
505 * mangement::newEntry($action,$target,$all,"usertabs","USERTABS","users");
506 * }
507 * case 'newGroup' : {
508 * mangement::newEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
509 * }
510 * }
511 * }
512 **/
513 $tabType = $this->tabType;
514 $tabClass = $this->tabClass;
515 $aclCategory = $this->aclCategory;
516 if(!empty($altTabClass)) $tabClass = $altTabClass;
517 if(!empty($altTabType)) $tabType = $altTabType;
518 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
520 // Check locking & lock entry if required
521 $this->displayApplyBtn = FALSE;
522 $this->dn = "new";
523 $this->is_new = TRUE;
524 $this->is_single_edit = FALSE;
525 $this->is_multiple_edit = FALSE;
527 set_object_info($this->dn);
529 // Open object.
530 if(empty($tabClass) || empty($tabType)){
531 // No tab type defined
532 }else{
533 $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
534 $this->tabObject->set_acl_base($this->headpage->getBase());
535 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!");
536 }
537 }
540 /*! \brief This method opens an existing object or a list of existing objects to be edited.
541 *
542 *
543 * @param String 'action' The name of the action which was the used as trigger.
544 * @param Array 'target' A list of object dns, which should be affected by this method.
545 * @param Array 'all' A combination of both 'action' and 'target'.
546 */
547 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
548 {
549 /* To handle mutliple object types overload this method.
550 * ...
551 * registerAction('editUser', 'editEntry');
552 * registerAction('editGroup','editEntry');
553 * ...
554 *
555 * function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
556 * {
557 * switch($action){
558 * case 'editUser' : {
559 * mangement::editEntry($action,$target,$all,"usertabs","USERTABS","users");
560 * }
561 * case 'editGroup' : {
562 * mangement::editEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
563 * }
564 * }
565 * }
566 **/
567 $tabType = $this->tabType;
568 $tabClass = $this->tabClass;
569 $aclCategory = $this->aclCategory;
570 if(!empty($altTabClass)) $tabClass = $altTabClass;
571 if(!empty($altTabType)) $tabType = $altTabType;
572 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
574 // Single edit - we only got one object dn.
575 if(count($target) == 1){
576 $this->displayApplyBtn = TRUE;
577 $this->is_new = FALSE;
578 $this->is_single_edit = TRUE;
579 $this->is_multiple_edit = FALSE;
581 // Get the dn of the object and creates lock
582 $this->dn = array_pop($target);
583 set_object_info($this->dn);
584 $user = get_lock($this->dn);
585 if ($user != ""){
586 return(gen_locked_message ($user, $this->dn,TRUE));
587 }
588 add_lock ($this->dn, $this->ui->dn);
590 // Open object.
591 if(empty($tabClass) || empty($tabType)){
592 trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
593 }else{
594 $tab = $tabClass;
595 $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$tabType], $this->dn,$aclCategory);
596 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Edit entry initiated!");
597 $this->tabObject->set_acl_base($this->dn);
598 }
599 }else{
601 // We've multiple entries to edit.
602 $this->is_new = FALSE;
603 $this->is_singel_edit = FALSE;
604 $this->is_multiple_edit = TRUE;
606 // Open multiple edit handler.
607 if(empty($tabClass) || empty($tabType)){
608 trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
609 }else{
610 $this->dns = $target;
611 $tmp = new multi_plug($this->config,$tabClass,$this->config->data['TABS'][$tabType],
612 $this->dns,$this->headpage->getBase(),$aclCategory);
614 // Check for locked entries
615 if ($tmp->entries_locked()){
616 return($tmp->display_lock_message());
617 }
619 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Edit entry initiated!");
621 // Now lock entries.
622 $tmp->lock_entries($this->ui->dn);
623 if($tmp->multiple_available()){
624 $this->tabObject = $tmp;
625 set_object_info($this->tabObject->get_object_info());
626 }
627 }
628 }
629 }
632 /*! \brief Save object modifications and closes dialogs (returns to object listing).
633 * - Calls '::check' to validate the given input.
634 * - Calls '::save' to save back object modifications (e.g. to ldap).
635 * - Calls '::remove_locks' to remove eventually created locks.
636 * - Calls '::closeDialogs' to return to the object listing.
637 */
638 protected function saveChanges()
639 {
640 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
641 $this->tabObject->save_object();
642 $msgs = $this->tabObject->check();
643 if(count($msgs)){
644 msg_dialog::displayChecks($msgs);
645 return("");
646 }else{
647 $this->tabObject->save();
648 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
649 $this->remove_lock();
650 $this->closeDialogs();
651 }
652 }
653 }
656 /*! \brief Save object modifications and keep dialogs opened.
657 * - Calls '::check' to validate the given input.
658 * - Calls '::save' to save back object modifications (e.g. to ldap).
659 */
660 protected function applyChanges()
661 {
662 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
663 $this->tabObject->save_object();
664 $msgs = $this->tabObject->check();
665 if(count($msgs)){
666 msg_dialog::displayChecks($msgs);
667 return("");
668 }else{
669 $this->tabObject->save();
670 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Modifications applied!");
671 $this->tabObject->re_init();
672 }
673 }
674 }
677 /*! \brief This method closes dialogs
678 * and cleans up the cached object info and the ui.
679 */
680 protected function closeDialogs()
681 {
682 $this->last_dn = $this->dn;
683 $this->last_dns = $this->dns;
684 $this->last_tabObject = $this->tabObject;
685 $this->last_dialogObject = $this->dialogObject;
686 $this->dn = "";
687 $this->dns = array();
688 $this->tabObject = null;
689 $this->dialogObject = null;
690 set_object_info();
691 }
694 /*! \brief Editing an object was caneled.
695 * Close dialogs/tabs and remove locks.
696 */
697 protected function cancelEdit()
698 {
699 $this->remove_lock();
700 $this->closeDialogs();
701 }
704 /*! \brief Every click in the list user interface sends an event
705 * here can we connect those events to a method.
706 * eg. ::registerEvent('new','createUser')
707 * When the action/event new is send, the method 'createUser'
708 * will be called.
709 */
710 function registerAction($action,$target)
711 {
712 $this->actions[$action] = $target;
713 }
716 /*! \brief Removes ldap object locks created by this class.
717 * Whenever an object is edited, we create locks to avoid
718 * concurrent modifications.
719 * This locks will automatically removed here.
720 */
721 function remove_lock()
722 {
723 if(!empty($this->dn) && $this->dn != "new"){
724 del_lock($this->dn);
725 }
726 if(count($this->dns)){
727 del_lock($this->dns);
728 }
729 }
732 /*! \brief This method is used to queue and process copy&paste actions.
733 * Allows to copy, cut and paste mutliple entries at once.
734 * @param String 'action' The name of the action which was the used as trigger.
735 * @param Array 'target' A list of object dns, which should be affected by this method.
736 * @param Array 'all' A combination of both 'action' and 'target'.
737 */
738 function copyPasteHandler($action="",$target=array(),$all=array(),
739 $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
740 {
741 // Return without any actions while copy&paste handler is disabled.
742 if(!is_object($this->cpHandler)) return("");
744 $tabType = $this->tabType;
745 $tabClass = $this->tabClass;
746 $aclCategory = $this->aclCategory;
747 $aclPlugin = $this->aclPlugin;
748 if(!empty($altTabClass)) $tabClass = $altTabClass;
749 if(!empty($altTabType)) $tabType = $altTabType;
750 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
751 if(!empty($altAclPlugin)) $aclPlugin = $altAclPlugin;
753 // Save user input
754 $this->cpHandler->save_object();
756 // Add entries to queue
757 if($action == "copy" || $action == "cut"){
758 $this->cpHandler->cleanup_queue();
759 foreach($target as $dn){
760 if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
761 $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory);
762 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!");
763 }
764 if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
765 $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory);
766 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!");
767 }
768 }
769 }
771 // Initiate pasting
772 if($action == "paste"){
773 $this->cpPastingStarted = TRUE;
774 }
776 // Display any c&p dialogs, eg. object modifications required before pasting.
777 if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
778 $this->cpHandler->SetVar("base",$this->headpage->getBase());
779 $data = $this->cpHandler->execute();
780 if(!empty($data)){
781 return($data);
782 }
783 }
785 // Automatically disable pasting process since there is no entry left to paste.
786 if(!$this->cpHandler->entries_queued()){
787 $this->cpPastingStarted = FALSE;
788 }
789 return("");
790 }
793 function setFilter($str) {
794 $this->filter = $str;
795 }
797 }
799 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
800 ?>