ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilFileUploadGUI Class Reference
+ Collaboration diagram for ilFileUploadGUI:

Public Member Functions

 __construct ($a_drop_zone_id, $a_ref_id=null, $current_obj=false)
 Creates a new file upload GUI. More...
 
 getHTML ()
 Gets the HTML code to enable the file upload. More...
 
 enableFormSubmit ($input_field_id, $a_submit_name, $a_cancel_name)
 
 setMaxFileSize ($a_max)
 Sets the maximum file size in bytes. More...
 
 getMaxFileSize ()
 Gets the maximum file size in bytes. More...
 
 setArchiveSuffixes ($a_suffixes)
 Set accepted archive suffixes. More...
 
 getArchiveSuffixes ()
 Get accepted archive suffixes. More...
 
 setSuffixes ($a_suffixes)
 Set accepted suffixes. More...
 
 getSuffixes ()
 Get accepted suffixes. More...
 
 setInputFieldName ($a_name)
 Sets the name of the input field the files are submitted with. More...
 
 getInputFieldName ()
 Gets the name of the input field the files are submitted with. More...
 
 setDropAreaId ($a_id)
 
 getDropAreaId ()
 
 setFileListId ($a_id)
 
 getFileListId ()
 
 setFileSelectButtonId ($a_id)
 
 getFileSelectButtonId ()
 

Static Public Member Functions

static initFileUpload ()
 Initializes the file upload and loads the needed javascripts and styles. More...
 

Data Fields

const FILE_OBJ_GUI_CLASS = "ilObjFileGUI"
 

Protected Member Functions

 getSharedHtml ()
 Gets the code that is shared by all upload instances. More...
 
 buildSuffixList ($suffixes)
 

Private Member Functions

 getUploadUrl ()
 
 makeJqueryId ($a_id)
 

Private Attributes

 $drop_zone_id = null
 
 $ref_id = null
 
 $current_obj = false
 
 $max_file_size = null
 
 $suffixes = array()
 
 $archive_suffixes = array()
 
 $input_field_name = "upload_files"
 
 $input_field_id = null
 
 $use_form = false
 
 $drop_area_id = null
 
 $submit_button_name = null
 
 $cancel_button_name = null
 
 $file_list_id = null
 
 $file_select_button_id = null
 

Static Private Attributes

static $shared_code_loaded = false
 

Detailed Description

Definition at line 15 of file class.ilFileUploadGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilFileUploadGUI::__construct (   $a_drop_zone_id,
  $a_ref_id = null,
  $current_obj = false 
)

Creates a new file upload GUI.

Definition at line 38 of file class.ilFileUploadGUI.php.

39 {
40 global $ilCtrl;
41
42 $this->drop_zone_id = $a_drop_zone_id;
43 $this->ref_id = $a_ref_id;
44 $this->current_obj = $current_obj;
45 }
global $ilCtrl
Definition: ilias.php:18

References $current_obj, and $ilCtrl.

Member Function Documentation

◆ buildSuffixList()

ilFileUploadGUI::buildSuffixList (   $suffixes)
protected

Definition at line 230 of file class.ilFileUploadGUI.php.

231 {
232 $list = $delim = "";
233
234 if (is_array($suffixes) && count($suffixes) > 0)
235 {
236 foreach($suffixes as $suffix)
237 {
238 $list .= $delim . "\"" . $suffix . "\"";
239 $delim = ", ";
240 }
241 }
242
243 return $list;
244 }

References $suffixes.

Referenced by getHTML().

+ Here is the caller graph for this function:

◆ enableFormSubmit()

ilFileUploadGUI::enableFormSubmit (   $input_field_id,
  $a_submit_name,
  $a_cancel_name 
)

Definition at line 246 of file class.ilFileUploadGUI.php.

247 {
248 $this->use_form = true;
249 $this->input_field_id = $input_field_id;
250 $this->submit_button_name = $a_submit_name;
251 $this->cancel_button_name = $a_cancel_name;
252 }

References $input_field_id.

◆ getArchiveSuffixes()

ilFileUploadGUI::getArchiveSuffixes ( )

Get accepted archive suffixes.

Returns
array Accepted archive suffixes.

Definition at line 287 of file class.ilFileUploadGUI.php.

288 {
290 }

References $archive_suffixes.

Referenced by getHTML().

+ Here is the caller graph for this function:

◆ getDropAreaId()

ilFileUploadGUI::getDropAreaId ( )

Definition at line 337 of file class.ilFileUploadGUI.php.

338 {
339 return $this->drop_area_id;
340 }

References $drop_area_id.

◆ getFileListId()

ilFileUploadGUI::getFileListId ( )

