<?php
define('ROOT','../');
define('GCMS',true);
require_once (ROOT.'system/power.php');
$foto = $db -> query("SELECT * FROM `albom_fotos` where `id`='$id'")->fetch_assoc();
$pav = $db -> query("SELECT `id`,`name`,`cat` FROM `albom_pav` where `id`='$foto[cat]'")->fetch_assoc();
$cat = $db -> query("SELECT `id`,`name` FROM `albom_cat` where `id`='$pav[cat]'")->fetch_assoc();
$diz -> head('Фотоальбомы');
$diz -> title("<a href='./'>Фотоальбомы</a>/<a href='cat$cat[id]'>$cat[name]</a>/<a href='albom$pav[id]'>$pav[name]</a>/<b>".$foto['name']."</b>");
if($aut==true and ($ya['level']>1 or $foto['user']==$ya['id'])){
$msg.='<div class="tochechki">
'.$diz -> img('albom/delete.png').' <a href="./func.php?id='.$id.'&amp;mode=delf">Удалить фотографию</a></br>
'.$diz -> img('albom/satting.png').' <a href="./func.php?id='.$id.'&amp;mode=redf">Редактировать фотографию</a></div>';
}
switch($mode) {
    case 'write':
if ($ya['balls']>$nastr['obcom']) {
$text = shit($_POST['text']);
$te = $db -> query("SELECT * FROM `comes` WHERE `where`='albom' and `idwh` = '".(int)$id."' and `user` = '".(int)$ya['id']."' LIMIT 1");
if (mb_strlen($text) < 3) {
     $msg .= '<div class="fon">Короткий комментарий!</div>';
     header('refresh: 3; url=?mode=write&id='.$id.'');
}else{
$db -> multi_query("UPDATE `users` SET `balls` = balls+$nastr[bcoms] WHERE `id` = '".$ya['id']."'");
$db -> multi_query("INSERT INTO `comes` SET `where`='albom', `user` = '".(int)$ya['id']."', `idwh` = '".$id."',`text` = '".$text."',`time` = '".time()."'");
header('location: ?id='.(int)$id.'&page='.(int)$page);
}
}else{
     $msg .= '<div class="fon">Вам не доступна данная функция!</div>';
     header('refresh: 3; url=?mode=write&id='.$id.'');  
}
break;
case 'del':
if ($aut == true and $id != false) {
$sql = $db -> query("SELECT * FROM `comes` WHERE `id` = '".$sid."' LIMIT 1");
if ($sql -> num_rows > 0) {
$ass = $sql -> fetch_assoc();
if ($ya['level']>4 or $ass['user']==$ya['id'] or $foto['user']==$ya['id']) {
$db -> query("DELETE FROM `comes` WHERE `id` = '".$sid."' LIMIT 1");
header('location: ?id='.(int)$ass['idwh'].'&page='.(int)$page);
} else header('location: ?id='.(int)$ass['idwh'].'&page='.(int)$page);
} else header('location: ./');
} else header('location: ../');
break;
default:
$foto2 = ''.ROOT.'albom/'.$foto['url']; 
$msg .= '<div class="fon"><img src="/system/resize.php?img='.$foto2.'&width=128&height=128&i=0" alt=""/></br>
<a href="'.$foto['url'].'">Скачать оригинал</a> ('.$func->size(filesize($foto['url'])).')</br>
<b>Название:</b> '.$foto['name'].'</br>
<b>Описание:</b> '.$foto['text'].'</br>
<b>Добавил:</b> '.$func->user($foto['user']).'</br></div>';
////-------------------/////
$count = $db -> dbcount('COUNT(`id`)','comes',"`idwh` = '".$id."' and `where`='albom'"); 
$num = isset($ya['num']) ? $ya['num'] : 10;
$total = intval(($count - 1) / $num) + 1; 
if (!isset($_GET['page']) || !is_numeric($_GET['page']) || $_GET['page'] < 1 )
{
$page = 1;
} elseif($_GET['page'] > $total)
{ $page = $total;
} else $page = (int)$_GET['page'];
$start = $page * $num - $num;
////------------------/////
$msg.='<div class="fon">';
$for = $db -> query("SELECT * FROM `comes` where `idwh` = '".$id."' and `where`='albom' order by `time` DESC LIMIT ".$start.",".$num);
while ($assoc = $for -> fetch_assoc()) {               
$dop = null;
if ($aut) {
$arr = $db -> query("SELECT `login` FROM `users` WHERE `id` = '".(int)$assoc['user']."' LIMIT 1");
if ($arr -> num_rows > 0) {
$array = $arr -> fetch_assoc();
$array['login'] = '<a href="'.ROOT.'my/id'.$assoc['user'].'">'.$array['login'].'</a>';
}
if ($ya['level'] > 1 or $assoc['user']==$ya['id']) {
$dop = ' | <a href="?id='.$id.'&amp;sid='.$assoc['id'].'&amp;mode=del&amp;page='.$page.'">[Удалить]</a>';
}
}
$msg .= '<div class="top">'.$array['login'].' ('.$func -> vremja($assoc['time']).') '.$dop.'';
$text = $func -> tags($func -> smiles($assoc['text']));
$msg .='<br/>'.$text.'</div>';
}
$act = '?id='.$id;
$msg .= ''.$func -> pagenav($act,$page,$total).'';
if ($aut == true) {
$msg .= '<form action="?id='.$id.'&amp;mode=write&amp;page='.$page.'" method="post" enctype="multipart/form-data"><div>';
$msg .= '<hr>Комментарий:<br/>
<textarea name="text" rows="3" cols="15"></textarea><br/>
<input type="submit" value="Написать!"/>
</div></form>';}
$msg.='</div>';
}
$msg .= '<div class="levo">'.$diz -> img('home.png').'<a href="/">На главную</a></div>';
#####Копирайт#######
require_once ('../system/kopy.php');
$diz -> out($msg);
?>