ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 41 of file class.ilCloudPluginUploadGUI.php.

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

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

◆ cancelAll()

ilCloudPluginUploadGUI::cancelAll ( )

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

References exit.

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

◆ executeCommand()

ilCloudPluginUploadGUI::executeCommand ( )

execute command

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

References $cmd, $DIC, and $ilCtrl.

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

◆ handleFileUpload()

ilCloudPluginUploadGUI::handleFileUpload (   $file_upload)

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

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

Referenced by uploadFiles().

141  {
142  // create answer object
143  $response = new stdClass();
144  $response->fileName = $_POST["title"];
145  $response->fileSize = intval($file_upload["size"]);
146  $response->fileType = $file_upload["type"];
147  $response->fileUnzipped = $file_upload["extract"];
148  $response->error = null;
149 
151 
152  if ($file_upload["extract"])
153  {
154  $newdir = ilUtil::ilTempnam();
155  ilUtil::makeDir($newdir);
156 
157  include_once './Services/Utilities/classes/class.ilFileUtils.php';
158  try
159  {
160  ilFileUtils::processZipFile($newdir, $file_upload["tmp_name"], $file_upload["keep_structure"]);
161  }
162  catch (Exception $e)
163  {
164  $response->error = $e->getMessage();
165  ilUtil::delDir($newdir);
166  exit;
167  }
168 
169  try
170  {
171  $this->uploadDirectory($newdir, $_SESSION["cld_folder_id"], $file_tree, $file_upload["keep_structure"]);
172  }
173  catch (Exception $e)
174  {
175  $response->error = $e->getMessage();
176  ilUtil::delDir($newdir);
177  exit;
178  }
179 
180  ilUtil::delDir($newdir);
181  return $response;
182  }
183  else
184  {
185  $file_tree->uploadFileToService($_SESSION["cld_folder_id"], $file_upload["tmp_name"], $_POST["title"]);
186  return $response;
187  }
188 
189  }
$_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)
Create a temporary file in an ILIAS writable directory.
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 66 of file class.ilCloudPluginUploadGUI.php.

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

Referenced by asyncUploadFile(), and uploadFiles().

67  {
68  global $DIC;
69  $ilCtrl = $DIC['ilCtrl'];
70  $lng = $DIC['lng'];
71 
72  include_once("./Services/Form/classes/class.ilDragDropFileInputGUI.php");
73  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
74 
75  $this->form = new ilPropertyFormGUI();
76  $this->form->setId("upload");
77  $this->form->setMultipart(true);
78  $this->form->setHideLabels();
79 
80  $file = new ilDragDropFileInputGUI($lng->txt("cld_upload_files"), "upload_files");
81  $file->setRequired(true);
82  $this->form->addItem($file);
83 
84  $this->form->addCommandButton("uploadFiles", $lng->txt("upload"));
85  $this->form->addCommandButton("cancelAll", $lng->txt("cancel"));
86 
87  $this->form->setTableWidth("100%");
88  $this->form->setTitle($lng->txt("upload_files_title"));
89 // $this->form->setTitleIcon(ilUtil::getImagePath('icon_file.gif'), $lng->txt('obj_file'));
90  $this->form->setTitleIcon(ilUtil::getImagePath('icon_dcl_file.svg'), $lng->txt('obj_file'));
91 
92  $this->form->setTitle($lng->txt("upload_files"));
93  $this->form->setFormAction($ilCtrl->getFormAction($this, "uploadFiles"));
94  $this->form->setTarget("cld_blank_target");
95  }
This class represents a property form user interface.
global $ilCtrl
Definition: ilias.php:18
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
global $lng
Definition: privfeed.php:17
global $DIC
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
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 200 of file class.ilCloudPluginUploadGUI.php.

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

Referenced by handleFileUpload().

200  {
201  $dirlist = opendir($dir);
202 
203  while (false !== ($file = readdir ($dirlist)))
204  {
205 
206  if (!is_file($dir . "/" . $file) && !is_dir($dir . "/" . $file))
207  {
208  global $DIC;
209  $lng = $DIC['lng'];
210  throw new ilCloudException($lng->txt("filenames_not_supported") , ilFileUtilsException::$BROKEN_FILE);
211  }
212  if ($file != '.' && $file != '..')
213  {
214  $newpath = $dir.'/'.$file;
215  if (is_dir($newpath))
216  {
217  if($keep_structure)
218  {
219  $newnode = $file_tree->addFolderToService($parent_id, basename($newpath));
220  $this->uploadDirectory($newpath, $newnode->getId(), $file_tree);
221  }
222  else
223  {
224  $this->uploadDirectory($newpath, $parent_id, $file_tree, false);
225  }
226  }
227  else
228  {
229  $file_tree->uploadFileToService($parent_id, $newpath, basename($newpath));
230  }
231  }
232  }
233  closedir($dirlist);
234  }
uploadDirectory($dir, $parent_id, $file_tree, $keep_structure=true)
Recursive Method to upload a directory.
global $lng
Definition: privfeed.php:17
global $DIC
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
Class ilCloudException.
+ Here is the caller graph for this function:

◆ uploadFiles()

ilCloudPluginUploadGUI::uploadFiles ( )

Update properties.

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

References $error, array, ilJsonUtil\encode(), exit, handleFileUpload(), header, initUploadForm(), object, and ilCloudException\UPLOAD_FAILED.

108  {
109  $response = new stdClass();
110  $response->error = null;
111  $response->debug = null;
112 
113  $this->initUploadForm();
114  if ($this->form->checkInput())
115  {
116  try
117  {
118  $fileresult = $this->handleFileUpload($this->form->getInput("upload_files"));
119  if ($fileresult)
120  {
121  $response = (object)array_merge((array)$response, (array)$fileresult);
122  }
123  } catch (ilException $e)
124  {
125  $response->error = $e->getMessage();
126  }
127  } else
128  {
130  $response->error = $error->getMessage();
131  }
132 
133  // send response object (don't use 'application/json' as IE wants to download it!)
134  header('Vary: Accept');
135  header('Content-type: text/plain');
136  echo ilJsonUtil::encode($response);
137  exit;
138  }
$error
Definition: Error.php:17
Base class for ILIAS Exception handling.
static encode($mixed, $suppress_native=false)
Add a drawing to the header
Definition: 04printing.php:69
Create styles array
The data for the language used.
Create new PHPExcel object
obj_idprivate
Class ilCloudException.
+ 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: