ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilCloudPluginUploadGUI Class Reference

Class ilCloudPluginUploadGUI. More...

+ Inheritance diagram for ilCloudPluginUploadGUI:
+ Collaboration diagram for ilCloudPluginUploadGUI:

Public Member Functions

 executeCommand ()
 execute command More...
 
 asyncUploadFile ()
 
 initUploadForm ()
 
 cancelAll ()
 
 uploadFiles ()
 Update properties. More...
 
 handleFileUpload ($file_upload)
 
- Public Member Functions inherited from ilCloudPluginGUI
 __construct ($plugin_service_class)
 
 getPluginObject ()
 
 getPluginHookObject ()
 
 getAdminConfigObject ()
 
 getService ()
 
 txt ($var="")
 
 executeCommand ()
 

Protected Member Functions

 uploadDirectory ($dir, $parent_id, $file_tree, $keep_structure=true)
 Recursive Method to upload a directory. More...
 

Protected Attributes

 $form
 
- Protected Attributes inherited from ilCloudPluginGUI
 $service = null
 

Detailed Description

Class ilCloudPluginUploadGUI.

Standard class for uploading files. Can be overwritten if needed.

Author
Timon Amstutz timon.nosp@m..ams.nosp@m.tutz@.nosp@m.ilub.nosp@m..unib.nosp@m.e.ch
Version
$Id:

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

Member Function Documentation

◆ asyncUploadFile()

ilCloudPluginUploadGUI::asyncUploadFile ( )

Definition at line 40 of file class.ilCloudPluginUploadGUI.php.

References $_POST, $_SESSION, $DIC, PHPMailer\PHPMailer\$options, ilJsonUtil\encode(), exit, and initUploadForm().

41  {
42  global $DIC;
43  $ilTabs = $DIC['ilTabs'];
44 
45  $ilTabs->activateTab("content");
46  $this->initUploadForm();
47  echo $this->form->getHTML();
48 
49 
50  $options = new stdClass();
51  $options->dropZone = "#ilFileUploadDropZone_1";
52  $options->fileInput = "#ilFileUploadInput_1";
53  $options->submitButton = "uploadFiles";
54  $options->cancelButton = "cancelAll";
55  $options->dropArea = "#ilFileUploadDropArea_1";
56  $options->fileList = "#ilFileUploadList_1";
57  $options->fileSelectButton = "#ilFileUploadFileSelect_1";
58  echo "<script language='javascript' type='text/javascript'>var fileUpload1 = new ilFileUpload(1, " . ilJsonUtil::encode($options) . ");</script>";
59 
60  $_SESSION["cld_folder_id"] = $_POST["folder_id"];
61 
62  exit;
63  }
$_SESSION["AccountId"]
global $DIC
Definition: saml.php:7
static encode($mixed, $suppress_native=false)
exit
Definition: backend.php:16
$_POST["username"]
+ Here is the call graph for this function:

◆ cancelAll()

ilCloudPluginUploadGUI::cancelAll ( )

Definition at line 96 of file class.ilCloudPluginUploadGUI.php.

References exit.

97  {
98  echo "<script language='javascript' type='text/javascript'>window.parent.il.CloudFileList.afterUpload('cancel');</script>";
99  exit;
100  }
exit
Definition: backend.php:16

◆ executeCommand()

ilCloudPluginUploadGUI::executeCommand ( )

execute command

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

References $DIC, and $ilCtrl.

27  {
28  global $DIC;
29  $ilCtrl = $DIC['ilCtrl'];
30 
31  $cmd = $ilCtrl->getCmd();
32 
33  switch ($cmd) {
34  default:
35  $this->$cmd();
36  break;
37  }
38  }
global $DIC
Definition: saml.php:7
global $ilCtrl
Definition: ilias.php:18

◆ handleFileUpload()

ilCloudPluginUploadGUI::handleFileUpload (   $file_upload)

Definition at line 134 of file class.ilCloudPluginUploadGUI.php.

References $_POST, $_SESSION, $response, ilUtil\delDir(), exit, ilCloudFileTree\getFileTreeFromSession(), ilUtil\ilTempnam(), ilUtil\makeDir(), ilFileUtils\processZipFile(), and uploadDirectory().

Referenced by uploadFiles().

135  {
136  // create answer object
137  $response = new stdClass();
138  $response->fileName = $_POST["title"];
139  $response->fileSize = intval($file_upload["size"]);
140  $response->fileType = $file_upload["type"];
141  $response->fileUnzipped = $file_upload["extract"];
142  $response->error = null;
143 
145 
146  if ($file_upload["extract"]) {
147  $newdir = ilUtil::ilTempnam();
148  ilUtil::makeDir($newdir);
149 
150  include_once './Services/Utilities/classes/class.ilFileUtils.php';
151  try {
152  ilFileUtils::processZipFile($newdir, $file_upload["tmp_name"], $file_upload["keep_structure"]);
153  } catch (Exception $e) {
154  $response->error = $e->getMessage();
155  ilUtil::delDir($newdir);
156  exit;
157  }
158 
159  try {
160  $this->uploadDirectory($newdir, $_SESSION["cld_folder_id"], $file_tree, $file_upload["keep_structure"]);
161  } catch (Exception $e) {
162  $response->error = $e->getMessage();
163  ilUtil::delDir($newdir);
164  exit;
165  }
166 
167  ilUtil::delDir($newdir);
168  return $response;
169  } else {
170  $file_tree->uploadFileToService($_SESSION["cld_folder_id"], $file_upload["tmp_name"], $_POST["title"]);
171  return $response;
172  }
173  }
$_SESSION["AccountId"]
uploadDirectory($dir, $parent_id, $file_tree, $keep_structure=true)
Recursive Method to upload a directory.
static processZipFile($a_directory, $a_file, $structure, $ref_id=null, $containerType=null, $tree=null, $access_handler=null)
unzips in given directory and processes uploaded zip for use as single files
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
exit
Definition: backend.php:16
$response
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
$_POST["username"]
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initUploadForm()

