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
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; either version 2 of the License, or
20 # (at your option) any later version.
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #=====================================================================
31 # user related functions
33 #=====================================================================
45 $main::lxdebug->enter_sub();
47 my ($type, $memfile, $login) = @_;
51 &error("", "$memfile locked!") if (-f "${memfile}.LCK");
53 open(MEMBER, "$memfile") or &error("", "$memfile : $!");
64 # remove any trailing whitespace
67 ($key, $value) = split(/=/, $_, 2);
69 if (($key eq "stylesheet") && ($value eq "sql-ledger.css")) {
70 $value = "lx-office-erp.css";
73 $self->{$key} = $value;
76 $self->{login} = $login;
84 $main::lxdebug->leave_sub();
89 $main::lxdebug->enter_sub();
94 # scan the locale directory and read in the LANGUAGE files
95 opendir(DIR, "locale");
97 my @dir = grep(!/(^\.\.?$|\..*)/, readdir(DIR));
99 foreach my $dir (@dir) {
100 next unless open(FH, "locale/$dir/LANGUAGE");
104 $cc{$dir} = "@language";
109 $main::lxdebug->leave_sub();
115 $main::lxdebug->enter_sub();
117 my ($self, $form, $userspath) = @_;
121 if ($self->{login}) {
123 if ($self->{password}) {
124 if ($form->{hashed_password}) {
125 $form->{password} = $form->{hashed_password};
127 $form->{password} = crypt($form->{password},
128 substr($self->{login}, 0, 2));
130 if ($self->{password} ne $form->{password}) {
131 $main::lxdebug->leave_sub();
136 unless (-e "$userspath/$self->{login}.conf") {
137 $self->create_config("$userspath/$self->{login}.conf");
140 do "$userspath/$self->{login}.conf";
141 $myconfig{dbpasswd} = unpack('u', $myconfig{dbpasswd});
143 # check if database is down
145 DBI->connect($myconfig{dbconnect}, $myconfig{dbuser},
147 or $self->error(DBI::errstr);
149 # we got a connection, check the version
150 my $query = qq|SELECT version FROM defaults|;
151 my $sth = $dbh->prepare($query);
152 $sth->execute || $form->dberror($query);
154 my ($dbversion) = $sth->fetchrow_array;
157 # add login to employee table if it does not exist
158 # no error check for employee table, ignore if it does not exist
159 $query = qq|SELECT id FROM employee WHERE login = ?|;
160 my ($login) = selectrow_query($form, $dbh, $query, $self->{login});
163 $query = qq|INSERT INTO employee (login, name, workphone, role)| .
164 qq|VALUES (?, ?, ?, ?)|;
165 my @values = ($self->{login}, $myconfig{name}, $myconfig{tel}, "user");
166 do_query($form, $dbh, $query, @values);
169 $self->create_schema_info_table($form, $dbh);
176 parse_dbupdate_controls($form, $myconfig{"dbdriver"});
178 map({ $form->{$_} = $myconfig{$_} }
179 qw(dbname dbhost dbport dbdriver dbuser dbpasswd dbconnect));
181 if (update_available($myconfig{"dbdriver"}, $dbversion) ||
182 update2_available($form, $controls)) {
184 $form->{"stylesheet"} = "lx-office-erp.css";
185 $form->{"title"} = $main::locale->text("Dataset upgrade");
187 print($form->parse_html_template("dbupgrade/header"));
189 $form->{dbupdate} = "db$myconfig{dbname}";
190 $form->{ $form->{dbupdate} } = 1;
192 if ($form->{"show_dbupdate_warning"}) {
193 print($form->parse_html_template("dbupgrade/warning"));
198 open(FH, ">$userspath/nologin") or die("$!");
200 # required for Oracle
201 $form->{dbdefault} = $sid;
203 # ignore HUP, QUIT in case the webserver times out
204 $SIG{HUP} = 'IGNORE';
205 $SIG{QUIT} = 'IGNORE';
207 $self->dbupdate($form);
208 $self->dbupdate2($form, $controls);
211 unlink("$userspath/nologin");
214 $self->{"menustyle"} eq "v3" ? "menuv3.pl" :
215 $self->{"menustyle"} eq "neu" ? "menunew.pl" :
218 print($form->parse_html_template("dbupgrade/footer",
219 { "menufile" => $menufile }));
226 $main::lxdebug->leave_sub();
232 $main::lxdebug->enter_sub();
234 my ($form, $db) = @_;
237 'Pg' => { 'yy-mm-dd' => 'set DateStyle to \'ISO\'',
238 'yyyy-mm-dd' => 'set DateStyle to \'ISO\'',
239 'mm/dd/yy' => 'set DateStyle to \'SQL, US\'',
240 'mm-dd-yy' => 'set DateStyle to \'POSTGRES, US\'',
241 'dd/mm/yy' => 'set DateStyle to \'SQL, EUROPEAN\'',
242 'dd-mm-yy' => 'set DateStyle to \'POSTGRES, EUROPEAN\'',
243 'dd.mm.yy' => 'set DateStyle to \'GERMAN\''
246 'yy-mm-dd' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'YY-MM-DD\'',
247 'yyyy-mm-dd' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'YYYY-MM-DD\'',
248 'mm/dd/yy' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'MM/DD/YY\'',
249 'mm-dd-yy' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'MM-DD-YY\'',
250 'dd/mm/yy' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'DD/MM/YY\'',
251 'dd-mm-yy' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'DD-MM-YY\'',
252 'dd.mm.yy' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'DD.MM.YY\'',
255 $form->{dboptions} = $dboptions{ $form->{dbdriver} }{ $form->{dateformat} };
257 if ($form->{dbdriver} eq 'Pg') {
258 $form->{dbconnect} = "dbi:Pg:dbname=$db";
261 if ($form->{dbdriver} eq 'Oracle') {
262 $form->{dbconnect} = "dbi:Oracle:sid=$form->{sid}";
265 if ($form->{dbhost}) {
266 $form->{dbconnect} .= ";host=$form->{dbhost}";
268 if ($form->{dbport}) {
269 $form->{dbconnect} .= ";port=$form->{dbport}";
272 $main::lxdebug->leave_sub();
276 $main::lxdebug->enter_sub();
278 my @drivers = DBI->available_drivers();
280 $main::lxdebug->leave_sub();
282 return (grep { /(Pg|Oracle)/ } @drivers);
286 $main::lxdebug->enter_sub();
288 my ($self, $form) = @_;
293 $form->{dbdefault} = $form->{dbuser} unless $form->{dbdefault};
294 $form->{sid} = $form->{dbdefault};
295 &dbconnect_vars($form, $form->{dbdefault});
298 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
301 if ($form->{dbdriver} eq 'Pg') {
303 qq|SELECT datname FROM pg_database | .
304 qq|WHERE NOT datname IN ('template0', 'template1')|;
305 $sth = $dbh->prepare($query);
306 $sth->execute() || $form->dberror($query);
308 while (my ($db) = $sth->fetchrow_array) {
310 if ($form->{only_acc_db}) {
312 next if ($db =~ /^template/);
314 &dbconnect_vars($form, $db);
316 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
320 qq|SELECT tablename FROM pg_tables | .
321 qq|WHERE (tablename = 'defaults') AND (tableowner = ?)|;
322 my $sth = $dbh->prepare($query);
323 $sth->execute($form->{dbuser}) ||
324 $form->dberror($query . " ($form->{dbuser})");
326 if ($sth->fetchrow_array) {
327 push(@dbsources, $db);
333 push(@dbsources, $db);
337 if ($form->{dbdriver} eq 'Oracle') {
338 if ($form->{only_acc_db}) {
340 qq|SELECT owner FROM dba_objects | .
341 qq|WHERE object_name = 'DEFAULTS' AND object_type = 'TABLE'|;
343 $query = qq|SELECT username FROM dba_users|;
346 $sth = $dbh->prepare($query);
347 $sth->execute || $form->dberror($query);
349 while (my ($db) = $sth->fetchrow_array) {
350 push(@dbsources, $db);
357 $main::lxdebug->leave_sub();
363 $main::lxdebug->enter_sub();
365 my ($self, $form) = @_;
367 $form->{sid} = $form->{dbdefault};
368 &dbconnect_vars($form, $form->{dbdefault});
370 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
372 $form->{db} =~ s/\"//g;
374 'Pg' => qq|CREATE DATABASE "$form->{db}"|,
376 qq|CREATE USER "$form->{db}" DEFAULT TABLESPACE USERS | .
377 qq|TEMPORARY TABLESPACE TEMP IDENTIFIED BY "$form->{db}"|
384 push(@{$dboptions{"Pg"}}, "ENCODING = " . $dbh->quote($form->{"encoding"}))
385 if ($form->{"encoding"});
386 if ($form->{"dbdefault"}) {
387 my $dbdefault = $form->{"dbdefault"};
388 $dbdefault =~ s/[^a-zA-Z0-9_\-]//g;
389 push(@{$dboptions{"Pg"}}, "TEMPLATE = $dbdefault");
392 my $query = $dbcreate{$form->{dbdriver}};
393 $query .= " WITH " . join(" ", @{$dboptions{"Pg"}}) if (@{$dboptions{"Pg"}});
395 do_query($form, $dbh, $query);
397 if ($form->{dbdriver} eq 'Oracle') {
398 $query = qq|GRANT CONNECT, RESOURCE TO "$form->{db}"|;
399 do_query($form, $dbh, $query);
403 # setup variables for the new database
404 if ($form->{dbdriver} eq 'Oracle') {
405 $form->{dbuser} = $form->{db};
406 $form->{dbpasswd} = $form->{db};
409 &dbconnect_vars($form, $form->{db});
411 $dbh = DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
414 my $db_charset = $Common::db_encoding_to_charset{$form->{encoding}};
415 $db_charset ||= Common::DEFAULT_CHARSET;
418 $self->process_query($form, $dbh, "sql/lx-office.sql", undef, $db_charset);
420 # load chart of accounts
421 $self->process_query($form, $dbh, "sql/$form->{chart}-chart.sql", undef, $db_charset);
423 $query = "UPDATE defaults SET coa = ?";
424 do_query($form, $dbh, $query, $form->{chart});
428 $main::lxdebug->leave_sub();
431 # Process a Perl script which updates the database.
432 # If the script returns 1 then the update was successful.
433 # Return code "2" means "needs more interaction; remove
434 # users/nologin and exit".
435 # All other return codes are fatal errors.
436 sub process_perl_script {
437 $main::lxdebug->enter_sub();
439 my ($self, $form, $dbh, $filename, $version_or_control, $db_charset) = @_;
441 my $fh = IO::File->new($filename, "r") or $form->error("$filename : $!\n");
443 my $file_charset = Common::DEFAULT_CHARSET;
445 if (ref($version_or_control) eq "HASH") {
446 $file_charset = $version_or_control->{charset};
451 next if !/^--\s*\@charset:\s*(.+)/;
455 $fh->seek(0, SEEK_SET);
458 my $contents = join "", <$fh>;
461 $db_charset ||= Common::DEFAULT_CHARSET;
463 my $iconv = SL::Iconv::get_converter($file_charset, $db_charset);
467 my %dbup_myconfig = ();
468 map({ $dbup_myconfig{$_} = $form->{$_}; }
469 qw(dbname dbuser dbpasswd dbhost dbport dbconnect));
471 my $nls_file = $filename;
472 $nls_file =~ s|.*/||;
473 $nls_file =~ s|.pl$||;
474 my $dbup_locale = Locale->new($main::language, $nls_file);
476 my $result = eval($contents);
483 if (!defined($result)) {
484 print($form->parse_html_template("dbupgrade/error",
485 { "file" => $filename,
488 } elsif (1 != $result) {
489 unlink("users/nologin") if (2 == $result);
493 if (ref($version_or_control) eq "HASH") {
494 $dbh->do("INSERT INTO schema_info (tag, login) VALUES (" .
495 $dbh->quote($version_or_control->{"tag"}) . ", " .
496 $dbh->quote($form->{"login"}) . ")");
497 } elsif ($version_or_control) {
498 $dbh->do("UPDATE defaults SET version = " .
499 $dbh->quote($version_or_control));
503 $main::lxdebug->leave_sub();
507 $main::lxdebug->enter_sub();
509 my ($self, $form, $dbh, $filename, $version_or_control, $db_charset) = @_;
511 my $fh = IO::File->new($filename, "r") or $form->error("$filename : $!\n");
516 my $file_charset = Common::DEFAULT_CHARSET;
519 next if !/^--\s*\@charset:\s*(.+)/;
523 $fh->seek(0, SEEK_SET);
525 $db_charset ||= Common::DEFAULT_CHARSET;
530 $_ = SL::Iconv::convert($file_charset, $db_charset, $_);
532 # Remove DOS and Unix style line endings.
538 for (my $i = 0; $i < length($_); $i++) {
539 my $char = substr($_, $i, 1);
541 # Are we inside a string?
543 if ($char eq $quote_chars[-1]) {
549 if (($char eq "'") || ($char eq "\"")) {
550 push(@quote_chars, $char);
552 } elsif ($char eq ";") {
554 # Query is complete. Send it.
556 $sth = $dbh->prepare($query);
557 if (!$sth->execute()) {
558 my $errstr = $dbh->errstr;
561 $form->dberror("The database update/creation did not succeed. " .
562 "The file ${filename} containing the following " .
563 "query failed:<br>${query}<br>" .
564 "The error message was: ${errstr}<br>" .
565 "All changes in that file have been reverted.");
578 if (ref($version_or_control) eq "HASH") {
579 $dbh->do("INSERT INTO schema_info (tag, login) VALUES (" .
580 $dbh->quote($version_or_control->{"tag"}) . ", " .
581 $dbh->quote($form->{"login"}) . ")");
582 } elsif ($version_or_control) {
583 $dbh->do("UPDATE defaults SET version = " .
584 $dbh->quote($version_or_control));
590 $main::lxdebug->leave_sub();
594 $main::lxdebug->enter_sub();
596 my ($self, $form) = @_;
597 $form->{db} =~ s/\"//g;
598 my %dbdelete = ('Pg' => qq|DROP DATABASE "$form->{db}"|,
599 'Oracle' => qq|DROP USER "$form->{db}" CASCADE|);
601 $form->{sid} = $form->{dbdefault};
602 &dbconnect_vars($form, $form->{dbdefault});
604 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
606 my $query = $dbdelete{$form->{dbdriver}};
607 do_query($form, $dbh, $query);
611 $main::lxdebug->leave_sub();
614 sub dbsources_unused {
615 $main::lxdebug->enter_sub();
617 my ($self, $form, $memfile) = @_;
622 $form->error('File locked!') if (-f "${memfile}.LCK");
625 open(FH, "$memfile") or $form->error("$memfile : $!");
629 my ($null, $item) = split(/=/);
636 $form->{only_acc_db} = 1;
637 my @db = &dbsources("", $form);
639 push @dbexcl, $form->{dbdefault};
641 foreach $item (@db) {
642 unless (grep /$item$/, @dbexcl) {
643 push @dbsources, $item;
647 $main::lxdebug->leave_sub();
653 $main::lxdebug->enter_sub();
655 my ($self, $form) = @_;
660 $form->{sid} = $form->{dbdefault};
661 &dbconnect_vars($form, $form->{dbdefault});
664 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
667 if ($form->{dbdriver} eq 'Pg') {
670 qq|SELECT d.datname FROM pg_database d, pg_user u | .
671 qq|WHERE d.datdba = u.usesysid AND u.usename = ?|;
672 my $sth = prepare_execute_query($form, $dbh, $query, $form->{dbuser});
674 while (my ($db) = $sth->fetchrow_array) {
676 next if ($db =~ /^template/);
678 &dbconnect_vars($form, $db);
681 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
685 qq|SELECT tablename FROM pg_tables | .
686 qq|WHERE tablename = 'defaults'|;
687 my $sth2 = prepare_execute_query($form, $dbh, $query);
689 if ($sth2->fetchrow_array) {
690 $query = qq|SELECT version FROM defaults|;
691 my ($version) = selectrow_query($form, $dbh2, $query);
692 $dbsources{$db} = $version;
700 if ($form->{dbdriver} eq 'Oracle') {
702 qq|SELECT owner FROM dba_objects |.
703 qq|WHERE object_name = 'DEFAULTS' AND object_type = 'TABLE'|;
705 $sth = $dbh->prepare($query);
706 $sth->execute || $form->dberror($query);
708 while (my ($db) = $sth->fetchrow_array) {
710 $form->{dbuser} = $db;
711 &dbconnect_vars($form, $db);
714 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
717 $query = qq|SELECT version FROM defaults|;
718 my $sth = $dbh->prepare($query);
721 if (my ($version) = $sth->fetchrow_array) {
722 $dbsources{$db} = $version;
732 $main::lxdebug->leave_sub();
738 $main::lxdebug->enter_sub(2);
740 my (@v, $version, $i);
742 @v = split(/\./, $_[0]);
743 while (scalar(@v) < 4) {
747 for ($i = 0; $i < 4; $i++) {
752 $main::lxdebug->leave_sub(2);
756 sub cmp_script_version {
757 my ($a_from, $a_to, $b_from, $b_to);
758 my ($i, $res_a, $res_b);
759 my ($my_a, $my_b) = ($a, $b);
761 $my_a =~ s/.*-upgrade-//;
763 $my_b =~ s/.*-upgrade-//;
765 ($my_a_from, $my_a_to) = split(/-/, $my_a);
766 ($my_b_from, $my_b_to) = split(/-/, $my_b);
768 $res_a = calc_version($my_a_from);
769 $res_b = calc_version($my_b_from);
771 if ($res_a == $res_b) {
772 $res_a = calc_version($my_a_to);
773 $res_b = calc_version($my_b_to);
776 return $res_a <=> $res_b;
779 sub update_available {
780 my ($dbdriver, $cur_version) = @_;
782 opendir(SQLDIR, "sql/${dbdriver}-upgrade")
783 or &error("", "sql/${dbdriver}-upgrade: $!");
785 grep(/$form->{dbdriver}-upgrade-\Q$cur_version\E.*\.(sql|pl)$/,
789 return ($#upgradescripts > -1);
792 sub create_schema_info_table {
793 $main::lxdebug->enter_sub();
795 my ($self, $form, $dbh) = @_;
797 my $query = "SELECT tag FROM schema_info LIMIT 1";
798 if (!$dbh->do($query)) {
801 qq|CREATE TABLE schema_info (| .
804 qq| itime timestamp DEFAULT now(), | .
805 qq| PRIMARY KEY (tag))|;
806 $dbh->do($query) || $form->dberror($query);
809 $main::lxdebug->leave_sub();
813 $main::lxdebug->enter_sub();
815 my ($self, $form) = @_;
817 $form->{sid} = $form->{dbdefault};
819 my @upgradescripts = ();
823 if ($form->{dbupdate}) {
825 # read update scripts into memory
826 opendir(SQLDIR, "sql/" . $form->{dbdriver} . "-upgrade")
827 or &error("", "sql/" . $form->{dbdriver} . "-upgrade : $!");
829 sort(cmp_script_version
830 grep(/$form->{dbdriver}-upgrade-.*?\.(sql|pl)$/,
835 my $db_charset = $main::dbcharset;
836 $db_charset ||= Common::DEFAULT_CHARSET;
838 foreach my $db (split(/ /, $form->{dbupdate})) {
840 next unless $form->{$db};
842 # strip db from dataset
844 &dbconnect_vars($form, $db);
847 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
851 $query = qq|SELECT version FROM defaults|;
852 my ($version) = selectrow_query($form, $dbh, $query);
854 next unless $version;
856 $version = calc_version($version);
858 foreach my $upgradescript (@upgradescripts) {
859 my $a = $upgradescript;
860 $a =~ s/^$form->{dbdriver}-upgrade-|\.(sql|pl)$//g;
863 my ($mindb, $maxdb) = split /-/, $a;
864 my $str_maxdb = $maxdb;
865 $mindb = calc_version($mindb);
866 $maxdb = calc_version($maxdb);
868 next if ($version >= $maxdb);
870 # if there is no upgrade script exit
871 last if ($version < $mindb);
874 $main::lxdebug->message(DEBUG2, "Applying Update $upgradescript");
875 if ($file_type eq "sql") {
876 $self->process_query($form, $dbh, "sql/" . $form->{"dbdriver"} .
877 "-upgrade/$upgradescript", $str_maxdb, $db_charset);
879 $self->process_perl_script($form, $dbh, "sql/" . $form->{"dbdriver"} .
880 "-upgrade/$upgradescript", $str_maxdb, $db_charset);
892 $main::lxdebug->leave_sub();
898 $main::lxdebug->enter_sub();
900 my ($self, $form, $controls) = @_;
902 $form->{sid} = $form->{dbdefault};
904 my @upgradescripts = ();
905 my ($query, $sth, $tag);
908 @upgradescripts = sort_dbupdate_controls($controls);
910 my $db_charset = $main::dbcharset;
911 $db_charset ||= Common::DEFAULT_CHARSET;
913 foreach my $db (split / /, $form->{dbupdate}) {
915 next unless $form->{$db};
917 # strip db from dataset
919 &dbconnect_vars($form, $db);
922 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
925 map({ $_->{"applied"} = 0; } @upgradescripts);
927 $query = qq|SELECT tag FROM schema_info|;
928 $sth = $dbh->prepare($query);
929 $sth->execute() || $form->dberror($query);
930 while (($tag) = $sth->fetchrow_array()) {
931 $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag}));
936 foreach (@upgradescripts) {
937 if (!$_->{"applied"}) {
943 next if ($all_applied);
945 foreach my $control (@upgradescripts) {
946 next if ($control->{"applied"});
948 $control->{description} = SL::Iconv::convert($control->{charset}, $db_charset, $control->{description});
950 $control->{"file"} =~ /\.(sql|pl)$/;
954 $main::lxdebug->message(DEBUG2, "Applying Update $control->{file}");
955 print($form->parse_html_template("dbupgrade/upgrade_message2",
958 if ($file_type eq "sql") {
959 $self->process_query($form, $dbh, "sql/" . $form->{"dbdriver"} .
960 "-upgrade2/$control->{file}", $control, $db_charset);
962 $self->process_perl_script($form, $dbh, "sql/" . $form->{"dbdriver"} .
963 "-upgrade2/$control->{file}", $control, $db_charset);
972 $main::lxdebug->leave_sub();
977 sub update2_available {
978 $main::lxdebug->enter_sub();
980 my ($form, $controls) = @_;
982 map({ $_->{"applied"} = 0; } values(%{$controls}));
984 dbconnect_vars($form, $form->{"dbname"});
987 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}) ||
990 my ($query, $tag, $sth);
992 $query = qq|SELECT tag FROM schema_info|;
993 $sth = $dbh->prepare($query);
994 $sth->execute() || $form->dberror($query);
995 while (($tag) = $sth->fetchrow_array()) {
996 $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag}));
1001 map({ $main::lxdebug->leave_sub() and return 1 if (!$_->{"applied"}) }
1002 values(%{$controls}));
1004 $main::lxdebug->leave_sub();
1009 $main::lxdebug->enter_sub();
1011 my ($self, $filename) = @_;
1013 @config = &config_vars;
1015 open(CONF, ">$filename") or $self->error("$filename : $!");
1017 # create the config file
1018 print CONF qq|# configuration file for $self->{login}
1023 foreach $key (sort @config) {
1024 $self->{$key} =~ s/\'/\\\'/g;
1025 print CONF qq| $key => '$self->{$key}',\n|;
1028 print CONF qq|);\n\n|;
1032 $main::lxdebug->leave_sub();
1036 $main::lxdebug->enter_sub();
1038 my ($self, $memberfile, $userspath) = @_;
1042 # format dbconnect and dboptions string
1043 &dbconnect_vars($self, $self->{dbname});
1045 $self->error('File locked!') if (-f "${memberfile}.LCK");
1046 open(FH, ">${memberfile}.LCK") or $self->error("${memberfile}.LCK : $!");
1049 open(CONF, "+<$memberfile") or $self->error("$memberfile : $!");
1056 while ($line = shift @config) {
1057 if ($line =~ /^\[$self->{login}\]/) {
1064 # remove everything up to next login or EOF
1065 while ($line = shift @config) {
1066 last if ($line =~ /^\[/);
1069 # this one is either the next login or EOF
1072 while ($line = shift @config) {
1076 print CONF qq|[$self->{login}]\n|;
1078 if ((($self->{dbpasswd} ne $self->{old_dbpasswd}) || $newmember)
1080 $self->{dbpasswd} = pack 'u', $self->{dbpasswd};
1081 chop $self->{dbpasswd};
1083 if (defined($self->{new_password})) {
1084 if ($self->{new_password} ne $self->{old_password}) {
1085 $self->{password} = crypt $self->{new_password},
1086 substr($self->{login}, 0, 2)
1087 if $self->{new_password};
1090 if ($self->{password} ne $self->{old_password}) {
1091 $self->{password} = crypt $self->{password}, substr($self->{login}, 0, 2)
1092 if $self->{password};
1096 if ($self->{'root login'}) {
1097 @config = ("password");
1099 @config = &config_vars;
1102 # replace \r\n with \n
1103 map { $self->{$_} =~ s/\r\n/\\n/g } qw(address signature);
1104 foreach $key (sort @config) {
1105 print CONF qq|$key=$self->{$key}\n|;
1110 unlink "${memberfile}.LCK";
1113 $self->create_config("$userspath/$self->{login}.conf")
1114 unless $self->{'root login'};
1116 $main::lxdebug->leave_sub();
1120 $main::lxdebug->enter_sub();
1122 my @conf = qw(acs address admin businessnumber company countrycode
1123 currency dateformat dbconnect dbdriver dbhost dbport dboptions
1124 dbname dbuser dbpasswd email fax name numberformat password
1125 printer role sid signature stylesheet tel templates vclimit angebote
1126 bestellungen rechnungen anfragen lieferantenbestellungen einkaufsrechnungen
1127 taxnumber co_ustid duns menustyle template_format default_media
1128 default_printer_id copies show_form_details);
1130 $main::lxdebug->leave_sub();
1136 $main::lxdebug->enter_sub();
1138 my ($self, $msg) = @_;
1140 if ($ENV{HTTP_USER_AGENT}) {
1141 print qq|Content-Type: text/html
1143 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
1145 <body bgcolor=ffffff>
1147 <h2><font color=red>Error!</font></h2>
1152 die "Error: $msg\n";
1154 $main::lxdebug->leave_sub();