$state->countrycode = $countrycode;
        $state->code = trim($data[0]);
        $state->var_name = $state->mod_write_check(trim($data[1]));
        $state->name = trim($data[1]);
        $save = $state->save();
    }
    fclose($file);
    $message = "<div class='success'>State codes loaded from " . $filename . " </div>";
    $session->message($message);
    redirect_to($_SERVER['PHP_SELF']);
}
//delete all the states from list
if (isset($_POST['deletestates'])) {
    global $db, $database;
    $state = new StateProvince();
    $state->delete_by_country($countrycode);
    /* We should remove the state definition from counties, cities and zips tables also for this country */
    $db->query("update " . TBL_COUNTIES . " set statecode='' where countrycode='{$countrycode}' ");
    $db->query("update " . TBL_CITY . " set statecode='' where countrycode='{$countrycode}' ");
    $message = "<div class='success'>State codes for #COUNTRY# are deleted </div>";
    $message = str_replace('#COUNTRY#', $countrycode, $message);
    /* Analyze the table to adjust index values */
    //$db->optimize_table( TBL_COUNTRY );
    $db->optimize_table(TBL_STATES);
    $db->optimize_table(TBL_COUNTIES);
    $db->optimize_table(TBL_CITY);
    $session->message($message);
    redirect_to($_SERVER['PHP_SELF']);
}
//get the states files
$files = array();