ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMultipleImagesInputGUI.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/Form/classes/class.ilIdentifiedMultiValuesInputGUI.php';
5require_once 'Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php';
6
14{
15 const RENDERING_TEMPLATE = 'tpl.prop_multi_image_inp.html';
16
17 const ITERATOR_SUBFIELD_NAME = 'iteratorfield';
18 const STORED_IMAGE_SUBFIELD_NAME = 'storedimage';
19 const IMAGE_UPLOAD_SUBFIELD_NAME = 'imageupload';
20
21 const FILE_DATA_INDEX_DODGING_FILE = 'dodging_file';
26
30 protected $editElementOrderEnabled = false;
31
35 protected $suffixes = array();
36
37 protected $imageRemovalCommand = 'removeImage';
38
39 protected $imageUploadCommand = 'uploadImage';
40
47 public function __construct($a_title = "", $a_postvar = "")
48 {
49 global $DIC;
50
51 $this->lng = $DIC->language();
52 parent::__construct($a_title, $a_postvar);
53
54 $this->setSuffixes(array("jpg", "jpeg", "png", "gif"));
55 $this->setSize('25');
56 $this->validationRegexp = "";
57
58 require_once 'Services/Form/classes/class.ilMultipleImagesAdditionalIndexLevelRemover.php';
60 $manipulator->setPostVar($this->getPostVar());
61 $this->addFormValuesManipulator($manipulator);
62
63 require_once 'Services/Form/classes/class.ilMultipleImagesFileSubmissionDataCompletion.php';
65 $manipulator->setPostVar($this->getPostVar());
66 $this->addFormValuesManipulator($manipulator);
67
68 require_once 'Services/Form/classes/class.ilIdentifiedMultiFilesJsPositionIndexRemover.php';
70 $manipulator->setPostVar($this->getPostVar());
71 $this->addFormValuesManipulator($manipulator);
72
73 require_once 'Services/Form/classes/class.ilMultiFilesSubmitRecursiveSlashesStripper.php';
75 $manipulator->setPostVar($this->getPostVar());
76 $this->addFormValuesManipulator($manipulator);
77 }
78
84 public function setSuffixes($a_suffixes)
85 {
86 $this->suffixes = $a_suffixes;
87 }
88
94 public function getSuffixes()
95 {
96 return $this->suffixes;
97 }
98
102 public function getImageRemovalCommand()
103 {
105 }
106
111 {
112 $this->imageRemovalCommand = $imageRemovalCommand;
113 }
114
118 public function getImageUploadCommand()
119 {
121 }
122
127 {
128 $this->imageUploadCommand = $imageUploadCommand;
129 }
130
135 {
137 }
138
143 {
144 $this->editElementOccuranceEnabled = $editElementOccuranceEnabled;
145 }
146
151 {
153 }
154
159 {
160 $this->editElementOrderEnabled = $editElementOrderEnabled;
161 }
162
167 abstract protected function isValidFilenameInput($filenameInput);
168
174 public function onCheckInput()
175 {
176 $lng = $GLOBALS['DIC'] ? $GLOBALS['DIC']['lng'] : $GLOBALS['lng'];
177 $F = $_FILES[$this->getPostVar()];
178 if ($F && isset($_REQUEST[$this->getPostVar()][self::FILE_DATA_INDEX_DODGING_FILE])) {
179 $F = array_merge(array(self::FILE_DATA_INDEX_DODGING_FILE => $_REQUEST[$this->getPostVar()][self::FILE_DATA_INDEX_DODGING_FILE]), $F);
180 }
181
182 if ($this->getRequired() && !is_array($F['error'])) {
183 $this->setAlert($lng->txt("form_msg_file_no_upload"));
184 return false;
185 } else {
186 foreach ($F['error'] as $index => $error) {
187 // error handling
188 if ($error > 0) {
189 switch ($error) {
190 case UPLOAD_ERR_INI_SIZE:
191 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
192 return false;
193 break;
194
195 case UPLOAD_ERR_FORM_SIZE:
196 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
197 return false;
198 break;
199
200 case UPLOAD_ERR_PARTIAL:
201 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
202 return false;
203 break;
204
205 case UPLOAD_ERR_NO_FILE:
206 if (!$this->getRequired()) {
207 break;
208 } elseif (strlen($F[self::FILE_DATA_INDEX_DODGING_FILE][$index])) {
209 break;
210 }
211 $this->setAlert($lng->txt("form_msg_file_no_upload"));
212 return false;
213 break;
214
215 case UPLOAD_ERR_NO_TMP_DIR:
216 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
217 return false;
218 break;
219
220 case UPLOAD_ERR_CANT_WRITE:
221 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
222 return false;
223 break;
224
225 case UPLOAD_ERR_EXTENSION:
226 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
227 return false;
228 break;
229 }
230 }
231 }
232 }
233
234 if (is_array($F['tmp_name'])) {
235 foreach ($F['tmp_name'] as $index => $tmpname) {
236 $filename = $F['name'][$index];
237 if (is_array($filename)) {
238 $filename = array_shift($filename);
239 $tmpname = array_shift($tmpname);
240 }
241 $filename_arr = pathinfo($filename);
242 $suffix = $filename_arr["extension"];
243 $mimetype = $F['type'][$index];
244 $size_bytes = $F['size'][$index];
245 // check suffixes
246 if (strlen($tmpname) && is_array($this->getSuffixes())) {
247 if (!in_array(strtolower($suffix), $this->getSuffixes())) {
248 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
249 return false;
250 }
251 }
252 }
253 }
254
255 foreach ($F['tmp_name'] as $index => $tmpname) {
256 $filename = $F['name'][$index];
257 if (is_array($filename)) {
258 $filename = array_shift($filename);
259 $tmpname = array_shift($tmpname);
260 }
261 $filename_arr = pathinfo($filename);
262 $suffix = $filename_arr["extension"];
263 $mimetype = $F['type'][$index];
264 $size_bytes = $F['size'][$index];
265 // virus handling
266 if (strlen($tmpname)) {
267 $vir = ilUtil::virusHandling($tmpname, $filename);
268 if ($vir[0] == false) {
269 $this->setAlert($lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
270 return false;
271 }
272 }
273 }
274
275 return $this->checkSubItemsInput();
276 }
277
282 public function render($a_mode = "")
283 {
285
286 $tpl = $this->getTemplate();
287 $i = 0;
288
290 foreach ($identified_multi_values as $identifier => $value) {
292 $tpl->setCurrentBlock('image');
293
294 $tpl->setVariable('STORED_IMAGE_SRC', $this->fetchContentImageSourceFromValue($value));
295 $tpl->setVariable('STORED_IMAGE_ALT', ilUtil::prepareFormOutput($this->fetchContentImageTitleFromValue($value)));
296 $tpl->setVariable('STORED_IMAGE_FILENAME', $this->fetchContentImageTitleFromValue($value));
297 $tpl->setVariable("STORED_IMAGE_POST_VAR", $this->getMultiValuePostVarSubFieldPosIndexed($identifier, self::STORED_IMAGE_SUBFIELD_NAME, $i));
298
299 $tpl->setVariable("TXT_DELETE_EXISTING", $lng->txt("delete_existing_file"));
300 $tpl->setVariable("IMAGE_CMD_REMOVE", $this->buildMultiValueSubmitVar($identifier, $i, $this->getImageRemovalCommand()));
301
302 $tpl->parseCurrentBlock();
303 }
304
305 $tpl->setCurrentBlock('addimage');
306
307 $tpl->setVariable("IMAGE_BROWSE", $lng->txt('select_file'));
308 $tpl->setVariable("IMAGE_ID", $this->getMultiValuePosIndexedSubFieldId($identifier, self::IMAGE_UPLOAD_SUBFIELD_NAME, $i));
309 $tpl->setVariable("TXT_IMAGE_SUBMIT", $lng->txt("upload"));
310 $tpl->setVariable("IMAGE_CMD_UPLOAD", $this->buildMultiValueSubmitVar($identifier, $i, $this->getImageUploadCommand()));
311 $tpl->setVariable("UPLOAD_IMAGE_POST_VAR", $this->getMultiValuePostVarSubFieldPosIndexed($identifier, self::IMAGE_UPLOAD_SUBFIELD_NAME, $i));
312 $tpl->setVariable("COUNT_POST_VAR", $this->getMultiValuePostVarSubFieldPosIndexed($identifier, self::ITERATOR_SUBFIELD_NAME, $i));
313
314 $tpl->parseCurrentBlock();
315
316 if ($this->isEditElementOrderEnabled()) {
317 $tpl->setCurrentBlock("move");
318 $tpl->setVariable("ID_UP", $this->getMultiValuePosIndexedSubFieldId($identifier, 'up', $i));
319 $tpl->setVariable("ID_DOWN", $this->getMultiValuePosIndexedSubFieldId($identifier, 'down', $i));
320 $tpl->setVariable("CMD_UP", $this->buildMultiValueSubmitVar($identifier, $i, 'up'));
321 $tpl->setVariable("CMD_DOWN", $this->buildMultiValueSubmitVar($identifier, $i, 'down'));
322 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
323 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
324 $tpl->parseCurrentBlock();
325 }
326
327 if ($this->isEditElementOccuranceEnabled()) {
328 $tpl->setCurrentBlock("row");
329 $tpl->setVariable("ID_ADD", $this->getMultiValuePosIndexedSubFieldId($identifier, 'add', $i));
330 $tpl->setVariable("ID_REMOVE", $this->getMultiValuePosIndexedSubFieldId($identifier, 'remove', $i));
331 $tpl->setVariable("CMD_ADD", $this->buildMultiValueSubmitVar($identifier, $i, 'add'));
332 $tpl->setVariable("CMD_REMOVE", $this->buildMultiValueSubmitVar($identifier, $i, 'remove'));
333 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
334 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
335 $tpl->parseCurrentBlock();
336 }
337
338 $i++;
339 }
340
341 if (is_array($this->getSuffixes())) {
342 $suff_str = $delim = "";
343 foreach ($this->getSuffixes() as $suffix) {
344 $suff_str .= $delim . "." . $suffix;
345 $delim = ", ";
346 }
347 $tpl->setCurrentBlock('allowed_image_suffixes');
348 $tpl->setVariable("TXT_ALLOWED_SUFFIXES", $lng->txt("file_allowed_suffixes") . " " . $suff_str);
349 $tpl->parseCurrentBlock();
350 }
351 /*
352 $tpl->setCurrentBlock("image_heading");
353 $tpl->setVariable("ANSWER_IMAGE", $lng->txt('answer_image'));
354 $tpl->parseCurrentBlock();
355 */
356
357 $tpl->setVariable("TXT_MAX_SIZE", ilUtil::getFileSizeInfo());
358 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
359 $tpl->setVariable("TEXT_YES", $lng->txt('yes'));
360 $tpl->setVariable("TEXT_NO", $lng->txt('no'));
361 $tpl->setVariable("DELETE_IMAGE_HEADER", $lng->txt('delete_image_header'));
362 $tpl->setVariable("DELETE_IMAGE_QUESTION", $lng->txt('delete_image_question'));
363 $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
364 $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
365
366 if (!$this->getDisabled()) {
367 $tpl->setCurrentBlock('js_engine_initialisation');
368 $tpl->setVariable('UPLOAD_CMD', $this->getImageUploadCommand());
369 $tpl->setVariable('REMOVE_CMD', $this->getImageRemovalCommand());
370 $tpl->setVariable('ITERATOR', self::ITERATOR_SUBFIELD_NAME);
371 $tpl->setVariable('STORED_IMAGE_POSTVAR', self::STORED_IMAGE_SUBFIELD_NAME);
372 $tpl->setVariable('UPLOAD_IMAGE_POSTVAR', self::IMAGE_UPLOAD_SUBFIELD_NAME);
373 $tpl->parseCurrentBlock();
374
375 $globalTpl = $GLOBALS['DIC'] ? $GLOBALS['DIC']['tpl'] : $GLOBALS['tpl'];
376 $globalTpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
377 $globalTpl->addJavascript("./Services/Form/js/ServiceFormIdentifiedWizardInputExtend.js");
378 //$globalTpl->addJavascript("./Services/Form/js/ServiceFormIdentifiedImageWizardInputConcrete.js");
379 }
380
381 return $tpl->get();
382 }
383
389 {
390 return is_array($value)
391 && array_key_exists('src', $value)
392 && $value['src'] !== '';
393 }
394
400 {
402 return $value['src'];
403 }
404
405 return null;
406 }
407
413 {
414 return isset($value['title']) && strlen($value['title']);
415 }
416
421 {
422 if ($this->valueHasContentImageTitle($value)) {
423 return $value['title'];
424 }
425
427 }
428
432 protected function getTemplate()
433 {
434 return new ilTemplate(self::RENDERING_TEMPLATE, true, true, "Services/Form");
435 }
436}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$filename
Definition: buildRTE.php:89
An exception for terminatinating execution or to throw for unit testing.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
static get($a_glyph, $a_text="")
Get glyph html.
addFormValuesManipulator(ilFormValuesManipulator $manipulator)
getMultiValuePostVarSubFieldPosIndexed($identifier, $subFieldIndex, $positionIndex)
getMultiValuePosIndexedSubFieldId($identifier, $subFieldIndex, $positionIndex)
buildMultiValueSubmitVar($identifier, $positionIndex, $submitCommand)
__construct($a_title="", $a_postvar="")
Constructor.
onCheckInput()
Check input, strip slashes etc.
setEditElementOccuranceEnabled($editElementOccuranceEnabled)
isValidFilenameInput($filenameInput)
setEditElementOrderEnabled($editElementOrderEnabled)
setSuffixes($a_suffixes)
Set Accepted Suffixes.
special template class to simplify handling of ITX/PEAR
setSize($a_size)
Set Size.
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
static getFileSizeInfo()
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
global $DIC
Definition: goto.php:24
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$index
Definition: metadata.php:128
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc