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