tags MDLSITE-1000 Set a better page layout on the standard theme
[moodle.git] / tag / index.php
CommitLineData
6bfe7aac 1<?php
c933a060 2
000ebd5c
DM
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.
14//
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/>.
17
18/**
19 * @package core
20 * @subpackage tag
21 * @copyright 2007 Luiz Cruz <luiz.laydner@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
c933a060 25require_once('../config.php');
26require_once('lib.php');
48d56528 27require_once('locallib.php');
c933a060 28require_once($CFG->dirroot.'/lib/weblib.php');
8a275c72 29require_once($CFG->dirroot.'/blog/lib.php');
c933a060 30
31require_login();
32
33if (empty($CFG->usetags)) {
48d56528 34 print_error('tagsaredisabled', 'tag');
c933a060 35}
36
3d535996 37$tagid = optional_param('id', 0, PARAM_INT); // tag id
38fb8190 38$tagname = optional_param('tag', '', PARAM_TAG); // tag
8479c2e0 39
5557c75a 40$edit = optional_param('edit', -1, PARAM_BOOL);
3d535996 41$userpage = optional_param('userpage', 0, PARAM_INT); // which page to show
5557c75a 42$perpage = optional_param('perpage', 24, PARAM_INT);
c933a060 43
0edd6535 44$systemcontext = get_context_instance(CONTEXT_SYSTEM);
8479c2e0 45
46if ($tagname) {
47 $tag = tag_get('name', $tagname, '*');
48} else if ($tagid) {
49 $tag = tag_get('id', $tagid, '*');
50}
51
52if (empty($tag)) {
c933a060 53 redirect($CFG->wwwroot.'/tag/search.php');
54}
55
a6855934 56$PAGE->set_url('/tag/index.php', array('id' => $tag->id));
f8b80dbd 57$PAGE->set_subpage($tag->id);
0edd6535 58$PAGE->set_context($systemcontext);
8d873bdc 59$PAGE->set_pagelayout('standard');
cfcfb9f3 60$PAGE->set_blocks_editing_capability('moodle/tag:editblocks');
5557c75a 61
62if (($edit != -1) and $PAGE->user_allowed_editing()) {
63 $USER->editing = $edit;
64}
65
f8b80dbd 66$tagname = tag_display_name($tag);
f8b80dbd 67$title = get_string('tag', 'tag') .' - '. $tagname;
68
69$button = '';
70if ($PAGE->user_allowed_editing() ) {
cf132980 71 $button = $OUTPUT->edit_button(new moodle_url("$CFG->wwwroot/tag/index.php", array('id' => $tagid)));
f8b80dbd 72}
968583af 73
a6855934 74$PAGE->navbar->add(get_string('tags', 'tag'), new moodle_url('/tag/search.php'));
968583af 75$PAGE->navbar->add($tagname);
76$PAGE->set_title($title);
440e1f1a 77$PAGE->set_heading($COURSE->fullname);
968583af 78$PAGE->set_button($button);
79echo $OUTPUT->header();
5557c75a 80
03ce38cd 81// Manage all tags links
82if (has_capability('moodle/tag:manage', $systemcontext)) {
83 echo '<div class="managelink"><a href="'. $CFG->wwwroot .'/tag/manage.php">'. get_string('managetags', 'tag') .'</a></div>' ;
84}
85
5557c75a 86$tagname = tag_display_name($tag);
c933a060 87
c933a060 88if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
28f64040 89 $tagname = '<span class="flagged-tag">' . $tagname . '</span>';
c933a060 90}
91
73aec3a7 92echo $OUTPUT->heading($tagname, 2, 'headingblock header tag-heading');
3d535996 93tag_print_management_box($tag);
94tag_print_description_box($tag);
c933a060 95
90723839 96echo '<div class="relatedpages"><p><a href="#course">'.get_string('courses').
3caea5dc 97 '</a> | <a href="#blog">'.get_string('relatedblogs', 'tag').
98 '</a> | <a href="#user">'.get_string('users').'</a></p></div>';
99
38fb8190 100// Display courses tagged with the tag
101require_once($CFG->dirroot.'/tag/coursetagslib.php');
102if ($courses = coursetag_get_tagged_courses($tag->id)) {
c933a060 103
38fb8190 104 $totalcount = count( $courses );
456d32fd 105 echo $OUTPUT->box_start('generalbox', 'tag-blogs'); //could use an id separate from tag-blogs, but would have to copy the css style to make it look the same
6cbf4bd4 106
3caea5dc 107 $heading = get_string('courses') . ' ' . get_string('taggedwith', 'tag', $tagname) .': '. $totalcount;
108 echo "<a name='course'></a>";
73aec3a7 109 echo $OUTPUT->heading($heading, 3);
5557c75a 110
38fb8190 111 foreach ($courses as $course) {
112 print_course($course);
4454447d 113 }
c933a060 114
456d32fd 115 echo $OUTPUT->box_end();
c933a060 116}
c933a060 117
38fb8190 118// Print up to 10 previous blogs entries
1c7b8b93
NC
119if (has_capability('moodle/blog:view', $systemcontext)) {
120 require_once($CFG->dirroot.'/blog/lib.php');
121 require_once($CFG->dirroot.'/blog/locallib.php');
061f14b2 122
1c7b8b93
NC
123 $bloglisting = new blog_listing(array('tag' => $tag->id));
124 $limit = 10;
125 $start = 0;
b55d5f76 126
1c7b8b93 127 if ($blogs = $bloglisting->get_entries($start, $limit)) {
b55d5f76 128
456d32fd 129 echo $OUTPUT->box_start('generalbox', 'tag-blogs');
3caea5dc 130 $heading = get_string('relatedblogs', 'tag', $tagname). ' ' . get_string('taggedwith', 'tag', $tagname);
131 echo "<a name='blog'></a>";
73aec3a7 132 echo $OUTPUT->heading($heading, 3);
b55d5f76 133
134 echo '<ul id="tagblogentries">';
135 foreach ($blogs as $blog) {
136 if ($blog->publishstate == 'draft') {
137 $class = 'class="dimmed"';
138 } else {
139 $class = '';
140 }
141 echo '<li '.$class.'>';
1c7b8b93 142 echo '<a '.$class.' href="'.$CFG->wwwroot.'/blog/index.php?entryid='.$blog->id.'">';
b55d5f76 143 echo format_string($blog->subject);
144 echo '</a>';
38fb8190 145 echo ' - ';
b55d5f76 146 echo '<a '.$class.' href="'.$CFG->wwwroot.'/user/view.php?id='.$blog->userid.'">';
147 echo fullname($blog);
148 echo '</a>';
149 echo ', '. userdate($blog->lastmodified);
150 echo '</li>';
53bde3e1 151 }
b55d5f76 152 echo '</ul>';
5557c75a 153
a6855934 154 $allblogsurl = new moodle_url('/blog/index.php', array('tagid' => $tag->id));
1c7b8b93 155 echo '<p class="moreblogs"><a href="'.$allblogsurl->out().'">'.get_string('seeallblogs', 'tag', $tagname).'</a></p>';
44842cc6 156
456d32fd 157 echo $OUTPUT->box_end();
b55d5f76 158 }
061f14b2 159}
01d0a971 160
38fb8190 161$usercount = tag_record_count('user', $tag->id);
162if ($usercount > 0) {
061f14b2 163
38fb8190 164 //user table box
456d32fd 165 echo $OUTPUT->box_start('generalbox', 'tag-user-table');
5557c75a 166
3caea5dc 167 $heading = get_string('users'). ' ' . get_string('taggedwith', 'tag', $tagname) . ': ' . $usercount;
168 echo "<a name='user'></a>";
73aec3a7 169 echo $OUTPUT->heading($heading, 3);
38fb8190 170
a6855934 171 $baseurl = new moodle_url('/tag/index.php', array('id' => $tag->id));
929d7a83 172 $pagingbar = new paging_bar($usercount, $userpage, $perpage, $baseurl);
928a93da 173 $pagingbar->pagevar = 'userpage';
929d7a83 174 echo $OUTPUT->render($pagingbar);
38fb8190 175 tag_print_tagged_users_table($tag, $userpage * $perpage, $perpage);
456d32fd 176 echo $OUTPUT->box_end();
38fb8190 177}
178
1dd2ba54 179echo $OUTPUT->footer();