diff --git a/db/upgrade.php b/db/upgrade.php
index 762a9be9..2a51ab6c 100644
--- a/db/upgrade.php
+++ b/db/upgrade.php
@@ -151,5 +151,18 @@ function xmldb_block_configurable_reports_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2019062001, 'block', 'configurable_reports');
}
+ if ($oldversion < 2024051300) {
+ $table = new xmldb_table('block_configurable_reports');
+ $field = new xmldb_field('displaytotalrecords', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '1', null);
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+ $field = new xmldb_field('displayprintbutton', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '1', null);
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+ upgrade_plugin_savepoint(true, 2024051300, 'block', 'configurable_reports');
+ }
+
return true;
}
diff --git a/editreport.php b/editreport.php
index decd5caa..cab94e73 100755
--- a/editreport.php
+++ b/editreport.php
@@ -215,6 +215,14 @@
$data->cron = 0;
}
+ if (!isset($data->displaytotalrecords)) {
+ $data->displaytotalrecords = 0;
+ }
+
+ if (!isset($data->displayprintbutton)) {
+ $data->displayprintbutton = 0;
+ }
+
if (empty($report)) {
$data->ownerid = $USER->id;
$data->courseid = $courseid;
diff --git a/editreport_form.php b/editreport_form.php
index a4039421..26ff0685 100644
--- a/editreport_form.php
+++ b/editreport_form.php
@@ -97,12 +97,10 @@ public function definition(): void {
$mform->addHelpButton('jsordering', 'jsordering', 'block_configurable_reports');
$mform->setDefault('jsordering', 1);
- $mform->addElement(
- 'checkbox',
- 'cron',
- get_string('cron', 'block_configurable_reports'),
- get_string('crondescription', 'block_configurable_reports')
- );
+ $mform->addElement('checkbox', 'displaytotalrecords', get_string('displaytotalrecords', 'block_configurable_reports'), get_string('displaytotalrecordsdescription', 'block_configurable_reports'));
+ $mform->addElement('checkbox', 'displayprintbutton', get_string('displayprintbutton', 'block_configurable_reports'), get_string('displayprintbuttondescription', 'block_configurable_reports'));
+
+ $mform->addElement('checkbox', 'cron', get_string('cron', 'block_configurable_reports'), get_string('crondescription', 'block_configurable_reports'));
$mform->addHelpButton('cron', 'cron', 'block_configurable_reports');
$mform->setDefault('cron', 0);
$mform->disabledIf('cron', 'type', 'neq', 'sql');
@@ -116,6 +114,24 @@ public function definition(): void {
$mform->addHelpButton('remote', 'remote', 'block_configurable_reports');
$mform->setDefault('remote', 0);
+ // Adds an embed link for easy copy/paste once the report is saved.
+ if (isset($this->_customdata['report']->id) && $this->_customdata['report']->id) {
+
+ $params = [
+ 'id' => $this->_customdata['report']->id,
+ 'courseid' => $this->_customdata['courseid'],
+ 'embed' => true
+ ];
+ $url = new \moodle_url('/blocks/configurable_reports/viewreport.php', $params);
+
+ $mform->addElement('static', 'embedlink',
+ get_string('embedlink', 'block_configurable_reports'),
+ html_writer::tag('pre', $url, ['class' => 'mb-0']).
+ get_string('embedlinkdescription', 'block_configurable_reports')
+ );
+ }
+
+
$mform->addElement('header', 'exportoptions', get_string('exportoptions', 'block_configurable_reports'));
$options = cr_get_export_plugins();
@@ -140,8 +156,14 @@ public function definition(): void {
$mform->setType('courseid', PARAM_INT);
}
+ // Submit button string.
+ $submitstring = get_string('add');
+ if (!empty($this->_customdata['report']->id)) {
+ $submitstring = get_string('update');
+ }
+
// Buttons.
- $this->add_action_buttons(true, get_string('add'));
+ $this->add_action_buttons(true, $submitstring);
}
/**
diff --git a/lang/en/block_configurable_reports.php b/lang/en/block_configurable_reports.php
index 1927f9b0..4f0d9975 100644
--- a/lang/en/block_configurable_reports.php
+++ b/lang/en/block_configurable_reports.php
@@ -61,6 +61,7 @@
$string['configurable_reports:viewreports'] = "View reports";
$string['exportoptions'] = "Export options";
+$string['embedoptions'] = "Embed options";
$string['field'] = "Field";
// Report form.
@@ -77,6 +78,12 @@
$string['jsordering'] = 'JavaScript Ordering';
$string['cron'] = 'Auto run daily';
$string['crondescription'] = 'Schedule this query to run each day (At night)';
+$string['displaytotalrecords'] = 'Total Records';
+$string['displaytotalrecordsdescription'] = 'Displays the total number of results in the report';
+$string['displayprintbutton'] = 'Print Button';
+$string['displayprintbuttondescription'] = 'Displays the print button at the bottom of the report';
+$string['embedlink'] = 'Embed Link';
+$string['embedlinkdescription'] = 'You can copy this link to embed the report in an HTML block';
$string['cron_help'] = 'Schedule this query to run each day (At night)';
$string['remote'] = 'Run on remote db';
$string['remotedescription'] = 'Do you want to run this query on the remote db';
diff --git a/report.class.php b/report.class.php
index e15232dd..2cc9c4c4 100755
--- a/report.class.php
+++ b/report.class.php
@@ -863,9 +863,11 @@ public function print_template($config, moodle_page $moodlepage): void {
echo format_text($pagecontents['header'], FORMAT_HTML);
}
- $a = new stdClass();
- $a->totalrecords = $this->totalrecords;
- echo html_writer::tag('div', get_string('totalrecords', 'block_configurable_reports', $a), ['id' => 'totalrecords']);
+ if ($this->config->displaytotalrecords) {
+ $a = new \stdClass();
+ $a->totalrecords = $this->totalrecords;
+ echo \html_writer::tag('div', get_string('totalrecords', 'block_configurable_reports', $a), array('id' => 'totalrecords'));
+ }
if ($recordtpl) {
if ($this->config->pagination) {
@@ -897,11 +899,12 @@ public function print_template($config, moodle_page $moodlepage): void {
}
echo "\n";
- echo '\n";
+ if ($this->config->displayprintbutton) {
+ echo '\n";
+ }
}
/**
@@ -913,7 +916,9 @@ public function print_template($config, moodle_page $moodlepage): void {
public function print_report_page(moodle_page $moodlepage) {
global $OUTPUT;
- cr_print_js_function();
+ if ($this->config->displayprintbutton) {
+ cr_print_js_function();
+ }
$components = cr_unserialize($this->config->components);
$template = (isset($components['template']['config']) && $components['template']['config']->enabled &&
@@ -1011,11 +1016,12 @@ public function print_report_page(moodle_page $moodlepage) {
echo '' . get_string('norecordsfound', 'block_configurable_reports') . '
';
}
- echo '\n";
+ if ($this->config->displayprintbutton) {
+ echo '\n";
+ }
}
/**
diff --git a/viewreport.php b/viewreport.php
index 06fd25d0..aca79fdb 100755
--- a/viewreport.php
+++ b/viewreport.php
@@ -30,6 +30,7 @@
$download = optional_param('download', false, PARAM_BOOL);
$format = optional_param('format', '', PARAM_ALPHA);
$courseid = optional_param('courseid', null, PARAM_INT);
+$embed = optional_param('embed', false, PARAM_BOOL);
if (!$report = $DB->get_record('block_configurable_reports', ['id' => $id])) {
throw new moodle_exception('reportdoesnotexists', 'block_configurable_reports');
@@ -100,9 +101,13 @@
$PAGE->set_title($reportname);
$PAGE->set_heading($reportname);
$PAGE->set_cacheable(true);
+ if ($embed) {
+ $PAGE->set_pagelayout('embedded');
+ }
echo $OUTPUT->header();
- if ($hasmanageallcap || ($hasmanageowncap && $report->ownerid == $USER->id)) {
+ $canmanage = ($hasmanageallcap || ($hasmanageowncap && $report->ownerid == $USER->id));
+ if (!$embed && $canmanage) {
$currenttab = 'viewreport';
include('tabs.php');
}