ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilFileSystemGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
14  public $ctrl;
15 
16  protected $use_upload_directory = false;
17  const CDIR = "cdir";
21  protected $allowed_suffixes = array();
22 
26  protected $forbidden_suffixes = array();
27 
28  public function __construct($a_main_directory)
29  {
30  global $DIC;
31  $lng = $DIC['lng'];
32  $ilCtrl = $DIC['ilCtrl'];
33  $tpl = $DIC['tpl'];
34  $ilias = $DIC['ilias'];
35 
36  $this->ctrl = $ilCtrl;
37  $this->lng = $lng;
38  $this->ilias = $ilias;
39  $this->tpl = $tpl;
40  $this->main_dir = $a_main_directory;
41  $this->post_dir_path = false;
42 
43  $this->defineCommands();
44 
45  $this->file_labels = array();
46  $this->label_enable = false;
47  $this->ctrl->saveParameter($this, self::CDIR);
48  $lng->loadLanguageModule("content");
49  $this->setAllowDirectories(true);
50  $this->setAllowDirectoryCreation(true);
51  $this->setAllowFileCreation(true);
52  //echo "<br>main_dir:".$this->main_dir.":";
53  }
54 
60  public function setAllowedSuffixes($a_suffixes)
61  {
62  $this->allowed_suffixes = $a_suffixes;
63  }
64 
70  public function getAllowedSuffixes()
71  {
73  }
74 
80  public function setForbiddenSuffixes($a_suffixes)
81  {
82  $this->forbidden_suffixes = $a_suffixes;
83  }
84 
90  public function getForbiddenSuffixes()
91  {
93  }
94 
101  public function isValidSuffix($a_suffix)
102  {
103  if (is_array($this->getForbiddenSuffixes()) && in_array($a_suffix, $this->getForbiddenSuffixes())) {
104  return false;
105  }
106  if (is_array($this->getAllowedSuffixes()) && in_array($a_suffix, $this->getAllowedSuffixes())) {
107  return true;
108  }
109  if (!is_array($this->getAllowedSuffixes()) || count($this->getAllowedSuffixes()) == 0) {
110  return true;
111  }
112  return false;
113  }
114 
115 
121  public function setAllowDirectories($a_val)
122  {
123  $this->allow_directories = $a_val;
124  }
125 
131  public function getAllowDirectories()
132  {
133  return $this->allow_directories;
134  }
135 
141  public function setPostDirPath($a_val)
142  {
143  $this->post_dir_path = $a_val;
144  }
145 
151  public function getPostDirPath()
152  {
153  return $this->post_dir_path;
154  }
155 
161  public function setTableId($a_val)
162  {
163  $this->table_id = $a_val;
164  }
165 
171  public function getTableId()
172  {
173  return $this->table_id;
174  }
175 
181  public function setTitle($a_val)
182  {
183  $this->title = $a_val;
184  }
185 
191  public function getTitle()
192  {
193  return $this->title;
194  }
195 
201  public function setUseUploadDirectory($a_val)
202  {
203  $this->use_upload_directory = $a_val;
204  }
205 
211  public function getUseUploadDirectory()
212  {
214  }
215 
222  protected function setPerformedCommand($command, $pars = "")
223  {
224  if (!is_array($pars)) {
225  $pars = array();
226  }
227  $_SESSION["fsys"]["lastcomm"] = array_merge(
228  array("cmd" => $command),
229  $pars
230  );
231  }
232 
238  public function getLastPerformedCommand()
239  {
240  $ret = $_SESSION["fsys"]["lastcomm"];
241  $_SESSION["fsys"]["lastcomm"] = "none";
242  return $ret;
243  }
244 
248  public function executeCommand()
249  {
250  $next_class = $this->ctrl->getNextClass($this);
251  $cmd = $this->ctrl->getCmd("listFiles");
252 
253  switch ($next_class) {
254 
255  default:
256  if (substr($cmd, 0, 11) == "extCommand_") {
257  $ret = $this->extCommand(substr($cmd, 11, strlen($cmd) - 11));
258  } else {
259  $ret = $this->$cmd();
260  }
261  break;
262  }
263 
264  return $ret;
265  }
266 
267 
271  public function addCommand(
272  &$a_obj,
273  $a_func,
274  $a_name,
275  $a_single = true,
276  $a_allow_dir = false
277  ) {
278  $i = count($this->commands);
279 
280  $this->commands[$i]["object"] = $a_obj;
281  $this->commands[$i]["method"] = $a_func;
282  $this->commands[$i]["name"] = $a_name;
283  $this->commands[$i]["single"] = $a_single;
284  $this->commands[$i]["allow_dir"] = $a_allow_dir;
285 
286  //$this->commands[] = $arr;
287  }
288 
292  public function clearCommands()
293  {
294  $this->commands = array();
295  }
296 
300  public function labelFile($a_file, $a_label)
301  {
302  $this->file_labels[$a_file][] = $a_label;
303  }
304 
308  public function activateLabels($a_act, $a_label_header)
309  {
310  $this->label_enable = $a_act;
311  $this->label_header = $a_label_header;
312  }
313 
314 
315 
316  protected function parseCurrentDirectory()
317  {
318  // determine directory
319  // FIXME: I have to call stripSlashes here twice, because I could not
320  // determine where the second layer of slashes is added to the
321  // URL Parameter
322  $cur_subdir = ilUtil::stripSlashes(ilUtil::stripSlashes($_GET[self::CDIR]));
323  $new_subdir = ilUtil::stripSlashes(ilUtil::stripSlashes($_GET["newdir"]));
324 
325  if ($new_subdir == "..") {
326  $cur_subdir = substr($cur_subdir, 0, strrpos($cur_subdir, "/"));
327  } else {
328  if (!empty($new_subdir)) {
329  if (!empty($cur_subdir)) {
330  $cur_subdir = $cur_subdir . "/" . $new_subdir;
331  } else {
332  $cur_subdir = $new_subdir;
333  }
334  }
335  }
336 
337  $cur_subdir = str_replace("..", "", $cur_subdir);
338  $cur_dir = (!empty($cur_subdir))
339  ? $this->main_dir . "/" . $cur_subdir
340  : $this->main_dir;
341 
342  return array("dir"=>$cur_dir, "subdir"=>$cur_subdir);
343  }
344 
345  protected function getFileList($a_dir, $a_subdir = null)
346  {
347  $items = array();
348 
349  $entries = (is_dir($a_dir))
350  ? ilUtil::getDir($a_dir)
351  : array(array("type" => "dir", "entry" => ".."));
352 
353  $items = array();
354  foreach ($entries as $e) {
355  if (($e["entry"] == ".") ||
356  ($e["entry"] == ".." && empty($a_subdir))) {
357  continue;
358  }
359 
360  $cfile = (!empty($a_subdir))
361  ? $a_subdir . "/" . $e["entry"]
362  : $e["entry"];
363 
364  $items[] = array(
365  "file" => $cfile,
366  "entry" => $e["entry"],
367  "type" => $e["type"],
368  "size" => $e["size"],
369  "hash" => md5($e["entry"])
370  );
371  }
372 
373  return $items;
374  }
375 
376  protected function getIncomingFiles()
377  {
378  $sel_files = $hashes = array();
379  if (isset($_POST["file"])) {
380  $hashes = $_POST["file"];
381  } elseif (isset($_GET["fhsh"])) {
382  $hashes = array($_GET["fhsh"]);
383  }
384 
385  if (sizeof($hashes)) {
386  $dir = $this->parseCurrentDirectory();
387  $all_files = $this->getFileList($dir["dir"], $dir["subdir"]);
388  foreach ($hashes as $hash) {
389  foreach ($all_files as $file) {
390  if ($file["hash"] == $hash) {
391  $sel_files[] = $this->getPostDirPath()
392  ? $file["file"]
393  : $file["entry"];
394  break;
395  }
396  }
397  }
398  }
399 
400  return $sel_files;
401  }
402 
406  public function extCommand($a_nr)
407  {
408  $selected = $this->getIncomingFiles();
409 
410  if (!count($selected)) {
411  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
412  $this->ctrl->redirect($this, "listFiles");
413  }
414 
415  // check if only one item is select, if command does not allow multiple selection
416  if (count($selected) > 1 && $this->commands[$a_nr]["single"]) {
417  ilUtil::sendFailure($this->lng->txt("cont_select_max_one_item"), true);
418  $this->ctrl->redirect($this, "listFiles");
419  }
420 
421  $cur_subdir = $this->sanitizeCurrentDirectory();
422 
423  // collect files and
424  $files = array();
425  foreach ($selected as $file) {
426  $file = ilUtil::stripSlashes($file);
427  $file = (!empty($cur_subdir))
428  ? $cur_subdir . "/" . $file
429  : $file;
430 
431  // check wether selected item is a directory
432  if (@is_dir($this->main_dir . "/" . $file) &&
433  !$this->commands[$a_nr]["allow_dir"]) {
434  ilUtil::sendFailure($this->lng->txt("select_a_file"), true);
435  $this->ctrl->redirect($this, "listFiles");
436  }
437 
438  $files[] = $file;
439  }
440 
441  if ($this->commands[$a_nr]["single"]) {
442  $files = array_shift($files);
443  }
444 
445  $obj = $this->commands[$a_nr]["object"];
446  $method = $this->commands[$a_nr]["method"];
447 
448  return $obj->$method($files);
449  }
450 
454  public function setAllowDirectoryCreation($a_val)
455  {
456  $this->directory_creation = $a_val;
457  }
458 
462  public function getAllowDirectoryCreation()
463  {
464  return $this->directory_creation;
465  }
466 
470  public function setAllowFileCreation($a_val)
471  {
472  $this->file_creation = $a_val;
473  }
474 
478  public function getAllowFileCreation()
479  {
480  return $this->file_creation;
481  }
482 
489  public function listFiles($a_table_gui = null)
490  {
491  global $DIC;
492  $ilToolbar = $DIC['ilToolbar'];
493  $lng = $DIC['lng'];
494  $ilCtrl = $DIC['ilCtrl'];
495 
496  $dir = $this->parseCurrentDirectory();
497 
498  $this->ctrl->setParameter($this, self::CDIR, $dir["subdir"]);
499 
500  // toolbar for adding files/directories
501  $ilToolbar->setFormAction($ilCtrl->getFormAction($this), true);
502  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
503 
504  if ($this->getAllowDirectories() && $this->getAllowDirectoryCreation()) {
505  $ti = new ilTextInputGUI($this->lng->txt("cont_new_dir"), "new_dir");
506  $ti->setMaxLength(80);
507  $ti->setSize(10);
508  $ilToolbar->addInputItem($ti, true);
509  $ilToolbar->addFormButton($lng->txt("create"), "createDirectory");
510 
511  $ilToolbar->addSeparator();
512  }
513 
514  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
515  if ($this->getAllowFileCreation()) {
516  $fi = new ilFileInputGUI($this->lng->txt("cont_new_file"), "new_file");
517  $fi->setSize(10);
518  $ilToolbar->addInputItem($fi, true);
519  $ilToolbar->addFormButton($lng->txt("upload"), "uploadFile");
520  }
521 
522  include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
524  $ilToolbar->addSeparator();
526  $options[""] = $lng->txt("cont_select_from_upload_dir");
527  foreach ($files as $file) {
528  $file = htmlspecialchars($file, ENT_QUOTES, "utf-8");
529  $options[$file] = $file;
530  }
531  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
532  $si = new ilSelectInputGUI($this->lng->txt("cont_uploaded_file"), "uploaded_file");
533  $si->setOptions($options);
534  $ilToolbar->addInputItem($si, true);
535  $ilToolbar->addFormButton($lng->txt("copy"), "uploadFile");
536  }
537 
538  $fs_table = $this->getTable($dir["dir"], $dir["subdir"]);
539 
540  if ($this->getTitle() != "") {
541  $fs_table->setTitle($this->getTitle());
542  }
543  if ($_GET["resetoffset"] == 1) {
544  $fs_table->resetOffset();
545  }
546  $this->tpl->setContent($fs_table->getHTML());
547  }
548 
555  public function getTable($a_dir, $a_subdir)
556  {
557  include_once("./Services/FileSystem/classes/class.ilFileSystemTableGUI.php");
558  return new ilFileSystemTableGUI(
559  $this,
560  "listFiles",
561  $a_dir,
562  $a_subdir,
563  $this->label_enable,
564  $this->file_labels,
565  $this->label_header,
566  $this->commands,
567  $this->getPostDirPath(),
568  $this->getTableId()
569  );
570  }
571 
575  public function renameFileForm($a_file)
576  {
577  global $DIC;
578  $lng = $DIC['lng'];
579  $ilCtrl = $DIC['ilCtrl'];
580 
581  $cur_subdir = $this->sanitizeCurrentDirectory();
582  $file = $this->main_dir . "/" . $a_file;
583 
584  $this->ctrl->setParameter($this, "old_name", basename($a_file));
585  $this->ctrl->setParameter($this, self::CDIR, ilUtil::stripSlashes($_GET[self::CDIR]));
586 
587  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
588  $form = new ilPropertyFormGUI();
589 
590  // file/dir name
591  $ti = new ilTextInputGUI($this->lng->txt("name"), "new_name");
592  $ti->setMaxLength(200);
593  $ti->setSize(40);
594  $ti->setValue(basename($a_file));
595  $form->addItem($ti);
596 
597  // save and cancel commands
598  $form->addCommandButton("renameFile", $lng->txt("rename"));
599  $form->addCommandButton("cancelRename", $lng->txt("cancel"));
600  $form->setFormAction($ilCtrl->getFormAction($this, "renameFile"));
601 
602  if (@is_dir($file)) {
603  $form->setTitle($this->lng->txt("cont_rename_dir"));
604  } else {
605  $form->setTitle($this->lng->txt("rename_file"));
606  }
607 
608  $this->tpl->setContent($form->getHTML());
609  }
610 
614  public function renameFile()
615  {
616  global $DIC;
617  $lng = $DIC['lng'];
618 
619  $new_name = str_replace("..", "", ilUtil::stripSlashes($_POST["new_name"]));
620  $new_name = str_replace("/", "", $new_name);
621  if ($new_name == "") {
622  $this->ilias->raiseError($this->lng->txt("enter_new_name"), $this->ilias->error_obj->MESSAGE);
623  }
624 
625  $pi = pathinfo($new_name);
626  $suffix = $pi["extension"];
627  if ($suffix != "" && !$this->isValidSuffix($suffix)) {
628  ilUtil::sendFailure($this->lng->txt("file_no_valid_file_type") . " ($suffix)", true);
629  $this->ctrl->redirect($this, "listFiles");
630  }
631 
632  $cur_subdir = $this->sanitizeCurrentDirectory();
633  $dir = (!empty($cur_subdir))
634  ? $this->main_dir . "/" . $cur_subdir . "/"
635  : $this->main_dir . "/";
636 
637 
638  if (is_dir($dir . ilUtil::stripSlashes($_GET["old_name"]))) {
639  rename($dir . ilUtil::stripSlashes($_GET["old_name"]), $dir . $new_name);
640  } else {
641  include_once("./Services/Utilities/classes/class.ilFileUtils.php");
642 
643  try {
644  ilFileUtils::rename($dir . ilUtil::stripSlashes($_GET["old_name"]), $dir . $new_name);
645  } catch (ilException $e) {
646  ilUtil::sendFailure($e->getMessage(), true);
647  $this->ctrl->redirect($this, "listFiles");
648  }
649  }
650 
651  ilUtil::renameExecutables($this->main_dir);
652  if (@is_dir($dir . $new_name)) {
653  ilUtil::sendSuccess($lng->txt("cont_dir_renamed"), true);
654  $this->setPerformedCommand("rename_dir", array("old_name" => $_GET["old_name"],
655  "new_name" => $new_name));
656  } else {
657  ilUtil::sendSuccess($lng->txt("cont_file_renamed"), true);
658  $this->setPerformedCommand("rename_file", array("old_name" => $_GET["old_name"],
659  "new_name" => $new_name));
660  }
661  $this->ctrl->redirect($this, "listFiles");
662  }
663 
667  public function cancelRename()
668  {
669  $this->ctrl->redirect($this, "listFiles");
670  }
671 
675  public function createDirectory()
676  {
677  global $DIC;
678  $lng = $DIC['lng'];
679 
680  // determine directory
681  $cur_subdir = $this->sanitizeCurrentDirectory();
682  $cur_dir = (!empty($cur_subdir))
683  ? $this->main_dir . "/" . $cur_subdir
684  : $this->main_dir;
685 
686  $new_dir = str_replace(".", "", ilUtil::stripSlashes($_POST["new_dir"]));
687  $new_dir = str_replace("/", "", $new_dir);
688 
689  if (!empty($new_dir)) {
690  ilUtil::makeDir($cur_dir . "/" . $new_dir);
691  if (is_dir($cur_dir . "/" . $new_dir)) {
692  ilUtil::sendSuccess($lng->txt("cont_dir_created"), true);
693  $this->setPerformedCommand("create_dir", array("name" => $new_dir));
694  }
695  } else {
696  ilUtil::sendFailure($lng->txt("cont_enter_a_dir_name"), true);
697  }
698  $this->ctrl->saveParameter($this, self::CDIR);
699  $this->ctrl->redirect($this, 'listFiles');
700  }
701 
706  public function uploadFile()
707  {
708  global $DIC;
709  $lng = $DIC['lng'];
710 
711  // determine directory
712  $cur_subdir = $this->sanitizeCurrentDirectory();
713  $cur_dir = (!empty($cur_subdir))
714  ? $this->main_dir . "/" . $cur_subdir
715  : $this->main_dir;
716 
717  $tgt_file = null;
718 
719  $pi = pathinfo($_FILES["new_file"]["name"]);
720  $suffix = $pi["extension"];
721  if (!$this->isValidSuffix($suffix)) {
722  ilUtil::sendFailure($this->lng->txt("file_no_valid_file_type") . " ($suffix)", true);
723  $this->ctrl->redirect($this, "listFiles");
724  }
725 
726  if (is_file($_FILES["new_file"]["tmp_name"])) {
727  $name = ilUtil::stripSlashes($_FILES["new_file"]["name"]);
728  $tgt_file = $cur_dir . "/" . $name;
729 
730  ilUtil::moveUploadedFile($_FILES["new_file"]["tmp_name"], $name, $tgt_file);
731  } elseif ($_POST["uploaded_file"]) {
732  include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
733 
734  // check if the file is in the ftp directory and readable
735  if (ilUploadFiles::_checkUploadFile($_POST["uploaded_file"])) {
736  $tgt_file = $cur_dir . "/" . ilUtil::stripSlashes($_POST["uploaded_file"]);
737 
738  // copy uploaded file to data directory
739  ilUploadFiles::_copyUploadFile($_POST["uploaded_file"], $tgt_file);
740  }
741  } elseif (trim($_FILES["new_file"]["name"]) == "") {
742  ilUtil::sendFailure($lng->txt("cont_enter_a_file"), true);
743  }
744 
745  if ($tgt_file && is_file($tgt_file)) {
746  $unzip = null;
747 
748  // extract zip?
749  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
750  if (ilMimeTypeUtil::getMimeType($tgt_file) == "application/zip") {
751  $this->ctrl->setParameter($this, "upfile", basename($tgt_file));
752  $url = $this->ctrl->getLinkTarget($this, "unzipFile");
753  $this->ctrl->setParameter($this, "upfile", "");
754 
755  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
756  $unzip = ilLinkButton::getInstance();
757  $unzip->setCaption("unzip");
758  $unzip->setUrl($url);
759  $unzip = " " . $unzip->render();
760  }
761 
762  ilUtil::sendSuccess($lng->txt("cont_file_created") . $unzip, true);
763 
764  $this->setPerformedCommand(
765  "create_file",
766  array("name" => substr($tgt_file, strlen($this->main_dir)+1))
767  );
768  }
769 
770  $this->ctrl->saveParameter($this, self::CDIR);
771 
772  ilUtil::renameExecutables($this->main_dir);
773 
774  $this->ctrl->redirect($this, 'listFiles');
775  }
776 
780  public function confirmDeleteFile(array $a_files)
781  {
782  global $DIC;
783  $ilCtrl = $DIC['ilCtrl'];
784  $tpl = $DIC['tpl'];
785  $lng = $DIC['lng'];
786 
787  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
788  $cgui = new ilConfirmationGUI();
789  $cgui->setFormAction($ilCtrl->getFormAction($this));
790  $cgui->setHeaderText($lng->txt("info_delete_sure"));
791  $cgui->setCancel($lng->txt("cancel"), "listFiles");
792  $cgui->setConfirm($lng->txt("delete"), "deleteFile");
793 
794  foreach ($a_files as $i) {
795  $cgui->addItem("file[]", $i, $i);
796  }
797 
798  $tpl->setContent($cgui->getHTML());
799  }
800 
804  public function deleteFile()
805  {
806  global $DIC;
807  $lng = $DIC['lng'];
808 
809  if (!isset($_POST["file"])) {
810  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
811  }
812 
813  foreach ($_POST["file"] as $post_file) {
814  if (ilUtil::stripSlashes($post_file) == "..") {
815  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
816  break;
817  }
818 
819  $cur_subdir = $this->sanitizeCurrentDirectory();
820  $cur_dir = (!empty($cur_subdir))
821  ? $this->main_dir . "/" . $cur_subdir
822  : $this->main_dir;
823  $pi = pathinfo($post_file);
824  $file = $cur_dir . "/" . ilUtil::stripSlashes($pi["basename"]);
825 
826  if (@is_file($file)) {
827  unlink($file);
828  }
829 
830  if (@is_dir($file)) {
831  $is_dir = true;
833  }
834  }
835 
836  $this->ctrl->saveParameter($this, self::CDIR);
837  if ($is_dir) {
838  ilUtil::sendSuccess($lng->txt("cont_dir_deleted"), true);
839  $this->setPerformedCommand(
840  "delete_dir",
841  array("name" => ilUtil::stripSlashes($post_file))
842  );
843  } else {
844  ilUtil::sendSuccess($lng->txt("cont_file_deleted"), true);
845  $this->setPerformedCommand(
846  "delete_file",
847  array("name" => ilUtil::stripSlashes($post_file))
848  );
849  }
850  $this->ctrl->redirect($this, 'listFiles');
851  }
852 
856  public function unzipFile($a_file = null)
857  {
858  global $DIC;
859  $lng = $DIC['lng'];
860 
861  // #17470 - direct unzip call (after upload)
862  if (!$a_file &&
863  isset($_GET["upfile"])) {
864  $a_file = basename($_GET["upfile"]);
865  }
866 
867  $cur_subdir = $this->sanitizeCurrentDirectory();
868  $cur_dir = (!empty($cur_subdir))
869  ? $this->main_dir . "/" . $cur_subdir
870  : $this->main_dir;
871  $a_file = $this->main_dir . "/" . $a_file;
872 
873  if (@is_file($a_file)) {
874  include_once("./Services/Utilities/classes/class.ilFileUtils.php");
875  $cur_files = array_keys(ilUtil::getDir($cur_dir));
876  $cur_files_r = iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cur_dir)));
877 
878  if ($this->getAllowDirectories()) {
879  ilUtil::unzip($a_file, true);
880  } else {
881  ilUtil::unzip($a_file, true, true);
882  }
883 
884  $new_files = array_keys(ilUtil::getDir($cur_dir));
885  $new_files_r = iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cur_dir)));
886 
887  $diff = array_diff($new_files, $cur_files);
888  $diff_r = array_diff($new_files_r, $cur_files_r);
889 
890  // unlink forbidden file types
891  foreach ($diff_r as $f => $d) {
892  $pi = pathinfo($f);
893  if (!is_dir($f) && !$this->isValidSuffix(strtolower($pi["extension"]))) {
894  ilUtil::sendFailure($lng->txt("file_some_invalid_file_types_removed") . " (" . $pi["extension"] . ")", true);
895  unlink($f);
896  }
897  }
898 
899  if (sizeof($diff)) {
900  if ($this->getAllowDirectories()) {
901  include_once("./Services/Utilities/classes/class.ilFileUtils.php");
902  $new_files = array();
903 
904  foreach ($diff as $new_item) {
905  if (is_dir($cur_dir . "/" . $new_item)) {
906  ilFileUtils::recursive_dirscan($cur_dir . "/" . $new_item, $new_files);
907  }
908  }
909 
910  if (is_array($new_files["path"])) {
911  foreach ($new_files["path"] as $idx => $path) {
912  $path = substr($path, strlen($this->main_dir)+1);
913  $diff[] = $path . $new_files["file"][$idx];
914  }
915  }
916  }
917 
918  $this->setPerformedCommand(
919  "unzip_file",
920  array("name" => substr($file, strlen($this->main_dir)+1),
921  "added" => $diff)
922  );
923  }
924  }
925 
926  ilUtil::renameExecutables($this->main_dir);
927 
928  $this->ctrl->saveParameter($this, self::CDIR);
929  ilUtil::sendSuccess($lng->txt("cont_file_unzipped"), true);
930  $this->ctrl->redirect($this, "listFiles");
931  }
932 
936  public function downloadFile($a_file)
937  {
938  $file = $this->main_dir . "/" . $a_file;
939 
940  if (@is_file($file) && !(@is_dir($file))) {
941  ilUtil::deliverFile($file, basename($a_file));
942  exit;
943  } else {
944  $this->ctrl->saveParameter($this, self::CDIR);
945  $this->ctrl->redirect($this, "listFiles");
946  }
947  }
948 
952  public function getTabs(&$tabs_gui)
953  {
954  global $DIC;
955  $ilCtrl = $DIC['ilCtrl'];
956 
957  $ilCtrl->setParameter($this, "resetoffset", 1);
958  $tabs_gui->addTarget(
959  "cont_list_files",
960  $this->ctrl->getLinkTarget($this, "listFiles"),
961  "listFiles",
962  get_class($this)
963  );
964  $ilCtrl->setParameter($this, "resetoffset", "");
965  }
966 
970  public function getActionCommands()
971  {
972  return $this->commands;
973  }
974 
978  public function defineCommands()
979  {
980  $this->commands = array(
981  0 => array(
982  "object" => $this,
983  "method" => "downloadFile",
984  "name" => $this->lng->txt("download"),
985  "int" => true,
986  "single" => true
987  ),
988  1 => array(
989  "object" => $this,
990  "method" => "confirmDeleteFile",
991  "name" => $this->lng->txt("delete"),
992  "allow_dir" => true,
993  "int" => true
994  ),
995  2 => array(
996  "object" => $this,
997  "method" => "unzipFile",
998  "name" => $this->lng->txt("unzip"),
999  "int" => true,
1000  "single" => true
1001  ),
1002  3 => array(
1003  "object" => $this,
1004  "method" => "renameFileForm",
1005  "name" => $this->lng->txt("rename"),
1006  "allow_dir" => true,
1007  "int" => true,
1008  "single" => true
1009  ),
1010  );
1011  }
1012 
1013 
1017  private function sanitizeCurrentDirectory()
1018  {
1019  global $DIC;
1020 
1021  return str_replace("..", "", ilUtil::stripSlashes($DIC->http()->request()->getQueryParams()[self::CDIR]));
1022  }
1023 }
$files
Definition: add-vimline.php:18
downloadFile($a_file)
delete object file
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
listFiles($a_table_gui=null)
List files.
setTitle($a_val)
Set title.
$_SESSION["AccountId"]
This class represents a selection list property in a property form.
activateLabels($a_act, $a_label_header)
activate file labels
This class represents a property form user interface.
getTableId()
Get table id.
global $DIC
Definition: saml.php:7
setPostDirPath($a_val)
Set post dir path.
$_GET["client_id"]
$tpl
Definition: ilias.php:10
This class represents a file property in a property form.
setAllowDirectories($a_val)
Set allow directories.
renameFileForm($a_file)
list files
getAllowDirectoryCreation()
Get allowed directory creation.
getForbiddenSuffixes()
Get Accepted Suffixes.
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
addCommand(&$a_obj, $a_func, $a_name, $a_single=true, $a_allow_dir=false)
Add command.
static _getUploadDirectory()
Get the directory with uploaded files.
static _getUploadFiles()
Get a list of readable files in the upload directory.
getAllowedSuffixes()
Get allowed Suffixes.
setSize($a_size)
Set Size.
setUseUploadDirectory($a_val)
Set use upload directory.
getLastPerformedCommand()
Get performed command.
getTable($a_dir, $a_subdir)
Get table.
createDirectory()
create directory
clearCommands()
Clear commands.
global $ilCtrl
Definition: ilias.php:18
static rename($a_source, $a_target)
Rename a file.
static getMimeType($a_file='', $a_filename='', $a_mime='')
setTableId($a_val)
Set table id.
setForbiddenSuffixes($a_suffixes)
Set forbidden Suffixes.
executeCommand()
execute command
getTabs(&$tabs_gui)
get tabs
if($format !==null) $name
Definition: metadata.php:146
extCommand($a_nr)
call external command
deleteFile()
delete object file
if(isset($_POST['submit'])) $form
getUseUploadDirectory()
Get use upload directory.
cancelRename()
cancel renaming a file
setAllowedSuffixes($a_suffixes)
Set allowed Suffixes.
This class represents a text property in a property form.
renameFile()
rename a file
redirection script todo: (a better solution should control the processing via a xml file) ...
getAllowDirectories()
Get allow directories.
setMaxLength($a_maxlength)
Set Max Length.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
isValidSuffix($a_suffix)
Is suffix valid?
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
setAllowDirectoryCreation($a_val)
Set allowed directory creation.
__construct($a_main_directory)
defineCommands()
Define commands available.
uploadFile()
Upload file.
getPostDirPath()
Get post dir path.
getFileList($a_dir, $a_subdir=null)
setAllowFileCreation($a_val)
Set allowed file creation.
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.
global $lng
Definition: privfeed.php:17
getAllowFileCreation()
Get allowed file creation.
$ret
Definition: parser.php:6
$i
Definition: disco.tpl.php:19
confirmDeleteFile(array $a_files)
Confirm file deletion.
setPerformedCommand($command, $pars="")
Set performed command.
$url
static recursive_dirscan($dir, &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
static _checkUploadFile($a_file)
Check if a file exists in the upload directory and is readable.
File System Explorer GUI class.
labelFile($a_file, $a_label)
label a file
static _copyUploadFile($a_file, $a_target, $a_raise_errors=true)
copy an uploaded file to the target directory (including virus check)
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
unzipFile($a_file=null)
delete object file
$_POST["username"]
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
Confirmation screen class.
TableGUI class for file system.