ILIAS  release_4-4 Revision
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 $ilCtrl.

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

Member Function Documentation

◆ buildSuffixList()

ilFileUploadGUI::buildSuffixList (   $suffixes)
protected

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

References $suffixes.

Referenced by getHTML().

229  {
230  $list = $delim = "";
231 
232  if (is_array($suffixes) && count($suffixes) > 0)
233  {
234  foreach($suffixes as $suffix)
235  {
236  $list .= $delim . "\"" . $suffix . "\"";
237  $delim = ", ";
238  }
239  }
240 
241  return $list;
242  }
+ Here is the caller graph for this function:

◆ enableFormSubmit()

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

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

References $input_field_id.

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

◆ getArchiveSuffixes()

ilFileUploadGUI::getArchiveSuffixes ( )

Get accepted archive suffixes.

Returns
array Accepted archive suffixes.

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

References $archive_suffixes.

Referenced by getHTML().

286  {
288  }
+ Here is the caller graph for this function:

◆ getDropAreaId()

ilFileUploadGUI::getDropAreaId ( )

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

References $drop_area_id.

336  {
337  return $this->drop_area_id;
338  }

◆ getFileListId()

ilFileUploadGUI::getFileListId ( )

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

References $file_list_id.

346  {
347  return $this->file_list_id;
348  }

◆ getFileSelectButtonId()

ilFileUploadGUI::getFileSelectButtonId ( )

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

References $file_select_button_id.

356  {
358  }

◆ 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.

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

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)
103  $options->fileInput = $this->input_field_name;
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  }
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)
if(!is_array($argv)) $options
static _lookupObjId($a_id)
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
getArchiveSuffixes()
Get accepted archive suffixes.
getSuffixes()
Get accepted suffixes.
global $lng
Definition: privfeed.php:40
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 325 of file class.ilFileUploadGUI.php.

References $input_field_name.

326  {
328  }

◆ getMaxFileSize()

ilFileUploadGUI::getMaxFileSize ( )

Gets the maximum file size in bytes.

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

References $max_file_size.

Referenced by getHTML().

266  {
267  return $this->max_file_size;
268  }
+ 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.

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

Referenced by getHTML().

159  {
160  global $lng;
161 
162  // already loaded?
163  if (self::$shared_code_loaded)
164  return "";
165 
166  // make sure required scripts are loaded
167  self::initFileUpload();
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 
200  $tpl_shared->setCurrentBlock("fileupload_panel_tmpl");
201  $tpl_shared->setVariable("PANEL_TEMPLATE_HTML", $tpl_panel->get());
202  $tpl_shared->parseCurrentBlock();
203 
204  // load row template
205  $tpl_row = new ilTemplate("tpl.fileupload_row_template.html", true, true, "Services/FileUpload");
206  $tpl_row->setVariable("IMG_ALERT", ilUtil::getImagePath("icon_alert_s.gif"));
207  $tpl_row->setVariable("ALT_ALERT", $lng->txt("alert"));
208  $tpl_row->setVariable("TXT_CANCEL", $lng->txt("cancel"));
209  $tpl_row->setVariable("TXT_REMOVE", $lng->txt("remove"));
210  $tpl_row->setVariable("TXT_TITLE", $lng->txt("title"));
211  $tpl_row->setVariable("TXT_DESCRIPTION", $lng->txt("description"));
212  $tpl_row->setVariable("TXT_EXTRACT", $lng->txt("unzip"));
213  $tpl_row->setVariable("TXT_KEEP_STRUCTURE", $lng->txt("take_over_structure"));
214  $tpl_row->setVariable("TXT_KEEP_STRUCTURE_INFO", $lng->txt("take_over_structure_info"));
215  $tpl_row->setVariable("TXT_PENDING", $lng->txt("upload_pending"));
216 
217  $tpl_shared->setCurrentBlock("fileupload_row_tmpl");
218  $tpl_shared->setVariable("ROW_TEMPLATE_HTML", $tpl_row->get());
219  $tpl_shared->parseCurrentBlock();
220 
221  // shared code now loaded
222  self::$shared_code_loaded = true;
223 
224  // create HTML
225  return $tpl_shared->get();
226  }
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.
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
global $lng
Definition: privfeed.php:40
+ 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 305 of file class.ilFileUploadGUI.php.

References $suffixes.

Referenced by getHTML().

306  {
307  return $this->suffixes;
308  }
+ Here is the caller graph for this function:

◆ getUploadUrl()

ilFileUploadGUI::getUploadUrl ( )
private

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

References $ilCtrl, and ilFileUploadUtil\isUploadSupported().

Referenced by getHTML().

361  {
362  global $ilCtrl;
363 
364  // return null when the form is used
365  if ($this->use_form)
366  return null;
367 
368  // check if supported
370  return false;
371 
372  // build upload URL
373  include_once("Modules/File/classes/class.ilObjFileGUI.php");
374  $ilCtrl->setParameterByClass(self::FILE_OBJ_GUI_CLASS, "ref_id", $this->ref_id);
375  $ilCtrl->setParameterByClass(self::FILE_OBJ_GUI_CLASS, "new_type", "file");
376 
377  return $ilCtrl->getFormActionByClass(self::FILE_OBJ_GUI_CLASS, "uploadFiles", "", true, false);
378  }
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 50 of file class.ilFileUploadGUI.php.

References $tpl, and ilUtil\getStyleSheetLocation().

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

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
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
+ 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 380 of file class.ilFileUploadGUI.php.

Referenced by getHTML().

381  {
382  if ($a_id != null && count($a_id) > 0)
383  {
384  if ($a_id[0] != "#")
385  return "#" . $a_id;
386  }
387 
388  return $a_id;
389  }
+ 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 275 of file class.ilFileUploadGUI.php.

276  {
277  $this->archive_suffixes = $a_suffixes;
278  }

◆ setDropAreaId()

ilFileUploadGUI::setDropAreaId (   $a_id)

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

331  {
332  $this->drop_area_id = $a_id;
333  }

◆ setFileListId()

ilFileUploadGUI::setFileListId (   $a_id)

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

341  {
342  $this->file_list_id = $a_id;
343  }

◆ setFileSelectButtonId()

ilFileUploadGUI::setFileSelectButtonId (   $a_id)

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

351  {
352  $this->file_select_button_id = $a_id;
353  }

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

316  {
317  $this->input_field_name = $a_name;
318  }

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

258  {
259  $this->max_file_size = $a_max;
260  }

◆ setSuffixes()

ilFileUploadGUI::setSuffixes (   $a_suffixes)

Set accepted suffixes.

Parameters
array$a_suffixesAccepted suffixes.

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

296  {
297  $this->suffixes = $a_suffixes;
298  }

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: