3aa32f2f823d90d1efd047eb416fff213658041b
[kivitendo-erp.git] / bin / mozilla / menuXML.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 ######################################################################
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #  Contributors: Christopher Browne
16 #
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; either version 2 of the License, or
20 # (at your option) any later version.
21 #
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #######################################################################
30 #
31 # three frame layout with refractured menu
32 #
33 # CHANGE LOG:
34 #   DS. 2002-03-25  Created
35 #  2004-12-14 - New Optik - Marco Welter <mawe@linux-studio.de>
36 #  2007-10-14 - XMLified  - Holger Will  <holger@treebuilder.de>
37 #######################################################################
38
39 $menufile = "menu.ini";
40 use SL::Menu;
41
42 use CGI::Carp qw(fatalsToBrowser);
43 use Encode;
44 1;
45
46 # end of main
47
48 sub display {
49   print "Content-type: text/xml; charset=iso-8859-1\n\n";
50   print qq|<?xml version="1.0" encoding="iso-8859-1"?>\n|;
51   print qq|<?xml-stylesheet href="xslt/xulmenu.xsl" type="text/xsl"?>\n|;
52   print qq|<!DOCTYPE doc [
53 <!ENTITY szlig "ß">
54 <!ENTITY auml "ä">
55 <!ENTITY uuml "ü">
56 <!ENTITY ouml "ö">
57 ]>|;
58   print qq|<doc>|;
59   print qq|<name>|;
60   print %myconfig->{name};
61   print qq|</name>|;
62   print qq|<db>|;
63   print %myconfig->{dbname};
64   print qq|</db>|;
65   print qq|<favorites>|;
66   my $fav=%myconfig->{favorites};
67   my @favorites = split(/;/, $fav);
68   foreach (@favorites) {
69     print qq|<link name="$_"/>|;
70   }
71   print qq|</favorites>|;
72   print qq|<menu>|;
73 my $isoencodedmenu=&acc_menu($menu);
74  print encode("iso-8859-1",$isoencodedmenu );
75
76   print qq|</menu>|;
77   print qq|</doc>|;
78   
79 }
80
81
82 sub acc_menu {
83   $locale = Locale->new($language, "menu");
84
85   $mainlevel = $form->{level};
86   $mainlevel =~ s/$mainlevel--//g;
87   my $menu = new Menu "$menufile";
88
89   $| = 1;
90
91   return print_menu($menu);
92 }
93
94 sub print_menu {
95   my ($menu, $parent, $depth) = @_;
96   my $html;
97
98   die if ($depth * 1 > 5);
99
100   my @menuorder;
101
102   @menuorder = $menu->access_control(\%myconfig, $parent);
103
104   $parent .= "--" if ($parent);
105
106   foreach my $item (@menuorder) {
107     my $menu_item_id = $item;
108     substr($item, 0, length($parent)) = "";
109     next if (($item eq "") || ($item =~ /--/));
110
111     my $menu_item = $menu->{"${parent}${item}"};
112     my $menu_title = $locale->text($item);
113     my $menu_text = $menu_title;
114
115     my $target = "main_window";
116     $target = $menu_item->{"target"} if ($menu_item->{"target"});
117
118     if ($menu_item->{"submenu"} || !defined($menu_item->{"module"}) ||
119         ($menu_item->{"module"} eq "menu.pl")) {
120
121       my $h = print_menu($menu, "${parent}${item}", $depth * 1 + 1)."\n";
122       if (!$parent) {
123         $html .= qq|<item name='${menu_text}' id='${menu_item_id}'>${h}</item>\n|;
124       } else {
125         $html .= qq|<item name='${menu_text}' id='${menu_item_id}'>${h}</item>\n|;
126       }
127     } else {
128       $html .= qq|<item |;
129       $html .= $menu->menuitem_XML(\%myconfig, $form, "${parent}$item",
130                                   { "title" => $menu_title,
131                                     "target" => $target });
132       $html .= qq| name="${menu_text}" id='${menu_item_id}'/>\n|;
133     }
134   }
135
136   return $html;
137 }