summaryrefslogtreecommitdiff
path: root/LedgerSMB/Menu.pm
blob: d6ce2053c8dc26d9418d255582d2118d84408794 (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 $style;
  46. if ($form->{menubar}){
  47. $style = "";
  48. } else {
  49. $style = "display:block;";
  50. }
  51. my $str = qq|<a style="$style"|.
  52. qq|href="$module?path=$form->{path}&amp;action=$action&amp;|.
  53. qq|level=$level&amp;login=$form->{login}&amp;|.
  54. qq|timeout=$form->{timeout}&amp;sessionid=$form->{sessionid}|.
  55. qq|&amp;js=$form->{js}|;
  56. my @vars = qw(module action target href);
  57. if ($self->{$item}{href}) {
  58. $str = qq|<a href="$self->{$item}{href}|;
  59. @vars = qw(module target href);
  60. }
  61. for (@vars) { delete $self->{$item}{$_} }
  62. delete $self->{$item}{submenu};
  63. # add other params
  64. foreach my $key (keys %{ $self->{$item} }) {
  65. $str .= "&amp;".$form->escape($key)."=";
  66. ($value, $conf) = split /=/, $self->{$item}{$key}, 2;
  67. $value = "$myconfig->{$value}$conf"
  68. if $self->{$item}{$key} =~ /=/;
  69. $str .= $form->escape($value);
  70. }
  71. $str .= qq|#id$form->{tag}| if $target eq 'acc_menu';
  72. if ($target) {
  73. $str .= qq|" target="$target"|;
  74. }
  75. else{
  76. $str .= '"';
  77. }
  78. $str .= qq|>|;
  79. }
  80. sub access_control {
  81. my ($self, $myconfig, $menulevel) = @_;
  82. my @menu = ();
  83. if ($menulevel eq "") {
  84. @menu = grep { !/--/ } @{ $self->{ORDER} };
  85. } else {
  86. @menu = grep { /^${menulevel}--/; } @{ $self->{ORDER} };
  87. }
  88. my @a = split /;/, $myconfig->{acs};
  89. my $excl = ();
  90. # remove --AR, --AP from array
  91. grep { ($a, $b) = split /--/; s/--$a$//; } @a;
  92. for (@a) { $excl{$_} = 1 }
  93. @a = ();
  94. for (@menu) { push @a, $_ unless $excl{$_} }
  95. @a;
  96. }
  97. 1;