<?php
	include("vars.php");
	include("db.php");

	$page_status = "no";
	if(isset($u_event) && isset($u_secure))
	{

		session_cache_limiter('private');
		$cache_limiter = session_cache_limiter();

		session_cache_expire(90);
		$cache_expire = session_cache_expire();

		session_start();

		$s_secure = $_SESSION['s_secure'];
		$user_id = $_SESSION['user_id'];
		
		if($u_secure == $s_secure)
		{
			if(isset($s_secure) && isset($user_id))
			{
				$page_status = "yes";
				$result = mysql_query("SELECT * FROM register WHERE id = '$user_id'",$db);
				$myrow = mysql_fetch_array($result);
				$active_code = $myrow['active_code'];
				if($u_event == "book")
				{
					echo('<script>'."\n");
					echo('parent.first.location = "home_book.php?user_id='.$user_id.'&active_code='.$myrow['active_code'].'&u_event=sms&u_secure='.$u_secure.'"');
					echo('</script>'."\n");
				}
				if($_SERVER['REQUEST_METHOD'] == "POST" && $sms_user != "" && $sms_geo_result != "" && $u_event != "" && $u_secure != "" && $your_name_result != "")//
				{
					//
					$dline = strlen($sms_geo_result);
					if($dline < $dline_count)
					{
						$sms_geo_result = $sms_geo_result;
					}
					//
					if($myrow['with_email'] == "yes")
					{
						$headers = "From: ".$myrow['email']." \n";
					}
					else
					{
						$headers = "From: ".$email_from_var." \n";
					}
					//
					if($myrow['with_name'] == "yes")
					{
						$sms_sender_name = $your_name_result;
					}
					else
					{
						$sms_sender_name = "Noname";
					}
					//
					$sms_sender_name = $sms_sender_name." >";
					// $mobile_email = "995".$sms_user."@sms.ge";
					//
					$result15 = mysql_query("SELECT * FROM sms_user WHERE id = '$sms_user'", $db);
					if($myrow15 = mysql_fetch_array($result15))
					{
						$preff2 = "995";
						$smsgate2 = "@sms.ge";
						//
						$mobile_number = $myrow15['user_mobile'];
						if($myrow15['nstyle'] == 2)
						{
							$preff2 = $myrow15['startnumber'];
							$smsgate2 = $myrow15['smsgateway'];
						}
					}
					$mobile_email = $preff2.$mobile_number.$smsgate2;
					// echo($mobile_email);
					//
					$msg = "";
					mysql_query("DELETE FROM secure WHERE event_date <> '$event_date'");
					$result = mysql_query("SELECT * FROM secure WHERE user_ip = '$user_ip'", $db);

					if($myrow = mysql_fetch_array($result))
					{
						$sms_count = $myrow["sms_count"];
						$sms_count = $sms_count + 1;
						if($sms_count < $max_sms_ry)
						{
							mysql_query("UPDATE secure SET sms_count = '$sms_count' WHERE user_ip = '$user_ip'");
							// sms total
							$result = mysql_query("SELECT * FROM sms_statics", $db);
							$myrow = mysql_fetch_array($result);
							$sms_total = $myrow["sms_total"];
							$sms_total = $sms_total + 1;
							mysql_query("UPDATE sms_statics SET sms_total = '$sms_total'");
							//
							$result = mysql_query("SELECT * FROM register WHERE id = '$user_id'", $db);
							$myrow = mysql_fetch_array($result);
							$sms_total = $myrow["sms_count"];
							$sms_total = $sms_total + 1;
							mysql_query("UPDATE register SET sms_count = '$sms_total' WHERE id = '$user_id'");
							// reiting
							$result10 = mysql_query("SELECT * FROM sms_user WHERE id = '$sms_user'", $db);
							if($myrow10 = mysql_fetch_array($result10))
							{
								$smucount = $myrow10['count'];
								$smucount = $smucount + 1;
								mysql_query("UPDATE sms_user SET count = '$smucount' WHERE id = '$sms_user'");
							}							
							//
							//mail();
							$svariant = "sms_reg";
							include($sfile_url);
							$msg = "<font face='Tahoma,Arial,Verdana' size='1'>SMS</font>-i gagzavnilia, ".$preff2.$mobile_number." (".$send_time.")";
						}
						else
						{
							$msg = "dRes sakmarisia Tqveni <font face='Tahoma,Arial,Verdana' size='1'>SMS</font>-ebis gagzavna";
						}
					}
					else
					{
						mysql_query("INSERT INTO secure values('','$user_ip','1','','','','$event_date')");
						// sms total
						$result = mysql_query("SELECT * FROM sms_statics", $db);
						$myrow = mysql_fetch_array($result);
						$sms_total = $myrow["sms_total"];
						$sms_total = $sms_total + 1;
						mysql_query("UPDATE sms_statics SET sms_total = '$sms_total'");
						//
						$result = mysql_query("SELECT * FROM register WHERE id = '$user_id'", $db);
						$myrow = mysql_fetch_array($result);
						$sms_total = $myrow["sms_count"];
						$sms_total = $sms_total + 1;
						mysql_query("UPDATE register SET sms_count = '$sms_total' WHERE id = '$user_id'");
						// reiting
						$result9 = mysql_query("SELECT * FROM sms_user WHERE id = '$sms_user'", $db);
						if($myrow9 = mysql_fetch_array($result9))
						{
							$smucount = $myrow9['count'];
							$smucount = $smucount + 1;
							mysql_query("UPDATE sms_user SET count = '$smucount' WHERE id = '$sms_user'");
						}
						//
						//mail();
						$svariant = "sms_reg";
						include($sfile_url);
						$msg = "<font face='Tahoma,Arial,Verdana' size='1'>SMS</font>-i gagzavnilia, ".$preff2.$mobile_number." (".$send_time.")";
					}
				}
				else
				{
					//$msg = "sms-i ar gaigzavna";
				}
			}	
		}
	}
