Exemple #1
0
function parseTextAndComposePerson($hc, $nombreCarrion, $curl_exec)
{
    //  identificar y extraer seccion de interes
    $entireString = obtenerTablaQueRodeaOcurrenciaDeCadena($curl_exec, "DATOS PERSONALES");
    $response = simplificarHtml($entireString);
    $xmlArray = xmlStringToArray($response);
    $person = array();
    $person['hc'] = $hc;
    $person['nombre'] = valueToString($xmlArray['tr'][1]['td'][1]['B']);
    $person['fecha_nacimiento'] = valueToString($xmlArray['tr'][2]['td'][1]);
    $person['dni'] = valueToString($xmlArray['tr'][2]['td'][3]);
    $person['tipo_asegurado'] = valueToString($xmlArray['tr'][3]['td'][1]);
    $person['codigo_asegurado'] = valueToString($xmlArray['tr'][3]['td'][3]);
    $person['tipo_seguro'] = valueToString($xmlArray['tr'][4]['td'][3]);
    $person['centro_asistencial'] = valueToString($xmlArray['tr'][6]['td'][1]['b']);
    $person['afiliado_desde'] = valueToString($xmlArray['tr'][6]['td'][3]['b']);
    $person['direccion'] = valueToString($xmlArray['tr'][7]['td'][1]);
    $person['afiliado_hasta'] = valueToString($xmlArray['tr'][7]['td'][3]['b']);
    $person['centro_afiliacion'] = valueToString($xmlArray['tr'][8]['td'][1]);
    $person['nombre_hc_carrion'] = $nombreCarrion;
    return $person;
}
Exemple #2
0
function generateDocument($pages, $generatorPipeline)
{
    if (preg_match('/.\\//s', $generatorPipeline)) {
        webServiceError('&error-disallowed-characters;');
    }
    $userAgent = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:bignumber) Docvert';
    $httpContextOptions = array('http' => array('header' => 'User-Agent: ' . $userAgent));
    $httpContext = stream_context_create($httpContextOptions);
    $docvertDir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR;
    $docvertWritableDir = getWritableDirectory();
    $disallowDocumentGeneration = getGlobalConfigItem('doNotAllowDocumentGeneration');
    if ($disallowDocumentGeneration == 'true') {
        webServiceError('&document-generation-disabled;');
    }
    $pageXml = '<c:document xmlns="http://www.w3.org/1999/xhtml" xmlns:c="container">' . "\n";
    $pageTemplate = "\n\t" . '<c:page url="{{url}}" {{baseUrl}}>{{page}}</c:page>' . "\n";
    $config = array('indent' => true, 'output-xhtml' => true, 'wrap' => 200);
    if (!class_exists('tidy')) {
        webServiceError('&tidy-is-not-installed;');
    }
    $tidy = new tidy();
    $baseTagPattern = "/<base[^>]*?href=([^>]*?)>/is";
    foreach ($pages as $page) {
        if (trim($page) != '' && (stringStartsWith($page, 'http://') || stringStartsWith($page, 'https://'))) {
            $pageHtml = file_get_contents($page, null, $httpContext);
            $tidy->parseString($pageHtml, $config, 'utf8');
            $tidy->cleanRepair();
            $thisPage = str_replace('{{url}}', $page, $pageTemplate);
            $baseUrl = '';
            //supporting that ugly old hack of <base>
            preg_match($baseTagPattern, $pageHtml, $matches);
            if (count($matches) > 0) {
                $baseUrl = 'baseUrl="' . substr($matches[1], 1, -2) . '"';
            }
            $thisPage = str_replace('{{baseUrl}}', $baseUrl, $thisPage);
            $tidiedPageContents = characterEntityToNCR(removeDoctype(removeXmlComments($tidy)));
            $styleTagPattern = "/<style.*?<\\/style>/is";
            $tidiedPageContents = preg_replace($styleTagPattern, '', $tidiedPageContents);
            $scriptTagPattern = "/<script.*?<\\/script>/is";
            $tidiedPageContents = preg_replace($scriptTagPattern, '', $tidiedPageContents);
            $questionMarkPattern = "/<\\?.*?\\?>/is";
            //as strangely used on news.yahoo.com
            $tidiedPageContents = preg_replace($questionMarkPattern, '', $tidiedPageContents);
            $thisPage = str_replace('{{page}}', $tidiedPageContents, $thisPage);
            $pageXml .= $thisPage;
        }
    }
    $pageXml .= '</c:document>';
    $temporaryDirectory = getTemporaryDirectory();
    $pipelineDirectory = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'generator-pipeline' . DIRECTORY_SEPARATOR . $generatorPipeline . DIRECTORY_SEPARATOR;
    $pipelinePath = $pipelineDirectory . 'pipeline.xml';
    if (!file_exists($pipelinePath)) {
        webServiceError('&generation-pipeline-not-found; ' . revealXml($pipelinePath));
    }
    $pipelineString = file_get_contents($pipelinePath);
    $pipelineString = substr($pipelineString, strpos($pipelineString, '<pipeline>') + 10);
    $pipelineString = substr($pipelineString, 0, strpos($pipelineString, '</pipeline>'));
    $pipelineStages = xmlStringToArray($pipelineString);
    $pipelineSettings = array("pipeline" => $generatorPipeline, "autopipeline" => $generatorPipeline);
    processAPipelineLevel($pipelineStages, $pageXml, $pipelineDirectory, $temporaryDirectory, $temporaryDirectory, $pipelineSettings);
    $openDocumentPath = $temporaryDirectory . 'output.odt';
    zipFiles($temporaryDirectory, $openDocumentPath);
    header('Content-disposition: attachment; filename=' . basename($openDocumentPath));
    header('Content-type: application/vnd.oasis.opendocument.text');
    readfile($openDocumentPath);
}