1<?php 2/* 3 +-----------------------------------------------------------------------------+ 4 | ILIAS open source | 5 +-----------------------------------------------------------------------------+ 6 | Copyright (c) 1998-2008 ILIAS open source, University of Cologne | 7 | | 8 | This program is free software; you can redistribute it and/or | 9 | modify it under the terms of the GNU General Public License | 10 | as published by the Free Software Foundation; either version 2 | 11 | of the License, or (at your option) any later version. | 12 | | 13 | This program is distributed in the hope that it will be useful, | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 16 | GNU General Public License for more details. | 17 | | 18 | You should have received a copy of the GNU General Public License | 19 | along with this program; if not, write to the Free Software | 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 21 +-----------------------------------------------------------------------------+ 22*/ 23 24/** 25 * This class represents a email property in a property form. 26 * @author Alex Killing <alex.killing@gmx.de> 27 * @version $Id$ 28 * @ingroup ServicesForm 29 */ 30class ilEMailInputGUI extends ilFormPropertyGUI 31{ 32 /** 33 * @var ilLanguage 34 */ 35 protected $lng; 36 37 protected $value; 38 protected $size = 30; 39 protected $max_length = 80; 40 protected $allowRFC822 = false; // [bool] 41 42 /** 43 * @var bool 44 */ 45 protected $retype = false; 46 47 /** 48 * @var string 49 */ 50 protected $retypevalue = ''; 51 52 /** 53 * Constructor 54 * @param string $a_title Title 55 * @param string $a_postvar Post Variable 56 */ 57 public function __construct($a_title = "", $a_postvar = "") 58 { 59 global $DIC; 60 61 $this->lng = $DIC->language(); 62 parent::__construct($a_title, $a_postvar); 63 $this->setRetype(false); 64 } 65 66 /** 67 * Set Value. 68 * @param string $a_value Value 69 */ 70 public function setValue($a_value) 71 { 72 $this->value = $a_value; 73 } 74 75 /** 76 * Get Value. 77 * @return string Value 78 */ 79 public function getValue() 80 { 81 return $this->value; 82 } 83 84 /** 85 * Set value by array 86 * @param array $a_values value array 87 */ 88 public function setValueByArray($a_values) 89 { 90 $this->setValue($a_values[$this->getPostVar()]); 91 $this->setRetypeValue($a_values[$this->getPostVar() . '_retype']); 92 } 93 94 /** 95 * Allow extended email address format 96 * 97 * "example@example.com" vs "example <example@example.com>" 98 * 99 * @param bool $a_value 100 */ 101 public function allowRFC822($a_value) 102 { 103 $this->allowRFC822 = (bool) $a_value; 104 } 105 106 /** 107 * Check input, strip slashes etc. set alert, if input is not ok. 108 * @return boolean Input ok, true/false 109 */ 110 public function checkInput() 111 { 112 $lng = $this->lng; 113 114 $_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()], !(bool) $this->allowRFC822); 115 $_POST[$this->getPostVar() . '_retype'] = ilUtil::stripSlashes($_POST[$this->getPostVar() . '_retype'], !(bool) $this->allowRFC822); 116 if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "") { 117 $this->setAlert($lng->txt("msg_input_is_required")); 118 119 return false; 120 } 121 if ($this->getRetype() && ($_POST[$this->getPostVar()] != $_POST[$this->getPostVar() . '_retype'])) { 122 $this->setAlert($lng->txt('email_not_match')); 123 124 return false; 125 } 126 if (!ilUtil::is_email($_POST[$this->getPostVar()]) && 127 trim($_POST[$this->getPostVar()]) != "" 128 ) { 129 $this->setAlert($lng->txt("email_not_valid")); 130 131 return false; 132 } 133 134 135 return true; 136 } 137 138 /** 139 * @param ilTemplate $a_tpl 140 */ 141 public function insert(ilTemplate $a_tpl) 142 { 143 $lng = $this->lng; 144 145 $ptpl = new ilTemplate('tpl.prop_email.html', true, true, 'Services/Form'); 146 147 if ($this->getRetype()) { 148 $ptpl->setCurrentBlock('retype_email'); 149 $ptpl->setVariable('RSIZE', $this->getSize()); 150 $ptpl->setVariable('RID', $this->getFieldId()); 151 $ptpl->setVariable('RMAXLENGTH', $this->getMaxLength()); 152 $ptpl->setVariable('RPOST_VAR', $this->getPostVar()); 153 154 $retype_value = $this->getRetypeValue(); 155 $ptpl->setVariable('PROPERTY_RETYPE_VALUE', ilUtil::prepareFormOutput($retype_value)); 156 if ($this->getDisabled()) { 157 $ptpl->setVariable('RDISABLED', ' disabled="disabled"'); 158 } 159 $ptpl->setVariable('TXT_RETYPE', $lng->txt('form_retype_email')); 160 $ptpl->parseCurrentBlock(); 161 } 162 163 $ptpl->setVariable('POST_VAR', $this->getPostVar()); 164 $ptpl->setVariable('ID', $this->getFieldId()); 165 $ptpl->setVariable('PROPERTY_VALUE', ilUtil::prepareFormOutput($this->getValue())); 166 $ptpl->setVariable('SIZE', $this->getSize()); 167 $ptpl->setVariable('MAXLENGTH', $this->getMaxLength()); 168 if ($this->getDisabled()) { 169 $ptpl->setVariable('DISABLED', ' disabled="disabled"'); 170 $ptpl->setVariable('HIDDEN_INPUT', $this->getHiddenTag($this->getPostVar(), $this->getValue())); 171 } 172 173 if ($this->getRequired()) { 174 $ptpl->setVariable("REQUIRED", "required=\"required\""); 175 } 176 177 $a_tpl->setCurrentBlock('prop_generic'); 178 $a_tpl->setVariable('PROP_GENERIC', $ptpl->get()); 179 $a_tpl->parseCurrentBlock(); 180 } 181 182 /** 183 * @param boolean $a_val 184 */ 185 public function setRetype($a_val) 186 { 187 $this->retype = $a_val; 188 } 189 190 /** 191 * @return boolean 192 */ 193 public function getRetype() 194 { 195 return $this->retype; 196 } 197 198 /** 199 * @param string $a_retypevalue 200 */ 201 public function setRetypeValue($a_retypevalue) 202 { 203 $this->retypevalue = $a_retypevalue; 204 } 205 206 /** 207 * @return string 208 */ 209 public function getRetypeValue() 210 { 211 return $this->retypevalue; 212 } 213 214 /** 215 * @param int $size 216 */ 217 public function setSize($size) 218 { 219 $this->size = $size; 220 } 221 222 /** 223 * @return int 224 */ 225 public function getSize() 226 { 227 return $this->size; 228 } 229 230 /** 231 * @param int $max_length 232 */ 233 public function setMaxLength($max_length) 234 { 235 $this->max_length = $max_length; 236 } 237 238 /** 239 * @return int 240 */ 241 public function getMaxLength() 242 { 243 return $this->max_length; 244 } 245} 246