<?php
$set['title']='Фотоальбомы &amp; '.$_SERVER['HTTP_HOST'];

include_once '../sys/inc/thead.php';

title();

err();



$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery`"),0);
$k_page = k_page($k_post,$set['p_str']);
$page = page($k_page);
$start = $set['p_str']*$page-$set['p_str'];
echo "<div class='menu'>"; 
echo '<form action="index.php?page='.$page.'" method="post">';
echo '<b>Сорт</b>:&nbsp;<select name="sort"><option value="name">имя</option><option value="time_create">дата создания</option><option value="time">последнее обновление</option><option value="posl">старые</option><option value="new">новые</option></select>';
echo '<input type="submit" value="ok"></form>';
echo '</div>';
echo '<table class="post">';

if($k_post==0){
	echo '<tr><td class="p_t">Нет фотоальбомов</td></tr>';
	}

$asc='DESC';
$order='id';

if(isset($_POST['sort']) && $_POST['sort']=='name'){
	$order='name';
	}else if(isset($_POST['sort']) && $_POST['sort']=='time_create'){
		$order='time_create';
		}else if(isset($_POST['sort']) && $_POST['sort']=='time'){
			$order='time';
			}else if(isset($_POST['sort']) && $_POST['sort']=='new'){
				$order='id';
				$asc='DESC';
				}else if(isset($_POST['sort']) && $_POST['sort']=='posl'){
					$order='time_create';
					$asc='ASC';
					}

$q = mysql_query("SELECT * FROM `gallery` ORDER BY $order $asc LIMIT $start, $set[p_str]");
while($post = mysql_fetch_array($q)){
	$ank = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '".$post['id_user']."' LIMIT 1"));

echo '<tr><td class="icon14">';
echo avatar2($ank['id']);
echo '</td><td class="p_m">';
$all = mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_foto` WHERE `id_gallery` = '".$post['id']."'"),0);
echo '<a href="/foto/'.$ank['id'].'/'.$post['id'].'/">Альбом <span style="color:'.$ank['ncolor'].'">'.$ank['nick'].'</span></a> (<b>'.$all.'</b>)<br/>';

if($post['opis']!=null){
	echo output_text($post['opis']).'<br/>';
	}

echo '<b>Создан</b>: '.vremja($post['time_create']).'<br/>';
echo '<b>Обновлён</b>: '.vremja($post['time']).'<br/>';

echo '</td></tr>';
}

echo '</table>';

if($k_page>1){
	str('?',$k_page,$page);
	}

if(isset($user)){
echo "<div class='menu'>"; 
	echo '<a href="/foto/'.$user['id'].'/">Мои альбомы</a><br/>';
	}

echo '</div>';
include_once '../sys/inc/tfoot.php';
exit;
?>