View file vopr.php

File size: 12.1Kb
<?php

/*
////////////////////////////////////////////////////////////////////////////////
// JohnCMS                             Content Management System              //
// Официальный сайт сайт проекта:      http://johncms.com                     //
// Дополнительный сайт поддержки:      http://gazenwagen.com                  //
////////////////////////////////////////////////////////////////////////////////
// JohnCMS core team:                                                         //
// Евгений Рябинин aka john77          [email protected]                  //
// Олег Касьянов aka AlkatraZ          [email protected]                //
//                                                                            //
// Информацию о версиях смотрите в прилагаемом файле version.txt              //
////////////////////////////////////////////////////////////////////////////////
*/

define('_IN_JOHNCMS', 1);
$headmod = '';
$textl = 'Вопросы';
require_once('../incfiles/core.php');
require_once('../incfiles/head.php');
$set = mysql_fetch_array(mysql_query("SELECT * FROM voprset"));
echo "<div class='phdr'  align=''>Вопросы</div>";
if ($user_id){
$q = mysql_query("SELECT * FROM users WHERE id = '$user_id' ");
$us = mysql_fetch_array($q);
echo "<div class='phdr'>У вас <a href='?mod=vivod'>".$us[money]."</a> монет</div>";
}
if(!empty($_GET[mod]))echo '<div class="phdr"><a href="vopr.php">К разделам</a></div>';


 switch($_GET[mod]){
 default:
 $query = mysql_query("SELECT * FROM vopr WHERE type = 'cat' ");
 $colmes = mysql_num_rows($query);
 $query = mysql_query("SELECT * FROM vopr WHERE type = 'cat' ");
 while($arr=mysql_fetch_array($query)){
     echo '<div class="menu"><a href="vopr.php?mod=ocat&amp;id='.$arr[id].'">'.$arr[text].'</a> ';
	 if($rights >= '6') echo '<a href="vopr.php?mod=act&amp;d=del&amp;id='.$arr[id].'">Удалить</a>';
	 echo '</div>';
	  }
	
break;

case 'vivod':
if($user_id){
$us = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE id = '$user_id' "));

if(empty($_POST[sum])){
echo '<div class="phdr">Минимальная сумма к выводу '.$set[min].'руб.</div>';

if($set[min] > $us[money]){
echo 'У вас недостаточно средств для вывода';
} else {
echo '<form method="post">Сумма к выводу <input name="sum" value="'.$us[money].'"><br />
<input type="submit" value="Заказать выплату">
</form>';
}

} else {
$mon = abs($_POST[sum]);

if($set[min] > $mon){
echo 'У вас недостаточно средств для вывода';
} else {
mysql_query("UPDATE users SET money = money - $mon WHERE id = $user_id");
mysql_query("INSERT INTO vivod SET who = '$user_id', sum = '$mon'");
echo 'Выплата заказана';
}
}


}

break;

case 'vi':
if($rights >= '6'){
if(!empty($_GET[id])) mysql_query("UPDATE vivod SET status = 'yes' WHERE id = '$_GET[id]' ");
$q = mysql_query("SELECT * FROM vivod WHERE status = 'no' ");
$colmes = mysql_num_rows($query);
$q = mysql_query("SELECT * FROM vivod WHERE status = 'no' LIMIT $start,$kmess ");
while($arr = mysql_fetch_array($q)){
echo 'Выплата ID: '.$arr[id].' | <a href="anketa.php?id='.$arr[who].'">Заказал</a> | '.$arr[sum].'руб. <a href="?mod=vi&amp;id='.$arr[id].'">[x]</a><br />';
}
if ($colmes > $kmess) {
                echo '<p>' . pagenav('vopr.php?', $start, $colmes, $kmess) . '</p>';
                echo '<p><form action="vopr.php" method="get"><input type="text" name="page" size="2"/><input type="submit" value="К странице &amp;gt;&gt;"/></form></p>';
            }

}

break;


case 'ocat':
$id = abs($_GET[id]);			
$query = mysql_query("SELECT * FROM vopr WHERE 	vopid = '$id'");
$colmes = mysql_num_rows($query);
$query = mysql_query("SELECT * FROM vopr WHERE 	vopid = '$id' ORDER BY id DESC LIMIT $start,$kmess");
while($arr = mysql_fetch_array($query)){
echo '<div class="menu"><a href="vopr.php?mod=o&amp;id='.$arr[id].'">'.antilink(checkout($arr['zag'], 0, 2)).'</a></div>';
}
if ($colmes > $kmess) {
                echo '<p>' . pagenav('vopr.php?', $start, $colmes, $kmess) . '</p>';
                echo '<p><form action="vopr.php" method="get"><input type="text" name="page" size="2"/><input type="submit" value="К странице &amp;gt;&gt;"/></form></p>';
            }

 break;

 case 'act':
 if(!$user_id) {
echo 'Доступно только зарегистрированым';
include '../incfiles/end.php';
exit;
}
 $id=abs($_GET[id]);
 if(empty($id)) heder('Location: vopr.php');

 if($_GET[d]=='del'){
 	$q=mysql_query("SELECT * FROM vopr WHERE id = '$id' ");
 	$arr=mysql_fetch_array($q);
 	if($arr[user] != $user_id or $rights >= '6') header('Location: vopr.php?mod=o&amp;id='.$id.'');
 	mysql_query("DELETE FROM vopr WHERE id = '$id' ");
 	header('Location: vopr.php');
 }
 break;
 case 'o':
 if(empty($_GET[id]))header('Location: vopr.php');
 $lid = abs($_GET[l]);
 if(!empty($lid)){
 mysql_query("UPDATE vopr SET zag = 'lu' WHERE id = '$lid' ");
 $us = abs($_GET[us]);
 mysql_query("UPDATE users SET money = money + $set[lu] WHERE id = $us");
 }
 $id = abs($_GET[id]);
 $query = mysql_query("SELECT * FROM vopr WHERE id = '$id'");
 $arr=mysql_fetch_array($query);
 $q=mysql_query("SELECT * FROM users WHERE id='$arr[user]' ");
 $name1=mysql_fetch_array($q);
 echo '<div class="list1">'.antilink(checkout($arr['zag'], 0, 2)).'<br />';
 $usr = $arr[user];
 echo '<a href="anketa.php?id='.$name1[id].'">'.$name1[name].'</a> задал вопрос: <div class="reply">'.antilink(checkout($arr['text'], 0, 2)).'</div></div>';
     $query = mysql_query("SELECT * FROM vopr WHERE zag = 'lu' and vopid = '$id' ");
	 $arr2 = mysql_fetch_array($query);
     $q=mysql_query("SELECT * FROM users WHERE id = '$arr2[user]'");
     $name = mysql_fetch_array($q);
     if(mysql_num_rows($query) != 0) echo '<div class="list1">Лучший ответ <a href="anketa.php?id='.$name[id].'">'.$name[name].'</a><br />'.antilink(checkout($arr2['text'], 0, 2)).'<br />';
	 $query = mysql_query("SELECT * FROM vopr WHERE vopid = '$id' and zag != 'lu' ");
     $colmes = mysql_num_rows($query);
     $query = mysql_query("SELECT * FROM vopr WHERE vopid = '$id' and zag != 'lu' ORDER BY id DESC LIMIT $start,$kmess");
     $lu = mysql_num_rows(mysql_query("SELECT * FROM vopr WHERE vopid = '$arr[id]' AND  zag = 'lu' "));
 while ($arr = mysql_fetch_array($query)) {

 $q=mysql_query("SELECT * FROM users WHERE id = '$arr[user]'");
 $name = mysql_fetch_array($q);
 echo '<div class="list1"><a href="anketa.php?id='.$name[id].'">'.$name[name].'</a><br />'.antilink(checkout($arr['text'], 0, 2));
 if($arr[zag] != 'lu' and $lu == 0  and $user_id == $usr and $user_id != $name[id]) echo '<br /><a href="vopr.php?mod=o&amp;id='.$id.'&amp;l='.$arr[id].'&amp;us='.$arr[user].'">Лучший</a>';
echo ' </div>';
 }

 if($user_id){ echo 'Добавить ответ: <br /><form name="" action="?mod=addotv&amp;ido='.$id.'" method="post"><textarea name="otvet" rows="5" cols="40" wrap="off"></textarea><br /><input type="submit" name="submit" value="Send"></input>';
             if($name1[id] == $user_id or $rights >= '6') echo '<br /><a href="?mod=act&amp;d=del&amp;id='.$id.'">Удалить</a>';
             }
            break;

  case 'addotv':
  if(!$user_id) {
echo 'Доступно только зарегистрированым';
include '../incfiles/end.php';
exit;
}
  $ido=abs($_GET[ido]);
  if(empty($_POST[submit]) or empty($_POST[otvet])) header('Location: vopr.php?mod=o&amp;id='.$id.'');
  if(!empty($_POST[otvet])){
  $text=check($_POST[otvet]);
  $time = time();
  mysql_query("INSERT INTO vopr SET user = '$user_id', text = '$text', vopid = '$ido', time = '$time', type = 'otv' ");
  mysql_query("UPDATE users SET money = money + $set[otv] WHERE id = $user_id");
  header('Location: vopr.php?mod=o&id='.$ido);
  }
  break;

 case 'add':
 if(!$user_id) {
echo 'Доступно только зарегистрированым';
include '../incfiles/end.php';
exit;
}
$tim = time() - (60*60*24);

$query = mysql_query("SELECT * FROM vopr WHERE time > $tim and user = '$user_id' and type = '0' ");
if (mysql_num_rows($query) >= $set[maxvopr]) {
echo 'Лимит вопросов истек.<br /><a href="vopr.php">К вопросам</a>';
require_once('../incfiles/end.php');
exit;
}
 if(empty($_POST[submit])){

     echo '<form name="add" action="?mod=add" method="post">
     Заголовок: <input name="zag" type="text" value="">
     <br /><select name="cat">';
	 $q = mysql_query("SELECT * FROM vopr WHERE type = 'cat' ");
	 while($arr=mysql_fetch_array($q)){
	 echo '<option value="'.$arr[id].'">'.$arr[text].'</option>';
	 }
	 echo '</select><br /> Текст: <input name="text" type="text" value=""><br />
     <input type="submit" value="Send" name="submit">
     ';
    }
  else {
     $zag=mysql_real_escape_string(trim($_POST['zag']));
     $text=mysql_real_escape_string(trim($_POST['text']));
	 $vopid = abs($_POST[cat]);
	 $time = time();
     mysql_query("INSERT INTO vopr SET zag = '$zag', text = '$text', user = '$user_id', vopid = '$vopid', time = '$time' ");
	 mysql_query("UPDATE users SET money = money + $set[vopr] WHERE id = $user_id");
	 header('Location: vopr.php');
	 exit;
  }

 break;
 
 case 'my':
 if(!$user_id) header('Location: vopr.php');
 if($_GET[ver] == 'vopr'){
 $qu = mysql_query("SELECT * FROM vopr WHERE user = '$user_id' and type != 'otv' and type != 'cat' ORDER BY time DESC LIMIT 15");
 while($q = mysql_fetch_array($qu)){
  echo '<div class="menu"><a href="vopr.php?mod=o&amp;id='.$q[id].'">'.$q[zag].'</a></div>';
 }
 }else {
         $qu = mysql_query("SELECT * FROM vopr WHERE user = '$user_id' AND type = 'otv' ORDER BY time DESC LIMIT 15");
 while($q = mysql_fetch_array($qu)){
     $qu2 = mysql_query("Select * From vopr Where id = '$q[vopid]' ");
	 $arr = mysql_fetch_array($qu2);
  echo '<div class="menu"><a href="vopr.php?mod=o&amp;id='.$arr[id].'">'.$q[text].'</a></div>';
 }
          }
 
 break;
 
 case 'new':
 if($_GET[ver] == 'vopr'){
 $qu = mysql_query("SELECT * FROM vopr WHERE type != 'cat' and type != 'otv' ORDER BY time DESC LIMIT 15");
 while($q = mysql_fetch_array($qu)){
  echo '<div class="menu"><a href="vopr.php?mod=o&amp;id='.$q[id].'">'.$q[zag].'</a></div>';
 }
 }else {
         $qu = mysql_query("SELECT * FROM vopr WHERE vopid != '0' AND type = 'otv' ORDER BY time DESC LIMIT 15");
 while($q = mysql_fetch_array($qu)){
     $qu2 = mysql_query("Select * From vopr Where id = '$q[vopid]' ");
	 $arr = mysql_fetch_array($qu2);
  echo '<div class="menu"><a href="vopr.php?mod=o&amp;id='.$arr[id].'">'.$q[text].'</a></div>';
 }
          }
 
 
 break;
 
 case 'addcat':
 if(!$user_id) {
echo 'Доступно только зарегистрированым';
include '../incfiles/end.php';
exit;
}
if($rights >= '6') {
 if(empty($_POST[name])){
     echo '<form action="?mod=addcat" method="post">Имя категории: <input name="name"> <br /><input type="submit" value="Создать"></form></input></input>';
 
     } else {
	 $name=mysql_real_escape_string(trim($_POST['name']));
	 if(mysql_query("INSERT INTO vopr SET text = '$name', type= 'cat' ")) {
	 header('Location: vopr.php');
	 } 
	 else echo "Бляяяяяяяя";
	}
 }
 break;
}

echo "<div class='phdr'>Новые: <a href='vopr.php?mod=new&amp;ver=vopr'>вопросы</a> | <a href='vopr.php?mod=new'>ответы</a></div>";

if($user_id)echo "<div class='phdr'>Мои: <a href='vopr.php?mod=my&amp;ver=vopr'>вопросы</a> | <a href='vopr.php?mod=my'>ответы</a></div>";
if (!$_GET[mod]) if($rights >= '6') echo '<br /><a href="vopr.php?mod=addcat">Добавить категорию</a><br /> <a href="voprset.php">Настройки</a><br /> <a href="?mod=vi">Запросы на вывод</a>';
if($_GET[mod] != 'add')echo '<br /><a href="vopr.php?mod=add">Добавить</a>';
require_once('../incfiles/end.php');

?>