ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 require_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 
80  public function setImageHeight($image_height)
81  {
82  $this->image_height = $image_height;
83  }
84 
88  public function getImageHeight()
89  {
90  return $this->image_height;
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  {
131  $lng = $this->lng;
132 
133  $_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()]);
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  {
163  $lng = $this->lng;
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 }
setValue($a_value)
Set Value.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
This class represents a captcha input in a property form.
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
getPostVar()
Get Post Variable.
insert(ilTemplate $a_tpl)
setValueByArray($a_values)
Set value by array.
setAlert($a_alert)
Set Alert Text.
setType($a_type)
Set Type.
static appendUrlParameterString($a_url, $a_par, $xml_style=false)
append URL parameter string ("par1=value1&par2=value2...") to given URL string
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:613
checkInput()
Check input, strip slashes etc.
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
__construct($a_title='', $a_postvar='')
Constructor.
setCurrentBlock($part="DEFAULT")
Überladene Funktion, die sich hier lokal noch den aktuellen Block merkt.
font size
Definition: langcheck.php:162
This class represents a property in a property form.
SecurImage Wrapper (very simply wrapper, does not abstract other captchas)
language handling
$_POST["username"]
$html
Definition: example_001.php:87
parseCurrentBlock($part="DEFAULT")
Überladene Funktion, die auf den aktuelle Block vorher noch ein replace ausführt public...