[ Index ]

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

title

Body

[close]

/blocks/admin/ -> block_admin.php (source)

   1  <?php //$Id: block_admin.php,v 1.100.2.10 2008/07/24 23:14:09 skodak Exp $
   2  
   3  class block_admin extends block_list {
   4      function init() {
   5          $this->title = get_string('administration');
   6          $this->version = 2007101509;
   7      }
   8  
   9      function get_content() {
  10  
  11          global $CFG, $USER, $SITE, $COURSE;
  12  
  13          if ($this->content !== NULL) {
  14              return $this->content;
  15          }
  16  
  17          $this->content = new stdClass;
  18          $this->content->items = array();
  19          $this->content->icons = array();
  20          $this->content->footer = '';
  21  
  22          if (empty($this->instance)) {
  23              return $this->content = '';
  24          } else if ($this->instance->pageid == SITEID) {
  25              // return $this->content = '';
  26          }
  27  
  28          if (!empty($this->instance->pageid)) {
  29              $context = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
  30              if ($COURSE->id == $this->instance->pageid) {
  31                  $course = $COURSE;
  32              } else {
  33                  $course = get_record('course', 'id', $this->instance->pageid);
  34              }
  35          } else {
  36              $context = get_context_instance(CONTEXT_SYSTEM);
  37              $course = $SITE;
  38          }
  39  
  40          if (!has_capability('moodle/course:view', $context)) {  // Just return
  41              return $this->content;
  42          }
  43  
  44          if (empty($CFG->loginhttps)) {
  45              $securewwwroot = $CFG->wwwroot;
  46          } else {
  47              $securewwwroot = str_replace('http:','https:',$CFG->wwwroot);
  48          }
  49  
  50      /// Course editing on/off
  51  
  52          if ($course->id !== SITEID and has_capability('moodle/course:update', $context)) {
  53              $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/edit.gif" class="icon" alt="" />';
  54              if (isediting($this->instance->pageid)) {
  55                  $this->content->items[]='<a href="view.php?id='.$this->instance->pageid.'&amp;edit=off&amp;sesskey='.sesskey().'">'.get_string('turneditingoff').'</a>';
  56              } else {
  57                  $this->content->items[]='<a href="view.php?id='.$this->instance->pageid.'&amp;edit=on&amp;sesskey='.sesskey().'">'.get_string('turneditingon').'</a>';
  58              }
  59  
  60              $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/edit.php?id='.$this->instance->pageid.'">'.get_string('settings').'</a>';
  61              $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/settings.gif" class="icon" alt="" />';
  62          }
  63  
  64      /// Assign roles to the course
  65  
  66          if ($course->id != SITEID) {
  67              if (has_capability('moodle/role:assign', $context)) {
  68                  $this->content->items[]='<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id.'">'.get_string('assignroles', 'role').'</a>';
  69                  $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/roles.gif" class="icon" alt="" />';
  70              } else if (get_overridable_roles($context, 'name', ROLENAME_ORIGINAL)) {
  71                  $this->content->items[]='<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/override.php?contextid='.$context->id.'">'.get_string('overridepermissions', 'role').'</a>';
  72                  $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/roles.gif" class="icon" alt="" />';
  73              }
  74          }
  75  
  76      /// View course grades (or just your own grades, same link)
  77      /// find all accessible reports
  78          if ($course->id !== SITEID) {
  79              $reportavailable = false;
  80              if (has_capability('moodle/grade:viewall', $context)) {
  81                  $reportavailable = true;
  82              } else if (!empty($course->showgrades)) {
  83                  if ($reports = get_list_of_plugins('grade/report')) {     // Get all installed reports
  84                      arsort($reports); // user is last, we want to test it first
  85                      foreach ($reports as $plugin) {
  86                          if (has_capability('gradereport/'.$plugin.':view', $context)) {
  87                              //stop when the first visible plugin is found
  88                              $reportavailable = true;
  89                              break;
  90                          }
  91                      }
  92                  }
  93              }
  94  
  95              if ($reportavailable) {
  96                  $this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/report/index.php?id='.$this->instance->pageid.'">'.get_string('grades').'</a>';
  97                  $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/grades.gif" class="icon" alt="" />';
  98              }
  99          }
 100  
 101      /// Course outcomes (to help give it more prominence because it's important)
 102          if (!empty($CFG->enableoutcomes)) {
 103              if ($course->id!==SITEID and has_capability('moodle/course:update', $context)) {
 104                  $this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/edit/outcome/course.php?id='.$this->instance->pageid.'">'.get_string('outcomes', 'grades').'</a>';
 105                  $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/outcomes.gif" class="icon" alt="" />';
 106              }
 107          }
 108  
 109      /// Manage metacourses
 110          if ($course->metacourse) {
 111              if (has_capability('moodle/course:managemetacourse', $context)) {
 112                  $strchildcourses = get_string('childcourses');
 113                  $this->content->items[]='<a href="importstudents.php?id='.$this->instance->pageid.'">'.$strchildcourses.'</a>';
 114                  $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/course.gif" class="icon" alt="" />';
 115              } else if (has_capability('moodle/role:assign', $context)) {
 116                  $strchildcourses = get_string('childcourses');
 117                  $this->content->items[]='<span class="dimmed_text">'.$strchildcourses.'</span>';
 118                  $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/course.gif" class="icon" alt="" />';
 119              }
 120          }
 121  
 122  
 123      /// Manage groups in this course
 124  
 125          if (($course->id!==SITEID) && ($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $context)) {
 126              $strgroups = get_string('groups');
 127              $this->content->items[]='<a title="'.$strgroups.'" href="'.$CFG->wwwroot.'/group/index.php?id='.$this->instance->pageid.'">'.$strgroups.'</a>';
 128              $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/group.gif" class="icon" alt="" />';
 129          }
 130  
 131      /// Backup this course
 132  
 133          if ($course->id!==SITEID and has_capability('moodle/site:backup', $context)) {
 134              $this->content->items[]='<a href="'.$CFG->wwwroot.'/backup/backup.php?id='.$this->instance->pageid.'">'.get_string('backup').'</a>';
 135              $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/backup.gif" class="icon" alt="" />';
 136          }
 137  
 138      /// Restore to this course
 139          if ($course->id !== SITEID and has_capability('moodle/site:restore', $context)) {
 140              $this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'&amp;wdir=/backupdata">'.get_string('restore').'</a>';
 141              $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" class="icon" alt="" />';
 142          }
 143  
 144      /// Import data from other courses
 145          if ($course->id !== SITEID and has_capability('moodle/site:import', $context)) {
 146              $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/import.php?id='.$this->instance->pageid.'">'.get_string('import').'</a>';
 147              $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" class="icon" alt="" />';
 148          }
 149  
 150      /// Reset this course
 151          if ($course->id!==SITEID and has_capability('moodle/course:reset', $context)) {
 152              $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/reset.php?id='.$this->instance->pageid.'">'.get_string('reset').'</a>';
 153              $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/return.gif" class="icon" alt="" />';
 154          }
 155  
 156      /// View course reports
 157          if ($course->id !== SITEID and has_capability('moodle/site:viewreports', $context)) {
 158              $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/report.php?id='.$this->instance->pageid.'">'.get_string('reports').'</a>';
 159              $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/stats.gif" class="icon" alt="" />';
 160          }
 161  
 162      /// Manage questions
 163          if ($course->id !== SITEID){
 164              $questionlink = '';
 165              $questioncaps = array(
 166                                      'moodle/question:add',
 167                                      'moodle/question:editmine',
 168                                      'moodle/question:editall',
 169                                      'moodle/question:viewmine',
 170                                      'moodle/question:viewall',
 171                                      'moodle/question:movemine',
 172                                      'moodle/question:moveall');
 173              foreach ($questioncaps as $questioncap){
 174                  if (has_capability($questioncap, $context)){
 175                      $questionlink = 'edit.php';
 176                      break;
 177                  }
 178              }
 179              if (!$questionlink && has_capability('moodle/question:managecategory', $context)) {
 180                 $questionlink = 'category.php';
 181              }
 182              if ($questionlink) {
 183                  $this->content->items[]='<a href="'.$CFG->wwwroot.'/question/'.$questionlink.
 184                          '?courseid='.$this->instance->pageid.'">'.get_string('questions', 'quiz').'</a>';
 185                  $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/questions.gif" class="icon" alt="" />';
 186              }
 187          }
 188  
 189  
 190      /// Manage files
 191          if ($course->id !== SITEID and has_capability('moodle/course:managefiles', $context)) {
 192              $this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'">'.get_string('files').'</a>';
 193              $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/files.gif" class="icon" alt="" />';
 194          }
 195  
 196      /// Authorize hooks
 197          if ($course->enrol == 'authorize' || (empty($course->enrol) && $CFG->enrol == 'authorize') && ($course->id!==SITEID)) {
 198              require_once($CFG->dirroot.'/enrol/authorize/const.php');
 199              $paymenturl = '<a href="'.$CFG->wwwroot.'/enrol/authorize/index.php?course='.$course->id.'">'.get_string('payments').'</a> ';
 200              if (has_capability('enrol/authorize:managepayments', $context)) {
 201                  if ($cnt = count_records('enrol_authorize', 'status', AN_STATUS_AUTH, 'courseid', $course->id)) {
 202                      $paymenturl .= '<a href="'.$CFG->wwwroot.'/enrol/authorize/index.php?status='.AN_STATUS_AUTH.'&amp;course='.$course->id.'">'.get_string('paymentpending', 'moodle', $cnt).'</a>';
 203                  }
 204              }
 205              $this->content->items[] = $paymenturl;
 206              $this->content->icons[] = '<img src="'.$CFG->pixpath.'/i/payment.gif" class="icon" alt="" />';
 207          }
 208  
 209      /// Unenrol link
 210          if (empty($course->metacourse) && ($course->id!==SITEID)) {
 211              if (has_capability('moodle/legacy:guest', $context, NULL, false)) {   // Are a guest now
 212                  $this->content->items[]='<a href="enrol.php?id='.$this->instance->pageid.'">'.get_string('enrolme', '', format_string($course->shortname)).'</a>';
 213                  $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" class="icon" alt="" />';
 214              } else if (has_capability('moodle/role:unassignself', $context, NULL, false) and get_user_roles($context, $USER->id, false)) {  // Have some role
 215                  $this->content->items[]='<a href="unenrol.php?id='.$this->instance->pageid.'">'.get_string('unenrolme', '', format_string($course->shortname)).'</a>';
 216                  $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" class="icon" alt="" />';
 217              }
 218          }
 219  
 220      /// Link to the user own profile (except guests)
 221          if (!isguestuser() and isloggedin()) {
 222              $this->content->items[]='<a href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&amp;course='.$course->id.'">'.get_string('profile').'</a>';
 223              $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" alt="" />';
 224          }
 225  
 226          return $this->content;
 227      }
 228  
 229      function applicable_formats() {
 230          return array('course' => true);   // Not needed on site
 231      }
 232  }
 233  
 234  ?>


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