<?php
   $link = "People";
   include("inc/header.php");
   include("inc/db.php");
   include("inc/functions.php");
?>


<div id="gray-message">
<table align="center">
   <tr>
      <td style='font-size: 10pt; vertical-align:middle;'><b>Legend</b>:&nbsp;&nbsp;&nbsp;&nbsp;</td>
      <td style='font-size: 8pt; vertical-align:middle;'><img src='<?php echolink('icons/email.png');?>'></td>
      <td style='font-size: 8pt; vertical-align:middle;'>Email&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
      <td style='font-size: 8pt; vertical-align:middle;'><img src='<?php echolink('icons/user.png');?>'></td>
      <td style='font-size: 8pt; vertical-align:middle;'>Individual Website&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
      <td style='font-size: 8pt; vertical-align:middle;'><img src='<?php echolink('icons/group.png');?>'></td>
      <td style='font-size: 8pt; vertical-align:middle;'>Group Website</td>
   </tr>
</table>
</div>

<?php
   $query = "SELECT * FROM `people-types` ORDER BY `order` ASC";
   $result = mysql_query($query);
   if (!$result)
      die(mysql_error());

   $types = array();
   $total_types = 0;
   $defaultAdmin = array();
   while ($row = mysql_fetch_array($result))
   {
      $types[$total_types] = $row['type'];
      $defaultAdmin[$total_types] = $row['defaultAdmin'];
      $total_types++;
   }



   for ($i=0; $i<$total_types; $i++)
   {
      $query = "SELECT * FROM `people` WHERE (`type`='" . $types[$i] . "' && `active`>0) ORDER BY `lname`";
      $result = mysql_query($query);
      if (!$result)
         die(mysql_error());
      $total = 0;
      $usernames = array();


      while ($row = mysql_fetch_array($result))
      {
         if ($total <= 0)
         {
            echo "<h3>" . $types[$i] . "</h3>";
            echo "<div style='text-align: center;'>";
         }
         $theCsailid = $row['csailid'];
         $theCsailun = stripUsername($theCsailid);
         $timestamp = $row['picture_timestamp'];

         $name = stripslashes($row['fname']) . " ";
         $name .= (($row['mname']=="") ? "" : $row['mname'] . ". ");
         $name .= stripslashes($row['lname']);
         $dispString = "";
         if ($row['email'] != "")
            $dispString .= "<a href='mailto:" . safetyEmail(stripslashes($row['email'])) . "'><img src='" . mklink('icons/email.png') . "'></a>";
         else
            $dispString .= "<img src='" . mklink('icons/email.png') . "'>";
         if ($row['url'] != "")
            $dispString .= "<a href='" . stripslashes($row['url']) . "'><img src='" . mklink('icons/user.png') . "'></a>";
         else
            $dispString .= "<img src='" . mklink('icons/user-gray.png') . "'>";
         if ($row['groupurl'] != "")
            $dispString .= "<a href='" . stripslashes($row['groupurl']) . "'><img src='" . mklink('icons/group.png') . "'></a>";
         else
            $dispString .= "<img src='" . mklink('icons/group-gray.png') . "'>";

         //displayImage("pictures/" . $theCsailun . ".jpg", stripslashes($row['url']), "<a href='mailto:" . safetyEmail(stripslashes($row['email'])) . "'><font color='#000000'>" . stripslashes($row['name']) . "</a>");
         displayImage2("pictures/" . $theCsailun . "_" . $timestamp . ".jpg", stripslashes($row['url']), $name, $dispString);
         if ($defaultAdmin[$i])
         {
            if ($total%5==4)
               echo "<br>";
         }
         else
         {
            if ($total%8==7)
               echo "<br>";
         }

         $total++;
      }
      if ($total > 0)
         echo "</div><hr width=60% >";
/*

      while ($row = mysql_fetch_array($result))
      {
         if ($total <= 0)
         {
            echo "<h3>" . $types[$i] . "</h3>";
            echo "<div style='text-align: center;'>";
         }
         $theCsailid = $row['csailid'];
         $theCsailun = stripUsername($theCsailid);
         $timestamp = $row['picture_timestamp'];

         $dispString = stripslashes($row['name']) . "<br>";
         if ($row['email'] != "")
            $dispString .= "<a href='mailto:" . safetyEmail(stripslashes($row['email'])) . "'><img src='" . mklink('icons/email.png') . "'></a>";
         else
            $dispString .= "<img src='" . mklink('icons/email.png') . "'>";
         if ($row['url'] != "")
            $dispString .= "<a href='" . stripslashes($row['url']) . "'><img src='" . mklink('icons/user.png') . "'></a>";
         else
            $dispString .= "<img src='" . mklink('icons/user-gray.png') . "'>";
         if ($row['groupurl'] != "")
            $dispString .= "<a href='" . stripslashes($row['groupurl']) . "'><img src='" . mklink('icons/group.png') . "'></a>";
         else
            $dispString .= "<img src='" . mklink('icons/group-gray.png') . "'>";

         //displayImage("pictures/" . $theCsailun . ".jpg", stripslashes($row['url']), "<a href='mailto:" . safetyEmail(stripslashes($row['email'])) . "'><font color='#000000'>" . stripslashes($row['name']) . "</a>");
         displayImage("pictures/" . $theCsailun . "_" . $timestamp . ".jpg", stripslashes($row['url']), $dispString);
         if ($total%8==7)
            echo "<br><br>";

         $total++;
      }
      if ($total > 0)
         echo "</div>";*/
   }

   for ($i=0; $i<$total_types; $i++)
   {
      //$query = "SELECT * FROM `people` WHERE `type`='" . $types[$i] . "' && `active`=0 ORDER BY `lname`";
      $query = "SELECT * FROM `people` WHERE (`type`='" . $types[$i] . "' && `active`=0) || (`type2`='" . $types[$i] . "') ORDER BY `lname`";
      $result = mysql_query($query);
      if (!$result)
         die(mysql_error());
      $total = 0;
      $usernames = array();
      while ($row = mysql_fetch_array($result))
      {
         if ($total <= 0)
         {
            echo "<h3>Past " . $types[$i] . "</h3>";
            echo "<table align='center' width=90% border=0>";
         }
         if ($total%4==0)
            echo "<tr>";
         echo "<td align='right' width=25% style='font-size: 8pt'>";
         if ($row['url'] != "")
            echo "<a href='" . stripslashes($row['url']) . "'>";
         $name = stripslashes($row['fname']) . " ";
         $name .= (($row['mname']=="") ? "" : $row['mname'] . ". ");
         $name .= stripslashes($row['lname']);
         echo $name;
         if ($row['url'] != "")
            echo "</a>";
         echo " <a href='mailto:" . safetyEmail(stripslashes(htmlspecialchars($row['email']))) . "'><img src='icons/email.png'></a>";
         if ($total%4==3)
            echo "</tr>";
         
         $total++;
      }
      if ($total>0)
         echo "</table>";
   }
?>
