N000 + 3 positions for key + 1 space byte
* @access private
*/
private $key;
/**
* @var string $password Senha de acesso ao mainframe (8 bytes)
* @access private
*/
private $password;
/**
* @var string $application APLIC (4 bytes) application => 3 bytes for system acronym AND 1 byte to environment 'P' or 'D'
* @access private
*/
private $application;
/**
* @var string $system Sistema (4 bytes)
* @access private
*/
private $system;
/**
* @var string $logon LOGON (8 bytes)
* @access private
*/
private $logon;
/**
* @var string $rc PA_RC - Código de Retorno (4 bytes)
* @access private
*/
private $rc;
/**
* @var string $msg PA_MSG - Mensagem de retorno (60 bytes)
* @access private
*/
private $msg;
/**
* @var string $dataParameter Return of MAINFRAME environment
* @access private
*/
private $dataParameter;
/**
* @var object $resultSet Armazena o resultado das consulta
* @access public
*/
public $resultSet;
/**
* @var object $obj Objeto de Classe que contém a especificação e estrutura do programa natural acessado
* @access protected
*/
protected $obj;
/**
* Construtor da clase Natural
* @access public
*/
public function Natural()
{
$this->protocol = "/cics/cwba/jaspin?";
$this->endOfProtocol = "!jaspin_fim_de_dados!";
$this->isDBGateway = false;
}
/**
* Carrega atributos da classe com valores iniciais
* @param String - Name of sub-program
* @param String - Input parameters to sub-program
* @access protected
* @return void
*/
protected function initialize($strSubProgram/*, $strInputParameter*/)
{
$this->strSubProgram = strtoupper($strSubProgram);
// $this->strInputParameter = strtoupper($strInputParameter);
// get the acronym of the sub-program
$this->acronym = strtoupper(substr($strSubProgram, 0, 3));
// set the system
$this->system = str_repeat("X", 4);
// set the static logon
$this->logon = "N000" . $this->acronym . SPACE;
// initialize the return code
$this->rc = "9999";
// initialize the return message
$this->msg = str_repeat(SPACE, 60);
// initialize the data parameter
$this->dataParameter = "0000000000";
}
/**
* Determina o protocolo a ser usado pelo Gateway
*
* In DBGateway protocol the size of returned data does not have any bound.
* if you does not set DBGataway, PHP NatAPI will use DBCON. Using DBCon you can transfer only 32Kb of data.
* @param String $dbGateway set BDGateway protocol
* @access public
* @return void
*/
public function setDBGatewayProtocol($dbGateway = true)
{
$this->isDBGateway = $dbGateway;
if ($dbGateway){
$this->protocol = "/cics/cwba/jasppion?";
$this->endOfProtocol = "!jasppion_fim_de_dados!";
} else {
$this->protocol = "/cics/cwba/jaspin?";
$this->endOfProtocol = "!jaspin_fim_de_dados!";
}
}
/**
* Access and retrieve data from mainframe
*
* @return boolean
* @access protected
*/
protected function execute($inputParams = "")
{
if (!empty($this->application) && !empty($this->strSubProgram) && !empty($this->key) && !empty($this->password) &&
!empty($this->IPAddress) && !empty($this->serverPort))
{
try
{
$str = Factory::newInstance('PosString', Factory::newInstance('NatType'));
$this->strInputParameter = $str->mountString(array_merge($this->obj->input, $this->obj->output), $inputParams);
$url = $this->protocol . ($this->acronym . $this->application) . $this->system . $this->logon . $this->strSubProgram . $this->key . $this->password . $this->rc . $this->msg . $this->strInputParameter . $this->endOfProtocol;
$link = "http://" . $this->IPAddress . ":". $this->serverPort . $url;
// echo $link . "
";
$fp = @fsockopen($this->IPAddress, $this->serverPort, $errnum, $errstr);
$line = "";
$size = 0;
if ($fp) {
@fputs($fp, "GET " . $url . " HTTP/1.1\r\nHost: " . $this->IPAddress . "\r\nConnection: close\r\n\r\n");
$line = "";
while (!feof($fp)) {
$temp = fread($fp, 128);
$line = $line . $temp;
}
@fclose($fp);
$pos1 = @strpos($line, "
* $rowConf example - array (name_of_field => size_of_field)
* $array = array("id" => 5, "name" => 10);
*
* @param int $lineSize Size of each line return from mainframe
* @param array $rowConf Configuration of the field's name and size of each fild
* @return void
* @access public
*/
public function configureResultSet($lineSize, $rowConf)
{
//$rows = explode("%NAT_SEP%", wordwrap($this->dataParameter, $lineSize, "%NAT_SEP%"));
for ($i=0; $i < strlen($this->dataParameter)/$lineSize; $i++){
$rows[] = substr($this->dataParameter, $lineSize*$i , $lineSize);
}
$result = array();
// for each row returned from mainframe
foreach ($rows as $id => $values){
$last_id = 0;
// get configuration array to build the result
foreach ($rowConf as $id_conf => $value_conf)
{
$result[$id][$id_conf] = substr($values, $last_id, $value_conf);
$last_id += (int)$value_conf;
}
}
if (!empty($this->resultSet))
unset($this->resultSet);
$this->resultSet = &Factory::newInstance('NaturalResultSet', $result);
}
}
?>