ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
ilFileSystemGUI Class Reference

File System Explorer GUI class. More...

+ Collaboration diagram for ilFileSystemGUI:

Public Member Functions

 ilFileSystemGUI ($a_main_directory)
 
 setAllowedSuffixes ($a_suffixes)
 Set allowed Suffixes. More...
 
 getAllowedSuffixes ()
 Get allowed Suffixes. More...
 
 setForbiddenSuffixes ($a_suffixes)
 Set forbidden Suffixes. More...
 
 getForbiddenSuffixes ()
 Get Accepted Suffixes. More...
 
 isValidSuffix ($a_suffix)
 Is suffix valid? More...
 
 setAllowDirectories ($a_val)
 Set allow directories. More...
 
 getAllowDirectories ()
 Get allow directories. More...
 
 setPostDirPath ($a_val)
 Set post dir path. More...
 
 getPostDirPath ()
 Get post dir path. More...
 
 setTableId ($a_val)
 Set table id. More...
 
 getTableId ()
 Get table id. More...
 
 setTitle ($a_val)
 Set title. More...
 
 getTitle ()
 Get title. More...
 
 setUseUploadDirectory ($a_val)
 Set use upload directory. More...
 
 getUseUploadDirectory ()
 Get use upload directory. More...
 
 getLastPerformedCommand ()
 Get performed command. More...
 
executeCommand ()
 execute command More...
 
 addCommand (&$a_obj, $a_func, $a_name, $a_single=true, $a_allow_dir=false)
 Add command. More...
 
 clearCommands ()
 Clear commands. More...
 
 labelFile ($a_file, $a_label)
 label a file More...
 
 activateLabels ($a_act, $a_label_header)
 activate file labels More...
 
extCommand ($a_nr)
 call external command More...
 
 setAllowDirectoryCreation ($a_val)
 Set allowed directory creation. More...
 
 getAllowDirectoryCreation ()
 Get allowed directory creation. More...
 
 setAllowFileCreation ($a_val)
 Set allowed file creation. More...
 
 getAllowFileCreation ()
 Get allowed file creation. More...
 
 listFiles ()
 list files More...
 
 renameFileForm ()
 list files More...
 
 renameFile ()
 rename a file More...
 
 cancelRename ()
 cancel renaming a file More...
 
 createDirectory ()
 create directory More...
 
 uploadFile ()
 upload file More...
 
 confirmDeleteFile ()
 Confirm file deletion. More...
 
 deleteFile ()
 delete object file More...
 
 unzipFile ()
 delete object file More...
 
 downloadFile ()
 delete object file More...
 
 getTabs (&$tabs_gui)
 get tabs More...
 

Data Fields

 $ctrl
 

Protected Member Functions

 setPerformedCommand ($command, $pars="")
 Set performed command. More...
 

Protected Attributes

 $use_upload_directory = false
 
 $allowed_suffixes = array()
 
 $forbidden_suffixes = array()
 

Detailed Description

File System Explorer GUI class.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 12 of file class.ilFileSystemGUI.php.

Member Function Documentation

◆ activateLabels()

ilFileSystemGUI::activateLabels (   $a_act,
  $a_label_header 
)

activate file labels

Definition at line 333 of file class.ilFileSystemGUI.php.

334 {
335 $this->label_enable = $a_act;
336 $this->label_header = $a_label_header;
337 }

◆ addCommand()

ilFileSystemGUI::addCommand ( $a_obj,
  $a_func,
  $a_name,
  $a_single = true,
  $a_allow_dir = false 
)

Add command.

Definition at line 300 of file class.ilFileSystemGUI.php.

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 }

◆ cancelRename()

ilFileSystemGUI::cancelRename ( )

cancel renaming a file

Definition at line 634 of file class.ilFileSystemGUI.php.

635 {
636 $this->ctrl->redirect($this, "listFiles");
637 }

◆ clearCommands()

ilFileSystemGUI::clearCommands ( )

Clear commands.

Definition at line 317 of file class.ilFileSystemGUI.php.

318 {
319 $this->commands = array();
320 }

◆ confirmDeleteFile()

ilFileSystemGUI::confirmDeleteFile ( )

Confirm file deletion.

Definition at line 755 of file class.ilFileSystemGUI.php.

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 }
global $tpl
Definition: ilias.php:8
Confirmation screen class.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$_POST['username']
Definition: cron.php:12
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40

