<?php
/**
 * Добавляем таблицы для модуля IP-телефонии Asterisk
 * Created by: Andrey
 * Release: 14.07.2014
 * App Version: 2.0.3
 * Copyright: Clientbase (www.clientbase.ru)
 */

run_query("CREATE TABLE IF NOT EXISTS " . $config['table_prefix'] . "module_asterisk_servers (id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
                                                                                        name VARCHAR(255) NOT NULL,
                                                                                        server VARCHAR(255) NOT NULL,
                                                                                        sip_account VARCHAR(255) NOT NULL,
                                                                                        hello_audio TEXT NOT NULL,
                                                                                        city_code int NOT NULL,
                                                                                        inter_code int NOT NULL,
                                                                                        from_city_code int NOT NULL,
                                                                                        to_city_code int NOT NULL,
                                                                                        max_phone_numbers int NOT NULL);");
run_query("CREATE TABLE IF NOT EXISTS " . $config['table_prefix'] . "module_asterisk_users   (id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
                                                                                        server_id int NOT NULL,
                                                                                        user_id int NOT NULL,
                                                                                        login VARCHAR(255) NOT NULL,
                                                                                        password VARCHAR(255) NOT NULL,
                                                                                        from_browser int NOT NULL);");


/**
 * Добавляем поля в пользователей для модуля IP-телефонии Asterisk
 * Created by: Andrey
 * Release: 14.07.2014
 * App Version: 2.0.3
 * Copyright: Clientbase (www.clientbase.ru)
 */

$res = run_query("SHOW COLUMNS FROM " . $config['table_prefix'] . "users LIKE 'asterisk_login'");
if (!sql_num_rows($res)) {
    run_query("ALTER TABLE " . $config['table_prefix'] . "users ADD asterisk_login VARCHAR(255) NOT NULL");
}

$res = run_query("SHOW COLUMNS FROM " . $config['table_prefix'] . "users LIKE 'asterisk_password'");
if (!sql_num_rows($res)) {
    run_query("ALTER TABLE " . $config['table_prefix'] . "users ADD asterisk_password VARCHAR(255) NOT NULL");
}

/**
 * Добавляем модуль IP-телефонии Asterisk
 * Created by: Andrey
 * Release: 14.07.2014
 * App Version: 2.0.3
 * Copyright: Clientbase (www.clientbase.ru)
 */

$res = run_query("SELECT id FROM " . $config['table_prefix'] . "modules WHERE name='asterisk'");
if (!sql_num_rows($res)) {
    run_query("INSERT INTO " . $config['table_prefix'] . "modules (name, version, status) VALUES ('asterisk', '1.0', '0')");
}
?>