Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/grade/edit/scale/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 require_once '../../../config.php';
00019 require_once $CFG->dirroot.'/grade/lib.php';
00020 require_once $CFG->dirroot.'/grade/report/lib.php';
00021 require_once 'edit_form.php';
00022 
00023 $courseid = optional_param('courseid', 0, PARAM_INT);
00024 $id       = optional_param('id', 0, PARAM_INT);
00025 
00026 $PAGE->set_url('/grade/edit/scale/edit.php', array('id' => $id, 'courseid' => $courseid));
00027 $PAGE->set_pagelayout('admin');
00028 
00029 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
00030 $heading = '';
00031 
00032 // a bit complex access control :-O
00033 if ($id) {
00034     $heading = get_string('editscale', 'grades');
00035 
00037     if (!$scale_rec = $DB->get_record('scale', array('id' => $id))) {
00038         print_error('invalidscaleid');
00039     }
00040     if ($scale_rec->courseid) {
00041         $scale_rec->standard = 0;
00042         if (!$course = $DB->get_record('course', array('id' => $scale_rec->courseid))) {
00043             print_error('invalidcourseid');
00044         }
00045         require_login($course);
00046         $context = get_context_instance(CONTEXT_COURSE, $course->id);
00047         require_capability('moodle/course:managescales', $context);
00048         $courseid = $course->id;
00049     } else {
00050         if ($courseid) {
00051             if (!$course = $DB->get_record('course', array('id' => $courseid))) {
00052                 print_error('invalidcourseid');
00053             }
00054         }
00055         $scale_rec->standard = 1;
00056         $scale_rec->courseid = $courseid;
00057         require_login($courseid);
00058         require_capability('moodle/course:managescales', $systemcontext);
00059     }
00060 
00061 } else if ($courseid){
00062     $heading = get_string('addscale', 'grades');
00064     if (!$course = $DB->get_record('course', array('id' => $courseid))) {
00065         print_error('nocourseid');
00066     }
00067     $scale_rec = new stdClass();
00068     $scale_rec->standard = 0;
00069     $scale_rec->courseid = $courseid;
00070     require_login($course);
00071     $context = get_context_instance(CONTEXT_COURSE, $course->id);
00072     require_capability('moodle/course:managescales', $context);
00073 
00074 } else {
00076     $scale_rec = new stdClass();
00077     $scale_rec->standard = 1;
00078     $scale_rec->courseid = 0;
00079     require_login();
00080     require_capability('moodle/course:managescales', $systemcontext);
00081 }
00082 
00083 if (!$courseid) {
00084     require_once $CFG->libdir.'/adminlib.php';
00085     admin_externalpage_setup('scales');
00086 }
00087 
00088 // default return url
00089 $gpr = new grade_plugin_return();
00090 $returnurl = $gpr->get_return_url('index.php?id='.$courseid);
00091 $editoroptions = array(
00092     'maxfiles'  => EDITOR_UNLIMITED_FILES,
00093     'maxbytes'  => $CFG->maxbytes,
00094     'trusttext' => false,
00095     'noclean'   => true,
00096     'context'   => $systemcontext
00097 );
00098 
00099 if (!empty($scale_rec->id)) {
00100     $scale_rec = file_prepare_standard_editor($scale_rec, 'description', $editoroptions, $systemcontext, 'grade', 'scale', $scale_rec->id);
00101 } else {
00102     $scale_rec = file_prepare_standard_editor($scale_rec, 'description', $editoroptions, $systemcontext, 'grade', 'scale', null);
00103 }
00104 $mform = new edit_scale_form(null, compact('gpr', 'editoroptions'));
00105 
00106 $mform->set_data($scale_rec);
00107 
00108 if ($mform->is_cancelled()) {
00109     redirect($returnurl);
00110 
00111 } else if ($data = $mform->get_data()) {
00112     $scale = new grade_scale(array('id'=>$id));
00113     $data->userid = $USER->id;
00114 
00115     if (empty($scale->id)) {
00116         $data->description = $data->description_editor['text'];
00117         $data->descriptionformat = $data->description_editor['format'];
00118         grade_scale::set_properties($scale, $data);
00119         if (!has_capability('moodle/grade:manage', $systemcontext)) {
00120             $data->standard = 0;
00121         }
00122         $scale->courseid = !empty($data->standard) ? 0 : $courseid;
00123         $scale->insert();
00124         $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade', 'scale', $scale->id);
00125         $DB->set_field($scale->table, 'description', $data->description, array('id'=>$scale->id));
00126     } else {
00127         $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade', 'scale', $id);
00128         grade_scale::set_properties($scale, $data);
00129         if (isset($data->standard)) {
00130             $scale->courseid = !empty($data->standard) ? 0 : $courseid;
00131         } else {
00132             unset($scale->courseid); // keep previous
00133         }
00134         $scale->update();
00135     }
00136     redirect($returnurl);
00137 }
00138 
00139 if ($courseid) {
00140     print_grade_page_head($course->id, 'scale', 'edit', $heading);
00141 } else {
00142     echo $OUTPUT->header();
00143 }
00144 
00145 $mform->display();
00146 
00147 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations