summaryrefslogtreecommitdiff
path: root/LedgerSMB/Menu.pm
blob: f61db708b99412eb11cab19eeb3fc610e968cf9d (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 NOT 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}) ? $self->{$item}{module} : $form->{script};
  39. my $action = ($self->{$item}{action}) ? $self->{$item}{action} : "section_menu";
  40. my $target = ($self->{$item}{target}) ? $self->{$item}{target} : "";
  41. my $level = $form->escape($item);
  42. 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}|;
  43. my @vars = qw(module action target href);
  44. if ($self->{$item}{href}) {
  45. $str = qq|<a href="$self->{$item}{href}|;
  46. @vars = qw(module target href);
  47. }
  48. for (@vars) { delete $self->{$item}{$_} }
  49. delete $self->{$item}{submenu};
  50. # add other params
  51. foreach my $key (keys %{ $self->{$item} }) {
  52. $str .= "&amp;".$form->escape($key)."=";
  53. ($value, $conf) = split /=/, $self->{$item}{$key}, 2;
  54. $value = "$myconfig->{$value}$conf" if $self->{$item}{$key} =~ /=/;
  55. $str .= $form->escape($value);
  56. }
  57. $str .= qq|#id$form->{tag}| if $target eq 'acc_menu';
  58. if ($target) {
  59. $str .= qq|" target="$target"|;
  60. }
  61. else{
  62. $str .= '"';
  63. }
  64. $str .= qq|>|;
  65. }
  66. sub access_control {
  67. my ($self, $myconfig, $menulevel) = @_;
  68. my @menu = ();
  69. if ($menulevel eq "") {
  70. @menu = grep { !/--/ } @{ $self->{ORDER} };
  71. } else {
  72. @menu = grep { /^${menulevel}--/; } @{ $self->{ORDER} };
  73. }
  74. my @a = split /;/, $myconfig->{acs};
  75. my $excl = ();
  76. # remove --AR, --AP from array
  77. grep { ($a, $b) = split /--/; s/--$a$//; } @a;
  78. for (@a) { $excl{$_} = 1 }
  79. @a = ();
  80. for (@menu) { push @a, $_ unless $excl{$_} }
  81. @a;
  82. }
  83. 1;