summaryrefslogtreecommitdiff
path: root/common.pl
blob: b93b20e902effe6eed1678dba2a648816a145649 (plain)
  1. #!c:\vanilla-perl\perl\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(
  27. dbh login favicon stylesheet titlebar password custom_db_fields
  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. my %temphash;
  37. for (@common_attrs){
  38. $temphash{$_} = $form->{$_};
  39. }
  40. require "bin/$script";
  41. undef $form;
  42. $form = new Form($argv);
  43. for (@common_attrs){
  44. $form->{$_} = $temphash{$_};
  45. }
  46. if (!$myconfig){ # needed for login
  47. %myconfig = %{LedgerSMB::User->fetch_config($form->{login})};
  48. }
  49. if (!$form->{dbh}){
  50. $form->db_init(\%myconfig);
  51. }
  52. &{$form->{action}};
  53. }
  54. 1;