
<?php
	header('Access-Control-Allow-Origin: *');  

	//$homepage = file_get_contents('https://www.dropbox.com/sh/fabbat8d38eb5em/9RO8qP6JVQ/aud%C3%ADfonos');
	//$homepage = file_get_contents($strUrl);

	//print_r (explode(" ",$homepage));
	
	
	if(1==2){ //Es para obtener MEDICAMENTOS
	
		if(isset($_REQUEST['intPagina'])){
			$intPagina = $_REQUEST['intPagina'];
		}else{
			$intPagina = 0;
		}

		$strUrl = 'http://www.medicamentosplm.com/Home/Medicamento';
		
		if(1==2){ //extraer lo que contiene un ol
			$posIni = strpos($homepage, "<ol");
			$homepage = substr($homepage,$posIni);
			//print($homepage);
			$posFin = strpos($homepage, "</ol>");
			//print($posFin);
			$homepage = substr($homepage,0,$posFin+5);
		}
		
		//'strLetter' => 'B',
		
		$postdata = http_build_query(
			array(
				'strPagina' => $intPagina
			)
		);
		
		$opts = array('http' =>
			array(
				'method'  => 'POST',
				'header'  => 'Content-type: application/x-www-form-urlencoded',
				'content' => $postdata
			)
		);
	
		$context  = stream_context_create($opts);
		
		$result = file_get_contents($strUrl, false, $context);
		
		$posIni = strpos($result, '<div id="contenido">');
		$result = substr($result, $posIni);
		
		$posFin = strpos($result, '<div class="footer">');
		$result = substr($result, 0, $posFin-35);
	
		$posIni = strpos($result, '<div id="container-wrapper">');
		$result = substr($result, $posIni);
	
		$posFin = strpos($result, '<div id="text_inter">');
		$result = substr($result, 0, $posFin);
	
		$result = str_replace('class="tab-6 first"', 'class="tab-6"', $result);
		$result = str_replace('class="renglon gris2"', 'class="renglon gris1"', $result);
		$result = str_replace('class="renglon gris1"', 'class="Row"', $result);
		$result = str_replace('class="renglon"', 'class="Row"', $result);
		
		$result = str_replace('<div id="container-wrapper">', '', $result);
		
		$result = substr($result, 0, -20);
	
		$result =  strip_tags($result, '<div>');

	}else if(1==1){ //Es para obtener el CIE10
	
		if(isset($_REQUEST['strTerm'])){
			$strTerm = $_REQUEST['strTerm'];
		}else{
			$strTerm = 'A';
		}

		$strUrl = 'http://www.medicamentosplm.com/Home/CIE10';
				
		//'strLetter' => 'B',
		
		$postdata = http_build_query(
			array(
				'strTerm' => $strTerm
			)
		);
		
		$opts = array('http' =>
			array(
				'method'  => 'POST',
				'header'  => 'Content-type: application/x-www-form-urlencoded',
				'content' => $postdata
			)
		);
	
		$context  = stream_context_create($opts);
		
		$result = file_get_contents($strUrl, false, $context);
		
		$posIni = strpos($result, '<div id="contenido">');
		$result = substr($result, $posIni);
		
		$posFin = strpos($result, '<div class="footer">');
		$result = substr($result, 0, $posFin-35);
	
		$posIni = strpos($result, '<div id="container-wrapper">');
		$result = substr($result, $posIni);
	
		$posFin = strpos($result, '<div id="text_inter">');
		$result = substr($result, 0, $posFin);
	
		//$result = str_replace('class="tab-6 first"', 'class="tab-6"', $result);
		$result = str_replace('class="fila_izq gris2"', 'class="fila_izq gris1"', $result);
		$result = str_replace('class="fila_izq gris1"', 'class="Row"', $result);
		$result = str_replace('class="izq01"', 'class="Celda"', $result);
		$result = str_replace('class="izq02"', 'class="Celda"', $result);
		
		$result = str_replace('<div id="container-wrapper">', '', $result);
		
		$posIni = strpos($result, '<div class="Row">');
		$result = substr($result, $posIni); //Regresa desde la posicion dada en adelante
		
		$posFin = strpos($result, '<div id="right_tab">');
		$result = substr($result, 0, $posFin-20); //Regresa desde la posicion dada en adelante
	
		$result =  strip_tags($result, '<div>'); //elimino todos los demas tags que no sean DIV's
	
	}

	print($result);
	
	
/*
EJEMPLO DE PREG REPLACE REGEX

$cadena = 'Abril 15, 2003';
$patrón = '/(\w+) (\d+), (\d+)/i';
$sustitución = '${1}1,$3';
echo preg_replace($patrón, $sustitución, $cadena);
?>
El resultado del ejemplo sería:

Abril1,2003
*/

/*

MEDICAMENTO

<div class="renglon gris2">

	<div class="tab-6 first "><input type="checkbox" name="Interactions" id="Interactions" value="acloral_solucion_inyectable,103,101,6104,162"/>
		<a href="/Home/productos/acloral_solucion_inyectable/103/101/6104/162" onclick="javascript:showWait();">ACLORAL</a>
	</div>

	<div class="tab-6">
		<form action="/Home/Sustancia" method="post">                    
			<input type="hidden" name="source" value="2" />
			<button type="submit" name="strTerm" value="1105,RANITIDINA" class="sustancia_med gris2"  onclick="javascript:showWait();" style="border:0; text-decoration:underline" >RANITIDINA</button>
		</form>                
	</div>

	<div class="tab-6">Soluci&#243;n inyectable</div>

	<div class="tab-6">1 Caja 5 Ampolleta(s)   50/2 mg/ml</div>

	<div class="tab-6">
		<form action="/Home/Laboratorio" method="post">                    
		<input type="hidden" name="source" value="3" />
		<button type="submit" name="strTerm" value="103,LIOMONT"  onclick="javascript:showWait();"  style="border:0; text-decoration:underline"  class="sustancia_med gris2" >LIOMONT</button>
		</form>                
	</div>
	<div class="tab-6"></div>
</div>

*/

/*
CIE10

<div class="fila_izq gris2">

	<div class="izq01">

		<button type="submit" name="strTerm" value="18,A23,Brucelosis"  onclick="javascript:showWait();"

			style="border:0; width:100%; text-decoration:underline" >A23</button></div>

	<div class="izq02">

		<button type="submit" name="strTerm" value="18,A23,Brucelosis"  onclick="javascript:showWait();"

			style="border:0; width:100%; text-decoration:underline" >Brucelosis</button></div>

</div>

<div class="fila_izq gris1">

	<div class="izq01">

		<button type="submit" name="strTerm" value="34,A44,Bartonelosis"  onclick="javascript:showWait();"

			style="border:0; width:100%; text-decoration:underline" >A44</button></div>

	<div class="izq02">

		<button type="submit" name="strTerm" value="34,A44,Bartonelosis"  onclick="javascript:showWait();"

			style="border:0; width:100%; text-decoration:underline" >Bartonelosis</button></div>

</div>

*/
?>

