<?
$pre   = '';
include "common.php";
$title = "US GLOBEC Standing Committee for Synthesis";
// Since register_globals is on, the $_GET variables override anything
// I set in my scripts so I have this $imenu for initial menu then it
// can be reset by the $_GET['menu'] variable.
$imenu = 'members';
$logo  = true;
include HEAD;

$cat = array( 'nep'=>'on','so'=>'on','gb'=>'on','exec_committee'=>'on',
              'ex_officio'=>'on','staff'=>'on','agency_contact'=>'on');
$tbname = TABLE_PERSONNEL;

if(!empty($_GET['s'])){
   $data  = $_GET;
   $suf1  = '';
   $suf2  = '';
   $terms = preg_split ("/(\s+|\+)/", $_GET['s']);
   $num   = count($terms);
   $tmp   = array_intersect_assoc($cat,$data); // Search limiting
   for($i=0;$i<$num;$i++){
      $term = addslashes($terms[$i]);
      $suf1.="last_name LIKE '%$term%' OR first_name LIKE '%$term%' OR institute LIKE '%$term%' OR ";
   }

   // compile search limiting terms
   foreach($tmp as $key => $value){
      $suf2 .= $key . "='Y' OR ";
   }

   $suf1=substr($suf1,0,-4); // chop last ' OR ' off
   $suf2=substr($suf2,0,-4); // chop last ' OR ' off

   if(empty($suf2)) // No-limit seacrch
      $query1="SELECT * FROM $tbname WHERE (" . $suf1 . ") AND scs='Y' ORDER BY last_name";
   else // Limited Search
      $query1="SELECT * FROM $tbname WHERE (" . $suf1 . ") AND scs='Y' AND (" . $suf2 . ") ORDER BY last_name";
} // if(!empty($_GET[s])){

if(!empty($query1)){
   $result=$db->sql_query($query1);
   if(!$db->sql_numrows($result)){
      echo '<br /><h2>Sorry, there are no results for your query.</h2><br />' . "\n";
   }
   while($row=$db->sql_fetchrow($result)){
      echo '<p style="text-indent: -20px; padding-left: 20px">' . "\n";
      if(!empty($row['position'])){
         echo '<b>' . $row['last_name'] . ', ' . $row['first_name'] . '</b> (' . $row['position'] . ")<br />\n";
      }
      else{
         echo '<b>' . $row['last_name'] . ', ' . $row['first_name'] . "</b><br />\n";
      }
      echo $row['institute'] . "<br />\n";
      echo $row['phone'] . "<br />\n";
      if(!empty($row['fax'])){
         echo $row['fax'] . " (fax)<br />\n";
      }
      echo '<a href="mailto:' . $row['email'] . '">' . $row['email'] . "</a>\n";
      echo "</p>\n";

   }
   echo "<hr>\n";
}

/*
$i = '<br />
      <a href="#a">A</a> | <a href="#b">B</a> | <a href="#c">C</a> | <a href="#d">D</a> | <a href="#e">E</a> | 
      <a href="#f">F</a> | <a href="#g">G</a> | <a href="#h">H</a> | <a href="#i">I</a> | <a href="#j">J</a> | 
      <a href="#k">K</a> | <a href="#l">L</a> | <a href="#m">M</a> | <a href="#n">N</a> | <a href="#o">O</a> | 
      <a href="#p">P</a> | <a href="#q">Q</a> | <a href="#r">R</a> | <a href="#s">S</a> | <a href="#t">T</a> | 
      <a href="#u">U</a> | <a href="#v">V</a> | <a href="#w">W</a> | <a href="#x">X</a> | <a href="#y">Y</a> | 
      <a href="#z">Z</a><br />';

echo $i;
*/
$query1  = "SELECT last_name,first_name,position,institute,phone,fax,email,exec_committee FROM $tbname WHERE scs='Y' ORDER BY last_name";
$result1 = $db->sql_query($query1);
$index   = '';
echo "<br />\n";

// Get all the First letters of last names
for($i=0;$row=$db->sql_fetchrow($result1);$i++){
   $names_ssc[$i] = strtoupper(substr($row['last_name'],0,1));
   $info_ssc[$i]  = $row;
}

// Create the SSC A-Z nav bar
$j=65; // ACSII index of capital A
$nav_ssc=""; // variable to compile nav bar
for($i=0;$i<count($names_ssc);$i){
   $a=$names_ssc[$i];
   //echo $a;
   if( $a == chr($j) && $a != $index){
      $nav_ssc .= '<a href="#' . $a . "_ssc" . '">' . $a . '</a> | ';
      $index=$a;
      $j++;
   }
   if( $a != chr($j) && $a != $index){
      //$j++;
      $d=chr($j);
      $nav_ssc .= $d . ' | ';
      $j++;
   }
   if($a == $index){
      $i++;
   }
   if($j == 91) break;
}

// fill remaining letters to Z
while($j < 91){
   $d=chr($j);
   $nav_ssc .= $d . ' | ';
   $j++;
}
//$nav_ssc .= chr(90);
$nav_ssc = substr($nav_ssc, 0, -3); // 
echo "<font size=\"+2\"><B>Standing Committee for Synthesis Members</b></font><br /><hr /><br />\n";
echo $nav_ssc;


$anchor="";
$info_ssc = array_reverse($info_ssc);
while( $row=array_pop($info_ssc) ){
   if( ($a=strtoupper(substr($row[last_name],0,1))) != $anchor){
      $anchor=$a;
      echo "\n" . '<a name="' . $anchor . "_ssc" . '"></a>' . "\n";
      //echo $i;
   }
   echo '<p style="text-indent: -20px; padding-left: 20px">' . "\n";
   if(!empty($row['position'])){
      echo '<b>' . $row['last_name'] . ', ' . $row['first_name'] . '</b> (' . $row['position'] . ")<br />\n";
   }
   else{
      echo '<b>' . $row['last_name'] . ', ' . $row['first_name'] . "</b><br />\n";
   }
   echo $row['institute'] . "<br />\n";
   echo $row['phone'] . "<br />\n";
   if(!empty($row[fax])){
      echo $row[fax] . " (fax)<br />\n";
   }
   echo '<a href="mailto:' . $row['email'] . '">' . $row['email'] . "</a>\n";
   echo "</p>\n";

}

include FOOT;
?>
