summaryrefslogtreecommitdiff
path: root/LedgerSMB/Menu.pm
blob: 3de367b65f73bb1aee5757ea92e09885d4753055 (plain)
  1. =head1 NAME
  2. Menu Routines to handle LedgerSMB menu files and format entries for display.
  3. =head1 STATUS
  4. API I<deprecated>, data format I<deprecated>, replaced in 1.3 by
  5. LedgerSMB::Menu.
  6. =head1 SYNOPIS
  7. Routines to handle LedgerSMB menu files and conversion of menu entries into a
  8. form usable by a web browser. LedgerSMB menu files are a specific form of ini
  9. file. Subclasses LedgerSMB::Inifile.
  10. Files use both ';' and '#' to denote line comments. Any text after a line that
  11. starts with '.' (i.e. ".foo") is ignored. Menu items are denoted as [section],
  12. with the sections containing key=value pairs. The keys 'module', 'action',
  13. 'target', 'href', and 'submenu' are specially treated, while other keys are
  14. output as arguments to the destination link. Blank lines are ignored.
  15. =head2 Special key treatment
  16. =over
  17. =item action
  18. This key is deleted on menuitem calls if there is no href value.
  19. =item module
  20. This is the Perl script that the menu item will call if the href attribute is
  21. not set. This key is always deleted on a menuitem call.
  22. =item target
  23. The value given for target will be passed as the target attribute for the tag.
  24. This key is always deleted on a menuitem call.
  25. =item href
  26. When set, this key's value becomes the base URL for the menu item. This key is
  27. always deleted on a menuitem call.
  28. =item submenu
  29. This key is not displayed in output, but is deleted from the Menufile object
  30. when menuitem is called on the item.
  31. =back
  32. =head2 Value Interpolation
  33. If a value for a regular key includes an equals sign (=), values from the user's
  34. configuration are substituted into the place of the string preceding and the
  35. first encountered equals sign in the value. So a menu entry of 'apples=login='
  36. would have the substition of 'apples=$myconfig->{login}' on generation of the
  37. menu link.
  38. =head1 METHODS
  39. =over
  40. =item new ([$filename])
  41. Create a new Menu object. If a filename is specified, load the file with
  42. add_file.
  43. =item add_file ($filename)
  44. Load the contents of the specified file into the Menu object. If the file
  45. cannot be read, Form->error will be called with the failure message. Attempts
  46. to load already loaded items will result in the newer item merging with and
  47. overwriting stored data from the previous load.
  48. Menu item titles are stored as keys in the Menufile object, and a special key,
  49. ORDER maintains a list of the order in which menu items were first seen.
  50. =item menuitem ($myconfig, $form, $item)
  51. Formats the menu item for the given key $item as an HTML <a href=""> open tag.
  52. Returns the tag and deletes the module, target, href, action, and submenu
  53. attributes for the item from the Menufile object.
  54. If the menubar attribute of the passed in Form attribute is set, no style will
  55. be set for the tag, otherwise the style is set to "display:block".
  56. =item access_control ($myconfig, [$menulevel])
  57. Returns the list of menu items that can be displayed with $myconfig->{acs} at
  58. the selected menu level. $menulevel is the string corresponding to a displayed
  59. menu, such as 'AR' or 'AR--Reports'. A blank level corresponds to the top
  60. level. Merely excluding a top-level element does not exclude corresponding
  61. lower level elements, i.e. excluding 'AR' will not block 'AR--Reports'.
  62. $myconfig->{acs} is a semicolon seperated list of menu items to exclude.
  63. This is only a cosmetic form of access_control. Users can still access
  64. "disallowed" sections of the application by manually entering in the URL.
  65. =back
  66. =head1 Copyright (C) 2006, The LedgerSMB core team.
  67. #====================================================================
  68. # LedgerSMB
  69. # Small Medium Business Accounting software
  70. # http://www.ledgersmb.org/
  71. #
  72. # Copyright (C) 2006
  73. # This work contains copyrighted information from a number of sources
  74. # all used with permission.
  75. #
  76. # This file contains source code included with or based on SQL-Ledger
  77. # which is Copyright Dieter Simader and DWS Systems Inc. 2000-2005
  78. # and licensed under the GNU General Public License version 2 or, at
  79. # your option, any later version. For a full list including contact
  80. # information of contributors, maintainers, and copyright holders,
  81. # see the CONTRIBUTORS file.
  82. #
  83. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  84. # Copyright (C) 2002
  85. #
  86. # Author: DWS Systems Inc.
  87. # Web: http://www.sql-ledger.org
  88. #
  89. # Contributors:
  90. # Tony Fraser <tony@sybaspace.com>
  91. #
  92. #=====================================================================
  93. =cut
  94. package Menu;
  95. use LedgerSMB::Inifile;
  96. @ISA = qw/Inifile/;
  97. sub menuitem {
  98. my ( $self, $myconfig, $form, $item ) = @_;
  99. my $module =
  100. ( $self->{$item}{module} ) ? $self->{$item}{module} : $form->{script};
  101. my $action =
  102. ( $self->{$item}{action} ) ? $self->{$item}{action} : "section_menu";
  103. my $target = ( $self->{$item}{target} ) ? $self->{$item}{target} : "";
  104. my $level = $form->escape($item);
  105. my $style;
  106. if ( $form->{menubar} ) {
  107. $style = "";
  108. }
  109. else {
  110. $style = "display:block;";
  111. }
  112. my $str =
  113. qq|<a style="$style"|
  114. . qq|href="$module?path=$form->{path}&amp;action=$action&amp;|
  115. . qq|level=$level&amp;login=$form->{login}&amp;|
  116. . qq|timeout=$form->{timeout}&amp;sessionid=$form->{sessionid}|
  117. . qq|&amp;js=$form->{js}|;
  118. my @vars = qw(module action target href);
  119. if ( $self->{$item}{href} ) {
  120. $str = qq|<a href="$self->{$item}{href}|;
  121. @vars = qw(module target href);
  122. }
  123. for (@vars) { delete $self->{$item}{$_} }
  124. delete $self->{$item}{submenu};
  125. # add other params
  126. foreach my $key ( keys %{ $self->{$item} } ) {
  127. $str .= "&amp;" . $form->escape($key) . "=";
  128. ( $value, $conf ) = split /=/, $self->{$item}{$key}, 2;
  129. $value = "$myconfig->{$value}$conf"
  130. if $self->{$item}{$key} =~ /=/;
  131. $str .= $form->escape($value);
  132. }
  133. $str .= qq|#id$form->{tag}| if $target eq 'acc_menu';
  134. if ($target) {
  135. $str .= qq|" target="$target"|;
  136. }
  137. else {
  138. $str .= '"';
  139. }
  140. $str .= qq|>|;
  141. }
  142. sub access_control {
  143. my ( $self, $myconfig, $menulevel ) = @_;
  144. my @menu = ();
  145. if ( $menulevel eq "" ) {
  146. @menu = grep { !/--/ } @{ $self->{ORDER} };
  147. }
  148. else {
  149. @menu = grep { /^${menulevel}--/; } @{ $self->{ORDER} };
  150. }
  151. my @a = split /;/, $myconfig->{acs};
  152. my %excl = ();
  153. # remove --AR, --AP from array
  154. grep { ( $a, $b ) = split /--/; s/--$a$//; } @a;
  155. for (@a) { $excl{$_} = 1 }
  156. @a = ();
  157. for (@menu) { push @a, $_ unless $excl{$_} }
  158. @a;
  159. }
  160. 1;