<?php
if (!defined("ADMIN_FILE") || !is_admin_god($aid)) die("Illegal File Access");

include("config/config_fields.php");

function UserNavi() {
	global $admin_file, $chng_user, $search;
	GraphicAdmin();
	OpenTable();
	echo "<center><font class=\"title\"><b>"._USERADMIN."</b></font><br /><br />"
	."<font class=\"content\">[ <a href=\"".$admin_file.".php?op=ShowUser\">"._HOME."</a>"
	." | <a href=\"".$admin_file.".php?op=NewUser\">"._ADD."</a>"
	." | <a href=\"".$admin_file.".php?op=UserConf\">"._PREFERENCES."</a> ]</center>";
	CloseTable();
	OpenTable();
    echo "<center><font class=\"option\"><b>"._SEARCH."</b></font><br>"
	."<form method=\"post\" action=\"".$admin_file.".php\"><input type=\"hidden\" name=\"op\" value=\"ModiUser\">"
	."<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\" align=\"center\">"
	."<tr><td><select name=\"search\">"
	."<option value='1'";
    if ($search == "1") echo " selected";
	echo ">"._ID."</option>"
	."<option value='2'";
    if ($search == "2") echo " selected";
	echo ">"._NICKNAME."</option>"
	."<option value='3'";
    if ($search == "3") echo " selected";
	echo ">"._EMAIL."</option>"
	."<option value='4'";
    if ($search == "4") echo " selected";
	echo ">"._IP."</option>"
	."<option value='5'";
    if ($search == "5") echo " selected";
	echo ">"._URL."</option>"
	."</select></td>"
	."<td><input name=\"chng_user\" type=\"text\" size=\"30\" value=\"$chng_user\"></td>"
	."<td><input type=\"submit\" value=\""._SEARCH."\"></td></tr></form></table>";
    CloseTable();
}

function ShowUser() {
	global $prefix, $db, $pagenum, $admin_file;
	head();
	UserNavi();
	OpenTable();
	if ($pagenum == "") $pagenum = 1;
	$storynum = 100;
	$offset = ($pagenum-1) * $storynum;
	$result = $db->sql_query("SELECT user_id, user_name, user_email, user_regdate, user_lastvisit, user_points FROM ".$prefix."_users ORDER BY user_id DESC LIMIT ".$offset.", ".$storynum."");
	echo "<center><font class=\"option\"><b>"._EDITUSER."</b></font><br /><br />"
	."<script language=\"JavaScript\" type=\"text/javascript\" src=\"javascripts/SortTable.js\"></script>"
	."<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" class=\"sort\" id=\"sort_id\"><tr>"
	."<th>"._ID."</th><th>"._NICKNAME."</th><th>"._EMAIL."</th><th>"._REG_DATE."</th>"
	."<th>"._LAST_VISIT."</th><th>"._POINTS."</th><th>"._FUNCTIONS."</th>"
	. "</tr>";
	while (list($user_id, $user_name, $user_email, $user_regdate, $user_lastvisit, $user_points) = $db->sql_fetchrow($result)) {
		echo "<tr class=\"bgcolor1\">"
		."<td align=\"center\">".$user_id."</td>"
		."<td>".$user_name."</td>"
		."<td>".$user_email."</td>";
		preg_match("/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/", $user_regdate, $datetime);
		$user_regdate = "".$datetime[3].".".$datetime[2].".".$datetime[1]."";	
		$user_lastvisit = (!$user_lastvisit) ? "0" : gmdate('d.m.Y', $user_lastvisit);
		echo "<td align=\"center\">".$user_regdate."</td>"
		."<td align=\"center\">".$user_lastvisit."</td>"
		."<td align=\"center\">".$user_points."</td>"
		."<td align=\"center\"><a href=\"".$admin_file.".php?op=ModiUser&chng_user=".$user_name."\" title=\""._EDIT."\"><img src=\"images/edit.gif\" border=\"0\" alt=\""._EDIT."\"></a> <a href=\"".$admin_file.".php?op=DelUser&user_id=".$user_id."&chng_user=".$user_name."\" title=\""._DELETE."\"><img src=images/delete.gif border=\"0\" alt=\""._DELETE."\"></a></td></tr>";
	}
	echo "</table>";
	CloseTable();
	list($numstories) = $db->sql_fetchrow($db->sql_query("SELECT Count(user_id) FROM ".$prefix."_users"));
	$numpages = ceil($numstories / $storynum);
	num_page("", $numstories, $numpages, $storynum, "op=ShowUser&");
	foot();
}

