<?php
define('NTLCMS', 1);
$module = 'mytask';
include ('../system/start.php');
include ('../system/function.php');
include ('../system/antidos.php');
$page_title = 'Страница ваших заданий - клик клуба ' . strtoupper($_SERVER['HTTP_HOST']);
include ('../system/head.php');
if (!$active){
header('Location: '.URL);
$_SESSION['fail'] = 'Вы не авторизированы!';
exit;
}
echo '<div class="title"><b>'.razd.' Ваши задания</b></div>';
$sql = DB :: run() -> query("select * from `jobs_category`");
while ($data = $sql -> fetch(PDO::FETCH_OBJ)){
$names[$data -> id] = $data -> name;
}
if (isset($_POST['del_here']) && is_numeric($_POST['del_here'])){
$payed = isset($_POST['del_here']) ? filter_var($_POST['del_here'], FILTER_SANITIZE_NUMBER_INT) : '0';	
$task = DB :: run() -> querySingle("select * from `jobs` where `user` = '$ulogin' and `id` = '$payed' and `accept` = '1'");
if ($task > 0){
DB :: run() -> query("delete from `jobs` where `id` = '$payed'");
DB :: run() -> query("delete from `jobs_use` where `id_job` = '$payed'");
echo '<div class="error"><center><i class="fa fa-check-circle fa-fw"></i> Заявка успешно отменена!</center></div>';
}
}
if (isset($_POST['save_here']) && is_numeric($_POST['save_here'])){
$payed = isset($_POST['save_here']) ? filter_var($_POST['save_here'], FILTER_SANITIZE_NUMBER_INT) : '0';	
$task = DB :: run() -> querySingle("select * from `jobs` where `user` = '$ulogin' AND `id` = '$payed' AND `accept` = '1'");
if ($task > 0){
DB :: run() -> query("update `jobs` set `done` = '1' where `id` = '$payed'");
echo '<div class="post"><center><i class="fa fa-check-circle fa-fw"></i> Заявка успешно завершена!</center></div>';
}
}
$k_post = DB :: run() -> querySingle("select count(`id`) from `jobs` where `user` = '$ulogin' and `accept` = '1'");
$k_page = k_page($k_post, $onpage); 
$page = page($k_page); 
$start = $onpage * $page - $onpage;
$sql = DB :: run() -> query("select * from `jobs` where `user` = '$ulogin' and `accept` = '1' order by `id` desc limit ".$start.", ".$onpage);
if ($k_post == 0){
echo '<div class="error"><center><i class="fa fa-close fa-fw"></i> Задания отсутствуют!</center></div>';
} else {
while ($row = $sql -> fetch(PDO::FETCH_OBJ)){
echo '<div class="menu">
<div class="right"><a href="'.URL.'/tasks_edit'.ints($row -> id).'" title="Редактировать"><span class="badge badge-primary"><i class="fa fa-pencil fa-fw"></i></span></a></div>
#'.$row -> id.'. <b>'.$row -> name.'</b> (Оплата '.coins($row -> pay).')<br/>
<i class="fa fa-list-alt fa-fw"></i> <b>Описание:</b> '.substr($row -> about, 0, 100).'...<br/>	
<i class="fa fa-folder-o fa-fw"></i> <b>Категория:</b> '.$names[$row -> category].'<br/><br>';
if ($row -> done == 0 && $row -> period == 0){ 
echo '<form action="'.URL.'/deletetask'.((int) $row -> id).'" method="post">
<input type="hidden" name="del_here" value="'.$row -> id.'" />
<input type="submit" class="btn btn-success btn-sm" value="Отменить задание"/></form>';
} else if($row -> done == 0 && $row -> period == 1){
echo '<form action="'.URL.'/savetask'.((int) $row -> id).'" method="post">
<input type="hidden" name="save_here" value="'.$row -> id.'" />
<input type="submit" class="btn btn-success btn-sm" value="Завершить задание"/></form>';
} else {
echo '<div class="post"><center><i class="fa fa-check-circle fa-fw"></i> Выполнено!</center></div>';
}
echo '</div>';
}
if ($k_page > 1) navigation(URL.'/mytask?', $k_page, $page);
}
echo '<div class="block"><i class="fa fa-home fa-fw"></i> <a href="'.URL.'/cabinet">В кабинет</a> | <a href="'.URL.'/tasks">Задания пользователей</a></div>';
include ('../system/foot.php');
?>