<div class="middle_module_container weather_advanced_container">
    <?php
    if($module_change_scale == 1 || $module_show_print_link == 1) {
        ?>
        <div class="weather_tools">
            <table cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <?php
                    if($module_change_scale == 1) {
                        if($c_to_f == "c") {
                            $scale_name = "Fahrenheit (&deg;F)";
                            $scale_unit = "f";
                        }
                        if($c_to_f == "f") {
                            $scale_name = "Celsius (&deg;C)";
                            $scale_unit = "c";
                        }

                        $weather_link = $_SERVER['REQUEST_URI'];
                        if(($qmark = strpos($weather_link, "?")) === false) {
                            $weather_link .= "?show_scale=" . $scale_unit;
                        }
                        else {
                            $qs = substr($weather_link, $qmark, strlen($weather_link)-1);
                            if($qs == "?") {
                                $qs .= "show_scale=" . $scale_unit;
                            }
                            else {
                                $qp = str_replace("?", "", $qs);
                                $qp = explode("&", $qp);
                                if(is_array($qp) && count($qp)>0) {
                                    $new_qs = "?";
                                    foreach ($qp as $i=>$par) {
                                        if(strpos($par, "=") !== false) {
                                            $pars = explode("=", $par);
                                            if($pars[0] == "show_scale") {
                                                $new_qs .= "&show_scale=$scale_unit";
                                            }
                                            else {
                                                $new_qs .= "&$par";
                                            }
                                        }
                                        else {
                                            $new_qs .= "&$par";
                                        }
                                    }
                                    $qs = $new_qs;
                                }
                                else {
                                    $qs .= "&show_scale=" . $scale_unit;
                                }
                            }
                            $new_weather_link = substr($weather_link, 0, $qmark);
                            $weather_link = $new_weather_link . $qs;
                        }
                        $weather_link = str_replace("?&", "?", $weather_link);
                        ?>
                        <td><a class="change_scale" href="<?php echo $weather_link;?>"><?php echo tx("$scale_name");?></a></td>
                        <?php
                    }

                    if($module_show_print_link == 1) {
                        if(!isset($print_screen)) {
                            ?>
                            <td><a class="print" href="index.php?print=1&module_page=weather_advanced&show_scale=<?php echo $c_to_f;?>&lang=<?php echo 'en';?>&action=print&ccmi=<?php echo $current_catdom_module_id;?>" target="_blank"><?php echo tx("Print");?></a></td>
                            <?php
                        }
                        else {
                            ?>
                            <td><a class="print" href="javascript:print();"><?php echo tx("Print");?></a></td>
                            <?php
                        }
                    }

                    ?>
                </tr>
            </table>
        </div>
        <?php
    }
    if(is_array($weather_current) && count($weather_current)>0) {
        foreach ($weather_current as $k=>$city) {
            $loc_fr = "";
            $fin_wnd_dir = mb_strtoupper($city['wind_dir'], 'UTF-8');
            $wnd_dir = str_split(mb_strtolower($city['wind_dir'], 'UTF-8'));
            if(is_array($wnd_dir) && count($wnd_dir)>0) {
                $co_card = array("n"=> tx("NORTH"), "e"=> tx("EAST"), "s"=> tx("SOUTH"), "w"=> tx("WEST"));
                $fin_wnd_dir = "";
                foreach ($wnd_dir as $dir_letter) {
                    if(array_key_exists($dir_letter, $co_card)) {
                        $fin_wnd_dir .= mb_substr ( tx($co_card[$dir_letter]), 0, 1);
                    }
                }

                $fin_wnd_dir = mb_strtoupper($fin_wnd_dir, 'UTF-8');
            }

            //echo '<pre>', var_export($city, true), '</pre>';

            ?>



            <div class="weather_container_adv">
                <table cellpadding="0" cellspacing="0" border="0" width="100%">
                    <tr>
                        <th colspan="2">
                            <?php
                            if(is_array($cities_list_link_title) && isset($cities_list_link_title[$city['location']]) && trim($cities_list_link_title[$city['location']]) != "") {
                                //echo '<h2>' . tx(stripslashes($cities_list_link_title[$city['location']])) . '</h2>';

                                if(isset($cities_list_friendly_url[$city['location']]) && trim($cities_list_friendly_url[$city['location']]) != "") {
                                    $loc_fr = trim($cities_list_friendly_url[$city['location']]) . ".html";

                                    echo '<h2>';
                                    echo '<a href="', $loc_fr, '" target="_self">', tx($cities_list_link_title[$city['location']]), '</a>';
                                    echo '</h2>';

                                }
                                else {
                                    echo '<h2>' . tx(stripslashes($cities_list_link_title[$city['location']])) . '</h2>';
                                }

                            }
                            else {
                                echo '<h2>' . tx(stripslashes($city['ws_city_name'])) . '</h2>';
                            }
                            //echo '<pre>', var_export($city, true), '</pre>';
                            ?>
                        </th>
                        <th colspan="3" align="left">
                            <?php
                            if($loc_fr != "") {
                                ?>
                                <span class="weather_forecast_link"><a href="<?php echo $loc_fr;?>" target="_self"><?php echo tx("Weather Forecast " . $city['ws_city_name'] . "");?></a></span>
                                <?php
                            }
                            ?>
                        </th>
                    </tr>
                    <tr>
                        <td class="ws_td ws_1st_row ws_1st_row_first" align="center" valign="top">
                            <strong><?php echo tx("CURRENT");?></strong><br/>
                            <p class="degree"><span><?php echo convert_temp($city['temp'], $c_to_f) . '&deg; ' . show_scale($city['temp_units'], $c_to_f);?></span></p>
                        </td>
                        <td class="ws_td ws_1st_row" align="center" valign="top">
                            <strong><?php echo mb_strtoupper ( tx($city['phrase']), 'UTF-8');?></strong><br/>
                            <div class="m_icon"><img src="<?php echo $out_path_cache;?>images/weather_icons/<?php echo $city['icon'];?>.png" alt="<?php echo $city['phrase'];?>" title="<?php echo $city['phrase'];?>" border="0"/></div>
                        </td>
                        <td class="ws_td ws_1st_row ws_1st_row_last" valign="middle" align="center"  colspan="3">
                            <table cellpadding="0" cellspacing="0" border="0" class="ws_details">
                                <tr>
                                    <td align="left" nowrap class="para_name"><?php echo tx("Visibility");?>:</td>
                                    <td align="left" nowrap class="para_value"><?php echo $city['vis'] . " " . $city['vis_unit'];?></td>
                                    <td align="left" nowrap class="para_name"><?php echo tx("Wind speed");?>:</td>
                                    <td align="left" nowrap class="para_value"><?php echo $city['windspeed'] . " " . $city['windspeed_unit'];?></td>
                                </tr>
                                <tr>
                                    <td align="left" nowrap class="para_name"><?php echo tx("Pressure");?>:</td>
                                    <td align="left" nowrap class="para_value"><?php echo $city['pres'] . " " . $city['pres_unit'];?></td>
                                    <td align="left" nowrap class="para_name"><?php echo tx("Wind direction");?>:</td>
                                    <td align="left" nowrap class="para_value"><?php echo $fin_wnd_dir ;?></td>
                                </tr>
                                <tr>
                                    <td align="left" nowrap class="para_name"><?php echo tx("Humidity");?>:</td>
                                    <td align="left" nowrap class="para_value"><?php echo $city['rhumid'] . " " . $city['rhumid_unit'];?></td>
                                    <td align="left" nowrap class="para_name"><?php echo tx("Wind Chill");?>:</td>
                                    <td align="left" nowrap class="para_value"><?php echo convert_temp($city['wndchl'], $c_to_f) . "&deg; " . show_scale($city['wndchl_unit'], $c_to_f);?></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <?php
                    if(isset($weather_fiveday[$city['ws_city_id']])) {
                        $tmp = array();
                        $tmp = $weather_fiveday[$city['ws_city_id']];
                        asort($tmp);
                        $weather_fiveday[$city['ws_city_id']] = $tmp;

                        // Put the names of days of the week
                        ?>
                        <tr>
                            <?php
                            $cnt = 1;
                            foreach ($weather_fiveday[$city['ws_city_id']] as $id=>$fd) {
                                if($cnt <= 5) {
                                    $ext_cls = "";
                                    if($cnt == 1) $ext_cls = "ws_2nd_row_first";
                                    if($cnt == 5) $ext_cls = "ws_2nd_row_last";
                                    ?>
                                    <td width="20%" class="ws_td ws_2nd_row <?php echo $ext_cls;?>" align="center"><?php echo tx($fd['day_name']);?></td>
                                    <?php
                                }
                                $cnt++;
                            }
                            ?>
                        </tr>
                        <?php

                        // Put the particular forecast data per day
                        ?>
                        <tr>
                            <?php
                            $cnt = 1;
                            foreach ($weather_fiveday[$city['ws_city_id']] as $id=>$fd) {
                                if($cnt <= 5) {
                                    $ext_cls = "";
                                    if($cnt == 1) $ext_cls = "ws_3rd_row_first";
                                    if($cnt == 5) $ext_cls = "ws_3rd_row_last";
                                    ?>
                                    <td width="20%" class="ws_td ws_3rd_row <?php echo $ext_cls;?>" align="center">
                                        <div class="m_icon"><img src="<?php echo $out_path_cache;?>images/weather_icons/<?php echo $fd['icon'];?>.png" border="0" alt="<?php echo tx($fd['phrase']);?>" title="<?php echo tx($fd['phrase']);?>"/></div>
                                        <table border="0" cellspacing="0" cellpadding="0" class="ws_details">
                                            <tr>
                                                <td nowrap class="para_name"><?php echo tx("High");?>:</td>
                                                <td nowrap class="para_value para_high" align="right"><?php echo convert_temp($fd['high'], $c_to_f) . '&deg;' . show_scale($fd['high_unit'], $c_to_f); ?></td>
                                            </tr>
                                            <tr>
                                                <td nowrap class="para_name"><?php echo tx("Low");?>:</td>
                                                <td nowrap class="para_value para_low" align="right"><?php echo convert_temp($fd['low'], $c_to_f) . '&deg;' . show_scale($fd['low_unit'], $c_to_f); ?></td>
                                            </tr>
                                        </table>
                                    </td>
                                    <?php
                                }
                                $cnt++;
                            }
                            ?>
                        </tr>
                        <?php

                        // Put the particular forecast phrase
                        ?>
                        <tr>
                            <?php
                            $cnt = 1;
                            foreach ($weather_fiveday[$city['ws_city_id']] as $id=>$fd) {
                                if($cnt <= 5) {
                                    $ext_cls = "";
                                    if($cnt == 1) $ext_cls = "ws_4th_row_first";
                                    if($cnt == 5) $ext_cls = "ws_4th_row_last";
                                    ?>
                                    <td width="20%" class="ws_td ws_4th_row <?php echo $ext_cls;?>" align="center"><?php echo tx($fd['phrase']);?></td>
                                    <?php
                                }
                                $cnt++;
                            }
                            ?>
                        </tr>
                        <?php
                    }
                    ?>
                </table>

            </div>
            <br>
            <?php
        }
    }
    ?>

</div>