}
sub create_or_refresh_session {
- $main::lxdebug->enter_sub();
-
- my $self = shift;
-
- $session_id ||= $self->_create_session_id();
-
- my ($form, $dbh, $query, $sth, $id);
-
- $form = $main::form;
- $dbh = $self->dbconnect();
-
- $dbh->begin_work;
- do_query($::form, $dbh, qq|LOCK auth.session_content|);
-
- $query = qq|SELECT id FROM auth.session WHERE id = ?|;
-
- ($id) = selectrow_query($form, $dbh, $query, $session_id);
-
- if ($id) {
- do_query($form, $dbh, qq|UPDATE auth.session SET mtime = now() WHERE id = ?|, $session_id);
-
- } else {
- do_query($form, $dbh, qq|INSERT INTO auth.session (id, ip_address, mtime) VALUES (?, ?, now())|, $session_id, $ENV{REMOTE_ADDR});
-
- }
-
- $self->save_session($dbh);
-
- $dbh->commit();
-
- $main::lxdebug->leave_sub();
+ $session_id ||= shift->_create_session_id;
}
sub save_session {
+ $::lxdebug->enter_sub;
my $self = shift;
my $provided_dbh = shift;
my $dbh = $provided_dbh || $self->dbconnect(1);
- return unless $dbh;
+ $::lxdebug->leave_sub && return unless $dbh;
$dbh->begin_work unless $provided_dbh;
do_query($::form, $dbh, qq|LOCK auth.session_content|);
do_query($::form, $dbh, qq|DELETE FROM auth.session_content WHERE session_id = ?|, $session_id);
+ my $query = qq|SELECT id FROM auth.session WHERE id = ?|;
+
+ my ($id) = selectrow_query($::form, $dbh, $query, $session_id);
+
+ if ($id) {
+ do_query($::form, $dbh, qq|UPDATE auth.session SET mtime = now() WHERE id = ?|, $session_id);
+ } else {
+ do_query($::form, $dbh, qq|INSERT INTO auth.session (id, ip_address, mtime) VALUES (?, ?, now())|, $session_id, $ENV{REMOTE_ADDR});
+ }
+
if (%{ $self->{SESSION} }) {
my $query = qq|INSERT INTO auth.session_content (session_id, sess_key, sess_value) VALUES (?, ?, ?)|;
my $sth = prepare_query($::form, $dbh, $query);
}
$dbh->commit() unless $provided_dbh;
+ $::lxdebug->leave_sub;
}
sub set_session_value {
}
sub load_rights_for_user {
- $main::lxdebug->enter_sub();
-
- my $self = shift;
- my $login = shift;
-
- my $form = $main::form;
- my $dbh = $self->dbconnect();
+ $::lxdebug->enter_sub;
+ my ($self, $login) = @_;
+ my $dbh = $self->dbconnect;
my ($query, $sth, $row, $rights);
- $rights = {};
+ $rights = { map { $rights->{$_} = 0 } all_rights() };
$query =
qq|SELECT gr."right", gr.granted
LEFT JOIN auth."user" u ON (ug.user_id = u.id)
WHERE u.login = ?)|;
- $sth = prepare_execute_query($form, $dbh, $query, $login);
+ $sth = prepare_execute_query($::form, $dbh, $query, $login);
while ($row = $sth->fetchrow_hashref()) {
$rights->{$row->{right}} |= $row->{granted};
}
$sth->finish();
- map({ $rights->{$_} = 0 unless (defined $rights->{$_}); } SL::Auth::all_rights());
-
- $main::lxdebug->leave_sub();
+ $::lxdebug->leave_sub;
return $rights;
}
--- /dev/null
+package SL::Controller::DebugMenu;
+
+use strict;
+use parent qw(SL::Controller::Base);
+
+# safety
+__PACKAGE__->run_before(sub { die 'not allowed in config' unless $::lx_office_conf{debug}{show_debug_menu}; });
+
+sub action_reload {
+ my ($self, %params) = @_;
+
+ print $::cgi->redirect('kopf.pl');
+ exit;
+}
+
+sub action_toggle {
+ my ($self, %params) = @_;
+
+ $::lxdebug->level_by_name($::form->{level}, !$::lxdebug->level_by_name($::form->{level}));
+ print $::cgi->redirect('kopf.pl');
+ return;
+}
+
+1;
require Log::Log4perl;
require DBIx::Log4perl;
- my $filename = $LXDebug::file_name;
+ my $filename = $::lxdebug->file;
my $config = $::lx_office_conf{debug}->{dbix_log4perl_config};
$config =~ s/LXDEBUGFILE/${filename}/g;
show_error('login/auth_db_unreachable');
}
}
- $::auth->expire_sessions;
}
sub show_error {
$::myconfig = ();
Form::disconnect_standard_dbh;
$::auth->expire_session_keys->save_session;
+ $::auth->expire_sessions;
$::auth->reset;
$::lxdebug->end_request;
$global_level & REQUEST_TIMER;
}
+sub file {
+ @_ == 2 ? $_[0]->{file} = $_[1] : $_[0]->{file};
+}
+
+sub _by_name {
+ my ($self, $level) = @_;
+ my $meth = $self->can(uc $level);
+ die 'unknown level' unless $meth;
+ $meth->();
+}
+
+sub level_by_name {
+ my ($self, $level, $val) = @_;
+ if (@_ == 3) {
+ $global_level |= $self->_by_name($level) if $val;
+ $global_level &= ~$self->_by_name($level) if !$val;
+ }
+ return $global_level & $self->_by_name($level);
+}
+
1;
# creating invalid UTF-8 characters upon URL-unescaping.
# The only addition is the "Encode::encode()" line.
-
+no warnings 'redefine';
sub url {
my ($self, $text) = @_;
return undef unless defined $text;
#!/usr/bin/perl
-#
-
-#$| = 1;
-
-#use CGI::Carp qw(fatalsToBrowser);
use strict;
+use DateTime;
sub run {
my $session_result = shift;
- %::myconfig = $::auth->read_user($::form->{login}) if $::form->{login};
- $::locale = Locale->new($::myconfig{countrycode}) if $::myconfig{countrycode};
-
-my $form = $main::form;
-my $locale = $main::locale;
-
-$form->header;
-my $paramstring = $ENV{"QUERY_STRING"};
-my @felder = split "&", $paramstring;
-my ($name, $wert);
-foreach (@felder) {
- ($name, $wert) = split "=", $_;
- $wert =~ tr/+/ /;
- $name = $wert;
-}
-my $login =
- "". $locale->text('User') . ": " . $form->{login}
- . " [<a href=\"login.pl?action=logout\" target=\"_top\" title=\"". $locale->text('Logout now') . "\">"
- . $locale->text('Logout')
- . "</a>] ";
-my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat,
- $Jahr, $Wochentag, $Jahrestag, $Sommerzeit)
- = localtime(time);
-my $CTIME_String = localtime(time);
-$Monat += 1;
-$Jahrestag += 1;
-$Monat = $Monat < 10 ? $Monat = "0" . $Monat : $Monat;
-$Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag;
-$Jahr += 1900;
-my @Wochentage = ("Sonntag", "Montag", "Dienstag", "Mittwoch",
- "Donnerstag", "Freitag", "Samstag");
-my @Monatsnamen = ("", "Januar", "Februar", "März",
- "April", "Mai", "Juni", "Juli",
- "August", "September", "Oktober", "November",
- "Dezember");
-my $datum =
- $Wochentage[$Wochentag] . ", der "
- . $Monatstag . "."
- . $Monat . "."
- . $Jahr . " - ";
-
-#$zeit="<div id='Uhr'>".$Stunden.":".$Minuten.":".$Sekunden."</div>";
-my $zeit = "<div id='Uhr'>" . $Stunden . ":" . $Minuten . "</div>";
-print qq|
-<script type="text/javascript">
-<!--
-var clockid=new Array()
-var clockidoutside=new Array()
-var i_clock=-1
-var thistime= new Date()
-var hours= | . $Stunden . qq|;
-var minutes= | . $Minuten . qq|;
-var seconds= | . $Sekunden . qq|;
-if (eval(hours) <10) {hours="0"+hours}
-if (eval(minutes) < 10) {minutes="0"+minutes}
-if (seconds < 10) {seconds="0"+seconds}
-//var thistime = hours+":"+minutes+":"+seconds
-var thistime = hours+":"+minutes
-
-function writeclock() {
- i_clock++
- if (document.all \|\| document.getElementById \|\| document.layers) {
- clockid[i_clock]="clock"+i_clock
- document.write("<font family=arial size=2><span id='"+clockid[i_clock]+"' style='position:relative'>"+thistime+"</span></font>")
- }
-}
-
-function clockon() {
- thistime= new Date()
- hours=thistime.getHours()
- minutes=thistime.getMinutes()
- seconds=thistime.getSeconds()
- if (eval(hours) <10) {hours="0"+hours}
- if (eval(minutes) < 10) {minutes="0"+minutes}
- if (seconds < 10) {seconds="0"+seconds}
- //thistime = hours+":"+minutes+":"+seconds
- thistime = hours+":"+minutes
-
- if (document.all) {
- for (i=0;i<=clockid.length-1;i++) {
- var thisclock=eval(clockid[i])
- thisclock.innerHTML=thistime
- }
- }
-
- if (document.getElementById) {
- for (i=0;i<=clockid.length-1;i++) {
- document.getElementById(clockid[i]).innerHTML=thistime
- }
- }
- var timer=setTimeout("clockon()",60000)
-}
-window.onload=clockon
-//-->
-</script>
-|;
+ %::myconfig = $::auth->read_user($::form->{login}) if $::form->{login};
+ $::locale = Locale->new($::myconfig{countrycode}) if $::myconfig{countrycode};
-print qq|
-<body bgcolor="#ffffff" text="#ffffff" link="#ffffff" vlink="#ffffff" alink="#ffffff" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" style="background-image: url('image/fade.png'); background-repeat:repeat-x;">
-<script language='JavaScript' src='js/switchmenuframe.js'></script>
-<table border="0" width="100%" background="image/bg_titel.gif" cellpadding="0" cellspacing="0">
- <tr>|;
- if ( !($ENV{HTTP_USER_AGENT} =~ /links/i) ) { # do not show the the links in case of "links" in HTTP_USER_AGENT
- print qq|
- <td style="color:white; font-family:verdana,arial,sans-serif; font-size: 12px;" nowrap>
- [<a href="JavaScript:Switch_Menu();" title="| . $locale->text('Switch Menu on / off') . qq|">| . $locale->text('Menu') . qq|</a>]
- [<a HREF="login.pl" target="_blank" title="| . $locale->text('Open a further Lx-Office Window or Tab') . qq|">| . $locale->text('New Win/Tab') . qq|</a>]
- [<a href="JavaScript:top.main_window.print();" title="| . $locale->text('Hardcopy') . qq|">| . $locale->text('Print') . qq|</a>]
- [<a href="Javascript:top.main_window.history.back();" title="| . $locale->text('Go one step back') . qq|">| . $locale->text('Back') . qq|</a>]
- [<a href="Javascript:top.main_window.history.forward();" title="| . $locale->text('Go one step forward') . qq|">| . $locale->text('Fwd') . qq|</a>]
- </td>|;
- }
- print qq|
- <td align="right" style="vertical-align:middle; color:white; font-family:verdana,arial,sans-serif; font-size: 12px;" nowrap>|
- . $login . $datum . qq| <script>writeclock()</script>
- </td>
- </tr>
-</table>
-</body>
-</html>
-|;
+ $::form->header;
+ print $::form->parse_html_template('menu/header', {
+ now => DateTime->now,
+ show_debug => $::lx_office_conf{debug}{show_debug_menu},
+ lxdebug => $::lxdebug,
+ is_links => ($ENV{HTTP_USER_AGENT} =~ /links/i),
+ });
}
1;
# location of history file for permanent history
history_file = users/console_history
+# location of a separate log file for the console. everything normally written
+# to the lx-office log will be put here if triggered from the console
+log_file = /tmp/lxoffice_console_debug.log
+
[debug]
# Use DBIx::Log4perl for logging DBI calls. The string LXDEBUGFILE
# will be replaced by the file name configured for $::lxdebug.
# default.
watch_form = 0
+# Im HTML Menü ein Hilfsmenü zur Debugsteuerung zeigen.
+show_debug_menu = 0
+
# If you want to debug the creation of LaTeX files then set this to 1.
# That way the temporary LaTeX files created during PDF creation are
# not removed and remain in the "users" directory.
my $login = shift || $::lx_office_conf{console}{login} || 'demo';
my $history_file = $::lx_office_conf{console}{history_file} || '/tmp/lxoffice_console_history.log'; # fallback if users is not writable
+my $debug_file = $::lx_office_conf{Console}{log_file} || '/tmp/lxoffice_console_debug.log';
my $autorun = $::lx_office_conf{console}{autorun};
# will be configed eventually
package main;
- $::lxdebug = LXDebug->new;
+ $::lxdebug = LXDebug->new(file => $debug_file);
$::locale = Locale->new($::lx_office_conf{system}->{language});
$::cgi = CGI->new qw();
$::form = Form->new;
my @source_texts = source_texts($module);
local $" = $/;
- print <<EOL;
+ print STDERR <<EOL;
+-----------------------------------------------------------------------------+
$module->{fullname} could not be loaded.
--- /dev/null
+[%- USE T8 %]
+<style type='text/css'>
+ body { margin: 0; color: white; background: url('image/fade.png') repeat-x; }
+ a:link, a:visited, a:hover, a:active { color:white }
+ body > * { font-size: 12px; font-family:verdana,arial,sans-serif; vertical-align:middle; }
+ table { border:0; width: 100%; background: url('image/bg_titel.gif'); border-spacing:0; }
+ td { padding: 0 }
+</style>
+<script language='javascript' src='js/switchmenuframe.js'></script>
+<body>
+ <table>
+ <tr>
+[% UNLESS is_links %]
+ <td nowrap>
+ [<a href="JavaScript:Switch_Menu();" title="[% 'Switch Menu on / off' | $T8 %]">[% 'Menu' | $T8 %]</a>]
+ [<a HREF="login.pl" target="_blank" title="[% 'Open a further Lx-Office Window or Tab' | $T8 %]">[% 'New Win/Tab' | $T8 %]</a>]
+ [<a href="JavaScript:top.main_window.print();" title="[% 'Hardcopy' | $T8 %]">[% 'Print' | $T8 %]</a>]
+ [<a href="Javascript:top.main_window.history.back();" title="[% 'Go one step back' | $T8 %]">[% 'Back' | $T8 %]</a>]
+ [<a href="Javascript:top.main_window.history.forward();" title="[% 'Go one step forward' | $T8 %]">[% 'Fwd' | $T8 %]</a>]
+ </td>
+[%- END %]
+[% IF show_debug %]
+ <td align='center' nowrap>
+ Debug:
+ [<a href='controller.pl?action=DebugMenu/reload']>FCGI Reload</a>]
+ [<a href='controller.pl?action=DebugMenu/toggle&level=request_timer'>[% IF lxdebug.level_by_name('request_timer') %]<b>Timing</b>[% ELSE %]Timing[% END %]</a>]
+ [<a href='controller.pl?action=DebugMenu/toggle&level=trace'>[% IF lxdebug.level_by_name('trace') %]<b>Trace</b>[% ELSE %]Trace[% END %]</a>]
+ [<a href='controller.pl?action=DebugMenu/toggle&level=query'>[% IF lxdebug.level_by_name('query') %]<b>Query</b>[% ELSE %]Query[% END %]</a>]
+ </td>
+[%- END %]
+ <td align="right" nowrap>
+ [% 'User' | $T8 %]:
+ [% login %]
+ [<a href="login.pl?action=logout" target="_top" title="[% 'Logout now' | $T8 %]">[% 'Logout' | $T8 %]</a>]
+ [% now.to_lxoffice %] -
+ [% now.hms %]
+ </td>
+ </tr>
+ </table>
+</body>
+</html>
<tr>
<th align="right">[% 'Contact Person' | $T8 %]</th>
<td>
- [%- INCLUDE 'generic/multibox.html'
- name = 'cp_id',
- style = 'width: 250px',
- DATA = ALL_CONTACTS,
- id_key = 'cp_id',
- label_sub = 'contact_labels',
- show_empty = 1 -%]
+ [% L.select_tag('cp_id', L.options_for_select(ALL_CONTACTS, default=cp_id, value='cp_id', title_sub=\contact_labels, with_empty=1), style='width: 250px') %]
</td>
</tr>
[%- END %]
<tr>
<th align="right">[% 'Shipping Address' | $T8 %]</th>
<td>
- [%- INCLUDE 'generic/multibox.html'
- name = 'shipto_id',
- style = 'width: 250px',
- DATA = ALL_SHIPTO,
- id_key = 'shipto_id',
- label_sub = 'shipto_labels',
- show_empty = 1,
- onChange = "document.getElementById('update_button').click();" -%]
+ [% L.select_tag('shipto_id', L.options_for_select(ALL_SHIPTO, default=shipto_id, value='shipto_id', title_sub=\shipto_labels, with_empty=1), style='width: 250px', onChange="document.getElementById('update_button').click();") %]
</td>
</tr>
[%- END %]
<tr>
<th align="right">[% 'Steuersatz' | $T8 %]</th>
<td>
- [%- INCLUDE 'generic/multibox.html'
- name = 'taxzone_id',
- style = 'width: 250px',
- DATA = ALL_TAXZONES,
- id_key = 'id',
- label_key = 'description' -%]
+ [% L.select_tag('taxzone_id', L.options_for_select(ALL_TAXZONES, default=taxzone_id, title='description'), style='width: 250px') %]
</td>
</tr>
[%- IF ALL_DEPARTMENTS %]
<tr>
<th align="right" nowrap>[% 'Department' | $T8 %]</th>
<td colspan="3">
- [%- INCLUDE 'generic/multibox.html'
- name = 'department_id',
- style = 'width: 250px',
- DATA = ALL_DEPARTMENTS,
- id_key = 'id',
- label_sub = 'department_labels',
- show_empty = 1 -%]
+ [% L.select_tag('department_id', L.options_for_select(ALL_DEPARTMENTS, default=department_id, title_sub=\department_labels, with_empty=1), style='width:250px') %]
</td>
</tr>
[%- END %]
<tr>
<th align="right">[% 'Employee' | $T8 %]</th>
<td>
- [%- INCLUDE 'generic/multibox.html'
- name = 'employee_id',
- DATA = ALL_EMPLOYEES,
- id_key = 'id',
- label_sub = 'sales_employee_labels' -%]
+ [% L.select_tag('employee_id', L.options_for_select(ALL_EMPLOYEES, default=employee_id, title_sub=\sales_employee_labels)) %]
</td>
</tr>
[%- IF is_sales and ALL_SALESMEN.size %]
<tr>
<th align="right">[% 'Salesman' | $T8 %]</th>
<td>
- [%- INCLUDE 'generic/multibox.html'
- name = 'salesman_id',
- default = salesman_id ? salesman_id : employee_id,
- DATA = ALL_SALESMEN,
- id_key = 'id',
- label_sub = 'sales_employee_labels' -%]
+ [% L.select_tag('salesman_id', L.options_for_select(ALL_SALESMEN, default=(salesman_id ? salesman_id : employee_id), title_sub=\sales_employee_labels)) %]
</td>
</tr>
[%- END %]
<tr>
<th width="70%" align="right" nowrap>[% 'Project Number' | $T8 %]</th>
<td>
- [%- INCLUDE 'generic/multibox.html'
- name = 'globalproject_id',
- DATA = ALL_PROJECTS,
- id_key = 'id',
- label_key = 'projectnumber',
- show_empty = 1,
- onChange = "document.getElementById('update_button').click();" -%]
+ [%- L.select_tag('globalproject_id', L.options_for_select(ALL_PROJECTS, title='projectnumber', default=globalproject_id, with_empty='1'), onChange="document.getElementById('update_button').click();") %]
</td>
</tr>
</table>