Файл: mylaf.ru/jokes/index.php
Строк: 813
<?
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/shif.php';
include_once '../sys/inc/user.php';
$set['title']='Анекдоты';
include_once '../sys/inc/thead.php';
title();
aut();
err();
echo "<style type='text/css'>
.block_hr {border-bottom:1px dotted #abbefb}
div.row3{padding:1px;background-color:#e1e1e1}
div.row4{padding:1px;background-color:#ffffff}
div.backlink{background-color:#EFF3F6;padding:2px}
div.blueline{padding:1px;background-color:#e7f1fe;border-top:1px solid #99ccff;border-bottom:1px solid #AFCDDC}
div.even{padding:1px;background-color:#fff;border-top:1px dotted #CCC}
div.block{margin:2px;padding:1px;border-top:1px dotted gray;border-bottom:1px dotted gray}
div.busi{padding:2px;background-color:#fff9d7;border-top:1px solid #e2c822;border-bottom:1px solid #e2c822}
div.header_path{border-left:1px solid #abbefb;border-right:1px solid #abbefb;border-bottom:1px solid #abbefb;border-left: 1px solid #999999;border-right: 1px solid #999999;background:#e8e8e8;margin:0px;padding:3px}
div.odd{padding:1px;background-color:#edeff4;border-top:1px dotted #CCC}
a:link,a:visited{color:#006699}
a:visited{color:#666666;}
a:hover{color: #ff0000;text-decoration: underline}
div.title1{padding:3px;background-color:#d7ddf8;border-bottom:1px dotted #AFCDDC}
img.icon {vertical-align: middle}
.clear{ clear:both}</style>n";
function cut_joke( $text, $maxwords = 30, $maxchar = 100 ){$sep=' ';$sep2='...';$words = split($sep,$text);$char = iconv_strlen($text,'utf-8');if (count($words) > $maxwords)$text = join($sep, array_slice($words, 0, $maxwords));return $text;}
if(isset($_GET['add_cat']) && $user['level']>0)
{
if(isset($_POST['ok']))
{
$name=$_POST[name];
$name=esc(stripcslashes(htmlspecialchars($name)));
if (isset($_POST['translit_name']) && $_POST['translit_name']==1)$name=translit($name);
if(strlen2($name)<1)
{
$err='';
echo "<img src='img/err.png' /> Введите названиеn";
}
if(strlen2($name)>60)
{
$err='';
echo "<img src='img/err.png' /> Название слишком длинное";
}
$name=my_esc($name);
$text=$_POST[text];
$text=esc(stripcslashes(htmlspecialchars($_POST['text'])));
if (isset($_POST['translit_text']) && $_POST['translit_text']==1)$text=translit($text);
if(strlen2($text)>100)
{
$err='';
echo "<img src='img/err.png' /> Описание слишком длинное";
}
$text=my_esc($text);
if(!isset($err))
{
mysql_query("INSERT INTO `jokes_cat` (`name`, `text`, `balls`) values ('$name', '$text', '0')");
header("Location: ?categories");
}
}
echo "<form method='post' action='?add_cat'>n";
echo "<img src='img/cat.png' /> <span style='font-size:small;color:darkblue'><b>Название</b> (60 знаков)</span><br/><input type='text' name='name' value=''><br/>n";
if ($user['set_translit']==1)echo "<label><input type='checkbox' name='translit_name' value='1' /> Транслит</label><br />n";
echo "<img src='img/joke.png' /> <span style='font-size:small;color:darkblue'><b>Описание</b> (100 знаков)</span><br/><input type='text' name='text' value='' rows='5' cols='30'><br/>n";
if ($user['set_translit']==1)echo "<label><input type='checkbox' name='translit_text' value='1' /> Транслит</label><br />n";
echo "<input type='submit' value='Создать' name='ok' ></form><br/>n";
echo "<a href='?cat=$cat[id]'><div class='gmenu'><img src='img/back.png'> Назад</div></a>n";
}
elseif(isset($_GET['add_joke']))
{
if(!isset($user))header("Location: /aut.php");
$cat=mysql_fetch_array(mysql_query("SELECT * FROM `jokes_cat` WHERE `id` = '".intval($_GET['add_joke'])."' LIMIT 1"));
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes_cat` WHERE `id` = '$cat[id]' LIMIT 1"),0)!=0)
{
if(isset($user))
{
if(isset($_POST['ok']))
{
$text=$_POST['text'];
$text=esc(stripcslashes(htmlspecialchars($_POST['text'])));
if (isset($_POST['translit_text']) && $_POST['translit_text']==1)$text=translit($text);
if(strlen2($text)<5)
{
$err='';
echo "<div class='err'><img src='img/err.png' /> Введите текст</div>n";
}
if(strlen2($text)>100000)
{
$err='';
echo "<div class='err'><img src='img/err.png' /> Текст слишком длинный</div>n";
}
$text=my_esc($text);
if(!isset($err))
{
mysql_query("INSERT INTO `jokes` (`cat`, `time`, `text`, `id_user`) values ('$cat[id]', '$time', '$text', '$user[id]')");
$h=mysql_insert_id();
header("Location: ?joke=$h");
}
}
echo "<form method='post' action='?add_joke=$cat[id]'>n";
echo "<img src='img/joke.png' alt=''/> <span style='font-size:small;color:darkblue'><b>Анекдот</b> (от 5 до 100000 знаков)</span><br/><textarea name='text' rows='5' cols='30'></textarea><br />n";
if ($user['set_translit']==1)echo "<label><input type='checkbox' name='translit_text' value='1' /> Транслит</label><br />n";
echo "<input type='submit' value='Создать' name='ok' ></form><br/>n";
}
else echo"<img src='img/err.png' /> Разрешено создавать один анекдот в 10 минут!n";
echo "<a href='?cat=$cat[id]'><div class='gmenu'><img src='img/back.png'> Назад</div></a>n";
}
else echo "Категория не найденаn";
}
elseif(isset($_GET['edit_cat']) && $user['level']>0)
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes_cat` WHERE `id` = '".intval($_GET['edit_cat'])."' LIMIT 1"),0)!=0)
{
$cat=mysql_fetch_array(mysql_query("SELECT * FROM `jokes_cat` WHERE `id` = '".intval($_GET['edit_cat'])."' LIMIT 1"));
if(isset($_POST['ok']))
{
$name=$_POST['name'];
$name=esc(stripcslashes(htmlspecialchars($_POST['name'])));
if (isset($_POST['translit_name']) && $_POST['translit_name']==1)$name=translit($name);
if(strlen2($name)<1)
{
$err='';
echo "<div class='err'><img src='img/err.png' /> Введите название</div>n";
}
if(strlen2($name)>60)
{
$err='';
echo "<div class='err'><img src='img/err.png' /> Название слишком длинное</div>n";
}
$name=my_esc($name);
$text=$_POST['text'];
$text=esc(stripcslashes(htmlspecialchars($_POST['text'])));
if (isset($_POST['translit_text']) && $_POST['translit_text']==1)$text=translit($text);
if(strlen2($text)>100)
{
$err='';
echo "<div class='err'><img src='img/err.png' /> Описание слишком длинное</div>n";
}
$text=my_esc($text);
if(!isset($err))
{
mysql_query("UPDATE `jokes_cat` SET `name` = '$name', `text` = '$text', `balls` = '0' WHERE `id` = '$cat[id]' LIMIT 1");
header("Location: ?categories");
}
else header("Location: ?categories");
}
echo "<form method='post' action='?edit_cat=$cat[id]'>n";
echo "<img src='img/cat.png' /> <span style='font-size:small;color:darkblue'><b>Имя </b> (60 знаков)</span><br/><br /><input type='text' name='name' value='$cat[name]'/> <br />n";
if ($user['set_translit']==1)echo "<label><input type='checkbox' name='translit_name' value='1' /> Транслит</label><br />n";
echo "<img src='img/joke.png' /> <span style='font-size:small;color:darkblue'><b>Описание</b> (1024 знакa)</span><br/><input type='text' name='text' value='$cat[text]' rows='5' cols='30'/> <br />n";
if ($user['set_translit']==1)echo "<label><input type='checkbox' name='translit_text' value='1' /> Транслит</label><br />n";
echo "<input type='submit' value='Сохранить' name='ok' /><br /></form>
<div class='block_hr'></div><div class='row4'>[<a href='?del_cat=$cat[id]'><span style='color:red'>×</span> удалить</a>]</div>n";
echo "<a href='?cat=$cat[id]'><div class='gmenu'><img src='img/back.png'> Назад</div></a>n";
}
else header("Location: ?categories");
}
elseif(isset($_GET['edit_joke']))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes` WHERE `id` = '".intval($_GET['edit_joke'])."' LIMIT 1"),0)!=0)
{
$joke=mysql_fetch_array(mysql_query("SELECT * FROM `jokes` WHERE `id` = '".intval($_GET['edit_joke'])."' LIMIT 1"));
$avtor=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$joke[id_user]' LIMIT 1"));
if($user['id']==$avtor['id'] && $joke['time']>time()-600 || $user['level']>0)
{
if(isset($_POST['ok']))
{
$text=$_POST[text];
$text=esc(stripcslashes(htmlspecialchars($_POST['text'])));
if (isset($_POST['translit_text']) && $_POST['translit_text']==1)$text=translit($text);
if(strlen2($text)>100000)
{
$err='';
echo "<div class='err'><img src='img/err.png' /> Анекдот слишком длинный</div>n";
}
if(strlen2($text)<5)
{
$err='';
echo "<div class='err'><img src='img/err.png' /> Анекдот слишком короткий</div>n";
}
$text=my_esc($text);
if(!isset($err))
{
mysql_query("UPDATE `jokes` SET `text` = '$text' WHERE `id` = '$joke[id]' LIMIT 1");
header("Location:?joke=$joke[id]");
}
}
echo "<form method='post' action='?edit_joke=$joke[id]'>n";
echo "<img src='img/joke.png' /> <span style='font-size:small;color:darkblue'><b>Анекдот</b> (от 5 до 100000 знаков)</span><br/><textarea name='text' rows='5' cols='30'>$joke[text]</textarea> <br />n";
if ($user['set_translit']==1)echo "<label><input type='checkbox' name='translit_text' value='1' /> Транслит</label><br />n";
echo "<input type='submit' value='Сохранить' name='ok' /><br/>n";
}
else echo "<img src='img/err.png' /> У Вас нет прав на даное действие!n";
echo "<a href='?joke=$joke[id]'><div class='gmenu'><img src='img/back.png'> Назад</div></a>n";
}
else header("Location:/jokes");
}
elseif(isset($_GET['del_cat']))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes_cat` WHERE `id` = '".intval($_GET['del_cat'])."' LIMIT 1"),0)!=0)
{
$cat=mysql_fetch_array(mysql_query("SELECT * FROM `jokes_cat` WHERE `id` = '".intval($_GET['del_cat'])."' LIMIT 1"));
if($user['level']>0)
{
echo "<center><img src='img/err.png' /> Вы уверены, что хотите удалить этот раздел?<br />
<small>[<a style='color:red' href='?del_cat_ok=$_GET[del_cat]'>Да</a>]</small> [<a style='color:blue' href='?categories'>Нет</a>]</center><br />n";
}
else echo "<img src='img/err.png' /> У Вас нет прав на даное действие!n";
echo "<a href='?categories'><div class='gmenu'><img src='img/back.png'> Назад</div></a>n";
}
else header("Location:/jokes");
}
elseif(isset($_GET['del_cat_ok']))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes_cat` WHERE `id` = '".intval($_GET['del_cat_ok'])."' LIMIT 1"),0)!=0)
{
$cat=mysql_fetch_array(mysql_query("SELECT * FROM `jokes_cat` WHERE `id` = '$_GET[del_cat_ok]' LIMIT 1"));
if($user['level']>0)
{
mysql_query("DELETE FROM `jokes` WHERE `cat` = '$_GET[del_cat_ok]'");
mysql_query("DELETE FROM `jokes_cat` WHERE `id` = '$_GET[del_cat_ok]'");
header("location: ?categories");
}
else echo "<img src='img/err.png' /> У Вас нет прав на даное действие!n";
}
else header("location: /jokes");
}
elseif(isset($_GET['del_joke']))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes` WHERE `id` = '$_GET[del_joke]' LIMIT 1"),0)!=0)
{
$joke=mysql_fetch_array(mysql_query("SELECT * FROM `jokes` WHERE `id` = '$_GET[del_joke]' LIMIT 1"));
if($user['id']==$joke['id_user'] && $joke['time']>time()-600 || $user['level']>0)
{
echo "<center>Вы уверены, что хотите удалить этот анекдот?<br />
<small>[<a style='color:red' href='?del_joke_ok=$_GET[del_joke]'>Да</a>]</small> [<a style='color:blue' href='?joke=$_GET[del_joke]'>Нет</a>]</center><br />n";
}
else echo "<img src='img/err.png' /> У Вас нет прав на даное действие!n";
echo "<a href='?joke=$_GET[del_joke]'><div class='gmenu'><img src='img/back.png'> Назад</div></a>n";
}
else header("Location:/jokes");
}
elseif(isset($_GET['del_joke_ok']))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes` WHERE `id` = '$_GET[del_joke_ok]' LIMIT 1"),0)!=0)
{
$joke=mysql_fetch_array(mysql_query("SELECT * FROM `jokes` WHERE `id` = '$_GET[del_joke_ok]' LIMIT 1"));
$_SESSION['mother_joke_del']=$joke['cat'];
if($user['id']==$joke['id_user'] && $joke['time']>time()-600 || $user['level']>0)
{
mysql_query("DELETE FROM `jokes` WHERE `id` = '$_GET[del_joke_ok]'");
$back=$_SESSION['mother_joke_del'];
header("location: /jokes/?cat=$back");
}
else echo "<img src='img/err.png' /> У Вас нет прав на даное действие!n";
}
else header("location: /jokes");
}
elseif(isset($_GET['o_k']) && isset($user))
{
if(!isset($user))header("Location:/aut.php");
if(isset($_GET['o_k']))$o_k=$_GET[o_k];
$komm=mysql_fetch_array(mysql_query("SELECT * FROM `jokes_komm` WHERE `id` = '$o_k' LIMIT 1"));
$komm_mother=mysql_fetch_array(mysql_query("SELECT * FROM `jokes` WHERE `id` = '$komm[id_joke]' LIMIT 1"));
$komm_avtor=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$komm[id_user]' LIMIT 1"));
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes` WHERE `id` = '$komm_mother[id]' LIMIT 1"),0)==0)echo "<img src='img/err.png' /> Error!n";
elseif(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes_komm` WHERE `id` = '$o_k' LIMIT 1"),0)==0)echo "<img src='img/err.png' /> Комментарий не найденn";
else
{
if(isset($_POST['msg_otvet']))
{
$msg=esc(stripcslashes(htmlspecialchars($_POST['msg_otvet'])));
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
if (strlen2($msg)>1024)
{
$err='';
echo "<img src='img/err.png' /> Сообщение слишком длинноe<br/>";}
elseif (strlen2($msg)<2)
{
$err='';
echo "<img src='img/err.png' /> Короткое сообщение<br/>";
}
elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes_komm` WHERE `id_joke` = '$komm_mother[id]' AND `id_user` = '$user[id]' AND `msg` = '".mysql_real_escape_string($msg)."' LIMIT 1"),0)!=0)
{
$err='';
echo "<img src='img/err.png' /> Ваше сообщение повторяет предыдущее<br/>";}
else
{
mysql_query("INSERT INTO `jokes_komm` (`id_joke`, `id_user`, `time`, `msg`, `id_otvet`) values('$komm_mother[id]', '$user[id]', '$time', '".my_esc($msg)."', '$komm_avtor[id]')");
if($user['id']!=$komm_avtor['id'])
{
if($user['pol']==1)$pol='оставил'; else $pol='оставила';
mysql_query("INSERT INTO `jurnal` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$komm_avtor[id]', '[url=/info.php?$user[id]]$user[nick][/url] $pol ответил на ваше сообщени в [url=/jokes/?joke=$komm_mother[id]]этом[/url] анекдоте', '$time')");
}
if($komm_mother['id_user']!=$user['id'])
{
if($user['pol']==1)$pol='оставил'; else $pol='оставила';
mysql_query("INSERT INTO `jurnal` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$komm_mother[id_user]', '[url=/info.php?id=$user[id]]$user[nick][/url] $pol комментарий в [url=/jokes/?joke=$komm_mother[id]]вашем анекдоте[/url]', '$time')");
}
header("Location: /jokes/?joke=$komm_mother[id]");
}
}
echo "$komm_avtor[nick] написал:<br/>
$komm[msg]n";
echo "<form method='post' name='msg_otvet' action='?o_k=$komm[id]' >n";
echo "<img src='img/joke.png' /> <span style='font-size:small;color:darkblue'><b>Сообщение</b> (1024 знаков)</span><br /><textarea name='msg_otvet'></textarea><br />n";
if ($user['set_translit']==1)echo "<label><input type='checkbox' name='translit' value='1' /> Транслит</label><br />n";
echo "<input value='Отправить' type='submit' />n";
echo "</form>n";
}
echo "<a href='?joke=$komm_mother[id]'><div class='gmenu'><img src='img/back.png'> Назад</div></a>n";
}
elseif(isset($_GET['categories']))
{
echo "<a href='/jokes'><div class='gmenu'><img src='img/back.png'> Анекдоты</div></a>n";
$list = mysql_query("SELECT * FROM `jokes_cat` ORDER BY `name` DESC");
if (mysql_num_rows($list)==0)
{
echo "<br/> <tr>n";
echo " <td class='p_t'>n";
echo "Категорий ещо никто не создавал<br/>n";
echo " </td>n";
echo " </tr>n";
}
while ($cat = mysql_fetch_array($list))
{
if($num==1){
echo "<div class='post'>";
$num=0;
}else{
echo "<div class='post'>";
$num=1;}
$k_a = mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes` WHERE `cat` = '$cat[id]'"),0);
$k_a_n= mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes` WHERE `time` > '".(time()-86400)."' AND `cat` = '$cat[id]'"),0);
if ($k_a_n==0)$k_a_n=NULL;
else $k_a_n='/+'.$k_a_n;
if(isset($_GET['move']))$move=$_GET['move'];
if(isset($_GET['move']) && $user['level']>0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes` WHERE `id` = '$move' LIMIT 1"),0)!=0)
{
$move = mysql_fetch_array(mysql_query("SELECT * FROM `jokes` WHERE `id` = '$move' LIMIT 1"));
echo "<span style='color:red'>>></span> <a href='?cat=$cat[id]&move_ok=$move[id]'>$cat[name]</a>n";
}
else echo "<img src='img/cat.png' /> <a href='?cat=$cat[id]'>$cat[name]</a> [$k_a$k_a_n]n";
if($user['level']>0)
{
echo " <a class='icolink' href='?del_cat=$cat[id]' title='удалить' style='color:red;font-size:small'><b>x</b></a>n";
echo " | <a class='icolink' href='?edit_cat=$cat[id]' title='редактировать' style='color:green;font-size:small'><b>ред</b></a>n";
}
if(strlen2($cat['text'])>0)echo "<br/><span style='font-size:small'>$cat[text]</span>n";
echo "</div>n";
}
if($user['level']>0)echo "<a href='?add_cat'><div class='gmenu'><img src='img/add.png'> Добавить категорию</a></div>n";
echo "<a href='/jokes'><div class='gmenu'><img src='img/back.png'> Анекдоты</div></a>n";
}
elseif(isset($_GET['new']))
{
echo "<div class='main'><div class='backlink'><img src='img/back.png' alt=''/><a href='/jokes'>Анекдоты</a></div><img src='img/new.png' /> <b>Новые анекдоты</b>n";
$list = mysql_query("SELECT * FROM `jokes` WHERE `time` > '".(time()-86400)."' ORDER BY `time` DESC");
if (mysql_num_rows($list)==0)
{
echo "<br/> <tr>n";
echo " <td class='p_t'>n";
echo "Анекдотов ещо никто не создавал<br/>n";
echo " </td>n";
echo " </tr>n";
}
while ($a = mysql_fetch_array($list))
{
if($num==1){
echo "<div class='post'>";
$num=0;
}else{
echo "<div class='post'>";
$num=1;}
echo "<img src='img/joke.png' /> n";
$tmp = cut_joke($a['text']);
echo $tmp."...n";
echo "<a href='?joke=$a[id]'><span style='color:#eb7400'>читать дальше</span> <img src='img/arrow.png' /></a>n";
echo "</div>n";
}
echo "<a href='/jokes'><div class='gmenu'><img src='img/back.png'> Анекдоты</div></a>n";
}
elseif(isset($_GET['top_in_cat']))
{
$cat=mysql_fetch_array(mysql_query("SELECT * FROM `jokes_cat` WHERE `id` = '$_GET[top_in_cat]' LIMIT 1"));
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes_cat` WHERE `id` = '$cat[id]' LIMIT 1"),0)!=0)
{
echo "<div class='gmenu'><div class='backlink'><img src='img/back.png' alt=''/><a href='?cat=$cat[id]'>$cat[name]</a></div><img src='img/new.png' /> <b>ТОП-10 анекдотов в ''$cat[name]''</b>n";
$list = mysql_query("SELECT * FROM `jokes` WHERE `cat` = '$cat[id]' ORDER BY `rating` DESC LIMIT 10");
if (mysql_num_rows($list)==0)
{
echo "<br/> <tr>n";
echo " <td class='p_t'>n";
echo "Анекдотов ещо никто не создавал<br/>n";
echo " </td>n";
echo " </tr>n";
}
while ($a = mysql_fetch_array($list))
{
if($num==1){
echo "<div class='post'>";
$num=0;
}else{
echo "<div class='post'>";
$num=1;}
echo "<img src='img/joke.png' /> n";
$tmp = cut_joke($a['text']);
echo $tmp."...n";
echo "<a href='?joke=$a[id]'><span style='color:#eb7400'>читать дальше</span> <img src='img/arrow.png' /></a>n";
echo "</div>n";
}
echo "<a href='?cat=$cat[id]'><div class='gmenu'><img src='img/back.png'> $cat[name]</div></a>n";
}
else echo "<img src='img/err.png' /> Категория не найденаn";
}
elseif(isset($_GET['new_in_cat']))
{
$cat=mysql_fetch_array(mysql_query("SELECT * FROM `jokes_cat` WHERE `id` = '$_GET[new_in_cat]' LIMIT 1"));
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes_cat` WHERE `id` = '$cat[id]' LIMIT 1"),0)!=0)
{
echo "<div class='main'><div class='backlink'><img src='img/back.png' alt=''/><a href='?cat=$cat[id]'>$cat[name]</a></div><img src='img/new.png' /> <b>Новые анекдоты в ''$cat[name]''</b>n";
$list = mysql_query("SELECT * FROM `jokes` WHERE `cat` = '$cat[id]' AND `time` > '".(time()-86400)."' ORDER BY `time` DESC");
if (mysql_num_rows($list)==0)
{
echo "<br/> <tr>n";
echo " <td class='p_t'>n";
echo "Анекдотов ещо никто не создавал<br/>n";
echo " </td>n";
echo " </tr>n";
}
while ($a = mysql_fetch_array($list))
{
if($num==1){
echo "<div class='post'>";
$num=0;
}else{
echo "<div class='post'>";
$num=1;}
echo "<img src='img/joke.png' /> n";
$tmp = cut_joke($a['text']);
echo $tmp."...n";
echo "<a href='?joke=$a[id]'><span style='color:#eb7400'>читать дальше</span> <img src='img/arrow.png' /></a>n";
echo "</div>n";
}
echo "<a href='?cat=$cat[id]'><div class='gmenu'><img src='img/back.png'> $cat[name]</div></a>n";
}
else echo "<img src='img/err.png' /> Категория не найденаn";
}
elseif(isset($_GET['cat']))
{
$k_post=mysql_result(mysql_query("SELECT * FROM `jokes_cat` WHERE `id` = '$_GET[cat]' ORDER BY time"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$cat=mysql_fetch_array(mysql_query("SELECT * FROM `jokes_cat` WHERE `id` = '$_GET[cat]' LIMIT $start, $set[p_str]"));
if(isset($_GET['move_ok']) && $user['level']>0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes` WHERE `id` = '$_GET[move_ok]' LIMIT 1"),0)!=0)
{
$move=$_GET[move_ok];
$move = mysql_fetch_array(mysql_query("SELECT * FROM `jokes` WHERE `id` = '$move' LIMIT 1"));
mysql_query("UPDATE `jokes` SET `cat` = '$cat[id]' WHERE `id` = '$move[id]' LIMIT 1");
header("Location: ?joke=$move[id]");
}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes_cat` WHERE `id` = '$cat[id]' LIMIT 1"),0)!=0)
{
echo "<div class='main'><div class='backlink'><img src='img/back.png' alt=''/><a href='?categories'>Категории</a></div><img src='img/cat.png' /> <b>$cat[name]</b> | <a href='?new_in_cat=$cat[id]'><img src='img/new.png' /> Новые</a> | <a href='?top_in_cat=$cat[id]'><img src='img/top.png' /> ТОП-10</a>n";
$list = mysql_query("SELECT * FROM `jokes` WHERE `cat` = '$cat[id]' ORDER BY `time` DESC");
if (mysql_num_rows($list)==0)
{
echo "<br/> <tr>n";
echo " <td class='p_t'>n";
echo "Анекдотов ещо никто не создавал<br/>n";
echo " </td>n";
echo " </tr>n";
}
while ($a = mysql_fetch_array($list))
{
if($num==1){
echo "<div class='post'>";
$num=0;
}else{
echo "<div class='post'>";
$num=1;}
echo "<img src='img/joke.png' /> n";
$tmp = cut_joke($a['text']);
echo $tmp."...n";
echo "<a href='?joke=$a[id]'><span style='color:#eb7400'>читать дальше</span> ></a>n";
echo "</div>n";
}
if ($k_page>1)str("/jokes/?cat=$cat[id]&",$k_page,$page); // Вывод страниц
if(isset($user))echo "<a href='?add_joke=$cat[id]'><div class='gmenu'><img src='img/add.png'> Добавить анекдот</div></a>n";
echo "<a href='?categories'><div class='gmenu'><img src='img/back.png'> Категории</div></a>n";
}
else echo "<img src='img/err.png' /> Категория не найденаn";
}
elseif(isset($_GET['rand']))
{
echo "<div class='main'><div class='backlink'><img src='img/back.png' alt=''/><a href='/jokes'>Анекдоты</a></div><br/><img src='img/rand.png' /> <b>Случайный анекдот</b>n";
$list = mysql_query("SELECT * FROM `jokes` ORDER BY rand() LIMIT 4");
if (mysql_num_rows($list)==0)
{
echo " <tr>n";
echo " <td class='p_t'>n";
echo "Анекдотов ещо никто не создавал<br/>n";
echo " </td>n";
echo " </tr>n";
}
while ($a = mysql_fetch_array($list))
{
if($num==1){
echo "<div class='post'>";
$num=0;
}else{
echo "<div class='post'>";
$num=1;}
echo "<img src='img/joke.png' /> n";
$tmp = cut_joke($a['text']);
echo $tmp."...n";
echo "<a href='?joke=$a[id]'><span style='color:#eb7400'>читать дальше</span> <img src='img/arrow.png' /></a>n";
echo "</div>n";
}
echo "<a href='/jokes'><div class='gmenu'><img src='img/back.png'> Анекдоты</div></a>n";
}
elseif(isset($_GET['top']))
{
echo "<div class='main'><div class='backlink'><img src='img/back.png' alt=''/><a href='/jokes'>Анекдоты</a></div><img src='img/top.png' /> <b>ТОП-10 лучших анекдотов</b>n";
$list = mysql_query("SELECT * FROM `jokes` ORDER BY rating DESC LIMIT 10");
if (mysql_num_rows($list)==0)
{
echo "<br/> <tr>n";
echo " <td class='p_t'>n";
echo "Анекдотов ещо никто не создавал<br/>n";
echo " </td>n";
echo " </tr>n";
}
while ($a = mysql_fetch_array($list))
{
if($num==1){
echo "<div class='post'>";
$num=0;
}else{
echo "<div class='post'>";
$num=1;}
echo "<img src='img/joke.png' /> n";
$tmp = cut_joke($a['text']);
echo $tmp."...n";
echo "<a href='?joke=$a[id]'><span style='color:#eb7400'>читать дальше</span> <img src='img/arrow.png' /></a>n";
echo "</div>n";
}
echo "<a href='/jokes'><div class='gmenu'><img src='img/back.png'> Анекдоты</div></a>n";
}
//////////////////
elseif(isset($_GET['joke']))
{
$joke=mysql_fetch_array(mysql_query("SELECT * FROM `jokes` WHERE `id` = $_GET[joke] LIMIT 1"));
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes` WHERE `id` = '$joke[id]' LIMIT 1"),0)!=0)
{
if(isset($_GET['rating']) && $_GET['rating']=='plus' || isset($_GET['rating']) && $_GET['rating']=='minus')
{
$prov=mysql_result(mysql_query("SELECT COUNT(*) FROM `joke_oprosen` WHERE `id_joke` = '$joke[id]' AND `id_user`='$user[id]' ",$db), 0);
if($prov==0)
{
if($_GET['rating']=='plus')
{
mysql_query("INSERT INTO `joke_oprosen` (`id_user`, `id_joke`, `time`, `msg`) values('$user[id]', '$joke[id]', '$time', '+1')");
mysql_query("UPDATE `jokes` SET `rating`='".($joke['rating']+1)."' WHERE `id`='$joke[id]' LIMIT 1");
header("Location:/jokes/?joke=$joke[id]");
}
elseif($_GET['rating']=='minus')
{
mysql_query("INSERT INTO `joke_oprosen` (`id_user`, `id_joke`, `time`, `msg`) values('$user[id]', '$joke[id]', '$time', '-1')");
mysql_query("UPDATE `jokes` SET `rating`='".($joke['rating']-1)."' WHERE `id`='$joke[id]' LIMIT 1");
header("Location:/jokes/?joke=$joke[id]");
}
}
else echo "Вы уже отдали свой голос раньше!n";
}
elseif(isset($_GET['who_oprosen']))
{
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `joke_oprosen` WHERE `id_joke` = '$joke[id]'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$q=mysql_query("SELECT * FROM `joke_oprosen` WHERE `id_joke` = '$joke[id]' ORDER BY `id` ASC LIMIT $start, $set[p_str]");
if (mysql_num_rows($q)==0)
{
echo "Никто ещо отдал своего голоса!n";
}
while ($post = mysql_fetch_assoc($q))
{
if($num==1){
echo "<div class='post'>";
$num=0;
}else{
echo "<div class='post'>";
$num=1;}
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $post[id_user] LIMIT 1"));
echo "".status($ank['id'])."<a href='/info.php?id=$ank[id]'><b>$ank[nick]</b></a> ".medal($ank['id'])."".vip($ank['id'])."".wap_web($ank['id'])." ($post[msg]) [".vremja($post['time'])."]<br/>n";
echo "</div>";
}
if ($k_page>1)str("/jokes/?joke=$joke[id]&who_oprosen&",$k_page,$page); // Вывод страниц
echo "<a href='?joke=$joke[id]'><div class='gmenu'><img src='img/back.png'> Назад</div></a>n";
}
else
{
$mother=mysql_fetch_array(mysql_query("SELECT * FROM `jokes_cat` WHERE `id` = '$joke[cat]' LIMIT 1"));
echo "<a href='?cat=$mother[id]'><div class='gmenu'><img src='img/back.png'> $mother[name]</div></a>n";
$avtor=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $joke[id_user] LIMIT 1"));
if (isset($_POST['msg']) && isset($user))
{
$msg=esc(stripcslashes(htmlspecialchars($_POST['msg'])));
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
if (strlen2($msg)>1024){$err='';echo "<img src='img/err.png' /> Сообщение слишком длинное<br/>";}
elseif (strlen2($msg)<2){$err='';echo "<img src='img/err.png' /> Короткое сообщение<br/>";}
elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes_komm` WHERE `id_joke` = '$joke[id]' AND `id_user` = '$user[id]' AND `msg` = '".mysql_real_escape_string($msg)."' LIMIT 1"),0)!=0){$err='';echo "<img src='img/err.png' /> Ваше сообщение повторяет предыдущее<br/>";}
else
{
mysql_query("INSERT INTO `jokes_komm` (`id_joke`, `id_user`, `time`, `msg`) values('$joke[id]', '$user[id]', '$time', '".my_esc($msg)."')");
if($joke['id_user']!=$user['id'])
{
if($user['pol']==1)$pol='оставил'; else $pol='оставила';
mysql_query("INSERT INTO `jurnal` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$joke[id_user]', '[url=/info.php?id=$user[id]]$user[nick][/url] $pol комментарий в [url=/jokes/?joke=$joke[id]]вашем анекдоте[/url]', '$time')");
}
header("Location:/jokes/?joke=$joke[id]");
}
}
elseif(isset($_GET['del_komm']) && $user['level']>0)
{
$komm=$_GET['del_komm'];
$komm=mysql_fetch_array(mysql_query("SELECT * FROM `jokes_komm` WHERE `id` = '$komm' LIMIT 1"));
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes_komm` WHERE `id` = '$komm[id]' LIMIT 1"),0)!=0)
{
mysql_query("DELETE FROM `jokes_komm` WHERE `id` = '$komm[id]'");
header("location: /jokes/?joke=$joke[id]");
}
else header("Location:/jokes");
}
echo "".status($avtor['id'])."<a href='/info.php?id=$avtor[id]'><b>$avtor[nick]</b></a> ".medal($avtor['id'])."".vip($avtor['id'])."".wap_web($avtor['id'])." ".vremja($joke['time'])."<br/>n";
echo esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($joke['text']))))))))."<br/><span style='color:#79358c'><b><center><img src='img/joke.png' /> Рейтинг анекдота: $joke[rating]</center></b></span>n";
$prov=mysql_result(mysql_query("SELECT COUNT(*) FROM `joke_oprosen` WHERE `id_joke` = '$joke[id]' AND `id_user`='$user[id]' ",$db), 0);
if($prov==0)echo "<br/><a href='?joke=$joke[id]&rating=minus'><img src='img/minus.png'></a> | <a href='?joke=$joke[id]&rating=plus'><img src='img/plus.png'></a>n";
echo "<a href='?joke=$joke[id]&who_oprosen'><span style='color:#79358c'>Кто проголосовал?</span></a><br/>";
if($user['id']==$avtor['id'] && $joke['time']>time()-600 || $user['level']>0)
{
echo "<br/><img src='img/del.png' /> <a class='icolink' href='?del_joke=$joke[id]' title='удалить' style='color:red;font-size:small'><b>Удалить</b></a>n";
echo "<br/><img src='img/edit.png' /> <a class='icolink' href='?edit_joke=$joke[id]' title='ред' style='color:green;font-size:small'><b>Pедактировать</b></a>n";
}
if($user['level']>0)echo "<br/><img src='img/replace.png' /> <a class='icolink' href='?categories&move=$joke[id]' title='переместить' style='color:green;font-size:small'><b>Переместить</b></a>n";
$count_komm = mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes_komm` WHERE `id_joke` = '$joke[id]'"),0);
$joke_next = mysql_query("SELECT * FROM `jokes` WHERE `time` > '$joke[time]' AND `cat` = '$joke[cat]' ORDER BY `time` ASC LIMIT 1");
$joke_last = mysql_query("SELECT * FROM `jokes` WHERE `time` < '$joke[time]' AND `cat` = '$joke[cat]' ORDER BY `time` DESC LIMIT 1");
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes` WHERE `time` < '$joke[time]' AND `cat` = '$joke[cat]' LIMIT 1"),0)!=0 || mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes` WHERE `time` > '$joke[time]' AND `cat` = '$joke[cat]' LIMIT 1"),0)!=0)echo "<div class='block_hr'></div>n";
echo "<div class='row4' style='font-weight: bold; font-size: small; text-align:center'>n";
while ($hl = mysql_fetch_array($joke_last))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes` WHERE `time` < '$joke[time]' AND `cat` = '$joke[cat]' LIMIT 1"),0)!=0)echo "<a href='?joke=$hl[id]'><img src='img/last.png' class='icon' />Пред.</a>n";
}
while ($hn = mysql_fetch_array($joke_next))
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes` WHERE `time` > '$joke[time]' AND `cat` = '$joke[cat]' LIMIT 1"),0)!=0)echo " <a href='?joke=$hn[id]'>След.<img src='img/next.png' class='icon' /></a>n";
}
echo "</div>n";
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes` WHERE `time` < '$joke[time]' AND `cat` = '$joke[cat]' LIMIT 1"),0)!=0 || mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes` WHERE `time` > '$joke[time]' AND `cat` = '$joke[cat]' LIMIT 1"),0)!=0)echo "<div class='block_hr'></div>n";
echo "<div style='color: #b40000; font-size: small'><img src='img/joke.png' /> Комментариев: $count_komm</div>n";
echo "</div>n";
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `jokes_komm` WHERE `id_joke` = '$joke[id]' ORDER BY time"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$komm_list = mysql_query("SELECT * FROM `jokes_komm` WHERE `id_joke` = '$joke[id]' ORDER BY time ASC LIMIT $start, $set[p_str]");
if (mysql_num_rows($komm_list)==0) {
echo " <tr>n";
echo " <td class='p_t'>n";
echo "Нет комментариев в анекдотеn";
echo " </td>n";
echo " </tr>n";
}
while ($post = mysql_fetch_array($komm_list))
{
if($num==1){
echo "<div class='post'>";
$num=0;
}else{
echo "<div class='post'>";
$num=1;}
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $post[id_user] LIMIT 1"));
echo "".status($ank['id'])."<a href='/info.php?id=$ank[id]'><b>$ank[nick]</b></a> ".medal($ank['id'])."".vip($ank['id'])."".wap_web($ank['id'])." [".vremja($post['time'])."]<br/>n";
$komm_otvet=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$post[id_otvet]' LIMIT 1"));
if($post['id_otvet']>0)
echo "Ответ для $komm_otvet[nick]:<br/>n";
echo esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($post['msg']))))))))."<br/>n";
if(isset($user))echo " <a href='?o_k=$post[id]'>[oтвет]</a>n";
if($user['level']>0)echo " <a href='?joke=$joke[id]&del_komm=$post[id]'>[удалить]</a>n";
echo "</div>n";
}
if ($k_page>1)str("/jokes/?joke=$joke[id]&",$k_page,$page); // Вывод страниц
if(isset($user))
{
echo "<form method='post' name='msg' action='?joke=$joke[id]'>n";
if ($set['web'] && is_file(H.'style/themes/'.$set['set_them'].'/altername_post_form.php'))
include_once H.'style/themes/'.$set['set_them'].'/altername_post_form.php';
else echo "Сообщение:<br /><textarea name='msg'></textarea><br />n";
if ($user['set_translit']==1)echo'<label><input type="checkbox" name="translit" value="1" /> Транслит</label><br />';
echo "<input value='Отправить' type='submit' />n";
echo "</form>n";
}
echo "<a href='?cat=$mother[id]'><div class='gmenu'><img src='img/back.png'> $mother[name]</div></a>";}
}
else echo "<img src='img/err.png' /> Анекдот ненайденn";
}
//////////////////
else
{
echo "<img src='img/new.png' /> <a href='?new'>Новые</a> | <img src='img/top.png' /> <a href='?top'>ТОП-10</a>n";
echo "<span style='color:#79358c'><b><center>Лучший анекдот:</center></b></span>n";
$list = mysql_query("SELECT * FROM `jokes` ORDER BY rating DESC LIMIT 1");
if (mysql_num_rows($list)==0)
{
echo "<br/> <tr>n";
echo " <td class='p_t'>n";
echo "Анекдотов ещо никто не создавал<br/>n";
echo " </td>n";
echo " </tr>n";
}
while ($a = mysql_fetch_array($list))
{
echo "<div class='post'>";
echo "<img src='img/joke.png' /> n";
$tmp = cut_joke($a['text']);
echo $tmp."...n";
echo "<a href='?joke=$a[id]'><span style='color:#eb7400'>читать дальше</span> <img src='img/arrow.png' /></a>n";
echo "</div>n";
}
echo "<div class='block_hr'></div><span style='color:#79358c'><b><center>Случайный анекдот:</center></b></span>n";
$list = mysql_query("SELECT * FROM `jokes` ORDER BY rand() LIMIT 1");
if (mysql_num_rows($list)==0)
{
echo "<br/> <tr>n";
echo " <td class='p_t'>n";
echo "Анекдотов ещо никто не создавал<br/>n";
echo " </td>n";
echo " </tr>n";
}
while ($a = mysql_fetch_array($list))
{
echo "<div class='post'>";
echo "<img src='img/rand.png' /> n";
$tmp = cut_joke($a['text']);
echo $tmp."...n";
echo "<a href='?joke=$a[id]'><span style='color:#eb7400'>читать дальше <img src='img/arrow.png' /></span></a>n";
echo "</div>n";
echo "<img src='img/jokes.png' /> <a href='?rand'><span style='color:#79358c'><b>Ещё анекдоты...</b></span></a>n";
}
echo "<br/><img src='img/cat.png' /> <a href='?categories'><span style='color:#79358c'><b>Анекдоты по категориям</b></span></a>n";
}
include_once '../sys/inc/tfoot.php';
?>