<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=en&action=print&ccmi=<?php echo $current_catdom_module_id;?>" target="_blank"><?php echo tx("Print");?></a></td>
                            <?php
                        }
                    }

                    ?>
                </tr>
            </table>
        </div>
        <?php
    }
    if(isset($weather_fiveday[$adv_city_id])) {
        $tmp = array();
        $tmp = $weather_fiveday[$city['ws_city_id']];
        asort($tmp);
        $weather_fiveday[$city['ws_city_id']] = $tmp;

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

        // Put the names of days of the week
        ?>
        <table cellpadding="0" cellspacing="0" border="0" width="100%">

            <?php
            $cnt = 0;
            foreach ($weather_fiveday[$city['ws_city_id']] as $id=>$fd) {
                $day_timestamp = ($cnt == 0) ? time() : strtotime("+$cnt day", time());



                ?>
                <tr>
                    <td class="ws_td_day day_date" align="left" width="50%"><?php echo tx("%d %s", array(date("d", $day_timestamp), date("F", $day_timestamp)));?></td>
                    <td class="ws_td_day day_name" align="right" width="50%"><?php echo tx($fd['day_name']);?></td>


                </tr>
                <tr>
                    <td colspan="2" class="ws_td_daydetails" align="left" width="100%">
                        <?php
                        if(!isset($fd['gust'])) {
                            ?>
                            <table border="0" cellspacing="0" cellpadding="0" width="100%">
                                <tr>
                                    <td rowspan="2" align="center" valign="middle" class="ws_day_para_value" width="80">
                                        <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>
                                    </td>
                                    <td nowrap class="ws_day_para_name" align="center" width="25%"><strong><?php echo tx("High");?></strong></td>
                                    <td nowrap class="ws_day_para_name" align="center" width="25%"><strong><?php echo tx("Low");?></strong></td>
                                    <td rowspan="2" class="ws_day_para_value day_phrase" align="left" width="50%"><?php echo tx($fd['phrase']);?></td>
                                </tr>
                                <tr>
                                    <td nowrap class="ws_day_para_value" align="center" width="25%"><p class="degree"><?php echo convert_temp($fd['high'], $c_to_f) . '&deg;' . show_scale($fd['high_unit'], $c_to_f); ?></p></td>
                                    <td nowrap class="ws_day_para_value" align="center" width="25%"><p class="degree"><?php echo convert_temp($fd['low'], $c_to_f) . '&deg;' . show_scale($fd['low_unit'], $c_to_f); ?></p></td>
                                </tr>
                                <tr>
                                    <td rowspan="2" align="center" valign="top" class="ws_day_para_value" width="80">
                                        <strong><?php echo tx("Real Feel");?></strong>
                                    </td>
                                    <td nowrap class="ws_day_para_name" align="center" width="25%"><strong><?php echo tx("High");?></strong></td>
                                    <td nowrap class="ws_day_para_name" align="center" width="25%"><strong><?php echo tx("Low");?></strong></td>
                                </tr>
                                <tr>
                                    <td nowrap class="ws_day_para_value" align="center" width="25%"><p class="degree"><?php echo convert_temp($fd['rfhigh'], $c_to_f) . '&deg;' . show_scale($fd['high_unit'], $c_to_f); ?></p></td>
                                    <td nowrap class="ws_day_para_value" align="center" width="25%"><p class="degree"><?php echo convert_temp($fd['rflow'], $c_to_f) . '&deg;' . show_scale($fd['low_unit'], $c_to_f); ?></p></td>
                                </tr>
                            </table>
                            <?php
                        }
                        else {
                            ?>
                            <table cellpadding="0" cellspacing="0" border="0" width="100%">
                                <tr>
                                    <th colspan="6" align="left"><?php echo tx($city['ws_city_name']);?></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"><?php echo convert_temp($city['temp'], $c_to_f) . '&deg; ' . show_scale($city['temp_units'], $c_to_f);?></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 mb_strtoupper ( tx($city['phrase']), 'UTF-8');?>" 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>
                            </table>
                            <?php
                        }
                        ?>
                    </td>
                </tr>
                <?php
                $cnt++;
            }
            ?>
        </table>
        <?php
    }
    ?>
</div>
<?php