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
00038 require_once "class.ilObjectGUI.php";
00039 require_once "./classes/class.ilObjFile.php";
00040
00041 class ilObjFileGUI extends ilObjectGUI
00042 {
00047 function ilObjFileGUI($a_data,$a_id,$a_call_by_reference = true, $a_prepare_output = true)
00048 {
00049 $this->type = "file";
00050 $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference, $a_prepare_output);
00051 }
00052
00053 function _forwards()
00054 {
00055 return array();
00056 }
00057
00058 function &executeCommand()
00059 {
00060 $next_class = $this->ctrl->getNextClass($this);
00061 $cmd = $this->ctrl->getCmd();
00062
00063 switch ($next_class)
00064 {
00065 default:
00066 if (empty($cmd))
00067 {
00068 $this->ctrl->returnToParent($this);
00069 $cmd = "view";
00070 }
00071
00072 $cmd .= "Object";
00073 $this->$cmd();
00074 break;
00075 }
00076 }
00077
00083 function createObject()
00084 {
00085 global $rbacsystem;
00086
00087 $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
00088
00089 if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
00090 {
00091 $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00092 }
00093
00094
00095 $data = array();
00096 $data["fields"] = array();
00097 $data["fields"]["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
00098 $data["fields"]["desc"] = ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]);
00099 $data["fields"]["file"] = $_SESSION["error_post_vars"]["Fobject"]["file"];
00100
00101 $this->getTemplateFile("new",$this->type);
00102
00103 foreach ($data["fields"] as $key => $val)
00104 {
00105 $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
00106 $this->tpl->setVariable(strtoupper($key), $val);
00107 #$this->tpl->parseCurrentBlock();
00108 }
00109
00110 $this->tpl->setVariable("FORMACTION", $this->getFormAction("save",$this->ctrl->getFormAction($this)."&new_type=".$new_type));
00111
00112 $this->tpl->setVariable("TXT_TITLE_NOTE", $this->lng->txt("if_no_title_then_filename"));
00113 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->type."_new"));
00114 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00115 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($this->type."_add"));
00116 $this->tpl->setVariable("CMD_SUBMIT", "save");
00117 $this->tpl->setVariable("TARGET", $this->getTargetFrame("save"));
00118 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00119 }
00120
00126 function saveObject()
00127 {
00128 global $rbacsystem, $objDefinition;
00129
00130 $data = $_FILES["Fobject"];
00131
00132
00133 while (substr($data["name"]["file"],-1) == '/')
00134 {
00135 $data["name"]["file"] = substr($data["name"]["file"],0,-1);
00136 }
00137
00138 if (empty($data["name"]["file"]))
00139 {
00140 $this->ilias->raiseError($this->lng->txt("msg_no_file"),$this->ilias->error_obj->MESSAGE);
00141 }
00142
00143 if (empty($_POST["Fobject"]["title"]))
00144 {
00145 $_POST["Fobject"]["title"] = $_FILES["Fobject"]["name"]["file"];
00146
00147 }
00148
00149
00150 include_once("classes/class.ilObjFile.php");
00151 $fileObj = new ilObjFile();
00152 $fileObj->setType($this->type);
00153 $fileObj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
00154 $fileObj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
00155 $fileObj->setFileName(ilUtil::stripSlashes($_FILES["Fobject"]["name"]["file"]));
00156 $fileObj->setFileType($_FILES["Fobject"]["type"]["file"]);
00157 $fileObj->create();
00158 $fileObj->createReference();
00159 $fileObj->putInTree($_GET["ref_id"]);
00160 $fileObj->setPermissions($_GET["ref_id"]);
00161
00162 $fileObj->createDirectory();
00163 $fileObj->getUploadFile($_FILES["Fobject"]["tmp_name"]["file"],ilUtil::stripSlashes($_FILES["Fobject"]["name"]["file"]));
00164
00165 sendInfo($this->lng->txt("file_added"),true);
00166 ilUtil::redirect($this->getReturnLocation("save",$this->ctrl->getLinkTarget($this,"")));
00167
00168 }
00169
00175 function updateObject()
00176 {
00177 $data = $_FILES["Fobject"];
00178
00179
00180 while (substr($data["name"]["file"],-1) == '/')
00181 {
00182 $data["name"]["file"] = substr($data["name"]["file"],0,-1);
00183 }
00184
00185 if (empty($data["name"]["file"]) && empty($_POST["Fobject"]["title"]))
00186 {
00187 $this->ilias->raiseError($this->lng->txt("msg_no_title"),$this->ilias->error_obj->MESSAGE);
00188 }
00189
00190 if (empty($_POST["Fobject"]["title"]))
00191 {
00192 $_POST["Fobject"]["title"] = $_FILES["Fobject"]["name"]["file"];
00193 }
00194
00195 if (!empty($data["name"]["file"]))
00196 {
00197 $this->object->replaceFile($_FILES["Fobject"]["tmp_name"]["file"],$_FILES["Fobject"]["name"]["file"]);
00198 $this->object->setFileName($_FILES["Fobject"]["name"]["file"]);
00199 $this->object->setFileType($_FILES["Fobject"]["type"]["file"]);
00200 }
00201
00202 $this->object->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
00203 $this->object->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
00204
00205 $this->update = $this->object->update();
00206
00207 sendInfo($this->lng->txt("msg_obj_modified"),true);
00208
00209 ilUtil::redirect($this->getReturnLocation("update",$this->ctrl->getLinkTarget($this)));
00210
00211 }
00212
00213
00219 function editObject()
00220 {
00221 global $rbacsystem;
00222
00223 if (!$rbacsystem->checkAccess("write", $this->ref_id))
00224 {
00225 $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
00226 }
00227
00228 $fields = array();
00229
00230 if ($_SESSION["error_post_vars"])
00231 {
00232
00233 $fields["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
00234 $fields["desc"] = ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]);
00235 }
00236 else
00237 {
00238 $fields["title"] = ilUtil::prepareFormOutput($this->object->getTitle());
00239 $fields["desc"] = ilUtil::stripSlashes($this->object->getDescription());
00240 }
00241
00242 $this->getTemplateFile("edit");
00243 $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
00244 $this->tpl->setVariable("TITLE", $fields["title"]);
00245 $this->tpl->setVariable("TXT_DESC", $this->lng->txt("desc"));
00246 $this->tpl->setVariable("DESC", $fields["desc"]);
00247 $this->tpl->setVariable("TXT_REPLACE_FILE", $this->lng->txt("replace_file"));
00248
00249
00250 $obj_str = ($this->call_by_reference) ? "" : "&obj_id=".$this->obj_id;
00251
00252 $this->tpl->setVariable("FORMACTION", $this->getFormAction("update",$this->ctrl->getFormAction($this).$obj_str));
00253
00254 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->object->getType()."_edit"));
00255 $this->tpl->setVariable("TARGET", $this->getTargetFrame("update"));
00256 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00257 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
00258 $this->tpl->setVariable("CMD_SUBMIT", "update");
00259 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00260
00261 }
00262
00263 function sendFileObject()
00264 {
00265 $this->object->sendFile($_GET["hist_id"]);
00266
00267 return true;
00268 }
00269
00270
00276 function versionsObject()
00277 {
00278 global $rbacsystem;
00279
00280 if (!$rbacsystem->checkAccess("read", $_GET["ref_id"]))
00281 {
00282 $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00283 }
00284
00285 require_once("classes/class.ilHistoryGUI.php");
00286
00287 $hist_gui =& new ilHistoryGUI($this->object->getId());
00288
00289
00290
00291 $hist_html = $hist_gui->getVersionsTable(
00292 array("ref_id" => $_GET["ref_id"], "cmd" => "versions",
00293 "cmdClass" =>$_GET["cmdClass"], "cmdNode" =>$_GET["cmdNode"]));
00294
00295 $this->tpl->setVariable("ADM_CONTENT", $hist_html);
00296 }
00297
00298
00299 function getTabs(&$tabs_gui)
00300 {
00301 global $rbacsystem;
00302
00303 $this->ctrl->setParameter($this,"ref_id",$this->ref_id);
00304
00305 if ($rbacsystem->checkAccess('write',$this->ref_id))
00306 {
00307 $tabs_gui->addTarget("edit_properties",
00308 $this->ctrl->getLinkTarget($this, "edit"), "edit", get_class($this));
00309 }
00310
00311 if ($rbacsystem->checkAccess('write',$this->ref_id))
00312 {
00313 $tabs_gui->addTarget("versions",
00314 $this->ctrl->getLinkTarget($this, "versions"), "versions", get_class($this));
00315 }
00316
00317 if ($rbacsystem->checkAccess('edit_permission',$this->ref_id))
00318 {
00319 $tabs_gui->addTarget("perm_settings",
00320 $this->ctrl->getLinkTarget($this, "perm"), "perm", get_class($this));
00321 }
00322 }
00323
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00355 }
00356 ?>