summaryrefslogtreecommitdiff
path: root/sqlbox/view.php
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-23 10:03:32 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-23 10:03:32 +0100
commit93934b0ef0cac682681764050f485e8231838b30 (patch)
tree1b15c018e9460736d2eeaae8193a57583528f628 /sqlbox/view.php
parentcb68bde9de9060e369103a3e5a8d217ed4104b8e (diff)
parent1e7e0ed272a3fa984241314dc01a871d3fa03c35 (diff)
downloadsqltutor-plugin-93934b0ef0cac682681764050f485e8231838b30.tar.gz
sqltutor-plugin-93934b0ef0cac682681764050f485e8231838b30.tar.bz2
sqltutor-plugin-93934b0ef0cac682681764050f485e8231838b30.zip
Merge branch 'master' of ssh://git.bnfr.net/git/sqltutor-plugin
Diffstat (limited to 'sqlbox/view.php')
-rw-r--r--sqlbox/view.php29
1 files changed, 28 insertions, 1 deletions
diff --git a/sqlbox/view.php b/sqlbox/view.php
index a82e9c8..5f0e4a0 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
@@ -72,7 +73,33 @@ 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();
+$data = $form->get_data();
+
+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->sqlbox_query);
+ if (!$result)
+ error("Query failed: ".pg_last_error($db));
+
+ $table = new html_table;
+ $n = pg_num_fields($result);
+ 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);
+}
// Finish the page
echo $OUTPUT->footer();