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