[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 * LDAP enrolment plugin admin setting classes 19 * 20 * @package enrol_ldap 21 * @author Iñaki Arenaza 22 * @copyright 2010 Iñaki Arenaza <iarenaza@eps.mondragon.edu> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 class admin_setting_configtext_trim_lower extends admin_setting_configtext { 29 /* @var boolean whether to lowercase the value or not before writing in to the db */ 30 private $lowercase; 31 32 /** 33 * Constructor: uses parent::__construct 34 * 35 * @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins. 36 * @param string $visiblename localised 37 * @param string $description long localised info 38 * @param string $defaultsetting default value for the setting 39 * @param boolean $lowercase if true, lowercase the value before writing it to the db. 40 * @param boolean $enabled if true, the input field is enabled, otherwise it's disabled. 41 */ 42 public function __construct($name, $visiblename, $description, $defaultsetting, $lowercase=false, $enabled=true) { 43 $this->lowercase = $lowercase; 44 $this->enabled = $enabled; 45 parent::__construct($name, $visiblename, $description, $defaultsetting); 46 } 47 48 /** 49 * Saves the setting(s) provided in $data 50 * 51 * @param array $data An array of data, if not array returns empty str 52 * @return mixed empty string on useless data or success, error string if failed 53 */ 54 public function write_setting($data) { 55 if ($this->paramtype === PARAM_INT and $data === '') { 56 // do not complain if '' used instead of 0 57 $data = 0; 58 } 59 60 // $data is a string 61 $validated = $this->validate($data); 62 if ($validated !== true) { 63 return $validated; 64 } 65 if ($this->lowercase) { 66 $data = core_text::strtolower($data); 67 } 68 if (!$this->enabled) { 69 return ''; 70 } 71 return ($this->config_write($this->name, trim($data)) ? '' : get_string('errorsetting', 'admin')); 72 } 73 74 /** 75 * Return an XHTML string for the setting 76 * @return string Returns an XHTML string 77 */ 78 public function output_html($data, $query='') { 79 $default = $this->get_defaultsetting(); 80 $disabled = $this->enabled ? '': ' disabled="disabled"'; 81 return format_admin_setting($this, $this->visiblename, 82 '<div class="form-text defaultsnext"><input type="text" size="'.$this->size.'" id="'.$this->get_id().'" name="'.$this->get_full_name().'" value="'.s($data).'" '.$disabled.' /></div>', 83 $this->description, true, '', $default, $query); 84 } 85 86 } 87 88 class admin_setting_ldap_rolemapping extends admin_setting { 89 90 /** 91 * Constructor: uses parent::__construct 92 * 93 * @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins. 94 * @param string $visiblename localised 95 * @param string $description long localised info 96 * @param string $defaultsetting default value for the setting (actually unused) 97 */ 98 public function __construct($name, $visiblename, $description, $defaultsetting) { 99 parent::__construct($name, $visiblename, $description, $defaultsetting); 100 } 101 102 /** 103 * Returns the current setting if it is set 104 * 105 * @return mixed null if null, else an array 106 */ 107 public function get_setting() { 108 $roles = role_fix_names(get_all_roles()); 109 $result = array(); 110 foreach ($roles as $role) { 111 $contexts = $this->config_read('contexts_role'.$role->id); 112 $memberattribute = $this->config_read('memberattribute_role'.$role->id); 113 $result[] = array('id' => $role->id, 114 'name' => $role->localname, 115 'contexts' => $contexts, 116 'memberattribute' => $memberattribute); 117 } 118 return $result; 119 } 120 121 /** 122 * Saves the setting(s) provided in $data 123 * 124 * @param array $data An array of data, if not array returns empty str 125 * @return mixed empty string on useless data or success, error string if failed 126 */ 127 public function write_setting($data) { 128 if(!is_array($data)) { 129 return ''; // ignore it 130 } 131 132 $result = ''; 133 foreach ($data as $roleid => $data) { 134 if (!$this->config_write('contexts_role'.$roleid, trim($data['contexts']))) { 135 $return = get_string('errorsetting', 'admin'); 136 } 137 if (!$this->config_write('memberattribute_role'.$roleid, core_text::strtolower(trim($data['memberattribute'])))) { 138 $return = get_string('errorsetting', 'admin'); 139 } 140 } 141 return $result; 142 } 143 144 /** 145 * Returns XHTML field(s) as required by choices 146 * 147 * Relies on data being an array should data ever be another valid vartype with 148 * acceptable value this may cause a warning/error 149 * if (!is_array($data)) would fix the problem 150 * 151 * @todo Add vartype handling to ensure $data is an array 152 * 153 * @param array $data An array of checked values 154 * @param string $query 155 * @return string XHTML field 156 */ 157 public function output_html($data, $query='') { 158 $return = html_writer::start_tag('div', array('style' =>'float:left; width:auto; margin-right: 0.5em;')); 159 $return .= html_writer::tag('div', get_string('roles', 'role'), array('style' => 'height: 2em;')); 160 foreach ($data as $role) { 161 $return .= html_writer::tag('div', s($role['name']), array('style' => 'height: 2em;')); 162 } 163 $return .= html_writer::end_tag('div'); 164 165 $return .= html_writer::start_tag('div', array('style' => 'float:left; width:auto; margin-right: 0.5em;')); 166 $return .= html_writer::tag('div', get_string('contexts', 'enrol_ldap'), array('style' => 'height: 2em;')); 167 foreach ($data as $role) { 168 $contextid = $this->get_id().'['.$role['id'].'][contexts]'; 169 $contextname = $this->get_full_name().'['.$role['id'].'][contexts]'; 170 $return .= html_writer::start_tag('div', array('style' => 'height: 2em;')); 171 $return .= html_writer::label(get_string('role_mapping_context', 'enrol_ldap', $role['name']), $contextid, false, array('class' => 'accesshide')); 172 $attrs = array('type' => 'text', 'size' => '40', 'id' => $contextid, 'name' => $contextname, 'value' => s($role['contexts'])); 173 $return .= html_writer::empty_tag('input', $attrs); 174 $return .= html_writer::end_tag('div'); 175 } 176 $return .= html_writer::end_tag('div'); 177 178 $return .= html_writer::start_tag('div', array('style' => 'float:left; width:auto; margin-right: 0.5em;')); 179 $return .= html_writer::tag('div', get_string('memberattribute', 'enrol_ldap'), array('style' => 'height: 2em;')); 180 foreach ($data as $role) { 181 $memberattrid = $this->get_id().'['.$role['id'].'][memberattribute]'; 182 $memberattrname = $this->get_full_name().'['.$role['id'].'][memberattribute]'; 183 $return .= html_writer::start_tag('div', array('style' => 'height: 2em;')); 184 $return .= html_writer::label(get_string('role_mapping_attribute', 'enrol_ldap', $role['name']), $memberattrid, false, array('class' => 'accesshide')); 185 $attrs = array('type' => 'text', 'size' => '15', 'id' => $memberattrid, 'name' => $memberattrname, 'value' => s($role['memberattribute'])); 186 $return .= html_writer::empty_tag('input', $attrs); 187 $return .= html_writer::end_tag('div'); 188 } 189 $return .= html_writer::end_tag('div'); 190 $return .= html_writer::tag('div', '', array('style' => 'clear:both;')); 191 192 return format_admin_setting($this, $this->visiblename, $return, 193 $this->description, true, '', '', $query); 194 } 195 } 196 197 /** 198 * Class implements new specialized setting for course categories that are loaded 199 * only when required 200 * @author Darko Miletic 201 * 202 */ 203 class enrol_ldap_admin_setting_category extends admin_setting_configselect { 204 public function __construct($name, $visiblename, $description) { 205 parent::__construct($name, $visiblename, $description, 1, null); 206 } 207 208 public function load_choices() { 209 if (is_array($this->choices)) { 210 return true; 211 } 212 213 $this->choices = make_categories_options(); 214 return true; 215 } 216 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |