<?php
/*
Name:    Amy Jean Charette
Date:    December 15th 2009
Purpose:    Displays Faculty webpage
*/

    //start the session
   
session_start();

   
$show_link=FALSE;
   
$show_error=TRUE;
   
$row=array();
   
$id="";

    
//check to see if the id have been sent via the GET or POST if so store it to the $id varible
   
if ($_GET['id'])
      {
      
$id=$_GET['id'];
      }

   if (
$_POST['id'])
      {
      
$id=$_POST['id'];
      }
    
//if the length is greather than 0 connect otherwise if there is some info stored in the varible
   
if (strlen($id)>0)
      {
      require 
"inc_connect.php";
      
$table_name "faculty";
    
//if connection fails do this
      
if ($DBConnect==FALSE)
         {
         
$title="Connection Error";

         
$error_msg="ERROR: ".mysql_error()."<br />\n";
         
$show_link=TRUE;
         
$show_error=TRUE;
         }
    
//If connects get info from table
       
else
         {
         if (
$DBConnect)
            {
            
$sql="select * from $table_name ".
                  
" where id=".number_format($id);

            
$rows=mysql_query($sql,$DBConnect);
        
//checks if their is any information stored if not then error
            
if ($rows==FALSE)
               {
               
$title="Data Error";

               
$error_msg="ERROR: ".mysql_error()."<br />\n";
               
$show_link=TRUE;
               
$show_error=TRUE;
               }
        
//checks if the member is stored if not then error
             
else if (mysql_num_rows($rows)==0)
               {
               
$title="Data Error";

               
$error_msg="ERROR: Faculty member not found<br />\n";
               
$show_link=TRUE;
               
$show_error=TRUE;
               }
        
//if found gets info from talbe
             
else if (mysql_num_rows($rows)==1)
               {
               
$row=mysql_fetch_array($rows);
               
$title=$row[firstName]." ".$row[lastName].
                     
"'s Faculty Information";
               }
        
//all other errors
             
else
               {
               
$title="Data Error";

               
$error_msg="ERROR: Internal data error<br />\n";
               
$show_link=TRUE;
               
$show_error=TRUE;
               }
            }
        
//all other errors
          
else
            {
            
$title="Data Error";

            
$error_msg="ERROR: ".mysql_error()."<br />\n";
            
$show_link=TRUE;
            
$show_error=TRUE;
            }
         }
      }
    else
      {
// echo "<pre>".phpinfo()."</pre>\n";

      
header("Location: view_fac_list.php");
      exit;
      }

?>

<!DOCTYPE html PUBLIC "-//W3c// DTD XHTML 1.0 Transitional//EN"
"http://www.w3org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/199/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title><?php echo $title?> (view_fac_webpage.php)</title>
<style>
body
    {
    background-color:#555;
    color: #fff;
    }
a
    {
    color: #fff;
    }


</style>
</head>
<body>
<h1 align = "center"><strong>F<SMALL>ACULTY</SMALL> I<SMALL>NFORMATION</SMALL></strong></h1>
<?php
   
echo "<p />\n";
//display error message
   
if ($show_error)
      {
      echo 
"$error_msg\n";
      echo 
"<p />\n";
      }
//show faculty list link with error message
   
if ($show_link)
      {
      echo 
"Visit the <a href=\"view_fac_list.php\">Faculty ".
            
"List</a> to select a faculty member.\n";
      echo 
"<p />\n";
      }
//if all set show Faculty Member
    
else
      {
      print
"<center>";
      print
"<table border = '15'>";

        print 
"<tr>\n";
      print 
"   <td colspan=2 style =\"background-color:#555\" align=\"center\" valign=\"top\">";
      if (
strlen($row[image])>0)
         {
         print 
"<img src=\"images/".$row[userName]."/".
               
$row[image]."\" alt=\"[".$row[firstName]." ".
               
$row[lastName]."]\">&nbsp;";
         }
      print 
"<br /><b>".$row[firstName]."&nbsp;".$row[lastName].
            
"</b></td>\n";
      print 
"</tr><tr>\n";
      print 
"   <td style =\"background-color:#777\" align=\"right\"><b>Title :&nbsp;</b></td>\n";
      print 
"   <td align=\"left\">".$row[title]."&nbsp;</td>\n";
      print 
"</tr><tr>\n";
      print 
"   <td style =\"background-color:#777\" align=\"right\"><b>Location :&nbsp;</b></td>\n";
      print 
"   <td align=\"left\">".$row[location]."&nbsp;</td>\n";
      print 
"</tr><tr>\n";
      print 
"   <td style =\"background-color:#777\" align=\"right\"><b>Office Address :&nbsp;</b></td>\n";
      print 
"   <td align=\"left\">".$row[officeAddress]."&nbsp;</td>\n";
      print 
"</tr><tr>\n";
      print 
"   <td style =\"background-color:#777\" align=\"right\"><b>Office Hours :&nbsp;</b></td>\n";
      print 
"   <td align=\"left\">".$row[officeHours]."&nbsp;</td>\n";
      print 
"</tr><tr>\n";
      print 
"   <td style =\"background-color:#777\" align=\"right\"><b>Semester :&nbsp;</b></td>\n";
      print 
"   <td align=\"left\">".$row[semester]."&nbsp;</td>\n";
      print 
"</tr><tr>\n";
      print 
"   <td style =\"background-color:#777\" align=\"right\"><b>Phone Number :&nbsp;</b></td>\n";
      print 
"   <td align=\"left\">".$row[phone]."&nbsp;</td>\n";
      print 
"</tr><tr>\n";
      print 
"   <td style =\"background-color:#777\" align=\"right\"><b>Fax Number :&nbsp;</b></td>\n";
      print 
"   <td align=\"left\">".$row[fax]."&nbsp;</td>\n";
      print 
"</tr><tr>\n";
      print 
"   <td style =\"background-color:#777\" align=\"right\"><b>E-Mail Address :&nbsp;</b></td>\n";
      print 
"   <td align=\"left\">".$row[emailAddress]."&nbsp;</td>\n";
      print 
"</tr><tr>\n";
      print 
"   <td style =\"background-color:#777\" align=\"right\"><b>Academic Area :&nbsp;</b></td>\n";
      print 
"   <td align=\"left\">".$row[academicArea]."&nbsp;</td>\n";
      print 
"</tr><tr>\n";
      print 
"   <td style =\"background-color:#777\" align=\"right\"><b>Room :&nbsp;</b></td>\n";
      print 
"   <td align=\"left\">".$row[room]."&nbsp;</td>\n";
      print 
"</tr><tr>\n";
      print 
"   <td bgcolor=\"#777\" align=\"right\"><b>Web Page URL :&nbsp;</b></td>\n";
      print 
"   <td align=\"left\">".$row[webPage]."&nbsp;</td>\n";
        print 
"</tr>\n";

      print 
"</table>\n";
      print
"</center>";
      echo 
"<p />\n";
//list of links to other pages
$message "<p>What would you like to do now?</p>\n";
         
$message .= "<ul>\n";
         
$message .= "   <li><a href=\"view_fac_list.php\">View the faculty list</a><br /><br /></li>\n";
         
$message .= "   <li><a href=\"view_fac_webpage.php?id=".
               
$_SESSION['id']."\">View my faculty web page</a><br /><br /></li>\n";
         
$message .= "   <li><a href=\"fac_update.php\">Update my information</a><br /><br /></li>\n";
         
$message .= "   <li><a href=\"fac_login.html\">Log in as a different faculty member</a></li>\n";
         
$message .= "</ul>\n";

      echo 
$message;

      }
 
?>
</body>
</html>