Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/group/group.php
Go to the documentation of this file.
00001 <?php
00012 require_once('../config.php');
00013 require_once('lib.php');
00014 require_once('group_form.php');
00015 
00017 $courseid = optional_param('courseid', 0, PARAM_INT);
00018 $id       = optional_param('id', 0, PARAM_INT);
00019 $delete   = optional_param('delete', 0, PARAM_BOOL);
00020 $confirm  = optional_param('confirm', 0, PARAM_BOOL);
00021 
00022 // This script used to support group delete, but that has been moved. In case
00023 // anyone still links to it, let's redirect to the new script.
00024 if($delete) {
00025     redirect('delete.php?courseid='.$courseid.'&groups='.$id);
00026 }
00027 
00028 if ($id) {
00029     if (!$group = $DB->get_record('groups', array('id'=>$id))) {
00030         print_error('invalidgroupid');
00031     }
00032     if (empty($courseid)) {
00033         $courseid = $group->courseid;
00034 
00035     } else if ($courseid != $group->courseid) {
00036         print_error('invalidcourseid');
00037     }
00038 
00039     if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
00040         print_error('invalidcourseid');
00041     }
00042 
00043 } else {
00044     if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
00045         print_error('invalidcourseid');
00046     }
00047     $group = new stdClass();
00048     $group->courseid = $course->id;
00049 }
00050 
00051 if ($id !== 0) {
00052     $PAGE->set_url('/group/group.php', array('id'=>$id));
00053 } else {
00054     $PAGE->set_url('/group/group.php', array('courseid'=>$courseid));
00055 }
00056 
00057 require_login($course);
00058 $context = get_context_instance(CONTEXT_COURSE, $course->id);
00059 require_capability('moodle/course:managegroups', $context);
00060 
00061 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id;
00062 
00063 if ($id and $delete) {
00064     if (!$confirm) {
00065         $PAGE->set_title(get_string('deleteselectedgroup', 'group'));
00066         $PAGE->set_heading($course->fullname . ': '. get_string('deleteselectedgroup', 'group'));
00067         echo $OUTPUT->header();
00068         $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
00069         $optionsno  = array('id'=>$courseid);
00070         $formcontinue = new single_button(new moodle_url('group.php', $optionsyes), get_string('yes'), 'get');
00071         $formcancel = new single_button(new moodle_url($baseurl, $optionsno), get_string('no'), 'get');
00072         echo $OUTPUT->confirm(get_string('deletegroupconfirm', 'group', $group->name), $formcontinue, $formcancel);
00073         echo $OUTPUT->footer();
00074         die;
00075 
00076     } else if (confirm_sesskey()){
00077         if (groups_delete_group($id)) {
00078             redirect('index.php?id='.$course->id);
00079         } else {
00080             print_error('erroreditgroup', 'group', $returnurl);
00081         }
00082     }
00083 }
00084 
00085 // Prepare the description editor: We do support files for group descriptions
00086 $editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$course->maxbytes, 'trust'=>false, 'context'=>$context, 'noclean'=>true);
00087 if (!empty($group->id)) {
00088     $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', $group->id);
00089 } else {
00090     $group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', null);
00091 }
00092 
00094 $editform = new group_form(null, array('editoroptions'=>$editoroptions));
00095 $editform->set_data($group);
00096 
00097 if ($editform->is_cancelled()) {
00098     redirect($returnurl);
00099 
00100 } elseif ($data = $editform->get_data()) {
00101 
00102     if ($data->id) {
00103         groups_update_group($data, $editform, $editoroptions);
00104     } else {
00105         $id = groups_create_group($data, $editform, $editoroptions);
00106         $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id;
00107     }
00108 
00109     redirect($returnurl);
00110 }
00111 
00112 $strgroups = get_string('groups');
00113 $strparticipants = get_string('participants');
00114 
00115 if ($id) {
00116     $strheading = get_string('editgroupsettings', 'group');
00117 } else {
00118     $strheading = get_string('creategroup', 'group');
00119 }
00120 
00121 $PAGE->navbar->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$courseid)));
00122 $PAGE->navbar->add($strgroups, new moodle_url('/group/index.php', array('id'=>$courseid)));
00123 $PAGE->navbar->add($strheading);
00124 
00126 $PAGE->set_title($strgroups);
00127 $PAGE->set_heading($course->fullname . ': '.$strgroups);
00128 echo $OUTPUT->header();
00129 echo '<div id="grouppicture">';
00130 if ($id) {
00131     print_group_picture($group, $course->id);
00132 }
00133 echo '</div>';
00134 $editform->display();
00135 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations