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 "class.ilObjectGUI.php";
00027 require_once "./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 $next_class = $this->ctrl->getNextClass($this);
00059 $cmd = $this->ctrl->getCmd();
00060 $this->prepareOutput();
00061
00062
00063 switch ($next_class)
00064 {
00065 case "ilinfoscreengui":
00066 $this->infoScreen();
00067 break;
00068
00069 case 'ilmdeditorgui':
00070
00071 include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
00072
00073 $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
00074 $md_gui->addObserver($this->object,'MDUpdateListener','General');
00075
00076
00077 $md_gui->addObserver($this->object,'MDUpdateListener','Technical');
00078
00079 $this->ctrl->forwardCommand($md_gui);
00080 break;
00081
00082 case 'ilpermissiongui':
00083 include_once("./classes/class.ilPermissionGUI.php");
00084 $perm_gui =& new ilPermissionGUI($this);
00085 $ret =& $this->ctrl->forwardCommand($perm_gui);
00086 break;
00087
00088 default:
00089 if (empty($cmd))
00090 {
00091
00092
00093
00094 $cmd = "infoScreen";
00095 }
00096
00097 $cmd .= "Object";
00098 $this->$cmd();
00099 break;
00100 }
00101 }
00102
00108 function createObject()
00109 {
00110 global $rbacsystem;
00111
00112 $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
00113
00114 if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
00115 {
00116 $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00117 }
00118
00119
00120 $data = array();
00121 $data["fields"] = array();
00122 $data["fields"]["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
00123 $data["fields"]["desc"] = ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]);
00124 $data["fields"]["file"] = $_SESSION["error_post_vars"]["Fobject"]["file"];
00125
00126 $this->getTemplateFile("new",$this->type);
00127
00128 $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_file.gif'));
00129 $this->tpl->setVariable("ALT_IMG", $this->lng->txt('obj_file'));
00130
00131 foreach ($data["fields"] as $key => $val)
00132 {
00133 $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
00134 $this->tpl->setVariable(strtoupper($key), $val);
00135 #$this->tpl->parseCurrentBlock();
00136 }
00137
00138 $this->ctrl->setParameter($this, "new_type", $new_type);
00139 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00140
00141 $this->tpl->setVariable("TXT_TITLE_NOTE", $this->lng->txt("if_no_title_then_filename"));
00142 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->type."_new"));
00143 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00144 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($this->type."_add"));
00145 $this->tpl->setVariable("TXT_SUBMIT_AND_META", $this->lng->txt("file_add_and_metadata"));
00146 $this->tpl->setVariable("CMD_SUBMIT", "save");
00147 $this->tpl->setVariable("CMD_SUBMIT_AND_META", "saveAndMeta");
00148 $this->tpl->setVariable("TARGET", $this->getTargetFrame("save"));
00149 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00150 }
00151
00157 function saveObject()
00158 {
00159 global $rbacsystem, $objDefinition;
00160
00161 $data = $_FILES["Fobject"];
00162
00163
00164 while (substr($data["name"]["file"],-1) == '/')
00165 {
00166 $data["name"]["file"] = substr($data["name"]["file"],0,-1);
00167 }
00168
00169 if (empty($data["name"]["file"]))
00170 {
00171 $this->ilias->raiseError($this->lng->txt("msg_no_file"),$this->ilias->error_obj->MESSAGE);
00172 }
00173
00174 if (empty($_POST["Fobject"]["title"]))
00175 {
00176 $_POST["Fobject"]["title"] = $_FILES["Fobject"]["name"]["file"];
00177
00178 }
00179
00180
00181 include_once("classes/class.ilObjFile.php");
00182 $fileObj = new ilObjFile();
00183 $fileObj->setType($this->type);
00184 $fileObj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
00185 $fileObj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
00186 $fileObj->setFileName(ilUtil::stripSlashes($_FILES["Fobject"]["name"]["file"]));
00187 $fileObj->setFileType($_FILES["Fobject"]["type"]["file"]);
00188 $fileObj->setFileSize($_FILES["Fobject"]["size"]["file"]);
00189 $fileObj->create();
00190 $fileObj->createReference();
00191 $fileObj->putInTree($_GET["ref_id"]);
00192 $fileObj->setPermissions($_GET["ref_id"]);
00193
00194 $fileObj->createDirectory();
00195 $fileObj->getUploadFile($_FILES["Fobject"]["tmp_name"]["file"],ilUtil::stripSlashes($_FILES["Fobject"]["name"]["file"]));
00196
00197 sendInfo($this->lng->txt("file_added"),true);
00198
00199 $this->ctrl->setParameter($this, "ref_id", $fileObj->getRefId());
00200 if ($this->ctrl->getCmd() == "saveAndMeta")
00201 {
00202 ilUtil::redirect($this->getReturnLocation("save",
00203 $this->ctrl->getLinkTargetByClass(array("ilobjfilegui", "ilmdeditorgui"), "listSection")));
00204 }
00205 else
00206 {
00207 $this->ctrl->returnToParent($this);
00208 }
00209 }
00210
00216 function saveAndMetaObject()
00217 {
00218 $this->saveObject();
00219 }
00220
00226 function updateObject()
00227 {
00228 $data = $_FILES["Fobject"];
00229
00230
00231 while (substr($data["name"]["file"],-1) == '/')
00232 {
00233 $data["name"]["file"] = substr($data["name"]["file"],0,-1);
00234 }
00235
00236 if (empty($data["name"]["file"]) && empty($_POST["Fobject"]["title"]))
00237 {
00238 $this->ilias->raiseError($this->lng->txt("msg_no_title"),$this->ilias->error_obj->MESSAGE);
00239 }
00240
00241 if (empty($_POST["Fobject"]["title"]))
00242 {
00243 $_POST["Fobject"]["title"] = $_FILES["Fobject"]["name"]["file"];
00244 }
00245
00246 if (!empty($data["name"]["file"]))
00247 {
00248 $this->object->replaceFile($_FILES["Fobject"]["tmp_name"]["file"],$_FILES["Fobject"]["name"]["file"]);
00249 $this->object->setFileName($_FILES["Fobject"]["name"]["file"]);
00250 $this->object->setFileType($_FILES["Fobject"]["type"]["file"]);
00251 $this->object->setFileSize($_FILES["Fobject"]["size"]["file"]);
00252 }
00253
00254 $this->object->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
00255 $this->object->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
00256
00257 $this->update = $this->object->update();
00258
00259 sendInfo($this->lng->txt("msg_obj_modified"),true);
00260
00261 ilUtil::redirect($this->getReturnLocation("update",$this->ctrl->getLinkTarget($this, "edit")));
00262 }
00263
00264
00270 function editObject()
00271 {
00272 global $rbacsystem, $ilAccess;
00273
00274 if (!$ilAccess->checkAccess("write", "", $this->ref_id))
00275 {
00276 $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
00277 }
00278
00279 $fields = array();
00280
00281 if ($_SESSION["error_post_vars"])
00282 {
00283
00284 $fields["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
00285 $fields["desc"] = ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]);
00286 }
00287 else
00288 {
00289 $fields["title"] = ilUtil::prepareFormOutput($this->object->getTitle());
00290 $fields["desc"] = ilUtil::stripSlashes($this->object->getDescription());
00291 }
00292
00293 $this->getTemplateFile("edit");
00294 $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
00295 $this->tpl->setVariable("TITLE", $fields["title"]);
00296 $this->tpl->setVariable("TXT_DESC", $this->lng->txt("desc"));
00297 $this->tpl->setVariable("DESC", $fields["desc"]);
00298 $this->tpl->setVariable("TXT_REPLACE_FILE", $this->lng->txt("replace_file"));
00299
00300
00301 $obj_str = ($this->call_by_reference) ? "" : "&obj_id=".$this->obj_id;
00302
00303 $this->tpl->setVariable("FORMACTION", $this->getFormAction("update",$this->ctrl->getFormAction($this).$obj_str));
00304 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->object->getType()."_edit"));
00305 $this->tpl->setVariable("TARGET", $this->getTargetFrame("update"));
00306 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00307 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
00308 $this->tpl->setVariable("CMD_SUBMIT", "update");
00309 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00310
00311 }
00312
00313 function sendFileObject()
00314 {
00315 global $ilAccess;
00316
00317 if ($ilAccess->checkAccess("read", "", $this->ref_id))
00318 {
00319 $this->object->sendFile($_GET["hist_id"]);
00320 }
00321 else
00322 {
00323 $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00324 }
00325
00326 return true;
00327 }
00328
00329
00335 function versionsObject()
00336 {
00337 global $rbacsystem, $ilAccess;
00338
00339 if (!$ilAccess->checkAccess("read", "", $_GET["ref_id"]))
00340 {
00341 $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00342 }
00343
00344 require_once("classes/class.ilHistoryGUI.php");
00345
00346 $hist_gui =& new ilHistoryGUI($this->object->getId());
00347
00348
00349
00350 $hist_html = $hist_gui->getVersionsTable(
00351 array("ref_id" => $_GET["ref_id"], "cmd" => "versions",
00352 "cmdClass" =>$_GET["cmdClass"], "cmdNode" =>$_GET["cmdNode"]));
00353
00354 $this->tpl->setVariable("ADM_CONTENT", $hist_html);
00355 }
00356
00362 function infoScreenObject()
00363 {
00364 $this->ctrl->setCmd("showSummary");
00365 $this->ctrl->setCmdClass("ilinfoscreengui");
00366 $this->infoScreen();
00367 }
00368
00372 function infoScreen()
00373 {
00374 global $ilAccess;
00375
00376 if (!$ilAccess->checkAccess("visible", "", $this->ref_id))
00377 {
00378 $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
00379 }
00380
00381 include_once("classes/class.ilInfoScreenGUI.php");
00382 $info = new ilInfoScreenGUI($this);
00383
00384 if ($ilAccess->checkAccess("read", "sendfile", $this->ref_id))
00385 {
00386 $info->addButton($this->lng->txt("file_read"), $this->ctrl->getLinkTarget($this, "sendfile"));
00387 }
00388
00389 $info->enablePrivateNotes();
00390
00391
00392 $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
00393
00394 $info->addSection($this->lng->txt("file_info"));
00395 $info->addProperty($this->lng->txt("filename"),
00396 $this->object->getFileName());
00397 $info->addProperty($this->lng->txt("type"),
00398 $this->object->getFileType());
00399 $info->addProperty($this->lng->txt("size"),
00400 ilObjFile::_lookupFileSize($this->object->getId(), true));
00401 $info->addProperty($this->lng->txt("version"),
00402 $this->object->getVersion());
00403
00404
00405 $this->ctrl->forwardCommand($info);
00406 }
00407
00408
00409
00410 function getTabs(&$tabs_gui)
00411 {
00412 global $rbacsystem, $ilAccess;
00413
00414
00415
00416 $this->ctrl->setParameter($this,"ref_id",$this->ref_id);
00417
00418 if ($ilAccess->checkAccess("visible", "", $this->ref_id))
00419 {
00420 $force_active = (strtolower($_GET["cmdClass"]) == "ilinfoscreengui"
00421 || strtolower($_GET["cmdClass"]) == "ilnotegui")
00422 ? true
00423 : false;
00424 $tabs_gui->addTarget("info_short",
00425 $this->ctrl->getLinkTargetByClass(
00426 array("ilobjfilegui", "ilinfoscreengui"), "showSummary"),
00427 array("showSummary","", "infoScreen"),
00428 "", "", $force_active);
00429 }
00430
00431 if ($ilAccess->checkAccess("write", "", $this->ref_id))
00432 {
00433 $tabs_gui->addTarget("edit",
00434 $this->ctrl->getLinkTarget($this, "edit"), "edit", "");
00435 }
00436
00437
00438 if ($ilAccess->checkAccess("write", "", $this->ref_id))
00439 {
00440 $tabs_gui->addTarget("meta_data",
00441 $this->ctrl->getLinkTargetByClass(array('ilobjfilegui','ilmdeditorgui'),'listSection'),
00442 "", 'ilmdeditorgui');
00443 }
00444
00445 if ($ilAccess->checkAccess("write", "", $this->ref_id))
00446 {
00447 $tabs_gui->addTarget("versions",
00448 $this->ctrl->getLinkTarget($this, "versions"), "versions", get_class($this));
00449 }
00450
00451 if ($ilAccess->checkAccess("edit_permission", "", $this->ref_id))
00452 {
00453 $tabs_gui->addTarget("perm_settings",
00454 $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
00455 }
00456 }
00457
00458 function _goto($a_target)
00459 {
00460 global $ilAccess, $ilErr, $lng;
00461
00462 if ($ilAccess->checkAccess("visible", "", $a_target))
00463 {
00464 $_GET["cmd"] = "infoScreen";
00465 $_GET["ref_id"] = $a_target;
00466 include("repository.php");
00467 exit;
00468 }
00469 else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
00470 {
00471 $_GET["cmd"] = "frameset";
00472 $_GET["target"] = "";
00473 $_GET["ref_id"] = ROOT_FOLDER_ID;
00474 sendInfo(sprintf($lng->txt("msg_no_perm_read_item"),
00475 ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
00476 include("repository.php");
00477 exit;
00478 }
00479
00480 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
00481
00482 }
00483
00484 }
00485 ?>