@ 2015-10-24T00:52:35Z <?php
class DB_Functions {
private $db;
//put your code here
// constructor
function __construct() {
require_once 'DB_Connect.php';
// connecting to database
$this->db = new DB_Connect();
$this->db->connect();
}
// destructor
function __destruct() {
}
/**
* Storing new user
* returns user details
*/
public function storeUser($name, $email, $password, $phoneNumber) {
$uuid = uniqid('', true);
$hash = $this->hashSSHA($password);
$encrypted_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
$result = mysql_query("INSERT INTO users(unique_id, phone, name, email, encrypted_password, salt, created_at) VALUES('$uuid', '$phoneNumber', '$name', '$email', '$encrypted_password', '$salt', NOW())") or die(mysql_error());
// check for successful store
if ($result) {
// return user details
return $result;
} else {
return false;
}
}
/**
* Get user by email and password
*/
public function getUserByEmailAndPassword($email, $password) {
$result = mysql_query("SELECT * FROM users WHERE email = '$email'") or die(mysql_error());
// check for result
$no_of_rows = mysql_num_rows($result);
if ($no_of_rows > 0) {
$result = mysql_fetch_array($result);
$salt = $result['salt'];
$encrypted_password = $result['encrypted_password'];
$hash = $this->checkhashSSHA($salt, $password);
// check for password equality
if ($encrypted_password == $hash) {
// user authentication details are correct
return $result;
}
} else {
// user not found
return false;
}
}
public function getCourses($user, $selectionKey, $selectionValue){
/** Mysql select Array**/
$temp = array("CourseID"=>array(),"College" => array(), "Department"=>array(),"CRN" => array(),
"SubjectCRS"=>array(),"Section" => array(), "Title"=>array(),"Building" => array(),
"Room" => array(), "Instructor"=>array(),"Campus" => array(), "Time" =>array(),
"Days" =>array());
$result = null;
if($user == true){
$result = mysql_query(" SELECT * FROM StudentCourses S_C, users S, UsfCourses C
WHERE S.StudentID = '$user' AND S_C.CourseID = C.CourseID AND S_C.StudentID = S.StudentID")or die(mysql_error());
} else if($selectionKey =='CRN'){
$result = mysql_query("SELECT * FROM UsfCourses where $selectionKey = '$selectionValue'") or die(mysql_error());
} else {
$result = mysql_query("SELECT * FROM UsfCourses where $selectionKey = '$selectionValue'") or die(mysql_error());
}
if ($result->mysql_num_rows > 0) {
while($row = mysql_fetch_array($result)){
array_push($temp["CourseID"], $row["CourseID"]);
array_push($temp["College"], $row["College"]);
array_push($temp["Department"], $row["Department"]);
array_push($temp["CRN"], $row["CRN"]);
array_push($temp["SubjectCRS"], $row["SubjectCRS"]);
array_push($temp["Section"], $row["Section"]);
array_push($temp["Title"], $row["Title"]);
array_push($temp["Building"], $row["Building"]);
array_push($temp["Room"], $row["Room"]);
array_push($temp["Instructor"], $row["Instructor"]);
array_push($temp["Campus"], $row["Campus"]);
array_push($temp["Time"], $row["Time"]);
array_push($temp["Days"], $row["Days"]);
}
return $temp;
}
return false; //course was not found
}
/**
* Check user is existed or not
*/
public function isUserExisted($email) {
$result = mysql_query("SELECT email from users WHERE email = '$email'");
$no_of_rows = mysql_num_rows($result);
if ($no_of_rows > 0) {
// user existed
return true;
} else {
// user not existed
return false;
}
}
/**
* Encrypting password
* @param password
* returns salt and encrypted password
*/
public function hashSSHA($password) {
$salt = sha1(rand());
$salt = substr($salt, 0, 10);
$encrypted = base64_encode(sha1($password . $salt, true) . $salt);
$hash = array("salt" => $salt, "encrypted" => $encrypted);
return $hash;
}
/**
* Decrypting password
* @param salt, password
* returns hash string
*/
public function checkhashSSHA($salt, $password) {
$hash = base64_encode(sha1($password . $salt, true) . $salt);
return $hash;
}
public function storeCourse($StudentID, $CourseID){
$result = mysql_query("INSERT INTO StudentCourses(StudentID, CourseID) VALUES('$StudentID', '$CourseID')");
// check for successful store
if ($result) {
$uid = mysql_insert_id(); // last inserted id
$result = mysql_query("SELECT * FROM StudentCourses WHERE StudentClassID = $uid");
return mysql_fetch_array($result);
} else {
return false;
}
}
public function getFriendsByCourseIdAndStudentId($StudentID, $CourseID){
$temp = array("name"=>array(),"CourseID"=>array(),"College" => array(), "Department"=>array(),"CRN" => array(),
"SubjectCRS"=>array(),"Section" => array(), "Title"=>array(),"Building" => array(),
"Room" => array(), "Instructor"=>array(),"Campus" => array(), "Time" =>array(),
"Days" =>array());
$result = mysql_query("SELECT
U2.name, C.*
FROM
StudentCourses SC1,
StudentCourses SC2,
users U,
Friends F,
users U2,
UsfCourses C
WHERE
SC1.StudentID = $StudentID
AND F.StudentID = U.StudentID
AND SC2.StudentID = F.FriendOfID
AND SC1.CourseID = SC2.CourseID
AND F.FriendOfID = U2.StudentID
AND SC1.CourseID = $CourseID");
$no_of_rows = mysql_num_rows($result);
if ($no_of_rows > 0) {
while($row = mysql_fetch_array($result)){
array_push($temp["name"], $row["name"]);
array_push($temp["CourseID"], $row["CourseID"]);
array_push($temp["College"], $row["College"]);
array_push($temp["Department"], $row["Department"]);
array_push($temp["CRN"], $row["CRN"]);
array_push($temp["SubjectCRS"], $row["SubjectCRS"]);
array_push($temp["Section"], $row["Section"]);
array_push($temp["Title"], $row["Title"]);
array_push($temp["Building"], $row["Building"]);
array_push($temp["Room"], $row["Room"]);
array_push($temp["Instructor"], $row["Instructor"]);
array_push($temp["Campus"], $row["Campus"]);
array_push($temp["Time"], $row["Time"]);
array_push($temp["Days"], $row["Days"]);
}
return $temp;
}
//course was not found
return false;
}
}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.1.7 0.000 0.007 16.67 7.1.6 0.003 0.021 19.13 7.1.5 0.000 0.020 16.73 7.1.0 0.000 0.077 22.44 7.0.20 0.004 0.004 16.61 7.0.10 0.013 0.077 20.00 7.0.9 0.020 0.040 20.16 7.0.8 0.013 0.063 20.03 7.0.7 0.003 0.050 20.03 7.0.6 0.003 0.080 20.10 7.0.5 0.007 0.080 20.36 7.0.4 0.010 0.063 20.13 7.0.3 0.013 0.073 19.96 7.0.2 0.007 0.087 20.18 7.0.1 0.007 0.050 20.07 7.0.0 0.003 0.090 20.04 5.6.28 0.003 0.033 21.21 5.6.25 0.020 0.070 20.66 5.6.24 0.007 0.090 20.56 5.6.23 0.000 0.090 20.68 5.6.22 0.013 0.060 20.66 5.6.21 0.007 0.077 20.67 5.6.20 0.013 0.077 20.99 5.6.19 0.013 0.057 21.13 5.6.18 0.007 0.083 20.99 5.6.17 0.003 0.090 21.06 5.6.16 0.017 0.077 21.07 5.6.15 0.013 0.073 21.09 5.6.14 0.007 0.080 20.98 5.6.13 0.013 0.077 20.98 5.6.12 0.017 0.083 21.00 5.6.11 0.003 0.087 21.08 5.6.10 0.010 0.080 21.09 5.6.9 0.007 0.080 21.07 5.6.8 0.010 0.080 20.39 5.6.7 0.007 0.050 20.48 5.6.6 0.003 0.077 20.55 5.6.5 0.023 0.067 20.46 5.6.4 0.017 0.073 20.44 5.6.3 0.007 0.077 20.42 5.6.2 0.017 0.053 20.43 5.6.1 0.017 0.077 20.52 5.6.0 0.007 0.077 20.44 5.5.38 0.003 0.087 20.48 5.5.37 0.017 0.073 20.40 5.5.36 0.007 0.087 20.39 5.5.35 0.007 0.077 20.52 5.5.34 0.007 0.087 20.95 5.5.33 0.010 0.080 20.91 5.5.32 0.020 0.063 20.88 5.5.31 0.017 0.040 21.00 5.5.30 0.007 0.083 20.95 5.5.29 0.003 0.057 20.99 5.5.28 0.013 0.057 20.98 5.5.27 0.010 0.080 20.87 5.5.26 0.013 0.077 20.81 5.5.25 0.013 0.080 20.80 5.5.24 0.003 0.083 20.20 5.5.23 0.017 0.073 20.32 5.5.22 0.013 0.073 20.34 5.5.21 0.013 0.070 20.20 5.5.20 0.007 0.087 20.15 5.5.19 0.007 0.050 20.20 5.5.18 0.017 0.067 20.30 5.5.16 0.007 0.043 20.27 5.5.15 0.000 0.053 20.32 5.5.14 0.000 0.083 20.22 5.5.13 0.017 0.073 20.21 5.5.12 0.007 0.073 20.24 5.5.11 0.007 0.047 20.15 5.5.10 0.020 0.067 20.23 5.5.9 0.007 0.073 20.16 5.5.8 0.020 0.067 20.10 5.5.7 0.017 0.037 20.09 5.5.6 0.007 0.073 20.20 5.5.5 0.007 0.083 20.19 5.5.4 0.007 0.067 20.13 5.5.3 0.010 0.073 20.11 5.5.2 0.007 0.080 20.10 5.5.1 0.007 0.047 20.14 5.5.0 0.010 0.067 20.10 5.4.45 0.013 0.060 19.49 5.4.44 0.003 0.047 19.27 5.4.43 0.010 0.077 19.23 5.4.42 0.007 0.080 19.27 5.4.41 0.010 0.070 19.24 5.4.40 0.013 0.077 18.85 5.4.39 0.003 0.083 19.14 5.4.38 0.007 0.057 19.16 5.4.37 0.000 0.070 19.12 5.4.36 0.003 0.053 19.05 5.4.35 0.007 0.043 18.85 5.4.34 0.007 0.047 19.04 5.4.32 0.013 0.073 19.09 5.4.31 0.007 0.080 19.03 5.4.30 0.017 0.070 19.22 5.4.29 0.000 0.080 18.90 5.4.28 0.010 0.077 19.03 5.4.27 0.003 0.080 18.84 5.4.26 0.007 0.070 18.89 5.4.25 0.010 0.043 19.23 5.4.24 0.017 0.057 19.20 5.4.23 0.010 0.070 19.09 5.4.22 0.017 0.057 18.94 5.4.21 0.017 0.063 19.12 5.4.20 0.013 0.070 19.11 5.4.19 0.013 0.063 19.13 5.4.18 0.003 0.077 19.21 5.4.17 0.010 0.080 19.13 5.4.16 0.000 0.080 19.14 5.4.15 0.007 0.077 19.16 5.4.14 0.017 0.047 16.28 5.4.13 0.007 0.077 16.33 5.4.12 0.007 0.073 16.41 5.4.11 0.007 0.077 16.41 5.4.10 0.007 0.073 16.45 5.4.9 0.000 0.080 16.41 5.4.8 0.003 0.057 16.40 5.4.7 0.000 0.073 16.32 5.4.6 0.017 0.060 16.39 5.4.5 0.007 0.073 16.45 5.4.4 0.007 0.067 16.29 5.4.3 0.010 0.033 16.56 5.4.2 0.010 0.043 16.34 5.4.1 0.003 0.043 16.53 5.4.0 0.003 0.077 15.88
preferences:dark mode live preview
31.07 ms | 400 KiB | 5 Q