<?php

// Require the initialisation file
require_once '../../init.php';

if($GLOBALS['_MAX']['CONF']['database']['type']=='mysql'){
    require_once MAX_PATH . '/lib/OA/Dal/Delivery/mysql.php';
} else if($GLOBALS['_MAX']['CONF']['database']['type']=='pgsql'){
    require_once MAX_PATH . '/lib/OA/Dal/Delivery/pgsql.php';
} else if($GLOBALS['_MAX']['CONF']['database']['type']=='mysqli'){
    require_once MAX_PATH . '/lib/OA/Dal/Delivery/mysqli.php';
}




//** SSP LISTING BASED ON INVENTORY TYPE (SELF AJAX METHOD) START **//

$ssp_listing = [];
$condition = $_POST['condition'];

if($condition)
{
    $table_prefix = $GLOBALS['_MAX']['CONF']['table']['prefix'];
    $query = OA_Dal_Delivery_query(" SELECT exchange_name, exchange_id FROM {$table_prefix}dj_ad_exchange WHERE {$condition} ");

    if( OA_Dal_Delivery_numRows($query) > 0 )
    {
        $i = 0;

        while ( $row = OA_Dal_Delivery_fetchAssoc( $query ) ) 
        {          
            $ssp_listing[$i] =   array('exchange_name'=> $row['exchange_name'], 'exchange_id'=> $row['exchange_id']);
            $i++;
        } 
    }
    
	echo json_encode($ssp_listing);

	exit;
}

//** SSP LISTING BASED ON INVENTORY TYPE (SELF AJAX METHOD) END **//

?>