weekly release 2.6dev
[moodle.git] / course / search.php
CommitLineData
aa6c1ced 1<?php
f520dcd9
SH
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Displays external information about a course
19 * @package core
20 * @category course
21 * @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25require_once("../config.php");
26require_once($CFG->dirroot.'/course/lib.php');
4e0b6025 27require_once($CFG->libdir.'/coursecatlib.php');
f520dcd9
SH
28
29$search = optional_param('search', '', PARAM_RAW); // search words
30$page = optional_param('page', 0, PARAM_INT); // which page to show
837d548e 31$perpage = optional_param('perpage', '', PARAM_RAW); // how many per page, may be integer or 'all'
f520dcd9
SH
32$blocklist = optional_param('blocklist', 0, PARAM_INT);
33$modulelist= optional_param('modulelist', '', PARAM_PLUGIN);
9e76429d 34$tagid = optional_param('tagid', '', PARAM_INT); // searches for courses tagged with this tag id
f520dcd9
SH
35
36// List of minimum capabilities which user need to have for editing/moving course
37$capabilities = array('moodle/course:create', 'moodle/category:manage');
38
4e0b6025
MG
39// Populate usercatlist with list of category id's with course:create and category:manage capabilities.
40$usercatlist = coursecat::make_categories_list($capabilities);
f520dcd9
SH
41
42$search = trim(strip_tags($search)); // trim & clean raw searched string
a8b56716 43
f520dcd9 44$site = get_site();
38a10939 45
837d548e 46$searchcriteria = array();
9e76429d 47foreach (array('search', 'blocklist', 'modulelist', 'tagid') as $param) {
f520dcd9 48 if (!empty($$param)) {
837d548e 49 $searchcriteria[$param] = $$param;
680a65a0 50 }
f520dcd9 51}
837d548e
MG
52$urlparams = array();
53if ($perpage !== 'all' && !($perpage = (int)$perpage)) {
54 // default number of courses per page
55 $perpage = $CFG->coursesperpage;
56} else {
f520dcd9
SH
57 $urlparams['perpage'] = $perpage;
58}
837d548e
MG
59if (!empty($page)) {
60 $urlparams['page'] = $page;
61}
62$PAGE->set_url('/course/search.php', $searchcriteria + $urlparams);
f520dcd9
SH
63$PAGE->set_context(context_system::instance());
64$PAGE->set_pagelayout('standard');
f4b571ab 65$courserenderer = $PAGE->get_renderer('core', 'course');
f520dcd9
SH
66
67if ($CFG->forcelogin) {
68 require_login();
69}
70
f520dcd9
SH
71$strcourses = new lang_string("courses");
72$strsearch = new lang_string("search");
73$strsearchresults = new lang_string("searchresults");
f520dcd9
SH
74$strnovalidcourses = new lang_string('novalidcourses');
75
f520dcd9
SH
76$PAGE->navbar->add($strcourses, new moodle_url('/course/index.php'));
77$PAGE->navbar->add($strsearch, new moodle_url('/course/search.php'));
78if (!empty($search)) {
79 $PAGE->navbar->add(s($search));
80}
cf5b731c 81
60047003
MG
82if (empty($searchcriteria)) {
83 // no search criteria specified, print page with just search form
84 $PAGE->set_title("$site->fullname : $strsearch");
f520dcd9 85} else {
60047003
MG
86 // this is search results page
87 $PAGE->set_title("$site->fullname : $strsearchresults");
88 // Link to manage search results should be visible if user have system or category level capability
89 if ((can_edit_in_category() || !empty($usercatlist))) {
90 $aurl = new moodle_url('/course/manage.php', $searchcriteria);
91 $searchform = $OUTPUT->single_button($aurl, get_string('managecourses'), 'get');
92 } else {
93 $searchform = $courserenderer->course_search_form($search, 'navbar');
f520dcd9 94 }
60047003 95 $PAGE->set_button($searchform);
f520dcd9
SH
96}
97
60047003 98$PAGE->set_heading($site->fullname);
f520dcd9 99
60047003
MG
100echo $OUTPUT->header();
101echo $courserenderer->search_courses($searchcriteria);
f520dcd9 102echo $OUTPUT->footer();