summaryrefslogtreecommitdiff
path: root/bin/menu.pl
blob: a64d1e44cbdcdc2b9aa5d6ad177ce39a6289b1e2 (plain)
  1. #=====================================================================
  2. # LedgerSMB
  3. # Small Medium Business Accounting software
  4. # http://www.ledgersmb.org/
  5. #
  6. #
  7. # See COPYRIGHT file for copyright information
  8. #======================================================================
  9. #
  10. # This file has undergone whitespace cleanup.
  11. #
  12. #======================================================================
  13. #
  14. # two frame layout with refractured menu
  15. #
  16. #######################################################################
  17. $menufile = "menu.ini";
  18. use LedgerSMB::Menu;
  19. 1;
  20. # end of main
  21. sub display {
  22. if ( $form->{lynx} ) {
  23. $menu = new Menu "$menufile";
  24. $menu->add_file("custom_$menufile") if -f "custom_$menufile";
  25. $menu->add_file("$form->{login}_$menufile")
  26. if -f "$form->{login}_$menufile";
  27. @menuorder = $menu->access_control( \%myconfig );
  28. $form->{title} = "LedgerSMB $form->{version}";
  29. $form->header(1);
  30. $offset = int( 21 - $#menuorder ) / 2;
  31. print "<pre>";
  32. print "\n" x $offset;
  33. print "</pre>";
  34. print qq|<center><table>|;
  35. map {
  36. print "<tr><td>"
  37. . $menu->menuitem( \%myconfig, \%$form, $_ )
  38. . $locale->text($_)
  39. . qq|</a></td></tr>|;
  40. } @menuorder;
  41. print qq'</table></body></html>';
  42. }
  43. else {
  44. $menuwidth = ( $ENV{HTTP_USER_AGENT} =~ /links/i ) ? "240" : "155";
  45. $menuwidth = $myconfig{menuwidth} if $myconfig{menuwidth};
  46. $form->header( !$form->{duplicate} );
  47. print qq|
  48. <frameset cols="$menuwidth,*" border="1">
  49. <frame name="acc_menu" src="menu.pl?login=$form->{login}&amp;sessionid=$form->{sessionid}&amp;action=acc_menu&amp;path=$form->{path}&amp;js=$form->{js}" />
  50. <frame name="main_window" src="locale/html/splash.html" />
  51. </frameset>
  52. </html>
  53. |;
  54. }
  55. }
  56. sub acc_menu {
  57. if ( $form->{lynx} ) {
  58. &section_menu;
  59. }
  60. else {
  61. my $menu = new Menu "$menufile";
  62. $menu->add_file("custom_$menufile") if -f "custom_$menufile";
  63. $menu->add_file("$form->{login}_$menufile")
  64. if -f "$form->{login}_$menufile";
  65. $form->{title} = $locale->text('Accounting Menu');
  66. my $headeradd = q|
  67. <script type="text/javascript">
  68. function SwitchMenu(obj) {
  69. if (document.getElementById) {
  70. var el = document.getElementById(obj);
  71. if (el.style.display == "none") {
  72. el.style.display = "block"; //display the block of info
  73. } else {
  74. el.style.display = "none";
  75. }
  76. }
  77. }
  78. function ChangeClass(menu, newClass) {
  79. if (document.getElementById) {
  80. document.getElementById(menu).className = newClass;
  81. }
  82. }
  83. document.onselectstart = new Function("return false");
  84. </script>|;
  85. $form->header( undef, $headeradd );
  86. print q|
  87. <body class="menu">
  88. <img class="cornderlogo" src="ledger-smb_small.png" width="100" height="50" border="1" alt="ledger-smb" />
  89. |;
  90. if ( $form->{js} ) {
  91. &js_menu($menu);
  92. }
  93. else {
  94. &section_menu($menu);
  95. }
  96. print q|
  97. </body>
  98. </html>
  99. |;
  100. }
  101. }
  102. sub section_menu {
  103. if ( $form->{lynx} ) {
  104. $menu = new Menu "$menufile", $form->{level};
  105. $menu->add_file("custom_$menufile") if -f "custom_$menufile";
  106. $menu->add_file("$form->{login}_$menufile")
  107. if -f "$form->{login}_$menufile";
  108. # build tiered menus
  109. @menuorder = $menu->access_control( \%myconfig, $form->{level} );
  110. foreach $item (@menuorder) {
  111. $a = $item;
  112. $item =~ s/^$form->{level}--//;
  113. push @neworder, $a unless ( $item =~ /--/ );
  114. }
  115. @menuorder = @neworder;
  116. $level = $form->{level};
  117. $level =~ s/--/ /g;
  118. $form->{title} = $locale->text($level);
  119. $form->header;
  120. $offset = int( 21 - $#menuorder ) / 2;
  121. print "<pre>";
  122. print "\n" x $offset;
  123. print "</pre>";
  124. print qq|<center><table>|;
  125. foreach $item (@menuorder) {
  126. $label = $item;
  127. $label =~ s/$form->{level}--//g;
  128. # remove target
  129. $menu->{$item}{target} = "";
  130. print "<tr><td>"
  131. . $menu->menuitem( \%myconfig, \%$form, $item, $form->{level} )
  132. . $locale->text($label)
  133. . "</a></td></tr>";
  134. }
  135. print qq'</table></body></html>';
  136. }
  137. else {
  138. my ( $menu, $level ) = @_;
  139. # build tiered menus
  140. my @menuorder = $menu->access_control( \%myconfig, $level );
  141. while (@menuorder) {
  142. $item = shift @menuorder;
  143. $label = $item;
  144. $label =~ s/$level--//g;
  145. my $spacer = "&nbsp;" x ( ( $item =~ s/--/--/g ) * 2 );
  146. $label =~ s/.*--//g;
  147. $label = $locale->text($label);
  148. $label =~ s/ /&nbsp;/g if $label !~ /<img /i;
  149. $menu->{$item}{target} = "main_window"
  150. unless $menu->{$item}{target};
  151. if ( $menu->{$item}{submenu} ) {
  152. $menu->{$item}{$item} = !$form->{$item};
  153. if ( $form->{level} && $item =~ $form->{level} ) {
  154. # expand menu
  155. print qq|<br />\n$spacer|
  156. . $menu->menuitem( \%myconfig, \%$form, $item, $level )
  157. . qq|$label</a>|;
  158. # remove same level items
  159. map { shift @menuorder } grep /^$item/, @menuorder;
  160. &section_menu( $menu, $item );
  161. print qq|<br />\n|;
  162. }
  163. else {
  164. print qq|<br />\n$spacer|
  165. . $menu->menuitem( \%myconfig, \%$form, $item, $level )
  166. . qq|$label&nbsp;...</a>|;
  167. # remove same level items
  168. map { shift @menuorder } grep /^$item/, @menuorder;
  169. }
  170. }
  171. else {
  172. if ( $menu->{$item}{module} ) {
  173. print qq|<br />\n$spacer|
  174. . $menu->menuitem( \%myconfig, \%$form, $item, $level )
  175. . qq|$label</a>|;
  176. }
  177. else {
  178. $form->{tag}++;
  179. print qq|<a name="id$form->{tag}"></a><p><b>$label</b></p>|;
  180. &section_menu( $menu, $item );
  181. print qq|<br />\n|;
  182. }
  183. }
  184. }
  185. }
  186. }
  187. sub js_menu {
  188. my ( $menu, $level ) = @_;
  189. print qq| <div id="div_$menu_$level"> |;
  190. # build tiered menus
  191. my @menuorder = $menu->access_control( \%myconfig, $level );
  192. while (@menuorder) {
  193. $i++;
  194. $item = shift @menuorder;
  195. $label = $item;
  196. $label =~ s/.*--//g;
  197. $label = $locale->text($label);
  198. $menu->{$item}{target} = "main_window" unless $menu->{$item}{target};
  199. if ( $menu->{$item}{submenu} ) {
  200. $display = "display: none;" unless $level eq ' ';
  201. print qq|
  202. <div id="menu$i" class="menuOut" onclick="SwitchMenu('sub$i')" onmouseover="ChangeClass('menu$i','menuOver')" onmouseout="ChangeClass('menu$i','menuOut')">$label</div>
  203. <div class="submenu" id="sub$i" style="$display">|;
  204. # remove same level items
  205. map { shift @menuorder } grep /^$item/, @menuorder;
  206. &js_menu( $menu, $item );
  207. print qq|
  208. </div>
  209. |;
  210. }
  211. else {
  212. if ( $menu->{$item}{module} ) {
  213. if ( $level eq "" ) {
  214. print
  215. qq|<div id="menu$i" class="menuOut" onmouseover="ChangeClass('menu$i','menuOver')" onmouseout="ChangeClass('menu$i','menuOut')"> |
  216. . $menu->menuitem( \%myconfig, \%$form, $item, $level )
  217. . qq|$label</a></div>|;
  218. # remove same level items
  219. map { shift @menuorder } grep /^$item/, @menuorder;
  220. &js_menu( $menu, $item );
  221. }
  222. else {
  223. print qq|<div class="submenu"> |
  224. . $menu->menuitem( \%myconfig, \%$form, $item, $level )
  225. . qq|$label</a></div>|;
  226. }
  227. }
  228. else {
  229. $display = "display: none;" unless $item eq ' ';
  230. print qq|
  231. <div id="menu$i" class="menuOut" onclick="SwitchMenu('sub$i')" onmouseover="ChangeClass('menu$i','menuOver')" onmouseout="ChangeClass('menu$i','menuOut')">$label</div>
  232. <div class="submenu" id="sub$i" style="$display">|;
  233. &js_menu( $menu, $item );
  234. print qq| </div> |;
  235. }
  236. }
  237. }
  238. print qq| </div> |;
  239. }
  240. sub menubar {
  241. if ( $form->{lynx} ) {
  242. $menu = new Menu "$menufile", "";
  243. # build menubar
  244. @menuorder = $menu->access_control( \%myconfig, "" );
  245. @neworder = ();
  246. map { push @neworder, $_ unless ( $_ =~ /--/ ) } @menuorder;
  247. @menuorder = @neworder;
  248. print "<p>";
  249. $form->{script} = "menu.pl";
  250. print "| ";
  251. foreach $item (@menuorder) {
  252. $label = $item;
  253. # remove target
  254. $menu->{$item}{target} = "";
  255. print $menu->menuitem( \%myconfig, \%$form, $item, "" )
  256. . $locale->text($label)
  257. . "</a> | ";
  258. }
  259. }
  260. else {
  261. 1;
  262. }
  263. }