1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Form to edit handlers. 19 * 20 * @package tool_messageinbound 21 * @copyright 2014 Andrew Nicols 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 require_once($CFG->libdir . '/formslib.php'); 28 29 /** 30 * Form to edit handlers. 31 * 32 * @copyright 2014 Andrew Nicols 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class tool_messageinbound_edit_handler_form extends moodleform { 36 37 /** 38 * The form definition 39 */ 40 public function definition() { 41 $mform = $this->_form; 42 43 $handler = $this->_customdata['handler']; 44 45 // Set up the options for formatting text for descriptions, etc. 46 $formatoptions = new stdClass(); 47 $formatoptions->trusted = false; 48 $formatoptions->noclean = false; 49 $formatoptions->smiley = false; 50 $formatoptions->filter = false; 51 $formatoptions->para = true; 52 $formatoptions->newlines = false; 53 $formatoptions->overflowdiv = true; 54 55 // General information about the handler. 56 $mform->addElement('header', 'general', get_string('general')); 57 $mform->addElement('static', 'name', get_string('name', 'tool_messageinbound'), 58 $handler->name); 59 $mform->addElement('static', 'classname', get_string('classname', 'tool_messageinbound')); 60 61 $description = format_text($handler->description, FORMAT_MARKDOWN, $formatoptions); 62 63 $mform->addElement('static', 'description', get_string('description', 'tool_messageinbound'), 64 $description); 65 66 // Items which can be configured. 67 $mform->addElement('header', 'configuration', get_string('configuration')); 68 69 if ($handler->can_change_defaultexpiration()) { 70 // Show option to change expiry only if the handler supports it. 71 $options = array( 72 HOURSECS => get_string('onehour', 'tool_messageinbound'), 73 DAYSECS => get_string('oneday', 'tool_messageinbound'), 74 WEEKSECS => get_string('oneweek', 'tool_messageinbound'), 75 YEARSECS => get_string('oneyear', 'tool_messageinbound'), 76 0 => get_string('noexpiry', 'tool_messageinbound'), 77 ); 78 $mform->addElement('select', 'defaultexpiration', get_string('defaultexpiration', 'tool_messageinbound'), $options); 79 $mform->addHelpButton('defaultexpiration', 'defaultexpiration', 'tool_messageinbound'); 80 } else { 81 $text = $this->get_defaultexpiration_text($handler); 82 $mform->addElement('static', 'defaultexpiration_fake', get_string('defaultexpiration', 'tool_messageinbound'), $text); 83 $mform->addElement('hidden', 'defaultexpiration'); 84 $mform->addHelpButton('defaultexpiration_fake', 'defaultexpiration', 'tool_messageinbound'); 85 $mform->setType('defaultexpiration', PARAM_INT); 86 } 87 88 if ($handler->can_change_validateaddress()) { 89 $mform->addElement('checkbox', 'validateaddress', get_string('requirevalidation', 'tool_messageinbound')); 90 $mform->addHelpButton('validateaddress', 'validateaddress', 'tool_messageinbound'); 91 } else { 92 if ($handler->validateaddress) { 93 $text = get_string('yes'); 94 } else { 95 $text = get_string('no'); 96 } 97 $mform->addElement('static', 'validateaddress_fake', get_string('requirevalidation', 'tool_messageinbound'), $text); 98 $mform->addElement('hidden', 'validateaddress'); 99 $mform->addHelpButton('validateaddress_fake', 'fixedvalidateaddress', 'tool_messageinbound'); 100 $mform->setType('validateaddress', PARAM_INT); 101 } 102 103 if ($handler->can_change_enabled()) { 104 $mform->addElement('checkbox', 'enabled', get_string('enabled', 'tool_messageinbound')); 105 } else { 106 if ($handler->enabled) { 107 $text = get_string('yes'); 108 } else { 109 $text = get_string('no'); 110 } 111 $mform->addElement('static', 'enabled_fake', get_string('enabled', 'tool_messageinbound'), $text); 112 $mform->addHelpButton('enabled', 'fixedenabled', 'tool_messageinbound'); 113 $mform->addElement('hidden', 'enabled'); 114 $mform->setType('enabled', PARAM_INT); 115 } 116 117 $this->add_action_buttons(true, get_string('savechanges')); 118 } 119 120 /** 121 * Return a text string representing the selected default expiration for the handler. 122 * 123 * @param \core\message\inbound\handler $handler handler instance. 124 * 125 * @return string localised text string. 126 */ 127 protected function get_defaultexpiration_text(\core\message\inbound\handler $handler) { 128 switch($handler->defaultexpiration) { 129 case HOURSECS : 130 return get_string('onehour', 'tool_messageinbound'); 131 case DAYSECS : 132 return get_string('oneday', 'tool_messageinbound'); 133 case WEEKSECS : 134 return get_string('oneweek', 'tool_messageinbound'); 135 case YEARSECS : 136 return get_string('oneyear', 'tool_messageinbound'); 137 case 0: 138 return get_string('noexpiry', 'tool_messageinbound'); 139 default: 140 return ''; // Should never happen. 141 } 142 } 143 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body