summaryrefslogtreecommitdiff
path: root/LedgerSMB/User.pm
blob: 67249a0428d26e2903da18621da5e11b28aa4292 (plain)
  1. #=====================================================================
  2. # LedgerSMB
  3. # Small Medium Business Accounting software
  4. # http://www.ledgersmb.org/
  5. #
  6. # Copyright (C) 2006
  7. # This work contains copyrighted information from a number of sources all used
  8. # with permission.
  9. #
  10. # This file contains source code included with or based on SQL-Ledger which
  11. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  12. # under the GNU General Public License version 2 or, at your option, any later
  13. # version. For a full list including contact information of contributors,
  14. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  15. #
  16. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  17. # Copyright (C) 2000
  18. #
  19. # Author: DWS Systems Inc.
  20. # Web: http://www.sql-ledger.org
  21. #
  22. # Contributors: Jim Rawlings <jim@your-dba.com>
  23. #
  24. #======================================================================
  25. #
  26. # This file has undergone whitespace cleanup.
  27. #
  28. #======================================================================
  29. #
  30. # user related functions
  31. #
  32. #=====================================================================
  33. package LedgerSMB::User;
  34. use LedgerSMB::Sysconfig;
  35. sub new {
  36. my ($type, $memfile, $login) = @_;
  37. my $self = {};
  38. if ($login ne "") {
  39. &error("", "$memfile locked!") if (-f "${memfile}.LCK");
  40. open(MEMBER, "$memfile") or &error("", "$memfile : $!");
  41. while (<MEMBER>) {
  42. if (/^\[$login\]/) {
  43. while (<MEMBER>) {
  44. last if /^\[/;
  45. next if /^(#|\s)/;
  46. # remove comments
  47. s/^\s*#.*//g;
  48. # remove any trailing whitespace
  49. s/^\s*(.*?)\s*$/$1/;
  50. ($key, $value) = split /=/, $_, 2;
  51. $self->{$key} = $value;
  52. }
  53. $self->{login} = $login;
  54. last;
  55. }
  56. }
  57. close MEMBER;
  58. }
  59. bless $self, $type;
  60. }
  61. sub country_codes {
  62. use Locale::Country;
  63. use Locale::Language;
  64. my %cc = ();
  65. # scan the locale directory and read in the LANGUAGE files
  66. opendir DIR, "${LedgerSMB::Sysconfig::localepath}";
  67. my @dir = grep !/^\..*$/, readdir DIR;
  68. foreach my $dir (@dir) {
  69. $dir = substr($dir, 0, -3);
  70. $cc{$dir} = code2language(substr($dir, 0, 2));
  71. $cc{$dir} .= ("/" . code2country(substr($dir, 3, 2)))
  72. if length($dir) > 2;
  73. $cc{$dir} .= (" " . substr($dir, 6)) if length($dir) > 5;
  74. }
  75. closedir(DIR);
  76. %cc;
  77. }
  78. sub login {
  79. my ($self, $form) = @_;
  80. my $rc = -1;
  81. if ($self->{login} ne "") {
  82. if ($self->{password} ne "") {
  83. my $password =
  84. crypt $form->{password},
  85. substr($self->{login}, 0, 2);
  86. if ($self->{password} ne $password) {
  87. return -1;
  88. }
  89. }
  90. #there shouldn't be any harm in always doing this.
  91. #It might even un-bork things.
  92. $self->create_config(
  93. "${LedgerSMB::Sysconfig::userspath}/$self->{login}.conf");
  94. do "${LedgerSMB::Sysconfig::userspath}/$self->{login}.conf";
  95. $myconfig{dbpasswd} = unpack 'u', $myconfig{dbpasswd};
  96. # check if database is down
  97. my $dbh = DBI->connect(
  98. $myconfig{dbconnect}, $myconfig{dbuser},
  99. $myconfig{dbpasswd})
  100. or $self->error($DBI::errstr);
  101. # we got a connection, check the version
  102. my $query = qq|
  103. SELECT value FROM defaults
  104. WHERE setting_key = 'version'|;
  105. my $sth = $dbh->prepare($query);
  106. $sth->execute || $form->dberror($query);
  107. my ($dbversion) = $sth->fetchrow_array;
  108. $sth->finish;
  109. # add login to employee table if it does not exist
  110. # no error check for employee table, ignore if it does not exist
  111. my $login = $self->{login};
  112. $login =~ s/@.*//;
  113. $query = qq|SELECT id FROM employee WHERE login = ?|;
  114. $sth = $dbh->prepare($query);
  115. $sth->execute($login);
  116. my ($id) = $sth->fetchrow_array;
  117. $sth->finish;
  118. if (! $id) {
  119. my ($employeenumber) =
  120. $form->update_defaults(
  121. \%myconfig, "employeenumber", $dbh);
  122. $query = qq|
  123. INSERT INTO employee
  124. (login, employeenumber, name,
  125. workphone, role)
  126. VALUES (?, ?, ?, ?, ?)|;
  127. $sth = $dbh->prepare($query);
  128. $sth->execute(
  129. $login, $employeenumber, $myconfig{name},
  130. $myconfig{tel}, $myconfig{role});
  131. }
  132. $dbh->disconnect;
  133. $rc = 0;
  134. if ($form->{dbversion} ne $dbversion) {
  135. $rc = -3;
  136. $dbupdate = (calc_version($dbversion)
  137. < calc_version($form->{dbversion}));
  138. }
  139. if ($dbupdate) {
  140. $rc = -4;
  141. # if DB2 bale out
  142. if ($myconfig{dbdriver} eq 'DB2') {
  143. $rc = -2;
  144. }
  145. }
  146. }
  147. $rc;
  148. }
  149. sub check_recurring {
  150. my ($self, $form) = @_;
  151. $self->{dbpasswd} = unpack 'u', $self->{dbpasswd};
  152. my $dbh = DBI->connect(
  153. $self->{dbconnect}, $self->{dbuser}, $self->{dbpasswd})
  154. or $form->dberror;
  155. my $query = qq|
  156. SELECT count(*) FROM recurring
  157. WHERE enddate >= current_date AND nextdate <= current_date|;
  158. ($_) = $dbh->selectrow_array($query);
  159. $dbh->disconnect;
  160. $_;
  161. }
  162. sub dbconnect_vars {
  163. my ($form, $db) = @_;
  164. my %dboptions = (
  165. 'Pg' => {
  166. 'yy-mm-dd' => 'set DateStyle to \'ISO\'',
  167. 'mm/dd/yy' => 'set DateStyle to \'SQL, US\'',
  168. 'mm-dd-yy' => 'set DateStyle to \'POSTGRES, US\'',
  169. 'dd/mm/yy' => 'set DateStyle to \'SQL, EUROPEAN\'',
  170. 'dd-mm-yy' => 'set DateStyle to \'POSTGRES, EUROPEAN\'',
  171. 'dd.mm.yy' => 'set DateStyle to \'GERMAN\''
  172. }
  173. );
  174. $form->{dboptions} = $dboptions{$form->{dbdriver}}{$form->{dateformat}};
  175. $form->{dbconnect} = "dbi:$form->{dbdriver}:dbname=$db";
  176. if ($form->{dbhost}) {
  177. $form->{dbconnect} .= ";host=$form->{dbhost}";
  178. }
  179. if ($form->{dbport}) {
  180. $form->{dbconnect} .= ";port=$form->{dbport}";
  181. }
  182. }
  183. sub dbdrivers {
  184. my @drivers = DBI->available_drivers();
  185. # return (grep { /(Pg|Oracle|DB2)/ } @drivers);
  186. return (grep { /Pg$/ } @drivers);
  187. }
  188. sub dbsources {
  189. my ($self, $form) = @_;
  190. my @dbsources = ();
  191. my ($sth, $query);
  192. $form->{dbdefault} = $form->{dbuser} unless $form->{dbdefault};
  193. $form->{sid} = $form->{dbdefault};
  194. &dbconnect_vars($form, $form->{dbdefault});
  195. my $dbh = DBI->connect(
  196. $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
  197. or $form->dberror;
  198. if ($form->{dbdriver} eq 'Pg') {
  199. $query = qq|SELECT datname FROM pg_database|;
  200. $sth = $dbh->prepare($query);
  201. $sth->execute || $form->dberror($query);
  202. while (my ($db) = $sth->fetchrow_array) {
  203. if ($form->{only_acc_db}) {
  204. next if ($db =~ /^template/);
  205. &dbconnect_vars($form, $db);
  206. my $dbh = DBI->connect(
  207. $form->{dbconnect}, $form->{dbuser},
  208. $form->{dbpasswd})
  209. or $form->dberror;
  210. $query = qq|
  211. SELECT tablename FROM pg_tables
  212. WHERE tablename = 'defaults'
  213. AND tableowner = ?|;
  214. my $sth = $dbh->prepare($query);
  215. $sth->execute($form->{dbuser})
  216. || $form->dberror($query);
  217. if ($sth->fetchrow_array) {
  218. push @dbsources, $db;
  219. }
  220. $sth->finish;
  221. $dbh->disconnect;
  222. next;
  223. }
  224. push @dbsources, $db;
  225. }
  226. }
  227. $sth->finish;
  228. $dbh->disconnect;
  229. return @dbsources;
  230. }
  231. sub dbcreate {
  232. my ($self, $form) = @_;
  233. my %dbcreate = ( 'Pg' => qq|CREATE DATABASE "$form->{db}"| );
  234. $dbcreate{Pg} .= " WITH ENCODING = '$form->{encoding}'"
  235. if $form->{encoding};
  236. $form->{sid} = $form->{dbdefault};
  237. &dbconnect_vars($form, $form->{dbdefault});
  238. # The below line connects to Template1 or another template file in order
  239. # to create the db. One must disconnect and reconnect later.
  240. if ($form->{dbsuperuser}){
  241. my $superdbh = DBI->connect(
  242. $form->{dbconnect},
  243. $form->{dbsuperuser},
  244. $form->{dbsuperpasswd})
  245. or $form->dberror;
  246. my $query = qq|$dbcreate{$form->{dbdriver}}|;
  247. $superdbh->do($query) || $form->dberror($query);
  248. $superdbh->disconnect;
  249. }
  250. #Reassign for the work below
  251. &dbconnect_vars($form, $form->{db});
  252. my $dbh = DBI->connect(
  253. $form->{dbconnect},
  254. $form->{dbuser},
  255. $form->{dbpasswd})
  256. or $form->dberror;
  257. if ($form->{dbsuperuser}){
  258. my $superdbh = DBI->connect(
  259. $form->{dbconnect},
  260. $form->{dbsuperuser},
  261. $form->{dbsuperpasswd})
  262. or $form->dberror;
  263. # JD: We need to check for plpgsql,
  264. # if it isn't there create it, if we can't error
  265. # Good chance I will have to do this twice as I get
  266. # used to the way the code is structured
  267. my %langcreate = ( 'Pg' => qq|CREATE LANGUAGE plpgsql|);
  268. my $query = qq|$langcreate{$form->{dbdriver}}|;
  269. $superdbh->do($query);
  270. $superdbh->disconnect;
  271. }
  272. # create the tables
  273. my $dbdriver =
  274. ($form->{dbdriver} =~ /Pg/)
  275. ? 'Pg'
  276. : $form->{dbdriver};
  277. my $filename = qq|sql/Pg-database.sql|;
  278. $self->process_query($form, $dbh, $filename);
  279. # load gifi
  280. ($filename) = split /_/, $form->{chart};
  281. $filename =~ s/_//;
  282. $self->process_query($form, $dbh, "sql/${filename}-gifi.sql");
  283. # load chart of accounts
  284. $filename = qq|sql/$form->{chart}-chart.sql|;
  285. $self->process_query($form, $dbh, $filename);
  286. # create custom tables and functions
  287. my $item;
  288. foreach $item (qw(tables functions)) {
  289. $filename = "sql/${dbdriver}-custom_${item}.sql";
  290. if (-f "$filename") {
  291. $self->process_query($form, $dbh, $filename);
  292. }
  293. }
  294. $dbh->disconnect;
  295. }
  296. sub process_query {
  297. my ($self, $form, $dbh, $filename) = @_;
  298. return unless (-f $filename);
  299. open(FH, "$filename") or $form->error("$filename : $!\n");
  300. $ENV{PGPASSWORD} = $form->{dbpasswd};
  301. $ENV{PGUSER} = $form->{dbuser};
  302. $ENV{PGDATABASE} = $form->{db};
  303. open(PSQL, "| psql") or $form->error("psql : $! \n");
  304. print PSQL "\\o spool/log \n";
  305. while (<FH>){
  306. print PSQL $_;
  307. }
  308. close FH;
  309. }
  310. sub dbdelete {
  311. my ($self, $form) = @_;
  312. $form->{sid} = $form->{dbdefault};
  313. &dbconnect_vars($form, $form->{dbdefault});
  314. my $dbh = DBI->connect(
  315. $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
  316. or $form->dberror;
  317. my $query = qq|DROP DATABASE "$form->{db}"|;
  318. $dbh->do($query) || $form->dberror($query);
  319. $dbh->disconnect;
  320. }
  321. sub dbsources_unused {
  322. my ($self, $form, $memfile) = @_;
  323. my @dbexcl = ();
  324. my @dbsources = ();
  325. $form->error("$memfile locked!") if (-f "${memfile}.LCK");
  326. # open members file
  327. open(FH, "$memfile") or $form->error("$memfile : $!");
  328. while (<FH>) {
  329. if (/^dbname=/) {
  330. my ($null,$item) = split /=/;
  331. push @dbexcl, $item;
  332. }
  333. }
  334. close FH;
  335. $form->{only_acc_db} = 1;
  336. my @db = &dbsources("", $form);
  337. push @dbexcl, $form->{dbdefault};
  338. foreach $item (@db) {
  339. unless (grep /$item$/, @dbexcl) {
  340. push @dbsources, $item;
  341. }
  342. }
  343. return @dbsources;
  344. }
  345. sub dbneedsupdate {
  346. my ($self, $form) = @_;
  347. my %dbsources = ();
  348. my $query;
  349. $form->{sid} = $form->{dbdefault};
  350. &dbconnect_vars($form, $form->{dbdefault});
  351. my $dbh = DBI->connect(
  352. $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
  353. or $form->dberror;
  354. if ($form->{dbdriver} =~ /Pg/) {
  355. $query = qq|
  356. SELECT d.datname
  357. FROM pg_database d, pg_user u
  358. WHERE d.datdba = u.usesysid
  359. AND u.usename = ?|;
  360. my $sth = $dbh->prepare($query);
  361. $sth->execute($form->{dbuser}) || $form->dberror($query);
  362. while (my ($db) = $sth->fetchrow_array) {
  363. next if ($db =~ /^template/);
  364. &dbconnect_vars($form, $db);
  365. my $dbh = DBI->connect(
  366. $form->{dbconnect}, $form->{dbuser},
  367. $form->{dbpasswd})
  368. or $form->dberror;
  369. $query = qq|
  370. SELECT tablename
  371. FROM pg_tables
  372. WHERE tablename = 'defaults'|;
  373. my $sth = $dbh->prepare($query);
  374. $sth->execute || $form->dberror($query);
  375. if ($sth->fetchrow_array) {
  376. $query = qq|
  377. SELECT value FROM defaults
  378. WHERE setting_key = 'version'|;
  379. my $sth = $dbh->prepare($query);
  380. $sth->execute;
  381. if (my ($version) = $sth->fetchrow_array) {
  382. $dbsources{$db} = $version;
  383. }
  384. $sth->finish;
  385. }
  386. $sth->finish;
  387. $dbh->disconnect;
  388. }
  389. $sth->finish;
  390. }
  391. $dbh->disconnect;
  392. %dbsources;
  393. }
  394. sub dbupdate {
  395. my ($self, $form) = @_;
  396. $form->{sid} = $form->{dbdefault};
  397. my @upgradescripts = ();
  398. my $query;
  399. my $rc = -2;
  400. if ($form->{dbupdate}) {
  401. # read update scripts into memory
  402. opendir SQLDIR, "sql/." or $form->error($!);
  403. @upgradescripts =
  404. sort script_version
  405. grep /$form->{dbdriver}-upgrade-.*?\.sql$/,
  406. readdir SQLDIR;
  407. closedir SQLDIR;
  408. }
  409. foreach my $db (split / /, $form->{dbupdate}) {
  410. next unless $form->{$db};
  411. # strip db from dataset
  412. $db =~ s/^db//;
  413. &dbconnect_vars($form, $db);
  414. my $dbh = DBI->connect(
  415. $form->{dbconnect}, $form->{dbuser},
  416. $form->{dbpasswd}, {AutoCommit => 0})
  417. or $form->dberror;
  418. # check version
  419. $query = qq|
  420. SELECT value FROM defaults
  421. WHERE setting_key = 'version'|;
  422. my $sth = $dbh->prepare($query);
  423. # no error check, let it fall through
  424. $sth->execute;
  425. my $version = $sth->fetchrow_array;
  426. $sth->finish;
  427. next unless $version;
  428. $version = calc_version($version);
  429. my $dbversion = calc_version($form->{dbversion});
  430. foreach my $upgradescript (@upgradescripts) {
  431. my $a = $upgradescript;
  432. $a =~ s/(^$form->{dbdriver}-upgrade-|\.sql$)//g;
  433. my ($mindb, $maxdb) = split /-/, $a;
  434. $mindb = calc_version($mindb);
  435. $maxdb = calc_version($maxdb);
  436. next if ($version >= $maxdb);
  437. # exit if there is no upgrade script or version == mindb
  438. last if ($version < $mindb || $version >= $dbversion);
  439. # apply upgrade
  440. $self->process_query($form, $dbh, "sql/$upgradescript");
  441. $dbh->commit;
  442. $version = $maxdb;
  443. }
  444. $rc = 0;
  445. $dbh->disconnect;
  446. }
  447. $rc;
  448. }
  449. sub calc_version {
  450. my @v = split /\./, $_[0];
  451. my $version = 0;
  452. my $i;
  453. for ($i = 0; $i <= $#v; $i++) {
  454. $version *= 1000;
  455. $version += $v[$i];
  456. }
  457. return $version;
  458. }
  459. sub script_version {
  460. my ($my_a, $my_b) = ($a, $b);
  461. my ($a_from, $a_to, $b_from, $b_to);
  462. my ($res_a, $res_b, $i);
  463. $my_a =~ s/.*-upgrade-//;
  464. $my_a =~ s/.sql$//;
  465. $my_b =~ s/.*-upgrade-//;
  466. $my_b =~ s/.sql$//;
  467. ($a_from, $a_to) = split(/-/, $my_a);
  468. ($b_from, $b_to) = split(/-/, $my_b);
  469. $res_a = calc_version($a_from);
  470. $res_b = calc_version($b_from);
  471. if ($res_a == $res_b) {
  472. $res_a = calc_version($a_to);
  473. $res_b = calc_version($b_to);
  474. }
  475. return $res_a <=> $res_b;
  476. }
  477. sub create_config {
  478. my ($self, $filename) = @_;
  479. @config = &config_vars;
  480. open(CONF, ">$filename") or $self->error("$filename : $!");
  481. # create the config file
  482. print CONF qq|# configuration file for $self->{login}
  483. \%myconfig = (
  484. |;
  485. foreach $key (sort @config) {
  486. $self->{$key} =~ s/\\/\\\\/g;
  487. $self->{$key} =~ s/'/\\'/g;
  488. #remaining conversion from SL
  489. $self->{$key} =~ s/sql-ledger([^.]*)\.css/ledger-smb$1.css/g;
  490. print CONF qq| $key => '$self->{$key}',\n|;
  491. }
  492. print CONF qq|);\n\n|;
  493. close CONF;
  494. }
  495. sub save_member {
  496. my ($self) = @_;
  497. # format dbconnect and dboptions string
  498. &dbconnect_vars($self, $self->{dbname});
  499. $self->error("${LedgerSMB::Sysconfig::memberfile} locked!")
  500. if (-f "${LedgerSMB::Sysconfig::memberfile}.LCK");
  501. open(FH, ">${LedgerSMB::Sysconfig::memberfile}.LCK")
  502. or $self->error("${LedgerSMB::Sysconfig::memberfile}.LCK : $!");
  503. close(FH);
  504. if (! open(CONF, "+<${LedgerSMB::Sysconfig::memberfile}")) {
  505. unlink "${LedgerSMB::Sysconfig::memberfile}.LCK";
  506. $self->error("${LedgerSMB::Sysconfig::memberfile} : $!");
  507. }
  508. @config = <CONF>;
  509. seek(CONF, 0, 0);
  510. truncate(CONF, 0);
  511. while ($line = shift @config) {
  512. last if ($line =~ /^\[$self->{login}\]/);
  513. #remaining conversion from SL
  514. $line =~ s/sql-ledger([^.]*)\.css/ledger-smb$1.css/g;
  515. print CONF $line;
  516. }
  517. # remove everything up to next login or EOF
  518. while ($line = shift @config) {
  519. last if ($line =~ /^\[/);
  520. }
  521. # this one is either the next login or EOF
  522. print CONF $line;
  523. while ($line = shift @config) {
  524. print CONF $line;
  525. }
  526. print CONF qq|[$self->{login}]\n|;
  527. if ($self->{packpw}) {
  528. $self->{dbpasswd} = pack 'u', $self->{dbpasswd};
  529. chop $self->{dbpasswd};
  530. }
  531. if ($self->{password} ne $self->{old_password}) {
  532. $self->{password} = crypt $self->{password},
  533. substr($self->{login}, 0, 2) if $self->{password};
  534. }
  535. if ($self->{'root login'}) {
  536. @config = qw(password);
  537. } else {
  538. @config = &config_vars;
  539. }
  540. # replace \r\n with \n
  541. for (qw(address signature)) { $self->{$_} =~ s/\r?\n/\\n/g }
  542. for (sort @config) {
  543. print CONF qq|$_=$self->{$_}\n|
  544. }
  545. print CONF "\n";
  546. close CONF;
  547. unlink "${LedgerSMB::Sysconfig::memberfile}.LCK";
  548. # create conf file
  549. if (! $self->{'root login'}) {
  550. $self->create_config("${LedgerSMB::Sysconfig::userspath}/$self->{login}.conf");
  551. $self->{dbpasswd} =~ s/\\'/'/g;
  552. $self->{dbpasswd} =~ s/\\\\/\\/g;
  553. $self->{dbpasswd} = unpack 'u', $self->{dbpasswd};
  554. # check if login is in database
  555. my $dbh = DBI->connect(
  556. $self->{dbconnect}, $self->{dbuser}, $self->{dbpasswd},
  557. {AutoCommit => 0})
  558. or $self->error($DBI::errstr);
  559. # add login to employee table if it does not exist
  560. my $login = $self->{login};
  561. $login =~ s/@.*//;
  562. my $query = qq|SELECT id FROM employee WHERE login = '$login'|;
  563. my $sth = $dbh->prepare($query);
  564. $sth->execute;
  565. my ($id) = $sth->fetchrow_array;
  566. $sth->finish;
  567. my $employeenumber;
  568. my @values;
  569. if ($id) {
  570. $query = qq|UPDATE employee SET
  571. role = ?,
  572. email = ?,
  573. name = ?
  574. WHERE login = ?|;
  575. @values = ($self->{role}, $self->{email}, $self->{name}, $login);
  576. } else {
  577. my ($employeenumber) = Form::update_defaults(
  578. "", \%$self, "employeenumber", $dbh);
  579. $query = qq|
  580. INSERT INTO employee
  581. (login, employeenumber, name,
  582. workphone, role, email, sales)
  583. VALUES (?, ?, ?, ?, ?, ?, '1')|;
  584. @values = ($login, $employeenumber, $self->{name}, $self->{tel},
  585. $self->{role}, $self->{email})
  586. }
  587. $sth = $dbh->prepare($query);
  588. $sth->execute(@values);
  589. $dbh->commit;
  590. $dbh->disconnect;
  591. }
  592. }
  593. sub delete_login {
  594. my ($self, $form) = @_;
  595. my $dbh = DBI->connect(
  596. $form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd},
  597. {AutoCommit => 0})
  598. or $form->dberror;
  599. my $login = $form->{login};
  600. $login =~ s/@.*//;
  601. my $query = qq|SELECT id FROM employee WHERE login = ?|;
  602. my $sth = $dbh->prepare($query);
  603. $sth->execute($login) || $form->dberror($query);
  604. my ($id) = $sth->fetchrow_array;
  605. $sth->finish;
  606. my $query = qq|
  607. UPDATE employee
  608. SET login = NULL,
  609. enddate = current_date
  610. WHERE login = ?|;
  611. $sth = $dbh->prepare($query);
  612. $sth->execute($login);
  613. $dbh->commit;
  614. $dbh->disconnect;
  615. }
  616. sub config_vars {
  617. my @conf =
  618. qw(acs address businessnumber company countrycode
  619. currency dateformat dbconnect dbdriver dbhost dbname dboptions
  620. dbpasswd dbport dbuser email fax menuwidth name numberformat
  621. password printer role sid signature stylesheet tel templates
  622. timeout vclimit);
  623. @conf;
  624. }
  625. sub error {
  626. my ($self, $msg) = @_;
  627. if ($ENV{HTTP_USER_AGENT}) {
  628. print qq|Content-Type: text/html\n\n|.
  629. qq|<body bgcolor=ffffff>\n\n|.
  630. qq|<h2><font color=red>Error!</font></h2>\n|.
  631. qq|<p><b>$msg</b>|;
  632. }
  633. die "Error: $msg\n";
  634. }
  635. 1;