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