4 require_once
"Services/Object/classes/class.ilObject2.php";
5 include_once(
'Modules/File/classes/class.ilFSStorageFile.php');
39 $this->raise_upload_error =
true;
58 protected function doCreate($a_upload =
false, $a_prevent_meta_data_creation =
false)
79 $this->file_storage->create();
87 require_once(
"./Services/History/classes/class.ilHistory.php");
92 require_once(
"./Services/News/classes/class.ilNewsItem.php");
94 if ($default_visibility ==
"public")
97 1, 0, $this->
getId());
100 $q =
"INSERT INTO file_data (file_id,file_name,file_type,file_size,version,f_mode) "
101 .
"VALUES (".$ilDB->quote($this->
getId() ,
'integer').
","
104 .$ilDB->quote((
int) $this->
getFileSize() ,
'integer').
","
105 .$ilDB->quote(1 ,
'integer').
",".$ilDB->quote($this->
getMode() ,
'text').
")";
106 $res = $ilDB->manipulate($q);
109 if ($this->
getMode() !=
"filelist" && !$a_prevent_meta_data_creation)
123 $technical = $md_obj->addTechnical();
126 $format = $technical->addFormat();
129 $technical->update();
136 include_once
'Services/MetaData/classes/class.ilMD.php';
138 if(!is_object($md_gen = $md->getGeneral()))
143 $md_gen->setTitle(
$title);
151 include_once
'Services/MetaData/classes/class.ilMD.php';
159 if(!is_object($md_technical = $md->getTechnical()))
164 foreach($md_technical->getFormatIds() as
$id)
166 $md_format = $md_technical->getFormat(
$id);
180 $version_subdir =
"";
185 $version_subdir = sprintf(
"%03d", $a_version);
189 if(!is_object($this->file_storage))
194 return $this->file_storage->getAbsolutePath().
'/'.$version_subdir;
204 $this->raise_upload_error = $a_raise;
207 function getUploadFile($a_upload_file, $a_filename, $a_prevent_preview =
false)
223 if (!$a_prevent_preview)
236 require_once(
"./Services/History/classes/class.ilHistory.php");
240 $a_filename.
",".$this->getVersion()
242 $this->setFilename($a_filename);
254 require_once(
"./Services/History/classes/class.ilHistory.php");
258 $a_filename.
",".$this->getVersion()
260 $this->setFilename($a_filename);
271 function copy($a_source,$a_destination)
294 require_once(
"./Services/History/classes/class.ilHistory.php");
296 if ($a_hist_entry_ids == null || count($a_hist_entry_ids) < 1)
298 $ilDB->manipulate(
"UPDATE file_data SET version = 1 WHERE file_id = ".$ilDB->quote($this->getId() ,
'integer'));
308 $actualVersionDeleted =
false;
314 foreach ($a_hist_entry_ids as $hist_id)
319 foreach ($versions as $index => $version)
321 if ($version[
"hist_entry_id"] == $hist_id)
327 $version_dir = $this->
getDirectory($version[
"version"]);
331 if ($version[
"version"] == $this->
getVersion())
332 $actualVersionDeleted =
true;
335 unset($versions[$index]);
342 if ($actualVersionDeleted)
345 $version = reset($versions);
363 $q =
"SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($this->
getId() ,
'integer');
364 $r = $this->ilias->db->query($q);
380 if ($this->
getMode() !=
"filelist")
397 $q =
"UPDATE file_data SET file_name = ".$ilDB->quote($this->
getFileName() ,
'text').
398 ", file_type = ".$ilDB->quote($this->getFiletype() ,
'text').
" ".
399 ", file_size = ".$ilDB->quote((
int) $this->
getFileSize() ,
'integer').
" ".
400 ", version = ".$ilDB->quote($this->
getVersion() ,
'integer').
" ".
401 ", f_mode = ".$ilDB->quote($this->
getMode() ,
'text').
" ".
402 ", rating = ".$ilDB->quote($this->
hasRating() ,
'integer').
" ".
403 "WHERE file_id = ".$ilDB->quote($this->
getId() ,
'integer');
404 $res = $ilDB->manipulate($q);
418 if(!is_object($technical = $md_obj->getTechnical()))
420 $technical = $md_obj->addTechnical();
425 $format_ids = $technical->getFormatIds();
426 if (count($format_ids) > 0)
428 $format = $technical->getFormat($format_ids[0]);
434 $format = $technical->addFormat();
438 $technical->update();
446 $this->filename = $a_name;
459 $this->filetype = $a_type;
469 $this->filesize = $a_size;
474 return $this->filesize;
484 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
492 if (is_null($a_hist_entry_id))
498 require_once(
"./Services/History/classes/class.ilHistory.php");
501 if ($entry ===
false)
515 $this->version = $a_version;
520 return $this->version;
530 $this->mode = $a_mode;
547 $q =
"UPDATE file_data SET ".
548 " file_type = ".$ilDB->quote($a_format ,
'text').
549 " WHERE file_id = ".$ilDB->quote($a_id ,
'integer');
550 $res = $ilDB->manipulate($q);
558 $q =
"SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($a_id ,
'integer');
559 $r = $ilDB->query($q);
569 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
578 require_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
587 if (is_null($a_hist_entry_id))
593 require_once(
"./Services/History/classes/class.ilHistory.php");
596 if ($entry ===
false)
612 if (is_null($a_hist_entry_id))
617 if (@!is_file(
$file))
624 require_once(
"./Services/History/classes/class.ilHistory.php");
627 if ($entry ===
false)
629 echo
"3";
return false;
636 if (@!is_file(
$file))
647 global $ilClientIniFile;
650 if ($ilClientIniFile->readVariable(
'file_access',
'download_with_uploaded_filename') !=
'1' && is_null($a_hist_entry_id))
670 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
679 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
686 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
699 $path = pathinfo($a_file);
700 if (
$path[
"extension"] !=
"")
706 $filename =
"dummy.".$this->getFileExtension();
708 include_once(
"./Services/Utilities/classes/class.ilMimeTypeUtil.php");
763 $a_new_obj->createDirectory();
770 $query =
"INSERT INTO file_data (file_id,file_name,file_type,file_size,version,rating,f_mode) VALUES (".
771 $ilDB->quote($a_new_obj->getId() ,
'integer').
",".
772 $ilDB->quote($this->getFileName() ,
'text').
",".
773 $ilDB->quote($this->getFileType() ,
'text').
",".
774 $ilDB->quote((
int) $this->getFileSize() ,
'integer').
", ".
775 $ilDB->quote($this->getVersion() ,
'integer').
", ".
776 $ilDB->quote($this->hasRating() ,
'integer').
", ".
777 $ilDB->quote($this->getMode() ,
'text').
")";
778 $res = $ilDB->manipulate($query);
781 require_once(
"./Services/Preview/classes/class.ilPreview.php");
785 require_once(
"./Services/History/classes/class.ilHistory.php");
789 $a_new_obj->addNewsNotification(
"file_created");
800 if (count($usages) == 0)
812 $q =
"DELETE FROM file_data WHERE file_id = ".$ilDB->quote($this->
getId() ,
'integer');
813 $this->ilias->db->query($q);
816 require_once(
"./Services/History/classes/class.ilHistory.php");
826 if ($this->
getMode() !=
"filelist")
846 $subdir =
"il_".IL_INST_ID.
"_file_".$this->
getId();
851 if (@!is_dir($filedir))
866 $and_hist = ($a_usage_hist_nr !==
false)
867 ?
" AND usage_hist_nr = ".$ilDB->quote($a_usage_hist_nr,
"integer")
871 $set = $ilDB->query(
"SELECT id FROM file_usage".
872 " WHERE usage_type = ".$ilDB->quote($a_type,
"text").
873 " AND usage_id= ".$ilDB->quote($a_id,
"integer").
874 " AND usage_lang= ".$ilDB->quote($a_usage_lang,
"text").
876 while(
$row = $ilDB->fetchAssoc($set))
878 $file_ids[] =
$row[
"id"];
881 $ilDB->manipulate(
"DELETE FROM file_usage WHERE usage_type = ".
882 $ilDB->quote($a_type,
"text").
883 " AND usage_id = ".$ilDB->quote((
int) $a_id,
"integer").
884 " AND usage_lang= ".$ilDB->quote($a_usage_lang,
"text").
885 " AND usage_hist_nr = ".$ilDB->quote((
int) $a_usage_hist_nr,
"integer"));
887 foreach($file_ids as $file_id)
896 function _saveUsage($a_file_id, $a_type, $a_id, $a_usage_hist_nr = 0, $a_usage_lang =
"-")
900 $ilDB->manipulate(
"DELETE FROM file_usage WHERE usage_type = ".
901 $ilDB->quote((
string) $a_type,
"text").
902 " AND usage_id = ".$ilDB->quote((
int) $a_id,
"integer").
903 " AND usage_lang = ".$ilDB->quote($a_lang,
"text").
904 " AND usage_hist_nr = ".$ilDB->quote((
int) $a_usage_hist_nr,
"integer").
905 " AND id = ".$ilDB->quote((
int) $a_file_id,
"integer"));
907 $ilDB->manipulate(
"INSERT INTO file_usage (id, usage_type, usage_id, usage_hist_nr, usage_lang) VALUES".
908 " (".$ilDB->quote((
int) $a_file_id,
"integer").
",".
909 $ilDB->quote((
string) $a_type,
"text").
",".
910 $ilDB->quote((
int) $a_id,
"integer").
",".
911 $ilDB->quote((
int) $a_usage_hist_nr,
"integer").
",".
912 $ilDB->quote($a_usage_lang,
"text").
926 $q =
"SELECT * FROM file_usage WHERE id = ".$ilDB->quote($this->
getId(),
"integer");
927 $us_set = $ilDB->query($q);
929 while($us_rec = $ilDB->fetchAssoc($us_set))
931 $ret[] = array(
"type" => $us_rec[
"usage_type"],
932 "id" => $us_rec[
"usage_id"],
933 "lang" => $us_rec[
"usage_lang"],
934 "hist_nr" => $us_rec[
"usage_hist_nr"]);
953 $q =
"SELECT * FROM file_usage WHERE ".
954 "usage_id = ".$ilDB->quote((
int) $a_id,
"integer").
" AND ".
955 "usage_type = ".$ilDB->quote((
string) $a_type,
"text").
" AND ".
956 "usage_lang = ".$ilDB->quote((
string) $a_usage_lang,
"text").
" AND ".
957 "usage_hist_nr = ".$ilDB->quote((
int) $a_usage_hist_nr,
"integer");
958 $file_set = $ilDB->query($q);
960 while($file_rec = $ilDB->fetchAssoc($file_set))
962 $ret[$file_rec[
"id"]] = $file_rec[
"id"];
992 include_once(
"./Services/News/classes/class.ilNewsItem.php");
993 include_once(
"./Modules/File/classes/class.ilObjFileAccess.php");
995 $news_item->setContext($this->
getId(), $this->
getType());
997 $news_item->setTitle($a_lang_var);
998 $news_item->setContentIsLangVar(
true);
1001 $news_item->setContent(
1005 $news_item->setUserId($ilUser->getId());
1007 $news_item->create();
1041 rename($a_upload_file,
$file);
1055 $version_subdir =
"";
1057 if (!is_numeric($a_version))
1061 $version_subdir = DIRECTORY_SEPARATOR.sprintf(
"%03d", $a_version);
1062 return $file_storage->getAbsolutePath().$version_subdir.DIRECTORY_SEPARATOR.$filename;
1071 include_once
'./Modules/File/classes/class.ilObjFileAccess.php';
1074 if ($titleExtension != $fileExtension && strlen($fileExtension) > 0)
1078 $suffix = $pi[
"extension"];
1081 if (substr($new_title,
1082 strlen($new_title) - strlen($suffix) - 1)
1085 $new_title = substr($new_title, 0, strlen($new_title) - strlen($suffix) - 1);
1088 $new_title .=
'.'.$fileExtension;
1101 include_once(
"./Services/History/classes/class.ilHistory.php");
1104 if ($version_ids != null && count($version_ids) > 0)
1106 foreach ($versions as $index => $version)
1108 if (!in_array($version[
"hist_entry_id"], $version_ids,
true))
1110 unset($versions[$index]);
1116 foreach ($versions as $index => $version)
1119 $versions[$index] = array_merge($version, $params);
1123 usort($versions, array($this,
"compareVersions"));
1136 include_once(
"./Services/History/classes/class.ilHistory.php");
1138 if ($version ===
false)
1143 $version[
"hist_entry_id"] = $version[
"id"];
1144 $version[
"user_id"] = $version[
"usr_id"];
1145 $version[
"date"] = $version[
"hdate"];
1146 unset($version[
"id"], $version[
"usr_id"], $version[
"hdate"]);
1150 return array_merge($version, $params);
1164 if ($source ===
false)
1166 $this->ilErr->raiseError($this->lng->txt(
"obj_not_found"), $this->ilErr->MESSAGE);
1173 $source_path = $this->
getDirectory($source[
"version"]) .
"/" . $source[
"filename"];
1175 if (@!is_dir($dest_dir))
1178 copy($source_path, $dest_dir .
"/" . $source[
"filename"]);
1181 include_once(
"./Services/History/classes/class.ilHistory.php");
1185 $source[
"filename"] .
"," . $new_version_nr .
"|" . $source[
"version"] .
"|" . $ilUser->getId());
1198 return $new_version;
1237 return (
int)$v2[
"version"] - (int)$v1[
"version"];
1248 $data = preg_split(
"/(.*),(.*)/", $entry[
"info_params"], 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
1252 if (empty($data[1]))
1255 $result = array(
"filename" => $data[0],
"version" => $data[1],
"rollback_version" =>
"",
"rollback_user_id" =>
"");
1258 if ($entry[
"action"] ==
"rollback")
1260 $tokens = explode(
"|",
$result[
"version"]);
1261 if (count($tokens) > 1)
1263 $result[
"version"] = $tokens[0];
1264 $result[
"rollback_version"] = $tokens[1];
1266 if (count($tokens) > 2)
1267 $result[
"rollback_user_id"] = $tokens[2];
1276 include_once
"Services/MediaObjects/classes/class.ilObjMediaObject.php";
1280 $parent_obj_ids = array($a_file->
getId());
1284 $parent_obj_id = $mob->getParentObjectIdForUsage($item);
1285 if($parent_obj_id &&
1286 !in_array($parent_obj_id, $parent_obj_ids))
1288 $parent_obj_ids[]= $parent_obj_id;
1292 include_once
"Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
1307 if ($this->
getMode() !=
"object")
1310 require_once(
"./Services/Preview/classes/class.ilPreview.php");
1320 if ($this->
getMode() !=
"object")
1323 require_once(
"./Services/Preview/classes/class.ilPreview.php");
1329 $this->rating = (bool)$a_value;