$output_params[RUN_OUTPUT_FORMAT] = $_GET['format'];
if ($_GET['format'] == RUN_OUTPUT_FORMAT_HTML) {
    $page = 0;
    if ($_GET['page'] != '') {
        $page = $_GET['page'];
    }
    $output_params[RUN_OUTPUT_PAGE] = $page;
}
$result = ws_runReport($currentUri, $report_params, $output_params, $attachments);
// 4.
if (is_soap_fault($result)) {
    $errorMessage = $result->getFault()->faultstring;
    echo $errorMessage;
    exit;
}
$operationResult = getOperationResult($result);
if ($operationResult['returnCode'] != '0') {
    echo "Error executing the report:<br><font color=\"red\">" . $operationResult['returnMessage'] . "</font>";
    exit;
}
if (is_array($attachments)) {
    if ($_GET['format'] == RUN_OUTPUT_FORMAT_PDF) {
        header("Content-type: application/pdf");
        echo $attachments["cid:report"];
    } else {
        if ($_GET['format'] == RUN_OUTPUT_FORMAT_HTML) {
            // 1. Save attachments....
            // 2. Print the report....
            header("Content-type: text/html");
            foreach (array_keys($attachments) as $key) {
                if ($key != "cid:report") {
 /**
  * Rutina principal de entrada .
  *
  * @param type $reportServerUser
  * @param type $reportServerPassword
  * @param type $formatOutput
  */
 protected function executeReport($reportServerUser, $reportServerPassword, $formatOutput)
 {
     try {
         // recogemos los que seran parametros del reporte y los parseamos
         // para generar el formato requerido.
         $input_params =& $this->getInputReportParamsList();
         $report_params =& $this->getReportParams($input_params);
         // El formato de salida del reporte.
         $output_params = array();
         $output_params[RUN_OUTPUT_FORMAT] = $formatOutput;
         // ejecutamos el reporte , via SOAP.
         $currentUri = $this->getReportURI();
         $result = ws_runReport($reportServerUser, $reportServerPassword, $currentUri, $report_params, $output_params, $attachments);
         // verficamos si el reporte pudo ser ejecutado.
         if (is_soap_fault($result)) {
             $errorMessage = $result->getFault()->faultstring;
             $this->outputError(strlen($errorMessage) > 0 ? $errorMessage : 'Reporte no procesado , error en proceso');
             die;
         }
         // Verificamos si el reporte fue ejecutado este fue exitoso.
         $operationResult = getOperationResult($result);
         if ($operationResult['returnCode'] != '0') {
             $msg = 'Error executing the report:<br><font color="red">' . $operationResult['returnMessage'] . '</font>';
             $this->outputError($msg);
             die;
         }
         // si el reporte tiene attachments (en jasper es la manera de emitir)
         // segun el formato se imprime, solo soportamos PDF y XLS.
         if (is_array($attachments)) {
             $contents = $attachments["cid:report"];
             if ($output_params[RUN_OUTPUT_FORMAT] == RUN_OUTPUT_FORMAT_PDF) {
                 header("Content-type: application/pdf");
                 $answer = $this->createReportOutputFile($contents);
                 if ($answer === FALSE) {
                     $this->outputError('Error grabando archivo de salida...');
                 } else {
                     echo $answer;
                 }
                 // readfile($tn);
                 //print_r(array_keys($attachments));
             } else {
                 if ($output_params[RUN_OUTPUT_FORMAT] == RUN_OUTPUT_FORMAT_XLS) {
                     header('Content-type: application/xls');
                     header('Cache-Control: must-revalidate');
                     header('Pragma: public');
                     header('Content-Description: File Transfer');
                     header('Content-Disposition: attachment; filename="reportxxx.xls"');
                     $answer = $this->createReportOutputFile($contents);
                     if ($answer === FALSE) {
                         $this->outputError('Error grabando archivo de salida...');
                     } else {
                         echo $answer;
                     }
                     //                    readfile($tn);
                 }
             }
             //  die();
         } else {
             $this->outputError('No se encontro contenido del reporte...');
         }
     } catch (Exception $ex) {
         $this->outputError($ex->getMessage());
     }
 }