<?php
//  All of the documentation and software included in the PHP Climate
//  Release is copyrighted by Sebastien Windal
//
//  Copyright 2002
//  Sebastien Windal.  All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//  1. Redistributions of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//  2. Redistributions in binary form must reproduce the above copyright
//     notice, this list of conditions and the following disclaimer in the
//     documentation and/or other materials provided with the distribution.
//  3. All advertising materials mentioning features or use of this software
//     must display the following acknowledgement:
//     This product includes software developed by Sebastien Windal and their
//     contributors.
//  4. Neither my name nor the names of its contributors may be used to
//     endorse or promote products derived from this software without
//     specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
//  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
//  ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
//  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
//  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
//  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
//  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
//  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
//  SUCH DAMAGE.
//

?>

<html>
<head>
<title>City Climate Comparison</title>
</head>
<body bgcolor="#f0f0f0" link="#999999" vlink="#999999" alink="#999999">

<?php
include_once "weather_com.php";
include_once 
"dual_precip_graph.php";
include_once 
"zip.php";
include_once 
"dbtxt.php";
include_once 
"admin/citylog.php";

$name1 $city1;
$name2 $city2;

//by default do not use metric system
if (!isset($metric))
    
$metric="false";

//Log those two cities.
log_city($name1);
log_city($name2);

$db = new db_data_collector("data"$metric);

if (
$db->connect_server() == 0) {
        
//connection successful
        
$db->get_raw_data_from_idx($city1);
        
$weather1 $db->get_clim_data_from_raw_data();
}

if (
count($weather1['maxtemp'])!=12 || count($weather1['mintemp'])!=12 ||
    
count($weather1['meantemp'])!=12 || count($weather1['precip'])!=12) {
    echo 
"<P>no data for $city1 \n";
    echo 
"<P>Please try again with another one. <a href=\"./\">back</a>";
    die;
}

$db = new db_data_collector("data"$metric);

if (
$db->connect_server() == 0) {
        
//connection successful
        
$db->get_raw_data_from_idx($city2);
        
$weather2 $db->get_clim_data_from_raw_data();
}

if (
count($weather2['maxtemp'])!=12 || count($weather2['mintemp'])!=12 ||
    
count($weather2['meantemp'])!=12 || count($weather2['precip'])!=12) {
    echo 
"<P>no data for $city2 \n";
    echo 
"<P>Please try again with another one. <a href=\"./\">back</a>";
    die;
}


?>


<table class="top" cellpadding="5" cellspacing="0" border="0" width="100%">
  <tr> 
    <td valign="top" width="434" height="800"> 
      <table cellpadding="1" cellspacing="0" border="0" class="d4">
    <tr> 
      <td class="nav" width="300" height="20" bgcolor="#000000">&nbsp;&nbsp;<b>::</b>&nbsp;&nbsp;&nbsp;Precipitation</td>
    </tr>
    <tr bgcolor="#f0f0f0"> 
      <td class="tx" colspan="2" height="68">
<?php
$temp_url 
"precip.php"
        
"?zip1="  base64_encode(serialize($name1))
        . 
"&zip2=" base64_encode(serialize($name2))
            . 
"&metric=$metric"
            
"&precip1=" base64_encode(serialize($weather1['precip']))
        . 
"&precip2=" base64_encode(serialize($weather2['precip']));

echo 
"<img src=\"$temp_url\">\n";
?>
      </td>
    </tr>
      </table>
      <br>
      <table cellpadding="1" cellspacing="0" border="0" class="d4">
    <tr> 
      <td class="nav" width="300" height="20" bgcolor="#000000">&nbsp;&nbsp;<b>::</b>&nbsp;&nbsp;&nbsp;Temperatures</td>
    </tr>
    <tr bgcolor="#f0f0f0"> 
      <td class="tx" colspan="2">
<?php
$temp_url 
"temp.php"
        
"?zip1=" base64_encode(serialize($name1))
        . 
"&zip2=" base64_encode(serialize($name2))
        . 
"&metric=$metric"
        
"&mintemp1=" base64_encode(serialize($weather1['mintemp']))
        . 
"&mintemp2=" base64_encode(serialize($weather2['mintemp']))
        . 
"&maxtemp1=" base64_encode(serialize($weather1['maxtemp']))
        . 
"&maxtemp2=" base64_encode(serialize($weather2['maxtemp']));

echo 
"<img src=\"$temp_url\">\n";
?>
      </td>
    </tr>
      </table>
    </td>
    <td valign="top" width="677"> 
      <table cellpadding="1" cellspacing="0" border="0" class="d4" width="350">
    <tr> 
      <td class="nav" width="280" height="20" bgcolor="#000000">&nbsp;&nbsp;<b>::</b>&nbsp;&nbsp;&nbsp;<?php echo "$name1 vs. $name2"?> </td>
      <td class="nav" width="30" height="20" bgcolor="#000000">&nbsp;</td>
    </tr>
    <tr bgcolor="#f0f0f0" valign="top"> 
      <td class="tx" colspan="2" height="300"> <br>
        <center>
        <table width="280" border="0" cellspacing="20" cellpadding="0">
          <tr> 
        <td>
        <H3><CENTER><?php echo "$name1<BR>vs.<BR>$name2"?></CENTER></H3>
        <FONT SIZE="-1">Temperatures and precipitation are
        normal monthly values.
        <BR>

        <FORM ACTION="compare.php?city1=<?php echo $city1?>&city2=<?php echo $city2?>" method="POST">Unit:

        <SELECT NAME="metric">
        <OPTION
<?php if ($metric != "true") echo "SELECTED"?> value="false">US
        <OPTION
<?php if ($metric == "true") echo "SELECTED"?> value="true">Metric
        </SELECT>
        <INPUT TYPE="submit" value="Convert">
        </FORM>
        <HR><center>
        [<A HREF="index.php?metric=<?php echo $metric?>">back</A>]
        </center>
        </font>
        </td>
          </tr>
        </table>
       </center>
      </td>
    </tr>
      </table>
    </td>
  </tr>
</table>


</BODY></HTML>