|
Moodle
2.2.1
http://www.collinsharper.com
|
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 00027 require_once("../config.php"); 00028 require_once($CFG->dirroot."/question/editlib.php"); 00029 require_once($CFG->dirroot."/question/category_class.php"); 00030 00031 list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = 00032 question_edit_setup('categories', '/question/category.php'); 00033 00034 // get values from form for actions on this page 00035 $param = new stdClass(); 00036 $param->moveup = optional_param('moveup', 0, PARAM_INT); 00037 $param->movedown = optional_param('movedown', 0, PARAM_INT); 00038 $param->moveupcontext = optional_param('moveupcontext', 0, PARAM_INT); 00039 $param->movedowncontext = optional_param('movedowncontext', 0, PARAM_INT); 00040 $param->tocontext = optional_param('tocontext', 0, PARAM_INT); 00041 $param->left = optional_param('left', 0, PARAM_INT); 00042 $param->right = optional_param('right', 0, PARAM_INT); 00043 $param->delete = optional_param('delete', 0, PARAM_INT); 00044 $param->confirm = optional_param('confirm', 0, PARAM_INT); 00045 $param->cancel = optional_param('cancel', '', PARAM_ALPHA); 00046 $param->move = optional_param('move', 0, PARAM_INT); 00047 $param->moveto = optional_param('moveto', 0, PARAM_INT); 00048 $param->edit = optional_param('edit', 0, PARAM_INT); 00049 00050 $url = new moodle_url($thispageurl); 00051 foreach ((array)$param as $key=>$value) { 00052 if (($key !== 'cancel' && $value !== 0) || ($key === 'cancel' && $value !== '')) { 00053 $url->param($key, $value); 00054 } 00055 } 00056 $PAGE->set_url($url); 00057 00058 $qcobject = new question_category_object($pagevars['cpage'], $thispageurl, $contexts->having_one_edit_tab_cap('categories'), $param->edit, $pagevars['cat'], $param->delete, 00059 $contexts->having_cap('moodle/question:add')); 00060 00061 $streditingcategories = get_string('editcategories', 'question'); 00062 if ($param->left || $param->right || $param->moveup || $param->movedown|| $param->moveupcontext || $param->movedowncontext){ 00063 require_sesskey(); 00064 foreach ($qcobject->editlists as $list){ 00065 //processing of these actions is handled in the method where appropriate and page redirects. 00066 $list->process_actions($param->left, $param->right, $param->moveup, $param->movedown, 00067 $param->moveupcontext, $param->movedowncontext, $param->tocontext); 00068 } 00069 } 00070 if ($param->delete && ($questionstomove = $DB->count_records("question", array("category" => $param->delete)))){ 00071 if (!$category = $DB->get_record("question_categories", array("id" => $param->delete))) { // security 00072 print_error('nocate', 'question', $thispageurl->out(), $param->delete); 00073 } 00074 $categorycontext = get_context_instance_by_id($category->contextid); 00075 $qcobject->moveform = new question_move_form($thispageurl, 00076 array('contexts'=>array($categorycontext), 'currentcat'=>$param->delete)); 00077 if ($qcobject->moveform->is_cancelled()){ 00078 redirect($thispageurl); 00079 } elseif ($formdata = $qcobject->moveform->get_data()) { 00081 list($tocategoryid, $tocontextid) = explode(',', $formdata->category); 00082 $qcobject->move_questions_and_delete_category($formdata->delete, $tocategoryid); 00083 $thispageurl->remove_params('cat', 'category'); 00084 redirect($thispageurl); 00085 } 00086 } else { 00087 $questionstomove = 0; 00088 } 00089 if ($qcobject->catform->is_cancelled()) { 00090 redirect($thispageurl); 00091 } else if ($catformdata = $qcobject->catform->get_data()) { 00092 if (!$catformdata->id) {//new category 00093 $qcobject->add_category($catformdata->parent, $catformdata->name, $catformdata->info); 00094 } else { 00095 $qcobject->update_category($catformdata->id, $catformdata->parent, $catformdata->name, $catformdata->info); 00096 } 00097 redirect($thispageurl); 00098 } else if ((!empty($param->delete) and (!$questionstomove) and confirm_sesskey())) { 00099 $qcobject->delete_category($param->delete);//delete the category now no questions to move 00100 $thispageurl->remove_params('cat', 'category'); 00101 redirect($thispageurl); 00102 } 00103 00104 if ($param->edit){ 00105 $PAGE->navbar->add(get_string('editingcategory', 'question')); 00106 } 00107 00108 $PAGE->set_title($streditingcategories); 00109 $PAGE->set_heading($COURSE->fullname); 00110 echo $OUTPUT->header(); 00111 00112 // display UI 00113 if (!empty($param->edit)) { 00114 $qcobject->edit_single_category($param->edit); 00115 } else if ($questionstomove){ 00116 $qcobject->display_move_form($questionstomove, $category); 00117 } else { 00118 // display the user interface 00119 $qcobject->display_user_interface(); 00120 } 00121 echo $OUTPUT->footer();