ILIAS  release_8 Revision v8.24
class.ilFileWizardInputGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29{
31 protected array $filenames = array();
32 protected bool $allowMove = false;
33 protected string $imagepath_web = "";
34
35 public function __construct(
36 string $a_title = "",
37 string $a_postvar = ""
38 ) {
39 global $DIC;
40
41 $this->lng = $DIC->language();
42 $this->lng->loadLanguageModule("form");
43 $this->tpl = $DIC["tpl"];
44 parent::__construct($a_title, $a_postvar);
45 }
46
47 public function setImagePathWeb(string $a_path): void
48 {
49 $this->imagepath_web = $a_path;
50 }
51
52 public function getImagePathWeb(): string
53 {
55 }
56
57 public function setFilenames(array $a_filenames): void
58 {
59 $this->filenames = $a_filenames;
60 }
61
62 public function getFilenames(): array
63 {
64 return $this->filenames;
65 }
66
67 public function setAllowMove(bool $a_allow_move): void
68 {
69 $this->allowMove = $a_allow_move;
70 }
71
72 public function getAllowMove(): bool
73 {
74 return $this->allowMove;
75 }
76
77 public function checkInput(): bool
78 {
80
81 // see ilFileInputGUI
82 // if no information is received, something went wrong
83 // this is e.g. the case, if the post_max_size has been exceeded
84 if (!isset($_FILES[$this->getPostVar()]) || !is_array($_FILES[$this->getPostVar()])) {
85 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
86 return false;
87 }
88
89 $pictures = $_FILES[$this->getPostVar()];
90 $uploadcheck = true;
91 if (is_array($pictures)) {
92 foreach ($pictures['name'] as $index => $name) {
93 // remove trailing '/'
94 $name = rtrim($name, '/');
95
97 $filename_arr = pathinfo($name);
98 $suffix = $filename_arr["extension"] ?? "";
99 $temp_name = $pictures["tmp_name"][$index];
100 $error = $pictures["error"][$index];
101
102 $_FILES[$this->getPostVar()]["name"][$index] = Util::sanitizeFileName($_FILES[$this->getPostVar()]["name"][$index]);
103
104
105 // error handling
106 if ($error > 0) {
107 switch ($error) {
108 case UPLOAD_ERR_FORM_SIZE:
109 case UPLOAD_ERR_INI_SIZE:
110 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
111 $uploadcheck = false;
112 break;
113
114 case UPLOAD_ERR_PARTIAL:
115 $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
116 $uploadcheck = false;
117 break;
118
119 case UPLOAD_ERR_NO_FILE:
120 if ($this->getRequired()) {
121 $filename = $this->filenames[$index];
122 if (!strlen($filename)) {
123 $this->setAlert($lng->txt("form_msg_file_no_upload"));
124 $uploadcheck = false;
125 }
126 }
127 break;
128
129 case UPLOAD_ERR_NO_TMP_DIR:
130 $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
131 $uploadcheck = false;
132 break;
133
134 case UPLOAD_ERR_CANT_WRITE:
135 $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
136 $uploadcheck = false;
137 break;
138
139 case UPLOAD_ERR_EXTENSION:
140 $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
141 $uploadcheck = false;
142 break;
143 }
144 }
145
146 // check suffixes
147 if ($pictures["tmp_name"][$index] != "" && is_array($this->getSuffixes()) && count($this->getSuffixes()) > 0) {
148 if (!in_array(strtolower($suffix), $this->getSuffixes())) {
149 $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
150 $uploadcheck = false;
151 }
152 }
153
154 // virus handling
155 if ($pictures["tmp_name"][$index] != "") {
156 $vir = ilVirusScanner::virusHandling($temp_name, $filename);
157 if ($vir[0] == false) {
158 $this->setAlert($lng->txt("form_msg_file_virus_found") . "<br />" . $vir[1]);
159 $uploadcheck = false;
160 }
161 }
162 }
163 }
164
165 if (!$uploadcheck) {
166 return false;
167 }
168
169 return $this->checkSubItemsInput();
170 }
171
172 public function insert(ilTemplate $a_tpl): void
173 {
175
176 $tpl = new ilTemplate("tpl.prop_filewizardinput.html", true, true, "Services/Form");
177
178 $i = 0;
179 foreach ($this->filenames as $value) {
180 if (strlen($value)) {
181 $tpl->setCurrentBlock("image");
183 "SRC_IMAGE",
185 $value
186 )
187 );
189 $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
192 }
193 if ($this->getAllowMove()) {
194 $tpl->setCurrentBlock("move");
195 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
196 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
197 $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
198 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
201 }
202
203 $this->outputSuffixes($tpl, "allowed_image_suffixes");
204
205 $tpl->setCurrentBlock("row");
206 $tpl->setVariable("POST_VAR", $this->getPostVar() . "[$i]");
207 $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
208 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
209 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
210 $tpl->setVariable("ALT_ADD", $lng->txt("add"));
211 $tpl->setVariable("ALT_REMOVE", $lng->txt("remove"));
212 if ($this->getDisabled()) {
213 $tpl->setVariable(
214 "DISABLED",
215 " disabled=\"disabled\""
216 );
217 }
218
221 $tpl->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice") . " " . $this->getMaxFileSizeString());
222 $tpl->setVariable("MAX_UPLOAD_VALUE", $this->getMaxFileUploads());
223 $tpl->setVariable("TXT_MAX_UPLOADS", $lng->txt("form_msg_max_upload") . " " . $this->getMaxFileUploads());
225 $i++;
226 }
227 $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
228
229 $a_tpl->setCurrentBlock("prop_generic");
230 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
231 $a_tpl->parseCurrentBlock();
232
233 $main_tpl = $this->tpl;
234 $main_tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
235 $main_tpl->addJavascript("./Services/Form/templates/default/filewizard.js");
236 }
237}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
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)
static get(string $a_glyph, string $a_text="")
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)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
if($format !==null) $name
Definition: metadata.php:247
$index
Definition: metadata.php:145
$i
Definition: metadata.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc