<?php
  ///////////////////////////////////////////////////
  //2007 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

  $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if(is_file ("lang/".$lang.".php")) include "lang/".$lang.".php";
     else include "lang/ru.php";

  $title=$titlepage=$TEXT['global-forecast'];
  require_once "config.php";
  require_once "utils/top_forecast.php";

  $query1 = "SELECT DISTINCT station, region FROM `tbl_forecast` ORDER BY station ";
  $tmp_for = mysql_query($query1);
    if(!$tmp_for) puterror($TEXT['error-tbl21']);
       while($for_res = mysql_fetch_array($tmp_for,MYSQL_ASSOC))
         {
         ?>
         <table class="table" border="0" cellpadding="5" cellspacing="1" width="100%">
         <tr align="left">
          <td>&nbsp;</td>
         </tr>
         <tr class="news">
          <td width="10%"><a class="forecastcity" href="forecast.php" title="<?php echo $for_res['region']; ?>"><?php echo $for_res['station']; ?></a></td>
          <td><?php echo $TEXT['forecast1']; ?></td>
          <td><?php echo $TEXT['forecast2']; ?></td>
          <td><?php echo $TEXT['forecast5']; ?></td>
          <td><?php echo $TEXT['forecast6']; ?></td>
          <td><?php echo $TEXT['forecast7']; ?></td>
          <td><?php echo $TEXT['forecast4']; ?></td>
          <td><?php echo $TEXT['forecast3']; ?></td>
          <td><?php echo $TEXT['forecast8']; ?></td>
          <td><?php echo $TEXT['forecast9']; ?></td>
         </tr>
          <?php
            $query2 = "SELECT DISTINCT dat FROM `tbl_forecast` WHERE `station`='".$for_res['station']."' ORDER BY dat ";
              $tmp_for2 = mysql_query($query2);
                 if(!$tmp_for2) puterror($TEXT['error-tbl21']);
                   while($for_res2 = mysql_fetch_array($tmp_for2,MYSQL_ASSOC))
                    {
                     $query3 = "SELECT * FROM `tbl_forecast` WHERE `dat`='".$for_res2['dat']."' AND `station`='".$for_res['station']."'";
                        $tmp_for3 = mysql_query($query3);
                          if(!$tmp_for3) puterror($TEXT['error-tbl21']);
                            while($for_res3 = mysql_fetch_array($tmp_for3,MYSQL_ASSOC))
                               {
                                $date_day_forec = substr($for_res2['dat'], -2);
                                $date_month_forec_tmp = substr($for_res2['dat'], 0,7);
                                $date_month_forec = substr($date_month_forec_tmp, -2);
                                $date_year_forec = substr($for_res2['dat'], 0,4);
                                $chislo_forec = ("$date_day_forec $month[$date_month_forec] $date_year_forec $year");
                                if($for_res3['wind_dir']<23) $wind=$TEXT['forecast_n'];
                                if($for_res3['wind_dir']>22 && $for_res3['wind_dir']<68) $wind=$TEXT['forecast_ne'];
                                if($for_res3['wind_dir']>67 && $for_res3['wind_dir']<113) $wind=$TEXT['forecast_e'];
                                if($for_res3['wind_dir']>112 && $for_res3['wind_dir']<158) $wind=$TEXT['forecast_se'];
                                if($for_res3['wind_dir']>157 && $for_res3['wind_dir']<203) $wind=$TEXT['forecast_s'];
                                if($for_res3['wind_dir']>202 && $for_res3['wind_dir']<248) $wind=$TEXT['forecast_sw'];
                                if($for_res3['wind_dir']>247 && $for_res3['wind_dir']<293) $wind=$TEXT['forecast_w'];
                                if($for_res3['wind_dir']>292 && $for_res3['wind_dir']<338) $wind=$TEXT['forecast_nw'];
                                if($for_res3['wind_dir']>337) $wind=$TEXT['forecast_n'];
                                ?>
                                  <tr class="forecast">
                                     <td><?php echo $chislo_forec; ?></td>
                                     <td><?php echo $for_res3['tday']; ?> &#67;&#176;</td>
                                     <td><?php echo $for_res3['tnight']; ?> &#67;&#176;</td>
                                     <td><?php echo $wind; ?></td>
                                     <td><?php echo $for_res3['wind_speed']; ?>  <?php echo $TEXT['forecast12']; ?></td>
                                     <td><?php echo $for_res3['weather_conditions']; ?></td>
                                     <td><?php echo $for_res3['prec_prob']; ?> &#37; </td>
                                     <td><?php echo $for_res3['prec']; ?> <?php echo $TEXT['forecast11']; ?></td>
                                     <td><?php echo $for_res3['pday']; ?> <?php echo $TEXT['forecast10']; ?></td>
                                     <td><?php echo $for_res3['pnight']; ?> <?php echo $TEXT['forecast10']; ?></td>
                                  </tr>
                                    <?php
                               }
                    }
            ?>
            </table>
            <?php
         }
?>
<?php
  require_once "utils/bottom.php";
?>