- my $group = {
- 'name' => $locale->text('Full Access'),
- 'description' => $locale->text('Full access to all functions'),
- 'rights' => { map { $_ => 1 } SL::Auth::all_rights() },
- 'members' => [ map { $_->{id} } values %members ],
- };
-
- $auth->save_group($group);
-
- user_migration_complete(1);
-}
-
-sub dont_create_standard_group {
- user_migration_complete(0);
-}
-
-sub user_migration_complete {
- my $standard_group_created = shift;
-
- $form->{title} = $locale->text('User migration complete');
- $form->header();
-
- print $form->parse_html_template('admin/user_migration_complete', { 'standard_group_created' => $standard_group_created });
-}
-
-sub list_users {
- my %members = $auth->read_all_users();
-
- delete $members{"root login"};
-
- map { $_->{templates} =~ s|.*/||; } values %members;
-
- $form->{title} = "Lx-Office ERP " . $locale->text('Administration');
- $form->{LOCKED} = -e "$userspath/nologin";
- $form->{MEMBERS} = [ @members{sort { lc $a cmp lc $b } keys %members} ];
-
- $form->header();
- print $form->parse_html_template("admin/list_users");
-}
-
-sub add_user {
-
- $form->{title} =
- "Lx-Office ERP "
- . $locale->text('Administration') . " / "
- . $locale->text('Add User');
-
- my $myconfig = {
- "vclimit" => 200,
- "countrycode" => "de",
- "numberformat" => "1.000,00",
- "dateformat" => "dd.mm.yy",
- "stylesheet" => "lx-office-erp.css",
- "menustyle" => "v3",
- };
-
- edit_user_form($myconfig);
-}
-
-sub edit_user {
-
- $form->{title} =
- "Lx-Office ERP "
- . $locale->text('Administration') . " / "
- . $locale->text('Edit User');
- $form->{edit} = 1;
-
- $form->isblank("login", $locale->text("The login is missing."));
-
- # get user
- my $myconfig = new User($form->{login});
-
- # strip basedir from templates directory
- $myconfig->{templates} =~ s|.*/||;
-
- edit_user_form($myconfig);
-}
-
-sub edit_user_form {
- my ($myconfig) = @_;
-
- my @valid_dateformats = qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd);
- $form->{ALL_DATEFORMATS} = [ map { { "format" => $_, "selected" => $_ eq $myconfig->{dateformat} } } @valid_dateformats ];
-
- my @valid_numberformats = qw(1,000.00 1000.00 1.000,00 1000,00);
- $form->{ALL_NUMBERFORMATS} = [ map { { "format" => $_, "selected" => $_ eq $myconfig->{numberformat} } } @valid_numberformats ];
-
- %countrycodes = User->country_codes;
- $form->{ALL_COUNTRYCODES} = [];
- foreach $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
- push @{ $form->{ALL_COUNTRYCODES} }, { "value" => $countrycode,
- "name" => $countrycodes{$countrycode},
- "selected" => $countrycode eq $myconfig->{countrycode} };
- }
-
- # is there a templates basedir
- if (!-d "$templates") {
- $form->error(sprintf($locale->text("The directory %s does not exist."), $templates));
- }
-
- opendir TEMPLATEDIR, "$templates/." or $form->error("$templates : $ERRNO");
- my @all = readdir(TEMPLATEDIR);
- my @alldir = sort grep { -d "$templates/$_" && !/^\.\.?$/ } @all;
- my @allhtml = sort grep { -f "$templates/$_" && /\.html$/ } @all;
- closedir TEMPLATEDIR;
-
- @alldir = grep !/\.(html|tex|sty|odt|xml|txb)$/, @alldir;
- @alldir = grep !/^(webpages|\.svn)$/, @alldir;
-
- @allhtml = reverse grep !/Default/, @allhtml;
- push @allhtml, 'Default';
- @allhtml = reverse @allhtml;
-
- $form->{ALL_TEMPLATES} = [ map { { "name", => $_, "selected" => $_ eq $myconfig->{templates} } } @alldir ];
-
- $lastitem = $allhtml[0];
- $lastitem =~ s/-.*//g;
- $form->{ALL_MASTER_TEMPLATES} = [ { "name" => $lastitem, "selected" => $lastitem eq "German" } ];
- foreach $item (@allhtml) {
- $item =~ s/-.*//g;
- next if ($item eq $lastitem);
-
- push @{ $form->{ALL_MASTER_TEMPLATES} }, { "name" => $item, "selected" => $item eq "German" };
- $lastitem = $item;
- }
-
- # css dir has styles that are not intended as general layouts.
- # reverting to hardcoded list
- $form->{ALL_STYLESHEETS} = [ map { { "name" => $_, "selected" => $_ eq $myconfig->{stylesheet} } } qw(lx-office-erp.css Win2000.css) ];
-
- $form->{"menustyle_" . $myconfig->{menustyle} } = 1;
-
- map { $form->{"myc_${_}"} = $myconfig->{$_} } keys %{ $myconfig };
-
- my $groups = [];
-
- if ($form->{edit}) {
- my $user_id = $auth->get_user_id($form->{login});
- my $all_groups = $auth->read_groups();
-
- foreach my $group (values %{ $all_groups }) {
- push @{ $groups }, $group if (grep { $user_id == $_ } @{ $group->{members} });
- }
-
- $groups = [ sort { lc $a->{name} cmp lc $b->{name} } @{ $groups } ];
- }
-
- $form->{CAN_CHANGE_PASSWORD} = $auth->can_change_password();
-
- $form->header();
- print $form->parse_html_template("admin/edit_user", { 'GROUPS' => $groups });
-}
-
-sub save_user {
- $form->{dbdriver} = 'Pg';
-
- # no spaces allowed in login name
- $form->{login} =~ s|\s||g;
- $form->isblank("login", $locale->text('Login name missing!'));
-
- # check for duplicates
- if (!$form->{edit}) {
- my %members = $auth->read_all_users();
- if ($members{$form->{login}}) {
- $form->show_generic_error($locale->text('Another user with the login #1 does already exist.', $form->{login}), 'back_button' => 1);
- }
- }
-
- # no spaces allowed in directories
- ($form->{newtemplates}) = split / /, $form->{newtemplates};
-
- if ($form->{newtemplates}) {
- $form->{templates} = $form->{newtemplates};
- } else {
- $form->{templates} =
- ($form->{usetemplates}) ? $form->{usetemplates} : $form->{login};
- }
-
- # is there a basedir
- if (!-d "$templates") {
- $form->error(sprintf($locale->text("The directory %s does not exist."), $templates));
- }
-
- # add base directory to $form->{templates}
- $form->{templates} =~ s|.*/||;
- $form->{templates} = "$templates/$form->{templates}";
-
- $myconfig = new User($form->{login});
-
- $form->isblank("dbname", $locale->text('Dataset missing!'));
- $form->isblank("dbuser", $locale->text('Database User missing!'));
-
- foreach $item (keys %{$form}) {
- $myconfig->{$item} = $form->{$item};
- }
-
- delete $myconfig->{stylesheet};
- if ($form->{userstylesheet}) {
- $myconfig->{stylesheet} = $form->{userstylesheet};
- }
-
- $myconfig->save_member();
-
- if ($auth->can_change_password()
- && defined $form->{new_password}
- && ($form->{new_password} ne '********')) {
- $auth->change_password($form->{login}, $form->{new_password});
- }
-
- if ($webdav) {
- @webdavdirs =
- qw(angebote bestellungen rechnungen anfragen lieferantenbestellungen einkaufsrechnungen);
- foreach $directory (@webdavdirs) {
- $file = "webdav/" . $directory . "/webdav-user";
- if ($form->{$directory}) {
- if (open(HTACCESS, "$file")) {
- while (<HTACCESS>) {
- ($login, $password) = split(/:/, $_);
- if ($login ne $form->{login}) {
- $newfile .= $_;
- }
- }
- close(HTACCESS);
- }
- open(HTACCESS, "> $file") or die "cannot open $file $ERRNO\n";
- $newfile .= $myconfig->{login} . ":" . $myconfig->{password} . "\n";
- print(HTACCESS $newfile);
- close(HTACCESS);
- } else {
- $form->{$directory} = 0;
- if (open(HTACCESS, "$file")) {
- while (<HTACCESS>) {
- ($login, $password) = split(/:/, $_);
- if ($login ne $form->{login}) {
- $newfile .= $_;
- }
- }
- close(HTACCESS);
- }
- open(HTACCESS, "> $file") or die "cannot open $file $ERRNO\n";
- print(HTACCESS $newfile);
- close(HTACCESS);
- }
- }
- }
-
- $form->{templates} =~ s|.*/||;
- $form->{templates} = "${templates}/$form->{templates}";
- $form->{mastertemplates} =~ s|.*/||;
-
- # create user template directory and copy master files
- if (!-d "$form->{templates}") {
- umask(002);
-
- if (mkdir "$form->{templates}", oct("771")) {
-
- umask(007);
-
- # copy templates to the directory
- opendir TEMPLATEDIR, "$templates/." or $form - error("$templates : $ERRNO");
- @templates = grep /$form->{mastertemplates}.*?\.(html|tex|sty|odt|xml|txb)$/,
- readdir TEMPLATEDIR;
- closedir TEMPLATEDIR;
-
- foreach $file (@templates) {
- open(TEMP, "$templates/$file")
- or $form->error("$templates/$file : $ERRNO");
-
- $file =~ s/\Q$form->{mastertemplates}\E-//;
- open(NEW, ">$form->{templates}/$file")
- or $form->error("$form->{templates}/$file : $ERRNO");
-
- while ($line = <TEMP>) {
- print NEW $line;
- }
- close(TEMP);
- close(NEW);
- }