ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 $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 
73  public function setImageHeight($image_height)
74  {
75  $this->image_height = $image_height;
76  }
77 
81  public function getImageHeight()
82  {
83  return $this->image_height;
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 
126  $_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()]);
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 }