<?php
if ($config['type'] == 'SAAS') {
    $result = sql_select($config["table_prefix"] . "module_asterisk_sips");
    if (!sql_num_rows($result)) {
        $result = sql_select_field($config["table_prefix"] . "module_asterisk_servers", "record_table", "id=1");
        $row = sql_fetch_assoc($result);
        if ($table_id = $row['record_table']) {
            sql_query("DROP TABLE IF EXISTS " . $config["table_prefix"] . "data" . $table_id);
            sql_delete($config["table_prefix"] . "tables", 'id=', $table_id);
            sql_delete($config["table_prefix"] . "acc_tables", 'table_id=', $table_id);
            sql_delete($config["table_prefix"] . "acc_tables_par", 'table_id=', $table_id);
            sql_delete($config["table_prefix"] . "fields", 'table_id=', $table_id);
            sql_delete($config["table_prefix"] . "acc_fields", 'table_id=', $table_id);
            sql_delete($config["table_prefix"] . "acc_tables_par", 'table_id=', $table_id);
            sql_delete($config["table_prefix"] . "subtables", 'link_table_id=', $table_id);
            sql_delete($config["table_prefix"] . "buttons", 'table_id=', $table_id);
            $result = sql_select($config["table_prefix"] . "calc", "name='Привязка телефона к Записи разговоров'");
            while ($calc = sql_fetch_assoc($result)) {
                sql_delete($config["table_prefix"] . "calc", 'id=', $calc['id']);
                sql_delete($config["table_prefix"] . "calc_cond", 'calc_id=', $calc['id']);
            }
        }
        sql_delete($config["table_prefix"] . "module_asterisk_log");
        sql_delete($config["table_prefix"] . "module_asterisk_servers");
        sql_delete($config["table_prefix"] . "module_asterisk_sips");
        sql_delete($config["table_prefix"] . "module_asterisk_tables");
        sql_delete($config["table_prefix"] . "module_asterisk_users");
    }
}
?>