function NewUser() {
    global $admin_file, $conffi;
    head();
	UserNavi();
    OpenTable();
    echo "<center><font class=\"option\"><b>"._ADDUSER."</b></font><br><br>"
	."<form name=\"post\" action=\"".$admin_file.".php\" method=\"post\">"
	."<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\">"
	."<tr><td width=\"100\">"._NICKNAME.":</td><td><input type=\"text\" name=\"add_uname\" maxlength=\"25\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>"._EMAIL.":</td><td><input type=\"text\" name=\"add_email\" maxlength=\"60\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>"._SITEURL.":</td><td><input type=\"text\" name=\"add_url\" maxlength=\"60\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>"._ICQ.":</td><td><input type=\"text\" name=\"add_user_icq\" maxlength=\"20\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>"._AIM.":</td><td><input type=\"text\" name=\"add_user_aim\" maxlength=\"20\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>"._YIM.":</td><td><input type=\"text\" name=\"add_user_yim\" maxlength=\"20\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>"._MSNM.":</td><td><input type=\"text\" name=\"add_user_msnm\" maxlength=\"20\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>"._LOCATION.":</td><td><input type=\"text\" name=\"add_user_from\" maxlength=\"60\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>"._OCCUPATION.":</td><td><input type=\"text\" name=\"add_user_occ\" maxlength=\"60\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>"._INTERESTS.":</td><td><input type=\"text\" name=\"add_user_intrest\" maxlength=\"255\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<tr><td>"._ALLOWUSERS.":</td><td><input type=\"checkbox\" name=\"add_user_viewemail\" value=\"1\"></td></tr>"
	."<tr><td>"._NEWSLETTER.":</td><td><input type=\"radio\" name=\"add_newsletter\" value=\"1\">"._YES." &nbsp;&nbsp; <input type=\"radio\" name=\"add_newsletter\" value=\"0\" checked>"._NO."</td></tr>"
	."<tr><td>"._SIGNATURE.":</td><td><textarea id=\"area\" name=\"add_user_sig\" cols=\"65\" rows=\"5\" style=\"width:400px\" OnKeyPress=\"TransliteFeld(this, event)\" OnSelect=\"FieldName(this, this.name)\" OnClick=\"FieldName(this, this.name)\" OnKeyUp=\"FieldName(this, this.name)\"></textarea>".get_code("area")."</td></tr>";
	if ($conffi['account']) echo "".fields_in("", $conffi['account'])."";
	echo "<tr><td>"._PASSWORD.":</td><td><input type=\"password\" name=\"add_pass\" maxlength=\"12\" size=\"65\" style=\"width:400px\"></td></tr>"
	."<input type=\"hidden\" name=\"add_avatar\" value=\"00.gif\">"
	."<input type=\"hidden\" name=\"op\" value=\"AddUser\">"
	."<tr><td colspan=\"2\" align=\"center\"><br><input type=\"submit\" value=\""._ADD."\"></td></tr></table></form>";
    CloseTable();
    foot();
}

