}
$minimum_external = array(5 => 30, 10 => 50, 15 => 60, 20 => 70);
// 	echo set_coupon_external('3','','',5,$minimum_external[5],'www.innovashop.tv/gift_sms')."<br>";
// // 	echo (4 % 4)."<br>";
// // 	echo (3 % 4)."<br>";
// // 	echo (2 % 4)."<br>";
// // 	echo (1 % 4)."<br>";
// // 	echo (0 % 4)."<br>";
// 	return;
// Include the PHP TwilioRest library
require "twilio.php";
// Twilio REST API version
$ApiVersion = "2010-04-01";
// Set our AccountSid and AuthToken
$AccountSid = "ACab28583e662dcbf859ad7c0bf28d79b3";
$AuthToken = "454323a547b60b63f55faa44849959cc";
// Instantiate a new Twilio Rest Client
$client = new TwilioRestClient($AccountSid, $AuthToken);
// make an associative array of server admins
$people = array("7024150544" => "7024150544", "4848095924" => "4848095924", "4106249335" => "4106249335", "8155055787" => "8155055787", "2148547074" => "2148547074", "2148817818" => "2148817818", "2147158065" => "2147158065", "2146078480" => "2146078480", "9803288215" => "9803288215", "9563424185" => "9563424185", "9045543263" => "9045543263", "3054672615" => "3054672615", "9563424185" => "9563424185", "9512964397" => "9512964397", "8058901699" => "8058901699", "9802009997" => "9802009997", "3134240913" => "3134240913", "4693353497" => "4693353497", "9723588145" => "9723588145", "7608990114" => "7608990114", "3134240913" => "3134240913", "2139092084" => "2139092084", "6269230249" => "6269230249", "9727488756" => "9727488756", "8173171009" => "8173171009", "8052481918" => "8052481918", "4694466857" => "4694466857", "7143910850" => "7143910850", "7135843055" => "7135843055", "7862004423" => "7862004423", "9092324439" => "9092324439", "6822215143" => "6822215143", "2148593338" => "2148593338", "4093384907" => "4093384907", "2106072643" => "2106072643", "3234455131" => "3234455131");
// Iterate over all our server admins
foreach ($people as $number => $name) {
    // Send a new outgoinging SMS by POST'ing to the SMS resource */
    // YYY-YYY-YYYY must be a Twilio validated phone number
    $response = $client->request("/{$ApiVersion}/Accounts/{$AccountSid}/SMS/Messages", "POST", array("To" => $number, "From" => "760-547-7777", "Body" => "Felicitaciones! Su regalo lo puede pedir en www.innovashop.tv/sms o llamandonos al 888-448-7762 y usando esta clave " . set_coupon_external('3', '', '', 5, $minimum_external[5], 'www.innovashop.tv/gift_sms')));
    if ($response->IsError) {
        echo "Error: {$response->ErrorMessage}";
    } else {
        echo "Sent message to {$name}";
    }
}
    }
}
//look for customers with the same cellphone
// 	$sth = mysql_query("Select * from sl_customers where right(cellphone,10)=right($in[from],10)") or die("Query failed : " . mysql_error());
// 	while ($rec = mysql_fetch_assoc($sth))
// 	{
// 		$customers.="ID:$rec[ID_customers]<br>\nName: $rec[FirstName]<br>\nLast Name: $rec[LastName1]<br>\n";
// 	}
if (isset($in['from']) and $in['from'] != '' and isset($in['body']) and $in['body'] != '') {
    #it looks for the customers
    $sth = mysql_query("Select ID_orders\n\t\tfrom sl_customers \n\t\tinner join sl_orders on sl_customers.ID_customers=sl_orders.ID_customers\n\t\twhere right(cellphone,10)=right({$in['from']},10) \n\t\torder by ID_orders desc\n\t\tlimit 1") or die("Query failed : " . mysql_error());
    $rec = mysql_fetch_assoc($sth);
    mysql_query("Insert into sl_orders_notes \n\t\tset ID_orders='{$rec['ID_orders']}',\n\t\tNotes='El usuario con celular número: {$in['from']} escribió:<br>\n{$in['body']}<br>\n',\n\t\tType='Low',\n\t\tDate=curdate(),\n\t\tTime=curtime(),\n\t\tID_admin_users='1'") or die("Query failed : " . mysql_error());
    $bodymail = "Éste correo es para usuarios que piden regalo vía SMS.<br>\nEl usuario con celular número: {$in['from']} escribió:<br>\n{$in['body']}<br>\n";
    $cabeceras_sm = 'MIME-Version: 1.0' . "\r\n";
    $cabeceras_sm .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    $cabeceras_sm .= 'From: sales@innovagroupusa.com<*****@*****.**>' . "\r\n";
    mail('*****@*****.**', 'Gift via SMS', $bodymail, $cabeceras_sm);
    mail('*****@*****.**', 'Gift vía SMS', $bodymail, $cabeceras_sm);
    mail('*****@*****.**', 'Gift vía SMS', $bodymail, $cabeceras_sm);
}
header("content-type: text/xml");
//   	$sth = mysql_query("insert into sl_orders_notes set notes='inserta".print_r($in,1)."'") or die("Query failed : " . mysql_error());
echo "<?xml version='1.0' ?>\n";
?>
<Response>
	<Sms><?php 
echo "Felicitaciones! Su regalo lo puede pedir en www.innovashop.tv/sms o llamandonos al 888-448-7762 y usando esta clave " . set_coupon_external('3', '', '', 5, $minimum_external[5], 'www.innovashop.tv/gift_sms');
?>
</Sms>
</Response>