This commit was generated by cvs2svn to compensate for changes in r4407,
[freeside.git] / sql-ledger / bin / mozilla / admin.pl
1 #=====================================================================
2 # SQL-Ledger Accounting
3 # Copyright (c) 2002
4 #
5 #  Author: Dieter Simader
6 #   Email: dsimader@sql-ledger.org
7 #     Web: http://www.sql-ledger.org
8 #
9 #
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.
14 #
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 #======================================================================
23 #
24 # setup module
25 # add/edit/delete users
26 #
27 #======================================================================
28
29 $menufile = "menu.ini";
30
31 use SL::Form;
32 use SL::User;
33
34
35 $form = new Form;
36
37 $locale = new Locale $language, "admin";
38   
39 eval { require DBI; };
40 $form->error($locale->text('DBI not installed!')) if ($@);
41
42 $form->{stylesheet} = "sql-ledger.css";
43 $form->{favicon} = "favicon.ico";
44 $form->{timeout} = 600;
45
46 require "$form->{path}/pw.pl";
47
48 # customization
49 if (-f "$form->{path}/custom_$form->{script}") {
50   eval { require "$form->{path}/custom_$form->{script}"; };
51   $form->error($@) if ($@);
52 }
53
54
55 if ($form->{action}) {
56
57   $subroutine = $locale->findsub($form->{action});
58
59   &check_password unless $form->{action} eq 'logout';
60   
61   &$subroutine;
62     
63 } else {
64
65   # if there are no drivers bail out
66   $form->error($locale->text('No Database Drivers available!')) unless (User->dbdrivers);
67
68   # create memberfile
69   if (! -f $memberfile) {
70     open(FH, ">$memberfile") or $form->error("$memberfile : $!");
71     print FH qq|# SQL-Ledger Accounting members
72
73 [root login]
74 password=
75
76 |;
77     close FH;
78   }
79
80   &adminlogin;
81
82 }
83
84 1;
85 # end
86
87
88 sub adminlogin {
89
90   $form->{title} = qq|SQL-Ledger $form->{version} |.$locale->text('Administration');
91   
92   $form->{login} = "root login";
93   $form->header(1);
94   
95     print qq|
96 <script language="JavaScript" type="text/javascript">
97 <!--
98 function sf(){
99   document.admin.password.focus();
100 }
101 // End -->
102 </script>
103
104 <body class=admin onload="sf()">
105
106 <div align=center>
107
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>
110
111 <form method=post action="$form->{script}" name=admin>
112
113 <table>
114   <tr>
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>
118   </tr>
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}>
122 </table>
123
124 </form>
125
126 <a href=http://www.sql-ledger.org>SQL-Ledger |.$locale->text('website').qq|</a>
127
128 </div>
129
130 </body>
131 </html>
132 |;
133
134 }
135
136
137 sub login {
138
139   &list_users;
140
141 }
142
143
144 sub logout {
145
146   $form->{callback} = "$form->{script}?path=$form->{path}&endsession=1";
147   $form->redirect($locale->text('You are logged out'));
148
149 }
150
151
152 sub add_user {
153   
154   $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Add User');
155
156   $form->{Oracle_sid} = $sid;
157   $form->{Oracle_dbport} = '1521';
158   $form->{Oracle_dbhost} = `hostname`;
159
160   if (-f "css/sql-ledger.css") {
161     $myconfig->{stylesheet} = "sql-ledger.css";
162   }
163   $myconfig->{vclimit} = 1000;
164   $myconfig->{menuwidth} = 155;
165   $myconfig->{timeout} = 3600;
166   
167   &form_header;
168   &form_footer;
169   
170 }
171
172
173
174 sub edit {
175
176   $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Edit User');
177   $form->{edit} = 1;
178
179   &form_header;
180   &form_footer;
181
182 }
183
184
185 sub form_footer {
186
187   if ($form->{edit}) {
188     $delete = qq|<input type=submit class=submit name=action value="|.$locale->text('Delete').qq|">
189 <input type=hidden name=edit value=1>|;
190   }
191
192   print qq|
193
194 <input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}&sessionid=$form->{sessionid}">
195
196 <input type=hidden name=path value=$form->{path}>
197 <input type=hidden name=sessionid value=$form->{sessionid}>
198
199 <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">
200 $delete
201
202 </form>
203
204 </body>
205 </html>
206 |;
207
208 }
209
210
211 sub list_users {
212
213   open(FH, "$memberfile") or $form->error("$memberfile : $!");
214
215   $nologin = qq|
216 <input type=submit class=submit name=action value="|.$locale->text('Lock System').qq|">|;
217
218   if (-e "$userspath/nologin") {
219     $nologin = qq|
220 <input type=submit class=submit name=action value="|.$locale->text('Unlock System').qq|">|;
221   }
222
223
224   while (<FH>) {
225     chop;
226     
227     if (/^\[.*\]/) {
228       $login = $_;
229       $login =~ s/(\[|\])//g;
230     }
231
232     if (/^(name=|company=|templates=|dbuser=|dbdriver=|dbname=|dbhost=)/) {
233       chop ($var = $&);
234       ($null, $member{$login}{$var}) = split /=/, $_, 2;
235     }
236   }
237   
238   close(FH);
239
240 # type=submit $locale->text('Pg Database Administration')
241 # type=submit $locale->text('PgPP Database Administration')
242 # type=submit $locale->text('Oracle Database Administration')
243
244   foreach $item (User->dbdrivers) {
245     $dbdrivers .= qq|<input name=action type=submit class=submit value="|.$locale->text("$item Database Administration").qq|">|;
246   }
247
248
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>|;
256
257   @column_index = qw(login name company dbdriver dbhost dataset templates);
258
259   $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Administration');
260
261   $form->{login} = "root login";
262   $form->header;
263
264   print qq|
265 <body class=admin>
266
267 <form method=post action=$form->{script}>
268
269 <table width=100%>
270   <tr>
271   <tr class=listheading>
272     <th>$form->{title}</th>
273   </tr>
274   <tr size=5></tr>
275   <tr>
276     <td>
277       <table width=100%>
278         <tr class=listheading>|;
279
280   map { print "$column_header{$_}\n" } @column_index;
281   
282   print qq|
283         </tr>
284 |;
285
286 foreach $key (sort keys %member) {
287   $href = "$script?action=edit&login=$key&path=$form->{path}&sessionid=$form->{sessionid}";
288   $href =~ s/ /%20/g;
289   
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');
293
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>|;
301   
302   $i++; $i %= 2;
303   print qq|
304         <tr class=listrow$i>|;
305
306   map { print "$column_data{$_}\n" } @column_index;
307
308   print qq|
309         </tr>|;
310 }
311
312
313 print qq|
314       </table>
315     </td>
316   </tr>
317   <tr>
318     <td><hr size=3 noshade></td>
319   </tr>
320 </table>
321
322 <input type=hidden name=path value=$form->{path}>
323 <input type=hidden name=sessionid value=$form->{sessionid}>
324
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|">
327
328 $dbdrivers
329 $nologin
330
331 <input type=submit class=submit name=action value="|.$locale->text('Logout').qq|">
332
333 </form>
334
335 |.$locale->text('Click on login name to edit!').qq|
336 <br>
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|
338
339 </body>
340 </html>
341 |;
342
343 }
344
345
346
347 sub form_header {
348
349   # if there is a login, get user
350   if ($form->{login}) {
351     # get user
352     $myconfig = new User "$memberfile", "$form->{login}";
353
354     $myconfig->{signature} =~ s/\\n/\r\n/g;
355     $myconfig->{address} =~ s/\\n/\r\n/g;
356
357     # strip basedir from templates directory
358     $myconfig->{templates} =~ s/^$templates\///;
359
360     $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd};
361   }
362
363
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";
366   }
367
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";
370   }
371
372
373   %countrycodes = User->country_codes;
374   $countrycodes = "";
375   
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}";
378   }
379   $countrycodes = qq|<option value="">English\n$countrycodes|;
380
381   # is there a templates basedir
382   if (! -d "$templates") {
383     $form->error($locale->text('Directory').": $templates ".$locale->text('does not exist'));
384   }
385
386   opendir TEMPLATEDIR, "$templates/." or $form->error("$templates : $!");
387   @all = grep !/^\.\.?$/, readdir TEMPLATEDIR;
388   closedir TEMPLATEDIR;
389
390   @allhtml = sort grep /\.html/, @all;
391   @alldir = grep !/\.(html|tex|txt)$/, @all;
392   
393   @allhtml = reverse grep !/Default/, @allhtml;
394   push @allhtml, 'Default';
395   @allhtml = reverse @allhtml;
396   
397   foreach $item (sort @alldir) {
398     if ($item eq $myconfig->{templates}) {
399       $usetemplates .= qq|<option selected>$item\n|;
400     } else {
401       $usetemplates .= qq|<option>$item\n|;
402     }
403   }
404   
405   $lastitem = $allhtml[0];
406   $lastitem =~ s/-.*//g;
407   $mastertemplates = qq|<option>$lastitem\n|;
408   foreach $item (@allhtml) {
409     $item =~ s/-.*//g;
410     
411     if ($item ne $lastitem) {
412       $mastertemplates .= qq|<option>$item\n|;
413       $lastitem = $item;
414     }
415   }
416
417   opendir CSS, "css/.";
418   @all = grep /.*\.css$/, readdir CSS;
419   closedir CSS;
420   
421   foreach $item (@all) {
422     if ($item eq $myconfig->{stylesheet}) {
423       $selectstylesheet .= qq|<option selected>$item\n|;
424     } else {
425       $selectstylesheet .= qq|<option>$item\n|;
426     }
427   }
428   $selectstylesheet .= "<option>\n";
429   
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|;
435       } else {
436         $selectprinter .= qq|<option value="$item">$item\n|;
437       }
438     }
439
440     $printer = qq|
441         <tr>
442           <th align=right>|.$locale->text('Printer').qq|</th>
443           <td><select name=printer>$selectprinter</select></td>
444         </tr>
445 |;
446
447   }
448   
449   $user = $form->{login};
450   $form->{login} = "root login";
451   $form->header;
452   $form->{login} = $user;
453  
454   print qq|
455 <body class=admin>
456
457 <form method=post action=$form->{script}>
458
459 <table width=100%>
460   <tr class=listheading><th colspan=2>$form->{title}</th></tr>
461   <tr size=5></tr>
462   <tr valign=top>
463     <td>
464       <table>
465         <tr>
466           <th align=right>|.$locale->text('Login').qq|</th>
467           <td><input name=login value="$myconfig->{login}"></td>
468         </tr>
469         <tr>
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}>
473         </tr>
474         <tr>
475           <th align=right>|.$locale->text('Name').qq|</th>
476           <td><input name=name size=15 value="$myconfig->{name}"></td>
477         </tr>
478         <tr>
479           <th align=right>|.$locale->text('E-mail').qq|</th>
480           <td><input name=email size=30 value="$myconfig->{email}"></td>
481         </tr>
482         <tr valign=top>
483           <th align=right>|.$locale->text('Signature').qq|</th>
484           <td><textarea name=signature rows=3 cols=35>$myconfig->{signature}</textarea></td>
485         </tr>
486         <tr>
487           <th align=right>|.$locale->text('Phone').qq|</th>
488           <td><input name=tel size=14 value="$myconfig->{tel}"></td>
489         </tr>
490         <tr>
491           <th align=right>|.$locale->text('Fax').qq|</th>
492           <td><input name=fax size=14 value="$myconfig->{fax}"></td>
493         </tr>
494         <tr>
495           <th align=right>|.$locale->text('Company').qq|</th>
496           <td><input name=company size=35 value="$myconfig->{company}"></td>
497         </tr>
498         <tr valign=top>
499           <th align=right>|.$locale->text('Address').qq|</th>
500           <td><textarea name=address rows=4 cols=35>$myconfig->{address}</textarea></td>
501         </tr>
502       </table>
503     </td>
504     <td>
505       <table>
506         <tr>
507           <th align=right>|.$locale->text('Date Format').qq|</th>
508           <td><select name=dateformat>$dateformat</select></td>
509         </tr>
510         <tr>
511           <th align=right>|.$locale->text('Number Format').qq|</th>
512           <td><select name=numberformat>$numberformat</select></td>
513         </tr>
514         <tr>
515           <th align=right>|.$locale->text('Dropdown Limit').qq|</th>
516           <td><input name=vclimit value="$myconfig->{vclimit}"></td>
517         </tr>
518         <tr>
519           <th align=right>|.$locale->text('Menu Width').qq|</th>
520           <td><input name=menuwidth value="$myconfig->{menuwidth}"></td>
521         </tr>
522         <tr>
523           <th align=right>|.$locale->text('Language').qq|</th>
524           <td><select name=countrycode>$countrycodes</select></td>
525         </tr>
526         <tr>
527           <th align=right>|.$locale->text('Character Set').qq|</th>
528           <td><input name=charset value="$myconfig->{charset}"></td>
529         </tr>
530         <tr>
531           <th align=right>|.$locale->text('Session Timeout').qq|</th>
532           <td><input name=timeout value="$myconfig->{timeout}"></td>
533         </tr>
534
535         <tr>
536           <th align=right>|.$locale->text('Stylesheet').qq|</th>
537           <td><select name=userstylesheet>$selectstylesheet</select></td>
538         </tr>
539         $printer
540         <tr>
541           <th align=right>|.$locale->text('Use Templates').qq|</th>
542           <td><select name=usetemplates>$usetemplates</select></td>
543         </tr>
544         <tr>
545           <th align=right>|.$locale->text('New Templates').qq|</th>
546           <td><input name=newtemplates></td>
547         </tr>
548         <tr>
549           <th align=right>|.$locale->text('Setup Templates').qq|</th>
550           <td><select name=mastertemplates>$mastertemplates</select></td>
551         </tr>
552         <input type=hidden name=templates value=$myconfig->{templates}>
553       </table>
554     </td>
555   </tr>
556   <tr class=listheading>
557     <th colspan=2>|.$locale->text('Database').qq|</th>
558   </tr>|;
559
560     # list section for database drivers
561     foreach $item (User->dbdrivers) {
562       
563     print qq|
564   <tr>
565     <td colspan=2>
566       <table>
567         <tr>|;
568
569     $checked = "";
570     if ($myconfig->{dbdriver} eq $item) {
571       map { $form->{"${item}_$_"} = $myconfig->{$_} } qw(dbhost dbport dbuser dbpasswd dbname sid);
572       $checked = "checked";
573     }
574
575     print qq|
576           <th align=right>|.$locale->text('Driver').qq|</th>
577           <td><input name=dbdriver type=radio class=radio value=$item $checked>&nbsp;$item</td>
578           <th align=right>|.$locale->text('Host').qq|</th>
579           <td><input name="${item}_dbhost" size=30 value=$form->{"${item}_dbhost"}></td>
580         </tr>
581         <tr>|;
582
583     if ($item =~ /Pg/) {
584       print qq|
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>
589         </tr>
590         <tr>
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>
595         </tr>|;
596
597     }
598
599     if ($item eq 'Oracle') {
600       print qq|
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>
605         </tr>
606         <tr>
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>
611           
612         </tr>|;
613     }
614     
615       
616     print qq|
617         <input type=hidden name=old_dbpasswd value=$myconfig->{dbpasswd}>
618       </table>
619     </td>
620   </tr>
621   <tr>
622     <td colspan=2><hr size=2 noshade></td>
623   </tr>
624 |;
625
626   }
627
628
629   # access control
630   open(FH, $menufile) or $form->error("$menufile : $!");
631   # scan for first menu level
632   @a = <FH>;
633   close(FH);
634   
635   if (open(FH, "custom_$menufile")) {
636     push @a, <FH>;
637   }
638   close(FH);
639
640   foreach $item (@a) {
641     next unless $item =~ /\[\w+/;
642     next if $item =~ /\#/;
643
644     $item =~ s/(\[|\])//g;
645     chop $item;
646
647     if ($item =~ /--/) {
648       ($level, $menuitem) = split /--/, $item, 2;
649     } else {
650       $level = $item;
651       $menuitem = $item;
652       push @acsorder, $item;
653     }
654
655     push @{ $acs{$level} }, $menuitem;
656
657   }
658   
659   %role = ( 'admin' => $locale->text('Administrator'),
660             'user' => $locale->text('User'),
661             'manager' => $locale->text('Manager')
662
663            );
664             
665   $selectrole = "";
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";
668   }
669   
670   print qq|
671   <tr class=listheading>
672     <th colspan=2>|.$locale->text('Access Control').qq|</th>
673   </tr>
674   <tr>
675     <td><select name=role>$selectrole</select></td>
676   </tr>
677 |;
678   
679   foreach $item (split /;/, $myconfig->{acs}) {
680     ($key, $value) = split /--/, $item, 2;
681     $excl{$key}{$value} = 1;
682   }
683   
684   foreach $key (@acsorder) {
685
686     $checked = "checked";
687     if ($form->{login}) {
688       $checked = ($excl{$key}{$key}) ? "" : "checked";
689     }
690     
691     # can't have variable names with spaces
692     # the 1 is for apache 2
693     $item = $form->escape("${key}--$key", 1);
694     
695     $acsheading = $key;
696     $acsheading =~ s/ /&nbsp;/g;
697     
698     $acsheading = qq|
699     <th align=left><input name="$item" class=checkbox type=checkbox value=1 $checked>&nbsp;$acsheading</th>\n|;
700     $menuitems .= "$item;";
701     $acsdata = "
702     <td>";
703
704     foreach $item (@{ $acs{$key} }) {
705       next if ($key eq $item);
706
707       $checked = "checked";
708       if ($form->{login}) {
709         $checked = ($excl{$key}{$item}) ? "" : "checked";
710       }
711
712       $acsitem = $form->escape("${key}--$item", 1);
713       
714       $acsdata .= qq|
715     <br><input name="$acsitem" class=checkbox type=checkbox value=1 $checked>&nbsp;$item|;
716       $menuitems .= "$acsitem;";
717     }
718
719     $acsdata .= "
720     </td>";
721
722     print qq|
723   <tr valign=top>$acsheading $acsdata
724   </tr>
725 |;
726   }
727   
728   print qq|<input type=hidden name=acs value="$menuitems">
729   
730    <tr>
731     <td colspan=2><hr size=3 noshade></td>
732   </tr>
733 </table>
734 </div>
735 |;
736
737 }
738
739
740 sub save {
741
742   # no driver checked
743   $form->error($locale->text('Database Driver not checked!')) unless $form->{dbdriver};
744
745   # no spaces allowed in login name
746   ($form->{login}) = split / /, $form->{login};
747
748   $form->isblank("login", $locale->text('Login name missing!'));
749   
750   # check for duplicates
751   if (!$form->{edit}) {
752     $temp = new User "$memberfile", "$form->{login}";
753    
754     if ($temp->{login}) {
755       $form->error("$form->{login} ".$locale->text('is already a member!'));
756     }
757   }
758   
759   # no spaces allowed in directories
760   ($form->{newtemplates}) = split / /, $form->{newtemplates};
761   
762   if ($form->{newtemplates}) {
763     $form->{templates} = $form->{newtemplates};
764   } else {
765     $form->{templates} = ($form->{usetemplates}) ? $form->{usetemplates} : $form->{login};
766   }
767   
768   # is there a basedir
769   if (! -d "$templates") {
770     $form->error($locale->text('Directory').": $templates ".$locale->text('does not exist'));
771   }
772
773   # add base directory to $form->{templates}
774   $form->{templates} = "$templates/$form->{templates}";
775
776
777   $myconfig = new User "$memberfile", "$form->{login}";
778
779   # redo acs variable and delete all the acs codes
780   @acs = split /;/, $form->{acs};
781
782   $form->{acs} = "";
783   foreach $item (@acs) {
784     $item = $form->escape($item, 1);
785
786     if (!$form->{$item}) {
787       $form->{acs} .= $form->unescape($form->unescape($item)).";";
788     }
789     delete $form->{$item};
790   }
791   
792   # check which database was filled in
793   
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"};
799  
800   if ($form->{dbdriver} eq 'Oracle') {
801     $form->{sid} = $form->{Oracle_sid}, ;
802
803     $form->isblank("dbhost", $locale->text('Hostname missing!'));
804     $form->isblank("dbport", $locale->text('Port missing!'));
805     $form->isblank("dbuser", $locale->text('Dataset missing!'));
806   }
807   if ($form->{dbdriver} =~ /Pg/) {
808     $form->isblank("dbname", $locale->text('Dataset missing!'));
809     $form->isblank("dbuser", $locale->text('Database User missing!'));
810   }
811     
812   foreach $item (keys %{$form}) {
813     $myconfig->{$item} = $form->{$item};
814   }
815
816   $myconfig->{password} = $form->{new_password} if $form->{new_password} ne $form->{old_password};
817
818   delete $myconfig->{stylesheet};
819   if ($form->{userstylesheet}) {
820     $myconfig->{stylesheet} = $form->{userstylesheet};
821   }
822   
823   $myconfig->save_member($memberfile, $userspath);
824
825   # create user template directory and copy master files
826   if (! -d "$form->{templates}") {
827     umask(002);
828     
829     if (mkdir "$form->{templates}", oct("771")) {
830       
831       umask(007);
832       
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;
837
838       foreach $file (@templates) {
839         open(TEMP, "$templates/$file") or $form->error("$templates/$file : $!");
840         
841         $file =~ s/$form->{mastertemplates}-//;
842         open(NEW, ">$form->{templates}/$file") or $form->error("$form->{templates}/$file : $!");
843           
844         while ($line = <TEMP>) {
845           print NEW $line;
846         }
847         close(TEMP);
848         close(NEW);
849       }
850     } else {
851       $form->error("$!: $form->{templates}");
852     }
853   }
854
855   $form->redirect($locale->text('User saved!'));
856   
857 }
858
859
860 sub delete {
861
862   $form->{templates} = ($form->{templates}) ? "$templates/$form->{templates}" : "$templates/$form->{login}";
863   
864   $form->error("$memberfile ".$locale->text('locked!')) if (-f ${memberfile}.LCK);
865   open(FH, ">${memberfile}.LCK") or $form->error("${memberfile}.LCK : $!");
866   close(FH);
867   
868   if (! open(CONF, "+<$memberfile")) {
869     unlink "${memberfile}.LCK";
870     $form->error("$memberfile : $!");
871   }
872
873   @config = <CONF>;
874
875   seek(CONF, 0, 0);
876   truncate(CONF, 0);
877   
878   while ($line = shift @config) {
879
880     chop $line;
881
882     if ($line =~ /^\[/) {
883       last if ($line =~ /\[$form->{login}\]/);
884       $login = &login_name($line);
885     }
886     
887     if ($line =~ /^templates=/) {
888       $user{$login} = &get_value($line);
889     }
890
891     print CONF "$line\n";
892   }
893
894   # remove everything up to next login or EOF
895   # and save template variable
896   while ($line = shift @config) {
897
898     chop $line;
899     
900     ($key, $value) = split /=/, $line, 2;
901     $myconfig{$key} = $value;
902     
903     last if ($line =~ /^\[/);
904   }
905
906   # this one is either the next login or EOF
907   print CONF "$line\n";
908
909   $login = &login_name($line);
910   
911
912   while ($line = shift @config) {
913
914     chop $line;
915
916     if ($line =~ /^\[/) {
917       $login = &login_name($line);
918     }
919     
920     if ($line =~ /^templates=/) {
921       $user{$login} = &get_value($line);
922     }
923     
924     print CONF "$line\n";
925   }
926
927   close(CONF);
928   unlink "${memberfile}.LCK";
929
930   # scan %user for $templatedir
931   foreach $login (keys %user) {
932     last if ($found = ($myconfig{templates} eq $user{$login}));
933   }
934
935   map { $form->{$_} = $myconfig{$_} } keys %myconfig;
936   
937   # if found keep directory otherwise delete
938   if (!$found) {
939     # delete it if there is a template directory
940     $dir = "$form->{templates}";
941     if (-d "$dir") {
942       unlink <$dir/*.html>;
943       unlink <$dir/*.tex>;
944       unlink <$dir/*.txt>;
945       rmdir "$dir";
946     }
947   }
948   
949   # delete config file for user
950   unlink "$userspath/$form->{login}.conf";
951
952   User::delete_login("", \%$form);
953   
954   $form->redirect($locale->text('User deleted!'));
955   
956 }
957
958
959 sub login_name {
960   my $login = shift;
961   
962   $login =~ s/\[\]//g;
963   return ($login) ? $login : undef;
964   
965 }
966
967
968
969 sub get_value {
970   my $line = shift;
971   
972   my ($null, $value) = split /=/, $line, 2;
973
974   # remove comments
975   $value =~ s/^\s*#.*//g;
976       
977   # remove any trailing whitespace
978   $value =~ s/^\s*(.*?)\s*$/$1/;
979
980   $value;
981 }
982
983
984
985 sub change_admin_password {
986
987   $form->{title} = qq|SQL-Ledger |.$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Change Admin Password');
988
989   $form->{login} = "root login";
990   $form->header;
991
992   print qq|
993 <body class=admin>
994
995 <form method=post action=$form->{script}>
996
997 <table>
998   <tr>
999   <tr class=listheading>
1000     <th>|.$locale->text('Change Password').qq|</th>
1001   </tr>
1002   <tr size=5></tr>
1003   <tr>
1004     <td>
1005       <table width=100%>
1006         <tr>
1007           <th align=right>|.$locale->text('Password').qq|</th>
1008           <td><input type=password name=new_password></td>
1009         </tr>
1010         <tr>
1011           <th align=right>|.$locale->text('Confirm').qq|</th>
1012           <td><input type=password name=confirm_password></td>
1013         </tr>
1014       </table>
1015     </td>
1016   </tr>
1017
1018 </table>
1019
1020 <br>
1021 <hr size=3 noshade>
1022 <input type=hidden name=path value=$form->{path}>
1023 <input type=hidden name=sessionid value=$form->{sessionid}>
1024
1025 <p>
1026 <input type=submit class=submit name=action value="|.$locale->text('Change Password').qq|">
1027
1028 </form>
1029
1030 </body>
1031 </html>
1032 |;
1033
1034 }
1035
1036
1037 sub change_password {
1038
1039   $form->error($locale->text('Passwords do not match!')) if $form->{new_password} ne $form->{confirm_password};
1040   
1041   $root->{password} = $form->{new_password};
1042   
1043   $root->{'root login'} = 1;
1044   $root->save_member($memberfile);
1045
1046   $form->{callback} = "$form->{script}?action=list_users&path=$form->{path}&sessionid=$form->{sessionid}";
1047
1048   $form->redirect($locale->text('Password changed!'));
1049
1050 }
1051
1052
1053 sub check_password {
1054
1055   $root = new User "$memberfile", "root login";
1056
1057   if ($root->{password}) {
1058       
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') {
1063         &getpassword;
1064         exit;
1065       }
1066     } else {
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}) {
1071           &getpassword(1);
1072           exit;
1073         }
1074       }
1075     }
1076   }
1077
1078 }
1079
1080
1081 sub pg_database_administration {
1082
1083   $form->{dbdriver} = 'Pg';
1084   &dbselect_source;
1085
1086 }
1087
1088
1089 sub pgpp_database_administration {
1090
1091   $form->{dbdriver} = 'PgPP';
1092   &dbselect_source;
1093
1094 }
1095
1096
1097 sub oracle_database_administration {
1098   
1099   $form->{dbdriver} = 'Oracle';
1100   &dbselect_source;
1101
1102 }
1103
1104
1105 sub dbdriver_defaults {
1106
1107   # load some defaults for the selected driver
1108   %driverdefaults = ( 'Pg' => { dbport => '',
1109                                 dbuser => 'sql-ledger',
1110                              dbdefault => 'template1',
1111                                 dbhost => '',
1112                          connectstring => $locale->text('Connect to')
1113                               },
1114                   'Oracle' => { dbport => '1521',
1115                                 dbuser => 'oralin',
1116                              dbdefault => $sid,
1117                                 dbhost => `hostname`,
1118                          connectstring => 'SID'
1119                               }
1120                     );
1121
1122   $driverdefaults{PgPP} = $driverdefaults{Pg};
1123
1124   map { $form->{$_} = $driverdefaults{$form->{dbdriver}}{$_} } keys %{ $driverdefaults{Pg} };
1125   
1126 }
1127   
1128
1129 sub dbselect_source {
1130
1131   &dbdriver_defaults;
1132
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!');
1136   
1137
1138  $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." / ".$locale->text('Database Administration');
1139   
1140   $form->{login} = "root login";
1141   $form->header;
1142
1143   print qq|
1144 <body class=admin>
1145
1146 <center>
1147 <h2>$form->{title}</h2>
1148
1149 <form method=post action=$form->{script}>
1150
1151 <table>
1152   <tr>
1153     <td>
1154       <table>
1155         <tr class=listheading>
1156           <th colspan=4>|.$locale->text('Database').qq|</th>
1157         </tr>
1158         <input type=hidden name=dbdriver value=$form->{dbdriver}>
1159         <tr>
1160           <td>
1161             <table>
1162               <tr>
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>
1167               </tr>
1168               <tr>
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>
1173               </tr>
1174               <tr>
1175
1176                 <th align=right>$form->{connectstring}</th>
1177                 <td colspan=3><input name=dbdefault size=10 value=$form->{dbdefault}></td>
1178
1179               </tr>
1180             </table>
1181           </td>
1182         </tr>
1183       </table>
1184
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}>
1188
1189 <br>
1190
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|">
1194
1195 </form>
1196
1197     </td>
1198   </tr>
1199 </table>
1200
1201 <p>|.$locale->text('This is a preliminary check for existing sources. Nothing will be created or deleted at this stage!')
1202
1203 .qq|
1204 <br>$msg{$form->{dbdriver}}
1205
1206
1207 </body>
1208 </html>
1209 |;
1210
1211 }
1212
1213
1214 sub continue {
1215
1216   &{ $form->{nextsub} };
1217
1218 }
1219
1220
1221 sub update_dataset {
1222
1223   %needsupdate = User->dbneedsupdate(\%$form);
1224
1225   $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Update Dataset');
1226   
1227   $form->{login} = "root login";
1228   $form->header;
1229
1230   print qq|
1231 <body class=admin>
1232
1233
1234 <center>
1235 <h2>$form->{title}</h2>
1236 |;
1237
1238
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 ";
1243     }
1244   }
1245
1246   chop $form->{dbupdate};
1247
1248
1249   if ($form->{dbupdate}) {
1250
1251     print qq|
1252 <table width=100%>
1253 <form method=post action=$form->{script}>
1254
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}>
1261
1262 <tr class=listheading>
1263   <th>|.$locale->text('The following Datasets need to be updated').qq|</th>
1264 </tr>
1265 <tr>
1266 <td>
1267
1268 $upd
1269
1270 </td>
1271 </tr>
1272 <tr>
1273 <td>
1274
1275 <input name=dbupdate type=hidden value="$form->{dbupdate}">
1276
1277 <input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}">
1278
1279 <input type=hidden name=path value=$form->{path}>
1280 <input type=hidden name=sessionid value=$form->{sessionid}>
1281
1282 <input type=hidden name=nextsub value=dbupdate>
1283
1284 <hr size=3 noshade>
1285
1286 <br>
1287 <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
1288
1289 </td></tr>
1290 </table>
1291 </form>
1292 |;
1293
1294   } else {
1295
1296     print $locale->text('All Datasets up to date!');
1297
1298   }
1299   
1300   print qq|
1301
1302 </body>
1303 </html>
1304 |;
1305
1306 }
1307
1308
1309 sub dbupdate {
1310
1311   User->dbupdate(\%$form);
1312
1313   $form->redirect($locale->text('Dataset updated!'));
1314   
1315 }
1316
1317
1318 sub create_dataset {
1319
1320   @dbsources = sort User->dbsources(\%$form);
1321
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|;
1327   }
1328   closedir SQLDIR;
1329
1330   # add Default at beginning
1331   unshift @charts, qq|<input name=chart class=radio type=radio value="Default" checked>Default|;
1332
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)
1362   |;
1363   
1364   $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Create Dataset');
1365   
1366   $form->{login} = "root login";
1367   $form->header;
1368
1369   print qq|
1370 <body class=admin>
1371
1372
1373 <center>
1374 <h2>$form->{title}</h2>
1375
1376 <form method=post action=$form->{script}>
1377
1378 <table width=100%>
1379   <tr class=listheading>
1380     <th colspan=2>&nbsp;</th>
1381   </tr>
1382
1383   <tr>
1384
1385     <th align=right nowrap>|.$locale->text('Existing Datasets').qq|</th>
1386     <td>
1387 |;
1388
1389     map { print "[&nbsp;$_&nbsp;] " } @dbsources;
1390     
1391     print qq|
1392     </td>
1393   </tr>
1394   
1395   <tr>
1396
1397     <th align=right nowrap>|.$locale->text('Create Dataset').qq|</th>
1398     <td><input name=db></td>
1399
1400   </tr>
1401
1402   <tr>
1403
1404     <th align=right nowrap>|.$locale->text('Multibyte Encoding').qq|</th>
1405     <td><select name=encoding>$selectencoding</select></td>
1406
1407   </tr>
1408  
1409   <tr>
1410
1411     <th align=right nowrap>|.$locale->text('Create Chart of Accounts').qq|</th>
1412     <td>
1413       <table>
1414 |;
1415
1416   while (@charts) {
1417     print qq|
1418         <tr>
1419 |;
1420
1421     map { print "<td>$charts[$_]</td>\n" } (0 .. 2);
1422
1423     print qq|
1424         </tr>
1425 |;
1426
1427     splice @charts, 0, 3;
1428   }
1429
1430   print qq|
1431       </table>
1432     </td>
1433   </tr>
1434   <tr>
1435     <td colspan=2>
1436     <hr size=3 noshade>
1437     </td>
1438   </tr>
1439 </table>
1440  
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}>
1447
1448 <input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}">
1449
1450 <input type=hidden name=path value=$form->{path}>
1451 <input type=hidden name=sessionid value=$form->{sessionid}>
1452
1453 <input type=hidden name=nextsub value=dbcreate>
1454
1455 <br>
1456 <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
1457
1458
1459 </form>
1460
1461 </body>
1462 </html>
1463 |;
1464
1465 }
1466
1467
1468 sub dbcreate {
1469
1470   $form->isblank("db", $locale->text('Dataset missing!'));
1471
1472   User->dbcreate(\%$form);
1473   
1474   $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Create Dataset');
1475
1476   $form->{login} = "root login";
1477   $form->header;
1478
1479   print qq|
1480 <body class=admin>
1481
1482
1483 <center>
1484 <h2>$form->{title}</h2>
1485
1486 <form method=post action=$form->{script}>|
1487
1488 .$locale->text('Dataset')." $form->{db} ".$locale->text('successfully created!')
1489
1490 .qq|
1491
1492 <input type=hidden name=path value="$form->{path}">
1493 <input type=hidden name=sessionid value=$form->{sessionid}>
1494
1495 <input type=hidden name=nextsub value=list_users>
1496
1497 <p><input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
1498 </form>
1499
1500
1501 </body>
1502 </html>
1503 |;
1504
1505 }
1506
1507
1508 sub delete_dataset {
1509
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>&nbsp;$item |;
1513     }
1514   } else {
1515     $form->error($locale->text('Nothing to delete!'));
1516   }
1517
1518   $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Delete Dataset');
1519
1520   $form->{login} = "root login";
1521   $form->header;
1522
1523   print qq|
1524 <body class=admin>
1525
1526 <h2>$form->{title}</h2>
1527
1528 <form method=post action=$form->{script}>
1529
1530 <table width=100%>
1531   <tr class=listheading>
1532     <th>|.$locale->text('The following Datasets are not in use and can be deleted').qq|</th>
1533   </tr>
1534
1535   <tr>
1536     <td>
1537     $dbsources
1538     </td>
1539   </tr>
1540   
1541   <tr><td>
1542 <p>
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}>
1549
1550 <input name=callback type=hidden value="$form->{script}?action=list_users&path=$form->{path}">
1551
1552 <input type=hidden name=path value="$form->{path}">
1553 <input type=hidden name=sessionid value=$form->{sessionid}>
1554
1555 <input type=hidden name=nextsub value=dbdelete>
1556
1557 <hr size=3 noshade>
1558
1559 <br>
1560 <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
1561
1562   </td></tr>
1563 </table>
1564
1565 </form>
1566
1567 </body>
1568 </html>
1569 |;
1570
1571 }
1572
1573
1574 sub dbdelete {
1575
1576   if (!$form->{db}) {
1577     $form->error($locale->text('No Dataset selected!'));
1578   }
1579
1580   User->dbdelete(\%$form);
1581
1582   $form->{title} = "SQL-Ledger ".$locale->text('Accounting')." ".$locale->text('Database Administration')." / ".$locale->text('Delete Dataset');
1583
1584   $form->{login} = "root login";
1585   $form->header;
1586
1587   print qq|
1588 <body class=admin>
1589
1590
1591 <center>
1592 <h2>$form->{title}</h2>
1593
1594 <form method=post action=$form->{script}>
1595
1596 $form->{db} |.$locale->text('successfully deleted!')
1597
1598 .qq|
1599
1600 <input type=hidden name=path value="$form->{path}">
1601 <input type=hidden name=sessionid value=$form->{sessionid}>
1602
1603 <input type=hidden name=nextsub value=list_users>
1604
1605 <p><input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
1606 </form>
1607
1608
1609 </body>
1610 </html>
1611 |;
1612
1613 }
1614
1615
1616 sub unlock_system {
1617
1618   unlink "$userspath/nologin";
1619   
1620   $form->{callback} = "$form->{script}?action=list_users&path=$form->{path}&sessionid=$form->{sessionid}";
1621
1622   $form->redirect($locale->text('Lockfile removed!'));
1623
1624 }
1625
1626
1627 sub lock_system {
1628
1629   open(FH, ">$userspath/nologin") or $form->error($locale->text('Cannot create Lock!'));
1630   close(FH);
1631   
1632   $form->{callback} = "$form->{script}?action=list_users&path=$form->{path}&sessionid=$form->{sessionid}";
1633
1634   $form->redirect($locale->text('Lockfile created!'));
1635
1636 }
1637
1638