function doReport($row)
{
    global $publish, $format;
    if ($row['rps_FilePath'] != null) {
        $dir = $row['rps_FilePath'];
        if (substr($dir, -1) != "/") {
            $dir = $dir . "/";
        }
    } else {
        $dir = HEURIST_UPLOAD_DIR . "generated-reports/";
        if (!file_exists($dir)) {
            if (!mkdir($dir, 0777, true)) {
                die('Failed to create folder for generated reports');
            }
        }
    }
    $filename = $row['rps_FileName'] != null ? $row['rps_FileName'] : $row['rps_Template'];
    $outputfile = $dir . $filename;
    if ($publish == 3) {
        $path_parts = pathinfo($outputfile);
        $ext = array_key_exists('extension', $path_parts) ? $path_parts['extension'] : null;
        /*****DEBUG****/
        //error_log("EXT=".$ext);
        if ($ext == null) {
            $filename2 = $outputfile . "." . $format;
            if (file_exists($filename2)) {
                $outputfile = $filename2;
                $ext = $format;
            } else {
                if ($format == "js") {
                    $outputfile = $outputfile . ".html";
                    $ext = "html";
                }
            }
        }
        if (file_exists($outputfile)) {
            $content = file_get_contents($outputfile);
            if ($format == "js" && $ext != $format) {
                $content = str_replace("\n", "", $content);
                $content = str_replace("\r", "", $content);
                $content = str_replace("'", "'", $content);
                echo "document.write('" . $content . "');";
            } else {
                echo $content;
            }
            return;
        }
        $publish = 1;
    }
    //publish==3
    $hquery = $row['rps_HQuery'];
    if (strpos($hquery, "&q=") > 0) {
        parse_str($hquery, $params);
    } else {
        $params = array("q" => $hquery);
    }
    if (!array_key_exists("ver", $params)) {
        $params["ver"] = "1";
    }
    if (!array_key_exists("w", $params)) {
        $params["w"] = "all";
    }
    $params["template"] = $row['rps_Template'];
    $params["output"] = $outputfile;
    $params["mode"] = $format;
    $params["publish"] = $publish;
    $params["rps_id"] = $row['rps_ID'];
    executeSmartyTemplate($params);
    //in showReps
}
Exemple #2
0
require_once dirname(__FILE__) . '/reportRecord.php';
$outputfile = null;
$isJSout = false;
$rtStructs = null;
$dtStructs = null;
$dtTerms = null;
$gparams = null;
$loaded_recs = array();
$max_allowed_depth = 2;
$publishmode = 0;
$execution_counter = 0;
$execution_total_counter = 0;
$session_id = @$_REQUEST['session'];
$mysqli = null;
if ((@$_REQUEST['q'] || @$_REQUEST['recordset']) && (array_key_exists('template', $_REQUEST) || array_key_exists('template_body', $_REQUEST))) {
    executeSmartyTemplate($_REQUEST);
}
/**
* Main function
*
* @param mixed $_REQUEST
*/
function executeSmartyTemplate($params)
{
    global $smarty, $outputfile, $isJSout, $rtStructs, $dtStructs, $dtTerms, $gparams, $max_allowed_depth, $publishmode, $execution_counter, $execution_total_counter, $session_id, $mysqli;
    set_time_limit(0);
    //no script execution time limit
    mysql_connection_overwrite(DATABASE);
    //AO: mysql_connection_select - does not work since there is no access to stored procedures(getTemporalDateString)
    //    which Steve used in some queries
    //TODO SAW  grant ROuser EXECUTE on getTemporalDate and any other readonly procs