|
Moodle
2.2.1
http://www.collinsharper.com
|
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 00027 require_once("../../config.php"); 00028 require_once($CFG->dirroot.'/mod/lesson/locallib.php'); 00029 require_once('editpage_form.php'); 00030 00031 // first get the preceeding page 00032 $pageid = required_param('pageid', PARAM_INT); 00033 $id = required_param('id', PARAM_INT); // Course Module ID 00034 $qtype = optional_param('qtype', 0, PARAM_INT); 00035 $edit = optional_param('edit', false, PARAM_BOOL); 00036 00037 $cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST);; 00038 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); 00039 $lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST)); 00040 00041 require_login($course, false, $cm); 00042 00043 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00044 require_capability('mod/lesson:edit', $context); 00045 00046 $PAGE->set_url('/mod/lesson/editpage.php', array('pageid'=>$pageid, 'id'=>$id, 'qtype'=>$qtype)); 00047 00048 if ($edit) { 00049 $editpage = lesson_page::load($pageid, $lesson); 00050 $qtype = $editpage->qtype; 00051 $edit = true; 00052 } else { 00053 $edit = false; 00054 } 00055 00056 $jumpto = lesson_page::get_jumptooptions($pageid, $lesson); 00057 $manager = lesson_page_type_manager::get($lesson); 00058 $editoroptions = array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes); 00059 00060 // If the previous page was the Question type selection form, this form 00061 // will have a different name (e.g. _qf__lesson_add_page_form_selection 00062 // versus _qf__lesson_add_page_form_multichoice). This causes confusion 00063 // in moodleform::_process_submission because the array key check doesn't 00064 // tie up with the current form name, which in turn means the "submitted" 00065 // check ends up evaluating as false, thus it's not possible to check whether 00066 // the Question type selection was cancelled. For this reason, a dummy form 00067 // is created here solely to check whether the selection was cancelled. 00068 if ($qtype) { 00069 $mformdummy = $manager->get_page_form(0, array('editoroptions'=>$editoroptions, 'jumpto'=>$jumpto, 'lesson'=>$lesson, 'edit'=>$edit, 'maxbytes'=>$PAGE->course->maxbytes)); 00070 if ($mformdummy->is_cancelled()) { 00071 redirect("$CFG->wwwroot/mod/lesson/edit.php?id=$id"); 00072 exit; 00073 } 00074 } 00075 00076 $mform = $manager->get_page_form($qtype, array('editoroptions'=>$editoroptions, 'jumpto'=>$jumpto, 'lesson'=>$lesson, 'edit'=>$edit, 'maxbytes'=>$PAGE->course->maxbytes)); 00077 00078 if ($mform->is_cancelled()) { 00079 redirect("$CFG->wwwroot/mod/lesson/edit.php?id=$id"); 00080 exit; 00081 } 00082 00083 if ($edit) { 00084 $data = $editpage->properties(); 00085 $data->pageid = $editpage->id; 00086 $data->id = $cm->id; 00087 $editoroptions['context'] = $context; 00088 $data = file_prepare_standard_editor($data, 'contents', $editoroptions, $context, 'mod_lesson', 'page_contents', $editpage->id); 00089 $mform->set_data($data); 00090 $PAGE->navbar->add(get_string('edit'), new moodle_url('/mod/lesson/edit.php', array('id'=>$id))); 00091 $PAGE->navbar->add(get_string('editingquestionpage', 'lesson', get_string($mform->qtypestring, 'lesson'))); 00092 } else { 00093 // Give the page type being created a chance to override the creation process 00094 // this is used by endofbranch, cluster, and endofcluster to skip the creation form. 00095 // IT SHOULD ALWAYS CALL require_sesskey(); 00096 $mform->construction_override($pageid, $lesson); 00097 00098 $data = new stdClass; 00099 $data->id = $cm->id; 00100 $data->pageid = $pageid; 00101 if ($qtype) { 00102 //TODO: the handling of form for the selection of question type is a bloody hack! (skodak) 00103 $data->qtype = $qtype; 00104 } 00105 $data = file_prepare_standard_editor($data, 'contents', $editoroptions, null); 00106 $mform->set_data($data); 00107 $PAGE->navbar->add(get_string('addanewpage', 'lesson'), $PAGE->url); 00108 if ($qtype !== 'unknown') { 00109 $PAGE->navbar->add(get_string($mform->qtypestring, 'lesson')); 00110 } 00111 } 00112 00113 if ($data = $mform->get_data()) { 00114 require_sesskey(); 00115 if ($edit) { 00116 $data->lessonid = $data->id; 00117 $data->id = $data->pageid; 00118 unset($data->pageid); 00119 unset($data->edit); 00120 $editpage->update($data, $context, $PAGE->course->maxbytes); 00121 } else { 00122 $editpage = lesson_page::create($data, $lesson, $context, $PAGE->course->maxbytes); 00123 } 00124 redirect(new moodle_url('/mod/lesson/edit.php', array('id'=>$cm->id))); 00125 } 00126 00127 $lessonoutput = $PAGE->get_renderer('mod_lesson'); 00128 echo $lessonoutput->header($lesson, $cm); 00129 $mform->display(); 00130 echo $lessonoutput->footer();