ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDragDropFileInputGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/Form/classes/class.ilFileInputGUI.php");
5
14{
18 protected $lng;
19
20 private $uniqueId = 0;
21 private $archive_suffixes = array();
22 private $submit_button_name = null;
23 private $cancel_button_name = null;
24
25 private static $uniqueInc = 1;
26
27 private static function getNextUniqueId()
28 {
29 return self::$uniqueInc++;
30 }
31
38 public function __construct($a_title = "", $a_postvar = "")
39 {
40 global $DIC;
41
42 $this->lng = $DIC->language();
43 parent::__construct($a_title, $a_postvar);
44 $this->uniqueId = self::getNextUniqueId();
45 }
46
52 public function setArchiveSuffixes($a_suffixes)
53 {
54 $this->archive_suffixes = $a_suffixes;
55 }
56
62 public function getArchiveSuffixes()
63 {
65 }
66
67 public function setCommandButtonNames($a_submit_name, $a_cancel_name)
68 {
69 $this->submit_button_name = $a_submit_name;
70 $this->cancel_button_name = $a_cancel_name;
71 }
72
76 public function render($a_mode = "")
77 {
79
80 // make sure jQuery is loaded
82
83 // add file upload scripts
84 include_once("./Services/FileUpload/classes/class.ilFileUploadGUI.php");
86
87 // load template
88 $this->tpl = new ilTemplate("tpl.prop_dndfiles.html", true, true, "Services/Form");
89
90 // general variables
91 $this->tpl->setVariable("UPLOAD_ID", $this->uniqueId);
92
93 // input
94 $this->tpl->setVariable("FILE_SELECT_ICON", ilObject::_getIcon("", "", "fold"));
95 $this->tpl->setVariable("TXT_SHOW_ALL_DETAILS", $lng->txt('show_all_details'));
96 $this->tpl->setVariable("TXT_HIDE_ALL_DETAILS", $lng->txt('hide_all_details'));
97 $this->tpl->setVariable("TXT_SELECTED_FILES", $lng->txt('selected_files'));
98 $this->tpl->setVariable("TXT_DRAG_FILES_HERE", $lng->txt('drag_files_here'));
99 $this->tpl->setVariable("TXT_NUM_OF_SELECTED_FILES", $lng->txt('num_of_selected_files'));
100 $this->tpl->setVariable("TXT_SELECT_FILES_FROM_COMPUTER", $lng->txt('select_files_from_computer'));
101 $this->tpl->setVariable("TXT_OR", $lng->txt('logic_or'));
102 $this->tpl->setVariable("INPUT_ACCEPT_SUFFIXES", $this->getInputAcceptSuffixes($this->getSuffixes()));
103
104 // info
105 $this->tpl->setCurrentBlock("max_size");
106 $this->tpl->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice") . " " . $this->getMaxFileSizeString());
107 $this->tpl->parseCurrentBlock();
108
109 if ($quota_legend) {
110 $this->tpl->setVariable("TXT_MAX_SIZE", $quota_legend);
111 $this->tpl->parseCurrentBlock();
112 }
113
114 $this->outputSuffixes($this->tpl);
115
116 // create file upload object
117 $upload = new ilFileUploadGUI("ilFileUploadDropZone_" . $this->uniqueId, $this->uniqueId, false);
118 $upload->enableFormSubmit("ilFileUploadInput_" . $this->uniqueId, $this->submit_button_name, $this->cancel_button_name);
119 $upload->setDropAreaId("ilFileUploadDropArea_" . $this->uniqueId);
120 $upload->setFileListId("ilFileUploadList_" . $this->uniqueId);
121 $upload->setFileSelectButtonId("ilFileUploadFileSelect_" . $this->uniqueId);
122
123 $this->tpl->setVariable("FILE_UPLOAD", $upload->getHTML());
124
125 return $this->tpl->get();
126 }
127
133 public function checkInput()
134 {
136
137 // if no information is received, something went wrong
138 // this is e.g. the case, if the post_max_size has been exceeded
139 if (!is_array($_FILES[$this->getPostVar()])) {
140 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
141 return false;
142 }
143
144 // empty file, could be a folder
145 if ($_FILES[$this->getPostVar()]["size"] < 1) {
146 $this->setAlert($lng->txt("error_upload_was_zero_bytes"));
147 return false;
148 }
149
150 // call base
151 $inputValid = parent::checkInput();
152
153 // set additionally sent input on post array
154 if ($inputValid) {
155 $_POST[$this->getPostVar()]["extract"] = isset($_POST["extract"]) ? (bool) $_POST["extract"] : false;
156 $_POST[$this->getPostVar()]["title"] = isset($_POST["title"]) ? $_POST["title"] : "";
157 $_POST[$this->getPostVar()]["description"] = isset($_POST["description"]) ? $_POST["description"] : "";
158 $_POST[$this->getPostVar()]["keep_structure"] = isset($_POST["keep_structure"]) ? (bool) $_POST["keep_structure"] : true;
159
160 include_once("./Services/Utilities/classes/class.ilStr.php");
161 $_POST[$this->getPostVar()]["name"] = ilStr::normalizeUtf8String($_POST[$this->getPostVar()]["name"]);
162 $_POST[$this->getPostVar()]["title"] = ilStr::normalizeUtf8String($_POST[$this->getPostVar()]["title"]);
163 }
164
165 return $inputValid;
166 }
167
168 protected function getInputAcceptSuffixes($suffixes)
169 {
170 $list = $delim = "";
171
172 if (is_array($suffixes) && count($suffixes) > 0) {
173 foreach ($suffixes as $suffix) {
174 $list .= $delim . "." . $suffix;
175 $delim = ",";
176 }
177 }
178
179 return $list;
180 }
181
182 protected function buildSuffixList($suffixes)
183 {
184 $list = $delim = "";
185
186 if (is_array($suffixes) && count($suffixes) > 0) {
187 foreach ($suffixes as $suffix) {
188 $list .= $delim . "\"" . $suffix . "\"";
189 $delim = ", ";
190 }
191 }
192
193 return $list;
194 }
195
196 protected function getMaxFileSize()
197 {
198 // get the value for the maximal uploadable filesize from the php.ini (if available)
199 $umf = ini_get("upload_max_filesize");
200 // get the value for the maximal post data from the php.ini (if available)
201 $pms = ini_get("post_max_size");
202
203 //convert from short-string representation to "real" bytes
204 $multiplier_a = array("K" => 1024, "M" => 1024 * 1024, "G" => 1024 * 1024 * 1024);
205
206 $umf_parts = preg_split("/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
207 $pms_parts = preg_split("/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
208
209 if (count($umf_parts) == 2) {
210 $umf = $umf_parts[0] * $multiplier_a[$umf_parts[1]];
211 }
212 if (count($pms_parts) == 2) {
213 $pms = $pms_parts[0] * $multiplier_a[$pms_parts[1]];
214 }
215
216 // use the smaller one as limit
217 $max_filesize = min($umf, $pms);
218
219 if (!$max_filesize) {
220 $max_filesize = max($umf, $pms);
221 }
222
223 return $max_filesize;
224 }
225}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a file input property where multiple files can be dopped in a property form.
setArchiveSuffixes($a_suffixes)
Set accepted archive suffixes.
checkInput()
Check input, strip slashes etc.
getArchiveSuffixes()
Get accepted archive suffixes.
__construct($a_title="", $a_postvar="")
Constructor.
setCommandButtonNames($a_submit_name, $a_cancel_name)
This class represents a file property in a property form.
outputSuffixes($a_tpl, $a_block="allowed_suffixes")
getSuffixes()
Get Accepted Suffixes.
static initFileUpload()
Initializes the file upload and loads the needed javascripts and styles.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static normalizeUtf8String($a_str)
Normalize UTF8 string.
special template class to simplify handling of ITX/PEAR
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc