Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions classes/report_types/MysqlReportType.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,22 @@ public static function closeConnection(&$report) {
}

public static function getVariableOptions($params, &$report) {
$query = 'SELECT DISTINCT '.$params['column'].' FROM '.$params['table'];

if(isset($params['where'])) {
$query .= ' WHERE '.$params['where'];
}
if (isset($params['query'])) {
$query = $params['query'];
} else if (isset($params['column']) && isset($params['table'])) {
$query = 'SELECT DISTINCT ' . $params['column'] . ' FROM ' . $params['table'];

if (isset($params['where'])) {
$query .= ' WHERE ' . $params['where'];
}

if(isset($params['order']) && in_array($params['order'], array('ASC', 'DESC')) ) {
$query .= ' ORDER BY '.$params['column'].' '.$params['order'];
if (isset($params['order']) && in_array($params['order'], array('ASC', 'DESC'))) {
$query .= ' ORDER BY ' . $params['column'] . ' ' . $params['order'];
}
}


if(empty($query)) return array();

$result = mysql_query($query, $report->conn);

if(!$result) {
Expand All @@ -105,11 +111,16 @@ public static function getVariableOptions($params, &$report) {
$options = array();

if(isset($params['all'])) $options[] = 'ALL';

while($row = mysql_fetch_assoc($result)) {
$options[] = $row[$params['column']];

if (isset($params['column'])) {
while ($row = mysql_fetch_assoc($result)) {
$options[] = $row[$params['column']];
}
} else {
while ($row = mysql_fetch_array($result)) {
$options[] = $row[0];
}
}

return $options;
}

Expand Down
28 changes: 27 additions & 1 deletion classes/report_types/PhpReportType.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,33 @@ public static function openConnection(&$report) {
public static function closeConnection(&$report) {

}


public static function getVariableOptions($params, &$report)
{

if (is_array($params)) {

// support for dynamic select type using database_options in php reports
// only supporting mysql currently:

if (stristr($params['type'], 'mysql')) {

// create a clone of our report for a mysql connection to not pollute
// the original object. This may not be necessary.
$reportMysql = clone $report;

// Connect to the database since this we are using a different type.
// This also allows for setting the database with the varaible string.
$reportMysql->options['Database'] = isset($params['database']) ? $params['database'] : 'mysql';
MysqlReportType::openConnection($reportMysql);

return MysqlReportType::getVariableOptions($params, $reportMysql);
}
}

return array();
}

public static function run(&$report) {
$eval = "<?php /*BEGIN REPORT MACROS*/ ?><?php ";
foreach($report->macros as $key=>$value) {
Expand Down