Merge branch 'MDL-38821_master' of git://github.com/dmonllao/moodle
[moodle.git] / course / index.php
blob5b3cbd21b0a1ab6c6af740c992243bd6e387b458
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Lists the course categories
21 * @copyright 1999 Martin Dougiamas http://dougiamas.com
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @package course
26 require_once("../config.php");
27 require_once("lib.php");
29 $site = get_site();
31 $systemcontext = context_system::instance();
33 $PAGE->set_url('/course/index.php');
34 $PAGE->set_context($systemcontext);
35 $PAGE->set_pagelayout('admin');
37 if ($CFG->forcelogin) {
38 require_login();
41 $countcategories = $DB->count_records('course_categories');
42 if (can_edit_in_category()) {
43 $managebutton = $OUTPUT->single_button(new moodle_url('/course/manage.php'),
44 get_string('managecourses'), 'get');
47 $showaddcoursebutton = true;
48 if ($countcategories > 1 || ($countcategories == 1 && $DB->count_records('course') > 200)) {
49 $strcategories = get_string('categories');
51 $PAGE->set_title("$site->shortname: $strcategories");
52 $PAGE->set_heading($COURSE->fullname);
53 if (isset($managebutton)) {
54 $PAGE->set_button($managebutton);
56 echo $OUTPUT->header();
57 echo $OUTPUT->heading($strcategories);
58 echo $OUTPUT->skip_link_target();
59 echo $OUTPUT->box_start('categorybox');
60 print_whole_category_list();
61 echo $OUTPUT->box_end();
62 print_course_search();
63 } else {
64 $strfulllistofcourses = get_string('fulllistofcourses');
66 $PAGE->set_title("$site->shortname: $strfulllistofcourses");
67 $PAGE->set_heading($COURSE->fullname);
68 if (isset($managebutton)) {
69 $PAGE->set_button($managebutton);
71 echo $OUTPUT->header();
72 echo $OUTPUT->skip_link_target();
73 echo $OUTPUT->box_start('courseboxes');
74 $showaddcoursebutton = print_courses(0);
75 echo $OUTPUT->box_end();
78 echo $OUTPUT->container_start('buttons');
79 if (has_capability('moodle/course:create', $systemcontext) && $showaddcoursebutton) {
80 // Print link to create a new course, for the 1st available category.
81 $options = array('category' => $CFG->defaultrequestcategory, 'returnto' => 'topcat');
82 echo $OUTPUT->single_button(new moodle_url('edit.php', $options), get_string('addnewcourse'), 'get');
84 print_course_request_buttons($systemcontext);
85 echo $OUTPUT->container_end();
86 echo $OUTPUT->footer();