function ModiUser($chng_user) {
    global $prefix, $db, $admin_file, $conffi;
    head();
	UserNavi();
	if ($_POST['search'] == 1 && $chng_user) {
		$sqlstring = "WHERE user_id='$chng_user'";
	} elseif ($_POST['search'] == 3 && $chng_user) {
		$sqlstring = "WHERE user_email='$chng_user'";
	} elseif ($_POST['search'] == 4 && $chng_user) {
		$sqlstring = "WHERE user_last_ip='$chng_user'";
	} elseif ($_POST['search'] == 5 && $chng_user) {
		$sqlstring = "WHERE user_website='$chng_user'";
	} else {
		$sqlstring = "WHERE user_name='$chng_user'";
	}
	$result = $db->sql_query("SELECT user_id, user_name, user_website, user_email, user_icq, user_aim, user_yim, user_msnm, user_from, user_occ, user_interests, user_viewemail, user_avatar, user_sig, user_password, user_newsletter, user_lastvisit, user_points, user_last_ip, user_warnings, user_group, user_field FROM ".$prefix."_users ".$sqlstring."");
	$numrows = $db->sql_numrows($result);
    if ($numrows > 0) {
        list($chng_user_id, $chng_uname, $chng_url, $chng_email, $chng_user_icq, $chng_user_aim, $chng_user_yim, $chng_user_msnm, $chng_user_from, $chng_user_occ, $chng_user_intrest, $chng_user_viewemail, $chng_avatar, $chng_user_sig, $chng_pass, $chng_newsletter, $chng_lastvisit, $chng_points, $chng_user_ip, $chng_user_warnings, $chng_user_group, $chng_user_field) = $db->sql_fetchrow($result);
	$result_info = $db->sql_query("SELECT firstname,lastname,gender,birthday,postindex,region,street,house,flat,city,country FROM ".$prefix."_users_info WHERE user_name='$chng_uname'");
        list($firstname,$lastname,$gender,$birthday,$postindex,$region,$street,$house,$flat,$city,$country)=$db->sql_fetchrow($result_info);
        OpenTable();
        echo "<center><font class=\"option\"><b>"._MODIFY.": $chng_uname</b></font></center>"
		."<form name=\"post\" action=\"".$admin_file.".php\" method=\"post\">"
		."<table border=\"0\" align=\"center\">"
		."<tr><td>"._ID.":</td><td>$chng_user_id</td></tr>"
		."<tr><td>"._IP.":</td><td>$chng_user_ip</td></tr>"
		."<tr><td>"._LAST_VISIT.":</td><td>".gmdate('d.m.Y', $chng_lastvisit)."</td></tr>"
		."<tr><td>"._WARNINGS.":</td><td><input type=\"text\" name=\"chng_user_warnings\" value=\"$chng_user_warnings\" maxlength=\"25\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._SPEŃ_GROUP.":</td><td><select name='chng_user_group' style='width:400px'>"
		."<option value='0'>"._NO."</option>";
		$result = $db->sql_query("SELECT id, name FROM ".$prefix."_groups WHERE extra='1'");
		while(list($grid, $grname) = $db->sql_fetchrow($result)) {
			echo "<option value='$grid'";
			if ($grid == $chng_user_group) echo " selected";
			echo ">$grname</option>";
		}
		if($gender==1)
		 $gender=_MAN;
		else
		 $gender=_WOMEN;
		$birthday=explode('-',$birthday);
                $birthday=$birthday[2].".".$birthday[1].".".$birthday[0];
		echo "</select></td></tr>"
		."<tr><td>"._POINTS.":</td><td><input type=\"text\" name=\"chng_points\" value=\"$chng_points\" maxlength=\"25\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._NICKNAME.":</td><td><input type=\"text\" name=\"chng_uname\" value=\"$chng_uname\" maxlength=\"25\" size=\"65\" style=\"width:400px\"></td></tr>"


		."<tr><td>"._FIRSTNAME.":</td><td>$firstname</td></tr>"
		."<tr><td>"._LASTNAME.":</td><td>$lastname</td></tr>"
		."<tr><td>"._GENDER.":</td><td>$gender</td></tr>"

		."<tr><td>"._BIRTHDAY.":</td><td>$birthday</td></tr>"
		."<tr><td>"._INDEX.":</td><td>$postindex</td></tr>"
		."<tr><td>"._REGION.":</td><td>$region</td></tr>"
		."<tr><td>"._STREET.":</td><td>$street</td></tr>"
		."<tr><td>"._HOUSE.":</td><td>$house</td></tr>"
		."<tr><td>"._FLAT.":</td><td>$flat</td></tr>"
		."<tr><td>"._CITY.":</td><td>$city</td></tr>"
		."<tr><td>"._COUNTRY.":</td><td>$country</td></tr>"




		."<tr><td>"._SITEURL.":</td><td><input type=\"text\" name=\"chng_url\" value=\"$chng_url\" maxlength=\"60\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._EMAIL.":</td><td><input type=\"text\" name=\"chng_email\" value=\"$chng_email\" maxlength=\"60\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._ICQ.":</td><td><input type=\"text\" name=\"chng_user_icq\" value=\"$chng_user_icq\" maxlength=\"20\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._AIM.":</td><td><input type=\"text\" name=\"chng_user_aim\" value=\"$chng_user_aim\" maxlength=\"20\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._YIM.":</td><td><input type=\"text\" name=\"chng_user_yim\" value=\"$chng_user_yim\" maxlength=\"20\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._MSNM.":</td><td><input type=\"text\" name=\"chng_user_msnm\" value=\"$chng_user_msnm\" maxlength=\"20\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._LOCATION.":</td><td><input type=\"text\" name=\"chng_user_from\" value=\"$chng_user_from\" maxlength=\"60\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._OCCUPATION.":</td><td><input type=\"text\" name=\"chng_user_occ\" value=\"$chng_user_occ\" maxlength=\"60\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._INTERESTS.":</td><td><input type=\"text\" name=\"chng_user_intrest\" value=\"$chng_user_intrest\" maxlength=\"255\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._ALLOWUSERS.":</td>";
        if ($chng_user_viewemail == 1) {
            echo "<td><input type=\"checkbox\" name=\"chng_user_viewemail\" value=\"1\" checked></td></tr>";
        } else {
            echo "<td><input type=\"checkbox\" name=\"chng_user_viewemail\" value=\"1\"></td></tr>";
        }
        if ($chng_newsletter == 1) {
            echo "<tr><td>"._NEWSLETTER.":</td><td><input type=\"radio\" name=\"chng_newsletter\" value=\"1\" checked>"._YES." &nbsp;&nbsp; <input type=\"radio\" name=\"chng_newsletter\" value=\"0\">"._NO."</td></tr>";
        } elseif ($chng_newsletter == 0) {
            echo "<tr><td>"._NEWSLETTER.":</td><td><input type=\"radio\" name=\"chng_newsletter\" value=\"1\">"._YES." &nbsp;&nbsp; <input type=\"radio\" name=\"chng_newsletter\" value=\"0\" checked>"._NO."</td></tr>";
        }
		echo "<tr><td>"._SIGNATURE.":</td><td><textarea id=\"area\" name=\"chng_user_sig\" cols=\"65\" rows=\"5\" style=\"width:400px\" OnKeyPress=\"TransliteFeld(this, event)\" OnSelect=\"FieldName(this, this.name)\" OnClick=\"FieldName(this, this.name)\" OnKeyUp=\"FieldName(this, this.name)\">".replace_break($chng_user_sig)."</textarea>".get_code("area")."</td></tr>";
		if ($conffi['account']) echo "".fields_in($chng_user_field, $conffi['account'])."";
		echo "<tr><td>"._PASSWORD.":</td><td><input type=\"password\" name=\"chng_pass\" maxlength=\"12\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<tr><td>"._RETYPEPASSWORD.":</td><td><input type=\"password\" name=\"chng_pass2\" maxlength=\"12\" size=\"65\" style=\"width:400px\"></td></tr>"
		."<input type=\"hidden\" name=\"chng_avatar\" value=\"$chng_avatar\">"
		."<input type=\"hidden\" name=\"chng_user_id\" value=\"$chng_user_id\">"
		."<input type=\"hidden\" name=\"op\" value=\"UpUser\">"
		."<tr><td colspan=\"2\" align=\"center\"><table border=\"0\" align=\"center\"><tr><td><input type=\"submit\" value=\""._SAVECHANGES."\"></td></form><form action=\"".$admin_file.".php\" method=\"post\"><input type=\"hidden\" name=\"op\" value=\"DelUser\"><input type=\"hidden\" name=\"user_id\" value=\"$chng_user_id\"><input type=\"hidden\" name=\"chng_user\" value=\"$chng_uname\"><td><input type=\"submit\" value=\""._DELETE."\"></td></tr></form></table></td></tr></table>";
        CloseTable();
    } else {
        OpenTable();
        echo "<center><font class=\"option\">"._USERNOEXIST."</font></center>";
        CloseTable();
    }
    foot();
}

