Location: PHPKode > projects > pkZoos Website > users.php
<?php
	if(!defined('PK_MAGIC'))
		die('hack or what?');





	/* */

	if(!isset($_GET['mode']))
	{
		$_GET['mode'] = '';
	}

	switch($_GET['mode'])
	{
		case 'all':
		case 'online':
			break;

		default:
			$_GET['mode'] = 'all';
			break;
	}





	/* */

	if(isset($_GET['start']) && check_int($_GET['start']))
	{
		$users_start = $_GET['start'];
	}
	else
	{
		$users_start = 0;
	}

    $q = "
        SELECT COUNT(user_id) as count
        FROM " . USERS_TABLE . "
        WHERE
            user_is_activated <> 0
            " . ($_GET['mode'] == 'online' ? "AND last_online_time > " . (CURRENT_TIME - $config['session_online_time']) : "") . "
    ";

    $user_res = $db->query($q);
    $user_row = $db->fetch_row($user_res);
    $users_total = $user_row['count'];

	if($users_start >= $users_total)
	{
		$users_start = $users_total - 1;
	}

	if($users_start < 0)
	{
		$users_start = 0;
	}

	$users_start = (int)($users_start / $config['users_per_page']) * $config['users_per_page'];

	$pages_total = $users_total / $config['users_per_page'];
	$pages_total = (int)($pages_total + (($pages_total > (int)$pages_total) ? 1 : 0));

	$pages_current = $users_start / $config['users_per_page'];





	/* */

    $tpl->add_var('MODE_ALL', 0);
    $tpl->add_var('MODE_ONLINE', 0);
	$tpl->add_var('URL_SEARCH_USER_ALL', '');
	$tpl->add_var('URL_SEARCH_USER_ONLINE', '');

	if($_GET['mode'] == 'all')
	{
		$tpl->add_var('MODE_ALL', 1);
		$tpl->add_var('URL_SEARCH_USER_ALL', html_escape(make_url('search', array('action' => 'search_user_all', 'start' => $users_start))));
	}
	else if($_GET['mode'] == 'online')
	{
		$tpl->add_var('MODE_ONLINE', 1);
		$tpl->add_var('URL_SEARCH_USER_ONLINE', html_escape(make_url('search', array('action' => 'search_user_online', 'start' => $users_start))));
	}





	/* */

	$fr[0] = 0;
	$to[0] = -1;

	$fr[1] = $pages_current - 6;
	$to[1] = $pages_current + 6;

	$fr[2] = $pages_total;
	$to[2] = $pages_total - 1;

	$spacer[0] = false;
	$spacer[1] = false;
	$spacer[2] = false;

	if($pages_current > 6)
	{
        $to[0] = 1;
		$fr[1] = $pages_current - 4;
		$spacer[0] = true;
	}

	if($pages_total - 8 >= $pages_current)
	{
		$to[1] = $pages_current + 4;
		$fr[2] = $pages_total - 2;
		$spacer[1] = true;
	}

	if($fr[1] < 0)
	{
		$fr[1] = 0;
	}

	if($to[1] > $pages_total - 1)
	{
		$to[1] = $pages_total - 1;
	}

	$page_count = 0;

	for($i = 0; $i < 3; $i++)
	{
        for($page_i = $fr[$i]; $page_i <= $to[$i]; $page_i++)
        {
			$tpl->add_block_vars
			(
				'pages', array
				(
					'NUMBER' => $page_i + 1,
					'URL' => ($page_i != $pages_current) ? html_escape(make_url('users', array('mode' => $_GET['mode'], 'start' => ($page_i * $config['users_per_page'])))) : ''
				)
			);

        	$page_count++;
        }

        if($spacer[$i])
        {
			$tpl->add_block_vars
			(
				'pages', array
				(
					'NUMBER' => -1,
					'URL' => ''
				)
			);

        	$page_count++;
        }
    }

    $tpl->add_var('PAGE_COUNT', $page_count);





	/* */

    $q = "
        SELECT
            user_id,
            user_name,
            user_regtime,
            user_topics,
            user_posts,
            last_post_time,
            user_is_disabled,
            user_is_activated,
            user_is_admin,
            user_is_member,
            last_online_time
        FROM " . USERS_TABLE . "
        " . ($_GET['mode'] == 'online' ? " WHERE last_online_time > " . (CURRENT_TIME - $config['session_online_time']) : "") . "
        ORDER BY user_name ASC
    ";

    $user_res = $db->query($q);
    $user_count = $db->num_rows($user_res);

	$tpl->add_var('USER_COUNT', $user_count);

    for($user_i = 0; $user_i < $user_count; $user_i++)
    {
        $user_row = $db->fetch_row($user_res);





		/* */

		$q = "
			SELECT mod_id
			FROM " . MODS_TABLE . "
			WHERE user_id = " . $user_row['user_id'] . "
		";

        $mod_res = $db->query($q);

        if($db->fetch_row($mod_res))
        {
        	$user_row['user_is_mod'] = 1;
        }
        else
        {
        	$user_row['user_is_mod'] = 0;
        }





		/* */

        $tpl->add_block_vars
        (
            'users', array
            (
                'NAME' => html_escape($user_row['user_name']),
                'IS_DISABLED' => $user_row['user_is_disabled'],
                'IS_ACTIVATED' => $user_row['user_is_activated'],
                'IS_MOD' => $user_row['user_is_mod'],
                'IS_ADMIN' => $user_row['user_is_admin'],
                'IS_MEMBER' => $user_row['user_is_member'],
                'IS_ONLINE' => (($user_row['last_online_time'] > CURRENT_TIME - $config['session_online_time']) ? 1 : 0),
                'URL' => html_escape(make_url('user', array('user_id' => $user_row['user_id']))),
                'DATE' => html_escape(make_date($user_row['user_regtime'])),
                'TOPICS' => $user_row['user_topics'],
                'REPLIES' => $user_row['user_posts'],
                'LAST_POST_DATE' => html_escape(make_date($user_row['last_post_time']))
            )
        );
    }





    /* */

	$tpl->add_var('SHOW_ALL_USERS', 0);
	$tpl->add_var('SHOW_ONLINE_USERS', 0);

	switch($_GET['mode'])
	{
		case 'all':
			$tpl->add_var('SHOW_ALL_USERS', 1);
			$tpl->add_var('PAGE_TITLE', html_escape($l['title_all_users']));
			break;

		case 'online':
			$tpl->add_var('SHOW_ONLINE_USERS', 1);
			$tpl->add_var('PAGE_TITLE', html_escape($l['title_online_users']));
			break;
	}
?>
Return current item: pkZoos Website