<?php
/*
Name:    Amy Jean Charette
Date:    December 15th 2009
Purpose:    Updates Faculty Information
*/
//start a session 
session_start();
?>
<!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/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Update My Faculty Data (fac_update.php)</title>
<style>
body
    {
    background-color:#555;
    color: #fff;
    }
a
    {
    color:#fff;
    }

td.left
{
text-align:left;
background-color:#777;
}

td.right
{
text-align:right;
background-color:#666
font-weight:bold;
}

</style>
</head>
<body>
<h1 align = "center"><strong>U<SMALL>PDATE</SMALL> M<SMALL>Y</SMALL> F<SMALL>ACULTY</SMALL> D<SMALL>ATA</SMALL></strong></h1><br />

<?php
//if the user entered the page through a hyperlink with user id passed
if (isset($_SESSION['id']))
   {
   
//connect to the database
   
require "inc_connect.php";
   
//save the table name to a variable
   
$table_name "faculty";
   
//if the user has clicked the submit button, update the table information
   
if (isset($_POST['submit']))
      {
      
$sqlString="UPDATE $table_name SET ".
            
"firstName = '".$_POST['firstName']."', ".
            
"lastName = '".$_POST['lastName']."', ".
            
"title = '".$_POST['title']."', ".
            
"location = '".$_POST['location']."', ".
            
"officeAddress = '".$_POST['officeAddress']."', ".
            
"officeHours = '".$_POST['officeHours']."', ".
            
"semester = '".$_POST['semester']."', ".
            
"phone = '".$_POST['phone']."', ".
            
"fax = '".$_POST['fax']."', ".
            
"emailAddress = '".$_POST['emailAddress']."', ".
            
"academicArea = '".$_POST['academicArea']."', ".
            
"room = '".$_POST['room']."', ".
            
"webPage = '".$_POST['webPage']."', ".
            
"password = '".$_POST['password']."' ".
            
"WHERE id=".$_SESSION['id'];

       
$result mysql_query($sqlString);

            if(
$result === FALSE) {
               echo 
"<p>unable to update faculty information</p>\n";
            }
      }

   
$result = @mysql_query("SELECT * FROM $table_name WHERE id=".
         
number_format($_SESSION['id']));

         if (
$result === FALSE) {
              echo 
"<p>Unable to display faculty information</p>\n";
         }
         else {
        
//form to upload an image file
           
echo "<center>";
           echo 
"<strong>Choose an image to upload:</strong><br />\n";
           echo 
"<form method=\"post\" action=\"fac_upload.php\" ".
                 
"enctype=\"multipart/form-data\">".
                 
"<input type=\"file\" name=\"image\">".
                 
"<input type=\"submit\" name=\"submit\" value=\"Upload\">".
                 
"</form>\n";
           echo 
"</center>";

           echo
"<form action=\"fac_update.php\" method=\"POST\">\n";

           echo 
"<center>";

           echo
"<br /><table border = '15'>";
        
//loops through to check if there is a value or is an image file uploading if not displays no image error
           
while($row mysql_fetch_array($result))
              {
              
$loadimage=FALSE;
              if (
strlen($row[image])==0)
                 {
                 
$imagetext="<i>(No Image Uploaded)</i>";
                 }
                
//if true then updates and uploads the image to the image folder
               
else
                 {
                 
$imagetext=$row[image];
                 
$loadimage=TRUE;
                 }
                
//Table to display form for updating faculty information
                
echo "<tr>\n";
              echo 
"   <td class = 'right'>First Name :&nbsp;</td>\n";
              echo 
"   <td class = 'left'><input type=\"text\" size=\"50\" maxlength=\"50\" name=\"firstName\" value=\"".$row[firstName]."\"></td>\n";
              echo 
"</tr><tr>\n";
              echo 
"   <td class = 'right'>Last Name :&nbsp;</td>\n";
              echo 
"   <td class = 'left'><input type=\"text\" size=\"50\" maxlength=\"50\" name=\"lastName\" value=\"".$row[lastName]."\"></td>\n";
              echo 
"</tr><tr>\n";
              echo 
"   <td class = 'right'>Title :&nbsp;</td>\n";
              echo 
"   <td class = 'left'><input type=\"text\" size=\"50\" maxlength=\"50\" name=\"title\" value=\"".$row[title]."\"></td>\n";
              echo 
"</tr><tr>\n";
              echo 
"   <td class = 'right'>Location :&nbsp;</td>\n";
              echo 
"   <td class = 'left'><input type=\"text\" size=\"50\" maxlength=\"50\" name=\"location\" value=\"".$row[location]."\"></td>\n";
              echo 
"</tr><tr>\n";
              echo 
"   <td class = 'right'>Office Address :&nbsp;</td>\n";
              echo 
"   <td class = 'left'><input type=\"text\" size=\"50\" maxlength=\"50\" name=\"officeAddress\" value=\"".$row[officeAddress]."\"></td>\n";
              echo 
"</tr><tr>\n";
              echo 
"   <td class = 'right'>Office Hours :&nbsp;</td>\n";
              echo 
"   <td class = 'left'><input type=\"text\" size=\"100\" maxlength=\"100\" name=\"officeHours\" value=\"".$row[officeHours]."\"></td>\n";
              echo 
"</tr><tr>\n";
              echo 
"   <td class = 'right'>Semester :&nbsp;</td>\n";
              echo 
"   <td class = 'left'><input type=\"text\" size=\"25\" maxlength=\"25\" name=\"semester\" value=\"".$row[semester]."\"></td>\n";
              echo 
"</tr><tr>\n";
              echo 
"   <td class = 'right'>Phone Number :&nbsp;</td>\n";
              echo 
"   <td class = 'left'><input type=\"text\" size=\"25\" maxlength=\"25\" name=\"phone\" value=\"".$row[phone]."\"></td>\n";
              echo 
"</tr><tr>\n";
              echo 
"   <td class = 'right'>Fax Number :&nbsp;</td>\n";
              echo 
"   <td class = 'left'><input type=\"text\" size=\"25\" maxlength=\"25\" name=\"fax\" value=\"".$row[fax]."\"></td>\n";
              echo 
"</tr><tr>\n";
              echo 
"   <td class = 'right'>E-Mail Address :&nbsp;</td>\n";
              echo 
"   <td class = 'left'><input type=\"text\" size=\"25\" maxlength=\"25\" name=\"emailAddress\" value=\"".$row[emailAddress]."\"></td>\n";
              echo 
"</tr><tr>\n";
              echo 
"   <td class = 'right'>Academic Area :&nbsp;</td>\n";
              echo 
"   <td class = 'left'><input type=\"text\" size=\"75\" maxlength=\"200\" name=\"academicArea\" value=\"".$row[academicArea]."\"></td>\n";
              echo 
"</tr><tr>\n";
              echo 
"   <td class = 'right'>Image :&nbsp;</td>\n";
              echo 
"   <td class = 'left' style = 'vertical-align:top'>".$imagetext."&nbsp;<br />";
            
//conditional statement to check for image  
            
if ($loadimage)
                 {
                 echo 
"<img src=\"images/".$row[userName]."/".
                       
$imagetext."\" alt=\"[".$row[firstName]." ".
                             
$row[lastName]."]\">";
                 }
              echo 
"</td>\n";
              echo 
"</tr><tr>\n";
              echo 
"   <td class = 'right'>Room :&nbsp;</td>\n";
              echo 
"   <td class = 'left'><input type=\"text\" size=\"25\" maxlength=\"25\" name=\"room\" value=\"".$row[room]."\"></td>\n";
              echo 
"</tr><tr>\n";
              echo 
"   <td class = 'right'>Web Page URL :&nbsp;</td>\n";
              echo 
"   <td class = 'left'><input type=\"text\" size=\"75\" name=\"webPage\" value=\"".$row[webPage]."\"></td>\n";
              echo 
"</tr><tr>\n";
              echo 
"   <td class = 'right'>Password :&nbsp;</td>\n";
              echo 
"   <td class = 'left'><input type=\"password\" size=\"50\" maxlength=\"50\" name=\"password\" value=\"".$row[password]."\"></td>\n";
              echo 
"</tr><tr>\n";
              echo 
"   <td bgcolor=\"#E0E0E0\" style = 'text-align:center' colspan='2'>";
              echo 
"<input type=\"submit\" name=\"submit\" value=\"Save Updated Information\"></td>\n";
                echo 
"</tr>\n";
              }
           echo 
"</table>\n";
           echo
"</center>";
           echo 
"</form>\n";
            
$message "   <p align = 'center'><a href=\"view_fac_list.php\">View the faculty list</a> | ";
                       
$message .= "   <a href=\"view_fac_webpage.php?id=".
                             
$_SESSION['id']."\">View my faculty web page</a> | ";
                       
$message .= "   <a href=\"fac_update.php\">Update my information</a> | ";
                       
$message .= "   <a href =\"fac_login.html\">Log in as a different faculty member</a>\n";
                       
$message .= "<br /><br />";

              echo 
$message;
           }
//ends else for unable to display
}
 else
   {
   echo 
"You are not logged in. You cannot view this information.<p />\n";
   echo 
"Please <a href='fac_login.html'>log in</a> to view this information.\n";
   }

?>

</body>
</html>