ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilFileWizardInputGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30{
32 protected \ILIAS\UI\Factory $ui_factory;
33 protected \ILIAS\UI\Renderer $ui_renderer;
34 protected array $filenames = array();
35 protected bool $allowMove = false;
36 protected string $imagepath_web = "";
37
38 public function __construct(
39 string $a_title = "",
40 string $a_postvar = ""
41 ) {
42 global $DIC;
43
44 $this->lng = $DIC->language();
45 $this->lng->loadLanguageModule("form");
46 $this->tpl = $DIC["tpl"];
47 $this->ui_factory = $DIC->ui()->factory();
48 $this->ui_renderer = $DIC->ui()->renderer();
49 parent::__construct($a_title, $a_postvar);
50 }
51
52 public function setImagePathWeb(string $a_path): void
53 {
54 $this->imagepath_web = $a_path;
55 }
56
57 public function getImagePathWeb(): string
58 {
60 }
61
62 public function setFilenames(array $a_filenames): void
63 {
64 $this->filenames = $a_filenames;
65 }
66
67 public function getFilenames(): array
68 {
69 return $this->filenames;
70 }
71
72 public function setAllowMove(bool $a_allow_move): void
73 {
74 $this->allowMove = $a_allow_move;
75 }
76
77 public function getAllowMove(): bool
78 {
79 return $this->allowMove;
80 }
81
82 public function checkInput(): bool
83 {
85
86 // see ilFileInputGUI
87 // if no information is received, something went wrong
88 // this is e.g. the case, if the post_max_size has been exceeded
89 if (!isset($_FILES[$this->getPostVar()]) || !is_array($_FILES[$this->getPostVar()])) {
90 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
91 return false;
92 }
93
94 $pictures = $_FILES[$this->getPostVar()];
95 $uploadcheck = true;
96 if (is_array($pictures)) {
97 foreach ($pictures['name'] as $index => $name) {
98 // remove trailing '/'
99 $name = rtrim($name, '/');
100
101 $filename = $name;
102 $filename_arr = pathinfo($name);
103 $suffix = $filename_arr["extension"] ?? "";
104 $temp_name = $pictures["tmp_name"][$index];
105 $error = $pictures["error"][$index];
106
107 $_FILES[$this->getPostVar()]["name"][$index] = Util::sanitizeFileName($_FILES[$this->getPostVar()]["name"][$index]);
108
109
110 // error handling
111 if ($error > 0) {
112 switch ($error) {
113 case UPLOAD_ERR_FORM_SIZE:
114 case UPLOAD_ERR_INI_SIZE:
115 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
116 $uploadcheck = false;
117 break;
118
119 case UPLOAD_ERR_PARTIAL:
120 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
121 $uploadcheck = false;
122 break;
123
124 case UPLOAD_ERR_NO_FILE:
125 if ($this->getRequired()) {
126 $filename = $this->filenames[$index];
127 if (!strlen($filename)) {
128 $this->setAlert($lng->txt("form_msg_file_no_upload"));
129 $uploadcheck = false;
130 }
131 }
132 break;
133
134 case UPLOAD_ERR_NO_TMP_DIR:
135 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
136 $uploadcheck = false;
137 break;
138
139 case UPLOAD_ERR_CANT_WRITE:
140 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
141 $uploadcheck = false;
142 break;
143
144 case UPLOAD_ERR_EXTENSION:
145 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
146 $uploadcheck = false;
147 break;
148 }
149 }
150
151 // check suffixes
152 if ($pictures["tmp_name"][$index] != "" && is_array($this->getSuffixes()) && count($this->getSuffixes()) > 0) {
153 if (!in_array(strtolower($suffix), $this->getSuffixes())) {
154 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
155 $uploadcheck = false;
156 }
157 }
158
159 // virus handling
160 if ($pictures["tmp_name"][$index] != "") {
161 $vir = ilVirusScanner::virusHandling($temp_name, $filename);
162 if ($vir[0] == false) {
163 $this->setAlert($lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
164 $uploadcheck = false;
165 }
166 }
167 }
168 }
169
170 if (!$uploadcheck) {
171 return false;
172 }
173
174 return $this->checkSubItemsInput();
175 }
176
177 public function insert(ilTemplate $a_tpl): void
178 {
180
181 $tpl = new ilTemplate("tpl.prop_filewizardinput.html", true, true, "components/ILIAS/Form");
182
183 $i = 0;
184 foreach ($this->filenames as $value) {
185 if (strlen($value)) {
186 $tpl->setCurrentBlock("image");
188 "SRC_IMAGE",
190 $value
191 )
192 );
194 $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
197 }
198 if ($this->getAllowMove()) {
199 $tpl->setCurrentBlock("move");
200 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
201 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
202 $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
203 $tpl->setVariable(
204 "UP_BUTTON",
205 $this->ui_renderer->render(
206 $this->ui_factory->symbol()->glyph()->up()
207 )
208 );
210 "DOWN_BUTTON",
211 $this->ui_renderer->render(
212 $this->ui_factory->symbol()->glyph()->down()
213 )
214 );
216 }
217
218 $this->outputSuffixes($tpl, "allowed_image_suffixes");
219
220 $tpl->setCurrentBlock("row");
221 $tpl->setVariable("POST_VAR", $this->getPostVar() . "[$i]");
222 $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
223 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
224 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
225 $tpl->setVariable("ALT_ADD", $lng->txt("add"));
226 $tpl->setVariable("ALT_REMOVE", $lng->txt("remove"));
227 if ($this->getDisabled()) {
228 $tpl->setVariable(
229 "DISABLED",
230 " disabled=\"disabled\""
231 );
232 }
233
235 "ADD_BUTTON",
236 $this->ui_renderer->render(
237 $this->ui_factory->symbol()->glyph()->add()
238 )
239 );
241 "REMOVE_BUTTON",
242 $this->ui_renderer->render(
243 $this->ui_factory->symbol()->glyph()->remove()
244 )
245 );
246 $tpl->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice") . " " . $this->getMaxFileSizeString());
247 $tpl->setVariable("MAX_UPLOAD_VALUE", $this->getMaxFileUploads());
248 $tpl->setVariable("TXT_MAX_UPLOADS", $lng->txt("form_msg_max_upload") . " " . $this->getMaxFileUploads());
250 $i++;
251 }
252 $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
253
254 $a_tpl->setCurrentBlock("prop_generic");
255 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
256 $a_tpl->parseCurrentBlock();
257
258 $main_tpl = $this->tpl;
259 $main_tpl->addJavascript("assets/js/ServiceFormWizardInput.js");
260 $main_tpl->addJavascript("assets/js/filewizard.js");
261 }
262}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
This class represents a file property in a property form.
getMaxFileUploads()
Get number of maximum file uploads as declared in php.ini.
outputSuffixes(ilTemplate $a_tpl, string $a_block="allowed_suffixes")
This class represents a file wizard property in a property form.
ilGlobalTemplateInterface $tpl
__construct(string $a_title="", string $a_postvar="")
checkInput()
Check input, strip slashes etc.
setFilenames(array $a_filenames)
setAllowMove(bool $a_allow_move)
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)
static virusHandling(string $a_file, string $a_orig_name='', bool $a_clean=true)
setVariable(string $variable, $value='')
Sets the given variable to the given value.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26