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 #======================================================================
35 $menufile = "menu.ini";
44 require "bin/mozilla/common.pl";
46 our $cgi = new CGI('');
49 $form->{"root"} = "root login";
51 $locale = new Locale $language, "admin";
54 if (-f "bin/mozilla/custom_$form->{script}") {
55 eval { require "bin/mozilla/custom_$form->{script}"; };
56 $form->error($@) if ($@);
59 $form->{stylesheet} = "lx-office-erp.css";
60 $form->{favicon} = "favicon.ico";
62 if ($form->{action}) {
65 $subroutine = $locale->findsub($form->{action});
67 if ($subroutine eq 'login') {
69 $form->{rpw} = crypt $form->{rpw}, "ro";
75 call_sub($subroutine);
79 # if there are no drivers bail out
80 $form->error($locale->text('No Database Drivers available!'))
81 unless (User->dbdrivers);
84 if (!-f $memberfile) {
85 open(FH, ">$memberfile") or $form->error("$memberfile : $!");
86 print FH qq|# SQL-Ledger Accounting members
106 qq|Lx-Office ERP $form->{version} | . $locale->text('Administration');
109 print $form->parse_html_template('admin/adminlogin');
118 $form->error($locale->text('File locked!')) if (-f "${memberfile}.LCK");
120 open(FH, "$memberfile") or $form->error("$memberfile : $!");
129 $login =~ s/(\[|\])//g;
131 $members{$login} = { "login" => $login };
134 if (/^([a-z]+)=(.*)/) {
135 $members{$login}->{$1} = $2;
141 delete $members{"root login"};
142 map { $_->{templates} =~ s|.*/||; } values %members;
144 $form->{title} = "Lx-Office ERP " . $locale->text('Administration');
145 $form->{LOCKED} = -e "$userspath/nologin";
146 $form->{MEMBERS} = [ @members{sort { lc $a cmp lc $b } keys %members} ];
149 print $form->parse_html_template("admin/list_users");
156 . $locale->text('Administration') . " / "
157 . $locale->text('Add User');
159 $form->{Oracle_sid} = $sid;
160 $form->{Oracle_dbport} = '1521';
161 $form->{Oracle_dbhost} = `hostname`;
165 "countrycode" => "de",
166 "numberformat" => "1000,00",
167 "dateformat" => "dd.mm.yy",
168 "stylesheet" => "lx-office-erp.css",
171 edit_user_form($myconfig);
178 . $locale->text('Administration') . " / "
179 . $locale->text('Edit User');
182 $form->isblank("login", $locale->text("The login is missing."));
185 my $myconfig = new User "$memberfile", "$form->{login}";
187 $myconfig->{signature} =~ s/\\n/\r\n/g;
188 $myconfig->{address} =~ s/\\n/\r\n/g;
190 # strip basedir from templates directory
191 $myconfig->{templates} =~ s|.*/||;
193 edit_user_form($myconfig);
199 my @valid_dateformats = qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd);
200 $form->{ALL_DATEFORMATS} = [ map { { "format" => $_, "selected" => $_ eq $myconfig->{dateformat} } } @valid_dateformats ];
202 my @valid_numberformats = qw(1,000.00 1000.00 1.000,00 1000,00);
203 $form->{ALL_NUMBERFORMATS} = [ map { { "format" => $_, "selected" => $_ eq $myconfig->{numberformat} } } @valid_numberformats ];
205 %countrycodes = User->country_codes;
206 $form->{ALL_COUNTRYCODES} = [];
207 foreach $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
208 push @{ $form->{ALL_COUNTRYCODES} }, { "value" => $countrycode,
209 "name" => $countrycodes{$countrycode},
210 "selected" => $countrycode eq $myconfig->{countrycode} };
213 # is there a templates basedir
214 if (!-d "$templates") {
215 $form->error(sprintf($locale->text("The directory %s does not exist."), $templates));
218 opendir TEMPLATEDIR, "$templates/." or $form->error("$templates : $!");
219 my @all = readdir(TEMPLATEDIR);
220 my @alldir = sort grep { -d "$templates/$_" && !/^\.\.?$/ } @all;
221 my @allhtml = sort grep { -f "$templates/$_" && /\.html$/ } @all;
222 closedir TEMPLATEDIR;
224 @alldir = grep !/\.(html|tex|sty|odt|xml|txb)$/, @alldir;
225 @alldir = grep !/^(webpages|\.svn)$/, @alldir;
227 @allhtml = reverse grep !/Default/, @allhtml;
228 push @allhtml, 'Default';
229 @allhtml = reverse @allhtml;
231 $form->{ALL_TEMPLATES} = [ map { { "name", => $_, "selected" => $_ eq $myconfig->{templates} } } @alldir ];
233 $lastitem = $allhtml[0];
234 $lastitem =~ s/-.*//g;
235 $form->{ALL_MASTER_TEMPLATES} = [ { "name" => $lastitem, "selected" => $lastitem eq "German" } ];
236 foreach $item (@allhtml) {
238 next if ($item eq $lastitem);
240 push @{ $form->{ALL_MASTER_TEMPLATES} }, { "name" => $item, "selected" => $item eq "German" };
244 # css dir has styles that are not intended as general layouts.
245 # reverting to hardcoded list
246 $form->{ALL_STYLESHEETS} = [ map { { "name" => $_, "selected" => $_ eq $myconfig->{stylesheet} } } qw(lx-office-erp.css Win2000.css) ];
248 $form->{"menustyle_" . $myconfig->{menustyle} } = 1;
250 map { $form->{"myc_${_}"} = $myconfig->{$_} } keys %{ $myconfig };
252 map { $form->{"Pg_${_}"} = $myconfig->{$_} } qw(dbhost dbport dbname dbuser dbpasswd);
258 open(FH, $menufile) or $form->error("$menufile : $!");
260 while ($item = <FH>) {
261 next unless $item =~ /\[/;
262 next if $item =~ /\#/;
264 $item =~ s/(\[|\])//g;
267 my ($level, $menuitem);
270 ($level, $menuitem) = split /--/, $item, 2;
274 push @acsorder, $item;
278 push @{ $acs{$level} }, $menuitem;
282 foreach $item (split(/;/, $myconfig->{acs})) {
283 ($key, $value) = split /--/, $item, 2;
284 $excl{$key}{$value} = 1;
288 $form->{all_acs} = "";
290 foreach $key (@acsorder) {
291 my $acl = { "checked" => $form->{login} ? !$excl{$key}->{$key} : 1,
292 "name" => "${key}--${key}",
295 $form->{all_acs} .= "${key}--${key};";
297 foreach $item (@{ $acs{$key} }) {
298 next if ($key eq $item);
300 my $subacl = { "checked" => $form->{login} ? !$excl{$key}->{$item} : 1,
301 "name" => "${key}--${item}",
303 push @{ $acl->{SUBACLS} }, $subacl;
304 $form->{all_acs} .= "${key}--${item};";
306 push @{ $form->{ACLS} }, $acl;
309 chop $form->{all_acs};
312 print $form->parse_html_template("admin/edit_user");
318 $form->error($locale->text('Database Driver not checked!'))
319 unless $form->{dbdriver};
321 # no spaces allowed in login name
322 ($form->{login}) = split / /, $form->{login};
324 $form->isblank("login", $locale->text('Login name missing!'));
326 # check for duplicates
327 if (!$form->{edit}) {
328 $temp = new User "$memberfile", "$form->{login}";
330 if ($temp->{login}) {
331 $form->error("$form->{login} " . $locale->text('is already a member!'));
335 # no spaces allowed in directories
336 ($form->{newtemplates}) = split / /, $form->{newtemplates};
338 if ($form->{newtemplates}) {
339 $form->{templates} = $form->{newtemplates};
342 ($form->{usetemplates}) ? $form->{usetemplates} : $form->{login};
346 if (!-d "$templates") {
347 $form->error(sprintf($locale->text("The directory %s does not exist."), $templates));
350 # add base directory to $form->{templates}
351 $form->{templates} =~ s|.*/||;
352 $form->{templates} = "$templates/$form->{templates}";
354 $myconfig = new User "$memberfile", "$form->{login}";
356 # redo acs variable and delete all the acs codes
358 foreach $item (split m|;|, $form->{all_acs}) {
359 my $name = "ACS_${item}";
361 push @acs, $item if !$form->{$name};
362 delete $form->{$name};
364 $form->{acs} = join ";", @acs;
366 # check which database was filled in
367 if ($form->{dbdriver} eq 'Oracle') {
368 $form->{sid} = $form->{Oracle_sid},;
369 $form->{dbhost} = $form->{Oracle_dbhost},;
370 $form->{dbport} = $form->{Oracle_dbport};
371 $form->{dbpasswd} = $form->{Oracle_dbpasswd};
372 $form->{dbuser} = $form->{Oracle_dbuser};
373 $form->{dbname} = $form->{Oracle_dbuser};
375 $form->isblank("dbhost", $locale->text('Hostname missing!'));
376 $form->isblank("dbport", $locale->text('Port missing!'));
377 $form->isblank("dbuser", $locale->text('Dataset missing!'));
379 if ($form->{dbdriver} eq 'Pg') {
380 $form->{dbhost} = $form->{Pg_dbhost};
381 $form->{dbport} = $form->{Pg_dbport};
382 $form->{dbpasswd} = $form->{Pg_dbpasswd};
383 $form->{dbuser} = $form->{Pg_dbuser};
384 $form->{dbname} = $form->{Pg_dbname};
386 $form->isblank("dbname", $locale->text('Dataset missing!'));
387 $form->isblank("dbuser", $locale->text('Database User missing!'));
390 foreach $item (keys %{$form}) {
391 $myconfig->{$item} = $form->{$item};
394 delete $myconfig->{stylesheet};
395 if ($form->{userstylesheet}) {
396 $myconfig->{stylesheet} = $form->{userstylesheet};
399 $myconfig->save_member($memberfile, $userspath);
403 qw(angebote bestellungen rechnungen anfragen lieferantenbestellungen einkaufsrechnungen);
404 foreach $directory (@webdavdirs) {
405 $file = "webdav/" . $directory . "/webdav-user";
406 if ($form->{$directory}) {
407 if (open(HTACCESS, "$file")) {
409 ($login, $password) = split(/:/, $_);
410 if ($login ne $form->{login}) {
416 open(HTACCESS, "> $file") or die "cannot open $file $!\n";
417 $newfile .= $myconfig->{login} . ":" . $myconfig->{password} . "\n";
418 print(HTACCESS $newfile);
421 $form->{$directory} = 0;
422 if (open(HTACCESS, "$file")) {
424 ($login, $password) = split(/:/, $_);
425 if ($login ne $form->{login}) {
431 open(HTACCESS, "> $file") or die "cannot open $file $!\n";
432 print(HTACCESS $newfile);
438 $form->{templates} =~ s|.*/||;
439 $form->{templates} = "${templates}/$form->{templates}";
440 $form->{mastertemplates} =~ s|.*/||;
442 # create user template directory and copy master files
443 if (!-d "$form->{templates}") {
446 if (mkdir "$form->{templates}", oct("771")) {
450 # copy templates to the directory
451 opendir TEMPLATEDIR, "$templates/." or $form - error("$templates : $!");
452 @templates = grep /$form->{mastertemplates}.*?\.(html|tex|sty|xml|txb)$/,
454 closedir TEMPLATEDIR;
456 foreach $file (@templates) {
457 open(TEMP, "$templates/$file")
458 or $form->error("$templates/$file : $!");
460 $file =~ s/$form->{mastertemplates}-//;
461 open(NEW, ">$form->{templates}/$file")
462 or $form->error("$form->{templates}/$file : $!");
464 while ($line = <TEMP>) {
471 $form->error("$!: $form->{templates}");
475 $form->redirect($locale->text('User saved!'));
483 ? "$templates/$form->{templates}"
484 : "$templates/$form->{login}";
486 $form->error($locale->text('File locked!')) if (-f ${memberfile} . LCK);
487 open(FH, ">${memberfile}.LCK") or $form->error("${memberfile}.LCK : $!");
490 open(CONF, "+<$memberfile") or $form->error("$memberfile : $!");
497 while ($line = shift @config) {
499 if ($line =~ /^\[/) {
500 last if ($line =~ /\[$form->{login}\]/);
501 $login = login_name($line);
504 if ($line =~ /^templates=/) {
505 $user{$login} = get_value($line);
511 # remove everything up to next login or EOF
512 # and save template variable
513 while ($line = shift @config) {
514 if ($line =~ /^templates=/) {
515 $templatedir = get_value($line);
517 last if ($line =~ /^\[/);
520 # this one is either the next login or EOF
523 $login = login_name($line);
525 while ($line = shift @config) {
526 if ($line =~ /^\[/) {
527 $login = login_name($line);
530 if ($line =~ /^templates=/) {
531 $user{$login} = get_value($line);
538 unlink "${memberfile}.LCK";
540 # scan %user for $templatedir
541 foreach $login (keys %user) {
542 last if ($found = ($templatedir eq $user{$login}));
545 # if found keep directory otherwise delete
548 # delete it if there is a template directory
549 $dir = "$form->{templates}";
551 unlink <$dir/*.html>;
558 # delete config file for user
559 unlink "$userspath/$form->{login}.conf";
561 $form->redirect($locale->text('User deleted!'));
569 return ($login) ? $login : undef;
576 my ($null, $value) = split(/=/, $line, 2);
579 $value =~ s/\s#.*//g;
581 # remove any trailing whitespace
582 $value =~ s/^\s*(.*?)\s*$/$1/;
587 sub change_admin_password {
591 . $locale->text('Administration') . " / "
592 . $locale->text('Change Admin Password');
595 print $form->parse_html_template("admin/change_admin_password");
598 sub change_password {
599 if ($form->{"password"} ne $form->{"password_again"}) {
602 . $locale->text('Administration') . " / "
603 . $locale->text('Change Admin Password');
606 $form->error($locale->text("The passwords do not match."));
609 $root->{password} = $form->{password};
611 $root->{'root login'} = 1;
612 $root->save_member($memberfile);
615 "$form->{script}?action=list_users&rpw=$root->{password}";
617 $form->redirect($locale->text('Password changed!'));
621 $root = new User "$memberfile", $form->{root};
623 if (!defined($root->{password}) || ($root->{password} ne $form->{rpw})) {
624 $form->error($locale->text('Incorrect Password!'));
629 sub pg_database_administration {
631 $form->{dbdriver} = 'Pg';
636 sub oracle_database_administration {
638 $form->{dbdriver} = 'Oracle';
643 sub dbdriver_defaults {
645 # load some defaults for the selected driver
647 'Pg' => { dbport => '5432',
648 dbuser => 'postgres',
649 dbdefault => 'template1',
650 dbhost => 'localhost',
651 connectstring => $locale->text('Connect to')
653 'Oracle' => { dbport => '1521',
656 dbhost => `hostname`,
657 connectstring => 'SID'
660 map { $form->{$_} = $driverdefaults{ $form->{dbdriver} }{$_} }
661 keys %{ $driverdefaults{Pg} };
665 sub dbselect_source {
671 'Leave host and port field empty unless you want to make a remote connection.'
675 'You must enter a host and port for local and remote connections!');
678 "Lx-Office ERP / " . $locale->text('Database Administration');
687 <h2>$form->{title}</h2>
689 <form method=post action=$form->{script}>
696 <tr class=listheading>
697 <th colspan=4>| . $locale->text('Database') . qq|</th>
700 <input type=hidden name=dbdriver value=$form->{dbdriver}>
707 <th align=right>| . $locale->text('Host') . qq|</th>
708 <td><input name=dbhost size=25 value=$form->{dbhost}></td>
709 <th align=right>| . $locale->text('Port') . qq|</th>
710 <td><input name=dbport size=5 value=$form->{dbport}></td>
716 <th align=right>| . $locale->text('User') . qq|</th>
717 <td><input name="dbuser" size="10" value="$form->{dbuser}"></td>
718 <th align=right>| . $locale->text('Password') . qq|</th>
719 <td><input type="password" name="dbpasswd" size="10"></td>
725 <th align=right>$form->{connectstring}</th>
726 <td colspan=3><input name=dbdefault size=10 value=$form->{dbdefault}></td>
735 <input name=callback type=hidden value="$form->{script}?action=list_users&rpw=$form->{rpw}">
736 <input type=hidden name=rpw value=$form->{rpw}>
740 <input type=submit class=submit name=action value="|
741 . $locale->text('Create Dataset') . qq|">|;
742 # Vorübergehend Deaktiviert
743 # <input type=submit class=submit name=action value="|
744 # . $locale->text('Update Dataset') . qq|">
745 print qq| <input type=submit class=submit name=action value="|
746 . $locale->text('Delete Dataset') . qq|">
755 'This is a preliminary check for existing sources. Nothing will be created or deleted at this stage!'
759 <br>$msg{$form->{dbdriver}}
769 call_sub($form->{"nextsub"});
774 %needsupdate = User->dbneedsupdate(\%$form);
778 . $locale->text('Database Administration') . " / "
779 . $locale->text('Update Dataset');
788 <h2>$form->{title}</h2>
791 foreach $key (sort keys %needsupdate) {
792 if ($needsupdate{$key} ne $form->{dbversion}) {
793 $upd .= qq|<input id="$field_id" name="db$key" type="checkbox" value="1" checked> $key\n|;
794 $form->{dbupdate} .= "db$key ";
799 chop $form->{dbupdate};
801 if ($form->{dbupdate}) {
805 <form method=post action=$form->{script}>
807 <input type=hidden name="dbdriver" value="$form->{dbdriver}">
808 <input type=hidden name="dbhost" value="$form->{dbhost}">
809 <input type=hidden name="dbport" value="$form->{dbport}">
810 <input type=hidden name="dbuser" value="$form->{dbuser}">
811 <input type=hidden name="dbpasswd" value="$form->{dbpasswd}">
812 <input type=hidden name="dbdefault" value="$form->{dbdefault}">
814 <tr class=listheading>
815 <th>| . $locale->text('The following Datasets need to be updated') . qq|</th>
827 <input name=dbupdate type=hidden value="$form->{dbupdate}">
829 <input name=callback type=hidden value="$form->{script}?action=list_users&rpw=$form->{rpw}">
831 <input type=hidden name=rpw value=$form->{rpw}>
833 <input type=hidden name=nextsub value=dbupdate>
838 <input type=submit class=submit name=action value="|
839 . $locale->text('Continue') . qq|">
848 print $locale->text('All Datasets up to date!');
861 $form->{"stylesheet"} = "lx-office-erp.css";
862 $form->{"title"} = $main::locale->text("Dataset upgrade");
866 map({ s/\s//g; s/^db//; $_; }
868 split(/\s+/, $form->{"dbupdate"}))));
869 print($form->parse_html_template("dbupgrade/header",
870 { "dbname" => $dbname }));
872 User->dbupdate(\%$form);
877 | . $locale->text('Dataset updated!') . qq|
881 <a id="enddatasetupdate" href="admin.pl?action=login&| .
882 join("&", map({ "$_=" . $form->escape($form->{$_}); } qw(rpw))) .
883 qq|">| . $locale->text("Continue") . qq|</a>|;
888 $form->{dbsources} = join " ", map { "[${_}]" } sort User->dbsources(\%$form);
890 $form->{CHARTS} = [];
892 opendir SQLDIR, "sql/." or $form - error($!);
893 foreach $item (sort grep /-chart\.sql\z/, readdir SQLDIR) {
894 next if ($item eq 'Default-chart.sql');
895 $item =~ s/-chart\.sql//;
896 push @{ $form->{CHARTS} }, { "name" => $item,
897 "selected" => $item eq "Germany-DATEV-SKR03EU" };
901 my $default_charset = $dbcharset;
902 $default_charset ||= Common::DEFAULT_CHARSET;
904 $form->{DBENCODINGS} = [];
906 foreach my $encoding (@Common::db_encodings) {
907 push @{ $form->{DBENCODINGS} }, { "dbencoding" => $encoding->{dbencoding},
908 "label" => $encoding->{label},
909 "selected" => $encoding->{charset} eq $default_charset };
914 . $locale->text('Database Administration') . " / "
915 . $locale->text('Create Dataset');
918 print $form->parse_html_template("admin/create_dataset");
922 $form->isblank("db", $locale->text('Dataset missing!'));
924 User->dbcreate(\%$form);
928 . $locale->text('Database Administration') . " / "
929 . $locale->text('Create Dataset');
932 print $form->parse_html_template("admin/dbcreate");
936 @dbsources = User->dbsources_unused(\%$form, $memberfile);
937 $form->error($locale->text('Nothing to delete!')) unless @dbsources;
941 . $locale->text('Database Administration') . " / "
942 . $locale->text('Delete Dataset');
943 $form->{DBSOURCES} = [ map { { "name", $_ } } sort @dbsources ];
946 print $form->parse_html_template("admin/delete_dataset");
952 $form->error($locale->text('No Dataset selected!'));
955 User->dbdelete(\%$form);
959 . $locale->text('Database Administration') . " / "
960 . $locale->text('Delete Dataset');
963 print $form->parse_html_template("admin/dbdelete");
968 unlink "$userspath/nologin";
971 "$form->{script}?action=list_users&rpw=$root->{password}";
973 $form->redirect($locale->text('Lockfile removed!'));
979 open(FH, ">$userspath/nologin")
980 or $form->error($locale->text('Cannot create Lock!'));
984 "$form->{script}?action=list_users&rpw=$root->{password}";
986 $form->redirect($locale->text('Lockfile created!'));