From 3b4ec98a01e98fd3209c03a8d21452d0bd8af55f Mon Sep 17 00:00:00 2001 From: "Jehan-Guillaume (ioguix) de Rorthais" Date: Sat, 18 Aug 2012 01:58:33 +0200 Subject: [PATCH] Add plugin Report This plugin is the old Report feature from PPA <5.1 moved as a plugin in the new plugin architecture. --- plugins/Report/INSTALL | 13 + plugins/Report/classes/Reports.php | 128 ++++ plugins/Report/conf/config.inc.php | 12 + plugins/Report/images/Report.png | Bin 0 -> 405 bytes plugins/Report/images/Reports.png | Bin 0 -> 339 bytes plugins/Report/lang/afrikaans.php | 23 + plugins/Report/lang/arabic.php | 23 + plugins/Report/lang/catalan.php | 23 + plugins/Report/lang/chinese-sim.php | 22 + plugins/Report/lang/chinese-tr.php | 23 + plugins/Report/lang/chinese-utf8-zh_CN.php | 23 + plugins/Report/lang/chinese-utf8-zh_TW.php | 23 + plugins/Report/lang/czech.php | 23 + plugins/Report/lang/danish.php | 25 + plugins/Report/lang/dutch.php | 21 + plugins/Report/lang/english.php | 23 + plugins/Report/lang/french.php | 23 + plugins/Report/lang/galician.php | 23 + plugins/Report/lang/german.php | 23 + plugins/Report/lang/greek.php | 24 + plugins/Report/lang/hebrew.php | 23 + plugins/Report/lang/hungarian.php | 23 + plugins/Report/lang/italian.php | 23 + plugins/Report/lang/japanese.php | 23 + plugins/Report/lang/lithuanian.php | 23 + plugins/Report/lang/mongol.php | 22 + plugins/Report/lang/polish.php | 23 + plugins/Report/lang/portuguese-br.php | 23 + plugins/Report/lang/portuguese-pt.php | 23 + plugins/Report/lang/romanian.php | 23 + plugins/Report/lang/russian.php | 23 + plugins/Report/lang/slovak.php | 23 + plugins/Report/lang/spanish.php | 23 + plugins/Report/lang/swedish.php | 25 + plugins/Report/lang/turkish.php | 23 + plugins/Report/lang/ukrainian.php | 23 + plugins/Report/plugin.php | 774 +++++++++++++++++++++ plugins/Report/sql/reports-pgsql.sql | 27 + 38 files changed, 1668 insertions(+) create mode 100644 plugins/Report/INSTALL create mode 100644 plugins/Report/classes/Reports.php create mode 100644 plugins/Report/conf/config.inc.php create mode 100644 plugins/Report/images/Report.png create mode 100644 plugins/Report/images/Reports.png create mode 100644 plugins/Report/lang/afrikaans.php create mode 100644 plugins/Report/lang/arabic.php create mode 100644 plugins/Report/lang/catalan.php create mode 100644 plugins/Report/lang/chinese-sim.php create mode 100644 plugins/Report/lang/chinese-tr.php create mode 100644 plugins/Report/lang/chinese-utf8-zh_CN.php create mode 100644 plugins/Report/lang/chinese-utf8-zh_TW.php create mode 100644 plugins/Report/lang/czech.php create mode 100644 plugins/Report/lang/danish.php create mode 100644 plugins/Report/lang/dutch.php create mode 100644 plugins/Report/lang/english.php create mode 100644 plugins/Report/lang/french.php create mode 100644 plugins/Report/lang/galician.php create mode 100644 plugins/Report/lang/german.php create mode 100644 plugins/Report/lang/greek.php create mode 100644 plugins/Report/lang/hebrew.php create mode 100644 plugins/Report/lang/hungarian.php create mode 100644 plugins/Report/lang/italian.php create mode 100644 plugins/Report/lang/japanese.php create mode 100644 plugins/Report/lang/lithuanian.php create mode 100644 plugins/Report/lang/mongol.php create mode 100644 plugins/Report/lang/polish.php create mode 100644 plugins/Report/lang/portuguese-br.php create mode 100644 plugins/Report/lang/portuguese-pt.php create mode 100644 plugins/Report/lang/romanian.php create mode 100644 plugins/Report/lang/russian.php create mode 100644 plugins/Report/lang/slovak.php create mode 100644 plugins/Report/lang/spanish.php create mode 100644 plugins/Report/lang/swedish.php create mode 100644 plugins/Report/lang/turkish.php create mode 100644 plugins/Report/lang/ukrainian.php create mode 100644 plugins/Report/plugin.php create mode 100644 plugins/Report/sql/reports-pgsql.sql diff --git a/plugins/Report/INSTALL b/plugins/Report/INSTALL new file mode 100644 index 00000000..263f308b --- /dev/null +++ b/plugins/Report/INSTALL @@ -0,0 +1,13 @@ +phpPgAdmin Report Plugin Installation Guide +------------------------------------------- +1. Report Plugin activation + + Open conf/config.inc.php and add the 'Report' value in the $conf['plugins'] array: + + $conf['plugins'] = array('Report'); + +2. Set up the reports database. + + If you want to enable reports (which are a useful feature) then go to + the 'sql' subdirectory and view the SQL script for your database. It + will contain instructions on how to set up the reports database. diff --git a/plugins/Report/classes/Reports.php b/plugins/Report/classes/Reports.php new file mode 100644 index 00000000..a0303a99 --- /dev/null +++ b/plugins/Report/classes/Reports.php @@ -0,0 +1,128 @@ +conf = $conf; + + // Check to see if the reports database exists + $rs = $data->getDatabase($this->conf['reports_db']); + if ($rs->recordCount() != 1) $status = -1; + else { + // Create a new database access object. + $this->driver = $misc->getDatabaseAccessor($this->conf['reports_db']); + // Reports database should have been created in public schema + $this->driver->setSchema($this->conf['reports_schema']); + $status = 0; + } + } + + /** + * Finds all reports + * @return A recordset + */ + function getReports() { + global $misc; + // Filter for owned reports if necessary + if ($this->conf['owned_reports_only']) { + $server_info = $misc->getServerInfo(); + $filter['created_by'] = $server_info['username']; + $ops = array('created_by' => '='); + } + else $filter = $ops = array(); + + $sql = $this->driver->getSelectSQL($this->conf['reports_table'], + array('report_id', 'report_name', 'db_name', 'date_created', 'created_by', 'descr', 'report_sql', 'paginate'), + $filter, $ops, array('db_name' => 'asc', 'report_name' => 'asc')); + + return $this->driver->selectSet($sql); + } + + /** + * Finds a particular report + * @param $report_id The ID of the report to find + * @return A recordset + */ + 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 + * @param $db_name The name of the database + * @param $descr The comment on the report + * @param $report_sql The SQL for the report + * @param $paginate The report should be paginated + * @return 0 success + */ + function createReport($report_name, $db_name, $descr, $report_sql, $paginate) { + global $misc; + $server_info = $misc->getServerInfo(); + $temp = array( + 'report_name' => $report_name, + 'db_name' => $db_name, + 'created_by' => $server_info['username'], + 'report_sql' => $report_sql, + 'paginate' => $paginate ? 'true' : 'false', + ); + if ($descr != '') $temp['descr'] = $descr; + + return $this->driver->insert($this->conf['reports_table'], $temp); + } + + /** + * Alters a report + * @param $report_id The ID of the report + * @param $report_name The name of the report + * @param $db_name The name of the database + * @param $descr The comment on the report + * @param $report_sql The SQL for the report + * @param $paginate The report should be paginated + * @return 0 success + */ + function alterReport($report_id, $report_name, $db_name, $descr, $report_sql, $paginate) { + global $misc; + $server_info = $misc->getServerInfo(); + $temp = array( + 'report_name' => $report_name, + 'db_name' => $db_name, + 'created_by' => $server_info['username'], + 'report_sql' => $report_sql, + 'paginate' => $paginate ? 'true' : 'false', + 'descr' => $descr + ); + + return $this->driver->update($this->conf['reports_table'], $temp, + array('report_id' => $report_id)); + } + + /** + * Drops a report + * @param $report_id The ID of the report to drop + * @return 0 success + */ + function dropReport($report_id) { + return $this->driver->delete($this->conf['reports_table'], array('report_id' => $report_id)); + } + + } +?> diff --git a/plugins/Report/conf/config.inc.php b/plugins/Report/conf/config.inc.php new file mode 100644 index 00000000..c036544e --- /dev/null +++ b/plugins/Report/conf/config.inc.php @@ -0,0 +1,12 @@ + diff --git a/plugins/Report/images/Report.png b/plugins/Report/images/Report.png new file mode 100644 index 0000000000000000000000000000000000000000..f9158b9a02d899fa802621243df3d0b64cf3b8d0 GIT binary patch literal 405 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G_YAk0{w5<>&kwEkwaWrmT&d!4-5>9N}eu`Ar`%NCvEg%4is?p|F-s~ z#NuiH8pX6CesI^dYz<{vX5iYjVnIUYWF^N=wk-mGdKEHTM9TiPi=CYPTPIBTaMYS< zd^~4z&&jlDwg_az-#3!t`;q(gckQC{mVXvnGZ-Gouvk!g^>J;E2FoHR#?}ejT0D1X z98&RVe5$f6a(!rH)SsoF&Az=comaHde%@Q3=b8>&Hgn!5rCB^TFy7N*o}6^7so3Yt zhq#Jhu>_&t%g^uRdDp*v6N7%?=_9kXl?W}qeiyajwQ!ixar7%8C zGW^ba%JY+ceuCPq-mm%5!OZz?sT)nE@2&g6tiQPK=d9BUE=QbV3iIYHU+cT4MP*4t xYeSRAqYAzCYeS40-krRdXnOruWGSN^L&mFroJukae*goJ!PC{xWt~$(698}>rz-#e literal 0 HcmV?d00001 diff --git a/plugins/Report/images/Reports.png b/plugins/Report/images/Reports.png new file mode 100644 index 0000000000000000000000000000000000000000..4a403e070c32a1be865b83d74dac2e83cf9fab11 GIT binary patch literal 339 zcmV-Z0j&OsP)`^WGXjQ=z6va>Lh z=VgH`z-a)(*I$1aRxMk~aQ^sVoK66`^gp^w;0F8y+62-}s!QMofE1DA61V|>paziY z5)2n0yTrBlC{`D&YBazM#J_+4VYp;@lL=7#FIemkkp2x~{{gZ8VH)t~-(L)uMAn_b z>Vm~JI+zCVbFgE$WNx)C*fzNBAo>r4MmJ!3ZBcF}x=WHhF3Ib?h1CVqin*~HfbNn-)!Ja&{( diff --git a/plugins/Report/lang/arabic.php b/plugins/Report/lang/arabic.php new file mode 100644 index 00000000..32a34c31 --- /dev/null +++ b/plugins/Report/lang/arabic.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/catalan.php b/plugins/Report/lang/catalan.php new file mode 100644 index 00000000..0f5c82c3 --- /dev/null +++ b/plugins/Report/lang/catalan.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/chinese-sim.php b/plugins/Report/lang/chinese-sim.php new file mode 100644 index 00000000..aedf4d13 --- /dev/null +++ b/plugins/Report/lang/chinese-sim.php @@ -0,0 +1,22 @@ + diff --git a/plugins/Report/lang/chinese-tr.php b/plugins/Report/lang/chinese-tr.php new file mode 100644 index 00000000..d5bfbc14 --- /dev/null +++ b/plugins/Report/lang/chinese-tr.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/chinese-utf8-zh_CN.php b/plugins/Report/lang/chinese-utf8-zh_CN.php new file mode 100644 index 00000000..834a93b8 --- /dev/null +++ b/plugins/Report/lang/chinese-utf8-zh_CN.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/chinese-utf8-zh_TW.php b/plugins/Report/lang/chinese-utf8-zh_TW.php new file mode 100644 index 00000000..907b2342 --- /dev/null +++ b/plugins/Report/lang/chinese-utf8-zh_TW.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/czech.php b/plugins/Report/lang/czech.php new file mode 100644 index 00000000..ff6f539c --- /dev/null +++ b/plugins/Report/lang/czech.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/danish.php b/plugins/Report/lang/danish.php new file mode 100644 index 00000000..7d5df866 --- /dev/null +++ b/plugins/Report/lang/danish.php @@ -0,0 +1,25 @@ + diff --git a/plugins/Report/lang/dutch.php b/plugins/Report/lang/dutch.php new file mode 100644 index 00000000..aa541fbc --- /dev/null +++ b/plugins/Report/lang/dutch.php @@ -0,0 +1,21 @@ + diff --git a/plugins/Report/lang/english.php b/plugins/Report/lang/english.php new file mode 100644 index 00000000..2ceee1e2 --- /dev/null +++ b/plugins/Report/lang/english.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/french.php b/plugins/Report/lang/french.php new file mode 100644 index 00000000..13db41dc --- /dev/null +++ b/plugins/Report/lang/french.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/galician.php b/plugins/Report/lang/galician.php new file mode 100644 index 00000000..87da669b --- /dev/null +++ b/plugins/Report/lang/galician.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/german.php b/plugins/Report/lang/german.php new file mode 100644 index 00000000..5f5cec5a --- /dev/null +++ b/plugins/Report/lang/german.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/greek.php b/plugins/Report/lang/greek.php new file mode 100644 index 00000000..78bde375 --- /dev/null +++ b/plugins/Report/lang/greek.php @@ -0,0 +1,24 @@ + diff --git a/plugins/Report/lang/hebrew.php b/plugins/Report/lang/hebrew.php new file mode 100644 index 00000000..d369f066 --- /dev/null +++ b/plugins/Report/lang/hebrew.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/hungarian.php b/plugins/Report/lang/hungarian.php new file mode 100644 index 00000000..bb94af95 --- /dev/null +++ b/plugins/Report/lang/hungarian.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/italian.php b/plugins/Report/lang/italian.php new file mode 100644 index 00000000..17716eaa --- /dev/null +++ b/plugins/Report/lang/italian.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/japanese.php b/plugins/Report/lang/japanese.php new file mode 100644 index 00000000..ec0dad25 --- /dev/null +++ b/plugins/Report/lang/japanese.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/lithuanian.php b/plugins/Report/lang/lithuanian.php new file mode 100644 index 00000000..2f4ddd5e --- /dev/null +++ b/plugins/Report/lang/lithuanian.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/mongol.php b/plugins/Report/lang/mongol.php new file mode 100644 index 00000000..0b171dcd --- /dev/null +++ b/plugins/Report/lang/mongol.php @@ -0,0 +1,22 @@ + diff --git a/plugins/Report/lang/polish.php b/plugins/Report/lang/polish.php new file mode 100644 index 00000000..ed5e0475 --- /dev/null +++ b/plugins/Report/lang/polish.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/portuguese-br.php b/plugins/Report/lang/portuguese-br.php new file mode 100644 index 00000000..d686d23e --- /dev/null +++ b/plugins/Report/lang/portuguese-br.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/portuguese-pt.php b/plugins/Report/lang/portuguese-pt.php new file mode 100644 index 00000000..769a2c0a --- /dev/null +++ b/plugins/Report/lang/portuguese-pt.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/romanian.php b/plugins/Report/lang/romanian.php new file mode 100644 index 00000000..c4ad1599 --- /dev/null +++ b/plugins/Report/lang/romanian.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/russian.php b/plugins/Report/lang/russian.php new file mode 100644 index 00000000..2082be2a --- /dev/null +++ b/plugins/Report/lang/russian.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/slovak.php b/plugins/Report/lang/slovak.php new file mode 100644 index 00000000..fa55a36b --- /dev/null +++ b/plugins/Report/lang/slovak.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/spanish.php b/plugins/Report/lang/spanish.php new file mode 100644 index 00000000..7499d2f0 --- /dev/null +++ b/plugins/Report/lang/spanish.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/swedish.php b/plugins/Report/lang/swedish.php new file mode 100644 index 00000000..8936ea6c --- /dev/null +++ b/plugins/Report/lang/swedish.php @@ -0,0 +1,25 @@ + diff --git a/plugins/Report/lang/turkish.php b/plugins/Report/lang/turkish.php new file mode 100644 index 00000000..278bd9fa --- /dev/null +++ b/plugins/Report/lang/turkish.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/lang/ukrainian.php b/plugins/Report/lang/ukrainian.php new file mode 100644 index 00000000..16060472 --- /dev/null +++ b/plugins/Report/lang/ukrainian.php @@ -0,0 +1,23 @@ + diff --git a/plugins/Report/plugin.php b/plugins/Report/plugin.php new file mode 100644 index 00000000..8af27c05 --- /dev/null +++ b/plugins/Report/plugin.php @@ -0,0 +1,774 @@ +lang and $this->conf */ + parent::__construct($language); + + /* default values */ + if (! isset($this->conf['reports_db'])) { + $this->conf['reports_db'] = 'phppgadmin'; + } + if (! isset($this->conf['reports_schema'])) { + $this->conf['reports_schema'] = 'public'; + } + if (! isset($this->conf['reports_table'])) { + $this->conf['reports_table'] = 'ppa_reports'; + } + if (! isset($this->conf['owned_reports_only'])) { + $this->conf['owned_reports_only'] = false; + } + } + + function get_reportsdb() { + if ($this->_reportsdb === null) { + $status = 0; + $this->_reportsdb = new Reports($this->conf, $status); + + if ($status !== 0) { + global $misc, $lang; + $misc->printHeader($lang['strreports']); + $misc->printBody(); + $misc->printTrail('server'); + $misc->printTabs('server','reports'); + $misc->printMsg($lang['strnoreportsdb']); + $misc->printFooter(); + exit; + } + } + + return $this->_reportsdb; + } + + /** + * This method returns the functions that will hook in the phpPgAdmin core. + * To do include a function just put in the $hooks array the follwing code: + * 'hook' => array('function1', 'function2'). + * + * Example: + * $hooks = array( + * 'toplinks' => array('add_plugin_toplinks'), + * 'tabs' => array('add_tab_entry'), + * 'action_buttons' => array('add_more_an_entry') + * ); + * + * @return $hooks + */ + function get_hooks() { + $hooks = array( + 'tabs' => array('add_plugin_tabs'), + 'trail' => array('add_plugin_trail'), + 'navlinks' => array('add_plugin_navlinks') + ); + return $hooks; + } + + /** + * This method returns the functions that will be used as actions. + * To do include a function that will be used as action, just put in the $actions array the follwing code: + * + * $actions = array( + * 'show_page', + * 'show_error', + * ); + * + * @return $actions + */ + function get_actions() { + $actions = array( + 'save_edit', + 'edit', + 'properties', + 'save_create', + 'create', + 'drop', + 'confirm_drop', + 'execute', + 'default_action' + ); + return $actions; + } + + /** + * Add plugin in the tabs + * @param $plugin_functions_parameters + */ + function add_plugin_tabs(&$plugin_functions_parameters) { + global $misc; + + $tabs = &$plugin_functions_parameters['tabs']; + + if ($plugin_functions_parameters['section'] == 'server') { + $tabs['report_plugin'] = array ( + 'title' => $this->lang['strplugindescription'], + 'url' => 'plugin.php', + 'urlvars' => array( + 'subject' => 'server', + 'action' => 'default_action', + 'plugin' => $this->name + ), + 'hide' => false, + 'icon' => $this->icon('Report') + ); + } + + if ($plugin_functions_parameters['section'] == 'report') { + $tabs['report_plugin'] = array ( + 'title' => $this->lang['strplugindescription'], + 'url' => 'plugin.php', + 'urlvars' => array( + 'subject' => 'server', + 'action' => 'default_action', + 'plugin' => $this->name + ), + 'hide' => false, + 'icon' => $this->icon('Report') + ); + } + } + + /** + * Add plugin in the trail + * @param $plugin_functions_parameters + */ + function add_plugin_trail(&$plugin_functions_parameters) { + global $misc, $lang; + $trail = &$plugin_functions_parameters['trail']; + $done = false; + $subject = ''; + if (isset($_REQUEST['subject'])) { + $subject = $_REQUEST['subject']; + } + + $action = ''; + if (isset($_REQUEST['action'])) { + $action = $_REQUEST['action']; + } + + if (isset($_REQUEST['plugin']) and $_REQUEST['plugin'] == 'Report') { + $url = array ( + 'url' => 'plugin.php', + 'urlvars' => array ( + 'plugin' => $this->name, + 'action' => 'default_action' + ) + ); + $trail['report_plugin'] = array ( + 'title' => $this->lang['strreport'], + 'text' => $this->lang['strreport'], + 'url' => $misc->getActionUrl($url, $_REQUEST, null, false), + 'icon' => $this->icon('Reports') + ); + } + + if (isset($_REQUEST['plugin']) + and $_REQUEST['plugin'] == 'Report' + and $action != 'default_action' + and in_array($action, $this->get_actions()) + ) { + + $url = array ( + 'url' => 'plugin.php', + 'urlvars' => array ( + 'plugin' => $this->name, + 'action' => 'properties', + 'report_id' => field('report_id'), + ) + ); + + if (isset($_REQUEST['report'])) + $url['urlvars']['report'] = field('report'); + + $trail['report_plugin_name'] = array ( + 'title' => $this->lang['strreport'], + 'text' => $this->lang['strreport'], + 'url' => $misc->getActionUrl($url, $_REQUEST, null, false), + 'icon' => $this->icon('Report') + ); + + if (isset($_REQUEST['report'])) + $trail['report_plugin_name']['text'] = $_REQUEST['report']; + + } + } + + /** + * Add plugin in the navlinks + * @param $plugin_functions_parameters + */ + 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; + } + } + } + + function get_subject_params() { + $vars = array(); + + if (! isset($_REQUEST['action'])) + return $vars; + + $action = $_REQUEST['action']; + + switch ($action) { + case 'execute': + $vars = array( + 'report_id' => $_REQUEST['report_id'], + 'report' => $_REQUEST['report'], + 'action' => 'properties' /*defaults to properties*/ + ); + if (isset($_REQUEST['back'])) + $vars['action'] = $_REQUEST['back']; + break; + } + + return $vars; + } + + function edit($msg = '') { + global $data, $misc, $lang; + + $reportsdb = $this->get_reportsdb(); + + $misc->printHeader($this->lang['strreports']); + $misc->printBody(); + $misc->printTrail('server'); + $misc->printTabs('server', 'report_plugin'); + $misc->printMsg($msg); + + // If it's a first, load then get the data from the database + $report = $reportsdb->getReport($_REQUEST['report_id']); + + if ($_REQUEST['action'] == 'edit') { + $_POST['report_name'] = $report->fields['report_name']; + $_POST['db_name'] = $report->fields['db_name']; + $_POST['descr'] = $report->fields['descr']; + $_POST['report_sql'] = $report->fields['report_sql']; + if ($report->fields['paginate'] == 't') { + $_POST['paginate'] = true; + } + } + + // Get a list of available databases + $databases = $data->getDatabases(); + + $_REQUEST['report'] = $report->fields['report_name']; + + echo "
name}\" method=\"post\">\n"; + echo $misc->form; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
{$lang['strname']}_maxNameLen}\" value=\"", + htmlspecialchars($_POST['report_name']), "\" />
{$lang['strdatabase']}
{$lang['strcomment']}
{$lang['strsql']}
\n"; + echo "\n"; + echo "

