ILIAS PHP Cross Reference Learning Management Systems

Source: /Modules/Session/classes/class.ilSessionFile.php - 278 lines - 6777 bytes - Summary - Text - Print

   1  <?php
   2  /*
   3      +-----------------------------------------------------------------------------+
   4      | ILIAS open source                                                           |
   5      +-----------------------------------------------------------------------------+
   6      | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
   7      |                                                                             |
   8      | This program is free software; you can redistribute it and/or               |
   9      | modify it under the terms of the GNU General Public License                 |
  10      | as published by the Free Software Foundation; either version 2              |
  11      | of the License, or (at your option) any later version.                      |
  12      |                                                                             |
  13      | This program is distributed in the hope that it will be useful,             |
  14      | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
  15      | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
  16      | GNU General Public License for more details.                                |
  17      |                                                                             |
  18      | You should have received a copy of the GNU General Public License           |
  19      | along with this program; if not, write to the Free Software                 |
  20      | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
  21      +-----------------------------------------------------------------------------+
  22  */
  23  
  24  include_once ('Modules/Session/classes/class.ilFSStorageSession.php');
  25  
  26  /**
  27  * class ilEvent
  28  *
  29  * @author Stefan Meyer <smeyer.ilias@gmx.de> 
  30  * @version $Id$
  31  * 
  32  * @extends Object
  33  */
  34  
  35  
  36  class ilSessionFile
  37  {
  38      var $ilErr;
  39      var $ilDB;
  40      var $tree;
  41      var $lng;
  42  
  43      var $event_id = null;
  44      var $file_id = null;
  45  
  46      private $fss_storage = null;
  47  
  48  	function ilSessionFile($a_file_id = null)
  49      {
  50          global $ilErr,$ilDB,$lng;
  51  
  52          $this->ilErr =& $ilErr;
  53          $this->db  =& $ilDB;
  54          $this->lng =& $lng;
  55  
  56          $this->file_id = $a_file_id;
  57          $this->__read();
  58      }
  59  
  60  	function setFileId($a_id)
  61      {
  62          $this->file_id = $a_id;
  63      }
  64  	function getFileId()
  65      {
  66          return $this->file_id;
  67      }
  68  
  69  	function getSessionId()
  70      {
  71          return $this->event_id;
  72      }
  73  	function setSessionId($a_event_id)
  74      {
  75          $this->event_id = $a_event_id;
  76      }
  77  
  78  	function setFileName($a_name)
  79      {
  80          $this->file_name = $a_name;
  81      }
  82  	function getFileName()
  83      {
  84          return $this->file_name;
  85      }
  86  	function setFileType($a_type)
  87      {
  88          $this->file_type = $a_type;
  89      }
  90  	function getFileType()
  91      {
  92          return $this->file_type;
  93      }
  94  	function setFileSize($a_size)
  95      {
  96          $this->file_size = $a_size;
  97      }
  98  	function getFileSize()
  99      {
 100          return $this->file_size;
 101      }
 102  	function setTemporaryName($a_name)
 103      {
 104          $this->tmp_name = $a_name;
 105      }
 106  	function getTemporaryName()
 107      {
 108          return $this->tmp_name;
 109      }
 110  	function setErrorCode($a_code)
 111      {
 112          $this->error_code = $a_code;
 113      }
 114  	function getErrorCode()
 115      {
 116          return $this->error_code;
 117      }
 118      
 119  	function getAbsolutePath()
 120      {
 121          return $this->fss_storage->getAbsolutePath()."/".$this->getFileId();
 122      }
 123  
 124  	function validate()
 125      {
 126          switch($this->getErrorCode())
 127          {
 128              case UPLOAD_ERR_INI_SIZE:
 129                  $this->ilErr->appendMessage($this->lng->txt('file_upload_ini_size'));
 130                  break;
 131              case UPLOAD_ERR_FORM_SIZE:
 132                  $this->ilErr->appendMessage($this->lng->txt('file_upload_form_size'));
 133                  break;
 134  
 135              case UPLOAD_ERR_PARTIAL:
 136                  $this->ilErr->appendMessage($this->lng->txt('file_upload_only_partial'));
 137                  break;
 138  
 139              case UPLOAD_ERR_NO_TMP_DIR:
 140                  $this->ilErr->appendMessage($this->lng->txt('file_upload_no_tmp_dir'));
 141                  break;
 142  
 143              #case UPLOAD_ERR_CANT_WRITE:
 144              #    $this->ilErr->appendMessage($this->lng->txt('file_upload_no_write'));
 145              #    break;
 146  
 147              case UPLOAD_ERR_OK:
 148              case UPLOAD_ERR_NO_FILE:
 149              default:
 150                  return true;
 151          }
 152      }
 153      
 154      /**
 155       * Clone files
 156       *
 157       * @access public
 158       * @param int new event_id
 159       * 
 160       */
 161  	public function cloneFiles($a_target_event_id)
 162      {
 163           $file = new ilSessionFile();
 164           $file->setSessionId($a_target_event_id);
 165           $file->setFileName($this->getFileName());
 166           $file->setFileType($this->getFileType());
 167           $file->setFileSize($this->getFileSize());
 168           $file->create(false);
 169           
 170           // Copy file
 171          $source = new ilFSStorageSession($this->getSessionId());
 172          $source->copyFile($this->getAbsolutePath(),$file->getAbsolutePath());         
 173      }
 174  
 175  	function create($a_upload = true)
 176      {
 177          global $ilDB;
 178          
 179          if($this->getErrorCode() != 0)
 180          {
 181              return false;
 182          }
 183  
 184          $next_id = $ilDB->nextId('event_file');
 185          $query = "INSERT INTO event_file (file_id,event_id,file_name,file_size,file_type) ".
 186              "VALUES( ".
 187              $ilDB->quote($next_id ,'integer').", ".
 188              $ilDB->quote($this->getSessionId() ,'integer').", ".
 189              $ilDB->quote($this->getFileName() ,'text').", ".
 190              $ilDB->quote($this->getFileSize() ,'integer').", ".
 191              $ilDB->quote($this->getFileType() ,'text')." ".
 192              ")";
 193          
 194          $res = $ilDB->manipulate($query);
 195          $this->setFileId($next_id);
 196  
 197          $this->fss_storage = new ilFSStorageSession($this->getSessionId());
 198          $this->fss_storage->createDirectory();
 199  
 200          if($a_upload)
 201          {
 202              // now create file
 203              ilUtil::moveUploadedFile($this->getTemporaryName(),
 204                  $this->getFileName(),
 205                  $this->fss_storage->getAbsolutePath().'/'.$this->getFileId());
 206              
 207          }
 208  
 209          return true;
 210      }
 211  
 212  	function delete()
 213      {
 214          global $ilDB;
 215          
 216          // Delete db entry
 217          $query = "DELETE FROM event_file ".
 218              "WHERE file_id = ".$ilDB->quote($this->getFileId() ,'integer')." ";
 219          $res = $ilDB->manipulate($query);
 220  
 221          // Delete file
 222          $this->fss_storage->deleteFile($this->getAbsolutePath());
 223          return true;
 224      }
 225          
 226  	function _deleteByEvent($a_event_id)
 227      {
 228          global $ilDB;
 229  
 230          // delete all event ids and delete assigned files
 231          $query = "DELETE FROM event_file ".
 232              "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')."";
 233          $res = $ilDB->manipulate($query);
 234  
 235          #$this->fss_storage->delete();
 236          return true;
 237      }
 238  
 239  	function _readFilesByEvent($a_event_id)
 240      {
 241          global $ilDB;
 242  
 243          $query = "SELECT * FROM event_file ".
 244              "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')."";
 245  
 246          $res = $ilDB->query($query);
 247          while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
 248          {
 249              $files[] =& new ilSessionFile($row->file_id);
 250          }
 251          return is_array($files) ? $files : array();
 252      }
 253  
 254  	function __read()
 255      {
 256          global $ilDB;
 257          
 258          if(!$this->file_id)
 259          {
 260              return true;
 261          }
 262  
 263          // read file data
 264          $query = "SELECT * FROM event_file WHERE file_id = ".$ilDB->quote($this->file_id ,'integer')."";
 265          $res = $this->db->query($query);
 266          while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
 267          {
 268              $this->setFileName($row->file_name);
 269              $this->setFileSize($row->file_size);
 270              $this->setFileType($row->file_type);
 271              $this->setSessionId($row->event_id);
 272          }
 273          $this->fss_storage = new ilFSStorageSession($this->getSessionId());
 274          return true;
 275      }
 276          
 277  }
 278  ?>

title

Description

title

Description

title

Description

title

title

Body