<?php

/*
    @   74027
*/

$result_search_field = sql_fetch_assoc(sql_query("SELECT TABLE_NAME FROM information_schema.columns WHERE TABLE_SCHEMA='".$config['dbname']."' AND COLUMN_NAME='sub_type_field'"));
if ($result_search_field) {
    run_query('ALTER TABLE '. $config['table_prefix'] .'fields DROP sub_type_field');
}

run_query("DELETE FROM ".$config['table_prefix']."fields WHERE type_field=11 AND 
(name_field='Кто изменил' OR name_field='Who changed') OR type_field=12 AND (name_field='Когда изменил' OR name_field='When changed')");

$result = run_query('SELECT id FROM '. $config['table_prefix'] .'tables GROUP BY id ORDER BY id');
while ($row = sql_fetch_assoc($result)) {
    $result_search_who_changed = sql_fetch_assoc(sql_query("SELECT TABLE_NAME FROM information_schema.columns WHERE TABLE_SCHEMA='".$config['dbname']."' 
    AND TABLE_NAME='". $config['table_prefix'] . "data" . $row['id']."' AND COLUMN_NAME='who_changed'"));
    if ($result_search_who_changed) {
        run_query("ALTER TABLE ". $config['table_prefix'] . "data" . $row['id'] ." DROP who_changed");
    }

    $result_search_when_changed = sql_fetch_assoc(sql_query("SELECT TABLE_NAME FROM information_schema.columns WHERE TABLE_SCHEMA='".$config['dbname']."' 
    AND TABLE_NAME='". $config['table_prefix'] . "data" . $row['id']."' AND COLUMN_NAME='when_changed'"));
    if ($result_search_when_changed) {
        run_query("ALTER TABLE ". $config['table_prefix'] . "data" . $row['id'] ." DROP when_changed");
    }
}
