Created
September 13, 2013 19:06
-
-
Save davemo/6554758 to your computer and use it in GitHub Desktop.
Old php codes is old.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Dave Mosher, CST224 | |
// December 7, 2006 | |
//BASIC FUNCTIONALITY | |
////////////////////////////////////////////////////////////////////////////////////////// | |
//builds an html code header for a page | |
function genHeader($sTitle, $sMetaRefresh="", $sJScripts="includes/finalScripts.js", $sStyleSheet="includes/phpfinal.css", $sAuthor="Dave Mosher, CST224") | |
{ | |
?> | |
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> | |
<head> | |
<title><? print $sTitle ?></title> | |
<meta name='author' content='<? print $sAuthor ?>'> | |
<link href='<? print $sStyleSheet ?>' rel='stylesheet' type='text/css' /> | |
<script language='Javascript' type='text/javascript' src='<? print $sJScripts ?>' ></script> | |
<? | |
} | |
function genNav() | |
{ | |
include_once("nav.php"); | |
} | |
function startContent() | |
{ | |
?> | |
<div id='content'> | |
<? | |
} | |
function endContent() | |
{ | |
?> | |
</div><!-- End of Content Div --> | |
<? | |
} | |
//builds a footer for the page. | |
function genFooter() | |
{ | |
?> | |
<div id='footer'><p>© 2006 CST224. All rights reserved.</p></div> | |
<? | |
} | |
//LOGIN STUFF | |
////////////////////////////////////////////////////////////////////////////////////////// | |
//Show the login box | |
//username added to allow for autofilling of the formfield if the cookie is set | |
function showLogin($userName="") | |
{ | |
?> | |
<h2>Login</h2> | |
<table id="loginBox"> | |
<tr><td colspan="2">Please login to the system to continue</td></tr> | |
<form id="userLogin" name="userLogin" method="POST" action="procLogin.php"> | |
<tr><td class="right">UserID <input type="text" name="userID" value="<? print $userName ?>" /></td></tr> | |
<tr><td class="right">Password <input type="password" name="password" /></td></tr> | |
<tr><td colspan="2" align="right"><input type="submit" value="Login" /></td></tr> | |
</form> | |
</table> | |
<h3>Haven't registered yet?</h3> | |
<a href="studentRegister.php">Register as a Student</a><br /> | |
<a href="tutorRegister.php">Register as a Tutor</a><br /> | |
<h3>Forgot password?</h3> | |
<a href="forgotPassword.php">Click here to recover password.</a><br /> | |
<? | |
} | |
//Show the student reg form | |
//TODO: validate with JS | |
function showStudRegForm() | |
{ | |
?> | |
<table id="loginBox"> | |
<tr><td colspan="2"><b>Please fill out ALL the fields below.</b></td></tr> | |
<form id="studentReg" name="studentReg" method="POST" action="procReg.php" onSubmit="return validateReg(this)"> | |
<tr><td>CST Account Number <input type="text" id="userID" name="userID" onKeyUp="checkName(this)"/></td></tr> | |
<tr><td class="right">First Name <input type="text" id="firstName" name="firstName" /></td></tr> | |
<tr><td class="right">Last Name <input type="text" id="lastName" name="lastName" /></td></tr> | |
<tr><td class="right">Phone Number <input type="text" id="phone" name="phone" /></td></tr> | |
<tr><td class="right">Email <input type="text" id="email" name="email" /></td></tr> | |
<tr><td class="right">Password <input type="password" id="password" name="password" /></td></tr> | |
<tr><td colspan="2" align="right"><input type="submit" value="Register" /></td></tr> | |
</form> | |
</table> | |
<? | |
} | |
function showPasswordRetrievalForm() | |
{ | |
?> | |
<table id="loginBox"> | |
<tr><td colspan="2"><b>Please fill in your username and click submit. Your password will be emailed to the address you specified on your registration.</b></td></tr> | |
<form id="forgotPass" name="forgotPass" method="POST" action="mailPass.php"> | |
<tr><td>CST Account Number <input type="text" id="userID" name="userID" /></td></tr> | |
<tr><td colspan="2" align="right"><input type="submit" value="Send me my Password" /></td></tr> | |
</form> | |
</table> | |
<? | |
} | |
function showTutorSelectCourses($obDB) | |
{ | |
//Build an associate the selection stuff | |
$result = $obDB->query("SELECT * FROM FCourse"); | |
?> | |
<table id="loginBox"> | |
<form id="selectTutorCourse" name="selectTutorCourse" method="POST" action="procTutorSelect.php"> | |
<tr><td><? print "<select name='tutorSelection[]' id='tutorSelection[]' multiple size='6'>\n"; ?> | |
<? | |
//Loop thru for each row | |
while($row = $result->fetch_assoc()) | |
{ | |
print "<option value='" . $row[courseID] . "'>" . $row[courseID] . " -> " . $row[courseName] . "</option>\n"; | |
} | |
?> | |
</select></tr></td> | |
<tr><td colspan="2" align="center"><input type="submit" value="Submit Course Selections" /></td></tr> | |
</form> | |
</table> | |
<? | |
} | |
function showTutoringJobsForm($obDB, $userID) | |
{ | |
//Build an associate the selection stuff | |
$result = $obDB->query("SELECT ta.courseID, c.courseName FROM FTutorAvail ta JOIN FCourse c ON c.courseID=ta.courseID WHERE tutorID='" . $userID . "'"); | |
?> | |
<table id="loginBox"> | |
<form id="selectTutorJob" name="selectTutorJob" > | |
<tr><td><? print "<select name='jobSelection' id='jobSelection' size='6'>\n"; ?> | |
<? | |
//Loop thru for each row | |
while($row = $result->fetch_assoc()) | |
{ | |
print "<option value='" . $row[courseID] . "' onclick='showJobs(this)'>" . $row[courseID] . " -> " . $row[courseName] . "</option>\n"; | |
} | |
?> | |
</select></tr></td> | |
</form> | |
</table> | |
<? | |
} | |
function showStudentCourseSelection($obDB) | |
{ | |
//Build a form with course selections | |
$result = $obDB->query("SELECT * FROM FCourse"); | |
?> | |
<table id="loginBox"> | |
<form id="selectStudentCourse" name="selectStudentCourse" method="POST" action="procStudentSelect.php"> | |
<tr><td><? print "<select name='studentSelection[]' id='studentSelection[]' multiple size='6'>\n"; ?> | |
<? | |
//Loop thru for each row | |
while($row = $result->fetch_assoc()) | |
{ | |
print "<option value='" . $row[courseID] . "'>" . $row[courseID] . " -> " . $row[courseName] . "</option>\n"; | |
} | |
?> | |
</select></tr></td> | |
<tr><td colspan="2" align="center"><input type="submit" value="Submit Tutoring Requests" /></td></tr> | |
</form> | |
</table> | |
<? | |
} | |
function showStudentCourseCancel($obDB, $userID) | |
{ | |
//Build a form with current course selections for the given user | |
$result = $obDB->query("SELECT c.courseName, sr.courseID FROM FStudentRequest sr JOIN FCourse c ON c.courseID=sr.courseID WHERE sr.studentID='" . $userID . "'"); | |
?> | |
<table id="loginBox"> | |
<form id="cancelTutorRequest" name="cancelTutorRequest" method="POST" action="procStudentCancel.php"> | |
<tr><td><? print "<select name='studentCancel[]' id='studentCancel[]' multiple size='6'>\n"; ?> | |
<? | |
//Loop thru for each row | |
while($row = $result->fetch_assoc()) | |
{ | |
print "<option value='" . $row[courseID] . "'>" . $row[courseID] . " -> " . $row[courseName] . "</option>\n"; | |
} | |
?> | |
</select></tr></td> | |
<tr><td colspan="2" align="center"><input type="submit" value="Submit Cancellations" /></td></tr> | |
</form> | |
</table> | |
<? | |
} | |
function showCurrentStudentSelections($obDB, $userName) | |
{ | |
$currCourses = mysqli_prepare($obDB, "SELECT fsr.courseID, fc.courseName FROM FStudentRequest fsr JOIN FCourse fc ON fsr.courseID=fc.courseID WHERE fsr.studentID=?"); | |
$currCourses->bind_param("s", $userName); | |
$currCourses->bind_result($courseID, $courseName); | |
$currCourses->execute(); | |
while($currCourses->fetch()) | |
{ | |
print "<p>$courseID -> $courseName</p>\n"; | |
} | |
} | |
function showCurrentTutoringSelections($obDB, $tutorID) | |
{ | |
$currTutoring = mysqli_prepare($obDB, "SELECT ta.courseID, c.courseName FROM FTutorAvail ta JOIN FCourse c ON c.courseID=ta.courseID WHERE ta.tutorID=?"); | |
$currTutoring->bind_param("s", $tutorID); | |
$currTutoring->bind_result($courseID, $courseName); | |
$currTutoring->execute(); | |
while($currTutoring->fetch()) | |
{ | |
print "<p>$courseID -> $courseName</p>\n"; | |
} | |
} | |
//Check Login | |
function checkLogin($obDB, $userID, $password) | |
{ | |
$result = false; | |
//query the db for the information | |
$qryUser = mysqli_prepare($obDB, "SELECT userID, password FROM FUser WHERE userID=?"); | |
$qryUser->bind_param("s", $userID); | |
$qryUser->execute(); | |
$qryUser->bind_result($qUserID, $qPassword); | |
//check the username password | |
while($qryUser->fetch()) | |
{ | |
if($userID == $qUserID && $password == $qPassword) | |
{ | |
$result = true; | |
} | |
} | |
//return the result of the check | |
return $result; | |
} | |
//Inserts users registration information into the DB | |
function insertRegistration($obDB, $userID, $firstName, $lastName, $phone, $email, $password) | |
{ | |
$insUser = mysqli_prepare($obDB, "INSERT INTO FUser (userID, firstName, lastName, phone, email, password) VALUES (?,?,?,?,?,?)"); | |
$insUser->bind_param("ssssss", $userID, $firstName, $lastName, $phone, $email, $password); | |
$insUser->execute(); | |
} | |
function insertTutorSelection($obDB, $userID, $courseID) | |
{ | |
//first, check if we've already inserted an entry for this user into the table | |
$check = mysqli_prepare($obDB, "SELECT * FROM FTutorAvail WHERE tutorID=? AND courseID=?"); | |
$check->bind_param("ss", $userID, $courseID); | |
$check->bind_result($tutorID, $course); | |
$check->execute(); | |
$check->fetch(); | |
//Check if the entry already exists | |
if($tutorID != null) | |
{ | |
//The user already has an entry for this in the db | |
print "<p>You are already tutoring $courseID . This entry was not added</p>"; | |
} | |
//Otherwise, add it to the table | |
else | |
{ | |
print "<p>Added you as a tutor for $courseID</p>"; | |
$insertClass = mysqli_prepare($obDB, "INSERT INTO FTutorAvail VALUES (?,?)"); | |
$insertClass->bind_param("ss", $userID, $courseID); | |
$insertClass->execute(); | |
} | |
} | |
function insertStudentCourseSelection($obDB, $userID, $courseID) | |
{ | |
//first, check if we've already inserted an entry for this user into the table | |
$check = mysqli_prepare($obDB, "SELECT * FROM FStudentRequest WHERE studentID=? AND courseID=?"); | |
$check->bind_param("ss", $userID, $courseID); | |
$check->bind_result($tutorID, $course); | |
$check->execute(); | |
$check->fetch(); | |
//Check if the entry already exists | |
if($tutorID != null) | |
{ | |
//The user already has an entry for this in the db | |
print "<p>You are already signed up to be tutored for $courseID . This entry was not added</p>"; | |
} | |
//Otherwise, add it to the table | |
else | |
{ | |
print "<p>Added you to the list to be tutored for $courseID</p>"; | |
$insertClass = mysqli_prepare($obDB, "INSERT INTO FStudentRequest VALUES (?,?)"); | |
$insertClass->bind_param("ss", $userID, $courseID); | |
$insertClass->execute(); | |
} | |
} | |
function removeStudentCourseSelection($obDB, $userID, $courseID) | |
{ | |
//first, check if there are no entries for this user in the table | |
$check = mysqli_prepare($obDB, "SELECT studentID, courseID FROM FStudentRequest WHERE studentID=? AND courseID=?"); | |
$check->bind_param("ss", $userID, $courseID); | |
$check->bind_result($studentID, $course); | |
$check->execute(); | |
$check->fetch(); | |
//Check if there were no entries | |
if($studentID == null) | |
{ | |
//The user already has an entry for this in the db | |
print "<p>There were no tutoring requests for $userID found in the database.</p>"; | |
} | |
//Otherwise, remove it from the table | |
else | |
{ | |
print "<p>Removed your tutoring request for $courseID</p>"; | |
//Needed for some reason because a function can't re-use the db object within a function | |
$innerDB = new mysqli("142.99.43.2", "CST224", "IPBRYL", "CST224"); | |
$removeRequest = mysqli_prepare($innerDB, "DELETE FROM FStudentRequest WHERE studentID=? AND courseID=?"); | |
$removeRequest->bind_param("ss", $userID, $courseID); | |
$removeRequest->execute(); | |
} | |
} | |
function hasTutoringRequests($obDB, $userID) | |
{ | |
$result = false; | |
$qryUser = mysqli_prepare($obDB, "SELECT studentID FROM FStudentRequest WHERE studentID=?"); | |
$qryUser->bind_param("s", $userID); | |
$qryUser->execute(); | |
$qryUser->bind_result($studentID); | |
//check that the user has a tutoring request in the table | |
while($qryUser->fetch()) | |
{ | |
if($studentID != null) | |
{ | |
$result = true; | |
} | |
} | |
//return the result of the check | |
return $result; | |
} | |
function hasTutoringJobs($obDB, $tutorID) | |
{ | |
$result = false; | |
$qryUser = mysqli_prepare($obDB, "SELECT tutorID FROM FTutorAvail WHERE tutorID=?"); | |
$qryUser->bind_param("s", $tutorID); | |
$qryUser->execute(); | |
$qryUser->bind_result($tutorID); | |
//check that the user has a tutoring request in the table | |
while($qryUser->fetch()) | |
{ | |
if($tutorID != null) | |
{ | |
$result = true; | |
} | |
} | |
//return the result of the check | |
return $result; | |
} | |
function getEmail($obDB, $student) | |
{ | |
$qryEmail = mysqli_prepare($obDB, "SELECT email FROM FUser WHERE userID=?"); | |
$qryEmail->bind_param("s", $student); | |
$qryEmail->execute(); | |
$qryEmail->bind_result($email); | |
$qryEmail->fetch(); | |
return $email; | |
} | |
function getName($obDB, $student) | |
{ | |
$qryName = mysqli_prepare($obDB, "SELECT CONCAT(firstName, \" \", lastName) FROM FUser WHERE userID=?"); | |
$qryName->bind_param("s", $student); | |
$qryName->execute(); | |
$qryName->bind_result($name); | |
$qryName->fetch(); | |
return $name; | |
} | |
function getPhone($obDB, $student) | |
{ | |
$qryPhone = mysqli_prepare($obDB, "SELECT phone FROM FUser WHERE userID=?"); | |
$qryPhone->bind_param("s", $student); | |
$qryPhone->execute(); | |
$qryPhone->bind_result($phone); | |
$qryPhone->fetch(); | |
return $phone; | |
} | |
/****************************************** | |
* Function estCookie | |
* Purpose This routine shall be responsible for going through | |
* and setting a cookie value | |
* Params sName - Name of the Cookie | |
* sVal - Value of the cookie | |
* nDuration - How many days cookie lasts | |
*************************************************/ | |
function estCookie($sName, $sVal, $nDuration) | |
{ | |
setcookie($sName, $sVal, time() + 24 * 3600 * $nDuration); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment