summaryrefslogtreecommitdiff
path: root/common.pl
blob: 78d2b510a59a8ead23c6190e079fb1d897806d67 (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 vc
  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. for (@common_attrs) {
  45. $form->{$_} = $temphash{$_};
  46. }
  47. $form->{script} = $script;
  48. if ( !%myconfig ) { # needed for login
  49. %myconfig = %{ LedgerSMB::User->fetch_config( $form ) };
  50. }
  51. if ( !$form->{dbh} and ( $script ne 'admin.pl' ) ) {
  52. $form->db_init( \%myconfig );
  53. }
  54. require "bin/$script";
  55. &{ $form->{action} };
  56. }
  57. 1;