ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
15 private $uniqueId = 0;
16 private $archive_suffixes = array();
17 private $submit_button_name = null;
18 private $cancel_button_name = null;
19
20 private static $uniqueInc = 1;
21
22 static private function getNextUniqueId()
23 {
24 return self::$uniqueInc++;
25 }
26
33 function __construct($a_title = "", $a_postvar = "")
34 {
35 parent::__construct($a_title, $a_postvar);
36 $this->uniqueId = self::getNextUniqueId();
37 }
38
44 function setArchiveSuffixes($a_suffixes)
45 {
46 $this->archive_suffixes = $a_suffixes;
47 }
48
55 {
57 }
58
59 function setCommandButtonNames($a_submit_name, $a_cancel_name)
60 {
61 $this->submit_button_name = $a_submit_name;
62 $this->cancel_button_name = $a_cancel_name;
63 }
64
68 function render($a_mode = "")
69 {
70 global $lng, $tpl, $ilUser;
71
72 $quota_exceeded = $quota_legend = false;
73 if(self::$check_wsp_quota)
74 {
75 include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
77 {
78 $lng->loadLanguageModule("file");
79 return $lng->txt("personal_workspace_quota_exceeded_warning");
80 }
81 else
82 {
84 }
85 }
86
87 // make sure jQuery is loaded
89
90 // add file upload scripts
91 include_once("./Services/FileUpload/classes/class.ilFileUploadGUI.php");
93
94 // load template
95 $this->tpl = new ilTemplate("tpl.prop_dndfiles.html", true, true, "Services/Form");
96
97 // general variables
98 $this->tpl->setVariable("UPLOAD_ID", $this->uniqueId);
99
100 // input
101 $this->tpl->setVariable("FILE_SELECT_ICON", ilObject::_getIcon("", "", "fold"));
102 $this->tpl->setVariable("TXT_SHOW_ALL_DETAILS", $lng->txt('show_all_details'));
103 $this->tpl->setVariable("TXT_HIDE_ALL_DETAILS", $lng->txt('hide_all_details'));
104 $this->tpl->setVariable("TXT_SELECTED_FILES", $lng->txt('selected_files'));
105 $this->tpl->setVariable("TXT_DRAG_FILES_HERE", $lng->txt('drag_files_here'));
106 $this->tpl->setVariable("TXT_NUM_OF_SELECTED_FILES", $lng->txt('num_of_selected_files'));
107 $this->tpl->setVariable("TXT_SELECT_FILES_FROM_COMPUTER", $lng->txt('select_files_from_computer'));
108 $this->tpl->setVariable("TXT_OR", $lng->txt('logic_or'));
109 $this->tpl->setVariable("INPUT_ACCEPT_SUFFIXES", $this->getInputAcceptSuffixes($this->getSuffixes()));
110
111 // info
112 $this->tpl->setCurrentBlock("max_size");
113 $this->tpl->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice")." ".$this->getMaxFileSizeString());
114 $this->tpl->parseCurrentBlock();
115
116 if($quota_legend)
117 {
118 $this->tpl->setVariable("TXT_MAX_SIZE", $quota_legend);
119 $this->tpl->parseCurrentBlock();
120 }
121
122 $this->outputSuffixes($this->tpl);
123
124 // create file upload object
125 $upload = new ilFileUploadGUI("ilFileUploadDropZone_" . $this->uniqueId, $this->uniqueId, false);
126 $upload->enableFormSubmit("ilFileUploadInput_" . $this->uniqueId, $this->submit_button_name, $this->cancel_button_name);
127 $upload->setDropAreaId("ilFileUploadDropArea_" . $this->uniqueId);
128 $upload->setFileListId("ilFileUploadList_" . $this->uniqueId);
129 $upload->setFileSelectButtonId("ilFileUploadFileSelect_" . $this->uniqueId);
130
131 $this->tpl->setVariable("FILE_UPLOAD", $upload->getHTML());
132
133 return $this->tpl->get();
134 }
135
141 function checkInput()
142 {
143 global $lng;
144
145 // if no information is received, something went wrong
146 // this is e.g. the case, if the post_max_size has been exceeded
147 if (!is_array($_FILES[$this->getPostVar()]))
148 {
149 $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
150 return false;
151 }
152
153 // empty file, could be a folder
154 if ($_FILES[$this->getPostVar()]["size"] < 1)
155 {
156 $this->setAlert($lng->txt("error_upload_was_zero_bytes"));
157 return false;
158 }
159
160 // call base
161 $inputValid = parent::checkInput();
162
163 // set additionally sent input on post array
164 if ($inputValid)
165 {
166 $_POST[$this->getPostVar()]["extract"] = isset($_POST["extract"]) ? (bool)$_POST["extract"] : false;
167 $_POST[$this->getPostVar()]["title"] = isset($_POST["title"]) ? $_POST["title"] : "";
168 $_POST[$this->getPostVar()]["description"] = isset($_POST["description"]) ? $_POST["description"] : "";
169 $_POST[$this->getPostVar()]["keep_structure"] = isset($_POST["keep_structure"]) ? (bool)$_POST["keep_structure"] : true;
170
171 include_once("./Services/Utilities/classes/class.ilStr.php");
172 $_POST[$this->getPostVar()]["name"] = ilStr::normalizeUtf8String($_POST[$this->getPostVar()]["name"]);
173 $_POST[$this->getPostVar()]["title"] = ilStr::normalizeUtf8String($_POST[$this->getPostVar()]["title"]);
174
175 }
176
177 return $inputValid;
178 }
179
180 protected function getInputAcceptSuffixes($suffixes)
181 {
182 $list = $delim = "";
183
184 if (is_array($suffixes) && count($suffixes) > 0)
185 {
186 foreach($suffixes as $suffix)
187 {
188 $list .= $delim . "." . $suffix;
189 $delim = ",";
190 }
191 }
192
193 return $list;
194 }
195
196 protected function buildSuffixList($suffixes)
197 {
198 $list = $delim = "";
199
200 if (is_array($suffixes) && count($suffixes) > 0)
201 {
202 foreach($suffixes as $suffix)
203 {
204 $list .= $delim . "\"" . $suffix . "\"";
205 $delim = ", ";
206 }
207 }
208
209 return $list;
210 }
211
212 protected function getMaxFileSize()
213 {
214 // get the value for the maximal uploadable filesize from the php.ini (if available)
215 $umf = ini_get("upload_max_filesize");
216 // get the value for the maximal post data from the php.ini (if available)
217 $pms = ini_get("post_max_size");
218
219 //convert from short-string representation to "real" bytes
220 $multiplier_a=array("K"=>1024, "M"=>1024*1024, "G"=>1024*1024*1024);
221
222 $umf_parts=preg_split("/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
223 $pms_parts=preg_split("/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
224
225 if (count($umf_parts) == 2) {
226 $umf = $umf_parts[0]*$multiplier_a[$umf_parts[1]];
227 }
228 if (count($pms_parts) == 2) {
229 $pms = $pms_parts[0]*$multiplier_a[$pms_parts[1]];
230 }
231
232 // use the smaller one as limit
233 $max_filesize = min($umf, $pms);
234
235 if (!$max_filesize)
236 $max_filesize=max($umf, $pms);
237
238 return $max_filesize;
239 }
240}
241?>
global $tpl
Definition: ilias.php:8
static isUploadPossible($a_additional_size=null)
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.
normalizeUtf8String($a_str)
Normalize UTF8 string.
special template class to simplify handling of ITX/PEAR
static initjQuery($a_tpl=null)
Init jQuery.
$_POST['username']
Definition: cron.php:12
global $lng
Definition: privfeed.php:40
echo;exit;}function LogoutNotification($SessionID) { global $ilDB; $q="SELECT session_id, data FROM usr_session WHERE expires > (\w+)\|/" PREG_SPLIT_NO_EMPTY PREG_SPLIT_DELIM_CAPTURE
global $ilUser
Definition: imgupload.php:15