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

4 years ago
  1. <?php
  2. //-----------------------------------------------------------------
  3. class ConexDMUG //Version 2014-7-1
  4. {
  5. var $ipserver;
  6. var $portserver;
  7. var $hs;
  8. var $service;
  9. var $query;
  10. var $name;
  11. var $info;
  12. var $reporte;
  13. var $version;
  14. var $user;
  15. var $password;
  16. var $database;
  17. var $schema;
  18. var $table;
  19. var $index;
  20. var $lock;
  21. var $program;
  22. var $xmldoc;
  23. var $xmldocres;
  24. var $xmlresult;
  25. var $xmlstring;
  26. var $estado;
  27. var $socket;
  28. var $xmlrequest;
  29. var $xmlraw;
  30. var $xmlout;
  31. var $row;
  32. var $colum;
  33. var $pos;
  34. var $nro_error;
  35. var $text_error;
  36. var $filas;
  37. var $matriz;
  38. function ConexDMUG( $p_ipserver, $p_portserver , $p_hs , $p_user , $p_password )
  39. {
  40. $this->ipserver = $p_ipserver;
  41. $this->portserver = $p_portserver;
  42. $this->hs = $p_hs;
  43. $this->user = $p_user;
  44. $this->password = $p_password;
  45. $this->xmlstring = '<?xml version="1.0" ?> <document></document>' ;
  46. $this->xmldoc = new SimpleXMLElement( $this->xmlstring );
  47. $this->estado = 0;
  48. $this->lock = 0;
  49. $this->service = "";
  50. $this->name = "";
  51. $this->row = 0;
  52. $this->table = "";
  53. $this->matriz = "";
  54. $this->colum=0;
  55. $this->filas=0;
  56. $this->pos= -1;
  57. $this->nro_error=0;
  58. $this->text_error="EXACTO";
  59. }
  60. function _ConexDMUG()
  61. {
  62. delete($this);
  63. }
  64. function SetCursor( $p_database , $p_schema , $p_table , $p_index )
  65. {
  66. $this->service = "CURSOR";
  67. $this->database = $p_database;
  68. $this->schema = $p_schema;
  69. $this->table = $p_table;
  70. $this->index = $p_index;
  71. }
  72. function SetQuery( $p_schema , $p_query )
  73. {
  74. $this->service = "QUERY";
  75. $this->schema = $p_schema;
  76. $this->query = $p_query;
  77. }
  78. function SetEsquema( $p_schema )
  79. {
  80. $this->schema = $p_schema;
  81. }
  82. function SetDataBase($p_database )
  83. {
  84. $this->database = $p_database;
  85. }
  86. function SetProgram ( $p_program )
  87. {
  88. $this->service = "PROGRAM";
  89. $this->program = $p_program;
  90. }
  91. function SetParameter( $p_par , $p_val )
  92. {
  93. $this->xmldoc->addChild( $p_par , $p_val );
  94. }
  95. function SetMCAREP ( $p_reporte , $p_version )
  96. {
  97. $this->service = "MCAREP";
  98. $this->reporte = $p_reporte;
  99. $this->version = $p_version;
  100. }
  101. function SetInfo($p_info)
  102. {
  103. $this->info = $p_info;
  104. }
  105. private function SetXML()
  106. {
  107. $this->xmldoc->addChild('hs' , $this->hs );
  108. $this->xmldoc->addChild('service' , $this->service );
  109. $this->xmldoc->addChild('info' , $this->info );
  110. $this->xmldoc->addChild('user' , $this->user );
  111. $this->xmldoc->addChild('password', $this->password );
  112. $this->xmldoc->addChild('lock' , $this->lock );
  113. $this->xmldoc->addChild('query' , $this->query );
  114. $this->xmldoc->addChild('name' , $this->name );
  115. $this->xmldoc->addChild('REPORTE' , $this->reporte );
  116. $this->xmldoc->addChild('VERSION' , $this->version );
  117. $this->xmldoc->addChild('program' , $this->program );
  118. $this->xmldoc->addChild('DATABASE', $this->database );
  119. $this->xmldoc->addChild('SCHEMA' , $this->schema );
  120. $this->xmldoc->addChild('TABLE' , $this->table );
  121. $this->xmldoc->addChild('INDEX' , $this->index );
  122. }
  123. public function AddParam( $p_par , $p_val )
  124. {
  125. $this->xmldoc->addChild( $p_par , $p_val );
  126. }
  127. public function NextRecord()
  128. {
  129. if ( $this->estado == 0 )
  130. $this->Execute_DMUG();
  131. if( $this->estado == 1)
  132. $this->NextRecord_DMUG();
  133. if( $this->estado == 1)
  134. return true;
  135. else
  136. return false;
  137. }
  138. function Execute_DMUG()
  139. {
  140. $this->SetXML();
  141. /////$this->xmlout = html_entity_decode( $xmldoc->asXML() );
  142. $this->xmlout = $this->xmldoc->asXML();
  143. //echo $this->xmlout."\n";
  144. /* Crear un socket TCP/IP. */
  145. $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  146. if ($this->socket === false)
  147. {
  148. echo "socket_create() fallo :" . socket_strerror(socket_last_error()) . "\n";
  149. return -1;
  150. }
  151. else
  152. {
  153. //echo "OK.\n";
  154. }
  155. ///echo "ATENCION:Conectando a '$this->ipserver' en el puerto '$this->portserver'...";
  156. socket_set_option( $this->socket , SOL_SOCKET, SO_SNDTIMEO , array('sec' => 1 , 'usec' => 1 ));
  157. socket_set_option( $this->socket , SOL_SOCKET, SO_RCVTIMEO , array('sec' => 2 , 'usec' => 1 ));
  158. $result = socket_connect( $this->socket , $this->ipserver , $this->portserver );
  159. if ($result === false)
  160. {
  161. echo "ERROR EN CONEXION SOCKET ( Error:9800 !!!! )\n";
  162. return -1;
  163. }
  164. else
  165. {
  166. }
  167. socket_write($this->socket , $this->xmlout , strlen($this->xmlout));
  168. $out="";
  169. /////echo "Leyendo respuesta:\n\n";
  170. $this->xmlrequest="";
  171. //socket_set_nonblock($this->socket);
  172. $count = 0;
  173. while ( 1 )
  174. {
  175. $out = socket_read( $this->socket , 10000 , PHP_BINARY_READ );
  176. $this->xmlrequest.=$out;
  177. if (strstr( $this->xmlrequest , "</document>") )
  178. break;
  179. if ( $count > 3 )
  180. {
  181. echo "Se aborta Lectura Intento :".$count."\n";
  182. socket_close($this->socket);
  183. return -1;
  184. }
  185. if ( $out == "" ) $count++;
  186. }
  187. //GUARDAR EL RAW XML
  188. $this->xmlraw = $this->xmlrequest;
  189. //CONVERSION DEL STRING A OBJETO XML
  190. //error_log($this->xmlrequest);
  191. $this->xmlrequest = new SimpleXMLElement( $this->xmlrequest );
  192. $this->matriz = "";
  193. foreach ( $this->xmlrequest->children() AS $child )
  194. {
  195. $nametag = $child->getname();
  196. if ( $nametag == "resulset" )
  197. {
  198. $this->matriz = &$child;
  199. break;
  200. }
  201. }
  202. ///$this->matriz = (string)$this->xmlrequest->resultset;
  203. // var_dump( $this->xmlrequest );
  204. // var_dump( $this->matriz );
  205. ///////////////////////////////////////
  206. //echo "MATRIZ=".$this->matriz."\n";
  207. //////////////////////////////////////
  208. //echo "MATRIZ=".$this->matriz ;
  209. //echo "RESUL=". $this->xmlrequest->resultset;
  210. $this->matriz = explode("\n", $this->matriz );
  211. $this->filas = count($this->matriz) - 2;
  212. if( $this->filas <= 0 )
  213. {
  214. $this->estado = 9 ;
  215. return 1 ;
  216. }
  217. for($v_ii=0 ; $v_ii <= $this->filas ; $v_ii++)
  218. {
  219. $this->matriz[$v_ii] = explode ( "\t", $this->matriz[$v_ii] );
  220. }
  221. $this->colum = count($this->matriz[1])-1;
  222. $this->pos = 0 ;
  223. $this->row = 0 ;
  224. $this->nro_error = 0;
  225. $this->text_error = "EXACTO" ;
  226. $this->estado = 1;
  227. return 1;
  228. }
  229. private function NextRecord_DMUG()
  230. {
  231. $this->row++;
  232. $this->pos++;
  233. if ( $this->row > $this->filas )
  234. {
  235. $this->estado = 9 ;
  236. return 1;
  237. }
  238. $this->estado = 1;
  239. return 1;
  240. }
  241. public function CloseConex()
  242. {
  243. //echo "\nCerrando socket...";
  244. socket_close($this->socket);
  245. //echo "\n";
  246. //delete $this->xmldoc;
  247. //delete $this->xmlrequest;
  248. //delete $this;
  249. }
  250. public function GetField( $p_f )
  251. {
  252. return $this->matriz[ $this->row ][$p_f];
  253. }
  254. public function GetPos()
  255. {
  256. return $this->row;
  257. }
  258. public function GetEstado()
  259. {
  260. return $this->estado;
  261. }
  262. public function GetColum()
  263. {
  264. return $this->colum;
  265. }
  266. public function GetFilas()
  267. {
  268. return $this->filas;
  269. }
  270. public function GetNError()
  271. {
  272. return $this->nro_error;
  273. }
  274. public function GetSError()
  275. {
  276. return $this->text_error;
  277. }
  278. public function GetInfo()
  279. {
  280. return (string)$this->info;
  281. }
  282. public function GetMatriz()
  283. {
  284. return (string)$this->matriz;
  285. }
  286. public function GetChild( $tag )
  287. {
  288. //$this->xmlrequest = new SimpleXMLElement( $this->xmlrequest );
  289. $valor = "";
  290. foreach ( $this->xmlrequest->children() AS $child )
  291. {
  292. $nametag = $child->getname();
  293. if ( $nametag == $tag )
  294. {
  295. $valor = &$child;
  296. break;
  297. }
  298. }
  299. return $valor;
  300. }
  301. }
  302. //------------------------------------------------------------------