1 #=====================================================================
2 # SQL-Ledger Accounting
5 # Author: Dieter Simader
6 # Email: dsimader@sql-ledger.org
7 # Web: http://www.sql-ledger.org
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #======================================================================
25 # add/edit/delete users
27 #======================================================================
29 $menufile = "menu.ini";
37 $locale = new Locale $language, "admin";
39 eval { require DBI; };
40 $form->error($locale->text('DBI not installed!')) if ($@);
42 $form->{stylesheet} = "sql-ledger.css";
43 $form->{favicon} = "favicon.ico";
44 $form->{timeout} = 600;
46 require "$form->{path}/pw.pl";
49 if (-f "$form->{path}/custom_$form->{script}") {
50 eval { require "$form->{path}/custom_$form->{script}"; };
51 $form->error($@) if ($@);
55 if ($form->{action}) {
57 $subroutine = $locale->findsub($form->{action});
59 &check_password unless $form->{action} eq 'logout';
65 # if there are no drivers bail out
66 $form->error($locale->text('No Database Drivers available!')) unless (User->dbdrivers);
69 if (! -f $memberfile) {
70 open(FH, ">$memberfile") or $form->error("$memberfile : $!");
71 print FH qq|# SQL-Ledger Accounting members
90 $form->{title} = qq|SQL-Ledger $form->{version} |.$locale->text('Administration');
92 $form->{login} = "root login";
96 <script language="JavaScript" type="text/javascript">
99 document.admin.password.focus();
104 <body class=admin onload="sf()">
108 <a href="http://www.sql-ledger.org"><img src=sql-ledger.png border=0></a>
109 <h1 class=login>|.$locale->text('Version').qq| $form->{version}<p>|.$locale->text('Administration').qq|</h1>
111 <form method=post action="$form->{script}" name=admin>
115 <th>|.$locale->text('Password').qq|</th>
116 <td><input type=password name=password></td>
117 <td><input type=submit class=submit name=action value="|.$locale->text('Login').qq|"></td>
119 <input type=hidden name=action value=login>
120 <input type=hidden name=path value=$form->{path}>
121 <input type=hidden name=sessionid value=$form->{sessionid}>
126 <a href=http://www.sql-ledger.org>SQL-Ledger |.$locale->text('website').qq|</a>
146 $form->{callback} = "$form->{script}?path=$form->{path}&endsession=1";
147 $form->redirect($locale->text('You are logged out'));
154 $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Add User');
156 $form->{Oracle_sid} = $sid;
157 $form->{Oracle_dbport} = '1521';
158 $form->{Oracle_dbhost} = `hostname`;
160 if (-f "css/sql-ledger.css") {
161 $myconfig->{stylesheet} = "sql-ledger.css";
163 $myconfig->{vclimit} = 1000;
164 $myconfig->{menuwidth} = 155;
165 $myconfig->{timeout} = 3600;
176 $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Edit User');
188 $delete = qq|<input type=submit class=submit name=action value="|.$locale->text('Delete').qq|">
189 <input type=hidden name=edit value=1>|;
194 <input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}&sessionid=$form->{sessionid}">
196 <input type=hidden name=path value=$form->{path}>
197 <input type=hidden name=sessionid value=$form->{sessionid}>
199 <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">
213 open(FH, "$memberfile") or $form->error("$memberfile : $!");
216 <input type=submit class=submit name=action value="|.$locale->text('Lock System').qq|">|;
218 if (-e "$userspath/nologin") {
220 <input type=submit class=submit name=action value="|.$locale->text('Unlock System').qq|">|;
229 $login =~ s/(\[|\])//g;
232 if (/^(name=|company=|templates=|dbuser=|dbdriver=|dbname=|dbhost=)/) {
234 ($null, $member{$login}{$var}) = split /=/, $_, 2;
240 # type=submit $locale->text('Pg Database Administration')
241 # type=submit $locale->text('PgPP Database Administration')
242 # type=submit $locale->text('Oracle Database Administration')
244 foreach $item (User->dbdrivers) {
245 $dbdrivers .= qq|<input name=action type=submit class=submit value="|.$locale->text("$item Database Administration").qq|">|;
249 $column_header{login} = qq|<th>|.$locale->text('Login').qq|</th>|;
250 $column_header{name} = qq|<th>|.$locale->text('Name').qq|</th>|;
251 $column_header{company} = qq|<th>|.$locale->text('Company').qq|</th>|;
252 $column_header{dbdriver} = qq|<th>|.$locale->text('Driver').qq|</th>|;
253 $column_header{dbhost} = qq|<th>|.$locale->text('Host').qq|</th>|;
254 $column_header{dataset} = qq|<th>|.$locale->text('Dataset').qq|</th>|;
255 $column_header{templates} = qq|<th>|.$locale->text('Templates').qq|</th>|;
257 @column_index = qw(login name company dbdriver dbhost dataset templates);
259 $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Administration');
261 $form->{login} = "root login";
267 <form method=post action=$form->{script}>
271 <tr class=listheading>
272 <th>$form->{title}</th>
278 <tr class=listheading>|;
280 map { print "$column_header{$_}\n" } @column_index;
286 foreach $key (sort keys %member) {
287 $href = "$script?action=edit&login=$key&path=$form->{path}&sessionid=$form->{sessionid}";
290 $member{$key}{templates} =~ s/^$templates\///;
291 $member{$key}{dbhost} = $locale->text('localhost') unless $member{$key}{dbhost};
292 $member{$key}{dbname} = $member{$key}{dbuser} if ($member{$key}{dbdriver} eq 'Oracle');
294 $column_data{login} = qq|<td><a href=$href>$key</a></td>|;
295 $column_data{name} = qq|<td>$member{$key}{name}</td>|;
296 $column_data{company} = qq|<td>$member{$key}{company}</td>|;
297 $column_data{dbdriver} = qq|<td>$member{$key}{dbdriver}</td>|;
298 $column_data{dbhost} = qq|<td>$member{$key}{dbhost}</td>|;
299 $column_data{dataset} = qq|<td>$member{$key}{dbname}</td>|;
300 $column_data{templates} = qq|<td>$member{$key}{templates}</td>|;
304 <tr class=listrow$i>|;
306 map { print "$column_data{$_}\n" } @column_index;
318 <td><hr size=3 noshade></td>
322 <input type=hidden name=path value=$form->{path}>
323 <input type=hidden name=sessionid value=$form->{sessionid}>
325 <br><input type=submit class=submit name=action value="|.$locale->text('Add User').qq|">
326 <input type=submit class=submit name=action value="|.$locale->text('Change Admin Password').qq|">
331 <input type=submit class=submit name=action value="|.$locale->text('Logout').qq|">
335 |.$locale->text('Click on login name to edit!').qq|
337 |.$locale->text('To add a user to a group edit a name, change the login name and save. A new user with the same variables will then be saved under the new login name.').qq|
349 # if there is a login, get user
350 if ($form->{login}) {
352 $myconfig = new User "$memberfile", "$form->{login}";
354 $myconfig->{signature} =~ s/\\n/\r\n/g;
355 $myconfig->{address} =~ s/\\n/\r\n/g;
357 # strip basedir from templates directory
358 $myconfig->{templates} =~ s/^$templates\///;
360 $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd};
364 foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
365 $dateformat .= ($item eq $myconfig->{dateformat}) ? "<option selected>$item\n" : "<option>$item\n";
368 foreach $item (qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00)) {
369 $numberformat .= ($item eq $myconfig->{numberformat}) ? "<option selected>$item\n" : "<option>$item\n";
373 %countrycodes = User->country_codes;
376 foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
377 $countrycodes .= ($myconfig->{countrycode} eq $key) ? "<option selected value=$key>$countrycodes{$key}" : "<option value=$key>$countrycodes{$key}";
379 $countrycodes = qq|<option value="">English\n$countrycodes|;
381 # is there a templates basedir
382 if (! -d "$templates") {
383 $form->error($locale->text('Directory').": $templates ".$locale->text('does not exist'));
386 opendir TEMPLATEDIR, "$templates/." or $form->error("$templates : $!");
387 @all = grep !/^\.\.?$/, readdir TEMPLATEDIR;
388 closedir TEMPLATEDIR;
390 @allhtml = sort grep /\.html/, @all;
391 @alldir = grep !/\.(html|tex|txt)$/, @all;
393 @allhtml = reverse grep !/Default/, @allhtml;
394 push @allhtml, 'Default';
395 @allhtml = reverse @allhtml;
397 foreach $item (sort @alldir) {
398 if ($item eq $myconfig->{templates}) {
399 $usetemplates .= qq|<option selected>$item\n|;
401 $usetemplates .= qq|<option>$item\n|;
405 $lastitem = $allhtml[0];
406 $lastitem =~ s/-.*//g;
407 $mastertemplates = qq|<option>$lastitem\n|;
408 foreach $item (@allhtml) {
411 if ($item ne $lastitem) {
412 $mastertemplates .= qq|<option>$item\n|;
417 opendir CSS, "css/.";
418 @all = grep /.*\.css$/, readdir CSS;
421 foreach $item (@all) {
422 if ($item eq $myconfig->{stylesheet}) {
423 $selectstylesheet .= qq|<option selected>$item\n|;
425 $selectstylesheet .= qq|<option>$item\n|;
428 $selectstylesheet .= "<option>\n";
430 if (%printer && $latex) {
431 $selectprinter = "<option>\n";
432 foreach $item (sort keys %printer) {
433 if ($myconfig->{printer} eq $item) {
434 $selectprinter .= qq|<option value="$item" selected>$item\n|;
436 $selectprinter .= qq|<option value="$item">$item\n|;
442 <th align=right>|.$locale->text('Printer').qq|</th>
443 <td><select name=printer>$selectprinter</select></td>
449 $user = $form->{login};
450 $form->{login} = "root login";
452 $form->{login} = $user;
457 <form method=post action=$form->{script}>
460 <tr class=listheading><th colspan=2>$form->{title}</th></tr>
466 <th align=right>|.$locale->text('Login').qq|</th>
467 <td><input name=login value="$myconfig->{login}"></td>
470 <th align=right>|.$locale->text('Password').qq|</th>
471 <td><input type=password name=new_password size=8 value=$myconfig->{password}></td>
472 <input type=hidden name=old_password value=$myconfig->{password}>
475 <th align=right>|.$locale->text('Name').qq|</th>
476 <td><input name=name size=15 value="$myconfig->{name}"></td>
479 <th align=right>|.$locale->text('E-mail').qq|</th>
480 <td><input name=email size=30 value="$myconfig->{email}"></td>
483 <th align=right>|.$locale->text('Signature').qq|</th>
484 <td><textarea name=signature rows=3 cols=35>$myconfig->{signature}</textarea></td>
487 <th align=right>|.$locale->text('Phone').qq|</th>
488 <td><input name=tel size=14 value="$myconfig->{tel}"></td>
491 <th align=right>|.$locale->text('Fax').qq|</th>
492 <td><input name=fax size=14 value="$myconfig->{fax}"></td>
495 <th align=right>|.$locale->text('Company').qq|</th>
496 <td><input name=company size=35 value="$myconfig->{company}"></td>
499 <th align=right>|.$locale->text('Address').qq|</th>
500 <td><textarea name=address rows=4 cols=35>$myconfig->{address}</textarea></td>
507 <th align=right>|.$locale->text('Date Format').qq|</th>
508 <td><select name=dateformat>$dateformat</select></td>
511 <th align=right>|.$locale->text('Number Format').qq|</th>
512 <td><select name=numberformat>$numberformat</select></td>
515 <th align=right>|.$locale->text('Dropdown Limit').qq|</th>
516 <td><input name=vclimit value="$myconfig->{vclimit}"></td>
519 <th align=right>|.$locale->text('Menu Width').qq|</th>
520 <td><input name=menuwidth value="$myconfig->{menuwidth}"></td>
523 <th align=right>|.$locale->text('Language').qq|</th>
524 <td><select name=countrycode>$countrycodes</select></td>
527 <th align=right>|.$locale->text('Character Set').qq|</th>
528 <td><input name=charset value="$myconfig->{charset}"></td>
531 <th align=right>|.$locale->text('Session Timeout').qq|</th>
532 <td><input name=timeout value="$myconfig->{timeout}"></td>
536 <th align=right>|.$locale->text('Stylesheet').qq|</th>
537 <td><select name=userstylesheet>$selectstylesheet</select></td>
541 <th align=right>|.$locale->text('Use Templates').qq|</th>
542 <td><select name=usetemplates>$usetemplates</select></td>
545 <th align=right>|.$locale->text('New Templates').qq|</th>
546 <td><input name=newtemplates></td>
549 <th align=right>|.$locale->text('Setup Templates').qq|</th>
550 <td><select name=mastertemplates>$mastertemplates</select></td>
552 <input type=hidden name=templates value=$myconfig->{templates}>
556 <tr class=listheading>
557 <th colspan=2>|.$locale->text('Database').qq|</th>
560 # list section for database drivers
561 foreach $item (User->dbdrivers) {
570 if ($myconfig->{dbdriver} eq $item) {
571 map { $form->{"${item}_$_"} = $myconfig->{$_} } qw(dbhost dbport dbuser dbpasswd dbname sid);
572 $checked = "checked";
576 <th align=right>|.$locale->text('Driver').qq|</th>
577 <td><input name=dbdriver type=radio class=radio value=$item $checked> $item</td>
578 <th align=right>|.$locale->text('Host').qq|</th>
579 <td><input name="${item}_dbhost" size=30 value=$form->{"${item}_dbhost"}></td>
585 <th align=right>|.$locale->text('Dataset').qq|</th>
586 <td><input name="${item}_dbname" size=15 value=$form->{"${item}_dbname"}></td>
587 <th align=right>|.$locale->text('Port').qq|</th>
588 <td><input name="${item}_dbport" size=4 value=$form->{"${item}_dbport"}></td>
591 <th align=right>|.$locale->text('User').qq|</th>
592 <td><input name="${item}_dbuser" size=15 value=$form->{"${item}_dbuser"}></td>
593 <th align=right>|.$locale->text('Password').qq|</th>
594 <td><input name="${item}_dbpasswd" type=password size=10 value=$form->{"${item}_dbpasswd"}></td>
599 if ($item eq 'Oracle') {
601 <th align=right>SID</th>
602 <td><input name=Oracle_sid value=$form->{Oracle_sid}></td>
603 <th align=right>|.$locale->text('Port').qq|</th>
604 <td><input name="${item}_dbport size=4 value=$form->{"${item}_dbport"}></td>
607 <th align=right>|.$locale->text('Dataset').qq|</th>
608 <td><input name="${item}_dbuser" size=15 value=$form->{"${item}_dbuser"}></td>
609 <th align=right>|.$locale->text('Password').qq|</th>
610 <td><input name="${item}_dbpasswd" type=password size=10 value=$form->{"${item}_dbpasswd"}></td>
617 <input type=hidden name=old_dbpasswd value=$myconfig->{dbpasswd}>
622 <td colspan=2><hr size=2 noshade></td>
630 open(FH, $menufile) or $form->error("$menufile : $!");
631 # scan for first menu level
635 if (open(FH, "custom_$menufile")) {
641 next unless $item =~ /\[\w+/;
642 next if $item =~ /\#/;
644 $item =~ s/(\[|\])//g;
648 ($level, $menuitem) = split /--/, $item, 2;
652 push @acsorder, $item;
655 push @{ $acs{$level} }, $menuitem;
659 %role = ( 'admin' => $locale->text('Administrator'),
660 'user' => $locale->text('User'),
661 'manager' => $locale->text('Manager')
666 foreach $item (qw(user admin manager)) {
667 $selectrole .= ($myconfig->{role} eq $item) ? "<option selected value=$item>$role{$item}\n" : "<option value=$item>$role{$item}\n";
671 <tr class=listheading>
672 <th colspan=2>|.$locale->text('Access Control').qq|</th>
675 <td><select name=role>$selectrole</select></td>
679 foreach $item (split /;/, $myconfig->{acs}) {
680 ($key, $value) = split /--/, $item, 2;
681 $excl{$key}{$value} = 1;
684 foreach $key (@acsorder) {
686 $checked = "checked";
687 if ($form->{login}) {
688 $checked = ($excl{$key}{$key}) ? "" : "checked";
691 # can't have variable names with spaces
692 # the 1 is for apache 2
693 $item = $form->escape("${key}--$key", 1);
696 $acsheading =~ s/ / /g;
699 <th align=left><input name="$item" class=checkbox type=checkbox value=1 $checked> $acsheading</th>\n|;
700 $menuitems .= "$item;";
704 foreach $item (@{ $acs{$key} }) {
705 next if ($key eq $item);
707 $checked = "checked";
708 if ($form->{login}) {
709 $checked = ($excl{$key}{$item}) ? "" : "checked";
712 $acsitem = $form->escape("${key}--$item", 1);
715 <br><input name="$acsitem" class=checkbox type=checkbox value=1 $checked> $item|;
716 $menuitems .= "$acsitem;";
723 <tr valign=top>$acsheading $acsdata
728 print qq|<input type=hidden name=acs value="$menuitems">
731 <td colspan=2><hr size=3 noshade></td>
743 $form->error($locale->text('Database Driver not checked!')) unless $form->{dbdriver};
745 # no spaces allowed in login name
746 ($form->{login}) = split / /, $form->{login};
748 $form->isblank("login", $locale->text('Login name missing!'));
750 # check for duplicates
751 if (!$form->{edit}) {
752 $temp = new User "$memberfile", "$form->{login}";
754 if ($temp->{login}) {
755 $form->error("$form->{login} ".$locale->text('is already a member!'));
759 # no spaces allowed in directories
760 ($form->{newtemplates}) = split / /, $form->{newtemplates};
762 if ($form->{newtemplates}) {
763 $form->{templates} = $form->{newtemplates};
765 $form->{templates} = ($form->{usetemplates}) ? $form->{usetemplates} : $form->{login};
769 if (! -d "$templates") {
770 $form->error($locale->text('Directory').": $templates ".$locale->text('does not exist'));
773 # add base directory to $form->{templates}
774 $form->{templates} = "$templates/$form->{templates}";
777 $myconfig = new User "$memberfile", "$form->{login}";
779 # redo acs variable and delete all the acs codes
780 @acs = split /;/, $form->{acs};
783 foreach $item (@acs) {
784 $item = $form->escape($item, 1);
786 if (!$form->{$item}) {
787 $form->{acs} .= $form->unescape($form->unescape($item)).";";
789 delete $form->{$item};
792 # check which database was filled in
794 $form->{dbhost} = $form->{"$form->{dbdriver}_dbhost"};
795 $form->{dbport} = $form->{"$form->{dbdriver}_dbport"};
796 $form->{dbpasswd} = $form->{"$form->{dbdriver}_dbpasswd"};
797 $form->{dbuser} = $form->{"$form->{dbdriver}_dbuser"};
798 $form->{dbname} = $form->{"$form->{dbdriver}_dbname"};
800 if ($form->{dbdriver} eq 'Oracle') {
801 $form->{sid} = $form->{Oracle_sid}, ;
803 $form->isblank("dbhost", $locale->text('Hostname missing!'));
804 $form->isblank("dbport", $locale->text('Port missing!'));
805 $form->isblank("dbuser", $locale->text('Dataset missing!'));
807 if ($form->{dbdriver} =~ /Pg/) {
808 $form->isblank("dbname", $locale->text('Dataset missing!'));
809 $form->isblank("dbuser", $locale->text('Database User missing!'));
812 foreach $item (keys %{$form}) {
813 $myconfig->{$item} = $form->{$item};
816 $myconfig->{password} = $form->{new_password} if $form->{new_password} ne $form->{old_password};
818 delete $myconfig->{stylesheet};
819 if ($form->{userstylesheet}) {
820 $myconfig->{stylesheet} = $form->{userstylesheet};
823 $myconfig->save_member($memberfile, $userspath);
825 # create user template directory and copy master files
826 if (! -d "$form->{templates}") {
829 if (mkdir "$form->{templates}", oct("771")) {
833 # copy templates to the directory
834 opendir TEMPLATEDIR, "$templates/." or $form->error("$templates : $!");
835 @templates = grep /$form->{mastertemplates}.*?\.(html|tex|txt)$/, readdir TEMPLATEDIR;
836 closedir TEMPLATEDIR;
838 foreach $file (@templates) {
839 open(TEMP, "$templates/$file") or $form->error("$templates/$file : $!");
841 $file =~ s/$form->{mastertemplates}-//;
842 open(NEW, ">$form->{templates}/$file") or $form->error("$form->{templates}/$file : $!");
844 while ($line = <TEMP>) {
851 $form->error("$!: $form->{templates}");
855 $form->redirect($locale->text('User saved!'));
862 $form->{templates} = ($form->{templates}) ? "$templates/$form->{templates}" : "$templates/$form->{login}";
864 $form->error("$memberfile ".$locale->text('locked!')) if (-f ${memberfile}.LCK);
865 open(FH, ">${memberfile}.LCK") or $form->error("${memberfile}.LCK : $!");
868 if (! open(CONF, "+<$memberfile")) {
869 unlink "${memberfile}.LCK";
870 $form->error("$memberfile : $!");
878 while ($line = shift @config) {
882 if ($line =~ /^\[/) {
883 last if ($line =~ /\[$form->{login}\]/);
884 $login = &login_name($line);
887 if ($line =~ /^templates=/) {
888 $user{$login} = &get_value($line);
891 print CONF "$line\n";
894 # remove everything up to next login or EOF
895 # and save template variable
896 while ($line = shift @config) {
900 ($key, $value) = split /=/, $line, 2;
901 $myconfig{$key} = $value;
903 last if ($line =~ /^\[/);
906 # this one is either the next login or EOF
907 print CONF "$line\n";
909 $login = &login_name($line);
912 while ($line = shift @config) {
916 if ($line =~ /^\[/) {
917 $login = &login_name($line);
920 if ($line =~ /^templates=/) {
921 $user{$login} = &get_value($line);
924 print CONF "$line\n";
928 unlink "${memberfile}.LCK";
930 # scan %user for $templatedir
931 foreach $login (keys %user) {
932 last if ($found = ($myconfig{templates} eq $user{$login}));
935 map { $form->{$_} = $myconfig{$_} } keys %myconfig;
937 # if found keep directory otherwise delete
939 # delete it if there is a template directory
940 $dir = "$form->{templates}";
942 unlink <$dir/*.html>;
949 # delete config file for user
950 unlink "$userspath/$form->{login}.conf";
952 User::delete_login("", \%$form);
954 $form->redirect($locale->text('User deleted!'));
963 return ($login) ? $login : undef;
972 my ($null, $value) = split /=/, $line, 2;
975 $value =~ s/^\s*#.*//g;
977 # remove any trailing whitespace
978 $value =~ s/^\s*(.*?)\s*$/$1/;
985 sub change_admin_password {
987 $form->{title} = qq|SQL-Ledger |.$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Change Admin Password');
989 $form->{login} = "root login";
995 <form method=post action=$form->{script}>
999 <tr class=listheading>
1000 <th>|.$locale->text('Change Password').qq|</th>
1007 <th align=right>|.$locale->text('Password').qq|</th>
1008 <td><input type=password name=new_password></td>
1011 <th align=right>|.$locale->text('Confirm').qq|</th>
1012 <td><input type=password name=confirm_password></td>
1022 <input type=hidden name=path value=$form->{path}>
1023 <input type=hidden name=sessionid value=$form->{sessionid}>
1026 <input type=submit class=submit name=action value="|.$locale->text('Change Password').qq|">
1037 sub change_password {
1039 $form->error($locale->text('Passwords do not match!')) if $form->{new_password} ne $form->{confirm_password};
1041 $root->{password} = $form->{new_password};
1043 $root->{'root login'} = 1;
1044 $root->save_member($memberfile);
1046 $form->{callback} = "$form->{script}?action=list_users&path=$form->{path}&sessionid=$form->{sessionid}";
1048 $form->redirect($locale->text('Password changed!'));
1053 sub check_password {
1055 $root = new User "$memberfile", "root login";
1057 if ($root->{password}) {
1059 if ($form->{password}) {
1060 $form->{callback} .= "&password=$form->{password}" if $form->{callback};
1061 $form->{sessionid} = time;
1062 if ($root->{password} ne crypt $form->{password}, 'ro') {
1067 if ($ENV{HTTP_USER_AGENT}) {
1068 $ENV{HTTP_COOKIE} =~ s/;\s*/;/g;
1069 %cookie = split /[=;]/, $ENV{HTTP_COOKIE};
1070 if ((! $cookie{"SQL-Ledger-root login"}) || $cookie{"SQL-Ledger-root login"} ne $form->{sessionid}) {
1081 sub pg_database_administration {
1083 $form->{dbdriver} = 'Pg';
1089 sub pgpp_database_administration {
1091 $form->{dbdriver} = 'PgPP';
1097 sub oracle_database_administration {
1099 $form->{dbdriver} = 'Oracle';
1105 sub dbdriver_defaults {
1107 # load some defaults for the selected driver
1108 %driverdefaults = ( 'Pg' => { dbport => '',
1109 dbuser => 'sql-ledger',
1110 dbdefault => 'template1',
1112 connectstring => $locale->text('Connect to')
1114 'Oracle' => { dbport => '1521',
1117 dbhost => `hostname`,
1118 connectstring => 'SID'
1122 $driverdefaults{PgPP} = $driverdefaults{Pg};
1124 map { $form->{$_} = $driverdefaults{$form->{dbdriver}}{$_} } keys %{ $driverdefaults{Pg} };
1129 sub dbselect_source {
1133 $msg{Pg} = $locale->text('Leave host and port field empty unless you want to make a remote connection.');
1134 $msg{PgPP} = $msg{Pg};
1135 $msg{Oracle} = $locale->text('You must enter a host and port for local and remote connections!');
1138 $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." / ".$locale->text('Database Administration');
1140 $form->{login} = "root login";
1147 <h2>$form->{title}</h2>
1149 <form method=post action=$form->{script}>
1155 <tr class=listheading>
1156 <th colspan=4>|.$locale->text('Database').qq|</th>
1158 <input type=hidden name=dbdriver value=$form->{dbdriver}>
1163 <th align=right>|.$locale->text('Host').qq|</th>
1164 <td><input name=dbhost size=25 value=$form->{dbhost}></td>
1165 <th align=right>|.$locale->text('Port').qq|</th>
1166 <td><input name=dbport size=5 value=$form->{dbport}></td>
1169 <th align=right>|.$locale->text('User').qq|</th>
1170 <td><input name=dbuser size=10 value=$form->{dbuser}></td>
1171 <th align=right>|.$locale->text('Password').qq|</th>
1172 <td><input type=password name=dbpasswd size=10></td>
1176 <th align=right>$form->{connectstring}</th>
1177 <td colspan=3><input name=dbdefault size=10 value=$form->{dbdefault}></td>
1185 <input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}">
1186 <input type=hidden name=path value=$form->{path}>
1187 <input type=hidden name=sessionid value=$form->{sessionid}>
1191 <input type=submit class=submit name=action value="|.$locale->text('Create Dataset').qq|">
1192 <input type=submit class=submit name=action value="|.$locale->text('Update Dataset').qq|">
1193 <input type=submit class=submit name=action value="|.$locale->text('Delete Dataset').qq|">
1201 <p>|.$locale->text('This is a preliminary check for existing sources. Nothing will be created or deleted at this stage!')
1204 <br>$msg{$form->{dbdriver}}
1216 &{ $form->{nextsub} };
1221 sub update_dataset {
1223 %needsupdate = User->dbneedsupdate(\%$form);
1225 $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Update Dataset');
1227 $form->{login} = "root login";
1235 <h2>$form->{title}</h2>
1239 foreach $key (sort keys %needsupdate) {
1240 if ($needsupdate{$key} ne $form->{dbversion}) {
1241 $upd .= qq|<input name="db$key" type=checkbox value=1 checked> $key\n|;
1242 $form->{dbupdate} .= "db$key ";
1246 chop $form->{dbupdate};
1249 if ($form->{dbupdate}) {
1253 <form method=post action=$form->{script}>
1255 <input type=hidden name=dbdriver value=$form->{dbdriver}>
1256 <input type=hidden name=dbhost value=$form->{dbhost}>
1257 <input type=hidden name=dbport value=$form->{dbport}>
1258 <input type=hidden name=dbuser value=$form->{dbuser}>
1259 <input type=hidden name=dbpasswd value=$form->{dbpasswd}>
1260 <input type=hidden name=dbdefault value=$form->{dbdefault}>
1262 <tr class=listheading>
1263 <th>|.$locale->text('The following Datasets need to be updated').qq|</th>
1275 <input name=dbupdate type=hidden value="$form->{dbupdate}">
1277 <input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}">
1279 <input type=hidden name=path value=$form->{path}>
1280 <input type=hidden name=sessionid value=$form->{sessionid}>
1282 <input type=hidden name=nextsub value=dbupdate>
1287 <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
1296 print $locale->text('All Datasets up to date!');
1311 User->dbupdate(\%$form);
1313 $form->redirect($locale->text('Dataset updated!'));
1318 sub create_dataset {
1320 @dbsources = sort User->dbsources(\%$form);
1322 opendir SQLDIR, "sql/." or $form->error($!);
1323 foreach $item (sort grep /-chart\.sql/, readdir SQLDIR) {
1324 next if ($item eq 'Default-chart.sql');
1325 $item =~ s/-chart\.sql//;
1326 push @charts, qq|<input name=chart class=radio type=radio value="$item">$item|;
1330 # add Default at beginning
1331 unshift @charts, qq|<input name=chart class=radio type=radio value="Default" checked>Default|;
1333 $selectencoding = qq|<option>
1334 <option value=SQL_ASCII>ASCII
1335 <option value=EUC_JP>Japanese EUC
1336 <option value=EUC_CN>Chinese EUC
1337 <option value=EUC_KR>Korean EUC
1338 <option value=JOHAB>Korean EUC (Hangle base)
1339 <option value=EUC_TW>Taiwan EUC
1340 <option value=UNICODE>Unicode (UTF-8)
1341 <option value=MULE_INTERNAL>Mule internal type
1342 <option value=LATIN1>ISO 8859-1/ECMA 94 (Latin alphabet no. 1)
1343 <option value=LATIN2>ISO 8859-2/ECMA 94 (Latin alphabet no. 2)
1344 <option value=LATIN3>ISO 8859-3/ECMA 94 (Latin alphabet no. 3)
1345 <option value=LATIN4>ISO 8859-4/ECMA 94 (Latin alphabet no. 4)
1346 <option value=LATIN5>ISO 8859-9/ECMA 128 (Latin alphabet no. 5)
1347 <option value=LATIN6>ISO 8859-10/ECMA 144 (Latin alphabet no. 6)
1348 <option value=LATIN7>ISO 8859-13 (Latin alphabet no. 7)
1349 <option value=LATIN8>ISO 8859-14 (Latin alphabet no. 8)
1350 <option value=LATIN9>ISO 8859-15 (Latin alphabet no. 9)
1351 <option value=LATIN10>ISO 8859-16/ASRO SR 14111 (Latin alphabet no. 10)
1352 <option value=ISO_8859_5>ISO 8859-5/ECMA 113 (Latin/Cyrillic)
1353 <option value=ISO_8859_6>ISO 8859-6/ECMA 114 (Latin/Arabic)
1354 <option value=ISO_8859_7>ISO 8859-7/ECMA 118 (Latin/Greek)
1355 <option value=ISO_8859_8>ISO 8859-8/ECMA 121 (Latin/Hebrew)
1356 <option value=KOI8>KOI8-R(U)
1357 <option value=WIN>Windows CP1251
1358 <option value=ALT>Windows CP866
1359 <option value=WIN1256>Windows CP1256 (Arabic)
1360 <option value=TCVN>Windows CP1258 (Vietnamese)
1361 <option value=WIN874>Windows CP874 (Thai)
1364 $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Create Dataset');
1366 $form->{login} = "root login";
1374 <h2>$form->{title}</h2>
1376 <form method=post action=$form->{script}>
1379 <tr class=listheading>
1380 <th colspan=2> </th>
1385 <th align=right nowrap>|.$locale->text('Existing Datasets').qq|</th>
1389 map { print "[ $_ ] " } @dbsources;
1397 <th align=right nowrap>|.$locale->text('Create Dataset').qq|</th>
1398 <td><input name=db></td>
1404 <th align=right nowrap>|.$locale->text('Multibyte Encoding').qq|</th>
1405 <td><select name=encoding>$selectencoding</select></td>
1411 <th align=right nowrap>|.$locale->text('Create Chart of Accounts').qq|</th>
1421 map { print "<td>$charts[$_]</td>\n" } (0 .. 2);
1427 splice @charts, 0, 3;
1441 <input type=hidden name=dbdriver value=$form->{dbdriver}>
1442 <input type=hidden name=dbuser value=$form->{dbuser}>
1443 <input type=hidden name=dbhost value=$form->{dbhost}>
1444 <input type=hidden name=dbport value=$form->{dbport}>
1445 <input type=hidden name=dbpasswd value=$form->{dbpasswd}>
1446 <input type=hidden name=dbdefault value=$form->{dbdefault}>
1448 <input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}">
1450 <input type=hidden name=path value=$form->{path}>
1451 <input type=hidden name=sessionid value=$form->{sessionid}>
1453 <input type=hidden name=nextsub value=dbcreate>
1456 <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
1470 $form->isblank("db", $locale->text('Dataset missing!'));
1472 User->dbcreate(\%$form);
1474 $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Create Dataset');
1476 $form->{login} = "root login";
1484 <h2>$form->{title}</h2>
1486 <form method=post action=$form->{script}>|
1488 .$locale->text('Dataset')." $form->{db} ".$locale->text('successfully created!')
1492 <input type=hidden name=path value="$form->{path}">
1493 <input type=hidden name=sessionid value=$form->{sessionid}>
1495 <input type=hidden name=nextsub value=list_users>
1497 <p><input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
1508 sub delete_dataset {
1510 if (@dbsources = User->dbsources_unused(\%$form, $memberfile)) {
1511 foreach $item (sort @dbsources) {
1512 $dbsources .= qq|<input name=db class=radio type=radio value=$item> $item |;
1515 $form->error($locale->text('Nothing to delete!'));
1518 $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Delete Dataset');
1520 $form->{login} = "root login";
1526 <h2>$form->{title}</h2>
1528 <form method=post action=$form->{script}>
1531 <tr class=listheading>
1532 <th>|.$locale->text('The following Datasets are not in use and can be deleted').qq|</th>
1543 <input type=hidden name=dbdriver value=$form->{dbdriver}>
1544 <input type=hidden name=dbuser value=$form->{dbuser}>
1545 <input type=hidden name=dbhost value=$form->{dbhost}>
1546 <input type=hidden name=dbport value=$form->{dbport}>
1547 <input type=hidden name=dbpasswd value=$form->{dbpasswd}>
1548 <input type=hidden name=dbdefault value=$form->{dbdefault}>
1550 <input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}">
1552 <input type=hidden name=path value="$form->{path}">
1553 <input type=hidden name=sessionid value=$form->{sessionid}>
1555 <input type=hidden name=nextsub value=dbdelete>
1560 <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
1577 $form->error($locale->text('No Dataset selected!'));
1580 User->dbdelete(\%$form);
1582 $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Delete Dataset');
1584 $form->{login} = "root login";
1592 <h2>$form->{title}</h2>
1594 <form method=post action=$form->{script}>
1596 $form->{db} |.$locale->text('successfully deleted!')
1600 <input type=hidden name=path value="$form->{path}">
1601 <input type=hidden name=sessionid value=$form->{sessionid}>
1603 <input type=hidden name=nextsub value=list_users>
1605 <p><input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
1618 unlink "$userspath/nologin";
1620 $form->{callback} = "$form->{script}?action=list_users&path=$form->{path}&sessionid=$form->{sessionid}";
1622 $form->redirect($locale->text('Lockfile removed!'));
1629 open(FH, ">$userspath/nologin") or $form->error($locale->text('Cannot create Lock!'));
1632 $form->{callback} = "$form->{script}?action=list_users&path=$form->{path}&sessionid=$form->{sessionid}";
1634 $form->redirect($locale->text('Lockfile created!'));