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