<?php
require_once '../iventitymatcherhtm/watchListUtils.php';
require_once '../iventitymatcherhtm/config.php';

require_once 'sqlUtils.php';
$mysqli = sqlCreateConnection("init_mainEng - $action");
ini_set('auto_detect_line_endings', TRUE);

$files_dir = $argv[1];//"C:\\xampp\\htdocs\\galgalanda\\iventitymatcherhtm\\tmp";

foreach(glob($files_dir.'/*.*') as $lst_name){
    // Store each row in this array
    if (($handle = fopen($lst_name, 'r')) === false) {
        die('Error opening file');
    }
    while ($row = fgetcsv($handle, 1024, ',')) {
        
        $json_data[] = json_encode($row);
        $content .= $row[0]."\n";
    }
    //     $content = json_encode($json_data, true);
    $base64_content = base64_encode($content);
    
    $file_name = basename($lst_name);
    echo "WORKING ON $file_name\n";
    $json = "[
    {
    \"fileData\": {
    \"name\": \"$file_name\",
    \"type\": \"application/vnd.ms-excel\"
},
\"content\": \"$base64_content\",
\"target\": \"merged_full_250k\"
}
]";
    $sent_data = json_decode($json, true);
    $WLclass = new WLUtilsClass($mysqli, $sent_data);
    $response = $WLclass->compareWLs();
}

