<?

if ( $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ) {
    define( 'ROOT', 'http://'.$_SERVER['HTTP_HOST'] );
    define( 'ROOT_DIR', $_SERVER['DOCUMENT_ROOT'] );
    session_start();
    header( 'Content-type: text/html; charset=windows-1251' );
    include_once ROOT_DIR . '/engine/config.php';
    include_once ROOT_DIR . '/engine/function.php';
    include_once ROOT_DIR . '/engine/classes/bbcode.class.php';
} else {
    if ( !defined( 'MISOFT' ) ) { exit(); }
}

if ( !isset( $_SESSION['iduser'] ) ) {
    echo '<div style="margin-left: -10px;" class="alert alert-info alert-dismissible fade in" role="alert">
			<button type="button" class="close" data-dismiss="alert" aria-label="Close">
				<span aria-hidden="true">&times;</span>
			</button>
			<h5 class="alert-heading"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Внимание!</h5>
			<p style="font-size: 14px;">Вы не авторизованы. Доступ к этой странице разрешен только авторизованным пользователям. <br>Пожалуйста, воспользуйтесь формой авторизации.</p>
			<p style="font-size: 14px;" class="m-b-0">Для перехода в форму авторизации нажмите <a class="a_link" href="/login" >назад</a>.</p>
		  </div>';
} else
if ( !$config_user['activate'] ) {
    echo '<div style="margin-left: -10px;" class="alert alert-info alert-dismissible fade in" role="alert">
			<button type="button" class="close" data-dismiss="alert" aria-label="Close">
				<span aria-hidden="true">&times;</span>
			</button>
			<h5 class="alert-heading"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Внимание!</h5>
			<p style="font-size: 14px;">Для продолжения, Вам необходимо активировать свой аккаунт, перейдя в раздел <a class="a_link" href="/profile" >настройки аккаунта</a>. </p>
			
		  </div>';
} else {
      
			$view_test = mysql_query( "SELECT * FROM tests t1 WHERE t1.paused = 1 and t1.balance > '" . $config['tests'] . "' and id = '" . ( int ) $_GET['id'] . "' and NOT EXISTS ( SELECT ident, iduser FROM tests_temp t2 WHERE t1.id = t2.ident and t2.iduser = '" . $_SESSION['iduser'] . "') ORDER BY id DESC" );
			if ( mysql_num_rows( $view_test ) > 0 ) {
				$db_test = mysql_fetch_array( $view_test );
			  ?>
				<script type="text/javascript">
					var t;
					var top = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
					var answer1_set;
					var answer2_set;
					var answer3_set;
					
					function up() {
					  var top = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
					  if(top > 0) {
						window.scrollBy(0,-100);
						t = setTimeout('up()',1);
					  } else clearTimeout(t);
					  return false;
					}
					
					function test_send() {
						$('#wrap_btn_test').html('<img src="<?=ROOT?>/theme/images/preload.gif" width="20" height="20" alt="" style="margin-top: 1px; margin-bottom: -5px;" />');
						$.post('ajax.php?type=answertests', {
							id: '<?=$db_test['id']?>',
							t1: answer1_set,
							t2: answer2_set,
							t3: answer3_set
						}, function(data) {
							if (data == 1) {
								$('#testcontent').fadeOut();
								$('#success_test').fadeIn();
								up();
							} else
							if (data == 2) {
								$('#testcontent').fadeOut();
								$('#fail_test').fadeIn();
								up();
							} else {
								$('.error_test').fadeIn(500).html(data);
								setTimeout(function() {
									$('.error_test').fadeOut(500).html('&nbsp;');
								}, 7000);
								$('#wrap_btn_test').html('<a href="#" onclick="test_send(); return false;" class="btn_box_big">Отправить отчёт</a>');
							}
						});
					}
				</script>
				<div class="content_bar content_bar_fix_chain">
					<article class="postBox">
						<br><h2><a>Выполнение теста</a></h2><br>
						<div class="textPreview" style="margin-top: -20px;">
							<p class="">
								Внимательно прочтите и следуйте инструкции к выполнению теста. Последовательно ответьте на вопросы в тесте. Помните, все ответы должны быть верными, иначе тест будет закрыт для вас на 24 часа.
							</p>
						</div>
						<div class="tskblank4">
							<div class="tskblank3">
								<div class="tskblank2">
									<div class="tskblank1">
										<span class="tskblank-title">Тест №<?=$db_test['id']?>. <?=$db_test['title']?></span>
										<div class="tskblock">
											<span class="taskdescription"><b>Инструкции:</b><br>
												
												<div class=""><div class="fa fa-external-link" aria-hidden="true"></div> <a href="<?=$db_test['url']?>" class="link_color" target="_blank">Перейти на сайт рекламодателя</a></div>
												<div class="text_viev_test"><?=$db_test['description']?></div>
											</span>
											
											<div id="success_test" class="alert alert-success2 alert-dismissible" role="alert">
											  <div id="alert_success_icon" class=" fa fa-info-circle " aria-hidden="true"></div> 
											  <span style="margin-left: 22px;">Тест выполнен на отлично! Плата за выполнение <b><?=moneyraund( $config['tests'] * $config['factor_test'], 2 ) . ' ' . $config['valutaname'];?></b> уже зачислена.</span>
											</div>
											<div id="fail_test" class="alert alert-danger alert-dismissible" role="alert">
											  <div id="alert_success_icon" class=" fa fa-info-circle " aria-hidden="true"></div> 
											  <span style="margin-left: 22px;">Вы провалили этот тест! <i class="fa fa-frown-o" aria-hidden="true"></i> Не на все вопросы были даны правильные ответы.<br></span>
											  <span style="margin-left: 22px;">В связи с этим доступ к данному тесту блокируется на 24 часа!</span>
											</div>
											
											<div id="testcontent">
												<span class="task-subtitle">Ответьте на вопросы теста:</span>
												
												<span class="taskquestion"><b>Вопрос 1:</b> <?=$db_test['v1']?></span>
												<div class="blockreply">
													<?
														$inp = array( 1, 2, 3 );
														shuffle( $inp );
														$rand1 = $inp[0];
														$rand2 = $inp[1];
														$rand3 = $inp[2];
													?>
													<script type="text/javascript">
														function answer1_clix1() {
															answer1_set = '<?=md5($db_test['id'] . $message_md5 . $rand1) ?>';
															document.getElementById("answer_1").className = "seltestanswer";
															document.getElementById("answer_2").className = "seltestanswer";
															document.getElementById("answer_3").className = "seltestanswer";
															document.getElementById("answer_1").className = "seltestansweract";
														}
														function answer1_clix2() {
															answer1_set = '<?=md5($db_test['id'] . $message_md5 . $rand2) ?>';
															document.getElementById("answer_1").className = "seltestanswer";
															document.getElementById("answer_2").className = "seltestanswer";
															document.getElementById("answer_3").className = "seltestanswer";
															document.getElementById("answer_2").className = "seltestansweract";
														}
														function answer1_clix3() {
															answer1_set = '<?=md5($db_test['id'] . $message_md5 . $rand3) ?>';
															document.getElementById("answer_1").className = "seltestanswer";
															document.getElementById("answer_2").className = "seltestanswer";
															document.getElementById("answer_3").className = "seltestanswer";
															document.getElementById("answer_3").className = "seltestansweract";
														}
													</script>
													<span id="answer_1" onclick="answer1_clix1(); return false;" class="seltestanswer" onclick="">&nbsp;<?=$db_test['answer'.$rand1] ?></span>
													<span id="answer_2" onclick="answer1_clix2(); return false;" class="seltestanswer" onclick="">&nbsp;<?=$db_test['answer'.$rand2] ?></span>
													<span id="answer_3" onclick="answer1_clix3(); return false;" class="seltestanswer" onclick="">&nbsp;<?=$db_test['answer'.$rand3] ?></span>
												</div>
												<span class="taskquestion"><b>Вопрос 2:</b> <?=$db_test['v2']?></span>
												<div class="blockreply">
													<?
														$inp2 = array( 4, 5, 6 );
														shuffle( $inp2 );
														$rand4 = $inp2[0];
														$rand5 = $inp2[1];
														$rand6 = $inp2[2];
													?>
													<script type="text/javascript">
														function answer2_clix1() {
															answer2_set = '<?=md5($db_test['id'] . $message_md5 . $rand4) ?>';
															document.getElementById("answer_4").className = "seltestanswer";
															document.getElementById("answer_5").className = "seltestanswer";
															document.getElementById("answer_6").className = "seltestanswer";
															document.getElementById("answer_4").className = "seltestansweract";
														}
														function answer2_clix2() {
															answer2_set = '<?=md5($db_test['id'] . $message_md5 . $rand5) ?>';
															document.getElementById("answer_4").className = "seltestanswer";
															document.getElementById("answer_5").className = "seltestanswer";
															document.getElementById("answer_6").className = "seltestanswer";
															document.getElementById("answer_5").className = "seltestansweract";
														}
														function answer2_clix3() {
															answer2_set = '<?=md5($db_test['id'] . $message_md5 . $rand6) ?>';
															document.getElementById("answer_4").className = "seltestanswer";
															document.getElementById("answer_5").className = "seltestanswer";
															document.getElementById("answer_6").className = "seltestanswer";
															document.getElementById("answer_6").className = "seltestansweract";
														}
													</script>
													<span id="answer_4" onclick="answer2_clix1(); return false;" class="seltestanswer" onclick="">&nbsp;<?=$db_test['answer'.$rand4] ?></span>
													<span id="answer_5" onclick="answer2_clix2(); return false;" class="seltestanswer" onclick="">&nbsp;<?=$db_test['answer'.$rand5] ?></span>
													<span id="answer_6" onclick="answer2_clix3(); return false;" class="seltestanswer" onclick="">&nbsp;<?=$db_test['answer'.$rand6] ?></span>
												</div>
												<span class="taskquestion"><b>Вопрос 3:</b> <?=$db_test['v3']?></span>
												<div class="blockreply">
													<?
														$inp3 = array( 7, 8, 9 );
														shuffle( $inp3 );
														$rand7 = $inp3[0];
														$rand8 = $inp3[1];
														$rand9 = $inp3[2];
													?>
													<script type="text/javascript">
														function answer3_clix1() {
															answer3_set = '<?=md5($db_test['id'] . $message_md5 . $rand7) ?>';
															document.getElementById("answer_7").className = "seltestanswer";
															document.getElementById("answer_8").className = "seltestanswer";
															document.getElementById("answer_9").className = "seltestanswer";
															document.getElementById("answer_7").className = "seltestansweract";
														}
														function answer3_clix2() {
															answer3_set = '<?=md5($db_test['id'] . $message_md5 . $rand8) ?>';
															document.getElementById("answer_7").className = "seltestanswer";
															document.getElementById("answer_8").className = "seltestanswer";
															document.getElementById("answer_9").className = "seltestanswer";
															document.getElementById("answer_8").className = "seltestansweract";
														}
														function answer3_clix3() {
															answer3_set = '<?=md5($db_test['id'] . $message_md5 . $rand9) ?>';
															document.getElementById("answer_7").className = "seltestanswer";
															document.getElementById("answer_8").className = "seltestanswer";
															document.getElementById("answer_9").className = "seltestanswer";
															document.getElementById("answer_9").className = "seltestansweract";
														}
													</script>
													<span id="answer_7" onclick="answer3_clix1(); return false;" class="seltestanswer" onclick="">&nbsp;<?=$db_test['answer'.$rand7] ?></span>
													<span id="answer_8" onclick="answer3_clix2(); return false;" class="seltestanswer" onclick="">&nbsp;<?=$db_test['answer'.$rand8] ?></span>
													<span id="answer_9" onclick="answer3_clix3(); return false;" class="seltestanswer" onclick="">&nbsp;<?=$db_test['answer'.$rand9] ?></span>
												</div>
												<div id="testcontent">
													
													<div class="error_test" style="display: none; margin: 15px auto;"></div>
													<div id="wrap_btn_test"><a href="#" onclick="test_send(); return false;" class="btn_box_big">Отправить отчёт</a></div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="banner_gorizontal banner_gorizontal_fix" style="margin-top: 31px;"><? include_once ROOT_DIR . '/modules/banner468x60/rotator.php';?></div>
						
					</article>
				</div>
			  <?
			} else {
				echo '<div style="margin-left: -10px;" class="alert alert-info alert-dismissible fade in" role="alert">
				<button type="button" class="close" data-dismiss="alert" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h5 class="alert-heading"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Внимание!</h5>
				<p style="font-size: 14px;">Тест не существует или не активен.. </p>
				<p style="font-size: 14px;" class="m-b-0">Для возврата на предыдущую страницу нажмите <a class="a_link" href="/tests" >назад</a>.</p>
			  </div>';
			}
		 
	}

?>