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