• 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-2001 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 
00036 require_once "class.ilObjectGUI.php";
00037 require_once "./classes/class.ilObjFile.php"; // temp. fix
00038 
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, $a_prepare_output);
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 
00061                 switch ($next_class)
00062                 {
00063                         default:
00064                                 if (empty($cmd))
00065                                 {
00066                                         $this->ctrl->returnToParent($this);
00067                                         $cmd = "view";
00068                                 }
00069 
00070                                 $cmd .= "Object";
00071                                 $this->$cmd();
00072                                 break;
00073                 }               
00074         }
00075 
00081         function createObject()
00082         {
00083                 global $rbacsystem;
00084 
00085                 $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
00086 
00087                 if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
00088                 {
00089                         $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00090                 }
00091 
00092                 // fill in saved values in case of error
00093                 $data = array();
00094                 $data["fields"] = array();
00095                 $data["fields"]["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
00096                 $data["fields"]["desc"] = ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]);
00097                 $data["fields"]["file"] = $_SESSION["error_post_vars"]["Fobject"]["file"];
00098 
00099                 $this->getTemplateFile("new",$this->type);
00100 
00101                 foreach ($data["fields"] as $key => $val)
00102                 {
00103                         $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
00104                         $this->tpl->setVariable(strtoupper($key), $val);
00105                         $this->tpl->parseCurrentBlock();
00106                 }
00107 
00108                 $this->tpl->setVariable("FORMACTION", $this->getFormAction("save",$this->ctrl->getFormAction($this)."&new_type=".$new_type));
00109                 //$this->tpl->setVariable("FORMACTION", $this->getFormAction("save","adm_object.php?cmd=gateway&ref_id=".$_GET["ref_id"]."&new_type=".$this->type));
00110                 $this->tpl->setVariable("TXT_TITLE_NOTE", $this->lng->txt("if_no_title_then_filename"));
00111                 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->type."_new"));
00112                 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00113                 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($this->type."_add"));
00114                 $this->tpl->setVariable("CMD_SUBMIT", "save");
00115                 $this->tpl->setVariable("TARGET", $this->getTargetFrame("save"));
00116                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00117         }
00118 
00124         function saveObject()
00125         {
00126                 global $rbacsystem, $objDefinition;
00127 
00128                 $data = $_FILES["Fobject"];
00129 
00130                 // delete trailing '/' in filename
00131                 while (substr($data["name"]["file"],-1) == '/')
00132                 {
00133                         $data["name"]["file"] = substr($data["name"]["file"],0,-1);
00134                 }
00135 
00136                 if (empty($data["name"]["file"]))
00137                 {
00138                         $this->ilias->raiseError($this->lng->txt("msg_no_file"),$this->ilias->error_obj->MESSAGE);
00139                 }
00140 
00141                 if (empty($_POST["Fobject"]["title"]))
00142                 {
00143                         $_POST["Fobject"]["title"] = $_FILES["Fobject"]["name"]["file"];
00144                         //$this->ilias->raiseError($this->lng->txt("msg_no_title"),$this->ilias->error_obj->MESSAGE);
00145                 }
00146 
00147                 // create and insert file in grp_tree
00148                 include_once("classes/class.ilObjFile.php");
00149                 $fileObj = new ilObjFile();
00150                 $fileObj->setType($this->type);
00151                 $fileObj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
00152                 $fileObj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
00153                 $fileObj->setFileName(ilUtil::stripSlashes($_FILES["Fobject"]["name"]["file"]));
00154                 $fileObj->setFileType($_FILES["Fobject"]["type"]["file"]);
00155                 $fileObj->create();
00156                 $fileObj->createReference();
00157                 $fileObj->putInTree($_GET["ref_id"]);
00158                 $fileObj->setPermissions($_GET["ref_id"]);
00159                 // upload file to filesystem
00160                 $fileObj->createDirectory();
00161                 $fileObj->getUploadFile($_FILES["Fobject"]["tmp_name"]["file"],ilUtil::stripSlashes($_FILES["Fobject"]["name"]["file"]));
00162 
00163                 sendInfo($this->lng->txt("file_added"),true);
00164                 ilUtil::redirect($this->getReturnLocation("save",$this->ctrl->getLinkTarget($this,"")));
00165                 //ilUtil::redirect($this->getReturnLocation("save","adm_object.php?".$this->link_params));
00166         }
00167         
00173         function updateObject()
00174         {
00175                 $data = $_FILES["Fobject"];
00176 
00177                 // delete trailing '/' in filename
00178                 while (substr($data["name"]["file"],-1) == '/')
00179                 {
00180                         $data["name"]["file"] = substr($data["name"]["file"],0,-1);
00181                 }
00182 
00183                 if (empty($data["name"]["file"]) && empty($_POST["Fobject"]["title"]))
00184                 {
00185                         $this->ilias->raiseError($this->lng->txt("msg_no_title"),$this->ilias->error_obj->MESSAGE);
00186                 }
00187 
00188                 if (empty($_POST["Fobject"]["title"]))
00189                 {
00190                         $_POST["Fobject"]["title"] = $_FILES["Fobject"]["name"]["file"];
00191                 }
00192 
00193                 if (!empty($data["name"]["file"]))
00194                 {
00195                         $this->object->replaceFile($_FILES["Fobject"]["tmp_name"]["file"],$_FILES["Fobject"]["name"]["file"]);
00196                         $this->object->setFileName($_FILES["Fobject"]["name"]["file"]);
00197                         $this->object->setFileType($_FILES["Fobject"]["type"]["file"]);
00198                 }
00199                 
00200                 $this->object->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
00201                 $this->object->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
00202 
00203                 $this->update = $this->object->update();
00204 
00205                 sendInfo($this->lng->txt("msg_obj_modified"),true);
00206 
00207                 ilUtil::redirect($this->getReturnLocation("update",$this->ctrl->getLinkTarget($this)));
00208                 //ilUtil::redirect($this->getReturnLocation("update","adm_object.php?ref_id=".$this->ref_id));
00209         }
00210 
00211         
00217         function editObject()
00218         {
00219                 global $rbacsystem;
00220 
00221                 if (!$rbacsystem->checkAccess("write", $this->ref_id))
00222                 {
00223                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
00224                 }
00225 
00226                 $fields = array();
00227 
00228                 if ($_SESSION["error_post_vars"])
00229                 {
00230                         // fill in saved values in case of error
00231                         $fields["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
00232                         $fields["desc"] = ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]);
00233                 }
00234                 else
00235                 {
00236                         $fields["title"] = ilUtil::prepareFormOutput($this->object->getTitle());
00237                         $fields["desc"] = ilUtil::stripSlashes($this->object->getDescription());
00238                 }
00239                 
00240                 $this->getTemplateFile("edit");
00241                 $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
00242                 $this->tpl->setVariable("TITLE", $fields["title"]);
00243                 $this->tpl->setVariable("TXT_DESC", $this->lng->txt("desc"));
00244                 $this->tpl->setVariable("DESC", $fields["desc"]);
00245                 $this->tpl->setVariable("TXT_REPLACE_FILE", $this->lng->txt("replace_file"));
00246                 //$this->tpl->parseCurrentBlock();
00247 
00248                 $obj_str = ($this->call_by_reference) ? "" : "&obj_id=".$this->obj_id;
00249 
00250                 $this->tpl->setVariable("FORMACTION", $this->getFormAction("update",$this->ctrl->getFormAction($this).$obj_str));
00251                 //$this->tpl->setVariable("FORMACTION", $this->getFormAction("update","adm_object.php?cmd=gateway&ref_id=".$this->ref_id.$obj_str));
00252                 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->object->getType()."_edit"));
00253                 $this->tpl->setVariable("TARGET", $this->getTargetFrame("update"));
00254                 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00255                 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
00256                 $this->tpl->setVariable("CMD_SUBMIT", "update");
00257                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00258                 //$this->tpl->parseCurrentBlock();
00259         }
00260         
00261         function sendFileObject()
00262         {
00263                 $this->object->sendFile($_GET["hist_id"]);
00264                 
00265                 return true;
00266         }
00267 
00273         function cancelObject()
00274         {
00275                 session_unregister("saved_post");
00276 
00277                 sendInfo($this->lng->txt("msg_cancel"),true);
00278 
00279                 //sendInfo($this->lng->txt("action_aborted"),true);
00280                 $return_location = $_GET["cmd_return_location"];
00281                                 
00282                 ilUtil::redirect($this->ctrl->getLinkTarget($this,$return_location));
00283                 //ilUtil::redirect($this->getReturnLocation("cancel","adm_object.php?".$this->link_params));
00284         }
00285         
00286         
00292         function versionsObject()
00293         {
00294                 global $rbacsystem;
00295 
00296                 if (!$rbacsystem->checkAccess("read", $_GET["ref_id"]))
00297                 {
00298                         $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00299                 }
00300 
00301                 require_once("classes/class.ilHistoryGUI.php");
00302                 
00303                 $hist_gui =& new ilHistoryGUI($this->object->getId());
00304                 
00305                 // not nice, should be changed, if ilCtrl handling
00306                 // has been introduced to administration
00307                 $hist_html = $hist_gui->getVersionsTable(
00308                         array("ref_id" => $_GET["ref_id"], "cmd" => "versions",
00309                         "cmdClass" =>$_GET["cmdClass"], "cmdNode" =>$_GET["cmdNode"]));
00310                 
00311                 $this->tpl->setVariable("ADM_CONTENT", $hist_html);
00312         }
00313 
00314         // get tabs
00315         function getTabs(&$tabs_gui)
00316         {
00317                 global $rbacsystem;
00318 
00319                 $this->ctrl->setParameter($this,"ref_id",$this->ref_id);
00320 
00321                 if ($rbacsystem->checkAccess('write',$this->ref_id))
00322                 {
00323                         $tabs_gui->addTarget("edit_properties",
00324                                 $this->ctrl->getLinkTarget($this, "edit"), "edit", get_class($this));
00325                 }
00326                 
00327                 if ($rbacsystem->checkAccess('write',$this->ref_id))
00328                 {
00329                         $tabs_gui->addTarget("versions",
00330                                 $this->ctrl->getLinkTarget($this, "versions"), "versions", get_class($this));
00331                 }
00332 
00333                 if ($rbacsystem->checkAccess('edit_permission',$this->ref_id))
00334                 {
00335                         $tabs_gui->addTarget("perm_settings",
00336                                 $this->ctrl->getLinkTarget($this, "perm"), "perm", get_class($this));
00337                 }
00338                 
00339                 if ($this->ctrl->getTargetScript() == "adm_object.php")
00340                 {
00341                         $tabs_gui->addTarget("show_owner",
00342                                 $this->ctrl->getLinkTarget($this, "owner"), "owner", get_class($this));
00343                         
00344                         if ($this->tree->getSavedNodeData($this->ref_id))
00345                         {
00346                                 $tabs_gui->addTarget("trash",
00347                                         $this->ctrl->getLinkTarget($this, "trash"), "trash", get_class($this));
00348                         }
00349                 }
00350         }
00351 
00357         /*function cancelObject()
00358         {
00359                 $this->link_params = "ref_id=".$this->tree->getParentId($this->ref_id);
00360 
00361                 session_unregister("saved_post");
00362 
00363                 sendInfo($this->lng->txt("msg_cancel"),true);
00364 
00365                 ilUtil::redirect($this->getReturnLocation("cancel","adm_object.php?".$this->link_params));
00366         }*/
00367 
00383 } // END class.ilObjFileGUI
00384 ?>

Generated on Fri Dec 13 2013 09:06:34 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1