summaryrefslogtreecommitdiff
path: root/LedgerSMB/Menu.pm
blob: 723149fd72b3173194c27eec04597433bfb5d466 (plain)
  1. #=====================================================================
  2. # LedgerSMB
  3. # Small Medium Business Accounting software
  4. #
  5. # See COPYRIGHT file for copyright information
  6. #======================================================================
  7. #
  8. # This file has NOT undergone whitespace cleanup.
  9. #
  10. #======================================================================
  11. #
  12. # routines for menu items
  13. #
  14. #=====================================================================
  15. package Menu;
  16. use LedgerSMB::Inifile;
  17. @ISA = qw/Inifile/;
  18. sub menuitem {
  19. my ($self, $myconfig, $form, $item) = @_;
  20. my $module = ($self->{$item}{module}) ? $self->{$item}{module} : $form->{script};
  21. my $action = ($self->{$item}{action}) ? $self->{$item}{action} : "section_menu";
  22. my $target = ($self->{$item}{target}) ? $self->{$item}{target} : "";
  23. my $level = $form->escape($item);
  24. my $str = qq|<a style="display:block;" href="$module?path=$form->{path}&action=$action&level=$level&login=$form->{login}&timeout=$form->{timeout}&sessionid=$form->{sessionid}&js=$form->{js}|;
  25. my @vars = qw(module action target href);
  26. if ($self->{$item}{href}) {
  27. $str = qq|<a href="$self->{$item}{href}|;
  28. @vars = qw(module target href);
  29. }
  30. for (@vars) { delete $self->{$item}{$_} }
  31. delete $self->{$item}{submenu};
  32. # add other params
  33. foreach my $key (keys %{ $self->{$item} }) {
  34. $str .= "&".$form->escape($key)."=";
  35. ($value, $conf) = split /=/, $self->{$item}{$key}, 2;
  36. $value = "$myconfig->{$value}$conf" if $self->{$item}{$key} =~ /=/;
  37. $str .= $form->escape($value);
  38. }
  39. $str .= qq|#id$form->{tag}| if $target eq 'acc_menu';
  40. if ($target) {
  41. $str .= qq|" target="$target"|;
  42. }
  43. $str .= qq|>|;
  44. }
  45. sub access_control {
  46. my ($self, $myconfig, $menulevel) = @_;
  47. my @menu = ();
  48. if ($menulevel eq "") {
  49. @menu = grep { !/--/ } @{ $self->{ORDER} };
  50. } else {
  51. @menu = grep { /^${menulevel}--/; } @{ $self->{ORDER} };
  52. }
  53. my @a = split /;/, $myconfig->{acs};
  54. my $excl = ();
  55. # remove --AR, --AP from array
  56. grep { ($a, $b) = split /--/; s/--$a$//; } @a;
  57. for (@a) { $excl{$_} = 1 }
  58. @a = ();
  59. for (@menu) { push @a, $_ unless $excl{$_} }
  60. @a;
  61. }
  62. 1;