<?php
require_once('classes/body.class.php');
require_once('classes/db.class.php');
require_once('classes/system.class.php');
$title= new Body;
$title->SetTitle(homeurl.' - Отзывы и предложения ');
$title->GetHeader();
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="/"style="text-decoration:none; color:white;"> Главная</a> :: Отзывы и предложения</div></div></div>';

$do = isset($_GET['do']) ? check($_GET['do']) : false;
switch($do) {
default:
if ($b == true){
if (DB::$dbs->querySingle("SELECT COUNT(id) FROM otzyvy WHERE user_id = ?", [$b['id']]) == 0) 
echo '<div class="tile"><ul class="nav nav-pills nav-stacked"><li><a href="?do=add"><span class="label label-danger">Новый</span> Добавить отзыв</a></ul></div>';
}
if (isset($_GET['del'])) {
if ($b['level'] < 4) {
header('location: ?');
die();
}
DB::$dbs->query("DELETE FROM otzyvy WHERE id = ?", [abs((int)$_GET['del'])]);
header('location: ?');
die();
}
echo'<div class="t-body"><div class="list-group lg-alt">';
$look = DB::$dbs->querySingle("SELECT COUNT(id) FROM otzyvy WHERE activ = ?", [1]);
if ($look == 0) {
err('Отзывов нет! Будь первым :)');
}
$num = 10;
$k_page = k_page($look, $num);
$page = page($k_page);
$start = $num*$page-$num;
$sql = DB::$dbs->query("SELECT * FROM otzyvy WHERE activ = ? ORDER BY time DESC LIMIT $start,$num",[1]);
while($a = $sql->fetch()) {
$D = ($b['level'] > 4 ? '[<a href="?del='.$a['id'].'">Удл</a>] ':NULL);
echo'<a class="list-group-item media" href="/users/'.$a['user_id'].'"><div class="pull-left"><img class="img-circle pull-left" src="/'.(user_inf($a['user_id'], 'ava') != NULL ? user_inf($a['user_id'], 'ava') : 'assets/img/4.jpg').'" alt="" width="40" height="40"></div><div class="media-body"><div class="list-group-item-heading">'.user_inf($a['user_id'], 'name').'  '.user_inf($a['user_id'], 'family').' ('.vr($a['time']).') </div><small class="list-group-item-text"> '.($a['type'] == 1 ? '<font color="green">'.text($a['text']).'</font>':'<font color="red">'.text($a['text']).'</font>').'</small></div></a>';

//'.$D.' 
}
echo'</div></div>';
if ($k_page > 1) {
str('?',$k_page,$page);
}
break;
case 'add':
if (DB::$dbs->querySingle("SELECT COUNT(id) FROM otzyvy WHERE user_id = ?", [$b['id']]) > 0) {
header('location: ?');
die();
}
if (isset($_POST['add'])) {
$form = ['text' => isset($_POST['text']) ? check($_POST['text']) : null, 'type' => isset($_POST['type']) ? abs((int)$_POST['type']) : null, 'type' => isset($_POST['type']) ? abs((int)$_POST['type']) : null, 'sogl' => isset($_POST['sogl']) ? abs((int)$_POST['sogl']) : null];
if (empty($form['text']) OR empty($form['type']) OR empty($form['sogl'])) {
err('Ошибка добавления отзыва!');
} elseif (DB::$dbs->querySingle("SELECT COUNT(id) FROM otzyvy WHERE text = ?", [$form['text']]) > 0) {
err('Такой отзыв уже есть!');
} else {
DB::$dbs->query("INSERT INTO otzyvy SET text = ?, type = ?, user_id = ?, time= ?", [$form['text'],$form['type'],$b['id'],time()]);
echo '<div class="alert alert-success"role="alert">Отзыв добавлен и отправлен на модерацию.</div>';
$title->GetMenu();
$title->GetFooter();
die();
}
}
echo '<div class="list-group-item media"><form action="?do=add" method="POST">';
quickpaste('text');
quickpanel();
echo'<br/><br/><textarea name="text" class="form-control" rows="8" ></textarea><br/>
Тип:<br/><input type="radio" name="type" value="1" checked="checked"/> Положительный<br/><input type="radio" name="type" value="2"/> Отрицательный<br/><input type="checkbox" name="sogl" value="1"/> Мой отзыв не содержит клевету и оскорбления. С правилами согласен<br/><input type="submit" name="add" class="btn btn-primary"value="Добавить"/></form></div>';
break;
}

$title->GetMenu();
$title->GetFooter();
?>
