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