<?php
// Version: 2.0; FileManager

// Show the file index
function template_index()
{
	global $context, $txt, $files, $settings;
	
	echo '
		<table border="0" align="center" cellspacing="1" cellpadding="4" class="bordercolor" width="100%">
			<tr>
				<td colspan="5" class="titlebg">
					', $txt[139], ': ', $context['pageIndex'], '
				</td>
			</tr>
			<tr class="catbg">
				<td width="75"></td>
				<td width="15"></td>
				<td>', $txt['filemanager']['filename'], '</td>
				<td width="150">', $txt['filemanager']['size'], '</td>
				<td width="250">', $txt['filemanager']['date'], '</td>
			</tr>';
	
	// List the files!	
	foreach ($files as $key => $data)
	{
	  	echo '
			<tr class="windowbg">
				<td align="right">
					', isset($data['edit_href']) ? '<a href="' . $data['edit_href'] . '"><img src="' . $settings['images_url'] . '/edit.gif" alt="' . $txt['filemanager']['edit'] . '" /></a>' : '', '
					', isset($data['rename_href']) ? '<a href="' . $data['rename_href'] . '"><img src="' . $settings['images_url'] . '/rename.gif" alt="' . $txt['filemanager']['rename'] . '" /></a>' : '', '
					', isset($data['chmod_href']) ? '<a href="' . $data['chmod_href'] . '"><img src="' . $settings['images_url'] . '/chmod.gif" alt="' . $txt['filemanager']['chmod'] . '" /></a>' : '', '
					', isset($data['delete_href']) ? '<a href="' . $data['delete_href'] . '"><img src="' . $settings['images_url'] . '/delete.gif" alt="' . $txt['filemanager']['delete'] . '" /></a>' : '', '
				</td>
				<td align="center"><img src="', $settings['images_url'], '/', $data['icon'], '.gif" alt="', $data['icon'], '" /></td>
				<td><a href="', $data['href'], '">', $data['name'], '</a></td>
				<td>', $data['size'], '</td>
				<td>', $data['modified'], '</td>
			</tr>';
	}
	
	echo '
			<tr>
				<td colspan="5" class="titlebg">
					', $txt[139], ': ', $context['pageIndex'], '
				</td>
			</tr>
		</table>';
}

// Delete something. Now things get messy. :P
function template_delete()
{
	global $context, $return, $txt, $scripturl;

	echo '
		<table border="0" align="center" cellspacing="1" cellpadding="4" class="bordercolor" width="100%">
			<tr>
				<td class="titlebg">
					', (isset($_REQUEST['file']) ? $txt['filemanager']['deletefiletitle'] : $txt['filemanager']['deletefoldertitle']), '
				</td>
			</tr>
			<tr class="windowbg">
				<td>';
				
	if (isset($_REQUEST['sure']))
		 echo $return;
	else
	{
		echo '
					<form action="', $scripturl, '?action=filemanager;sa=delete;', (isset($_REQUEST['file']) ? 'file=' . $_REQUEST['file'] : 'folder=' . $_REQUEST['folder']), '" method="post">
						<p>', sprintf($txt['filemanager']['deletewarning'], (isset($_REQUEST['file']) ? $_REQUEST['file'] : $_REQUEST['folder'])), '</p>
						<p>', $txt['filemanager']['deleteareyousure'], '</p>
						<p><input type="submit" name="sure" value="', $txt['filemanager']['deleteyesiam'], '" /></p>
						<input type="hidden" name="sc" value="', $context['session_id'], '" />
					</form>';
	}
		
	echo '
				</td>
			</tr>
		</table>';
}
	
// CHMOD a file or folder
function template_chmod()
{
	global $context, $txt, $return, $scripturl;

	echo '
		<table border="0" align="center" cellspacing="1" cellpadding="4" class="bordercolor" width="100%">
			<tr>
				<td class="titlebg">
					', $txt['filemanager']['chmodtitle'], '
				</td>
			</tr>
			<tr class="windowbg">
				<td>';
				
	if (isset($_REQUEST['newperms']))
		 echo $return;
	else
	{
		echo '
					<form action="', $scripturl, '?action=filemanager;sa=chmod;', (isset($_REQUEST['file']) ? 'file=' . $_REQUEST['file'] : 'folder=' . $_REQUEST['folder']), '" method="post">
						<p>', sprintf($txt['filemanager']['chmodintro'], (isset($_REQUEST['file']) ? $_REQUEST['file'] : $_REQUEST['folder'])), '</p>
						<input type="hidden" name="what" file="', (isset($_REQUEST['file']) ? $_REQUEST['file'] : $_REQUEST['folder']), '" />
						<p>', $txt['filemanager']['chmodnewperms']. '<input type="text" size="3" maxlength="3" name="newperms" /></p>
						<p><input type="submit" value="', $txt['filemanager']['chmodapply'], '" /></p>
						<input type="hidden" name="sc" value="', $context['session_id'], '" />
					</form>';
	}
		
	echo '
				</td>
			</tr>
		</table>';
}

