ILIAS  release_8 Revision v8.24
class.ilImageWizardInputGUI.php
Go to the documentation of this file.
1<?php
2
27{
28 protected $values = array();
29 protected $allowMove = false;
30 protected $qstObject = null;
31 protected $suffixes = array();
32
39 public function __construct($a_title = "", $a_postvar = "")
40 {
41 parent::__construct($a_title, $a_postvar);
43 $this->setSize('25');
44 $this->validationRegexp = "";
45 }
46
47 public function setValue($a_value): void
48 {
49 $this->values = array();
50 if (is_array($a_value)) {
51 if (is_array($a_value['count'])) {
52 foreach ($a_value['count'] as $index => $value) {
53 array_push($this->values, $a_value['imagename'][$index]);
54 }
55 }
56 }
57 }
58
64 public function setSuffixes($a_suffixes): void
65 {
66 $this->suffixes = $a_suffixes;
67 }
68
74 public function getSuffixes(): array
75 {
76 return $this->suffixes;
77 }
78
84 public function setValues($a_values): void
85 {
86 $this->values = $a_values;
87 }
88
94 public function getValues(): array
95 {
96 return $this->values;
97 }
98
104 public function setQuestionObject($a_value): void
105 {
106 $this->qstObject = &$a_value;
107 }
108
114 public function getQuestionObject(): ?object
115 {
116 return $this->qstObject;
117 }
118
124 public function setAllowMove($a_allow_move): void
125 {
126 $this->allowMove = $a_allow_move;
127 }
128
134 public function getAllowMove(): bool
135 {
136 return $this->allowMove;
137 }
138
143 public function checkInput(): bool
144 {
145 global $DIC;
146 $lng = $DIC['lng'];
147
148 if (is_array($_POST[$this->getPostVar()])) {
149 $_POST[$this->getPostVar()] = ilArrayUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
150 }
151 if (is_array($_FILES[$this->getPostVar()]['error']['image'])) {
152 foreach ($_FILES[$this->getPostVar()]['error']['image'] as $index => $error) {
153 // error handling
154 if ($error > 0) {
155 switch ($error) {
156 case UPLOAD_ERR_FORM_SIZE:
157 case UPLOAD_ERR_INI_SIZE:
158 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
159 return false;
160 break;
161
162 case UPLOAD_ERR_PARTIAL:
163 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
164 return false;
165 break;
166
167 case UPLOAD_ERR_NO_FILE:
168 if ($this->getRequired()) {
169 if (!strlen($_POST[$this->getPostVar()]['imagename'][$index])) {
170 $this->setAlert($lng->txt("form_msg_file_no_upload"));
171 return false;
172 }
173 }
174 break;
175
176 case UPLOAD_ERR_NO_TMP_DIR:
177 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
178 return false;
179 break;
180
181 case UPLOAD_ERR_CANT_WRITE:
182 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
183 return false;
184 break;
185
186 case UPLOAD_ERR_EXTENSION:
187 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
188 return false;
189 break;
190 }
191 }
192 }
193 } else {
194 if ($this->getRequired()) {
195 $this->setAlert($lng->txt("form_msg_file_no_upload"));
196 return false;
197 }
198 }
199
200 if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
201 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
202 $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
203 $filename_arr = pathinfo($filename);
204 $suffix = $filename_arr["extension"];
205 $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
206 $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
207 // check suffixes
208 if (strlen($tmpname) && is_array($this->getSuffixes())) {
209 if (!in_array(strtolower($suffix), $this->getSuffixes())) {
210 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
211 return false;
212 }
213 }
214 }
215 }
216
217 if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image'])) {
218 foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname) {
219 $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
220 $filename_arr = pathinfo($filename);
221 $suffix = $filename_arr["extension"];
222 $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
223 $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
224 // virus handling
225 if (strlen($tmpname)) {
227 if ($vir[0] == false) {
228 $this->setAlert($lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
229 return false;
230 }
231 }
232 }
233 }
234
235 return $this->checkSubItemsInput();
236 }
237
242 public function insert(ilTemplate $a_tpl): void
243 {
244 global $DIC;
245 $lng = $DIC['lng'];
246
247 $tpl = new ilTemplate("tpl.prop_imagewizardinput.html", true, true, "Modules/TestQuestionPool");
248 $i = 0;
249 foreach ($this->values as $value) {
250 if (strlen($value)) {
251 $imagename = $this->qstObject->getImagePathWeb() . $value;
252 if ($this->qstObject->getThumbSize()) {
253 if (@file_exists($this->qstObject->getImagePath() . $this->qstObject->getThumbPrefix() . $value)) {
254 $imagename = $this->qstObject->getImagePathWeb() . $this->qstObject->getThumbPrefix() . $value;
255 }
256 }
257 $tpl->setCurrentBlock('image');
258 $tpl->setVariable('SRC_IMAGE', $imagename);
259 $tpl->setVariable('IMAGE_NAME', $value);
260 $tpl->setVariable('ALT_IMAGE', ilLegacyFormElementsUtil::prepareFormOutput($value));
261 $tpl->setVariable("TXT_DELETE_EXISTING", $lng->txt("delete_existing_file"));
262 $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
263 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
264 $tpl->parseCurrentBlock();
265 }
266 $tpl->setCurrentBlock('addimage');
267 $tpl->setVariable("IMAGE_BROWSE", $lng->txt('select_file'));
268 $tpl->setVariable("IMAGE_ID", $this->getPostVar() . "[image][$i]");
269 $tpl->setVariable("IMAGE_SUBMIT", $lng->txt("upload"));
270 $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
271 $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
272 $tpl->parseCurrentBlock();
273
274 if ($this->getAllowMove()) {
275 $tpl->setCurrentBlock("move");
276 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
277 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
278 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
279 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
280 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
281 $tpl->parseCurrentBlock();
282 }
283 $tpl->setCurrentBlock("row");
284 $tpl->setVariable("POST_VAR", $this->getPostVar());
285 $tpl->setVariable("ROW_NUMBER", $i);
286 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
287 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
288 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
289 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
290 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
291 $tpl->parseCurrentBlock();
292 $i++;
293 }
294
295 if (is_array($this->getSuffixes())) {
296 $suff_str = $delim = "";
297 foreach ($this->getSuffixes() as $suffix) {
298 $suff_str .= $delim . "." . $suffix;
299 $delim = ", ";
300 }
301 $tpl->setCurrentBlock('allowed_image_suffixes');
302 $tpl->setVariable("TXT_ALLOWED_SUFFIXES", $lng->txt("file_allowed_suffixes") . " " . $suff_str);
303 $tpl->parseCurrentBlock();
304 }
305 /*
306 $tpl->setCurrentBlock("image_heading");
307 $tpl->setVariable("ANSWER_IMAGE", $lng->txt('answer_image'));
308 $tpl->parseCurrentBlock();
309 */
310
311 $tpl->setVariable("TXT_MAX_SIZE", ilFileUtils::getFileSizeInfo());
312 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
313 $tpl->setVariable("TEXT_YES", $lng->txt('yes'));
314 $tpl->setVariable("TEXT_NO", $lng->txt('no'));
315 $tpl->setVariable("DELETE_IMAGE_HEADER", $lng->txt('delete_image_header'));
316 $tpl->setVariable("DELETE_IMAGE_QUESTION", $lng->txt('delete_image_question'));
317 $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
318 $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
319
320 $a_tpl->setCurrentBlock("prop_generic");
321 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
322 $a_tpl->parseCurrentBlock();
323
324 global $DIC;
325 $tpl = $DIC['tpl'];
326 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
327 $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/imagewizard.js");
328 }
329}
$filename
Definition: buildRTE.php:78
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
static getAllowedImageMaterialFileExtensions()
static stripSlashesRecursive($a_data, bool $a_strip_html=true, string $a_allow="")
static getFileSizeInfo()
static get(string $a_glyph, string $a_text="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setSuffixes($a_suffixes)
Set Accepted Suffixes.
insert(ilTemplate $a_tpl)
Insert property html.
checkInput()
Check input, strip slashes etc.
__construct($a_title="", $a_postvar="")
Constructor.
setAllowMove($a_allow_move)
Set allow move.
getSuffixes()
Get Accepted Suffixes.
setQuestionObject($a_value)
Set question object.
getQuestionObject()
Get question object.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static prepareFormOutput($a_str, bool $a_strip=false)
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This class represents a text property in a property form.
static virusHandling(string $a_file, string $a_orig_name='', bool $a_clean=true)
global $DIC
Definition: feed.php:28
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$index
Definition: metadata.php:145
$i
Definition: metadata.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc