324da97b09a3aa70235408fe1302c88d76f1a61c
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 private $headpage = null;
74 private $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 }
168 // No bases specified? Try base
169 if(!count($bases)) $bases[] = $this->headpage->getBase();
171 $this->snapHandler->setSnapshotBases($bases);
172 }
174 // Display list
175 return($this->renderList());
176 }
178 function renderList()
179 {
180 $this->headpage->update();
181 $display = $this->headpage->render();
182 return($this->getHeader().$display);
183 }
185 function getHeadpage()
186 {
187 return($this->headpage);
188 }
190 function getFilter()
191 {
192 return($this->filter);
193 }
195 /*! \brief Generates the plugin header which is displayed whenever a tab object is
196 * opened.
197 */
198 protected function getHeader()
199 {
200 if (get_object_info() != ""){
201 $display= print_header(get_template_path($this->plIcon),_($this->plDescription),
202 "<img alt=\"\" class=\"center\" src=\"".get_template_path('images/lists/locked.png')."\">".
203 LDAP::fix(get_object_info()));
204 } else {
205 $display= print_header(get_template_path($this->plIcon),_($this->plDescription));
206 }
207 return($display);
208 }
211 /*! \brief Generates the footer which is used whenever a tab object is
212 * displayed.
213 */
214 protected function _getTabFooter()
215 {
216 // Do not display tab footer for non tab objects
217 if(!($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug)){
218 return("");
219 }
221 // Check if there is a dialog opened - We don't need any buttons in this case.
222 if($this->tabObject->by_object[$this->tabObject->current]){
223 $current = $this->tabObject->by_object[$this->tabObject->current];
224 if(isset($current->dialog) && (is_object($current->dialog) || $current->dialog)){
225 return("");
226 }
227 }
229 // In case an of locked entry, we may have opened a read-only tab.
230 $str = "";
231 if(isset($this->tabObject->read_only) && $this->tabObject->read_only == TRUE){
232 $str.= "<p style=\"text-align:right\">
233 <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
234 </p>";
235 return($str);
236 }else{
238 // Display ok, (apply) and cancel buttons
239 $str.= "<p style=\"text-align:right\">\n";
240 $str.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
241 $str.= " \n";
242 if($this->displayApplyBtn){
243 $str.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
244 $str.= " \n";
245 }
246 $str.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
247 $str.= "</p>";
248 }
249 return($str);
250 }
253 /*! \brief Initiates the removal for the given entries
254 * and displays a confirmation dialog.
255 *
256 * @param String 'action' The name of the action which was the used as trigger.
257 * @param Array 'target' A list of object dns, which should be affected by this method.
258 * @param Array 'all' A combination of both 'action' and 'target'.
259 */
260 protected function removeEntryRequested($action="",$target=array(),$all=array())
261 {
262 $disallowed = array();
263 $this->dns = array();
265 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
267 // Check permissons for each target
268 foreach($target as $dn){
269 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
270 if(preg_match("/d/",$acl)){
271 $this->dns[] = $dn;
272 }else{
273 $disallowed[] = $dn;
274 }
275 }
276 if(count($disallowed)){
277 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
278 }
280 // We've at least one entry to delete.
281 if(count($this->dns)){
283 // check locks
284 if ($user= get_multiple_locks($this->dns)){
285 return(gen_locked_message($user,$this->dns));
286 }
288 // Add locks
289 $dns_names = array();
290 foreach($this->dns as $dn){
291 $dns_names[] =LDAP::fix($dn);
292 }
293 add_lock ($this->dns, $this->ui->dn);
295 // Display confirmation dialog.
296 $smarty = get_smarty();
297 $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
298 $smarty->assign("multiple", true);
299 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
300 }
301 }
304 /*! \brief Object removal was confirmed, now remove the requested entries.
305 *
306 * @param String 'action' The name of the action which was the used as trigger.
307 * @param Array 'target' A list of object dns, which should be affected by this method.
308 * @param Array 'all' A combination of both 'action' and 'target'.
309 */
310 function removeEntryConfirmed($action="",$target=array(),$all=array(),
311 $altTabClass="",$altTabType="",$altAclCategory="")
312 {
313 $tabType = $this->tabType;
314 $tabClass = $this->tabClass;
315 $aclCategory = $this->aclCategory;
316 if(!empty($altTabClass)) $tabClass = $altTabClass;
317 if(!empty($altTabType)) $tabType = $altTabType;
318 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
320 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
322 foreach($this->dns as $key => $dn){
324 // Check permissions, are we allowed to remove this object?
325 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
326 if(preg_match("/d/",$acl)){
328 // Delete the object
329 $this->dn = $dn;
330 $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
331 $this->tabObject->set_acl_base($this->dn);
332 $this->tabObject->delete ();
333 $this->tabObject->parent = &$this;
335 // Remove the lock for the current object.
336 del_lock($this->dn);
337 } else {
338 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
339 new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
340 }
341 }
343 // Cleanup
344 $this->remove_lock();
345 $this->closeDialogs();
346 }
349 /*! \brief Detects actions/events send by the ui
350 * and the corresponding targets.
351 */
352 function detectPostActions()
353 {
354 if(!is_object($this->headpage)){
355 trigger_error("No valid headpage given....!");
356 return(array());
357 }
358 $action= $this->headpage->getAction();
359 if(isset($_POST['edit_apply'])) $action['action'] = "apply";
360 if(isset($_POST['edit_finish'])) $action['action'] = "save";
361 if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";
362 if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";
363 if(isset($_POST['delete_cancel'])) $action['action'] = "cancelDelete";
365 // Detect Snapshot actions
366 if(isset($_POST['CreateSnapshot'])) $action['action'] = "saveSnapshot";
367 if(isset($_POST['CancelSnapshot'])) $action['action'] = "cancelSnapshot";
368 foreach($_POST as $name => $value){
369 $once =TRUE;
370 if(preg_match("/^RestoreSnapShot_/",$name) && $once){
371 $once = FALSE;
372 $entry = base64_decode(preg_replace("/^RestoreSnapShot_([^_]*)_[xy]$/i","\\1",$name));
373 $action['action'] = "restoreSnapshot";
374 $action['targets'] = array($entry);
375 }
376 }
378 return($action);
379 }
382 /*! \brief Calls the registered method for a given action/event.
383 */
384 function handleActions($action)
385 {
386 // Start action
387 if(isset($this->actions[$action['action']])){
388 $func = $this->actions[$action['action']];
389 if(!isset($action['targets']))$action['targets']= array();
390 return($this->$func($action['action'],$action['targets'],$action));
391 }
392 }
395 /*! \brief Opens the snapshot creation dialog for the given target.
396 *
397 * @param String 'action' The name of the action which was the used as trigger.
398 * @param Array 'target' A list of object dns, which should be affected by this method.
399 * @param Array 'all' A combination of both 'action' and 'target'.
400 */
401 function createSnapshotDialog($action="",$target=array(),$all=array())
402 {
403 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!");
405 foreach($target as $entry){
406 if(!empty($entry) && $this->ui->allow_snapshot_create($entry,$this->aclCategory)){
407 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
408 $this->dialogObject->aclCategories = array($this->aclCategory);
409 $this->dialogObject->parent = &$this;
411 }else{
412 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$entry),
413 ERROR_DIALOG);
414 }
415 }
416 }
419 /*! \brief Creates a snapshot new entry - This method is called when the somebody
420 * clicks 'save' in the "Create snapshot dialog" (see ::createSnapshotDialog).
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 saveSnapshot($action="",$target=array(),$all=array())
427 {
428 $this->dialogObject->save_object();
429 $msgs = $this->dialogObject->check();
430 if(count($msgs)){
431 foreach($msgs as $msg){
432 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
433 }
434 }else{
435 $this->dn = $this->dialogObject->dn;
436 $this->snapHandler->create_snapshot( $this->dn,$this->dialogObject->CurrentDescription);
437 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot created!");
438 $this->closeDialogs();
439 }
440 }
443 /*! \brief Restores a snapshot object.
444 * The dn of the snapshot entry has to be given as ['target'] parameter.
445 *
446 * @param String 'action' The name of the action which was the used as trigger.
447 * @param Array 'target' A list of object dns, which should be affected by this method.
448 * @param Array 'all' A combination of both 'action' and 'target'.
449 */
450 function restoreSnapshot($action="",$target=array(),$all=array())
451 {
452 $entry = array_pop($target);
453 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
454 $this->snapHandler->restore_snapshot($entry);
455 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot restored!");
456 $this->closeDialogs();
457 }else{
458 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
459 ERROR_DIALOG);
460 }
461 }
464 /*! \brief Displays the "Restore snapshot dialog" for a given target.
465 * If no target is specified, open the restore removed object
466 * dialog.
467 * @param String 'action' The name of the action which was the used as trigger.
468 * @param Array 'target' A list of object dns, which should be affected by this method.
469 * @param Array 'all' A combination of both 'action' and 'target'.
470 */
471 function restoreSnapshotDialog($action="",$target=array(),$all=array())
472 {
473 // Set current restore base for snapshot handling.
474 if(is_object($this->snapHandler)){
475 $bases = array();
476 foreach($this->storagePoints as $sp){
477 $bases[] = $sp.$this->headpage->getBase();
478 }
479 }
481 // No bases specified? Try base
482 if(!count($bases)) $bases[] = $this->headpage->getBase();
484 // No target, open the restore removed object dialog.
485 if(!count($target)){
486 $entry = $this->headpage->getBase();
487 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
488 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
489 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
490 $this->dialogObject->set_snapshot_bases($bases);
491 $this->dialogObject->display_all_removed_objects = true;
492 $this->dialogObject->display_restore_dialog = true;
493 $this->dialogObject->parent = &$this;
494 }else{
495 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
496 ERROR_DIALOG);
497 }
498 }else{
500 // Display the restore points for a given object.
501 $entry = array_pop($target);
502 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
503 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
504 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
505 $this->dialogObject->set_snapshot_bases($bases);
506 $this->dialogObject->display_restore_dialog = true;
507 $this->dialogObject->parent = &$this;
508 }else{
509 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
510 ERROR_DIALOG);
511 }
512 }
513 }
516 /*! \brief This method intiates the object creation.
517 *
518 * @param String 'action' The name of the action which was the used as trigger.
519 * @param Array 'target' A list of object dns, which should be affected by this method.
520 * @param Array 'all' A combination of both 'action' and 'target'.
521 */
522 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
523 {
524 /* To handle mutliple object types overload this method.
525 * ...
526 * registerAction('newUser', 'newEntry');
527 * registerAction('newGroup','newEntry');
528 * ...
529 *
530 * function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
531 * {
532 * switch($action){
533 * case 'newUser' : {
534 * mangement::newEntry($action,$target,$all,"usertabs","USERTABS","users");
535 * }
536 * case 'newGroup' : {
537 * mangement::newEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
538 * }
539 * }
540 * }
541 **/
542 $tabType = $this->tabType;
543 $tabClass = $this->tabClass;
544 $aclCategory = $this->aclCategory;
545 if(!empty($altTabClass)) $tabClass = $altTabClass;
546 if(!empty($altTabType)) $tabType = $altTabType;
547 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
549 // Check locking & lock entry if required
550 $this->displayApplyBtn = FALSE;
551 $this->dn = "new";
552 $this->is_new = TRUE;
553 $this->is_single_edit = FALSE;
554 $this->is_multiple_edit = FALSE;
556 set_object_info($this->dn);
558 // Open object.
559 if(empty($tabClass) || empty($tabType)){
560 // No tab type defined
561 }else{
562 $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
563 $this->tabObject->set_acl_base($this->headpage->getBase());
564 $this->tabObject->parent = &$this;
565 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!");
566 }
567 }
570 /*! \brief This method opens an existing object or a list of existing objects to be edited.
571 *
572 *
573 * @param String 'action' The name of the action which was the used as trigger.
574 * @param Array 'target' A list of object dns, which should be affected by this method.
575 * @param Array 'all' A combination of both 'action' and 'target'.
576 */
577 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
578 {
579 /* To handle mutliple object types overload this method.
580 * ...
581 * registerAction('editUser', 'editEntry');
582 * registerAction('editGroup','editEntry');
583 * ...
584 *
585 * function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
586 * {
587 * switch($action){
588 * case 'editUser' : {
589 * mangement::editEntry($action,$target,$all,"usertabs","USERTABS","users");
590 * }
591 * case 'editGroup' : {
592 * mangement::editEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
593 * }
594 * }
595 * }
596 **/
597 $tabType = $this->tabType;
598 $tabClass = $this->tabClass;
599 $aclCategory = $this->aclCategory;
600 if(!empty($altTabClass)) $tabClass = $altTabClass;
601 if(!empty($altTabType)) $tabType = $altTabType;
602 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
604 // Single edit - we only got one object dn.
605 if(count($target) == 1){
606 $this->displayApplyBtn = TRUE;
607 $this->is_new = FALSE;
608 $this->is_single_edit = TRUE;
609 $this->is_multiple_edit = FALSE;
611 // Get the dn of the object and creates lock
612 $this->dn = array_pop($target);
613 set_object_info($this->dn);
614 $user = get_lock($this->dn);
615 if ($user != ""){
616 return(gen_locked_message ($user, $this->dn,TRUE));
617 }
618 add_lock ($this->dn, $this->ui->dn);
620 // Open object.
621 if(empty($tabClass) || empty($tabType)){
622 trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
623 }else{
624 $tab = $tabClass;
625 $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$tabType], $this->dn,$aclCategory);
626 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Edit entry initiated!");
627 $this->tabObject->set_acl_base($this->dn);
628 $this->tabObject->parent = &$this;
629 }
630 }else{
632 // We've multiple entries to edit.
633 $this->is_new = FALSE;
634 $this->is_singel_edit = FALSE;
635 $this->is_multiple_edit = TRUE;
637 // Open multiple edit handler.
638 if(empty($tabClass) || empty($tabType)){
639 trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
640 }else{
641 $this->dns = $target;
642 $tmp = new multi_plug($this->config,$tabClass,$this->config->data['TABS'][$tabType],
643 $this->dns,$this->headpage->getBase(),$aclCategory);
645 // Check for locked entries
646 if ($tmp->entries_locked()){
647 return($tmp->display_lock_message());
648 }
650 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Edit entry initiated!");
652 // Now lock entries.
653 $tmp->lock_entries($this->ui->dn);
654 if($tmp->multiple_available()){
655 $this->tabObject = $tmp;
656 set_object_info($this->tabObject->get_object_info());
657 }
658 }
659 }
660 }
663 /*! \brief Save object modifications and closes dialogs (returns to object listing).
664 * - Calls '::check' to validate the given input.
665 * - Calls '::save' to save back object modifications (e.g. to ldap).
666 * - Calls '::remove_locks' to remove eventually created locks.
667 * - Calls '::closeDialogs' to return to the object listing.
668 */
669 protected function saveChanges()
670 {
671 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
672 $this->tabObject->save_object();
673 $msgs = $this->tabObject->check();
674 if(count($msgs)){
675 msg_dialog::displayChecks($msgs);
676 return("");
677 }else{
678 $this->tabObject->save();
679 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
680 $this->remove_lock();
681 $this->closeDialogs();
682 }
683 }
684 }
687 /*! \brief Save object modifications and keep dialogs opened.
688 * - Calls '::check' to validate the given input.
689 * - Calls '::save' to save back object modifications (e.g. to ldap).
690 */
691 protected function applyChanges()
692 {
693 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
694 $this->tabObject->save_object();
695 $msgs = $this->tabObject->check();
696 if(count($msgs)){
697 msg_dialog::displayChecks($msgs);
698 return("");
699 }else{
700 $this->tabObject->save();
701 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Modifications applied!");
702 $this->tabObject->re_init();
703 }
704 }
705 }
708 /*! \brief This method closes dialogs
709 * and cleans up the cached object info and the ui.
710 */
711 protected function closeDialogs()
712 {
713 $this->last_dn = $this->dn;
714 $this->last_dns = $this->dns;
715 $this->last_tabObject = $this->tabObject;
716 $this->last_dialogObject = $this->dialogObject;
717 $this->dn = "";
718 $this->dns = array();
719 $this->tabObject = null;
720 $this->dialogObject = null;
721 set_object_info();
722 }
725 /*! \brief Editing an object was caneled.
726 * Close dialogs/tabs and remove locks.
727 */
728 protected function cancelEdit()
729 {
730 $this->remove_lock();
731 $this->closeDialogs();
732 }
735 /*! \brief Every click in the list user interface sends an event
736 * here can we connect those events to a method.
737 * eg. ::registerEvent('new','createUser')
738 * When the action/event new is send, the method 'createUser'
739 * will be called.
740 */
741 function registerAction($action,$target)
742 {
743 $this->actions[$action] = $target;
744 }
747 /*! \brief Removes ldap object locks created by this class.
748 * Whenever an object is edited, we create locks to avoid
749 * concurrent modifications.
750 * This locks will automatically removed here.
751 */
752 function remove_lock()
753 {
754 if(!empty($this->dn) && $this->dn != "new"){
755 del_lock($this->dn);
756 }
757 if(count($this->dns)){
758 del_lock($this->dns);
759 }
760 }
763 /*! \brief This method is used to queue and process copy&paste actions.
764 * Allows to copy, cut and paste mutliple entries at once.
765 * @param String 'action' The name of the action which was the used as trigger.
766 * @param Array 'target' A list of object dns, which should be affected by this method.
767 * @param Array 'all' A combination of both 'action' and 'target'.
768 */
769 function copyPasteHandler($action="",$target=array(),$all=array(),
770 $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
771 {
772 // Return without any actions while copy&paste handler is disabled.
773 if(!is_object($this->cpHandler)) return("");
775 $tabType = $this->tabType;
776 $tabClass = $this->tabClass;
777 $aclCategory = $this->aclCategory;
778 $aclPlugin = $this->aclPlugin;
779 if(!empty($altTabClass)) $tabClass = $altTabClass;
780 if(!empty($altTabType)) $tabType = $altTabType;
781 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
782 if(!empty($altAclPlugin)) $aclPlugin = $altAclPlugin;
784 // Save user input
785 $this->cpHandler->save_object();
787 // Add entries to queue
788 if($action == "copy" || $action == "cut"){
789 $this->cpHandler->cleanup_queue();
790 foreach($target as $dn){
791 if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
792 $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this);
793 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!");
794 }
795 if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
796 $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this);
797 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!");
798 }
799 }
800 }
802 // Initiate pasting
803 if($action == "paste"){
804 $this->cpPastingStarted = TRUE;
805 }
807 // Display any c&p dialogs, eg. object modifications required before pasting.
808 if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
809 $this->cpHandler->SetVar("base",$this->headpage->getBase());
810 $data = $this->cpHandler->execute();
811 if(!empty($data)){
812 return($data);
813 }
814 }
816 // Automatically disable pasting process since there is no entry left to paste.
817 if(!$this->cpHandler->entries_queued()){
818 $this->cpPastingStarted = FALSE;
819 }
820 return("");
821 }
824 function setFilter($str) {
825 $this->filter = $str;
826 }
828 }
830 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
831 ?>