#
#======================================================================
-$menufile = "menu.ini";
-
+use DBI;
+use CGI;
+use English qw(-no_match_vars);
+use Fcntl;
+use File::Copy;
+use IO::File;
+use POSIX qw(strftime);
+use Sys::Hostname;
+
+use SL::Auth;
+use SL::Auth::PasswordPolicy;
use SL::Form;
+use SL::Iconv;
+use SL::Mailer;
use SL::User;
+use SL::Common;
+use SL::Inifile;
+use SL::DBUpgrade2;
+use SL::DBUtils;
-$form = new Form;
-
-$locale = new Locale $language, "admin";
-
-eval { require DBI; };
-$form->error($locale->text('DBI not installed!')) if ($@);
-
-# customization
-if (-f "$form->{path}/custom_$form->{script}") {
- eval { require "$form->{path}/custom_$form->{script}"; };
- $form->error($@) if ($@);
-}
-
-$form->{stylesheet} = "lx-office-erp.css";
-$form->{favicon} = "favicon.ico";
+require "bin/mozilla/common.pl";
+require "bin/mozilla/admin_groups.pl";
+require "bin/mozilla/admin_printer.pl";
-if ($form->{action}) {
+use strict;
- $subroutine = $locale->findsub($form->{action});
+our $cgi;
+our $form;
+our $locale;
+our $auth;
- if ($subroutine eq 'login') {
- if ($form->{rpw}) {
- $form->{rpw} = crypt $form->{rpw}, "ro";
- }
- }
+sub run {
+ $::lxdebug->enter_sub;
+ my $session_result = shift;
- &check_password;
+ $cgi = $::cgi;
+ $form = $::form;
+ $locale = $::locale;
+ $auth = $::auth;
- &$subroutine;
+ $::auth->set_session_value('rpw', $::form->{rpw}) if $session_result == SL::Auth->SESSION_OK;
-} else {
+ $form->{stylesheet} = "lx-office-erp.css";
+ $form->{favicon} = "favicon.ico";
- # if there are no drivers bail out
- $form->error($locale->text('No Database Drivers available!'))
- unless (User->dbdrivers);
-
- # create memberfile
- if (!-f $memberfile) {
- open(FH, ">$memberfile") or $form->error("$memberfile : $!");
- print FH qq|# SQL-Ledger Accounting members
+ if ($form->{action}) {
+ if ($auth->authenticate_root($form->{rpw}, 0) != $auth->OK()) {
+ $form->{error_message} = $locale->text('Incorrect Password!');
+ adminlogin();
+ } else {
+ if ($auth->session_tables_present()) {
+ $::auth->set_session_value('rpw', $::form->{rpw});
+ $::auth->create_or_refresh_session();
+ _apply_dbupgrade_scripts();
+ }
-[root login]
-password=
+ call_sub($locale->findsub($form->{action}));
+ }
+ } else {
+ # if there are no drivers bail out
+ $form->error($locale->text('No Database Drivers available!'))
+ unless (User->dbdrivers);
-|;
- close FH;
+ adminlogin();
}
-
- &adminlogin;
-
+ $::lxdebug->leave_sub;
}
-1;
+sub adminlogin {
+ my $form = $main::form;
+ my $locale = $main::locale;
-# end
+ $form->{title} = qq|Lx-Office ERP $form->{version} | . $locale->text('Administration');
-sub adminlogin {
+ $form->header();
+ print $form->parse_html_template('admin/adminlogin');
+}
- $form->{title} =
- qq|Lx-Office ERP $form->{version} | . $locale->text('Administration');
+sub login {
+ check_auth_db_and_tables();
+ list_users();
+}
- $form->header;
+sub logout {
+ $main::auth->destroy_session();
+ adminlogin();
+}
- print qq|
-<body class=admin>
+sub check_auth_db_and_tables {
+ my $form = $main::form;
+ my $locale = $main::locale;
+ my %params;
-<div align=center>
+ map { $params{"db_${_}"} = $main::auth->{DB_config}->{$_} } keys %{ $auth->{DB_config} };
-<a href="http://www.lx-office.org"><img src="image/lx-office-erp.png" border=0></a>
-<h1 class=login>|
- . $locale->text('Version')
- . qq| $form->{version}<p>|
- . $locale->text('Administration')
- . qq|</h1>
+ if (!$main::auth->check_database()) {
+ $form->{title} = $locale->text('Authentification database creation');
+ $form->header();
+ print $form->parse_html_template('admin/check_auth_database', \%params);
-<form method=post action="$form->{script}">
+ ::end_of_request();
+ }
-<table>
- <tr>
- <th>| . $locale->text('Password') . qq|</th>
- <td><input type=password name=rpw></td>
- <td><input type=submit class=submit name=action value="|
- . $locale->text('Login') . qq|"></td>
- </tr>
-<input type=hidden name=action value=login>
-<input type=hidden name=root value="root login">
-<input type=hidden name=path value=$form->{path}>
-</table>
+ if (!$main::auth->check_tables()) {
+ $form->{title} = $locale->text('Authentification tables creation');
+ $form->header();
+ print $form->parse_html_template('admin/check_auth_tables', \%params);
+ ::end_of_request();
+ }
-</form>
+ my $memberfile = $::lx_office_conf{paths}->{memberfile};
+ if (-f $memberfile) {
+ my $memberdir = "";
-<a href=http://www.lx-office.org>Lx-Office |
- . $locale->text('website') . qq|</a>
+ if ($memberfile =~ m|^.*/|) {
+ $memberdir = $&;
+ }
-</div>
+ my $backupdir = "${memberdir}member-file-migration";
-</body>
-</html>
-|;
+ $form->{title} = $locale->text('User data migration');
+ $form->header();
+ print $form->parse_html_template('admin/user_migration', { 'memberfile' => $memberfile,
+ 'backupdir' => $backupdir });
+ ::end_of_request();
+ }
}
-sub login {
-
- &list_users;
+sub create_auth_db {
+ my $form = $main::form;
+ $main::auth->create_database('superuser' => $form->{db_superuser},
+ 'superuser_password' => $form->{db_superuser_password},
+ 'template' => $form->{db_template});
+ login();
}
-sub add_user {
-
- $form->{title} =
- "Lx-Office ERP "
- . $locale->text('Administration') . " / "
- . $locale->text('Add User');
+sub create_auth_tables {
+ my $form = $main::form;
+ my $locale = $main::locale;
- $form->{Oracle_sid} = $sid;
- $form->{Oracle_dbport} = '1521';
- $form->{Oracle_dbhost} = `hostname`;
+ $main::auth->create_tables();
+ $main::auth->set_session_value('rpw', $form->{rpw});
+ $main::auth->create_or_refresh_session();
- if (-f "css/lx-office-erp.css") {
- $myconfig->{stylesheet} = "lx-office-erp.css";
+ my $memberfile = $::lx_office_conf{paths}->{memberfile};
+ if (!-f $memberfile) {
+ # New installation -- create a standard group with full access
+ my %members;
+ my $group = {
+ 'name' => $locale->text('Full Access'),
+ 'description' => $locale->text('Full access to all functions'),
+ 'rights' => { map { $_ => 1 } SL::Auth::all_rights() },
+ 'members' => [ map { $_->{id} } values %members ],
+ };
+
+ $main::auth->save_group($group);
}
- $myconfig->{vclimit} = 200;
-
- &form_header;
- &form_footer;
+ _apply_dbupgrade_scripts();
+ login();
}
-sub edit {
+sub migrate_users {
+ $main::lxdebug->enter_sub();
- $form->{title} =
- "Lx-Office ERP "
- . $locale->text('Administration') . " / "
- . $locale->text('Edit User');
- $form->{edit} = 1;
+ my $form = $main::form;
+ my $locale = $main::locale;
- &form_header;
- &form_footer;
+ my $memberdir = "";
-}
+ my $memberfile = $::lx_office_conf{paths}->{memberfile};
+ if ($memberfile =~ m|^.*/|) {
+ $memberdir = $&;
+ }
-sub form_footer {
+ my $backupdir = "${memberdir}member-file-migration";
- if ($form->{edit}) {
- $delete =
- qq|<input type=submit class=submit name=action value="|
- . $locale->text('Delete') . qq|">
-<input type=hidden name=edit value=1>|;
+ if (! -d $backupdir && !mkdir $backupdir, 0700) {
+ $form->error(sprintf($locale->text('The directory "%s" could not be created:\n%s'), $backupdir, $!));
}
- print qq|
+ copy $memberfile, "users/member-file-migration/members";
-<input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}&root=$form->{root}&rpw=$form->{rpw}">
-<input type=hidden name=root value="$form->{root}">
-<input type=hidden name=path value=$form->{path}>
-<input type=hidden name=rpw value=$form->{rpw}>
+ my $in = IO::File->new($memberfile, "r");
-<input type=submit class=submit name=action value="|
- . $locale->text('Save') . qq|">
-$delete
+ $form->error($locale->text('Could not open the old memberfile.')) if (!$in);
-</form>
+ my (%members, $login);
-</body>
-</html>
-|;
+ while (<$in>) {
+ chomp;
-}
+ next if (m/^\s*\#/);
-sub list_users {
+ if (m/^\[.*\]/) {
+ $login = $_;
+ $login =~ s/(\[|\])//g;
+ $login =~ s/^\s*//;
+ $login =~ s/\s*$//;
- $form->error($locale->text('File locked!')) if (-f "${memberfile}.LCK");
+ $members{$login} = { "login" => $login };
+ next;
+ }
- open(FH, "$memberfile") or $form->error("$memberfile : $!");
+ if ($login && m/=/) {
+ my ($key, $value) = split m/\s*=\s*/, $_, 2;
+ $key =~ s|^\s*||;
+ $value =~ s|\s*$||;
- $nologin = qq|
-<input type=submit class=submit name=action value="|
- . $locale->text('Lock System') . qq|">|;
+ $value =~ s|\\r||g;
+ $value =~ s|\\n|\n|g;
- if (-e "$userspath/nologin") {
- $nologin = qq|
-<input type=submit class=submit name=action value="|
- . $locale->text('Unlock System') . qq|">|;
+ $members{$login}->{$key} = $value;
+ }
}
- while (<FH>) {
- chop;
+ $in->close();
- if (/^\[.*\]/) {
- $login = $_;
- $login =~ s/(\[|\])//g;
- }
+ delete $members{"root login"};
- if (/^(name=|company=|templates=|dbuser=|dbdriver=|dbname=|dbhost=)/) {
- chop($var = $&);
- ($null, $member{$login}{$var}) = split /=/, $_, 2;
- }
- }
+ map { $_->{dbpasswd} = unpack 'u', $_->{dbpasswd} } values %members;
- close(FH);
+ while (my ($login, $params) = each %members) {
+ $main::auth->save_user($login, %{ $params });
+ $main::auth->change_password($login, $params->{password}, 1);
- # type=submit $locale->text('Pg Database Administration')
- # type=submit $locale->text('Oracle Database Administration')
+ my $conf_file = "${memberdir}${login}.conf";
- foreach $item (User->dbdrivers) {
- $dbdrivers .=
- qq|<input name=action type=submit class=submit value="|
- . $locale->text("$item Database Administration") . qq|">|;
+ if (-f $conf_file) {
+ copy $conf_file, "${backupdir}/${login}.conf";
+ unlink $conf_file;
+ }
}
- $column_header{login} = qq|<th>| . $locale->text('Login') . qq|</th>|;
- $column_header{name} = qq|<th>| . $locale->text('Name') . qq|</th>|;
- $column_header{company} = qq|<th>| . $locale->text('Company') . qq|</th>|;
- $column_header{dbdriver} = qq|<th>| . $locale->text('Driver') . qq|</th>|;
- $column_header{dbhost} = qq|<th>| . $locale->text('Host') . qq|</th>|;
- $column_header{dataset} = qq|<th>| . $locale->text('Dataset') . qq|</th>|;
- $column_header{templates} =
- qq|<th>| . $locale->text('Templates') . qq|</th>|;
-
- @column_index = qw(login name company dbdriver dbhost dataset templates);
-
- $form->{title} = "Lx-Office ERP " . $locale->text('Administration');
-
- $form->header;
-
- print qq|
-<body class=admin>
-
-<form method=post action=$form->{script}>
-
-<table width=100%>
- <tr>
- <tr class=listheading>
- <th>$form->{title}</th>
- </tr>
- <tr size=5></tr>
- <tr>
- <td>
- <table width=100%>
- <tr class=listheading>|;
-
- map { print "$column_header{$_}\n" } @column_index;
-
- print qq|
- </tr>
-|;
-
- foreach $key (sort keys %member) {
- $href =
- "$script?action=edit&login=$key&path=$form->{path}&root=$form->{root}&rpw=$form->{rpw}";
- $href =~ s/ /%20/g;
-
- $member{$key}{templates} =~ s/^$templates\///;
- $member{$key}{dbhost} = $locale->text('localhost')
- unless $member{$key}{dbhost};
- $member{$key}{dbname} = $member{$key}{dbuser}
- if ($member{$key}{dbdriver} eq 'Oracle');
-
- $column_data{login} = qq|<td><a href=$href>$key</a></td>|;
- $column_data{name} = qq|<td>$member{$key}{name}</td>|;
- $column_data{company} = qq|<td>$member{$key}{company}</td>|;
- $column_data{dbdriver} = qq|<td>$member{$key}{dbdriver}</td>|;
- $column_data{dbhost} = qq|<td>$member{$key}{dbhost}</td>|;
- $column_data{dataset} = qq|<td>$member{$key}{dbname}</td>|;
- $column_data{templates} = qq|<td>$member{$key}{templates}</td>|;
-
- $i++;
- $i %= 2;
- print qq|
- <tr class=listrow$i>|;
-
- map { print "$column_data{$_}\n" } @column_index;
-
- print qq|
- </tr>|;
- }
+ unlink $memberfile;
- print qq|
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
-</table>
-
-<input type=hidden name=path value=$form->{path}>
-<input type=hidden name=rpw value=$form->{rpw}>
-<input type=hidden name=root value="$form->{root}">
-
-<br><input type=submit class=submit name=action value="|
- . $locale->text('Add User') . qq|">
-<input type=submit class=submit name=action value="|
- . $locale->text('Change Admin Password') . qq|">
-
-$dbdrivers
-$nologin
-
-</form>
-
-| . $locale->text('Click on login name to edit!') . qq|
-<br>
-|
- . $locale->text(
- 'To add a user to a group edit a name, change the login name and save. A new user with the same variables will then be saved under the new login name.'
- )
- . qq|
-
-<p>
-
-<form method=post action=login.pl>
-
-<table border=0 width=100%>
- <tr class=listheading>
- <th>Lx-Office ERP | . $locale->text('Login') . qq|</th>
- </tr>
- <tr>
- <td>
- <table>
- <tr>
- <th align=right>| . $locale->text('Name') . qq|</th>
- <td><input class=login name=login></td>
- <td> </td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Password') . qq|</th>
- <td><input class=login type=password name=password></td>
- <td><input type=submit name=action value="|
- . $locale->text('Login') . qq|"></td>
- </tr>
-<input type=hidden name=path value=$form->{path}>
- </table>
- </td>
- </tr>
-</table>
-
-</form>
-
-<hr size=3 noshade>
-
-</body>
-</html>
-|;
+ my @member_list = sort { lc $a->{login} cmp lc $b->{login} } values %members;
+ $form->{title} = $locale->text('User data migration');
+ $form->header();
+ print $form->parse_html_template('admin/user_migration_done', { 'MEMBERS' => \@member_list });
+
+ $main::lxdebug->leave_sub();
}
-sub form_header {
+sub create_standard_group_ask {
+ my $form = $main::form;
+ my $locale = $main::locale;
- # if there is a login, get user
- if ($form->{login}) {
+ $form->{title} = $locale->text('Create a standard group');
- # get user
- $myconfig = new User "$memberfile", "$form->{login}";
+ $form->header();
+ print $form->parse_html_template("admin/create_standard_group_ask");
+}
- $myconfig->{signature} =~ s/\\n/\r\n/g;
- $myconfig->{address} =~ s/\\n/\r\n/g;
+sub create_standard_group {
+ my $form = $main::form;
+ my $locale = $main::locale;
- # strip basedir from templates directory
- $myconfig->{templates} =~ s/^$templates\///;
+ my %members = $main::auth->read_all_users();
- # $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd};
- }
+ my $groups = $main::auth->read_groups();
- foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
- $dateformat .=
- ($item eq $myconfig->{dateformat})
- ? "<option selected>$item\n"
- : "<option>$item\n";
+ foreach my $group (values %{$groups}) {
+ if (($form->{group_id} != $group->{id})
+ && ($form->{name} eq $group->{name})) {
+ $form->show_generic_error($locale->text("A group with that name does already exist."));
+ }
}
- foreach $item (qw(1,000.00 1000.00 1.000,00 1000,00)) {
- $numberformat .=
- ($item eq $myconfig->{numberformat})
- ? "<option selected>$item\n"
- : "<option>$item\n";
- }
+ my $group = {
+ 'name' => $locale->text('Full Access'),
+ 'description' => $locale->text('Full access to all functions'),
+ 'rights' => { map { $_ => 1 } SL::Auth::all_rights() },
+ 'members' => [ map { $_->{id} } values %members ],
+ };
- %countrycodes = User->country_codes;
- $countrycodes = "";
- foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} }
- keys %countrycodes
- ) {
- $countrycodes .=
- ($myconfig->{countrycode} eq $key)
- ? "<option selected value=$key>$countrycodes{$key}"
- : "<option value=$key>$countrycodes{$key}";
- }
- $countrycodes = qq|<option value="">American English\n$countrycodes|;
+ $main::auth->save_group($group);
- # is there a templates basedir
- if (!-d "$templates") {
- $form->error( $locale->text('Directory')
- . ": $templates "
- . $locale->text('does not exist'));
- }
+ user_migration_complete(1);
+}
- opendir TEMPLATEDIR, "$templates/." or $form->error("$templates : $!");
- @all = grep !/^\.\.?$/, readdir TEMPLATEDIR;
- closedir TEMPLATEDIR;
+sub dont_create_standard_group {
+ user_migration_complete(0);
+}
- @allhtml = sort grep /\.html/, @all;
- @alldir = grep !/\.(html|tex)$/, @all;
+sub user_migration_complete {
+ my $standard_group_created = shift;
- @allhtml = reverse grep !/Default/, @allhtml;
- push @allhtml, 'Default';
- @allhtml = reverse @allhtml;
+ my $form = $main::form;
+ my $locale = $main::locale;
- foreach $item (@alldir) {
- if ($item eq $myconfig->{templates}) {
- $usetemplates .= qq|<option selected>$item\n|;
- } else {
- $usetemplates .= qq|<option>$item\n|;
- }
- }
+ $form->{title} = $locale->text('User migration complete');
+ $form->header();
- $lastitem = $allhtml[0];
- $lastitem =~ s/-.*//g;
- $mastertemplates = qq|<option>$lastitem\n|;
- foreach $item (@allhtml) {
- $item =~ s/-.*//g;
+ print $form->parse_html_template('admin/user_migration_complete', { 'standard_group_created' => $standard_group_created });
+}
- if ($item ne $lastitem) {
- $mastertemplates .= qq|<option>$item\n|;
- $lastitem = $item;
- }
- }
+sub list_users {
+ my $form = $main::form;
+ my $locale = $main::locale;
- opendir CSS, "css/.";
- @all = grep /.*\.css$/, readdir CSS;
- closedir CSS;
+ my %members = $main::auth->read_all_users();
- foreach $item (@all) {
- if ($item eq $myconfig->{stylesheet}) {
- $selectstylesheet .= qq|<option selected>$item\n|;
- } else {
- $selectstylesheet .= qq|<option>$item\n|;
- }
- }
- $selectstylesheet .= "<option>\n";
-
- $form->header;
-
- if ($myconfig->{menustyle} eq "neu") { $neu = "checked"; }
- else { $old = "checked"; }
-
- print qq|
-<body class=admin>
-
-<form method=post action=$form->{script}>
-
-<table width=100%>
- <tr class=listheading><th colspan=2>$form->{title}</th></tr>
- <tr size=5></tr>
- <tr valign=top>
- <td>
- <table>
- <tr>
- <th align=right>| . $locale->text('Login') . qq|</th>
- <td><input name=login value="$myconfig->{login}"></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Password') . qq|</th>
- <td><input type=password name=password size=8 value=$myconfig->{password}></td>
- <input type=hidden name=old_password value=$myconfig->{password}>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Name') . qq|</th>
- <td><input name=name size=15 value="$myconfig->{name}"></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('E-mail') . qq|</th>
- <td><input name=email size=30 value="$myconfig->{email}"></td>
- </tr>
- <tr valign=top>
- <th align=right>| . $locale->text('Signature') . qq|</th>
- <td><textarea name=signature rows=3 cols=35>$myconfig->{signature}</textarea></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Phone') . qq|</th>
- <td><input name=tel size=14 value="$myconfig->{tel}"></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Fax') . qq|</th>
- <td><input name=fax size=14 value="$myconfig->{fax}"></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Company') . qq|</th>
- <td><input name=company size=35 value="$myconfig->{company}"></td>
- </tr>
- <tr valign=top>
- <th align=right>| . $locale->text('Address') . qq|</th>
- <td><textarea name=address rows=4 cols=35>$myconfig->{address}</textarea></td>
- </tr>
- <tr valign=top>
- <th align=right>| . $locale->text('Steuernummer') . qq|</th>
- <td><input name=steuernummer size=14 value="$myconfig->{steuernummer}"></td>
- </tr>
- <tr valign=top>
- <th align=right>| . $locale->text('Ust-IDNr') . qq|</th>
- <td><input name=co_ustid size=14 value="$myconfig->{co_ustid}"></td>
- </tr>
- <tr valign=top>
- <th align=right>| . $locale->text('DUNS-Nr') . qq|</th>
- <td><input name=duns size=14 value="$myconfig->{duns}"></td>
- </tr>
- </table>
- </td>
- <td>
- <table>
- <tr>
- <th align=right>| . $locale->text('Date Format') . qq|</th>
- <td><select name=dateformat>$dateformat</select></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Number Format') . qq|</th>
- <td><select name=numberformat>$numberformat</select></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Dropdown Limit') . qq|</th>
- <td><input name=vclimit value="$myconfig->{vclimit}"></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Language') . qq|</th>
- <td><select name=countrycode>$countrycodes</select></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Character Set') . qq|</th>
- <td><input name=charset value="$myconfig->{charset}"></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Stylesheet') . qq|</th>
- <td><select name=userstylesheet>$selectstylesheet</select></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Printer') . qq|</th>
- <td><input name=printer size=20 value="$myconfig->{printer}"></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Use Templates') . qq|</th>
- <td><select name=usetemplates>$usetemplates</select></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('New Templates') . qq|</th>
- <td><input name=newtemplates></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Setup Templates') . qq|</th>
- <td><select name=mastertemplates>$mastertemplates</select></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Setup Menu') . qq|</th>
- <td><input name=menustyle type=radio class=radio value=neu $neu> New
- <input name=menustyle type=radio class=radio value=old $old> Old</td>
- </tr>
- <input type=hidden name=templates value=$myconfig->{templates}>
- </table>
- </td>
- </tr>
- <tr class=listheading>
- <th colspan=2>| . $locale->text('Database') . qq|</th>
- </tr>|;
-
- # list section for database drivers
- foreach $item (User->dbdrivers) {
-
- print qq|
- <tr>
- <td colspan=2>
- <table>
- <tr>|;
-
- $checked = "";
- if ($myconfig->{dbdriver} eq $item) {
- map { $form->{"${item}_$_"} = $myconfig->{$_} }
- qw(dbhost dbport dbuser dbpasswd dbname sid);
- $checked = "checked";
- }
+ delete $members{"root login"};
- print qq|
- <th align=right>| . $locale->text('Driver') . qq|</th>
- <td><input name=dbdriver type=radio class=radio value=$item $checked> $item</td>
- <th align=right>| . $locale->text('Host') . qq|</th>
- <td><input name="${item}_dbhost" size=30 value=$form->{"${item}_dbhost"}></td>
- </tr>
- <tr>|;
-
- if ($item eq 'Pg') {
- print qq|
- <th align=right>| . $locale->text('Dataset') . qq|</th>
- <td><input name=Pg_dbname size=15 value=$form->{Pg_dbname}></td>
- <th align=right>| . $locale->text('Port') . qq|</th>
- <td><input name=Pg_dbport size=4 value=$form->{Pg_dbport}></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('User') . qq|</th>
- <td><input name="${item}_dbuser" size=15 value=$form->{"${item}_dbuser"}></td>
- <th align=right>| . $locale->text('Password') . qq|</th>
- <td><input name="${item}_dbpasswd" type=password size=10 value=$form->{"${item}_dbpasswd"}></td>
- </tr>|;
+ map { $_->{templates} =~ s|.*/||; } values %members;
- }
+ $form->{title} = "Lx-Office ERP " . $locale->text('Administration');
+ $form->{LOCKED} = -e _nologin_file_name();
+ $form->{MEMBERS} = [ @members{sort { lc $a cmp lc $b } keys %members} ];
- if ($item eq 'Oracle') {
- print qq|
- <th align=right>SID</th>
- <td><input name=Oracle_sid value=$form->{Oracle_sid}></td>
- <th align=right>| . $locale->text('Port') . qq|</th>
- <td><input name=Oracle_dbport size=4 value=$form->{Oracle_dbport}></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Dataset') . qq|</th>
- <td><input name="${item}_dbuser" size=15 value=$form->{"${item}_dbuser"}></td>
- <th align=right>| . $locale->text('Password') . qq|</th>
- <td><input name="${item}_dbpasswd" type=password size=10 value=$form->{"${item}_dbpasswd"}></td>
-
- </tr>|;
- }
+ $form->header();
+ print $form->parse_html_template("admin/list_users");
+}
- print qq|
- <input type=hidden name=old_dbpasswd value=$myconfig->{dbpasswd}>
- </table>
- </td>
- </tr>
- <tr>
- <td colspan=2><hr size=2 noshade></td>
- </tr>
-|;
+sub add_user {
+ my $form = $main::form;
+ my $locale = $main::locale;
+
+ $form->{title} = "Lx-Office ERP " . $locale->text('Administration') . " / " . $locale->text('Add User');
+
+# Note: Menu Style 'v3' is not compatible to all browsers!
+# "menustyle" => "old" sets the HTML Menu to default.
+ my $myconfig = {
+ "vclimit" => 200,
+ "countrycode" => "de",
+ "numberformat" => "1.000,00",
+ "dateformat" => "dd.mm.yy",
+ "stylesheet" => "lx-office-erp.css",
+ "menustyle" => "old",
+ dbport => $::auth->{DB_config}->{port} || 5432,
+ dbuser => $::auth->{DB_config}->{user} || 'lxoffice',
+ dbhost => $::auth->{DB_config}->{host} || 'localhost',
+ };
+
+
+ edit_user_form($myconfig);
+}
- }
+sub edit_user {
+ my $form = $main::form;
+ my $locale = $main::locale;
- # access control
- open(FH, $menufile) or $form->error("$menufile : $!");
+ $form->{title} = "Lx-Office ERP " . $locale->text('Administration') . " / " . $locale->text('Edit User');
+ $form->{edit} = 1;
- # scan for first menu level
- @a = <FH>;
- close(FH);
+ $form->isblank("login", $locale->text("The login is missing."));
- if (open(FH, "custom_$menufile")) {
- push @a, <FH>;
- }
- close(FH);
+ # get user
+ my $myconfig = new User($form->{login});
- foreach $item (@a) {
- next unless $item =~ /\[/;
- next if $item =~ /\#/;
+ # strip basedir from templates directory
+ $myconfig->{templates} =~ s|.*/||;
- $item =~ s/(\[|\])//g;
- chop $item;
+ edit_user_form($myconfig);
+}
- if ($item =~ /--/) {
- ($level, $menuitem) = split /--/, $item, 2;
- } else {
- $level = $item;
- $menuitem = $item;
- push @acsorder, $item;
- }
+sub edit_user_form {
+ my ($myconfig) = @_;
- push @{ $acs{$level} }, $menuitem;
+ my $form = $main::form;
+ my $locale = $main::locale;
- }
+ my @valid_dateformats = qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd);
+ $form->{ALL_DATEFORMATS} = [ map { { "format" => $_, "selected" => $_ eq $myconfig->{dateformat} } } @valid_dateformats ];
+
+ my @valid_numberformats = ('1,000.00', '1000.00', '1.000,00', '1000,00');
+ $form->{ALL_NUMBERFORMATS} = [ map { { "format" => $_, "selected" => $_ eq $myconfig->{numberformat} } } @valid_numberformats ];
- %role = ('admin' => $locale->text('Administrator'),
- 'user' => $locale->text('User'),
- 'manager' => $locale->text('Manager'),
- 'supervisor' => $locale->text('Supervisor'));
-
- $selectrole = "";
- foreach $item (qw(user supervisor manager admin)) {
- $selectrole .=
- ($myconfig->{role} eq $item)
- ? "<option selected value=$item>$role{$item}\n"
- : "<option value=$item>$role{$item}\n";
+ my %countrycodes = User->country_codes;
+ $form->{ALL_COUNTRYCODES} = [];
+ foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
+ push @{ $form->{ALL_COUNTRYCODES} }, { "value" => $countrycode,
+ "name" => $countrycodes{$countrycode},
+ "selected" => $countrycode eq $myconfig->{countrycode} };
}
- print qq|
- <tr class=listheading>
- <th colspan=2>| . $locale->text('Access Control') . qq|</th>
- </tr>
- <tr>
- <td><select name=role>$selectrole</select></td>
- </tr>
-|;
-
- foreach $item (split /;/, $myconfig->{acs}) {
- ($key, $value) = split /--/, $item, 2;
- $excl{$key}{$value} = 1;
+ # is there a templates basedir
+ if (!-d $::lx_office_conf{paths}->{templates}) {
+ $form->error(sprintf($locale->text("The directory %s does not exist."), $::lx_office_conf{paths}->{templates}));
}
- foreach $key (@acsorder) {
+ opendir TEMPLATEDIR, $::lx_office_conf{paths}->{templates} or $form->error($::lx_office_conf{paths}->{templates} . " : $ERRNO");
+ my @all = readdir(TEMPLATEDIR);
+ my @alldir = sort grep { -d ($::lx_office_conf{paths}->{templates} . "/$_") && !/^\.\.?$/ } @all;
+ my @allhtml = sort grep { -f ($::lx_office_conf{paths}->{templates} . "/$_") && /\.html$/ } @all;
+ closedir TEMPLATEDIR;
- $checked = "checked";
- if ($form->{login}) {
- $checked = ($excl{$key}{$key}) ? "" : "checked";
- }
+ @alldir = grep !/\.(html|tex|sty|odt|xml|txb)$/, @alldir;
+ @alldir = grep !/^(webpages|\.svn)$/, @alldir;
- # can't have variable names with spaces
- # the 1 is for apache 2
- $item = $form->escape("${key}--$key", 1);
+ @allhtml = reverse grep !/Default/, @allhtml;
+ push @allhtml, 'Default';
+ @allhtml = reverse @allhtml;
- $acsheading = $key;
- $acsheading =~ s/ / /g;
+ $form->{ALL_TEMPLATES} = [ map { { "name", => $_, "selected" => $_ eq $myconfig->{templates} } } @alldir ];
- $acsheading = qq|
- <th align=left><input name="$item" class=checkbox type=checkbox value=1 $checked> $acsheading</th>\n|;
- $menuitems .= "$item;";
- $acsdata = "
- <td>";
+ my $lastitem = $allhtml[0];
+ $lastitem =~ s/-.*//g;
+ $form->{ALL_MASTER_TEMPLATES} = [ { "name" => $lastitem, "selected" => $lastitem eq "German" } ];
+ foreach my $item (@allhtml) {
+ $item =~ s/-.*//g;
+ next if ($item eq $lastitem);
- foreach $item (@{ $acs{$key} }) {
- next if ($key eq $item);
+ push @{ $form->{ALL_MASTER_TEMPLATES} }, { "name" => $item, "selected" => $item eq "German" };
+ $lastitem = $item;
+ }
- $checked = "checked";
- if ($form->{login}) {
- $checked = ($excl{$key}{$item}) ? "" : "checked";
- }
+ # css dir has styles that are not intended as general layouts.
+ # reverting to hardcoded list
+ $form->{ALL_STYLESHEETS} = [ map { { "name" => $_, "selected" => $_ eq $myconfig->{stylesheet} } } qw(lx-office-erp.css Win2000.css) ];
- $acsitem = $form->escape("${key}--$item", 1);
+ $form->{"menustyle_" . $myconfig->{menustyle} } = 1;
- $acsdata .= qq|
- <br><input name="$acsitem" class=checkbox type=checkbox value=1 $checked> $item|;
- $menuitems .= "$acsitem;";
- }
+ map { $form->{"myc_${_}"} = $myconfig->{$_} } keys %{ $myconfig };
- $acsdata .= "
- </td>";
+ my $groups = [];
- print qq|
- <tr valign=top>$acsheading $acsdata
- </tr>
-|;
- }
+ if ($form->{edit}) {
+ my $user_id = $main::auth->get_user_id($form->{login});
+ my $all_groups = $main::auth->read_groups();
- print qq|<input type=hidden name=acs value="$menuitems">
-|;
- if ($webdav) {
- @webdavdirs =
- qw(angebote bestellungen rechnungen anfragen lieferantenbestellungen einkaufsrechnungen);
- foreach $directory (@webdavdirs) {
- if ($myconfig->{$directory}) {
- $webdav{"${directory}c"} = "checked";
- } else {
- $webdav{"${directory}c"} = "";
- }
+ foreach my $group (values %{ $all_groups }) {
+ push @{ $groups }, $group if (grep { $user_id == $_ } @{ $group->{members} });
}
- print qq|
- <tr>
- <td colspan=2><hr size=3 noshade></td>
- </tr>
- <tr class=listheading>
- <th colspan=2>| . $locale->text('WEBDAV-Zugriff') . qq|</th>
- </tr>
- <table width=100%>
- <tr>
- <td><input name=angebote class=checkbox type=checkbox value=1 $webdav{angebotec}> Angebot</td>
- <td><input name=bestellungen class=checkbox type=checkbox value=1 $webdav{bestellungenc}> Bestellung</td>
- <td><input name=rechnungen class=checkbox type=checkbox value=1 $webdav{rechnungenc}> Rechnung</td>
- </tr>
- <tr>
- <td><input name=anfragen class=checkbox type=checkbox value=1 $webdav{anfragenc}> Angebot</td>
- <td><input name=lieferantenbestellungen class=checkbox type=checkbox value=1 $webdav{lieferantenbestellungenc}> Lieferantenbestellung</td>
- <td><input name=einkaufsrechnungen class=checkbox type=checkbox value=1 $webdav{einkaufsrechnungenc}> Einkaufsrechnung</td>
- </tr>
- </table>
- <tr>
- <td colspan=2><hr size=3 noshade></td>
- </tr>
-|;
+
+ $groups = [ sort { lc $a->{name} cmp lc $b->{name} } @{ $groups } ];
}
- print qq|
-</table>
-</div>
-|;
+ $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
+
+ $form->header();
+ print $form->parse_html_template("admin/edit_user", { 'GROUPS' => $groups });
}
-sub save {
+sub save_user {
+ my $form = $main::form;
+ my $locale = $main::locale;
- # no driver checked
- $form->error($locale->text('Database Driver not checked!'))
- unless $form->{dbdriver};
+ $form->{dbdriver} = 'Pg';
# no spaces allowed in login name
- ($form->{login}) = split / /, $form->{login};
-
+ $form->{login} =~ s|\s||g;
$form->isblank("login", $locale->text('Login name missing!'));
# check for duplicates
if (!$form->{edit}) {
- $temp = new User "$memberfile", "$form->{login}";
-
- if ($temp->{login}) {
- $form->error("$form->{login} " . $locale->text('is already a member!'));
+ my %members = $main::auth->read_all_users();
+ if ($members{$form->{login}}) {
+ $form->show_generic_error($locale->text('Another user with the login #1 does already exist.', $form->{login}), 'back_button' => 1);
}
}
}
# is there a basedir
- if (!-d "$templates") {
- $form->error( $locale->text('Directory')
- . ": $templates "
- . $locale->text('does not exist'));
+ if (!-d $::lx_office_conf{paths}->{templates}) {
+ $form->error(sprintf($locale->text("The directory %s does not exist."), $::lx_office_conf{paths}->{templates}));
}
# add base directory to $form->{templates}
- $form->{templates} = "$templates/$form->{templates}";
+ $form->{templates} =~ s|.*/||;
+ $form->{templates} = $::lx_office_conf{paths}->{templates} . "/$form->{templates}";
- $myconfig = new User "$memberfile", "$form->{login}";
+ my $myconfig = new User($form->{login});
- # redo acs variable and delete all the acs codes
- @acs = split /;/, $form->{acs};
+ $form->isblank("dbname", $locale->text('Dataset missing!'));
+ $form->isblank("dbuser", $locale->text('Database User missing!'));
- $form->{acs} = "";
- foreach $item (@acs) {
- $item = $form->escape($item, 1);
-
- if (!$form->{$item}) {
- $form->{acs} .= $form->unescape($form->unescape($item)) . ";";
- }
- delete $form->{$item};
- }
-
- # check which database was filled in
- if ($form->{dbdriver} eq 'Oracle') {
- $form->{sid} = $form->{Oracle_sid},;
- $form->{dbhost} = $form->{Oracle_dbhost},;
- $form->{dbport} = $form->{Oracle_dbport};
- $form->{dbpasswd} = $form->{Oracle_dbpasswd};
- $form->{dbuser} = $form->{Oracle_dbuser};
- $form->{dbname} = $form->{Oracle_dbuser};
-
- $form->isblank("dbhost", $locale->text('Hostname missing!'));
- $form->isblank("dbport", $locale->text('Port missing!'));
- $form->isblank("dbuser", $locale->text('Dataset missing!'));
- }
- if ($form->{dbdriver} eq 'Pg') {
- $form->{dbhost} = $form->{Pg_dbhost};
- $form->{dbport} = $form->{Pg_dbport};
- $form->{dbpasswd} = $form->{Pg_dbpasswd};
- $form->{dbuser} = $form->{Pg_dbuser};
- $form->{dbname} = $form->{Pg_dbname};
-
- $form->isblank("dbname", $locale->text('Dataset missing!'));
- $form->isblank("dbuser", $locale->text('Database User missing!'));
- }
-
- if ($webdav) {
- @webdavdirs =
- qw(angebote bestellungen rechnungen anfragen lieferantenbestellungen einkaufsrechnungen);
- foreach $directory (@webdavdirs) {
- if ($form->{$directory}) {
- $form->{$directory} = $form->{$directory};
- } else {
- $form->{$directory} = 0;
- }
- }
- }
-
- foreach $item (keys %{$form}) {
+ foreach my $item (keys %{$form}) {
$myconfig->{$item} = $form->{$item};
}
$myconfig->{stylesheet} = $form->{userstylesheet};
}
- $myconfig->save_member($memberfile, $userspath);
-
- if ($webdav) {
- @webdavdirs =
- qw(angebote bestellungen rechnungen anfragen lieferantenbestellungen einkaufsrechnungen);
- foreach $directory (@webdavdirs) {
- $file = "webdav/" . $directory . "/webdav-user";
- if ($form->{$directory}) {
- if (open(HTACCESS, "$file")) {
- while (<HTACCESS>) {
- ($login, $password) = split(/:/, $_);
- if ($login ne $form->{login}) {
- $newfile .= $_;
- }
- }
- close(HTACCESS);
- }
- open(HTACCESS, "> $file") or die "cannot open $file $!\n";
- $newfile .= $myconfig->{login} . ":" . $myconfig->{password} . "\n";
- print(HTACCESS $newfile);
- close(HTACCESS);
- } else {
- $form->{$directory} = 0;
- if (open(HTACCESS, "$file")) {
- while (<HTACCESS>) {
- ($login, $password) = split(/:/, $_);
- if ($login ne $form->{login}) {
- $newfile .= $_;
- }
- }
- close(HTACCESS);
- }
- open(HTACCESS, "> $file") or die "cannot open $file $!\n";
- print(HTACCESS $newfile);
- close(HTACCESS);
- }
- }
- }
+ $myconfig->save_member();
+
+ $form->{templates} =~ s|.*/||;
+ $form->{templates} = $::lx_office_conf{paths}->{templates} . "/$form->{templates}";
+ $form->{mastertemplates} =~ s|.*/||;
# create user template directory and copy master files
if (!-d "$form->{templates}") {
umask(007);
# copy templates to the directory
- opendir TEMPLATEDIR, "$templates/." or $form - error("$templates : $!");
- @templates = grep /$form->{mastertemplates}.*?\.(html|tex)$/,
+ opendir TEMPLATEDIR, $::lx_office_conf{paths}->{templates} or $form->error($::lx_office_conf{paths}->{templates} . " : $ERRNO");
+ my @templates = grep /$form->{mastertemplates}.*?\.(html|tex|sty|odt|xml|txb)$/,
readdir TEMPLATEDIR;
closedir TEMPLATEDIR;
- foreach $file (@templates) {
- open(TEMP, "$templates/$file")
- or $form->error("$templates/$file : $!");
+ foreach my $file (@templates) {
+ open(TEMP, $::lx_office_conf{paths}->{templates} . "/$file")
+ or $form->error($::lx_office_conf{paths}->{templates} . "/$file : $ERRNO");
- $file =~ s/$form->{mastertemplates}-//;
+ $file =~ s/\Q$form->{mastertemplates}\E-//;
open(NEW, ">$form->{templates}/$file")
- or $form->error("$form->{templates}/$file : $!");
+ or $form->error("$form->{templates}/$file : $ERRNO");
- while ($line = <TEMP>) {
+ while (my $line = <TEMP>) {
print NEW $line;
}
close(TEMP);
close(NEW);
}
} else {
- $form->error("$!: $form->{templates}");
+ $form->error("$ERRNO: $form->{templates}");
}
}
- $form->redirect($locale->text('User saved!'));
+ # Add new user to his groups.
+ if (ref $form->{new_user_group_ids} eq 'ARRAY') {
+ my $all_groups = $main::auth->read_groups();
+ my %user = $main::auth->read_user($form->{login});
-}
+ foreach my $group_id (@{ $form->{new_user_group_ids} }) {
+ my $group = $all_groups->{$group_id};
-sub delete {
-
- $form->{templates} =
- ($form->{templates})
- ? "$templates/$form->{templates}"
- : "$templates/$form->{login}";
-
- $form->error($locale->text('File locked!')) if (-f ${memberfile} . LCK);
- open(FH, ">${memberfile}.LCK") or $form->error("${memberfile}.LCK : $!");
- close(FH);
-
- open(CONF, "+<$memberfile") or $form->error("$memberfile : $!");
+ next if !$group;
- @config = <CONF>;
-
- seek(CONF, 0, 0);
- truncate(CONF, 0);
-
- while ($line = shift @config) {
-
- if ($line =~ /^\[/) {
- last if ($line =~ /\[$form->{login}\]/);
- $login = &login_name($line);
+ push @{ $group->{members} }, $user{id};
+ $main::auth->save_group($group);
}
+ }
- if ($line =~ /^templates=/) {
- $user{$login} = &get_value($line);
+ if ($main::auth->can_change_password()
+ && defined $form->{new_password}
+ && ($form->{new_password} ne '********')) {
+ my $verifier = SL::Auth::PasswordPolicy->new;
+ my $result = $verifier->verify($form->{new_password}, 1);
+
+ if ($result != SL::Auth::PasswordPolicy->OK()) {
+ $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
}
- print CONF $line;
+ $main::auth->change_password($form->{login}, $form->{new_password});
}
- # remove everything up to next login or EOF
- # and save template variable
- while ($line = shift @config) {
- if ($line =~ /^templates=/) {
- $templatedir = &get_value($line);
- }
- last if ($line =~ /^\[/);
- }
+ $form->redirect($locale->text('User saved!'));
+}
- # this one is either the next login or EOF
- print CONF $line;
+sub save_user_as_new {
+ my $form = $main::form;
- $login = &login_name($line);
+ $form->{login} = $form->{new_user_login};
+ delete @{$form}{qw(edit new_user_login)};
- while ($line = shift @config) {
- if ($line =~ /^\[/) {
- $login = &login_name($line);
- }
+ save_user();
+}
- if ($line =~ /^templates=/) {
- $user{$login} = &get_value($line);
- }
+sub delete_user {
+ my $form = $main::form;
+ my $locale = $main::locale;
- print CONF $line;
- }
+ my %members = $main::auth->read_all_users();
+ my $templates = $members{$form->{login}}->{templates};
- close(CONF);
- unlink "${memberfile}.LCK";
+ $main::auth->delete_user($form->{login});
- # scan %user for $templatedir
- foreach $login (keys %user) {
- last if ($found = ($templatedir eq $user{$login}));
- }
+ if ($templates) {
+ my $templates_in_use = 0;
- # if found keep directory otherwise delete
- if (!$found) {
+ foreach my $login (keys %members) {
+ next if $form->{login} eq $login;
+ next if $members{$login}->{templates} ne $templates;
+ $templates_in_use = 1;
+ last;
+ }
- # delete it if there is a template directory
- $dir = "$form->{templates}";
- if (-d "$dir") {
- unlink <$dir/*.html>;
- unlink <$dir/*.tex>;
- rmdir "$dir";
+ if (!$templates_in_use && -d $templates) {
+ unlink <$templates/*>;
+ rmdir $templates;
}
}
- # delete config file for user
- unlink "$userspath/$form->{login}.conf";
-
$form->redirect($locale->text('User deleted!'));
}
}
sub get_value {
- my $line = shift;
-
+ my $line = shift;
my ($null, $value) = split(/=/, $line, 2);
# remove comments
$value;
}
-sub change_admin_password {
-
- $form->{title} =
- qq|Lx-Office ERP |
- . $locale->text('Administration') . " / "
- . $locale->text('Change Admin Password');
-
- $form->header;
-
- print qq|
-<body class=admin>
-
-
-<h2>| . $locale->text('Change Admin Password') . qq|</h2>
+sub pg_database_administration {
+ my $form = $main::form;
-<form method=post action=$form->{script}>
+ $form->{dbdriver} = 'Pg';
+ dbselect_source();
-<b>|
- . $locale->text('Password')
- . qq|</b> <input type=password name=password size=8>
+}
-<input type=hidden name=root value="$form->{root}">
-<input type=hidden name=path value=$form->{path}>
-<input type=hidden name=rpw value=$form->{rpw}>
+sub dbselect_source {
+ my $form = $main::form;
+ my $locale = $main::locale;
-<p>
-<input type=submit class=submit name=action value="|
- . $locale->text('Change Password') . qq|">
+ $form->{dbport} = $::auth->{DB_config}->{port} || 5432;
+ $form->{dbuser} = $::auth->{DB_config}->{user} || 'lxoffice';
+ $form->{dbdefault} = 'template1';
+ $form->{dbhost} = $::auth->{DB_config}->{host} || 'localhost';
-</form>
+ $form->{title} = "Lx-Office ERP / " . $locale->text('Database Administration');
-</body>
-</html>
-|;
+ # Intentionnaly disabled unless fixed to work with the authentication DB.
+ $form->{ALLOW_DBBACKUP} = 0; # "$pg_dump_exe" ne "DISABLED";
+ $form->header();
+ print $form->parse_html_template("admin/dbadmin");
}
-sub change_password {
+sub test_db_connection {
+ my $form = $main::form;
+ my $locale = $main::locale;
- $root->{password} = $form->{password};
+ $form->{dbdriver} = 'Pg';
+ User::dbconnect_vars($form, $form->{dbname});
- $root->{'root login'} = 1;
- $root->save_member($memberfile);
+ my $dbh = DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd});
- $form->{callback} =
- "$form->{script}?action=list_users&path=$form->{path}&root=$form->{root}&rpw=$root->{password}";
+ $form->{connection_ok} = $dbh ? 1 : 0;
+ $form->{errstr} = $DBI::errstr;
- $form->redirect($locale->text('Password changed!'));
+ $dbh->disconnect() if ($dbh);
+ $form->{title} = $locale->text('Database Connection Test');
+ $form->header();
+ print $form->parse_html_template("admin/test_db_connection");
}
-sub check_password {
-
- $root = new User "$memberfile", $form->{root};
-
- if ($root->{password}) {
- if ($root->{password} ne $form->{rpw}) {
- $form->error($locale->text('Incorrect Password!'));
- }
- }
-
+sub continue {
+ call_sub($main::form->{"nextsub"});
}
-sub pg_database_administration {
-
- $form->{dbdriver} = 'Pg';
- &dbselect_source;
-
-}
+sub update_dataset {
+ my $form = $main::form;
+ my $locale = $main::locale;
-sub oracle_database_administration {
+ $form->{title} = "Lx-Office ERP " . $locale->text('Database Administration') . " / " . $locale->text('Update Dataset');
- $form->{dbdriver} = 'Oracle';
- &dbselect_source;
+ my @need_updates = User->dbneedsupdate($form);
+ $form->{NEED_UPDATES} = \@need_updates;
+ $form->{ALL_UPDATED} = !scalar @need_updates;
+ $form->header();
+ print $form->parse_html_template("admin/update_dataset");
}
-sub dbdriver_defaults {
-
- # load some defaults for the selected driver
- %driverdefaults = (
- 'Pg' => { dbport => '5432',
- dbuser => 'postgres',
- dbdefault => 'template1',
- dbhost => 'localhost',
- connectstring => $locale->text('Connect to')
- },
- 'Oracle' => { dbport => '1521',
- dbuser => 'oralin',
- dbdefault => $sid,
- dbhost => `hostname`,
- connectstring => 'SID'
- });
-
- map { $form->{$_} = $driverdefaults{ $form->{dbdriver} }{$_} }
- keys %{ $driverdefaults{Pg} };
-
-}
+sub dbupdate {
+ my $form = $main::form;
+ my $locale = $main::locale;
-sub dbselect_source {
+ $form->{stylesheet} = "lx-office-erp.css";
+ $form->{title} = $locale->text("Dataset upgrade");
+ $form->header();
- &dbdriver_defaults;
+ my $rowcount = $form->{rowcount} * 1;
+ my @update_rows = grep { $form->{"update_$_"} } (1 .. $rowcount);
+ $form->{NOTHING_TO_DO} = !scalar @update_rows;
+ my $saved_form = save_form();
- $msg{Pg} =
- $locale->text(
- 'Leave host and port field empty unless you want to make a remote connection.'
- );
- $msg{Oracle} =
- $locale->text(
- 'You must enter a host and port for local and remote connections!');
+ $| = 1;
- $form->{title} =
- "Lx-Office ERP / " . $locale->text('Database Administration');
+ print $form->parse_html_template("admin/dbupgrade_all_header");
- $form->header;
+ foreach my $i (@update_rows) {
+ restore_form($saved_form);
- print qq|
-<body class=admin>
+ map { $form->{$_} = $form->{"${_}_${i}"} } qw(dbname dbdriver dbhost dbport dbuser dbpasswd);
+ print $form->parse_html_template("admin/dbupgrade_header");
-<center>
-<h2>$form->{title}</h2>
+ $form->{dbupdate} = $form->{dbname};
+ $form->{$form->{dbname}} = 1;
-<form method=post action=$form->{script}>
+ User->dbupdate($form);
+ User->dbupdate2($form, SL::DBUpgrade2->new(form => $form, dbdriver => $form->{dbdriver})->parse_dbupdate_controls);
-<table>
-<tr><td>
+ print $form->parse_html_template("admin/dbupgrade_footer");
+ }
-<table>
+ print $form->parse_html_template("admin/dbupgrade_all_done");
+}
- <tr class=listheading>
- <th colspan=4>| . $locale->text('Database') . qq|</th>
- </tr>
+sub create_dataset {
+ my $form = $main::form;
+ my $locale = $main::locale;
-<input type=hidden name=dbdriver value=$form->{dbdriver}>
+ $form->{dbsources} = join " ", map { "[${_}]" } sort User->dbsources($form);
- <tr><td>
- <table>
+ $form->{CHARTS} = [];
- <tr>
+ opendir SQLDIR, "sql/." or $form->error($ERRNO);
+ foreach my $item (sort grep /-chart\.sql\z/, readdir SQLDIR) {
+ next if ($item eq 'Default-chart.sql');
+ $item =~ s/-chart\.sql//;
+ push @{ $form->{CHARTS} }, { "name" => $item,
+ "selected" => $item eq "Germany-DATEV-SKR03EU" };
+ }
+ closedir SQLDIR;
- <th align=right>| . $locale->text('Host') . qq|</th>
- <td><input name=dbhost size=25 value=$form->{dbhost}></td>
- <th align=right>| . $locale->text('Port') . qq|</th>
- <td><input name=dbport size=5 value=$form->{dbport}></td>
+ my $default_charset = $::lx_office_conf{system}->{dbcharset};
+ $default_charset ||= Common::DEFAULT_CHARSET;
- </tr>
+ my $cluster_encoding = User->dbclusterencoding($form);
+ if ($cluster_encoding && ($cluster_encoding =~ m/^(?:UTF-?8|UNICODE)$/i)) {
+ if ($::lx_office_conf{system}->{dbcharset} !~ m/^UTF-?8$/i) {
+ $form->show_generic_error($locale->text('The selected PostgreSQL installation uses UTF-8 as its encoding. ' .
+ 'Therefore you have to configure Lx-Office to use UTF-8 as well.'),
+ 'back_button' => 1);
+ }
- <tr>
+ $form->{FORCE_DBENCODING} = 'UNICODE';
- <th align=right>| . $locale->text('User') . qq|</th>
- <td><input name=dbuser size=10 value=$form->{dbuser}></td>
- <th align=right>| . $locale->text('Password') . qq|</th>
- <td><input type=password name=dbpasswd size=10></td>
+ } else {
+ $form->{DBENCODINGS} = [];
- </tr>
+ foreach my $encoding (@Common::db_encodings) {
+ push @{ $form->{DBENCODINGS} }, { "dbencoding" => $encoding->{dbencoding},
+ "label" => $encoding->{label},
+ "selected" => $encoding->{charset} eq $default_charset };
+ }
+ }
- <tr>
+ $form->{title} = "Lx-Office ERP " . $locale->text('Database Administration') . " / " . $locale->text('Create Dataset');
- <th align=right>$form->{connectstring}</th>
- <td colspan=3><input name=dbdefault size=10 value=$form->{dbdefault}></td>
+ $form->header();
+ print $form->parse_html_template("admin/create_dataset");
+}
- </tr>
+sub dbcreate {
+ my $form = $main::form;
+ my $locale = $main::locale;
-</table>
+ $form->isblank("db", $locale->text('Dataset missing!'));
-</td></tr>
-</table>
+ User->dbcreate(\%$form);
-<input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}&root=$form->{root}&rpw=$form->{rpw}">
-<input type=hidden name=root value="$form->{root}">
-<input type=hidden name=path value=$form->{path}>
-<input type=hidden name=rpw value=$form->{rpw}>
+ $form->{title} = "Lx-Office ERP " . $locale->text('Database Administration') . " / " . $locale->text('Create Dataset');
-<br>
+ $form->header();
+ print $form->parse_html_template("admin/dbcreate");
+}
-<input type=submit class=submit name=action value="|
- . $locale->text('Create Dataset') . qq|">
-<input type=submit class=submit name=action value="|
- . $locale->text('Update Dataset') . qq|">
-<input type=submit class=submit name=action value="|
- . $locale->text('Delete Dataset') . qq|">
+sub delete_dataset {
+ my $form = $main::form;
+ my $locale = $main::locale;
-</form>
+ my @dbsources = User->dbsources_unused($form);
+ $form->error($locale->text('Nothing to delete!')) unless @dbsources;
-</td></tr>
-</table>
+ $form->{title} = "Lx-Office ERP " . $locale->text('Database Administration') . " / " . $locale->text('Delete Dataset');
+ $form->{DBSOURCES} = [ map { { "name", $_ } } sort @dbsources ];
-<p>|
- . $locale->text(
- 'This is a preliminary check for existing sources. Nothing will be created or deleted at this stage!'
- )
+ $form->header();
+ print $form->parse_html_template("admin/delete_dataset");
+}
- . qq|
-<br>$msg{$form->{dbdriver}}
+sub dbdelete {
+ my $form = $main::form;
+ my $locale = $main::locale;
+ if (!$form->{db}) {
+ $form->error($locale->text('No Dataset selected!'));
+ }
-</body>
-</html>
-|;
+ User->dbdelete(\%$form);
+ $form->{title} = "Lx-Office ERP " . $locale->text('Database Administration') . " / " . $locale->text('Delete Dataset');
+ $form->header();
+ print $form->parse_html_template("admin/dbdelete");
}
-sub continue {
-
- &{ $form->{nextsub} };
+sub backup_dataset {
+ my $form = $main::form;
+ my $locale = $main::locale;
-}
+ $form->{title} = "Lx-Office ERP " . $locale->text('Database Administration') . " / " . $locale->text('Backup Dataset');
-sub update_dataset {
+ if ($::lx_office_conf{applications}->{pg_dump} eq "DISABLED") {
+ $form->error($locale->text('Database backups and restorations are disabled in the configuration.'));
+ }
- %needsupdate = User->dbneedsupdate(\%$form);
+ my @dbsources = sort User->dbsources($form);
+ $form->{DATABASES} = [ map { { "dbname" => $_ } } @dbsources ];
+ $form->{NO_DATABASES} = !scalar @dbsources;
- $form->{title} =
- "Lx-Office ERP "
- . $locale->text('Database Administration') . " / "
- . $locale->text('Update Dataset');
+ my $username = getpwuid $UID || "unknown-user";
+ my $hostname = hostname() || "unknown-host";
+ $form->{from} = "Lx-Office Admin <${username}\@${hostname}>";
- $form->header;
+ $form->header();
+ print $form->parse_html_template("admin/backup_dataset");
+}
- print qq|
-<body class=admin>
+sub backup_dataset_start {
+ my $form = $main::form;
+ my $locale = $main::locale;
+ $form->{title} = "Lx-Office ERP " . $locale->text('Database Administration') . " / " . $locale->text('Backup Dataset');
-<center>
-<h2>$form->{title}</h2>
-|;
+ my $pg_dump_exe = $::lx_office_conf{applications}->{pg_dump} || "pg_dump";
- foreach $key (sort keys %needsupdate) {
- if ($needsupdate{$key} ne $form->{dbversion}) {
- $upd .= qq|<input name="db$key" type=checkbox value=1 checked> $key\n|;
- $form->{dbupdate} .= "db$key ";
- }
+ if ("$pg_dump_exe" eq "DISABLED") {
+ $form->error($locale->text('Database backups and restorations are disabled in the configuration.'));
}
- chop $form->{dbupdate};
+ $form->isblank("dbname", $locale->text('The dataset name is missing.'));
+ $form->isblank("to", $locale->text('The email address is missing.')) if $form->{destination} eq "email";
- if ($form->{dbupdate}) {
+ my $tmpdir = "/tmp/lx_office_backup_" . Common->unique_id();
+ mkdir $tmpdir, 0700 || $form->error($locale->text('A temporary directory could not be created:') . " $ERRNO");
- print qq|
-<table width=100%>
-<form method=post action=$form->{script}>
+ my $pgpass = IO::File->new("${tmpdir}/.pgpass", O_WRONLY | O_CREAT, 0600);
-<input type=hidden name=dbdriver value=$form->{dbdriver}>
-<input type=hidden name=dbhost value=$form->{dbhost}>
-<input type=hidden name=dbport value=$form->{dbport}>
-<input type=hidden name=dbuser value=$form->{dbuser}>
-<input type=hidden name=dbpasswd value=$form->{dbpasswd}>
-<input type=hidden name=dbdefault value=$form->{dbdefault}>
+ if (!$pgpass) {
+ unlink $tmpdir;
+ $form->error($locale->text('A temporary file could not be created:') . " $ERRNO");
+ }
-<tr class=listheading>
- <th>| . $locale->text('The following Datasets need to be updated') . qq|</th>
-</tr>
-<tr>
-<td>
+ print $pgpass "$form->{dbhost}:$form->{dbport}:$form->{dbname}:$form->{dbuser}:$form->{dbpasswd}\n";
+ $pgpass->close();
-$upd
+ $ENV{HOME} = $tmpdir;
-</td>
-</tr>
-<tr>
-<td>
+ my @args = ("-Ft", "-c", "-o", "-h", $form->{dbhost}, "-U", $form->{dbuser});
+ push @args, ("-p", $form->{dbport}) if ($form->{dbport});
+ push @args, $form->{dbname};
-<input name=dbupdate type=hidden value="$form->{dbupdate}">
+ my $cmd = "$pg_dump_exe " . join(" ", map { s/\\/\\\\/g; s/\"/\\\"/g; $_ } @args);
+ my $name = "dataset_backup_$form->{dbname}_" . strftime("%Y%m%d", localtime()) . ".tar";
-<input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}&root=$form->{root}&rpw=$form->{rpw}">
+ if ($form->{destination} ne "email") {
+ my $in = IO::File->new("$cmd |");
-<input type=hidden name=root value="$form->{root}">
-<input type=hidden name=path value=$form->{path}>
-<input type=hidden name=rpw value=$form->{rpw}>
+ if (!$in) {
+ unlink "${tmpdir}/.pgpass";
+ rmdir $tmpdir;
-<input type=hidden name=nextsub value=dbupdate>
+ $form->error($locale->text('The pg_dump process could not be started.'));
+ }
+
+ print "content-type: application/x-tar\n";
+ print "content-disposition: attachment; filename=\"${name}\"\n\n";
-<hr size=3 noshade>
+ while (my $line = <$in>) {
+ print $line;
+ }
-<br>
-<input type=submit class=submit name=action value="|
- . $locale->text('Continue') . qq|">
+ $in->close();
-</td></tr>
-</table>
-</form>
-|;
+ unlink "${tmpdir}/.pgpass";
+ rmdir $tmpdir;
} else {
+ my $tmp = $tmpdir . "/dump_" . Common::unique_id();
- print $locale->text('All Datasets up to date!');
-
- }
+ if (system("$cmd > $tmp") != 0) {
+ unlink "${tmpdir}/.pgpass", $tmp;
+ rmdir $tmpdir;
- print qq|
+ $form->error($locale->text('The pg_dump process could not be started.'));
+ }
-</body>
-</html>
-|;
+ my $mail = new Mailer;
-}
+ map { $mail->{$_} = $form->{$_} } qw(from to cc subject message);
-sub dbupdate {
+ $mail->{charset} = $::lx_office_conf{system}->{dbcharset} || Common::DEFAULT_CHARSET;
+ $mail->{attachments} = [ { "filename" => $tmp, "name" => $name } ];
+ $mail->send();
- User->dbupdate(\%$form);
+ unlink "${tmpdir}/.pgpass", $tmp;
+ rmdir $tmpdir;
- $form->redirect($locale->text('Dataset updated!'));
+ $form->{title} = "Lx-Office ERP " . $locale->text('Database Administration') . " / " . $locale->text('Backup Dataset');
+ $form->header();
+ print $form->parse_html_template("admin/backup_dataset_email_done");
+ }
}
-sub create_dataset {
+sub restore_dataset {
+ my $form = $main::form;
+ my $locale = $main::locale;
- foreach $item (sort User->dbsources(\%$form)) {
- $dbsources .= "[$item] ";
- }
+ $form->{title} = "Lx-Office ERP " . $locale->text('Database Administration') . " / " . $locale->text('Restore Dataset');
- opendir SQLDIR, "sql/." or $form - error($!);
- foreach $item (sort grep /-chart\.sql/, readdir SQLDIR) {
- next if ($item eq 'Default-chart.sql');
- $item =~ s/-chart\.sql//;
- push @charts,
- qq| <input name=chart class=radio type=radio value="$item"> $item|;
+ if ($::lx_office_conf{applications}->{pg_restore} eq "DISABLED") {
+ $form->error($locale->text('Database backups and restorations are disabled in the configuration.'));
}
- closedir SQLDIR;
-
- $selectencoding = qq|<option>
- <option value=SQL_ASCII>ASCII
- <option value=EUC_JP>Japanese Extended UNIX Code
- <option value=EUC_CN>Chinese Extended UNIX Code
- <option value=EUC_KR>Korean Extended UNIX Code
- <option value=EUC_TW>Taiwan Extended UNIX Code
- <option value=UNICODE>UTF-8 Unicode
- <option value=MULE_INTERNAL>Mule internal type
- <option value=LATIN1>ISO 8859-1
- <option value=LATIN2>ISO 8859-2
- <option value=LATIN3>ISO 8859-3
- <option value=LATIN4>ISO 8859-4
- <option value=LATIN5>ISO 8859-5
- <option value=KOI8>KOI8-R
- <option value=WIN>Windows CP1251
- <option value=ALT>Windows CP866
- |;
- $form->{title} =
- "Lx-Office ERP "
- . $locale->text('Database Administration') . " / "
- . $locale->text('Create Dataset');
+ my $default_charset = $::lx_office_conf{system}->{dbcharset};
+ $default_charset ||= Common::DEFAULT_CHARSET;
- $form->header;
+ $form->{DBENCODINGS} = [];
- print qq|
-<body class=admin>
+ foreach my $encoding (@Common::db_encodings) {
+ push @{ $form->{DBENCODINGS} }, { "dbencoding" => $encoding->{dbencoding},
+ "label" => $encoding->{label},
+ "selected" => $encoding->{charset} eq $default_charset };
+ }
+ $form->header();
+ print $form->parse_html_template("admin/restore_dataset");
+}
-<center>
-<h2>$form->{title}</h2>
+sub restore_dataset_start {
+ my $form = $main::form;
+ my $locale = $main::locale;
-<form method=post action=$form->{script}>
+ $form->{title} = "Lx-Office ERP " . $locale->text('Database Administration') . " / " . $locale->text('Restore Dataset');
-<table width=100%>
- <tr class=listheading>
- <th colspan=2> </th>
- </tr>
+ my $pg_restore_exe = $::lx_office_conf{applications}->{pg_restore} || "pg_restore";
- <tr>
+ if ("$pg_restore_exe" eq "DISABLED") {
+ $form->error($locale->text('Database backups and restorations are disabled in the configuration.'));
+ }
- <th align=right nowrap>| . $locale->text('Existing Datasets') . qq|</th>
- <td>$dbsources</td>
+ $form->isblank("new_dbname", $locale->text('The dataset name is missing.'));
+ $form->isblank("content", $locale->text('No backup file has been uploaded.'));
- </tr>
+ # Create temporary directories. Write the backup file contents to a temporary
+ # file. Create a .pgpass file with the username and password for the pg_restore
+ # utility.
- <tr>
+ my $tmpdir = "/tmp/lx_office_backup_" . Common->unique_id();
+ mkdir $tmpdir, 0700 || $form->error($locale->text('A temporary directory could not be created:') . " $ERRNO");
- <th align=right nowrap>| . $locale->text('Create Dataset') . qq|</th>
- <td><input name=db></td>
+ my $pgpass = IO::File->new("${tmpdir}/.pgpass", O_WRONLY | O_CREAT, 0600);
- </tr>
+ if (!$pgpass) {
+ unlink $tmpdir;
+ $form->error($locale->text('A temporary file could not be created:') . " $ERRNO");
+ }
- <tr>
+ print $pgpass "$form->{dbhost}:$form->{dbport}:$form->{new_dbname}:$form->{dbuser}:$form->{dbpasswd}\n";
+ $pgpass->close();
- <th align=right nowrap>| . $locale->text('Multibyte Encoding') . qq|</th>
- <td><select name=encoding>$selectencoding</select></td>
+ $ENV{HOME} = $tmpdir;
- </tr>
+ my $tmp = $tmpdir . "/dump_" . Common::unique_id();
+ my $tmpfile;
- <tr>
+ if (substr($form->{content}, 0, 2) eq "\037\213") {
+ $tmpfile = IO::File->new("| gzip -d > $tmp");
+ $tmpfile->binary();
- <th align=right nowrap>|
- . $locale->text('Create Chart of Accounts') . qq|</th>
- <td>@charts</td>
+ } else {
+ $tmpfile = IO::File->new($tmp, O_WRONLY | O_CREAT | O_BINARY, 0600);
+ }
- </tr>
+ if (!$tmpfile) {
+ unlink "${tmpdir}/.pgpass";
+ rmdir $tmpdir;
- <tr><td colspan=2>
-<p>
-<input type=hidden name=dbdriver value=$form->{dbdriver}>
-<input type=hidden name=dbuser value=$form->{dbuser}>
-<input type=hidden name=dbhost value=$form->{dbhost}>
-<input type=hidden name=dbport value=$form->{dbport}>
-<input type=hidden name=dbpasswd value=$form->{dbpasswd}>
-<input type=hidden name=dbdefault value=$form->{dbdefault}>
+ $form->error($locale->text('A temporary file could not be created:') . " $ERRNO");
+ }
-<input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}&root=$form->{root}&rpw=$form->{rpw}">
+ print $tmpfile $form->{content};
+ $tmpfile->close();
-<input type=hidden name=root value="$form->{root}">
-<input type=hidden name=path value=$form->{path}>
-<input type=hidden name=rpw value=$form->{rpw}>
+ delete $form->{content};
-<input type=hidden name=nextsub value=dbcreate>
+ # Try to connect to the database. Find out if a database with the same name exists.
+ # If yes, then drop the existing database. Create a new one with the name and encoding
+ # given by the user.
-<hr size=3 noshade>
+ User::dbconnect_vars($form, "template1");
-<br>
-<input type=submit class=submit name=action value="|
- . $locale->text('Continue') . qq|">
+ my %myconfig = map { $_ => $form->{$_} } grep /^db/, keys %{ $form };
+ my $dbh = $form->dbconnect(\%myconfig) || $form->dberror();
- </td></tr>
-</table>
+ my ($query, $sth);
-</form>
+ $form->{new_dbname} =~ s|[^a-zA-Z0-9_\-]||g;
+ $query = qq|SELECT COUNT(*) FROM pg_database WHERE datname = ?|;
+ my ($count) = selectrow_query($form, $dbh, $query, $form->{new_dbname});
+ if ($count) {
+ do_query($form, $dbh, qq|DROP DATABASE $form->{new_dbname}|);
+ }
-</body>
-</html>
-|;
+ my $found = 0;
+ foreach my $item (@Common::db_encodings) {
+ if ($item->{dbencoding} eq $form->{dbencoding}) {
+ $found = 1;
+ last;
+ }
+ }
+ $form->{dbencoding} = "LATIN9" unless $form->{dbencoding};
-}
+ do_query($form, $dbh, qq|CREATE DATABASE $form->{new_dbname} ENCODING ? TEMPLATE template0|, $form->{dbencoding});
-sub dbcreate {
+ $dbh->disconnect();
- $form->isblank("db", $locale->text('Dataset missing!'));
+ # Spawn pg_restore on the temporary file.
- User->dbcreate(\%$form);
+ my @args = ("-h", $form->{dbhost}, "-U", $form->{dbuser}, "-d", $form->{new_dbname});
+ push @args, ("-p", $form->{dbport}) if ($form->{dbport});
+ push @args, $tmp;
- $form->{title} =
- "Lx-Office ERP "
- . $locale->text('Database Administration') . " / "
- . $locale->text('Create Dataset');
+ my $cmd = "$pg_restore_exe " . join(" ", map { s/\\/\\\\/g; s/\"/\\\"/g; $_ } @args);
- $form->header;
+ my $in = IO::File->new("$cmd 2>&1 |");
- print qq|
-<body class=admin>
+ if (!$in) {
+ unlink "${tmpdir}/.pgpass", $tmp;
+ rmdir $tmpdir;
+ $form->error($locale->text('The pg_restore process could not be started.'));
+ }
-<center>
-<h2>$form->{title}</h2>
+ $English::AUTOFLUSH = 1;
-<form method=post action=$form->{script}>|
+ $form->header();
+ print $form->parse_html_template("admin/restore_dataset_start_header");
- . $locale->text('Dataset')
- . " $form->{db} "
- . $locale->text('successfully created!')
+ while (my $line = <$in>) {
+ print $line;
+ }
+ $in->close();
- . qq|
+ $form->{retval} = $CHILD_ERROR >> 8;
+ print $form->parse_html_template("admin/restore_dataset_start_footer");
-<input type=hidden name=root value="$form->{root}">
-<input type=hidden name=path value="$form->{path}">
-<input type=hidden name=rpw value="$form->{rpw}">
+ unlink "${tmpdir}/.pgpass", $tmp;
+ rmdir $tmpdir;
+}
-<input type=hidden name=nextsub value=list_users>
+sub unlock_system {
+ my $form = $main::form;
+ my $locale = $main::locale;
-<p><input type=submit class=submit name=action value="|
- . $locale->text('Continue') . qq|">
-</form>
+ unlink _nologin_file_name();;
+ $form->{callback} = "admin.pl?action=list_users";
-</body>
-</html>
-|;
+ $form->redirect($locale->text('Lockfile removed!'));
}
-sub delete_dataset {
-
- if (@dbsources = User->dbsources_unused(\%$form, $memberfile)) {
- foreach $item (sort @dbsources) {
- $dbsources .=
- qq|<input name=db class=radio type=radio value=$item> $item |;
- }
- } else {
- $form->error($locale->text('Nothing to delete!'));
- }
+sub lock_system {
+ my $form = $main::form;
+ my $locale = $main::locale;
- $form->{title} =
- "Lx-Office ERP "
- . $locale->text('Database Administration') . " / "
- . $locale->text('Delete Dataset');
+ open(FH, ">" . _nologin_file_name())
+ or $form->error($locale->text('Cannot create Lock!'));
+ close(FH);
- $form->header;
+ $form->{callback} = "admin.pl?action=list_users";
- print qq|
-<body class=admin>
+ $form->redirect($locale->text('Lockfile created!'));
-<h2>$form->{title}</h2>
+}
-<form method=post action=$form->{script}>
+sub yes {
+ call_sub($main::form->{yes_nextsub});
+}
-<table width=100%>
- <tr class=listheading>
- <th>|
- . $locale->text('The following Datasets are not in use and can be deleted')
- . qq|</th>
- </tr>
+sub no {
+ call_sub($main::form->{no_nextsub});
+}
- <tr>
- <td>
- $dbsources
- </td>
- </tr>
+sub add {
+ call_sub($main::form->{add_nextsub});
+}
- <tr><td>
-<p>
-<input type=hidden name=dbdriver value=$form->{dbdriver}>
-<input type=hidden name=dbuser value=$form->{dbuser}>
-<input type=hidden name=dbhost value=$form->{dbhost}>
-<input type=hidden name=dbport value=$form->{dbport}>
-<input type=hidden name=dbpasswd value=$form->{dbpasswd}>
-<input type=hidden name=dbdefault value=$form->{dbdefault}>
+sub edit {
+ my $form = $main::form;
-<input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}&root=$form->{root}&rpw=$form->{rpw}">
+ $form->{edit_nextsub} ||= 'edit_user';
-<input type=hidden name=root value="$form->{root}">
-<input type=hidden name=path value="$form->{path}">
-<input type=hidden name=rpw value="$form->{rpw}">
+ call_sub($form->{edit_nextsub});
+}
-<input type=hidden name=nextsub value=dbdelete>
+sub delete {
+ my $form = $main::form;
-<hr size=3 noshade>
+ $form->{delete_nextsub} ||= 'delete_user';
-<br>
-<input type=submit class=submit name=action value="|
- . $locale->text('Continue') . qq|">
+ call_sub($form->{delete_nextsub});
+}
- </td></tr>
-</table>
+sub save {
+ my $form = $main::form;
-</form>
+ $form->{save_nextsub} ||= 'save_user';
-</body>
-</html>
-|;
+ call_sub($form->{save_nextsub});
+}
+sub back {
+ call_sub($main::form->{back_nextsub});
}
-sub dbdelete {
+sub dispatcher {
+ my $form = $main::form;
+ my $locale = $main::locale;
- if (!$form->{db}) {
- $form->error($locale->text('No Dataset selected!'));
+ foreach my $action (qw(create_standard_group dont_create_standard_group
+ save_user delete_user save_user_as_new)) {
+ if ($form->{"action_${action}"}) {
+ call_sub($action);
+ return;
+ }
}
- User->dbdelete(\%$form);
-
- $form->{title} =
- "Lx-Office ERP "
- . $locale->text('Database Administration') . " / "
- . $locale->text('Delete Dataset');
-
- $form->header;
-
- print qq|
-<body class=admin>
-
-
-<center>
-<h2>$form->{title}</h2>
-
-<form method=post action=$form->{script}>
-
-$form->{db} | . $locale->text('successfully deleted!')
-
- . qq|
-
-<input type=hidden name=root value="$form->{root}">
-<input type=hidden name=path value="$form->{path}">
-<input type=hidden name=rpw value="$form->{rpw}">
-
-<input type=hidden name=nextsub value=list_users>
-
-<p><input type=submit class=submit name=action value="|
- . $locale->text('Continue') . qq|">
-</form>
-
-
-</body>
-</html>
-|;
+ call_sub($form->{default_action}) if ($form->{default_action});
+ $form->error($locale->text('No action defined.'));
}
-sub unlock_system {
-
- unlink "$userspath/nologin";
-
- $form->{callback} =
- "$form->{script}?action=list_users&path=$form->{path}&root=$form->{root}&rpw=$root->{password}";
-
- $form->redirect($locale->text('Lockfile removed!'));
-
+sub _apply_dbupgrade_scripts {
+ ::end_of_request() if SL::DBUpgrade2->new(form => $::form, dbdriver => 'Pg', auth => 1)->apply_admin_dbupgrade_scripts(1);
}
-sub lock_system {
-
- open(FH, ">$userspath/nologin")
- or $form->error($locale->text('Cannot create Lock!'));
- close(FH);
-
- $form->{callback} =
- "$form->{script}?action=list_users&path=$form->{path}&root=$form->{root}&rpw=$root->{password}";
-
- $form->redirect($locale->text('Lockfile created!'));
-
+sub _nologin_file_name {
+ return $::lx_office_conf{paths}->{userspath} . '/nologin';
}
+
+1;