ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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.

References $current_obj, $DIC, and $ilCtrl.

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

Member Function Documentation

◆ buildSuffixList()

ilFileUploadGUI::buildSuffixList (   $suffixes)
protected

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

References $list, and $suffixes.

Referenced by getHTML().

249  {
250  $list = $delim = "";
251 
252  if (is_array($suffixes) && count($suffixes) > 0) {
253  foreach ($suffixes as $suffix) {
254  $list .= $delim . "\"" . $suffix . "\"";
255  $delim = ", ";
256  }
257  }
258 
259  return $list;
260  }
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
+ Here is the caller graph for this function:

◆ enableFormSubmit()

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

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

References $input_field_id.

263  {
264  $this->use_form = true;
265  $this->input_field_id = $input_field_id;
266  $this->submit_button_name = $a_submit_name;
267  $this->cancel_button_name = $a_cancel_name;
268  }

◆ getArchiveSuffixes()

ilFileUploadGUI::getArchiveSuffixes ( )

Get accepted archive suffixes.

Returns
array Accepted archive suffixes.

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

References $archive_suffixes.

Referenced by getHTML().

304  {
306  }
+ Here is the caller graph for this function:

◆ getDropAreaId()

ilFileUploadGUI::getDropAreaId ( )

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

References $drop_area_id.

354  {
355  return $this->drop_area_id;
356  }

◆ getFileListId()

ilFileUploadGUI::getFileListId ( )

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

References $file_list_id.

364  {
365  return $this->file_list_id;
366  }

◆ getFileSelectButtonId()

ilFileUploadGUI::getFileSelectButtonId ( )

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

References $file_select_button_id.

374  {
376  }

◆ getHTML()

ilFileUploadGUI::getHTML ( )

Gets the HTML code to enable the file upload.

Returns
string The created HTML.

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

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

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

References $input_field_name.

344  {
346  }

◆ getMaxFileSize()

ilFileUploadGUI::getMaxFileSize ( )

Gets the maximum file size in bytes.

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

References $max_file_size.

Referenced by getHTML().

284  {
285  return $this->max_file_size;
286  }
+ 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 174 of file class.ilFileUploadGUI.php.

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

Referenced by getHTML().

175  {
176  global $DIC;
177  $lng = $DIC['lng'];
178 
179  // already loaded?
180  if (self::$shared_code_loaded) {
181  return "";
182  }
183 
184  // make sure required scripts are loaded
185  self::initFileUpload();
186 
187  // load script template
188  $tpl_shared = new ilTemplate("tpl.fileupload_shared.html", true, true, "Services/FileUpload");
189 
190  // initialize localized texts
191  $lng->loadLanguageModule("form");
192  $tpl_shared->setCurrentBlock("fileupload_texts");
193  $tpl_shared->setVariable("ERROR_MSG_FILE_TOO_LARGE", $lng->txt("form_msg_file_size_exceeds"));
194  $tpl_shared->setVariable("ERROR_MSG_WRONG_FILE_TYPE", $lng->txt("form_msg_file_wrong_file_type"));
195  $tpl_shared->setVariable("ERROR_MSG_EMPTY_FILE_OR_FOLDER", $lng->txt("error_empty_file_or_folder"));
196  $tpl_shared->setVariable("ERROR_MSG_UPLOAD_ZERO_BYTES", $lng->txt("error_upload_was_zero_bytes"));
197  $tpl_shared->setVariable("QUESTION_CANCEL_ALL", $lng->txt("cancel_file_upload"));
198  $tpl_shared->setVariable("ERROR_MSG_EXTRACT_FAILED", $lng->txt("error_extraction_failed"));
199  $tpl_shared->setVariable("PROGRESS_UPLOADING", $lng->txt("uploading"));
200  $tpl_shared->setVariable("PROGRESS_EXTRACTING", $lng->txt("extracting"));
201  $tpl_shared->setVariable("DROP_FILES_HERE", $lng->txt("drop_files_on_repo_obj_info"));
202  $tpl_shared->parseCurrentBlock();
203 
204  // initialize default values
205  $tpl_shared->setCurrentBlock("fileupload_defaults");
206  $tpl_shared->setVariable("CONCURRENT_UPLOADS", ilFileUploadSettings::getConcurrentUploads());
207  $tpl_shared->setVariable("MAX_FILE_SIZE", ilFileUploadUtil::getMaxFileSize());
208  $tpl_shared->setVariable("ALLOWED_SUFFIXES", "");
209  $tpl_shared->setVariable("SUPPORTED_ARCHIVES", "\"zip\"");
210  $tpl_shared->parseCurrentBlock();
211 
212  // load panel template
213  $tpl_panel = new ilTemplate("tpl.fileupload_panel_template.html", true, true, "Services/FileUpload");
214  $tpl_panel->setVariable("TXT_HEADER", $lng->txt("upload_files_title"));
215  $tpl_panel->setVariable("TXT_SHOW_ALL_DETAILS", $lng->txt('show_all_details'));
216  $tpl_panel->setVariable("TXT_HIDE_ALL_DETAILS", $lng->txt('hide_all_details'));
217  $tpl_panel->setVariable("TXT_SUBMIT", $lng->txt('upload_files'));
218  $tpl_panel->setVariable("TXT_CANCEL", $lng->txt('cancel'));
219 
220  $tpl_shared->setCurrentBlock("fileupload_panel_tmpl");
221  $tpl_shared->setVariable("PANEL_TEMPLATE_HTML", $tpl_panel->get());
222  $tpl_shared->parseCurrentBlock();
223 
224  // load row template
225  $tpl_row = new ilTemplate("tpl.fileupload_row_template.html", true, true, "Services/FileUpload");
226  $tpl_row->setVariable("IMG_ALERT", ilUtil::getImagePath("icon_alert.svg"));
227  $tpl_row->setVariable("ALT_ALERT", $lng->txt("alert"));
228  $tpl_row->setVariable("TXT_CANCEL", $lng->txt("cancel"));
229  $tpl_row->setVariable("TXT_REMOVE", $lng->txt("remove"));
230  $tpl_row->setVariable("TXT_TITLE", $lng->txt("title"));
231  $tpl_row->setVariable("TXT_DESCRIPTION", $lng->txt("description"));
232  $tpl_row->setVariable("TXT_EXTRACT", $lng->txt("unzip"));
233  $tpl_row->setVariable("TXT_KEEP_STRUCTURE", $lng->txt("take_over_structure"));
234  $tpl_row->setVariable("TXT_KEEP_STRUCTURE_INFO", $lng->txt("take_over_structure_info"));
235  $tpl_row->setVariable("TXT_PENDING", $lng->txt("upload_pending"));
236 
237  $tpl_shared->setCurrentBlock("fileupload_row_tmpl");
238  $tpl_shared->setVariable("ROW_TEMPLATE_HTML", $tpl_row->get());
239  $tpl_shared->parseCurrentBlock();
240 
241  // shared code now loaded
242  self::$shared_code_loaded = true;
243 
244  // create HTML
245  return $tpl_shared->get();
246  }
global $DIC
Definition: saml.php:7
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.
$lng
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
special template class to simplify handling of ITX/PEAR
+ 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 323 of file class.ilFileUploadGUI.php.

