<?php
//User soll das ROOT-Verzeichnis nicht verlassen
if((strstr($verzname, "..")) || ($_GET['dir'] == "..")) die("<p class='error'>".$lang['not_this_dir']."</p>");
if(strstr($verzname, "//")) die("<p class='error'>".$lang['not_this_dir']."</p>");

$filelistargs['parent_dir'] = find_parent_dir($verzname);
$filelistargs['verzname'] = $verzname;
$filelistargs['newlink'] = "<a href='index.php?dir=".$verzname."&amp;mode=new'><img src='template/".$template->layoutname."/images/menu/new.gif' title='".$lang['newfile']."' border='0'></a>";
$filelistargs['pastelink'] ="<a href='index.php?mode=paste&amp;dir=".$verzname."'><img src='template/".$template->layoutname."/images/menu/paste.gif' title='".$lang['paste']."' border='0'></a>";
$filelistargs['uploadlink'] = ($user->has_right("upload"))?"&nbsp;<a href='index.php?mode=upload&amp;dir=".$verzname."'><img src='template/".$template->layoutname."/images/menu/upload.gif' title='".$lang['upload']."' border='0'></a>":"";	
$filelistargs['htaccesslink'] = ($user->isAdmin())?"&nbsp;<a href='index.php?mode=htaccess&amp;dir=".$verzname."'><img src='template/".$template->layoutname."/images/menu/htaccess.gif' title='".$lang['htaccess']."' border='0'></a>&nbsp;":"";
	
$filelistargs['defaultoption'] = "<option value='default'>".$lang['selected'].":";
$filelistargs['copyoption'] = "<option value='copy'>".$lang['copy'];	
$filelistargs['deloption'] = ($user->has_right("delete"))? "<option value='delete'>".$lang['delete']:"";
$filelistargs['lockoption'] = "<option value='lock_file'>".$lang['lock'];


//select all files of that directorie
$dh = opendir( ROOT_DIR."/".$user->user_root_dir.$verzname ) or die("<p class='error'>There is an error in the general configuration. Please open the Admin-Control-Panel -> general configruation and check the inputs!</p>");
$directories = array();
$files = array();
while ( gettype($file = readdir( $dh )) != "boolean")
{
	if(($file != ".") && ($file != "..")) 
	{
		//seperate directories and files
		if(is_dir(ROOT_DIR."/".$user->user_root_dir.$verzname."/".$file))
			$directories[] = $verzname."".$file;
		else
		{
			$display = new file($user->user_root_dir.$verzname."".$file);
			$files[] = array("name" => $display->file_name ,"path" => $display->file_path, "size" => $display->file_size, "lr" => $display->lastchange);
			$totalsize = $totalsize + $display->file_size;
		}
	} 
}
@closedir($dh);
$totalsize = sprintf("%.2f",$totalsize / 1024);


$filelistargs['fsize'] = $lang['size'].": ".$totalsize;
$filelistargs['stat'] = $lang['stat'];

//sotr order
$sortby = (IsSet($_GET['sortby'])) ? $_GET['sortby'] : "name";
$sort_order= (IsSet($_GET['sort_order'])) ? $_GET['sort_order'] : "asc";

$filelistargs['name_sort'] = "<a href='index.php?dir=".$verzname."&amp;sortby=name&amp;sort_order=".(($sortby == "name" && $sort_order == "asc")? "desc": "asc")."'>".$lang['file_name']."</a>";
if($sortby == "name")	$filelistargs['name_sort'] .= "<img src='".(($sort_order == "asc")? "template/".$template->layoutname."/images/up.gif":"template/".$template->layoutname."/images/down.gif")."'>";

$filelistargs['size_sort'] = "<a href='index.php?dir=".$verzname."&amp;sortby=size&amp;sort_order=".(($sortby == "size" && $sort_order == "asc")? "desc": "asc")."'>".$lang['size']."</a>"; 
if($sortby == "size")	$filelistargs['size_sort'] .= "<img src='".(($sort_order == "asc")? "template/".$template->layoutname."/images/up.gif":"template/".$template->layoutname."/images/down.gif")."'>";

$filelistargs['lreq_sort'] = "<a href='index.php?dir=".$verzname."&amp;sortby=lr&amp;sort_order=".(($sortby == "lr" && $sort_order == "asc")? "desc": "asc")."'>".$lang['last_request']."</a>"; 
if($sortby == "lr")	$filelistargs['lreq_sort'] .= "<img src='".(($sort_order == "asc")? "template/".$template->layoutname."/images/up.gif":"template/".$template->layoutname."/images/down.gif")."'>";

$filelistargs['operation'] = $lang['operation'];

$colored = false;
//sortieren der Verzeichnisse
if($sort_order == "desc" && $sortby == "name")
	rsort($directories);
else
	sort($directories);	