function UpUser($chng_user_id, $chng_uname, $chng_url, $chng_email, $chng_user_icq, $chng_user_aim, $chng_user_yim, $chng_user_msnm, $chng_user_from, $chng_user_occ, $chng_user_intrest, $chng_user_viewemail, $chng_avatar, $chng_user_sig, $chng_pass, $chng_pass2, $chng_newsletter, $chng_points, $chng_user_warnings, $chng_user_group) {
    global $db, $prefix, $admin_file;
	$field = fields_save($_POST['field']);
	$tmp = 0;
    if ($chng_pass2 != "") {
		if ($chng_pass != $chng_pass2) {
			head();
			UserNavi();
            OpenTable();
            echo "<center>"._PASSWDNOMATCH."<br><br>"._GOBACK."</center>";
            CloseTable();
            foot();
            exit;
        }
        $tmp = 1;
    }
    if ($tmp == 0) {
        $db->sql_query("UPDATE ".$prefix."_users SET user_name='$chng_uname', user_email='$chng_email', user_website='$chng_url', user_icq='$chng_user_icq', user_aim='$chng_user_aim', user_yim='$chng_user_yim', user_msnm='$chng_user_msnm', user_from='$chng_user_from', user_occ='$chng_user_occ', user_interests='$chng_user_intrest', user_viewemail='$chng_user_viewemail', user_avatar='$chng_avatar', user_sig='$chng_user_sig', user_newsletter='$chng_newsletter', user_points='$chng_points', user_warnings='$chng_user_warnings', user_group='$chng_user_group', user_field='$field' WHERE user_id='$chng_user_id'");
    }
    if ($tmp == 1) {
		$cpass = md5($chng_pass);
        $db->sql_query("UPDATE ".$prefix."_users SET user_name='$chng_uname', user_email='$chng_email', user_website='$chng_url', user_icq='$chng_user_icq', user_aim='$chng_user_aim', user_yim='$chng_user_yim', user_msnm='$chng_user_msnm', user_from='$chng_user_from', user_occ='$chng_user_occ', user_interests='$chng_user_intrest', user_viewemail='$chng_user_viewemail', user_avatar='$chng_avatar', user_sig='$chng_user_sig', user_password='$cpass', user_newsletter='$chng_newsletter', user_points='$chng_points', user_warnings='$chng_user_warnings', user_group='$chng_user_group', user_field='$field' WHERE user_id='$chng_user_id'");
    }
	Header("Location: ".$admin_file.".php?op=ShowUser");
}