References $_POST, $ilCtrl, $lng, $tpl, and ilUtil\sendFailure().

+ Here is the call graph for this function:

◆ createDirectory()

ilFileSystemGUI::createDirectory ( )

create directory

Definition at line 642 of file class.ilFileSystemGUI.php.

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 }
$_GET["client_id"]
setPerformedCommand($command, $pars="")
Set performed command.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...

References $_GET, $_POST, $lng, ilUtil\makeDir(), ilUtil\sendFailure(), ilUtil\sendSuccess(), setPerformedCommand(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ deleteFile()

ilFileSystemGUI::deleteFile ( )

delete object file

Definition at line 785 of file class.ilFileSystemGUI.php.

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 }
print $file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
redirection script todo: (a better solution should control the processing via a xml file)

References $_GET, $_POST, $file, $lng, ilUtil\delDir(), ilUtil\sendSuccess(), setPerformedCommand(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ downloadFile()

ilFileSystemGUI::downloadFile ( )

delete object file

Definition at line 941 of file class.ilFileSystemGUI.php.

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 }
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
$valid
exit
Definition: login.php:54

References $_GET, $_POST, $file, $valid, ilUtil\deliverFile(), exit, ilUtil\getDir(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ executeCommand()

& ilFileSystemGUI::executeCommand ( )

execute command

Definition at line 273 of file class.ilFileSystemGUI.php.

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 }
& extCommand($a_nr)
call external command
$cmd
Definition: sahs_server.php:35

References $cmd, $ret, and extCommand().

+ Here is the call graph for this function:

◆ extCommand()

& ilFileSystemGUI::extCommand (   $a_nr)

call external command

Definition at line 342 of file class.ilFileSystemGUI.php.

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 }

References $_GET, $_POST, $file, and ilUtil\stripSlashes().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAllowDirectories()

ilFileSystemGUI::getAllowDirectories ( )

Get allow directories.

Returns
boolean allow directories

Definition at line 157 of file class.ilFileSystemGUI.php.

158 {
159 return $this->allow_directories;
160 }

Referenced by listFiles(), and unzipFile().

+ Here is the caller graph for this function:

◆ getAllowDirectoryCreation()

ilFileSystemGUI::getAllowDirectoryCreation ( )

Get allowed directory creation.

Definition at line 410 of file class.ilFileSystemGUI.php.

411 {
412 return $this->directory_creation;
413 }

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ getAllowedSuffixes()

ilFileSystemGUI::getAllowedSuffixes ( )

Get allowed Suffixes.

Returns
array allowed Suffixes

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

References $allowed_suffixes.

Referenced by isValidSuffix().

+ Here is the caller graph for this function:

◆ getAllowFileCreation()

ilFileSystemGUI::getAllowFileCreation ( )

Get allowed file creation.

Definition at line 426 of file class.ilFileSystemGUI.php.

427 {
428 return $this->file_creation;
429 }

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ getForbiddenSuffixes()

ilFileSystemGUI::getForbiddenSuffixes ( )

Get Accepted Suffixes.

Returns
array forbidden Suffixes

Definition at line 113 of file class.ilFileSystemGUI.php.

References $forbidden_suffixes.

Referenced by isValidSuffix().

+ Here is the caller graph for this function:

◆ getLastPerformedCommand()

ilFileSystemGUI::getLastPerformedCommand ( )

Get performed command.

Returns
array command array

Definition at line 263 of file class.ilFileSystemGUI.php.

264 {
265 $ret = $_SESSION["fsys"]["lastcomm"];
266 $_SESSION["fsys"]["lastcomm"] = "none";
267 return $ret;
268 }
< 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']

References $_SESSION, and $ret.

◆ getPostDirPath()

ilFileSystemGUI::getPostDirPath ( )

Get post dir path.

Returns
boolean post dir path

Definition at line 177 of file class.ilFileSystemGUI.php.

178 {
179 return $this->post_dir_path;
180 }

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ getTableId()

ilFileSystemGUI::getTableId ( )

Get table id.

Returns
string table id

Definition at line 197 of file class.ilFileSystemGUI.php.

198 {
199 return $this->table_id;
200 }

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ getTabs()

ilFileSystemGUI::getTabs ( $tabs_gui)

get tabs

Definition at line 986 of file class.ilFileSystemGUI.php.

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 }

References $ilCtrl.

◆ getTitle()

ilFileSystemGUI::getTitle ( )

