-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetAnswer.php
39 lines (30 loc) · 1.21 KB
/
getAnswer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
require_once "includes/main.php";
$answer = cleanAnswer($_POST[answer]);
$challengeid = $_POST[question];
$success = false;
$content = Content::find(array('challengeid'=>$challengeid));
//fuzzy matching
similar_text($content[0]->a1, $answer, $match_strength);
if($content[0]->a1 == $answer){
$success = true;
} else {
if($match_strength > 70){
$success = true;
}
}
session_start();
if($success){
echo "true";
error_log('User '.$_SESSION['user'].' (id:'.$_SESSION['user_id'].') has successfully completed '.$challengeid);
Content::increment(array('completed'=>$content[0]->id));
// Content::addUserToList(array('completed'=>$content[0]->id));
Content::addUserToChallengeCompletedList($content[0]->id);
Content::addChallengeToUserCompletedList($challengeid);
} else {
echo "Sorry, try again.";
error_log('User '.$_SESSION['user'].' failed to complete challenge '.$challengeid.' with a match strength of '.$match_strength);
}
/* implement similar text function here. */
//echo("you answered: ".$answer. " and the real answer is: ".$content[0]->a1." for challengeid: ".$challenge);
?>