5744c841feaa36051bc633d707f56e1ffdbeae02
[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 my $menufile = "menu.ini";
40 use SL::Menu;
41
42 use CGI::Carp qw(fatalsToBrowser);
43 use Encode;
44 use URI;
45
46 use strict;
47
48 my $locale;
49
50 1;
51
52 # end of main
53
54 sub display {
55   my $form     = $main::form;
56   my %myconfig = %main::myconfig;
57
58   $locale     = Locale->new($myconfig{countrycode}, "menu");
59   my $charset = $main::dbcharset || 'ISO-8859-1';
60   my $callback            = $form->unescape($form->{callback});
61   $callback               = URI->new($callback)->rel($callback) if $callback;
62   $callback               = "login.pl?action=company_logo"      if $callback =~ /^(\.\/)?$/;
63
64   my $text    = $form->create_http_response('content_type' => 'text/xml',
65                                             'charset'      => $charset)
66     . qq|<?xml version="1.0" encoding="${charset}"?>
67 <?xml-stylesheet href="xslt/xulmenu.xsl" type="text/xsl"?>
68 <!DOCTYPE doc [
69 <!ENTITY szlig "| . $locale->{iconv_iso8859}->convert('ß') . qq|">
70 <!ENTITY auml "| . $locale->{iconv_iso8859}->convert('ä') . qq|">
71 <!ENTITY ouml "| . $locale->{iconv_iso8859}->convert('ö') . qq|">
72 <!ENTITY uuml "| . $locale->{iconv_iso8859}->convert('ü') . qq|">
73 ]>
74
75 <doc>
76 <name>$myconfig{name}</name>
77 <version>$form->{version}</version>
78 <callback>$callback</callback>
79 <db>$myconfig{dbname}</db>
80
81 <favorites>|;
82
83   my $fav       = $myconfig{favorites};
84   my @favorites = split m/;/, $fav;
85   foreach (@favorites) {
86     $text .= qq|<link name="$_"/>|;
87   }
88
89   $text .= qq|</favorites>\n|
90     . qq|<menu>\n|
91     . acc_menu()
92     . qq|</menu>\n|
93     . qq|</doc>\n|;
94
95   print $text;
96 }
97
98
99 sub acc_menu {
100   my $form     = $main::form;
101
102   my $mainlevel = $form->{level};
103   $mainlevel =~ s/$mainlevel--//g;
104   my $menu = new Menu "$menufile";
105
106   $| = 1;
107
108   return print_menu($menu);
109 }
110
111 sub print_menu {
112   my ($menu, $parent, $depth) = @_;
113   my $html;
114
115   my $form     = $main::form;
116   my %myconfig = %main::myconfig;
117
118   die if ($depth * 1 > 5);
119
120   my @menuorder;
121
122   @menuorder = $menu->access_control(\%myconfig, $parent);
123
124   $parent .= "--" if ($parent);
125
126   foreach my $item (@menuorder) {
127     my $menu_item_id = $item;
128     substr($item, 0, length($parent)) = "";
129     next if (($item eq "") || ($item =~ /--/));
130
131     my $menu_item = $menu->{"${parent}${item}"};
132     my $menu_title = $locale->text($item);
133     my $menu_text = $menu_title;
134
135     my $target = "main_window";
136     $target = $menu_item->{"target"} if ($menu_item->{"target"});
137
138     if ($menu_item->{"submenu"} || !defined($menu_item->{"module"}) ||
139         ($menu_item->{"module"} eq "menu.pl")) {
140
141       my $h = print_menu($menu, "${parent}${item}", $depth * 1 + 1)."\n";
142       if (!$parent) {
143         $html .= qq|<item name='${menu_text}' id='${menu_item_id}'>${h}</item>\n|;
144       } else {
145         $html .= qq|<item name='${menu_text}' id='${menu_item_id}'>${h}</item>\n|;
146       }
147     } else {
148       $html .= qq|<item |;
149       $html .= $menu->menuitem_XML(\%myconfig, $form, "${parent}$item",
150                                   { "title" => $menu_title,
151                                     "target" => $target });
152       $html .= qq| name="${menu_text}" id='${menu_item_id}'/>\n|;
153     }
154   }
155
156   return $html;
157 }