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