Просмотр файла panel/users.php

Размер файла: 8.41Kb
<?php
// by Mike O. (mides), coolcms.mobi

require_once '../system/sys.php';
require_once '../system/auth_a.php';
require_once '../system/header.php';

if (!access(3)) {
    redirect(HTTPHOME);
}

switch ($act) {
    default:
        tp('Пользователи');
		$users0 = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `ok` = 0"), 0);
		if ($users0 > 0) {
			echo '- <a href="?act=nonact">Неактивированные</a> ('.$users0.')<br />';
		}
        echo 'Введите логин или букву:<br /><form name="form" action="?act=sort" method="post">
        <input name="q" type="text" maxlength="12" size="10" /><br />
        <input name="submit" type="submit" value="Поиск" />
        </form><br />';
        
        echo '<a href="?act=sort&amp;q=1">0-9</a> / <a href="?act=sort&amp;q=a">A</a> / <a href="?act=sort&amp;q=b">B</a> / <a href="?act=sort&amp;q=c">C</a> / <a href="?act=sort&amp;q=d">D</a> / <a href="?act=sort&amp;q=e">E</a> / <a href="?act=sort&amp;q=f">F</a> / <a href="?act=sort&amp;q=g">G</a> / <a href="?act=sort&amp;q=h">H</a> / <a href="?act=sort&amp;q=i">I</a> / <a href="?act=sort&amp;q=j">J</a> / <a href="?act=sort&amp;q=k">K</a> / <a href="?act=sort&amp;q=l">L</a> / <a href="?act=sort&amp;q=m">M</a> / <a href="?act=sort&amp;q=n">N</a> / <a href="?act=sort&amp;q=o">O</a> / <a href="?act=sort&amp;q=p">P</a> / <a href="?act=sort&amp;q=q">Q</a> / <a href="?act=sort&amp;q=r">R</a> / <a href="?act=sort&amp;q=s">S</a> / <a href="?act=sort&amp;q=t">T</a> / <a href="?act=sort&amp;q=u">U</a> / <a href="?act=sort&amp;q=v">V</a> / <a href="?act=sort&amp;q=w">W</a> / <a href="?act=sort&amp;q=x">X</a> / <a href="?act=sort&amp;q=y">Y</a> / <a href="?act=sort&amp;q=z">Z</a><br />';
        nav('./');
    break;
        
    case 'sort':
        if (isset($_POST['q'])) {
            $q = check(strtolower($_POST['q']));
        } else {
            $q = check(strtolower($_GET['q']));
        } 
        
        if (isset($q)) {
            if ($q == 1) {
                $search = "RLIKE '^[-0-9]'";
            } else {
                $search = "LIKE '$q%'";
            }
            
        }
        
        $total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `users` WHERE LOWER(`username`) ".$search.";"), 0);

        $pages = ceil($total / $config['onpage']);
        if ($page > $pages or $page == 0) {
            $page = 1;
        }
        $begin = ($page - 1) * $config['onpage'];
        
        tp('<a href="?">Пользователи</a>');
        echo '<form name="form" action="?act=sort" method="post">
        <input name="q" type="text" maxlength="12" size="10" />
        <input name="submit" type="submit" value="Поиск" />
        </form><br />';

        $users_r = mysql_query("SELECT `id`, `karma` FROM `users` WHERE LOWER(`username`) ".$search." ORDER BY `karma` DESC LIMIT $begin, $config[onpage]");
        while ($user = mysql_fetch_assoc($users_r)) {
            echo '<a href="../profile.php?id='.$user['id'].'">'.username($user['id']).'</a> (<a href="?act=edit&amp;id='.$user['id'].'">ред</a>/<a href="?act=del&amp;id='.$user['id'].'">уд</a>)<br />';
        }
        navig($page, '?act=sort&amp;', $pages);
        nav('./');
    break;

    case 'edit':
		$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '$id'"));
		if ($user['id']) {
			if ($ok) {
				$email = check($_POST['email']);
				$access = abs(intval($_POST['access']));
				switch ($access) {
					default: $access = $user['access']; break;
					case '1': $access = 1; break;
					case '2': $access = 2; break;
					case '3': $access = 3; break;
					case '4': $access = 0; break;
				}
				$icq = abs(intval($_POST['icq']));
				$skype = check($_POST['skype']);
				$name = check($_POST['name']);
				$gender = abs(intval($_POST['gender']));
				$from = check($_POST['from']);
				$birthday = check($_POST['birthday']);
				$site = check($_POST['site']);
				$about = check($_POST['about']);
				mysql_query("UPDATE `users` SET `email` = '$email', `access` = '$access', `icq` = '$icq', `skype` = '$skype', `name` = '$name', `gender` = '$gender', `from` = '$from', `birthday` = '$birthday', `site` = '$site', `about` = '$about' WHERE `id` = '$id'");
				redirect('?act=edit&id='.$id);
			} else {
				tp('Ред-ть профиль');
				echo '<form name="form" action="?act=edit&amp;id='.$id.'&amp;ok=1" method="post">
				<u>'.access2($user['id']).' </u>
				<select name="access">
				<option value="0">Не изменять</option>
				<option value="4">Пользователь</option>
				<option value="1">Куратор</option>
				<option value="2">Модератор</option>
				<option value="3">Администратор</option>
				</select><br />
				E-mail(max50):<br /><input name="email" type="text" maxlength="50" value="'.$user['email'].'" /><br />
				ICQ(max9):<br /><input name="icq" type="text" maxlength="9" value="'.$user['icq'].'" /><br />
				Skype(max32):<br /><input name="skype" type="text" maxlength="32" value="'.$user['skype'].'" /><br />
				Имя(max20):<br /><input name="name" type="text" maxlength="20" value="'.$user['name'].'" /><br />
				Пол: ';
				switch ($user['gender']) {
					case '1': echo 'муж<input name="gender" type="radio" value="1" checked /> <input name="gender" type="radio" value="2" />жен'; break;
					case '2': echo 'муж<input name="gender" type="radio" value="1" /> <input name="gender" type="radio" value="2" checked />жен'; break;
					default: echo 'муж<input name="gender" type="radio" value="1" /> <input name="gender" type="radio" value="2" />жен'; break;
				}
				echo '<br />
				Откуда(max25):<br /><input name="from" type="text" maxlength="25" value="'.$user['from'].'" /><br />
				Дата рождения (дд.мм.гггг):<br /><input name="birthday" type="text" maxlength="25" value="'.$user['birthday'].'" /><br />
				Wap-сайт(<del>http://</del>, max20):<br /><input name="site" type="text" maxlength="20" value="'.$user['site'].'" /><br />
				О себе(max250):<br /><textarea name="about" cols="" rows="3">'.$user['about'].'</textarea><br />
				<input name="submit" type="submit" value="Ok" />
				</form>';
				nav('?');
			}
		} else {
			redirect('?');
		}
    break;

    case 'del':
		if ($id != 1) {
			if (isset($_GET['ok'])) {
				mysql_query("DELETE FROM `voting` WHERE `type` = 'profile' and `id_for` = '$id'");
				mysql_query("DELETE FROM `users` WHERE `id` = '$id'");
				$_SESSION['note'] = 'Удален.';
				redirect('?');
			} else {
				tp('Подтвердите');
				echo 'Вы действительно хотите удалить пользователя '.username($id).'?
				<form name="form" action="?act=del&amp;id='.$id.'&amp;ok=1" method="post">
				<input name="submit" type="submit" value="Да" />
				</form>';
				nav('?');
			}
		} else {
			$_SESSION['note'] = 'Нельзя удалить администратора-создателя.';
			redirect('?');
		}
    break;
	
	case 'nonact':
		$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `ok` = 0"), 0);

        $pages = ceil($total / $config['onpage']);
        if ($page > $pages or $page == 0) {
            $page = 1;
        }
        $begin = ($page - 1) * $config['onpage'];
        
        tp('<a href="./">АДМ</a> &raquo; Неактивированные</a>');	
		echo '- <a href="?">Все юзеры</a>, <a href="?act=useract_all">актив. всех</a><hr />';
		note();

        $users_r = mysql_query("SELECT `id`, `karma` FROM `users` WHERE `ok` = 0 ORDER BY `regtime` LIMIT $begin, $config[onpage]");
        while ($user = mysql_fetch_assoc($users_r)) {
            echo '<a href="../profile.php?id='.$user['id'].'">'.username($user['id']).'</a> (<a href="?act=useract&amp;id='.$user['id'].'">Акт</a>/<a href="?act=del&amp;id='.$user['id'].'">DEL</a>)<br />';
        }
        navig($page, '?act=nonact&amp;', $pages);
        nav('./');
	break;
	
	case 'useract':
		mysql_query("UPDATE `users` SET `ok` = 1 WHERE `id` = '$id'");
		$_SESSION['note'] = 'Активирован.';
		redirect('?act=nonact');
	break;
	
	case 'useract_all':
		mysql_query("UPDATE `users` SET `ok` = 1");
		$_SESSION['note'] = 'Все были активированы.';
		redirect('?act=nonact');
	break;
	
}

require_once '../system/tail_p.php';
?>