<?php
	


	include_once(__DIR__."/../../core.php");
	$idanagrafica = save($_GET['idanagrafica']);
	$id_record = save($_GET['idanagrafica']);

	// lettura parametri sms
	$gateway_sms = get_var( 'Gateway SMS' );
	$oggetto = get_var( 'Oggetto SMS' );

	//Mi ricavo il cellulare  del cliente
	$q = "SELECT cellulare FROM an_anagrafiche WHERE idanagrafica='".$idanagrafica."'";
	$rs_ana = $dbo->fetchArray($q);
	$mail_destinatario = "+39".$rs_ana[0]['cellulare'].$gateway_sms;
	
	$testo_sms="";



	echo "<script type=\"text/javascript\" charset=\"utf-8\" src=\"".$rootdir."/lib/ckeditor/ckeditor.js\"></script>\n";

	echo "<form id=\"send_email\" action=\"".$rootdir."/editor.php?id_module=$id_module&id_record=$id_record\" onsubmit=\"return check_submit()\" method=\"post\">\n";
	echo "	<input type='hidden' name='backto' value='record-edit'>\n";
	echo "	<input type='hidden' name='op' value='sendemail'>\n";
	echo "	<input type='hidden' name='id_record' value='".$id_record."'>\n";


	echo "	<div class='row form-group'>\n";
	echo "		<div class='col-md-2'>\n";
	echo "			<span><b>Destinatario:</b><span>";
	echo "		</div>\n";
	echo "		<div class='col-md-8'>\n";
	echo "			<input type=\"text\" name=\"destinatario\" id=\"destinatario\" maxlength=\"255\"  value=\"".$mail_destinatario."\" class=\"form-control\" />\n";
	echo "		</div>\n";
	echo "	</div>\n";	

	// oggetto
	echo "	<div class='row form-group'>\n";
	echo "		<div class='col-md-2'>\n";
	echo "			<span><b>Oggetto:</b><span>";
	echo "		</div>\n";
	echo "		<div class='col-md-8'>\n";
	echo "			<input type=\"text\" name=\"oggetto\" id=\"oggetto\" maxlength=\"255\"  value=\"".$oggetto."\" class=\"form-control\"  />\n";
	echo "		</div>\n";
	echo "	</div>\n";
	
	
	// corpo del messaggio
	echo "	<div class='row form-group'>\n";
	echo "		<div class='col-md-12'>\n";
	echo "			<textarea placeholder=\"\" class=\"form-control\" id=\"body\" name=\"body\">$testo_sms</textarea>\n";
	echo "		</div>\n";
	echo "	</div>\n";
	
	
	echo "	<button type='button' class='btn btn-primary pull-right' onclick=\"$('#send_email').submit();\"><i class=\"fa fa-envelope\"></i> Invia E-mail to SMS </button>\n";
	
	echo "</form>\n";
	echo "<div class='clearfix'></div>\n";
?>


<script type="text/javascript">
	
	function check_submit(){

		if( $('#destinatario').val()!='' && $('#oggetto').val()!='' ){

			if( confirm('Inviare E-mail TO Sms?') ) 
					return true;
			else 
					return false;

		} else {
			alert("impostare destinatario ed oggetto!");
			return false;
		}
	}
	


	$(document).ready(function(){

		// autocompletamento destinatario
		$(document).load("ajax_autocomplete.php?module=Anagrafiche&op=getemail&idanagrafica=<?php echo $idanagrafica ?>", function(response){
			$("#destinatario").autocomplete({source: response.split("|")});

		} );

	
		
		

	});

	
</script>
