Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/feedback/edit_item.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00025 require_once("../../config.php");
00026 require_once("lib.php");
00027 
00028 feedback_init_feedback_session();
00029 
00030 $cmid = required_param('cmid', PARAM_INT);
00031 $typ = optional_param('typ', false, PARAM_ALPHA);
00032 $id = optional_param('id', false, PARAM_INT);
00033 $action = optional_param('action', false, PARAM_ALPHA);
00034 
00035 $editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$cmid));
00036 
00037 if (!$typ) {
00038     redirect($editurl->out(false));
00039 }
00040 
00041 $url = new moodle_url('/mod/feedback/edit_item.php', array('cmid'=>$cmid));
00042 if ($typ !== false) {
00043     $url->param('typ', $typ);
00044 }
00045 if ($id !== false) {
00046     $url->param('id', $id);
00047 }
00048 $PAGE->set_url($url);
00049 
00050 // set up some general variables
00051 $usehtmleditor = can_use_html_editor();
00052 
00053 
00054 if (($formdata = data_submitted()) AND !confirm_sesskey()) {
00055     print_error('invalidsesskey');
00056 }
00057 
00058 if (! $cm = get_coursemodule_from_id('feedback', $cmid)) {
00059     print_error('invalidcoursemodule');
00060 }
00061 
00062 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
00063     print_error('coursemisconf');
00064 }
00065 
00066 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
00067     print_error('invalidcoursemodule');
00068 }
00069 
00070 if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
00071         print_error('badcontext');
00072 }
00073 
00074 require_login($course->id, true, $cm);
00075 
00076 require_capability('mod/feedback:edititems', $context);
00077 
00078 //if the typ is pagebreak so the item will be saved directly
00079 if ($typ == 'pagebreak') {
00080     feedback_create_pagebreak($feedback->id);
00081     redirect($editurl->out(false));
00082     exit;
00083 }
00084 
00085 //get the existing item or create it
00086 // $formdata->itemid = isset($formdata->itemid) ? $formdata->itemid : NULL;
00087 if ($id and $item = $DB->get_record('feedback_item', array('id'=>$id))) {
00088     $typ = $item->typ;
00089 } else {
00090     $item = new stdClass();
00091     $item->id = null;
00092     $item->position = -1;
00093     if (!$typ) {
00094         print_error('typemissing', 'feedback', $editurl->out(false));
00095     }
00096     $item->typ = $typ;
00097     $item->options = '';
00098 }
00099 
00100 require_once($CFG->dirroot.'/mod/feedback/item/'.$typ.'/lib.php');
00101 
00102 $itemobj = feedback_get_item_class($typ);
00103 
00104 $itemobj->build_editform($item, $feedback, $cm);
00105 
00106 if ($itemobj->is_cancelled()) {
00107     redirect($editurl->out(false));
00108     exit;
00109 }
00110 if ($itemobj->get_data()) {
00111     if ($item = $itemobj->save_item()) {
00112         feedback_move_item($item, $item->position);
00113         redirect($editurl->out(false));
00114     }
00115 }
00116 
00119 $strfeedbacks = get_string("modulenameplural", "feedback");
00120 $strfeedback  = get_string("modulename", "feedback");
00121 
00122 if ($item->id) {
00123     $PAGE->navbar->add(get_string('edit_item', 'feedback'));
00124 } else {
00125     $PAGE->navbar->add(get_string('add_item', 'feedback'));
00126 }
00127 $PAGE->set_heading(format_string($course->fullname));
00128 $PAGE->set_title(format_string($feedback->name));
00129 echo $OUTPUT->header();
00131 require('tabs.php');
00133 echo $OUTPUT->heading(format_text($feedback->name));
00134 //print errormsg
00135 if (isset($error)) {
00136     echo $error;
00137 }
00138 $itemobj->show_editform();
00139 
00140 if ($typ!='label') {
00141     $PAGE->requires->js('/mod/feedback/feedback.js');
00142     $PAGE->requires->js_function_call('set_item_focus', Array('id_itemname'));
00143 }
00144 
00149 
00150 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations