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