function UserConf() {
	global $admin_file;
	head();
	UserNavi();
	include("config/config_users.php");
	$permtest = end_chmod("config/config_users.php", 666);
	if ($permtest) warning($permtest, "", "", 1);
	OpenTable();
	echo "<center><font class='option'>"._GENSITEINFO."</font></center><br>"
    ."<form action='".$admin_file.".php' method='post'>"
	."<table border='0' align='center' cellpadding='3' cellspacing='0'>"
	."<tr><td>"._ANONYMOUSNAME.":</td><td><input type='text' name='xanonymous' value='$anonymous' size='65' style='width:400px'></td></tr>"
	."<tr><td>"._ADIR.":</td><td><input type='text' name='xadirectory' value='$adirectory' size='65' style='width:400px'></td></tr>"
	."<tr><td>"._ATYPE.":</td><td><input type='text' name='xatypefile' value='$atypefile' size='65' style='width:400px'></td></tr>"
	."<tr><td>"._ASIZE.":</td><td><input type='text' name='xamaxsize' value='$amaxsize' size='65' style='width:400px'></td></tr>"
	."<tr><td>"._AWIDTH.":</td><td><input type='text' name='xawidth' value='$awidth' size='65' style='width:400px'></td></tr>"
	."<tr><td>"._AHEIGHT.":</td><td><input type='text' name='xaheight' value='$aheight' size='65' style='width:400px'></td></tr>"
	."<tr><td>"._PASSWDLEN.":</td><td>"
	."<select name='xminpass' style='width:400px'>"
	."<option value='3'";
	if ($minpass == "3") echo " selected";
	echo ">3</option>"
	."<option value='5'";
    if ($minpass == "5") echo " selected";
	echo ">5</option>"
	."<option value='8'";
    if ($minpass == "8") echo " selected";
	echo ">8</option>"
	."<option value='10'";
    if ($minpass == "10") echo " selected";
	echo ">10</option>"
	."</select></td></tr>"
	."<tr><td>"._AUPLOAD."</td><td>";
	if ($aupload == 1) {
		echo "<input type='radio' name='xaupload' value='1' checked>"._YES." &nbsp;<input type='radio' name='xaupload' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xaupload' value='1'>"._YES." &nbsp;<input type='radio' name='xaupload' value='0' checked>"._NO."";
    }
	echo "<tr><td>"._NO_MAIL_REG."</td><td>";
	if ($no_mail_reg == 1) {
		echo "<input type='radio' name='xno_mail_reg' value='1' checked>"._YES." &nbsp;<input type='radio' name='xno_mail_reg' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xno_mail_reg' value='1'>"._YES." &nbsp;<input type='radio' name='xno_mail_reg' value='0' checked>"._NO."";
    }
	echo "</td></tr><tr><td>"._BROADCASTMSG."</td><td>";
    if ($broadcast_msg == 1) {
        echo "<input type='radio' name='xbroadcast_msg' value='1' checked>"._YES." &nbsp;<input type='radio' name='xbroadcast_msg' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xbroadcast_msg' value='1'>"._YES." &nbsp;<input type='radio' name='xbroadcast_msg' value='0' checked>"._NO."";
    }
    echo "</td></tr><tr><td>"._MYHEADLINES."</td><td>";
    if ($my_headlines == 1) {
        echo "<input type='radio' name='xmy_headlines' value='1' checked>"._YES." &nbsp;<input type='radio' name='xmy_headlines' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xmy_headlines' value='1'>"._YES." &nbsp;<input type='radio' name='xmy_headlines' value='0' checked>"._NO."";
    }
    echo "</td></tr><tr><td>"._USERSHOMENUM."</td><td>";
    if ($user_news == 1) {
        echo "<input type='radio' name='xuser_news' value='1' checked>"._YES." &nbsp;<input type='radio' name='xuser_news' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xuser_news' value='1'>"._YES." &nbsp;<input type='radio' name='xuser_news' value='0' checked>"._NO."";
    }
	echo "</td></tr><tr><td>"._USERIPCHECK."</td><td>";
    if ($ip_check == 1) {
        echo "<input type='radio' name='xip_check' value='1' checked>"._YES." &nbsp;<input type='radio' name='xip_check' value='0'>"._NO."";
    } else {
        echo "<input type='radio' name='xip_check' value='1'>"._YES." &nbsp;<input type='radio' name='xip_check' value='0' checked>"._NO."";
    }
	echo "<tr><td>"._NAME_BLOCK.":</td><td><textarea name=\"xname_blocker\" cols=\"65\" rows=\"5\" style=\"width:400px\">".$name_blocker."</textarea></td></tr>"
	."<tr><td>"._MAIL_BLOCK.":</td><td><textarea name=\"xmail_blocker\" cols=\"65\" rows=\"5\" style=\"width:400px\">".$mail_blocker."</textarea></td></tr></table>";
	echo "<center><br><input type='hidden' name='op' value='UserSave'><input type='submit' value='" . _SAVECHANGES . "'></center></form>";
	CloseTable();
	foot();
}