ilCloudPluginUploadGUI::initUploadForm ( )

Definition at line 65 of file class.ilCloudPluginUploadGUI.php.

References $DIC, $ilCtrl, $lng, ilUtil\getImagePath(), and ilFormPropertyGUI\setRequired().

Referenced by asyncUploadFile(), and uploadFiles().

66  {
67  global $DIC;
68  $ilCtrl = $DIC['ilCtrl'];
69  $lng = $DIC['lng'];
70 
71  include_once("./Services/Form/classes/class.ilDragDropFileInputGUI.php");
72  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
73 
74  $this->form = new ilPropertyFormGUI();
75  $this->form->setId("upload");
76  $this->form->setMultipart(true);
77  $this->form->setHideLabels();
78 
79  $file = new ilDragDropFileInputGUI($lng->txt("cld_upload_files"), "upload_files");
80  $file->setRequired(true);
81  $this->form->addItem($file);
82 
83  $this->form->addCommandButton("uploadFiles", $lng->txt("upload"));
84  $this->form->addCommandButton("cancelAll", $lng->txt("cancel"));
85 
86  $this->form->setTableWidth("100%");
87  $this->form->setTitle($lng->txt("upload_files_title"));
88 // $this->form->setTitleIcon(ilUtil::getImagePath('icon_file.gif'), $lng->txt('obj_file'));
89  $this->form->setTitleIcon(ilUtil::getImagePath('icon_dcl_file.svg'), $lng->txt('obj_file'));
90 
91  $this->form->setTitle($lng->txt("upload_files"));
92  $this->form->setFormAction($ilCtrl->getFormAction($this, "uploadFiles"));
93  $this->form->setTarget("cld_blank_target");
94  }
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
global $ilCtrl
Definition: ilias.php:18
$lng
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
setRequired($a_required)
Set Required.
This class represents a file input property where multiple files can be dopped in a property form...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ uploadDirectory()

ilCloudPluginUploadGUI::uploadDirectory (   $dir,
  $parent_id,
  $file_tree,
  $keep_structure = true 
)
protected

Recursive Method to upload a directory.

Parameters
string$dirpath to directory
int$parent_idid of parent folder
ilCloudFileTree$file_tree
bool$keep_structureif false, only files will be extracted, without folder structure
Exceptions
ilCloudException

Definition at line 184 of file class.ilCloudPluginUploadGUI.php.

References ilFileUtilsException\$BROKEN_FILE, $DIC, and $lng.

Referenced by handleFileUpload().

185  {
186  $dirlist = opendir($dir);
187 
188  while (false !== ($file = readdir($dirlist))) {
189  if (!is_file($dir . "/" . $file) && !is_dir($dir . "/" . $file)) {
190  global $DIC;
191  $lng = $DIC['lng'];
192  throw new ilCloudException($lng->txt("filenames_not_supported"), ilFileUtilsException::$BROKEN_FILE);
193  }
194  if ($file != '.' && $file != '..') {
195  $newpath = $dir . '/' . $file;
196  if (is_dir($newpath)) {
197  if ($keep_structure) {
198  $newnode = $file_tree->addFolderToService($parent_id, basename($newpath));
199  $this->uploadDirectory($newpath, $newnode->getId(), $file_tree);
200  } else {
201  $this->uploadDirectory($newpath, $parent_id, $file_tree, false);
202  }
203  } else {
204  $file_tree->uploadFileToService($parent_id, $newpath, basename($newpath));
205  }
206  }
207  }
208  closedir($dirlist);
209  }
global $DIC
Definition: saml.php:7
uploadDirectory($dir, $parent_id, $file_tree, $keep_structure=true)
Recursive Method to upload a directory.
$lng
Class ilCloudException.
+ Here is the caller graph for this function:

◆ uploadFiles()

ilCloudPluginUploadGUI::uploadFiles ( )

Update properties.

Definition at line 106 of file class.ilCloudPluginUploadGUI.php.

References $response, ilJsonUtil\encode(), exit, handleFileUpload(), initUploadForm(), and ilCloudException\UPLOAD_FAILED.

107  {
108  $response = new stdClass();
109  $response->error = null;
110  $response->debug = null;
111 
112  $this->initUploadForm();
113  if ($this->form->checkInput()) {
114  try {
115  $fileresult = $this->handleFileUpload($this->form->getInput("upload_files"));
116  if ($fileresult) {
117  $response = (object) array_merge((array) $response, (array) $fileresult);
118  }
119  } catch (ilException $e) {
120  $response->error = $e->getMessage();
121  }
122  } else {
124  $response->error = $error->getMessage();
125  }
126 
127  // send response object (don't use 'application/json' as IE wants to download it!)
128  header('Vary: Accept');
129  header('Content-type: text/plain');
131  exit;
132  }
static encode($mixed, $suppress_native=false)
exit
Definition: backend.php:16
Class ilCloudException.
$response
+ Here is the call graph for this function:

Field Documentation

◆ $form

ilCloudPluginUploadGUI::$form
protected

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


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