$index_md = 0;
foreach ($ar_tmp as $value) {
    echo '{index_md: ' . $index_md . ', id: ' . $value . ',landname:\'' . $land_ref_arr[$charts_modul_ref_land[$value]] . '\',modulname: \'' . $charts_modul_ref[$value] . '\',';
    echo 'timeunit: [';
    $ival_tmp = get_exa_chart_ival($value);
    foreach ($ival_tmp as $key => $row) {
        echo "{index_tu: " . $index_tu . ",id_tu: '" . $key . "', name_tu: '" . $row . "'},";
        $index_tu++;
    }
    echo '],';
    echo 'timekey: [';
    foreach ($ival_tmp as $key => $row) {
        $timekey_tmp = get_exa_chart_time_key($value, $key);
        $index = 0;
        foreach ($timekey_tmp as $keys) {
            echo "{index_tk: " . $index . ", id_tk: '" . $key . "', key_tk: " . $keys . ", name_tk: '" . convert_zeitekey($keys, $key) . "'},";
            $index++;
        }
    }
    echo ']';
    echo '},';
    $index_md++;
}
echo '];';
echo '$scope.current_exa_modul_index = 0;';
echo '$scope.current_exa_modul_time_unit_index = 0;';
echo '$scope.current_exa_modul_time_key_index = 0;';
?>
		$scope.top_chk_box = [{'top':10}];
		$scope.change_exa_modul = function change_exa_modul(){
			$scope.exasolTabTimeUnit_val = $scope.exasolTabModulId_val.timeunit[0];
function get_chart_from_exasol($top, $modul_id, $zeikey, $zeit_unit)
{
    //modul_id = 101 : Single
    //modul_id = 102 : Longplay
    //modul_id = 103 : Compilation
    echo "get chart from Exasol: top {$top} , modul {$modul_id} , {$zeit_unit} {$zeikey} ...";
    $format = $modul_id == 101 ? 'SONG' : 'ALBUM';
    global $db;
    $ar = array();
    $sql = "SELECT\r\n\t\tNVL(Platzierung, 0) AS pnposak,\r\n\t\tNVL(Platz_Zeitraum_1, ' ') AS pnposvv,\r\n\t\tNVL(Platz_Zeitraum_2, ' ') AS pnposww,\r\n\t\tNVL(Autor, ' ') AS pninterp,\r\n\t\tNVL(Titel, ' ') AS pntitel,\r\n\t\tNVL(code, ' ') AS Code\r\n\tFROM\r\n\t\t(\r\n\t\t\tSELECT\r\n\t\t\t\tTO_NUMBER(Platzierung) AS Platzierung,\r\n\t\t\t\tm2.Platz_Zeitraum_1,\r\n\t\t\t\tm2.Platz_Zeitraum_2,\r\n\t\t\t\tm2.Autor,\r\n\t\t\t\tm2.Titel,\r\n\t\t\t\tm2.code\r\n\t\t\tFROM\r\n\t\t\t\tmcchart m2,\r\n\t\t\t\tmcchrth h2\r\n\t\t\tWHERE\r\n\t\t\t\th2.Modul_Id = {$modul_id} AND\r\n\t\t\t\th2.Ausw_Zeitraum = '" . convert_zeitekey($zeikey, $zeit_unit) . "' AND\r\n\t\t\t\th2.Ausw_Zeitraum_Einheit = '" . $zeit_unit . "' AND\r\n\t\t\t\tm2.referenz = h2.referenz\r\n\t\t\tORDER BY\r\n\t\t\t\t1\r\n\t\t)\r\n\tWHERE\r\n\t\tPlatzierung <= {$top}";
    $res = $db->query($sql);
    echo "done \n";
    if ($modul_id == 101) {
        $itunes_top100 = get_itunes_top100_song();
        $amazon_top100_phys = get_amazon_top100_phys_song();
        $amazon_top100_dwn = get_amazon_top100_dwn_song();
    } else {
        $itunes_top100 = get_itunes_top100_album();
        $amazon_top100_phys = get_amazon_top100_phys_album();
        $amazon_top100_dwn = get_amazon_top100_dwn_album();
    }
    while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
        $stamm_titel = get_de_stamm_titel(trim($row['code']), $modul_id);
        $stamm_artist = get_de_stamm_artist(trim($row['code']), $modul_id);
        $ar[] = array('RANK' => $row['pnposak'], 'RANK_W_1' => $row['pnposvv'], 'RANK_W_2' => $row['pnposww'], 'TITEL' => $stamm_titel, 'ARTIST' => $stamm_artist, 'ITUNES_LINK' => get_itunes_links($stamm_titel, $stamm_artist, $itunes_top100), 'AMAZON_PHYS_LINK' => get_amazon_links($stamm_titel, $stamm_artist, $amazon_top100_phys), 'AMAZON_DWN_LINK' => get_amazon_links($stamm_titel, $stamm_artist, $amazon_top100_dwn), 'VIDEO_LINK' => '', 'MODUL_ID' => $modul_id, 'TIME_KEY' => $zeikey, 'TIME_UNIT' => $zeit_unit);
    }
    return $ar;
}