function UserSave($xanonymous, $xadirectory, $xatypefile, $xamaxsize, $xawidth, $xaheight, $xminpass, $xaupload, $xno_mail_reg, $xbroadcast_msg, $xmy_headlines, $xuser_news, $xip_check, $xname_blocker, $xmail_blocker) {
	global $admin_file;
	include("config/config_users.php");
	$protect = array("\n" => "", "\t" => "", "\r" => "", " " => "");
	$xatypefile = (!$xatypefile) ? "gif,jpg,jpeg,png" : strtolower(strtr($xatypefile, $protect));
	$xamaxsize = (!intval($xamaxsize)) ? 51200 : $xamaxsize;
	$xawidth = (!intval($xawidth)) ? 100 : $xawidth;
	$xaheight = (!intval($xaheight)) ? 100 : $xaheight;
	$xname_blocker = strtolower(strtr($xname_blocker, $protect));
	$xmail_blocker = strtolower(strtr($xmail_blocker, $protect));
	$content = "\$anonymous = \"$xanonymous\";\n";
	$content .= "\$adirectory = \"$xadirectory\";\n";
	$content .= "\$atypefile = \"$xatypefile\";\n";
	$content .= "\$amaxsize = \"$xamaxsize\";\n";
	$content .= "\$awidth = \"$xawidth\";\n";
	$content .= "\$aheight = \"$xaheight\";\n";
	$content .= "\$minpass = \"$xminpass\";\n";
	$content .= "\$aupload = \"$xaupload\";\n";
	$content .= "\$no_mail_reg = \"$xno_mail_reg\";\n";
	$content .= "\$broadcast_msg = \"$xbroadcast_msg\";\n";
	$content .= "\$my_headlines = \"$xmy_headlines\";\n";
	$content .= "\$user_news = \"$xuser_news\";\n";
	$content .= "\$ip_check = \"$xip_check\";\n";
	$content .= "\$name_blocker = \"$xname_blocker\";\n";
	$content .= "\$mail_blocker = \"$xmail_blocker\";\n";
	$content .= "\$power = base64_decode('UG93ZXJlZCBieSA8YSBocmVmPSJodHRwOi8vd3d3LnNsYWVkLm5ldCIgdGFyZ2V0PSJfYmxhbmsiIHRpdGxlPSJTTEFFRCBDTVMiPlNMQUVEIENNUzwvYT4gJmNvcHk7IDIwMDUtMjAwNyBTTEFFRC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4=');\n";
	save_conf("config/config_users.php", $content);
	Header("Location: ".$admin_file.".php?op=UserConf");
}

