<?php
	//Standardzeug
	if ( !defined('IN_MFA') )
		die("Hacking attempt");
	$user->DieNotValid();
	if(!IsSet($_GET['object']) || !file_exists(ROOT_DIR."/".$user->user_root_dir.$_GET['object']))
		message_die("Invalid Object","Invalid Object","Error");
		
	$display = new file_info($user->user_root_dir.$_GET['object']);
	$layouthistoryargs = array();
	
	
	$layouthistoryargs['back'] = "<a href='index.php?dir=".$_GET['dir']."'>".$lang['back']."</a>";

	//file_data
	$finfo = lstat(ROOT_DIR."/".$display->file_path);
	
	if(function_exists('posix_getpwuid'))
	{
		$fowner = posix_getpwuid($finfo['uid']);
		$fowner = ($fowner['name'] != "")?$fowner['name']:"nobody" ;
		$fgroup = posix_getgrgid($finfo['gid']);
		$fgroup = ($fgroup['name'] != "")?$fgroup['name']:"nobody" ;
	}
	else
	{
		$fowner = "n/a";
		$fgroup = "n/a";
	}
	$layouthistoryargs['confirm'] = "";
	
	$layouthistoryargs['lang_general_user_info'] = $lang['general_user_info'];
	$layouthistoryargs['realpath'] = ROOT_DIR."/".$display->file_path;
	$layouthistoryargs['chmod'] = decoct($display->getchmod());
	$layouthistoryargs['fowner'] = $fowner;
	$layouthistoryargs['fgroup'] = $fgroup;
	
	//file history
	//reset history
	if(IsSet($_GET['resethistory']))
	{
		if(!IsSet($_GET['confirm']))
		{
			$layouthistoryargs['confirm'] .="<span class='error'>".$lang['sure']."</span> <br>";
			$layouthistoryargs['confirm'] .="<a href='index.php?mode=file_info&amp;dir=".$verzname."&amp;object=".$_GET['object']."&amp;resethistory=on&amp;confirm=on'>".$lang['yes']."</a>&nbsp;|&nbsp;<a href='index.php?mode=file_info&amp;dir=".$verzname."&amp;object=".$_GET['object']."'>".$lang['no']."</a><br>";
		}
		else
		{
			$to_delete = new file(SCRIPT_PATH."/work/data/finfo_".md5($display->file_path).".php");
			$to_delete->delete();
			$display = new file_info($user->user_root_dir.$_GET['object']);
		}
	}
	
	$layouthistoryargs['lang_file_history'] = $lang['file_history'];
	$layouthistoryargs['reset_history_href'] = "index.php?mode=file_info&amp;dir=".$verzname."&amp;object=".$_GET['object']."&amp;resethistory=on";
	$layouthistoryargs['file_history'] = "";

	foreach($display->file_info as $info_item)
	{
		$info_item = explode("##,##",$info_item);
		$layouthistoryargs['file_history'] .= "<div>(".$users[$info_item[1]].",".$info_item[0]."):&nbsp;".$info_item[2]."</div>";
	}
	//file_comments
	
	//reset comments
	if(IsSet($_GET['resetcomments']))
	{
		if(!IsSet($_GET['confirm']))
		{
			$layouthistoryargs['confirm'] .="<span class='error'>".$lang['sure']."</span> <br>";
			$layouthistoryargs['confirm'] .="<a href='index.php?mode=file_info&amp;dir=".$verzname."&amp;object=".$_GET['object']."&amp;resetcomments=on&amp;confirm=on'>".$lang['yes']."</a>&nbsp;|&nbsp;<a href='index.php?mode=file_info&amp;dir=".$verzname."&amp;object=".$_GET['object']."'>".$lang['no']."</a><br>";
		}
		else
		{
			$to_delete = new file(SCRIPT_PATH."/work/data/fcomments_".md5($display->file_path).".php");
			$to_delete->delete();
			$display = new file_info($user->user_root_dir.$_GET['object']);
		}
	}
	//addcomment
	if(IsSet($_POST['addcomment']))
	{
		if($_POST['comment_title'] == "")
			$title = "no title";
		else
			$title = $_POST['comment_title'];
		
		$display->add_comment($title,$_POST['comment_text']);	
		$display = new file_info($user->user_root_dir.$_GET['object']);
	}
	
	
	$layouthistoryargs['lang_comments'] = $lang['comments'];
	$layouthistoryargs['reset_comments_href'] = "index.php?mode=file_info&amp;dir=".$verzname."&amp;object=".$_GET['object']."&amp;resetcomments=on";
	$layouthistoryargs['lang_reset'] = $lang['reset'];
	
	if(count($display->file_comments) == 0)
		$layouthistoryargs['comments'] = "<div class='error'>".$lang['no_comments']."</div>";
	foreach($display->file_comments as $comment)
	{
		$comment_data = explode("##,##",$comment);
		$layouthistoryargs['comments'] .= "<div><b>".$comment_data[0]."</b>(".$users[$comment_data[1]].", ".date("d.m.Y H:i",$comment_data[2]).")</div>";
		$layouthistoryargs['comments'] .= "<div class='hr' style='text-align:left;margin:5px'>".nl2br($comment_data[3])."</div>";
	}
	$layouthistoryargs['lang_add_comment'] = $lang['add_comment'];
	$layouthistoryargs['formargs'] = "index.php?mode=file_info&amp;dir=".$verzname."&amp;object=".$_GET['object'];
	$layouthistoryargs['lang_title'] = $lang['title'];

	$show_after_header .= $template->layoutparser("file_history",$layouthistoryargs);
	unset($layouthistoryargs);
?>