<?php global $wpdb; ?>

<div class="wrap">
	<h2><?php echo __( 'Import', 'realia' ); ?></h2>

	<?php if ( ! empty( $_SESSION['import_status'] ) ) : ?>
		<div class="updated">
			<?php foreach ( $_SESSION['import_status'] as $status ) : ?>
				<p><?php echo esc_attr( $status ); ?></p>
			<?php endforeach; ?>
		</div><!-- /.updated -->

		<?php unset( $_SESSION['import_status'] ); ?>
	<?php endif; ?>

	<?php if ( ! empty( $_SESSION['import_messages'] ) ) : ?>
		<div class="error">
			<?php foreach ( $_SESSION['import_messages'] as $message ) : ?>
				<p><?php echo esc_attr( $message ); ?></p>
			<?php endforeach; ?>
		</div><!-- /.error -->

		<?php unset( $_SESSION['import_messages'] ); ?>
	<?php endif; ?>

	<p><?php echo __( 'Before importing the properties please consider following notices', 'realia' ) ; ?>:</p>

	<ol>
		<li><?php echo __( 'Import is working only for properties.', 'realia' ); ?></li>
		<li><?php echo __( 'You can import only image paths, not image data.', 'realia' ); ?></li>
		<li><?php echo __( 'If you rename or add new fields, you need the change import logic too.', 'realia' ); ?></li>
		<li><?php echo __( 'Don\'t upload large files. If you decide to import thousands of properties per once, change the values below in your php.ini.', 'realia' ); ?></li>
	</ol>

	<form method="post" action="" enctype="multipart/form-data" class="import-wrapper">
		<input type="file" name="file">
		<button type="submit" name="import-form"><?php echo __( 'Import', 'realia' ); ?></button>
	</form>

	<table class="table">
		<thead>
			<tr>
				<th colspan="2">
					<?php echo __( 'Environment Variables', 'realia' ); ?>
				</th>
			</tr>
		</thead>

		<tbody>
			<tr>
				<td class="width33"><?php echo __( 'Memory limit', 'realia'); ?>:</td>
				<td><strong><?php echo ini_get( 'memory_limit' ); ?></strong></td>
			</tr>
			<tr>
				<td class="width33"><?php echo __( 'Max execution time', 'realia'); ?>:</td>
				<td><strong><?php echo ini_get( 'max_execution_time' ); ?> <?php echo __( 'seconds', 'realia' ); ?></strong></td>
			</tr>
			<tr>				
				<td class="width33"><?php echo __( 'Upload max filesize', 'realia'); ?>:</td>
				<td><strong><?php echo ini_get(	'upload_max_filesize' ); ?></strong></td>
			</tr>
		</tbody>
	</table>


	<table class="table">
		<thead>
			<tr>
				<th><?php echo __( 'Index', 'realia' ); ?></th>
				<th><?php echo __( 'Name', 'realia' ); ?></th>
				<th><?php echo __( 'Database table', 'realia' ); ?></th>
				<th><?php echo __( 'Database column', 'realia' ); ?></th>
				<th><?php echo __( 'Extra', 'realia' ); ?></th>				
			</tr>
		</thead>

		<tbody>
			<tr>
				<td class="no-wrap center min-width">0</td>
				<td><?php echo __( 'Title', 'realia' ); ?></td>
				<td><?php echo esc_attr( $wpdb->prefix ); ?>posts</td>
				<td>post_title</td>
				<td class="width33"></td>
			</tr>

			<tr>
				<td class="no-wrap center min-width">1</td>
				<td><?php echo __( 'Content', 'realia' ); ?></td>
				<td><?php echo esc_attr( $wpdb->prefix ); ?>posts</td>
				<td>post_content</td>
				<td class="width33"></td>
			</tr>			

			<tr>
				<td class="no-wrap center min-width">2</td>
				<td><?php echo __( 'Image', 'realia' ); ?></td>
				<td><?php echo esc_attr( $wpdb->prefix ); ?>posts, <?php echo esc_attr( $wpdb->prefix ); ?>postmenta</td>
				<td>-</td>
				<td class="width33"><?php echo __( 'HTTP path to a file. Example of correct path: http://example.com/wp-uploads/2015/02/01.jpg.', 'realia' ); ?></td>
			</tr>			

			<tr>
				<td class="no-wrap center min-width">3</td>
				<td><?php echo __( 'Locations', 'realia' ); ?></td>
				<td><?php echo esc_attr( $wpdb->prefix ); ?>terms</td>
				<td>slug</td>
				<td class="width33"><?php echo __( 'Provide term name. After that term name is converted to slug and created if not exists otherwise is used term with same slug.', 'realia' ); ?></td>
			</tr>						

			<tr>
				<td class="no-wrap center min-width">4</td>
				<td><?php echo __( 'Types', 'realia' ); ?></td>
				<td><?php echo esc_attr( $wpdb->prefix ); ?>terms</td>
				<td>slug</td>
				<td class="width33"><?php echo __( 'Provide term name. After that term name is converted to slug and created if not exists otherwise is used term with same slug.', 'realia' ); ?></td>
			</tr>

			<tr>
				<td class="no-wrap center min-width">5</td>
				<td><?php echo __( 'Contracts', 'realia' ); ?></td>
				<td><?php echo esc_attr( $wpdb->prefix ); ?>terms</td>
				<td>slug</td>
				<td class="width33"><?php echo __( 'Provide term name. After that term name is converted to slug and created if not exists otherwise is used term with same slug.', 'realia' ); ?></td>
			</tr>

			<tr>
				<td class="no-wrap center min-width">6</td>
				<td><?php echo __( 'Amenities', 'realia' ); ?></td>
				<td><?php echo esc_attr( $wpdb->prefix ); ?>terms</td>
				<td>slug</td>
				<td class="width33"><?php echo __( 'Provide term name. After that term name is converted to slug and created if not exists otherwise is used term with same slug.', 'realia' ); ?>.</td>
			</tr>

			<tr>
				<td class="no-wrap center min-width">7</td>
				<td><?php echo __( 'ID', 'realia' ); ?></td>
				<td><?php echo esc_attr( $wpdb->prefix ); ?>postmeta</td>
				<td>meta_value</td>
				<td class="width33">property_id key</td>
			</tr>

			<tr>
				<td class="no-wrap center min-width">8</td>
				<td><?php echo __( 'Latitude', 'realia' ); ?></td>
				<td><?php echo esc_attr( $wpdb->prefix ); ?>postmeta</td>
				<td>meta_value</td>
				<td class="width33">property_location_latitude key</td>
			</tr>

			<tr>
				<td class="no-wrap center min-width">9</td>
				<td><?php echo __( 'Longitude', 'realia' ); ?></td>
				<td><?php echo esc_attr( $wpdb->prefix ); ?>postmeta</td>
				<td>meta_value</td>
				<td class="width33">property_location_longitude key</td>
			</tr>

			<tr>
				<td class="no-wrap center min-width">10</td>
				<td><?php echo __( 'Price', 'realia' ); ?></td>
				<td><?php echo esc_attr( $wpdb->prefix ); ?>postmeta</td>
				<td>meta_value</td>
				<td class="width33">property_price key</td>
			</tr>			

			<tr>
				<td class="no-wrap center min-width">11</td>
				<td><?php echo __( 'Baths', 'realia' ); ?></td>
				<td><?php echo esc_attr( $wpdb->prefix ); ?>postmeta</td>
				<td>meta_value</td>
				<td class="width33">property_attributes_baths key</td>
			</tr>						

			<tr>
				<td class="no-wrap center min-width">12</td>
				<td><?php echo __( 'Beds', 'realia' ); ?></td>
				<td><?php echo esc_attr( $wpdb->prefix ); ?>postmeta</td>
				<td>meta_value</td>
				<td class="width33">property_attributes_beds key</td>
			</tr>									

			<tr>
				<td class="no-wrap center min-width">13</td>
				<td><?php echo __( 'Garages', 'realia' ); ?></td>
				<td><?php echo esc_attr( $wpdb->prefix ); ?>postmeta</td>
				<td>meta_value</td>
				<td class="width33">property_attributes_garages key</td>
			</tr>	

			<tr>
				<td class="no-wrap center min-width">14</td>
				<td><?php echo __( 'Area', 'realia' ); ?></td>
				<td><?php echo esc_attr( $wpdb->prefix ); ?>postmeta</td>
				<td>meta_value</td>
				<td class="width33">property_attributes_area key</td>
			</tr>															

			<tr>
				<td class="no-wrap center min-width">15</td>
				<td><?php echo __( 'Gallery', 'realia' ); ?></td>
				<td><?php echo esc_attr( $wpdb->prefix ); ?>postmeta</td>
				<td>meta_value</td>
				<td class="width33">property_gallery key. <?php echo __( 'Space is separator so don\'t use spaces in filenames. Use HTTP path to a file. Example of correct path: http://example.com/wp-uploads/2015/02/01.jpg.', 'realia' ); ?></td>
			</tr>																		
		</tbody>
	</table>
</div><!-- /.wrap -->