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