summaryrefslogtreecommitdiff
path: root/scripts/menu.pl
blob: 6836c1b4dc147559f98375b88c0f9325019dc737 (plain)
  1. #!/usr/bin/perl
  2. # This file is copyright (C) 2007the LedgerSMB core team and licensed under
  3. # the GNU General Public License. For more information please see the included
  4. # LICENSE and COPYRIGHT files
  5. package LedgerSMB::Scripts::menu;
  6. our $VERSION = '0.1';
  7. $menufile = "menu.ini";
  8. use LedgerSMB::Menu;
  9. use LedgerSMB::Template;
  10. use strict;
  11. sub display {
  12. my ($request) = @_;
  13. my $template;
  14. if (!$request->{menubar}){
  15. $request->{main} = "splash.html" if $request->{main} eq 'company_logo';
  16. $request->{main} = "am.pl?action=recurring_transactions"
  17. if $request->{main} eq 'recurring_transactions';
  18. $template = LedgerSMB::Template->new(
  19. user =>$request->{_user},
  20. locale => $request->{_locale},
  21. path => 'UI',
  22. template => 'frameset',
  23. format => 'HTML'
  24. );
  25. } else {
  26. # TODO: Create Lynx Initial Menu
  27. }
  28. $template->render($request);
  29. }
  30. sub expanding_menu {
  31. my ($request) = @_;
  32. my $menu = new LedgerSMB::Menu(
  33. {files => ['menu.ini'], user => $request->{_user}}
  34. );
  35. my $template = LedgerSMB::Template->new(
  36. user => $request->{_user},
  37. locale => $request->{_locale},
  38. path => 'UI',
  39. template => 'menu_expand',
  40. format => 'HTML',
  41. );
  42. $request->{subs} = [];
  43. _attach_references({source => $menu, dest => $request->{subs}, path => ""});
  44. $menu->debug({file => '/tmp/debug-menu'});
  45. $request->debug({file => '/tmp/debug'});
  46. $template->render($request);
  47. }
  48. sub _attach_references {
  49. no strict qw(refs);
  50. my ($args) = @_;
  51. my ($source, $dest, $path)
  52. = ($args->{source}, $args->{dest}, $args->{path});
  53. my %hash;
  54. if ($path and $source->{id}){
  55. for (sort keys %$source){
  56. next if $_ eq 'subs';
  57. $hash{$_} = $source->{$_};
  58. }
  59. $hash{path} = $path;
  60. push @{$dest}, \%hash;
  61. foreach (sort keys %{$source->{subs}}) {
  62. _attach_references({
  63. source => $source->{subs}->{$_},
  64. dest => $dest,
  65. path => "$path--$_",
  66. });
  67. }
  68. } else {
  69. foreach (sort keys %$source){
  70. _attach_references({
  71. source => $source->{$_},
  72. dest => $dest,
  73. path => "$_",
  74. });
  75. }
  76. }
  77. }
  78. 1;