<?php

/******************************************************************************
 *
 *	PROJECT: Flynax Classifieds Software
 *	VERSION: 4.X
 *	LICENSE: FL0M2SG681CQ - http://www.flynax.com/license-agreement.html
 *	PRODUCT: Pets Classifieds
 *	DOMAIN: pupsnshop.com
 *	FILE: IMPORT.PHP
 *
 *	The software is a commercial product delivered under single, non-exclusive, 
 *	non-transferable license for one domain or IP address. Therefore distribution, 
 *	sale or transfer of the file in whole or in part without permission of Flynax 
 *	respective owners is considered to be illegal and breach of Flynax License End 
 *	User Agreement. 
 *
 *	You are not allowed to remove this information from the file without permission
 *	of Flynax respective owners.
 *
 *	Flynax Classifieds Software 2014 |  All copyrights reserved. 
 *
 *	http://www.flynax.com/
 *
 ******************************************************************************/

set_time_limit(0);

/* system config */
require_once( '../../includes/config.inc.php' );
session_start();
	
require_once( RL_CLASSES . 'rlDb.class.php' );
require_once( RL_CLASSES . 'reefless.class.php' );

$rlDb = new rlDb();
$reefless = new reefless();

/* load classes */
$reefless -> connect(RL_DBHOST, RL_DBPORT, RL_DBUSER, RL_DBPASS, RL_DBNAME);
$reefless -> loadClass('Debug');
$reefless -> loadClass('Config');

$config = $rlConfig -> allConfig();

$reefless -> loadClass('Cache');
$reefless -> loadClass('Valid');
$reefless -> loadClass('Hook');
$reefless -> loadClass('Lang');
$reefless -> loadClass('Actions');
$reefless -> loadClass('ListingTypes', null, false, true);

$limit = $_SESSION['iel_data']['post']['import_per_run'];
$start = (int)$_GET['index'];

$account_info = $_SESSION['account'];

/* exit if user not logged in */
$reefless -> loadClass( 'Account' );
if ( !$rlAccount -> isLogin() )
	exit;

/* prepare available listings */
foreach ($_SESSION['iel_data']['post']['rows_tmp'] as $index => $val)
{
	$available_rows[] = $index;
}

$reefless -> loadClass('ExportImport', null, 'export_import');
$rlExportImport -> import(
	$_SESSION['iel_data']['post']['data'],
	$available_rows,
	$_SESSION['iel_data']['post']['cols'],
	$_SESSION['iel_data']['post']['field'],
	$start,
	$limit,
	$_SESSION['iel_data']['post']['import_listing_type'],
	$_SESSION['iel_data']['post']['import_category_id'],
	$account_info['ID'],
	$_SESSION['iel_data']['post']['import_plan_id'],
	false,
	$_SESSION['iel_data']['post']['import_status'],
	true
);

$items['from'] = $start + $limit;
$items['to'] = $start + ($limit * 2) - 1;
$items['count'] = count($available_rows);

echo $rlJson ->  encode($items);