#!/usr/local/bin/perl
# change.cgi
# Make all the changes, and re-direct to / in case the theme has changed

require './change-user-lib.pl';
&ReadParse();

$| = 1;
$theme_no_table++;
&header($text{'change_title'}, "");
print "<hr>\n";

@users = &acl::list_users();
($user) = grep { $_->{'name'} eq $base_remote_user } @users;

print "$text{'change_user'}<br>\n";
if ($in{'lang_def'}) {
	$user->{'lang'} = undef;
	}
else {
	$user->{'lang'} = $in{'lang'};
	}
if ($in{'theme_def'}) {
	$user->{'theme'} = undef;
	}
else {
	$user->{'theme'} = $in{'theme'};
	}
if (&can_change_pass($user)) {
	if (!$in{'pass_def'}) {
		$in{'pass'} =~ /:/ && &error($text{'change_ecolon'});
		$salt = chr(int(rand(26))+65).chr(int(rand(26))+65);
		$user->{'pass'} = crypt($in{'pass'}, $salt);
		}
	}
&acl::modify_user($user->{'name'}, $user);
print "$text{'change_done'}<p>\n";

print "$text{'change_restart'}<br>\n";
&restart_miniserv();
print "$text{'change_done'}<p>\n";

if (!$in{'theme_def'}) {
	print "$text{'change_redirect'}<br>\n";
	print "<script>\n";
	print "location = '/';\n";
	print "</script>\n";
	print "$text{'change_done'}<p>\n";
	}

print "<hr>\n";
&footer("/", $text{'index'});