// Rename a file or folder
function template_rename()
{
	global $context, $return, $txt, $boarddir, $scripturl, $boarddir;
	
	echo '
		<table border="0" align="center" cellspacing="1" cellpadding="4" class="bordercolor" width="100%">
			<tr>
				<td class="titlebg">
					', $txt['filemanager']['renametitle'], '
				</td>
			</tr>
			<tr class="windowbg">
				<td>';

	// Is there anything renamed yet?				
	if (isset($return))
		echo $return;
	// No? Then let's show the form.
	else
	{
		echo '
					<form action="', $scripturl, '?action=filemanager;sa=rename;file=', $_REQUEST['file'], '" method="post">
						<p><strong>', $txt['filemanager']['renameoriginal'], '</strong> ', $boarddir, '/', (!empty($_REQUEST['file']) ? $_REQUEST['file'] : '').' <input type="hidden" name="oldname" value="', $boarddir, '/', (!empty($_REQUEST['file']) ? $_REQUEST['file'] : ''), '" /><br />
						<strong>', $txt['filemanager']['renamenew'], '</strong> <input type="text" name="newname" size="70" value="'. $boarddir, '/', (!empty($_REQUEST['file']) ? $_REQUEST['file'] : ''), '" /></p>
						<p><input type="submit" value="', $txt['filemanager']['renamesubmit'], '" /></p>
						<input type="hidden" name="sc" value="', $context['session_id'], '" />
					</form>';
	}
		
	echo '
				</td>
			</tr>
		</table>';
}

// Create a new folder
function template_newfolder()
{
	global $context, $return, $txt, $folder, $boarddir, $scripturl;
	
	echo '
		<table border="0" align="center" cellspacing="1" cellpadding="4" class="bordercolor" width="100%">
			<tr>
				<td class="titlebg">
					', $txt['filemanager']['newfoldertitle'], '
				</td>
			</tr>
			<tr class="windowbg">
				<td>';

	// Is there anything created yet?				
	if (isset($return))
		echo $return;
	// No? Then let's show the form.
	else
	{
		echo '
					<p>', $txt['filemanager']['desiredname'], $boarddir, '/', (!empty($folder) ? $folder . '/' : ''), '</p>
					<form action="', $scripturl, '?action=filemanager;sa=newfolder', (isset($folder) ? ';folder=' . $folder : ''), '" method="post">
						<p><strong>', $txt['filemanager']['foldername'], '</strong> <input type="text" name="foldername" size="40" /><br />
						<p><input type="submit" value="', $txt['filemanager']['foldersubmit'], '" /></p>
						<input type="hidden" name="sc" value="', $context['session_id'], '" />
					</form>';
	}
		
	echo '
				</td>
			</tr>
		</table>';
}

// Edit a file
function template_edit()
{
	global $context, $return, $txt, $writable, $file, $scripturl, $contents;
	
	echo '
		<table border="0" align="center" cellspacing="1" cellpadding="4" class="bordercolor" width="100%">
			<tr>
				<td class="titlebg">
					', $txt['filemanager']['edittitle'], '
				</td>
			</tr>
			<tr class="windowbg">
				<td>';

	// Is there anything done yet?
	if (isset($return))
		echo $return;
	// No? Then let's show the form.
	else
	{
		echo '
					<form action="', $scripturl, '?action=filemanager;sa=edit;file=', $_REQUEST['file'], '" method="post">
						<p>', $writable ? sprintf($txt['filemanager']['editcontents'], $file) : sprintf($txt['filemanager']['viewcontents'], $file), '</p>
						<p><textarea name="content" cols="60" rows="20" class="editor" style="font: 12px Courier New">', $contents, '</textarea></p>
						<p><input type="submit" value="', $txt['filemanager']['editsubmit'], '" /></p>
						<input type="hidden" name="sc" value="', $context['session_id'], '" />
					</form>';
	}
		
	echo '
				</td>
			</tr>
		</table>';
}
	
// Upload a file
function template_uploadfile()
{
	global $context, $scripturl, $boarddir, $folder, $txt, $return;
	
	echo '
		<table border="0" align="center" cellspacing="1" cellpadding="4" class="bordercolor" width="100%">
			<tr>
				<td class="titlebg">
					', $txt['filemanager']['uploadfiletitle'], '
				</td>
			</tr>
			<tr class="windowbg">
				<td>';

	// Is there anything uploaded yet?				
	if (isset($return))
		echo $return;

	// No? Then let's show the form, shall we?
	else
		echo '
					<p>', $txt['filemanager']['selectfile'], $boarddir, '/', (!empty($folder) ? $folder . '/' : ''), '</p>
					<form enctype="multipart/form-data" action="', $scripturl, '?action=filemanager;sa=uploadfile', (isset($folder) ? ';folder=' . $folder : ''), '" method="post">
						<p><strong>', $txt['filemanager']['choosefile'], '</strong> <input type="file" name="uploadfile" size="40" /><br />
						<strong>', $txt['filemanager']['changefilename'], '</strong> <input type="text" name="newname" size="40" /></p>
						<p><input type="submit" value="', $txt['filemanager']['uploadsubmit'], '" /></p>
						<input type="hidden" name="sc" value="', $context['session_id'], '" />
					</form>';
	
	echo '
				</td>
			</tr>
		</table>';
}

// This is a pretty useless function in this case, but it still has to be defined...
function template_filemanager_above()
{
}

// Copyright notice. Please leave it intact!
function template_filemanager_below()
{
	echo '
		<p class="smalltext" align="right">SMF File Manager v2.1 by <a href="http://www.aaronweb.net/">A&auml;ron van Geffen</a>, July 2008';
}
?>