\n"; + echo "\n"; + echo "

\n"; + echo "fields['report_id']}\" />\n"; + echo "
\n"; + $misc->printFooter(); + } + + /** + * Saves changes to a report + */ + function save_edit() { + global $lang; + + $reportsdb = $this->get_reportsdb(); + + if (isset($_REQUEST['cancel'])) { + $this->default_action(); + exit; + } + + if (!isset($_POST['report_name'])) $_POST['report_name'] = ''; + if (!isset($_POST['db_name'])) $_POST['db_name'] = ''; + if (!isset($_POST['descr'])) $_POST['descr'] = ''; + if (!isset($_POST['report_sql'])) $_POST['report_sql'] = ''; + + // Check that they've given a name and a definition + if ($_POST['report_name'] == '') { + $this->edit($this->lang['strreportneedsname']); + } elseif ($_POST['report_sql'] == '') { + $this->edit($this->lang['strreportneedsdef']); + } else { + $status = $reportsdb->alterReport($_POST['report_id'], $_POST['report_name'], $_POST['db_name'], + $_POST['descr'], $_POST['report_sql'], isset($_POST['paginate'])); + if ($status == 0) + $this->default_action($this->lang['strreportcreated']); + else + $this->edit($this->lang['strreportcreatedbad']); + } + } + + /** + * Display read-only properties of a report + */ + function properties($msg = '') { + global $data, $reportsdb, $misc; + global $lang; + + $reportsdb = $this->get_reportsdb(); + + $misc->printHeader($this->lang['strreports']); + $misc->printBody(); + $misc->printTrail('server'); + $misc->printTabs('server', 'report_plugin'); + $misc->printMsg($msg); + + $report = $reportsdb->getReport($_REQUEST['report_id']); + + $_REQUEST['report'] = $report->fields['report_name']; + + if ($report->recordCount() == 1) { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
{$lang['strname']}", $misc->printVal($report->fields['report_name']), "
{$lang['strdatabase']}", $misc->printVal($report->fields['db_name']), "
{$lang['strcomment']}", $misc->printVal($report->fields['descr']), "
{$lang['strpaginate']}", $misc->printVal($report->fields['paginate'], 'yesno', array('align' => 'left')), "
{$lang['strsql']}", $misc->printVal($report->fields['report_sql']), "
\n"; + } + else echo "

