4 require_once
"./classes/class.ilObject.php";
5 include_once(
'Modules/File/classes/class.ilFSStorageFile.php');
35 function ilObjFile($a_id = 0,$a_call_by_reference =
true)
39 $this->raise_upload_error =
true;
40 $this->
ilObject($a_id,$a_call_by_reference);
53 function create($a_upload =
false, $a_prevent_meta_data_creation =
false)
77 $this->file_storage->create();
85 require_once(
"classes/class.ilHistory.php");
90 require_once(
"./Services/News/classes/class.ilNewsItem.php");
92 if ($default_visibility ==
"public")
95 1, 0, $this->
getId());
98 $q =
"INSERT INTO file_data (file_id,file_name,file_type,file_size,version,f_mode) "
99 .
"VALUES (".$ilDB->quote($this->
getId() ,
'integer').
","
102 .$ilDB->quote((
int) $this->
getFileSize() ,
'integer').
","
103 .$ilDB->quote(1 ,
'integer').
",".$ilDB->quote($this->
getMode() ,
'text').
")";
104 $res = $ilDB->manipulate($q);
107 if ($this->
getMode() !=
"filelist" && !$a_prevent_meta_data_creation)
123 $technical = $md_obj->addTechnical();
126 $format = $technical->addFormat();
129 $technical->update();
147 include_once
'Services/MetaData/classes/class.ilMD.php';
149 if(!is_object($md_gen = $md->getGeneral()))
154 $md_gen->setTitle(
$title);
161 include_once
'Services/MetaData/classes/class.ilMD.php';
169 if(!is_object($md_technical = $md->getTechnical()))
174 foreach($md_technical->getFormatIds() as
$id)
176 $md_format = $md_technical->getFormat(
$id);
192 $version_subdir =
"";
197 $version_subdir = sprintf(
"%03d", $a_version);
201 if(!is_object($this->file_storage))
206 return $this->file_storage->getAbsolutePath().
'/'.$version_subdir;
216 $this->raise_upload_error = $a_raise;
240 require_once(
"classes/class.ilHistory.php");
244 $a_filename.
",".$this->getVersion()
246 $this->setFilename($a_filename);
255 require_once(
"classes/class.ilHistory.php");
259 $a_filename.
",".$this->getVersion()
261 $this->setFilename($a_filename);
270 function copy($a_source,$a_destination)
288 $ilDB->manipulate(
"UPDATE file_data SET version = 1 WHERE file_id = ".$ilDB->quote($this->getId() ,
'integer'));
292 require_once(
"classes/class.ilHistory.php");
306 $q =
"SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($this->
getId() ,
'integer');
307 $r = $this->ilias->db->query($q);
327 if ($this->
getMode() !=
"filelist")
337 $q =
"UPDATE file_data SET file_name = ".$ilDB->quote($this->
getFileName() ,
'text').
338 ", file_type = ".$ilDB->quote($this->getFiletype() ,
'text').
" ".
339 ", file_size = ".$ilDB->quote((
int) $this->
getFileSize() ,
'integer').
" ".
340 ", version = ".$ilDB->quote($this->
getVersion() ,
'integer').
" ".
341 ", f_mode = ".$ilDB->quote($this->
getMode() ,
'text').
" ".
342 "WHERE file_id = ".$ilDB->quote($this->
getId() ,
'integer');
343 $res = $ilDB->manipulate($q);
357 if(!is_object($technical = $md_obj->getTechnical()))
359 $technical = $md_obj->addTechnical();
364 $format_ids = $technical->getFormatIds();
365 if (count($format_ids) > 0)
367 $format = $technical->getFormat($format_ids[0]);
373 $format = $technical->addFormat();
377 $technical->update();
385 $this->filename = $a_name;
398 $this->filetype = $a_type;
408 $this->filesize = $a_size;
413 return $this->filesize;
423 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
431 if (is_null($a_hist_entry_id))
437 require_once(
"classes/class.ilHistory.php");
440 if ($entry ===
false)
445 $data = explode(
",",$entry[
"info_params"]);
462 $this->version = $a_version;
467 return $this->version;
477 $this->mode = $a_mode;
494 $q =
"UPDATE file_data SET ".
495 " file_type = ".$ilDB->quote($a_format ,
'text').
496 " WHERE file_id = ".$ilDB->quote($a_id ,
'integer');
497 $res = $ilDB->manipulate($q);
505 $q =
"SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($a_id ,
'integer');
506 $r = $ilDB->query($q);
516 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
525 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
534 if (is_null($a_hist_entry_id))
540 require_once(
"classes/class.ilHistory.php");
543 if ($entry ===
false)
548 $data = explode(
",",$entry[
"info_params"]);
563 if (is_null($a_hist_entry_id))
568 if (@!is_file(
$file))
575 require_once(
"classes/class.ilHistory.php");
578 if ($entry ===
false)
580 echo
"3";
return false;
583 $data = explode(
",",$entry[
"info_params"]);
595 if (@!is_file(
$file))
606 global $ilClientIniFile;
607 if ($ilClientIniFile->readVariable(
'file_access',
'download_with_uploaded_filename') !=
'1')
627 require_once
'class.ilObjFileAccess.php';
636 require_once
'class.ilObjFileAccess.php';
643 require_once
'class.ilObjFileAccess.php';
656 $path = pathinfo($a_file);
657 if (
$path[
"extension"] !=
"")
663 $filename =
"dummy.".$this->getFileExtension();
665 include_once(
"./Services/Utilities/classes/class.ilMimeTypeUtil.php");
720 $new_obj->createDirectory();
727 $query =
"INSERT INTO file_data (file_id,file_name,file_type,file_size,version,f_mode) VALUES (".
728 $ilDB->quote($new_obj->getId() ,
'integer').
",".
729 $ilDB->quote($this->getFileName() ,
'text').
",".
730 $ilDB->quote($this->getFileType() ,
'text').
",".
731 $ilDB->quote((
int) $this->getFileSize() ,
'integer').
", ".
732 $ilDB->quote($this->getVersion() ,
'integer').
", ".
733 $ilDB->quote($this->getMode() ,
'text').
")";
734 $res = $ilDB->manipulate($query);
737 require_once(
"classes/class.ilHistory.php");
741 $new_obj->addNewsNotification(
"file_created");
760 if (count($usages) == 0)
763 if (!parent::delete())
769 $q =
"DELETE FROM file_data WHERE file_id = ".$ilDB->quote($this->
getId() ,
'integer');
770 $this->ilias->db->query($q);
773 require_once(
"classes/class.ilHistory.php");
783 if ($this->
getMode() !=
"filelist")
803 $subdir =
"il_".IL_INST_ID.
"_file_".$this->
getId();
808 if (@!is_dir($filedir))
823 $ilDB->manipulate(
"DELETE FROM file_usage WHERE usage_type = ".
824 $ilDB->quote($a_type,
"text").
825 " AND usage_id = ".$ilDB->quote((
int) $a_id,
"integer").
826 " AND usage_hist_nr = ".$ilDB->quote((
int) $a_usage_hist_nr,
"integer"));
832 function _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0)
836 $ilDB->manipulate(
"DELETE FROM file_usage WHERE usage_type = ".
837 $ilDB->quote((
string) $a_type,
"text").
838 " AND usage_id = ".$ilDB->quote((
int) $a_id,
"integer").
839 " AND usage_hist_nr = ".$ilDB->quote((
int) $a_usage_hist_nr,
"integer").
840 " AND id = ".$ilDB->quote((
int) $a_mob_id,
"integer"));
842 $ilDB->manipulate(
"INSERT INTO file_usage (id, usage_type, usage_id, usage_hist_nr) VALUES".
843 " (".$ilDB->quote((
int) $a_mob_id,
"integer").
",".
844 $ilDB->quote((
string) $a_type,
"text").
",".
845 $ilDB->quote((
int) $a_id,
"integer").
",".
846 $ilDB->quote((
int) $a_usage_hist_nr,
"integer").
")");
857 $q =
"SELECT * FROM file_usage WHERE id = ".$ilDB->quote($this->
getId(),
"integer");
858 $us_set = $ilDB->query($q);
860 while($us_rec = $ilDB->fetchAssoc($us_set))
862 $ret[] = array(
"type" => $us_rec[
"usage_type"],
863 "id" => $us_rec[
"usage_id"],
864 "hist_nr" => $us_rec[
"usage_hist_nr"]);
883 $q =
"SELECT * FROM file_usage WHERE ".
884 "usage_id = ".$ilDB->quote((
int) $a_id,
"integer").
" AND ".
885 "usage_type = ".$ilDB->quote((
string) $a_type,
"text").
" AND ".
886 "usage_hist_nr = ".$ilDB->quote((
int) $a_usage_hist_nr,
"integer");
887 $file_set = $ilDB->query($q);
889 while($file_rec = $ilDB->fetchAssoc($file_set))
891 $ret[$file_rec[
"id"]] = $file_rec[
"id"];
921 include_once(
"./Services/News/classes/class.ilNewsItem.php");
922 include_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
924 $news_item->setContext($this->
getId(), $this->
getType());
926 $news_item->setTitle($a_lang_var);
927 $news_item->setContentIsLangVar(
true);
930 $news_item->setContent(
934 $news_item->setUserId($ilUser->getId());
936 $news_item->create();
970 rename($a_upload_file,
$file);
981 $version_subdir =
"";
983 if (!is_numeric($a_version))
987 $version_subdir = DIRECTORY_SEPARATOR.sprintf(
"%03d", $a_version);
988 return $file_storage->getAbsolutePath().$version_subdir.DIRECTORY_SEPARATOR.$filename;
997 include_once
'./Modules/File/classes/class.ilObjFileAccess.php';
1000 if ($titleExtension != $fileExtension && strlen($fileExtension) > 0)
1004 $suffix = $pi[
"extension"];
1007 if (substr($new_title,
1008 strlen($new_title) - strlen($suffix) - 1)
1011 $new_title = substr($new_title, 0, strlen($new_title) - strlen($suffix) - 1);
1014 $new_title .=
'.'.$fileExtension;