ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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, and $DIC.

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: goto.php:24

Member Function Documentation

◆ buildSuffixList()

ilFileUploadGUI::buildSuffixList (   $suffixes)
protected

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

References $suffixes.

Referenced by getHTML().

248  {
249  $list = $delim = "";
250 
251  if (is_array($suffixes) && count($suffixes) > 0) {
252  foreach ($suffixes as $suffix) {
253  $list .= $delim . "\"" . $suffix . "\"";
254  $delim = ", ";
255  }
256  }
257 
258  return $list;
259  }
+ Here is the caller graph for this function:

◆ enableFormSubmit()

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

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

References $input_field_id.

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

◆ getArchiveSuffixes()

ilFileUploadGUI::getArchiveSuffixes ( )

Get accepted archive suffixes.

Returns
array Accepted archive suffixes.

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

References $archive_suffixes.

Referenced by getHTML().

303  {
305  }
+ Here is the caller graph for this function:

◆ getDropAreaId()

ilFileUploadGUI::getDropAreaId ( )

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

References $drop_area_id.

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

◆ getFileListId()

ilFileUploadGUI::getFileListId ( )

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

References $file_list_id.

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

◆ getFileSelectButtonId()

ilFileUploadGUI::getFileSelectButtonId ( )

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

References $file_select_button_id.

373  {
375  }

◆ getHTML()

ilFileUploadGUI::getHTML ( )

Gets the HTML code to enable the file upload.

Returns
string The created HTML.

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

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

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

References $input_field_name.

343  {
345  }

◆ getMaxFileSize()

ilFileUploadGUI::getMaxFileSize ( )

Gets the maximum file size in bytes.

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

References $max_file_size.

Referenced by getHTML().

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

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

Referenced by getHTML().

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

References $suffixes.

Referenced by getHTML().

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

◆ getUploadUrl()

ilFileUploadGUI::getUploadUrl ( )
private

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

References $DIC, and ilFileUploadUtil\isUploadSupported().

Referenced by getHTML().

378  {
379  global $DIC;
380  $ilCtrl = $DIC['ilCtrl'];
381 
382  // return null when the form is used
383  if ($this->use_form) {
384  return null;
385  }
386 
387  // check if supported
389  return false;
390  }
391 
392  // build upload URL
393  include_once("Modules/File/classes/class.ilObjFileGUI.php");
394  $ilCtrl->setParameterByClass(self::FILE_OBJ_GUI_CLASS, "ref_id", $this->ref_id);
395  $ilCtrl->setParameterByClass(self::FILE_OBJ_GUI_CLASS, "new_type", "file");
396 
397  return $ilCtrl->getFormActionByClass(self::FILE_OBJ_GUI_CLASS, "uploadFiles", "", true, false);
398  }
global $DIC
Definition: goto.php:24
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", true, 3);
63  // needed styles
64  $tpl->addCss(ilUtil::getStyleSheetLocation("filesystem", "fileupload.css", "Services/FileUpload"));
65  }
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
global $DIC
Definition: goto.php:24
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
+ 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 404 of file class.ilFileUploadGUI.php.

Referenced by getHTML().

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

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

◆ setDropAreaId()

ilFileUploadGUI::setDropAreaId (   $a_id)

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

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

◆ setFileListId()

ilFileUploadGUI::setFileListId (   $a_id)

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

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

◆ setFileSelectButtonId()

ilFileUploadGUI::setFileSelectButtonId (   $a_id)

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

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

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

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

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

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

◆ setSuffixes()

ilFileUploadGUI::setSuffixes (   $a_suffixes)

Set accepted suffixes.

Parameters
array$a_suffixesAccepted suffixes.

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

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

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: