diff options
author | Jehan-Guillaume (ioguix) de Rorthais | 2012-08-21 22:38:54 +0000 |
---|---|---|
committer | Jehan-Guillaume (ioguix) de Rorthais | 2012-08-22 10:39:42 +0000 |
commit | 71b21dd28ba3c3d203ffc98d22bd41e5d02a83d8 (patch) | |
tree | 8de7817f0cac53b7d8daf46c3e4d68348cd129f2 | |
parent | 122f96b0269dfcbf9d8e6401410a0e6b1fababff (diff) |
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
-rw-r--r-- | plugins/Report/classes/Reports.php | 6 | ||||
-rw-r--r-- | plugins/Report/lang/english.php | 1 | ||||
-rw-r--r-- | plugins/Report/lang/french.php | 1 | ||||
-rw-r--r-- | plugins/Report/plugin.php | 175 | ||||
-rw-r--r-- | sql.php | 2 |
5 files changed, 94 insertions, 91 deletions
diff --git a/plugins/Report/classes/Reports.php b/plugins/Report/classes/Reports.php index a0303a99..19327b48 100644 --- a/plugins/Report/classes/Reports.php +++ b/plugins/Report/classes/Reports.php @@ -16,7 +16,7 @@ /* Constructor */ function __construct(&$conf, &$status) { global $misc, $data; - + $this->conf = $conf; // Check to see if the reports database exists @@ -57,14 +57,14 @@ * @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 diff --git a/plugins/Report/lang/english.php b/plugins/Report/lang/english.php index 2ceee1e2..ce6e6f77 100644 --- a/plugins/Report/lang/english.php +++ b/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"?'; diff --git a/plugins/Report/lang/french.php b/plugins/Report/lang/french.php index 13db41dc..ac1f5fdb 100644 --- a/plugins/Report/lang/french.php +++ b/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 » ?'; diff --git a/plugins/Report/plugin.php b/plugins/Report/plugin.php index 8af27c05..9cfc5cc5 100644 --- a/plugins/Report/plugin.php +++ b/plugins/Report/plugin.php @@ -44,12 +44,12 @@ class Report extends Plugin { $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 @@ class Report extends Plugin { * @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 @@ class Report extends Plugin { 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 @@ class Report extends Plugin { * Saves changes to a report */ function save_edit() { - global $lang; - $reportsdb = $this->get_reportsdb(); if (isset($_REQUEST['cancel'])) { @@ -519,7 +515,12 @@ class Report extends Plugin { 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 @@ class Report extends Plugin { * 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 @@ class Report extends Plugin { } function execute() { - global $misc, $lang, $data; + global $misc, $data; $reportsdb = $this->get_reportsdb(); @@ -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); |