b15a124623ef4f417141566efd8d290a03d62a5b
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$$
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 public $dn = ""; // this is public due to some compatibility problems with class plugin..
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 $aclPlugin = ""; // e.g. generic
50 protected $aclCategory = ""; // e.g. users
51 protected $objectName = ""; // e.g. users
53 // The opened object.
54 protected $tabObject = null;
55 protected $dialogObject = null;
57 // The last opened object.
58 protected $last_tabObject = null;
59 protected $last_dialogObject = null;
61 // Whether to display the apply button or not
62 protected $displayApplyBtn = FALSE;
64 // Whether to display a header or not.
65 protected $skipHeader = false;
67 // Whether to display a footer or not.
68 protected $skipFooter = false;
70 // Copy&Paste handler
71 protected $cpHandler = null;
73 // Indicates that we want to paste objects right now.
74 protected $cpPastingStarted = FALSE;
76 // The Snapshot handler class.
77 protected $snapHandler = null;
79 // The listing handlers
80 private $headpage = null;
81 private $filter = null;
83 // A list of configured actions/events
84 protected $actions = array();
86 // Attributes managed by this plugin, can be used in post events;
87 public $attributes = array();
89 function __construct(&$config,$ui,$plugname, $headpage)
90 {
91 $this->plugname = $plugname;
92 $this->headpage = $headpage;
93 $this->ui = $ui;
94 $this->config = $config;
96 if($this->cpHandler) $this->headpage->setCopyPasteHandler($this->cpHandler);
97 if($this->snapHandler) $this->headpage->setSnapshotHandler($this->snapHandler);
99 if(empty($this->plIcon)){
100 $this->plIcon = "plugins/".$plugname."/images/plugin.png";
101 }
103 // Register default actions
104 $this->registerAction("new", "newEntry");
105 $this->registerAction("edit", "editEntry");
106 $this->registerAction("apply", "applyChanges");
107 $this->registerAction("save", "saveChanges");
108 $this->registerAction("cancel", "cancelEdit");
109 $this->registerAction("cancelDelete", "cancelEdit");
110 $this->registerAction("remove", "removeEntryRequested");
111 $this->registerAction("removeConfirmed", "removeEntryConfirmed");
113 $this->registerAction("copy", "copyPasteHandler");
114 $this->registerAction("cut", "copyPasteHandler");
115 $this->registerAction("paste", "copyPasteHandler");
117 $this->registerAction("snapshot", "createSnapshotDialog");
118 $this->registerAction("restore", "restoreSnapshotDialog");
119 $this->registerAction("saveSnapshot","saveSnapshot");
120 $this->registerAction("restoreSnapshot","restoreSnapshot");
121 $this->registerAction("cancelSnapshot","closeDialogs");
123 $this->registerAction("config-filter","editFilter");
124 }
126 /*! \brief Execute this plugin
127 * Handle actions/events, locking, snapshots, dialogs, tabs,...
128 */
129 function execute()
130 {
131 // Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog.
132 $vars = array('/^act$/','/^listing/','/^PID$/','/^FILTER_PID$/');
133 session::set('LOCK_VARS_TO_USE',$vars);
135 /* Display the copy & paste dialog, if it is currently open */
136 $ret = $this->copyPasteHandler("",array());
137 if($ret){
138 return($this->getHeader().$ret);
139 }
141 // Update filter
142 if ($this->filter) {
143 $this->filter->update();
144 session::global_set(get_class($this)."_filter", $this->filter);
145 session::set('autocomplete', $this->filter);
146 }
148 // Handle actions (POSTs and GETs)
149 $str = $this->handleActions($this->detectPostActions());
150 if($str) return($this->getHeader().$str);
152 // Open single dialog objects
153 if(is_object($this->dialogObject)){
154 if(method_exists($this->dialogObject,'save_object')) $this->dialogObject->save_object();
155 if(method_exists($this->dialogObject,'execute')){
156 $display = $this->dialogObject->execute();
157 $display.= $this->_getTabFooter();
158 return($this->getHeader().$display);
159 }
160 }
162 // Display tab object.
163 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
164 # $this->tabObject->save_object();
165 $display = $this->tabObject->execute();
166 $display.= $this->_getTabFooter();
167 return($this->getHeader().$display);
168 }
170 // Set current restore base for snapshot handling.
171 if(is_object($this->snapHandler)){
172 $bases = array();
173 foreach($this->storagePoints as $sp){
174 $bases[] = $sp.$this->headpage->getBase();
175 }
177 // No bases specified? Try base
178 if(!count($bases)) $bases[] = $this->headpage->getBase();
180 $this->snapHandler->setSnapshotBases($bases);
181 }
183 // Display list
184 return($this->renderList());
185 }
187 function editFilter()
188 {
189 $this->dialogObject = new userFilter($this->config,$this->getHeadpage());
190 }
192 function renderList()
193 {
194 $this->headpage->update();
195 $display = $this->headpage->render();
196 return($this->getHeader().$display);
197 }
199 function getHeadpage()
200 {
201 return($this->headpage);
202 }
204 function getFilter()
205 {
206 return($this->filter);
207 }
209 /*! \brief Generates the plugin header which is displayed whenever a tab object is
210 * opened.
211 */
212 protected function getHeader()
213 {
214 // We do not display any headers right now.
215 if(1 || $this->skipHeader) return("");
216 }
219 /*! \brief Generates the footer which is used whenever a tab object is
220 * displayed.
221 */
222 protected function _getTabFooter()
223 {
224 // Do not display tab footer for non tab objects
225 if(!($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug)){
226 return("");
227 }
229 // Check if there is a dialog opened - We don't need any buttons in this case.
230 if($this->tabObject->by_object[$this->tabObject->current]){
231 $current = $this->tabObject->by_object[$this->tabObject->current];
232 if(isset($current->dialog) && (is_object($current->dialog) || $current->dialog)){
233 return("");
234 }
235 }
237 // Skip footer if requested;
238 if($this->skipFooter) return("");
240 // In case an of locked entry, we may have opened a read-only tab.
241 $str = "";
242 if(isset($this->tabObject->read_only) && $this->tabObject->read_only == TRUE){
243 $str.= "<p style=\"text-align:right\">
244 <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
245 </p>";
246 return($str);
247 }else{
249 // Display ok, (apply) and cancel buttons
250 $str.= "<p style=\"text-align:right\">\n";
251 $str.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
252 $str.= " \n";
253 if($this->displayApplyBtn){
254 $str.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
255 $str.= " \n";
256 }
257 $str.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
258 $str.= "</p>";
259 }
260 return($str);
261 }
264 /*! \brief Initiates the removal for the given entries
265 * and displays a confirmation dialog.
266 *
267 * @param String 'action' The name of the action which was the used as trigger.
268 * @param Array 'target' A list of object dns, which should be affected by this method.
269 * @param Array 'all' A combination of both 'action' and 'target'.
270 */
271 protected function removeEntryRequested($action="",$target=array(),$all=array())
272 {
273 $disallowed = array();
274 $this->dns = array();
276 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
278 // Check permissons for each target
279 foreach($target as $dn){
280 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
281 if(preg_match("/d/",$acl)){
282 $this->dns[] = $dn;
283 }else{
284 $disallowed[] = $dn;
285 }
286 }
287 if(count($disallowed)){
288 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
289 }
291 // We've at least one entry to delete.
292 if(count($this->dns)){
294 // check locks
295 if ($user= get_multiple_locks($this->dns)){
296 return(gen_locked_message($user,$this->dns));
297 }
299 // Add locks
300 $dns_names = array();
301 foreach($this->dns as $dn){
302 $dns_names[] =LDAP::fix($dn);
303 }
304 add_lock ($this->dns, $this->ui->dn);
306 // Display confirmation dialog.
307 $smarty = get_smarty();
308 $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
309 $smarty->assign("multiple", true);
310 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
311 }
312 }
315 /*! \brief Object removal was confirmed, now remove the requested entries.
316 *
317 * @param String 'action' The name of the action which was the used as trigger.
318 * @param Array 'target' A list of object dns, which should be affected by this method.
319 * @param Array 'all' A combination of both 'action' and 'target'.
320 */
321 function removeEntryConfirmed($action="",$target=array(),$all=array(),
322 $altTabClass="",$altTabType="",$altAclCategory="")
323 {
324 $tabType = $this->tabType;
325 $tabClass = $this->tabClass;
326 $aclCategory = $this->aclCategory;
327 if(!empty($altTabClass)) $tabClass = $altTabClass;
328 if(!empty($altTabType)) $tabType = $altTabType;
329 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
331 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
333 foreach($this->dns as $key => $dn){
335 // Check permissions, are we allowed to remove this object?
336 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
337 if(preg_match("/d/",$acl)){
339 // Delete the object
340 $this->dn = $dn;
341 $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory, true, true);
342 $this->tabObject->set_acl_base($this->dn);
343 $this->tabObject->parent = &$this;
344 $this->tabObject->delete ();
346 // Remove the lock for the current object.
347 del_lock($this->dn);
348 } else {
349 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
350 new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
351 }
352 }
354 // Cleanup
355 $this->remove_lock();
356 $this->closeDialogs();
357 }
360 /*! \brief Detects actions/events send by the ui
361 * and the corresponding targets.
362 */
363 function detectPostActions()
364 {
365 if(!is_object($this->headpage)){
366 trigger_error("No valid headpage given....!");
367 return(array());
368 }
369 $action= $this->headpage->getAction();
370 if(isset($_POST['edit_apply'])) $action['action'] = "apply";
371 if(isset($_POST['edit_finish'])) $action['action'] = "save";
372 if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";
373 if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";
374 if(isset($_POST['delete_cancel'])) $action['action'] = "cancelDelete";
375 if(isset($_POST['saveFilter'])) $action['action'] = "save";
376 if(isset($_POST['cancelFilter'])) $action['action'] = "cancel";
378 // Detect Snapshot actions
379 if(isset($_POST['CreateSnapshot'])) $action['action'] = "saveSnapshot";
380 if(isset($_POST['CancelSnapshot'])) $action['action'] = "cancelSnapshot";
381 foreach($_POST as $name => $value){
382 $once =TRUE;
383 if(preg_match("/^RestoreSnapShot_/",$name) && $once){
384 $once = FALSE;
385 $entry = base64_decode(preg_replace("/^RestoreSnapShot_([^_]*)_[xy]$/i","\\1",$name));
386 $action['action'] = "restoreSnapshot";
387 $action['targets'] = array($entry);
388 }
389 }
391 return($action);
392 }
395 /*! \brief Calls the registered method for a given action/event.
396 */
397 function handleActions($action)
398 {
399 // Start action
400 if(isset($this->actions[$action['action']])){
401 $func = $this->actions[$action['action']];
402 if(!isset($action['targets']))$action['targets']= array();
403 return($this->$func($action['action'],$action['targets'],$action));
404 }
405 }
408 /*! \brief Opens the snapshot creation dialog for the given target.
409 *
410 * @param String 'action' The name of the action which was the used as trigger.
411 * @param Array 'target' A list of object dns, which should be affected by this method.
412 * @param Array 'all' A combination of both 'action' and 'target'.
413 */
414 function createSnapshotDialog($action="",$target=array(),$all=array())
415 {
416 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!");
418 foreach($target as $entry){
419 if(!empty($entry) && $this->ui->allow_snapshot_create($entry,$this->aclCategory)){
420 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
421 $this->dialogObject->aclCategories = array($this->aclCategory);
422 $this->dialogObject->parent = &$this;
424 }else{
425 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$entry),
426 ERROR_DIALOG);
427 }
428 }
429 }
432 /*! \brief Creates a snapshot new entry - This method is called when the somebody
433 * clicks 'save' in the "Create snapshot dialog" (see ::createSnapshotDialog).
434 *
435 * @param String 'action' The name of the action which was the used as trigger.
436 * @param Array 'target' A list of object dns, which should be affected by this method.
437 * @param Array 'all' A combination of both 'action' and 'target'.
438 */
439 function saveSnapshot($action="",$target=array(),$all=array())
440 {
441 if(!is_object($this->dialogObject)) return;
442 $this->dialogObject->save_object();
443 $msgs = $this->dialogObject->check();
444 if(count($msgs)){
445 foreach($msgs as $msg){
446 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
447 }
448 }else{
449 $this->dn = $this->dialogObject->dn;
450 $this->snapHandler->create_snapshot( $this->dn,$this->dialogObject->CurrentDescription);
451 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot created!");
452 $this->closeDialogs();
453 }
454 }
457 /*! \brief Restores a snapshot object.
458 * The dn of the snapshot entry has to be given as ['target'] parameter.
459 *
460 * @param String 'action' The name of the action which was the used as trigger.
461 * @param Array 'target' A list of object dns, which should be affected by this method.
462 * @param Array 'all' A combination of both 'action' and 'target'.
463 */
464 function restoreSnapshot($action="",$target=array(),$all=array())
465 {
466 $entry = array_pop($target);
467 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
468 $this->snapHandler->restore_snapshot($entry);
469 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot restored!");
470 $this->closeDialogs();
471 }else{
472 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
473 ERROR_DIALOG);
474 }
475 }
478 /*! \brief Displays the "Restore snapshot dialog" for a given target.
479 * If no target is specified, open the restore removed object
480 * dialog.
481 * @param String 'action' The name of the action which was the used as trigger.
482 * @param Array 'target' A list of object dns, which should be affected by this method.
483 * @param Array 'all' A combination of both 'action' and 'target'.
484 */
485 function restoreSnapshotDialog($action="",$target=array(),$all=array())
486 {
487 // Set current restore base for snapshot handling.
488 if(is_object($this->snapHandler)){
489 $bases = array();
490 foreach($this->storagePoints as $sp){
491 $bases[] = $sp.$this->headpage->getBase();
492 }
493 }
495 // No bases specified? Try base
496 if(!count($bases)) $bases[] = $this->headpage->getBase();
498 // No target, open the restore removed object dialog.
499 if(!count($target)){
500 $entry = $this->headpage->getBase();
501 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
502 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
503 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
504 $this->dialogObject->set_snapshot_bases($bases);
505 $this->dialogObject->display_all_removed_objects = true;
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 }else{
514 // Display the restore points for a given object.
515 $entry = array_pop($target);
516 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
517 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
518 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
519 $this->dialogObject->set_snapshot_bases($bases);
520 $this->dialogObject->display_restore_dialog = true;
521 $this->dialogObject->parent = &$this;
522 }else{
523 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
524 ERROR_DIALOG);
525 }
526 }
527 }
530 /*! \brief This method intiates the object creation.
531 *
532 * @param String 'action' The name of the action which was the used as trigger.
533 * @param Array 'target' A list of object dns, which should be affected by this method.
534 * @param Array 'all' A combination of both 'action' and 'target'.
535 */
536 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
537 {
538 /* To handle mutliple object types overload this method.
539 * ...
540 * registerAction('newUser', 'newEntry');
541 * registerAction('newGroup','newEntry');
542 * ...
543 *
544 * function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
545 * {
546 * switch($action){
547 * case 'newUser' : {
548 * mangement::newEntry($action,$target,$all,"usertabs","USERTABS","users");
549 * }
550 * case 'newGroup' : {
551 * mangement::newEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
552 * }
553 * }
554 * }
555 **/
556 $tabType = $this->tabType;
557 $tabClass = $this->tabClass;
558 $aclCategory = $this->aclCategory;
559 if(!empty($altTabClass)) $tabClass = $altTabClass;
560 if(!empty($altTabType)) $tabType = $altTabType;
561 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
563 // Check locking & lock entry if required
564 $this->displayApplyBtn = FALSE;
565 $this->dn = "new";
566 $this->is_new = TRUE;
567 $this->is_single_edit = FALSE;
568 $this->is_multiple_edit = FALSE;
570 set_object_info($this->dn);
572 // Open object.
573 if(empty($tabClass) || empty($tabType)){
574 // No tab type defined
575 }else{
576 if (isset($this->config->data['TABS'][$tabType])) {
577 $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
578 $this->tabObject->set_acl_base($this->headpage->getBase());
579 $this->tabObject->parent = &$this;
580 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!");
581 } else {
582 msg_dialog::display(_("Error"), sprintf(_("No tab declaration for '%s' found in your configuration file. Cannot create plugin instance!"), $tabType), ERROR_DIALOG);
583 }
584 }
585 }
588 /*! \brief This method opens an existing object or a list of existing objects to be edited.
589 *
590 *
591 * @param String 'action' The name of the action which was the used as trigger.
592 * @param Array 'target' A list of object dns, which should be affected by this method.
593 * @param Array 'all' A combination of both 'action' and 'target'.
594 */
595 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
596 {
597 /* To handle mutliple object types overload this method.
598 * ...
599 * registerAction('editUser', 'editEntry');
600 * registerAction('editGroup','editEntry');
601 * ...
602 *
603 * function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
604 * {
605 * switch($action){
606 * case 'editUser' : {
607 * mangement::editEntry($action,$target,$all,"usertabs","USERTABS","users");
608 * }
609 * case 'editGroup' : {
610 * mangement::editEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
611 * }
612 * }
613 * }
614 **/
616 // Do not create a new tabObject while there is already one opened,
617 // the user may have just pressed F5 to reload the page.
618 if(is_object($this->tabObject)){
619 return;
620 }
622 $tabType = $this->tabType;
623 $tabClass = $this->tabClass;
624 $aclCategory = $this->aclCategory;
625 if(!empty($altTabClass)) $tabClass = $altTabClass;
626 if(!empty($altTabType)) $tabType = $altTabType;
627 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
629 // Single edit - we only got one object dn.
630 if(count($target) == 1){
631 $this->displayApplyBtn = TRUE;
632 $this->is_new = FALSE;
633 $this->is_single_edit = TRUE;
634 $this->is_multiple_edit = FALSE;
636 // Get the dn of the object and creates lock
637 $this->dn = array_pop($target);
638 set_object_info($this->dn);
639 $user = get_lock($this->dn);
640 if ($user != ""){
641 return(gen_locked_message ($user, $this->dn,TRUE));
642 }
643 add_lock ($this->dn, $this->ui->dn);
645 // Open object.
646 if(empty($tabClass) || empty($tabType)){
647 trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
648 }else{
649 $tab = $tabClass;
650 $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$tabType], $this->dn,$aclCategory);
651 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Edit entry initiated!");
652 $this->tabObject->set_acl_base($this->dn);
653 $this->tabObject->parent = &$this;
654 }
655 }else{
657 // We've multiple entries to edit.
658 $this->is_new = FALSE;
659 $this->is_singel_edit = FALSE;
660 $this->is_multiple_edit = TRUE;
662 // Open multiple edit handler.
663 if(empty($tabClass) || empty($tabType)){
664 trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
665 }else{
666 $this->dns = $target;
667 $tmp = new multi_plug($this->config,$tabClass,$this->config->data['TABS'][$tabType],
668 $this->dns,$this->headpage->getBase(),$aclCategory);
670 // Check for locked entries
671 if ($tmp->entries_locked()){
672 return($tmp->display_lock_message());
673 }
675 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Edit entry initiated!");
677 // Now lock entries.
678 if($tmp->multiple_available()){
679 $tmp->lock_entries($this->ui->dn);
680 $this->tabObject = $tmp;
681 set_object_info($this->tabObject->get_object_info());
682 }
683 }
684 }
685 }
688 /*! \brief Save object modifications and closes dialogs (returns to object listing).
689 * - Calls '::check' to validate the given input.
690 * - Calls '::save' to save back object modifications (e.g. to ldap).
691 * - Calls '::remove_locks' to remove eventually created locks.
692 * - Calls '::closeDialogs' to return to the object listing.
693 */
694 protected function saveChanges()
695 {
696 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
697 $this->tabObject->save_object();
698 $msgs = $this->tabObject->check();
699 if(count($msgs)){
700 msg_dialog::displayChecks($msgs);
701 return("");
702 }else{
703 $this->tabObject->save();
704 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
705 $this->remove_lock();
706 $this->closeDialogs();
707 }
708 }elseif($this->dialogObject instanceOf plugin){
709 $this->dialogObject->save_object();
710 $msgs = $this->dialogObject->check();
711 if(count($msgs)){
712 msg_dialog::displayChecks($msgs);
713 return("");
714 }else{
715 $this->dialogObject->save();
716 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
717 $this->remove_lock();
718 $this->closeDialogs();
719 }
720 }
721 }
724 /*! \brief Save object modifications and keep dialogs opened.
725 * - Calls '::check' to validate the given input.
726 * - Calls '::save' to save back object modifications (e.g. to ldap).
727 */
728 protected function applyChanges()
729 {
730 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
731 $this->tabObject->save_object();
732 $msgs = $this->tabObject->check();
733 if(count($msgs)){
734 msg_dialog::displayChecks($msgs);
735 return("");
736 }else{
737 $this->tabObject->save();
738 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Modifications applied!");
739 $this->tabObject->re_init();
740 }
741 }
742 }
745 /*! \brief This method closes dialogs
746 * and cleans up the cached object info and the ui.
747 */
748 protected function closeDialogs()
749 {
750 $this->last_dn = $this->dn;
751 $this->last_dns = $this->dns;
752 $this->last_tabObject = $this->tabObject;
753 $this->last_dialogObject = $this->dialogObject;
754 $this->dn = "";
755 $this->dns = array();
756 $this->tabObject = null;
757 $this->dialogObject = null;
758 $this->skipFooter = FALSE;
759 set_object_info();
760 }
763 /*! \brief Editing an object was caneled.
764 * Close dialogs/tabs and remove locks.
765 */
766 protected function cancelEdit()
767 {
768 $this->remove_lock();
769 $this->closeDialogs();
770 }
773 /*! \brief Every click in the list user interface sends an event
774 * here can we connect those events to a method.
775 * eg. ::registerEvent('new','createUser')
776 * When the action/event new is send, the method 'createUser'
777 * will be called.
778 */
779 function registerAction($action,$target)
780 {
781 $this->actions[$action] = $target;
782 }
785 /*! \brief Removes ldap object locks created by this class.
786 * Whenever an object is edited, we create locks to avoid
787 * concurrent modifications.
788 * This locks will automatically removed here.
789 */
790 function remove_lock()
791 {
792 if(!empty($this->dn) && $this->dn != "new"){
793 del_lock($this->dn);
794 }
795 if(count($this->dns)){
796 del_lock($this->dns);
797 }
798 }
801 /*! \brief This method is used to queue and process copy&paste actions.
802 * Allows to copy, cut and paste mutliple entries at once.
803 * @param String 'action' The name of the action which was the used as trigger.
804 * @param Array 'target' A list of object dns, which should be affected by this method.
805 * @param Array 'all' A combination of both 'action' and 'target'.
806 */
807 function copyPasteHandler($action="",$target=array(),$all=array(),
808 $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
809 {
810 // Return without any actions while copy&paste handler is disabled.
811 if(!is_object($this->cpHandler)) return("");
813 $tabType = $this->tabType;
814 $tabClass = $this->tabClass;
815 $aclCategory = $this->aclCategory;
816 $aclPlugin = $this->aclPlugin;
817 if(!empty($altTabClass)) $tabClass = $altTabClass;
818 if(!empty($altTabType)) $tabType = $altTabType;
819 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
820 if(!empty($altAclPlugin)) $aclPlugin = $altAclPlugin;
822 // Save user input
823 $this->cpHandler->save_object();
825 // Add entries to queue
826 if($action == "copy" || $action == "cut"){
827 $this->cpHandler->cleanup_queue();
828 foreach($target as $dn){
829 if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
830 $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this);
831 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!");
832 }
833 if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
834 $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this);
835 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!");
836 }
837 }
838 }
840 // Initiate pasting
841 if($action == "paste"){
842 $this->cpPastingStarted = TRUE;
843 }
845 // Display any c&p dialogs, eg. object modifications required before pasting.
846 if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
847 $this->cpHandler->SetVar("base",$this->headpage->getBase());
848 $data = $this->cpHandler->execute();
849 if(!empty($data)){
850 return($data);
851 }
852 }
854 // Automatically disable pasting process since there is no entry left to paste.
855 if(!$this->cpHandler->entries_queued()){
856 $this->cpPastingStarted = FALSE;
857 }
858 return("");
859 }
862 function setFilter($str) {
863 $this->filter = $str;
864 }
867 function postcreate() {
868 $this->_handlePostEvent('POSTCREATE');
869 }
870 function postmodify(){
871 $this->_handlePostEvent('POSTMODIFY');
872 }
873 function postremove(){
874 $this->_handlePostEvent('POSTREMOVE');
875 }
877 function _handlePostEvent($type)
878 {
880 /* Find postcreate entries for this class */
881 $command= $this->config->search(get_class($this), $type,array('menu', 'tabs'));
882 if ($command != ""){
884 /* Walk through attribute list */
885 foreach ($this->attributes as $attr){
886 if (!is_array($this->$attr)){
887 $add_attrs[$attr] = $this->$attr;
888 }
889 }
890 $add_attrs['dn']=$this->dn;
892 $tmp = array();
893 foreach($add_attrs as $name => $value){
894 $tmp[$name] = strlen($name);
895 }
896 arsort($tmp);
898 /* Additional attributes */
899 foreach ($tmp as $name => $len){
900 $value = $add_attrs[$name];
901 $command= str_replace("%$name", "$value", $command);
902 }
904 if (check_command($command)){
905 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
906 $command, "Execute");
907 exec($command,$arr);
908 foreach($arr as $str){
909 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
910 $command, "Result: ".$str);
911 }
912 } else {
913 $message= msgPool::cmdnotfound($type, get_class($this));
914 msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
915 }
916 }
917 }
919 function is_modal_dialog()
920 {
921 return(is_object($this->tabObject) || is_object($this->dialogObject));
922 }
925 /*! \brief Forward command execution request
926 * to the correct method.
927 */
928 function handle_post_events($mode, $addAttrs= array())
929 {
930 if(!in_array($mode, array('add','remove','modify'))){
931 trigger_error(sprintf("Invalid post event type given '%s'! Valid types are [add,modify,remove].", $mode));
932 return;
933 }
934 switch ($mode){
935 case "add":
936 plugin::callHook($this,"POSTCREATE", $addAttrs);
937 break;
939 case "modify":
940 plugin::callHook($this,"POSTMODIFY", $addAttrs);
941 break;
943 case "remove":
944 plugin::callHook($this,"POSTREMOVE", $addAttrs);
945 break;
946 }
947 }
948 }
950 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
951 ?>