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