summaryrefslogtreecommitdiff
path: root/common.pl
blob: bc227697130dde4801f221d5417b26f8c3c13e1d (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. 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. $oldform = $form;
  35. require "bin/$script";
  36. $form = new Form($argv);
  37. for (@common_attrs){
  38. $form->{$_} = $oldform->{$_};
  39. }
  40. if (!$myconfig){ # needed for login
  41. %myconfig = %{LedgerSMB::User->fetch_config($form->{login})};
  42. }
  43. if (!$form->{dbh}){
  44. $form->db_init(\%myconfig);
  45. }
  46. &{$form->{action}};
  47. }
  48. 1;