mysql_close();
?>
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title></title>
<link href="../js_css/iframe.css" rel="stylesheet">
</head>

<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0" bgcolor="#1AB9F1">
<script language="javascript" src="../js_css/javascript.js"></script>
<form name="form1" action="<?=$_SERVER['REQUEST_URI']?>" method="POST">
<table border="0" width="297" id="table1" cellspacing="0" cellpadding="0">
	<tr>
		<td height="19" colspan="2" width="297">
		<img border="0" src="../img/title/address_book.jpg" width="196" height="19"></td>
	</tr>
	<tr>
		<td width="10">&nbsp;</td>
		<td width="287" class="geo">&nbsp;</td>
	</tr>
<?php
if($page_status == "yes")
{
?>
	<tr>
		<td width="10">&nbsp;</td>
		<td width="287" class="geo">
		<select name="sms_user" class="in_geo3">
		<option value="00">nomrebis wignaki</option>
		<?php
		$result = mysql_query("SELECT * FROM sms_user WHERE user_id = '$user_id' ORDER by your_name ASC",$db);
		if($myrow = mysql_fetch_array($result))
		{
			do{
				$preff = "995";
				if($myrow['nstyle'] == 2)
				{
					$preff = $myrow['startnumber'];
				}
				echo('<option value="'.$myrow['id'].'">'.$myrow['your_name'].' '.$myrow['your_surname'].' - '.$preff.$myrow['user_mobile'].'</option>'."\n");
			}
			while($myrow = mysql_fetch_array($result));
		}
		$result = mysql_query("SELECT * FROM register WHERE id = '$user_id'",$db);
		if($myrow = mysql_fetch_array($result))
		{
			$current_name = $myrow['name'];
		}
		?>
		</select>&nbsp;</td>
	</tr>
	<tr>
		<td width="10">&nbsp;</td>
		<td width="287" class="geo">
		<textarea name="sms_geo" cols="43" rows="6" class="in_geo" onfocus="input_empty('sms_geo','teqsti');" ondblclick="text_replace_su();"  onfocus="text_replace_su();"  onkeypress="text_replace_su();"  onkeydown="text_replace_su();"  onkeyup="text_replace_su();"  onchange="text_replace_su();"  onblur="text_replace_su();">teqsti</textarea>
		<input type="hidden" name="sms_geo_result" value="">
		<input type="hidden" name="your_name" value="<?=$current_name?>">
		<input type="hidden" name="your_name_result" value="">
		<input type="hidden" name="active_code" value="<?=$active_code?>">
		<input type="hidden" name="sta_geo" id="sta_geo" value="geo">
		<input type="hidden" name="u_event" value="sms">
		<input type="hidden" name="u_secure" value="<?=$u_secure?>">
		</td>
	</tr>
	<tr>
		<td width="10">&nbsp;</td>
		<td width="287" class="geo">
		<input type=button class="bu_geo3" name="send" value="  gagzavna" style="cursor:hand;" onclick="send_to_user();">&nbsp;&nbsp;
		<input type=text class="in_geo" name="symbols_number" size="5" value="" maxlength="3" readonly>
		&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" class="link_geo4" onclick="parent.first.location='home_book.php?user_id=<?=$user_id?>&active_code=<?=$active_code?>&u_event=sms&u_secure=<?=$u_secure?>'"><img src="../img/icons/9.gif" width="16" height="16" border="0">&nbsp;kontrol paneli</a></td>
	</tr>
<?}?>
	<tr>
		<td width="10">&nbsp;</td>
		<td width="287" class="geo_s" align="center">&nbsp;<?=@$msg?><?php include("redirect.php");?></td>
	</tr>
</table>
</form>
</body>

</html>