<?php
   function NAME_COLOR() 
   {
        //return "#00FFFF";
	return "#7CFC00";
   }

   /*
   || Load and display HTML Header and Menu Bar
   */

   include "lib/header.php";
   include "lib/states.php";

   HTML_HEADER("The Wawasee List");
   MENU_BAR();

   $search_userid = checkCookie();

   //echo("<br><br><br>"); // Needed for FireFox.
   echo("\n<center>\n");
   echo("<img src=\"images/the_wawasee_list.gif\" width=\"720\" ");
   echo(" height=\"87\" alt=\"The Wawasee List\">");
   echo("\n</center>\n");


/*
|| FUNCTION: print_row
||
|| This function prints out a single WHS list row.
||
*/

function print_row($row)
{

     global $_SERVER;
     global $search_userid;
     global $country_list;

     $rowid = $row['id'];
     $ldate = $row['ldate'];
     $lname = $row['lname'];
     $fname = $row['fname'];
     $mname = $row['mname'];
     $date  = $row['year'];
     $email = $row['email'];
     $password = $row['password'];
     $about = $row['about_html'];
     $homeurl = $row['homeurl'];
     $picturl = $row['picturl'];
     $city  = $row['city'];
     $state = $row['state'];
     $country = $country_list[$row['country']];

     list($sec, $min, $hour, $mday, $mon, $year) = localtime($ldate);

     $name = "<font color=\"" . NAME_COLOR() . "\" size=6> ";
     if ($mname <> $lname)
     {
	$name .= "$lname ($mname), $fname";
     } else
     {  
	$name .= "$lname, $fname";
     }

     $name .= "</font> \n";

     if ((time() - 30*24*3600) < $ldate) 
     {
	$name .= "<img src=\"images/updated.gif\" align=\"top\" ";
	$name .= "width=60 height=12 alt=\"updated\">\n";
     }

     $picturl = cleanImageUrl($picturl);
     $thumburl = getThumbUrl($picturl);

     echo("<a href=\"$picturl\" target=\"_blank\">");
     echo("<img style=\"float: right; padding: 3px 7px 0px 3px;\" ");
     echo(" border = 0 src=\"$thumburl\" width=\"300\" /></a>");

    

     echo ("<p>\n\t$name<br>\n");

     echo("<div style=\"padding-left:30px;\">\n");
     if ($ldate != 0)
     {
	echo("(Last updated: " . ($mon + 1) . "/$mday/") ;
	echo(($year + 1900) . ") <br>\n"); 
     } else {
	echo("(Last updated: Unknown) <br> \n");
     }

     if ($search_userid == 0)
     {
	$url = "action=" . $_SERVER['PHP_SELF'] ;
	$url .= urlencode("?" . $_SERVER['QUERY_STRING']);

	echo("\t<a href=\"login.php?$url\"> Please login for email addresses");
	echo("</a><br>\n");
     }
     else
     {
        echo("\t<a href=\"mailto:$email\">$email</a><br>\n");
     }


     if (! preg_match("/NONE/i", $homeurl))
     {
	echo("\t<a href=\"$homeurl\" target=\"member\">$homeurl</a>");
	echo("<br>");
     }

     //echo("\tClass of <font color=\"#7CFC00\"> $date</font><br>");
     echo("\tClass of <a href=\"year.php?year=$date\"><img src=\"year_image.php?year=$date\" border=0></a><br>");

     if (! preg_match("/UNLISTED/i", $city))
     {
	echo("\tCurrently living in: <font color=\"#7CFC00\">" );
	echo(" $city, $state ($country)</font> <br>\n");
     }

     if (! preg_match("/^NONE/i", $about))
     {
	echo("<p><font color=\"#87CEFA\">$about<br></font>\n");
     }

     echo("</div>");
     echo("\t<p>   \n\n\n");
}
?>

<?php include "message.php" ?>


<?php
/*
|| MAIN
||
|| Purpose: To display records matching filter criteria
||
*/

/*
|| Init Vars
*/
$i= 1;                                // Used to filter by start
$num_rows = 0;                        // Count of returned rows (limit 50)
$row_limit= 50;                       // Number of records per page
$filter_type = "";                    // Type of filter
$filter   = "xx_nada__xx";            // Filter Condition.
$start    = 0;   		      // Offset into search criteria
$letter   = "";                       // Letter to filter by

if(isset($_GET['start']))
   $start    = stripHTML($_GET['start']);        // Offset into search criteria
if(isset($_GET['letter']))
   $letter   = stripHTML($_GET['letter']);       // Letter to filter by
if(isset($_GET['s_type']))
   $filter_type = stripHTML($_GET['s_type']);    // Type of filter
if(isset($_GET['s_text']))
   $filter   = stripHTML($_GET['s_text']);       // Filter Condition.


