From 0db7c312a512a665f343a83cee7aef603551da84 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Tue, 20 Nov 2012 13:51:52 +0100 Subject: sqlbox: Set version to 1 Needs to be different to 0, or the module will not be installed. --- sqlbox/version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlbox/version.php b/sqlbox/version.php index 6d83433..d436b9c 100644 --- a/sqlbox/version.php +++ b/sqlbox/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$module->version = 0; // If version == 0 then module will not be installed +$module->version = 1; // If version == 0 then module will not be installed //$module->version = 2010032200; // The current module version (Date: YYYYMMDDXX) $module->requires = 2010031900; // Requires this Moodle version $module->cron = 0; // Period for cron to check this module (secs) -- cgit From 9d50e1da6601bee2582f76ad850eaba0d5d0b9c0 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Tue, 20 Nov 2012 15:16:44 +0100 Subject: Add input box for sql string. --- sqlbox/view.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sqlbox/view.php b/sqlbox/view.php index a82e9c8..4580f16 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -74,5 +74,12 @@ if ($sqlbox->intro) { // Conditions to show the intro can change to look for own // Replace the following lines with you own code echo $OUTPUT->heading('Yay! It works!'); +$form = < + +EOF; + +echo $OUTPUT->heading($form); + // Finish the page echo $OUTPUT->footer(); -- cgit From 13acd7742a9287249c1f0de15435e663f9c8cc28 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Tue, 20 Nov 2012 15:20:44 +0100 Subject: Fix multiline string. --- sqlbox/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlbox/view.php b/sqlbox/view.php index 4580f16..e2330e1 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -74,7 +74,7 @@ if ($sqlbox->intro) { // Conditions to show the intro can change to look for own // Replace the following lines with you own code echo $OUTPUT->heading('Yay! It works!'); -$form = < EOF; -- cgit From db77666426e101c2bb374947af6193570b564e10 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Tue, 20 Nov 2012 20:27:07 +0100 Subject: sqlbox: Add a simple form using formslib --- sqlbox/sqlbox_form.php | 18 ++++++++++++++++++ sqlbox/view.php | 9 +++------ 2 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 sqlbox/sqlbox_form.php diff --git a/sqlbox/sqlbox_form.php b/sqlbox/sqlbox_form.php new file mode 100644 index 0000000..6569595 --- /dev/null +++ b/sqlbox/sqlbox_form.php @@ -0,0 +1,18 @@ +libdir.'/formslib.php'); + +class mod_sqlbox_form extends moodleform { + + public function definition() { + $mform = $this->_form; + $mform->addElement('header', 'general', 'SQLBox'); + $mform->addElement('text', 'query', 'Query', 'size="50"'); + $mform->addElement('editor', 'query2', 'Query2'); + $mform->addElement('submit', 'button', 'Submit'); + } +} + +?> diff --git a/sqlbox/view.php b/sqlbox/view.php index e2330e1..96c3e36 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -31,6 +31,7 @@ require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); require_once(dirname(__FILE__).'/lib.php'); +require_once(dirname(__FILE__).'/sqlbox_form.php'); $id = optional_param('id', 0, PARAM_INT); // course_module ID, or $n = optional_param('n', 0, PARAM_INT); // sqlbox instance ID - it should be named as the first character of the module @@ -74,12 +75,8 @@ if ($sqlbox->intro) { // Conditions to show the intro can change to look for own // Replace the following lines with you own code echo $OUTPUT->heading('Yay! It works!'); -$form = << - -EOF; - -echo $OUTPUT->heading($form); +$form = new mod_sqlbox_form(NULL, array()); +$form->display(); // Finish the page echo $OUTPUT->footer(); -- cgit From 731c82ea796e95d6c717deaad4bd164dba65ad6f Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Wed, 21 Nov 2012 07:09:51 +0100 Subject: Add raw data output. --- sqlbox/view.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sqlbox/view.php b/sqlbox/view.php index 96c3e36..123c21f 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -78,5 +78,10 @@ echo $OUTPUT->heading('Yay! It works!'); $form = new mod_sqlbox_form(NULL, array()); $form->display(); +$data = $form->get_data(); + +if ($data) + print_r($data); + // Finish the page echo $OUTPUT->footer(); -- cgit From 597af18edf0c143d78797381226f28157a470617 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Wed, 21 Nov 2012 07:11:27 +0100 Subject: change data output for debug purpos. --- sqlbox/view.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/sqlbox/view.php b/sqlbox/view.php index 123c21f..426e1d9 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -78,10 +78,7 @@ echo $OUTPUT->heading('Yay! It works!'); $form = new mod_sqlbox_form(NULL, array()); $form->display(); -$data = $form->get_data(); - -if ($data) - print_r($data); +print_r($form->get_data()); // Finish the page echo $OUTPUT->footer(); -- cgit From 49cee88bd8b1696f49e732e08765e98cf93e3839 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 09:23:25 +0100 Subject: sqlbox_form: Use Reference of &this->_form --- sqlbox/sqlbox_form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlbox/sqlbox_form.php b/sqlbox/sqlbox_form.php index 6569595..be6e20d 100644 --- a/sqlbox/sqlbox_form.php +++ b/sqlbox/sqlbox_form.php @@ -7,7 +7,7 @@ require_once($CFG->libdir.'/formslib.php'); class mod_sqlbox_form extends moodleform { public function definition() { - $mform = $this->_form; + $mform = &$this->_form; $mform->addElement('header', 'general', 'SQLBox'); $mform->addElement('text', 'query', 'Query', 'size="50"'); $mform->addElement('editor', 'query2', 'Query2'); -- cgit From 4e71a612e6449cf022b948e0d1db4fa8e258281d Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 09:25:12 +0100 Subject: sqlbox/view: Pass page url to form --- sqlbox/view.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sqlbox/view.php b/sqlbox/view.php index 426e1d9..ee30811 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -75,9 +75,8 @@ if ($sqlbox->intro) { // Conditions to show the intro can change to look for own // Replace the following lines with you own code echo $OUTPUT->heading('Yay! It works!'); -$form = new mod_sqlbox_form(NULL, array()); +$form = new mod_sqlbox_form($PAGE->url->out(false)); $form->display(); - print_r($form->get_data()); // Finish the page -- cgit From f1234ad5c967e2fc3f18662d32362cdfc5a93495 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 10:49:44 +0100 Subject: wip --- sqlbox/view.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sqlbox/view.php b/sqlbox/view.php index ee30811..0f371b8 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -77,7 +77,24 @@ echo $OUTPUT->heading('Yay! It works!'); $form = new mod_sqlbox_form($PAGE->url->out(false)); $form->display(); -print_r($form->get_data()); +$data = $form->get_data(); + +echo $OUTPUT->heading('Query: '.$data->query); +if (isset($data->query)) { + $db = pg_connect("host=localhost dbname=sqlbox user=sqlbox password=foobar"); + if (!db) + error("Failed to connect to sqlbox db"); + + $result = pg_query($db, $data->query); + if (!$result) + error("Query failed!"); + + while($row=pg_fetch_row($result)){ + print_r($row); + echo "
\n"; + } +} + // Finish the page echo $OUTPUT->footer(); -- cgit From 4dd307bf59e4245bfe982f45b01e72f9dcd02136 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 11:02:29 +0100 Subject: sqlbox: Add support for issuing query to database --- sqlbox/view.php | 1 - 1 file changed, 1 deletion(-) diff --git a/sqlbox/view.php b/sqlbox/view.php index 0f371b8..b6d4f45 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -95,6 +95,5 @@ if (isset($data->query)) { } } - // Finish the page echo $OUTPUT->footer(); -- cgit From 934b840382d4593299216105a0d74064ecfaf3e2 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 11:02:53 +0100 Subject: sqlbox_form: Remove big editor --- sqlbox/sqlbox_form.php | 1 - 1 file changed, 1 deletion(-) diff --git a/sqlbox/sqlbox_form.php b/sqlbox/sqlbox_form.php index be6e20d..eb88b6f 100644 --- a/sqlbox/sqlbox_form.php +++ b/sqlbox/sqlbox_form.php @@ -10,7 +10,6 @@ class mod_sqlbox_form extends moodleform { $mform = &$this->_form; $mform->addElement('header', 'general', 'SQLBox'); $mform->addElement('text', 'query', 'Query', 'size="50"'); - $mform->addElement('editor', 'query2', 'Query2'); $mform->addElement('submit', 'button', 'Submit'); } } -- cgit From 93269a59dcc12a69969fdee366cc491fd8c4c35c Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 11:03:30 +0100 Subject: sqlbox: Remove "Yay! It works!" --- sqlbox/view.php | 1 - 1 file changed, 1 deletion(-) diff --git a/sqlbox/view.php b/sqlbox/view.php index b6d4f45..f15c5e4 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -73,7 +73,6 @@ if ($sqlbox->intro) { // Conditions to show the intro can change to look for own } // Replace the following lines with you own code -echo $OUTPUT->heading('Yay! It works!'); $form = new mod_sqlbox_form($PAGE->url->out(false)); $form->display(); -- cgit From 854159ddbf2c284118a83495e215a178f2bf39e9 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 11:48:17 +0100 Subject: sqlbox: s/Query/SQL Query/ --- sqlbox/sqlbox_form.php | 2 +- sqlbox/view.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlbox/sqlbox_form.php b/sqlbox/sqlbox_form.php index eb88b6f..c91888c 100644 --- a/sqlbox/sqlbox_form.php +++ b/sqlbox/sqlbox_form.php @@ -9,7 +9,7 @@ class mod_sqlbox_form extends moodleform { public function definition() { $mform = &$this->_form; $mform->addElement('header', 'general', 'SQLBox'); - $mform->addElement('text', 'query', 'Query', 'size="50"'); + $mform->addElement('text', 'query', 'SQL Query', 'size="50"'); $mform->addElement('submit', 'button', 'Submit'); } } diff --git a/sqlbox/view.php b/sqlbox/view.php index f15c5e4..e9e4ba6 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -78,7 +78,7 @@ $form = new mod_sqlbox_form($PAGE->url->out(false)); $form->display(); $data = $form->get_data(); -echo $OUTPUT->heading('Query: '.$data->query); +echo $OUTPUT->heading('SQL Query: '.$data->query); if (isset($data->query)) { $db = pg_connect("host=localhost dbname=sqlbox user=sqlbox password=foobar"); if (!db) -- cgit From a4d8c7f7b7670dd7ac2a8c09441b522ea4fa11a4 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Wed, 21 Nov 2012 11:58:37 +0100 Subject: Query output format as table. --- sqlbox/view.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sqlbox/view.php b/sqlbox/view.php index e9e4ba6..c6f99a1 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -88,10 +88,15 @@ if (isset($data->query)) { if (!$result) error("Query failed!"); + echo ""; while($row=pg_fetch_row($result)){ - print_r($row); - echo "
\n"; + echo ""; + foreach($row as $val) { + echo ""; + } + echo ""; } + echo "
$val
"; } // Finish the page -- cgit From 8143bfc345cd7ac03be51456588860d420f4fdd8 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Wed, 21 Nov 2012 11:59:39 +0100 Subject: Fix wrong td tag. --- sqlbox/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlbox/view.php b/sqlbox/view.php index c6f99a1..0091807 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -92,7 +92,7 @@ if (isset($data->query)) { while($row=pg_fetch_row($result)){ echo ""; foreach($row as $val) { - echo "$val"; + echo "$val"; } echo ""; } -- cgit From 04e6e490862db2c164526b3aede92c7e9d8eb316 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Wed, 21 Nov 2012 12:00:43 +0100 Subject: Add border to output table. --- sqlbox/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlbox/view.php b/sqlbox/view.php index 0091807..8cf6848 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -88,7 +88,7 @@ if (isset($data->query)) { if (!$result) error("Query failed!"); - echo ""; + echo "
"; while($row=pg_fetch_row($result)){ echo ""; foreach($row as $val) { -- cgit From ce4fa77b60ed3aad6dcd09dbd48fd7b119bc1261 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 12:04:06 +0100 Subject: sqlbox: Show query field names --- sqlbox/view.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sqlbox/view.php b/sqlbox/view.php index 8cf6848..dd20fb9 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -89,6 +89,10 @@ if (isset($data->query)) { error("Query failed!"); echo "
"; + $n = pg_num_fields($result); + for ($i = 0; $i < $n; $i++) { + echo ""; + } while($row=pg_fetch_row($result)){ echo ""; foreach($row as $val) { -- cgit From ac24b67ed58bf62a1140ee6dc7417b6a0a97ecc6 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 12:11:03 +0100 Subject: sqlbox: Close database connection --- sqlbox/view.php | 1 + 1 file changed, 1 insertion(+) diff --git a/sqlbox/view.php b/sqlbox/view.php index dd20fb9..316489a 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -101,6 +101,7 @@ if (isset($data->query)) { echo ""; } echo "
".pg_field_name($result, $i)."
"; + pg_close($db); } // Finish the page -- cgit From 199d95ae1f065a3a252af3d4aad9bc3d778aedd3 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Wed, 21 Nov 2012 12:22:02 +0100 Subject: Change output box border style. --- sqlbox/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlbox/view.php b/sqlbox/view.php index 316489a..b5d613e 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -88,7 +88,7 @@ if (isset($data->query)) { if (!$result) error("Query failed!"); - echo ""; + echo "
"; $n = pg_num_fields($result); for ($i = 0; $i < $n; $i++) { echo ""; -- cgit From e6d9384cfa1af9c69636b4bc6bf1108327ea3085 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 13:06:06 +0100 Subject: sqlbox: Add prefixes to form Or it clashes with moodle search box. --- sqlbox/sqlbox_form.php | 6 +++--- sqlbox/view.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sqlbox/sqlbox_form.php b/sqlbox/sqlbox_form.php index c91888c..946fad4 100644 --- a/sqlbox/sqlbox_form.php +++ b/sqlbox/sqlbox_form.php @@ -8,9 +8,9 @@ class mod_sqlbox_form extends moodleform { public function definition() { $mform = &$this->_form; - $mform->addElement('header', 'general', 'SQLBox'); - $mform->addElement('text', 'query', 'SQL Query', 'size="50"'); - $mform->addElement('submit', 'button', 'Submit'); + $mform->addElement('header', 'sqlbox_general', 'SQLBox'); + $mform->addElement('text', 'sqlbox_query', 'SQL Query', 'size="50"'); + $mform->addElement('submit', 'sqlbox_button', 'Submit'); } } diff --git a/sqlbox/view.php b/sqlbox/view.php index b5d613e..1158d7b 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -78,13 +78,13 @@ $form = new mod_sqlbox_form($PAGE->url->out(false)); $form->display(); $data = $form->get_data(); -echo $OUTPUT->heading('SQL Query: '.$data->query); -if (isset($data->query)) { +echo $OUTPUT->heading('SQL Query: '.$data->sqlbox_query); +if (isset($data->sqlbox_query)) { $db = pg_connect("host=localhost dbname=sqlbox user=sqlbox password=foobar"); if (!db) error("Failed to connect to sqlbox db"); - $result = pg_query($db, $data->query); + $result = pg_query($db, $data->sqlbox_query); if (!$result) error("Query failed!"); -- cgit From 0b3e94f02d5c4cfcfb93a90896881652eceafc55 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Wed, 21 Nov 2012 13:34:09 +0100 Subject: Add additional error string from database. --- sqlbox/view.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sqlbox/view.php b/sqlbox/view.php index 1158d7b..d334835 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -84,7 +84,10 @@ if (isset($data->sqlbox_query)) { if (!db) error("Failed to connect to sqlbox db"); - $result = pg_query($db, $data->sqlbox_query); +// $result = pg_query($db, $data->sqlbox_query); + $result = pg_send_query($db, $data->sqlbox_query); + $result = pg_get_result($db); + echo pg_result_error_field($result, PGSQL_DIAG_SQLSTATE); if (!$result) error("Query failed!"); -- cgit From b27fcb3087ecac1b61cff59d35bdab7c7d5ded09 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 14:54:59 +0100 Subject: Revert "Add additional error string from database." This reverts commit 0b3e94f02d5c4cfcfb93a90896881652eceafc55. --- sqlbox/view.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/sqlbox/view.php b/sqlbox/view.php index d334835..1158d7b 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -84,10 +84,7 @@ if (isset($data->sqlbox_query)) { if (!db) error("Failed to connect to sqlbox db"); -// $result = pg_query($db, $data->sqlbox_query); - $result = pg_send_query($db, $data->sqlbox_query); - $result = pg_get_result($db); - echo pg_result_error_field($result, PGSQL_DIAG_SQLSTATE); + $result = pg_query($db, $data->sqlbox_query); if (!$result) error("Query failed!"); -- cgit From bbee0f79be6080ba589b043e68321c17dd295d65 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 21 Nov 2012 14:55:30 +0100 Subject: sqlbox: Display error message --- sqlbox/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlbox/view.php b/sqlbox/view.php index 1158d7b..b45924b 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -86,7 +86,7 @@ if (isset($data->sqlbox_query)) { $result = pg_query($db, $data->sqlbox_query); if (!$result) - error("Query failed!"); + error("Query failed: ".pg_last_error($db)); echo "
".pg_field_name($result, $i)."
"; $n = pg_num_fields($result); -- cgit From 215c5b14818dd4a6bb2e1f72a56902dbc7ce8143 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Thu, 22 Nov 2012 10:54:14 +0100 Subject: sqlbox/index.php: Initialize $table as html_table --- sqlbox/index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/sqlbox/index.php b/sqlbox/index.php index b4c9456..b0942e0 100644 --- a/sqlbox/index.php +++ b/sqlbox/index.php @@ -51,6 +51,7 @@ if (! $sqlboxs = get_all_instances_in_course('sqlbox', $course)) { notice(get_string('nosqlboxs', 'sqlbox'), new moodle_url('/course/view.php', array('id' => $course->id))); } +$table = new html_table(); if ($course->format == 'weeks') { $table->head = array(get_string('week'), get_string('name')); $table->align = array('center', 'left'); -- cgit From 0a8ddd6c1d9e827496b2b2d6ef466ebe55fe7183 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Thu, 22 Nov 2012 11:15:58 +0100 Subject: sqlbox/index.php: Fix incorrect links to view.php --- sqlbox/index.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sqlbox/index.php b/sqlbox/index.php index b0942e0..591e3fe 100644 --- a/sqlbox/index.php +++ b/sqlbox/index.php @@ -45,6 +45,7 @@ $PAGE->set_title(format_string($course->fullname)); $PAGE->set_heading(format_string($course->fullname)); $PAGE->set_context($coursecontext); + echo $OUTPUT->header(); if (! $sqlboxs = get_all_instances_in_course('sqlbox', $course)) { @@ -66,12 +67,12 @@ if ($course->format == 'weeks') { foreach ($sqlboxs as $sqlbox) { if (!$sqlbox->visible) { $link = html_writer::link( - new moodle_url('/mod/sqlbox.php', array('id' => $sqlbox->coursemodule)), + new moodle_url('/mod/sqlbox/view.php', array('id' => $sqlbox->coursemodule)), format_string($sqlbox->name, true), array('class' => 'dimmed')); } else { $link = html_writer::link( - new moodle_url('/mod/sqlbox.php', array('id' => $sqlbox->coursemodule)), + new moodle_url('/mod/sqlbox/view.php', array('id' => $sqlbox->coursemodule)), format_string($sqlbox->name, true)); } -- cgit From 2a14d4ae5af7dd2b08e7a16b155d45cebd3ca763 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Thu, 22 Nov 2012 12:07:35 +0100 Subject: sqlbox: User html_output::table to show query result ..instead of own table code. --- sqlbox/view.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/sqlbox/view.php b/sqlbox/view.php index b45924b..2169ab0 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -88,19 +88,16 @@ if (isset($data->sqlbox_query)) { if (!$result) error("Query failed: ".pg_last_error($db)); - echo "
"; + $table = new html_table(); $n = pg_num_fields($result); - for ($i = 0; $i < $n; $i++) { - echo ""; - } - while($row=pg_fetch_row($result)){ - echo ""; - foreach($row as $val) { - echo ""; - } - echo ""; - } - echo "
".pg_field_name($result, $i)."
$val
"; + for ($i = 0; $i < $n; $i++) + $table->head[] = pg_field_name($result, $i); + $table->align = array_fill(0, $n, 'left'); + while ($row = pg_fetch_row($result)) + $table->data[] = $row; + + echo html_writer::table($table); + pg_close($db); } -- cgit From acd0d17d577081af76709a440e368f41bfb28b48 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Thu, 22 Nov 2012 12:33:25 +0100 Subject: sqlbox: Fix plural name --- sqlbox/lang/en/sqlbox.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlbox/lang/en/sqlbox.php b/sqlbox/lang/en/sqlbox.php index 802589a..da9c7a2 100644 --- a/sqlbox/lang/en/sqlbox.php +++ b/sqlbox/lang/en/sqlbox.php @@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die(); $string['modulename'] = 'sqlbox'; -$string['modulenameplural'] = 'sqlboxs'; +$string['modulenameplural'] = 'sqlboxes'; $string['modulename_help'] = 'Use the sqlbox module for... | The sqlbox module allows...'; $string['sqlboxfieldset'] = 'Custom example fieldset'; $string['sqlboxname'] = 'sqlbox name'; -- cgit From 1e7e0ed272a3fa984241314dc01a871d3fa03c35 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Thu, 22 Nov 2012 16:07:25 +0100 Subject: sqlbox: Remove unneeded brackets in class initialization --- sqlbox/index.php | 2 +- sqlbox/view.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlbox/index.php b/sqlbox/index.php index 591e3fe..eceb6b7 100644 --- a/sqlbox/index.php +++ b/sqlbox/index.php @@ -52,7 +52,7 @@ if (! $sqlboxs = get_all_instances_in_course('sqlbox', $course)) { notice(get_string('nosqlboxs', 'sqlbox'), new moodle_url('/course/view.php', array('id' => $course->id))); } -$table = new html_table(); +$table = new html_table; if ($course->format == 'weeks') { $table->head = array(get_string('week'), get_string('name')); $table->align = array('center', 'left'); diff --git a/sqlbox/view.php b/sqlbox/view.php index 2169ab0..5f0e4a0 100644 --- a/sqlbox/view.php +++ b/sqlbox/view.php @@ -88,7 +88,7 @@ if (isset($data->sqlbox_query)) { if (!$result) error("Query failed: ".pg_last_error($db)); - $table = new html_table(); + $table = new html_table; $n = pg_num_fields($result); for ($i = 0; $i < $n; $i++) $table->head[] = pg_field_name($result, $i); -- cgit