function parseEPGData($providerId)
{
    global $stationsXML, $programsXML, $schedulesXML, $baseTime;
    global $config, $numStations, $numPrograms, $numSchedules;
    $response = getEPGData($providerId);
    $stations = $response->xtvd->stations->station;
    $lineups = $response->xtvd->lineups->lineup->map;
    $stationsXML = getStationsXML($stations, $lineups, $providerId);
    $numStations = sizeof($stations);
    $programs = $response->xtvd->programs->program;
    normalizeProgramId($programs);
    $sortedSchedules = getSortedSchedules($response);
    $sortedGenres = getSortedGenres($response);
    $sortedLanguages = getSortedLanguages($sortedGenres);
    $programsXML = getProgramsXML($programs, $sortedSchedules, $sortedGenres, $sortedLanguages);
    $numPrograms = sizeof($programs);
    $schedules = $response->xtvd->schedules->schedule;
    $schedulesXML = getSchedulesXML($schedules);
    $numSchedules = sizeof($schedules);
}
<?php 
if (isset($_GET['ProviderId'])) {
    $providerId = $_GET['ProviderId'];
    setBaseTime($providerId);
    if (!isset($config['providers'][$providerId])) {
        $stations = array();
        $usingCache = true;
        // Response won't be cached that way
        $stationsXML = '';
        echo "\t<ErrorCode>1</ErrorCode>\n";
        echo "\t<ErrorDescription>Can't find provider with ID='{$providerId}' in config.inc.php</ErrorDescription>\n";
    } else {
        if ($config['providers'][$providerId]['epg-source'] == 'sd') {
            echo "\t<ErrorCode>0</ErrorCode>\n";
            echo "\t<ErrorDescription>OK</ErrorDescription>\n";
            $response = getEPGData($providerId);
            $stations = $response->xtvd->stations->station;
            $lineups = $response->xtvd->lineups->lineup->map;
            $stationsXML = getStationsXML($stations, $lineups, $providerId);
        } else {
            if ($config['providers'][$providerId]['epg-source'] == 'xmltv') {
                echo "\t<ErrorCode>0</ErrorCode>\n";
                echo "\t<ErrorDescription>OK</ErrorDescription>\n";
                require_once 'functions-xmltv.inc.php';
                $response = getEPGDataXMLTV($providerId);
                $stations = $response->channel;
                $stationsXML = getStationsXMLTV($stations, $providerId);
            }
        }
    }
}