summaryrefslogtreecommitdiff
path: root/lsmb-request.pl
blob: 85a6a5e21b75c464c4aefa8f64ecc7fb68cb3961 (plain)
  1. #!/usr/bin/perl
  2. =head1 NAME
  3. The LedgerSMB Request Handler
  4. =head1 SYNOPSYS
  5. This file receives the web request, instantiates the proper objects, and passes
  6. execution off to the appropriate workflow scripts. This is for use with new
  7. code only and should not be used with old SQL-Ledger(TM) code as it is
  8. architecturally dissimilar.
  9. =head1 COPYRIGHT
  10. Copyright (C) 2007 The LedgerSMB Core Team
  11. This file is licensed under the GNU General Public License (GPL) version 2 or
  12. at your option any later version. A copy of the GNU GPL has been included with
  13. this software.
  14. =cut
  15. package LedgerSMB::Handler;
  16. use LedgerSMB::Sysconfig;
  17. use Digest::MD5;
  18. use Error qw(:try);
  19. $| = 1;
  20. use LedgerSMB::User;
  21. use LedgerSMB;
  22. use LedgerSMB::Locale;
  23. use Data::Dumper;
  24. # for custom preprocessing logic
  25. eval { require "custom.pl"; };
  26. $request = new LedgerSMB;
  27. $request->{action} = '__default' if (!$request->{action});
  28. $ENV{SCRIPT_NAME} =~ m/([^\/\\]*.pl)\?*.*$/;
  29. $script = $1;
  30. $locale = LedgerSMB::Locale->get_handle( ${LedgerSMB::Sysconfig::language} )
  31. or $request->error( __FILE__ . ':' . __LINE__ . ": Locale not loaded: $!\n" );
  32. if (!$script){
  33. $request->error($locale->text('No workflow script specified'));
  34. }
  35. &call_script( $script, $request );
  36. sub call_script {
  37. my $script = shift @_;
  38. my $request = shift @_;
  39. $request->{script} = $script;
  40. eval { require "scripts/$script" }
  41. || $request->error($locale->text('Unable to open script') . ": scripts/$script : $!");
  42. $script =~ s/\.pl$//;
  43. $script = "LedgerSMB::Scripts::$script";
  44. $request->{_script_handle} = $script;
  45. $script->can($request->{action})
  46. || $request->error($locale->text("Action Not Defined: ") . $request->{action});
  47. $script->can( $request->{action} )->($request);
  48. }
  49. 1;