bd24cc5ec3b219e6b3293c61dad64452286be8d9
1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class management
24 {
25 // Public
26 public $config = null;
27 public $ui = null;
29 // The plugin description
30 public $plugname = "unconfigured";
31 public $plIcon = "unconfigured";
32 public $plDescription = "unconfigured";
33 public $plHeadline = "unconfigured";
35 // The currently used object(s) (e.g. in edit, removal)
36 public $dn = ""; // this is public due to some compatibility problems with class plugin..
37 protected $dns = array();
39 // The last used object(s).
40 protected $last_dn = "";
41 protected $last_dns = array();
43 // The common places the displayed objects are stored in. (e.g. array("ou=groups,",".."))
44 protected $storagePoints = array();
46 // The tab definitions to use for the current object.
47 protected $tabClass = ""; // e.g. usertabs
48 protected $tabType = ""; // e.g. USERTABS
49 protected $aclPlugin = ""; // e.g. generic
50 protected $aclCategory = ""; // e.g. users
51 protected $objectName = ""; // e.g. users
53 // The opened object.
54 protected $tabObject = null;
55 protected $dialogObject = null;
57 // The last opened object.
58 protected $last_tabObject = null;
59 protected $last_dialogObject = null;
61 // Whether to display the apply button or not
62 protected $displayApplyBtn = FALSE;
64 // Whether to display a header or not.
65 protected $skipHeader = false;
67 // Whether to display a footer or not.
68 protected $skipFooter = false;
70 // Copy&Paste handler
71 protected $cpHandler = null;
73 // Indicates that we want to paste objects right now.
74 protected $cpPastingStarted = FALSE;
76 // The Snapshot handler class.
77 protected $snapHandler = null;
79 // The listing handlers
80 private $headpage = null;
81 private $filter = null;
83 // A list of configured actions/events
84 protected $actions = array();
86 // Attributes managed by this plugin, can be used in post events;
87 public $attributes = array();
89 function __construct(&$config,$ui,$plugname, $headpage)
90 {
91 $this->plugname = $plugname;
92 $this->headpage = $headpage;
93 $this->ui = $ui;
94 $this->config = $config;
96 if($this->cpHandler) $this->headpage->setCopyPasteHandler($this->cpHandler);
97 if($this->snapHandler) $this->headpage->setSnapshotHandler($this->snapHandler);
99 if(empty($this->plIcon)){
100 $this->plIcon = "plugins/".$plugname."/images/plugin.png";
101 }
103 // Register default actions
104 $this->registerAction("new", "newEntry");
105 $this->registerAction("edit", "editEntry");
106 $this->registerAction("apply", "applyChanges");
107 $this->registerAction("save", "saveChanges");
108 $this->registerAction("cancel", "cancelEdit");
109 $this->registerAction("cancelDelete", "cancelEdit");
110 $this->registerAction("remove", "removeEntryRequested");
111 $this->registerAction("removeConfirmed", "removeEntryConfirmed");
113 $this->registerAction("copy", "copyPasteHandler");
114 $this->registerAction("cut", "copyPasteHandler");
115 $this->registerAction("paste", "copyPasteHandler");
117 $this->registerAction("snapshot", "createSnapshotDialog");
118 $this->registerAction("restore", "restoreSnapshotDialog");
119 $this->registerAction("saveSnapshot","saveSnapshot");
120 $this->registerAction("restoreSnapshot","restoreSnapshot");
121 $this->registerAction("cancelSnapshot","closeDialogs");
122 }
124 /*! \brief Execute this plugin
125 * Handle actions/events, locking, snapshots, dialogs, tabs,...
126 */
127 function execute()
128 {
129 // Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog.
130 $vars = array('/^act$/','/^listing/','/^PID$/','/^FILTER_PID$/');
131 session::set('LOCK_VARS_TO_USE',$vars);
133 /* Display the copy & paste dialog, if it is currently open */
134 $ret = $this->copyPasteHandler("",array());
135 if($ret){
136 return($this->getHeader().$ret);
137 }
139 // Update filter
140 if ($this->filter) {
141 $this->filter->update();
142 session::global_set(get_class($this)."_filter", $this->filter);
143 session::set('autocomplete', $this->filter);
144 }
146 // Handle actions (POSTs and GETs)
147 $str = $this->handleActions($this->detectPostActions());
148 if($str) return($this->getHeader().$str);
150 // Open single dialog objects
151 if(is_object($this->dialogObject)){
152 if(method_exists($this->dialogObject,'save_object')) $this->dialogObject->save_object();
153 if(method_exists($this->dialogObject,'execute')){
154 $display = $this->dialogObject->execute();
155 $display.= $this->_getTabFooter();
156 return($this->getHeader().$display);
157 }
158 }
160 // Display tab object.
161 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
162 # $this->tabObject->save_object();
163 $display = $this->tabObject->execute();
164 $display.= $this->_getTabFooter();
165 return($this->getHeader().$display);
166 }
168 // Set current restore base for snapshot handling.
169 if(is_object($this->snapHandler)){
170 $bases = array();
171 foreach($this->storagePoints as $sp){
172 $bases[] = $sp.$this->headpage->getBase();
173 }
175 // No bases specified? Try base
176 if(!count($bases)) $bases[] = $this->headpage->getBase();
178 $this->snapHandler->setSnapshotBases($bases);
179 }
181 // Add a dummy filter editing button.
182 if(userFilter::userFilteringAvailable()){
183 $dummy = "<button type='submit' name='editFilter'>!!</button>";
184 $this->registerAction("editFilter", "editFilter");
185 }
187 // Display list
188 return($dummy.$this->renderList());
189 }
191 function editFilter()
192 {
193 $headpage = $this->getHeadpage();
194 $this->dialogObject = new userFilter($this->config,$headpage->categories);
195 }
197 function renderList()
198 {
199 $this->headpage->update();
200 $display = $this->headpage->render();
201 return($this->getHeader().$display);
202 }
204 function getHeadpage()
205 {
206 return($this->headpage);
207 }
209 function getFilter()
210 {
211 return($this->filter);
212 }
214 /*! \brief Generates the plugin header which is displayed whenever a tab object is
215 * opened.
216 */
217 protected function getHeader()
218 {
219 // We do not display any headers right now.
220 if(1 || $this->skipHeader) return("");
221 }
224 /*! \brief Generates the footer which is used whenever a tab object is
225 * displayed.
226 */
227 protected function _getTabFooter()
228 {
229 // Do not display tab footer for non tab objects
230 if(!($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug)){
231 return("");
232 }
234 // Check if there is a dialog opened - We don't need any buttons in this case.
235 if($this->tabObject->by_object[$this->tabObject->current]){
236 $current = $this->tabObject->by_object[$this->tabObject->current];
237 if(isset($current->dialog) && (is_object($current->dialog) || $current->dialog)){
238 return("");
239 }
240 }
242 // Skip footer if requested;
243 if($this->skipFooter) return("");
245 // In case an of locked entry, we may have opened a read-only tab.
246 $str = "";
247 if(isset($this->tabObject->read_only) && $this->tabObject->read_only == TRUE){
248 $str.= "<p style=\"text-align:right\">
249 <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
250 </p>";
251 return($str);
252 }else{
254 // Display ok, (apply) and cancel buttons
255 $str.= "<p style=\"text-align:right\">\n";
256 $str.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
257 $str.= " \n";
258 if($this->displayApplyBtn){
259 $str.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
260 $str.= " \n";
261 }
262 $str.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
263 $str.= "</p>";
264 }
265 return($str);
266 }
269 /*! \brief Initiates the removal for the given entries
270 * and displays a confirmation dialog.
271 *
272 * @param String 'action' The name of the action which was the used as trigger.
273 * @param Array 'target' A list of object dns, which should be affected by this method.
274 * @param Array 'all' A combination of both 'action' and 'target'.
275 */
276 protected function removeEntryRequested($action="",$target=array(),$all=array())
277 {
278 $disallowed = array();
279 $this->dns = array();
281 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
283 // Check permissons for each target
284 foreach($target as $dn){
285 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
286 if(preg_match("/d/",$acl)){
287 $this->dns[] = $dn;
288 }else{
289 $disallowed[] = $dn;
290 }
291 }
292 if(count($disallowed)){
293 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
294 }
296 // We've at least one entry to delete.
297 if(count($this->dns)){
299 // check locks
300 if ($user= get_multiple_locks($this->dns)){
301 return(gen_locked_message($user,$this->dns));
302 }
304 // Add locks
305 $dns_names = array();
306 foreach($this->dns as $dn){
307 $dns_names[] =LDAP::fix($dn);
308 }
309 add_lock ($this->dns, $this->ui->dn);
311 // Display confirmation dialog.
312 $smarty = get_smarty();
313 $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
314 $smarty->assign("multiple", true);
315 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
316 }
317 }
320 /*! \brief Object removal was confirmed, now remove the requested entries.
321 *
322 * @param String 'action' The name of the action which was the used as trigger.
323 * @param Array 'target' A list of object dns, which should be affected by this method.
324 * @param Array 'all' A combination of both 'action' and 'target'.
325 */
326 function removeEntryConfirmed($action="",$target=array(),$all=array(),
327 $altTabClass="",$altTabType="",$altAclCategory="")
328 {
329 $tabType = $this->tabType;
330 $tabClass = $this->tabClass;
331 $aclCategory = $this->aclCategory;
332 if(!empty($altTabClass)) $tabClass = $altTabClass;
333 if(!empty($altTabType)) $tabType = $altTabType;
334 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
336 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
338 foreach($this->dns as $key => $dn){
340 // Check permissions, are we allowed to remove this object?
341 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
342 if(preg_match("/d/",$acl)){
344 // Delete the object
345 $this->dn = $dn;
346 $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory, true, true);
347 $this->tabObject->set_acl_base($this->dn);
348 $this->tabObject->parent = &$this;
349 $this->tabObject->delete ();
351 // Remove the lock for the current object.
352 del_lock($this->dn);
353 } else {
354 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
355 new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
356 }
357 }
359 // Cleanup
360 $this->remove_lock();
361 $this->closeDialogs();
362 }
365 /*! \brief Detects actions/events send by the ui
366 * and the corresponding targets.
367 */
368 function detectPostActions()
369 {
370 if(!is_object($this->headpage)){
371 trigger_error("No valid headpage given....!");
372 return(array());
373 }
374 $action= $this->headpage->getAction();
375 if(isset($_POST['edit_apply'])) $action['action'] = "apply";
376 if(isset($_POST['edit_finish'])) $action['action'] = "save";
377 if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";
378 if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";
379 if(isset($_POST['delete_cancel'])) $action['action'] = "cancelDelete";
380 if(isset($_POST['editFilter'])) $action['action'] = "editFilter";
381 if(isset($_POST['saveFilter'])) $action['action'] = "save";
382 if(isset($_POST['cancelFilter'])) $action['action'] = "cancel";
384 // Detect Snapshot actions
385 if(isset($_POST['CreateSnapshot'])) $action['action'] = "saveSnapshot";
386 if(isset($_POST['CancelSnapshot'])) $action['action'] = "cancelSnapshot";
387 foreach($_POST as $name => $value){
388 $once =TRUE;
389 if(preg_match("/^RestoreSnapShot_/",$name) && $once){
390 $once = FALSE;
391 $entry = base64_decode(preg_replace("/^RestoreSnapShot_([^_]*)_[xy]$/i","\\1",$name));
392 $action['action'] = "restoreSnapshot";
393 $action['targets'] = array($entry);
394 }
395 }
397 return($action);
398 }
401 /*! \brief Calls the registered method for a given action/event.
402 */
403 function handleActions($action)
404 {
405 // Start action
406 if(isset($this->actions[$action['action']])){
407 $func = $this->actions[$action['action']];
408 if(!isset($action['targets']))$action['targets']= array();
409 return($this->$func($action['action'],$action['targets'],$action));
410 }
411 }
414 /*! \brief Opens the snapshot creation dialog for the given target.
415 *
416 * @param String 'action' The name of the action which was the used as trigger.
417 * @param Array 'target' A list of object dns, which should be affected by this method.
418 * @param Array 'all' A combination of both 'action' and 'target'.
419 */
420 function createSnapshotDialog($action="",$target=array(),$all=array())
421 {
422 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!");
424 foreach($target as $entry){
425 if(!empty($entry) && $this->ui->allow_snapshot_create($entry,$this->aclCategory)){
426 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
427 $this->dialogObject->aclCategories = array($this->aclCategory);
428 $this->dialogObject->parent = &$this;
430 }else{
431 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$entry),
432 ERROR_DIALOG);
433 }
434 }
435 }
438 /*! \brief Creates a snapshot new entry - This method is called when the somebody
439 * clicks 'save' in the "Create snapshot dialog" (see ::createSnapshotDialog).
440 *
441 * @param String 'action' The name of the action which was the used as trigger.
442 * @param Array 'target' A list of object dns, which should be affected by this method.
443 * @param Array 'all' A combination of both 'action' and 'target'.
444 */
445 function saveSnapshot($action="",$target=array(),$all=array())
446 {
447 if(!is_object($this->dialogObject)) return;
448 $this->dialogObject->save_object();
449 $msgs = $this->dialogObject->check();
450 if(count($msgs)){
451 foreach($msgs as $msg){
452 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
453 }
454 }else{
455 $this->dn = $this->dialogObject->dn;
456 $this->snapHandler->create_snapshot( $this->dn,$this->dialogObject->CurrentDescription);
457 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot created!");
458 $this->closeDialogs();
459 }
460 }
463 /*! \brief Restores a snapshot object.
464 * The dn of the snapshot entry has to be given as ['target'] parameter.
465 *
466 * @param String 'action' The name of the action which was the used as trigger.
467 * @param Array 'target' A list of object dns, which should be affected by this method.
468 * @param Array 'all' A combination of both 'action' and 'target'.
469 */
470 function restoreSnapshot($action="",$target=array(),$all=array())
471 {
472 $entry = array_pop($target);
473 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
474 $this->snapHandler->restore_snapshot($entry);
475 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot restored!");
476 $this->closeDialogs();
477 }else{
478 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
479 ERROR_DIALOG);
480 }
481 }
484 /*! \brief Displays the "Restore snapshot dialog" for a given target.
485 * If no target is specified, open the restore removed object
486 * dialog.
487 * @param String 'action' The name of the action which was the used as trigger.
488 * @param Array 'target' A list of object dns, which should be affected by this method.
489 * @param Array 'all' A combination of both 'action' and 'target'.
490 */
491 function restoreSnapshotDialog($action="",$target=array(),$all=array())
492 {
493 // Set current restore base for snapshot handling.
494 if(is_object($this->snapHandler)){
495 $bases = array();
496 foreach($this->storagePoints as $sp){
497 $bases[] = $sp.$this->headpage->getBase();
498 }
499 }
501 // No bases specified? Try base
502 if(!count($bases)) $bases[] = $this->headpage->getBase();
504 // No target, open the restore removed object dialog.
505 if(!count($target)){
506 $entry = $this->headpage->getBase();
507 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
508 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
509 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
510 $this->dialogObject->set_snapshot_bases($bases);
511 $this->dialogObject->display_all_removed_objects = true;
512 $this->dialogObject->display_restore_dialog = true;
513 $this->dialogObject->parent = &$this;
514 }else{
515 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
516 ERROR_DIALOG);
517 }
518 }else{
520 // Display the restore points for a given object.
521 $entry = array_pop($target);
522 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
523 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
524 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
525 $this->dialogObject->set_snapshot_bases($bases);
526 $this->dialogObject->display_restore_dialog = true;
527 $this->dialogObject->parent = &$this;
528 }else{
529 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
530 ERROR_DIALOG);
531 }
532 }
533 }
536 /*! \brief This method intiates the object creation.
537 *
538 * @param String 'action' The name of the action which was the used as trigger.
539 * @param Array 'target' A list of object dns, which should be affected by this method.
540 * @param Array 'all' A combination of both 'action' and 'target'.
541 */
542 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
543 {
544 /* To handle mutliple object types overload this method.
545 * ...
546 * registerAction('newUser', 'newEntry');
547 * registerAction('newGroup','newEntry');
548 * ...
549 *
550 * function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
551 * {
552 * switch($action){
553 * case 'newUser' : {
554 * mangement::newEntry($action,$target,$all,"usertabs","USERTABS","users");
555 * }
556 * case 'newGroup' : {
557 * mangement::newEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
558 * }
559 * }
560 * }
561 **/
562 $tabType = $this->tabType;
563 $tabClass = $this->tabClass;
564 $aclCategory = $this->aclCategory;
565 if(!empty($altTabClass)) $tabClass = $altTabClass;
566 if(!empty($altTabType)) $tabType = $altTabType;
567 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
569 // Check locking & lock entry if required
570 $this->displayApplyBtn = FALSE;
571 $this->dn = "new";
572 $this->is_new = TRUE;
573 $this->is_single_edit = FALSE;
574 $this->is_multiple_edit = FALSE;
576 set_object_info($this->dn);
578 // Open object.
579 if(empty($tabClass) || empty($tabType)){
580 // No tab type defined
581 }else{
582 if (isset($this->config->data['TABS'][$tabType])) {
583 $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
584 $this->tabObject->set_acl_base($this->headpage->getBase());
585 $this->tabObject->parent = &$this;
586 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!");
587 } else {
588 msg_dialog::display(_("Error"), sprintf(_("No tab declaration for '%s' found in your configuration file. Cannot create plugin instance!"), $tabType), ERROR_DIALOG);
589 }
590 }
591 }
594 /*! \brief This method opens an existing object or a list of existing objects to be edited.
595 *
596 *
597 * @param String 'action' The name of the action which was the used as trigger.
598 * @param Array 'target' A list of object dns, which should be affected by this method.
599 * @param Array 'all' A combination of both 'action' and 'target'.
600 */
601 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
602 {
603 /* To handle mutliple object types overload this method.
604 * ...
605 * registerAction('editUser', 'editEntry');
606 * registerAction('editGroup','editEntry');
607 * ...
608 *
609 * function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
610 * {
611 * switch($action){
612 * case 'editUser' : {
613 * mangement::editEntry($action,$target,$all,"usertabs","USERTABS","users");
614 * }
615 * case 'editGroup' : {
616 * mangement::editEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
617 * }
618 * }
619 * }
620 **/
622 // Do not create a new tabObject while there is already one opened,
623 // the user may have just pressed F5 to reload the page.
624 if(is_object($this->tabObject)){
625 return;
626 }
628 $tabType = $this->tabType;
629 $tabClass = $this->tabClass;
630 $aclCategory = $this->aclCategory;
631 if(!empty($altTabClass)) $tabClass = $altTabClass;
632 if(!empty($altTabType)) $tabType = $altTabType;
633 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
635 // Single edit - we only got one object dn.
636 if(count($target) == 1){
637 $this->displayApplyBtn = TRUE;
638 $this->is_new = FALSE;
639 $this->is_single_edit = TRUE;
640 $this->is_multiple_edit = FALSE;
642 // Get the dn of the object and creates lock
643 $this->dn = array_pop($target);
644 set_object_info($this->dn);
645 $user = get_lock($this->dn);
646 if ($user != ""){
647 return(gen_locked_message ($user, $this->dn,TRUE));
648 }
649 add_lock ($this->dn, $this->ui->dn);
651 // Open object.
652 if(empty($tabClass) || empty($tabType)){
653 trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
654 }else{
655 $tab = $tabClass;
656 $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$tabType], $this->dn,$aclCategory);
657 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Edit entry initiated!");
658 $this->tabObject->set_acl_base($this->dn);
659 $this->tabObject->parent = &$this;
660 }
661 }else{
663 // We've multiple entries to edit.
664 $this->is_new = FALSE;
665 $this->is_singel_edit = FALSE;
666 $this->is_multiple_edit = TRUE;
668 // Open multiple edit handler.
669 if(empty($tabClass) || empty($tabType)){
670 trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
671 }else{
672 $this->dns = $target;
673 $tmp = new multi_plug($this->config,$tabClass,$this->config->data['TABS'][$tabType],
674 $this->dns,$this->headpage->getBase(),$aclCategory);
676 // Check for locked entries
677 if ($tmp->entries_locked()){
678 return($tmp->display_lock_message());
679 }
681 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Edit entry initiated!");
683 // Now lock entries.
684 if($tmp->multiple_available()){
685 $tmp->lock_entries($this->ui->dn);
686 $this->tabObject = $tmp;
687 set_object_info($this->tabObject->get_object_info());
688 }
689 }
690 }
691 }
694 /*! \brief Save object modifications and closes dialogs (returns to object listing).
695 * - Calls '::check' to validate the given input.
696 * - Calls '::save' to save back object modifications (e.g. to ldap).
697 * - Calls '::remove_locks' to remove eventually created locks.
698 * - Calls '::closeDialogs' to return to the object listing.
699 */
700 protected function saveChanges()
701 {
702 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
703 $this->tabObject->save_object();
704 $msgs = $this->tabObject->check();
705 if(count($msgs)){
706 msg_dialog::displayChecks($msgs);
707 return("");
708 }else{
709 $this->tabObject->save();
710 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
711 $this->remove_lock();
712 $this->closeDialogs();
713 }
714 }elseif($this->dialogObject instanceOf plugin){
715 $this->dialogObject->save_object();
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();
725 }
726 }
727 }
730 /*! \brief Save object modifications and keep dialogs opened.
731 * - Calls '::check' to validate the given input.
732 * - Calls '::save' to save back object modifications (e.g. to ldap).
733 */
734 protected function applyChanges()
735 {
736 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
737 $this->tabObject->save_object();
738 $msgs = $this->tabObject->check();
739 if(count($msgs)){
740 msg_dialog::displayChecks($msgs);
741 return("");
742 }else{
743 $this->tabObject->save();
744 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Modifications applied!");
745 $this->tabObject->re_init();
746 }
747 }
748 }
751 /*! \brief This method closes dialogs
752 * and cleans up the cached object info and the ui.
753 */
754 protected function closeDialogs()
755 {
756 $this->last_dn = $this->dn;
757 $this->last_dns = $this->dns;
758 $this->last_tabObject = $this->tabObject;
759 $this->last_dialogObject = $this->dialogObject;
760 $this->dn = "";
761 $this->dns = array();
762 $this->tabObject = null;
763 $this->dialogObject = null;
764 $this->skipFooter = FALSE;
765 set_object_info();
766 }
769 /*! \brief Editing an object was caneled.
770 * Close dialogs/tabs and remove locks.
771 */
772 protected function cancelEdit()
773 {
774 $this->remove_lock();
775 $this->closeDialogs();
776 }
779 /*! \brief Every click in the list user interface sends an event
780 * here can we connect those events to a method.
781 * eg. ::registerEvent('new','createUser')
782 * When the action/event new is send, the method 'createUser'
783 * will be called.
784 */
785 function registerAction($action,$target)
786 {
787 $this->actions[$action] = $target;
788 }
791 /*! \brief Removes ldap object locks created by this class.
792 * Whenever an object is edited, we create locks to avoid
793 * concurrent modifications.
794 * This locks will automatically removed here.
795 */
796 function remove_lock()
797 {
798 if(!empty($this->dn) && $this->dn != "new"){
799 del_lock($this->dn);
800 }
801 if(count($this->dns)){
802 del_lock($this->dns);
803 }
804 }
807 /*! \brief This method is used to queue and process copy&paste actions.
808 * Allows to copy, cut and paste mutliple entries at once.
809 * @param String 'action' The name of the action which was the used as trigger.
810 * @param Array 'target' A list of object dns, which should be affected by this method.
811 * @param Array 'all' A combination of both 'action' and 'target'.
812 */
813 function copyPasteHandler($action="",$target=array(),$all=array(),
814 $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
815 {
816 // Return without any actions while copy&paste handler is disabled.
817 if(!is_object($this->cpHandler)) return("");
819 $tabType = $this->tabType;
820 $tabClass = $this->tabClass;
821 $aclCategory = $this->aclCategory;
822 $aclPlugin = $this->aclPlugin;
823 if(!empty($altTabClass)) $tabClass = $altTabClass;
824 if(!empty($altTabType)) $tabType = $altTabType;
825 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
826 if(!empty($altAclPlugin)) $aclPlugin = $altAclPlugin;
828 // Save user input
829 $this->cpHandler->save_object();
831 // Add entries to queue
832 if($action == "copy" || $action == "cut"){
833 $this->cpHandler->cleanup_queue();
834 foreach($target as $dn){
835 if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
836 $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this);
837 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!");
838 }
839 if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
840 $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this);
841 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!");
842 }
843 }
844 }
846 // Initiate pasting
847 if($action == "paste"){
848 $this->cpPastingStarted = TRUE;
849 }
851 // Display any c&p dialogs, eg. object modifications required before pasting.
852 if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
853 $this->cpHandler->SetVar("base",$this->headpage->getBase());
854 $data = $this->cpHandler->execute();
855 if(!empty($data)){
856 return($data);
857 }
858 }
860 // Automatically disable pasting process since there is no entry left to paste.
861 if(!$this->cpHandler->entries_queued()){
862 $this->cpPastingStarted = FALSE;
863 }
864 return("");
865 }
868 function setFilter($str) {
869 $this->filter = $str;
870 }
873 function postcreate() {
874 $this->_handlePostEvent('POSTCREATE');
875 }
876 function postmodify(){
877 $this->_handlePostEvent('POSTMODIFY');
878 }
879 function postremove(){
880 $this->_handlePostEvent('POSTREMOVE');
881 }
883 function _handlePostEvent($type)
884 {
886 /* Find postcreate entries for this class */
887 $command= $this->config->search(get_class($this), $type,array('menu', 'tabs'));
888 if ($command != ""){
890 /* Walk through attribute list */
891 foreach ($this->attributes as $attr){
892 if (!is_array($this->$attr)){
893 $add_attrs[$attr] = $this->$attr;
894 }
895 }
896 $add_attrs['dn']=$this->dn;
898 $tmp = array();
899 foreach($add_attrs as $name => $value){
900 $tmp[$name] = strlen($name);
901 }
902 arsort($tmp);
904 /* Additional attributes */
905 foreach ($tmp as $name => $len){
906 $value = $add_attrs[$name];
907 $command= str_replace("%$name", "$value", $command);
908 }
910 if (check_command($command)){
911 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
912 $command, "Execute");
913 exec($command,$arr);
914 foreach($arr as $str){
915 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
916 $command, "Result: ".$str);
917 }
918 } else {
919 $message= msgPool::cmdnotfound($type, get_class($this));
920 msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
921 }
922 }
923 }
925 function is_modal_dialog()
926 {
927 return(is_object($this->tabObject) || is_object($this->dialogObject));
928 }
931 /*! \brief Forward command execution request
932 * to the correct method.
933 */
934 function handle_post_events($mode, $addAttrs= array())
935 {
936 if(!in_array($mode, array('add','remove','modify'))){
937 trigger_error(sprintf("Invalid post event type given '%s'! Valid types are [add,modify,remove].", $mode));
938 return;
939 }
940 switch ($mode){
941 case "add":
942 plugin::callHook($this,"POSTCREATE", $addAttrs);
943 break;
945 case "modify":
946 plugin::callHook($this,"POSTMODIFY", $addAttrs);
947 break;
949 case "remove":
950 plugin::callHook($this,"POSTREMOVE", $addAttrs);
951 break;
952 }
953 }
954 }
956 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
957 ?>