Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
/group/ -> group.php (source)

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 403]

   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  /**
  19   * Create group OR edit group settings.
  20   *
  21   * @copyright 2006 The Open University, N.D.Freear AT open.ac.uk, J.White AT open.ac.uk
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   * @package   core_group
  24   */
  25  
  26  require_once('../config.php');
  27  require_once ('lib.php');
  28  require_once ('group_form.php');
  29  
  30  /// get url variables
  31  $courseid = optional_param('courseid', 0, PARAM_INT);
  32  $id       = optional_param('id', 0, PARAM_INT);
  33  $delete   = optional_param('delete', 0, PARAM_BOOL);
  34  $confirm  = optional_param('confirm', 0, PARAM_BOOL);
  35  
  36  // This script used to support group delete, but that has been moved. In case
  37  // anyone still links to it, let's redirect to the new script.
  38  if ($delete) {
  39      debugging('Deleting a group through group/group.php is deprecated and will be removed soon. Please use group/delete.php instead');
  40      redirect(new moodle_url('delete.php', array('courseid' => $courseid, 'groups' => $id)));
  41  }
  42  
  43  
  44  if ($id) {
  45      if (!$group = $DB->get_record('groups', array('id'=>$id))) {
  46          throw new \moodle_exception('invalidgroupid');
  47      }
  48      if (empty($courseid)) {
  49          $courseid = $group->courseid;
  50  
  51      } else if ($courseid != $group->courseid) {
  52          throw new \moodle_exception('invalidcourseid');
  53      }
  54  
  55      if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
  56          throw new \moodle_exception('invalidcourseid');
  57      }
  58  
  59  } else {
  60      if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
  61          throw new \moodle_exception('invalidcourseid');
  62      }
  63      $group = new stdClass();
  64      $group->courseid = $course->id;
  65  }
  66  
  67  if ($id !== 0) {
  68      $PAGE->set_url('/group/group.php', array('id'=>$id));
  69  } else {
  70      $PAGE->set_url('/group/group.php', array('courseid'=>$courseid));
  71  }
  72  
  73  require_login($course);
  74  $context = context_course::instance($course->id);
  75  require_capability('moodle/course:managegroups', $context);
  76  
  77  $strgroups = get_string('groups');
  78  $PAGE->set_title($strgroups);
  79  $PAGE->set_heading($course->fullname . ': '.$strgroups);
  80  $PAGE->set_pagelayout('admin');
  81  navigation_node::override_active_url(new moodle_url('/group/index.php', array('id' => $course->id)));
  82  
  83  $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id;
  84  
  85  // Prepare the description editor: We do support files for group descriptions
  86  $editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$course->maxbytes, 'trust'=>false, 'context'=>$context, 'noclean'=>true);
  87  if (!empty($group->id)) {
  88      $editoroptions['subdirs'] = file_area_contains_subdirs($context, 'group', 'description', $group->id);
  89      $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', $group->id);
  90  } else {
  91      $editoroptions['subdirs'] = false;
  92      $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', null);
  93  }
  94  
  95  /// First create the form
  96  $editform = new group_form(null, array('editoroptions'=>$editoroptions));
  97  $editform->set_data($group);
  98  
  99  if ($editform->is_cancelled()) {
 100      redirect($returnurl);
 101  
 102  } elseif ($data = $editform->get_data()) {
 103      if (!has_capability('moodle/course:changeidnumber', $context)) {
 104          // Remove the idnumber if the user doesn't have permission to modify it
 105          unset($data->idnumber);
 106      }
 107  
 108      if ($data->id) {
 109          groups_update_group($data, $editform, $editoroptions);
 110      } else {
 111          $id = groups_create_group($data, $editform, $editoroptions);
 112          $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id;
 113      }
 114  
 115      redirect($returnurl);
 116  }
 117  
 118  $strgroups = get_string('groups');
 119  $strparticipants = get_string('participants');
 120  
 121  if ($id) {
 122      $strheading = get_string('editgroupsettings', 'group');
 123  } else {
 124      $strheading = get_string('creategroup', 'group');
 125  }
 126  
 127  $PAGE->navbar->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$courseid)));
 128  $PAGE->navbar->add($strgroups, new moodle_url('/group/index.php', array('id'=>$courseid)));
 129  $PAGE->navbar->add($strheading);
 130  
 131  /// Print header
 132  echo $OUTPUT->header();
 133  echo '<div id="grouppicture">';
 134  if ($id) {
 135      print_group_picture($group, $course->id);
 136  }
 137  echo '</div>';
 138  $editform->display();
 139  echo $OUTPUT->footer();