/*
|| Set up next filter
*/

$next_filter = "";
foreach($_GET as $key => $value)
{
   if ($key <> "start")
   {
      $next_filter .= "&$key=$value";
   }
}

if ($start == 0)
{
   $start = 1;
}

if (preg_match("/^[A-Z]$/", $letter))
{
   $filter_type = 1;
   echo("Displaying last or maiden names starting with $letter<p>");

} elseif ($filter_type == 1)
{
   $letter = $filter;
   echo("Displaying last or maiden names starting with $letter<p>");

} elseif ($letter == 1)
{
   echo("Displaying only entries updated in the last 30 days.<p>");

} elseif ($filter_type == 2)
{
   echo("Displaying entries for year $filter.<p>");

} elseif ($filter_type == 3)
{
  echo("Displaying entries for city $filter. <p>");
   
} elseif ($filter_type == 4)
{
  echo("Displaying entries for state $filter. <p>");

} elseif ($filter_type == 5)
{
  echo("Displaying entries for email address $filter. <p>");

} elseif ($filter_type == 6)
{
  echo("Displaying entries for key word $filter. <p>");

} elseif ($filter_type == 7)
{
  $filter = decryptUserID($filter); 
} elseif ($filter_type == 8)
{
  echo("Displaying entries for Country $filter. <p>");
}

/*
|| Connect to DB and get Records
*/
try {
   $dbh = getDB();
   $sql = "select * from users order by lname COLLATE NOCASE, mname COLLATE NOCASE, fname COLLATE NOCASE";
   foreach ($dbh->query($sql) as $row)
   {
      $rowid    = $row['id'];
      $ldate    = $row['ldate'];
      $lname    = $row['lname'];
      $fname    = $row['fname'];
      $mname    = $row['mname'];
      $date     = $row['year'];
      $email    = $row['email'];
      $password = $row['password'];
      $about    = $row['about'];
      $homeurl  = $row['homeurl'];
      $picturl  = $row['picturl'];
      $city     = $row['city'];
      $state    = $row['state'];
      $country  = $row['country'];


      if ($letter == 1 and  ((time() - 30*24*3600) > $ldate))
      {
	 continue;

      /*
      || If filtering by letter, then skip any rows
      || where the last or madain name doesn't start
      || with the specified letter
      */
      } elseif ($filter_type == 1 and !preg_match("/^$letter/i", $lname)
			      and !preg_match("/^$letter/i", $mname))
      {
         continue;


      } elseif ($filter_type == 2 and $filter <> $date)
      {
	 continue;

      } elseif ($filter_type == 3 and !preg_match("/$filter/i", $city))
      {
	 continue;

      } elseif ($filter_type == 4 and !preg_match("/$filter/i", $state))
      {
	 continue;

      } elseif ($filter_type == 5 and !preg_match("/$filter/i", $email))
      {
	 continue;

      } elseif ($filter_type == 6 and !preg_match("/$filter/i", $about))
      {
	 continue;

      } elseif ($filter_type == 7 and $rowid <> $filter)
      {
	 continue;

      } elseif ($filter_type == 8 and !preg_match("/$filter/i", $country))
      {
	 continue;
      }
          
      if ($i >= $start and $i < $start + $row_limit)
      {
         if ($filter_type == 7)
            print_row($row);     // Detail for single view
         else
            userSummary($row);
         echo("<br><br>");
         $num_rows++;
      }

      $i++;
   }

   echo ("<TABLE width=\"100%\" border=0> \n");
   echo ("\t<tr>\n\t\t<td width=\"33%\" align=\"right\">\n");



   if ($start <> 1)
   {
      echo("<a href=\"" . $_SERVER['PHP_SELF'] . "?$next_filter&start=" );
      echo(max(1,$start-$row_limit) . "\">");
      echo("&lt;&lt;&lt; Previous");
      echo("</a>");
   } else {
      echo("&nbsp;");
   }

   echo ("</td>\n\t\t<td width=\"33%\" align=\"center\">");
   if ($num_rows == 0)
   {
      echo("No rows found matching criteria.");
   } else
   {
      if ($filter_type != 7)
         echo("Displaying rows $start - " . ($start - 1 + $num_rows));
   }

   echo ("</td><td width=\"33%\" align=\"left\">");

   if ($num_rows == $row_limit)
   {
      echo("<a href=\"" . $_SERVER['PHP_SELF'] . "?$next_filter&start=" );
      echo(($start+$row_limit) . "\">");
      echo ("Next &gt;&gt;&gt;");
      echo("</a>");
   } else {
      echo ("&nbsp;");
   }

   echo ("</td></tr></TABLE>");

   } catch (PDOException $e)
   {
      echo "ERROR - ";
      echo $e->getMessage();
   }

   HTML_FOOTER();
?>
