ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
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, $options, ilJsonUtil\encode(), exit, and initUploadForm().

41  {
42  global $ilTabs;
43 
44  $ilTabs->activateTab("content");
45  $this->initUploadForm();
46  echo $this->form->getHTML();
47 
48 
49  $options = new stdClass();
50  $options->dropZone = "#ilFileUploadDropZone_1";
51  $options->fileInput = "#ilFileUploadInput_1";
52  $options->submitButton = "uploadFiles";
53  $options->cancelButton = "cancelAll";
54  $options->dropArea = "#ilFileUploadDropArea_1";
55  $options->fileList = "#ilFileUploadList_1";
56  $options->fileSelectButton = "#ilFileUploadFileSelect_1";
57  echo "<script language='javascript' type='text/javascript'>var fileUpload1 = new ilFileUpload(1, " . ilJsonUtil::encode($options) . ");</script>";
58 
59  $_SESSION["cld_folder_id"] = $_POST["folder_id"];
60 
61  exit;
62  }
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
exit
Definition: login.php:54
$_POST['username']
Definition: cron.php:12
static encode($mixed, $suppress_native=false)
if(!is_array($argv)) $options
+ Here is the call graph for this function:

◆ cancelAll()

ilCloudPluginUploadGUI::cancelAll ( )

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

References exit.

94  {
95  echo "<script language='javascript' type='text/javascript'>window.parent.il.CloudFileList.afterUpload('cancel');</script>";
96  exit;
97  }
exit
Definition: login.php:54

◆ executeCommand()

ilCloudPluginUploadGUI::executeCommand ( )

execute command

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

References $cmd, and $ilCtrl.

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

◆ handleFileUpload()

ilCloudPluginUploadGUI::handleFileUpload (   $file_upload)

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

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

Referenced by uploadFiles().

137  {
138  // create answer object
139  $response = new stdClass();
140  $response->fileName = $_POST["title"];
141  $response->fileSize = intval($file_upload["size"]);
142  $response->fileType = $file_upload["type"];
143  $response->fileUnzipped = $file_upload["extract"];
144  $response->error = null;
145 
147 
148  if ($file_upload["extract"])
149  {
150  $newdir = ilUtil::ilTempnam();
151  ilUtil::makeDir($newdir);
152 
153  include_once './Services/Utilities/classes/class.ilFileUtils.php';
154  try
155  {
156  ilFileUtils::processZipFile($newdir, $file_upload["tmp_name"], $file_upload["keep_structure"]);
157  }
158  catch (Exception $e)
159  {
160  $response->error = $e->getMessage();
161  ilUtil::delDir($newdir);
162  exit;
163  }
164 
165  try
166  {
167  $this->uploadDirectory($newdir, $_SESSION["cld_folder_id"], $file_tree, $file_upload["keep_structure"]);
168  }
169  catch (Exception $e)
170  {
171  $response->error = $e->getMessage();
172  ilUtil::delDir($newdir);
173  exit;
174  }
175 
176  ilUtil::delDir($newdir);
177  return $response;
178  }
179  else
180  {
181  $file_tree->uploadFileToService($_SESSION["cld_folder_id"], $file_upload["tmp_name"], $_POST["title"]);
182  return $response;
183  }
184 
185  }
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
exit
Definition: login.php:54
$_POST['username']
Definition: cron.php:12
uploadDirectory($dir, $parent_id, $file_tree, $keep_structure=true)
Recursive Method to upload a directory.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static ilTempnam()
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
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initUploadForm()

ilCloudPluginUploadGUI::initUploadForm ( )

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

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

Referenced by asyncUploadFile(), and uploadFiles().

65  {
66  global $ilCtrl, $lng;
67 
68  include_once("./Services/Form/classes/class.ilDragDropFileInputGUI.php");
69  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
70 
71  $this->form = new ilPropertyFormGUI();
72  $this->form->setId("upload");
73  $this->form->setMultipart(true);
74  $this->form->setHideLabels();
75 
76  $file = new ilDragDropFileInputGUI($lng->txt("cld_upload_files"), "upload_files");
77  $file->setRequired(true);
78  $this->form->addItem($file);
79 
80  $this->form->addCommandButton("uploadFiles", $lng->txt("upload"));
81  $this->form->addCommandButton("cancelAll", $lng->txt("cancel"));
82 
83  $this->form->setTableWidth("100%");
84  $this->form->setTitle($lng->txt("upload_files_title"));
85 // $this->form->setTitleIcon(ilUtil::getImagePath('icon_file.gif'), $lng->txt('obj_file'));
86  $this->form->setTitleIcon(ilUtil::getImagePath('icon_dcl_file.svg'), $lng->txt('obj_file'));
87 
88  $this->form->setTitle($lng->txt("upload_files"));
89  $this->form->setFormAction($ilCtrl->getFormAction($this, "uploadFiles"));
90  $this->form->setTarget("cld_blank_target");
91  }
print $file
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:40
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 196 of file class.ilCloudPluginUploadGUI.php.

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

Referenced by handleFileUpload().

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

◆ uploadFiles()

ilCloudPluginUploadGUI::uploadFiles ( )

Update properties.

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

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

104  {
105  $response = new stdClass();
106  $response->error = null;
107  $response->debug = null;
108 
109  $this->initUploadForm();
110  if ($this->form->checkInput())
111  {
112  try
113  {
114  $fileresult = $this->handleFileUpload($this->form->getInput("upload_files"));
115  if ($fileresult)
116  {
117  $response = (object)array_merge((array)$response, (array)$fileresult);
118  }
119  } catch (ilException $e)
120  {
121  $response->error = $e->getMessage();
122  }
123  } else
124  {
126  $response->error = $error->getMessage();
127  }
128 
129  // send response object (don't use 'application/json' as IE wants to download it!)
130  header('Vary: Accept');
131  header('Content-type: text/plain');
132  echo ilJsonUtil::encode($response);
133  exit;
134  }
exit
Definition: login.php:54
Base class for ILIAS Exception handling.
static encode($mixed, $suppress_native=false)
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: