00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 require_once "./classes/class.ilObjectGUI.php";
00027 require_once "./Modules/File/classes/class.ilObjFile.php";
00028
00039 class ilObjFileGUI extends ilObjectGUI
00040 {
00045 function ilObjFileGUI($a_data,$a_id,$a_call_by_reference = true, $a_prepare_output = true)
00046 {
00047 $this->type = "file";
00048 $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference, false);
00049 }
00050
00051 function _forwards()
00052 {
00053 return array();
00054 }
00055
00056 function &executeCommand()
00057 {
00058 global $ilAccess, $ilNavigationHistory;
00059
00060 $next_class = $this->ctrl->getNextClass($this);
00061 $cmd = $this->ctrl->getCmd();
00062 $this->prepareOutput();
00063
00064
00065 if (!$this->getCreationMode() &&
00066 $ilAccess->checkAccess("read", "", $_GET["ref_id"]))
00067 {
00068 $ilNavigationHistory->addItem($_GET["ref_id"],
00069 "repository.php?cmd=infoScreen&ref_id=".$_GET["ref_id"], "file");
00070 }
00071
00072
00073
00074
00075 switch ($next_class)
00076 {
00077 case "ilinfoscreengui":
00078 $this->infoScreen();
00079 break;
00080
00081 case 'ilmdeditorgui':
00082
00083 include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
00084
00085 $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
00086 $md_gui->addObserver($this->object,'MDUpdateListener','General');
00087
00088
00089 $md_gui->addObserver($this->object,'MDUpdateListener','Technical');
00090
00091 $this->ctrl->forwardCommand($md_gui);
00092 break;
00093
00094 case 'ilpermissiongui':
00095 include_once("./classes/class.ilPermissionGUI.php");
00096 $perm_gui =& new ilPermissionGUI($this);
00097 $ret =& $this->ctrl->forwardCommand($perm_gui);
00098 break;
00099
00100 default:
00101 if (empty($cmd))
00102 {
00103
00104
00105
00106 $cmd = "infoScreen";
00107 }
00108
00109 $cmd .= "Object";
00110 $this->$cmd();
00111 break;
00112 }
00113 }
00114
00120 function createObject($a_reload_form = "")
00121 {
00122 global $rbacsystem, $ilCtrl;
00123
00124 $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
00125
00126 if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
00127 {
00128 $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00129 }
00130
00131
00132 $this->getTemplateFile("new",$this->type);
00133
00134 if ($a_reload_form != "single_upload")
00135 {
00136 $this->initSingleUploadForm("create");
00137 }
00138 $this->tpl->setVariable("SINGLE_UPLOAD_FORM", $this->single_form_gui->getHtml());
00139
00140 if ($a_reload_form != "zip_upload")
00141 {
00142 $this->initZipUploadForm("create");
00143 }
00144
00145 $this->tpl->setVariable("ZIP_UPLOAD_FORM", $this->zip_form_gui->getHtml());
00146
00147 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00148 $this->tpl->setVariable("TXT_TAKE_OVER_STRUCTURE", $this->lng->txt("take_over_structure"));
00149 $this->tpl->setVariable("TXT_HEADER_ZIP", $this->lng->txt("header_zip"));
00150
00151 $this->fillCloneTemplate('DUPLICATE','file');
00152 }
00153
00159 public function initSingleUploadForm($a_mode = "create")
00160 {
00161 global $lng;
00162
00163 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
00164 $this->single_form_gui = new ilPropertyFormGUI();
00165
00166
00167 $in_title = new ilTextInputGUI($lng->txt("title"), "title");
00168 $in_title->setInfo($this->lng->txt("if_no_title_then_filename"));
00169 $in_title->setMaxLength(128);
00170 $in_title->setSize(40);
00171 $this->single_form_gui->addItem($in_title);
00172
00173
00174 $in_descr = new ilTextAreaInputGUI($lng->txt("description"), "description");
00175 $this->single_form_gui->addItem($in_descr);
00176
00177
00178 $in_file = new ilFileInputGUI($lng->txt("file"), "upload_file");
00179 $in_file->setRequired(true);
00180 $this->single_form_gui->addItem($in_file);
00181
00182
00183 if ($a_mode == "create")
00184 {
00185 $this->single_form_gui->addCommandButton("save", $this->lng->txt($this->type."_add"));
00186 $this->single_form_gui->addCommandButton("saveAndMeta", $this->lng->txt("file_add_and_metadata"));
00187 $this->single_form_gui->addCommandButton("cancel", $lng->txt("cancel"));
00188 }
00189 else
00190 {
00191
00192
00193 }
00194
00195 $this->single_form_gui->setTableWidth("60%");
00196 $this->single_form_gui->setTarget($this->getTargetFrame("save"));
00197 $this->single_form_gui->setTitle($this->lng->txt($this->type."_new"));
00198 $this->single_form_gui->setTitleIcon(ilUtil::getImagePath('icon_file.gif'), $this->lng->txt('obj_file'));
00199
00200 if ($a_mode == "create")
00201 {
00202 $this->ctrl->setParameter($this, "new_type", "file");
00203 }
00204 $this->single_form_gui->setFormAction($this->ctrl->getFormAction($this));
00205 }
00206
00212 public function initZipUploadForm($a_mode = "create")
00213 {
00214 global $lng;
00215
00216 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
00217 $this->zip_form_gui = new ilPropertyFormGUI();
00218
00219
00220 $in_file = new ilFileInputGUI($lng->txt("file"), "zip_file");
00221 $in_file->setRequired(true);
00222 $in_file->setSuffixes(array("zip"));
00223 $this->zip_form_gui->addItem($in_file);
00224
00225
00226 $in_str = new ilCheckboxInputGUI($this->lng->txt("take_over_structure"), "adopt_structure");
00227 $in_str->setInfo($this->lng->txt("take_over_structure_info"));
00228 $this->zip_form_gui->addItem($in_str);
00229
00230
00231 if ($a_mode == "create")
00232 {
00233 $this->zip_form_gui->addCommandButton("saveUnzip", $this->lng->txt($this->type."_add"));
00234 $this->zip_form_gui->addCommandButton("cancel", $lng->txt("cancel"));
00235 }
00236 else
00237 {
00238
00239
00240 }
00241
00242 $this->zip_form_gui->setTableWidth("60%");
00243 $this->zip_form_gui->setTarget($this->getTargetFrame("save"));
00244 $this->zip_form_gui->setTitle($this->lng->txt("header_zip"));
00245 $this->zip_form_gui->setTitleIcon(ilUtil::getImagePath('icon_file.gif'), $this->lng->txt('obj_file'));
00246
00247 if ($a_mode == "create")
00248 {
00249 $this->ctrl->setParameter($this, "new_type", "file");
00250 }
00251 $this->zip_form_gui->setFormAction($this->ctrl->getFormAction($this));
00252 }
00253
00259 function saveUnzipObject()
00260 {
00261 global $rbacsystem;
00262
00263 $this->initZipUploadForm("create");
00264
00265 if ($this->zip_form_gui->checkInput())
00266 {
00267 $zip_file = $this->zip_form_gui->getInput("zip_file");
00268 $adopt_structure = $this->zip_form_gui->getInput("adopt_structure");
00269
00270 include_once ("Services/Utilities/classes/class.ilFileUtils.php");
00271
00272
00273 $newDir = ilUtil::ilTempnam();
00274 ilUtil::makeDir($newDir);
00275
00276
00277 if (ilObject::_lookupType($_GET["ref_id"], TRUE) == "cat")
00278 {
00279 $permission = $rbacsystem->checkAccess("create", $_GET["ref_id"], "cat");
00280 $containerType = "Category";
00281 }
00282 else {
00283 $permission = $rbacsystem->checkAccess("create", $_GET["ref_id"], "fold");
00284 $containerType = "Folder";
00285 }
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 try
00296 {
00297 $processDone = ilFileUtils::processZipFile( $newDir,
00298 $zip_file["tmp_name"],
00299 ($adopt_structure && $permission),
00300 $_GET["ref_id"],
00301 $containerType,
00302 true);
00303 ilUtil::sendInfo($this->lng->txt("file_added"),true);
00304 }
00305 catch (ilFileUtilsException $e)
00306 {
00307 ilUtil::sendInfo($e->getMessage(), true);
00308 }
00309
00310 ilUtil::delDir($newDir);
00311 $this->ctrl->returnToParent($this);
00312 }
00313 else
00314 {
00315 $this->zip_form_gui->setValuesByPost();
00316 $this->createObject("zip_upload");
00317 }
00318 }
00319
00325 function saveObject()
00326 {
00327 global $rbacsystem, $objDefinition;
00328
00329 $this->initSingleUploadForm("create");
00330
00331 if ($this->single_form_gui->checkInput())
00332 {
00333 $title = $this->single_form_gui->getInput("title");
00334 $description = $this->single_form_gui->getInput("description");
00335 $upload_file = $this->single_form_gui->getInput("upload_file");
00336
00337 if (trim($title) == "")
00338 {
00339 $title = $upload_file["name"];
00340 }
00341
00342
00343 include_once("./Modules/File/classes/class.ilObjFile.php");
00344 $fileObj = new ilObjFile();
00345 $fileObj->setType($this->type);
00346 $fileObj->setTitle($title);
00347 $fileObj->setDescription($description);
00348 $fileObj->setFileName($upload_file["name"]);
00349 $fileObj->setFileType($upload_file["type"]);
00350 $fileObj->setFileSize($upload_file["size"]);
00351 $fileObj->create();
00352 $fileObj->createReference();
00353 $fileObj->putInTree($_GET["ref_id"]);
00354 $fileObj->setPermissions($_GET["ref_id"]);
00355
00356 $fileObj->createDirectory();
00357 $fileObj->getUploadFile($upload_file["tmp_name"],
00358 $upload_file["name"]);
00359
00360 ilUtil::sendInfo($this->lng->txt("file_added"),true);
00361
00362 $this->ctrl->setParameter($this, "ref_id", $fileObj->getRefId());
00363 if ($this->ctrl->getCmd() == "saveAndMeta")
00364 {
00365 $target =
00366 $this->ctrl->getLinkTargetByClass(array("ilobjfilegui", "ilmdeditorgui"), "listSection");
00367 $target = str_replace("new_type=", "nt=", $target);
00368 ilUtil::redirect($this->getReturnLocation("save", $target));
00369 }
00370 else
00371 {
00372 $this->ctrl->returnToParent($this);
00373 }
00374 }
00375 else
00376 {
00377 $this->single_form_gui->setValuesByPost();
00378 $this->createObject("single_upload");
00379 }
00380 }
00381
00387 function saveAndMetaObject()
00388 {
00389 $this->saveObject();
00390 }
00391
00397 function updateObject()
00398 {
00399 $data = $_FILES["Fobject"];
00400
00401
00402 while (substr($data["name"]["file"],-1) == '/')
00403 {
00404 $data["name"]["file"] = substr($data["name"]["file"],0,-1);
00405 }
00406
00407 if (empty($data["name"]["file"]) && empty($_POST["Fobject"]["title"]))
00408 {
00409 $this->ilias->raiseError($this->lng->txt("msg_no_title"),$this->ilias->error_obj->MESSAGE);
00410 }
00411
00412 if (empty($_POST["Fobject"]["title"]))
00413 {
00414 $_POST["Fobject"]["title"] = $_FILES["Fobject"]["name"]["file"];
00415 }
00416
00417 if (!empty($data["name"]["file"]))
00418 {
00419 $this->object->replaceFile($_FILES["Fobject"]["tmp_name"]["file"],$_FILES["Fobject"]["name"]["file"]);
00420 $this->object->setFileName($_FILES["Fobject"]["name"]["file"]);
00421 $this->object->setFileType($_FILES["Fobject"]["type"]["file"]);
00422 $this->object->setFileSize($_FILES["Fobject"]["size"]["file"]);
00423 }
00424
00425 $this->object->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
00426 $this->object->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
00427
00428 $this->update = $this->object->update();
00429
00430 ilUtil::sendInfo($this->lng->txt("msg_obj_modified"),true);
00431
00432 ilUtil::redirect($this->getReturnLocation("update",$this->ctrl->getLinkTarget($this, "edit")));
00433 }
00434
00435
00441 function editObject()
00442 {
00443 global $rbacsystem, $ilAccess;
00444
00445 if (!$ilAccess->checkAccess("write", "", $this->ref_id))
00446 {
00447 $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
00448 }
00449
00450 $fields = array();
00451
00452 if ($_SESSION["error_post_vars"])
00453 {
00454
00455 $fields["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
00456 $fields["desc"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["desc"], true);
00457 }
00458 else
00459 {
00460 $fields["title"] = ilUtil::prepareFormOutput($this->object->getTitle());
00461 $fields["desc"] = ilUtil::prepareFormOutput($this->object->getLongDescription());
00462 }
00463
00464 $this->getTemplateFile("edit");
00465 $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
00466 $this->tpl->setVariable("TITLE", $fields["title"]);
00467 $this->tpl->setVariable("TXT_DESC", $this->lng->txt("desc"));
00468 $this->tpl->setVariable("DESC", $fields["desc"]);
00469 $this->tpl->setVariable("TXT_REPLACE_FILE", $this->lng->txt("replace_file"));
00470
00471
00472 $obj_str = ($this->call_by_reference) ? "" : "&obj_id=".$this->obj_id;
00473
00474 $this->tpl->setVariable("FORMACTION", $this->getFormAction("update",$this->ctrl->getFormAction($this, "update").$obj_str));
00475 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->object->getType()."_edit"));
00476 $this->tpl->setVariable("TARGET", $this->getTargetFrame("update"));
00477 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00478 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
00479 $this->tpl->setVariable("CMD_SUBMIT", "update");
00480 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00481
00482 }
00483
00484 function sendFileObject()
00485 {
00486 global $ilAccess;
00487
00488 if ($ilAccess->checkAccess("read", "", $this->ref_id))
00489 {
00490 $this->object->sendFile($_GET["hist_id"]);
00491 }
00492 else
00493 {
00494 $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00495 }
00496 return true;
00497 }
00498
00499
00505 function versionsObject()
00506 {
00507 global $rbacsystem, $ilAccess;
00508
00509 if (!$ilAccess->checkAccess("read", "", $_GET["ref_id"]))
00510 {
00511 $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00512 }
00513
00514 require_once("classes/class.ilHistoryGUI.php");
00515
00516 $hist_gui =& new ilHistoryGUI($this->object->getId());
00517
00518
00519
00520 $hist_html = $hist_gui->getVersionsTable(
00521 array("ref_id" => $_GET["ref_id"], "cmd" => "versions",
00522 "cmdClass" =>$_GET["cmdClass"], "cmdNode" =>$_GET["cmdNode"]));
00523
00524 $this->tpl->setVariable("ADM_CONTENT", $hist_html);
00525 }
00526
00532 function infoScreenObject()
00533 {
00534 $this->ctrl->setCmd("showSummary");
00535 $this->ctrl->setCmdClass("ilinfoscreengui");
00536 $this->infoScreen();
00537 }
00538
00542 function infoScreen()
00543 {
00544 global $ilAccess;
00545
00546 if (!$ilAccess->checkAccess("visible", "", $this->ref_id))
00547 {
00548 $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
00549 }
00550
00551 include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
00552 $info = new ilInfoScreenGUI($this);
00553
00554 if ($ilAccess->checkAccess("read", "sendfile", $this->ref_id))
00555 {
00556 $info->addButton($this->lng->txt("file_read"), $this->ctrl->getLinkTarget($this, "sendfile"));
00557 }
00558
00559 $info->enablePrivateNotes();
00560
00561 if ($ilAccess->checkAccess("read", "", $_GET["ref_id"]))
00562 {
00563 $info->enableNews();
00564 }
00565
00566
00567 $info->enableNewsEditing(false);
00568 if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
00569 {
00570 $news_set = new ilSetting("news");
00571 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
00572
00573 if ($enable_internal_rss)
00574 {
00575 $info->setBlockProperty("news", "settings", true);
00576 $info->setBlockProperty("news", "public_notifications_option", true);
00577 }
00578 }
00579
00580
00581
00582 $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
00583
00584 $info->addSection($this->lng->txt("file_info"));
00585 $info->addProperty($this->lng->txt("filename"),
00586 $this->object->getFileName());
00587 $info->addProperty($this->lng->txt("type"),
00588 $this->object->getFileType());
00589 $info->addProperty($this->lng->txt("size"),
00590 ilObjFile::_lookupFileSize($this->object->getId(), true));
00591 $info->addProperty($this->lng->txt("version"),
00592 $this->object->getVersion());
00593
00594
00595 $this->ctrl->forwardCommand($info);
00596 }
00597
00598
00599
00600 function getTabs(&$tabs_gui)
00601 {
00602 global $rbacsystem, $ilAccess;
00603
00604
00605
00606 $this->ctrl->setParameter($this,"ref_id",$this->ref_id);
00607
00608 if ($ilAccess->checkAccess("visible", "", $this->ref_id))
00609 {
00610 $force_active = ($this->ctrl->getNextClass() == "ilinfoscreengui"
00611 || strtolower($_GET["cmdClass"]) == "ilnotegui")
00612 ? true
00613 : false;
00614 $tabs_gui->addTarget("info_short",
00615 $this->ctrl->getLinkTargetByClass(
00616 array("ilobjfilegui", "ilinfoscreengui"), "showSummary"),
00617 array("showSummary","", "infoScreen"),
00618 "", "", $force_active);
00619 }
00620
00621 if ($ilAccess->checkAccess("write", "", $this->ref_id))
00622 {
00623 $tabs_gui->addTarget("edit",
00624 $this->ctrl->getLinkTarget($this, "edit"), "edit", "");
00625 }
00626
00627
00628 if ($ilAccess->checkAccess("write", "", $this->ref_id))
00629 {
00630 $tabs_gui->addTarget("meta_data",
00631 $this->ctrl->getLinkTargetByClass(array('ilobjfilegui','ilmdeditorgui'),'listSection'),
00632 "", 'ilmdeditorgui');
00633 }
00634
00635 if ($ilAccess->checkAccess("write", "", $this->ref_id))
00636 {
00637 $tabs_gui->addTarget("versions",
00638 $this->ctrl->getLinkTarget($this, "versions"), "versions", get_class($this));
00639 }
00640
00641 if ($ilAccess->checkAccess("edit_permission", "", $this->ref_id))
00642 {
00643 $tabs_gui->addTarget("perm_settings",
00644 $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
00645 }
00646 }
00647
00648 function _goto($a_target)
00649 {
00650 global $ilAccess, $ilErr, $lng;
00651
00652 if ($ilAccess->checkAccess("visible", "", $a_target))
00653 {
00654 $_GET["cmd"] = "infoScreen";
00655 $_GET["ref_id"] = $a_target;
00656 include("repository.php");
00657 exit;
00658 }
00659 else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
00660 {
00661 $_GET["cmd"] = "frameset";
00662 $_GET["target"] = "";
00663 $_GET["ref_id"] = ROOT_FOLDER_ID;
00664 ilUtil::sendInfo(sprintf($lng->txt("msg_no_perm_read_item"),
00665 ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
00666 include("repository.php");
00667 exit;
00668 }
00669
00670 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
00671
00672 }
00673
00677 function addLocatorItems()
00678 {
00679 global $ilLocator;
00680
00681 if (is_object($this->object))
00682 {
00683 $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $_GET["ref_id"]);
00684 }
00685 }
00686
00687 }
00688 ?>