00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00032 class ilFileSystemGUI
00033 {
00034 var $ctrl;
00035
00036 function ilFileSystemGUI($a_main_directory)
00037 {
00038 global $lng, $ilCtrl, $tpl, $ilias;
00039
00040 $this->ctrl =& $ilCtrl;
00041 $this->lng =& $lng;
00042 $this->ilias =& $ilias;
00043 $this->tpl =& $tpl;
00044 $this->main_dir = $a_main_directory;
00045 $this->commands = array();
00046 $this->file_labels = array();
00047 $this->label_enable = false;
00048 $this->ctrl->saveParameter($this, "cdir");
00049
00050 }
00051
00055 function &executeCommand()
00056 {
00057 $next_class = $this->ctrl->getNextClass($this);
00058 $cmd = $this->ctrl->getCmd();
00059
00060 switch($next_class)
00061 {
00062
00063 default:
00064 if (substr($cmd, 0, 11) == "extCommand_")
00065 {
00066 $ret =& $this->extCommand(substr($cmd, 11, strlen($cmd) - 11));
00067 }
00068 else
00069 {
00070 $ret =& $this->$cmd();
00071 }
00072 break;
00073 }
00074
00075 return $ret;
00076 }
00077
00078
00082 function addCommand(&$a_obj, $a_func, $a_name)
00083 {
00084 $i = count($this->commands);
00085
00086 $this->commands[$i]["object"] =& $a_obj;
00087 $this->commands[$i]["method"] = $a_func;
00088 $this->commands[$i]["name"] = $a_name;
00089
00090
00091 }
00092
00093
00097 function labelFile($a_file, $a_label)
00098 {
00099 $this->file_labels[$a_file] = $a_label;
00100 }
00101
00105 function activateLabels($a_act, $a_label_header)
00106 {
00107 $this->label_enable = $a_act;
00108 $this->label_header = $a_label_header;
00109 }
00110
00114 function &extCommand($a_nr)
00115 {
00116 if (!isset($_POST["file"]))
00117 {
00118 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00119 }
00120
00121 if (count($_POST["file"]) > 1)
00122 {
00123 $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
00124 }
00125
00126 if ($_POST["file"][0] == ".." )
00127 {
00128 $this->ilias->raiseError($this->lng->txt("select_a_file"),$this->ilias->error_obj->MESSAGE);
00129 }
00130
00131 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
00132 $file = (!empty($cur_subdir))
00133 ? $this->main_dir."/".$cur_subdir."/".ilUtil::stripSlashes($_POST["file"][0])
00134 : $this->main_dir."/".ilUtil::stripSlashes($_POST["file"][0]);
00135
00136
00137 if (@is_dir($file))
00138 {
00139 $this->ilias->raiseError($this->lng->txt("select_a_file"),$this->ilias->error_obj->MESSAGE);
00140 }
00141
00142 $file = (!empty($cur_subdir))
00143 ? $cur_subdir."/".ilUtil::stripSlashes($_POST["file"][0])
00144 : ilUtil::stripSlashes($_POST["file"][0]);
00145
00146 $obj =& $this->commands[$a_nr]["object"];
00147 $method = $this->commands[$a_nr]["method"];
00148
00149
00150 return $obj->$method($file);
00151 }
00152
00153
00157 function listFiles()
00158 {
00159
00160 require_once("classes/class.ilTableGUI.php");
00161 $tbl = new ilTableGUI();
00162
00163
00164
00165
00166
00167 $cur_subdir = ilUtil::stripSlashes(ilUtil::stripSlashes($_GET["cdir"]));
00168 $new_subdir = ilUtil::stripSlashes(ilUtil::stripSlashes($_GET["newdir"]));
00169
00170 if($new_subdir == "..")
00171 {
00172 $cur_subdir = substr($cur_subdir, 0, strrpos($cur_subdir, "/"));
00173 }
00174 else
00175 {
00176 if (!empty($new_subdir))
00177 {
00178 if (!empty($cur_subdir))
00179 {
00180 $cur_subdir = $cur_subdir."/".$new_subdir;
00181 }
00182 else
00183 {
00184 $cur_subdir = $new_subdir;
00185 }
00186 }
00187 }
00188
00189 $cur_subdir = str_replace(".", "", $cur_subdir);
00190
00191 $cur_dir = (!empty($cur_subdir))
00192 ? $this->main_dir."/".$cur_subdir
00193 : $this->main_dir;
00194
00195
00196 $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.directory.html", false);
00197
00198 $this->ctrl->setParameter($this, "cdir", $cur_subdir);
00199 $this->tpl->setVariable("FORMACTION1", $this->ctrl->getFormAction($this));
00200 $this->tpl->setVariable("TXT_NEW_DIRECTORY", $this->lng->txt("cont_new_dir"));
00201 $this->tpl->setVariable("TXT_NEW_FILE", $this->lng->txt("cont_new_file"));
00202 $this->tpl->setVariable("CMD_NEW_DIR", "createDirectory");
00203 $this->tpl->setVariable("CMD_NEW_FILE", "uploadFile");
00204 $this->tpl->setVariable("BTN_NEW_DIR", $this->lng->txt("create"));
00205 $this->tpl->setVariable("BTN_NEW_FILE", $this->lng->txt("upload"));
00206
00207
00208 $this->tpl->addBlockfile("FILE_TABLE", "files", "tpl.table.html");
00209
00210
00211 $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.directory_row.html", false);
00212
00213 $num = 0;
00214
00215 $obj_str = ($this->call_by_reference) ? "" : "&obj_id=".$this->obj_id;
00216 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00217
00218 $tbl->setTitle($this->lng->txt("cont_files")." ".$cur_subdir);
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 if (!$this->label_enable)
00238 {
00239 $tbl->setHeaderNames(array("", "", $this->lng->txt("cont_dir_file"),
00240 $this->lng->txt("cont_size")));
00241 $this->tpl->setVariable("COLUMN_COUNTS", 4);
00242 $tbl->setColumnWidth(array("1%", "1%", "60%", "40%"));
00243 $cols = array("", "", "dir_file", "size");
00244 $header_params = $this->ctrl->getParameterArray($this, "listFiles");
00245
00246
00247
00248
00249 $tbl->setHeaderVars($cols, $header_params);
00250 }
00251 else
00252 {
00253 $tbl->setHeaderNames(array("", "", $this->lng->txt("cont_dir_file"),
00254 $this->lng->txt("cont_size"), $this->label_header));
00255 $this->tpl->setVariable("COLUMN_COUNTS", 5);
00256 $tbl->setColumnWidth(array("1%", "1%", "50%", "25%", "25%"));
00257 $cols = array("", "", "dir_file", "size", "label");
00258 $header_params = $this->ctrl->getParameterArray($this, "listFiles");
00259
00260
00261
00262 $tbl->setHeaderVars($cols, $header_params);
00263 }
00264
00265 $tbl->setOrderColumn($_GET["sort_by"]);
00266 $tbl->setOrderDirection($_GET["sort_order"]);
00267 $tbl->setLimit($_GET["limit"]);
00268 $tbl->setOffset($_GET["offset"]);
00269 $tbl->setMaxCount($this->maxcount);
00270
00271
00272 $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00273 $this->tpl->setCurrentBlock("tbl_action_btn");
00274 $this->tpl->setVariable("BTN_NAME", "deleteFile");
00275 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("delete"));
00276 $this->tpl->parseCurrentBlock();
00277
00278
00279 $this->tpl->setCurrentBlock("tbl_action_btn");
00280 $this->tpl->setVariable("BTN_NAME", "unzipFile");
00281 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("unzip"));
00282 $this->tpl->parseCurrentBlock();
00283
00284
00285 $this->tpl->setCurrentBlock("tbl_action_btn");
00286 $this->tpl->setVariable("BTN_NAME", "downloadFile");
00287 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("download"));
00288 $this->tpl->parseCurrentBlock();
00289
00290
00291 $this->tpl->setCurrentBlock("tbl_action_btn");
00292 $this->tpl->setVariable("BTN_NAME", "renameFileForm");
00293 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("rename"));
00294 $this->tpl->parseCurrentBlock();
00295
00296
00297 for ($i=0; $i < count($this->commands); $i++)
00298 {
00299 $this->tpl->setCurrentBlock("tbl_action_btn");
00300 $this->tpl->setVariable("BTN_NAME", "extCommand_".$i);
00301 $this->tpl->setVariable("BTN_VALUE", $this->commands[$i]["name"]);
00302 $this->tpl->parseCurrentBlock();
00303 }
00304
00305
00306
00307 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
00308
00309
00310 $entries = ilUtil::getDir($cur_dir);
00311
00312
00313 $tbl->setMaxCount(count($entries));
00314 $entries = array_slice($entries, $_GET["offset"], $_GET["limit"]);
00315
00316 $tbl->render();
00317 if(count($entries) > 0)
00318 {
00319 $i=0;
00320 foreach($entries as $entry)
00321 {
00322 if(($entry["entry"] == ".") || ($entry["entry"] == ".." && empty($cur_subdir)))
00323 {
00324 continue;
00325 }
00326
00327 $cfile = (!empty($cur_subdir))
00328 ? $cur_subdir."/".$entry["entry"]
00329 : $entry["entry"];
00330
00331
00332 if ($this->label_enable)
00333 {
00334 $this->tpl->setCurrentBlock("Label");
00335 if ($this->file_labels[$cfile] != "")
00336 {
00337 $this->tpl->setVariable("TXT_LABEL", $this->file_labels[$cfile]);
00338 }
00339 else
00340 {
00341 $this->tpl->setVariable("TXT_LABEL", " ");
00342 }
00343 $this->tpl->parseCurrentBlock();
00344 }
00345
00346
00347 if($entry["type"] == "dir")
00348 {
00349 $this->tpl->setCurrentBlock("FileLink");
00350 $this->ctrl->setParameter($this, "cdir", $cur_subdir);
00351 $this->ctrl->setParameter($this, "newdir", $entry["entry"]);
00352 $this->tpl->setVariable("LINK_FILENAME", $this->ctrl->getLinkTarget($this, "listFiles"));
00353 $this->tpl->setVariable("TXT_FILENAME", $entry["entry"]);
00354 $this->tpl->parseCurrentBlock();
00355
00356 $this->tpl->setVariable("ICON", "<img src=\"".
00357 ilUtil::getImagePath("icon_cat.gif")."\">");
00358 }
00359 else
00360 {
00361 $this->tpl->setCurrentBlock("File");
00362 $this->tpl->setVariable("TXT_FILENAME2", $entry["entry"]);
00363 $this->tpl->parseCurrentBlock();
00364 }
00365
00366 $this->tpl->setCurrentBlock("tbl_content");
00367 $css_row = ilUtil::switchColor($i++, "tblrow1", "tblrow2");
00368 $this->tpl->setVariable("CSS_ROW", $css_row);
00369
00370 $this->tpl->setVariable("TXT_SIZE", $entry["size"]);
00371 $this->tpl->setVariable("CHECKBOX_ID", $entry["entry"]);
00372 $compare = (!empty($cur_subdir))
00373 ? $cur_subdir."/".$entry["entry"]
00374 : $entry["entry"];
00375 $purpose = array();
00376
00377 $this->tpl->parseCurrentBlock();
00378 }
00379 }
00380 else
00381 {
00382 $this->tpl->setCurrentBlock("notfound");
00383 $this->tpl->setVariable("TXT_OBJECT_NOT_FOUND", $this->lng->txt("obj_not_found"));
00384 $this->tpl->setVariable("NUM_COLS", 4);
00385 $this->tpl->parseCurrentBlock();
00386 }
00387
00388 $this->tpl->parseCurrentBlock();
00389 }
00390
00394 function renameFileForm()
00395 {
00396 if (!isset($_POST["file"]))
00397 {
00398 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00399 }
00400
00401 if (count($_POST["file"]) > 1)
00402 {
00403 $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
00404 }
00405
00406 if (ilUtil::stripSlashes($_POST["file"][0]) == ".." )
00407 {
00408 $this->ilias->raiseError($this->lng->txt("select_a_file"),$this->ilias->error_obj->MESSAGE);
00409 }
00410
00411 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
00412 $file = (!empty($cur_subdir))
00413 ? $this->main_dir."/".$cur_subdir."/".ilUtil::stripSlashes($_POST["file"][0])
00414 : $this->main_dir."/".ilUtil::stripSlashes($_POST["file"][0]);
00415
00416
00417 $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.file_rename.html", false);
00418
00419 $this->ctrl->setParameter($this, "old_name", ilUtil::stripSlashes($_POST["file"][0]));
00420 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00421 if (@is_dir($file))
00422 {
00423 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt("rename_dir"));
00424 }
00425 else
00426 {
00427 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt("rename_file"));
00428 }
00429 $this->tpl->setVariable("TXT_NAME", $this->lng->txt("name"));
00430 $this->tpl->setVariable("VAL_NAME", ilUtil::stripSlashes($_POST["file"][0]));
00431 $this->tpl->setVariable("CMD_CANCEL", "cancelRename");
00432 $this->tpl->setVariable("CMD_SUBMIT", "renameFile");
00433 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00434 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("rename"));
00435
00436 $this->tpl->parseCurrentBlock();
00437 }
00438
00442 function renameFile()
00443 {
00444 $new_name = str_replace("..", "", ilUtil::stripSlashes($_POST["new_name"]));
00445 $new_name = str_replace("/", "", $new_name);
00446 if ($new_name == "")
00447 {
00448 $this->ilias->raiseError($this->lng->txt("enter_new_name"),$this->ilias->error_obj->MESSAGE);
00449 }
00450
00451 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
00452 $dir = (!empty($cur_subdir))
00453 ? $this->main_dir."/".$cur_subdir."/"
00454 : $this->main_dir."/";
00455
00456 rename($dir.ilUtil::stripSlashes($_GET["old_name"]), $dir.$new_name);
00457
00458 ilUtil::renameExecutables($this->main_dir);
00459
00460 $this->ctrl->redirect($this, "listFiles");
00461 }
00462
00466 function cancelRename()
00467 {
00468 $this->ctrl->redirect($this, "listFiles");
00469 }
00470
00474 function createDirectory()
00475 {
00476
00477
00478 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
00479 $cur_dir = (!empty($cur_subdir))
00480 ? $this->main_dir."/".$cur_subdir
00481 : $this->main_dir;
00482
00483 $new_dir = str_replace(".", "", ilUtil::stripSlashes($_POST["new_dir"]));
00484 $new_dir = str_replace("/", "", $new_dir);
00485
00486 if (!empty($new_dir))
00487 {
00488 ilUtil::makeDir($cur_dir."/".$new_dir);
00489 }
00490 $this->ctrl->saveParameter($this, "cdir");
00491 $this->ctrl->redirect($this, "listFiles");
00492 }
00493
00497 function uploadFile()
00498 {
00499
00500 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
00501 $cur_dir = (!empty($cur_subdir))
00502 ? $this->main_dir."/".$cur_subdir
00503 : $this->main_dir;
00504 if (is_file($_FILES["new_file"]["tmp_name"]))
00505 {
00506 move_uploaded_file($_FILES["new_file"]["tmp_name"],
00507 $cur_dir."/".ilUtil::stripSlashes($_FILES["new_file"]["name"]));
00508 }
00509 $this->ctrl->saveParameter($this, "cdir");
00510
00511 ilUtil::renameExecutables($this->main_dir);
00512
00513 $this->ctrl->redirect($this, "listFiles");
00514 }
00515
00516
00520 function deleteFile()
00521 {
00522 if (!isset($_POST["file"]))
00523 {
00524 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00525 }
00526
00527 foreach ($_POST["file"] as $post_file)
00528 {
00529 if (ilUtil::stripSlashes($post_file) == "..")
00530 {
00531 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00532 break;
00533 }
00534
00535 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
00536 $cur_dir = (!empty($cur_subdir))
00537 ? $this->main_dir."/".$cur_subdir
00538 : $this->main_dir;
00539 $file = $cur_dir."/".ilUtil::stripSlashes($post_file);
00540
00541 if (@is_file($file))
00542 {
00543 unlink($file);
00544 }
00545
00546 if (@is_dir($file))
00547 {
00548 ilUtil::delDir($file);
00549 }
00550 }
00551
00552 $this->ctrl->saveParameter($this, "cdir");
00553 $this->ctrl->redirect($this, "listFiles");
00554 }
00555
00559 function unzipFile()
00560 {
00561 if (!isset($_POST["file"]))
00562 {
00563 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00564 }
00565
00566 if (count($_POST["file"]) > 1)
00567 {
00568 $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
00569 }
00570
00571 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
00572 $cur_dir = (!empty($cur_subdir))
00573 ? $this->main_dir."/".$cur_subdir
00574 : $this->main_dir;
00575 $file = $cur_dir."/".ilUtil::stripSlashes($_POST["file"][0]);
00576
00577 if (@is_file($file))
00578 {
00579 ilUtil::unzip($file, true);
00580 }
00581
00582 ilUtil::renameExecutables($this->main_dir);
00583
00584 $this->ctrl->saveParameter($this, "cdir");
00585 $this->ctrl->redirect($this, "listFiles");
00586 }
00587
00591 function downloadFile()
00592 {
00593 if (!isset($_POST["file"]))
00594 {
00595 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00596 }
00597
00598 if (count($_POST["file"]) > 1)
00599 {
00600 $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
00601 }
00602
00603 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
00604 $cur_dir = (!empty($cur_subdir))
00605 ? $this->main_dir."/".$cur_subdir
00606 : $this->main_dir;
00607 $file = $cur_dir."/".$_POST["file"][0];
00608
00609 if (@is_file($file) && !(@is_dir($file)))
00610 {
00611 ilUtil::deliverFile($file, $_POST["file"][0]);
00612 exit;
00613 }
00614 else
00615 {
00616 $this->ctrl->saveParameter($this, "cdir");
00617 $this->ctrl->redirect($this, "listFiles");
00618 }
00619 }
00620
00624 function getTabs(&$tabs_gui)
00625 {
00626
00627 $tabs_gui->addTarget("cont_list_files",
00628 $this->ctrl->getLinkTarget($this, "listFiles"), "listFiles",
00629 get_class($this));
00630 }
00631
00632
00633 }
00634 ?>