@ 2015-10-21T06:09: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) {
$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, name, email, encrypted_password, salt, created_at) VALUES('$uuid', '$name', '$email', '$encrypted_password', '$salt', NOW())");
// check for successful store
if ($result) {
// get user details
$uid = mysql_insert_id(); // last inserted id
$result = mysql_query("SELECT * FROM users WHERE uid = $uid");
// return user details
return mysql_fetch_array($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 query
$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($selectionKey =='CRN')
$result = mysql_query("SELECT * FROM UsfCourses where '$selectionKey' = $selectionValue") or die(mysql_error());
if($selectionKey =='SubjectCRS')
$result = mysql_query("SELECT * FROM UsfCourses where '$selectionKey' = '$selectionValue'") or die(mysql_error());
if($user == true){
$result = mysql_query(" SELECT C.* FROM StudentCourses S_C, users S, UsfCourses C
WHERE S.StudentID = '$user' AND S_C.CourseID = C.CourseID");
}
$no_of_rows = mysql_num_rows($result);
if ($no_of_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;
}
//course was not found
return false;
}
/**
* 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) {
// get user details
$uid = mysql_insert_id(); // last inserted id
$result = mysql_query("SELECT * FROM StudentCourses WHERE StudentClassID = $uid");
// return user details
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.2.0 0.003 0.010 19.37 7.1.10 0.003 0.010 18.07 7.1.7 0.003 0.005 16.67 7.1.6 0.007 0.020 19.50 7.1.5 0.000 0.019 16.82 7.1.0 0.000 0.077 22.42 7.0.20 0.014 0.007 14.77 7.0.10 0.007 0.047 20.11 7.0.9 0.010 0.050 19.98 7.0.8 0.013 0.070 19.96 7.0.7 0.010 0.060 19.99 7.0.6 0.007 0.080 20.09 7.0.5 0.010 0.037 20.45 7.0.4 0.017 0.073 20.13 7.0.3 0.017 0.043 20.17 7.0.2 0.007 0.070 20.04 7.0.1 0.007 0.083 20.09 7.0.0 0.013 0.073 20.08 5.6.25 0.007 0.043 20.68 5.6.24 0.003 0.040 20.73 5.6.23 0.007 0.057 20.66 5.6.22 0.007 0.083 20.79 5.6.21 0.000 0.093 20.70 5.6.20 0.013 0.043 21.11 5.6.19 0.003 0.083 21.10 5.6.18 0.010 0.083 21.03 5.6.17 0.003 0.090 21.11 5.6.16 0.003 0.053 21.11 5.6.15 0.020 0.067 21.09 5.6.14 0.010 0.083 21.16 5.6.13 0.007 0.087 21.19 5.6.12 0.017 0.067 21.08 5.6.11 0.010 0.090 21.15 5.6.10 0.003 0.090 21.09 5.6.9 0.007 0.057 20.97 5.6.8 0.007 0.077 20.46 5.6.7 0.007 0.073 20.48 5.6.6 0.003 0.047 20.50 5.6.5 0.010 0.080 20.47 5.6.4 0.003 0.080 20.43 5.6.3 0.010 0.043 20.36 5.6.2 0.010 0.050 20.41 5.6.1 0.010 0.080 20.50 5.6.0 0.010 0.077 20.41 5.5.38 0.007 0.037 20.48 5.5.37 0.003 0.040 20.41 5.5.36 0.010 0.073 20.54 5.5.35 0.000 0.090 20.48 5.5.34 0.007 0.080 20.95 5.5.33 0.013 0.067 20.93 5.5.32 0.007 0.053 20.82 5.5.31 0.023 0.060 20.98 5.5.30 0.013 0.080 20.94 5.5.29 0.003 0.053 20.94 5.5.28 0.017 0.067 20.79 5.5.27 0.010 0.083 20.95 5.5.26 0.003 0.083 20.84 5.5.25 0.010 0.080 20.66 5.5.24 0.003 0.087 20.36 5.5.23 0.003 0.077 20.36 5.5.22 0.003 0.077 20.22 5.5.21 0.007 0.077 20.23 5.5.20 0.010 0.063 20.31 5.5.19 0.013 0.077 20.14 5.5.18 0.010 0.083 20.27 5.5.16 0.007 0.047 20.27 5.5.15 0.020 0.073 20.26 5.5.14 0.000 0.080 20.30 5.5.13 0.013 0.073 20.24 5.5.12 0.003 0.083 20.13 5.5.11 0.003 0.077 20.13 5.5.10 0.017 0.053 20.09 5.5.9 0.013 0.073 20.11 5.5.8 0.007 0.080 20.18 5.5.7 0.003 0.083 20.20 5.5.6 0.013 0.077 20.12 5.5.5 0.007 0.080 20.10 5.5.4 0.013 0.070 20.00 5.5.3 0.013 0.077 20.07 5.5.2 0.007 0.073 20.11 5.5.1 0.007 0.083 20.16 5.5.0 0.003 0.083 20.10 5.4.45 0.003 0.090 19.36 5.4.44 0.020 0.067 19.48 5.4.43 0.007 0.073 19.46 5.4.42 0.010 0.070 19.41 5.4.41 0.007 0.080 19.22 5.4.40 0.003 0.080 19.05 5.4.39 0.017 0.063 19.04 5.4.38 0.007 0.080 19.16 5.4.37 0.003 0.080 19.21 5.4.36 0.007 0.070 19.07 5.4.35 0.007 0.060 19.13 5.4.34 0.010 0.070 19.03 5.4.32 0.007 0.037 18.86 5.4.31 0.007 0.083 19.13 5.4.30 0.010 0.083 18.88 5.4.29 0.007 0.037 18.94 5.4.28 0.003 0.083 19.05 5.4.27 0.013 0.070 19.12 5.4.26 0.017 0.067 19.13 5.4.25 0.007 0.077 19.09 5.4.24 0.007 0.077 19.20 5.4.23 0.013 0.070 19.13 5.4.22 0.010 0.073 19.09 5.4.21 0.003 0.047 19.14 5.4.20 0.010 0.073 19.04 5.4.19 0.013 0.070 19.02 5.4.18 0.010 0.070 19.11 5.4.17 0.013 0.070 19.02 5.4.16 0.010 0.070 18.84 5.4.15 0.007 0.073 19.00 5.4.14 0.007 0.063 16.47 5.4.13 0.007 0.057 16.46 5.4.12 0.003 0.050 16.58 5.4.11 0.000 0.070 16.48 5.4.10 0.007 0.070 16.56 5.4.9 0.007 0.067 16.52 5.4.8 0.000 0.070 16.55 5.4.7 0.010 0.067 16.47 5.4.6 0.007 0.067 16.51 5.4.5 0.003 0.053 16.36 5.4.4 0.007 0.057 16.46 5.4.3 0.007 0.077 16.53 5.4.2 0.007 0.073 16.41 5.4.1 0.000 0.087 16.52 5.4.0 0.007 0.057 15.93
preferences:dark mode live preview
25.92 ms | 400 KiB | 5 Q