1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
31 # add/edit/delete users
33 #======================================================================
37 use English qw(-no_match_vars);
45 use POSIX qw(strftime);
49 use SL::Auth::PasswordPolicy;
50 use SL::DB::AuthClient;
62 require "bin/mozilla/common.pl";
68 # $locale->text('periodic')
69 # $locale->text('income')
70 # $locale->text('perpetual')
71 # $locale->text('balance')
79 $::lxdebug->enter_sub;
80 my $session_result = shift;
86 $::request->{layout} = SL::Layout::Dispatcher->new(style => 'admin');
87 $::request->{layout}->use_stylesheet("lx-office-erp.css");
88 $form->{favicon} = "favicon.ico";
90 if ($form->{action}) {
91 if ($auth->authenticate_root($form->{'{AUTH}admin_password'}) != $auth->OK()) {
92 $auth->punish_wrong_login;
93 $form->{error} = $locale->text('Incorrect password!');
94 $auth->delete_session_value('admin_password');
97 if ($auth->session_tables_present()) {
98 delete $::form->{'{AUTH}admin_password'};
101 call_sub($locale->findsub($form->{action}));
106 $::lxdebug->leave_sub;
110 print $::request->cgi->redirect('controller.pl?action=Admin/login');
113 sub pg_database_administration {
114 my $form = $main::form;
118 sub dbselect_source {
119 my $form = $main::form;
120 my $locale = $main::locale;
122 $form->{dbport} = $::auth->{DB_config}->{port} || 5432;
123 $form->{dbuser} = $::auth->{DB_config}->{user} || 'lxoffice';
124 $form->{dbdefault} = 'template1';
125 $form->{dbhost} = $::auth->{DB_config}->{host} || 'localhost';
127 $form->{title} = "kivitendo / " . $locale->text('Database Administration');
130 print $form->parse_html_template("admin/dbadmin");
134 call_sub($main::form->{"nextsub"});
138 my $form = $main::form;
139 my $locale = $main::locale;
141 $form->{title} = "kivitendo " . $locale->text('Database Administration') . " / " . $locale->text('Update Dataset');
143 my @need_updates = User->dbneedsupdate($form);
144 $form->{NEED_UPDATES} = \@need_updates;
145 $form->{ALL_UPDATED} = !scalar @need_updates;
148 print $form->parse_html_template("admin/update_dataset");
152 my $form = $main::form;
153 my $locale = $main::locale;
155 $::request->{layout}->use_stylesheet("lx-office-erp.css");
156 $form->{title} = $locale->text("Dataset upgrade");
159 my $rowcount = $form->{rowcount} * 1;
160 my @update_rows = grep { $form->{"update_$_"} } (1 .. $rowcount);
161 $form->{NOTHING_TO_DO} = !scalar @update_rows;
162 my $saved_form = save_form();
166 print $form->parse_html_template("admin/dbupgrade_all_header");
168 foreach my $i (@update_rows) {
169 restore_form($saved_form);
172 map { $form->{$_} = $::myconfig{$_} = $form->{"${_}_${i}"} } qw(dbname dbhost dbport dbuser dbpasswd);
174 print $form->parse_html_template("admin/dbupgrade_header");
176 User->dbupdate($form);
177 User->dbupdate2(form => $form, updater => SL::DBUpgrade2->new(form => $form)->parse_dbupdate_controls, database => $form->{dbname});
179 print $form->parse_html_template("admin/dbupgrade_footer");
182 print $form->parse_html_template("admin/dbupgrade_all_done");
186 my $form = $main::form;
187 my $locale = $main::locale;
189 $form->{dbsources} = join " ", map { "[${_}]" } sort User->dbsources($form);
191 $form->{CHARTS} = [];
193 tie my %dir_h, 'IO::Dir', 'sql/';
194 foreach my $item (map { s/-chart\.sql$//; $_ } sort grep { /-chart\.sql\z/ && !/Default-chart.sql\z/ } keys %dir_h) {
195 push @{ $form->{CHARTS} }, { name => $item,
196 selected => $item eq "Germany-DATEV-SKR03EU" };
199 $form->{ACCOUNTING_METHODS} = [ map { { name => $_, selected => $_ eq 'cash' } } qw(accrual cash) ];
200 $form->{INVENTORY_SYSTEMS} = [ map { { name => $_, selected => $_ eq 'periodic' } } qw(perpetual periodic) ];
201 $form->{PROFIT_DETERMINATIONS} = [ map { { name => $_, selected => $_ eq 'income' } } qw(balance income) ];
203 my $default_charset = $::lx_office_conf{system}->{dbcharset} || Common::DEFAULT_CHARSET;
205 my $cluster_encoding = User->dbclusterencoding($form);
206 if ($cluster_encoding && ($cluster_encoding =~ m/^(?:UTF-?8|UNICODE)$/i)) {
207 if ($::lx_office_conf{system}->{dbcharset} !~ m/^UTF-?8$/i) {
208 $form->show_generic_error($locale->text('The selected PostgreSQL installation uses UTF-8 as its encoding. ' .
209 'Therefore you have to configure kivitendo to use UTF-8 as well.'),
213 $form->{FORCE_DBENCODING} = 'UNICODE';
216 $form->{DBENCODINGS} = [ map { { %{$_}, selected => $_->{charset} eq $default_charset } } @Common::db_encodings ];
219 $form->{title} = "kivitendo " . $locale->text('Database Administration') . " / " . $locale->text('Create Dataset');
222 print $form->parse_html_template("admin/create_dataset");
226 my $form = $main::form;
227 my $locale = $main::locale;
229 $form->isblank("db", $locale->text('Dataset missing!'));
230 $form->isblank("defaultcurrency", $locale->text('Default currency missing!'));
232 User->dbcreate(\%$form);
234 $form->{title} = "kivitendo " . $locale->text('Database Administration') . " / " . $locale->text('Create Dataset');
237 print $form->parse_html_template("admin/dbcreate");
241 my $form = $main::form;
242 my $locale = $main::locale;
244 my @dbsources = User->dbsources_unused($form);
245 $form->error($locale->text('Nothing to delete!')) unless @dbsources;
247 $form->{title} = "kivitendo " . $locale->text('Database Administration') . " / " . $locale->text('Delete Dataset');
248 $form->{DBSOURCES} = [ map { { "name", $_ } } sort @dbsources ];
251 print $form->parse_html_template("admin/delete_dataset");
255 my $form = $main::form;
256 my $locale = $main::locale;
259 $form->error($locale->text('No Dataset selected!'));
262 User->dbdelete(\%$form);
264 $form->{title} = "kivitendo " . $locale->text('Database Administration') . " / " . $locale->text('Delete Dataset');
266 print $form->parse_html_template("admin/dbdelete");