Search moodle.org's
Developer Documentation


  • Bug fixes for general core bugs in 2.8.x ended 9 November 2015 (12 months).
  • Bug fixes for security issues in 2.8.x ended 9 May 2016 (18 months).
  • minimum PHP 5.4.4 (always use latest PHP 5.4.x or 5.5.x on Windows - http://windows.php.net/download/), PHP 7 is NOT supported
  • /cohort/ -> upload.php (source)

    Differences Between: [Versions 28 and 31] [Versions 28 and 34] [Versions 28 and 35] [Versions 28 and 36] [Versions 28 and 37]

       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   * A form for cohort upload.
      19   *
      20   * @package    core_cohort
      21   * @copyright  2014 Marina Glancy
      22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
      23   */
      24  
      25  require_once('../config.php');
      26  require_once($CFG->dirroot.'/cohort/lib.php');
      27  require_once($CFG->dirroot.'/cohort/upload_form.php');
      28  require_once($CFG->libdir . '/csvlib.class.php');
      29  
      30  $contextid = optional_param('contextid', 0, PARAM_INT);
      31  $returnurl = optional_param('returnurl', '', PARAM_URL);
      32  
      33  require_login();
      34  
      35  if ($contextid) {
      36      $context = context::instance_by_id($contextid, MUST_EXIST);
      37  } else {
      38      $context = context_system::instance();
      39  }
      40  if ($context->contextlevel != CONTEXT_COURSECAT && $context->contextlevel != CONTEXT_SYSTEM) {
      41      print_error('invalidcontext');
      42  }
      43  
      44  require_capability('moodle/cohort:manage', $context);
      45  
      46  $PAGE->set_context($context);
      47  $baseurl = new moodle_url('/cohort/upload.php', array('contextid' => $context->id));
      48  $PAGE->set_url($baseurl);
      49  $PAGE->set_heading($COURSE->fullname);
      50  $PAGE->set_pagelayout('admin');
      51  
      52  if ($context->contextlevel == CONTEXT_COURSECAT) {
      53      $PAGE->set_category_by_id($context->instanceid);
      54      navigation_node::override_active_url(new moodle_url('/cohort/index.php', array('contextid' => $context->id)));
      55  } else {
      56      navigation_node::override_active_url(new moodle_url('/cohort/index.php', array()));
      57  }
      58  
      59  $uploadform = new cohort_upload_form(null, array('contextid' => $context->id, 'returnurl' => $returnurl));
      60  
      61  if ($returnurl) {
      62      $returnurl = new moodle_url($returnurl);
      63  } else {
      64      $returnurl = new moodle_url('/cohort/index.php', array('contextid' => $context->id));
      65  }
      66  
      67  if ($uploadform->is_cancelled()) {
      68      redirect($returnurl);
      69  }
      70  
      71  $strheading = get_string('uploadcohorts', 'cohort');
      72  $PAGE->navbar->add($strheading);
      73  
      74  echo $OUTPUT->header();
      75  echo $OUTPUT->heading_with_help($strheading, 'uploadcohorts', 'cohort');
      76  
      77  if ($editcontrols = cohort_edit_controls($context, $baseurl)) {
      78      echo $OUTPUT->render($editcontrols);
      79  }
      80  
      81  if ($data = $uploadform->get_data()) {
      82      $cohortsdata = $uploadform->get_cohorts_data();
      83      foreach ($cohortsdata as $cohort) {
      84          cohort_add_cohort($cohort);
      85      }
      86      echo $OUTPUT->notification(get_string('uploadedcohorts', 'cohort', count($cohortsdata)), 'notifysuccess');
      87      echo $OUTPUT->continue_button($returnurl);
      88  } else {
      89      $uploadform->display();
      90  }
      91  
      92  echo $OUTPUT->footer();
      93  
    

    Search This Site: