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