Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision c7edb248

Von Sven Schöling vor mehr als 14 Jahren hinzugefügt

  • ID c7edb24800396748f2bf1e40ff05f90a18d31b02
  • Vorgänger 881cc205
  • Nachfolger ea4a7211

Nur ein globales Locale-Objekt anlegen

Außerdem alle lokalen Locale-Objekte entfernt. Ist so noch nicht funktionabel.

Conflicts:

SL/Template/Plugin/T8.pm
scripts/console
scripts/rose_auto_create_model.pl
scripts/sync_with_sugarcrm.pl

Unterschiede anzeigen:

SL/Dispatcher.pm
34 34
  my $template             = shift;
35 35
  my $error_type           = shift || '';
36 36

  
37
  $::locale                = Locale->new($::language, 'all');
37
  $::locale                = Locale->new($::language);
38 38
  $::form->{error}         = $::locale->text('The session is invalid or has expired.') if ($error_type eq 'session');
39 39
  $::form->{error}         = $::locale->text('Incorrect password!.')                   if ($error_type eq 'password');
40 40
  $::myconfig{countrycode} = $::language;
......
128 128
  require_main_code($script, $suffix);
129 129

  
130 130
  $::cgi            = CGI->new('');
131
  $::locale         = Locale->new($::language, $script);
131
  $::locale         = Locale->new($::language);
132 132
  $::form           = Form->new;
133 133
  $::form->{script} = $script . $suffix;
134 134

  
......
150 150

  
151 151
      show_error('login/password_error', 'password') unless $::myconfig{login};
152 152

  
153
      $::locale = Locale->new($::myconfig{countrycode}, $script);
153
      $::locale = Locale->new($::myconfig{countrycode});
154 154

  
155 155
      show_error('login/password_error', 'password') if SL::Auth::OK != $::auth->authenticate($::form->{login}, $::form->{password}, 0);