Get title.

Returns
string title

Definition at line 217 of file class.ilFileSystemGUI.php.

218 {
219 return $this->title;
220 }

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ getUseUploadDirectory()

ilFileSystemGUI::getUseUploadDirectory ( )

Get use upload directory.

Returns
bool use upload directory

Definition at line 237 of file class.ilFileSystemGUI.php.

References $use_upload_directory.

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ ilFileSystemGUI()

ilFileSystemGUI::ilFileSystemGUI (   $a_main_directory)

Definition at line 29 of file class.ilFileSystemGUI.php.

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 }
setAllowDirectories($a_val)
Set allow directories.
setAllowFileCreation($a_val)
Set allowed file creation.
setAllowDirectoryCreation($a_val)
Set allowed directory creation.

References $ilCtrl, $lng, $tpl, setAllowDirectories(), setAllowDirectoryCreation(), and setAllowFileCreation().

+ Here is the call graph for this function:

◆ isValidSuffix()

ilFileSystemGUI::isValidSuffix (   $a_suffix)

Is suffix valid?

Parameters
string$a_suffix
Returns
bool

Definition at line 124 of file class.ilFileSystemGUI.php.

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 }
getAllowedSuffixes()
Get allowed Suffixes.
getForbiddenSuffixes()
Get Accepted Suffixes.

References getAllowedSuffixes(), and getForbiddenSuffixes().

Referenced by renameFile(), unzipFile(), and uploadFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ labelFile()

ilFileSystemGUI::labelFile (   $a_file,
  $a_label 
)

label a file

Definition at line 325 of file class.ilFileSystemGUI.php.

326 {
327 $this->file_labels[$a_file][] = $a_label;
328 }

◆ listFiles()

ilFileSystemGUI::listFiles ( )

list files

Definition at line 434 of file class.ilFileSystemGUI.php.

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 }
This class represents a file property in a property form.
getUseUploadDirectory()
Get use upload directory.
getAllowDirectoryCreation()
Get allowed directory creation.
getAllowDirectories()
Get allow directories.
getTableId()
Get table id.
getPostDirPath()
Get post dir path.
getAllowFileCreation()
Get allowed file creation.
TableGUI class for file system.
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 _getUploadDirectory()
Get the directory with uploaded files.
if(!is_array($argv)) $options

References $_GET, $file, $ilCtrl, $lng, $options, $si, ilUploadFiles\_getUploadDirectory(), ilUploadFiles\_getUploadFiles(), getAllowDirectories(), getAllowDirectoryCreation(), getAllowFileCreation(), getPostDirPath(), getTableId(), getTitle(), getUseUploadDirectory(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ renameFile()

ilFileSystemGUI::renameFile ( )

rename a file

Definition at line 589 of file class.ilFileSystemGUI.php.

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 }
isValidSuffix($a_suffix)
Is suffix valid?
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.

References $_GET, $_POST, $lng, isValidSuffix(), ilUtil\renameExecutables(), ilUtil\sendFailure(), ilUtil\sendSuccess(), setPerformedCommand(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ renameFileForm()

ilFileSystemGUI::renameFileForm ( )

list files

Definition at line 533 of file class.ilFileSystemGUI.php.

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 }
This class represents a property form user interface.

References $_GET, $_POST, $file, $ilCtrl, $lng, and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ setAllowDirectories()

ilFileSystemGUI::setAllowDirectories (   $a_val)

Set allow directories.

Parameters
booleanallow directories

Definition at line 147 of file class.ilFileSystemGUI.php.

148 {
149 $this->allow_directories = $a_val;
150 }

Referenced by ilFileSystemGUI().

+ Here is the caller graph for this function:

◆ setAllowDirectoryCreation()

ilFileSystemGUI::setAllowDirectoryCreation (   $a_val)

Set allowed directory creation.

Definition at line 402 of file class.ilFileSystemGUI.php.

403 {
404 $this->directory_creation = $a_val;
405 }

Referenced by ilFileSystemGUI().

+ Here is the caller graph for this function:

◆ setAllowedSuffixes()

ilFileSystemGUI::setAllowedSuffixes (   $a_suffixes)

Set allowed Suffixes.

Parameters
array$a_suffixesallowed Suffixes

Definition at line 83 of file class.ilFileSystemGUI.php.

84 {
85 $this->allowed_suffixes = $a_suffixes;
86 }

