weekly release 1.9.14+
[moodle.git] / tag / index.php
blob7f0034e4e68362e43de6f8eefe6d20adf59d7d7d
1 <?php // $Id$
3 require_once('../config.php');
4 require_once('lib.php');
5 require_once('pagelib.php');
6 require_once($CFG->dirroot.'/lib/weblib.php');
7 require_once($CFG->dirroot.'/blog/lib.php');
9 require_login();
11 if (empty($CFG->usetags)) {
12 print_error('tagsaredisabled', 'tag');
15 $tagid = optional_param('id', 0, PARAM_INT); // tag id
16 $tagname = optional_param('tag', '', PARAM_TAG); // tag
18 $edit = optional_param('edit', -1, PARAM_BOOL);
19 $userpage = optional_param('userpage', 0, PARAM_INT); // which page to show
20 $perpage = optional_param('perpage', 24, PARAM_INT);
23 if ($tagname) {
24 $tag = tag_get('name', $tagname, '*');
25 } else if ($tagid) {
26 $tag = tag_get('id', $tagid, '*');
29 if (empty($tag)) {
30 redirect($CFG->wwwroot.'/tag/search.php');
34 //create a new page_tag object, defined in pagelib.php
35 $PAGE = page_create_object(PAGE_TAG_INDEX, $tag->id);
36 $pageblocks = blocks_setup($PAGE,BLOCKS_PINNED_BOTH);
37 $PAGE->tag_object = $tag;
39 if (($edit != -1) and $PAGE->user_allowed_editing()) {
40 $USER->editing = $edit;
44 $PAGE->print_header();
46 // Manage all tags links
47 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
49 if (has_capability('moodle/tag:manage', $systemcontext)) {
50 echo '<div class="managelink"><a href="'. $CFG->wwwroot .'/tag/manage.php">'. get_string('managetags', 'tag') .'</a></div>' ;
53 echo '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">';
54 echo '<tr valign="top">';
56 //----------------- left column -----------------
58 $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
60 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing()) {
61 echo '<td style="vertical-align: top; width: '.$blocks_preferred_width.'px;" id="left-column">';
62 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
63 echo '</td>';
66 //----------------- middle column -----------------
68 echo '<td valign="top" id="middle-column">';
70 $tagname = tag_display_name($tag);
72 if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
73 $tagname = '<span class="flagged-tag">' . $tagname . '</span>';
76 print_heading($tagname, '', 2, 'headingblock header tag-heading');
77 tag_print_management_box($tag);
78 tag_print_description_box($tag);
80 $usercount = tag_record_count('user', $tag->id);
82 if ($usercount > 0) {
84 //user table box
85 print_box_start('generalbox', 'tag-user-table');
87 $heading = get_string('userstaggedwith', 'tag', $tagname) . ': ' . $usercount;
88 print_heading($heading, '', 3);
90 $baseurl = $CFG->wwwroot.'/tag/index.php?id=' . $tag->id;
92 print_paging_bar($usercount, $userpage, $perpage, $baseurl.'&amp;', 'userpage');
93 tag_print_tagged_users_table($tag, $userpage * $perpage, $perpage);
94 print_box_end();
97 // Print last 10 blogs
99 // I was not able to use get_items_tagged_with() because it automatically
100 // tries to join on 'blog' table, since the itemtype is 'blog'. However blogs
101 // uses the post table so this would not really work. - Yu 29/8/07
102 if (has_capability('moodle/blog:view', $systemcontext)) { // You have to see blogs obviously
104 if ($blogs = blog_fetch_entries('', 10, 0, 'site', '', $tag->id)) {
106 print_box_start('generalbox', 'tag-blogs');
108 print_heading(get_string('relatedblogs', 'tag'), '', 3);
110 echo '<ul id="tagblogentries">';
111 foreach ($blogs as $blog) {
112 if ($blog->publishstate == 'draft') {
113 $class = 'class="dimmed"';
114 } else {
115 $class = '';
117 echo '<li '.$class.'>';
118 echo '<a '.$class.' href="'.$CFG->wwwroot.'/blog/index.php?postid='.$blog->id.'">';
119 echo format_string($blog->subject);
120 echo '</a>';
121 echo ' - ';
122 echo '<a '.$class.' href="'.$CFG->wwwroot.'/user/view.php?id='.$blog->userid.'">';
123 echo fullname($blog);
124 echo '</a>';
125 echo ', '. userdate($blog->lastmodified);
126 echo '</li>';
128 echo '</ul>';
130 echo '<p class="moreblogs"><a href="'.$CFG->wwwroot.'/blog/index.php?filtertype=site&filterselect=0&tagid='.$tag->id.'">'.get_string('seeallblogs', 'tag').'</a>...</p>';
132 print_box_end();
137 echo '</td>';
140 //----------------- right column -----------------
142 $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), 210);
144 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing()) {
145 echo '<td style="vertical-align: top; width: '.$blocks_preferred_width.'px;" id="right-column">';
146 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
147 echo '</td>';
150 /// Finish the page
151 echo '</tr></table>';
155 $PAGE->print_footer();