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