import sql-ledger 2.4.4
[freeside.git] / sql-ledger / bin / js / menu.pl
1 ######################################################################
2 # SQL-Ledger Accounting
3 # Copyright (c) 2004
4 #
5 #  Author: Dieter Simader
6 #   Email: dsimader@sql-ledger.org
7 #     Web: http://www.sql-ledger.org
8 #
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #######################################################################
23
24 $menufile = "menu.ini";
25 use SL::Menu;
26
27
28 1;
29 # end of main
30
31
32 sub display {
33
34   $menuwidth = ($myconfig{menuwidth}) ? $myconfig{menuwidth} : ($ENV{HTTP_USER_AGENT} =~ /links/i) ? "240" : "155";
35
36   $form->header(1);
37
38   print qq|
39
40 <FRAMESET COLS="$menuwidth,*" BORDER="1">
41
42   <FRAME NAME="acc_menu" SRC="$form->{script}?login=$form->{login}&sessionid=$form->{sessionid}&action=acc_menu&path=$form->{path}">
43   <FRAME NAME="main_window" SRC="am.pl?login=$form->{login}&sessionid=$form->{sessionid}&action=company_logo&path=$form->{path}">
44
45 </FRAMESET>
46
47 </BODY>
48 </HTML>
49 |;
50
51 }
52
53
54 sub acc_menu {
55
56   my $menu = new Menu "$menufile";
57   $menu = new Menu "custom_$menufile" if (-f "custom_$menufile");
58   $menu = new Menu "$form->{login}_$menufile" if (-f "$form->{login}_$menufile");
59
60   $form->{title} = $locale->text('Accounting Menu');
61
62   $form->header;
63
64   print qq|
65 <script type="text/javascript">
66 function SwitchMenu(obj) {
67         if (document.getElementById) {
68         var el = document.getElementById(obj);
69         var ar = document.getElementById("cont").getElementsByTagName("DIV");
70
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 }
79 function ChangeClass(menu, newClass) {
80          if (document.getElementById) {
81                 document.getElementById(menu).className = newClass;
82          }
83 }
84 document.onselectstart = new Function("return false");
85 </script>
86
87 <body class=menu>
88 |;
89
90   &section_menu($menu);
91
92   print qq|
93 </body>
94 </html>
95 |;
96
97 }
98
99
100 sub section_menu {
101   my ($menu, $level) = @_;
102
103  print qq|
104         <div id="cont">
105         |;
106
107   # build tiered menus
108   my @menuorder = $menu->access_control(\%myconfig, $level);
109   
110   while (@menuorder){
111     $i++;
112     $item = shift @menuorder;
113     $label = $item;
114     $label =~ s/.*--//g;
115     $label = $locale->text($label);
116
117     $menu->{$item}{target} = "main_window" unless $menu->{$item}{target};
118
119     if ($menu->{$item}{submenu}) {
120       
121         $display = "display: none;" unless $level eq ' ';
122
123         print qq|
124 <div id="menu$i" class="menuOut" onclick="SwitchMenu('sub$i')" onmouseover="ChangeClass('menu$i','menuOver')" onmouseout="ChangeClass('menu$i','menuOut')">$label</div>
125         <div class="submenu" id="sub$i" style="$display">|;
126         
127         # remove same level items
128         map { shift @menuorder } grep /^$item/, @menuorder;
129
130         &section_menu($menu, $item);
131         
132         print qq|
133
134                 </div>
135                 |;
136
137     } else {
138
139       if ($menu->{$item}{module}) {
140         if ($level eq "") {
141           print qq|<div id="menu$i" class="menuOut" onmouseover="ChangeClass('menu$i','menuOver')" onmouseout="ChangeClass('menu$i','menuOut')"> |. 
142           $menu->menuitem(\%myconfig, \%$form, $item, $level).qq|$label</a></div>|;
143
144           # remove same level items
145           map { shift @menuorder } grep /^$item/, @menuorder;
146
147           &section_menu($menu, $item);
148
149         } else {
150         
151           print qq|<div class="submenu"> |.
152           $menu->menuitem(\%myconfig, \%$form, $item, $level).qq|$label</a></div>|;
153         }
154
155       } else {
156
157         $display = "display: none;" unless $item eq ' ';
158
159         print qq|
160 <div id="menu$i" class="menuOut" onclick="SwitchMenu('sub$i')" onmouseover="ChangeClass('menu$i','menuOver')" onmouseout="ChangeClass('menu$i','menuOut')">$label</div>
161         <div class="submenu" id="sub$i" style="$display">|;
162         
163         &section_menu($menu, $item);
164         
165         print qq|
166
167                 </div>
168                 |;
169
170       }
171
172     }
173
174   }
175
176   print qq|
177         </div>
178         |;
179 }
180
181
182 sub menubar {
183
184   1;
185
186 }
187
188