◆ setAllowFileCreation()

ilFileSystemGUI::setAllowFileCreation (   $a_val)

Set allowed file creation.

Definition at line 418 of file class.ilFileSystemGUI.php.

419 {
420 $this->file_creation = $a_val;
421 }

Referenced by ilFileSystemGUI().

+ Here is the caller graph for this function:

◆ setForbiddenSuffixes()

ilFileSystemGUI::setForbiddenSuffixes (   $a_suffixes)

Set forbidden Suffixes.

Parameters
array$a_suffixesforbidden Suffixes

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

104 {
105 $this->forbidden_suffixes = $a_suffixes;
106 }

◆ setPerformedCommand()

ilFileSystemGUI::setPerformedCommand (   $command,
  $pars = "" 
)
protected

Set performed command.

Parameters
stringcommand
arrayparameter array

Definition at line 248 of file class.ilFileSystemGUI.php.

249 {
250 if (!is_array($pars))
251 {
252 $pars = array();
253 }
254 $_SESSION["fsys"]["lastcomm"] = array_merge(
255 array("cmd" => $command), $pars);
256 }

References $_SESSION.

Referenced by createDirectory(), deleteFile(), renameFile(), unzipFile(), and uploadFile().

+ Here is the caller graph for this function:

◆ setPostDirPath()

ilFileSystemGUI::setPostDirPath (   $a_val)

Set post dir path.

Parameters
booleanpost dir path

Definition at line 167 of file class.ilFileSystemGUI.php.

168 {
169 $this->post_dir_path = $a_val;
170 }

◆ setTableId()

ilFileSystemGUI::setTableId (   $a_val)

Set table id.

Parameters
stringtable id

Definition at line 187 of file class.ilFileSystemGUI.php.

188 {
189 $this->table_id = $a_val;
190 }

◆ setTitle()

ilFileSystemGUI::setTitle (   $a_val)

Set title.

Parameters
stringtitle

Definition at line 207 of file class.ilFileSystemGUI.php.

208 {
209 $this->title = $a_val;
210 }

◆ setUseUploadDirectory()

ilFileSystemGUI::setUseUploadDirectory (   $a_val)

Set use upload directory.

Parameters
bool$a_valuse upload directory

Definition at line 227 of file class.ilFileSystemGUI.php.

228 {
229 $this->use_upload_directory = $a_val;
230 }

◆ unzipFile()

ilFileSystemGUI::unzipFile ( )

delete object file

Definition at line 839 of file class.ilFileSystemGUI.php.

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 }
recursive_dirscan($dir, &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
$path
Definition: index.php:22

References $_GET, $_POST, $d, $file, $lng, $path, getAllowDirectories(), ilUtil\getDir(), isValidSuffix(), ilFileUtils\recursive_dirscan(), ilUtil\renameExecutables(), ilUtil\sendFailure(), ilUtil\sendSuccess(), setPerformedCommand(), ilUtil\stripSlashes(), and ilUtil\unzip().

+ Here is the call graph for this function:

◆ uploadFile()

ilFileSystemGUI::uploadFile ( )

upload file

Definition at line 675 of file class.ilFileSystemGUI.php.

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 }
static getInstance()
Factory.
static getMimeType($a_file="", $a_filename="", $a_mime="")
Get Mime type.
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.

References $_GET, $_POST, $lng, ilUploadFiles\_checkUploadFile(), ilUploadFiles\_copyUploadFile(), ilLinkButton\getInstance(), ilMimeTypeUtil\getMimeType(), isValidSuffix(), ilUtil\renameExecutables(), ilUtil\sendFailure(), ilUtil\sendSuccess(), setPerformedCommand(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

Field Documentation

◆ $allowed_suffixes

ilFileSystemGUI::$allowed_suffixes = array()
protected

Definition at line 21 of file class.ilFileSystemGUI.php.

Referenced by getAllowedSuffixes().

◆ $ctrl

ilFileSystemGUI::$ctrl

Definition at line 14 of file class.ilFileSystemGUI.php.

◆ $forbidden_suffixes

ilFileSystemGUI::$forbidden_suffixes = array()
protected

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

Referenced by getForbiddenSuffixes().

◆ $use_upload_directory

ilFileSystemGUI::$use_upload_directory = false
protected

Definition at line 16 of file class.ilFileSystemGUI.php.

Referenced by getUseUploadDirectory().


The documentation for this class was generated from the following file: