You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

404 lines
7.8 KiB

<?php
//-----------------------------------------------------------------
class ConexDMUG //Version 2014-7-1
{
var $ipserver;
var $portserver;
var $hs;
var $service;
var $query;
var $name;
var $info;
var $reporte;
var $version;
var $user;
var $password;
var $database;
var $schema;
var $table;
var $index;
var $lock;
var $program;
var $xmldoc;
var $xmldocres;
var $xmlresult;
var $xmlstring;
var $estado;
var $socket;
var $xmlrequest;
var $xmlraw;
var $xmlout;
var $row;
var $colum;
var $pos;
var $nro_error;
var $text_error;
var $filas;
var $matriz;
function ConexDMUG( $p_ipserver, $p_portserver , $p_hs , $p_user , $p_password )
{
$this->ipserver = $p_ipserver;
$this->portserver = $p_portserver;
$this->hs = $p_hs;
$this->user = $p_user;
$this->password = $p_password;
$this->xmlstring = '<?xml version="1.0" ?> <document></document>' ;
$this->xmldoc = new SimpleXMLElement( $this->xmlstring );
$this->estado = 0;
$this->lock = 0;
$this->service = "";
$this->name = "";
$this->row = 0;
$this->table = "";
$this->matriz = "";
$this->colum=0;
$this->filas=0;
$this->pos= -1;
$this->nro_error=0;
$this->text_error="EXACTO";
}
function _ConexDMUG()
{
delete($this);
}
function SetCursor( $p_database , $p_schema , $p_table , $p_index )
{
$this->service = "CURSOR";
$this->database = $p_database;
$this->schema = $p_schema;
$this->table = $p_table;
$this->index = $p_index;
}
function SetQuery( $p_schema , $p_query )
{
$this->service = "QUERY";
$this->schema = $p_schema;
$this->query = $p_query;
}
function SetEsquema( $p_schema )
{
$this->schema = $p_schema;
}
function SetDataBase($p_database )
{
$this->database = $p_database;
}
function SetProgram ( $p_program )
{
$this->service = "PROGRAM";
$this->program = $p_program;
}
function SetParameter( $p_par , $p_val )
{
$this->xmldoc->addChild( $p_par , $p_val );
}
function SetMCAREP ( $p_reporte , $p_version )
{
$this->service = "MCAREP";
$this->reporte = $p_reporte;
$this->version = $p_version;
}
function SetInfo($p_info)
{
$this->info = $p_info;
}
private function SetXML()
{
$this->xmldoc->addChild('hs' , $this->hs );
$this->xmldoc->addChild('service' , $this->service );
$this->xmldoc->addChild('info' , $this->info );
$this->xmldoc->addChild('user' , $this->user );
$this->xmldoc->addChild('password', $this->password );
$this->xmldoc->addChild('lock' , $this->lock );
$this->xmldoc->addChild('query' , $this->query );
$this->xmldoc->addChild('name' , $this->name );
$this->xmldoc->addChild('REPORTE' , $this->reporte );
$this->xmldoc->addChild('VERSION' , $this->version );
$this->xmldoc->addChild('program' , $this->program );
$this->xmldoc->addChild('DATABASE', $this->database );
$this->xmldoc->addChild('SCHEMA' , $this->schema );
$this->xmldoc->addChild('TABLE' , $this->table );
$this->xmldoc->addChild('INDEX' , $this->index );
}
public function AddParam( $p_par , $p_val )
{
$this->xmldoc->addChild( $p_par , $p_val );
}
public function NextRecord()
{
if ( $this->estado == 0 )
$this->Execute_DMUG();
if( $this->estado == 1)
$this->NextRecord_DMUG();
if( $this->estado == 1)
return true;
else
return false;
}
function Execute_DMUG()
{
$this->SetXML();
/////$this->xmlout = html_entity_decode( $xmldoc->asXML() );
$this->xmlout = $this->xmldoc->asXML();
//echo $this->xmlout."\n";
/* Crear un socket TCP/IP. */
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($this->socket === false)
{
echo "socket_create() fallo :" . socket_strerror(socket_last_error()) . "\n";
return -1;
}
else
{
//echo "OK.\n";
}
///echo "ATENCION:Conectando a '$this->ipserver' en el puerto '$this->portserver'...";
socket_set_option( $this->socket , SOL_SOCKET, SO_SNDTIMEO , array('sec' => 1 , 'usec' => 1 ));
socket_set_option( $this->socket , SOL_SOCKET, SO_RCVTIMEO , array('sec' => 2 , 'usec' => 1 ));
$result = socket_connect( $this->socket , $this->ipserver , $this->portserver );
if ($result === false)
{
echo "ERROR EN CONEXION SOCKET ( Error:9800 !!!! )\n";
return -1;
}
else
{
}
socket_write($this->socket , $this->xmlout , strlen($this->xmlout));
$out="";
/////echo "Leyendo respuesta:\n\n";
$this->xmlrequest="";
//socket_set_nonblock($this->socket);
$count = 0;
while ( 1 )
{
$out = socket_read( $this->socket , 10000 , PHP_BINARY_READ );
$this->xmlrequest.=$out;
if (strstr( $this->xmlrequest , "</document>") )
break;
if ( $count > 3 )
{
echo "Se aborta Lectura Intento :".$count."\n";
socket_close($this->socket);
return -1;
}
if ( $out == "" ) $count++;
}
//GUARDAR EL RAW XML
$this->xmlraw = $this->xmlrequest;
//CONVERSION DEL STRING A OBJETO XML
//error_log($this->xmlrequest);
$this->xmlrequest = new SimpleXMLElement( $this->xmlrequest );
$this->matriz = "";
foreach ( $this->xmlrequest->children() AS $child )
{
$nametag = $child->getname();
if ( $nametag == "resulset" )
{
$this->matriz = &$child;
break;
}
}
///$this->matriz = (string)$this->xmlrequest->resultset;
// var_dump( $this->xmlrequest );
// var_dump( $this->matriz );
///////////////////////////////////////
//echo "MATRIZ=".$this->matriz."\n";
//////////////////////////////////////
//echo "MATRIZ=".$this->matriz ;
//echo "RESUL=". $this->xmlrequest->resultset;
$this->matriz = explode("\n", $this->matriz );
$this->filas = count($this->matriz) - 2;
if( $this->filas <= 0 )
{
$this->estado = 9 ;
return 1 ;
}
for($v_ii=0 ; $v_ii <= $this->filas ; $v_ii++)
{
$this->matriz[$v_ii] = explode ( "\t", $this->matriz[$v_ii] );
}
$this->colum = count($this->matriz[1])-1;
$this->pos = 0 ;
$this->row = 0 ;
$this->nro_error = 0;
$this->text_error = "EXACTO" ;
$this->estado = 1;
return 1;
}
private function NextRecord_DMUG()
{
$this->row++;
$this->pos++;
if ( $this->row > $this->filas )
{
$this->estado = 9 ;
return 1;
}
$this->estado = 1;
return 1;
}
public function CloseConex()
{
//echo "\nCerrando socket...";
socket_close($this->socket);
//echo "\n";
//delete $this->xmldoc;
//delete $this->xmlrequest;
//delete $this;
}
public function GetField( $p_f )
{
return $this->matriz[ $this->row ][$p_f];
}
public function GetPos()
{
return $this->row;
}
public function GetEstado()
{
return $this->estado;
}
public function GetColum()
{
return $this->colum;
}
public function GetFilas()
{
return $this->filas;
}
public function GetNError()
{
return $this->nro_error;
}
public function GetSError()
{
return $this->text_error;
}
public function GetInfo()
{
return (string)$this->info;
}
public function GetMatriz()
{
return (string)$this->matriz;
}
public function GetChild( $tag )
{
//$this->xmlrequest = new SimpleXMLElement( $this->xmlrequest );
$valor = "";
foreach ( $this->xmlrequest->children() AS $child )
{
$nametag = $child->getname();
if ( $nametag == $tag )
{
$valor = &$child;
break;
}
}
return $valor;
}
}
//------------------------------------------------------------------