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 $this->registerAction("saveFilter","saveFilter");
126 // To temporay disable the filter caching UNcomment this line.
127 #session::global_un_set(get_class($this)."_filter");
128 }
130 /*! \brief Execute this plugin
131 * Handle actions/events, locking, snapshots, dialogs, tabs,...
132 */
133 function execute()
134 {
135 // Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog.
136 $vars = array('/^act$/','/^listing/','/^PID$/','/^FILTER_PID$/');
137 session::set('LOCK_VARS_TO_USE',$vars);
139 pathNavigator::registerPlugin($this);
141 /* Display the copy & paste dialog, if it is currently open */
142 $ret = $this->copyPasteHandler("",array());
143 if($ret){
144 return($this->getHeader().$ret);
145 }
147 // Update filter
148 if ($this->filter) {
149 $this->filter->update();
150 session::global_set(get_class($this)."_filter", $this->filter);
151 session::set('autocomplete', $this->filter);
152 }
154 // Handle actions (POSTs and GETs)
155 $str = $this->handleActions($this->detectPostActions());
156 if($str) return($this->getHeader().$str);
158 // Open single dialog objects
159 if(is_object($this->dialogObject)){
160 if(method_exists($this->dialogObject,'save_object')) $this->dialogObject->save_object();
161 if(method_exists($this->dialogObject,'execute')){
162 $display = $this->dialogObject->execute();
163 $display.= $this->_getTabFooter();
164 return($this->getHeader().$display);
165 }
166 }
168 // Display tab object.
169 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
170 # $this->tabObject->save_object();
171 $display = $this->tabObject->execute();
172 $display.= $this->_getTabFooter();
173 return($this->getHeader().$display);
174 }
176 // Set current restore base for snapshot handling.
177 if(is_object($this->snapHandler)){
178 $bases = array();
179 foreach($this->storagePoints as $sp){
180 $bases[] = $sp.$this->headpage->getBase();
181 }
183 // No bases specified? Try base
184 if(!count($bases)) $bases[] = $this->headpage->getBase();
186 $this->snapHandler->setSnapshotBases($bases);
187 }
189 // Display list
190 return($this->renderList());
191 }
193 function editFilter()
194 {
195 $this->dialogObject = new userFilter($this->config,$this->getHeadpage());
196 }
198 function renderList()
199 {
200 $this->headpage->update();
201 $display = $this->headpage->render();
202 return($this->getHeader().$display);
203 }
205 function getHeadpage()
206 {
207 return($this->headpage);
208 }
210 function getFilter()
211 {
212 return($this->filter);
213 }
215 /*! \brief Generates the plugin header which is displayed whenever a tab object is
216 * opened.
217 */
218 protected function getHeader()
219 {
220 // We do not display any headers right now.
221 if(1 || $this->skipHeader) return("");
222 }
225 /*! \brief Generates the footer which is used whenever a tab object is
226 * displayed.
227 */
228 protected function _getTabFooter()
229 {
230 // Do not display tab footer for non tab objects
231 if(!($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug)){
232 return("");
233 }
235 // Check if there is a dialog opened - We don't need any buttons in this case.
236 if($this->tabObject->by_object[$this->tabObject->current]){
237 $current = $this->tabObject->by_object[$this->tabObject->current];
238 if(isset($current->dialog) && (is_object($current->dialog) || $current->dialog)){
239 return("");
240 }
241 }
243 // Skip footer if requested;
244 if($this->skipFooter) return("");
246 // In case an of locked entry, we may have opened a read-only tab.
247 $str = "";
248 if(isset($this->tabObject->read_only) && $this->tabObject->read_only == TRUE){
249 $str.= "
250 <p style=\"text-align:right\">
251 <button type=submit name=\"edit_cancel\">".msgPool::cancelButton()."</button>
252 </p>";
253 return($str);
254 }else{
256 // Display ok, (apply) and cancel buttons
257 $str.= "<p style=\"text-align:right\">\n";
258 $str.= "<button type=\"submit\" name=\"edit_finish\" style=\"width:80px\">".msgPool::okButton()."</button>\n";
259 $str.= " \n";
260 if($this->displayApplyBtn){
261 $str.= "<button type=\"submit\" name=\"edit_apply\">".msgPool::applyButton()."</button>\n";
262 $str.= " \n";
263 }
264 $str.= "<button type=\"submit\" name=\"edit_cancel\">".msgPool::cancelButton()."</button>\n";
265 $str.= "</p>";
266 }
267 return($str);
268 }
271 /*! \brief Initiates the removal for the given entries
272 * and displays a confirmation dialog.
273 *
274 * @param String 'action' The name of the action which was the used as trigger.
275 * @param Array 'target' A list of object dns, which should be affected by this method.
276 * @param Array 'all' A combination of both 'action' and 'target'.
277 */
278 protected function removeEntryRequested($action="",$target=array(),$all=array())
279 {
280 // Close dialogs and remove locks for currently handled dns
281 $this->cancelEdit();
283 $disallowed = array();
284 $this->dns = array();
286 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
288 // Check permissons for each target
289 foreach($target as $dn){
290 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
291 if(preg_match("/d/",$acl)){
292 $this->dns[] = $dn;
293 }else{
294 $disallowed[] = $dn;
295 }
296 }
297 if(count($disallowed)){
298 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
299 }
301 // We've at least one entry to delete.
302 if(count($this->dns)){
304 // check locks
305 if ($user= get_multiple_locks($this->dns)){
306 return(gen_locked_message($user,$this->dns));
307 }
309 // Add locks
310 $dns_names = array();
311 foreach($this->dns as $dn){
312 $dns_names[] =LDAP::fix($dn);
313 }
314 add_lock ($this->dns, $this->ui->dn);
316 // Display confirmation dialog.
317 $smarty = get_smarty();
318 $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
319 $smarty->assign("multiple", true);
320 return($smarty->fetch(get_template_path('removeEntries.tpl')));
321 }
322 }
325 /*! \brief Object removal was confirmed, now remove the requested entries.
326 *
327 * @param String 'action' The name of the action which was the used as trigger.
328 * @param Array 'target' A list of object dns, which should be affected by this method.
329 * @param Array 'all' A combination of both 'action' and 'target'.
330 */
331 function removeEntryConfirmed($action="",$target=array(),$all=array(),
332 $altTabClass="",$altTabType="",$altAclCategory="")
333 {
334 $tabType = $this->tabType;
335 $tabClass = $this->tabClass;
336 $aclCategory = $this->aclCategory;
337 if(!empty($altTabClass)) $tabClass = $altTabClass;
338 if(!empty($altTabType)) $tabType = $altTabType;
339 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
341 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
343 foreach($this->dns as $key => $dn){
345 // Check permissions, are we allowed to remove this object?
346 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
347 if(preg_match("/d/",$acl)){
349 // Delete the object
350 $this->dn = $dn;
351 $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory, true, true);
352 $this->tabObject->set_acl_base($this->dn);
353 $this->tabObject->parent = &$this;
354 $this->tabObject->delete ();
356 // Remove the lock for the current object.
357 del_lock($this->dn);
358 } else {
359 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
360 new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
361 }
362 }
364 // Cleanup
365 $this->remove_lock();
366 $this->closeDialogs();
367 }
370 /*! \brief Detects actions/events send by the ui
371 * and the corresponding targets.
372 */
373 function detectPostActions()
374 {
375 if(!is_object($this->headpage)){
376 trigger_error("No valid headpage given....!");
377 return(array());
378 }
379 $action= $this->headpage->getAction();
380 if(isset($_POST['edit_apply'])) $action['action'] = "apply";
381 if(isset($_POST['edit_finish'])) $action['action'] = "save";
382 if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";
383 if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";
384 if(isset($_POST['delete_cancel'])) $action['action'] = "cancelDelete";
385 if(isset($_POST['saveFilter'])) $action['action'] = "saveFilter";
386 if(isset($_POST['cancelFilter'])) $action['action'] = "cancel";
388 // Detect Snapshot actions
389 if(isset($_POST['CreateSnapshot'])) $action['action'] = "saveSnapshot";
390 if(isset($_POST['CancelSnapshot'])) $action['action'] = "cancelSnapshot";
391 foreach($_POST as $name => $value){
392 $once =TRUE;
393 if(preg_match("/^RestoreSnapShot_/",$name) && $once){
394 $once = FALSE;
395 $entry = base64_decode(preg_replace("/^RestoreSnapShot_([^_]*)_[xy]$/i","\\1",$name));
396 $action['action'] = "restoreSnapshot";
397 $action['targets'] = array($entry);
398 }
399 }
401 return($action);
402 }
405 /*! \brief Calls the registered method for a given action/event.
406 */
407 function handleActions($action)
408 {
409 // Start action
410 if(isset($this->actions[$action['action']])){
411 $func = $this->actions[$action['action']];
412 if(!isset($action['targets']))$action['targets']= array();
413 return($this->$func($action['action'],$action['targets'],$action));
414 }
415 }
418 /*! \brief Opens the snapshot creation dialog for the given target.
419 *
420 * @param String 'action' The name of the action which was the used as trigger.
421 * @param Array 'target' A list of object dns, which should be affected by this method.
422 * @param Array 'all' A combination of both 'action' and 'target'.
423 */
424 function createSnapshotDialog($action="",$target=array(),$all=array())
425 {
426 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!");
428 foreach($target as $entry){
429 if(!empty($entry) && $this->ui->allow_snapshot_create($entry,$this->aclCategory)){
430 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
431 $this->dialogObject->aclCategories = array($this->aclCategory);
432 $this->dialogObject->parent = &$this;
434 }else{
435 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$entry),
436 ERROR_DIALOG);
437 }
438 }
439 }
442 /*! \brief Creates a snapshot new entry - This method is called when the somebody
443 * clicks 'save' in the "Create snapshot dialog" (see ::createSnapshotDialog).
444 *
445 * @param String 'action' The name of the action which was the used as trigger.
446 * @param Array 'target' A list of object dns, which should be affected by this method.
447 * @param Array 'all' A combination of both 'action' and 'target'.
448 */
449 function saveSnapshot($action="",$target=array(),$all=array())
450 {
451 if(!is_object($this->dialogObject)) return;
452 $this->dialogObject->save_object();
453 $msgs = $this->dialogObject->check();
454 if(count($msgs)){
455 foreach($msgs as $msg){
456 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
457 }
458 }else{
459 $this->dn = $this->dialogObject->dn;
460 $this->snapHandler->create_snapshot( $this->dn,$this->dialogObject->CurrentDescription);
461 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot created!");
462 $this->closeDialogs();
463 }
464 }
467 /*! \brief Restores a snapshot object.
468 * The dn of the snapshot entry has to be given as ['target'] parameter.
469 *
470 * @param String 'action' The name of the action which was the used as trigger.
471 * @param Array 'target' A list of object dns, which should be affected by this method.
472 * @param Array 'all' A combination of both 'action' and 'target'.
473 */
474 function restoreSnapshot($action="",$target=array(),$all=array())
475 {
476 $entry = array_pop($target);
477 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
478 $this->snapHandler->restore_snapshot($entry);
479 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot restored!");
480 $this->closeDialogs();
481 }else{
482 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
483 ERROR_DIALOG);
484 }
485 }
488 /*! \brief Displays the "Restore snapshot dialog" for a given target.
489 * If no target is specified, open the restore removed object
490 * dialog.
491 * @param String 'action' The name of the action which was the used as trigger.
492 * @param Array 'target' A list of object dns, which should be affected by this method.
493 * @param Array 'all' A combination of both 'action' and 'target'.
494 */
495 function restoreSnapshotDialog($action="",$target=array(),$all=array())
496 {
497 // Set current restore base for snapshot handling.
498 if(is_object($this->snapHandler)){
499 $bases = array();
500 foreach($this->storagePoints as $sp){
501 $bases[] = $sp.$this->headpage->getBase();
502 }
503 }
505 // No bases specified? Try base
506 if(!count($bases)) $bases[] = $this->headpage->getBase();
508 // No target, open the restore removed object dialog.
509 if(!count($target)){
510 $entry = $this->headpage->getBase();
511 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
512 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
513 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
514 $this->dialogObject->set_snapshot_bases($bases);
515 $this->dialogObject->display_all_removed_objects = true;
516 $this->dialogObject->display_restore_dialog = true;
517 $this->dialogObject->parent = &$this;
518 }else{
519 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
520 ERROR_DIALOG);
521 }
522 }else{
524 // Display the restore points for a given object.
525 $entry = array_pop($target);
526 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
527 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
528 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
529 $this->dialogObject->set_snapshot_bases($bases);
530 $this->dialogObject->display_restore_dialog = true;
531 $this->dialogObject->parent = &$this;
532 }else{
533 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
534 ERROR_DIALOG);
535 }
536 }
537 }
540 /*! \brief This method intiates the object creation.
541 *
542 * @param String 'action' The name of the action which was the used as trigger.
543 * @param Array 'target' A list of object dns, which should be affected by this method.
544 * @param Array 'all' A combination of both 'action' and 'target'.
545 */
546 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
547 {
548 /* To handle mutliple object types overload this method.
549 * ...
550 * registerAction('newUser', 'newEntry');
551 * registerAction('newGroup','newEntry');
552 * ...
553 *
554 * function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
555 * {
556 * switch($action){
557 * case 'newUser' : {
558 * mangement::newEntry($action,$target,$all,"usertabs","USERTABS","users");
559 * }
560 * case 'newGroup' : {
561 * mangement::newEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
562 * }
563 * }
564 * }
565 **/
566 $tabType = $this->tabType;
567 $tabClass = $this->tabClass;
568 $aclCategory = $this->aclCategory;
569 if(!empty($altTabClass)) $tabClass = $altTabClass;
570 if(!empty($altTabType)) $tabType = $altTabType;
571 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
573 // Check locking & lock entry if required
574 $this->displayApplyBtn = FALSE;
575 $this->dn = "new";
576 $this->is_new = TRUE;
577 $this->is_single_edit = FALSE;
578 $this->is_multiple_edit = FALSE;
580 set_object_info($this->dn);
582 // Open object.
583 if(empty($tabClass) || empty($tabType)){
584 // No tab type defined
585 }else{
586 if (isset($this->config->data['TABS'][$tabType])) {
587 $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
588 $this->tabObject->set_acl_base($this->headpage->getBase());
589 $this->tabObject->parent = &$this;
590 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!");
591 } else {
592 msg_dialog::display(_("Error"), sprintf(_("No tab declaration for '%s' found in your configuration file. Cannot create plugin instance!"), $tabType), ERROR_DIALOG);
593 }
594 }
595 }
598 /*! \brief This method opens an existing object or a list of existing objects to be edited.
599 *
600 *
601 * @param String 'action' The name of the action which was the used as trigger.
602 * @param Array 'target' A list of object dns, which should be affected by this method.
603 * @param Array 'all' A combination of both 'action' and 'target'.
604 */
605 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
606 {
607 /* To handle mutliple object types overload this method.
608 * ...
609 * registerAction('editUser', 'editEntry');
610 * registerAction('editGroup','editEntry');
611 * ...
612 *
613 * function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
614 * {
615 * switch($action){
616 * case 'editUser' : {
617 * mangement::editEntry($action,$target,$all,"usertabs","USERTABS","users");
618 * }
619 * case 'editGroup' : {
620 * mangement::editEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
621 * }
622 * }
623 * }
624 **/
626 // Do not create a new tabObject while there is already one opened,
627 // the user may have just pressed F5 to reload the page.
628 if(is_object($this->tabObject)){
629 return;
630 }
632 $tabType = $this->tabType;
633 $tabClass = $this->tabClass;
634 $aclCategory = $this->aclCategory;
635 if(!empty($altTabClass)) $tabClass = $altTabClass;
636 if(!empty($altTabType)) $tabType = $altTabType;
637 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
639 // Single edit - we only got one object dn.
640 if(count($target) == 1){
641 $this->displayApplyBtn = TRUE;
642 $this->is_new = FALSE;
643 $this->is_single_edit = TRUE;
644 $this->is_multiple_edit = FALSE;
646 // Get the dn of the object and creates lock
647 $this->dn = array_pop($target);
648 set_object_info($this->dn);
649 $user = get_lock($this->dn);
650 if ($user != ""){
651 return(gen_locked_message ($user, $this->dn,TRUE));
652 }
653 add_lock ($this->dn, $this->ui->dn);
655 // Open object.
656 if(empty($tabClass) || empty($tabType)){
657 trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
658 }else{
659 $tab = $tabClass;
660 $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$tabType], $this->dn,$aclCategory);
661 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Edit entry initiated!");
662 $this->tabObject->set_acl_base($this->dn);
663 $this->tabObject->parent = &$this;
664 }
665 }else{
667 // We've multiple entries to edit.
668 $this->is_new = FALSE;
669 $this->is_singel_edit = FALSE;
670 $this->is_multiple_edit = TRUE;
672 // Open multiple edit handler.
673 if(empty($tabClass) || empty($tabType)){
674 trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
675 }else{
676 $this->dns = $target;
677 $tmp = new multi_plug($this->config,$tabClass,$this->config->data['TABS'][$tabType],
678 $this->dns,$this->headpage->getBase(),$aclCategory);
680 // Check for locked entries
681 if ($tmp->entries_locked()){
682 return($tmp->display_lock_message());
683 }
685 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Edit entry initiated!");
687 // Now lock entries.
688 if($tmp->multiple_available()){
689 $tmp->lock_entries($this->ui->dn);
690 $this->tabObject = $tmp;
691 set_object_info($this->tabObject->get_object_info());
692 }
693 }
694 }
695 }
698 /*! \brief Save filter modifcations.
699 */
700 protected function saveFilter()
701 {
702 if($this->dialogObject instanceOf userFilter){
703 $msgs = $this->dialogObject->check();
704 if(count($msgs)){
705 msg_dialog::displayChecks($msgs);
706 return("");
707 }else{
708 $this->dialogObject->save();
709 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
710 $this->remove_lock();
711 $this->closeDialogs();
713 // Ask filter to reload information
714 $this->filter->reloadFilters();
715 }
716 }
717 }
720 /*! \brief Save object modifications and closes dialogs (returns to object listing).
721 * - Calls '::check' to validate the given input.
722 * - Calls '::save' to save back object modifications (e.g. to ldap).
723 * - Calls '::remove_locks' to remove eventually created locks.
724 * - Calls '::closeDialogs' to return to the object listing.
725 */
726 protected function saveChanges()
727 {
728 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
729 $this->tabObject->save_object();
730 $msgs = $this->tabObject->check();
731 if(count($msgs)){
732 msg_dialog::displayChecks($msgs);
733 return("");
734 }else{
735 $this->tabObject->save();
736 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
737 $this->remove_lock();
738 $this->closeDialogs();
739 }
740 }elseif($this->dialogObject instanceOf plugin){
741 $this->dialogObject->save_object();
742 $msgs = $this->dialogObject->check();
743 if(count($msgs)){
744 msg_dialog::displayChecks($msgs);
745 return("");
746 }else{
747 $this->dialogObject->save();
748 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
749 $this->remove_lock();
750 $this->closeDialogs();
751 }
752 }
753 }
756 /*! \brief Save object modifications and keep dialogs opened.
757 * - Calls '::check' to validate the given input.
758 * - Calls '::save' to save back object modifications (e.g. to ldap).
759 */
760 protected function applyChanges()
761 {
762 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
763 $this->tabObject->save_object();
764 $msgs = $this->tabObject->check();
765 if(count($msgs)){
766 msg_dialog::displayChecks($msgs);
767 return("");
768 }else{
769 $this->tabObject->save();
770 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Modifications applied!");
771 $this->tabObject->re_init();
772 }
773 }
774 }
777 /*! \brief This method closes dialogs
778 * and cleans up the cached object info and the ui.
779 */
780 protected function closeDialogs()
781 {
782 $this->last_dn = $this->dn;
783 $this->last_dns = $this->dns;
784 $this->last_tabObject = $this->tabObject;
785 $this->last_dialogObject = $this->dialogObject;
786 $this->dn = "";
787 $this->dns = array();
788 $this->tabObject = null;
789 $this->dialogObject = null;
790 $this->skipFooter = FALSE;
791 set_object_info();
792 }
795 /*! \brief Editing an object was caneled.
796 * Close dialogs/tabs and remove locks.
797 */
798 protected function cancelEdit()
799 {
800 $this->remove_lock();
801 $this->closeDialogs();
802 }
805 /*! \brief Every click in the list user interface sends an event
806 * here can we connect those events to a method.
807 * eg. ::registerEvent('new','createUser')
808 * When the action/event new is send, the method 'createUser'
809 * will be called.
810 */
811 function registerAction($action,$target)
812 {
813 $this->actions[$action] = $target;
814 }
817 /*! \brief Removes ldap object locks created by this class.
818 * Whenever an object is edited, we create locks to avoid
819 * concurrent modifications.
820 * This locks will automatically removed here.
821 */
822 function remove_lock()
823 {
824 if(!empty($this->dn) && $this->dn != "new"){
825 del_lock($this->dn);
826 }
827 if(count($this->dns)){
828 del_lock($this->dns);
829 }
830 }
833 /*! \brief This method is used to queue and process copy&paste actions.
834 * Allows to copy, cut and paste mutliple entries at once.
835 * @param String 'action' The name of the action which was the used as trigger.
836 * @param Array 'target' A list of object dns, which should be affected by this method.
837 * @param Array 'all' A combination of both 'action' and 'target'.
838 */
839 function copyPasteHandler($action="",$target=array(),$all=array(),
840 $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
841 {
842 // Return without any actions while copy&paste handler is disabled.
843 if(!is_object($this->cpHandler)) return("");
845 $tabType = $this->tabType;
846 $tabClass = $this->tabClass;
847 $aclCategory = $this->aclCategory;
848 $aclPlugin = $this->aclPlugin;
849 if(!empty($altTabClass)) $tabClass = $altTabClass;
850 if(!empty($altTabType)) $tabType = $altTabType;
851 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
852 if(!empty($altAclPlugin)) $aclPlugin = $altAclPlugin;
854 // Save user input
855 $this->cpHandler->save_object();
857 // Add entries to queue
858 if($action == "copy" || $action == "cut"){
859 $this->cpHandler->cleanup_queue();
860 foreach($target as $dn){
861 if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
862 $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this);
863 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!");
864 }
865 if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
866 $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this);
867 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!");
868 }
869 }
870 }
872 // Initiate pasting
873 if($action == "paste"){
874 $this->cpPastingStarted = TRUE;
875 }
877 // Display any c&p dialogs, eg. object modifications required before pasting.
878 if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
879 $this->cpHandler->SetVar("base",$this->headpage->getBase());
880 $data = $this->cpHandler->execute();
881 if(!empty($data)){
882 return($data);
883 }
884 }
886 // Automatically disable pasting process since there is no entry left to paste.
887 if(!$this->cpHandler->entries_queued()){
888 $this->cpPastingStarted = FALSE;
889 }
890 return("");
891 }
894 function setFilter($str) {
895 $this->filter = $str;
896 }
899 function postcreate() {
900 $this->_handlePostEvent('POSTCREATE');
901 }
902 function postmodify(){
903 $this->_handlePostEvent('POSTMODIFY');
904 }
905 function postremove(){
906 $this->_handlePostEvent('POSTREMOVE');
907 }
909 function _handlePostEvent($type)
910 {
912 /* Find postcreate entries for this class */
913 $command= $this->config->search(get_class($this), $type,array('menu', 'tabs'));
914 if ($command != ""){
916 /* Walk through attribute list */
917 foreach ($this->attributes as $attr){
918 if (!is_array($this->$attr)){
919 $add_attrs[$attr] = $this->$attr;
920 }
921 }
922 $add_attrs['dn']=$this->dn;
924 $tmp = array();
925 foreach($add_attrs as $name => $value){
926 $tmp[$name] = strlen($name);
927 }
928 arsort($tmp);
930 /* Additional attributes */
931 foreach ($tmp as $name => $len){
932 $value = $add_attrs[$name];
933 $command= str_replace("%$name", "$value", $command);
934 }
936 if (check_command($command)){
937 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
938 $command, "Execute");
939 exec($command,$arr);
940 foreach($arr as $str){
941 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
942 $command, "Result: ".$str);
943 }
944 } else {
945 $message= msgPool::cmdnotfound($type, get_class($this));
946 msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
947 }
948 }
949 }
951 function is_modal_dialog()
952 {
953 return(is_object($this->tabObject) || is_object($this->dialogObject));
954 }
957 /*! \brief Forward command execution request
958 * to the correct method.
959 */
960 function handle_post_events($mode, $addAttrs= array())
961 {
962 if(!in_array($mode, array('add','remove','modify'))){
963 trigger_error(sprintf("Invalid post event type given '%s'! Valid types are [add,modify,remove].", $mode));
964 return;
965 }
966 switch ($mode){
967 case "add":
968 plugin::callHook($this,"POSTCREATE", $addAttrs);
969 break;
971 case "modify":
972 plugin::callHook($this,"POSTMODIFY", $addAttrs);
973 break;
975 case "remove":
976 plugin::callHook($this,"POSTREMOVE", $addAttrs);
977 break;
978 }
979 }
980 }
982 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
983 ?>