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