Merged MDL-13640 to move "Manage tags" link
[moodle.git] / tag / index.php
CommitLineData
c933a060 1<?php // $Id$
2
3require_once('../config.php');
4require_once('lib.php');
5557c75a 5require_once('pagelib.php');
c933a060 6require_once($CFG->dirroot.'/lib/weblib.php');
8a275c72 7require_once($CFG->dirroot.'/blog/lib.php');
c933a060 8
9require_login();
10
11if (empty($CFG->usetags)) {
12 error(get_string('tagsaredisabled', 'tag'));
13}
14
3d535996 15$tagid = optional_param('id', 0, PARAM_INT); // tag id
16$tag_name = optional_param('tag', '', PARAM_TAG); // tag
17if ($tag_name) {
18 $tag = tag_get_id($tag_name, TAG_RETURN_OBJECT);
19} elseif ($tagid) {
20 $tag = tag_get_tag_by_id($tagid); // for backward compatibility
21}
5557c75a 22$edit = optional_param('edit', -1, PARAM_BOOL);
3d535996 23$userpage = optional_param('userpage', 0, PARAM_INT); // which page to show
5557c75a 24$perpage = optional_param('perpage', 24, PARAM_INT);
c933a060 25
3d535996 26if (!isset($tag) || !$tag->id) {
c933a060 27 redirect($CFG->wwwroot.'/tag/search.php');
28}
29
5557c75a 30//create a new page_tag object, defined in pagelib.php
31$PAGE = page_create_object(PAGE_TAG_INDEX, $tag->id);
32$pageblocks = blocks_setup($PAGE,BLOCKS_PINNED_BOTH);
33$PAGE->tag_object = $tag;
34
35if (($edit != -1) and $PAGE->user_allowed_editing()) {
36 $USER->editing = $edit;
37}
38
03ce38cd 39$systemcontext = get_context_instance(CONTEXT_SYSTEM);
40
5557c75a 41$PAGE->print_header();
42
03ce38cd 43// Manage all tags links
44if (has_capability('moodle/tag:manage', $systemcontext)) {
45 echo '<div class="managelink"><a href="'. $CFG->wwwroot .'/tag/manage.php">'. get_string('managetags', 'tag') .'</a></div>' ;
46}
47
353a8961 48echo '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">';
49echo '<tr valign="top">';
5557c75a 50
51//----------------- left column -----------------
52
53$blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
54
c91146b9 55if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing()) {
353a8961 56 echo '<td style="vertical-align: top; width: '.$blocks_preferred_width.'px;" id="left-column">';
5557c75a 57 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
ea640187 58 echo '</td>';
5557c75a 59}
5557c75a 60
5557c75a 61//----------------- middle column -----------------
c933a060 62
5557c75a 63echo '<td valign="top" id="middle-column">';
c933a060 64
5557c75a 65$tagname = tag_display_name($tag);
c933a060 66
c933a060 67if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
3d535996 68 $tagname = '<span class="flagged-tag">' . rawurlencode($tagname) . '</span>';
c933a060 69}
70
5557c75a 71print_heading($tagname, '', 2, 'headingblock header tag-heading');
3d535996 72tag_print_management_box($tag);
73tag_print_description_box($tag);
c933a060 74
3d535996 75$usercount = tag_record_count('user', $tag->id);
c933a060 76
77if ($usercount > 0) {
78
6cbf4bd4 79 //user table box
353a8961 80 print_box_start('generalbox', 'tag-user-table');
6cbf4bd4 81
5557c75a 82 $heading = get_string('userstaggedwith', 'tag', $tagname) . ': ' . $usercount;
83 print_heading($heading, '', 3);
84
85 $baseurl = $CFG->wwwroot.'/tag/index.php?id=' . $tag->id;
c933a060 86
c933a060 87 print_paging_bar($usercount, $userpage, $perpage, $baseurl.'&amp;', 'userpage');
3d535996 88 tag_print_tagged_users_table($tag, $userpage * $perpage, $perpage);
353a8961 89 print_box_end();
c933a060 90}
c933a060 91
01d0a971 92// Print last 10 blogs
061f14b2 93
94// I was not able to use get_items_tagged_with() because it automatically
95// tries to join on 'blog' table, since the itemtype is 'blog'. However blogs
01d0a971 96// uses the post table so this would not really work. - Yu 29/8/07
9133f939 97if ($blogs = blog_fetch_entries('', 10, 0, 'site', '', $tag->id)) {
061f14b2 98
01d0a971 99 print_box_start('generalbox', 'tag-blogs');
100
2773ced4 101 print_heading(get_string('relatedblogs', 'tag'), '', 3);
01d0a971 102
53bde3e1 103 echo '<ul id="tagblogentries">';
061f14b2 104 foreach ($blogs as $blog) {
53bde3e1 105 if ($blog->publishstate == 'draft') {
106 $class = 'class="dimmed"';
107 } else {
108 $class = '';
109 }
110 echo '<li '.$class.'>';
111 echo '<a '.$class.' href="'.$CFG->wwwroot.'/blog/index.php?postid='.$blog->id.'">';
112 echo format_string($blog->subject);
113 echo '</a>';
114 echo ' - ';
115 echo '<a '.$class.' href="'.$CFG->wwwroot.'/user/view.php?id='.$blog->userid.'">';
116 echo fullname($blog);
117 echo '</a>';
118 echo ', '. userdate($blog->lastmodified);
119 echo '</li>';
061f14b2 120 }
53bde3e1 121 echo '</ul>';
5557c75a 122
353a8961 123 echo '<p class="moreblogs"><a href="'.$CFG->wwwroot.'/blog/index.php?filtertype=site&filterselect=0&tagid='.$tag->id.'">'.get_string('seeallblogs', 'tag').'</a>...</p>';
44842cc6 124
01d0a971 125 print_box_end();
061f14b2 126}
01d0a971 127
061f14b2 128
129echo '</td>';
5557c75a 130
131
132//----------------- right column -----------------
133
134$blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), 210);
135
5557c75a 136if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing()) {
353a8961 137 echo '<td style="vertical-align: top; width: '.$blocks_preferred_width.'px;" id="right-column">';
5557c75a 138 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
ea640187 139 echo '</td>';
5557c75a 140}
5557c75a 141
142/// Finish the page
143echo '</tr></table>';
144
c933a060 145
146
5557c75a 147$PAGE->print_footer();
c933a060 148
149
150?>