<?php
	// open/close
	$lock = "no";
	// function
	if($lock == "no")
	{
		// no title
		$freklama_title = "info >";
		// no email
		$freklama_email = "send@sms.com";
		// current time
		$plus_time_today = strtotime ("+0 hour");
		$current_date = date(Y."-".m."-".d, $plus_time_today); 
		// include db // comments
		//include("db.php");
		// number 77-554433 // comments
		//$mobile_email = $_GET['mobile_email'];
		//$number2 = substr($mobile_email, 3, 8);
		// echo($number2);
		//
		$startnumber = $preff2;
		//
		if($svariant == "sms_geo" || $svariant == "sms_eng")
		{
			$startnumber = $sms_startnumber[$prefix];
		}
		//echo($startnumber."11");
		// function write new number
		$result1 = mysql_query("SELECT * FROM gsms_number WHERE number = '$mobile_number' AND startnumber = '$startnumber'", $db);
		if($myrow1 = mysql_fetch_array($result1))
		{
			$count1 = $myrow1['count'];
			$count1 = $count1 + 1;
			// update count
			mysql_query("UPDATE gsms_number SET count = '$count1' WHERE number = '$mobile_number' AND startnumber = '$startnumber'");
		}
		else
		{
			// write new number
			mysql_query("INSERT INTO gsms_number values('','$mobile_number','0','$current_date','$startnumber')");
		}
		// end write new number
		// delete data if not today
		mysql_query("DELETE FROM gsms_secure WHERE date <> '$current_date'");
		// write reklama number
		$result2 = mysql_query("SELECT * FROM gsms_secure WHERE number = '$mobile_number' AND startnumber = '$startnumber'", $db);
		if($myrow2 = mysql_fetch_array($result2))
		{
			$count2 = $myrow2['count'];
			$count2 = $count2 + 1;
			// update count
			mysql_query("UPDATE gsms_secure SET count = '$count2' WHERE number = '$mobile_number' AND startnumber = '$startnumber'");
		}
		else
		{
			// write new number
			mysql_query("INSERT INTO gsms_secure values('','$mobile_number','0','$current_date','$startnumber')");
			// new number and send reklama sms
			$result3 = mysql_query("SELECT * FROM gsms_send", $db);
			if($myrow3 = mysql_fetch_array($result3))
			{
				$count3 = $myrow3['count'];
				$count3 = $count3 + 1;
				//
				$strlenp = strlen($count3);
				$strlenm = $strlenp - 1;
				$count4 = substr($count3, $strlenm, 1);
				// echo('<br>'.$count4);
				// update count gsms_send
				mysql_query("UPDATE gsms_send SET count = '$count3'");
				// sms reklama
				$result5 = mysql_query("SELECT * FROM gsms_reklama WHERE idn = '$count4' AND status = '1'", $db);
				if($myrow5 = mysql_fetch_array($result5))
				{
					// update count gsms_reklama
					$count5 = $myrow5['count'];
					$count5 = $count5 + 1;
					mysql_query("UPDATE gsms_reklama SET count = '$count5' WHERE idn = '$count4'");
					// title check
					if($myrow5['title'] != "")
					{
						$freklama_title = $myrow5['title'];
					}
					// email check
					if($myrow5['email'] != "")
					{
						$freklama_email = $myrow5['email'];
					}
					// send sms data
					$headers_adv = "From: ".$freklama_email." \n";
					$text_reklama = $myrow5['text'];
					// write test
					// echo($mobile_email."<br>".$freklama_title."<br>".$text_reklama."<br>".$headers_adv."<br>");
					// send sms reklama
					mail($mobile_email, $freklama_title, $text_reklama, $headers_adv);
					$b5 = $mobile_email;
					$b6 = $freklama_title;
					$b7 = $text_reklama;
					$b8 = $headers_adv;
				}
				//end sms reklama
			}
			// end new number and send reklama sms
		}
		// write reklama
	}
	// end open/close
?>