<?php
ob_start();
require_once '../incfiles/core.php';
require_once '../incfiles/func.php';
require_once '../incfiles/auth.php';
require_once '../incfiles/user.php';
if (empty($user_id)) {go(URL.'/');}
$title = lang('Флирт','Флірт').'';
require_once '../incfiles/head.php';

echo '<div class="title">'.lang('Флирт','Флірт').' </div>';

if($_GET['act'] == 'yes'){
	$query = mysql_query("SELECT `id` FROM `users` WHERE `sex` = '".($user['sex'] == 1 ? 2 : 1)."' and `id` != '".$user['id']."' and `avatar` != 0 ORDER by RAND() LIMIT 1");
	$rand = mysql_fetch_array($query);
	
	$req_vop = mysql_query("SELECT * FROM `flirt_vopros` WHERE `id` != ".intval($_COOKIE['vopros'])."  and `sex` = '".($user['sex'] == 1 ? 2 : 1)."' ORDER BY RAND()");
	$vopros = mysql_fetch_array($req_vop);
	
	mysql_query("UPDATE `users` SET `rating` = `rating` + '0.1' WHERE `id` = '".intval($_GET['user'])."'");
	mysql_query("UPDATE `users` SET `statts` = `statts` + '0.1' WHERE `id` = '".intval($_GET['user'])."'");
	mysql_query("UPDATE `users` SET `statts` = `statts` + '0.1' WHERE `id` = '".$user_id."'");
	
	
	$req_insert = mysql_query("SELECT * FROM `flirt_vopros` WHERE `id` = ".intval($_GET['vopros'])."");
	$vopros_insert = mysql_fetch_array($req_insert);
	
	mysql_query("INSERT INTO `flirt_history` SET 
	`user_id` = '$user_id', 
	`who_id` = '".intval($_GET['user'])."' , 
	`type` = 'yes', 
	`sex` = '".$user['sex']."', 
	`text_ru` = '".$vopros_insert['ru_text']."',
	`text_ua` = '".$vopros_insert['ua_text']."',
	`time` = '".time()."'");
	
	if (mysql_query("INSERT INTO `notifications` SET
				`from_id` = '".$user_id."',
				`sex` = '".$user['sex']."',
				`for_id` = '".intval($_GET['user'])."',
				`mod` = 'flirt',
				`type` = 'comm',
				`refid` = '0',
				`id_file` = '".mysql_insert_id()."',
				`time` = '".time()."',
				`count` = 1,
				`new` = 1
				") == true) mysql_query("UPDATE `users` SET `notifications` = 1, notifications_journal=notifications_journal+1 WHERE `id` = '".intval($_GET['user'])."'");
	
	setcookie('flirt', $rand['id'], time()+86400*365, '/');
	setcookie('vopros', $vopros['id'], time()+86400*365, '/');
	go(URL.'/flirt/index.php?'); exit;
}

if($_GET['act'] == 'no'){
	$query = mysql_query("SELECT `id` FROM `users` WHERE `sex` = '".($user['sex'] == 1 ? 2 : 1)."' and `id` != '".$user['id']."' and `avatar` != 0 ORDER by RAND() LIMIT 1");
	$rand = mysql_fetch_array($query);
	
	$req_vop = mysql_query("SELECT * FROM `flirt_vopros` WHERE `id` != ".intval($_COOKIE['vopros'])."  and `sex` = '".($user['sex'] == 1 ? 2 : 1)."' ORDER BY RAND()");
	$vopros = mysql_fetch_array($req_vop);
	
	mysql_query("UPDATE `users` SET `rating` = `rating` - '0.1' WHERE `id` = '".intval($_GET['user'])."'");
mysql_query("UPDATE `users` SET `statts` = `statts` + '0.2' WHERE `id` = '".intval($_GET['user'])."'");
mysql_query("UPDATE `users` SET `statts` = `statts` + '0.2' WHERE `id` = '".$user_id."'");

	
	
	$req_insert = mysql_query("SELECT * FROM `flirt_vopros` WHERE `id` = ".intval($_GET['vopros'])."");
	$vopros_insert = mysql_fetch_array($req_insert);
	
	mysql_query("INSERT INTO `flirt_history` SET 
	`user_id` = '$user_id', 
	`who_id` = '".intval($_GET['user'])."' , 
	`type` = 'no', 
	`sex` = '".$user['sex']."', 
	`text_ru` = '".$vopros_insert['ru_text']."',
	`text_ua` = '".$vopros_insert['ua_text']."',
	`time` = '".time()."'");
	
	if (mysql_query("INSERT INTO `notifications` SET
				`from_id` = '".$user_id."',
				`sex` = '".$user['sex']."',
				`for_id` = '".intval($_GET['user'])."',
				`mod` = 'flirt',
				`type` = 'comm',
				`refid` = '0',
				`id_file` = '".mysql_insert_id()."',
				`time` = '".time()."',
				`count` = 1,
				`new` = 1
				") == true) mysql_query("UPDATE `users` SET `notifications` = 1, notifications_journal=notifications_journal+1 WHERE `id` = '".intval($_GET['user'])."'");
	
	setcookie('flirt', $rand['id'], time()+86400*365, '/');
	setcookie('vopros', $vopros['id'], time()+86400*365, '/');
	go(URL.'/flirt/index.php?'); exit;
}

$query = mysql_query("SELECT * FROM `avatars`  ".(empty($_COOKIE['flirt']) ? 'ORDER by RAND()' : ' WHERE `user_id` = '.intval($_COOKIE['flirt']))." LIMIT 1");
$arr_ava = mysql_fetch_array($query);

$result = mysql_query("SELECT * FROM `flirt_vopros` ".(!empty($_COOKIE['vopros']) ? 'WHERE `id` = '.intval($_COOKIE['vopros']).' and `sex` = '.($user['sex'] == 1 ? 2 : 1) : 'WHERE `sex` = '.($user['sex'] == 1 ? 2 : 1).' ORDER BY RAND()')."");
$vopros_text = mysql_fetch_array($result);

?>
<style>
.booble {
    border: 1px solid #CCCCCC;
    background-color: #fff;
    border-radius: 9px;
    -webkit-border-radius: 9px;
    -moz-border-radius: 9px;
    -khtml-border-radius: 9px;
    line-height: 130%;
    margin: auto;
    margin-top: 4px;
    margin-bottom: 9px;
    padding: 5px;
    position: relative;
    width: 95%;
    clear: left;
}

.f_red {
    color: #B40033;
}
.bold {
    font-weight: bold;
}
.booble .arrow {
    background: url("sp_arrow.png") 0px 0px no-repeat transparent;
    bottom: -8px;
    display: block;
    height: 8px;
    left: 46%;
    position: absolute;
    width: 15px;
}

.button_g {
    background-color: #1CB841;
	 color: white;
    border-radius: 4px;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    -khtml-border-radius: 4px;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
    font-family: inherit;
    font-size: 13px;
    padding: 5px 8px;
    display: inline-block;
    line-height: normal;
    white-space: nowrap;
    vertical-align: baseline;
    text-align: center;
    cursor: pointer;
    text-transform: none;
    text-decoration: none;
    border: 0;
}
.button_r {
    background-color: #dd514c;
    color: white;
    border-radius: 4px;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    -khtml-border-radius: 4px;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
    font-family: inherit;
    font-size: 13px;
    padding: 5px 8px;
    display: inline-block;
    line-height: normal;
    white-space: nowrap;
    vertical-align: baseline;
    text-align: center;
    cursor: pointer;
    text-transform: none;
    text-decoration: none;
    border: 0;
}

.vote_block span {
    font-size: 15px;
    color: #585858;
    font-weight: bold;
}

.vote_block {
    padding: 12px 0 6px 0;
    text-align: center;
    line-height: 1.5;
}
.box_a, .box_b, .box_i, .box_n {
    line-height: 150%;
    padding: 8px;
    word-wrap: break-word;
    clear: left;
}
Inherited from body

</style>

<?


$req = mysql_query("SELECT * FROM `users` WHERE `id` = '".$arr_ava['user_id']."'");
$user_ava = mysql_fetch_array($req);

if(empty($vopros_text['id'])) $vopros_text['id'] = 1;

echo '<div class="block"><center>
<div class="booble">
	<img src="off.png" alt="" class="ico"> <span class="bold f_red">'.$user_ava['name'].' '.$user_ava['surname'].' ('.$user_ava['rating'].')</span>'.($user_ava['hide_year'] != 0 ? ', '.age($user_ava['day'],$user_ava['month'],$user_ava['year']) : null).'
	'.(!empty($user_ava['city']) ? '<br>'.$user_ava['city'] : null).'<br>	<span class="arrow"></span>
</div><img class="preview" src="'.URL.'/files/avatars/'.$arr_ava['user_id'].'/preview/'.$arr_ava['name'].'"/>
<br /><div class="box_a vote_block"><span>'.$vopros_text['text'].' '.lang($vopros_text['ru_text'],$vopros_text['ua_text']).'

</span><div><br />
<a class="button_g bold" style="width: 18pt; margin: 4px 10px 2px 0px; padding: 6px 10px; font-size: 14px;" href="?act=yes&vopros='.$vopros_text['id'].'&user='.$user_ava['id'].'"  onclick="Page.Go(this.href); return false;">'.lang('Да','Так').'</a>
<a class="button_r bold" style="padding: 6px 10px; font-size: 14px;" href="?act=no&vopros='.$vopros_text['id'].'&user='.$user_ava['id'].'"  onclick="Page.Go(this.href); return false;">'.lang('Нет','Ні').'</a>
</center>';

if(empty($_COOKIE['flirt'])){
	$query = mysql_query("SELECT `id` FROM `users` WHERE `sex` = '".($user['sex'] == 1 ? 2 : 1)."' and `id` != '".$user['id']."' and `avatar` != 0 ORDER by RAND() LIMIT 1");
	$rand = mysql_fetch_array($query);
	
	$req_vop = mysql_query("SELECT * FROM `flirt_vopros`  WHERE `id` != ".intval($_COOKIE['vopros'])." and `sex` = '".($user['sex'] == 1 ? 2 : 1)."' ORDER BY RAND()");
	$vopros = mysql_fetch_array($req_vop);
	setcookie('flirt', $rand['id'], time()+86400*365, '/');
	setcookie('vopros', $vopros['id'], time()+86400*365, '/');
}

require_once '../incfiles/foot.php';


?>