<?php
include('config.php');
include('countrycodes.php');
include('header.php');


date_default_timezone_set('Asia/Jakarta');

define('GX_PATH', realpath(__DIR__.'/'));
define('GX_LIB', GX_PATH.'/lib/');

require 'autoload.php';
$page = 'import';

new Db();

if( isset($_POST['uploadcsv'])) {
    $tmpName = $_FILES['csv']['tmp_name'];
    $csvAsArray = array_map('str_getcsv', file($tmpName));
    // unset($csvAsArray[0]);
    // print_r($csvAsArray);

    foreach($csvAsArray as $k => $v) {
        if( $v[7] == 0) {
            // echo $v[0];
            Db::insert(array(
                'table' => 'lead_report',
                'key' => array(
                    'date' => $v[1],
                    'click_id' => $v[4],
                    'token_1' => $v[4],
                    'token_2' => $v[4],
                    'payout' => $v[6],
                    'country' => $v[5],
                    'os' => '',
                    'traffic_type' => 'WAP',
                    'connection_type' => '',
                    'carrier' => '',
                    'currency_symbol' => '$'
                ))
            );
        }
    }
}
echo "<div class='container'>
<form method='post' enctype='multipart/form-data'>
<div class='form-group'>
    <input type='file' name='csv' class='form-control'>
</div>
<div class='form-group'>
    <input type='submit' name='uploadcsv' class='btn btn-success' value='Upload'>
</div>
</form></div>";

include('footer.php');