<?php
include("AuthentMessage.php");

class AuthentSend{

  var $tsoid;
  var $application;
  //URL to send xmls to
  var $authentifyURL;
  //password for this application
  var $password;
  var $teid;

  //Constructor,  one may send in the data if you get it from some other source, rather than hardcoding it here.
  function AuthentSend($tsoid="Authentify_Demo",
		       $app="GenericReg",
		       $url="https://achdmp01/s2s/default.asp",
		       $password="11111111"){
    $this->tsoid = $tsoid;
    $this->application = $app;
    $this->authentifyURL = $url;
    $this->password = $password;
  }


  //Takes a message for request params,  returns a message of the response.
  function sendRequest( $message ){
    $xml = $message->toXML();
    $returnXML = $this->send($xml);
    $msg = new Message($returnXML);
    $this->teid = $msg->teid;
    return $msg;
  } 

  function send($data){
    $ch = curl_init($this->authentifyURL);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
    if(!empty($data)){
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    }
    ob_start();
    curl_exec($ch);
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
  }

}
?>