<?
error_reporting(0);
@error_reporting(E_ALL ^ E_NOTICE);
@ini_set('display_errors', false);
@ini_set('html_errors', false);
@ini_set('error_reporting', E_ALL ^ E_NOTICE);
require_once("lib/curl_http_client.php");
$curl = new Curl_HTTP_Client();
$useragent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$curl->set_user_agent($useragent);
$cookies_file = 'cookie.txt';
$curl->store_cookies($cookies_file);
$curl->set_referrer("https://mobile.beeline.uz/uz/main/sms/send.wbp");

if (isset($_GET['captcha'])){
error_reporting(0);
$url = "https://mobile.beeline.uz/uz/main/sms/mamimg.aspx";
$captcha = $curl->fetch_url($url);
@error_reporting(E_ALL ^ E_NOTICE);
echo $captcha;
exit();
}
define('_IN_JOHNCMS',1);
$textl='Bepul sms yuborish (Beeline)';
$rootpath='../../';
include_once $rootpath.'incfiles/core.php';
include_once $rootpath.'incfiles/head.php';
$headmod=''.$textl;
echo "<div align='center' class='phdr'>".$textl."</div>";
error_reporting(0);
$sql = mysql_query("SELECT `time` FROM `sms_service` ORDER BY `time` ASC"); 
$count = mysql_num_rows($sql);
$after_time = time() - 301;
if ($count > 0)
{
$timeleft = mysql_fetch_assoc($sql);

	if ($timeleft['time'] > $after_time)
	{
		$pause_time = date('i:s', $timeleft['time']);
	}
}

if (isset($_POST['ok']))
{
	$prefix = trim($_POST['prefix']);
	$number = trim($_POST['phone']);
	$captcha = trim($_POST['captcha']);
	$message = $_POST['message'];
	
	if ( isset($pause_time) )
	{
echo '<div class="menu"> Iltimos, ermak uchun bekorga SMS jo\'natmang. O\'zgalar mehnati va sarflagan mablag\'ini xurmat qiling. <b>'.$pause_time.' daqiqa</b>dan keyin qayta urinib ko\'rishingiz mumkin!<br/>- <a href="./">Ortga</a></div>';
		exit();
}
	
	# Prefixni filterlash
	if ( empty($prefix) )
	{
		$error .= 'Xatolik! Perefiks kiritilmadi.';
	}
	elseif ( $prefix != '99890' && $prefix != '99891' )
	{
		$error .= '+"' .$prefix.'" raqam prefiksi noto\'g\'ri farmotda kiritildi.';
	}

	# Raqamni filterlash
	if ( empty($number) )
	{
		$error .= 'Xatolik! Raqamingiz kiritilmadi.';
	}
	elseif ( !preg_match("/^[0-9]*$/", $number) )
	{
		$error .= 'Telefon raqamida faqat sonlar qatnashishi va raqamlar orasida bo\'sh joy bo\'lmasligi kerak.';
	}
	elseif ( !(strlen($number) == 7) )
	{
		$error .= 'Telefon raqami uzunligi 7 ta belgidan iborat bo\'lishi lozim.';
	}
	
	# Xabarni filterlash
	if ( empty($message) )
	{
		$error .= 'Xatolik! Xabar matni kiritilmadi.';
	}
	elseif( !preg_match("#^([A-zА-я0-9\'\`\,\(\)\.\:\!\?\$\%\&\*\@\~\-\_\n\r ])+$#ui", $message) )
	{
		$error .= 'Xatolik! Xabar matnida taqiqlangan belgilar mavjud yoki kril alifbosi belgilari ishlatilgan.';
	}
	elseif ( strlen($message) > 135 || strlen($message) < 2 )
	{
		$error .= 'Xabar matni uzunligi 2-130 ta belgidan iborat bo\'lishi lozim.';
	}

	if ( isset($error) )
	{
echo $error."\n:: <a href=\"./\">Qayta urinib ko'rish</a>";
	}

$message = $message."\n--\nAjoyib.Ru";
	
	$post_data = array('sendsms' => 'send', 'send' => 'send', 'smstext' => $message, 
	'smstoprefix' => $prefix, 'smsto' => $number, 'translit' => '',
	'confirmcode' => $captcha);
	
	$html_data = $curl->send_post_data("https://mobile.beeline.uz/uz/main/sms/send.wbp", $post_data);
	
	include('lib/simple_html_dom.php');
	$html = str_get_html($html_data);
	$result_1 = $html->find('span.red center b', 0) -> innertext;
	$result_2 = $html->find('center[style="margin-bottom: 30"]', 0) -> innertext;
	$result_3 = $html->find('center b', 0) -> innertext;
	if ($result_1 != null)
	{
		if ($result_1 == 'Невозможно отправить сообщение')
			$message = 'Noma\'lum xatolik. Iltimos keyinroq urinib ko\'ring!';
		else
			$message = 'Xatolik! Bir necha daqiqalardan keyin urinib ko\'ring!';
	}
	elseif ($result_2 != null)
		$message = 'Rasmdagi kod xato kiritildi!<br/>- <a href="./">Qayta urinib ko\'rish</a>';
	elseif ($result_3 != null)
	{
		$sql = mysql_query("INSERT INTO `sms_service` (time, number, message) 
		VALUES ('".time()."', '". $prefix.$number. "', '".mysql_real_escape_string($message)."')");
	
		$message = '+'.$prefix.'<b>'.$number.'</b> raqamiga SMS muvaffaqiyatli jo\'natildi!';
	}
	else
	{
		$message = 'Xatolik! Bir necha daqiqalardan keyin urinib ko\'ring!';
	}
	
echo '<div align="center" class="rmenu">'.$message.'</div>';
}


echo '<script type="text/javascript" src="text_count.js"></script>';
if ( isset($pause_time) ){
echo '<div class="menu">
	<span style="color:red">Navbatdagi SMS jo\'natish <b>'.$pause_time.' daqiqadan</b> keyin ishga tushuriladi. Iltimos biroz kuting!</span>
	</div>';
}
echo <<<ECH
<div class="menu">
	<form action="index.php" method="POST" accept-charset="utf-8" enctype="application/x-www-form-urlencoded" > 
	Prefiks:<br/>
	<select name="prefix">
	<option value="99890">+99890</option>
	<option value="99891">+99891</option>
	</select><br>
	Raqam:<br/>
	<input type="text" size="7" maxlength="7" name="phone" value="" {CLASS}/><br>
	Xabar matni:<br/>
	<textarea id="smsarea" name="message"></textarea><br/>
	<input id="symleft" type="text" size="3" maxlength="3" readonly="true"/></span> - belgi qoldi<br/>
	Ruhsat etilgan belgilar: <span class="p_t">- _ , . ) ( ' ` ! : ? $ % & * @ ~</span>
	</div>
<div class="menu">
	Tekshiruv kodi:<br/>
<img src="?captcha" alt="Tekshiruv kodi"><br/>
	Rasmdagi kodni yozing: <br/>
	<input type="text" name="captcha" size="4" maxlength="4" value=""/><br>
	<input type="submit" name="ok" value="Yuborish">  
	</form> 
	</div>
	<div class="sdsfd">
	</div>
<div class="menu">
Umumiy ushbu xizmatdan <b>$count   marta </b> SMS jo'natilgan!<br>

	<span style="color: red">Eslatma!</span><br/>
	1. SMS xabar qabul qiluvchidan hech qanday maxsus sozlamalar talab qilinmaydi, SMS'lar odatdagidek tartibda yuboriladi.<br/>
2. Jo'natilgan SMS'lar har <b>2-3 soniyadayoq</b> qabul qiluvchiga yetkaziladi!<br/>
	3. Agar qabul qiluvchi aloqadan tashqarida (o'chirilgan) bo'lsa. SMS aloqaga chiqqan paytda albatta yetkaziladi.<br/>
	4. Ushbu xizmatdan foydalanish ba'zi cheklovlardan tashqari, mutlaqo bepul hisoblanadi. <br/>
	<span style="color: red">Qat'iyan taqiqlanadi:</span><br/>
	1. Xabar matnida haqoratli so'zlar ishlatish.<br/>
	2. Xabar matnida O'zb. Res. Qonunchiligiga zid so'zlar ishlatish.<br/>
	3. Katta miqdorda SMS spam'lar tarqatish.<br/>
	4. Har turdagi reklamalar tarqatishda foydalanish.<br/>
	* Xizmatdan foydalangan har-bir foydalanuvchi haqidagi ma'lumotlar bazamizda saqlanib qoladi. Ushbu shartlar amal qilinmagan taqdirda qoidabuzarni topish biz uchun muammo bo'lmaydi. Qoidabuzar topilgach esa kechirilmaydi va qattiq qarshi chora ko'riladi!   
	</div>
ECH;

require('../../incfiles/end.php');
?>