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) = @_;
55 &error("", "$memfile locked!") if (-f "${memfile}.LCK");
57 open(MEMBER, "$memfile") or &error("", "$memfile : $!");
68 # remove any trailing whitespace
71 ($key, $value) = split(/=/, $_, 2);
73 if (($key eq "stylesheet") && ($value eq "sql-ledger.css")) {
74 $value = "lx-office-erp.css";
77 $self->{$key} = $value;
80 $self->{login} = $login;
88 $main::lxdebug->leave_sub();
93 $main::lxdebug->enter_sub();
100 # scan the locale directory and read in the LANGUAGE files
101 opendir(DIR, "locale");
103 my @dir = grep(!/(^\.\.?$|\..*)/, readdir(DIR));
105 foreach my $dir (@dir) {
106 next unless open(FH, "locale/$dir/LANGUAGE");
110 $cc{$dir} = "@language";
115 $main::lxdebug->leave_sub();
121 $main::lxdebug->enter_sub();
123 my ($self, $form, $userspath) = @_;
129 if ($self->{login}) {
131 if ($self->{password}) {
132 if ($form->{hashed_password}) {
133 $form->{password} = $form->{hashed_password};
135 $form->{password} = crypt($form->{password},
136 substr($self->{login}, 0, 2));
138 if ($self->{password} ne $form->{password}) {
139 $main::lxdebug->leave_sub();
144 unless (-e "$userspath/$self->{login}.conf") {
145 $self->create_config();
148 do "$userspath/$self->{login}.conf";
149 $myconfig{dbpasswd} = unpack('u', $myconfig{dbpasswd});
151 # check if database is down
153 DBI->connect($myconfig{dbconnect}, $myconfig{dbuser},
155 or $self->error(DBI::errstr);
157 # we got a connection, check the version
158 my $query = qq|SELECT version FROM defaults|;
159 my $sth = $dbh->prepare($query);
160 $sth->execute || $form->dberror($query);
162 my ($dbversion) = $sth->fetchrow_array;
165 # add login to employee table if it does not exist
166 # no error check for employee table, ignore if it does not exist
167 $query = qq|SELECT id FROM employee WHERE login = ?|;
168 my ($login) = selectrow_query($form, $dbh, $query, $self->{login});
171 $query = qq|INSERT INTO employee (login, name, workphone, role)| .
172 qq|VALUES (?, ?, ?, ?)|;
173 my @values = ($self->{login}, $myconfig{name}, $myconfig{tel}, "user");
174 do_query($form, $dbh, $query, @values);
177 $self->create_schema_info_table($form, $dbh);
184 parse_dbupdate_controls($form, $myconfig{"dbdriver"});
186 map({ $form->{$_} = $myconfig{$_} }
187 qw(dbname dbhost dbport dbdriver dbuser dbpasswd dbconnect));
189 if (update_available($myconfig{"dbdriver"}, $dbversion) ||
190 update2_available($form, $controls)) {
192 $form->{"stylesheet"} = "lx-office-erp.css";
193 $form->{"title"} = $main::locale->text("Dataset upgrade");
195 print($form->parse_html_template("dbupgrade/header"));
197 $form->{dbupdate} = "db$myconfig{dbname}";
198 $form->{ $form->{dbupdate} } = 1;
200 if ($form->{"show_dbupdate_warning"}) {
201 print($form->parse_html_template("dbupgrade/warning"));
206 open(FH, ">$userspath/nologin") or die("$!");
208 # required for Oracle
209 $form->{dbdefault} = $sid;
211 # ignore HUP, QUIT in case the webserver times out
212 $SIG{HUP} = 'IGNORE';
213 $SIG{QUIT} = 'IGNORE';
215 $self->dbupdate($form);
216 $self->dbupdate2($form, $controls);
221 unlink("$userspath/nologin");
224 $self->{"menustyle"} eq "v3" ? "menuv3.pl" :
225 $self->{"menustyle"} eq "neu" ? "menunew.pl" :
228 print($form->parse_html_template("dbupgrade/footer",
229 { "menufile" => $menufile }));
236 $main::lxdebug->leave_sub();
242 $main::lxdebug->enter_sub();
244 my ($form, $db) = @_;
247 'Pg' => { 'yy-mm-dd' => 'set DateStyle to \'ISO\'',
248 'yyyy-mm-dd' => 'set DateStyle to \'ISO\'',
249 'mm/dd/yy' => 'set DateStyle to \'SQL, US\'',
250 'mm-dd-yy' => 'set DateStyle to \'POSTGRES, US\'',
251 'dd/mm/yy' => 'set DateStyle to \'SQL, EUROPEAN\'',
252 'dd-mm-yy' => 'set DateStyle to \'POSTGRES, EUROPEAN\'',
253 'dd.mm.yy' => 'set DateStyle to \'GERMAN\''
256 'yy-mm-dd' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'YY-MM-DD\'',
257 'yyyy-mm-dd' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'YYYY-MM-DD\'',
258 'mm/dd/yy' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'MM/DD/YY\'',
259 'mm-dd-yy' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'MM-DD-YY\'',
260 'dd/mm/yy' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'DD/MM/YY\'',
261 'dd-mm-yy' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'DD-MM-YY\'',
262 'dd.mm.yy' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'DD.MM.YY\'',
265 $form->{dboptions} = $dboptions{ $form->{dbdriver} }{ $form->{dateformat} };
267 if ($form->{dbdriver} eq 'Pg') {
268 $form->{dbconnect} = "dbi:Pg:dbname=$db";
271 if ($form->{dbdriver} eq 'Oracle') {
272 $form->{dbconnect} = "dbi:Oracle:sid=$form->{sid}";
275 if ($form->{dbhost}) {
276 $form->{dbconnect} .= ";host=$form->{dbhost}";
278 if ($form->{dbport}) {
279 $form->{dbconnect} .= ";port=$form->{dbport}";
282 $main::lxdebug->leave_sub();
286 $main::lxdebug->enter_sub();
288 my @drivers = DBI->available_drivers();
290 $main::lxdebug->leave_sub();
292 return (grep { /(Pg|Oracle)/ } @drivers);
296 $main::lxdebug->enter_sub();
298 my ($self, $form) = @_;
303 $form->{dbdefault} = $form->{dbuser} unless $form->{dbdefault};
304 $form->{sid} = $form->{dbdefault};
305 &dbconnect_vars($form, $form->{dbdefault});
308 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
311 if ($form->{dbdriver} eq 'Pg') {
313 qq|SELECT datname FROM pg_database | .
314 qq|WHERE NOT datname IN ('template0', 'template1')|;
315 $sth = $dbh->prepare($query);
316 $sth->execute() || $form->dberror($query);
318 while (my ($db) = $sth->fetchrow_array) {
320 if ($form->{only_acc_db}) {
322 next if ($db =~ /^template/);
324 &dbconnect_vars($form, $db);
326 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
330 qq|SELECT tablename FROM pg_tables | .
331 qq|WHERE (tablename = 'defaults') AND (tableowner = ?)|;
332 my $sth = $dbh->prepare($query);
333 $sth->execute($form->{dbuser}) ||
334 $form->dberror($query . " ($form->{dbuser})");
336 if ($sth->fetchrow_array) {
337 push(@dbsources, $db);
343 push(@dbsources, $db);
347 if ($form->{dbdriver} eq 'Oracle') {
348 if ($form->{only_acc_db}) {
350 qq|SELECT owner FROM dba_objects | .
351 qq|WHERE object_name = 'DEFAULTS' AND object_type = 'TABLE'|;
353 $query = qq|SELECT username FROM dba_users|;
356 $sth = $dbh->prepare($query);
357 $sth->execute || $form->dberror($query);
359 while (my ($db) = $sth->fetchrow_array) {
360 push(@dbsources, $db);
367 $main::lxdebug->leave_sub();
373 $main::lxdebug->enter_sub();
375 my ($self, $form) = @_;
377 $form->{sid} = $form->{dbdefault};
378 &dbconnect_vars($form, $form->{dbdefault});
380 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
382 $form->{db} =~ s/\"//g;
384 'Pg' => qq|CREATE DATABASE "$form->{db}"|,
386 qq|CREATE USER "$form->{db}" DEFAULT TABLESPACE USERS | .
387 qq|TEMPORARY TABLESPACE TEMP IDENTIFIED BY "$form->{db}"|
394 push(@{$dboptions{"Pg"}}, "ENCODING = " . $dbh->quote($form->{"encoding"}))
395 if ($form->{"encoding"});
396 if ($form->{"dbdefault"}) {
397 my $dbdefault = $form->{"dbdefault"};
398 $dbdefault =~ s/[^a-zA-Z0-9_\-]//g;
399 push(@{$dboptions{"Pg"}}, "TEMPLATE = $dbdefault");
402 my $query = $dbcreate{$form->{dbdriver}};
403 $query .= " WITH " . join(" ", @{$dboptions{"Pg"}}) if (@{$dboptions{"Pg"}});
405 do_query($form, $dbh, $query);
407 if ($form->{dbdriver} eq 'Oracle') {
408 $query = qq|GRANT CONNECT, RESOURCE TO "$form->{db}"|;
409 do_query($form, $dbh, $query);
413 # setup variables for the new database
414 if ($form->{dbdriver} eq 'Oracle') {
415 $form->{dbuser} = $form->{db};
416 $form->{dbpasswd} = $form->{db};
419 &dbconnect_vars($form, $form->{db});
421 $dbh = DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
424 my $db_charset = $Common::db_encoding_to_charset{$form->{encoding}};
425 $db_charset ||= Common::DEFAULT_CHARSET;
428 $self->process_query($form, $dbh, "sql/lx-office.sql", undef, $db_charset);
430 # load chart of accounts
431 $self->process_query($form, $dbh, "sql/$form->{chart}-chart.sql", undef, $db_charset);
433 $query = "UPDATE defaults SET coa = ?";
434 do_query($form, $dbh, $query, $form->{chart});
438 $main::lxdebug->leave_sub();
441 # Process a Perl script which updates the database.
442 # If the script returns 1 then the update was successful.
443 # Return code "2" means "needs more interaction; remove
444 # users/nologin and exit".
445 # All other return codes are fatal errors.
446 sub process_perl_script {
447 $main::lxdebug->enter_sub();
449 my ($self, $form, $dbh, $filename, $version_or_control, $db_charset) = @_;
451 my $fh = IO::File->new($filename, "r") or $form->error("$filename : $!\n");
453 my $file_charset = Common::DEFAULT_CHARSET;
455 if (ref($version_or_control) eq "HASH") {
456 $file_charset = $version_or_control->{charset};
461 next if !/^--\s*\@charset:\s*(.+)/;
465 $fh->seek(0, SEEK_SET);
468 my $contents = join "", <$fh>;
471 $db_charset ||= Common::DEFAULT_CHARSET;
473 my $iconv = SL::Iconv::get_converter($file_charset, $db_charset);
477 my %dbup_myconfig = ();
478 map({ $dbup_myconfig{$_} = $form->{$_}; }
479 qw(dbname dbuser dbpasswd dbhost dbport dbconnect));
481 my $nls_file = $filename;
482 $nls_file =~ s|.*/||;
483 $nls_file =~ s|.pl$||;
484 my $dbup_locale = Locale->new($main::language, $nls_file);
486 my $result = eval($contents);
493 if (!defined($result)) {
494 print($form->parse_html_template("dbupgrade/error",
495 { "file" => $filename,
498 } elsif (1 != $result) {
499 unlink("users/nologin") if (2 == $result);
503 if (ref($version_or_control) eq "HASH") {
504 $dbh->do("INSERT INTO schema_info (tag, login) VALUES (" .
505 $dbh->quote($version_or_control->{"tag"}) . ", " .
506 $dbh->quote($form->{"login"}) . ")");
507 } elsif ($version_or_control) {
508 $dbh->do("UPDATE defaults SET version = " .
509 $dbh->quote($version_or_control));
513 $main::lxdebug->leave_sub();
517 $main::lxdebug->enter_sub();
519 my ($self, $form, $dbh, $filename, $version_or_control, $db_charset) = @_;
521 my $fh = IO::File->new($filename, "r") or $form->error("$filename : $!\n");
526 my $file_charset = Common::DEFAULT_CHARSET;
529 next if !/^--\s*\@charset:\s*(.+)/;
533 $fh->seek(0, SEEK_SET);
535 $db_charset ||= Common::DEFAULT_CHARSET;
540 $_ = SL::Iconv::convert($file_charset, $db_charset, $_);
542 # Remove DOS and Unix style line endings.
548 for (my $i = 0; $i < length($_); $i++) {
549 my $char = substr($_, $i, 1);
551 # Are we inside a string?
553 if ($char eq $quote_chars[-1]) {
559 if (($char eq "'") || ($char eq "\"")) {
560 push(@quote_chars, $char);
562 } elsif ($char eq ";") {
564 # Query is complete. Send it.
566 $sth = $dbh->prepare($query);
567 if (!$sth->execute()) {
568 my $errstr = $dbh->errstr;
571 $form->dberror("The database update/creation did not succeed. " .
572 "The file ${filename} containing the following " .
573 "query failed:<br>${query}<br>" .
574 "The error message was: ${errstr}<br>" .
575 "All changes in that file have been reverted.");
588 if (ref($version_or_control) eq "HASH") {
589 $dbh->do("INSERT INTO schema_info (tag, login) VALUES (" .
590 $dbh->quote($version_or_control->{"tag"}) . ", " .
591 $dbh->quote($form->{"login"}) . ")");
592 } elsif ($version_or_control) {
593 $dbh->do("UPDATE defaults SET version = " .
594 $dbh->quote($version_or_control));
600 $main::lxdebug->leave_sub();
604 $main::lxdebug->enter_sub();
606 my ($self, $form) = @_;
607 $form->{db} =~ s/\"//g;
608 my %dbdelete = ('Pg' => qq|DROP DATABASE "$form->{db}"|,
609 'Oracle' => qq|DROP USER "$form->{db}" CASCADE|);
611 $form->{sid} = $form->{dbdefault};
612 &dbconnect_vars($form, $form->{dbdefault});
614 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
616 my $query = $dbdelete{$form->{dbdriver}};
617 do_query($form, $dbh, $query);
621 $main::lxdebug->leave_sub();
624 sub dbsources_unused {
625 $main::lxdebug->enter_sub();
627 my ($self, $form, $memfile) = @_;
634 $form->error('File locked!') if (-f "${memfile}.LCK");
637 open(FH, "$memfile") or $form->error("$memfile : $!");
641 my ($null, $item) = split(/=/);
648 $form->{only_acc_db} = 1;
649 my @db = &dbsources("", $form);
651 push @dbexcl, $form->{dbdefault};
653 foreach $item (@db) {
654 unless (grep /$item$/, @dbexcl) {
655 push @dbsources, $item;
659 $main::lxdebug->leave_sub();
665 $main::lxdebug->enter_sub();
667 my ($self, $form) = @_;
672 $form->{sid} = $form->{dbdefault};
673 &dbconnect_vars($form, $form->{dbdefault});
676 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
679 if ($form->{dbdriver} eq 'Pg') {
682 qq|SELECT d.datname FROM pg_database d, pg_user u | .
683 qq|WHERE d.datdba = u.usesysid AND u.usename = ?|;
684 my $sth = prepare_execute_query($form, $dbh, $query, $form->{dbuser});
686 while (my ($db) = $sth->fetchrow_array) {
688 next if ($db =~ /^template/);
690 &dbconnect_vars($form, $db);
693 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
697 qq|SELECT tablename FROM pg_tables | .
698 qq|WHERE tablename = 'defaults'|;
699 my $sth2 = prepare_execute_query($form, $dbh, $query);
701 if ($sth2->fetchrow_array) {
702 $query = qq|SELECT version FROM defaults|;
703 my ($version) = selectrow_query($form, $dbh2, $query);
704 $dbsources{$db} = $version;
712 if ($form->{dbdriver} eq 'Oracle') {
714 qq|SELECT owner FROM dba_objects |.
715 qq|WHERE object_name = 'DEFAULTS' AND object_type = 'TABLE'|;
717 $sth = $dbh->prepare($query);
718 $sth->execute || $form->dberror($query);
720 while (my ($db) = $sth->fetchrow_array) {
722 $form->{dbuser} = $db;
723 &dbconnect_vars($form, $db);
726 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
729 $query = qq|SELECT version FROM defaults|;
730 my $sth = $dbh->prepare($query);
733 if (my ($version) = $sth->fetchrow_array) {
734 $dbsources{$db} = $version;
744 $main::lxdebug->leave_sub();
750 $main::lxdebug->enter_sub(2);
752 my (@v, $version, $i);
754 @v = split(/\./, $_[0]);
755 while (scalar(@v) < 4) {
759 for ($i = 0; $i < 4; $i++) {
764 $main::lxdebug->leave_sub(2);
768 sub cmp_script_version {
769 my ($a_from, $a_to, $b_from, $b_to);
770 my ($i, $res_a, $res_b);
771 my ($my_a, $my_b) = ($a, $b);
773 $my_a =~ s/.*-upgrade-//;
775 $my_b =~ s/.*-upgrade-//;
777 ($my_a_from, $my_a_to) = split(/-/, $my_a);
778 ($my_b_from, $my_b_to) = split(/-/, $my_b);
780 $res_a = calc_version($my_a_from);
781 $res_b = calc_version($my_b_from);
783 if ($res_a == $res_b) {
784 $res_a = calc_version($my_a_to);
785 $res_b = calc_version($my_b_to);
788 return $res_a <=> $res_b;
791 sub update_available {
792 my ($dbdriver, $cur_version) = @_;
796 opendir(SQLDIR, "sql/${dbdriver}-upgrade")
797 or &error("", "sql/${dbdriver}-upgrade: $!");
799 grep(/$form->{dbdriver}-upgrade-\Q$cur_version\E.*\.(sql|pl)$/,
803 return ($#upgradescripts > -1);
806 sub create_schema_info_table {
807 $main::lxdebug->enter_sub();
809 my ($self, $form, $dbh) = @_;
811 my $query = "SELECT tag FROM schema_info LIMIT 1";
812 if (!$dbh->do($query)) {
815 qq|CREATE TABLE schema_info (| .
818 qq| itime timestamp DEFAULT now(), | .
819 qq| PRIMARY KEY (tag))|;
820 $dbh->do($query) || $form->dberror($query);
823 $main::lxdebug->leave_sub();
827 $main::lxdebug->enter_sub();
829 my ($self, $form) = @_;
833 $form->{sid} = $form->{dbdefault};
835 my @upgradescripts = ();
839 if ($form->{dbupdate}) {
841 # read update scripts into memory
842 opendir(SQLDIR, "sql/" . $form->{dbdriver} . "-upgrade")
843 or &error("", "sql/" . $form->{dbdriver} . "-upgrade : $!");
845 sort(cmp_script_version
846 grep(/$form->{dbdriver}-upgrade-.*?\.(sql|pl)$/,
851 my $db_charset = $main::dbcharset;
852 $db_charset ||= Common::DEFAULT_CHARSET;
854 foreach my $db (split(/ /, $form->{dbupdate})) {
856 next unless $form->{$db};
858 # strip db from dataset
860 &dbconnect_vars($form, $db);
863 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
867 $query = qq|SELECT version FROM defaults|;
868 my ($version) = selectrow_query($form, $dbh, $query);
870 next unless $version;
872 $version = calc_version($version);
874 foreach my $upgradescript (@upgradescripts) {
875 my $a = $upgradescript;
876 $a =~ s/^$form->{dbdriver}-upgrade-|\.(sql|pl)$//g;
879 my ($mindb, $maxdb) = split /-/, $a;
880 my $str_maxdb = $maxdb;
881 $mindb = calc_version($mindb);
882 $maxdb = calc_version($maxdb);
884 next if ($version >= $maxdb);
886 # if there is no upgrade script exit
887 last if ($version < $mindb);
890 $main::lxdebug->message(DEBUG2, "Applying Update $upgradescript");
891 if ($file_type eq "sql") {
892 $self->process_query($form, $dbh, "sql/" . $form->{"dbdriver"} .
893 "-upgrade/$upgradescript", $str_maxdb, $db_charset);
895 $self->process_perl_script($form, $dbh, "sql/" . $form->{"dbdriver"} .
896 "-upgrade/$upgradescript", $str_maxdb, $db_charset);
908 $main::lxdebug->leave_sub();
914 $main::lxdebug->enter_sub();
916 my ($self, $form, $controls) = @_;
918 $form->{sid} = $form->{dbdefault};
920 my @upgradescripts = ();
921 my ($query, $sth, $tag);
924 @upgradescripts = sort_dbupdate_controls($controls);
926 my $db_charset = $main::dbcharset;
927 $db_charset ||= Common::DEFAULT_CHARSET;
929 foreach my $db (split / /, $form->{dbupdate}) {
931 next unless $form->{$db};
933 # strip db from dataset
935 &dbconnect_vars($form, $db);
938 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
941 map({ $_->{"applied"} = 0; } @upgradescripts);
943 $query = qq|SELECT tag FROM schema_info|;
944 $sth = $dbh->prepare($query);
945 $sth->execute() || $form->dberror($query);
946 while (($tag) = $sth->fetchrow_array()) {
947 $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag}));
952 foreach (@upgradescripts) {
953 if (!$_->{"applied"}) {
959 next if ($all_applied);
961 foreach my $control (@upgradescripts) {
962 next if ($control->{"applied"});
964 $control->{description} = SL::Iconv::convert($control->{charset}, $db_charset, $control->{description});
966 $control->{"file"} =~ /\.(sql|pl)$/;
970 $main::lxdebug->message(DEBUG2, "Applying Update $control->{file}");
971 print($form->parse_html_template("dbupgrade/upgrade_message2",
974 if ($file_type eq "sql") {
975 $self->process_query($form, $dbh, "sql/" . $form->{"dbdriver"} .
976 "-upgrade2/$control->{file}", $control, $db_charset);
978 $self->process_perl_script($form, $dbh, "sql/" . $form->{"dbdriver"} .
979 "-upgrade2/$control->{file}", $control, $db_charset);
988 $main::lxdebug->leave_sub();
993 sub update2_available {
994 $main::lxdebug->enter_sub();
996 my ($form, $controls) = @_;
998 map({ $_->{"applied"} = 0; } values(%{$controls}));
1000 dbconnect_vars($form, $form->{"dbname"});
1003 DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}) ||
1006 my ($query, $tag, $sth);
1008 $query = qq|SELECT tag FROM schema_info|;
1009 $sth = $dbh->prepare($query);
1010 $sth->execute() || $form->dberror($query);
1011 while (($tag) = $sth->fetchrow_array()) {
1012 $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag}));
1017 map({ $main::lxdebug->leave_sub() and return 1 if (!$_->{"applied"}) }
1018 values(%{$controls}));
1020 $main::lxdebug->leave_sub();
1025 $main::lxdebug->enter_sub();
1031 @config = config_vars();
1033 my $userspath = $main::userspath;
1035 open(CONF, ">", "$userspath/$self->{login}.conf") || $self->error("$userspath/$self->{login}.conf : $!");
1037 # create the config file
1038 print CONF qq|# configuration file for $self->{login}
1043 foreach my $key (sort @config) {
1044 $self->{$key} =~ s/\'/\\\'/g;
1045 print CONF qq| $key => '$self->{$key}',\n|;
1048 print CONF qq|);\n\n|;
1052 $main::lxdebug->leave_sub();
1056 $main::lxdebug->enter_sub();
1058 my ($self, $memberfile, $userspath) = @_;
1064 # format dbconnect and dboptions string
1065 &dbconnect_vars($self, $self->{dbname});
1067 $self->error('File locked!') if (-f "${memberfile}.LCK");
1068 open(FH, ">${memberfile}.LCK") or $self->error("${memberfile}.LCK : $!");
1071 open(CONF, "+<$memberfile") or $self->error("$memberfile : $!");
1078 while ($line = shift @config) {
1079 if ($line =~ /^\[$self->{login}\]/) {
1086 # remove everything up to next login or EOF
1087 while ($line = shift @config) {
1088 last if ($line =~ /^\[/);
1091 # this one is either the next login or EOF
1094 while ($line = shift @config) {
1098 print CONF qq|[$self->{login}]\n|;
1100 if ((($self->{dbpasswd} ne $self->{old_dbpasswd}) || $newmember)
1102 $self->{dbpasswd} = pack 'u', $self->{dbpasswd};
1103 chop $self->{dbpasswd};
1105 if (defined($self->{new_password})) {
1106 if ($self->{new_password} ne $self->{old_password}) {
1107 $self->{password} = crypt $self->{new_password},
1108 substr($self->{login}, 0, 2)
1109 if $self->{new_password};
1112 if ($self->{password} ne $self->{old_password}) {
1113 $self->{password} = crypt $self->{password}, substr($self->{login}, 0, 2)
1114 if $self->{password};
1118 if ($self->{'root login'}) {
1119 @config = ("password");
1121 @config = &config_vars;
1124 # replace \r\n with \n
1125 map { $self->{$_} =~ s/\r\n/\\n/g } qw(address signature);
1126 foreach $key (sort @config) {
1127 print CONF qq|$key=$self->{$key}\n|;
1132 unlink "${memberfile}.LCK";
1135 $self->create_config() unless $self->{'root login'};
1137 $main::lxdebug->leave_sub();
1141 $main::lxdebug->enter_sub();
1143 my @conf = qw(acs address admin businessnumber company countrycode
1144 currency dateformat dbconnect dbdriver dbhost dbport dboptions
1145 dbname dbuser dbpasswd email fax name numberformat password
1146 printer role sid signature stylesheet tel templates vclimit angebote
1147 bestellungen rechnungen anfragen lieferantenbestellungen einkaufsrechnungen
1148 taxnumber co_ustid duns menustyle template_format default_media
1149 default_printer_id copies show_form_details);
1151 $main::lxdebug->leave_sub();
1157 $main::lxdebug->enter_sub();
1159 my ($self, $msg) = @_;
1161 $main::lxdebug->show_backtrace();
1163 if ($ENV{HTTP_USER_AGENT}) {
1164 print qq|Content-Type: text/html
1166 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
1168 <body bgcolor=ffffff>
1170 <h2><font color=red>Error!</font></h2>
1175 die "Error: $msg\n";
1177 $main::lxdebug->leave_sub();