• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilObjFileGUI.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004         +-----------------------------------------------------------------------------+
00005         | ILIAS open source                                                           |
00006         +-----------------------------------------------------------------------------+
00007         | Copyright (c) 1998-2005 ILIAS open source, University of Cologne            |
00008         |                                                                             |
00009         | This program is free software; you can redistribute it and/or               |
00010         | modify it under the terms of the GNU General Public License                 |
00011         | as published by the Free Software Foundation; either version 2              |
00012         | of the License, or (at your option) any later version.                      |
00013         |                                                                             |
00014         | This program is distributed in the hope that it will be useful,             |
00015         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00016         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00017         | GNU General Public License for more details.                                |
00018         |                                                                             |
00019         | You should have received a copy of the GNU General Public License           |
00020         | along with this program; if not, write to the Free Software                 |
00021         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00022         +-----------------------------------------------------------------------------+
00023 */
00024 
00025 
00038 require_once "class.ilObjectGUI.php";
00039 require_once "./classes/class.ilObjFile.php"; // temp. fix
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, false);
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                 $this->prepareOutput();
00063                 
00064 //echo "-$cmd-";
00065                 switch ($next_class)
00066                 {
00067                         case "ilinfoscreengui":
00068                                 $this->infoScreen();    // forwards command
00069                                 break;
00070 
00071                         case 'ilmdeditorgui':
00072 
00073                                 include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
00074 
00075                                 $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
00076                                 $md_gui->addObserver($this->object,'MDUpdateListener','General');
00077                                 
00078                                 // todo: make this work
00079                                 $md_gui->addObserver($this->object,'MDUpdateListener','Technical');
00080                                 
00081                                 $this->ctrl->forwardCommand($md_gui);
00082                                 break;
00083                                 
00084                         case 'ilpermissiongui':
00085                                 include_once("./classes/class.ilPermissionGUI.php");
00086                                 $perm_gui =& new ilPermissionGUI($this);
00087                                 $ret =& $this->ctrl->forwardCommand($perm_gui);
00088                                 break;
00089 
00090                         default:
00091                                 if (empty($cmd))
00092                                 {
00093                                         // does not seem to work
00094                                         //$this->ctrl->returnToParent($this);
00095                                         //$cmd = "view";
00096                                         $cmd = "infoScreen";
00097                                 }
00098 
00099                                 $cmd .= "Object";
00100                                 $this->$cmd();
00101                                 break;
00102                 }               
00103         }
00104 
00110         function createObject()
00111         {
00112                 global $rbacsystem;
00113 
00114                 $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
00115 
00116                 if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
00117                 {
00118                         $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00119                 }
00120 
00121                 // fill in saved values in case of error
00122                 $data = array();
00123                 $data["fields"] = array();
00124                 $data["fields"]["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
00125                 $data["fields"]["desc"] = ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]);
00126                 $data["fields"]["file"] = $_SESSION["error_post_vars"]["Fobject"]["file"];
00127 
00128                 $this->getTemplateFile("new",$this->type);
00129 
00130                 foreach ($data["fields"] as $key => $val)
00131                 {
00132                         $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
00133                         $this->tpl->setVariable(strtoupper($key), $val);
00134                         #$this->tpl->parseCurrentBlock();
00135                 }
00136                 
00137                 $this->ctrl->setParameter($this, "new_type", $new_type);
00138                 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00139 
00140                 $this->tpl->setVariable("TXT_TITLE_NOTE", $this->lng->txt("if_no_title_then_filename"));
00141                 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->type."_new"));
00142                 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00143                 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($this->type."_add"));
00144                 $this->tpl->setVariable("TXT_SUBMIT_AND_META", $this->lng->txt("file_add_and_metadata"));
00145                 $this->tpl->setVariable("CMD_SUBMIT", "save");
00146                 $this->tpl->setVariable("CMD_SUBMIT_AND_META", "saveAndMeta");
00147                 $this->tpl->setVariable("TARGET", $this->getTargetFrame("save"));
00148                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00149         }
00150 
00156         function saveObject()
00157         {
00158                 global $rbacsystem, $objDefinition;
00159 
00160                 $data = $_FILES["Fobject"];
00161 
00162                 // delete trailing '/' in filename
00163                 while (substr($data["name"]["file"],-1) == '/')
00164                 {
00165                         $data["name"]["file"] = substr($data["name"]["file"],0,-1);
00166                 }
00167 
00168                 if (empty($data["name"]["file"]))
00169                 {
00170                         $this->ilias->raiseError($this->lng->txt("msg_no_file"),$this->ilias->error_obj->MESSAGE);
00171                 }
00172 
00173                 if (empty($_POST["Fobject"]["title"]))
00174                 {
00175                         $_POST["Fobject"]["title"] = $_FILES["Fobject"]["name"]["file"];
00176                         //$this->ilias->raiseError($this->lng->txt("msg_no_title"),$this->ilias->error_obj->MESSAGE);
00177                 }
00178 
00179                 // create and insert file in grp_tree
00180                 include_once("classes/class.ilObjFile.php");
00181                 $fileObj = new ilObjFile();
00182                 $fileObj->setType($this->type);
00183                 $fileObj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
00184                 $fileObj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
00185                 $fileObj->setFileName(ilUtil::stripSlashes($_FILES["Fobject"]["name"]["file"]));
00186                 $fileObj->setFileType($_FILES["Fobject"]["type"]["file"]);
00187                 $fileObj->setFileSize($_FILES["Fobject"]["size"]["file"]);
00188                 $fileObj->create();
00189                 $fileObj->createReference();
00190                 $fileObj->putInTree($_GET["ref_id"]);
00191                 $fileObj->setPermissions($_GET["ref_id"]);
00192                 // upload file to filesystem
00193                 $fileObj->createDirectory();
00194                 $fileObj->getUploadFile($_FILES["Fobject"]["tmp_name"]["file"],ilUtil::stripSlashes($_FILES["Fobject"]["name"]["file"]));
00195 
00196                 sendInfo($this->lng->txt("file_added"),true);
00197                 
00198                 $this->ctrl->setParameter($this, "ref_id", $fileObj->getRefId());
00199                 if ($this->ctrl->getCmd() == "saveAndMeta")
00200                 {
00201                         ilUtil::redirect($this->getReturnLocation("save",
00202                                 $this->ctrl->getLinkTargetByClass(array("ilobjfilegui", "ilmdeditorgui"), "listSection")));
00203                 }
00204                 else
00205                 {
00206                         $this->ctrl->returnToParent($this);
00207                 }
00208         }
00209 
00215         function saveAndMetaObject()
00216         {
00217                 $this->saveObject();
00218         }
00219 
00225         function updateObject()
00226         {
00227                 $data = $_FILES["Fobject"];
00228 
00229                 // delete trailing '/' in filename
00230                 while (substr($data["name"]["file"],-1) == '/')
00231                 {
00232                         $data["name"]["file"] = substr($data["name"]["file"],0,-1);
00233                 }
00234 
00235                 if (empty($data["name"]["file"]) && empty($_POST["Fobject"]["title"]))
00236                 {
00237                         $this->ilias->raiseError($this->lng->txt("msg_no_title"),$this->ilias->error_obj->MESSAGE);
00238                 }
00239 
00240                 if (empty($_POST["Fobject"]["title"]))
00241                 {
00242                         $_POST["Fobject"]["title"] = $_FILES["Fobject"]["name"]["file"];
00243                 }
00244 
00245                 if (!empty($data["name"]["file"]))
00246                 {
00247                         $this->object->replaceFile($_FILES["Fobject"]["tmp_name"]["file"],$_FILES["Fobject"]["name"]["file"]);
00248                         $this->object->setFileName($_FILES["Fobject"]["name"]["file"]);
00249                         $this->object->setFileType($_FILES["Fobject"]["type"]["file"]);
00250                         $this->object->setFileSize($_FILES["Fobject"]["size"]["file"]);
00251                 }
00252                 
00253                 $this->object->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
00254                 $this->object->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
00255 
00256                 $this->update = $this->object->update();
00257 
00258                 sendInfo($this->lng->txt("msg_obj_modified"),true);
00259 //echo "-".$this->ctrl->getLinkTarget($this)."-";
00260                 ilUtil::redirect($this->getReturnLocation("update",$this->ctrl->getLinkTarget($this, "edit")));
00261         }
00262 
00263         
00269         function editObject()
00270         {
00271                 global $rbacsystem;
00272 
00273                 if (!$rbacsystem->checkAccess("write", $this->ref_id))
00274                 {
00275                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
00276                 }
00277 
00278                 $fields = array();
00279 
00280                 if ($_SESSION["error_post_vars"])
00281                 {
00282                         // fill in saved values in case of error
00283                         $fields["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
00284                         $fields["desc"] = ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]);
00285                 }
00286                 else
00287                 {
00288                         $fields["title"] = ilUtil::prepareFormOutput($this->object->getTitle());
00289                         $fields["desc"] = ilUtil::stripSlashes($this->object->getDescription());
00290                 }
00291                 
00292                 $this->getTemplateFile("edit");
00293                 $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
00294                 $this->tpl->setVariable("TITLE", $fields["title"]);
00295                 $this->tpl->setVariable("TXT_DESC", $this->lng->txt("desc"));
00296                 $this->tpl->setVariable("DESC", $fields["desc"]);
00297                 $this->tpl->setVariable("TXT_REPLACE_FILE", $this->lng->txt("replace_file"));
00298                 //$this->tpl->parseCurrentBlock();
00299 
00300                 $obj_str = ($this->call_by_reference) ? "" : "&obj_id=".$this->obj_id;
00301 
00302                 $this->tpl->setVariable("FORMACTION", $this->getFormAction("update",$this->ctrl->getFormAction($this).$obj_str));
00303                 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->object->getType()."_edit"));
00304                 $this->tpl->setVariable("TARGET", $this->getTargetFrame("update"));
00305                 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00306                 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
00307                 $this->tpl->setVariable("CMD_SUBMIT", "update");
00308                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00309                 //$this->tpl->parseCurrentBlock();
00310         }
00311         
00312         function sendFileObject()
00313         {
00314                 $this->object->sendFile($_GET["hist_id"]);
00315                 
00316                 return true;
00317         }
00318 
00319 
00325         function versionsObject()
00326         {
00327                 global $rbacsystem;
00328 
00329                 if (!$rbacsystem->checkAccess("read", $_GET["ref_id"]))
00330                 {
00331                         $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00332                 }
00333 
00334                 require_once("classes/class.ilHistoryGUI.php");
00335                 
00336                 $hist_gui =& new ilHistoryGUI($this->object->getId());
00337                 
00338                 // not nice, should be changed, if ilCtrl handling
00339                 // has been introduced to administration
00340                 $hist_html = $hist_gui->getVersionsTable(
00341                         array("ref_id" => $_GET["ref_id"], "cmd" => "versions",
00342                         "cmdClass" =>$_GET["cmdClass"], "cmdNode" =>$_GET["cmdNode"]));
00343                 
00344                 $this->tpl->setVariable("ADM_CONTENT", $hist_html);
00345         }
00346         
00352         function infoScreenObject()
00353         {
00354                 $this->ctrl->setCmd("showSummary");
00355                 $this->ctrl->setCmdClass("ilinfoscreengui");
00356                 $this->infoScreen();
00357         }
00358 
00362         function infoScreen()
00363         {
00364                 global $ilAccess;
00365 
00366                 if (!$ilAccess->checkAccess("visible", "", $this->ref_id))
00367                 {
00368                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
00369                 }
00370 
00371                 include_once("classes/class.ilInfoScreenGUI.php");
00372                 $info = new ilInfoScreenGUI($this);
00373 
00374                 if ($ilAccess->checkAccess("read", "sendfile", $this->ref_id))
00375                 {
00376                         $info->addButton($this->lng->txt("file_read"), $this->ctrl->getLinkTarget($this, "sendfile"));
00377                 }
00378                 
00379                 $info->enablePrivateNotes();
00380                 
00381                 // standard meta data
00382                 $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
00383                 
00384                 $info->addSection($this->lng->txt("file_info"));
00385                 $info->addProperty($this->lng->txt("filename"),
00386                         $this->object->getFileName());
00387                 $info->addProperty($this->lng->txt("type"),
00388                         $this->object->getFileType());
00389                 $info->addProperty($this->lng->txt("size"),
00390                         ilObjFile::_lookupFileSize($this->object->getId(), true));
00391                 $info->addProperty($this->lng->txt("version"),
00392                         $this->object->getVersion());
00393 
00394                 // forward the command
00395                 $this->ctrl->forwardCommand($info);
00396         }
00397 
00398 
00399         // get tabs
00400         function getTabs(&$tabs_gui)
00401         {
00402                 global $rbacsystem;
00403                 
00404 //echo "-".$this->ctrl->getCmd()."-";
00405 
00406                 $this->ctrl->setParameter($this,"ref_id",$this->ref_id);
00407 
00408                 if ($rbacsystem->checkAccess('visible',$this->ref_id))
00409                 {
00410 //echo "-".$this->ctrl->getNextClass()."-";
00411 //echo "-".$_GET["cmd"]."-";
00412                         $force_active = (strtolower($_GET["cmdClass"]) == "ilinfoscreengui"
00413                                 || strtolower($_GET["cmdClass"]) == "ilnotegui")
00414                                 ? true
00415                                 : false;
00416                         $tabs_gui->addTarget("info_short",
00417                                  $this->ctrl->getLinkTargetByClass(
00418                                  array("ilobjfilegui", "ilinfoscreengui"), "showSummary"),
00419                                  array("showSummary","", "infoScreen"),
00420                                  "", "", $force_active);
00421                 }
00422 
00423                 if ($rbacsystem->checkAccess('write',$this->ref_id))
00424                 {
00425                         $tabs_gui->addTarget("edit",
00426                                 $this->ctrl->getLinkTarget($this, "edit"), "edit", "");
00427                 }
00428                 
00429                 // meta data 
00430                 if($rbacsystem->checkAccess('write',$this->object->getRefId()))
00431                 {
00432                         $tabs_gui->addTarget("meta_data",
00433                                  $this->ctrl->getLinkTargetByClass(array('ilobjfilegui','ilmdeditorgui'),'listSection'),
00434                                  "", 'ilmdeditorgui');
00435                 }
00436 
00437                 if ($rbacsystem->checkAccess('write',$this->ref_id))
00438                 {
00439                         $tabs_gui->addTarget("versions",
00440                                 $this->ctrl->getLinkTarget($this, "versions"), "versions", get_class($this));
00441                 }
00442 
00443                 if ($rbacsystem->checkAccess('edit_permission',$this->ref_id))
00444                 {
00445                         $tabs_gui->addTarget("perm_settings",
00446                                 $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
00447                 }
00448         }
00449 
00450 } // END class.ilObjFileGUI
00451 ?>

Generated on Fri Dec 13 2013 11:57:54 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1