Файл: question.php
Строк: 268
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/constants.' . $phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
$user_lang = ($userdata['user_id'] != ANONYMOUS) ? $userdata['user_lang'] : $board_config['default_lang'];
if( file_exists($phpbb_root_path . 'language/lang_' . $user_lang . '/lang_viktorina.php') )
{
include_once($phpbb_root_path . 'language/lang_' . $user_lang . '/lang_viktorina.php');
}
else
{
$user_lang = 'english';
include_once($phpbb_root_path . 'language/lang_english/lang_viktorina.php');
}
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
global $db , $lang , $phpEx , $phpbb_root_path;
define('QUESTIONS_TABLE', $table_prefix.'question');
define('QUESTIONS_CONFIG_TABLE', $table_prefix.'questions_config');
define('QUESTIONS_TEMP_TABLE', $table_prefix.'questions_temp');
define('QUESTIONS_ACTIVE_TABLE', $table_prefix.'questions_active');
define('USERS_TABLE', $table_prefix.'users');
$time_now = date("U");
$user_id = $userdata['user_id'];
if (!$userdata['session_logged_in'] && $user_id == ANONYMOUS)
{
$header_location = ( @preg_match("/Microsoft|WebSTAR|Xitami/", getenv("SERVER_SOFTWARE")) ) ? "Refresh: 0; URL=" : "Location: ";
header($header_location . append_sid("login.$phpEx?redirect=viktorina.$phpEx", true));
exit;
}
$user_points = $userdata['user_points'];
$sql="SELECT *
FROM " . QUESTIONS_CONFIG_TABLE;
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."301", "", __LINE__, __FILE__, $sql);
}
while( $row = $db->sql_fetchrow($result) )
{
$quiz_conf[$row['config_name']] = $row['config_value'];
}
$conf_on_off = $quiz_conf['on_off'];
$conf_cost_right = $quiz_conf['cost_right'];
$conf_min_time = $quiz_conf['min_time'];
$conf_otv_time = $quiz_conf['otv_time'];
$conf_snd_on = $quiz_conf['snd_on'];
$points_name = ($board_config['points_name']) ? $board_config['points_name'] : 'points';
$template->set_filenames(array( 'body' => 'viktorina_act_body.tpl'));
if (!$conf_on_off)
{
message_die(GENERAL_MESSAGE, $lang['qz_is_off']);
}
if( isset($_GET['id']) AND isset($_GET['otvet']))
{
$no_vo = $_GET['id'];
$no_otv = $_GET['otvet'];
$sql= "SELECT *
FROM " . QUESTIONS_ACTIVE_TABLE . "
WHERE user_id = $user_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."302", "", __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$no_vo_re = $row['vop_id'];
$no_otv_re = $row['real_otvet'];
$start_time = $row['start_time'];
if ($no_vo != $no_vo_re)
{
$shtraf = ($user_points > $conf_cost_right*10) ? $conf_cost_right*10 : $user_points;
$sql = "UPDATE " . USERS_TABLE . "
SET user_points = user_points - $shtraf
WHERE user_id = $user_id";
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."303", "", __LINE__, __FILE__, $sql);
}
$message = $lang['qz_vzlom1'] . $conf_cost_right*10 . ' ' . $points_name . $lang['qz_vzlom2'] . sprintf("<a href="" . append_sid("index.$phpEx") . "">".'<br/>Перейти на главную'."</a>");
message_die(GENERAL_MESSAGE, $message);
}
if ( ($time_now - $start_time) > $conf_otv_time*2)
{
$shtraf = ($user_points > $conf_cost_right) ? $conf_cost_right : $user_points;
$sql = "UPDATE " . USERS_TABLE . "
SET user_points = user_points - $shtraf
WHERE user_id = $user_id";
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."304", "", __LINE__, __FILE__, $sql);
}
$time_old = date("U")-$start_time+$conf_otv_time*2;
$message = $lang['qz_timeout1'] . $time_old . $lang['qz_timeout2'] . $conf_cost_right . $points_name .'<br />' . sprintf('<a href="viktorina.php">'.'Продолжить'.'</a>');
message_die(GENERAL_MESSAGE, $message);
}
if (!$no_otv_re)
{
$shtraf = ($user_points > $conf_cost_right*10) ? $conf_cost_right*10 : $user_points;
$sql = "UPDATE " . USERS_TABLE . "
SET user_points = user_points - $shtraf
WHERE user_id = $user_id";
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."305", "", __LINE__, __FILE__, $sql);
}
$message = $lang['qz_vzlom3'] . $conf_cost_right*10 . ' ' . $points_name . $lang['qz_cry'] . sprintf('<a href="index.php">'.'На главную!'.'</a>');
message_die(GENERAL_MESSAGE, $message);
}
if ($no_otv == $no_otv_re)
{
$sql = "UPDATE " . USERS_TABLE . "
SET user_points = user_points + $conf_cost_right
WHERE user_id = $user_id";
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."306", "", __LINE__, __FILE__, $sql);
}
$sql = "UPDATE " . QUESTIONS_ACTIVE_TABLE . "
SET real_otvet = 0,
right_otv = right_otv+1
WHERE user_id = $user_id";
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."307", "", __LINE__, __FILE__, $sql);
}
$m8 = ($conf_min_time) ? $lang['qz_time2next'] . $conf_min_time . $lang['qz_minutes'] : '';
$message = $lang['qz_win'] . $conf_cost_right . $points_name . $m8 . sprintf("<a href="" . append_sid("viktorina.$phpEx") . "">".'<br/> Продолжить'."</a>");
message_die(GENERAL_MESSAGE, $message);
}
else
{
$m9 = ($conf_min_time) ? $lang['qz_dontcry'] . $conf_min_time . $lang['qz_once_again'] : $lang['qz_your_can'];
$message = $lang['qz_your_wrong'] . $m9 . sprintf("<a href="" . append_sid("viktorina.$phpEx") . "">".'<br/> Продолжить'."</a>") . sprintf("<a href="" . append_sid("index.$phpEx") . "">".'<br/>Перейти на главную'."</a>");
message_die(GENERAL_MESSAGE, $message);
}
}
$sql = "SELECT start_time, vop_id
FROM " . QUESTIONS_ACTIVE_TABLE . "
WHERE user_id = $user_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."308", "", __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$time_prev = $row['start_time'];
$vop_id = $row['vop_id'];
if ( (date("U")-$time_prev)/60 < $conf_min_time AND $conf_min_time)
{
$sql = "UPDATE " . USERS_TABLE . "
SET user_points = user_points - $conf_cost_right*2
WHERE user_id = $user_id";
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."309", "", __LINE__, __FILE__, $sql);
}
$message = $lang['qz_wait'] . $conf_min_time . $lang['qz_vzlom4'] . $conf_cost_right*2 . ' ' . $points_name . '!<br />' . sprintf("<a href="" . append_sid("index.$phpEx") . "">".'<br/>Перейти на главную'."</a>");
message_die(GENERAL_MESSAGE, $message);
}
$script_pop = '';
if( isset($_GET['pop']) AND $_GET['pop']==2)
{
$pop = $_GET['pop'];
$script_pop = "if (!confirm(" . $lang['qz_confirm'] . ") ) {self.close();} else {parent.location='question.php';}";
}
$sql= "SELECT *
FROM " . QUESTIONS_TABLE . "
WHERE moder = 1 ORDER BY RAND() LIMIT 1";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."310", "", __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$numb_q = $row['id'];
$quest = $row['question'];
$otv1 = $row['otvet_1'];
$otv2 = $row['otvet_2'];
$otv3 = $row['otvet_3'];
$otv4 = $row['otvet_4'];
$real = $row['otvet_verno'];
$autor = $row['author'];
if (!$quest)
{
$message = $lang['qz_base_empty'] . sprintf($lang['qz_send_q2b'], "<a href="" . append_sid("add_question.$phpEx") . "">", "</a>") . $lang['qz_your_q2'] . sprintf("<a href="" . append_sid("index.$phpEx") . "">".'<br/>Перейти на главную'."</a>");
message_die(GENERAL_MESSAGE, $message);
}
if ($numb_q==$vop_id AND !isset($_GET['pop']))
{
$message = $lang['qz_second'] . sprintf("<a href="" . append_sid("index.$phpEx") . "">".'<br/>Перейти на главную'."</a>");
message_die(GENERAL_MESSAGE, $message);
}
$sql = "SELECT COUNT(*) as count_user FROM " . QUESTIONS_ACTIVE_TABLE . " WHERE user_id = $user_id";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."311", "", __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$count_user = $row['count_user'];
$k4=3; // addition time for download page
$d= date("U")+$k4;
if ($count_user == 0 AND $pop!=2)
{
$sql = "INSERT INTO " . QUESTIONS_ACTIVE_TABLE . "
(user_id, vop_id, real_otvet, start_time, zad_vop)
VALUES ($user_id, $numb_q, $real, $d, '1')";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."312", '', __LINE__, __FILE__, $sql);
}
}
elseif ($pop!=2)
{
$sql= "UPDATE " . QUESTIONS_ACTIVE_TABLE . "
SET vop_id = $numb_q,
real_otvet = $real,
start_time = $d,
zad_vop = zad_vop+1
WHERE user_id = $user_id LIMIT 1";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."313", "", __LINE__, __FILE__, $sql);
}
}
$template->assign_vars(array(
'L_SCR1' => $lang['qz_inscript1'],
'L_SCR2' => $lang['qz_inscript2'],
'L_SCR3' => $lang['qz_inscript3'],
'L_VOP' => $lang['qz_quest'],
'L_AVTOR' => $lang['qz_autor_q'],
'L_COPYR' => $lang['qz_co'],
'SCRIPT_POP' => $script_pop,
'NUMB' => $numb_q,
'VOP' => $quest,
'OTV1' => $otv1,
'OTV2' => $otv2,
'OTV3' => $otv3,
'OTV4' => $otv4,
'AVTOR' => $autor,
'OTV_TIME' => $conf_otv_time
));
$template->assign_block_vars('', array());
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
?>