summaryrefslogtreecommitdiff
path: root/common.pl
blob: 54e452917967c2913cedf553e50874bdc2a17f1b (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. exit;
  30. }
  31. $form->error($locale->text("Invalid Redirect"))
  32. unless first {$_ eq $script} @{LedgerSMB::Sysconfig::scripts};
  33. $oldform = $form;
  34. require "bin/$script";
  35. $form = new Form($argv);
  36. for (@common_attrs){
  37. $form->{$_} = $oldform->{$_};
  38. }
  39. if (!$myconfig){ # needed for login
  40. %myconfig = %{LedgerSMB::User->fetch_config($form->{login})};
  41. }
  42. if (!$form->{dbh}){
  43. $form->db_init(\%myconfig);
  44. }
  45. &{$form->{action}};
  46. }
  47. 1;