| [ 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.7.2.1 2007/11/23 22:12:38 skodak Exp $ 2 require_once ($CFG->dirroot.'/lib/formslib.php'); 3 4 class mod_glossary_entry_form extends moodleform { 5 6 function definition() { 7 8 global $CFG, $COURSE; 9 $mform =& $this->_form; 10 11 $glossary =& $this->_customdata['glossary']; 12 $mode =& $this->_customdata['mode']; 13 $cm =& $this->_customdata['cm']; 14 $hook =& $this->_customdata['hook']; 15 $e =& $this->_customdata['e']; 16 17 //------------------------------------------------------------------------------- 18 $mform->addElement('header', 'general', get_string('general', 'form')); 19 20 $mform->addElement('text', 'concept', get_string('concept', 'glossary')); 21 $mform->setType('concept', PARAM_TEXT); 22 $mform->addRule('concept', null, 'required', null, 'client'); 23 24 $mform->addElement('htmleditor', 'definition', get_string('definition', 'glossary'), array('rows'=>20)); 25 $mform->setType('definition', PARAM_RAW); 26 $mform->addRule('definition', null, 'required', null, 'client'); 27 $mform->setHelpButton('definition', array('writing', 'richtext'), false, 'editorhelpbutton'); 28 29 $mform->addElement('format'); 30 31 $categories = array(); 32 if ($categories = get_records_menu('glossary_categories', 'glossaryid', $glossary->id, 'name ASC', 'id, name')){ 33 $categories = array(0 => get_string('notcategorised', 'glossary')) + $categories; 34 } else { 35 $categories = array(0 => get_string('notcategorised', 'glossary')); 36 } 37 38 $categoriesEl =& $mform->addElement('select', 'categories', get_string('categories', 'glossary'), $categories); 39 $categoriesEl->setMultiple(true); 40 $categoriesEl->setSize(5); 41 42 $mform->addElement('textarea', 'aliases', get_string('aliases', 'glossary'), 'rows="2" cols="40"'); 43 $mform->setType('aliases', PARAM_TEXT); 44 $mform->setHelpButton('aliases', array('aliases2', strip_tags(get_string('aliases', 'glossary')), 'glossary')); 45 46 $this->set_upload_manager(new upload_manager('attachment', true, false, $COURSE, false, 0, true, true, false)); 47 $mform->addElement('file', 'attachment', get_string('attachment', 'forum')); 48 $mform->setHelpButton('attachment', array('attachment', get_string('attachment', 'glossary'), 'glossary')); 49 50 if (isset($CFG->glossary_linkentries)) { 51 $usedynalink = $CFG->glossary_linkentries; 52 } else { 53 $usedynalink = 0; 54 } 55 if (isset($CFG->glossary_casesensitive)) { 56 $casesensitive = $CFG->glossary_casesensitive; 57 } else { 58 $casesensitive = 0; 59 } 60 if (isset($CFG->glossary_fullmatch)) { 61 $fullmatch = $CFG->glossary_fullmatch; 62 } else { 63 $fullmatch = 0; 64 } 65 if ( !$glossary->usedynalink ) { 66 $mform->addElement('hidden', 'usedynalink', $usedynalink); 67 $mform->addElement('hidden', 'casesensitive', $casesensitive); 68 $mform->addElement('hidden', 'fullmatch', $fullmatch); 69 } else { 70 //------------------------------------------------------------------------------- 71 $mform->addElement('header', 'linkinghdr', get_string('linking', 'glossary')); 72 73 $mform->addElement('checkbox', 'usedynalink', get_string('entryusedynalink', 'glossary')); 74 $mform->setHelpButton('usedynalink', array('usedynalinkentry', strip_tags(get_string('usedynalink', 'glossary')), 'glossary')); 75 $mform->setDefault('usedynalink', $usedynalink); 76 77 $mform->addElement('checkbox', 'casesensitive', get_string('casesensitive', 'glossary')); 78 $mform->setHelpButton('casesensitive', array('casesensitive', strip_tags(get_string('casesensitive', 'glossary')), 'glossary')); 79 $mform->disabledIf('casesensitive', 'usedynalink'); 80 $mform->setDefault('casesensitive', $casesensitive); 81 82 $mform->addElement('checkbox', 'fullmatch', get_string('fullmatch', 'glossary')); 83 $mform->setHelpButton('fullmatch', array('fullmatch', strip_tags(get_string('fullmatch', 'glossary')), 'glossary')); 84 $mform->disabledIf('fullmatch', 'usedynalink'); 85 $mform->setDefault('fullmatch', $fullmatch); 86 } 87 88 $mform->addElement('hidden', 'e', $e); 89 $mform->addElement('hidden', 'id', $cm->id); 90 $mform->addElement('hidden', 'mode', $mode); 91 $mform->addElement('hidden', 'hook', $hook); 92 93 //------------------------------------------------------------------------------- 94 $this->add_action_buttons(); 95 } 96 97 function validation($data, $files) { 98 global $CFG, $USER; 99 $errors = parent::validation($data, $files); 100 $e = $this->_customdata['e']; 101 $glossary = $this->_customdata['glossary']; 102 $context = $this->_customdata['context']; 103 $data['concept'] = trim($data['concept']); 104 if ($e) { 105 //We are updating an entry, so we compare current session user with 106 //existing entry user to avoid some potential problems if secureforms=off 107 //Perhaps too much security? Anyway thanks to skodak (Bug 1823) 108 $old = get_record('glossary_entries', 'id', $e); 109 $ineditperiod = ((time() - $old->timecreated < $CFG->maxeditingtime) || $glossary->editalways); 110 if ( (!$ineditperiod || $USER->id != $old->userid) and !has_capability('mod/glossary:manageentries', $context)) { 111 if ( $USER->id != $old->userid ) { 112 $errors['concept'] = get_string('errcannoteditothers', 'glossary'); 113 } elseif (!$ineditperiod) { 114 $errors['concept'] = get_string('erredittimeexpired', 'glossary'); 115 } 116 } 117 if ( !$glossary->allowduplicatedentries ) { 118 if ($dupentries = get_records('glossary_entries', 'lower(concept)', moodle_strtolower($data['concept']))) { 119 foreach ($dupentries as $curentry) { 120 if ( $glossary->id == $curentry->glossaryid ) { 121 if ( $curentry->id != $e ) { 122 $errors['concept'] = get_string('errconceptalreadyexists', 'glossary'); 123 break; 124 } 125 } 126 } 127 } 128 } 129 130 } else { 131 if ( !$glossary->allowduplicatedentries ) { 132 if ($dupentries = get_record('glossary_entries', 'lower(concept)', moodle_strtolower($data['concept']), 'glossaryid', $glossary->id)) { 133 $errors['concept'] = get_string('errconceptalreadyexists', 'glossary'); 134 } 135 } 136 } 137 return $errors; 138 } 139 140 } 141 ?>
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 |