<?php
	include("vars.php");
	include("db.php");
	include("operator.php");
	$page_hide = "no";
	$page_status = "no";	

if($_SERVER['REQUEST_METHOD'] == "POST")
{//1
	if($prefix != "")
	{
		$startnumber = $sms_startnumber[$prefix];
		$smsgateway = $sms_smsgateway[$prefix];
		$numbercount = $sms_numbercount[$prefix];
	}
	if($mobile_number && $prefix != "" && $your_name && $your_surname && $user_id  && $user_ip && $active_code && $smsgateway != "" && $numbercount != "")
	{//2
		//
		$result = mysql_query("SELECT * FROM register WHERE id = '$user_id' AND active_code = '$active_code'",$db);
		if($myrow = mysql_fetch_array($result))
		{
			$page_status = "yes";
		}
		//
		if($page_status == "yes")
		{
			// $mobile_num = $prefix.$mobile_number;
			$result = mysql_query("SELECT * FROM sms_user WHERE user_id = '$user_id' AND user_mobile = '$mobile_number' AND startnumber = '$startnumber'",$db);
			if($myrow = mysql_fetch_array($result))
			{
				$msg = "es nomeri Tqven gaqvT ukve damatebuli";
			}
			else
			{
				if($bd_year == "" || $bd_month == "" || $bd_day == "")
				{
					$bd_day = "00"; 
					$bd_month = "00"; 
					$bd_year = "0000";
				}
				$result = mysql_query("SELECT * FROM sms_user WHERE user_id = '$user_id'",$db);
				if($myrow = mysql_fetch_array($result))
				{
					$user_count = 0;
					do
					{
						$user_count = $user_count + 1;
					}
					while($myrow = mysql_fetch_array($result));
				}
				if($user_count < $user_book_count)
				{
					mysql_query("INSERT INTO sms_user values('','$your_name','$your_surname','$mobile_number','$user_id','$bd_day','$bd_month','$bd_year','$t15','0','','$startnumber','$smsgateway','$numbercount','2')");
					//$msg = 'mobiluris nomeri damatebulia, '.'<a href="add_number.php?user_id='.$user_id.'&active_code='.$active_code.'&u_event=sms&u_secure='.$u_secure.'" class="link_geo4" target="_self">kidev nomris damateba</a>, <a href="home_book.php?user_id='.$user_id.'&active_code='.$active_code.'&u_event=sms&u_secure='.$u_secure.'" class="link_geo4" target="_self">ukan dabruneba</a>';
					$msg = "mobiluris nomeri damatebulia";//, '.'<a href="add_number.php?user_id='.$user_id.'&active_code='.$active_code.'&u_event=sms&u_secure='.$u_secure.'" class="link_geo4" target="_self">kidev nomris damateba</a>, <a href="home_book.php?user_id='.$user_id.'&active_code='.$active_code.'&u_event=sms&u_secure='.$u_secure.'" class="link_geo4" target="_self">ukan dabruneba</a>';

					echo('<script>'."\n");
					echo('parent.second.location = "book.php?user_id='.$user_id.'&active_code='.$active_code.'&u_secure='.$u_secure.'&u_event=sms"');
					echo('</script>'."\n");
					$page_hide = "no";
				}
				else
				{
					$msg = "Zalian bevri nomeri gaqvT damatebuli";
				}
			}
		}
		
	}//2
	else
	{//2
		$msg = "nomeri ar aris dametebuli";
	}//2
}//1
else
{
	//$msg = "SemodiT nomrebis wignakSi Tavidan";
}
mysql_close();
?>
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<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="3" width="297">
		<img border="0" src="../img/title/add_number.jpg" width="196" height="19"></td>
	</tr>
	<tr>
		<td width="120" class="geo" align="right">&nbsp;</td>
		<td width="10">&nbsp;</td>
		<td width="167" class="geo">&nbsp;</td>
	</tr>
<?php
if($user_id != "" && $active_code != "" && $page_hide == "no") 
{
	$result = mysql_query("SELECT * FROM register WHERE id = '$user_id' AND active_code = '$active_code'",$db);
	if($myrow = mysql_fetch_array($result))
	{
?>
	<tr>
		<td width="120" class="geo" align="right">&nbsp;saxeli</td>
		<td width="10">&nbsp;</td>
		<td width="167" class="geo"><input type=text class="in_geo" name="your_name" size="16" value="" maxlength="10">&nbsp;</td>
	</tr>
	<tr>
		<td width="120" class="geo" align="right">&nbsp;gvari</td>
		<td width="10">&nbsp;</td>
		<td width="167" class="geo"><input type=text class="in_geo" name="your_surname" size="16" value="" maxlength="20">&nbsp;</td>
	</tr>
	<tr>
		<td width="120" class="geo" align="right">&nbsp;dabadebis TariRi (sasurvelia SeavsoT)</td>
		<td width="10">&nbsp;</td>
		<td width="167" class="geo"><input type=text class="in_geo" name="bd_day" size="2" value="" maxlength="2">&nbsp;<input type=text class="in_geo" name="bd_month" size="2" value="" maxlength="2">&nbsp;<input type=text class="in_geo" name="bd_year" size="4" value="" maxlength="4">&nbsp;[dR]&nbsp;[Tv]&nbsp;[weli]</td>
	</tr>
	<tr>
		<td width="297" class="geo" align="left" colspan="3">&nbsp;
		<select name="prefix" class="in_eng" onchange="onchange_max();">
		<option value="00">GSM Operator</option>
		<?php
			for($i=0;$i<count($sms_operator);$i++)
			{
				$selected = "";
				if($i == $prefix && $_SERVER['REQUEST_METHOD'] == "POST")
				{
					$selected = " selected ";
				}
				if($sms_subject[$i] == 0)
				{
					echo('<option value="'.$i.'" '.$selected.'>'.$sms_operator[$i].'</option>'."\n");
				}
			}
		?>
		</select>
		<?php
			for($i=0;$i<count($sms_operator);$i++)
			{
				echo('<input type="hidden" name="counti'.$i.'" id="counti'.$i.'" value="'.$sms_numbercount[$i].'">');
			}
		?>
		<input name="active_code" value="<?=$active_code?>" type="hidden">
		<input name="user_id" value="<?=$user_id?>" type="hidden">
		<input name="u_event" value="sms" type="hidden">
		<input name="u_secure" value="<?=$u_secure?>" type="hidden">
		</td>
	</tr>
	<tr>
		<td width="120" class="geo" align="right">&nbsp;mobiluris nomeri</td>
		<td width="10">&nbsp;</td>
		<td width="167" class="geo"><input type=text class="in_geo" name="mobile_number" size="18" value="" maxlength="10">&nbsp;</td>
	</tr>
	<tr>
		<td width="120" class="geo" align="right">&nbsp;<a href="javascript:open_popup('300','250','reiting.php');" class="link_geo4">reitingis</a> monawile</td>
		<td width="10">&nbsp;</td>
		<td width="167" class="geo">
		<select name="t15" class="in_geo">
		<?php
			include("yes_no.php");
		?>
		</select>&nbsp;
		</td>
	</tr>
	<tr>
		<td width="120" class="geo" align="right">&nbsp;<a href="home_book.php?user_id=<?=$user_id?>&active_code=<?=$active_code?>&u_event=sms&u_secure=<?=$u_secure?>" class="link_geo4" target="_self">ukan dabruneba</a></td>
		<td width="10">&nbsp;</td>
		<td width="167" class="geo"><input type=button class="bu_geo3" name="send" value=" damateba" style="cursor:hand;" onclick="add_number();">&nbsp;</td>
	</tr>
<?
	}
	else
	{
		$msg = "SemodiT nomrebis wignakSi Tavidan";
	}
}
else
{
	$msg = "SemodiT nomrebis wignakSi Tavidan";
}
?>
	<tr>
		<td height="19" colspan="3" width="297" class="geo" align="center">&nbsp;</td>
	</tr>
	<tr>
		<td height="19" colspan="3" width="297" class="geo" align="center">&nbsp;<?=@$msg?></td>
	</tr>
</table>
</form>
</body>

</html>