$i = 0;
$filelistargs['dirlist'] = array();
foreach($directories as $directory)
{
	$dirlineargs['color'] = ($colored)? " class='darkrow'": "";
	$dirlineargs['tr_colored'] = ($colored)?"true":"false";
	$colored = ($colored)? false: true;
	$file_name = find_file_name($directory);
	
	
	$dirlineargs['linktype'] = "small";
	$dirlineargs['linktitle'] = "";
	$dirlineargs['fsymbol'] = "template/".$template->layoutname."/images/folder_explorer.gif";
	$dirlineargs['filename'] = $file_name;
	$dirlineargs['filelink'] = "index.php?dir=".$directory."/&amp;open=".$directory."/";
	$dirlineargs['filesize'] = "----";
	$dirlineargs['last_request'] = "----";
	$dirlineargs['renamelink'] = "<a href='index.php?dir=".$verzname."&amp;mode=rename&amp;object=".$directory."'><img src='template/".$template->layoutname."/images/menu/rename.gif' ALT='logo' title='".$lang['rename']."' border='0'></a>&nbsp;&nbsp;";
	$dirlineargs['deletelink'] = ($user->has_right("delete"))? "<a href='index.php?dir=".$verzname."&amp;mode=delete&amp;object=".$directory."'><img src='template/".$template->layoutname."/images/menu/drop.gif' ALT='logo' title='".$lang['delete']."' border='0'></a>":"";
	$dirlineargs['linktarget'] = "";
	$dirlineargs['editlink'] = "";
	$dirlineargs['viewlink'] = "";
	$dirlineargs['downloadlink'] = "";
	$dirlineargs['locklink'] = "";
	$dirlineargs['checkbox'] = "";
	$dirlineargs['infolink'] = "";
	$dirlineargs['tr_id'] = "dir_".$i;
	$filelistargs['dirlist'][] = $dirlineargs;
	$i++;
}
unset($dirlineargs);


$filelistargs['numfiles'] = count($files);

$sort_order = ($sort_order == "asc")? SORT_ASC: SORT_DESC;
//DATEIEN ausgeben
$sorting = array();
foreach($files as $file)
	$sorting[] = $file[$sortby];
	
array_multisort($sorting,$sort_order,$files);

$filelistargs['filelist'] = array();
$i = 0;
foreach($files as $file)
{	
	$display = new file($file['path']);
	$working_user = is_locked($display->file_path);
	if(gettype($working_user) != "boolean")
		$working_user = $users[$working_user];
	$last_request= date("D d.n.Y G:i", $display->lastchange);

	if($display->file_path == SCRIPT_PATH."/config.php") continue;
  $filelineargs['color'] = ($colored)? " class='darkrow'": "";
	$filelineargs['tr_colored'] = ($colored)?"true":"false";
	$colored = ($colored)? false: true;
	//Prüfen ob Datei bearbeitet werden darf
	$allowed_to_change = (gettype($working_user) == "boolean")? true : (($working_user == $user->user_name)? true: false);
	
	
	$filelineargs['fsymbol'] = $display->symbol();
	$filelineargs['linktype'] = (!$working_user)? "small":"locked";
	$filelineargs['filelink'] = HOST_NAME."/".$display->file_path;
	$filelineargs['linktitle'] = (gettype($working_user) != "boolean")? "title='wird von ".$working_user." bearbeitet'":"";
	$filelineargs['linktarget'] = "target='_blank'";
	$filelineargs['filesize'] = sprintf("%.2f",$display->file_size / 1024);
	$filelineargs['filename'] = $display->file_name;
	$filelineargs['last_request'] = $last_request;
	
	$filelineargs['renamelink'] = ($allowed_to_change)?"<a href='index.php?dir=".$verzname."&amp;mode=rename&amp;object=".$verzname."".$display->file_name."'><img src='template/".$template->layoutname."/images/menu/rename.gif' ALT='logo' title='".$lang['rename']."' border='0'></a>&nbsp;&nbsp;":"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	$filelineargs['deletelink'] = ($user->has_right("delete") && $allowed_to_change)? "<a href='index.php?dir=".$verzname."&amp;mode=delete&amp;object=".$verzname."".$display->file_name."'><img src='template/".$template->layoutname."/images/menu/drop.gif' ALT='logo' title='".$lang['delete']."' border='0'></a>":"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	$filelineargs['editlink'] = ($user->has_right("edit")&& !$display->readonly()&&$allowed_to_change)? "<a href='index.php?dir=".$verzname."&amp;mode=edit&amp;object=".$verzname."".$display->file_name."'><img src='template/".$template->layoutname."/images/menu/edit.gif' ALT='logo' title='".$lang['edit']."' border='0'></a>":"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	$filelineargs['viewlink'] = ($user->has_right("view")&& !$display->readonly())?"&nbsp;<a href='index.php?dir=".$verzname."&amp;mode=view&amp;object=".$verzname."".$display->file_name."'><img src='template/".$template->layoutname."/images/menu/view.gif' ALT='logo' title='".$lang['view']."' border='0'></a>":"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	$filelineargs['downloadlink'] =($user->has_right("view"))? "&nbsp;<a href='index.php?dir=".$verzname."&amp;mode=download&amp;filename=".$verzname."".$display->file_name."'><img src='template/".$template->layoutname."/images/down.gif' ALT='logo' title='Download' border='0'></a>":"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	$filelineargs['locklink'] = ($allowed_to_change)?"&nbsp;<a href='index.php?dir=".$verzname."&amp;mode=lock_file&amp;object=".$verzname."".$display->file_name."'><img src='template/".$template->layoutname."/images/menu/lock.gif' ALT='logo' title='".$lang['working_mode']."' border='0'></a>":"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	$filelineargs['infolink'] = "<a href='index.php?dir=".$verzname."&amp;mode=file_info&amp;object=".$verzname."".$display->file_name."'><img src='template/".$template->layoutname."/images/redo.gif' ALT='logo' title='".$lang['file_history']."' border='0'></a>";
	$filelineargs['checkbox'] = "<input type='checkbox' id='check_".$i."' name='fileselect".$i."' value='".$verzname."".$display->file_name."'></input>";
	$filelineargs['tr_id'] = $i;
	$i++;
	
	$filelistargs['filelist'][] = $filelineargs;
}
unset($filelineargs);
echo $template->layoutparser("filelist",$filelistargs);
?>