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