<?php
$activeGatewayList = CHtml::listData($activeModels, "id", "name");
$disabledGatewayList = CHtml::listData($disabledModels, "id", "name");


if (count($disabledGatewayList) > 0) {
    foreach ($activeGatewayList as $id => $label) {
        $activeGatewayList[$id] = '✓ ' . $label;
    }

    foreach ($disabledGatewayList as $id => $label) {
        $disabledGatewayList[$id] = '× ' . $label;
    }

    if (count($activeGatewayList) > 0) {
        $listdata[__('ROUTING_OUTBOUND_SELECT_GATEWAY_ACTIVE_GATEWAY')] = $activeGatewayList;
    }
    $listdata[__('ROUTING_OUTBOUND_SELECT_GATEWAY_DISABLED_GATEWAY')] = $disabledGatewayList;
} else {
    $listdata = $activeGatewayList;
}



$gw_id = CHtml::activeDropDownList($data, 'gw_id', $listdata, array(
            "class" => "scalable",
            "name" => 'RoutingOutbound[' . $data->id . '][gw_id]',
            'data-translation-target' => 'ROUTING_OUTBOUND_SELECT_GATEWAY_TARGET',
));

$coutGWs = count($activeGatewayList) + count($disabledGatewayList);
if ($coutGWs >= 3) {
    $gw_id .= "<br>";
    $ldata = array("" => "---");
    $listdata = array_merge($ldata, $listdata);
    $gw_id .= CHtml::activeDropDownList($data, 'failover_1', $listdata, array(
                "class" => "scalable",
                "name" => 'RoutingOutbound[' . $data->id . '][failover_1]',
                'data-translation-target' => 'ROUTING_OUTBOUND_SELECT_GATEWAY_TARGET',
    ));
    $gw_id .= "<br>";
    $gw_id .= CHtml::activeDropDownList($data, 'failover_2', $listdata, array(
                "class" => "scalable",
                "name" => 'RoutingOutbound[' . $data->id . '][failover_2]',
                'data-translation-target' => 'ROUTING_OUTBOUND_SELECT_GATEWAY_TARGET',
    ));
} elseif ($coutGWs == 2) {
    $gw_id .= "<br>";
    $ldata = array("" => "-");
    $listdata = array_merge($ldata, $listdata);
    $gw_id .= CHtml::activeDropDownList($data, 'failover_1', $listdata, array(
                "class" => "scalable",
                "name" => 'RoutingOutbound[' . $data->id . '][failover_1]',
                'data-translation-target' => 'ROUTING_OUTBOUND_SELECT_GATEWAY_TARGET',
    ));
}
echo $gw_id;