ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  var $ctrl;
15 
16  protected $use_upload_directory = false;
17 
21  protected $allowed_suffixes = array();
22 
26  protected $forbidden_suffixes = array();
27 
28  function __construct($a_main_directory)
29  {
30  global $lng, $ilCtrl, $tpl, $ilias;
31 
32  $this->ctrl = $ilCtrl;
33  $this->lng = $lng;
34  $this->ilias = $ilias;
35  $this->tpl = $tpl;
36  $this->main_dir = $a_main_directory;
37  $this->post_dir_path = false;
38  $this->commands = array(
39  0 => array(
40  "object" => $this,
41  "method" => "downloadFile",
42  "name" => $lng->txt("download"),
43  "int" => true,
44  "single" => true
45  ),
46  1 => array(
47  "object" => $this,
48  "method" => "confirmDeleteFile",
49  "name" => $lng->txt("delete"),
50  "allow_dir" => true,
51  "int" => true
52  ),
53  2 => array(
54  "object" => $this,
55  "method" => "unzipFile",
56  "name" => $lng->txt("unzip"),
57  "int" => true,
58  "single" => true
59  ),
60  3 => array(
61  "object" => $this,
62  "method" => "renameFileForm",
63  "name" => $lng->txt("rename"),
64  "allow_dir" => true,
65  "int" => true,
66  "single" => true
67  ),
68  );
69 
70  $this->file_labels = array();
71  $this->label_enable = false;
72  $this->ctrl->saveParameter($this, "cdir");
73  $lng->loadLanguageModule("content");
74  $this->setAllowDirectories(true);
75  $this->setAllowDirectoryCreation(true);
76  $this->setAllowFileCreation(true);
77 //echo "<br>main_dir:".$this->main_dir.":";
78  }
79 
85  function setAllowedSuffixes($a_suffixes)
86  {
87  $this->allowed_suffixes = $a_suffixes;
88  }
89 
95  function getAllowedSuffixes()
96  {
98  }
99 
105  function setForbiddenSuffixes($a_suffixes)
106  {
107  $this->forbidden_suffixes = $a_suffixes;
108  }
109 
116  {
118  }
119 
126  function isValidSuffix($a_suffix)
127  {
128  if (is_array($this->getForbiddenSuffixes()) && in_array($a_suffix, $this->getForbiddenSuffixes()))
129  {
130  return false;
131  }
132  if (is_array($this->getAllowedSuffixes()) && in_array($a_suffix, $this->getAllowedSuffixes()))
133  {
134  return true;
135  }
136  if (!is_array($this->getAllowedSuffixes()) || count($this->getAllowedSuffixes()) == 0)
137  {
138  return true;
139  }
140  return false;
141  }
142 
143 
149  function setAllowDirectories($a_val)
150  {
151  $this->allow_directories = $a_val;
152  }
153 
160  {
161  return $this->allow_directories;
162  }
163 
169  function setPostDirPath($a_val)
170  {
171  $this->post_dir_path = $a_val;
172  }
173 
179  function getPostDirPath()
180  {
181  return $this->post_dir_path;
182  }
183 
189  function setTableId($a_val)
190  {
191  $this->table_id = $a_val;
192  }
193 
199  function getTableId()
200  {
201  return $this->table_id;
202  }
203 
209  function setTitle($a_val)
210  {
211  $this->title = $a_val;
212  }
213 
219  function getTitle()
220  {
221  return $this->title;
222  }
223 
229  function setUseUploadDirectory($a_val)
230  {
231  $this->use_upload_directory = $a_val;
232  }
233 
240  {
242  }
243 
250  protected function setPerformedCommand($command, $pars = "")
251  {
252  if (!is_array($pars))
253  {
254  $pars = array();
255  }
256  $_SESSION["fsys"]["lastcomm"] = array_merge(
257  array("cmd" => $command), $pars);
258  }
259 
265  public function getLastPerformedCommand()
266  {
267  $ret = $_SESSION["fsys"]["lastcomm"];
268  $_SESSION["fsys"]["lastcomm"] = "none";
269  return $ret;
270  }
271 
275  function executeCommand()
276  {
277  $next_class = $this->ctrl->getNextClass($this);
278  $cmd = $this->ctrl->getCmd("listFiles");
279 
280  switch($next_class)
281  {
282 
283  default:
284  if (substr($cmd, 0, 11) == "extCommand_")
285  {
286  $ret = $this->extCommand(substr($cmd, 11, strlen($cmd) - 11));
287  }
288  else
289  {
290  $ret = $this->$cmd();
291  }
292  break;
293  }
294 
295  return $ret;
296  }
297 
298 
302  function addCommand(&$a_obj, $a_func, $a_name, $a_single = true,
303  $a_allow_dir = false)
304  {
305  $i = count($this->commands);
306 
307  $this->commands[$i]["object"] = $a_obj;
308  $this->commands[$i]["method"] = $a_func;
309  $this->commands[$i]["name"] = $a_name;
310  $this->commands[$i]["single"] = $a_single;
311  $this->commands[$i]["allow_dir"] = $a_allow_dir;
312 
313  //$this->commands[] = $arr;
314  }
315 
319  function clearCommands()
320  {
321  $this->commands = array();
322  }
323 
327  function labelFile($a_file, $a_label)
328  {
329  $this->file_labels[$a_file][] = $a_label;
330  }
331 
335  function activateLabels($a_act, $a_label_header)
336  {
337  $this->label_enable = $a_act;
338  $this->label_header = $a_label_header;
339  }
340 
341 
342 
343  protected function parseCurrentDirectory()
344  {
345  // determine directory
346  // FIXME: I have to call stripSlashes here twice, because I could not
347  // determine where the second layer of slashes is added to the
348  // URL Parameter
349  $cur_subdir = ilUtil::stripSlashes(ilUtil::stripSlashes($_GET["cdir"]));
350  $new_subdir = ilUtil::stripSlashes(ilUtil::stripSlashes($_GET["newdir"]));
351 
352  if($new_subdir == "..")
353  {
354  $cur_subdir = substr($cur_subdir, 0, strrpos($cur_subdir, "/"));
355  }
356  else
357  {
358  if (!empty($new_subdir))
359  {
360  if (!empty($cur_subdir))
361  {
362  $cur_subdir = $cur_subdir."/".$new_subdir;
363  }
364  else
365  {
366  $cur_subdir = $new_subdir;
367  }
368  }
369  }
370 
371  $cur_subdir = str_replace("..", "", $cur_subdir);
372  $cur_dir = (!empty($cur_subdir))
373  ? $this->main_dir."/".$cur_subdir
374  : $this->main_dir;
375 
376  return array("dir"=>$cur_dir, "subdir"=>$cur_subdir);
377  }
378 
379  protected function getFileList($a_dir, $a_subdir = null)
380  {
381  $items = array();
382 
383  $entries = (is_dir($a_dir))
384  ? ilUtil::getDir($a_dir)
385  : array(array("type" => "dir", "entry" => ".."));
386 
387  $items = array();
388  foreach ($entries as $e)
389  {
390  if(($e["entry"] == ".") ||
391  ($e["entry"] == ".." && empty($a_subdir)))
392  {
393  continue;
394  }
395 
396  $cfile = (!empty($a_subdir))
397  ? $a_subdir."/".$e["entry"]
398  : $e["entry"];
399 
400  $items[] = array(
401  "file" => $cfile,
402  "entry" => $e["entry"],
403  "type" => $e["type"],
404  "size" => $e["size"],
405  "hash" => md5($e["entry"])
406  );
407  }
408 
409  return $items;
410  }
411 
412  protected function getIncomingFiles()
413  {
414  $sel_files = $hashes = array();
415  if (isset($_POST["file"]))
416  {
417  $hashes = $_POST["file"];
418  }
419  else if(isset($_GET["fhsh"]))
420  {
421  $hashes = array($_GET["fhsh"]);
422  }
423 
424  if(sizeof($hashes))
425  {
426  $dir = $this->parseCurrentDirectory();
427  $all_files = $this->getFileList($dir["dir"], $dir["subdir"]);
428  foreach($hashes as $hash)
429  {
430  foreach($all_files as $file)
431  {
432  if($file["hash"] == $hash)
433  {
434  $sel_files[] = $this->getPostDirPath()
435  ? $file["file"]
436  : $file["entry"];
437  break;
438  }
439  }
440  }
441  }
442 
443  return $sel_files;
444  }
445 
449  function extCommand($a_nr)
450  {
451  $selected = $this->getIncomingFiles();
452 
453  if(!count($selected))
454  {
455  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
456  $this->ctrl->redirect($this, "listFiles");
457  }
458 
459  // check if only one item is select, if command does not allow multiple selection
460  if (count($selected) > 1 && $this->commands[$a_nr]["single"])
461  {
462  ilUtil::sendFailure($this->lng->txt("cont_select_max_one_item"), true);
463  $this->ctrl->redirect($this, "listFiles");
464  }
465 
466  $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
467 
468  // collect files and
469  $files = array();
470  foreach ($selected as $file)
471  {
472  $file = ilUtil::stripSlashes($file);
473  $file = (!empty($cur_subdir))
474  ? $cur_subdir."/".$file
475  : $file;
476 
477  // check wether selected item is a directory
478  if (@is_dir($this->main_dir."/".$file) &&
479  !$this->commands[$a_nr]["allow_dir"])
480  {
481  ilUtil::sendFailure($this->lng->txt("select_a_file"), true);
482  $this->ctrl->redirect($this, "listFiles");
483  }
484 
485  $files[] = $file;
486  }
487 
488  if ($this->commands[$a_nr]["single"])
489  {
490  $files = array_shift($files);
491  }
492 
493  $obj = $this->commands[$a_nr]["object"];
494  $method = $this->commands[$a_nr]["method"];
495 
496  return $obj->$method($files);
497  }
498 
502  public function setAllowDirectoryCreation($a_val)
503  {
504  $this->directory_creation = $a_val;
505  }
506 
510  public function getAllowDirectoryCreation()
511  {
512  return $this->directory_creation;
513  }
514 
518  public function setAllowFileCreation($a_val)
519  {
520  $this->file_creation = $a_val;
521  }
522 
526  public function getAllowFileCreation()
527  {
528  return $this->file_creation;
529  }
530 
534  function listFiles()
535  {
536  global $ilToolbar, $lng, $ilCtrl;
537 
538  $dir = $this->parseCurrentDirectory();
539 
540  $this->ctrl->setParameter($this, "cdir", $dir["subdir"]);
541 
542  // toolbar for adding files/directories
543  $ilToolbar->setFormAction($ilCtrl->getFormAction($this), true);
544  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
545 
546  if ($this->getAllowDirectories() && $this->getAllowDirectoryCreation())
547  {
548  $ti = new ilTextInputGUI($this->lng->txt("cont_new_dir"), "new_dir");
549  $ti->setMaxLength(80);
550  $ti->setSize(10);
551  $ilToolbar->addInputItem($ti, true);
552  $ilToolbar->addFormButton($lng->txt("create"), "createDirectory");
553 
554  $ilToolbar->addSeparator();
555  }
556 
557  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
558  if ($this->getAllowFileCreation())
559  {
560  $fi = new ilFileInputGUI($this->lng->txt("cont_new_file"), "new_file");
561  $fi->setSize(10);
562  $ilToolbar->addInputItem($fi, true);
563  $ilToolbar->addFormButton($lng->txt("upload"), "uploadFile");
564  }
565 
566  include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
568  {
569  $ilToolbar->addSeparator();
571  $options[""] = $lng->txt("cont_select_from_upload_dir");
572  foreach($files as $file)
573  {
574  $file = htmlspecialchars($file, ENT_QUOTES, "utf-8");
575  $options[$file] = $file;
576  }
577  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
578  $si = new ilSelectInputGUI($this->lng->txt("cont_uploaded_file"), "uploaded_file");
579  $si->setOptions($options);
580  $ilToolbar->addInputItem($si, true);
581  $ilToolbar->addFormButton($lng->txt("copy"), "uploadFile");
582  }
583 
584  // load files templates
585  include_once("./Services/FileSystem/classes/class.ilFileSystemTableGUI.php");
586  $fs_table = new ilFileSystemTableGUI($this, "listFiles", $dir["dir"], $dir["subdir"],
587  $this->label_enable, $this->file_labels, $this->label_header, $this->commands,
588  $this->getPostDirPath(), $this->getTableId());
589  if ($this->getTitle() != "")
590  {
591  $fs_table->setTitle($this->getTitle());
592  }
593  if ($_GET["resetoffset"] == 1)
594  {
595  $fs_table->resetOffset();
596  }
597  $this->tpl->setContent($fs_table->getHTML());
598  }
599 
603  function renameFileForm($a_file)
604  {
605  global $lng, $ilCtrl;
606 
607  $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
608  $file = $this->main_dir."/".$a_file;
609 
610  $this->ctrl->setParameter($this, "old_name", basename($a_file));
611  $this->ctrl->setParameter($this, "cdir", ilUtil::stripSlashes($_GET["cdir"]));
612 
613  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
614  $form = new ilPropertyFormGUI();
615 
616  // file/dir name
617  $ti = new ilTextInputGUI($this->lng->txt("name"), "new_name");
618  $ti->setMaxLength(200);
619  $ti->setSize(40);
620  $ti->setValue(basename($a_file));
621  $form->addItem($ti);
622 
623  // save and cancel commands
624  $form->addCommandButton("renameFile", $lng->txt("rename"));
625  $form->addCommandButton("cancelRename", $lng->txt("cancel"));
626  $form->setFormAction($ilCtrl->getFormAction($this, "renameFile"));
627 
628  if (@is_dir($file))
629  {
630  $form->setTitle($this->lng->txt("cont_rename_dir"));
631  }
632  else
633  {
634  $form->setTitle($this->lng->txt("rename_file"));
635  }
636 
637  $this->tpl->setContent($form->getHTML());
638  }
639 
643  function renameFile()
644  {
645  global $lng;
646 
647  $new_name = str_replace("..", "", ilUtil::stripSlashes($_POST["new_name"]));
648  $new_name = str_replace("/", "", $new_name);
649  if ($new_name == "")
650  {
651  $this->ilias->raiseError($this->lng->txt("enter_new_name"),$this->ilias->error_obj->MESSAGE);
652  }
653 
654  $pi = pathinfo($new_name);
655  $suffix = $pi["extension"];
656  if ($suffix != "" && !$this->isValidSuffix($suffix))
657  {
658  ilUtil::sendFailure($this->lng->txt("file_no_valid_file_type")." ($suffix)", true);
659  $this->ctrl->redirect($this, "listFiles");
660  }
661 
662  $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
663  $dir = (!empty($cur_subdir))
664  ? $this->main_dir."/".$cur_subdir."/"
665  : $this->main_dir."/";
666 
667 
668  if (is_dir($dir.ilUtil::stripSlashes($_GET["old_name"])))
669  {
670  rename($dir.ilUtil::stripSlashes($_GET["old_name"]), $dir.$new_name);
671  }
672  else
673  {
674  include_once("./Services/Utilities/classes/class.ilFileUtils.php");
675 
676  try
677  {
678  ilFileUtils::rename($dir . ilUtil::stripSlashes($_GET["old_name"]), $dir . $new_name);
679  } catch (ilException $e)
680  {
681  ilUtil::sendFailure($e->getMessage(), true);
682  $this->ctrl->redirect($this, "listFiles");
683  }
684  }
685 
686  ilUtil::renameExecutables($this->main_dir);
687  if (@is_dir($dir.$new_name))
688  {
689  ilUtil::sendSuccess($lng->txt("cont_dir_renamed"), true);
690  $this->setPerformedCommand("rename_dir", array("old_name" => $_GET["old_name"],
691  "new_name" => $new_name));
692  }
693  else
694  {
695  ilUtil::sendSuccess($lng->txt("cont_file_renamed"), true);
696  $this->setPerformedCommand("rename_file", array("old_name" => $_GET["old_name"],
697  "new_name" => $new_name));
698  }
699  $this->ctrl->redirect($this, "listFiles");
700  }
701 
705  function cancelRename()
706  {
707  $this->ctrl->redirect($this, "listFiles");
708  }
709 
713  function createDirectory()
714  {
715  global $lng;
716 
717  // determine directory
718  $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
719  $cur_dir = (!empty($cur_subdir))
720  ? $this->main_dir."/".$cur_subdir
721  : $this->main_dir;
722 
723  $new_dir = str_replace(".", "", ilUtil::stripSlashes($_POST["new_dir"]));
724  $new_dir = str_replace("/", "", $new_dir);
725 
726  if (!empty($new_dir))
727  {
728  ilUtil::makeDir($cur_dir."/".$new_dir);
729  if (is_dir($cur_dir."/".$new_dir))
730  {
731  ilUtil::sendSuccess($lng->txt("cont_dir_created"), true);
732  $this->setPerformedCommand("create_dir", array("name" => $new_dir));
733  }
734  }
735  else
736  {
737  ilUtil::sendFailure($lng->txt("cont_enter_a_dir_name"), true);
738  }
739  $this->ctrl->saveParameter($this, "cdir");
740  $this->ctrl->redirect($this, "listFiles");
741  }
742 
746  function uploadFile()
747  {
748  global $lng;
749 
750  // determine directory
751  $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
752  $cur_dir = (!empty($cur_subdir))
753  ? $this->main_dir."/".$cur_subdir
754  : $this->main_dir;
755 
756  $tgt_file = null;
757 
758  $pi = pathinfo($_FILES["new_file"]["name"]);
759  $suffix = $pi["extension"];
760  if (!$this->isValidSuffix($suffix))
761  {
762  ilUtil::sendFailure($this->lng->txt("file_no_valid_file_type")." ($suffix)", true);
763  $this->ctrl->redirect($this, "listFiles");
764  }
765 
766  if (is_file($_FILES["new_file"]["tmp_name"]))
767  {
768  $name = ilUtil::stripSlashes($_FILES["new_file"]["name"]);
769  $tgt_file = $cur_dir."/".$name;
770 
771  ilUtil::moveUploadedFile($_FILES["new_file"]["tmp_name"], $name, $tgt_file);
772 
773  }
774  elseif ($_POST["uploaded_file"])
775  {
776  include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
777 
778  // check if the file is in the ftp directory and readable
779  if (ilUploadFiles::_checkUploadFile($_POST["uploaded_file"]))
780  {
781  $tgt_file = $cur_dir."/".ilUtil::stripSlashes($_POST["uploaded_file"]);
782 
783  // copy uploaded file to data directory
784  ilUploadFiles::_copyUploadFile($_POST["uploaded_file"], $tgt_file);
785  }
786  }
787  else if (trim($_FILES["new_file"]["name"]) == "")
788  {
789  ilUtil::sendFailure($lng->txt("cont_enter_a_file"), true);
790  }
791 
792  if($tgt_file && is_file($tgt_file))
793  {
794  $unzip = null;
795 
796  // extract zip?
797  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
798  if(ilMimeTypeUtil::getMimeType($tgt_file) == "application/zip")
799  {
800  $this->ctrl->setParameter($this, "upfile", basename($tgt_file));
801  $url = $this->ctrl->getLinkTarget($this, "unzipFile");
802  $this->ctrl->setParameter($this, "upfile", "");
803 
804  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
805  $unzip = ilLinkButton::getInstance();
806  $unzip->setCaption("unzip");
807  $unzip->setUrl($url);
808  $unzip = " ".$unzip->render();
809  }
810 
811  ilUtil::sendSuccess($lng->txt("cont_file_created").$unzip, true);
812 
813  $this->setPerformedCommand("create_file",
814  array("name" => substr($tgt_file, strlen($this->main_dir)+1)));
815  }
816 
817  $this->ctrl->saveParameter($this, "cdir");
818 
819  ilUtil::renameExecutables($this->main_dir);
820 
821  $this->ctrl->redirect($this, "listFiles");
822  }
823 
827  function confirmDeleteFile(array $a_files)
828  {
829  global $ilCtrl, $tpl, $lng;
830 
831  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
832  $cgui = new ilConfirmationGUI();
833  $cgui->setFormAction($ilCtrl->getFormAction($this));
834  $cgui->setHeaderText($lng->txt("info_delete_sure"));
835  $cgui->setCancel($lng->txt("cancel"), "listFiles");
836  $cgui->setConfirm($lng->txt("delete"), "deleteFile");
837 
838  foreach ($a_files as $i)
839  {
840  $cgui->addItem("file[]", $i, $i);
841  }
842 
843  $tpl->setContent($cgui->getHTML());
844  }
845 
849  function deleteFile()
850  {
851  global $lng;
852 
853  if (!isset($_POST["file"]))
854  {
855  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
856  }
857 
858  foreach ($_POST["file"] as $post_file)
859  {
860  if (ilUtil::stripSlashes($post_file) == "..")
861  {
862  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
863  break;
864  }
865 
866  $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
867  $cur_dir = (!empty($cur_subdir))
868  ? $this->main_dir."/".$cur_subdir
869  : $this->main_dir;
870  $pi = pathinfo($post_file);
871  $file = $cur_dir."/".ilUtil::stripSlashes($pi["basename"]);
872 
873  if (@is_file($file))
874  {
875  unlink($file);
876  }
877 
878  if (@is_dir($file))
879  {
880  $is_dir = true;
882  }
883  }
884 
885  $this->ctrl->saveParameter($this, "cdir");
886  if ($is_dir)
887  {
888  ilUtil::sendSuccess($lng->txt("cont_dir_deleted"), true);
889  $this->setPerformedCommand("delete_dir",
890  array("name" => ilUtil::stripSlashes($post_file)));
891  }
892  else
893  {
894  ilUtil::sendSuccess($lng->txt("cont_file_deleted"), true);
895  $this->setPerformedCommand("delete_file",
896  array("name" => ilUtil::stripSlashes($post_file)));
897  }
898  $this->ctrl->redirect($this, "listFiles");
899  }
900 
904  function unzipFile($a_file = null)
905  {
906  global $lng;
907 
908  // #17470 - direct unzip call (after upload)
909  if(!$a_file &&
910  isset($_GET["upfile"]))
911  {
912  $a_file = basename($_GET["upfile"]);
913  }
914 
915  $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
916  $cur_dir = (!empty($cur_subdir))
917  ? $this->main_dir."/".$cur_subdir
918  : $this->main_dir;
919  $a_file = $this->main_dir."/".$a_file;
920 
921  if (@is_file($a_file))
922  {
923  include_once("./Services/Utilities/classes/class.ilFileUtils.php");
924  $cur_files = array_keys(ilUtil::getDir($cur_dir));
925  $cur_files_r = iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cur_dir)));
926 
927  if ($this->getAllowDirectories())
928  {
929  ilUtil::unzip($a_file, true);
930  }
931  else
932  {
933  ilUtil::unzip($a_file, true, true);
934  }
935 
936  $new_files = array_keys(ilUtil::getDir($cur_dir));
937  $new_files_r = iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cur_dir)));
938 
939  $diff = array_diff($new_files, $cur_files);
940  $diff_r = array_diff($new_files_r, $cur_files_r);
941 
942  // unlink forbidden file types
943  foreach ($diff_r as $f => $d)
944  {
945  $pi = pathinfo($f);
946  if (!is_dir($f) && !$this->isValidSuffix(strtolower($pi["extension"])))
947  {
948  ilUtil::sendFailure($lng->txt("file_some_invalid_file_types_removed")." (".$pi["extension"].")", true);
949  unlink($f);
950  }
951  }
952 
953  if(sizeof($diff))
954  {
955  if ($this->getAllowDirectories())
956  {
957  include_once("./Services/Utilities/classes/class.ilFileUtils.php");
958  $new_files = array();
959 
960  foreach($diff as $new_item)
961  {
962  if(is_dir($cur_dir."/".$new_item))
963  {
964  ilFileUtils::recursive_dirscan($cur_dir."/".$new_item, $new_files);
965  }
966  }
967 
968  if(is_array($new_files["path"]))
969  {
970  foreach($new_files["path"] as $idx => $path)
971  {
972  $path = substr($path, strlen($this->main_dir)+1);
973  $diff[] = $path.$new_files["file"][$idx];
974  }
975  }
976  }
977 
978  $this->setPerformedCommand("unzip_file",
979  array("name" => substr($file, strlen($this->main_dir)+1),
980  "added" => $diff));
981  }
982  }
983 
984  ilUtil::renameExecutables($this->main_dir);
985 
986  $this->ctrl->saveParameter($this, "cdir");
987  ilUtil::sendSuccess($lng->txt("cont_file_unzipped"), true);
988  $this->ctrl->redirect($this, "listFiles");
989  }
990 
994  function downloadFile($a_file)
995  {
996  $file = $this->main_dir."/".$a_file;
997 
998  if (@is_file($file) && !(@is_dir($file)))
999  {
1000  ilUtil::deliverFile($file, basename($a_file));
1001  exit;
1002  }
1003  else
1004  {
1005  $this->ctrl->saveParameter($this, "cdir");
1006  $this->ctrl->redirect($this, "listFiles");
1007  }
1008  }
1009 
1013  function getTabs(&$tabs_gui)
1014  {
1015  global $ilCtrl;
1016 
1017  $ilCtrl->setParameter($this, "resetoffset", 1);
1018  $tabs_gui->addTarget("cont_list_files",
1019  $this->ctrl->getLinkTarget($this, "listFiles"), "listFiles",
1020  get_class($this));
1021  $ilCtrl->setParameter($this, "resetoffset", "");
1022  }
1023 
1024 }
1025 ?>
$files
Definition: add-vimline.php:18
downloadFile($a_file)
delete object file
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
$path
Definition: aliased.php:25
setTitle($a_val)
Set title.
Base class for ILIAS Exception handling.
$_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.
setPostDirPath($a_val)
Set post dir path.
$_GET["client_id"]
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.
$cmd
Definition: sahs_server.php:35
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.
$url
Definition: shib_logout.php:72
setUseUploadDirectory($a_val)
Set use upload directory.
getLastPerformedCommand()
Get performed command.
for($col=0; $col< 50; $col++) $d
createDirectory()
create directory
clearCommands()
Clear commands.
global $tpl
Definition: ilias.php:8
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
extCommand($a_nr)
call external command
deleteFile()
delete object file
if(!is_array($argv)) $options
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
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
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
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)
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
confirmDeleteFile(array $a_files)
Confirm file deletion.
setPerformedCommand($command, $pars="")
Set performed command.
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"]
Confirmation screen class.
PHPExcel root directory.
Definition: Database.php:30
TableGUI class for file system.