ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilCaptchaInputGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Captcha/classes/class.ilSecurImageUtil.php';
5
14{
18 protected $lng;
19
23 protected $value;
24
28 protected $size = 20;
29
33 protected $image_width = 215;
34
38 protected $image_height = 80;
39
45 public function __construct($a_title = '', $a_postvar = '')
46 {
47 global $DIC;
48
49 $this->lng = $DIC->language();
50 $lng = $DIC->language();
51
52 parent::__construct($a_title, $a_postvar);
53 $this->setType('captcha');
54 if ($lng instanceof ilLanguage) {
55 $lng->loadLanguageModule('cptch');
56 }
57 }
58
63 public function setValue($a_value)
64 {
65 $this->value = $a_value;
66 }
67
72 public function getValue()
73 {
74 return $this->value;
75 }
76
81 {
82 $this->image_height = $image_height;
83 }
84
88 public function getImageHeight()
89 {
91 }
92
96 public function setImageWidth($image_width)
97 {
98 $this->image_width = $image_width;
99 }
100
104 public function getImageWidth()
105 {
106 return $this->image_width;
107 }
108
112 public function setSize($size)
113 {
114 $this->size = $size;
115 }
116
120 public function getSize()
121 {
122 return $this->size;
123 }
124
129 public function checkInput()
130 {
132
134 if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == '') {
135 if ($lng instanceof ilLanguage) {
136 $this->setAlert($lng->txt('msg_input_is_required'));
137 }
138
139 return false;
140 }
141
142 include_once('./Services/Captcha/classes/class.ilSecurImage.php');
143 $si = new ilSecurImage();
144 if (!$si->check($_POST[$this->getPostVar()])) {
145 if ($lng instanceof ilLanguage) {
146 $this->setAlert($lng->txt('cptch_wrong_input'));
147 }
148
149 return false;
150 }
151
152 return true;
153 }
154
158 public function render()
159 {
164
165 $tpl = new ilTemplate('tpl.prop_captchainput.html', true, true, 'Services/Captcha');
166
167 if (strlen($this->getValue())) {
168 $tpl->setCurrentBlock('prop_text_propval');
169 $tpl->setVariable('PROPERTY_VALUE', ilUtil::prepareFormOutput($this->getValue()));
170 $tpl->parseCurrentBlock();
171 }
172 $tpl->setVariable('POST_VAR', $this->getPostVar());
173 $tpl->setVariable('CAPTCHA_ID', $this->getFieldId());
174 $tpl->setVariable('SIZE', $this->getSize());
175
177 $script = ilUtil::appendUrlParameterString($script, 'height=' . (int) $this->getImageHeight(), true);
178 $script = ilUtil::appendUrlParameterString($script, 'width=' . (int) $this->getImageWidth(), true);
179 $tpl->setVariable('IMAGE_SCRIPT', $script);
180 $tpl->setVariable('AUDIO_SCRIPT', ilSecurImageUtil::getAudioScript());
181 $tpl->setVariable('SRC_RELOAD', ilSecurImageUtil::getDirectory() . '/images/refresh.png');
182
183 $tpl->setVariable('TXT_CAPTCHA_ALT', $lng->txt('captcha_alt_txt'));
184 $tpl->setVariable('TXT_RELOAD', $lng->txt('captcha_code_reload'));
185 $tpl->setVariable('TXT_CAPTCHA_AUDIO_TITLE', $lng->txt('captcha_audio_title'));
186 $tpl->setVariable('TXT_CONSTR_PROP', $lng->txt('cont_constrain_proportions'));
187 $tpl->setVariable('TXT_CAPTCHA_INFO', $lng->txt('captcha_code_info'));
188
189 return $tpl->get();
190 }
191
195 public function insert(ilTemplate $a_tpl)
196 {
197 $html = $this->render();
198
199 $a_tpl->setCurrentBlock('prop_generic');
200 $a_tpl->setVariable('PROP_GENERIC', $html);
201 $a_tpl->parseCurrentBlock();
202 }
203
208 public function setValueByArray($a_values)
209 {
210 $this->setValue($a_values[$this->getPostVar()]);
211 }
212}
$tpl
Definition: ilias.php:10
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:613
This class represents a captcha input in a property form.
__construct($a_title='', $a_postvar='')
Constructor.
insert(ilTemplate $a_tpl)
setValueByArray($a_values)
Set value by array.
setValue($a_value)
Set Value.
checkInput()
Check input, strip slashes etc.
This class represents a property in a property form.
setType($a_type)
Set Type.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
language handling
SecurImage Wrapper (very simply wrapper, does not abstract other captchas)
special template class to simplify handling of ITX/PEAR
parseCurrentBlock($part="DEFAULT")
Überladene Funktion, die auf den aktuelle Block vorher noch ein replace ausführt @access public.
setCurrentBlock($part="DEFAULT")
Überladene Funktion, die sich hier lokal noch den aktuellen Block merkt.
static appendUrlParameterString($a_url, $a_par, $xml_style=false)
append URL parameter string ("par1=value1&par2=value2...") to given URL string
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$html
Definition: example_001.php:87
global $DIC
Definition: saml.php:7