{$lang['strinvalidparam']}

\n"; + + $urlvars = array ( + 'plugin' => $this->name, + 'server' => $_REQUEST['server'] + ); + if (isset($_REQUEST['schema'])) $urlvars['schema'] = $_REQUEST['schema']; + if (isset($_REQUEST['schema'])) $urlvars['database'] = $_REQUEST['schema']; + + $navlinks = array ( + 'showall' => array ( + 'attr'=> array ( + 'href' => array ( + 'url' => 'plugin.php', + 'urlvars' => array_merge($urlvars, array('action' => 'default_action')) + ) + ), + 'content' => $this->lang['strshowallreports'] + ), + 'edit' => array ( + 'attr'=> array ( + 'href' => array ( + 'url' => 'plugin.php', + 'urlvars' => array_merge($urlvars, array( + 'action' => 'edit', + 'report_id' => $report->fields['report_id']) + ) + ) + ), + 'content' => $lang['stredit'] + ), + 'execute' => array ( + 'attr'=> array ( + 'href' => array ( + 'url' => 'plugin.php', + 'urlvars' => array_merge($urlvars, array( + 'action' => 'execute', + 'report' => $report->fields['report_name'], + 'database' => $report->fields['db_name'], + 'report_id' => $report->fields['report_id'], + 'paginate' => $report->fields['paginate'], + 'nohistory' => 't', + 'return' => 'plugin', + 'back' => 'properties' + )) + ) + ), + 'content' => $lang['strexecute'] + ) + ); + $misc->printNavLinks($navlinks, 'reports-properties'); + } + + /** + * Displays a screen where they can enter a new report + */ + function create($msg = '') { + global $data, $reportsdb, $misc; + global $lang; + + $misc->printHeader($this->lang['strreports']); + $misc->printBody(); + $misc->printTrail('server'); + $misc->printTabs('server', 'report_plugin'); + $misc->printMsg($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['database'])) { + $_REQUEST['db_name'] = $_REQUEST['database']; + unset($_REQUEST['database']); + $misc->setForm(); + } + + $databases = $data->getDatabases(); + + echo "
name}\" method=\"post\">\n"; + echo $misc->form; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
{$lang['strname']}_maxNameLen}\" value=\"", + htmlspecialchars($_REQUEST['report_name']), "\" />
{$lang['strdatabase']}
{$lang['strcomment']}
{$lang['strsql']}
\n"; + echo "\n"; + echo "

