diff --git a/classes/local/form/form_backups_filter.php b/classes/local/form/form_backups_filter.php
new file mode 100644
index 0000000000000000000000000000000000000000..9abbe6c04f5fbf7b20a6d1614941b62a95ec4aca
--- /dev/null
+++ b/classes/local/form/form_backups_filter.php
@@ -0,0 +1,54 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * A moodle form for filtering the course backups table
+ *
+ * @package tool_lifecycle
+ * @copyright 2021 Justus Dieckmann WWU
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+namespace tool_lifecycle\local\form;
+
+defined('MOODLE_INTERNAL') || die();
+
+require_once($CFG->libdir . '/formslib.php');
+
+/**
+ * A moodle form for filtering the course backups table
+ *
+ * @package tool_lifecycle
+ * @copyright 2021 Justus Dieckmann WWU
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class form_backups_filter extends \moodleform {
+
+ /**
+ * Defines forms elements
+ */
+ public function definition() {
+ $mform = $this->_form;
+
+ $mform->addElement('text', 'shortname', get_string('shortname'));
+ $mform->setType('shortname', PARAM_TEXT);
+
+ $mform->addElement('text', 'fullname', get_string('fullname'));
+ $mform->setType('fullname', PARAM_TEXT);
+
+ $this->add_action_buttons(true, get_string('apply', 'tool_lifecycle'));
+ }
+
+}
diff --git a/classes/local/table/course_backups_table.php b/classes/local/table/course_backups_table.php
index 6220a5f99daa73f4c3ee0b5dbd584315c78a16b4..6b65441bccda2cb84e23c74bbf9b9710b73daaae 100644
--- a/classes/local/table/course_backups_table.php
+++ b/classes/local/table/course_backups_table.php
@@ -39,14 +39,31 @@ class course_backups_table extends \table_sql {
/**
* Constructor for course_backups_table.
* @param int $uniqueid Unique id of this table.
+ * @param \stdClass|null $filterdata
*/
- public function __construct($uniqueid) {
+ public function __construct($uniqueid, $filterdata) {
parent::__construct($uniqueid);
- global $PAGE;
+ global $PAGE, $DB;
$this->set_attribute('class', $this->attributes['class'] . ' ' . $uniqueid);
+
+ $where = ['TRUE'];
+ $params = [];
+
+ if ($filterdata) {
+ if ($filterdata && $filterdata->shortname) {
+ $where[] = $DB->sql_like('b.shortname', ':shortname', false, false);
+ $params['shortname'] = '%' . $DB->sql_like_escape($filterdata->shortname) . '%';
+ }
+
+ if ($filterdata && $filterdata->fullname) {
+ $where[] = $DB->sql_like('b.fullname', ':fullname', false, false);
+ $params['fullname'] = '%' . $DB->sql_like_escape($filterdata->fullname) . '%';
+ }
+ }
+
$this->set_sql('b.id, b.courseid, b.shortname as courseshortname, b.fullname as coursefullname, b.backupcreated',
'{tool_lifecycle_backups} b',
- "TRUE");
+ join(" AND ", $where), $params);
$this->no_sorting('download');
$this->no_sorting('restore');
$this->define_baseurl($PAGE->url);
diff --git a/coursebackups.php b/coursebackups.php
index 0b157191b675a041a60c5878df052d2936fe827f..b0a44a1c5fcba01b4931062bb193af9494b0152a 100644
--- a/coursebackups.php
+++ b/coursebackups.php
@@ -32,7 +32,23 @@ admin_externalpage_setup('tool_lifecycle_coursebackups');
$PAGE->set_url(new \moodle_url('/admin/tool/lifecycle/coursebackups.php'));
-$table = new tool_lifecycle\local\table\course_backups_table('tool_lifecycle_course_backups');
+$mform = new \tool_lifecycle\local\form\form_backups_filter();
+
+// Cache handling.
+$cache = cache::make('tool_lifecycle', 'mformdata');
+if ($mform->is_cancelled()) {
+ $cache->delete('coursebackups_filter');
+ redirect($PAGE->url);
+} else if ($data = $mform->get_data()) {
+ $cache->set('coursebackups_filter', $data);
+} else {
+ $data = $cache->get('coursebackups_filter');
+ if ($data) {
+ $mform->set_data($data);
+ }
+}
+
+$table = new tool_lifecycle\local\table\course_backups_table('tool_lifecycle_course_backups', $data);
$PAGE->set_title(get_string('course_backups_list_header', 'tool_lifecycle'));
$PAGE->set_heading(get_string('course_backups_list_header', 'tool_lifecycle'));
@@ -40,6 +56,13 @@ $PAGE->set_heading(get_string('course_backups_list_header', 'tool_lifecycle'));
$renderer = $PAGE->get_renderer('tool_lifecycle');
echo $renderer->header();
+
+echo '<br>';
+
+$mform->display();
+
+echo '<br>';
+
$table->out(50, false);
echo $renderer->footer();