<?php

include("_dirinfo.php");
include (PATH_TO_ROOT."init.php");

$db->ChangeDatabase(DB_WARPIT_USERSPOOL);
if ($_FILES['uploadLink']['tmp_name']) {
	
	$id_incentive_group = $_POST['id_incentive_group'];
	
	$content = file_get_contents($_FILES['uploadLink']['tmp_name']);
    
    $lines = preg_split ('/$\R?^/m', $content);
    
    foreach($lines as $line)
    {
        $explodeLine = explode(',', trim($line));
        if(count($explodeLine) == 4)
        {
            
           $values[] = "(" .$id_incentive_group . ",'" . mysql_real_escape_string($explodeLine[0]) . "', '" . mysql_real_escape_string($explodeLine[1]) . "', " . intval($explodeLine[2]) . ", " . intval($explodeLine[3]) . ", NOW())"; 
        }
    }
	$sql = "INSERT IGNORE INTO _IncentiveCoupons (id_incentive_group,incentive_code,client_incentive_id,incentive_points, value_of_coupon, startTime) VALUES ".implode(',',$values);
    print "/*" . $sql ."*/";
	$db->SQLexecute($sql);
	
	echo "{success: true}";
	exit;
}
echo "{success: false}";
?>