\n"; + echo "\n"; + echo "

\n"; + echo "
\n"; + $misc->printFooter(); + } + + /** + * Actually creates the new report in the database + */ + function save_create() { + global $lang; + + if (isset($_REQUEST['cancel'])) { + $this->default_action(); + exit; + } + + $reportsdb = $this->get_reportsdb(); + + if (!isset($_POST['report_name'])) $_POST['report_name'] = ''; + if (!isset($_POST['db_name'])) $_POST['db_name'] = ''; + if (!isset($_POST['descr'])) $_POST['descr'] = ''; + if (!isset($_POST['report_sql'])) $_POST['report_sql'] = ''; + + // Check that they've given a name and a definition + if ($_POST['report_name'] == '') $this->create($this->lang['strreportneedsname']); + elseif ($_POST['report_sql'] == '') $this->create($this->lang['strreportneedsdef']); + else { + $status = $reportsdb->createReport($_POST['report_name'], $_POST['db_name'], + $_POST['descr'], $_POST['report_sql'], isset($_POST['paginate'])); + if ($status == 0) + $this->default_action($this->lang['strreportcreated']); + else + $this->create($this->lang['strreportcreatedbad']); + } + } + + /** + * Show confirmation of drop and perform actual drop + */ + function drop() { + global $reportsdb, $misc; + global $lang; + + $confirm = false; + if (isset($_REQUEST['confirm'])) $confirm = true; + + $reportsdb = $this->get_reportsdb(); + + $misc->printHeader($this->lang['strreports']); + $misc->printBody(); + + if (isset($_REQUEST['cancel'])) { + $this->default_action(); + exit; + } + + if ($confirm) { + // Fetch report from the database + $report = $reportsdb->getReport($_REQUEST['report_id']); + + $_REQUEST['report'] = $report->fields['report_name']; + $misc->printTrail('report'); + $misc->printTitle($lang['strdrop']); + + echo "

