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