summaryrefslogtreecommitdiff
path: root/sqlbox
diff options
context:
space:
mode:
Diffstat (limited to 'sqlbox')
-rw-r--r--sqlbox/index.php6
-rw-r--r--sqlbox/lang/en/sqlbox.php2
-rw-r--r--sqlbox/sqlbox_form.php17
-rw-r--r--sqlbox/version.php2
-rw-r--r--sqlbox/view.php29
5 files changed, 51 insertions, 5 deletions
diff --git a/sqlbox/index.php b/sqlbox/index.php
index b4c9456..eceb6b7 100644
--- a/sqlbox/index.php
+++ b/sqlbox/index.php
@@ -45,12 +45,14 @@ $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)) {
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');
@@ -65,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));
}
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';
diff --git a/sqlbox/sqlbox_form.php b/sqlbox/sqlbox_form.php
new file mode 100644
index 0000000..946fad4
--- /dev/null
+++ b/sqlbox/sqlbox_form.php
@@ -0,0 +1,17 @@
+<?php
+
+defined('MOODLE_INTERNAL') || die();
+
+require_once($CFG->libdir.'/formslib.php');
+
+class mod_sqlbox_form extends moodleform {
+
+ public function definition() {
+ $mform = &$this->_form;
+ $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/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)
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();