[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/tag/ -> index.php (source)

   1  <?php // $Id: index.php,v 1.16.2.12 2008/04/02 06:10:07 dongsheng Exp $
   2  
   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');
   8  
   9  require_login();
  10  
  11  if (empty($CFG->usetags)) {
  12      print_error('tagsaredisabled', 'tag');
  13  }
  14  
  15  $tagid       = optional_param('id', 0, PARAM_INT); // tag id
  16  $tagname     = optional_param('tag', '', PARAM_TAG); // tag 
  17  
  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);
  21  
  22  
  23  if ($tagname) {
  24      $tag = tag_get('name', $tagname, '*');
  25  } else if ($tagid) {
  26      $tag = tag_get('id', $tagid, '*');
  27  }
  28  
  29  if (empty($tag)) {
  30      redirect($CFG->wwwroot.'/tag/search.php');
  31  }
  32  
  33  
  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;
  38  
  39  if (($edit != -1) and $PAGE->user_allowed_editing()) {
  40      $USER->editing = $edit;
  41  }
  42  
  43  
  44  $PAGE->print_header();
  45  
  46  // Manage all tags links
  47  $systemcontext   = get_context_instance(CONTEXT_SYSTEM);
  48  
  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>' ;
  51  }
  52  
  53  echo '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">';
  54  echo '<tr valign="top">';
  55  
  56  //----------------- left column -----------------
  57  
  58  $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
  59  
  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>';
  64  }
  65  
  66  //----------------- middle column -----------------
  67  
  68  echo '<td valign="top" id="middle-column">';
  69  
  70  $tagname  = tag_display_name($tag);
  71  
  72  if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
  73      $tagname =  '<span class="flagged-tag">' . $tagname . '</span>';
  74  }
  75  
  76  print_heading($tagname, '', 2, 'headingblock header tag-heading');
  77  tag_print_management_box($tag);
  78  tag_print_description_box($tag);
  79  
  80  $usercount = tag_record_count('user', $tag->id);
  81  
  82  if ($usercount > 0) {
  83  
  84      //user table box
  85      print_box_start('generalbox', 'tag-user-table');
  86  
  87      $heading = get_string('userstaggedwith', 'tag', $tagname) . ': ' . $usercount;
  88      print_heading($heading, '', 3);
  89  
  90      $baseurl = $CFG->wwwroot.'/tag/index.php?id=' . $tag->id;
  91  
  92      print_paging_bar($usercount, $userpage, $perpage, $baseurl.'&amp;', 'userpage');
  93      tag_print_tagged_users_table($tag, $userpage * $perpage, $perpage);
  94      print_box_end();
  95  }
  96  
  97  // Print last 10 blogs
  98  
  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
 103  
 104      if ($blogs = blog_fetch_entries('', 10, 0, 'site', '', $tag->id)) {
 105  
 106          print_box_start('generalbox', 'tag-blogs');
 107  
 108          print_heading(get_string('relatedblogs', 'tag'), '', 3);
 109  
 110          echo '<ul id="tagblogentries">';
 111          foreach ($blogs as $blog) {
 112              if ($blog->publishstate == 'draft') {
 113                  $class = 'class="dimmed"';
 114              } else {
 115                  $class = '';
 116              }
 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>';
 127          }
 128          echo '</ul>';
 129  
 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>';
 131  
 132          print_box_end();
 133      }
 134  }
 135  
 136  
 137  echo '</td>';
 138  
 139  
 140  //----------------- right column -----------------
 141  
 142  $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), 210);
 143  
 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>';
 148  }
 149  
 150  /// Finish the page
 151  echo '</tr></table>';
 152  
 153  
 154  
 155  $PAGE->print_footer();
 156  
 157  
 158  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7