"path" wird nicht mehr benötigt.
[kivitendo-erp.git] / bin / mozilla / admin.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
29 #
30 # setup module
31 # add/edit/delete users
32 #
33 #======================================================================
34
35 $menufile = "menu.ini";
36
37 use DBI;
38 use CGI;
39
40 use SL::Form;
41 use SL::User;
42 use SL::Common;
43
44 require "bin/mozilla/common.pl";
45
46 our $cgi = new CGI('');
47
48 $form = new Form;
49 $form->{"root"} = "root login";
50
51 $locale = new Locale $language, "admin";
52
53 # customization
54 if (-f "bin/mozilla/custom_$form->{script}") {
55   eval { require "bin/mozilla/custom_$form->{script}"; };
56   $form->error($@) if ($@);
57 }
58
59 $form->{stylesheet} = "lx-office-erp.css";
60 $form->{favicon}    = "favicon.ico";
61
62 if ($form->{action}) {
63
64
65   $subroutine = $locale->findsub($form->{action});
66
67   if ($subroutine eq 'login') {
68     if ($form->{rpw}) {
69       $form->{rpw} = crypt $form->{rpw}, "ro";
70     }
71   }
72
73   &check_password;
74
75   call_sub($subroutine);
76
77 } else {
78
79   # if there are no drivers bail out
80   $form->error($locale->text('No Database Drivers available!'))
81     unless (User->dbdrivers);
82
83   # create memberfile
84   if (!-f $memberfile) {
85     open(FH, ">$memberfile") or $form->error("$memberfile : $!");
86     print FH qq|# SQL-Ledger Accounting members
87
88 [root login]
89 password=
90
91 |;
92     close FH;
93   }
94
95   &adminlogin;
96
97 }
98
99 1;
100
101 # end
102
103 sub adminlogin {
104
105   $form->{title} =
106     qq|Lx-Office ERP $form->{version} | . $locale->text('Administration');
107
108   $form->header;
109
110   print qq|
111 <body class=admin>
112
113
114 <div align=center>
115
116 <a href="http://www.lx-office.org"><img src="image/lx-office-erp.png" border=0></a>
117 <h1 class=login>|
118     . $locale->text('Version')
119     . qq| $form->{version}<p>|
120     . $locale->text('Administration')
121     . qq|</h1>
122
123 <form method=post action="$form->{script}">
124
125 <table>
126   <tr>
127     <th>| . $locale->text('Password') . qq|</th>
128     <td><input type=password name=rpw></td>
129     <td><input type=submit class=submit name=action value="|
130     . $locale->text('Login') . qq|"></td>
131   </tr>
132 <input type=hidden name=action value=login>
133 </table>
134
135
136 </form>
137
138 <a href=http://www.lx-office.org>Lx-Office |
139     . $locale->text('website') . qq|</a>
140
141 </div>
142
143 </body>
144 </html>
145 |;
146
147 }
148
149 sub login {
150
151   &list_users;
152
153 }
154
155 sub add_user {
156
157   $form->{title} =
158       "Lx-Office ERP "
159     . $locale->text('Administration') . " / "
160     . $locale->text('Add User');
161
162   $form->{Oracle_sid}    = $sid;
163   $form->{Oracle_dbport} = '1521';
164   $form->{Oracle_dbhost} = `hostname`;
165
166   if (-f "css/lx-office-erp.css") {
167     $myconfig->{stylesheet} = "lx-office-erp.css";
168   }
169   $myconfig->{vclimit} = 200;
170
171   $myconfig->{"countrycode"} = "de";
172   $myconfig->{"numberformat"} = "1000,00";
173   $myconfig->{"dateformat"} = "dd.mm.yy";
174
175   &form_header;
176   &form_footer;
177
178 }
179
180 sub edit {
181
182   $form->{title} =
183       "Lx-Office ERP "
184     . $locale->text('Administration') . " / "
185     . $locale->text('Edit User');
186   $form->{edit} = 1;
187
188   &form_header;
189   &form_footer;
190
191 }
192
193 sub form_footer {
194
195   if ($form->{edit}) {
196     $delete =
197       qq|<input type=submit class=submit name=action value="|
198       . $locale->text('Delete') . qq|">
199 <input type=hidden name=edit value=1>|;
200   }
201
202   print qq|
203
204 <input name=callback type=hidden value="$form->{script}?action=list_users&rpw=$form->{rpw}">
205 <input type=hidden name=rpw value=$form->{rpw}>
206
207 <input type=submit class=submit name=action value="|
208     . $locale->text('Save') . qq|">
209 $delete
210
211 </form>
212
213 </body>
214 </html>
215 |;
216
217 }
218
219 sub list_users {
220
221   $form->error($locale->text('File locked!')) if (-f "${memberfile}.LCK");
222
223   open(FH, "$memberfile") or $form->error("$memberfile : $!");
224
225   $nologin = qq|
226 <input type=submit class=submit name=action value="|
227     . $locale->text('Lock System') . qq|">|;
228
229   if (-e "$userspath/nologin") {
230     $nologin = qq|
231 <input type=submit class=submit name=action value="|
232       . $locale->text('Unlock System') . qq|">|;
233   }
234
235   while (<FH>) {
236     chop;
237
238     if (/^\[.*\]/) {
239       $login = $_;
240       $login =~ s/(\[|\])//g;
241     }
242
243     if (/^(name=|company=|templates=|dbuser=|dbdriver=|dbname=|dbhost=)/) {
244       chop($var = $&);
245       ($null, $member{$login}{$var}) = split(/=/, $_, 2);
246     }
247   }
248
249   close(FH);
250
251   # type=submit $locale->text('Pg Database Administration')
252   # type=submit $locale->text('Oracle Database Administration')
253
254   foreach $item (User->dbdrivers) {
255     $dbdrivers .=
256       qq|<input name=action type=submit class=submit value="|
257       . $locale->text("$item Database Administration") . qq|">|;
258   }
259
260   $column_header{login}     = qq|<th>| . $locale->text('Login') . qq|</th>|;
261   $column_header{name}      = qq|<th>| . $locale->text('Name') . qq|</th>|;
262   $column_header{company}   = qq|<th>| . $locale->text('Company') . qq|</th>|;
263   $column_header{dbdriver}  = qq|<th>| . $locale->text('Driver') . qq|</th>|;
264   $column_header{dbhost}    = qq|<th>| . $locale->text('Host') . qq|</th>|;
265   $column_header{dataset}   = qq|<th>| . $locale->text('Dataset') . qq|</th>|;
266   $column_header{templates} =
267     qq|<th>| . $locale->text('Templates') . qq|</th>|;
268
269   @column_index = qw(login name company dbdriver dbhost dataset templates);
270
271   $form->{title} = "Lx-Office ERP " . $locale->text('Administration');
272
273   $form->header;
274
275   print qq|
276 <body class=admin>
277
278 <form method=post action=$form->{script}>
279
280 <table width=100%>
281   <tr>
282   <tr class=listheading>
283     <th>$form->{title}</th>
284   </tr>
285   <tr size=5></tr>
286   <tr>
287     <td>
288       <table width=100%>
289         <tr class=listheading>|;
290
291   map { print "$column_header{$_}\n" } @column_index;
292
293   print qq|
294         </tr>
295 |;
296
297   foreach $key (sort keys %member) {
298     $href =
299       "$script?action=edit&login=$key&rpw=$form->{rpw}";
300     $href =~ s/ /%20/g;
301
302     $member{$key}{templates} =~ s/^$templates\///;
303     $member{$key}{dbhost} = $locale->text('localhost')
304       unless $member{$key}{dbhost};
305     $member{$key}{dbname} = $member{$key}{dbuser}
306       if ($member{$key}{dbdriver} eq 'Oracle');
307
308     $column_data{login}     = qq|<td><a id="$key" href="$href">$key</a></td>|;
309     $column_data{name}      = qq|<td>$member{$key}{name}</td>|;
310     $column_data{company}   = qq|<td>$member{$key}{company}</td>|;
311     $column_data{dbdriver}  = qq|<td>$member{$key}{dbdriver}</td>|;
312     $column_data{dbhost}    = qq|<td>$member{$key}{dbhost}</td>|;
313     $column_data{dataset}   = qq|<td>$member{$key}{dbname}</td>|;
314     $column_data{templates} = qq|<td>$member{$key}{templates}</td>|;
315
316     $i++;
317     $i %= 2;
318     print qq|
319         <tr class="listrow$i">|;
320
321     map { print "$column_data{$_}\n" } @column_index;
322
323     print qq|
324         </tr>|;
325   }
326
327   print qq|
328       </table>
329     </td>
330   </tr>
331   <tr>
332     <td><hr size=3 noshade></td>
333   </tr>
334 </table>
335
336 <input type=hidden name=rpw value=$form->{rpw}>
337
338 <br><input type=submit class=submit name=action value="|
339     . $locale->text('Add User') . qq|">
340 <input type=submit class=submit name=action value="|
341     . $locale->text('Change Admin Password') . qq|">
342
343 $dbdrivers
344 $nologin
345
346 </form>
347
348 | . $locale->text('Click on login name to edit!') . qq|
349 <br>
350 |
351     . $locale->text(
352     '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.'
353     )
354     . qq|
355
356 <p>
357
358 <form method=post action=login.pl>
359
360 <table border=0 width=100%>
361   <tr class=listheading>
362     <th>Lx-Office ERP | . $locale->text('Login') . qq|</th>
363   </tr>
364   <tr>
365     <td>
366       <table>
367         <tr>
368           <th align=right>| . $locale->text('Name') . qq|</th>
369           <td><input class=login name=login></td>
370           <td>&nbsp;</td>
371         </tr>
372         <tr>
373           <th align=right>| . $locale->text('Password') . qq|</th>
374           <td><input class=login type=password name=password></td>
375           <td><input type=submit name=action value="|
376     . $locale->text('Login') . qq|"></td>
377         </tr>
378       </table>
379     </td>
380   </tr>
381 </table>
382
383 </form>
384
385 <hr size=3 noshade>
386
387 </body>
388 </html>
389 |;
390
391 }
392
393 sub form_header {
394
395   # if there is a login, get user
396   if ($form->{login}) {
397
398     # get user
399     $myconfig = new User "$memberfile", "$form->{login}";
400
401     $myconfig->{signature} =~ s/\\n/\r\n/g;
402     $myconfig->{address}   =~ s/\\n/\r\n/g;
403
404     # strip basedir from templates directory
405     $myconfig->{templates} =~ s/^$templates\///;
406
407     # $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd};
408   }
409
410   foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
411     $dateformat .=
412       ($item eq $myconfig->{dateformat})
413       ? "<option selected>$item\n"
414       : "<option>$item\n";
415   }
416
417   foreach $item (qw(1,000.00 1000.00 1.000,00 1000,00)) {
418     $numberformat .=
419       ($item eq $myconfig->{numberformat})
420       ? "<option selected>$item\n"
421       : "<option>$item\n";
422   }
423
424   %countrycodes = User->country_codes;
425   $countrycodes = "";
426   foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} }
427                 keys %countrycodes
428     ) {
429     $countrycodes .=
430       ($myconfig->{countrycode} eq $key)
431       ? "<option selected value=$key>$countrycodes{$key}"
432       : "<option value=$key>$countrycodes{$key}";
433   }
434   $countrycodes = qq|<option value="">American English\n$countrycodes|;
435
436   # is there a templates basedir
437   if (!-d "$templates") {
438     $form->error(  $locale->text('Directory')
439                  . ": $templates "
440                  . $locale->text('does not exist'));
441   }
442
443   opendir TEMPLATEDIR, "$templates/." or $form->error("$templates : $!");
444   my @all = readdir(TEMPLATEDIR);
445   my @alldir = sort(grep({ -d "$templates/$_" && !/^\.\.?$/ } @all));
446   my @allhtml = sort(grep({ -f "$templates/$_" && /\.html$/ } @all));
447   closedir TEMPLATEDIR;
448
449   @alldir = grep !/\.(html|tex|sty|odt|xml|txb)$/, @alldir;
450   @alldir = grep !/^(webpages|\.svn)$/, @alldir;
451
452   @allhtml = reverse grep !/Default/, @allhtml;
453   push @allhtml, 'Default';
454   @allhtml = reverse @allhtml;
455
456   foreach $item (@alldir) {
457     if ($item eq $myconfig->{templates}) {
458       $usetemplates .= qq|<option selected>$item\n|;
459     } else {
460       $usetemplates .= qq|<option>$item\n|;
461     }
462   }
463
464   $lastitem = $allhtml[0];
465   $lastitem =~ s/-.*//g;
466   $mastertemplates = qq|<option>$lastitem\n|;
467   foreach $item (@allhtml) {
468     $item =~ s/-.*//g;
469
470     if ($item ne $lastitem) {
471       my $selected = $item eq "German" ? " selected" : "";
472       $mastertemplates .= qq|<option$selected>$item\n|;
473       $lastitem = $item;
474     }
475   }
476
477 #  opendir CSS, "css/.";
478 #  @all = grep /.*\.css$/, readdir CSS;
479 #  closedir CSS;
480
481 # css dir has styles that are not intended as general layouts.
482 # reverting to hardcoded list
483   @all = qw(lx-office-erp.css Win2000.css);
484
485   foreach $item (@all) {
486     if ($item eq $myconfig->{stylesheet}) {
487       $selectstylesheet .= qq|<option selected>$item\n|;
488     } else {
489       $selectstylesheet .= qq|<option>$item\n|;
490     }
491   }
492
493   $form->header;
494
495   if ($myconfig->{menustyle} eq "v3") {
496     $menustyle_v3 = "checked";
497   } elsif ($myconfig->{menustyle} eq "neu") {
498     $menustyle_neu = "checked";
499   } else {
500     $menustyle_old = "checked";
501   }
502
503   print qq|
504 <body class=admin>
505
506 <form method=post action=$form->{script}>
507
508 <table width=100%>
509   <tr class=listheading><th colspan=2>$form->{title}</th></tr>
510   <tr size=5></tr>
511   <tr valign=top>
512     <td>
513       <table>
514         <tr>
515           <th align=right>| . $locale->text('Login') . qq|</th>
516           <td><input name="login" value="$myconfig->{login}"></td>
517         </tr>
518         <tr>
519           <th align=right>| . $locale->text('Password') . qq|</th>
520           <td><input type="password" name="password" size="8" value="$myconfig->{password}"></td>
521           <input type="hidden" name="old_password" value="$myconfig->{password}">
522         </tr>
523         <tr>
524           <th align=right>| . $locale->text('Name') . qq|</th>
525           <td><input name="name" size="15" value="$myconfig->{name}"></td>
526         </tr>
527         <tr>
528           <th align=right>| . $locale->text('E-mail') . qq|</th>
529           <td><input name=email size=30 value="$myconfig->{email}"></td>
530         </tr>
531         <tr valign=top>
532           <th align=right>| . $locale->text('Signature') . qq|</th>
533           <td><textarea name=signature rows=3 cols=35>$myconfig->{signature}</textarea></td>
534         </tr>
535         <tr>
536           <th align=right>| . $locale->text('Phone') . qq|</th>
537           <td><input name=tel size=14 value="$myconfig->{tel}"></td>
538         </tr>
539         <tr>
540           <th align=right>| . $locale->text('Fax') . qq|</th>
541           <td><input name=fax size=14 value="$myconfig->{fax}"></td>
542         </tr>
543         <tr>
544           <th align=right>| . $locale->text('Company') . qq|</th>
545           <td><input name=company size=35 value="$myconfig->{company}"></td>
546         </tr>
547         <tr valign=top>
548           <th align=right>| . $locale->text('Address') . qq|</th>
549           <td><textarea name=address rows=4 cols=35>$myconfig->{address}</textarea></td>
550         </tr>
551         <tr valign=top>
552           <th align=right>| . $locale->text('Tax number') . qq|</th>
553           <td><input name=taxnumber size=14 value="$myconfig->{taxnumber}"></td>
554         </tr>
555         <tr valign=top>
556           <th align=right>| . $locale->text('Ust-IDNr') . qq|</th>
557           <td><input name=co_ustid size=14 value="$myconfig->{co_ustid}"></td>
558         </tr>
559         <tr valign=top>
560           <th align=right>| . $locale->text('DUNS-Nr') . qq|</th>
561           <td><input name=duns size=14 value="$myconfig->{duns}"></td>
562         </tr>
563       </table>
564     </td>
565     <td>
566       <table>
567         <tr>
568           <th align=right>| . $locale->text('Date Format') . qq|</th>
569           <td><select name=dateformat>$dateformat</select></td>
570         </tr>
571         <tr>
572           <th align=right>| . $locale->text('Number Format') . qq|</th>
573           <td><select name=numberformat>$numberformat</select></td>
574         </tr>
575         <tr>
576           <th align=right>| . $locale->text('Dropdown Limit') . qq|</th>
577           <td><input name=vclimit value="$myconfig->{vclimit}"></td>
578         </tr>
579         <tr>
580           <th align=right>| . $locale->text('Language') . qq|</th>
581           <td><select name=countrycode>$countrycodes</select></td>
582         </tr>
583         <tr>
584           <th align=right>| . $locale->text('Stylesheet') . qq|</th>
585           <td><select name=userstylesheet>$selectstylesheet</select></td>
586         </tr>
587         <tr>
588           <th align=right>| . $locale->text('Printer') . qq|</th>
589           <td><input name=printer size=20 value="$myconfig->{printer}"></td>
590         </tr>
591         <tr>
592           <th align=right>| . $locale->text('Use Templates') . qq|</th>
593           <td><select name=usetemplates>$usetemplates</select></td>
594         </tr>
595         <tr>
596           <th align=right>| . $locale->text('New Templates') . qq|</th>
597           <td><input name=newtemplates></td>
598         </tr>
599         <tr>
600           <th align=right>| . $locale->text('Setup Templates') . qq|</th>
601           <td><select name=mastertemplates>$mastertemplates</select></td>
602         </tr>
603        <tr>
604            <th align=right>| . $locale->text('Setup Menu') . qq|</th>
605            <td><input name=menustyle type=radio class=radio value=v3 $menustyle_v3>&nbsp;| .
606            $locale->text("Top (CSS)") . qq|
607            <input name=menustyle type=radio class=radio value=neu $menustyle_neu>&nbsp;| .
608            $locale->text("Top (Javascript)") . qq|
609            <input name=menustyle type=radio class=radio value=old $menustyle_old>&nbsp;| .
610            $locale->text("Old (on the side)") . qq|
611            </td>
612          </tr>
613         <input type=hidden name=templates value=$myconfig->{templates}>
614       </table>
615     </td>
616   </tr>
617   <tr class=listheading>
618     <th colspan=2>| . $locale->text('Database') . qq|</th>
619   </tr>|;
620
621   # list section for database drivers
622   foreach $item (User->dbdrivers) {
623
624     print qq|
625   <tr>
626     <td colspan=2>
627       <table>
628         <tr>|;
629
630     $checked = "";
631     if ($myconfig->{dbdriver} eq $item) {
632       map { $form->{"${item}_$_"} = $myconfig->{$_} }
633         qw(dbhost dbport dbuser dbpasswd dbname sid);
634       $checked = "checked";
635     }
636
637     print qq|
638           <th align=right>| . $locale->text('Driver') . qq|</th>
639           <td><input name="dbdriver" type="radio" class="radio" value="$item" $checked>&nbsp;$item</td>
640           <th align=right>| . $locale->text('Host') . qq|</th>
641           <td><input name="${item}_dbhost" size=30 value="$form->{"${item}_dbhost"}"></td>
642         </tr>
643         <tr>|;
644
645     if ($item eq 'Pg') {
646     
647       print qq|
648           <th align=right>| . $locale->text('Dataset') . qq|</th>
649           <td><input name="Pg_dbname" size="15" value="$form->{Pg_dbname}"></td>
650           <th align=right>| . $locale->text('Port') . qq|</th>
651           <td><input name="Pg_dbport" size="4" value="$form->{Pg_dbport}"></td>
652         </tr>
653         <tr>
654           <th align=right>| . $locale->text('User') . qq|</th>
655           <td><input name="${item}_dbuser" size=15 value="$form->{"${item}_dbuser"}"></td>
656           <th align=right>| . $locale->text('Password') . qq|</th>
657           <td><input name="${item}_dbpasswd" type=password size=10 value="$form->{"${item}_dbpasswd"}"></td>
658         </tr>|;
659
660     }
661
662     if ($item eq 'Oracle') {
663       print qq|
664           <th align=right>SID</th>
665           <td><input name=Oracle_sid value=$form->{Oracle_sid}></td>
666           <th align=right>| . $locale->text('Port') . qq|</th>
667           <td><input name=Oracle_dbport size=4 value=$form->{Oracle_dbport}></td>
668         </tr>
669         <tr>
670           <th align=right>| . $locale->text('Dataset') . qq|</th>
671           <td><input name="${item}_dbuser" size=15 value=$form->{"${item}_dbuser"}></td>
672           <th align=right>| . $locale->text('Password') . qq|</th>
673           <td><input name="${item}_dbpasswd" type=password size=10 value="$form->{"${item}_dbpasswd"}"></td>
674
675         </tr>|;
676     }
677
678     print qq|
679         <input type="hidden" name="old_dbpasswd" value="$myconfig->{dbpasswd}">
680       </table>
681     </td>
682   </tr>
683   <tr>
684     <td colspan=2><hr size=2 noshade></td>
685   </tr>
686 |;
687
688   }
689
690   # access control
691   open(FH, $menufile) or $form->error("$menufile : $!");
692
693   # scan for first menu level
694   @a = <FH>;
695   close(FH);
696
697   if (open(FH, "custom_$menufile")) {
698     push @a, <FH>;
699   }
700   close(FH);
701
702   foreach $item (@a) {
703     next unless $item =~ /\[/;
704     next if $item =~ /\#/;
705
706     $item =~ s/(\[|\])//g;
707     chop $item;
708
709     if ($item =~ /--/) {
710       ($level, $menuitem) = split /--/, $item, 2;
711     } else {
712       $level    = $item;
713       $menuitem = $item;
714       push @acsorder, $item;
715     }
716
717     push @{ $acs{$level} }, $menuitem;
718
719   }
720
721   %role = ('admin'      => $locale->text('Administrator'),
722            'user'       => $locale->text('User'),
723            'manager'    => $locale->text('Manager'),
724            'supervisor' => $locale->text('Supervisor'));
725
726   $selectrole = "";
727   foreach $item (qw(user supervisor manager admin)) {
728     $selectrole .=
729       ($myconfig->{role} eq $item)
730       ? "<option selected value=$item>$role{$item}\n"
731       : "<option value=$item>$role{$item}\n";
732   }
733
734   print qq|
735   <tr class=listheading>
736     <th colspan=2>| . $locale->text('Access Control') . qq|</th>
737   </tr>
738   <tr>
739     <td><select name=role>$selectrole</select></td>
740   </tr>
741 |;
742
743   foreach $item (split(/;/, $myconfig->{acs})) {
744     ($key, $value) = split /--/, $item, 2;
745     $excl{$key}{$value} = 1;
746   }
747
748   foreach $key (@acsorder) {
749
750     $checked = "checked";
751     if ($form->{login}) {
752       $checked = ($excl{$key}{$key}) ? "" : "checked";
753     }
754
755     # can't have variable names with spaces
756     # the 1 is for apache 2
757     $item = $form->escape("${key}--$key", 1);
758
759     $acsheading = $key;
760     $acsheading =~ s/ /&nbsp;/g;
761
762     $acsheading = qq|
763     <th align=left><input name="$item" class=checkbox type=checkbox value=1 $checked>&nbsp;$acsheading</th>\n|;
764     $menuitems .= "$item;";
765     $acsdata = "
766     <td>";
767
768     foreach $item (@{ $acs{$key} }) {
769       next if ($key eq $item);
770
771       $checked = "checked";
772       if ($form->{login}) {
773         $checked = ($excl{$key}{$item}) ? "" : "checked";
774       }
775
776       $acsitem = $form->escape("${key}--$item", 1);
777
778       $acsdata .= qq|
779     <br><input name="$acsitem" class=checkbox type=checkbox value=1 $checked>&nbsp;$item|;
780       $menuitems .= "$acsitem;";
781     }
782
783     $acsdata .= "
784     </td>";
785
786     print qq|
787   <tr valign=top>$acsheading $acsdata
788   </tr>
789 |;
790   }
791
792   print qq|<input type=hidden name=acs value="$menuitems">
793 |;
794   if ($webdav) {
795     @webdavdirs =
796       qw(angebote bestellungen rechnungen anfragen lieferantenbestellungen einkaufsrechnungen);
797     foreach $directory (@webdavdirs) {
798       if ($myconfig->{$directory}) {
799         $webdav{"${directory}c"} = "checked";
800       } else {
801         $webdav{"${directory}c"} = "";
802       }
803     }
804     print qq|
805    <tr>
806     <td colspan=2><hr size=3 noshade></td>
807   </tr>
808   <tr class=listheading>
809     <th colspan=2>| . $locale->text('WEBDAV-Zugriff') . qq|</th>
810   </tr>
811   <table width=100%>
812         <tr>
813         <td><input name=angebote class=checkbox type=checkbox value=1 $webdav{angebotec}>&nbsp;Angebot</td>
814         <td><input name=bestellungen class=checkbox type=checkbox value=1 $webdav{bestellungenc}>&nbsp;Bestellung</td>
815         <td><input name=rechnungen class=checkbox type=checkbox value=1 $webdav{rechnungenc}>&nbsp;Rechnung</td>
816         </tr>
817         <tr>
818         <td><input name=anfragen class=checkbox type=checkbox value=1 $webdav{anfragenc}>&nbsp;Angebot</td>
819         <td><input name=lieferantenbestellungen class=checkbox type=checkbox value=1 $webdav{lieferantenbestellungenc}>&nbsp;Lieferantenbestellung</td>
820         <td><input name=einkaufsrechnungen class=checkbox type=checkbox value=1 $webdav{einkaufsrechnungenc}>&nbsp;Einkaufsrechnung</td>
821         </tr>
822   </table>
823   <tr>
824     <td colspan=2><hr size=3 noshade></td>
825   </tr>
826 |;
827   }
828   print qq|
829 </table>
830 </div>
831 |;
832
833 }
834
835 sub save {
836
837   # no driver checked
838   $form->error($locale->text('Database Driver not checked!'))
839     unless $form->{dbdriver};
840
841   # no spaces allowed in login name
842   ($form->{login}) = split / /, $form->{login};
843
844   $form->isblank("login", $locale->text('Login name missing!'));
845
846   # check for duplicates
847   if (!$form->{edit}) {
848     $temp = new User "$memberfile", "$form->{login}";
849
850     if ($temp->{login}) {
851       $form->error("$form->{login} " . $locale->text('is already a member!'));
852     }
853   }
854
855   # no spaces allowed in directories
856   ($form->{newtemplates}) = split / /, $form->{newtemplates};
857
858   if ($form->{newtemplates}) {
859     $form->{templates} = $form->{newtemplates};
860   } else {
861     $form->{templates} =
862       ($form->{usetemplates}) ? $form->{usetemplates} : $form->{login};
863   }
864
865   # is there a basedir
866   if (!-d "$templates") {
867     $form->error(  $locale->text('Directory')
868                  . ": $templates "
869                  . $locale->text('does not exist'));
870   }
871
872   # add base directory to $form->{templates}
873   $form->{templates} = "$templates/$form->{templates}";
874
875   $myconfig = new User "$memberfile", "$form->{login}";
876
877   # redo acs variable and delete all the acs codes
878   @acs = split(/;/, $form->{acs});
879
880   $form->{acs} = "";
881   foreach $item (@acs) {
882     $item = $form->escape($item, 1);
883
884     if (!$form->{$item}) {
885       $form->{acs} .= $form->unescape($form->unescape($item)) . ";";
886     }
887     delete $form->{$item};
888   }
889
890   # check which database was filled in
891   if ($form->{dbdriver} eq 'Oracle') {
892     $form->{sid}      = $form->{Oracle_sid},;
893     $form->{dbhost}   = $form->{Oracle_dbhost},;
894     $form->{dbport}   = $form->{Oracle_dbport};
895     $form->{dbpasswd} = $form->{Oracle_dbpasswd};
896     $form->{dbuser}   = $form->{Oracle_dbuser};
897     $form->{dbname}   = $form->{Oracle_dbuser};
898
899     $form->isblank("dbhost", $locale->text('Hostname missing!'));
900     $form->isblank("dbport", $locale->text('Port missing!'));
901     $form->isblank("dbuser", $locale->text('Dataset missing!'));
902   }
903   if ($form->{dbdriver} eq 'Pg') {
904     $form->{dbhost}   = $form->{Pg_dbhost};
905     $form->{dbport}   = $form->{Pg_dbport};
906     $form->{dbpasswd} = $form->{Pg_dbpasswd};
907     $form->{dbuser}   = $form->{Pg_dbuser};
908     $form->{dbname}   = $form->{Pg_dbname};
909
910     $form->isblank("dbname", $locale->text('Dataset missing!'));
911     $form->isblank("dbuser", $locale->text('Database User missing!'));
912   }
913
914   if ($webdav) {
915     @webdavdirs =
916       qw(angebote bestellungen rechnungen anfragen lieferantenbestellungen einkaufsrechnungen);
917     foreach $directory (@webdavdirs) {
918       if ($form->{$directory}) {
919         $form->{$directory} = $form->{$directory};
920       } else {
921         $form->{$directory} = 0;
922       }
923     }
924   }
925
926   foreach $item (keys %{$form}) {
927     $myconfig->{$item} = $form->{$item};
928   }
929
930   delete $myconfig->{stylesheet};
931   if ($form->{userstylesheet}) {
932     $myconfig->{stylesheet} = $form->{userstylesheet};
933   }
934
935   $myconfig->save_member($memberfile, $userspath);
936
937   if ($webdav) {
938     @webdavdirs =
939       qw(angebote bestellungen rechnungen anfragen lieferantenbestellungen einkaufsrechnungen);
940     foreach $directory (@webdavdirs) {
941       $file = "webdav/" . $directory . "/webdav-user";
942       if ($form->{$directory}) {
943         if (open(HTACCESS, "$file")) {
944           while (<HTACCESS>) {
945             ($login, $password) = split(/:/, $_);
946             if ($login ne $form->{login}) {
947               $newfile .= $_;
948             }
949           }
950           close(HTACCESS);
951         }
952         open(HTACCESS, "> $file") or die "cannot open $file $!\n";
953         $newfile .= $myconfig->{login} . ":" . $myconfig->{password} . "\n";
954         print(HTACCESS $newfile);
955         close(HTACCESS);
956       } else {
957         $form->{$directory} = 0;
958         if (open(HTACCESS, "$file")) {
959           while (<HTACCESS>) {
960             ($login, $password) = split(/:/, $_);
961             if ($login ne $form->{login}) {
962               $newfile .= $_;
963             }
964           }
965           close(HTACCESS);
966         }
967         open(HTACCESS, "> $file") or die "cannot open $file $!\n";
968         print(HTACCESS $newfile);
969         close(HTACCESS);
970       }
971     }
972   }
973
974   # create user template directory and copy master files
975   if (!-d "$form->{templates}") {
976     umask(002);
977
978     if (mkdir "$form->{templates}", oct("771")) {
979
980       umask(007);
981
982       # copy templates to the directory
983       opendir TEMPLATEDIR, "$templates/." or $form - error("$templates : $!");
984       @templates = grep /$form->{mastertemplates}.*?\.(html|tex|sty|xml|txb)$/,
985         readdir TEMPLATEDIR;
986       closedir TEMPLATEDIR;
987
988       foreach $file (@templates) {
989         open(TEMP, "$templates/$file")
990           or $form->error("$templates/$file : $!");
991
992         $file =~ s/$form->{mastertemplates}-//;
993         open(NEW, ">$form->{templates}/$file")
994           or $form->error("$form->{templates}/$file : $!");
995
996         while ($line = <TEMP>) {
997           print NEW $line;
998         }
999         close(TEMP);
1000         close(NEW);
1001       }
1002     } else {
1003       $form->error("$!: $form->{templates}");
1004     }
1005   }
1006
1007   $form->redirect($locale->text('User saved!'));
1008
1009 }
1010
1011 sub delete {
1012
1013   $form->{templates} =
1014     ($form->{templates})
1015     ? "$templates/$form->{templates}"
1016     : "$templates/$form->{login}";
1017
1018   $form->error($locale->text('File locked!')) if (-f ${memberfile} . LCK);
1019   open(FH, ">${memberfile}.LCK") or $form->error("${memberfile}.LCK : $!");
1020   close(FH);
1021
1022   open(CONF, "+<$memberfile") or $form->error("$memberfile : $!");
1023
1024   @config = <CONF>;
1025
1026   seek(CONF, 0, 0);
1027   truncate(CONF, 0);
1028
1029   while ($line = shift @config) {
1030
1031     if ($line =~ /^\[/) {
1032       last if ($line =~ /\[$form->{login}\]/);
1033       $login = &login_name($line);
1034     }
1035
1036     if ($line =~ /^templates=/) {
1037       $user{$login} = &get_value($line);
1038     }
1039
1040     print CONF $line;
1041   }
1042
1043   # remove everything up to next login or EOF
1044   # and save template variable
1045   while ($line = shift @config) {
1046     if ($line =~ /^templates=/) {
1047       $templatedir = &get_value($line);
1048     }
1049     last if ($line =~ /^\[/);
1050   }
1051
1052   # this one is either the next login or EOF
1053   print CONF $line;
1054
1055   $login = &login_name($line);
1056
1057   while ($line = shift @config) {
1058     if ($line =~ /^\[/) {
1059       $login = &login_name($line);
1060     }
1061
1062     if ($line =~ /^templates=/) {
1063       $user{$login} = &get_value($line);
1064     }
1065
1066     print CONF $line;
1067   }
1068
1069   close(CONF);
1070   unlink "${memberfile}.LCK";
1071
1072   # scan %user for $templatedir
1073   foreach $login (keys %user) {
1074     last if ($found = ($templatedir eq $user{$login}));
1075   }
1076
1077   # if found keep directory otherwise delete
1078   if (!$found) {
1079
1080     # delete it if there is a template directory
1081     $dir = "$form->{templates}";
1082     if (-d "$dir") {
1083       unlink <$dir/*.html>;
1084       unlink <$dir/*.tex>;
1085       unlink <$dir/*.sty>;
1086       rmdir "$dir";
1087     }
1088   }
1089
1090   # delete config file for user
1091   unlink "$userspath/$form->{login}.conf";
1092
1093   $form->redirect($locale->text('User deleted!'));
1094
1095 }
1096
1097 sub login_name {
1098   my $login = shift;
1099
1100   $login =~ s/\[\]//g;
1101   return ($login) ? $login : undef;
1102
1103 }
1104
1105 sub get_value {
1106   my $line = shift;
1107
1108   my ($null, $value) = split(/=/, $line, 2);
1109
1110   # remove comments
1111   $value =~ s/\s#.*//g;
1112
1113   # remove any trailing whitespace
1114   $value =~ s/^\s*(.*?)\s*$/$1/;
1115
1116   $value;
1117 }
1118
1119 sub change_admin_password {
1120
1121   $form->{title} =
1122       qq|Lx-Office ERP |
1123     . $locale->text('Administration') . " / "
1124     . $locale->text('Change Admin Password');
1125
1126   $form->header;
1127
1128   print qq|
1129 <body class=admin>
1130
1131
1132 <h2>| . $locale->text('Change Admin Password') . qq|</h2>
1133
1134 <form method=post action=$form->{script}>
1135
1136 <table>
1137   <tr>
1138     <td><b>| . $locale->text('Password') . qq|</b></td>
1139     <td><input type=password name=password size=8></td>
1140   </tr>
1141   <tr>
1142     <td><b>| . $locale->text('Repeat the password') . qq|</b></td>
1143     <td><input type=password name=password_again size=8></b></td>
1144   </tr>
1145 </table>
1146
1147 <input type=hidden name=rpw value=$form->{rpw}>
1148
1149 <p>
1150 <input type=submit class=submit name=action value="|
1151     . $locale->text('Change Password') . qq|">
1152
1153 </form>
1154
1155 </body>
1156 </html>
1157 |;
1158
1159 }
1160
1161 sub change_password {
1162   if ($form->{"password"} ne $form->{"password_again"}) {
1163     $form->{title} =
1164       qq|Lx-Office ERP |
1165       . $locale->text('Administration') . " / "
1166       . $locale->text('Change Admin Password');
1167
1168     $form->header;
1169
1170     print qq|
1171 <body class=admin>
1172
1173
1174 <h2>| . $locale->text('Change Admin Password') . qq|</h2>
1175
1176 <p>| . $locale->text("The passwords do not match.") . qq|<br>
1177 <input type="button" onclick="history.back()" value="| . $locale->text("Back") . qq|">|;
1178     return;
1179   }
1180
1181   $root->{password} = $form->{password};
1182
1183   $root->{'root login'} = 1;
1184   $root->save_member($memberfile);
1185
1186   $form->{callback} =
1187     "$form->{script}?action=list_users&rpw=$root->{password}";
1188
1189   $form->redirect($locale->text('Password changed!'));
1190
1191 }
1192
1193 sub check_password {
1194   $root = new User "$memberfile", $form->{root};
1195
1196   if (!defined($root->{password}) || ($root->{password} ne $form->{rpw})) {
1197     $form->error($locale->text('Incorrect Password!'));
1198   }
1199
1200 }
1201
1202 sub pg_database_administration {
1203
1204   $form->{dbdriver} = 'Pg';
1205   &dbselect_source;
1206
1207 }
1208
1209 sub oracle_database_administration {
1210
1211   $form->{dbdriver} = 'Oracle';
1212   &dbselect_source;
1213
1214 }
1215
1216 sub dbdriver_defaults {
1217
1218   # load some defaults for the selected driver
1219   %driverdefaults = (
1220                      'Pg' => { dbport        => '5432',
1221                                dbuser        => 'postgres',
1222                                dbdefault     => 'template1',
1223                                dbhost        => 'localhost',
1224                                connectstring => $locale->text('Connect to')
1225                      },
1226                      'Oracle' => { dbport        => '1521',
1227                                    dbuser        => 'oralin',
1228                                    dbdefault     => $sid,
1229                                    dbhost        => `hostname`,
1230                                    connectstring => 'SID'
1231                      });
1232
1233   map { $form->{$_} = $driverdefaults{ $form->{dbdriver} }{$_} }
1234     keys %{ $driverdefaults{Pg} };
1235
1236 }
1237
1238 sub dbselect_source {
1239
1240   &dbdriver_defaults;
1241
1242   $msg{Pg} =
1243     $locale->text(
1244     'Leave host and port field empty unless you want to make a remote connection.'
1245     );
1246   $msg{Oracle} =
1247     $locale->text(
1248            'You must enter a host and port for local and remote connections!');
1249
1250   $form->{title} =
1251     "Lx-Office ERP / " . $locale->text('Database Administration');
1252
1253   $form->header;
1254
1255   print qq|
1256 <body class=admin>
1257
1258
1259 <center>
1260 <h2>$form->{title}</h2>
1261
1262 <form method=post action=$form->{script}>
1263
1264 <table>
1265 <tr><td>
1266
1267 <table>
1268
1269   <tr class=listheading>
1270     <th colspan=4>| . $locale->text('Database') . qq|</th>
1271   </tr>
1272
1273 <input type=hidden name=dbdriver value=$form->{dbdriver}>
1274
1275   <tr><td>
1276    <table>
1277
1278   <tr>
1279
1280     <th align=right>| . $locale->text('Host') . qq|</th>
1281     <td><input name=dbhost size=25 value=$form->{dbhost}></td>
1282     <th align=right>| . $locale->text('Port') . qq|</th>
1283     <td><input name=dbport size=5 value=$form->{dbport}></td>
1284
1285   </tr>
1286
1287   <tr>
1288
1289     <th align=right>| . $locale->text('User') . qq|</th>
1290     <td><input name="dbuser" size="10" value="$form->{dbuser}"></td>
1291     <th align=right>| . $locale->text('Password') . qq|</th>
1292     <td><input type="password" name="dbpasswd" size="10"></td>
1293
1294   </tr>
1295
1296   <tr>
1297
1298     <th align=right>$form->{connectstring}</th>
1299     <td colspan=3><input name=dbdefault size=10 value=$form->{dbdefault}></td>
1300
1301   </tr>
1302
1303 </table>
1304
1305 </td></tr>
1306 </table>
1307
1308 <input name=callback type=hidden value="$form->{script}?action=list_users&rpw=$form->{rpw}">
1309 <input type=hidden name=rpw value=$form->{rpw}>
1310
1311 <br>
1312
1313 <input type=submit class=submit name=action value="|
1314     . $locale->text('Create Dataset') . qq|">|;
1315 # Vorübergehend Deaktiviert
1316 # <input type=submit class=submit name=action value="|
1317 #     . $locale->text('Update Dataset') . qq|">
1318 print qq| <input type=submit class=submit name=action value="|
1319     . $locale->text('Delete Dataset') . qq|">
1320
1321 </form>
1322
1323 </td></tr>
1324 </table>
1325
1326 <p>|
1327     . $locale->text(
1328     'This is a preliminary check for existing sources. Nothing will be created or deleted at this stage!'
1329     )
1330
1331     . qq|
1332 <br>$msg{$form->{dbdriver}}
1333
1334
1335 </body>
1336 </html>
1337 |;
1338
1339 }
1340
1341 sub continue {
1342   call_sub($form->{"nextsub"});
1343 }
1344
1345 sub update_dataset {
1346
1347   %needsupdate = User->dbneedsupdate(\%$form);
1348
1349   $form->{title} =
1350       "Lx-Office ERP "
1351     . $locale->text('Database Administration') . " / "
1352     . $locale->text('Update Dataset');
1353
1354   $form->header;
1355
1356   print qq|
1357 <body class=admin>
1358
1359
1360 <center>
1361 <h2>$form->{title}</h2>
1362 |;
1363   my $field_id = 0;
1364   foreach $key (sort keys %needsupdate) {
1365     if ($needsupdate{$key} ne $form->{dbversion}) {
1366       $upd .= qq|<input id="$field_id" name="db$key" type="checkbox" value="1" checked> $key\n|;
1367       $form->{dbupdate} .= "db$key ";
1368       $field_id++;
1369     }
1370   }
1371
1372   chop $form->{dbupdate};
1373
1374   if ($form->{dbupdate}) {
1375
1376     print qq|
1377 <table width=100%>
1378 <form method=post action=$form->{script}>
1379
1380 <input type=hidden name="dbdriver"  value="$form->{dbdriver}">
1381 <input type=hidden name="dbhost"    value="$form->{dbhost}">
1382 <input type=hidden name="dbport"    value="$form->{dbport}">
1383 <input type=hidden name="dbuser"    value="$form->{dbuser}">
1384 <input type=hidden name="dbpasswd"  value="$form->{dbpasswd}">
1385 <input type=hidden name="dbdefault" value="$form->{dbdefault}">
1386
1387 <tr class=listheading>
1388   <th>| . $locale->text('The following Datasets need to be updated') . qq|</th>
1389 </tr>
1390 <tr>
1391 <td>
1392
1393 $upd
1394
1395 </td>
1396 </tr>
1397 <tr>
1398 <td>
1399
1400 <input name=dbupdate type=hidden value="$form->{dbupdate}">
1401
1402 <input name=callback type=hidden value="$form->{script}?action=list_users&rpw=$form->{rpw}">
1403
1404 <input type=hidden name=rpw value=$form->{rpw}>
1405
1406 <input type=hidden name=nextsub value=dbupdate>
1407
1408 <hr size=3 noshade>
1409
1410 <br>
1411 <input type=submit class=submit name=action value="|
1412       . $locale->text('Continue') . qq|">
1413
1414 </td></tr>
1415 </table>
1416 </form>
1417 |;
1418
1419   } else {
1420
1421     print $locale->text('All Datasets up to date!');
1422
1423   }
1424
1425   print qq|
1426
1427 </body>
1428 </html>
1429 |;
1430
1431 }
1432
1433 sub dbupdate {
1434   $form->{"stylesheet"} = "lx-office-erp.css";
1435   $form->{"title"} = $main::locale->text("Dataset upgrade");
1436   $form->header();
1437   my $dbname =
1438     join(" ",
1439          map({ s/\s//g; s/^db//; $_; }
1440              grep({ $form->{$_} }
1441                   split(/\s+/, $form->{"dbupdate"}))));
1442   print($form->parse_html_template("dbupgrade/header",
1443                                    { "dbname" => $dbname }));
1444
1445   User->dbupdate(\%$form);
1446
1447   print qq|
1448 <hr>
1449
1450 | . $locale->text('Dataset updated!') . qq|
1451
1452 <br>
1453
1454 <a id="enddatasetupdate" href="admin.pl?action=login&| .
1455 join("&", map({ "$_=" . $form->escape($form->{$_}); } qw(rpw))) .
1456 qq|">| . $locale->text("Continue") . qq|</a>|;
1457
1458 }
1459
1460 sub create_dataset {
1461
1462   foreach $item (sort User->dbsources(\%$form)) {
1463     $dbsources .= "[$item] ";
1464   }
1465
1466   opendir SQLDIR, "sql/." or $form - error($!);
1467   foreach $item (sort grep /-chart\.sql\z/, readdir SQLDIR) {
1468     next if ($item eq 'Default-chart.sql');
1469     $item =~ s/-chart\.sql//;
1470     push @charts,
1471       qq| <input name=chart class=radio type=radio value="$item">&nbsp;$item|;
1472   }
1473   closedir SQLDIR;
1474
1475   my (@values, %labels);
1476
1477   my $default_charset = $dbcharset;
1478   $default_charset ||= Common::DEFAULT_CHARSET;
1479   my $default_encoding;
1480
1481   foreach my $encoding (@Common::db_encodings) {
1482     push @values, $encoding->{dbencoding};
1483     $labels{$encoding->{dbencoding}} = $encoding->{label};
1484
1485     $default_encoding = $encoding->{dbencoding} if $encoding->{charset} eq $default_charset;
1486   }
1487
1488   $selectencoding =
1489     NTI($cgi->popup_menu('-name' => 'encoding',
1490                          '-values' => \@values,
1491                          '-labels' => \%labels,
1492                          '-default' => $default_encoding));
1493
1494   $form->{title} =
1495       "Lx-Office ERP "
1496     . $locale->text('Database Administration') . " / "
1497     . $locale->text('Create Dataset');
1498
1499   $form->header;
1500
1501   print qq|
1502 <body class=admin>
1503
1504
1505 <center>
1506 <h2>$form->{title}</h2>
1507
1508 <form method=post action=$form->{script}>
1509
1510 <table width=100%>
1511   <tr class=listheading>
1512     <th colspan=2>&nbsp;</th>
1513   </tr>
1514
1515   <tr>
1516
1517     <th align=right nowrap>| . $locale->text('Existing Datasets') . qq|</th>
1518     <td>$dbsources</td>
1519
1520   </tr>
1521
1522   <tr>
1523
1524     <th align=right nowrap>| . $locale->text('Create Dataset') . qq|</th>
1525     <td><input name=db></td>
1526
1527   </tr>
1528
1529   <tr>
1530
1531     <th align=right nowrap>| . $locale->text('Multibyte Encoding') . qq|</th>
1532     <td>$selectencoding</td>
1533
1534   </tr>
1535
1536   <tr>
1537
1538     <th align=right nowrap>|
1539     . $locale->text('Create Chart of Accounts') . qq|</th>
1540     <td>@charts</td>
1541
1542   </tr>
1543
1544   <tr><td colspan=2>
1545 <p>
1546 <input type=hidden name="dbdriver"  value="$form->{dbdriver}">
1547 <input type=hidden name="dbuser"    value="$form->{dbuser}">
1548 <input type=hidden name="dbhost"    value="$form->{dbhost}">
1549 <input type=hidden name="dbport"    value="$form->{dbport}">
1550 <input type=hidden name="dbpasswd"  value="$form->{dbpasswd}">
1551 <input type=hidden name="dbdefault" value="$form->{dbdefault}">
1552
1553 <input name=callback type=hidden value="$form->{script}?action=list_users&rpw=$form->{rpw}">
1554
1555 <input type=hidden name=rpw value=$form->{rpw}>
1556
1557 <input type=hidden name=nextsub value=dbcreate>
1558
1559 <hr size=3 noshade>
1560
1561 <br>
1562 <input type=submit class=submit name=action value="|
1563     . $locale->text('Continue') . qq|">
1564
1565   </td></tr>
1566 </table>
1567
1568 </form>
1569
1570
1571 </body>
1572 </html>
1573 |;
1574
1575 }
1576
1577 sub dbcreate {
1578
1579   $form->isblank("db", $locale->text('Dataset missing!'));
1580
1581   User->dbcreate(\%$form);
1582
1583   $form->{title} =
1584       "Lx-Office ERP "
1585     . $locale->text('Database Administration') . " / "
1586     . $locale->text('Create Dataset');
1587
1588   $form->header;
1589
1590   print qq|
1591 <body class=admin>
1592
1593
1594 <center>
1595 <h2>$form->{title}</h2>
1596
1597 <form method=post action=$form->{script}>|
1598
1599     . $locale->text('Dataset')
1600     . " $form->{db} "
1601     . $locale->text('successfully created!')
1602
1603     . qq|
1604
1605 <input type=hidden name=rpw value="$form->{rpw}">
1606
1607 <input type=hidden name=nextsub value=list_users>
1608
1609 <p><input type=submit class=submit name=action value="|
1610     . $locale->text('Continue') . qq|">
1611 </form>
1612
1613
1614 </body>
1615 </html>
1616 |;
1617
1618 }
1619
1620 sub delete_dataset {
1621
1622   if (@dbsources = User->dbsources_unused(\%$form, $memberfile)) {
1623     foreach $item (sort @dbsources) {
1624       $dbsources .=
1625         qq|<input name=db class=radio type=radio value=$item>&nbsp;$item |;
1626     }
1627   } else {
1628     $form->error($locale->text('Nothing to delete!'));
1629   }
1630
1631   $form->{title} =
1632       "Lx-Office ERP "
1633     . $locale->text('Database Administration') . " / "
1634     . $locale->text('Delete Dataset');
1635
1636   $form->header;
1637
1638   print qq|
1639 <body class=admin>
1640
1641 <h2>$form->{title}</h2>
1642
1643 <form method=post action=$form->{script}>
1644
1645 <table width=100%>
1646   <tr class=listheading>
1647     <th>|
1648     . $locale->text('The following Datasets are not in use and can be deleted')
1649     . qq|</th>
1650   </tr>
1651
1652   <tr>
1653     <td>
1654     $dbsources
1655     </td>
1656   </tr>
1657
1658   <tr><td>
1659 <p>
1660 <input type=hidden name="dbdriver"  value="$form->{dbdriver}">
1661 <input type=hidden name="dbuser"    value="$form->{dbuser}">
1662 <input type=hidden name="dbhost"    value="$form->{dbhost}">
1663 <input type=hidden name="dbport"    value="$form->{dbport}">
1664 <input type=hidden name="dbpasswd"  value="$form->{dbpasswd}">
1665 <input type=hidden name="dbdefault" value="$form->{dbdefault}">
1666
1667 <input name=callback type=hidden value="$form->{script}?action=list_users&rpw=$form->{rpw}">
1668
1669 <input type=hidden name=rpw value="$form->{rpw}">
1670
1671 <input type=hidden name=nextsub value=dbdelete>
1672
1673 <hr size=3 noshade>
1674
1675 <br>
1676 <input type=submit class=submit name=action value="|
1677     . $locale->text('Continue') . qq|">
1678
1679   </td></tr>
1680 </table>
1681
1682 </form>
1683
1684 </body>
1685 </html>
1686 |;
1687
1688 }
1689
1690 sub dbdelete {
1691
1692   if (!$form->{db}) {
1693     $form->error($locale->text('No Dataset selected!'));
1694   }
1695
1696   User->dbdelete(\%$form);
1697
1698   $form->{title} =
1699       "Lx-Office ERP "
1700     . $locale->text('Database Administration') . " / "
1701     . $locale->text('Delete Dataset');
1702
1703   $form->header;
1704
1705   print qq|
1706 <body class=admin>
1707
1708
1709 <center>
1710 <h2>$form->{title}</h2>
1711
1712 <form method=post action=$form->{script}>
1713
1714 $form->{db} | . $locale->text('successfully deleted!')
1715
1716     . qq|
1717
1718 <input type=hidden name=rpw value="$form->{rpw}">
1719
1720 <input type=hidden name=nextsub value=list_users>
1721
1722 <p><input type=submit class=submit name=action value="|
1723     . $locale->text('Continue') . qq|">
1724 </form>
1725
1726
1727 </body>
1728 </html>
1729 |;
1730
1731 }
1732
1733 sub unlock_system {
1734
1735   unlink "$userspath/nologin";
1736
1737   $form->{callback} =
1738     "$form->{script}?action=list_users&rpw=$root->{password}";
1739
1740   $form->redirect($locale->text('Lockfile removed!'));
1741
1742 }
1743
1744 sub lock_system {
1745
1746   open(FH, ">$userspath/nologin")
1747     or $form->error($locale->text('Cannot create Lock!'));
1748   close(FH);
1749
1750   $form->{callback} =
1751     "$form->{script}?action=list_users&rpw=$root->{password}";
1752
1753   $form->redirect($locale->text('Lockfile created!'));
1754
1755 }