Skip to content
Browse files

Miscellaneous fix on Report plugin

Some fixes and cleanup while reviewing the Report plugin:
  * remove forgotten commented code
  * some variable typo fixes and cleanup
  * handle "create report" from the browse link on tables
  * support auto-check paginate on creating report when the recordset
    was paginated
  • Loading branch information...
1 parent 122f96b commit 71b21dd28ba3c3d203ffc98d22bd41e5d02a83d8 @ioguix ioguix committed
Showing with 94 additions and 91 deletions.
  1. +3 −3 plugins/Report/classes/Reports.php
  2. +1 −0 plugins/Report/lang/english.php
  3. +1 −0 plugins/Report/lang/french.php
  4. +87 −88 plugins/Report/plugin.php
  5. +2 −0 sql.php
View
6 plugins/Report/classes/Reports.php
@@ -16,7 +16,7 @@ class Reports {
/* Constructor */
function __construct(&$conf, &$status) {
global $misc, $data;
-
+
$this->conf = $conf;
// Check to see if the reports database exists
@@ -57,14 +57,14 @@ function getReports() {
* @param $report_id The ID of the report to find
* @return A recordset
*/
- function getReport($report_id) {
+ function getReport($report_id) {
$sql = $this->driver->getSelectSQL($this->conf['reports_table'],
array('report_id', 'report_name', 'db_name', 'date_created', 'created_by', 'descr', 'report_sql', 'paginate'),
array('report_id' => $report_id), array('report_id' => '='), array());
return $this->driver->selectSet($sql);
}
-
+
/**
* Creates a report
* @param $report_name The name of the report
View
1 plugins/Report/lang/english.php
@@ -13,6 +13,7 @@
$plugin_lang['strshowallreports'] = 'Show all reports';
$plugin_lang['strnoreports'] = 'No reports found.';
$plugin_lang['strcreatereport'] = 'Create report';
+ $plugin_lang['streditreport'] = 'Edit report';
$plugin_lang['strreportdropped'] = 'Report dropped.';
$plugin_lang['strreportdroppedbad'] = 'Report drop failed.';
$plugin_lang['strconfdropreport'] = 'Are you sure you want to drop the report "%s"?';
View
1 plugins/Report/lang/french.php
@@ -13,6 +13,7 @@
$plugin_lang['strshowallreports'] = 'Voir tous les rapports';
$plugin_lang['strnoreports'] = 'Aucun rapport trouvé.';
$plugin_lang['strcreatereport'] = 'Créer un rapport';
+ $plugin_lang['streditreport'] = 'Éditer un rapport';
$plugin_lang['strreportdropped'] = 'Rapport supprimé.';
$plugin_lang['strreportdroppedbad'] = 'Échec lors de la suppression du rapport.';
$plugin_lang['strconfdropreport'] = 'Êtes-vous sûr de vouloir supprimer le rapport « %s » ?';
View
175 plugins/Report/plugin.php
@@ -44,12 +44,12 @@ function get_reportsdb() {
$this->_reportsdb = new Reports($this->conf, $status);
if ($status !== 0) {
- global $misc, $lang;
- $misc->printHeader($lang['strreports']);
+ global $misc;
+ $misc->printHeader($this->lang['strreports']);
$misc->printBody();
$misc->printTrail('server');
$misc->printTabs('server','reports');
- $misc->printMsg($lang['strnoreportsdb']);
+ $misc->printMsg($this->lang['strnoreportsdb']);
$misc->printFooter();
exit;
}
@@ -150,7 +150,7 @@ function add_plugin_tabs(&$plugin_functions_parameters) {
* @param $plugin_functions_parameters
*/
function add_plugin_trail(&$plugin_functions_parameters) {
- global $misc, $lang;
+ global $misc;
$trail = &$plugin_functions_parameters['trail'];
$done = false;
$subject = '';
@@ -218,85 +218,83 @@ function add_plugin_navlinks(&$params) {
global $misc, $lang;
if (
- ($params['place'] == 'sql-form' or $params['place'] == 'display-browse')
- and (isset($_SESSION['sqlquery']) && isset($params['env']['rs']) && is_object($params['env']['rs']) && $params['env']['rs']->recordCount() > 0)
- ) {
- switch ($params['place']) {
- case 'sql-form':
- case 'display-browse':
- if ( ! (isset($_REQUEST['plugin']) && $_REQUEST['plugin'] == $this->name) )
- $params['navlinks'][] = array (
- 'attr'=> array (
- 'href' => array (
- 'url' => 'plugin.php',
- 'urlvars' => array (
- 'plugin' => $this->name,
- 'action' => 'create',
- 'server' => field('server'),
- 'database' => field('database'),
- 'schema' => field('schema'),
- 'report_sql' => $_SESSION['sqlquery']
- )
- )
- ),
- 'content' => $this->lang['strcreatereport']
- );
- else
- $params['navlinks'][] = array (
- 'attr'=> array (
- 'href' => array (
- 'url' => 'plugin.php',
- 'urlvars' => array (
- 'plugin' => $this->name,
- 'action' => 'edit',
- 'server' => field('server'),
- 'database' => field('database'),
- // 'schema' => field('schema'),
- 'report_id' => field('report_id')
- )
- )
- ),
- 'content' => $lang['stredit']
- );
- break;
- // case 'display-browse':
- // if ( ! (isset($_REQUEST['plugin']) && $_REQUEST['plugin'] == $this->name) )
- // $params['navlinks'][] = array (
- // 'attr'=> array (
- // 'href' => array (
- // 'url' => 'plugin.php',
- // 'urlvars' => array (
- // 'plugin' => $this->name,
- // 'action' => 'create',
- // 'server' => field('server'),
- // 'database' => field('database'),
- // 'schema' => field('schema'),
- // 'report_sql' => field('query'),
- // 'paginate' => (isset($_REQUEST['paginate']) ? $_REQUEST['paginate'] : 'f')
- // )
- // )
- // ),
- // 'content' => $this->lang['strcreatereport']
- // );
- // else
- // $params['navlinks'][] = array (
- // 'attr'=> array (
- // 'href' => array (
- // 'url' => 'plugin.php',
- // 'urlvars' => array (
- // 'plugin' => $this->name,
- // 'action' => 'edit',
- // 'server' => field('server'),
- // 'database' => field('database'),
- // // 'schema' => field('schema'),
- // 'report_id' => field('report_id')
- // )
- // )
- // ),
- // 'content' => $lang['stredit']
- // );
- break;
+ ($params['place'] == 'sql-form'
+ or $params['place'] == 'display-browse')
+ and ( isset($params['env']['rs'])
+ and is_object($params['env']['rs'])
+ and $params['env']['rs']->recordCount() > 0))
+ {
+ if ( ! (isset($_REQUEST['plugin'])
+ and $_REQUEST['plugin'] == $this->name)
+ ) {
+ /* ResultSet doesn't come from a plugin:
+ * show a create report link. */
+ $params['navlinks']['report_link'] = array (
+ 'attr'=> array (
+ 'href' => array (
+ 'url' => 'plugin.php',
+ 'urlvars' => array (
+ 'plugin' => $this->name,
+ 'action' => 'create',
+ 'server' => $_REQUEST['server'],
+ 'database' => $_REQUEST['database'],
+ )
+ )
+ ),
+ 'content' => $this->lang['strcreatereport']
+ );
+
+ if (isset($_REQUEST['paginate']))
+ $params['navlinks']['report_link']['attr']['href']['urlvars']['paginate']
+ = $_REQUEST['paginate'];
+
+ if (!empty($_SESSION['sqlquery'])) {
+ $params['navlinks']['report_link']['attr']['href']['urlvars']['report_sql']
+ = $_SESSION['sqlquery'];
+ }
+ else {
+ if (isset($_REQUEST['subject'])
+ and isset($_REQUEST[$_REQUEST['subject']]))
+ {
+ $params['navlinks']['report_link']['attr']['href']['urlvars']['subject']
+ = $_REQUEST['subject'];
+ $params['navlinks']['report_link']['attr']['href']['urlvars'][$_REQUEST['subject']]
+ = $_REQUEST[$_REQUEST['subject']];
+
+ $params['navlinks']['report_link']['attr']['href']['urlvars']['sortkey']
+ = isset($_REQUEST['sortkey']) ? $_REQUEST['sortkey'] : '';
+
+ $params['navlinks']['report_link']['attr']['href']['urlvars']['sortdir']
+ = isset($_REQUEST['sortdir']) ? $_REQUEST['sortdir'] : '';
+ }
+ else {
+ unset($params['navlinks']['report_link']);
+ }
+ }
}
+ else {
+ /* ResultSet comes from a plugin:
+ * show a edit report link. */
+ $params['navlinks']['report_link'] = array (
+ 'attr'=> array (
+ 'href' => array (
+ 'url' => 'plugin.php',
+ 'urlvars' => array (
+ 'plugin' => $this->name,
+ 'action' => 'edit',
+ 'server' => $_REQUEST['server'],
+ 'database' => $_REQUEST['database'],
+ 'report_id' => $_REQUEST['report_id']
+ )
+ )
+ ),
+ 'content' => $this->lang['streditreport']
+ );
+ }
+
+ if (isset($_REQUEST['schema']))
+ $params['navlinks']['report_link']['attr']['href']['urlvars']['schema']
+ = $_REQUEST['schema'];
}
}
@@ -388,8 +386,6 @@ function edit($msg = '') {
* Saves changes to a report
*/
function save_edit() {
- global $lang;
-
$reportsdb = $this->get_reportsdb();
if (isset($_REQUEST['cancel'])) {
@@ -519,7 +515,12 @@ function create($msg = '') {
if (!isset($_REQUEST['report_name'])) $_REQUEST['report_name'] = '';
if (!isset($_REQUEST['db_name'])) $_REQUEST['db_name'] = '';
if (!isset($_REQUEST['descr'])) $_REQUEST['descr'] = '';
- if (!isset($_REQUEST['report_sql'])) $_REQUEST['report_sql'] = '';
+ if (!isset($_REQUEST['report_sql'])) {
+ $_REQUEST['sortkey'] = isset($_REQUEST['sortkey']) ? $_REQUEST['sortkey'] : '';
+ if (preg_match('/^[0-9]+$/', $_REQUEST['sortkey']) && $_REQUEST['sortkey'] > 0) $orderby = array($_REQUEST['sortkey'] => $_REQUEST['sortdir']);
+ else $orderby = array();
+ $_REQUEST['report_sql'] = $data->getSelectSQL($_REQUEST[$_REQUEST['subject']], array(), array(), array(), $orderby);
+ }
if (isset($_REQUEST['database'])) {
$_REQUEST['db_name'] = $_REQUEST['database'];
@@ -564,8 +565,6 @@ function create($msg = '') {
* Actually creates the new report in the database
*/
function save_create() {
- global $lang;
-
if (isset($_REQUEST['cancel'])) {
$this->default_action();
exit;
@@ -640,7 +639,7 @@ function drop() {
}
function execute() {
- global $misc, $lang, $data;
+ global $misc, $data;
$reportsdb = $this->get_reportsdb();
View
2 sql.php
@@ -9,6 +9,8 @@
* $Id: sql.php,v 1.43 2008/01/10 20:19:27 xzilla Exp $
*/
+ global $lang;
+
// Prevent timeouts on large exports (non-safe mode only)
if (!ini_get('safe_mode')) set_time_limit(0);

0 comments on commit 71b21dd

Please sign in to comment.
Something went wrong with that request. Please try again.