Файл: viktorina.php
Строк: 292
<?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');
}
global $db , $lang , $phpEx , $phpbb_root_path;
define('QUESTIONS_TABLE', $table_prefix.'question');
define('QUESTIONS_TEMP_TABLE', $table_prefix.'questions_temp');
define('QUESTIONS_ACTIVE_TABLE', $table_prefix.'questions_active');
define('QUESTIONS_CONFIG_TABLE', $table_prefix.'questions_config');
$page_title = $lang['qz_page_title0'];
$user_id = $userdata['user_id'];
$template->set_filenames(array( 'body' => 'viktorina_body.tpl'));
if( isset($HTTP_POST_VARS['on_off']))
{
$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']."001", '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$count_user = $row['count_user'];
$on_off_user = 0;
if ($count_user)
{
$sql = "SELECT on_off_user FROM " . QUESTIONS_ACTIVE_TABLE . " WHERE user_id = $user_id";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."002", "", __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$on_off_user = $row['on_off_user'];
}
if ($count_user==0)
{
$sql = "INSERT INTO " . QUESTIONS_ACTIVE_TABLE . "
(user_id, on_off_user, start_time)
VALUES ($user_id, 1, 0)";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."003", "", __LINE__, __FILE__, $sql);
}
}
if ($count_user)
{
$on_off_user2 = ($on_off_user) ? 0 : 1;
$sql = "UPDATE " . QUESTIONS_ACTIVE_TABLE . "
SET on_off_user = $on_off_user2
WHERE user_id = $user_id";
if (!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."004", "", __LINE__, __FILE__, $sql);
}
}
redirect(append_sid("viktorina.$phpEx", true));
}
if( isset($HTTP_POST_VARS['add_vop']))
{
redirect(append_sid("add_question.$phpEx", true));
}
if( isset($HTTP_POST_VARS['adms']) AND $userdata['user_level']==ADMIN)
{
redirect('admin/admin_viktorina.' . $phpEx . '?p=2&sid=' . $userdata['session_id']);
}
$points_name = ($board_config['points_name']) ? $board_config['points_name'] : 'points';
$sql="SELECT *
FROM " . QUESTIONS_CONFIG_TABLE;
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."005", '', __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_max_numb_temp = $quiz_conf['max_numb_temp'];
$conf_min_time = $quiz_conf['min_time'];
$conf_right_rating = $quiz_conf['numb2rate'];
$sql = "SELECT COUNT(id) AS numb_all FROM " . QUESTIONS_TABLE . " WHERE moder=1";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."006", "", __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$numb_all = $row['numb_all'];
$sql = "SELECT SUM(zad_vop) AS all_sum_vop
FROM " . QUESTIONS_ACTIVE_TABLE . "
WHERE zad_vop > 0";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."007", '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$all_sum_vop = $row['all_sum_vop'];
$sql = "SELECT user_id, right_otv, zad_vop
FROM " . QUESTIONS_ACTIVE_TABLE . "
WHERE right_otv >= $conf_right_rating";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."008", '', __LINE__, __FILE__, $sql);
}
$row3 = $db->sql_fetchrowset($result);
$info_rate = $lang['qz_rate_non'] . $conf_right_rating . $lang['qz_right_ans'];
if (count($row3))
{
$max_rat = $row3[0]['right_otv']/$row3[0]['zad_vop'];
$max_user= $row3[0]['user_id'];
$max_zad= $row3[0]['zad_vop'];
for($i = 0; $i < count($row3); $i++)
{
if ($row3[$i]['right_otv']/$row3[$i]['zad_vop'] >= $max_rat)
{
$max_rat = $row3[$i]['right_otv']/$row3[$i]['zad_vop'];
$max_user= $row3[$i]['user_id'];
$max_zad= $row3[$i]['zad_vop'];
}
}
$sql = "SELECT username
FROM " . USERS_TABLE . "
WHERE user_id = $max_user
LIMIT 1";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."009", '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$max_rating_name = $row['username'];
$user_link = "<a href=" . $phpbb_root_path . "profile.php?mode=viewprofile&u=" . $max_user . ">" . $max_rating_name . "</a>";
$info_rate = $user_link . ' (' . sprintf("%.2f",$max_rat*100) . $lang['qz_right_ansv'] . $max_zad . $lang['qz_qs'];
}
if ($user_id > 0)
{
$name2= $lang['qz_but_send'];
$name3= $lang['qz_but_adm'];
$name4= $lang['qz_but_my'];
$dis3 = 'disabled';
$dis4 = 'disabled';
$go_dis = 'disabled';
if ($userdata['user_level']==ADMIN) $dis3='';
$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']."010", "", __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$count_user = $row['count_user'];
if ($count_user)
{
$sql = "SELECT on_off_user, zad_vop, right_otv, prin_vop, start_time
FROM " . QUESTIONS_ACTIVE_TABLE . "
WHERE user_id = $user_id LIMIT 1";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."011", "", __LINE__, __FILE__, $sql);
}
$row2 = $db->sql_fetchrow($result);
$on_off = $row2['on_off_user'];
$name1= ($on_off) ? $lang['qz_user_off'] : $lang['qz_user_on'];
$numb_zad = $row2['zad_vop'];
$numb_prav0 = $row2['right_otv'];
$numb_add = $row2['prin_vop'];
$numb_prav = ($numb_zad) ? $numb_prav0 . ' (' . sprintf("%.2f", $numb_prav0*100/$numb_zad).'%)' : 0;
$numb_prav1 = ($numb_zad) ? sprintf("%.1f", $numb_prav0*100/$numb_zad).'%' : 0;
$time_prev = $row2['start_time'];
$title_time = $lang['qz_time_requir'] . $conf_min_time . $lang['qz_minutes3'];
$helps = $lang['qz_helps_u1'];
if ( (date("U")-$time_prev)/60 >= $conf_min_time AND $on_off AND $conf_on_off)
{
$go_dis = 'onClick="window.open('question.php','add_user','width=600, height=300, resizable=no, scrollbars=no, status=no, toolbar=no, menubar=no'); void(0); return false;"';
$title_time = '';
$helps = '';
}
$sql = "SELECT COUNT(*) as numb_wait FROM " . QUESTIONS_TEMP_TABLE . " WHERE author = $user_id";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, $lang['qz_obloms']."012", "", __LINE__, __FILE__, $sql);
}
$row3 = $db->sql_fetchrow($result);
$numb_wait = $row3['numb_wait'];
if ($numb_wait>$conf_max_numb_temp-1)
{
$dis2='disabled';
$helps = $lang['qz_helps_u2'];
}
}
if ($count_user == 0)
{
$dis1 = '';
$dis2 = '';
$name1= $lang['qz_user_on'];
$helps = $lang['qz_helps_u3'];
$not_user = 1;
}
}
if (!$userdata['session_logged_in'] && $user_id == ANONYMOUS)
{
$name1= $lang['qz_user_on'];
$name2= $lang['qz_but_send'];
$name3= $lang['qz_but_adm'];
$name4= $lang['qz_but_my'];
$dis1 = 'disabled';
$dis2 = 'disabled';
$dis3 = 'disabled';
$dis4 = 'disabled';
$go_dis = 'disabled';
$title_time = $lang['qz_for_guests'];
$helps = $lang['qz_helps_u4'];
$not_user = 1;
}
if (!$helps AND $numb_prav0<$conf_right_rating)
{
$helps = $lang['qz_not_best'] . $conf_right_rating . $lang['qz_right_ans0'];
}
$template->assign_vars(array(
'DIS1' => $dis1,
'DIS2' => $dis2,
'DIS3' => $dis3,
'DIS4' => $dis4,
'L_ABOUT' => $lang['qz_about'],
'L_DESC1' => $lang['qz_desc1'],
'L_DESC2' => $lang['qz_desc2'],
'L_BONUS' => $lang['qz_about_bonus'],
'L_MY_ACTS' => $lang['qz_my_acts'],
'L_GAME_NOW' => $lang['qz_game_now'],
'L_USE_BONUS' => $lang['qz_use_bonus'],
'L_ALL_STAT' => $lang['qz_all_stat'],
'L_MY_STAT' => $lang['qz_my_stat'],
'L_COSTR' => $lang['qz_cost_right'],
'L_PROM' => $lang['qz_prom'],
'L_ALL_ZAD' => $lang['qz_all_zad'],
'L_BEST' => $lang['qz_best'],
'L_MY_ADDS' => $lang['qz_my_adds'],
'L_WAIT' => $lang['qz_wait_mod'],
'L_ZADANO' => $lang['qz_zadano'],
'L_PRAV' => $lang['qz_my_prav'],
'L_M' => $lang['qz_minutes'],
'L_COPYR' => $lang['qz_co'],
'GO_DIS' => $go_dis,
'TITLE_TIME' => $title_time,
'TIME_MIN' => $conf_min_time,
'HELPS' => $helps,
'SUM_VOP' => ($all_sum_vop) ? $all_sum_vop : 0,
'NUMB_VOP' => $numb_all,
'COST_RIGHT_POINTS' => $conf_cost_right . ' ' . $points_name,
'RATE_INFO' => $info_rate,
'N1' => (!$not_user) ? $numb_zad : 0,
'N2' => (!$not_user) ? $numb_prav : 0,
'N2-1'=>(!$not_user) ? $numb_prav1 : 0,
'N3' => (!$not_user) ? $numb_add : 0,
'N4' => (!$not_user) ? $numb_wait : 0,
'NAME1' => $name1,
'NAME2' => $name2,
'NAME3' => $name3,
'NAME4' => $name4
));
$template->assign_block_vars('', array());
include($phpbb_root_path . 'includes/page_header.' . $phpEx);
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.' . $phpEx);
?>