Revision 4531a6c7
Von Sven Schöling vor fast 13 Jahren hinzugefügt
bin/mozilla/admin.pl | ||
---|---|---|
73 | 73 |
our $locale; |
74 | 74 |
our $auth; |
75 | 75 |
|
76 |
my @valid_dateformats = qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd); |
|
77 |
my @valid_numberformats = ('1,000.00', '1000.00', '1.000,00', '1000,00'); |
|
78 |
my @all_stylesheets = qw(lx-office-erp.css Win2000.css); |
|
79 |
my @all_menustyles = ( |
|
80 |
{ id => 'old', title => $::locale->text('Old (on the side)') }, |
|
81 |
{ id => 'v3', title => $::locale->text('Top (CSS)') }, |
|
82 |
{ id => 'v4', title => $::locale->text('Top (CSS) new') }, |
|
83 |
{ id => 'neu', title => $::locale->text('Top (Javascript)') }, |
|
84 |
); |
|
85 |
|
|
76 | 86 |
sub run { |
77 | 87 |
$::lxdebug->enter_sub; |
78 | 88 |
my $session_result = shift; |
... | ... | |
366 | 376 |
} |
367 | 377 |
|
368 | 378 |
sub add_user { |
369 |
my $form = $main::form; |
|
370 |
my $locale = $main::locale; |
|
371 |
|
|
372 |
$form->{title} = "Lx-Office ERP " . $locale->text('Administration') . " / " . $locale->text('Add User'); |
|
379 |
$::form->{title} = "Lx-Office ERP " . $::locale->text('Administration') . " / " . $::locale->text('Add User'); |
|
373 | 380 |
|
374 | 381 |
# Note: Menu Style 'v3' is not compatible to all browsers! |
375 | 382 |
# "menustyle" => "old" sets the HTML Menu to default. |
376 |
my $myconfig = { |
|
383 |
# User does not have a well behaved new constructor, so we#Ll just have to build one ourself |
|
384 |
my $user = bless { |
|
377 | 385 |
"vclimit" => 200, |
378 | 386 |
"countrycode" => "de", |
379 | 387 |
"numberformat" => "1.000,00", |
... | ... | |
383 | 391 |
dbport => $::auth->{DB_config}->{port} || 5432, |
384 | 392 |
dbuser => $::auth->{DB_config}->{user} || 'lxoffice', |
385 | 393 |
dbhost => $::auth->{DB_config}->{host} || 'localhost', |
386 |
}; |
|
394 |
}, 'User';
|
|
387 | 395 |
|
388 |
|
|
389 |
edit_user_form($myconfig); |
|
396 |
edit_user_form($user); |
|
390 | 397 |
} |
391 | 398 |
|
392 | 399 |
sub edit_user { |
393 |
my $form = $main::form; |
|
394 |
my $locale = $main::locale; |
|
395 |
|
|
396 |
$form->{title} = "Lx-Office ERP " . $locale->text('Administration') . " / " . $locale->text('Edit User'); |
|
397 |
$form->{edit} = 1; |
|
398 |
|
|
399 |
$form->isblank("login", $locale->text("The login is missing.")); |
|
400 |
$::form->{title} = "Lx-Office ERP " . $::locale->text('Administration') . " / " . $::locale->text('Edit User'); |
|
401 |
$::form->{edit} = 1; |
|
400 | 402 |
|
401 | 403 |
# get user |
402 |
my $myconfig = new User($form->{login});
|
|
404 |
my $user = User->new(id => $::form->{user}{id});
|
|
403 | 405 |
|
404 | 406 |
# strip basedir from templates directory |
405 |
$myconfig->{templates} =~ s|.*/||;
|
|
407 |
$user->{templates} =~ s|.*/||;
|
|
406 | 408 |
|
407 |
edit_user_form($myconfig);
|
|
409 |
edit_user_form($user);
|
|
408 | 410 |
} |
409 | 411 |
|
410 | 412 |
sub edit_user_form { |
411 |
my ($myconfig) = @_; |
|
412 |
|
|
413 |
my $form = $main::form; |
|
414 |
my $locale = $main::locale; |
|
415 |
|
|
416 |
my @valid_dateformats = qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd); |
|
417 |
$form->{ALL_DATEFORMATS} = [ map { { "format" => $_, "selected" => $_ eq $myconfig->{dateformat} } } @valid_dateformats ]; |
|
418 |
|
|
419 |
my @valid_numberformats = ('1,000.00', '1000.00', '1.000,00', '1000,00'); |
|
420 |
$form->{ALL_NUMBERFORMATS} = [ map { { "format" => $_, "selected" => $_ eq $myconfig->{numberformat} } } @valid_numberformats ]; |
|
421 |
|
|
422 |
my %countrycodes = User->country_codes; |
|
423 |
$form->{ALL_COUNTRYCODES} = []; |
|
424 |
foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) { |
|
425 |
push @{ $form->{ALL_COUNTRYCODES} }, { "value" => $countrycode, |
|
426 |
"name" => $countrycodes{$countrycode}, |
|
427 |
"selected" => $countrycode eq $myconfig->{countrycode} }; |
|
428 |
} |
|
429 |
|
|
430 |
# is there a templates basedir |
|
431 |
if (!-d $::lx_office_conf{paths}->{templates}) { |
|
432 |
$form->error(sprintf($locale->text("The directory %s does not exist."), $::lx_office_conf{paths}->{templates})); |
|
433 |
} |
|
434 |
|
|
435 |
opendir TEMPLATEDIR, $::lx_office_conf{paths}->{templates} or $form->error($::lx_office_conf{paths}->{templates} . " : $ERRNO"); |
|
436 |
my @all = readdir(TEMPLATEDIR); |
|
437 |
my @alldir = sort grep { -d ($::lx_office_conf{paths}->{templates} . "/$_") && !/^\.\.?$/ } @all; |
|
438 |
closedir TEMPLATEDIR; |
|
439 |
|
|
440 |
@alldir = grep !/\.(html|tex|sty|odt|xml|txb)$/, @alldir; |
|
441 |
@alldir = grep !/^(webpages|print|\.svn)$/, @alldir; |
|
442 |
|
|
443 |
$form->{ALL_TEMPLATES} = [ map { { "name", => $_, "selected" => $_ eq $myconfig->{templates} } } @alldir ]; |
|
444 |
|
|
445 |
# mastertemplates |
|
446 |
opendir TEMPLATEDIR, "$::lx_office_conf{paths}->{templates}/print" or $form->error("$::lx_office_conf{paths}->{templates}/print" . " : $ERRNO"); |
|
447 |
my @allmaster = readdir(TEMPLATEDIR); |
|
448 |
closedir TEMPLATEDIR; |
|
449 |
|
|
450 |
@allmaster = sort grep { -d ("$::lx_office_conf{paths}->{templates}/print" . "/$_") && !/^\.\.?$/ } @allmaster; |
|
451 |
@allmaster = reverse grep !/Default/, @allmaster; |
|
452 |
push @allmaster, 'Default'; |
|
453 |
@allmaster = reverse @allmaster; |
|
454 |
|
|
455 |
foreach my $item (@allmaster) { |
|
456 |
push @{ $form->{ALL_MASTER_TEMPLATES} }, { "name" => $item, "selected" => $item eq "German" }; |
|
457 |
} |
|
458 |
|
|
459 |
# css dir has styles that are not intended as general layouts. |
|
460 |
# reverting to hardcoded list |
|
461 |
$form->{ALL_STYLESHEETS} = [ map { { "name" => $_, "selected" => $_ eq $myconfig->{stylesheet} } } qw(lx-office-erp.css Win2000.css) ]; |
|
462 |
|
|
463 |
$form->{"menustyle_" . $myconfig->{menustyle} } = 1; |
|
464 |
|
|
465 |
map { $form->{"myc_${_}"} = $myconfig->{$_} } keys %{ $myconfig }; |
|
413 |
my ($user) = @_; |
|
466 | 414 |
|
415 |
my %cc = $user->country_codes; |
|
416 |
my @all_countrycodes = map { id => $_, title => $cc{$_} }, sort { $cc{$a} cmp $cc{$b} } keys %cc; |
|
417 |
my ($all_dir, $all_master) = _search_templates(); |
|
467 | 418 |
my $groups = []; |
468 | 419 |
|
469 |
if ($form->{edit}) { |
|
470 |
my $user_id = $main::auth->get_user_id($form->{login});
|
|
471 |
my $all_groups = $main::auth->read_groups();
|
|
420 |
if ($::form->{edit}) {
|
|
421 |
my $user_id = $::auth->get_user_id($::form->{login});
|
|
422 |
my $all_groups = $::auth->read_groups(); |
|
472 | 423 |
|
473 |
foreach my $group (values %{ $all_groups }) {
|
|
424 |
for my $group (values %{ $all_groups }) { |
|
474 | 425 |
push @{ $groups }, $group if (grep { $user_id == $_ } @{ $group->{members} }); |
475 | 426 |
} |
476 | 427 |
|
477 | 428 |
$groups = [ sort { lc $a->{name} cmp lc $b->{name} } @{ $groups } ]; |
478 | 429 |
} |
479 | 430 |
|
480 |
$form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password(); |
|
481 |
|
|
482 |
$form->header(); |
|
483 |
print $form->parse_html_template("admin/edit_user", { 'GROUPS' => $groups }); |
|
431 |
$::form->header; |
|
432 |
print $::form->parse_html_template("admin/edit_user", { |
|
433 |
GROUPS => $groups, |
|
434 |
CAN_CHANGE_PASSWORD => $::auth->can_change_password, |
|
435 |
user => $user->data, |
|
436 |
all_stylesheets => \@all_stylesheets, |
|
437 |
all_numberformats => \@valid_numberformats, |
|
438 |
all_dateformats => \@valid_dateformats, |
|
439 |
all_countrycodes => \@all_countrycodes, |
|
440 |
all_menustyles => \@all_menustyles, |
|
441 |
all_templates => $all_dir, |
|
442 |
all_master_templates => $all_master, |
|
443 |
}); |
|
484 | 444 |
} |
485 | 445 |
|
486 | 446 |
sub save_user { |
487 | 447 |
my $form = $main::form; |
488 | 448 |
my $locale = $main::locale; |
489 | 449 |
|
490 |
$form->{dbdriver} = 'Pg'; |
|
450 |
my $user = $form->{user}; |
|
451 |
|
|
452 |
$user->{dbdriver} = 'Pg'; |
|
491 | 453 |
|
492 |
# no spaces allowed in login name |
|
493 |
$form->{login} =~ s|\s||g; |
|
494 |
$form->isblank("login", $locale->text('Login name missing!')); |
|
454 |
if (!$::form->{edit}) { |
|
455 |
# no spaces allowed in login name |
|
456 |
$user->{login} =~ s/\s//g; |
|
457 |
$::form->show_generic_error($::locale->text('Login name missing!')) unless $user->{login}; |
|
495 | 458 |
|
496 |
# check for duplicates |
|
497 |
if (!$form->{edit}) { |
|
498 |
my %members = $main::auth->read_all_users(); |
|
499 |
if ($members{$form->{login}}) { |
|
500 |
$form->show_generic_error($locale->text('Another user with the login #1 does already exist.', $form->{login}), 'back_button' => 1); |
|
459 |
# check for duplicates |
|
460 |
my %members = $::auth->read_all_users; |
|
461 |
if ($members{$user->{login}}) { |
|
462 |
$::form->show_generic_error($locale->text('Another user with the login #1 does already exist.', $user->{login}), 'back_button' => 1); |
|
501 | 463 |
} |
502 | 464 |
} |
503 | 465 |
|
504 | 466 |
# no spaces allowed in directories |
505 |
($form->{newtemplates}) = split / /, $form->{newtemplates}; |
|
506 |
|
|
507 |
if ($form->{newtemplates}) { |
|
508 |
$form->{templates} = $form->{newtemplates}; |
|
509 |
} else { |
|
510 |
$form->{templates} = |
|
511 |
($form->{usetemplates}) ? $form->{usetemplates} : $form->{login}; |
|
512 |
} |
|
467 |
($::form->{newtemplates}) = split / /, $::form->{newtemplates}; |
|
468 |
$user->{templates} = $::form->{newtemplates} || $::form->{usetemplates} || $user->{login}; |
|
513 | 469 |
|
514 | 470 |
# is there a basedir |
515 | 471 |
if (!-d $::lx_office_conf{paths}->{templates}) { |
516 |
$form->error(sprintf($locale->text("The directory %s does not exist."), $::lx_office_conf{paths}->{templates}));
|
|
472 |
$::form->error(sprintf($::locale->text("The directory %s does not exist."), $::lx_office_conf{paths}->{templates}));
|
|
517 | 473 |
} |
518 | 474 |
|
519 | 475 |
# add base directory to $form->{templates} |
520 |
$form->{templates} =~ s|.*/||; |
|
521 |
$form->{templates} = $::lx_office_conf{paths}->{templates} . "/$form->{templates}"; |
|
522 |
|
|
523 |
my $myconfig = new User($form->{login}); |
|
476 |
$user->{templates} =~ s|.*/||; |
|
477 |
$user->{templates} = $::lx_office_conf{paths}->{templates} . "/$user->{templates}"; |
|
524 | 478 |
|
525 |
$form->isblank("dbname", $locale->text('Dataset missing!')); |
|
526 |
$form->isblank("dbuser", $locale->text('Database User missing!')); |
|
479 |
my $myconfig = new User(id => $form->{id}); |
|
527 | 480 |
|
528 |
foreach my $item (keys %{$form}) { |
|
529 |
$myconfig->{$item} = $form->{$item}; |
|
530 |
} |
|
481 |
$::form->show_generic_error($::locale->text('Dataset missing!')) unless $user->{dbname}; |
|
482 |
$::form->show_generic_error($::locale->text('Database User missing!')) unless $user->{dbuser}; |
|
531 | 483 |
|
532 |
delete $myconfig->{stylesheet}; |
|
533 |
if ($form->{userstylesheet}) { |
|
534 |
$myconfig->{stylesheet} = $form->{userstylesheet}; |
|
484 |
foreach my $item (keys %{$user}) { |
|
485 |
$myconfig->{$item} = $user->{$item}; |
|
535 | 486 |
} |
536 | 487 |
|
537 |
$myconfig->save_member();
|
|
488 |
$myconfig->save_member; |
|
538 | 489 |
|
539 |
$form->{templates} =~ s|.*/||;
|
|
540 |
$form->{templates} = $::lx_office_conf{paths}->{templates} . "/$form->{templates}";
|
|
541 |
$form->{mastertemplates} =~ s|.*/||; |
|
490 |
$user->{templates} =~ s|.*/||;
|
|
491 |
$user->{templates} = $::lx_office_conf{paths}->{templates} . "/$user->{templates}";
|
|
492 |
$::form->{mastertemplates} =~ s|.*/||;
|
|
542 | 493 |
|
543 | 494 |
# create user template directory and copy master files |
544 |
if (!-d "$form->{templates}") {
|
|
495 |
if (!-d "$user->{templates}") {
|
|
545 | 496 |
umask(002); |
546 | 497 |
|
547 |
if (mkdir "$form->{templates}", oct("771")) {
|
|
498 |
if (mkdir "$user->{templates}", oct("771")) {
|
|
548 | 499 |
|
549 | 500 |
umask(007); |
550 | 501 |
|
551 | 502 |
# copy templates to the directory |
552 | 503 |
|
553 | 504 |
my $oldcurrdir = getcwd(); |
554 |
if (!chdir("$::lx_office_conf{paths}->{templates}/print/$form->{mastertemplates}")) { |
|
555 |
$form->error("$ERRNO: chdir $::lx_office_conf{paths}->{templates}/print/$form->{mastertemplates}"); |
|
505 |
if (!chdir("$::lx_office_conf{paths}->{templates}/print/$::form->{mastertemplates}")) {
|
|
506 |
$form->error("$ERRNO: chdir $::lx_office_conf{paths}->{templates}/print/$::form->{mastertemplates}");
|
|
556 | 507 |
} |
557 | 508 |
|
558 |
my $newdir = File::Spec->catdir($oldcurrdir, $form->{templates});
|
|
509 |
my $newdir = File::Spec->catdir($oldcurrdir, $user->{templates});
|
|
559 | 510 |
|
560 | 511 |
find( |
561 | 512 |
sub |
... | ... | |
584 | 535 |
chdir($oldcurrdir); |
585 | 536 |
|
586 | 537 |
} else { |
587 |
$form->error("$ERRNO: $form->{templates}");
|
|
538 |
$form->error("$ERRNO: $user->{templates}");
|
|
588 | 539 |
} |
589 | 540 |
} |
590 | 541 |
|
591 | 542 |
# Add new user to his groups. |
592 | 543 |
if (ref $form->{new_user_group_ids} eq 'ARRAY') { |
593 | 544 |
my $all_groups = $main::auth->read_groups(); |
594 |
my %user = $main::auth->read_user($form->{login});
|
|
545 |
my %user = $main::auth->read_user(login => $user->{login});
|
|
595 | 546 |
|
596 | 547 |
foreach my $group_id (@{ $form->{new_user_group_ids} }) { |
597 | 548 |
my $group = $all_groups->{$group_id}; |
... | ... | |
604 | 555 |
} |
605 | 556 |
|
606 | 557 |
if ($main::auth->can_change_password() |
607 |
&& defined $form->{new_password} |
|
608 |
&& ($form->{new_password} ne '********')) { |
|
558 |
&& defined $::form->{new_password}
|
|
559 |
&& ($::form->{new_password} ne '********')) {
|
|
609 | 560 |
my $verifier = SL::Auth::PasswordPolicy->new; |
610 |
my $result = $verifier->verify($form->{new_password}, 1); |
|
561 |
my $result = $verifier->verify($::form->{new_password}, 1);
|
|
611 | 562 |
|
612 | 563 |
if ($result != SL::Auth::PasswordPolicy->OK()) { |
613 | 564 |
$form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result))); |
614 | 565 |
} |
615 | 566 |
|
616 |
$main::auth->change_password($form->{login}, $form->{new_password});
|
|
567 |
$main::auth->change_password($user->{login}, $::form->{new_password});
|
|
617 | 568 |
} |
618 | 569 |
|
619 |
$form->redirect($locale->text('User saved!'));
|
|
570 |
$::form->redirect($::locale->text('User saved!'));
|
|
620 | 571 |
} |
621 | 572 |
|
622 | 573 |
sub save_user_as_new { |
623 | 574 |
my $form = $main::form; |
624 | 575 |
|
625 |
$form->{login} = $form->{new_user_login}; |
|
626 |
delete @{$form}{qw(edit new_user_login)}; |
|
576 |
$form->{user}{login} = $::form->{new_user_login}; |
|
577 |
delete $form->{user}{id}; |
|
578 |
delete @{$form}{qw(id edit new_user_login)}; |
|
627 | 579 |
|
628 | 580 |
save_user(); |
629 | 581 |
} |
... | ... | |
632 | 584 |
my $form = $main::form; |
633 | 585 |
my $locale = $main::locale; |
634 | 586 |
|
587 |
my $user = $::form->{user} || {}; |
|
588 |
|
|
589 |
$::form->show_generic_error($::locale->text('Missing user id!')) unless $user->{id}; |
|
590 |
|
|
591 |
my $loaded_user = User->new(id => $user->{id}); |
|
592 |
|
|
635 | 593 |
my %members = $main::auth->read_all_users(); |
636 |
my $templates = $members{$form->{login}}->{templates};
|
|
594 |
my $templates = $members{$loaded_user->{login}}->{templates};
|
|
637 | 595 |
|
638 |
$main::auth->delete_user($form->{login});
|
|
596 |
$main::auth->delete_user($loaded_user->{login});
|
|
639 | 597 |
|
640 | 598 |
if ($templates) { |
641 | 599 |
my $templates_in_use = 0; |
642 | 600 |
|
643 | 601 |
foreach my $login (keys %members) { |
644 |
next if $form->{login} eq $login;
|
|
602 |
next if $loaded_user->{login} eq $login;
|
|
645 | 603 |
next if $members{$login}->{templates} ne $templates; |
646 | 604 |
$templates_in_use = 1; |
647 | 605 |
last; |
... | ... | |
1233 | 1191 |
return $::lx_office_conf{paths}->{userspath} . '/nologin'; |
1234 | 1192 |
} |
1235 | 1193 |
|
1194 |
sub _search_templates { |
|
1195 |
# is there a templates basedir |
|
1196 |
if (!-d $::lx_office_conf{paths}->{templates}) { |
|
1197 |
$::form->error(sprintf($::locale->text("The directory %s does not exist."), $::lx_office_conf{paths}->{templates})); |
|
1198 |
} |
|
1199 |
|
|
1200 |
opendir TEMPLATEDIR, $::lx_office_conf{paths}->{templates} or $::form->error($::lx_office_conf{paths}->{templates} . " : $ERRNO"); |
|
1201 |
my @all = readdir(TEMPLATEDIR); |
|
1202 |
my @alldir = sort grep { -d ($::lx_office_conf{paths}->{templates} . "/$_") && !/^\.\.?$/ } @all; |
|
1203 |
closedir TEMPLATEDIR; |
|
1204 |
|
|
1205 |
@alldir = grep !/\.(html|tex|sty|odt|xml|txb)$/, @alldir; |
|
1206 |
@alldir = grep !/^(webpages|print|\.svn)$/, @alldir; |
|
1207 |
|
|
1208 |
# mastertemplates |
|
1209 |
opendir TEMPLATEDIR, "$::lx_office_conf{paths}->{templates}/print" or $::form->error("$::lx_office_conf{paths}->{templates}/print" . " : $ERRNO"); |
|
1210 |
my @allmaster = readdir(TEMPLATEDIR); |
|
1211 |
closedir TEMPLATEDIR; |
|
1212 |
|
|
1213 |
@allmaster = sort grep { -d ("$::lx_office_conf{paths}->{templates}/print" . "/$_") && !/^\.\.?$/ } @allmaster; |
|
1214 |
@allmaster = reverse grep !/Default/, @allmaster; |
|
1215 |
push @allmaster, 'Default'; |
|
1216 |
@allmaster = reverse @allmaster; |
|
1217 |
|
|
1218 |
return \@alldir, \@allmaster; |
|
1219 |
} |
|
1220 |
|
|
1236 | 1221 |
1; |
Auch abrufbar als: Unified diff
Usermaske im Adminbereich vor logins aus sessions geschützt.
Notwendigerweise zusätzlich User->new und Auth->read_user auf %params
umgeschrieben.