summaryrefslogtreecommitdiff
path: root/LedgerSMB/Menu.pm
blob: fb8516e47ff33474674eceef6bd847b180513dbf (plain)
  1. #=====================================================================
  2. # LedgerSMB
  3. # Small Medium Business Accounting software
  4. #
  5. # Copyright (C) 2006
  6. # This work contains copyrighted information from a number of sources all used
  7. # with permission.
  8. #
  9. # This file contains source code included with or based on SQL-Ledger which
  10. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  11. # under the GNU General Public License version 2 or, at your option, any later
  12. # version. For a full list including contact information of contributors,
  13. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  14. #
  15. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  16. # Copyright (C) 2002
  17. #
  18. # Author: DWS Systems Inc.
  19. # Web: http://www.sql-ledger.org
  20. #
  21. # Contributors: Tony Fraser <tony@sybaspace.com>
  22. #
  23. #======================================================================
  24. #
  25. # This file has NOT undergone whitespace cleanup.
  26. #
  27. #======================================================================
  28. #
  29. # routines for menu items
  30. #
  31. #=====================================================================
  32. package Menu;
  33. use LedgerSMB::Inifile;
  34. @ISA = qw/Inifile/;
  35. sub menuitem {
  36. my ($self, $myconfig, $form, $item) = @_;
  37. my $module = ($self->{$item}{module}) ? $self->{$item}{module} : $form->{script};
  38. my $action = ($self->{$item}{action}) ? $self->{$item}{action} : "section_menu";
  39. my $target = ($self->{$item}{target}) ? $self->{$item}{target} : "";
  40. my $level = $form->escape($item);
  41. my $str = qq|<a style="display:block;" href="$module?path=$form->{path}&amp;action=$action&amp;level=$level&amp;login=$form->{login}&amp;timeout=$form->{timeout}&amp;sessionid=$form->{sessionid}&amp;js=$form->{js}|;
  42. my @vars = qw(module action target href);
  43. if ($self->{$item}{href}) {
  44. $str = qq|<a href="$self->{$item}{href}|;
  45. @vars = qw(module target href);
  46. }
  47. for (@vars) { delete $self->{$item}{$_} }
  48. delete $self->{$item}{submenu};
  49. # add other params
  50. foreach my $key (keys %{ $self->{$item} }) {
  51. $str .= "&amp;".$form->escape($key)."=";
  52. ($value, $conf) = split /=/, $self->{$item}{$key}, 2;
  53. $value = "$myconfig->{$value}$conf" if $self->{$item}{$key} =~ /=/;
  54. $str .= $form->escape($value);
  55. }
  56. $str .= qq|#id$form->{tag}| if $target eq 'acc_menu';
  57. if ($target) {
  58. $str .= qq|" target="$target"|;
  59. }
  60. $str .= qq|>|;
  61. }
  62. sub access_control {
  63. my ($self, $myconfig, $menulevel) = @_;
  64. my @menu = ();
  65. if ($menulevel eq "") {
  66. @menu = grep { !/--/ } @{ $self->{ORDER} };
  67. } else {
  68. @menu = grep { /^${menulevel}--/; } @{ $self->{ORDER} };
  69. }
  70. my @a = split /;/, $myconfig->{acs};
  71. my $excl = ();
  72. # remove --AR, --AP from array
  73. grep { ($a, $b) = split /--/; s/--$a$//; } @a;
  74. for (@a) { $excl{$_} = 1 }
  75. @a = ();
  76. for (@menu) { push @a, $_ unless $excl{$_} }
  77. @a;
  78. }
  79. 1;