ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 $value;
19
23 protected $size = 20;
24
28 protected $image_width = 215;
29
33 protected $image_height = 80;
34
40 public function __construct($a_title = '', $a_postvar = '')
41 {
42 global $lng;
43
44 parent::__construct($a_title, $a_postvar);
45 $this->setType('captcha');
46 if($lng instanceof ilLanguage)
47 {
48 $lng->loadLanguageModule('cptch');
49 }
50 }
51
56 public function setValue($a_value)
57 {
58 $this->value = $a_value;
59 }
60
65 public function getValue()
66 {
67 return $this->value;
68 }
69
74 {
75 $this->image_height = $image_height;
76 }
77
81 public function getImageHeight()
82 {
84 }
85
89 public function setImageWidth($image_width)
90 {
91 $this->image_width = $image_width;
92 }
93
97 public function getImageWidth()
98 {
99 return $this->image_width;
100 }
101
105 public function setSize($size)
106 {
107 $this->size = $size;
108 }
109
113 public function getSize()
114 {
115 return $this->size;
116 }
117
122 public function checkInput()
123 {
124 global $lng;
125
127 if($this->getRequired() && trim($_POST[$this->getPostVar()]) == '')
128 {
129 if($lng instanceof ilLanguage)
130 {
131 $this->setAlert($lng->txt('msg_input_is_required'));
132 }
133
134 return false;
135 }
136
137 include_once('./Services/Captcha/classes/class.ilSecurImage.php');
138 $si = new ilSecurImage();
139 if(!$si->check($_POST[$this->getPostVar()]))
140 {
141 if($lng instanceof ilLanguage)
142 {
143 $this->setAlert($lng->txt('cptch_wrong_input'));
144 }
145
146 return false;
147 }
148
149 return true;
150 }
151
155 public function render()
156 {
160 global $lng;
161
162 $tpl = new ilTemplate('tpl.prop_captchainput.html', true, true, 'Services/Captcha');
163
164 if(strlen($this->getValue()))
165 {
166 $tpl->setCurrentBlock('prop_text_propval');
167 $tpl->setVariable('PROPERTY_VALUE', ilUtil::prepareFormOutput($this->getValue()));
168 $tpl->parseCurrentBlock();
169 }
170 $tpl->setVariable('POST_VAR', $this->getPostVar());
171 $tpl->setVariable('CAPTCHA_ID', $this->getFieldId());
172 $tpl->setVariable('SIZE', $this->getSize());
173
175 $script = ilUtil::appendUrlParameterString($script, 'height=' . (int)$this->getImageHeight(), true);
176 $script = ilUtil::appendUrlParameterString($script, 'width=' . (int)$this->getImageWidth(), true);
177 $tpl->setVariable('IMAGE_SCRIPT', $script);
178 $tpl->setVariable('AUDIO_SCRIPT', ilSecurImageUtil::getAudioScript());
179 $tpl->setVariable('SRC_RELOAD', ilSecurImageUtil::getDirectory() . '/images/refresh.png');
180
181 $tpl->setVariable('TXT_CAPTCHA_ALT', $lng->txt('captcha_alt_txt'));
182 $tpl->setVariable('TXT_RELOAD', $lng->txt('captcha_code_reload'));
183 $tpl->setVariable('TXT_CAPTCHA_AUDIO_TITLE', $lng->txt('captcha_audio_title'));
184 $tpl->setVariable('TXT_CONSTR_PROP', $lng->txt('cont_constrain_proportions'));
185 $tpl->setVariable('TXT_CAPTCHA_INFO', $lng->txt('captcha_code_info'));
186
187 return $tpl->get();
188 }
189
193 public function insert(ilTemplate $a_tpl)
194 {
195 $html = $this->render();
196
197 $a_tpl->setCurrentBlock('prop_generic');
198 $a_tpl->setVariable('PROP_GENERIC', $html);
199 $a_tpl->parseCurrentBlock();
200 }
201
206 public function setValueByArray($a_values)
207 {
208 $this->setValue($a_values[$this->getPostVar()]);
209 }
210}
global $tpl
Definition: ilias.php:8
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:626
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
$_POST['username']
Definition: cron.php:12
$html
Definition: example_001.php:87
global $lng
Definition: privfeed.php:40