Файл: PROFIWM.COM/ticket.php
Строк: 93
<?php
// ЛУЧШИЕ СКРИПТЫ ТОЛЬКО НА 4MAST.RU
// АВТОР Chainsaw
// ТОЛЬКО ЭКСКЛЮЗИВНЫЕ СКРИПТЫ
require_once('system/core.php');
require_once('system/header.php');
if(!$user['id']){
header('location:/');
die();
}
$_title = 'Тикеты';
$do = !empty($_GET['do']) ? TextGuard($_GET['do']) : false;
switch($do){
default:
echo '<div class="post1"><a href="?do=add">Создать тикет</a></div>';
echo '<div class="post1"><a href="?do=my">Мои тикеты</a> ('.core::$dbs->querySingle("SELECT COUNT(id) FROM ticket WHERE user_id = ?", array($user['id'])).')</div>';
break;
case 'my':
$k_post = core::$dbs->querySingle("SELECT COUNT(id) FROM ticket WHERE user_id = ?", array($user['id']));
$max = $user['on_page'];
$cp = ceil($k_post/$max);
if(isset($_GET['p']) && is_numeric($_GET['p'])){
$p = abs(intval($_GET['p']));
if($_GET['p']>$cp) $p = $cp;
if($_GET['p']<1)$p = 1;
} else {
$p = 1;
}
$start = $p*$max-$max;
if($k_post==0){
echo '<div class="post2"><b>Тикетов нет!</b></div>';
}
$array = core::$dbs->query("SELECT * FROM ticket WHERE user_id = ? ORDER BY time DESC LIMIT $start,$max", array($user['id']));
while($arr = $array->fetch()){
echo '<div class="post2"><a href="?do=view&id='.$arr['id'].'"> '.$arr['name'].'</a> ('.core::$dbs->querySingle("SELECT COUNT(id) FROM ticket_comm WHERE tid = ?", array($arr['id'])).') '.times($arr['time']).'<br/>» Статус: '.($arr['type'] == 0 ? 'Открытый':'<font color="red">Закрытый</font>').'</div>';
}
navig('?do=my&');
break;
/* Добавить тикет */
case 'add':
if (isset($_POST['add'])) {
$name = htmlspecialchars(trim($_POST['name']));
$text = htmlspecialchars(trim($_POST['text']));
if(empty($name) OR strlen($name)<3){
$err = 'Не введено название записи или оно короче 3 символов!';
}
if(empty($text) OR strlen($text)<5){
$err = 'Не введено содержание записи или оно короче 5 символов!';
}
if(empty($err)){
core::$dbs->query("INSERT INTO ticket SET name = ?, text = ?, time = ?, user_id = ?",array($name,$text,time(),$user['id']));
$last = core::$dbs->lastInsertId();
core::$dbs->query("INSERT INTO ticket_comm SET text = ?, time = ?, user_id = ?, tid = ?, type = ?",array($text,time(),$user['id'],$last,1));
header('location: ?do=view&id='.$last);
die();
} else {
echo '<div class="post2"><b>'.$err.'</b></div>';
}
}
echo '<div class="post2"><form action="?do=add" method="post">Название:<br/><input type="text" name="name"/><br/>Содержание:<br/><textarea name="text"></textarea><br/><input type="submit" name="add" value="Добавить"/></form></div>';
break;
case 'view':
$id = isset($_GET['id']) ? abs((int)$_GET['id']) : false;
$array = core::$dbs->query("SELECT * FROM ticket WHERE id = ? LIMIT 1",array($id));
if($array->rowCount()==0){
header('location:/');
die();
}
$arr = $array->fetch();
if (isset($_GET['delete'])) {
$delete = abs((int)$_GET['delete']);
core::$dbs->query("DELETE FROM ticket_comm WHERE
id = ? LIMIT 1",array($delete));
header('location: ?do=view&id='.$id);
die();
}
if ($user['ticket'] == 1 && $arr['user_id'] == $user['id']) {
if (isset($_GET['del'])) {
core::$dbs->query("DELETE FROM ticket_comm WHERE
tid = ?",array($id));
core::$dbs->query("DELETE FROM ticket WHERE
id = ?",array($id));
header('location: ?');
die();
}
if (isset($_GET['closed'])) {
if ($arr['type'] == 1) {
header('location: ?do=view&id='.$id);
die();
}
core::$dbs->query("UPDATE ticket SET type = ? WHERE
id = ? LIMIT 1",array(1,$id));
header('location: ?do=view&id='.$id);
die();
}
if (isset($_GET['open'])) {
if ($arr['type'] == 0) {
header('location: ?do=view&id='.$id);
die();
}
core::$dbs->query("UPDATE ticket SET type = ? WHERE
id = ? LIMIT 1",array(0,$id));
header('location: ?do=view&id='.$id);
die();
}
}
echo '<div class="post1"><center><b>'.$arr['name'].'</b> ('.times($arr['time']).')</center></div>';
if ($user['ticket'] == 1 && $arr['user_id'] == $user['id']) {
if ($arr['type'] == 1) {
echo '<div class="post1"><a href="?do=view&id='.$id.'&open">Открыть</a> / <a href="?do=view&id='.$id.'&del">Удалить</a></div>';
} else {
echo '<div class="post1"><a href="?do=view&id='.$id.'&closed">Закрыть</a> / <a href="?do=view&id='.$id.'&del">Удалить</a></div>';
}
}
if (!empty($_GET['nk'])) {
$nk = abs((int)$_GET['nk']);
$toUrl = '&nk='.$nk;
} else {
$toUrl = '';
}
$k_post = core::$dbs->querySingle("SELECT COUNT(id) FROM ticket_comm WHERE tid = ?",array($id));
if($k_post==0){
echo '<div class="post2"><b>Сообщений нет!</b></div>';
}
$max = $user['on_page'];
$cp = ceil($k_post/$max);
if(isset($_GET['p']) && is_numeric($_GET['p'])){
$p = abs(intval($_GET['p']));
if($_GET['p']>$cp) $p = $cp;
if($_GET['p']<1)$p = 1;
} else {
$p = 1;
}
$start = $p*$max-$max;
$ticket = core::$dbs->query("SELECT * FROM ticket_comm WHERE tid = ? ORDER BY `time` DESC LIMIT $start,$max",array($id));
while($t = $ticket->fetch()){
echo '<div class="post2">'.uname($t['user_id']).' / '.times($t['time']).'<br/>'.out($t['text']).'<br/>'.($user['status']>=2 && $user['ticket'] == 1 ? '<a href="?do=view&id='.$id.'&delete='.$arr['id'].'">Удалить</a> / ':'').(($arr['user_id'] != $user['id']) ? '<a href="?do=view&id='.$arr['user_id'].'">Ответить</a>':NULL) .'</div>';
}
if ($arr['type'] == 0) {
if (isset($_POST['add'])) {
$text = htmlspecialchars(trim($_POST['text']));
if(empty($text) OR strlen($text)<5){
$err = 'Не введено содержание записи или оно короче 5 символов!';
}
if (empty($err)) {
if (!empty($nk) && $nk != $user['id']) {
$m = $user['login'] . ' ответил на ваш комментарий в текете <a href="/ticket.php?do=view&id='.$id.'">' . $arr['name'] . '</a>!';
core::$dbs->query("INSERT INTO op SET who = ?,
ho = ?,text = ?,
time = ?,
read = ?, sort = ?",array($nk,$user['id'],$m,time(),0,2));
}
core::$dbs->query("INSERT INTO ticket_comm SET text = ?, time = ?, user_id = ?, tid = ?, type = ?",array($text,time(),$user['id'],$id,1));
header('location: ?do=view&id='.$id);
die();
} else {
echo '<div class="post2"><b>'.$err.'</b></div>';
}
}
echo '<div class="post2"><form action="?do=view&id='.$id.$toUrl.'" method="post">Сообщение:<br/><textarea name="text">'.(!empty($nk) ? '[b]'.user_inf($nk, 'login').'[/b], ':'').'</textarea><br/><input type="submit" name="add" value="Добавить"/></form></div>';
} else {
echo '<div class="post2"><b>Тикет закрыт</b></div>';
}
navig('?do=view&id='.$id.'&');
break;
case 'adm':
if ($user['ticket'] != 1) {
header('location: ?');
die();
}
$k_post = core::$dbs->querySingle("SELECT COUNT(id) FROM ticket");
$max = $user['on_page'];
$cp = ceil($k_post/$max);
if(isset($_GET['p']) && is_numeric($_GET['p'])){
$p = abs(intval($_GET['p']));
if($_GET['p']>$cp) $p = $cp;
if($_GET['p']<1)$p = 1;
} else {
$p = 1;
}
$start = $p*$max-$max;
if($k_post==0){
echo '<div class="post2"><b>Тикетов нет!</b></div>';
}
$array = core::$dbs->query("SELECT * FROM ticket ORDER BY time DESC LIMIT $start,$max");
while($arr = $array->fetch()){
$new_post = core::$dbs->querySingle("SELECT COUNT(id) FROM ticket_comm WHERE type = ? AND tid = ?",array(1,$arr['id']));
$new = (!empty($new_post) ? '<font color="red">+'.$new_post.'</font>':'');
echo '<div class="post2"><a href="/ticket.php?do=view&id='.$arr['id'].'"> '.$arr['name'].'</a> ('.core::$dbs->querySingle("SELECT COUNT(id) FROM ticket_comm WHERE tid = ?", array($arr['id'])).$new.') '.times($arr['time']).'<br/>» Статус: '.($arr['type'] == 0 ? 'Открытый':'<font color="red">Закрытый</font>').'</div>';
core::$dbs->query("UPDATE ticket_comm SET type = ? WHERE tid = ?", array(0,$arr['id']));
}
navig('?do=adm&');
break;
}
if (!empty($_GET['do'])) echo '<div class="post2"><a href="ticket.php?">Тикеты</a></div>';
require_once('system/footer.php');
?>