|
Moodle
2.2.1
http://www.collinsharper.com
|
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 00028 defined('MOODLE_INTERNAL') || die(); 00029 00030 class admin_setting_configtext_trim_lower extends admin_setting_configtext { 00031 /* @var boolean whether to lowercase the value or not before writing in to the db */ 00032 private $lowercase; 00033 00043 public function __construct($name, $visiblename, $description, $defaultsetting, $lowercase=false) { 00044 $this->lowercase = $lowercase; 00045 parent::__construct($name, $visiblename, $description, $defaultsetting); 00046 } 00047 00054 public function write_setting($data) { 00055 if ($this->paramtype === PARAM_INT and $data === '') { 00056 // do not complain if '' used instead of 0 00057 $data = 0; 00058 } 00059 00060 // $data is a string 00061 $validated = $this->validate($data); 00062 if ($validated !== true) { 00063 return $validated; 00064 } 00065 if ($this->lowercase) { 00066 $data = moodle_strtolower($data); 00067 } 00068 return ($this->config_write($this->name, trim($data)) ? '' : get_string('errorsetting', 'admin')); 00069 } 00070 } 00071 00072 class admin_setting_ldap_rolemapping extends admin_setting { 00073 00082 public function __construct($name, $visiblename, $description, $defaultsetting) { 00083 parent::__construct($name, $visiblename, $description, $defaultsetting); 00084 } 00085 00091 public function get_setting() { 00092 $roles = get_all_roles(); 00093 $result = array(); 00094 foreach ($roles as $role) { 00095 $contexts = $this->config_read('contexts_role'.$role->id); 00096 $memberattribute = $this->config_read('memberattribute_role'.$role->id); 00097 $result[] = array('id' => $role->id, 00098 'name' => $role->name, 00099 'contexts' => $contexts, 00100 'memberattribute' => $memberattribute); 00101 } 00102 return $result; 00103 } 00104 00111 public function write_setting($data) { 00112 if(!is_array($data)) { 00113 return ''; // ignore it 00114 } 00115 00116 $result = ''; 00117 foreach ($data as $roleid => $data) { 00118 if (!$this->config_write('contexts_role'.$roleid, trim($data['contexts']))) { 00119 $return = get_string('errorsetting', 'admin'); 00120 } 00121 if (!$this->config_write('memberattribute_role'.$roleid, moodle_strtolower(trim($data['memberattribute'])))) { 00122 $return = get_string('errorsetting', 'admin'); 00123 } 00124 } 00125 return $result; 00126 } 00127 00141 public function output_html($data, $query='') { 00142 $return = '<div style="float:left; width:auto; margin-right: 0.5em;">'; 00143 $return .= '<div style="height: 2em;">'.get_string('roles', 'role').'</div>'; 00144 foreach ($data as $role) { 00145 $return .= '<div style="height: 2em;">'.s($role['name']).'</div>'; 00146 } 00147 $return .= '</div>'; 00148 00149 $return .= '<div style="float:left; width:auto; margin-right: 0.5em;">'; 00150 $return .= '<div style="height: 2em;">'.get_string('contexts', 'enrol_ldap').'</div>'; 00151 foreach ($data as $role) { 00152 $contextid = $this->get_id().'['.$role['id'].'][contexts]'; 00153 $contextname = $this->get_full_name().'['.$role['id'].'][contexts]'; 00154 $return .= '<div style="height: 2em;"><input type="text" size="40" id="'.$contextid.'" name="'.$contextname.'" value="'.s($role['contexts']).'"/></div>'; 00155 } 00156 $return .= '</div>'; 00157 00158 $return .= '<div style="float:left; width:auto; margin-right: 0.5em;">'; 00159 $return .= '<div style="height: 2em;">'.get_string('memberattribute', 'enrol_ldap').'</div>'; 00160 foreach ($data as $role) { 00161 $memberattrid = $this->get_id().'['.$role['id'].'][memberattribute]'; 00162 $memberattrname = $this->get_full_name().'['.$role['id'].'][memberattribute]'; 00163 $return .= '<div style="height: 2em;"><input type="text" size="15" id="'.$memberattrid.'" name="'.$memberattrname.'" value="'.s($role['memberattribute']).'"/></div>'; 00164 } 00165 $return .= '</div>'; 00166 $return .= '<div style="clear:both;"></div>'; 00167 00168 return format_admin_setting($this, $this->visiblename, $return, 00169 $this->description, true, '', '', $query); 00170 } 00171 }