summaryrefslogtreecommitdiff
path: root/common.pl
blob: ac104f829327e0c63bd6624800640e2670cea549 (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 =
  27. qw(dbh login favicon stylesheet titlebar password
  28. );
  29. if (!$script){ # http redirect to login.pl if called w/no args
  30. print "Location: login.pl\n";
  31. print "Content-type: text/html\n\n";
  32. exit;
  33. }
  34. $form->error($locale->text(__FILE__.':'.__LINE__.':'.$script.':'."Invalid Redirect"))
  35. unless first {$_ eq $script} @{LedgerSMB::Sysconfig::scripts};
  36. $oldform = $form;
  37. require "bin/$script";
  38. $form = new Form($argv);
  39. for (@common_attrs){
  40. $form->{$_} = $oldform->{$_};
  41. }
  42. if (!$myconfig){ # needed for login
  43. %myconfig = %{LedgerSMB::User->fetch_config($form->{login})};
  44. }
  45. if (!$form->{dbh}){
  46. $form->db_init(\%myconfig);
  47. }
  48. &{$form->{action}};
  49. }
  50. 1;