switch($op) {
	case "ShowUser":
	ShowUser();
    break;

    case "NewUser":
    NewUser();
    break;

    case "ModiUser":
    ModiUser($chng_user);
    break;

    case "UpUser":
    UpUser($chng_user_id, $chng_uname, $chng_url, $chng_email, $chng_user_icq, $chng_user_aim, $chng_user_yim, $chng_user_msnm, $chng_user_from, $chng_user_occ, $chng_user_intrest, $chng_user_viewemail, $chng_avatar, $chng_user_sig, $chng_pass, $chng_pass2, $chng_newsletter, $chng_points, $chng_user_warnings, $chng_user_group);
    break;

    case "DelUser":
    head();
	UserNavi();
    OpenTable();
    echo "<center>"._DELETE." \"$chng_user\"?<br /><br />[ <a href=\"".$admin_file.".php?op=DelUserConf&user_id=$user_id\">"._YES."</a> | <a href=\"".$admin_file.".php?op=ShowUser\">"._NO."</a> ]</center>";
    CloseTable();
    foot();
    break;

    case "DelUserConf":
	$user_id = intval($user_id);
	$db->sql_query("DELETE FROM ".$prefix."_users WHERE user_id='$user_id'");
    Header("Location: ".$admin_file.".php?op=ShowUser");
    break;

    case "AddUser":
    $add_pass = md5($add_pass);
    if (!($add_uname && $add_email && $add_pass)) {
        head();
		UserNavi();
		OpenTable();
        echo "<center>"._NEEDTOCOMPLETE."<br><br>"._GOBACK."";
        CloseTable();
        foot();
		return;
	}
    $numrow = $db->sql_numrows($db->sql_query("SELECT user_id FROM ".$prefix."_users WHERE user_name='$add_uname'"));
    if ($numrow > 0) {
        head();
		UserNavi();
		OpenTable();
        echo "<center>"._USEREXIST."<br><br>"._GOBACK."";
        CloseTable();
        foot();
		return;
    } else {
		$field = fields_save($_POST['field']);
        $sql = "INSERT INTO ".$prefix."_users (user_id,  user_name, user_email, user_website, user_regdate, user_icq, user_aim, user_yim, user_msnm, user_from, user_occ, user_interests, user_viewemail, user_avatar, user_sig, user_password, user_newsletter, user_broadcast, user_field) VALUES (NULL, '$add_uname', '$add_email', '$add_url', now(), '$add_user_icq', '$add_user_aim', '$add_user_yim', '$add_user_msnm', '$add_user_from', '$add_user_occ', '$add_user_intrest', '$add_user_viewemail', '$add_avatar', '$add_user_sig', '$add_pass', '$add_newsletter', '1', '$field')";
        $result = $db->sql_query($sql);
    }
    Header("Location: ".$admin_file.".php?op=ShowUser");
    break;

	case "UserConf":
    UserConf();
    break;

    case "UserSave":
    UserSave($xanonymous, $xadirectory, $xatypefile, $xamaxsize, $xawidth, $xaheight, $xminpass, $xaupload, $xno_mail_reg, $xbroadcast_msg, $xmy_headlines, $xuser_news, $xip_check, $xname_blocker, $xmail_blocker);
    break;
}
?>