<?php
/**
 * ICEcat loading page
 *
 * @package 	CSVIVirtueMart
 * @subpackage 	Cron
 * @author 		Roland Dalmulder
 * @link 		http://www.csvimproved.com
 * @copyright 	Copyright (C) 2006 - 2012 RolandD Cyber Produksi
 * @license 	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 * @version 	$Id: icecat.php 1551 2011-03-16 08:51:20Z RolandD $
 */
 
defined( '_JEXEC' ) or die( 'Direct Access to this location is not allowed.' );
?>
<form method="post" action="index.php" name="adminForm">
	<table class="adminlist" id="progresstable" style="width: 45%;">
		<thead>
		<tr><th colspan="2" style="white-space:nowrap;"><?php echo JText::_('COM_CSVIVIRTUEMART_MAINTENANCE_AVAILABLEFIELDS'); ?></th></tr>
		</thead>
		<tfoot>
			<tr>
				<td colspan="2">
					<div id="progressbar"></div>
				</td>
			</tr>
		</tfoot>
		<tbody>
			<tr><td><?php echo JText::_('COM_CSVIVIRTUEMART_TABLES_PROCESSED'); ?></td><td><div id="status"></div></td></tr>
			<tr><td colspan="2"><img id="spinner" src='<?php echo JURI::root(); ?>/administrator/components/com_csvivirtuemart/assets/images/csvivirtuemart_ajax-loading.gif' /></td></tr>
		</tbody>
	</table> 
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="option" value="com_csvivirtuemart" />
	<input type="hidden" name="view" value="maintenance" />
</form>
<script type="text/javascript">
jQuery(function() {
	loadIndex();
});

// Start the import
function loadIndex() {
	jQuery.ajax({
		async: true,
		url: 'index.php',
		dataType: 'json',
		data: 'option=com_csvivirtuemart&view=maintenance&task=updateavailablefieldssingle&format=json',
		success: function(data) {
			if (data) {
				if (data.process == true) {
					jQuery('#status').append(data.table+'<br />');
					loadIndex();
				}
				else {
					window.location = data.url;
				}
			}
		},
		failure: function(data) {
			jQuery('#spinner').remove();
			jQuery('#status').html('<?php echo JText::_('COM_CSVIVIRTUEMART_ERROR_PROCESSING_RECORDS'); ?>'+data.responseText);
		},
		error: function(data) {
			jQuery('#spinner').remove();
			jQuery('#status').html('<?php echo JText::_('COM_CSVIVIRTUEMART_ERROR_PROCESSING_RECORDS'); ?>'+data.responseText);
		}
	});
}
</script>