$i = 0;
while (($data[] = fgetcsv($fp, 1000, $separator)) !== FALSE) {
    $i++;
}
fclose($fp);
if ($data[0][0] === 'groups_id') {
    $gid_col = 0;
    $gname_col = 1;
} else {
    $gname_col = 0;
    $gid_col = 1;
}
for ($t = 1; $t < $i; $t++) {
    $gid = $data[$t][$gid_col];
    $gname = $data[$t][$gname_col];
    verwerk($gid, $gname);
}
function verwerk($id, $naam)
{
    if ($id != 0) {
        // checken of klantengroep bestaat (op id))
        $id_query = tep_db_query("select groups_id from " . TABLE_GROUPS . " where groups_id = '" . $id . "'");
        $row = mysql_fetch_array($id_query);
        if ($row != '') {
            update($id, $naam);
        } else {
            echo "Fout! Id " . $id . " bestaat niet!";
        }
    } else {
        maak($naam);
    }
$i = 0;
while (($data[] = fgetcsv($fp, 1000, $separator)) !== FALSE) {
    $i++;
}
fclose($fp);
if ($data[0][0] === 'products_id') {
    $id_col = 0;
    $quant_col = 1;
} else {
    $quant_col = 0;
    $id_col = 1;
}
for ($t = 1; $t < $i; $t++) {
    $id = $data[$t][$id_col];
    $quant = $data[$t][$quant_col];
    verwerk($id, $quant);
}
function verwerk($id, $quant)
{
    // checken of product-id bestaat
    $id_query = tep_db_query("select * from " . TABLE_PRODUCTS . " where products_id = " . $id);
    $row = mysql_fetch_array($id_query);
    if ($row != '') {
        update($id, $quant);
    }
}
function update($id, $quant)
{
    tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = " . $quant . " where products_id = " . $id);
}
require DIR_WS_INCLUDES . 'application_bottom.php';