ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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  try {
730  ilUtil::moveUploadedFile($_FILES["new_file"]["tmp_name"], $name, $tgt_file);
731  } catch (ilException $e) {
732  ilUtil::sendFailure($e->getMessage(), true);
733  $this->ctrl->redirect($this, "listFiles");
734  }
735 
736  } elseif ($_POST["uploaded_file"]) {
737  include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
738 
739  // check if the file is in the ftp directory and readable
740  if (ilUploadFiles::_checkUploadFile($_POST["uploaded_file"])) {
741  $tgt_file = $cur_dir . "/" . ilUtil::stripSlashes($_POST["uploaded_file"]);
742 
743  // copy uploaded file to data directory
744  ilUploadFiles::_copyUploadFile($_POST["uploaded_file"], $tgt_file);
745  }
746  } elseif (trim($_FILES["new_file"]["name"]) == "") {
747  ilUtil::sendFailure($lng->txt("cont_enter_a_file"), true);
748  }
749 
750  if ($tgt_file && is_file($tgt_file)) {
751  $unzip = null;
752 
753  // extract zip?
754  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
755  if (ilMimeTypeUtil::getMimeType($tgt_file) == "application/zip") {
756  $this->ctrl->setParameter($this, "upfile", basename($tgt_file));
757  $url = $this->ctrl->getLinkTarget($this, "unzipFile");
758  $this->ctrl->setParameter($this, "upfile", "");
759 
760  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
761  $unzip = ilLinkButton::getInstance();
762  $unzip->setCaption("unzip");
763  $unzip->setUrl($url);
764  $unzip = " " . $unzip->render();
765  }
766 
767  ilUtil::sendSuccess($lng->txt("cont_file_created") . $unzip, true);
768 
769  $this->setPerformedCommand(
770  "create_file",
771  array("name" => substr($tgt_file, strlen($this->main_dir) + 1))
772  );
773  }
774 
775  $this->ctrl->saveParameter($this, self::CDIR);
776 
777  ilUtil::renameExecutables($this->main_dir);
778 
779  $this->ctrl->redirect($this, 'listFiles');
780  }
781 
785  public function confirmDeleteFile(array $a_files)
786  {
787  global $DIC;
788  $ilCtrl = $DIC['ilCtrl'];
789  $tpl = $DIC['tpl'];
790  $lng = $DIC['lng'];
791 
792  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
793  $cgui = new ilConfirmationGUI();
794  $cgui->setFormAction($ilCtrl->getFormAction($this));
795  $cgui->setHeaderText($lng->txt("info_delete_sure"));
796  $cgui->setCancel($lng->txt("cancel"), "listFiles");
797  $cgui->setConfirm($lng->txt("delete"), "deleteFile");
798 
799  foreach ($a_files as $i) {
800  $cgui->addItem("file[]", $i, $i);
801  }
802 
803  $tpl->setContent($cgui->getHTML());
804  }
805 
809  public function deleteFile()
810  {
811  global $DIC;
812  $lng = $DIC['lng'];
813 
814  if (!isset($_POST["file"])) {
815  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
816  }
817 
818  foreach ($_POST["file"] as $post_file) {
819  if (ilUtil::stripSlashes($post_file) == "..") {
820  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
821  break;
822  }
823 
824  $cur_subdir = $this->sanitizeCurrentDirectory();
825  $cur_dir = (!empty($cur_subdir))
826  ? $this->main_dir . "/" . $cur_subdir
827  : $this->main_dir;
828  $pi = pathinfo($post_file);
829  $file = $cur_dir . "/" . ilUtil::stripSlashes($pi["basename"]);
830 
831  if (@is_file($file)) {
832  unlink($file);
833  }
834 
835  if (@is_dir($file)) {
836  $is_dir = true;
837  ilUtil::delDir($file);
838  }
839  }
840 
841  $this->ctrl->saveParameter($this, self::CDIR);
842  if ($is_dir) {
843  ilUtil::sendSuccess($lng->txt("cont_dir_deleted"), true);
844  $this->setPerformedCommand(
845  "delete_dir",
846  array("name" => ilUtil::stripSlashes($post_file))
847  );
848  } else {
849  ilUtil::sendSuccess($lng->txt("cont_file_deleted"), true);
850  $this->setPerformedCommand(
851  "delete_file",
852  array("name" => ilUtil::stripSlashes($post_file))
853  );
854  }
855  $this->ctrl->redirect($this, 'listFiles');
856  }
857 
861  public function unzipFile($a_file = null)
862  {
863  global $DIC;
864  $lng = $DIC['lng'];
865 
866  // #17470 - direct unzip call (after upload)
867  if (!$a_file &&
868  isset($_GET["upfile"])) {
869  $a_file = basename($_GET["upfile"]);
870  }
871 
872  $cur_subdir = $this->sanitizeCurrentDirectory();
873  $cur_dir = (!empty($cur_subdir))
874  ? $this->main_dir . "/" . $cur_subdir
875  : $this->main_dir;
876  $a_file = $this->main_dir . "/" . $a_file;
877 
878  if (@is_file($a_file)) {
879  include_once("./Services/Utilities/classes/class.ilFileUtils.php");
880  $cur_files = array_keys(ilUtil::getDir($cur_dir));
881  $cur_files_r = iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cur_dir)));
882 
883  if ($this->getAllowDirectories()) {
884  ilUtil::unzip($a_file, true);
885  } else {
886  ilUtil::unzip($a_file, true, true);
887  }
888 
889  $new_files = array_keys(ilUtil::getDir($cur_dir));
890  $new_files_r = iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cur_dir)));
891 
892  $diff = array_diff($new_files, $cur_files);
893  $diff_r = array_diff($new_files_r, $cur_files_r);
894 
895  // unlink forbidden file types
896  foreach ($diff_r as $f => $d) {
897  $pi = pathinfo($f);
898  if (!is_dir($f) && !$this->isValidSuffix(strtolower($pi["extension"]))) {
899  ilUtil::sendFailure($lng->txt("file_some_invalid_file_types_removed") . " (" . $pi["extension"] . ")", true);
900  unlink($f);
901  }
902  }
903 
904  if (sizeof($diff)) {
905  if ($this->getAllowDirectories()) {
906  include_once("./Services/Utilities/classes/class.ilFileUtils.php");
907  $new_files = array();
908 
909  foreach ($diff as $new_item) {
910  if (is_dir($cur_dir . "/" . $new_item)) {
911  ilFileUtils::recursive_dirscan($cur_dir . "/" . $new_item, $new_files);
912  }
913  }
914 
915  if (is_array($new_files["path"])) {
916  foreach ($new_files["path"] as $idx => $path) {
917  $path = substr($path, strlen($this->main_dir) + 1);
918  $diff[] = $path . $new_files["file"][$idx];
919  }
920  }
921  }
922 
923  $this->setPerformedCommand(
924  "unzip_file",
925  array("name" => substr($file, strlen($this->main_dir) + 1),
926  "added" => $diff)
927  );
928  }
929  }
930 
931  ilUtil::renameExecutables($this->main_dir);
932 
933  $this->ctrl->saveParameter($this, self::CDIR);
934  ilUtil::sendSuccess($lng->txt("cont_file_unzipped"), true);
935  $this->ctrl->redirect($this, "listFiles");
936  }
937 
941  public function downloadFile($a_file)
942  {
943  $file = $this->main_dir . "/" . $a_file;
944 
945  if (@is_file($file) && !(@is_dir($file))) {
946  ilUtil::deliverFile($file, basename($a_file));
947  exit;
948  } else {
949  $this->ctrl->saveParameter($this, self::CDIR);
950  $this->ctrl->redirect($this, "listFiles");
951  }
952  }
953 
957  public function getTabs(&$tabs_gui)
958  {
959  global $DIC;
960  $ilCtrl = $DIC['ilCtrl'];
961 
962  $ilCtrl->setParameter($this, "resetoffset", 1);
963  $tabs_gui->addTarget(
964  "cont_list_files",
965  $this->ctrl->getLinkTarget($this, "listFiles"),
966  "listFiles",
967  get_class($this)
968  );
969  $ilCtrl->setParameter($this, "resetoffset", "");
970  }
971 
975  public function getActionCommands()
976  {
977  return $this->commands;
978  }
979 
983  public function defineCommands()
984  {
985  $this->commands = array(
986  0 => array(
987  "object" => $this,
988  "method" => "downloadFile",
989  "name" => $this->lng->txt("download"),
990  "int" => true,
991  "single" => true
992  ),
993  1 => array(
994  "object" => $this,
995  "method" => "confirmDeleteFile",
996  "name" => $this->lng->txt("delete"),
997  "allow_dir" => true,
998  "int" => true
999  ),
1000  2 => array(
1001  "object" => $this,
1002  "method" => "unzipFile",
1003  "name" => $this->lng->txt("unzip"),
1004  "int" => true,
1005  "single" => true
1006  ),
1007  3 => array(
1008  "object" => $this,
1009  "method" => "renameFileForm",
1010  "name" => $this->lng->txt("rename"),
1011  "allow_dir" => true,
1012  "int" => true,
1013  "single" => true
1014  ),
1015  );
1016  }
1017 
1018 
1022  private function sanitizeCurrentDirectory()
1023  {
1024  global $DIC;
1025 
1026  return str_replace("..", "", ilUtil::stripSlashes($DIC->http()->request()->getQueryParams()[self::CDIR]));
1027  }
1028 }
downloadFile($a_file)
delete object file
listFiles($a_table_gui=null)
List files.
exit
Definition: login.php:29
setTitle($a_val)
Set title.
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$_SESSION["AccountId"]
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.
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.
if($format !==null) $name
Definition: metadata.php:230
setForbiddenSuffixes($a_suffixes)
Set forbidden Suffixes.
executeCommand()
execute command
getTabs(&$tabs_gui)
get tabs
extCommand($a_nr)
call external command
deleteFile()
delete object file
$lng
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.
renameFile()
rename a file
redirection script todo: (a better solution should control the processing via a xml file) ...
getAllowDirectories()
Get allow directories.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
isValidSuffix($a_suffix)
Is suffix valid?
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.
getAllowFileCreation()
Get allowed file creation.
$ret
Definition: parser.php:6
$DIC
Definition: xapitoken.php:46
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.
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.
$i
Definition: metadata.php:24
Confirmation screen class.
TableGUI class for file system.