", sprintf($this->lang['strconfdropreport'], $misc->printVal($report->fields['report_name'])), "

\n"; + + echo "
name}\" method=\"post\">\n"; + echo $misc->form; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + } else { + $status = $reportsdb->dropReport($_POST['report_id']); + if ($status == 0) + $this->default_action($this->lang['strreportdropped']); + else + $this->default_action($this->lang['strreportdroppedbad']); + } + + $misc->printFooter(); + } + + function execute() { + global $misc, $lang, $data; + + $reportsdb = $this->get_reportsdb(); + + $report = $reportsdb->getReport($_REQUEST['report_id']); + + $_POST['query'] = $report->fields['report_sql']; + + include('./sql.php'); + } + + /** + * Show default list of reports in the database + */ + function default_action($msg = '') { + global $data, $misc, $lang; + + $reportsdb = $this->get_reportsdb(); + + $misc->printHeader($this->lang['strreports']); + $misc->printBody(); + $misc->printTrail('server'); + $misc->printTabs('server', 'report_plugin'); + $misc->printMsg($msg); + + $reports = $reportsdb->getReports(); + + $columns = array( + 'report' => array( + 'title' => $this->lang['strreport'], + 'field' => field('report_name'), + 'url' => "plugin.php?plugin={$this->name}&action=properties&{$misc->href}&", + 'vars' => array( + 'report_id' => 'report_id', + 'report' => 'report_name' + ), + ), + 'database' => array( + 'title' => $lang['strdatabase'], + 'field' => field('db_name'), + ), + 'created' => array( + 'title' => $lang['strcreated'], + 'field' => field('date_created'), + ), + 'paginate' => array( + 'title' => $lang['strpaginate'], + 'field' => field('paginate'), + 'type' => 'yesno', + ), + 'actions' => array( + 'title' => $lang['stractions'], + ), + 'comment' => array( + 'title' => $lang['strcomment'], + 'field' => field('descr'), + ), + ); + + //$return_url = urlencode("plugin.php?plugin={$this->name}&{$misc->href}"); + $urlvars = $misc->getRequestVars(); + + $actions = array( + 'run' => array ( + 'content' => $lang['strexecute'], + 'attr'=> array ( + 'href' => array ( + 'url' => 'plugin.php', + 'urlvars' => array_merge($urlvars, array ( + 'plugin' => $this->name, + 'action' => 'execute', + 'report' => field('report_name'), + 'database' => field('db_name'), + 'report_id' => field('report_id'), + 'paginate' => field('paginate'), + 'nohistory' => 't', + 'return' => 'plugin', + 'back' => 'default_action' + )) + ) + ) + ), + 'edit' => array ( + 'content' => $lang['stredit'], + 'attr'=> array ( + 'href' => array ( + 'url' => 'plugin.php', + 'urlvars' => array_merge($urlvars, array ( + 'plugin' => $this->name, + 'action' => 'edit', + 'report_id' => field('report_id'), + )) + ) + ) + ), + 'drop' => array( + 'content' => $lang['strdrop'], + 'attr'=> array ( + 'href' => array ( + 'url' => 'plugin.php', + 'urlvars' => array_merge($urlvars, array ( + 'plugin' => $this->name, + 'action' => 'drop', + 'confirm' => 'true', + 'report_id' => field('report_id'), + )) + ) + ) + ), + ); + + $misc->printTable($reports, $columns, $actions, 'reports-reports', $this->lang['strnoreports']); + + $navlinks = array ( + array ( + 'attr'=> array ( + 'href' => array ( + 'url' => 'plugin.php', + 'urlvars' => array ( + 'plugin' => $this->name, + 'server' => field('server'), + 'action' => 'create') + ) + ), + 'content' => $this->lang['strcreatereport'] + ) + ); + $misc->printNavLinks($navlinks, 'reports-reports'); + $misc->printFooter(); + } +} +?> diff --git a/plugins/Report/sql/reports-pgsql.sql b/plugins/Report/sql/reports-pgsql.sql new file mode 100644 index 00000000..1272a762 --- /dev/null +++ b/plugins/Report/sql/reports-pgsql.sql @@ -0,0 +1,27 @@ +-- SQL script to create reports database for PostgreSQL +-- +-- To run, type: psql template1 < reports-pgsql.sql +-- +-- $Id: reports-pgsql.sql,v 1.4 2007/04/16 11:02:36 mr-russ Exp $ + +CREATE DATABASE phppgadmin; + +\connect phppgadmin + +CREATE TABLE ppa_reports ( + report_id SERIAL, + report_name varchar(255) NOT NULL, + db_name varchar(255) NOT NULL, + date_created date DEFAULT NOW() NOT NULL, + created_by varchar(255) NOT NULL, + descr text, + report_sql text NOT NULL, + paginate boolean NOT NULL, + PRIMARY KEY (report_id) +); + +-- Allow everyone to do everything with reports. This may +-- or may not be what you want. +GRANT SELECT,INSERT,UPDATE,DELETE ON ppa_reports TO PUBLIC; +GRANT SELECT,UPDATE ON ppa_reports_report_id_seq TO PUBLIC; + -- 2.39.5