References $suffixes.

Referenced by getHTML().

324  {
325  return $this->suffixes;
326  }
+ Here is the caller graph for this function:

◆ getUploadUrl()

ilFileUploadGUI::getUploadUrl ( )
private

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

References $DIC, $ilCtrl, and ilFileUploadUtil\isUploadSupported().

Referenced by getHTML().

379  {
380  global $DIC;
381  $ilCtrl = $DIC['ilCtrl'];
382 
383  // return null when the form is used
384  if ($this->use_form) {
385  return null;
386  }
387 
388  // check if supported
390  return false;
391  }
392 
393  // build upload URL
394  include_once("Modules/File/classes/class.ilObjFileGUI.php");
395  $ilCtrl->setParameterByClass(self::FILE_OBJ_GUI_CLASS, "ref_id", $this->ref_id);
396  $ilCtrl->setParameterByClass(self::FILE_OBJ_GUI_CLASS, "new_type", "file");
397 
398  return $ilCtrl->getFormActionByClass(self::FILE_OBJ_GUI_CLASS, "uploadFiles", "", true, false);
399  }
global $DIC
Definition: saml.php:7
global $ilCtrl
Definition: ilias.php:18
static isUploadSupported()
Determines whether file upload is supported at the current location.
+ 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 51 of file class.ilFileUploadGUI.php.

References $DIC, $tpl, and ilUtil\getStyleSheetLocation().

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

52  {
53  global $DIC;
54  $tpl = $DIC['tpl'];
55 
56  // needed scripts
57  $tpl->addJavaScript("./Services/FileUpload/js/tmpl.js");
58  $tpl->addJavaScript("./Services/FileUpload/js/jquery.ui.widget.js");
59  $tpl->addJavaScript("./Services/FileUpload/js/jquery.iframe-transport.js");
60  $tpl->addJavaScript("./Services/FileUpload/js/jquery.fileupload.js");
61  $tpl->addJavaScript("./Services/FileUpload/js/jquery.ba-dotimeout.min.js");
62  $tpl->addJavaScript("./Services/FileUpload/js/ilFileUpload.js");
63 
64  // needed styles
65  $tpl->addCss(ilUtil::getStyleSheetLocation("filesystem", "fileupload.css", "Services/FileUpload"));
66  }
global $DIC
Definition: saml.php:7
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
$tpl
Definition: ilias.php:10
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ makeJqueryId()

ilFileUploadGUI::makeJqueryId (   $a_id)
private
Parameters
mixed$a_id
Returns
string

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

Referenced by getHTML().

406  {
407  if (is_string($a_id) && strlen($a_id) > 0 && $a_id[0] !== '#') {
408  return '#' . $a_id;
409  }
410 
411  return $a_id;
412  }
+ 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 293 of file class.ilFileUploadGUI.php.

294  {
295  $this->archive_suffixes = $a_suffixes;
296  }

◆ setDropAreaId()

ilFileUploadGUI::setDropAreaId (   $a_id)

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

349  {
350  $this->drop_area_id = $a_id;
351  }

◆ setFileListId()

ilFileUploadGUI::setFileListId (   $a_id)

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

359  {
360  $this->file_list_id = $a_id;
361  }

◆ setFileSelectButtonId()

ilFileUploadGUI::setFileSelectButtonId (   $a_id)

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

369  {
370  $this->file_select_button_id = $a_id;
371  }

◆ 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 333 of file class.ilFileUploadGUI.php.

334  {
335  $this->input_field_name = $a_name;
336  }

◆ 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 275 of file class.ilFileUploadGUI.php.

276  {
277  $this->max_file_size = $a_max;
278  }

◆ setSuffixes()

ilFileUploadGUI::setSuffixes (   $a_suffixes)

Set accepted suffixes.

Parameters
array$a_suffixesAccepted suffixes.

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

314  {
315  $this->suffixes = $a_suffixes;
316  }

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: