<?php

/**************************************************************
* This file is part of Remository
* Copyright (c) 2006 Martin Brampton
* Issued as open source under GNU/GPL
* For support and other information, visit http://remository.com
* To contact Martin Brampton, write to martin@remository.com
*
* Remository started life as the psx-dude script by psx-dude@psx-dude.net
* It was enhanced by Matt Smith up to version 2.10
* Since then development has been primarily by Martin Brampton,
* with contributions from other people gratefully accepted
*/

class remositoryErrorDisplaysHTML extends remositoryUserHTML {
	
	function noaccess ($file=null) {
		$file->showCMSPathway();
		$container = is_object($file) ? $file->getContainer() : null;
		$this->pathwayHTML($container);
		echo <<<NO_ACCESS
		
		<h2>{$this->show(_DOWN_ACCESS_REFUSED)}</h2>
		<p>
			{$this->show(_DOWN_MAYBE_LOGIN)}
		</p>
		
NO_ACCESS;

		$this->filesFooterHTML ();
		$this->remositoryCredits(false);
	}
	
	function uploadLimit () {
		echo <<<UPLOAD_LIMIT
		
		<script type="text/javascript">alert('{$this->show(_ERR9)}')</script>
		{$this->pathwayHTML(null)}
		<br/>&nbsp;<br/>{$this->show(_DOWN_ALL_DONE)}
		
UPLOAD_LIMIT;

	}

	public function noFileDiagnostics ($user) {
		$heading = _DOWN_NO_FILE_RECEIVED;
		$error = isset($_FILES['userfile']['error']) ? $_FILES['userfile']['error'] : 'No error message';
		$filename = isset($_FILES['userfile']['name']) ? $_FILES['userfile']['name'] : 'No file name provided';
		$filesize = isset($_FILES['userfile']['size']) ? $_FILES['userfile']['size'] : 'No file size provided';
		$tempfile = isset($_FILES['userfile']['tmp_name']) ? $_FILES['userfile']['tmp_name'] : 'No file path provided';
		$isuploaded = isset($_FILES['userfile']['tmp_name']) ? is_uploaded_file($tempfile) : 'No file path provided';
		if ($user->isAdmin()) echo <<<DIAGNOSE_UPLOAD
		
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<th colspan="2" align="left">
					$heading
				</th>
			</tr>
			<tr>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td width="30%" align="right">
					<strong>Error message: </strong>
				</td>
				<td>
					$error
				</td>
			</tr>
			<tr>
				<td width="30%" align="right">
					<strong>Real file name: </strong>
				</td>
				<td>
					$filename
				</td>
			</tr>
			<tr>
				<td width="30%" align="right">
					<strong>File size (bytes): </strong>
				</td>
				<td>
					$filesize
				</td>
			</tr>
			<tr>
				<td width="30%" align="right">
					<strong>Temporary file path: </strong>
				</td>
				<td>
					$tempfile
				</td>
			</tr>
			<tr>
				<td width="30%" align="right">
					<strong>Is it an uploaded file?: </strong>
				</td>
				<td>
					$isuploaded
				</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td width="30%" align="right">
					<strong>PHP file_uploads: </strong>
				</td>
				<td>
					{$this->showPHP('file_uploads')}
				</td>
			</tr>
			<tr>
				<td width="30%" align="right">
					<strong>PHP upload_tmp_dir: </strong>
				</td>
				<td>
					{$this->showPHP('upload_tmp_dir')}
				</td>
			</tr>
			<tr>
				<td width="30%" align="right">
					<strong>PHP upload_max_filesize: </strong>
				</td>
				<td>
					{$this->showPHP('upload_max_filesize')}
				</td>
			</tr>
			<tr>
				<td width="30%" align="right">
					<strong>PHP post_max_size: </strong>
				</td>
				<td>
					{$this->showPHP('post_max_size')}
				</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td colspan="2" align="left">
					<p>Points to watch out for are: <ul>
					<li>There should be no error message (typically, zero will be displayed)</li>
					<li>The real file name should correspond with the name of the file you sent</li>
					<li>The file size should be the correct size for the file you sent</li>
					<li>Temporary file path should look like a genuine specification for a file on the host system.  Its
					precise character will vary across different systems.  It should be a valid path including the name of
					the temporary file. If it is not overriden by the PHP config (see below) the temporary path will be
					the system temporary directory with file name added. The file name is generated by the system.</li>
					<li>If PHP is permitting file uploads, the file_uploads setting will be non zero.</li>
					<li>There may be no temporary upload directory specified in the PHP config.
					In this case, the system temporary directory will be used.
					For a Unix style system, this defaults to /tmp but can be configured to be
					anything. If the file path is specified, you would expect it to form part of the temporary file
					path shown above, followed by the temporary name.  A temporary upload directory specified to PHP will
					override the system temporary directory.</li>
					<li>PHP will have a setting for the maximum permitted uploaded file size.</li>
					<li>PHP also has a setting for the maximmum POST size, and the file upload is a POST
					so the setting must be at least a little larger than the maximum permitted upload
					size, or it will be a constraint on uploads.</li>
					</ul><br/>
					Note that the PHP settings cannot be overriden by a program like Remository.  If they
					are too restrictive, you need to talk to your hosting provider, or consider altering
					your PHP configuration if it is under your own control.
					</p>
				</td>
			</tr>
		</table>
	
DIAGNOSE_UPLOAD;
		
		else $this->uploadError($heading);
	}
	
	private function showPHP ($inivalue) {
		return ini_get($inivalue);
	}
	
	private function uploadError ($message) {
		echo <<<SIMPLE_ERROR
		
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<th colspan="2" align="left">
					$message
				</th>
			</tr>
		</table>
		
SIMPLE_ERROR;
		
	}
}