| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php //$Id: edit_form.php,v 1.10.2.2 2008/03/03 10:21:42 nicolasconnault Exp $ 2 3 /////////////////////////////////////////////////////////////////////////// 4 // // 5 // NOTICE OF COPYRIGHT // 6 // // 7 // Moodle - Modular Object-Oriented Dynamic Learning Environment // 8 // http://moodle.com // 9 // // 10 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com // 11 // // 12 // This program is free software; you can redistribute it and/or modify // 13 // it under the terms of the GNU General Public License as published by // 14 // the Free Software Foundation; either version 2 of the License, or // 15 // (at your option) any later version. // 16 // // 17 // This program is distributed in the hope that it will be useful, // 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 20 // GNU General Public License for more details: // 21 // // 22 // http://www.gnu.org/copyleft/gpl.html // 23 // // 24 /////////////////////////////////////////////////////////////////////////// 25 26 require_once $CFG->libdir.'/formslib.php'; 27 28 class edit_scale_form extends moodleform { 29 function definition() { 30 global $CFG; 31 $mform =& $this->_form; 32 33 // visible elements 34 $mform->addElement('header', 'general', get_string('scale')); 35 36 $mform->addElement('text', 'name', get_string('name'), 'size="40"'); 37 $mform->addRule('name', get_string('required'), 'required', null, 'client'); 38 $mform->setType('name', PARAM_TEXT); 39 40 $mform->addElement('advcheckbox', 'standard', get_string('scalestandard')); 41 $mform->setHelpButton('standard', array('scalestandard', get_string('scalestandard'), 'grade')); 42 43 $mform->addElement('static', 'used', get_string('used')); 44 45 $mform->addElement('textarea', 'scale', get_string('scale'), array('cols'=>50, 'rows'=>2)); 46 $mform->setHelpButton('scale', array('scales', get_string('scale'))); 47 $mform->addRule('scale', get_string('required'), 'required', null, 'client'); 48 $mform->setType('scale', PARAM_TEXT); 49 50 $mform->addElement('htmleditor', 'description', get_string('description'), array('cols'=>80, 'rows'=>20)); 51 52 53 // hidden params 54 $mform->addElement('hidden', 'id', 0); 55 $mform->setType('id', PARAM_INT); 56 57 $mform->addElement('hidden', 'courseid', 0); 58 $mform->setType('courseid', PARAM_INT); 59 60 /// add return tracking info 61 $gpr = $this->_customdata['gpr']; 62 $gpr->add_mform_elements($mform); 63 64 //------------------------------------------------------------------------------- 65 // buttons 66 $this->add_action_buttons(); 67 } 68 69 70 /// tweak the form - depending on existing data 71 function definition_after_data() { 72 global $CFG; 73 74 $mform =& $this->_form; 75 76 $courseid = $mform->getElementValue('courseid'); 77 78 if ($id = $mform->getElementValue('id')) { 79 $scale = grade_scale::fetch(array('id'=>$id)); 80 $used = $scale->is_used(); 81 82 if ($used) { 83 $mform->hardFreeze('scale'); 84 } 85 86 if (empty($courseid)) { 87 $mform->hardFreeze('standard'); 88 89 } else if (empty($scale->courseid) and !has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) { 90 $mform->hardFreeze('standard'); 91 92 } else if ($used and !empty($scale->courseid)) { 93 $mform->hardFreeze('standard'); 94 } 95 96 $usedstr = $scale->is_used() ? get_string('yes') : get_string('no'); 97 $used_el =& $mform->getElement('used'); 98 $used_el->setValue($usedstr); 99 100 } else { 101 $mform->removeElement('used'); 102 if (empty($courseid) or !has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) { 103 $mform->hardFreeze('standard'); 104 } 105 } 106 } 107 108 /// perform extra validation before submission 109 function validation($data, $files) { 110 global $CFG, $COURSE; 111 112 $errors = parent::validation($data, $files); 113 114 // we can not allow 2 scales with the same exact scale as this creates 115 // problems for backup/restore 116 117 $old = grade_scale::fetch(array('id'=>$data['id'])); 118 119 if (array_key_exists('standard', $data)) { 120 if (empty($data['standard'])) { 121 $courseid = $COURSE->id; 122 } else { 123 $courseid = 0; 124 } 125 126 } else { 127 $courseid = $old->courseid; 128 } 129 130 if (array_key_exists('scale', $data)) { 131 $count = count_records('scale', 'courseid', $courseid, 'scale', $data['scale']); 132 133 if (empty($old->id) or $old->courseid != $courseid) { 134 if ($count) { 135 $errors['scale'] = get_string('duplicatescale', 'grades'); 136 } 137 138 } else if ($old->scale != $data['scale']) { 139 if ($count) { 140 $errors['scale'] = get_string('duplicatescale', 'grades'); 141 } 142 } 143 144 $options = explode(',', $data['scale']); 145 if (count($options) < 2) { 146 $errors['scale'] = get_string('error'); 147 } 148 } 149 150 return $errors; 151 } 152 } 153 154 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |