<?php
class file_info extends file
{
	var $file_info = array();
	var $file_comments = array();
	
	function file_info($file_path)
	{
			$this->file_path = $file_path;
			if(file_exists(ROOT_DIR."/".$this->file_path))
			{
				$this->file_name = basename($this->file_path);
				$this->file_size = filesize(ROOT_DIR."/".$this->file_path);
				$this->lastchange = filemtime(ROOT_DIR."/".$this->file_path);
				$path_info = @pathinfo(ROOT_DIR."/".$this->file_path);
				$this->extension = $path_info["extension"];
			}
			if(file_exists(ROOT_DIR."/".SCRIPT_PATH."/work/data/finfo_".md5($this->file_path).".php"))
			{
				$finfo = new file(SCRIPT_PATH."/work/data/finfo_".md5($this->file_path).".php");
				$fcontent = $finfo->getContent();
				$this->file_info = explode("##;##",$fcontent);
				//nur die Pfadangabe
				unset($this->file_info[0]);		
			}
			if(file_exists(ROOT_DIR."/".SCRIPT_PATH."/work/data/fcomments_".md5($this->file_path).".php"))
			{
				$finfo = new file(SCRIPT_PATH."/work/data/fcomments_".md5($this->file_path).".php");
				$fcontent = $finfo->getContent();
				$this->file_comments = explode("##;##",$fcontent);
				unset($this->file_comments[0]);	
			}
	}	
	function add_action($action_msg)
	{
		global $user;
		if(!file_exists(ROOT_DIR."/".SCRIPT_PATH."/work/data/finfo_".md5($this->file_path).".php"))
		{
			//temporäre Datei erstellen
			$tmpfile = create_tmpfile();
			$tmpfile = new file(SCRIPT_PATH."/".$tmpfile);
			//die an den richtigen Art verschieben
			$tmpfile->move_to(SCRIPT_PATH."/work/data/finfo_".md5($this->file_path).".php");
			$tmpfile->delete();
		}
		
		$info_file = new file(SCRIPT_PATH."/work/data/finfo_".md5($this->file_path).".php");
		if(!$info_file->open("w")) return false;
		//Alles alte löschen
		fwrite($info_file->file_resource,$this->file_path."##;##");
		//$salt = array($action
		$this->file_info[] = date("d.m.Y H:i")."##,##".$user->user_id."##,##".$action_msg;
		fwrite($info_file->file_resource,implode("##;##",$this->file_info));
		$info_file->close();
		
		return true;
	}
	function add_comment($title,$msg)
	{
		global $user;
		if(!file_exists(ROOT_DIR."/".SCRIPT_PATH."/work/data/fcomments_".md5($this->file_path).".php"))
		{
			//temporäre Datei erstellen
			$tmpfile = create_tmpfile();
			$tmpfile = new file(SCRIPT_PATH."/".$tmpfile);
			//die an den richtigen Art verschieben
			$tmpfile->move_to(SCRIPT_PATH."/work/data/fcomments_".md5($this->file_path).".php");
			$tmpfile->delete();
		}
		
		$info_file = new file(SCRIPT_PATH."/work/data/fcomments_".md5($this->file_path).".php");
		if(!$info_file->open("w")) return false;
		//Alles alte löschen
		fwrite($info_file->file_resource,$this->file_path."##;##");
		$this->file_comments[] = $title."##,##".$user->user_id."##,##".time()."##,##".$msg;
		fwrite($info_file->file_resource,implode("##;##",$this->file_comments));
		$info_file->close();
		
		return true;
	}
}
?>