Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/cohort/edit.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 
00028 require('../config.php');
00029 require($CFG->dirroot.'/course/lib.php');
00030 require($CFG->dirroot.'/cohort/lib.php');
00031 require($CFG->dirroot.'/cohort/edit_form.php');
00032 
00033 $id        = optional_param('id', 0, PARAM_INT);
00034 $contextid = optional_param('contextid', 0, PARAM_INT);
00035 $delete    = optional_param('delete', 0, PARAM_BOOL);
00036 $confirm   = optional_param('confirm', 0, PARAM_BOOL);
00037 
00038 require_login();
00039 
00040 $category = null;
00041 if ($id) {
00042     $cohort = $DB->get_record('cohort', array('id'=>$id), '*', MUST_EXIST);
00043     $context = get_context_instance_by_id($cohort->contextid, MUST_EXIST);
00044 } else {
00045     $context = get_context_instance_by_id($contextid, MUST_EXIST);
00046     if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
00047         print_error('invalidcontext');
00048     }
00049     $cohort = new stdClass();
00050     $cohort->id          = 0;
00051     $cohort->contextid   = $context->id;
00052     $cohort->name        = '';
00053     $cohort->description = '';
00054 }
00055 
00056 require_capability('moodle/cohort:manage', $context);
00057 
00058 $returnurl = new moodle_url('/cohort/index.php', array('contextid'=>$context->id));
00059 
00060 if (!empty($cohort->component)) {
00061     // we can not manually edit cohorts that were created by external systems, sorry
00062     redirect($returnurl);
00063 }
00064 
00065 $PAGE->set_context($context);
00066 $PAGE->set_url('/cohort/edit.php', array('contextid'=>$context->id, 'id'=>$cohort->id));
00067 $PAGE->set_context($context);
00068 
00069 if ($context->contextlevel == CONTEXT_COURSECAT) {
00070     $category = $DB->get_record('course_categories', array('id'=>$context->instanceid), '*', MUST_EXIST);
00071     navigation_node::override_active_url(new moodle_url('/cohort/index.php', array('contextid'=>$cohort->contextid)));
00072     $PAGE->set_pagelayout('report');
00073 
00074 } else {
00075     navigation_node::override_active_url(new moodle_url('/cohort/index.php', array()));
00076     $PAGE->set_pagelayout('admin');
00077 }
00078 
00079 if ($delete and $cohort->id) {
00080     $PAGE->url->param('delete', 1);
00081     if ($confirm and confirm_sesskey()) {
00082         cohort_delete_cohort($cohort);
00083         redirect($returnurl);
00084     }
00085     $strheading = get_string('delcohort', 'cohort');
00086     $PAGE->navbar->add($strheading);
00087     $PAGE->set_title($strheading);
00088     $PAGE->set_heading($COURSE->fullname);
00089     echo $OUTPUT->header();
00090     echo $OUTPUT->heading($strheading);
00091     $yesurl = new moodle_url('/cohort/edit.php', array('id'=>$cohort->id, 'delete'=>1, 'confirm'=>1,'sesskey'=>sesskey()));
00092     $message = get_string('delconfirm', 'cohort', format_string($cohort->name));
00093     echo $OUTPUT->confirm($message, $yesurl, $returnurl);
00094     echo $OUTPUT->footer();
00095     die;
00096 }
00097 
00098 $editoroptions = array('maxfiles'=>0, 'context'=>$context);
00099 if ($cohort->id) {
00100     // edit existing
00101     $cohort = file_prepare_standard_editor($cohort, 'description', $editoroptions, $context);
00102     $strheading = get_string('editcohort', 'cohort');
00103 
00104 } else {
00105     // add new
00106     $cohort = file_prepare_standard_editor($cohort, 'description', $editoroptions, $context);
00107     $strheading = get_string('addcohort', 'cohort');
00108 }
00109 
00110 $PAGE->set_title($strheading);
00111 $PAGE->set_heading($COURSE->fullname);
00112 $PAGE->navbar->add($strheading);
00113 
00114 $editform = new cohort_edit_form(null, array('editoroptions'=>$editoroptions, 'data'=>$cohort));
00115 
00116 if ($editform->is_cancelled()) {
00117     redirect($returnurl);
00118 
00119 } else if ($data = $editform->get_data()) {
00120     $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $context);
00121 
00122     if ($data->id) {
00123         cohort_update_cohort($data);
00124     } else {
00125         cohort_add_cohort($data);
00126     }
00127 
00128     // use new context id, it could have been changed
00129     redirect(new moodle_url('/cohort/index.php', array('contextid'=>$data->contextid)));
00130 }
00131 
00132 echo $OUTPUT->header();
00133 echo $OUTPUT->heading($strheading);
00134 echo $editform->display();
00135 echo $OUTPUT->footer();
00136 
 All Data Structures Namespaces Files Functions Variables Enumerations