[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/report/courseoverview/ -> index.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Course overview report
  19   *
  20   * @package    report
  21   * @subpackage courseoverview
  22   * @copyright  1999 onwards Martin Dougiamas  {@link http://moodle.com}
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require_once('../../config.php');
  27  require_once($CFG->dirroot.'/lib/statslib.php');
  28  require_once($CFG->libdir.'/adminlib.php');
  29  
  30  $report     = optional_param('report', STATS_REPORT_ACTIVE_COURSES, PARAM_INT);
  31  $time       = optional_param('time', 0, PARAM_INT);
  32  $numcourses = optional_param('numcourses', 20, PARAM_INT);
  33  
  34  if (empty($CFG->enablestats)) {
  35      if (has_capability('moodle/site:config', context_system::instance())) {
  36          redirect("$CFG->wwwroot/$CFG->admin/search.php?query=enablestats", get_string('mustenablestats', 'admin'), 3);
  37      } else {
  38          print_error('statsdisable');
  39      }
  40  }
  41  
  42  admin_externalpage_setup('reportcourseoverview', '', null, '', array('pagelayout'=>'report'));
  43  echo $OUTPUT->header();
  44  
  45  $course = get_site();
  46  stats_check_uptodate($course->id);
  47  
  48  $strreports = get_string('reports');
  49  $strcourseoverview = get_string('courseoverview');
  50  
  51  $reportoptions = stats_get_report_options($course->id,STATS_MODE_RANKED);
  52  
  53  $earliestday = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_daily}');
  54  $earliestweek = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_weekly}');
  55  $earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_monthly}');
  56  
  57  if (empty($earliestday)) $earliestday = time();
  58  if (empty($earliestweek)) $earliestweek = time();
  59  if (empty($earliestmonth)) $earliestmonth = time();
  60  
  61  $now = stats_get_base_daily();
  62  $lastweekend = stats_get_base_weekly();
  63  $lastmonthend = stats_get_base_monthly();
  64  
  65  $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
  66  
  67  if (empty($timeoptions)) {
  68      print_error('nostatstodisplay', 'error', $CFG->wwwroot.'/course/view.php?id='.$course->id);
  69  }
  70  
  71  echo html_writer::start_tag('form', array('action' => 'index.php', 'method' => 'post'));
  72  echo html_writer::start_tag('div');
  73  
  74  $table = new html_table();
  75  $table->width = '*';
  76  $table->align = array('left','left','left','left','left','left');
  77  
  78  $reporttypemenu = html_writer::label(get_string('statsreporttype'), 'menureport', false, array('class' => 'accesshide'));
  79  $reporttypemenu .= html_writer::select($reportoptions,'report',$report, false);
  80  $timeoptionsmenu = html_writer::label(get_string('time'), 'menutime', false, array('class' => 'accesshide'));
  81  $timeoptionsmenu .= html_writer::select($timeoptions,'time',$time, false);
  82  
  83  $table->data[] = array(get_string('statsreporttype'),$reporttypemenu,
  84                         get_string('statstimeperiod'),$timeoptionsmenu,
  85                         html_writer::label(get_string('numberofcourses'), 'numcourses', false, array('class' => 'accesshide')) .
  86                         html_writer::empty_tag('input', array('type' => 'text', 'id' => 'numcourses', 'name' => 'numcourses', 'size' => '3', 'maxlength' => '2', 'value' => $numcourses)),
  87                         html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('view'))));
  88  
  89  echo html_writer::table($table);
  90  echo html_writer::end_tag('div');
  91  echo html_writer::end_tag('form');
  92  
  93  echo $OUTPUT->heading($reportoptions[$report]);
  94  
  95  
  96  if (!empty($report) && !empty($time)) {
  97      $param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED);
  98      if (!empty($param->sql)) {
  99          $sql = $param->sql;
 100      } else {
 101          $sql = "SELECT courseid,".$param->fields."
 102                    FROM {".'stats_'.$param->table."}
 103                   WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0
 104                GROUP BY courseid
 105                         $param->extras
 106                ORDER BY $param->orderby";
 107      }
 108  
 109      $courses = $DB->get_records_sql($sql, $param->params, 0, $numcourses);
 110  
 111      if (empty($courses)) {
 112          echo $OUTPUT->notification(get_string('statsnodata'));
 113          echo '</td></tr></table>';
 114  
 115      } else {
 116          echo '<div class="graph"><img alt="'.get_string('courseoverviewgraph').'" src="'.$CFG->wwwroot.'/report/courseoverview/reportsgraph.php?time='.$time.'&report='.$report.'&numcourses='.$numcourses.'" /></div>';
 117  
 118          $table = new html_table();
 119          $table->align = array('left','center','center','center');
 120          $table->head = array(get_string('course'),$param->line1);
 121          if (!empty($param->line2)) {
 122              $table->head[] = $param->line2;
 123          }
 124          if (!empty($param->line3)) {
 125              $table->head[] = $param->line3;
 126          }
 127  
 128          foreach  ($courses as $c) {
 129              $a = array();
 130              $a[] = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$c->courseid.'">'.$DB->get_field('course', 'shortname', array('id'=>$c->courseid)).'</a>';
 131  
 132              $a[] = $c->line1;
 133              if (isset($c->line2)) {
 134                  $a[] = $c->line2;
 135              }
 136              if (isset($c->line3)) {
 137                  $a[] = round($c->line3,2);
 138              }
 139              $table->data[] = $a;
 140          }
 141          echo html_writer::table($table);
 142      }
 143  }
 144  echo $OUTPUT->footer();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1