156 156

  
SL/Template/Plugin/LxERP.pm
110 110

  
111 111
sub t8 {
112 112
  my ($self, $text, @args) = @_;
113
  $self->{locale} ||= Locale->new($::myconfig{countrycode}, 'all');
114
  return $self->{locale}->text($text, @args) || $text;
113
  return $::locale->text($text, @args) || $text;
115 114
}
116 115

  
117 116
1;
SL/Template/Plugin/T8.pm
3 3
use Template::Plugin::Filter;
4 4
use base qw( Template::Plugin::Filter );
5 5

  
6
my $locale = undef;
7

  
8 6
sub init {
9 7
  my $self = shift;
10 8

  
11
  $locale ||= Locale->new($main::myconfig{countrycode}, 'all');
12

  
13 9
  # first arg can specify filter name
14 10
  $self->install_filter($self->{ _ARGS }->[0] || 'T8');
15 11

  
......
18 14

  
19 15
sub filter {
20 16
  my ($self, $text, $args) = @_;
21
  return $locale->text($text, @{ $args || [] }) || $text;
17
  return $::locale->text($text, @{ $args || [] }) || $text;
22 18
}
23 19

  
24 20
return 'SL::Template::Plugin::T8';
SL/User.pm
450 450
  map({ $dbup_myconfig{$_} = $form->{$_}; }
451 451
      qw(dbname dbuser dbpasswd dbhost dbport dbconnect));
452 452

  
453
  my $nls_file = $filename;
454
  $nls_file =~ s|.*/||;
455
  $nls_file =~ s|.pl$||;
456
  my $dbup_locale = Locale->new($main::language, $nls_file);
453
  my $dbup_locale = $::locale;
457 454

  
458 455
  my $result = eval($contents);
459 456

  
bin/mozilla/login.pl
39 39

  
40 40
our $cgi;
41 41
our $form;
42
our $locale;
43 42
our $auth;
44 43

  
45 44
sub run {
......
48 47

  
49 48
  $cgi    = $::cgi;
50 49
  $form   = $::form;
51
  $locale = $::locale;
52 50
  $auth   = $::auth;
53 51

  
54 52
  $form->{stylesheet} = "lx-office-erp.css";
55 53
  $form->{favicon}    = "favicon.ico";
56 54

  
57 55
  if (SL::Auth::SESSION_EXPIRED == $session_result) {
58
    $form->{error_message} = $locale->text('The session is invalid or has expired.');
56
    $form->{error_message} = $::locale->text('The session is invalid or has expired.');
59 57
    login_screen();
60 58
    ::end_of_request();
61 59
  }
......
67 65
    our %myconfig = $auth->read_user($form->{login}) if ($form->{login});
68 66

  
69 67
    if (!$myconfig{login} || (SL::Auth::OK != $auth->authenticate($form->{login}, $form->{password}, 0))) {
70
      $form->{error_message} = $locale->text('Incorrect Password!');
68
      $form->{error_message} = $::locale->text('Incorrect Password!');
71 69
      login_screen();
72 70
    } else {
73 71
      $auth->set_session_value('login', $form->{login}, 'password', $form->{password});
74 72
      $auth->create_or_refresh_session();
75 73

  
76 74
      $form->{titlebar} .= " - $myconfig{name} - $myconfig{dbname}";
77
      call_sub($locale->findsub($action));
75
      call_sub($::locale->findsub($action));
78 76
    }
79 77
  } else {
80 78
    login_screen();
......
103 101
  $main::lxdebug->enter_sub();
104 102

  
105 103
  unless ($form->{login}) {
106
    login_screen($locale->text('You did not enter a name!'));
104
    login_screen($::locale->text('You did not enter a name!'));
107 105
    ::end_of_request();
108 106
  }
109 107

  
......
113 111
  my $result;
114 112
  if (($result = $user->login($form)) <= -1) {
115 113
    ::end_of_request() if $result == -2;
116
    login_screen($locale->text('Incorrect username or password!'));
114
    login_screen($::locale->text('Incorrect username or password!'));
117 115
    ::end_of_request();
118 116
  }
119 117

  
......
151 149

  
152 150
  # remove the callback to display the message
153 151
  $form->{callback} = "login.pl?action=";
154
  $form->redirect($locale->text('You are logged out!'));
152
  $form->redirect($::locale->text('You are logged out!'));
155 153

  
156 154
  $main::lxdebug->leave_sub();
157 155
}
......
160 158
  $main::lxdebug->enter_sub();
161 159

  
162 160
  my %myconfig = %main::myconfig;
163
  $locale             =  new Locale $myconfig{countrycode}, "login" if ($main::language ne $myconfig{countrycode});
164

  
165 161
  $form->{todo_list}  =  create_todo_list('login_screen' => 1) if (!$form->{no_todo_list});
166 162

  
167 163
  $form->{stylesheet} =  $myconfig{stylesheet};
168
  $form->{title}      =  $locale->text('About');
164
  $form->{title}      =  $::locale->text('About');
169 165

  
170 166
  # create the logo screen
171 167
  $form->header() unless $form->{noheader};
......
177 173

  
178 174
sub show_error {
179 175
  my $template           = shift;
180
  my %myconfig = %main::myconfig;
181
  $locale                = Locale->new($main::language, 'all');
176
  my %myconfig           = %main::myconfig;
182 177
  $myconfig{countrycode} = $main::language;
183 178
  $form->{stylesheet}    = 'css/lx-office-erp.css';
184 179

  
bin/mozilla/menuXML.pl
45 45

  
46 46
use strict;
47 47

  
48
my $locale;
49

  
50 48
1;
51 49

  
52 50
# end of main
......
55 53
  my $form     = $main::form;
56 54
  my %myconfig = %main::myconfig;
57 55

  
58
  $locale     = Locale->new($myconfig{countrycode}, "menu");
59 56
  my $charset = $main::dbcharset || 'ISO-8859-1';
60 57
  my $callback            = $form->unescape($form->{callback});
61 58
  $callback               = URI->new($callback)->rel($callback) if $callback;
......
66 63
    . qq|<?xml version="1.0" encoding="${charset}"?>
67 64
<?xml-stylesheet href="xslt/xulmenu.xsl" type="text/xsl"?>
68 65
<!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|">
66
<!ENTITY szlig "| . $::locale->{iconv_iso8859}->convert('?') . qq|">
67
<!ENTITY auml "| . $::locale->{iconv_iso8859}->convert('?') . qq|">
68
<!ENTITY ouml "| . $::locale->{iconv_iso8859}->convert('?') . qq|">
69
<!ENTITY uuml "| . $::locale->{iconv_iso8859}->convert('?') . qq|">
73 70
]>
74 71

  
75 72
<doc>
......
129 126
    next if (($item eq "") || ($item =~ /--/));
130 127

  
131 128
    my $menu_item = $menu->{"${parent}${item}"};
132
    my $menu_title = $locale->text($item);
129
    my $menu_title = $::locale->text($item);
133 130
    my $menu_text = $menu_title;
134 131

  
135 132
    my $target = "main_window";
bin/mozilla/menujs.pl
41 41

  
42 42
use strict;
43 43

  
44
my $locale;
45

  
46 44
1;
47 45

  
48 46
# end of main
......
82 80
  my $login = "[Nutzer "
83 81
    . $form->{login}
84 82
    . " - <a href=\"login.pl?action=logout\" target=\"_top\">"
85
    . $locale->text('Logout')
83
    . $::locale->text('Logout')
86 84
    . "</a>] ";
87 85
  my ($Sekunden, $Minuten,   $Stunden,   $Monatstag, $Monat,
88 86
      $Jahr,     $Wochentag, $Jahrestag, $Sommerzeit)
......
136 134
  my $form     = $main::form;
137 135
  my %myconfig = %main::myconfig;
138 136

  
139
  $locale = Locale->new($myconfig{countrycode}, "menu");
140 137
  my $mainlevel = $form->{level};
141 138
  $mainlevel =~ s/$mainlevel--//g;
142 139
  my $menu = new Menu "$menufile";
......
390 387
    my $ml    = $item;
391 388
    $label =~ s/$level--//g;
392 389
    $ml    =~ s/--.*//;
393
    $label = $locale->text($label);
390
    $label = $::locale->text($label);
394 391
    $label =~ s/ /&nbsp;/g;
395 392
    $menu->{$item}{target} = "main_window" unless $menu->{$item}{target};
396 393

  
bin/mozilla/menunew.pl
40 40

  
41 41
use strict;
42 42

  
43
my $locale;
44

  
45 43
1;
46 44

  
47 45
# end of main
......
91 89
sub acc_menu {
92 90
  my $form     = $main::form;
93 91
  my %myconfig = %main::myconfig;
94
  $locale = Locale->new($myconfig{countrycode}, "menu");
95 92

  
96 93
  my $mainlevel =  $form->{level};
97 94
  $mainlevel    =~ s/\Q$mainlevel\E--//g;
......
135 132
    next if (($name eq "") || ($name =~ /--/));
136 133

  
137 134
    my $menu_item = $menu->{"${parent}${name}"};
138
    my $item      = { 'title' => $locale->text($name) };
135
    my $item      = { 'title' => $::locale->text($name) };
139 136
    push @{ $all_items }, $item;
140 137

  
141 138
    if ($menu_item->{submenu} || !defined($menu_item->{module}) || ($menu_item->{module} eq "menu.pl")) {
bin/mozilla/menuv3.pl
38 38
use strict;
39 39

  
40 40
my $menufile = "menu.ini";
41
my $locale;
42 41

  
43 42
1;
44 43

  
......
86 85
  my $form     = $main::form;
87 86
  my %myconfig = %main::myconfig;
88 87

  
89
  $locale = Locale->new($myconfig{countrycode}, "menu");
90

  
91 88
  my $mainlevel = $form->{level};
92 89
  $mainlevel =~ s/\Q$mainlevel\E--//g;
93 90
  my $menu = new Menu "$menufile";
......
118 115
    next if (($item eq "") || ($item =~ /--/));
119 116

  
120 117
    my $menu_item = $menu->{"${parent}${item}"};
121
    my $menu_title = $locale->text($item);
118
    my $menu_title = $::locale->text($item);
122 119
    my $menu_text = $menu_title;
123 120

  
124 121
    my $target = "main_window";
bin/mozilla/menuv4.pl
38 38
use strict;
39 39

  
40 40
my $menufile = "menu.ini";
41
my $locale;
42 41

  
43 42
1;
44 43

  
......
88 87
  my $form     = $main::form;
89 88
  my %myconfig = %main::myconfig;
90 89

  
91
  $locale = Locale->new($myconfig{countrycode}, "menu");
92

  
93 90
  my $mainlevel = $form->{level};
94 91
  $mainlevel =~ s/\Q$mainlevel\E--//g;
95 92
  my $menu = new Menu "$menufile";
......
120 117
    next if (($item eq "") || ($item =~ /--/));
121 118

  
122 119
    my $menu_item = $menu->{"${parent}${item}"};
123
    my $menu_title = $locale->text($item);
120
    my $menu_title = $::locale->text($item);
124 121
    my $menu_text = $menu_title;
125 122

  
126 123
    my $target = "main_window";
scripts/console
1
#!/usr/bin/perl
2

  
3
use warnings;
4
use strict;
5
use 5.008;                          # too much magic in here to include perl 5.6
6

  
7
BEGIN {
8
  unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
9
  push    @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
10
}
11

  
12
use Config::Std;
13
use Data::Dumper;
14
use Devel::REPL 1.002001;
15
use Term::ReadLine::Perl::Bind;     # use sane key binding for rxvt users
16

  
17
read_config 'config/console.conf' => my %config;# if -f 'config/console.conf';
18

  
19
my $login        = shift || $config{Console}{login}        || 'demo';
20
my $history_file =          $config{Console}{history_file} || '/tmp/lxoffice_console_history.log'; # fallback if users is not writable
21
my $autorun      =          $config{Console}{autorun};
22

  
23
# will be configed eventually
24
my @plugins      = qw(History LexEnv Colors MultiLine::PPI FancyPrompt PermanentHistory AutoloadModules);
25

  
26
my $repl = Devel::REPL->new;
27
$repl->load_plugin($_) for @plugins;
28
$repl->load_history($history_file);
29
$repl->eval('help');
30
$repl->print("trying to auto login as '$login'...");
31
$repl->print($repl->eval("lxinit '$login'"));
32
$repl->print($repl->eval($autorun)) if $autorun;
33
$repl->run;
34

  
35
package Devel::REPL;
36

  
37

  
38
# this is a cleaned up version of am.pl
39
# it lacks redirection, some html setup and most of the authentication process.
40
# it is assumed that anyone with physical access and execution rights on this script
41
# won't be hindered by authentication anyway.
42
sub lxinit {
43
  my $login = shift;
44

  
45
  die 'need login' unless $login;
46

  
47
  package main;
48

  
49
  { no warnings 'once';
50
    $::userspath  = "users";
51
    $::templates  = "templates";
52
    $::memberfile = "users/members";
53
    $::sendmail   = "| /usr/sbin/sendmail -t";
54
  }
55

  
56
  use SL::LXDebug;
57
  $::lxdebug = LXDebug->new;
58

  
59
  use CGI qw( -no_xhtml);
60
  use SL::Auth;
61
  use SL::Form;
62
  use SL::Locale;
63
  use Data::Dumper;
64

  
65
  eval { require "config/lx-erp.conf"; };
66
  eval { require "config/lx-erp-local.conf"; } if -f "config/lx-erp-local.conf";
67

  
68
  $::cgi  = CGI->new qw();
69
  $::form = Form->new;
70
  $::auth = SL::Auth->new;
71

  
72
  die 'cannot reach auth db'               unless $::auth->session_tables_present;
73

  
74
  $::auth->restore_session;
75

  
76
  require "bin/mozilla/common.pl";
77

  
78
  die "cannot find user $login"            unless %::myconfig = $::auth->read_user($login);
79
  die "cannot find locale for user $login" unless $::locale   = Locale->new($::myconfig{countrycode});
80

  
81
  return "logged in as $login";
82
}
83

  
84
# these function provides a load command to slurp in a lx-office module
85
# since it's seldomly useful, it's not documented in help
86
sub load {
87
  my $module = shift;
88
  $module =~ s/[^\w]//g;
89
  require "bin/mozilla/$module.pl";
90
}
91

  
92
sub reload {
93
  use Module::Reload;
94
  Module::Reload->check();
95

  
96
  return "modules reloaded";
97
}
98

  
99
sub quit {
100
  exit;
101
}
102

  
103
sub help {
104
  print <<EOL;
105

  
106
  Lx-Office Konsole
107

  
108
  ./scripts/console [login]
109

  
110
Spezielle Kommandos:
111

  
112
  help                - zeigt diese Hilfe an.
113
  lxinit 'login'      - l?dt das Lx-Office Environment f?r den User 'login'.
114
  reload              - l?dt modifizierte Module neu.
115
  pp DATA             - zeigt die Datenstruktur mit Data::Dumper an.
116
  quit                - beendet die Konsole
117

  
118
EOL
119
#  load   'module'     - l?d das angegebene Modul, d.h. bin/mozilla/module.pl und SL/Module.pm.
120
}
121

  
122
sub pp {
123
  $Data::Dumper::Indent   = 2;
124
  $Data::Dumper::Maxdepth = 2;
125
  Data::Dumper::Dumper(@_);
126
}
127

  
128
1;
129

  
130
__END__
131

  
132
=head1 NAME
133

  
134
scripts/console - Lx Office Console
135

  
136
=head1 SYNOPSIS
137

  
138
  ./script/console
139
  > help               # displays a brief documentation
140

  
141
=head1 DESCRIPTION
142

  
143
Users of Ruby on Rails will recognize this as a perl reimplementation of the
144
rails scripts/console. It's intend is to provide a shell environment to the
145
lx-office internals. This will mostly not interest you if you just want to do
146
your ERP stuff with lx-office, but will be invaluable for those who wish to
147
make changes to lx-office itself.
148

  
149
=head1 FUNCTIONS
150

  
151
You can do most things in the console that you could do in an actual perl
152
script. Certain helper functions will aid you in debugging the state of the
153
program:
154

  
155
=head2 pp C<DATA>
156

  
157
Named after the rails pretty print gem, this will call Data::Dumper on the
158
given C<DATA>. Use it to see what is going on.
159

  
160
Currently C<pp> will set the Data::Dumper depth to 2, so if you need a
161
different depth, you'll have to change that. A nice feature would be to
162
configure that, or at least to be able to change it at runtime.
163

  
164
=head2 lxinit C<login>
165

  
166
Login into lx-office using a specified login. No password will be required, and
167
security mechanisms will mostly be inactive. form, locale, myconfig will be
168
correctly set.
169

  
170
=head2 reload
171

  
172
Attempts to reload modules that changed since last reload (or inital startup).
173
This will mostly work just fine, except for Moose classes that have been made
174
immutable. Keep in mind that existing objects will continue to have the methods
175
of the classes they were created with.
176

  
177
=head1 BUGS
178

  
179
 - Reload on immutable Moose classes is buggy.
180
 - Logging in more than once is not supported by the program, and thus not by
181
   the console. It seems to work, but strange things may happen.
182

  
183
=head1 SEE ALSO
184

  
185
Configuration of this script is located in:
186

  
187
 config/console.conf
188
 config/console.conf.default
189

  
190
See there for interesting options.
191

  
192
=head1 AUTHOR
193

  
194
  Sven Sch?ling <s.schoeling@linet-services.de>
195

  
196
=cut
scripts/dbupgrade2_tool.pl
355 355
eval { require "config/lx-erp-local.conf"; } if (-f "config/lx-erp-local.conf");
356 356

  
357 357
$form = Form->new();
358
$locale = Locale->new("de", "login");
358
$locale = Locale->new("de");
359 359

  
360 360
#######
361 361
#######

Auch abrufbar als: Unified diff