summaryrefslogtreecommitdiff
path: root/common.pl
blob: 71026b0a308179e79c80668b7505e5f6e17e8b64 (plain)
  1. #
  2. ######################################################################
  3. # LedgerSMB Accounting and ERP
  4. # http://www.ledgersmb.org/
  5. #
  6. # Copyright (C) 2006
  7. # This work contains copyrighted information from a number of sources all used
  8. # with permission.
  9. #
  10. # This file contains source code included with or based on SQL-Ledger which
  11. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  12. # under the GNU General Public License version 2 or, at your option, any later
  13. # version. For a full list including contact information of contributors,
  14. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  15. #
  16. #####################################################################
  17. #
  18. # Common script handling routines for menu.pl, admin.pl, login.pl
  19. #
  20. #####################################################################
  21. use LedgerSMB::Sysconfig;
  22. sub redirect {
  23. use List::Util qw(first);
  24. my ( $script, $argv ) = split( /\?/, $form->{callback} );
  25. my @common_attrs = qw(
  26. dbh login favicon stylesheet titlebar password custom_db_fields
  27. );
  28. if ( !$script ) { # http redirect to login.pl if called w/no args
  29. print "Location: login.pl\n";
  30. print "Content-type: text/html\n\n";
  31. exit;
  32. }
  33. $form->error(
  34. $locale->text(
  35. __FILE__ . ':' . __LINE__ . ':' . $script . ':' . "Invalid Redirect"
  36. )
  37. ) unless first { $_ eq $script } @{LedgerSMB::Sysconfig::scripts};
  38. my %temphash;
  39. for (@common_attrs) {
  40. $temphash{$_} = $form->{$_};
  41. }
  42. undef $form;
  43. $form = new Form($argv);
  44. require "bin/$script";
  45. for (@common_attrs) {
  46. $form->{$_} = $temphash{$_};
  47. }
  48. $form->{script} = $script;
  49. if ( !$myconfig ) { # needed for login
  50. %myconfig = %{ LedgerSMB::User->fetch_config( $form->{login} ) };
  51. }
  52. if ( !$form->{dbh} and ( $script ne 'admin.pl' ) ) {
  53. $form->db_init( \%myconfig );
  54. }
  55. &{ $form->{action} };
  56. }
  57. 1;