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 $types = array();
312 $h = $this->getHeadpage();
314 // Build list of object -labels
315 foreach($h->objectTypes as $type){
316 $map[$type['objectClass']]= $type['label'];
317 }
319 foreach($this->dns as $dn){
320 $tmp = $h->getType($dn);
321 if(isset($map[$tmp])){
322 $dns_names[LDAP::fix($dn)] = _($map[$tmp]);
323 }else{
324 $dns_names[] =LDAP::fix($dn);
325 }
326 }
327 add_lock ($this->dns, $this->ui->dn);
329 // Display confirmation dialog.
330 $smarty = get_smarty();
331 $smarty->assign("info", msgPool::deleteInfo($dns_names));
332 $smarty->assign("multiple", true);
333 return($smarty->fetch(get_template_path('removeEntries.tpl')));
334 }
335 }
338 /*! \brief Object removal was confirmed, now remove the requested entries.
339 *
340 * @param String 'action' The name of the action which was the used as trigger.
341 * @param Array 'target' A list of object dns, which should be affected by this method.
342 * @param Array 'all' A combination of both 'action' and 'target'.
343 */
344 function removeEntryConfirmed($action="",$target=array(),$all=array(),
345 $altTabClass="",$altTabType="",$altAclCategory="")
346 {
347 $tabType = $this->tabType;
348 $tabClass = $this->tabClass;
349 $aclCategory = $this->aclCategory;
350 if(!empty($altTabClass)) $tabClass = $altTabClass;
351 if(!empty($altTabType)) $tabType = $altTabType;
352 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
354 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
356 foreach($this->dns as $key => $dn){
358 // Check permissions, are we allowed to remove this object?
359 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
360 if(preg_match("/d/",$acl)){
362 // Delete the object
363 $this->dn = $dn;
364 $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory, true, true);
365 $this->tabObject->set_acl_base($this->dn);
366 $this->tabObject->parent = &$this;
367 $this->tabObject->delete ();
369 // Remove the lock for the current object.
370 del_lock($this->dn);
371 } else {
372 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
373 new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
374 }
375 }
377 // Cleanup
378 $this->remove_lock();
379 $this->closeDialogs();
380 }
383 /*! \brief Detects actions/events send by the ui
384 * and the corresponding targets.
385 */
386 function detectPostActions()
387 {
388 if(!is_object($this->headpage)){
389 trigger_error("No valid headpage given....!");
390 return(array());
391 }
392 $action= $this->headpage->getAction();
393 if(isset($_POST['edit_apply'])) $action['action'] = "apply";
394 if(isset($_POST['edit_finish'])) $action['action'] = "save";
395 if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";
396 if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";
397 if(isset($_POST['delete_cancel'])) $action['action'] = "cancelDelete";
398 if(isset($_POST['saveFilter'])) $action['action'] = "saveFilter";
399 if(isset($_POST['cancelFilter'])) $action['action'] = "cancel";
401 // Detect Snapshot actions
402 if(isset($_POST['CreateSnapshot'])) $action['action'] = "saveSnapshot";
403 if(isset($_POST['CancelSnapshot'])) $action['action'] = "cancelSnapshot";
404 foreach($_POST as $name => $value){
405 $once =TRUE;
406 if(preg_match("/^RestoreSnapShot_/",$name) && $once){
407 $once = FALSE;
408 $entry = base64_decode(preg_replace("/^RestoreSnapShot_([^_]*)_[xy]$/i","\\1",$name));
409 $action['action'] = "restoreSnapshot";
410 $action['targets'] = array($entry);
411 }
412 }
414 return($action);
415 }
418 /*! \brief Calls the registered method for a given action/event.
419 */
420 function handleActions($action)
421 {
422 // Start action
423 if(isset($this->actions[$action['action']])){
424 $func = $this->actions[$action['action']];
425 if(!isset($action['targets']))$action['targets']= array();
426 return($this->$func($action['action'],$action['targets'],$action));
427 }
428 }
431 /*! \brief Opens the snapshot creation dialog for the given target.
432 *
433 * @param String 'action' The name of the action which was the used as trigger.
434 * @param Array 'target' A list of object dns, which should be affected by this method.
435 * @param Array 'all' A combination of both 'action' and 'target'.
436 */
437 function createSnapshotDialog($action="",$target=array(),$all=array())
438 {
439 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!");
441 foreach($target as $entry){
442 if(!empty($entry) && $this->ui->allow_snapshot_create($entry,$this->aclCategory)){
443 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
444 $this->dialogObject->aclCategories = array($this->aclCategory);
445 $this->dialogObject->parent = &$this;
447 }else{
448 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$entry),
449 ERROR_DIALOG);
450 }
451 }
452 }
455 /*! \brief Creates a snapshot new entry - This method is called when the somebody
456 * clicks 'save' in the "Create snapshot dialog" (see ::createSnapshotDialog).
457 *
458 * @param String 'action' The name of the action which was the used as trigger.
459 * @param Array 'target' A list of object dns, which should be affected by this method.
460 * @param Array 'all' A combination of both 'action' and 'target'.
461 */
462 function saveSnapshot($action="",$target=array(),$all=array())
463 {
464 if(!is_object($this->dialogObject)) return;
465 $this->dialogObject->save_object();
466 $msgs = $this->dialogObject->check();
467 if(count($msgs)){
468 foreach($msgs as $msg){
469 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
470 }
471 }else{
472 $this->dn = $this->dialogObject->dn;
473 $this->snapHandler->create_snapshot( $this->dn,$this->dialogObject->CurrentDescription);
474 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot created!");
475 $this->closeDialogs();
476 }
477 }
480 /*! \brief Restores a snapshot object.
481 * The dn of the snapshot entry has to be given as ['target'] parameter.
482 *
483 * @param String 'action' The name of the action which was the used as trigger.
484 * @param Array 'target' A list of object dns, which should be affected by this method.
485 * @param Array 'all' A combination of both 'action' and 'target'.
486 */
487 function restoreSnapshot($action="",$target=array(),$all=array())
488 {
489 $entry = array_pop($target);
490 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
491 $this->snapHandler->restore_snapshot($entry);
492 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot restored!");
493 $this->closeDialogs();
494 }else{
495 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
496 ERROR_DIALOG);
497 }
498 }
501 /*! \brief Displays the "Restore snapshot dialog" for a given target.
502 * If no target is specified, open the restore removed object
503 * dialog.
504 * @param String 'action' The name of the action which was the used as trigger.
505 * @param Array 'target' A list of object dns, which should be affected by this method.
506 * @param Array 'all' A combination of both 'action' and 'target'.
507 */
508 function restoreSnapshotDialog($action="",$target=array(),$all=array())
509 {
510 // Set current restore base for snapshot handling.
511 if(is_object($this->snapHandler)){
512 $bases = array();
513 foreach($this->storagePoints as $sp){
514 $bases[] = $sp.$this->headpage->getBase();
515 }
516 }
518 // No bases specified? Try base
519 if(!count($bases)) $bases[] = $this->headpage->getBase();
521 // No target, open the restore removed object dialog.
522 if(!count($target)){
523 $entry = $this->headpage->getBase();
524 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
525 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
526 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
527 $this->dialogObject->set_snapshot_bases($bases);
528 $this->dialogObject->display_all_removed_objects = true;
529 $this->dialogObject->display_restore_dialog = true;
530 $this->dialogObject->parent = &$this;
531 }else{
532 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
533 ERROR_DIALOG);
534 }
535 }else{
537 // Display the restore points for a given object.
538 $entry = array_pop($target);
539 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
540 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
541 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
542 $this->dialogObject->set_snapshot_bases($bases);
543 $this->dialogObject->display_restore_dialog = true;
544 $this->dialogObject->parent = &$this;
545 }else{
546 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
547 ERROR_DIALOG);
548 }
549 }
550 }
553 /*! \brief This method intiates the object creation.
554 *
555 * @param String 'action' The name of the action which was the used as trigger.
556 * @param Array 'target' A list of object dns, which should be affected by this method.
557 * @param Array 'all' A combination of both 'action' and 'target'.
558 */
559 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
560 {
561 /* To handle mutliple object types overload this method.
562 * ...
563 * registerAction('newUser', 'newEntry');
564 * registerAction('newGroup','newEntry');
565 * ...
566 *
567 * function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
568 * {
569 * switch($action){
570 * case 'newUser' : {
571 * mangement::newEntry($action,$target,$all,"usertabs","USERTABS","users");
572 * }
573 * case 'newGroup' : {
574 * mangement::newEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
575 * }
576 * }
577 * }
578 **/
579 $tabType = $this->tabType;
580 $tabClass = $this->tabClass;
581 $aclCategory = $this->aclCategory;
582 if(!empty($altTabClass)) $tabClass = $altTabClass;
583 if(!empty($altTabType)) $tabType = $altTabType;
584 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
586 // Check locking & lock entry if required
587 $this->displayApplyBtn = FALSE;
588 $this->dn = "new";
589 $this->is_new = TRUE;
590 $this->is_single_edit = FALSE;
591 $this->is_multiple_edit = FALSE;
593 set_object_info($this->dn);
595 // Open object.
596 if(empty($tabClass) || empty($tabType)){
597 // No tab type defined
598 }else{
599 if (isset($this->config->data['TABS'][$tabType])) {
600 $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
601 $this->tabObject->set_acl_base($this->headpage->getBase());
602 $this->tabObject->parent = &$this;
603 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!");
604 } else {
605 msg_dialog::display(_("Error"), sprintf(_("No tab declaration for '%s' found in your configuration file. Cannot create plugin instance!"), $tabType), ERROR_DIALOG);
606 }
607 }
608 }
611 /*! \brief This method opens an existing object or a list of existing objects to be edited.
612 *
613 *
614 * @param String 'action' The name of the action which was the used as trigger.
615 * @param Array 'target' A list of object dns, which should be affected by this method.
616 * @param Array 'all' A combination of both 'action' and 'target'.
617 */
618 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
619 {
620 /* To handle mutliple object types overload this method.
621 * ...
622 * registerAction('editUser', 'editEntry');
623 * registerAction('editGroup','editEntry');
624 * ...
625 *
626 * function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
627 * {
628 * switch($action){
629 * case 'editUser' : {
630 * mangement::editEntry($action,$target,$all,"usertabs","USERTABS","users");
631 * }
632 * case 'editGroup' : {
633 * mangement::editEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
634 * }
635 * }
636 * }
637 **/
639 // Do not create a new tabObject while there is already one opened,
640 // the user may have just pressed F5 to reload the page.
641 if(is_object($this->tabObject)){
642 return;
643 }
645 $tabType = $this->tabType;
646 $tabClass = $this->tabClass;
647 $aclCategory = $this->aclCategory;
648 if(!empty($altTabClass)) $tabClass = $altTabClass;
649 if(!empty($altTabType)) $tabType = $altTabType;
650 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
652 // Single edit - we only got one object dn.
653 if(count($target) == 1){
654 $this->displayApplyBtn = TRUE;
655 $this->is_new = FALSE;
656 $this->is_single_edit = TRUE;
657 $this->is_multiple_edit = FALSE;
659 // Get the dn of the object and creates lock
660 $this->dn = array_pop($target);
661 set_object_info($this->dn);
662 $user = get_lock($this->dn);
663 if ($user != ""){
664 return(gen_locked_message ($user, $this->dn,TRUE));
665 }
666 add_lock ($this->dn, $this->ui->dn);
668 // Open object.
669 if(empty($tabClass) || empty($tabType)){
670 trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
671 }else{
672 $tab = $tabClass;
673 $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$tabType], $this->dn,$aclCategory);
674 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Edit entry initiated!");
675 $this->tabObject->set_acl_base($this->dn);
676 $this->tabObject->parent = &$this;
677 }
678 }else{
680 // We've multiple entries to edit.
681 $this->is_new = FALSE;
682 $this->is_singel_edit = FALSE;
683 $this->is_multiple_edit = TRUE;
685 // Open multiple edit handler.
686 if(empty($tabClass) || empty($tabType)){
687 trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
688 }else{
689 $this->dns = $target;
690 $tmp = new multi_plug($this->config,$tabClass,$this->config->data['TABS'][$tabType],
691 $this->dns,$this->headpage->getBase(),$aclCategory);
693 // Check for locked entries
694 if ($tmp->entries_locked()){
695 return($tmp->display_lock_message());
696 }
698 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Edit entry initiated!");
700 // Now lock entries.
701 if($tmp->multiple_available()){
702 $tmp->lock_entries($this->ui->dn);
703 $this->tabObject = $tmp;
704 set_object_info($this->tabObject->get_object_info());
705 }
706 }
707 }
708 }
711 /*! \brief Save filter modifcations.
712 */
713 protected function saveFilter()
714 {
715 if($this->dialogObject instanceOf userFilter){
716 $msgs = $this->dialogObject->check();
717 if(count($msgs)){
718 msg_dialog::displayChecks($msgs);
719 return("");
720 }else{
721 $this->dialogObject->save();
722 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
723 $this->remove_lock();
724 $this->closeDialogs();
726 // Ask filter to reload information
727 $this->filter->reloadFilters();
728 }
729 }
730 }
733 /*! \brief Save object modifications and closes dialogs (returns to object listing).
734 * - Calls '::check' to validate the given input.
735 * - Calls '::save' to save back object modifications (e.g. to ldap).
736 * - Calls '::remove_locks' to remove eventually created locks.
737 * - Calls '::closeDialogs' to return to the object listing.
738 */
739 protected function saveChanges()
740 {
741 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
742 $this->tabObject->save_object();
743 $msgs = $this->tabObject->check();
744 if(count($msgs)){
745 msg_dialog::displayChecks($msgs);
746 return("");
747 }else{
748 $this->tabObject->save();
749 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
750 $this->remove_lock();
751 $this->closeDialogs();
752 }
753 }elseif($this->dialogObject instanceOf plugin){
754 $this->dialogObject->save_object();
755 $msgs = $this->dialogObject->check();
756 if(count($msgs)){
757 msg_dialog::displayChecks($msgs);
758 return("");
759 }else{
760 $this->dialogObject->save();
761 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
762 $this->remove_lock();
763 $this->closeDialogs();
764 }
765 }
766 }
769 /*! \brief Save object modifications and keep dialogs opened.
770 * - Calls '::check' to validate the given input.
771 * - Calls '::save' to save back object modifications (e.g. to ldap).
772 */
773 protected function applyChanges()
774 {
775 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
776 $this->tabObject->save_object();
777 $msgs = $this->tabObject->check();
778 if(count($msgs)){
779 msg_dialog::displayChecks($msgs);
780 return("");
781 }else{
782 $this->tabObject->save();
783 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Modifications applied!");
784 $this->tabObject->re_init();
785 }
786 }
787 }
790 /*! \brief This method closes dialogs
791 * and cleans up the cached object info and the ui.
792 */
793 protected function closeDialogs()
794 {
795 $this->last_dn = $this->dn;
796 $this->last_dns = $this->dns;
797 $this->last_tabObject = $this->tabObject;
798 $this->last_dialogObject = $this->dialogObject;
799 $this->dn = "";
800 $this->dns = array();
801 $this->tabObject = null;
802 $this->dialogObject = null;
803 $this->skipFooter = FALSE;
804 set_object_info();
805 }
808 /*! \brief Editing an object was caneled.
809 * Close dialogs/tabs and remove locks.
810 */
811 protected function cancelEdit()
812 {
813 $this->remove_lock();
814 $this->closeDialogs();
815 }
818 /*! \brief Every click in the list user interface sends an event
819 * here can we connect those events to a method.
820 * eg. ::registerEvent('new','createUser')
821 * When the action/event new is send, the method 'createUser'
822 * will be called.
823 */
824 function registerAction($action,$target)
825 {
826 $this->actions[$action] = $target;
827 }
830 /*! \brief Removes ldap object locks created by this class.
831 * Whenever an object is edited, we create locks to avoid
832 * concurrent modifications.
833 * This locks will automatically removed here.
834 */
835 function remove_lock()
836 {
837 if(!empty($this->dn) && $this->dn != "new"){
838 del_lock($this->dn);
839 }
840 if(count($this->dns)){
841 del_lock($this->dns);
842 }
843 }
846 /*! \brief This method is used to queue and process copy&paste actions.
847 * Allows to copy, cut and paste mutliple entries at once.
848 * @param String 'action' The name of the action which was the used as trigger.
849 * @param Array 'target' A list of object dns, which should be affected by this method.
850 * @param Array 'all' A combination of both 'action' and 'target'.
851 */
852 function copyPasteHandler($action="",$target=array(),$all=array(),
853 $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
854 {
855 // Return without any actions while copy&paste handler is disabled.
856 if(!is_object($this->cpHandler)) return("");
858 $tabType = $this->tabType;
859 $tabClass = $this->tabClass;
860 $aclCategory = $this->aclCategory;
861 $aclPlugin = $this->aclPlugin;
862 if(!empty($altTabClass)) $tabClass = $altTabClass;
863 if(!empty($altTabType)) $tabType = $altTabType;
864 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
865 if(!empty($altAclPlugin)) $aclPlugin = $altAclPlugin;
867 // Save user input
868 $this->cpHandler->save_object();
870 // Add entries to queue
871 if($action == "copy" || $action == "cut"){
872 $this->cpHandler->cleanup_queue();
873 foreach($target as $dn){
874 if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
875 $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this);
876 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!");
877 }
878 if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
879 $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this);
880 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!");
881 }
882 }
883 }
885 // Initiate pasting
886 if($action == "paste"){
887 $this->cpPastingStarted = TRUE;
888 }
890 // Display any c&p dialogs, eg. object modifications required before pasting.
891 if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
892 $this->cpHandler->SetVar("base",$this->headpage->getBase());
893 $data = $this->cpHandler->execute();
894 if(!empty($data)){
895 return($data);
896 }
897 }
899 // Automatically disable pasting process since there is no entry left to paste.
900 if(!$this->cpHandler->entries_queued()){
901 $this->cpPastingStarted = FALSE;
902 }
903 return("");
904 }
907 function setFilter($str) {
908 $this->filter = $str;
909 }
912 function postcreate() {
913 $this->_handlePostEvent('POSTCREATE');
914 }
915 function postmodify(){
916 $this->_handlePostEvent('POSTMODIFY');
917 }
918 function postremove(){
919 $this->_handlePostEvent('POSTREMOVE');
920 }
922 function _handlePostEvent($type)
923 {
925 /* Find postcreate entries for this class */
926 $command= $this->config->search(get_class($this), $type,array('menu', 'tabs'));
927 if ($command != ""){
929 /* Walk through attribute list */
930 foreach ($this->attributes as $attr){
931 if (!is_array($this->$attr)){
932 $add_attrs[$attr] = $this->$attr;
933 }
934 }
935 $add_attrs['dn']=$this->dn;
937 $tmp = array();
938 foreach($add_attrs as $name => $value){
939 $tmp[$name] = strlen($name);
940 }
941 arsort($tmp);
943 /* Additional attributes */
944 foreach ($tmp as $name => $len){
945 $value = $add_attrs[$name];
946 $command= str_replace("%$name", "$value", $command);
947 }
949 if (check_command($command)){
950 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
951 $command, "Execute");
952 exec($command,$arr);
953 foreach($arr as $str){
954 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
955 $command, "Result: ".$str);
956 }
957 } else {
958 $message= msgPool::cmdnotfound($type, get_class($this));
959 msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
960 }
961 }
962 }
964 function is_modal_dialog()
965 {
966 return(is_object($this->tabObject) || is_object($this->dialogObject));
967 }
970 /*! \brief Forward command execution request
971 * to the correct method.
972 */
973 function handle_post_events($mode, $addAttrs= array())
974 {
975 if(!in_array($mode, array('add','remove','modify'))){
976 trigger_error(sprintf("Invalid post event type given '%s'! Valid types are [add,modify,remove].", $mode));
977 return;
978 }
979 switch ($mode){
980 case "add":
981 plugin::callHook($this,"POSTCREATE", $addAttrs);
982 break;
984 case "modify":
985 plugin::callHook($this,"POSTMODIFY", $addAttrs);
986 break;
988 case "remove":
989 plugin::callHook($this,"POSTREMOVE", $addAttrs);
990 break;
991 }
992 }
993 }
995 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
996 ?>