<?php
// Fetch hosted server details from the Database
$global_option = $wpdb->get_results( 'SELECT gc_option, gc_value FROM ow_global_configuration' );
$globalArray = [];

foreach ( $global_option as $row ) {
	
	$globalArray[$row->gc_option] = $row->gc_value;
}
$ow_global_variables = $globalArray;

// CONNECT TO  IRIS DATABASE
// Check the hosted server and assign database credentials
if (array_key_exists('hosted_in', $ow_global_variables)) {
    if ($ow_global_variables['hosted_in'] == SERVER_1) {
        define("DB_HOST_IRIS", SERVER_1);
        define("DB_NAME_IRIS", "accweb_dbv4");
        define("DB_NAME_IRIS_OLD", "accweb_db");
        define("DB_USER_IRIS", "accweb_site");
        define("DB_PASSWORD_IRIS", "!MySqlP!*35");
    } else if ($ow_global_variables['hosted_in'] == SERVER_2) {
        define("DB_HOST_IRIS", SERVER_2);
        define("DB_NAME_IRIS", "iriswebportalliv_dbv4");
        define("DB_NAME_IRIS_OLD", "iriswebportalliv_db");
        define("DB_USER_IRIS", "iriswebportalliv_site");
        define("DB_PASSWORD_IRIS", "ZKg0HFIBD\$sk");
    } else {
        define("DB_HOST_IRIS", SERVER_2);
        define("DB_NAME_IRIS", "iriswebportalliv_dbv4");
        define("DB_NAME_IRIS_OLD", "iriswebportalliv_db");
        define("DB_USER_IRIS", "iriswebportalliv_site");
        define("DB_PASSWORD_IRIS", "ZKg0HFIBD\$sk");
    }
} else {
    define("DB_HOST_IRIS", SERVER_2);
    define("DB_NAME_IRIS", "iriswebportalliv_dbv4");
    define("DB_NAME_IRIS_OLD", "iriswebportalliv_db");
    define("DB_USER_IRIS", "iriswebportalliv_site");
    define("DB_PASSWORD_IRIS", "ZKg0HFIBD\$sk");
}

// IRIS DATABSE GLOBAL VARIABLE
$iris_db = new wpdb( DB_USER_IRIS, DB_PASSWORD_IRIS, DB_NAME_IRIS, DB_HOST_IRIS );
$iris_db_old = new wpdb( DB_USER_IRIS, DB_PASSWORD_IRIS, DB_NAME_IRIS_OLD, DB_HOST_IRIS );

const PRODUCT_NAME = 'IRIS WebPortal';
const PRODUCT_WEBSITE = 'https://iriswebportal.co.uk';

const PACKAGE_1 = 'Essentials';
const PACKAGE_2 = 'Select';
const PACKAGE_3 = 'Professional';
const PACKAGE_4 = 'Signature';
const PACKAGE_5 = 'Template Standard';
const PACKAGE_6 = 'Template Advanced';
const PACKAGE_7 = 'Bespoke Standard';
const PACKAGE_8 = 'Bespoke Advanced';

// SUPPORT DETAILS
const OW_SUPPORT_PHONE = '0845 544 0182';
const OW_SUPPORT_EMAIL = 'support@irisopenwebsite.co.uk';
const OW_SUPPORT_RESPONSE_TIME = 48; # HOURS

const OW_ADMIN_EMAIL = 'ow.admin@iris.co.uk';
define( 'OW_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); 

// FILE INCLUDES

// DEVELOPER CONSOLE
include OW_PLUGIN_PATH . 'developer-console/index.php';

// FUNCTION FILE
include OW_PLUGIN_PATH . 'functions.php';

// ADMIN AREA
if ( is_admin() ) {
	include OW_PLUGIN_PATH . 'admin/index.php';
}

// COMPONENTS
foreach ( glob( OW_PLUGIN_PATH . 'components/*.php' ) as $file ) {
	include $file;
}

// MEDIA HUB
include OW_PLUGIN_PATH . 'media/media-hub.php';

// WORDPRESS CLEAN
include OW_PLUGIN_PATH . 'wp-clean.php';

//----------------------------------------------------------------------------------------------------------------------
