<div class="row tv-mod">
    <?php

    $optres ['css'][] = $path . "amodules/tvmodule/css/tvmodule.css";
    $optres ['js'][] = $path . "assets/js/liabru/jquery.matchHeight.min.js";
    $date_unix = date('Y-m-d');
    foreach($tv_channels as $channel => $channel_data) {
        $sql = "SELECT * FROM tvschedule WHERE date_new='" . $date_unix . "' AND channel='$channel' ORDER BY s, time1, time2";
        //echo $sql;
        $result = @mysql_query($sql);
        if($result && mysql_num_rows($result) > 0) {
            $channel_schedule = array(
                '0' => array(),
                '1' => array(),
                '2' => array(),
                '3' => array(),
            );
            $channel_title = '';
            while($rowp = mysql_fetch_assoc($result)) {
                $row = array_map('stripslashes', $rowp);
                if($row['s'] == '') $row['s'] = '-';
                if($channel_title == '') $channel_title = $row['channel'];

                if ($row['s']{0} == 'F') {
                    $channel_schedule [0][] = $row;
                }


                if ($row['time1'] >= '05' && $row['s']{0} != 'L' && $row['s']{0} != 'F') {
                    $channel_schedule [1][] = $row;
                }

                if (($row['time1'] < '05') && $row['time1'] > '' && $row['s']{0} != 'L' && $row['s']{0} != 'F') {
                    $channel_schedule [2][] = $row;
                }

                if ($row['s']{0} == 'L') {
                    $channel_schedule [3][] = $row;
                }

            }

            //echo '<pre>', var_export($channel_schedule, true), '</pre>';
            ?>
            <div class="col-md-5">
                <section class="box box-compact box-tv" data-mh="tv-channel">
                    <header class="box-header">
                        <b><?=$channel_data['title'];?></b>
                        <img src="<?=$channel_data['logo'];?>" class="pull-right">
                    </header>
                    <table class="table table-hover">
                        <tbody>
                        <?php
                        foreach($channel_schedule as $zone=>$programs) {
                            foreach($programs as $row) {
                                ?>
                                <tr>
                                    <td class="col-xs-1">
                                        <b>
                                        <?php
                                        echo $row['time1'];
                                        if ($row['time1']) echo ":";
                                        echo $row['time2'];
                                        ?></b>

                                    </td>
                                    <td class="col-xs-9">
                                        <?php
                                        if ($row['link']) echo "<a href='{$row['link']}' target='_blank'>";
                                        echo $row['title'];
                                        if ($row['link']) echo "</a>";
                                        ?>
                                    </td>
                                </tr>
                                <?php
                            }
                        }
                        ?>
                        </tbody>
                    </table>

                </section>
            </div>

            <?php

        }
    }
    ?>
</div>
