<?
#Старт сессии
session_start();

#Подключаем базу
include '../engine/config.php';
include '../engine/classes/bbcode.class.php';
  
#Проверяем способ вызова файла
if ( !defined( 'MISOFT_ADMIN_DIRR' ) ) exit();

if ( !isset( $_SESSION['iduser'] ) or $config_user['account'] != 5 ) {
    echo '<div class="stabilisacion-engine"><div class="alert alert-danger" role="alert">
	  <strong>Внимание!</strong> Нарушен механизм безопасности! В силу безопасности и целостности сайта, выполнение скриптов остановлено. Ошибка №A1
	</div></div>';
	exit();
} else {
  
  $edit_test = mysql_fetch_array( mysql_query( "SELECT * FROM tests WHERE id = '" . ( int ) $_GET['id'] . "' LIMIT 1" ) );
  $edit_test_reklamodatel = mysql_fetch_array( mysql_query( "SELECT username, userdel FROM user WHERE id = '" . ( int ) $edit_test['iduser'] . "' LIMIT 1" ) );
  ?>
    <script type="text/javascript">
      function config_1() {
		$.ajax ({
            url: 'ajax_update.php?func=edittests',
            type: 'POST',
			dataType: 'html',
			data: $("#editform").serialize(),
            success: function(data) {
              if(data == 1) {
                $('#block_title_error').fadeIn(0);
                $('#success_ajax').fadeIn(500);
                setTimeout(function() {
                    $('#success_ajax').fadeOut(500);
					$('#block_title_error').fadeOut(0);
					location.reload();
                }, 4000);
              } else {
				$('#block_title_error').fadeIn(0);
				$('#error_ajax').fadeIn(500).html(data);
                setTimeout(function() {
                    $('#error_ajax').fadeOut(500).html('&nbsp;');
					$('#block_title_error').fadeOut(0);
                }, 4000);
			  }
            }
        });
      }
	  
	  function qbb(a, b, c) {
	    textarea = document.getElementById(c);
	    if (document.selection && document.selection.createRange) textarea.focus(), sel = document.selection.createRange(), sel.text = a + sel.text + b;
	    else if (textarea.selectionStart || "0" == textarea.selectionStart) {
		  c = textarea.selectionStart;
		  var d = textarea.selectionEnd;
		  textarea.value = textarea.value.substring(0, c) + a + textarea.value.substring(c, d) + b + textarea.value.substring(d, textarea.value.length);
		  textarea.selectionStart = textarea.selectionEnd = d + a.length + b.length
	    } else textarea.value += a + b;
	    textarea.focus()
	  };
    </script>
    <div class="content-wrapper">
	  <div class="container-fluid">
		<div class="row">
		  <div class="col-md-12">
		    <h2 class="page-title">Редактирование рекламной площадки.</h2>

			<div class="row">
			  <div class="col-md-6">
				<div class="panel panel-default">
				  <div class="panel-heading">Оплачиваемые тесты (площадка ID:<?=( int ) $_GET['id']?>)</div>
				  <div class="panel-body">
					<? if( $edit_test['nouser'] == 1 ) { ?>
					  <div class="alert alert-dismissible alert-warning">
					    <button type="button" class="close" data-dismiss="alert"><i class="fa fa-remove"></i></button>
					    Заказ площадки был осуществлен от не авторизированного пользователя (заказ без авторизации).
					  </div>
					<? } ?>
					<form id="editform" action="" method="POST" class="form-horizontal">
					  <input type="hidden" name="idtests" id="idtests" value="<?=$edit_test['id']?>" />
					  
					  <div class="form-group">
						<label class="col-sm-2 control-label ">Заголовок</label>
						<div class="col-sm-10 input-size-one">
						  <input type="text" class="form-control" name="title" id="title" value="<?=$edit_test['title']?>">
						  <span class="help-block m-b-none"></span>
						</div>
					  </div>
					  
					  <div class="hr-dashed"></div>
					  <div class="form-group ">
						<label class="col-sm-2 control-label label-size-one">Описание</label>
						<div class="col-sm-10 input-size-one">
						  <div class="bbcode-panel-forum-post ">
							<span onclick="qbb('[b]','[/b]','text')" id="bb_b" title="Полужирный текст" class="bb-b-forum"><i class="fa fa-bold" aria-hidden="true"></i></span>
							<span onclick="qbb('[i]','[/i]','text')" id="bb_i" title="Наклонный текст" class="bb-i-forum"><i class="fa fa-italic" aria-hidden="true"></i></span>
							<span onclick="qbb('[u]','[/u]','text')" id="bb_u" title="Подчеркнутый текст" class="bb-u-forum"><i class="fa fa-underline" aria-hidden="true"></i></span>
							<span onclick="qbb('[s]','[/s]','text')" id="bb_s" title="Зачеркнутый текст" class="bb-s-forum"><i class="fa fa-strikethrough" aria-hidden="true"></i></span>
							<span onclick="qbb('[sub]','[/sub]','text')" id="bb_sub" title="Нижний индекс" class="bb-sub-forum"><i class="fa fa-subscript" aria-hidden="true"></i></span>
							<span onclick="qbb('[sup]','[/sup]','text')" id="bb_sup" title="Верхний индекс" class="bb-sup-forum"><i class="fa fa-superscript" aria-hidden="true"></i></span>
							<span onclick="qbb('[quotet]','[/quotet]','text')" class="bb_quotet" id="quotet" title="Цитировать текст"><i class="fa fa-quote-left" aria-hidden="true"></i></span>
							<span onclick="qbb('[video]','[/video]','text')" class="bb_youtube" id="video" title="Вставить видео"><i class="fa fa-youtube-play" aria-hidden="true"></i></span>
							<span onclick="qbb('[images]','[/images]','text')" class="bb_youtube" id="images_forum_post" title="Вставить изображение (поддерживаются форматы jpg/png/bmp/gif)."><i class="fa fa-picture-o" aria-hidden="true"></i></span>
							<span onclick="qbb('[a]','[/a]','text')" class="bb_link" id="link_forum" title="Вставить ссылку"><i class="fa fa-link" aria-hidden="true"></i></span>
						  </div>
						  <textarea name="text" id="text" style="padding-top: 38px; max-width: 632px; min-width: 632px;" class="form-control" rows="10"><?=parce_html_code( $edit_test['description'] )?></textarea>
						</div>
					  </div>
					
					  <div class="hr-dashed"></div>
					  <div class="form-group">
						<label class="col-sm-2 control-label ">Вопрос №1</label>
						<div class="col-sm-10 input-size-one">
						  <input type="text" class="form-control" name="v1" id="v1" value="<?=$edit_test['v1']?>">
						  <span class="help-block m-b-none"></span> 
						</div>
					  </div>
					
					  <div class="hr-dashed"></div>
					  <div class="form-group">
						<label class="col-sm-2 control-label ">Ответ <span style="color: #3CB371;">(правильный)</span></label>
						<div class="col-sm-10 input-size-one">
						  <input type="text" class="form-control" name="answer1" id="answer1" value="<?=$edit_test['answer1']?>">
						  <span class="help-block m-b-none"></span> 
						</div>
					  </div>
					
					  <div class="hr-dashed"></div>
					  <div class="form-group">
						<label class="col-sm-2 control-label ">Ответ <span style="color: #DC143C;">(ложный)</span></label>
						<div class="col-sm-10 input-size-one">
						  <input type="text" class="form-control" name="answer2" id="answer2" value="<?=$edit_test['answer2']?>">
						  <span class="help-block m-b-none"></span> 
						</div>
					  </div>
					
					  <div class="hr-dashed"></div>
					  <div class="form-group">
						<label class="col-sm-2 control-label ">Ответ <span style="color: #DC143C;">(ложный)</span></label>
						<div class="col-sm-10 input-size-one">
						  <input type="text" class="form-control" name="answer3" id="answer3" value="<?=$edit_test['answer3']?>">
						  <span class="help-block m-b-none"></span> 
						</div>
					  </div>
					
					  <div class="hr-dashed"></div>
					  <div class="form-group">
						<label class="col-sm-2 control-label ">Вопрос №2</label>
						<div class="col-sm-10 input-size-one">
						  <input type="text" class="form-control" name="v2" id="v2" value="<?=$edit_test['v2']?>">
						  <span class="help-block m-b-none"></span> 
						</div>
					  </div>
					
					  <div class="hr-dashed"></div>
					  <div class="form-group">
						<label class="col-sm-2 control-label ">Ответ <span style="color: #3CB371;">(правильный)</span></label>
						<div class="col-sm-10 input-size-one">
						  <input type="text" class="form-control" name="answer4" id="answer4" value="<?=$edit_test['answer4']?>">
						  <span class="help-block m-b-none"></span> 
						</div>
					  </div>
					
					  <div class="hr-dashed"></div>
					  <div class="form-group">
						<label class="col-sm-2 control-label ">Ответ <span style="color: #DC143C;">(ложный)</span></label>
						<div class="col-sm-10 input-size-one">
						  <input type="text" class="form-control" name="answer5" id="answer5" value="<?=$edit_test['answer5']?>">
						  <span class="help-block m-b-none"></span> 
						</div>
					  </div>
					
					  <div class="hr-dashed"></div>
					  <div class="form-group">
						<label class="col-sm-2 control-label ">Ответ <span style="color: #DC143C;">(ложный)</span></label>
						<div class="col-sm-10 input-size-one">
						  <input type="text" class="form-control" name="answer6" id="answer6" value="<?=$edit_test['answer6']?>">
						  <span class="help-block m-b-none"></span> 
						</div>
					  </div>
					
					  <div class="hr-dashed"></div>
					  <div class="form-group">
						<label class="col-sm-2 control-label ">Вопрос №3</label>
						<div class="col-sm-10 input-size-one">
						  <input type="text" class="form-control" name="v3" id="v3" value="<?=$edit_test['v3']?>">
						  <span class="help-block m-b-none"></span> 
						</div>
					  </div>
					
					  <div class="hr-dashed"></div>
					  <div class="form-group">
						<label class="col-sm-2 control-label ">Ответ <span style="color: #3CB371;">(правильный)</span></label>
						<div class="col-sm-10 input-size-one">
						  <input type="text" class="form-control" name="answer7" id="answer7" value="<?=$edit_test['answer7']?>">
						  <span class="help-block m-b-none"></span> 
						</div>
					  </div>
					
					  <div class="hr-dashed"></div>
					  <div class="form-group">
						<label class="col-sm-2 control-label ">Ответ <span style="color: #DC143C;">(ложный)</span></label>
						<div class="col-sm-10 input-size-one">
						  <input type="text" class="form-control" name="answer8" id="answer8" value="<?=$edit_test['answer8']?>">
						  <span class="help-block m-b-none"></span> 
						</div>
					  </div>
					
					  <div class="hr-dashed"></div>
					  <div class="form-group">
						<label class="col-sm-2 control-label ">Ответ <span style="color: #DC143C;">(ложный)</span></label>
						<div class="col-sm-10 input-size-one">
						  <input type="text" class="form-control" name="answer9" id="answer9" value="<?=$edit_test['answer9']?>">
						  <span class="help-block m-b-none"></span> 
						</div>
					  </div>
					  
					  <div class="hr-dashed"></div>
					  <div class="form-group">
						<label class="col-sm-2 control-label ">URL сайта</label>
						<div class="col-sm-10 input-size-one">
						  <input type="text" class="form-control" name="url" id="url" value="<?=$edit_test['url']?>">
						  <span class="help-block m-b-none"></span> 
						</div>
					  </div>
					
					  <? if( $edit_test['nouser'] == 0 ) { ?>
					    <div class="hr-dashed"></div>
					    <div class="form-group">
						  <label class="col-sm-2 control-label ">Рекламодатель id</label>
						  <div class="col-sm-10 input-size-one">
						    <input type="text" class="form-control" name="iduser" id="iduser" value="<?=$edit_test['iduser']?>">
						    <span class="help-block m-b-none">Ник:&nbsp;<?=$edit_test_reklamodatel['username']?>&nbsp;<? if($edit_test_reklamodatel['userdel'] == 1) { echo '<font color="red">(пользователь удален)</font>';} ?></span> 
						  </div>
					    </div>
					  <? } ?>
					
					  <div class="hr-dashed"></div>
					  <div class="form-group">
						<label class="col-sm-2 control-label ">Баланс</label>
						<div class="col-sm-10 input-size-one">
						  <input type="text" class="form-control" name="balance" id="balance" value="<?=$edit_test['balance']?>">
						  <span class="help-block m-b-none"></span> 
						</div>
					  </div>
					  
					  <div class="hr-dashed"></div>
					  <div class="form-group">
						<label class="col-sm-2 control-label ">Геотаргетинг</label>
						<div class="col-sm-10">
						  <table class="table_geo_addtext">
							<tr>
							  <td style="width: 50%;">
							    <div class="checkbox checkbox-primary">
							      <input type="checkbox" name="geo_ru" id="geo_ru" value="ru" <? if( $edit_test['geo_ru'] == 'ru' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/ru.png" class="flagcountry" alt="" />&nbsp;&nbsp;Россия</label>
								</div>
							  </td>
							  <td style="width: 50%;">
							    <div class="checkbox checkbox-primary">
								  <input type="checkbox" name="geo_ua" id="geo_ua" value="ua" <? if( $edit_test['geo_ua'] == 'ua' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/ua.png" class="flagcountry" alt="" />&nbsp;&nbsp;Украина</label>
							    </div>
							  </td>
							</tr>
							<tr>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
								  <input type="checkbox" name="geo_by" id="geo_by" value="by" <? if( $edit_test['geo_by'] == 'by' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/by.png" class="flagcountry" alt="" />&nbsp;&nbsp;Белоруссия</label>
								</div>
							  </td>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
								  <input type="checkbox" name="geo_ge" id="geo_ge" value="ge" <? if( $edit_test['geo_ge'] == 'ge' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/ge.png" class="flagcountry" alt="" />&nbsp;&nbsp;Грузия</label>
								</div>
							  </td>
							</tr>
							<tr>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
								  <input type="checkbox" name="geo_md" id="geo_md" value="md" <? if( $edit_test['geo_md'] == 'md' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/md.png" class="flagcountry" alt="" />&nbsp;&nbsp;Молдова</label>
								</div>
							  </td>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
								  <input type="checkbox" name="geo_kz" id="geo_kz" value="kz" <? if( $edit_test['geo_kz'] == 'kz' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/kz.png" class="flagcountry" alt="" />&nbsp;&nbsp;Казакстан</label>
								</div>
							  </td>
							</tr>
							<tr>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
								  <input type="checkbox" name="geo_am" id="geo_am" value="am" <? if( $edit_test['geo_am'] == 'am' ) echo 'checked="selected"';?> />
								  <label>&nbsp;<img src="/theme/images/flags/am.png" class="flagcountry" alt="" />&nbsp;&nbsp;Армения</label>
								</div>
							  </td>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
								  <input type="checkbox" name="geo_tj" id="geo_tj" value="tj" <? if( $edit_test['geo_tj'] == 'tj' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/tj.png" class="flagcountry" alt="" />&nbsp;&nbsp;Таджикистан</label>
								</div>
							  </td>
							</tr>
							<tr>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
								  <input type="checkbox" name="geo_az" id="geo_az" value="az" <? if( $edit_test['geo_az'] == 'az' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/az.png" class="flagcountry" alt="" />&nbsp;&nbsp;Азербайджан</label>
								</div>
							  </td>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
								  <input type="checkbox" name="geo_uz" id="geo_uz" value="uz" <? if( $edit_test['geo_uz'] == 'uz' ) echo 'checked="selected"';?> />
								  <label>&nbsp;<img src="/theme/images/flags/uz.png" class="flagcountry" alt="" />&nbsp;&nbsp;Узбекистан</label>
								</div>
							  </td>
							</tr>
							<tr>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
								  <input type="checkbox" name="geo_pt" id="geo_pt" value="pt" <? if( $edit_test['geo_pt'] == 'pt' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/pt.png" class="flagcountry" alt="" />&nbsp;&nbsp;Португалия</label>
								</div>
							  </td>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
							      <input type="checkbox" name="geo_es" id="geo_es" value="es" <? if( $edit_test['geo_es'] == 'es' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/es.png" class="flagcountry" alt="" />&nbsp;&nbsp;Испания</label>
								</div>
							  </td>
							</tr>
							<tr>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
							      <input type="checkbox" name="geo_ee" id="geo_ee" value="ee" <? if( $edit_test['geo_ee'] == 'ee' ) echo 'checked="selected"';?> />
								  <label>&nbsp;<img src="/theme/images/flags/ee.png" class="flagcountry" alt="" />&nbsp;&nbsp;Эстония</label>
								</div>
							  </td>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
							      <input type="checkbox" name="geo_lv" id="geo_lv" value="lv" <? if( $edit_test['geo_lv'] == 'lv' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/lv.png" class="flagcountry" alt="" />&nbsp;&nbsp;Латвия</label>
								</div>
							  </td>
							</tr>
							<tr>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
							      <input type="checkbox" name="geo_lt" id="geo_lt" value="lt" <? if( $edit_test['geo_lt'] == 'lt' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/lt.png" class="flagcountry" alt="" />&nbsp;&nbsp;Литва</label>
								</div>
							  </td>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
							      <input type="checkbox" name="geo_us" id="geo_us" value="us" <? if( $edit_test['geo_us'] == 'us' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/us.png" class="flagcountry" alt="" />&nbsp;&nbsp;Америка</label>
								</div>
							  </td>
							</tr>
							<tr>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
							      <input type="checkbox" name="geo_gb" id="geo_gb" value="gb" <? if( $edit_test['geo_gb'] == 'gb' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/gb.png" class="flagcountry" alt="" />&nbsp;&nbsp;Англия</label>
								</div>
							  </td>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
							      <input type="checkbox" name="geo_fr" id="geo_fr" value="fr" <? if( $edit_test['geo_fr'] == 'fr' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/fr.png" class="flagcountry" alt="" />&nbsp;&nbsp;Франция</label>
								</div>
							  </td>
							</tr>
							<tr>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
							      <input type="checkbox" name="geo_de" id="geo_de" value="de" <? if( $edit_test['geo_de'] == 'de' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/de.png" class="flagcountry" alt="" />&nbsp;&nbsp;Германия</label>
								</div>
							  </td>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
							      <input type="checkbox" name="geo_cn" id="geo_cn" value="cn" <? if( $edit_test['geo_cn'] == 'cn' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/cn.png" class="flagcountry" alt="" />&nbsp;&nbsp;Китай</label>
								</div>
							  </td>
							</tr>
							<tr>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
							      <input type="checkbox" name="geo_it" id="geo_it" value="it" <? if( $edit_test['geo_it'] == 'it' ) echo 'checked="selected"';?> /> 
								  <label>&nbsp;<img src="/theme/images/flags/it.png" class="flagcountry" alt="" />&nbsp;&nbsp;Италия</label>
								</div>
							  </td>
							  <td style="width: 50%;">
								<div class="checkbox checkbox-primary">
							      <input type="checkbox" name="geo_all" id="geo_all" value="all" <? if( $edit_test['geo_all'] == 'all' ) echo 'checked="selected"';?> /> <label>Другие страны</label>
								</div>
							  </td>
							</tr>
						  </table>
						</div>
					  </div>
					  
					  <div class="form-group error-form-fix" id="block_title_error">
					    <div class="hr-dashed"></div>
						<div class="alert alert-dismissible alert-info" id="success_ajax">
						  Изменения успешно сохранены!
						</div>
						<div class="alert alert-dismissible alert-danger" id="error_ajax">
						  Внимание ошибка!
						</div>
					  </div>
					
					  <div class="hr-dashed"></div>
					  <div class="form-group class-float-right">
						<div class="col-sm-8 col-sm-offset-2">
						  <button class="btn btn-primary" type="submit" onclick="config_1();return false;">Сохранить изменения</button>
						</div>
					  </div>
					  
					</form>
				  </div>
				</div>
			  </div>
			  
			  
			  
			</div>
		  </div>
		</div>
	  </div>
	</div>
  <?
} 
?>