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