ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
29 function ilFileSystemGUI($a_main_directory)
30 {
31 global $lng, $ilCtrl, $tpl, $ilias;
32
33 $this->ctrl =& $ilCtrl;
34 $this->lng =& $lng;
35 $this->ilias =& $ilias;
36 $this->tpl =& $tpl;
37 $this->main_dir = $a_main_directory;
38 $this->post_dir_path = false;
39 $this->commands = array(
40 0 => array(
41 "object" => $this,
42 "method" => "downloadFile",
43 "name" => $lng->txt("download"),
44 "int" => 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 ),
59 3 => array(
60 "object" => $this,
61 "method" => "renameFileForm",
62 "name" => $lng->txt("rename"),
63 "allow_dir" => true,
64 "int" => true
65 ),
66 );
67
68 $this->file_labels = array();
69 $this->label_enable = false;
70 $this->ctrl->saveParameter($this, "cdir");
71 $lng->loadLanguageModule("content");
72 $this->setAllowDirectories(true);
73 $this->setAllowDirectoryCreation(true);
74 $this->setAllowFileCreation(true);
75//echo "<br>main_dir:".$this->main_dir.":";
76 }
77
83 function setAllowedSuffixes($a_suffixes)
84 {
85 $this->allowed_suffixes = $a_suffixes;
86 }
87
94 {
96 }
97
103 function setForbiddenSuffixes($a_suffixes)
104 {
105 $this->forbidden_suffixes = $a_suffixes;
106 }
107
114 {
116 }
117
124 function isValidSuffix($a_suffix)
125 {
126 if (is_array($this->getForbiddenSuffixes()) && in_array($a_suffix, $this->getForbiddenSuffixes()))
127 {
128 return false;
129 }
130 if (is_array($this->getAllowedSuffixes()) && in_array($a_suffix, $this->getAllowedSuffixes()))
131 {
132 return true;
133 }
134 if (!is_array($this->getAllowedSuffixes()) || count($this->getAllowedSuffixes()) == 0)
135 {
136 return true;
137 }
138 return false;
139 }
140
141
147 function setAllowDirectories($a_val)
148 {
149 $this->allow_directories = $a_val;
150 }
151
158 {
159 return $this->allow_directories;
160 }
161
167 function setPostDirPath($a_val)
168 {
169 $this->post_dir_path = $a_val;
170 }
171
177 function getPostDirPath()
178 {
179 return $this->post_dir_path;
180 }
181
187 function setTableId($a_val)
188 {
189 $this->table_id = $a_val;
190 }
191
197 function getTableId()
198 {
199 return $this->table_id;
200 }
201
207 function setTitle($a_val)
208 {
209 $this->title = $a_val;
210 }
211
217 function getTitle()
218 {
219 return $this->title;
220 }
221
227 function setUseUploadDirectory($a_val)
228 {
229 $this->use_upload_directory = $a_val;
230 }
231
238 {
240 }
241
248 protected function setPerformedCommand($command, $pars = "")
249 {
250 if (!is_array($pars))
251 {
252 $pars = array();
253 }
254 $_SESSION["fsys"]["lastcomm"] = array_merge(
255 array("cmd" => $command), $pars);
256 }
257
263 public function getLastPerformedCommand()
264 {
265 $ret = $_SESSION["fsys"]["lastcomm"];
266 $_SESSION["fsys"]["lastcomm"] = "none";
267 return $ret;
268 }
269
273 function &executeCommand()
274 {
275 $next_class = $this->ctrl->getNextClass($this);
276 $cmd = $this->ctrl->getCmd("listFiles");
277
278 switch($next_class)
279 {
280
281 default:
282 if (substr($cmd, 0, 11) == "extCommand_")
283 {
284 $ret =& $this->extCommand(substr($cmd, 11, strlen($cmd) - 11));
285 }
286 else
287 {
288 $ret =& $this->$cmd();
289 }
290 break;
291 }
292
293 return $ret;
294 }
295
296
300 function addCommand(&$a_obj, $a_func, $a_name, $a_single = true,
301 $a_allow_dir = false)
302 {
303 $i = count($this->commands);
304
305 $this->commands[$i]["object"] =& $a_obj;
306 $this->commands[$i]["method"] = $a_func;
307 $this->commands[$i]["name"] = $a_name;
308 $this->commands[$i]["single"] = $a_single;
309 $this->commands[$i]["allow_dir"] = $a_allow_dir;
310
311 //$this->commands[] = $arr;
312 }
313
317 function clearCommands()
318 {
319 $this->commands = array();
320 }
321
325 function labelFile($a_file, $a_label)
326 {
327 $this->file_labels[$a_file][] = $a_label;
328 }
329
333 function activateLabels($a_act, $a_label_header)
334 {
335 $this->label_enable = $a_act;
336 $this->label_header = $a_label_header;
337 }
338
342 function &extCommand($a_nr)
343 {
344 if (isset($_POST["file"]))
345 {
346 // remove ".." items
347 foreach ($_POST["file"] as $k => $v)
348 {
349 if ($_POST["file"][$k] == "..")
350 {
351 unset($_POST["file"][$k]);
352 }
353 }
354 }
355 // check if at least one item is select
356 else
357 {
358 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
359 }
360
361 // check if only one item is select, if command does not allow multiple selection
362 if (count($_POST["file"]) > 1 && $this->commands[$a_nr]["single"])
363 {
364 $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
365 }
366
367 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
368
369 // collect files and
370 $files = array();
371 foreach ($_POST["file"] as $k => $v)
372 {
373 $file = (!empty($cur_subdir))
374 ? $this->main_dir."/".$cur_subdir."/".ilUtil::stripSlashes($_POST["file"][$k])
375 : $this->main_dir."/".ilUtil::stripSlashes($_POST["file"][$k]);
376
377 // check wether selected item is a directory
378 if (@is_dir($file) && !$this->commands[$a_nr]["allow_dir"])
379 {
380 $this->ilias->raiseError($this->lng->txt("select_a_file"),$this->ilias->error_obj->MESSAGE);
381 }
382 $file = (!empty($cur_subdir))
383 ? $cur_subdir."/".ilUtil::stripSlashes($_POST["file"][$k])
384 : ilUtil::stripSlashes($_POST["file"][$k]);
385 $files[] = $file;
386 }
387
388 if ($this->commands[$a_nr]["single"])
389 {
390 $files = $files[0];
391 }
392
393 $obj =& $this->commands[$a_nr]["object"];
394 $method = $this->commands[$a_nr]["method"];
395
396 return $obj->$method($files);
397 }
398
402 public function setAllowDirectoryCreation($a_val)
403 {
404 $this->directory_creation = $a_val;
405 }
406
411 {
412 return $this->directory_creation;
413 }
414
418 public function setAllowFileCreation($a_val)
419 {
420 $this->file_creation = $a_val;
421 }
422
426 public function getAllowFileCreation()
427 {
428 return $this->file_creation;
429 }
430
434 function listFiles()
435 {
436 global $ilToolbar, $lng, $ilCtrl;
437
438
439 // determine directory
440 // FIXME: I have to call stripSlashes here twice, because I could not
441 // determine where the second layer of slashes is added to the
442 // URL Parameter
443 $cur_subdir = ilUtil::stripSlashes(ilUtil::stripSlashes($_GET["cdir"]));
444 $new_subdir = ilUtil::stripSlashes(ilUtil::stripSlashes($_GET["newdir"]));
445
446 if($new_subdir == "..")
447 {
448 $cur_subdir = substr($cur_subdir, 0, strrpos($cur_subdir, "/"));
449 }
450 else
451 {
452 if (!empty($new_subdir))
453 {
454 if (!empty($cur_subdir))
455 {
456 $cur_subdir = $cur_subdir."/".$new_subdir;
457 }
458 else
459 {
460 $cur_subdir = $new_subdir;
461 }
462 }
463 }
464
465 $cur_subdir = str_replace("..", "", $cur_subdir);
466 $cur_dir = (!empty($cur_subdir))
467 ? $this->main_dir."/".$cur_subdir
468 : $this->main_dir;
469
470 $this->ctrl->setParameter($this, "cdir", $cur_subdir);
471
472 // toolbar for adding files/directories
473 $ilToolbar->setFormAction($ilCtrl->getFormAction($this), true);
474 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
475
476 if ($this->getAllowDirectories() && $this->getAllowDirectoryCreation())
477 {
478 $ti = new ilTextInputGUI($this->lng->txt("cont_new_dir"), "new_dir");
479 $ti->setMaxLength(80);
480 $ti->setSize(10);
481 $ilToolbar->addInputItem($ti, true);
482 $ilToolbar->addFormButton($lng->txt("create"), "createDirectory");
483
484 $ilToolbar->addSeparator();
485 }
486
487 include_once("./Services/Form/classes/class.ilFileInputGUI.php");
488 if ($this->getAllowFileCreation())
489 {
490 $fi = new ilFileInputGUI($this->lng->txt("cont_new_file"), "new_file");
491 $fi->setSize(10);
492 $ilToolbar->addInputItem($fi, true);
493 $ilToolbar->addFormButton($lng->txt("upload"), "uploadFile");
494 }
495
496 include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
498 {
499 $ilToolbar->addSeparator();
501 $options[""] = $lng->txt("cont_select_from_upload_dir");
502 foreach($files as $file)
503 {
504 $file = htmlspecialchars($file, ENT_QUOTES, "utf-8");
506 }
507 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
508 $si = new ilSelectInputGUI($this->lng->txt("cont_uploaded_file"), "uploaded_file");
509 $si->setOptions($options);
510 $ilToolbar->addInputItem($si, true);
511 $ilToolbar->addFormButton($lng->txt("copy"), "uploadFile");
512 }
513
514 // load files templates
515 include_once("./Services/FileSystem/classes/class.ilFileSystemTableGUI.php");
516 $fs_table = new ilFileSystemTableGUI($this, "listFiles", $cur_dir, $cur_subdir,
517 $this->label_enable, $this->file_labels, $this->label_header, $this->commands,
518 $this->getPostDirPath(), $this->getTableId());
519 if ($this->getTitle() != "")
520 {
521 $fs_table->setTitle($this->getTitle());
522 }
523 if ($_GET["resetoffset"] == 1)
524 {
525 $fs_table->resetOffset();
526 }
527 $this->tpl->setContent($fs_table->getHTML());
528 }
529
533 function renameFileForm()
534 {
535 global $lng, $ilCtrl;
536
537 if (!isset($_POST["file"]))
538 {
539 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
540 }
541
542 if (count($_POST["file"]) > 1)
543 {
544 $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
545 }
546
547 if (ilUtil::stripSlashes($_POST["file"][0]) == ".." )
548 {
549 $this->ilias->raiseError($this->lng->txt("select_a_file"),$this->ilias->error_obj->MESSAGE);
550 }
551
552 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
553 $file = (!empty($cur_subdir))
554 ? $this->main_dir."/".$cur_subdir."/".ilUtil::stripSlashes($_POST["file"][0])
555 : $this->main_dir."/".ilUtil::stripSlashes($_POST["file"][0]);
556
557 $this->ctrl->setParameter($this, "old_name", ilUtil::stripSlashes($_POST["file"][0]));
558
559 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
560 $form = new ilPropertyFormGUI();
561
562 // file/dir name
563 $ti = new ilTextInputGUI($this->lng->txt("name"), "new_name");
564 $ti->setMaxLength(200);
565 $ti->setSize(40);
566 $ti->setValue(ilUtil::stripSlashes($_POST["file"][0]));
567 $form->addItem($ti);
568
569 // save and cancel commands
570 $form->addCommandButton("renameFile", $lng->txt("rename"));
571 $form->addCommandButton("cancelRename", $lng->txt("cancel"));
572 $form->setFormAction($ilCtrl->getFormAction($this, "renameFile"));
573
574 if (@is_dir($file))
575 {
576 $form->setTitle($this->lng->txt("cont_rename_dir"));
577 }
578 else
579 {
580 $form->setTitle($this->lng->txt("rename_file"));
581 }
582
583 $this->tpl->setContent($form->getHTML());
584 }
585
589 function renameFile()
590 {
591 global $lng;
592
593 $new_name = str_replace("..", "", ilUtil::stripSlashes($_POST["new_name"]));
594 $new_name = str_replace("/", "", $new_name);
595 if ($new_name == "")
596 {
597 $this->ilias->raiseError($this->lng->txt("enter_new_name"),$this->ilias->error_obj->MESSAGE);
598 }
599
600 $pi = pathinfo($new_name);
601 $suffix = $pi["extension"];
602 if ($suffix != "" && !$this->isValidSuffix($suffix))
603 {
604 ilUtil::sendFailure($this->lng->txt("file_no_valid_file_type")." ($suffix)", true);
605 $this->ctrl->redirect($this, "listFiles");
606 }
607
608 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
609 $dir = (!empty($cur_subdir))
610 ? $this->main_dir."/".$cur_subdir."/"
611 : $this->main_dir."/";
612
613 rename($dir.ilUtil::stripSlashes($_GET["old_name"]), $dir.$new_name);
614
615 ilUtil::renameExecutables($this->main_dir);
616 if (@is_dir($dir.$new_name))
617 {
618 ilUtil::sendSuccess($lng->txt("cont_dir_renamed"), true);
619 $this->setPerformedCommand("rename_dir", array("old_name" => $_GET["old_name"],
620 "new_name" => $new_name));
621 }
622 else
623 {
624 ilUtil::sendSuccess($lng->txt("cont_file_renamed"), true);
625 $this->setPerformedCommand("rename_file", array("old_name" => $_GET["old_name"],
626 "new_name" => $new_name));
627 }
628 $this->ctrl->redirect($this, "listFiles");
629 }
630
634 function cancelRename()
635 {
636 $this->ctrl->redirect($this, "listFiles");
637 }
638
643 {
644 global $lng;
645
646 // determine directory
647 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
648 $cur_dir = (!empty($cur_subdir))
649 ? $this->main_dir."/".$cur_subdir
650 : $this->main_dir;
651
652 $new_dir = str_replace(".", "", ilUtil::stripSlashes($_POST["new_dir"]));
653 $new_dir = str_replace("/", "", $new_dir);
654
655 if (!empty($new_dir))
656 {
657 ilUtil::makeDir($cur_dir."/".$new_dir);
658 if (is_dir($cur_dir."/".$new_dir))
659 {
660 ilUtil::sendSuccess($lng->txt("cont_dir_created"), true);
661 $this->setPerformedCommand("create_dir", array("name" => $new_dir));
662 }
663 }
664 else
665 {
666 ilUtil::sendFailure($lng->txt("cont_enter_a_dir_name"), true);
667 }
668 $this->ctrl->saveParameter($this, "cdir");
669 $this->ctrl->redirect($this, "listFiles");
670 }
671
675 function uploadFile()
676 {
677 global $lng;
678
679 // determine directory
680 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
681 $cur_dir = (!empty($cur_subdir))
682 ? $this->main_dir."/".$cur_subdir
683 : $this->main_dir;
684
685 $tgt_file = null;
686
687 $pi = pathinfo($_FILES["new_file"]["name"]);
688 $suffix = $pi["extension"];
689 if (!$this->isValidSuffix($suffix))
690 {
691 ilUtil::sendFailure($this->lng->txt("file_no_valid_file_type")." ($suffix)", true);
692 $this->ctrl->redirect($this, "listFiles");
693 }
694
695 if (is_file($_FILES["new_file"]["tmp_name"]))
696 {
697 $tgt_file = $cur_dir."/".ilUtil::stripSlashes($_FILES["new_file"]["name"]);
698
699 move_uploaded_file($_FILES["new_file"]["tmp_name"], $tgt_file);
700
701 }
702 elseif ($_POST["uploaded_file"])
703 {
704 include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
705
706 // check if the file is in the ftp directory and readable
707 if (ilUploadFiles::_checkUploadFile($_POST["uploaded_file"]))
708 {
709 $tgt_file = $cur_dir."/".ilUtil::stripSlashes($_POST["uploaded_file"]);
710
711 // copy uploaded file to data directory
712 ilUploadFiles::_copyUploadFile($_POST["uploaded_file"], $tgt_file);
713 }
714 }
715 else if (trim($_FILES["new_file"]["name"]) == "")
716 {
717 ilUtil::sendFailure($lng->txt("cont_enter_a_file"), true);
718 }
719
720 if($tgt_file && is_file($tgt_file))
721 {
722 $unzip = null;
723
724 // extract zip?
725 include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
726 if(ilMimeTypeUtil::getMimeType($tgt_file) == "application/zip")
727 {
728 $this->ctrl->setParameter($this, "upfile", basename($tgt_file));
729 $url = $this->ctrl->getLinkTarget($this, "unzipFile");
730 $this->ctrl->setParameter($this, "upfile", "");
731
732 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
733 $unzip = ilLinkButton::getInstance();
734 $unzip->setCaption("unzip");
735 $unzip->setUrl($url);
736 $unzip = " ".$unzip->render();
737 }
738
739 ilUtil::sendSuccess($lng->txt("cont_file_created").$unzip, true);
740
741 $this->setPerformedCommand("create_file",
742 array("name" => substr($tgt_file, strlen($this->main_dir)+1)));
743 }
744
745 $this->ctrl->saveParameter($this, "cdir");
746
747 ilUtil::renameExecutables($this->main_dir);
748
749 $this->ctrl->redirect($this, "listFiles");
750 }
751
756 {
757 global $ilCtrl, $tpl, $lng;
758
759 if (!is_array($_POST["file"]) || count($_POST["file"]) == 0)
760 {
761 ilUtil::sendFailure($lng->txt("no_checkbox"), true);
762 $ilCtrl->redirect($this, "listFile");
763 }
764 else
765 {
766 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
767 $cgui = new ilConfirmationGUI();
768 $cgui->setFormAction($ilCtrl->getFormAction($this));
769 $cgui->setHeaderText($lng->txt("info_delete_sure"));
770 $cgui->setCancel($lng->txt("cancel"), "listFiles");
771 $cgui->setConfirm($lng->txt("delete"), "deleteFile");
772
773 foreach ($_POST["file"] as $i)
774 {
775 $cgui->addItem("file[]", $i, $i);
776 }
777
778 $tpl->setContent($cgui->getHTML());
779 }
780 }
781
785 function deleteFile()
786 {
787 global $lng;
788
789 if (!isset($_POST["file"]))
790 {
791 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
792 }
793
794 foreach ($_POST["file"] as $post_file)
795 {
796 if (ilUtil::stripSlashes($post_file) == "..")
797 {
798 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
799 break;
800 }
801
802 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
803 $cur_dir = (!empty($cur_subdir))
804 ? $this->main_dir."/".$cur_subdir
805 : $this->main_dir;
806 $file = $cur_dir."/".ilUtil::stripSlashes($post_file);
807
808 if (@is_file($file))
809 {
810 unlink($file);
811 }
812
813 if (@is_dir($file))
814 {
815 $is_dir = true;
817 }
818 }
819
820 $this->ctrl->saveParameter($this, "cdir");
821 if ($is_dir)
822 {
823 ilUtil::sendSuccess($lng->txt("cont_dir_deleted"), true);
824 $this->setPerformedCommand("delete_dir",
825 array("name" => ilUtil::stripSlashes($post_file)));
826 }
827 else
828 {
829 ilUtil::sendSuccess($lng->txt("cont_file_deleted"), true);
830 $this->setPerformedCommand("delete_file",
831 array("name" => ilUtil::stripSlashes($post_file)));
832 }
833 $this->ctrl->redirect($this, "listFiles");
834 }
835
839 function unzipFile()
840 {
841 global $lng;
842
843 if (isset($_GET["upfile"]))
844 {
845 $file = basename($_GET["upfile"]);
846 }
847 else
848 {
849 if (!isset($_POST["file"]))
850 {
851 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
852 }
853
854 if (count($_POST["file"]) > 1)
855 {
856 $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
857 }
858
859 $file = basename($_POST["file"][0]);
860 }
861
862 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
863 $cur_dir = (!empty($cur_subdir))
864 ? $this->main_dir."/".$cur_subdir
865 : $this->main_dir;
866 $file = $cur_dir."/".ilUtil::stripSlashes($file);
867
868 if (@is_file($file))
869 {
870 include_once("./Services/Utilities/classes/class.ilFileUtils.php");
871 $cur_files = array_keys(ilUtil::getDir($cur_dir));
872 $cur_files_r = iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cur_dir)));
873
874 if ($this->getAllowDirectories())
875 {
876 ilUtil::unzip($file, true);
877 }
878 else
879 {
880 ilUtil::unzip($file, true, true);
881 }
882
883 $new_files = array_keys(ilUtil::getDir($cur_dir));
884 $new_files_r = iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cur_dir)));
885
886 $diff = array_diff($new_files, $cur_files);
887 $diff_r = array_diff($new_files_r, $cur_files_r);
888
889 // unlink forbidden file types
890 foreach ($diff_r as $f => $d)
891 {
892 $pi = pathinfo($f);
893 if (!is_dir($f) && !$this->isValidSuffix(strtolower($pi["extension"])))
894 {
895 ilUtil::sendFailure($lng->txt("file_some_invalid_file_types_removed")." (".$pi["extension"].")", true);
896 unlink($f);
897 }
898 }
899
900 if(sizeof($diff))
901 {
902 if ($this->getAllowDirectories())
903 {
904 include_once("./Services/Utilities/classes/class.ilFileUtils.php");
905 $new_files = array();
906
907 foreach($diff as $new_item)
908 {
909 if(is_dir($cur_dir."/".$new_item))
910 {
911 ilFileUtils::recursive_dirscan($cur_dir."/".$new_item, $new_files);
912 }
913 }
914
915 if(is_array($new_files["path"]))
916 {
917 foreach($new_files["path"] as $idx => $path)
918 {
919 $path = substr($path, strlen($this->main_dir)+1);
920 $diff[] = $path.$new_files["file"][$idx];
921 }
922 }
923 }
924
925 $this->setPerformedCommand("unzip_file",
926 array("name" => substr($file, strlen($this->main_dir)+1),
927 "added" => $diff));
928 }
929 }
930
931 ilUtil::renameExecutables($this->main_dir);
932
933 $this->ctrl->saveParameter($this, "cdir");
934 ilUtil::sendSuccess($lng->txt("cont_file_unzipped"), true);
935 $this->ctrl->redirect($this, "listFiles");
936 }
937
941 function downloadFile()
942 {
943 if (!isset($_POST["file"]))
944 {
945 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
946 }
947
948 if (count($_POST["file"]) > 1)
949 {
950 $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
951 }
952
953 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
954 $cur_dir = (!empty($cur_subdir))
955 ? $this->main_dir."/".$cur_subdir
956 : $this->main_dir;
957 $file = $cur_dir."/".$_POST["file"][0];
958
959 // validate against files of current directory
960 $valid = false;
961 foreach(ilUtil::getDir($cur_dir) as $entry)
962 {
963 if($entry["type"] == "file" &&
964 $cur_dir."/".$entry["entry"] == $file)
965 {
966 $valid = true;
967 break;
968 }
969 }
970
971 if (@is_file($file) && !(@is_dir($file)) && $valid)
972 {
973 ilUtil::deliverFile($file, $_POST["file"][0]);
974 exit;
975 }
976 else
977 {
978 $this->ctrl->saveParameter($this, "cdir");
979 $this->ctrl->redirect($this, "listFiles");
980 }
981 }
982
986 function getTabs(&$tabs_gui)
987 {
988 global $ilCtrl;
989
990 $ilCtrl->setParameter($this, "resetoffset", 1);
991 $tabs_gui->addTarget("cont_list_files",
992 $this->ctrl->getLinkTarget($this, "listFiles"), "listFiles",
993 get_class($this));
994 $ilCtrl->setParameter($this, "resetoffset", "");
995 }
996
997}
998?>
print $file
global $tpl
Definition: ilias.php:8
$_GET["client_id"]
Confirmation screen class.
This class represents a file property in a property form.
File System Explorer GUI class.
getAllowedSuffixes()
Get allowed Suffixes.
getUseUploadDirectory()
Get use upload directory.
setForbiddenSuffixes($a_suffixes)
Set forbidden Suffixes.
getAllowDirectoryCreation()
Get allowed directory creation.
setAllowDirectories($a_val)
Set allow directories.
createDirectory()
create directory
getAllowDirectories()
Get allow directories.
setPostDirPath($a_val)
Set post dir path.
getTableId()
Get table id.
labelFile($a_file, $a_label)
label a file
getPostDirPath()
Get post dir path.
unzipFile()
delete object file
setPerformedCommand($command, $pars="")
Set performed command.
addCommand(&$a_obj, $a_func, $a_name, $a_single=true, $a_allow_dir=false)
Add command.
isValidSuffix($a_suffix)
Is suffix valid?
deleteFile()
delete object file
cancelRename()
cancel renaming a file
& executeCommand()
execute command
getForbiddenSuffixes()
Get Accepted Suffixes.
& extCommand($a_nr)
call external command
setAllowFileCreation($a_val)
Set allowed file creation.
renameFile()
rename a file
setAllowedSuffixes($a_suffixes)
Set allowed Suffixes.
downloadFile()
delete object file
getLastPerformedCommand()
Get performed command.
ilFileSystemGUI($a_main_directory)
clearCommands()
Clear commands.
confirmDeleteFile()
Confirm file deletion.
setTitle($a_val)
Set title.
getTabs(&$tabs_gui)
get tabs
setTableId($a_val)
Set table id.
setUseUploadDirectory($a_val)
Set use upload directory.
setAllowDirectoryCreation($a_val)
Set allowed directory creation.
activateLabels($a_act, $a_label_header)
activate file labels
getAllowFileCreation()
Get allowed file creation.
TableGUI class for file system.
recursive_dirscan($dir, &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
static getInstance()
Factory.
static getMimeType($a_file="", $a_filename="", $a_mime="")
Get Mime type.
This class represents a property form user interface.
This class represents a selection list property in a property form.
This class represents a text property in a property form.
static _getUploadFiles()
Get a list of readable files in the upload directory.
static _copyUploadFile($a_file, $a_target, $a_raise_errors=true)
copy an uploaded file to the target directory (including virus check)
static _checkUploadFile($a_file)
Check if a file exists in the upload directory and is readable.
static _getUploadDirectory()
Get the directory with uploaded files.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
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.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.
$_POST['username']
Definition: cron.php:12
$valid
< 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']
global $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:54
redirection script todo: (a better solution should control the processing via a xml file)
global $lng
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35
$path
Definition: index.php:22
if(!is_array($argv)) $options