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