group.php 4.7 KB

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