<?php

if(!defined('MOZG'))
	die('Hacking attempt!');

if($ajax == 'yes')
	NoAjaxQuery();

if($logged){
	$act = $_GET['act'];
	
	
	
	switch($act){
	
	
		case "send":
			NoAjaxQuery();
		
			
			include ENGINE_DIR.'/classes/smspilot.class.php';

// Отправки SMS и заодно проверка баланса
$phone_test = $db->super_query("SELECT user_phone FROM `".PREFIX."_users` WHERE user_phone = '".$_POST['number']."'");

if(!$phone_test) {
	$apikey = '4J410J321K6S7E68FWU08694X5683DI0F1Z858L6E832TQLQ5RA30DOVWP3XHF2J';
	
	$sms = new SMSPilot( $apikey );
	
	$sms->from = $_POST['from'];
	
	$mains = rand(10000, 99999);
	
	$db->query("UPDATE `".PREFIX."_users` SET user_phone = '{$_POST['number']}', user_sms_hash = '{$mains}' WHERE user_id = '{$user_info['user_id']}'");
	
	$sms->send($_POST['number'], $mains);
	
	echo "1";	
} else {
	echo "2";	
}			

			die();
		break;
		
		
		case "check":
			NoAjaxQuery();
		
			
			

// Отправки SMS и заодно проверка баланса
$test = $db->super_query("SELECT user_sms_hash FROM `".PREFIX."_users` WHERE user_id = '".$user_info['user_id']."' AND user_sms_hash = '".$_POST['code']."'");

if($test) {
	
	$db->query("UPDATE `".PREFIX."_users` SET user_sms = '1' WHERE user_id = '{$user_info['user_id']}'");
	
	mozg_clear_cache_file('user_'.$user_info['user_id'].'/profile_'.$user_info['user_id']);
	mozg_clear_cache();
			
	echo "/u".$user_info['user_id']."";	
} else 
	echo "0";	
			

			die();
		break;
		
		
		default:
			
			
	}	
	
} else {
	$user_speedbar = 'Информация';
	msgbox('', $lang['not_logged'], 'info');
}
?>