Просмотр файла chat_bot.php

Размер файла: 1.93Kb
<?php
if (!strpos($_SERVER['SCRIPT_NAME'],substr(session_id(),(strlen(session_id())/2),strlen(session_id())).session_id().substr(session_id(),0,(strlen(session_id())/2)).'/index.php'))
    {
     header('location: http://'.$_SERVER['SERVER_NAME'].'/'); exit();
    }
$vposts = $idu->vposts;
$vict = mysql_fetch_object(mysql_query('SELECT * FROM `chat_vopros` WHERE `id` = "1"'));
$nq = mysql_query('SELECT * FROM `'.$px.$qtable.'`');
$num_ques = mysql_num_rows($nq);

$rand1 = $vict->vopros;
if (empty($rand1)) {$rand1 = rand(1,$num_ques);}
$ques = mysql_fetch_object(mysql_query('SELECT * FROM `'.$px.$qtable.'` WHERE `id` = "'.intval($rand1).'"'));

$nv = $ques->vopros;
$answer = $ques->otvet;
$answered = $vict->answered;
$vopros = $vict->vopros;
$time = $vict->time;
$now = time();

if ($vopros)
    {
     if (($now < $time + 120) && (empty($answered)))
         {
          if ($msg == $answer)
              {
	           mysql_query('UPDATE `'.$px.$utable.'` SET `vposts` = "'.($vposts+1).'" WHERE `id` = "'.$id.'" AND `login` = "'.$login.'"');
	           mysql_query('UPDATE `chat_vopros` SET  `msg` = "Молодец, '.$login.'!<br/>Правильный ответ: <b>'.$msg.'</b><br/>Правильных ответов: '.($vposts+1).'!", `vopros` = "0", `answered` = "1", `time` = "'.time().'" WHERE `id` = "1"');
              }
	     }
     else
         {
          if (empty($answered) && !empty($vopros))
              {
               mysql_query('UPDATE `chat_vopros` SET  `msg` = "Время истекло, следующий вопрос через минуту!", `vopros` = "0", `answered` = "0", `time` = "'.time().'" WHERE `id` = "1"');
              }
         }
    }
else
    {
     $len = strlen(utfmks($answer));
     mysql_query('UPDATE `chat_vopros` SET  `msg` = "'.$nv.' ('.$len.' букв)", `vopros` = "'.$rand1.'", `answered` = "0", `time` = "'.time().'" WHERE `id` = "1"');
    }


?>