<?
//"DAD291DE-1054-4871-001F-CB317F823046"
//include("includes/classes/sms.php");



// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	

  require('includes/application_top.php');
  
$action=isset($HTTP_POST_VARS['action'])?tep_db_prepare_input($HTTP_POST_VARS['action']):'';
$info=isset($HTTP_GET_VARS['info'])?tep_db_prepare_input($HTTP_GET_VARS['info']):'';
if ($action=="send_sms"){
  $sms_serialno=isset($HTTP_POST_VARS['fld_serialno'])?tep_db_prepare_input($HTTP_POST_VARS['fld_serialno']):'';
  $sms_key=isset($HTTP_POST_VARS['fld_key'])?tep_db_prepare_input($HTTP_POST_VARS['fld_key']):'';
  $sms_reply=isset($HTTP_POST_VARS['fld_reply'])?tep_db_prepare_input($HTTP_POST_VARS['fld_reply']):'';
  $sms_from=isset($HTTP_POST_VARS['fld_from'])?tep_db_prepare_input($HTTP_POST_VARS['fld_from']):'';
  $sms_mobile=isset($HTTP_POST_VARS['fld_mobile'])?tep_db_prepare_input($HTTP_POST_VARS['fld_mobile']):'';
  $sms_messagetext=isset($HTTP_POST_VARS['fld_messagetext'])?tep_db_prepare_input($HTTP_POST_VARS['fld_messagetext']):'';
  //echo $sms_serialno . '-' . $sms_key . '-' . $sms_reply . '-' . $sms_from . '-' . $sms_mobile . '-' . $sms_messagetext;

  $sms->set_option("serial_no",$sms_serialno);
  $sms->set_option("key",$sms_key);
  $sms->set_option("from",$sms_from);
  $sms->set_option("reply",$sms_reply);
 
	if (!$sms->send_sms($sms_mobile,$sms_from,$sms_messagetext)){
		echo $sms->get_failed_messages();
	} else {
		echo "SUCCESS";
	}
  //$return=$soapclient->SendTextSMS("DAD291DE-1054-4871-001F-CB317F823046","QJ7186","1234567890","Test from osCommRes","admin@oscommres.com","osCommRes",0,$out);
  if (getenv('HTTPS')=="on")
	$url="https://" . getenv("HTTP_HOST") . dirname(getenv("REQUEST_URI")) . '/send_sms.php';
  else
	$url="http://" . getenv("HTTP_HOST") . dirname(getenv("REQUEST_URI")) . '/send_sms.php';
  //header('Location: ' . $url . '?info=' . $ret["return"]);
}
?>
<html>
<head><title>Send SMS Message</title>
<style>
 .main{
  font-family: Verdana, Arial, sans-serif;
  font-size: 11px;
  line-height: 1.5;
  }
 .error{
  font-family: Verdana, Arial, sans-serif;
  font-size: 10px;
  line-height: 1.5;
  color:red;
  }
</style>
</head>
</html>
<body>
<script language=javascript>
function validateForm(frm)
{
  error_message="";
  if (frm.fld_serialno.value=="")
    error_message+="*SMS Serial No\n";
  if (frm.fld_key.value=="")
    error_message+="*SMS Key\n";
  if (frm.fld_reply.value=="")
    error_message+="*Reply Email\n";
  if (frm.fld_from.value=="")
    error_message+="*From\n";
  if (frm.fld_mobile.value=="")
    error_message+="*Mobile Number\n";
  if (frm.fld_messagetext.value=="")
    error_message+="*Message Text\n";
  if (error_message!=""){
    error_message="Following entries cannot be blank\n\n" + error_message;
	alert(error_message);
	return false;
  }
  return true;
}
</script>
<form action="send_sms.php" method="post" onSubmit="return validateForm(this)">
<table align=center cellpadding="2" cellspacing="2">
    <?php if ($info!=""){ ?>
	<tr>
	  <td colspan="2" class="error"><?php if ($info=="0") echo "Message sent successfully"; 
	                                      else echo "Error Sending: Return Code " . $info;
	                                ?>
	  </td>
    </tr>
	<?php }?>
    <tr>
	  <td colspan="2" class="main"><h3>SMS Settings</h3>
	  </td>
	</tr>
	<tr>
	  <td class="main">SMS Serial No: </td>
	  <td><input type="text" name="fld_serialno" size=40></td>
	</tr>
	<tr>
	  <td class="main">SMS Key: </td>
	  <td><input type="text" name="fld_key" size=20></td>
	</tr>
    <tr>
	  <td colspan="2" class="main"><h3>Message</h3>
	  </td>
	</tr>
	<tr>
	  <td class="main">Reply Email: </td>
	  <td><input type="text" name="fld_reply" size=40></td>
	</tr>
	<tr>
	  <td class="main">From: </td>
	  <td><input type="text" name="fld_from" size=40> </td>
	</tr>
	<tr>
	  <td class="main">Mobile Number: </td>
	  <td><input type="text" name="fld_mobile" size=20> </td>
	</tr>
	<tr valign="top">
	  <td class="main">Message Text: </td>
	  <td><textarea name="fld_messagetext" rows="10" cols="70"></textarea></td>
	</tr>
	<input type=hidden name="action" value="send_sms">
    <tr>
	  <td align="center" colspan="2" class="main"><input type="submit" name="process" value="send"></td>
	  </td>
	</tr>
</table>
</form>
</body>
</html>
