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