MDL-44079 Javascript: Check whether a dialogue is focused before closing
[moodle.git] / tag / coursetags_more.php
blob9b65813de1f5a72853ee461c2208c8ef1ff9c031
1 <?php
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.
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/>.
18 /**
19 * A full display of tags allowing some filtering and reordering
21 * @package core_tag
22 * @category tag
23 * @copyright 2007 j.beedell@open.ac.uk
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require_once('../config.php');
28 require_once($CFG->dirroot.'/tag/coursetagslib.php');
29 require_once($CFG->dirroot.'/tag/lib.php');
31 $sort = optional_param('sort', 'alpha', PARAM_ALPHA); //alpha, date or popularity
32 $show = optional_param('show', 'all', PARAM_ALPHA); //all, my, official, community or course
33 $courseid = optional_param('courseid', 0, PARAM_INT);
35 $url = new moodle_url('/tag/coursetags_more.php');
36 if ($sort !== 'alpha') {
37 $url->param('sort', $sort);
39 if ($show !== 'all') {
40 $url->param('show', $show);
42 if ($courseid !== 0) {
43 $url->param('courseid', $courseid);
45 $PAGE->set_url($url);
47 if (empty($CFG->usetags)) {
48 print_error('tagsaredisabled', 'tag');
51 // Some things require logging in
52 if ($CFG->forcelogin or $show == 'my') {
53 require_login();
56 // Permissions
57 $loggedin = isloggedin() && !isguestuser();
59 // Course check
60 if ($courseid) {
61 if (!($course = $DB->get_record('course', array('id'=>$courseid)))) {
62 $courseid = 0;
64 if ($courseid == SITEID) $courseid = 0;
67 if ($courseid) {
68 $PAGE->set_context(context_course::instance($courseid));
69 } else {
70 $PAGE->set_context(context_system::instance());
73 // Language strings
74 $tagslang = 'block_tags';
75 $title = get_string('moretitle', $tagslang);
76 $link1 = get_string('moreshow', $tagslang);
77 $link2 = get_string('moreorder', $tagslang);
78 $showalltags = get_string('moreshowalltags', $tagslang);
79 $showofficialtags = get_string('moreshowofficialtags', $tagslang);
80 $showmytags = get_string('moreshowmytags', $tagslang);
81 $showcommtags = get_string('moreshowcommtags', $tagslang);
82 $orderalpha = get_string('moreorderalpha', $tagslang);
83 $orderdate = get_string('moreorderdate', $tagslang);
84 $orderpop = get_string('moreorderpop', $tagslang);
85 $welcome = get_string('morewelcome', $tagslang);
87 // The title and breadcrumb
88 if ($courseid) {
89 $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($courseid)));
90 $PAGE->navbar->add($courseshortname, new moodle_url('/course/view.php', array('id'=>$courseid)));
92 $PAGE->navbar->add($title);
93 $PAGE->set_title($title);
94 $PAGE->set_heading($COURSE->fullname);
95 echo $OUTPUT->header();
96 echo $OUTPUT->heading($title, 2, 'centre');
98 // Prepare data for tags
99 $courselink = '';
100 if ($courseid) {
101 $courselink = '&amp;courseid='.$courseid;
103 $myurl = $CFG->wwwroot.'/tag/coursetags_more.php';
104 $myurl2 = $CFG->wwwroot.'/tag/coursetags_more.php?show='.$show;
106 if ($show == 'course' and $courseid) { // Course tags.
107 $tags = tag_print_cloud(coursetag_get_tags($courseid, 0, ''), 150, true, $sort);
108 } else if ($show == 'my' and $loggedin) { // My tags.
109 $tags = tag_print_cloud(coursetag_get_tags(0, $USER->id, 'default'), 150, true, $sort);
110 } else if ($show == 'official') { // Official course tags.
111 $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'official'), 150, true, $sort);
112 } else if ($show == 'community') { // Community (official and personal together) also called user tags.
113 $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'default'), 150, true, $sort);
114 } else {
115 // All tags for courses and blogs and any thing else tagged - the fallback default ($show == all).
116 $subtitle = $showalltags;
117 $tags = tag_print_cloud(coursetag_get_all_tags(), 150, true, $sort);
120 // Prepare the links for the show and order lines
121 if ($show == 'all') {
122 $link1 .= '<b>'.$showalltags.'</b>';
123 } else {
124 $link1 .= '<a href="'.$myurl.'?show=all'.$courselink.'">'.$showalltags.'</a>';
126 //if ($show == 'official') { //add back in if you start to use official course tags
127 // $link1 .= ' | <b>'.$showofficialtags.'</b>';
128 //} else {
129 // $link1 .= ' | <a href="'.$myurl.'?show=official'.$courselink.'">'.$showofficialtags.'</a>';
131 if ($show == 'community') {
132 $link1 .= ' | <b>'.$showcommtags.'</b>';
133 } else {
134 $link1 .= ' | <a href="'.$myurl.'?show=community'.$courselink.'">'.$showcommtags.'</a>';
136 if ($loggedin) {
137 if ($show == 'my') {
138 $link1 .= ' | <b>'.$showmytags.'</b>';
139 } else {
140 $link1 .= ' | <a href="'.$myurl.'?show=my'.$courselink.'">'.$showmytags.'</a>';
143 if ($courseid) {
144 $fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
145 if ($show == 'course') {
146 $link1 .= ' | <b>'.get_string('moreshowcoursetags', $tagslang, $fullname).'</b>';
147 } else {
148 $link1 .= ' | <a href="'.$myurl.'?show=course'.$courselink.'">'.get_string('moreshowcoursetags', $tagslang, $fullname).'</a>';
151 if ($sort == 'alpha') {
152 $link2 .= '<b>'.$orderalpha.'</b> | ';
153 } else {
154 $link2 .= '<a href="'.$myurl2.'&amp;sort=alpha'.$courselink.'">'.$orderalpha.'</a> | ';
156 if ($sort == 'popularity') {
157 $link2 .= '<b>'.$orderpop.'</b> | ';
158 } else {
159 $link2 .= '<a href="'.$myurl2.'&amp;sort=popularity'.$courselink.'">'.$orderpop.'</a> | ';
161 if ($sort == 'date') {
162 $link2 .= '<b>'.$orderdate.'</b>';
163 } else {
164 $link2 .= '<a href="'.$myurl2.'&amp;sort=date'.$courselink.'">'.$orderdate.'</a>';
167 // Prepare output
168 $fclass = '';
169 // make the tags larger when there are not so many
170 if (strlen($tags) < 10000) {
171 $fclass = 'coursetag_more_large';
173 $outstr = '
174 <div class="coursetag_more_title">
175 <div style="padding-bottom:5px">'.$welcome.'</div>
176 <div class="coursetag_more_link">'.$link1.'</div>
177 <div class="coursetag_more_link">'.$link2.'</div>
178 </div>
179 <div class="coursetag_more_tags '.$fclass.'">'.
180 $tags.'
181 </div>';
182 echo $outstr;
184 echo $OUTPUT->footer();