Definition at line 347 of file class.ilFileUploadGUI.php.

348 {
349 return $this->file_list_id;
350 }

References $file_list_id.

◆ getFileSelectButtonId()

ilFileUploadGUI::getFileSelectButtonId ( )

Definition at line 357 of file class.ilFileUploadGUI.php.

References $file_select_button_id.

◆ getHTML()

ilFileUploadGUI::getHTML ( )

Gets the HTML code to enable the file upload.

Returns
string The created HTML.

Definition at line 71 of file class.ilFileUploadGUI.php.

72 {
73 global $lng, $ilCtrl, $tpl;
74
75 // get values
76 $id = $this->ref_id;
77
78 // build options
79 $options = new stdClass();
80 $options->dropZone = $this->makeJqueryId($this->drop_zone_id);
81
82 // set url
83 $url = $this->getUploadUrl();
84 if ($url === false)
85 return "";
86
87 if ($url != null)
88 $options->url = $this->getUploadUrl();
89
90 // get title and replace quotes with HTML entities
91 if ($this->ref_id != null && !$this->use_form)
92 {
93 $title = ilObject::_lookupTitle(ilObject::_lookupObjId($this->ref_id));
94 $title = str_replace("\"", """, $title);
95 $title = str_replace("'", "'", $title);
96 $options->listTitle = $title;
97 }
98
99 // input field (use id if specified)
100 if ($this->input_field_id != null)
101 $options->fileInput = $this->makeJqueryId($this->input_field_id);
102 else if ($this->input_field_name != null)
104
105 // buttons
106 if ($this->submit_button_name != null)
107 $options->submitButton = $this->submit_button_name;
108 if ($this->cancel_button_name != null)
109 $options->cancelButton = $this->cancel_button_name;
110
111 // drop area
112 if ($this->drop_area_id != null)
113 $options->dropArea = $this->makeJqueryId($this->drop_area_id);
114
115 // file list
116 if ($this->file_list_id != null)
117 $options->fileList = $this->makeJqueryId($this->file_list_id);
118
119 // file list
120 if ($this->file_select_button_id != null)
121 $options->fileSelectButton = $this->makeJqueryId($this->file_select_button_id);
122
123 // max size
124 $max_size = $this->getMaxFileSize();
125 if ($max_size != null)
126 $options->maxFileSize = $max_size;
127
128 // allowed extensions
129 $allowed_suffixes = $this->buildSuffixList($this->getSuffixes());
130 if ($allowed_suffixes != "")
131 $options->allowedExtensions = "[" . $allowed_suffixes . "]";
132
133 // supported archive extensions
134 $supported_archives = $this->buildSuffixList($this->getArchiveSuffixes());
135 if ($supported_archives != "")
136 $options->supportedArchives = "[" . $supported_archives . "]";
137
138 // inject load script
139 include_once("./Services/JSON/classes/class.ilJsonUtil.php");
140
141 $onLoadCode = "";
142 if ($this->use_form)
143 $onLoadCode = "var fileUpload$id = new ilFileUpload($id, " . ilJsonUtil::encode($options) . ");";
144 else
145 $onLoadCode = "il.FileUpload.add(\"$id\", " . ilJsonUtil::encode($options) . ", " . ($this->current_obj ? "true" : "false") . ");";
146
147 $tpl->addOnLoadCode($onLoadCode);
148
149 // return shared code
150 return $this->getSharedHtml();
151 }
global $tpl
Definition: ilias.php:8
getArchiveSuffixes()
Get accepted archive suffixes.
getSuffixes()
Get accepted suffixes.
getSharedHtml()
Gets the code that is shared by all upload instances.
getMaxFileSize()
Gets the maximum file size in bytes.
static encode($mixed, $suppress_native=false)
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
global $lng
Definition: privfeed.php:40
$url
Definition: shib_logout.php:72
if(!is_array($argv)) $options

References $cancel_button_name, $ilCtrl, $input_field_name, $lng, $options, $ref_id, $submit_button_name, $tpl, $url, ilObject\_lookupObjId(), ilObject\_lookupTitle(), buildSuffixList(), ilJsonUtil\encode(), getArchiveSuffixes(), getMaxFileSize(), getSharedHtml(), getSuffixes(), getUploadUrl(), and makeJqueryId().

+ Here is the call graph for this function:

◆ getInputFieldName()

ilFileUploadGUI::getInputFieldName ( )

Gets the name of the input field the files are submitted with.

Returns
string The name of the input field.

Definition at line 327 of file class.ilFileUploadGUI.php.

328 {
330 }

References $input_field_name.

◆ getMaxFileSize()

ilFileUploadGUI::getMaxFileSize ( )

Gets the maximum file size in bytes.

Definition at line 267 of file class.ilFileUploadGUI.php.

268 {
270 }

References $max_file_size.

Referenced by getHTML().

+ Here is the caller graph for this function:

◆ getSharedHtml()

ilFileUploadGUI::getSharedHtml ( )
protected

Gets the code that is shared by all upload instances.

Returns
string The shared code by all upload instances.

Definition at line 158 of file class.ilFileUploadGUI.php.

159 {
160 global $lng;
161
162 // already loaded?
163 if (self::$shared_code_loaded)
164 return "";
165
166 // make sure required scripts are loaded
168
169 // load script template
170 $tpl_shared = new ilTemplate("tpl.fileupload_shared.html", true, true, "Services/FileUpload");
171
172 // initialize localized texts
173 $lng->loadLanguageModule("form");
174 $tpl_shared->setCurrentBlock("fileupload_texts");
175 $tpl_shared->setVariable("ERROR_MSG_FILE_TOO_LARGE", $lng->txt("form_msg_file_size_exceeds"));
176 $tpl_shared->setVariable("ERROR_MSG_WRONG_FILE_TYPE", $lng->txt("form_msg_file_wrong_file_type"));
177 $tpl_shared->setVariable("ERROR_MSG_EMPTY_FILE_OR_FOLDER", $lng->txt("error_empty_file_or_folder"));
178 $tpl_shared->setVariable("ERROR_MSG_UPLOAD_ZERO_BYTES", $lng->txt("error_upload_was_zero_bytes"));
179 $tpl_shared->setVariable("QUESTION_CANCEL_ALL", $lng->txt("cancel_file_upload"));
180 $tpl_shared->setVariable("ERROR_MSG_EXTRACT_FAILED", $lng->txt("error_extraction_failed"));
181 $tpl_shared->setVariable("PROGRESS_UPLOADING", $lng->txt("uploading"));
182 $tpl_shared->setVariable("PROGRESS_EXTRACTING", $lng->txt("extracting"));
183 $tpl_shared->setVariable("DROP_FILES_HERE", $lng->txt("drop_files_on_repo_obj_info"));
184 $tpl_shared->parseCurrentBlock();
185
186 // initialize default values
187 $tpl_shared->setCurrentBlock("fileupload_defaults");
188 $tpl_shared->setVariable("CONCURRENT_UPLOADS", ilFileUploadSettings::getConcurrentUploads());
189 $tpl_shared->setVariable("MAX_FILE_SIZE", ilFileUploadUtil::getMaxFileSize());
190 $tpl_shared->setVariable("ALLOWED_SUFFIXES", "");
191 $tpl_shared->setVariable("SUPPORTED_ARCHIVES", "\"zip\"");
192 $tpl_shared->parseCurrentBlock();
193
194 // load panel template
195 $tpl_panel = new ilTemplate("tpl.fileupload_panel_template.html", true, true, "Services/FileUpload");
196 $tpl_panel->setVariable("TXT_HEADER", $lng->txt("upload_files_title"));
197 $tpl_panel->setVariable("TXT_SHOW_ALL_DETAILS", $lng->txt('show_all_details'));
198 $tpl_panel->setVariable("TXT_HIDE_ALL_DETAILS", $lng->txt('hide_all_details'));
199 $tpl_panel->setVariable("TXT_SUBMIT", $lng->txt('upload_files'));
200 $tpl_panel->setVariable("TXT_CANCEL", $lng->txt('cancel'));
201
202 $tpl_shared->setCurrentBlock("fileupload_panel_tmpl");
203 $tpl_shared->setVariable("PANEL_TEMPLATE_HTML", $tpl_panel->get());
204 $tpl_shared->parseCurrentBlock();
205
206 // load row template
207 $tpl_row = new ilTemplate("tpl.fileupload_row_template.html", true, true, "Services/FileUpload");
208 $tpl_row->setVariable("IMG_ALERT", ilUtil::getImagePath("icon_alert.svg"));
209 $tpl_row->setVariable("ALT_ALERT", $lng->txt("alert"));
210 $tpl_row->setVariable("TXT_CANCEL", $lng->txt("cancel"));
211 $tpl_row->setVariable("TXT_REMOVE", $lng->txt("remove"));
212 $tpl_row->setVariable("TXT_TITLE", $lng->txt("title"));
213 $tpl_row->setVariable("TXT_DESCRIPTION", $lng->txt("description"));
214 $tpl_row->setVariable("TXT_EXTRACT", $lng->txt("unzip"));
215 $tpl_row->setVariable("TXT_KEEP_STRUCTURE", $lng->txt("take_over_structure"));
216 $tpl_row->setVariable("TXT_KEEP_STRUCTURE_INFO", $lng->txt("take_over_structure_info"));
217 $tpl_row->setVariable("TXT_PENDING", $lng->txt("upload_pending"));
218
219 $tpl_shared->setCurrentBlock("fileupload_row_tmpl");
220 $tpl_shared->setVariable("ROW_TEMPLATE_HTML", $tpl_row->get());
221 $tpl_shared->parseCurrentBlock();
222
223 // shared code now loaded
224 self::$shared_code_loaded = true;
225
226 // create HTML
227 return $tpl_shared->get();
228 }
static initFileUpload()
Initializes the file upload and loads the needed javascripts and styles.
static getConcurrentUploads()
Gets the number of files that can be uploaded at the same time.
static getMaxFileSize()
Gets the maximum upload file size allowed in bytes.
special template class to simplify handling of ITX/PEAR
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)

References $lng, ilFileUploadSettings\getConcurrentUploads(), ilUtil\getImagePath(), ilFileUploadUtil\getMaxFileSize(), and initFileUpload().

Referenced by getHTML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSuffixes()

ilFileUploadGUI::getSuffixes ( )

Get accepted suffixes.

Returns
array Accepted suffixes.

Definition at line 307 of file class.ilFileUploadGUI.php.

308 {
309 return $this->suffixes;
310 }

References $suffixes.

Referenced by getHTML().

+ Here is the caller graph for this function:

◆ getUploadUrl()

ilFileUploadGUI::getUploadUrl ( )
private

Definition at line 362 of file class.ilFileUploadGUI.php.

363 {
364 global $ilCtrl;
365
366 // return null when the form is used
367 if ($this->use_form)
368 return null;
369
370 // check if supported
372 return false;
373
374 // build upload URL
375 include_once("Modules/File/classes/class.ilObjFileGUI.php");
376 $ilCtrl->setParameterByClass(self::FILE_OBJ_GUI_CLASS, "ref_id", $this->ref_id);
377 $ilCtrl->setParameterByClass(self::FILE_OBJ_GUI_CLASS, "new_type", "file");
378
379 return $ilCtrl->getFormActionByClass(self::FILE_OBJ_GUI_CLASS, "uploadFiles", "", true, false);
380 }
static isUploadSupported()
Determines whether file upload is supported at the current location.

References $ilCtrl, and ilFileUploadUtil\isUploadSupported().

Referenced by getHTML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initFileUpload()

static ilFileUploadGUI::initFileUpload ( )
static

Initializes the file upload and loads the needed javascripts and styles.

Definition at line 50 of file class.ilFileUploadGUI.php.

51 {
52 global $tpl;
53
54 // needed scripts
55 $tpl->addJavaScript("./Services/FileUpload/js/tmpl.js");
56 $tpl->addJavaScript("./Services/FileUpload/js/jquery.ui.widget.js");
57 $tpl->addJavaScript("./Services/FileUpload/js/jquery.iframe-transport.js");
58 $tpl->addJavaScript("./Services/FileUpload/js/jquery.fileupload.js");
59 $tpl->addJavaScript("./Services/FileUpload/js/jquery.ba-dotimeout.min.js");
60 $tpl->addJavaScript("./Services/FileUpload/js/ilFileUpload.js");
61
62 // needed styles
63 $tpl->addCss(ilUtil::getStyleSheetLocation("filesystem", "fileupload.css", "Services/FileUpload"));
64 }
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user

References $tpl, and ilUtil\getStyleSheetLocation().

Referenced by ilObjectGUI\enableDragDropFileUpload(), ilCloudPluginItemCreationListGUI\getGroupedListItems(), getSharedHtml(), ilObjectListGUI\insertFileUpload(), and ilDragDropFileInputGUI\render().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ makeJqueryId()

ilFileUploadGUI::makeJqueryId (   $a_id)
private

Definition at line 382 of file class.ilFileUploadGUI.php.

383 {
384 if ($a_id != null && count($a_id) > 0)
385 {
386 if ($a_id[0] != "#")
387 return "#" . $a_id;
388 }
389
390 return $a_id;
391 }

Referenced by getHTML().

+ Here is the caller graph for this function:

◆ setArchiveSuffixes()

ilFileUploadGUI::setArchiveSuffixes (   $a_suffixes)

Set accepted archive suffixes.

Parameters
array$a_suffixesAccepted archive suffixes.

Definition at line 277 of file class.ilFileUploadGUI.php.

278 {
279 $this->archive_suffixes = $a_suffixes;
280 }

◆ setDropAreaId()

ilFileUploadGUI::setDropAreaId (   $a_id)

Definition at line 332 of file class.ilFileUploadGUI.php.

333 {
334 $this->drop_area_id = $a_id;
335 }

◆ setFileListId()

ilFileUploadGUI::setFileListId (   $a_id)

Definition at line 342 of file class.ilFileUploadGUI.php.

343 {
344 $this->file_list_id = $a_id;
345 }

◆ setFileSelectButtonId()

ilFileUploadGUI::setFileSelectButtonId (   $a_id)

Definition at line 352 of file class.ilFileUploadGUI.php.

353 {
354 $this->file_select_button_id = $a_id;
355 }

◆ setInputFieldName()

ilFileUploadGUI::setInputFieldName (   $a_name)

Sets the name of the input field the files are submitted with.

Parameters
string$a_nameThe name of the input field.

Definition at line 317 of file class.ilFileUploadGUI.php.

318 {
319 $this->input_field_name = $a_name;
320 }

◆ setMaxFileSize()

ilFileUploadGUI::setMaxFileSize (   $a_max)

Sets the maximum file size in bytes.

Parameters
int$a_max_sizeThe maximum file size in bytes.

Definition at line 259 of file class.ilFileUploadGUI.php.

260 {
261 $this->max_file_size = $a_max;
262 }

◆ setSuffixes()

ilFileUploadGUI::setSuffixes (   $a_suffixes)

Set accepted suffixes.

Parameters
array$a_suffixesAccepted suffixes.

Definition at line 297 of file class.ilFileUploadGUI.php.

298 {
299 $this->suffixes = $a_suffixes;
300 }

Field Documentation

◆ $archive_suffixes

ilFileUploadGUI::$archive_suffixes = array()
private

Definition at line 25 of file class.ilFileUploadGUI.php.

Referenced by getArchiveSuffixes().

◆ $cancel_button_name

ilFileUploadGUI::$cancel_button_name = null
private

Definition at line 31 of file class.ilFileUploadGUI.php.

Referenced by getHTML().

◆ $current_obj

ilFileUploadGUI::$current_obj = false
private

Definition at line 22 of file class.ilFileUploadGUI.php.

Referenced by __construct().

◆ $drop_area_id

ilFileUploadGUI::$drop_area_id = null
private

Definition at line 29 of file class.ilFileUploadGUI.php.

Referenced by getDropAreaId().

◆ $drop_zone_id

ilFileUploadGUI::$drop_zone_id = null
private

Definition at line 20 of file class.ilFileUploadGUI.php.

◆ $file_list_id

ilFileUploadGUI::$file_list_id = null
private

Definition at line 32 of file class.ilFileUploadGUI.php.

Referenced by getFileListId().

◆ $file_select_button_id

ilFileUploadGUI::$file_select_button_id = null
private

Definition at line 33 of file class.ilFileUploadGUI.php.

Referenced by getFileSelectButtonId().

◆ $input_field_id

ilFileUploadGUI::$input_field_id = null
private

Definition at line 27 of file class.ilFileUploadGUI.php.

Referenced by enableFormSubmit().

◆ $input_field_name

ilFileUploadGUI::$input_field_name = "upload_files"
private

Definition at line 26 of file class.ilFileUploadGUI.php.

Referenced by getHTML(), and getInputFieldName().

◆ $max_file_size

ilFileUploadGUI::$max_file_size = null
private

Definition at line 23 of file class.ilFileUploadGUI.php.

Referenced by getMaxFileSize().

◆ $ref_id

ilFileUploadGUI::$ref_id = null
private

Definition at line 21 of file class.ilFileUploadGUI.php.

Referenced by getHTML().

◆ $shared_code_loaded

ilFileUploadGUI::$shared_code_loaded = false
staticprivate

Definition at line 18 of file class.ilFileUploadGUI.php.

◆ $submit_button_name

ilFileUploadGUI::$submit_button_name = null
private

Definition at line 30 of file class.ilFileUploadGUI.php.

Referenced by getHTML().

◆ $suffixes

ilFileUploadGUI::$suffixes = array()
private

Definition at line 24 of file class.ilFileUploadGUI.php.

Referenced by buildSuffixList(), and getSuffixes().

◆ $use_form

ilFileUploadGUI::$use_form = false
private

Definition at line 28 of file class.ilFileUploadGUI.php.

◆ FILE_OBJ_GUI_CLASS

const ilFileUploadGUI::FILE_OBJ_GUI_CLASS = "ilObjFileGUI"

Definition at line 17 of file class.ilFileUploadGUI.php.


The documentation for this class was generated from the following file: