<?php
include ("ad_header.php");
$query="select * from users order by first desc";
$res=mysql_query($query);
$total=mysql_num_rows($res);
?>
<HTML><HEAD><TITLE>Общие настройки</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1251">
</HEAD>
<BODY text=#000000 vLink=#00468c aLink=#ff6633 link=#0053a2 bgColor=#ffffff>
<script language="JavaScript">
function sr() {
if (pt.value!="") {
location.href=pt.value;
}
}
</script>
<form action='ad_users.php' method=post>
Поиск пользователя: <input type=text name=slog> по  
<select name=spar>
<option value='logint'>Логину (точное совпадение)
<option value='name'>Логину (все варианты)
<option value='email'>E-Mail
<option value='firstname'>Имени
<option value='lastname'>Фамилии
<option value='country'>Стране
<option value='city'>Городу 
</select>
<input type=submit value='Найти'>
</form>
<table>
<tr><td>Всего пользователей: <?php echo $total; ?> </td>
<td><select name="pt" onChange="sr()" align=right>
<option>Страницы
<?php
$mestopage=10;
if (isset($_GET['niz'])) {
$niz=$_GET['niz'];
}
else {
$niz="";
}
if (isset($_GET['verh'])) {
$verh=$_GET['verh'];
}
else {
$verh="";
}
if ($niz=="" || $verh=="") {
$niz=0;
$verh=$mestopage-1;
}
$pages=ceil ($total/$mestopage);
$pages=$pages-1;
for ($j=0;$j<=$pages;$j++) {
$niz2=$j*$mestopage;
$verh2=$niz2+$mestopage-1;
$pok=$j+1;
echo "<option value=ad_users.php?niz=$niz2&verh=$verh2>$pok";
}
?>
</select></td></tr></table>

<?php
if (isset($_POST['slog']) && $_POST['slog']!="") {
$magic=get_magic_quotes_gpc();
$slog=$_POST['slog'];
$spar=$_POST['spar'];
$slogo=$slog;
if ($magic!=1) {
$slog=mysql_escape_string($slog);
$slog=str_replace ('"',"'",$slog);
$slogo=str_replace ('"',"'",$slogo);
}
else {
$slog=str_replace ('"',"'",$slog);
$slogo=stripslashes($slogo);
$slogo=str_replace ('"',"'",$slogo);
}
if ($spar!="logint") {
$search_query="select * from users where ($spar like ('%$slog%')) order by first desc";
}
else {
$crc_slog=crc32($slog);
$search_query="select * from users where (crcname='$crc_slog') order by first desc";
}
$res_search=mysql_query($search_query);
$num=mysql_num_rows($res_search);
echo "Результаты поиска ($num):";
echo "<table bgcolor=#D3D3D3><tr><th><font size=2>Логин</th><th><font size=2>E-Mail</th>";
echo "<th><font size=2>Имя</th><th><font size=2>Фамилия</th>";
echo "<th><font size=2>Страна</th><th><font size=2>Город</th></tr>";
while ($srow=mysql_fetch_assoc($res_search)) {
$slogin=$srow["name"];
$slogin=stripslashes($slogin);
$semail=$srow ["email"];
$semail=stripslashes($semail);
$sname=$srow ["firstname"];
$sname=stripslashes($sname);
$slastname=$srow ["lastname"];
$slastname=stripslashes($slastname);
$scountry=$srow ["country"];
$scountry=stripslashes($scountry);
$scity=$srow ["city"];
$scity=stripslashes($scity);
$sid=$srow ["first"];
echo "<tr bgcolor=white><td><font size=2>$slogin</td>";
echo "<td><form action='action_users.php' method=post>";
echo "<input type=hidden name='id' value='$sid'><input type=hidden name='slog' value=\"$slogo\"><input type=hidden name='spar' value=\"$spar\"><input type=text name='email' value=\"$semail\" size=9></td>\n";
echo "<td><input type=text name='firstname' value=\"$sname\" size=9></td>\n";
echo "<td><input type=text name='lastname' value=\"$slastname\" size=9></td>\n";
echo "<td><input type=text name='country' value=\"$scountry\" size=9></td>\n";
echo "<td><input type=text name='city' value=\"$scity\" size=9></td></tr>\n";
echo "<tr bgcolor=white><td colspan=6><center><input type=submit name=action value=change><input type=submit name=action value=delete></td></tr>";
echo "</form>";
}
echo "</table><br>";
}
?>
<table bgcolor="#D3D3D3">
<tr><th><font size=2>Логин</th><th><font size=2>E-Mail</th>
<th><font size=2>Имя</th><th><font size=2>Фамилия</th>
<th><font size=2>Страна</th><th><font size=2>Город</th></tr>
<?php
if ($total>0) {
mysql_data_seek($res,$niz);
}
$i=$niz;
while ($i<=$verh) {
$myrow=mysql_fetch_assoc($res);
$login_of_user=$myrow ["name"];
$login_of_user=stripslashes($login_of_user);
$email_of_user=$myrow ["email"];
$email_of_user=stripslashes($email_of_user);
$name_of_user=$myrow ["firstname"];
$name_of_user=stripslashes($name_of_user);
$lastname_of_user=$myrow ["lastname"];
$lastname_of_user=stripslashes($lastname_of_user);
$country_of_user=$myrow ["country"];
$country_of_user=stripslashes($country_of_user);
$city_of_user=$myrow ["city"];
$city_of_user=stripslashes($city_of_user);
$id=$myrow ["first"];
if ($login_of_user!="") {
echo "<tr bgcolor=white><td><font size=2>$login_of_user</td>";
echo "<td><form action='action_users.php' method=post><input type=hidden name='id' value='$id'><input type=text name='email' value=\"$email_of_user\" size=9></td>\n";
echo "<td><input type=text name='firstname' value=\"$name_of_user\" size=9></td>\n";
echo "<td><input type=text name='lastname' value=\"$lastname_of_user\" size=9></td>\n";
echo "<td><input type=text name='country' value=\"$country_of_user\" size=9></td>\n";
echo "<td><input type=text name='city' value=\"$city_of_user\" size=9></td></tr>\n";
echo "<tr bgcolor=white><td colspan=6><center><input type=submit name=action value=change><input type=submit name=action value=delete></td></tr>";
echo "</form>";
}
$i++;
}
?>
</table>
</BODY></HTML>
<?php
mysql_close ($link);
?>