summaryrefslogtreecommitdiff
path: root/common.pl
blob: 3435318d0b8c72196d3552cfcb1d0fe003c0f5cd (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($locale->text(__FILE__.':'.__LINE__.':'.$script.':'."Invalid Redirect"))
  33. unless first {$_ eq $script} @{LedgerSMB::Sysconfig::scripts};
  34. my %temphash;
  35. for (@common_attrs){
  36. $temphash{$_} = $form->{$_};
  37. }
  38. undef $form;
  39. $form = new Form($argv);
  40. require "bin/$script";
  41. for (@common_attrs){
  42. $form->{$_} = $temphash{$_};
  43. }
  44. $form->{script} = $script;
  45. if (!$myconfig){ # needed for login
  46. %myconfig = %{LedgerSMB::User->fetch_config($form->{login})};
  47. }
  48. if (!$form->{dbh} and ($script ne 'admin.pl')){
  49. $form->db_init(\%myconfig);
  50. }
  51. &{$form->{action}};
  52. }
  53. 1;