public static function display(&$report, &$request) { //determine if this is an asyncronous report or not $report->async = !isset($request->query['content_only']); if (isset($request->query['no_async'])) { $report->async = false; } //if we're only getting the report content if (isset($request->query['content_only'])) { $template = 'html/content_only'; } else { $template = 'html/report'; } try { $additional_vars = array(); if (isset($request->query['no_charts'])) { $additional_vars['no_charts'] = true; } $html = $report->renderReportPage($template, $additional_vars); echo $html; } catch (Exception $e) { if (isset($request->query['content_only'])) { $template = 'html/blank_page'; } $vars = array('title' => $report->report, 'header' => '<h2>There was an error running your report</h2>', 'error' => $e->getMessage(), 'content' => "<h2>Report Query</h2>" . $report->options['Query_Formatted']); echo PhpReports::render($template, $vars); } }
public function renderReportPage($template = 'html/report', $additional_vars = array()) { $this->run(); $template_vars = array('is_ready' => $this->is_ready, 'async' => $this->async, 'report_url' => PhpReports::$request->base . '/report/?' . $_SERVER['QUERY_STRING'], 'report_querystring' => $_SERVER['QUERY_STRING'], 'base' => PhpReports::$request->base, 'report' => $this->report, 'vars' => $this->prepareVariableForm(), 'macros' => $this->macros); $template_vars = array_merge($template_vars, $additional_vars); $template_vars = array_merge($template_vars, $this->options); return PhpReports::render($template, $template_vars); }
public static function run(&$report) { $macros = $report->macros; foreach ($macros as $key => $value) { if (is_array($value)) { $first = true; foreach ($value as $key2 => $value2) { $value[$key2] = mysql_real_escape_string(trim($value2)); $first = false; } $macros[$key] = $value; } else { $macros[$key] = mysql_real_escape_string($value); } if ($value === 'ALL') { $macros[$key . '_all'] = true; } } //add the config and environment settings as macros $macros['config'] = PhpReports::$config; $macros['environment'] = PhpReports::$config['environments'][$report->options['Environment']]; //expand macros in query $sql = PhpReports::render($report->raw_query, $macros); $report->options['Query'] = $sql; $report->options['Query_Formatted'] = SqlFormatter::format($sql); //split into individual queries and run each one, saving the last result $queries = SqlFormatter::splitQuery($sql); $datasets = array(); $explicit_datasets = preg_match('/--\\s+@dataset(\\s*=\\s*|\\s+)true/', $sql); foreach ($queries as $i => $query) { $is_last = $i === count($queries) - 1; //skip empty queries $query = trim($query); if (!$query) { continue; } $result = mysql_query($query, $report->conn); if (!$result) { throw new Exception("Query failed: " . mysql_error($report->conn)); } //if this query had an assert=empty flag and returned results, throw error if (preg_match('/^--[\\s+]assert[\\s]*=[\\s]*empty[\\s]*\\n/', $query)) { if (mysql_fetch_assoc($result)) { throw new Exception("Assert failed. Query did not return empty results."); } } // If this query should be included as a dataset if (!$explicit_datasets && $is_last || preg_match('/--\\s+@dataset(\\s*=\\s*|\\s+)true/', $query)) { $dataset = array('rows' => array()); while ($row = mysql_fetch_assoc($result)) { $dataset['rows'][] = $row; } // Get dataset title if it has one if (preg_match('/--\\s+@title(\\s*=\\s*|\\s+)(.*)/', $query, $matches)) { $dataset['title'] = $matches[2]; } $datasets[] = $dataset; } } return $datasets; }
public static function run(&$report) { $report->conn->SetFetchMode(ADODB_FETCH_ASSOC); $rows = array(); $macros = $report->macros; foreach ($macros as $key => $value) { if (is_array($value)) { $first = true; foreach ($value as $key2 => $value2) { $value[$key2] = mysql_real_escape_string(trim($value2)); $first = false; } $macros[$key] = $value; } else { $macros[$key] = mysql_real_escape_string($value); } if ($value === 'ALL') { $macros[$key . '_all'] = true; } } //add the config and environment settings as macros $macros['config'] = PhpReports::$config; $macros['environment'] = PhpReports::$config['environments'][$report->options['Environment']]; //expand macros in query $sql = PhpReports::render($report->raw_query, $macros); $report->options['Query'] = $sql; $report->options['Query_Formatted'] = SqlFormatter::format($sql); //split into individual queries and run each one, saving the last result $queries = SqlFormatter::splitQuery($sql); foreach ($queries as $query) { //skip empty queries $query = trim($query); if (!$query) { continue; } $result = $report->conn->Execute($query); if (!$result) { throw new Exception("Query failed: " . $report->conn->ErrorMsg()); } //if this query had an assert=empty flag and returned results, throw error if (preg_match('/^--[\\s+]assert[\\s]*=[\\s]*empty[\\s]*\\n/', $query)) { if ($result->GetAssoc()) { throw new Exception("Assert failed. Query did not return empty results."); } } } return $result->GetArray(); }
public static function run(&$report) { $report->conn->SetFetchMode(ADODB_FETCH_ASSOC); $rows = array(); $macros = $report->macros; foreach ($macros as $key => $value) { if (is_array($value)) { $first = true; foreach ($value as $key2 => $value2) { $value[$key2] = mysql_real_escape_string(trim($value2)); $first = false; } $macros[$key] = $value; } else { $macros[$key] = mysql_real_escape_string($value); } if ($value === 'ALL') { $macros[$key . '_all'] = true; } } //add the config and environment settings as macros $macros['config'] = PhpReports::$config; $macros['environment'] = PhpReports::$config['environments'][$report->options['Environment']]; $raw_sql = ""; foreach ($report->raw_query as $qry) { if (is_array($qry)) { foreach ($qry as $key => $value) { // TODO handle arrays better if (!is_bool($value) && !is_array($value)) { $qry[$key] = PhpReports::renderString($value, $macros); } } //TODO This sux - need a class or something :-) $raw_sql .= PivotTableSQL($report->conn, $qry['tables'], $qry['rows'], $qry['columns'], $qry['where'], $qry['orderBy'], $qry['limit'], $qry['agg_field'], $qry['agg_label'], $qry['agg_fun'], $qry['include_agg_field'], $qry['show_count']); } else { $raw_sql .= $qry; } } //expand macros in query $sql = PhpReports::render($raw_sql, $macros); $report->options['Query'] = $sql; $report->options['Query_Formatted'] = SqlFormatter::format($sql); //split into individual queries and run each one, saving the last result $queries = SqlFormatter::splitQuery($sql); foreach ($queries as $query) { if (!is_array($query)) { //skip empty queries $query = trim($query); if (!$query) { continue; } $result = $report->conn->Execute($query); if (!$result) { throw new Exception("Query failed: " . $report->conn->ErrorMsg()); } //if this query had an assert=empty flag and returned results, throw error if (preg_match('/^--[\\s+]assert[\\s]*=[\\s]*empty[\\s]*\\n/', $query)) { if ($result->GetAssoc()) { throw new Exception("Assert failed. Query did not return empty results."); } } } } return $result->GetArray(); }