<?php
/**
* @package Mambo Open Source
* @subpackage Installer
* @copyright (C) 2005 - 2006 Mambo Foundation Inc.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*
* Mambo was originally developed by Miro (www.miro.com.au) in 2000. Miro assigned the copyright in Mambo to The Mambo Foundation in 2005 to ensure
* that Mambo remained free Open Source software owned and managed by the community.
* Mambo is Free Software
*/ 

/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

function writableCell( $folder ) {
	echo '<tr>';
	echo '<td class="item">' . $folder . '/</td>';
	echo '<td align="left">';
	echo is_writable( $GLOBALS['mosConfig_absolute_path'] . '/' . $folder ) ? '<b><span class="green">'.T_('Writeable').'</span></b>' : '<b><span class="red">'.T_('Unwriteable').'</span></b>' . '</td>';
	echo '</tr>';
}

/**
* @package Mambo
*/
class HTML_installer {
	
	function showInstallForm( $title, $option, $element, $client = "", $p_startdir = "", $backLink="" ) {
		?>
		<script language="javascript" type="text/javascript">
		function submitbutton3(pressbutton) {
			var form = document.adminForm_dir;
	
			// do field validation
			if (form.userfile.value == ""){
				alert( "<?php echo T_('Please select a directory') ?>" );
			} else {
				form.submit();
			}
		}
		</script>
		<form enctype="multipart/form-data" action="index2.php" method="post" name="filename">
		<table class="adminheading">
		<tr>
			<th class="install">
			<?php echo $title;?>
			</th>
			<td align="right" nowrap="true">
			<?php echo $backLink;?>
			</td>
		</tr>
		</table>
		
		<table class="adminform">
		<tr>
			<th>
			<?php echo T_('Upload Package File') ?>
			</th>
		</tr>
		<tr>
			<td align="left">
			<?php echo T_('Package File:')?>
			<input class="text_area" name="userfile" type="file" size="70"/>
			<input class="button" type="submit" value="<?php echo T_('Upload File &amp; Install')?>" />
			</td>
		</tr>
		</table>
		
		<input type="hidden" name="task" value="uploadfile"/>
		<input type="hidden" name="option" value="<?php echo $option;?>"/>
		<input type="hidden" name="element" value="<?php echo $element;?>"/>
		<input type="hidden" name="client" value="<?php echo $client;?>"/>
		</form>
		<br />

		<?php
		if (ini_get('allow_url_fopen')) HTML_installer::showUrlForm('http://', $option, $element, $client);
		?>
		
		<form action="index2.php" method="post" name="adminForm_dir">
		<table class="adminform">
		<tr>
			<th>
			<?php echo T_('Install from directory')?>
			</th>
		</tr>
		<tr>
			<td align="left">
			<?php echo T_('Install directory:')?>&nbsp;
			<input type="text" name="userfile" class="text_area" size="65" value="<?php echo $p_startdir; ?>"/>&nbsp;
			<input type="button" class="button" value="<?php echo T_('Install')?>" onclick="submitbutton3()" />
			</td>
		</tr>
		</table>
		
		<input type="hidden" name="task" value="installfromdir" />
		<input type="hidden" name="option" value="<?php echo $option;?>"/>
		<input type="hidden" name="element" value="<?php echo $element;?>"/>
		<input type="hidden" name="client" value="<?php echo $client;?>"/>
		</form>
		<br />
		<?php
	}
	
	function showUrlForm ($prompt, $option, $element, $client) {
		?>
		<form action="index2.php" method="post" name="adminForm_url">
		<table class="adminform">
		<tr>
			<th>
			<?php echo T_('Install from HTTP URL')?>
			</th>
		</tr>
		<tr>
			<td align="left">
			<?php echo T_('Install HTTP URL:')?>&nbsp;
			<input type="text" name="userurl" class="text_area" size="65" value="<?php echo $prompt; ?>" />&nbsp;
			<input type="submit" class="button" value="<?php echo T_('Upload URL &amp; Install')?>" />
			</td>
		</tr>
		</table>

		<input type="hidden" name="task" value="installfromurl" />
		<input type="hidden" name="option" value="<?php echo $option;?>"/>
		<input type="hidden" name="element" value="<?php echo $element;?>"/>
		<input type="hidden" name="client" value="<?php echo $client;?>"/>
		</form>
		<br />
		<?php
	}
	
	function theSourceForm ($option, $element, $client) {
	    HTML_installer::showUrlForm('', $option, $element, $client);
	    echo '<object type="text/html" data="http://source.mambo-foundation.org/component/syndstyle/option,com_remository/" width="500" height="1000">'
	        .T_('Sorry, it seems that The Source is not available').'</object>';
	}
	
	/**
	* @param string
	* @param string
	* @param string
	* @param string
	*/
	function showInstallMessage ($messages, $title, $return) {
		global $PHP_SELF;
		if (!$return) $return = mamboCore::get('mosConfig_live_site').'/administrator/index2.php';
		?>
		<table class="adminheading">
		<tr>
			<th class="install">
			<?php echo $title; ?>
			</th>
		</tr>
		</table>
		
		<table class="adminform">
		<?php
		if (!is_array($messages)) $messages = array($messages);
		foreach ($messages as $message) {
			switch ($message->level) {
				case _MOS_ERROR_INFORM:
				$colour = 'green';
				$level = 'Information: ';
				break;
				case _MOS_ERROR_WARN:
				$colour = 'red';
				$level = 'Warning: ';
				break;
				case _MOS_ERROR_SEVERE:
				$colour = 'red';
				$level = 'Severe: ';
				break;
				case _MOS_ERROR_FATAL:
				$colour = 'red';
				$level = 'Fatal: ';
				break;
			}
			?>
			<tr>
				<td align="left">
				<span class="<?php echo $colour; ?>"><strong><?php echo $level.$message->text; ?></strong></span>
				</td>
		</tr>
		<?php
		}
		?>
		<tr>
			<td colspan="2" align="center">
			[&nbsp;<a href="<?php echo $return;?>" style="font-size: 16px; font-weight: bold"><?php echo T_('Continue ...')?></a>&nbsp;]
			</td>
		</tr>
		</table>
		<?php
	}
}
?>
