check_mock_results($mock_key,$candidate_id); $summary = $mock->get_mock_results($mock_key,$candidate_id); if($results){ echo json_encode( array( "message"=>"success", "data"=>$results, "summary"=>$summary ) ); }else{ echo json_encode( array( "message"=>"fail", "data"=>"null" ) ); } } // Results function band($score){ $band = 0; if($score >=39){ $band = 9; }else if($score >=37){ $band = 8.5; }else if($score >=35){ $band = 8; }else if($score >=32){ $band = 7.5; }else if($score >=30){ $band = 7.0; }else if($score >=26){ $band = 6.5; }else if($score >=23){ $band = 6.0; }else if($score >=18){ $band = 5.5; }else if($score >=16){ $band = 5.0; }else if($score >=13){ $band = 4.5; }else if($score >=10){ $band = 4.0; }else if($score >=8){ $band = 3.5; }else if($score >=6){ $band = 3.0; }else if($score >=4){ $band = 2.5; } return $band; } function genband($score){ $band = 0; if($score == 40){ $band = 9; }else if($score ==39){ $band = 8.5; }else if($score >=37){ $band = 8.0; }else if($score ==36){ $band = 7.5; }else if($score >=34){ $band = 7.0; }else if($score >=32){ $band = 6.5; }else if($score >=30){ $band = 6.0; }else if($score >=27){ $band = 5.5; }else if($score >=23){ $band = 5.0; }else if($score >=19){ $band = 4.5; }else if($score >=15){ $band = 4.0; }else if($score >=12){ $band = 3.5; }else if($score >=9){ $band = 3.0; }else if($score >=6){ $band = 2.5; } return $band; } if(isset($_POST['RLPeruser'])){ $full_name = $_POST['full_name']; $component = $_POST['component']; $candidate_number = $_POST['candidate_number']; $mock_key = $_POST['mock_key']; $phone_number = $_POST['phone_number']; $script = $_POST['script']; $qns = preg_split('/\r\n|\r|\n/', $script); $marked = "No"; $bandscore = 0; // print_r($qns); // echo $qns[1]; // print_r($answers_array); $i = 0; $score = 0; $mark = $script; $marked_script = ""; $reading = 0;$listening = 0;$writingTask1 = 0;$writingTask2 = 0;$generalreading = 0; // print_r($answers_array); if($component=="Reading"){ $AnswersFile = fopen('../Script/cam13test4reading.txt','r'); $answers_array = array(); $correctionTemp = ""; while(!feof($AnswersFile)){ $answers_array[] = fgets($AnswersFile); } // Deviation Start $answers = ['b','e','d']; $answersSet35 = ['b','e','d']; $answersSet36 = ['b','e','d']; $answersSet37 = ['b','e','d']; $key35 = ""; $key36 = ""; $key37 = ""; $qn35Ans = ""; $qn36Ans = ""; $qn37Ans = ""; $qn35 = strtolower(str_replace(' ','',$qns[34])); $qn36 = strtolower(str_replace(' ','',$qns[35])); $qn37 = strtolower(str_replace(' ','',$qns[36])); $qn35Input = substr($qn35, 3); $qn36Input = substr($qn36, 3); $qn37Input = substr($qn37, 3); // Qn35 Start if(in_array($qn35Input,$answers)){ $key35 = array_search($qn35Input,$answers); unset($answersSet35[$key35]); }else{ $key36 = array_search($qn36Input,$answers); if($key36!==""){ unset($answersSet35[$key36]); } $key37 = array_search($qn37Input,$answers); if($key37 !==""){ unset($answersSet35[$key37]); } $answersSet35 = array_values($answersSet35); if(count($answersSet35)){ $qn35Ans = $answersSet35[0]; } } // Qn35 End // Qn36 Start if(in_array($qn36Input,$answers)){ $key36 = array_search($qn36Input,$answers); unset($answersSet36[$key36]); }else{ $key35 = array_search($qn35Input,$answers); if($key35!==""){ unset($answersSet36[$key35]); } $key37 = array_search($qn37Input,$answers); if($key37!==""){ unset($answersSet36[$key37]); } $answersSet36 = array_values($answersSet36); if(count($answersSet36)>1){ $qn36Ans = $answersSet36[1]; } } // Qn36 ENd // Qn37 Start if(in_array($qn37Input,$answers)){ $key37 = array_search($qn37Input,$answers); unset($answersSet37[$key37]); }else{ $key35 = array_search($qn35Input,$answers); if($key35!==""){ unset($answersSet37[$key35]); } $key36 = array_search($qn36Input,$answers); if($key36!==""){ unset($answersSet37[$key36]); } $answersSet37 = array_values($answersSet37); if(count($answersSet37)){ $qn37Ans = end($answersSet37); } } // Qn37 ENd // Dviation End foreach($answers_array as $ans){ $correcton = substr($ans,3); if($i<40){ if (trim(strtolower(str_replace(' ','',$ans))) == trim(strtolower(str_replace(' ','',$qns[$i]))) || trim(strtolower(str_replace(' ','',$ans))).'.' == trim(strtolower(str_replace(' ','',$qns[$i])))) { $mark = '✅'; $score++; $marked_script .= "$qns[$i] $mark "; } else{ $mark = "⨉"; // if($correctionTemp=="B"){ // if($qns[35]=="D"){ // $correction = "E"; // }else if($qns[35]=="E"){ // $correction = "D"; // } // }else if($correctionTemp=="D"){ // if($qns[35]=="B"){ // $correction = "E"; // }else if($qns[35]=="E"){ // $correction = "B"; // } // }else if($correctionTemp=="E"){ // if($qns[35]=="D"){ // $correction = "B"; // }else if($qns[35]=="B"){ // $correction = "D"; // } // } $marked_script .= "$qns[$i] $mark $correcton "; } $i++; } } $marked = "Yes"; $marked_script .= " You scored $score/40. "; $bandscore = band($score); $marked_script .= " Band $bandscore "; }if($component=="GenReading"){ $AnswersFile = fopen('../Script/december22genreading.txt','r'); $answers_array = array(); $correctionTemp = ""; while(!feof($AnswersFile)){ $answers_array[] = fgets($AnswersFile); } // Deviation Start $answers = ['b','e','d']; $answersSet35 = ['b','e','d']; $answersSet36 = ['b','e','d']; $answersSet37 = ['b','e','d']; $key35 = ""; $key36 = ""; $key37 = ""; $qn35Ans = ""; $qn36Ans = ""; $qn37Ans = ""; $qn35 = strtolower(str_replace(' ','',$qns[34])); $qn36 = strtolower(str_replace(' ','',$qns[35])); $qn37 = strtolower(str_replace(' ','',$qns[36])); $qn35Input = substr($qn35, 3); $qn36Input = substr($qn36, 3); $qn37Input = substr($qn37, 3); // Qn35 Start if(in_array($qn35Input,$answers)){ $key35 = array_search($qn35Input,$answers); unset($answersSet35[$key35]); }else{ $key36 = array_search($qn36Input,$answers); if($key36!==""){ unset($answersSet35[$key36]); } $key37 = array_search($qn37Input,$answers); if($key37 !==""){ unset($answersSet35[$key37]); } $answersSet35 = array_values($answersSet35); if(count($answersSet35)){ $qn35Ans = $answersSet35[0]; } } // Qn35 End // Qn36 Start if(in_array($qn36Input,$answers)){ $key36 = array_search($qn36Input,$answers); unset($answersSet36[$key36]); }else{ $key35 = array_search($qn35Input,$answers); if($key35!==""){ unset($answersSet36[$key35]); } $key37 = array_search($qn37Input,$answers); if($key37!==""){ unset($answersSet36[$key37]); } $answersSet36 = array_values($answersSet36); if(count($answersSet36)>1){ $qn36Ans = $answersSet36[1]; } } // Qn36 ENd // Qn37 Start if(in_array($qn37Input,$answers)){ $key37 = array_search($qn37Input,$answers); unset($answersSet37[$key37]); }else{ $key35 = array_search($qn35Input,$answers); if($key35!==""){ unset($answersSet37[$key35]); } $key36 = array_search($qn36Input,$answers); if($key36!==""){ unset($answersSet37[$key36]); } $answersSet37 = array_values($answersSet37); if(count($answersSet37)){ $qn37Ans = end($answersSet37); } } // Qn37 ENd // Dviation End foreach($answers_array as $ans){ $correcton = substr($ans,3); if($i<40){ if (trim(strtolower(str_replace(' ','',$ans))) == trim(strtolower(str_replace(' ','',$qns[$i]))) || trim(strtolower(str_replace(' ','',$ans))).'.' == trim(strtolower(str_replace(' ','',$qns[$i])))) { $mark = '✅'; $score++; $marked_script .= "$qns[$i] $mark "; } else{ if($i==17){ if(trim(strtolower(str_replace(' ','',$qns[17])))==trim(strtolower(str_replace(' ','',"18. THE PAYROLL"))) || trim(strtolower(str_replace(' ','',$qns[17])))==trim(strtolower(str_replace(' ','',"18. PAYROLL"))) ){ $mark = '✅'; $marked_script .= "$qns[17] $mark "; $score++; }else{ $mark = "⨉"; $marked_script .= "$qns[$i] $mark $correcton "; } }else if($i==18){ if(trim(strtolower(str_replace(' ','',$qns[18])))==trim(strtolower(str_replace(' ','',"19. EMPLOYMENT"))) || trim(strtolower(str_replace(' ','',$qns[18])))==trim(strtolower(str_replace(' ','',"19. EMPLOYMENTS"))) ){ $mark = '✅'; $marked_script .= "$qns[18] $mark "; $score++; }else{ $mark = "⨉"; $marked_script .= "$qns[$i] $mark $correcton "; } }else if($i==20){ if(trim(strtolower(str_replace(' ','',$qns[20])))==trim(strtolower(str_replace(' ','',"21. THREE MONTHS"))) || trim(strtolower(str_replace(' ','',$qns[20])))==trim(strtolower(str_replace(' ','',"21. 3 MONTHS"))) ){ $mark = '✅'; $marked_script .= "$qns[20] $mark "; $score++; }else{ $mark = "⨉"; $marked_script .= "$qns[$i] $mark $correcton "; } }else if($i==21){ if(trim(strtolower(str_replace(' ','',$qns[21])))==trim(strtolower(str_replace(' ','',"22. OBVIOUS SPAM"))) || trim(strtolower(str_replace(' ','',$qns[21])))==trim(strtolower(str_replace(' ','',"22. SPAM"))) ){ $mark = '✅'; $marked_script .= "$qns[21] $mark "; $score++; }else{ $mark = "⨉"; $marked_script .= "$qns[$i] $mark $correcton "; } }else if($i==26){ if(trim(strtolower(str_replace(' ','',$qns[26])))==trim(strtolower(str_replace(' ','',"27. DEFINTE DATE"))) || trim(strtolower(str_replace(' ','',$qns[26])))==trim(strtolower(str_replace(' ','',"27. DATE"))) ){ $mark = '✅'; $marked_script .= "$qns[26] $mark "; $score++; }else{ $mark = "⨉"; $marked_script .= "$qns[$i] $mark $correcton "; } }else{ $mark = "⨉"; // if($correctionTemp=="B"){ // if($qns[35]=="D"){ // $correction = "E"; // }else if($qns[35]=="E"){ // $correction = "D"; // } // }else if($correctionTemp=="D"){ // if($qns[35]=="B"){ // $correction = "E"; // }else if($qns[35]=="E"){ // $correction = "B"; // } // }else if($correctionTemp=="E"){ // if($qns[35]=="D"){ // $correction = "B"; // }else if($qns[35]=="B"){ // $correction = "D"; // } // } $marked_script .= "$qns[$i] $mark $correcton "; } } $i++; } } $marked = "Yes"; $marked_script .= " You scored $score/40. "; $bandscore = genband($score); $marked_script .= " Band $bandscore "; }else if($component=="Listening"){ $AnswersFile = fopen('../Script/cam13test4listening.txt','r'); $answers_array = array(); while(!feof($AnswersFile)){ $answers_array[] = fgets($AnswersFile); } foreach($answers_array as $ans){ $correcton = substr($ans,3); if($i<40){ // echo trim(trim(strtolower(str_replace(' ','',$ans)))." = ".trim(trim(strtolower(str_replace(' ','',$qns[$i])))."
"; if (trim(strtolower(str_replace(' ','',$ans))) == trim(strtolower(str_replace(' ','',$qns[$i]))) || trim(strtolower(str_replace(' ','',$ans))).'.' == trim(strtolower(str_replace(' ','',$qns[$i])))) { $mark = '✅'; $score++; $marked_script .= "$qns[$i] $mark "; }else{ if($i==1){ if(trim(strtolower(str_replace(' ','',$qns[1])))==trim(strtolower(str_replace(' ','',"2. MATHS"))) || trim(strtolower(str_replace(' ','',$qns[1])))==trim(strtolower(str_replace(' ','',"2. MATH"))) || trim(strtolower(str_replace(' ','',$qns[1])))==trim(strtolower(str_replace(' ','',"2. MATHEMATICS"))) ){ $mark = '✅'; $marked_script .= "$qns[1] $mark "; $score++; }else{ $mark = "⨉"; $marked_script .= "$qns[$i] $mark $correcton "; } }else if($i==3){ if(trim(strtolower(str_replace(' ','',$qns[3])))==trim(strtolower(str_replace(' ','',"4. 17"))) || trim(strtolower(str_replace(' ','',$qns[3])))==trim(strtolower(str_replace(' ','',"4. SEVENTEEN"))) ){ $mark = '✅'; $marked_script .= "$qns[3] $mark "; $score++; }else{ $mark = "⨉"; $marked_script .= "$qns[$i] $mark $correcton "; } } else if($i==4){ if(trim(strtolower(str_replace(' ','',$qns[4])))==trim(strtolower(str_replace(' ','',"5. HOLIDAYS"))) || trim(strtolower(str_replace(' ','',$qns[4])))==trim(strtolower(str_replace(' ','',"5. HOLIDAY"))) || trim(strtolower(str_replace(' ','',$qns[4])))==trim(strtolower(str_replace(' ','',"5. VACATIONS"))) || trim(strtolower(str_replace(' ','',$qns[4])))==trim(strtolower(str_replace(' ','',"5. VACATION"))) ){ $mark = '✅'; $marked_script .= "$qns[4] $mark "; $score++; }else{ $mark = "⨉"; $marked_script .= "$qns[$i] $mark $correcton "; } }else if($i==26){ if(trim(strtolower(str_replace(' ','',$qns[26])))==trim(strtolower(str_replace(' ','',"27. B"))) || trim(strtolower(str_replace(' ','',$qns[26])))==trim(strtolower(str_replace(' ','',"27. C"))) ){ $mark = '✅'; $marked_script .= "$qns[26] $mark "; $score++; }else{ $mark = "⨉"; $marked_script .= "$qns[$i] $mark $correcton "; } }else if($i==27){ if(trim(strtolower(str_replace(' ','',$qns[27])))==trim(strtolower(str_replace(' ','',"28. B"))) && trim(strtolower(str_replace(' ','',$qns[26])))!=trim(strtolower(str_replace(' ','',"27. B"))) || trim(strtolower(str_replace(' ','',$qns[27])))==trim(strtolower(str_replace(' ','',"28. C"))) && trim(strtolower(str_replace(' ','',$qns[26])))!=trim(strtolower(str_replace(' ','',"27. C"))) ){ $mark = '✅'; $marked_script .= "$qns[27] $mark "; $score++; }else{ $mark = "⨉"; $marked_script .= "$qns[$i] $mark $correcton "; } }else if($i==28){ if(trim(strtolower(str_replace(' ','',$qns[28])))==trim(strtolower(str_replace(' ','',"29. D"))) || trim(strtolower(str_replace(' ','',$qns[28])))==trim(strtolower(str_replace(' ','',"29. E"))) ){ $mark = '✅'; $marked_script .= "$qns[28] $mark "; $score++; }else{ $mark = "⨉"; $marked_script .= "$qns[$i] $mark $correcton "; } }else if($i==29){ if(trim(strtolower(str_replace(' ','',$qns[29])))==trim(strtolower(str_replace(' ','',"30. D"))) && trim(strtolower(str_replace(' ','',$qns[28])))!=trim(strtolower(str_replace(' ','',"29. D"))) || trim(strtolower(str_replace(' ','',$qns[29])))==trim(strtolower(str_replace(' ','',"30. E"))) && trim(strtolower(str_replace(' ','',$qns[28])))!=trim(strtolower(str_replace(' ','',"29. E"))) ){ $mark = '✅'; $marked_script .= "$qns[29] $mark "; $score++; }else{ $mark = "⨉"; $marked_script .= "$qns[$i] $mark $correcton "; } }else if($i==31){ if(trim(strtolower(str_replace(' ','',$qns[31])))==trim(strtolower(str_replace(' ','',"32. UNIVERSITIES"))) || trim(strtolower(str_replace(' ','',$qns[31])))==trim(strtolower(str_replace(' ','',"32. UNIVERSITY"))) ){ $mark = '✅'; $marked_script .= "$qns[31] $mark "; $score++; }else{ $mark = "⨉"; $marked_script .= "$qns[$i] $mark $correcton "; } }else if($i==33){ if(trim(strtolower(str_replace(' ','',$qns[33])))==trim(strtolower(str_replace(' ','',"34. PORT"))) || trim(strtolower(str_replace(' ','',$qns[33])))==trim(strtolower(str_replace(' ','',"34. PORTS"))) ){ $mark = '✅'; $marked_script .= "$qns[33] $mark "; $score++; }else{ $mark = "⨉"; $marked_script .= "$qns[$i] $mark $correcton "; } }else if($i==34){ if(trim(strtolower(str_replace(' ','',$qns[34])))==trim(strtolower(str_replace(' ','',"35. SLAVES"))) || trim(strtolower(str_replace(' ','',$qns[9])))==trim(strtolower(str_replace(' ','',"35. SLAVERY"))) ){ $mark = '✅'; $marked_script .= "$qns[9] $mark "; $score++; }else{ $mark = "⨉"; $marked_script .= "$qns[$i] $mark $correcton "; } } else{ $mark = "⨉"; $marked_script .= "$qns[$i] $mark $correcton "; } } $i++; } } $marked = "Yes"; $marked_script .= " You scored $score/40. "; $bandscore = band($score); $marked_script .= " Band $bandscore "; }else if($component=="WritingTask1"){ $marked = "No"; $marked_script = $script; }else if($component=="WritingTask2"){ $marked = "No"; $marked_script = $script; } $data = array( "candidate_number"=>$candidate_number, "mock_key"=>$mock_key, "component"=>$component, "full_name"=>$full_name, "phone_number"=>$phone_number, "script"=>$script, "marked_script"=>$marked_script, "marked"=>$marked, "date_created"=>date("Y-m-d") ); $results = $mock->check_mock_results_duplicate($mock_key,$candidate_number,$component); $summary_results = $mock->get_mock_results($mock_key,$candidate_number); $summary_data = array(); $summary_data1 = array(); if($component == "Reading"){ $reading = $bandscore; $summary_data = array( "reading"=>$reading, "candidate_number"=>$candidate_number, "mock_key"=>$mock_key ); $summary_data1 = array( "reading"=>$bandscore ); }else if($component == "Listening"){ $listening = $bandscore; $summary_data = array( "listening"=>$listening, "candidate_number"=>$candidate_number, "mock_key"=>$mock_key ); $summary_data1 = array( "listening"=>$bandscore ); }else if($component == "WritingTask1"){ $writingTask1 = $bandscore; $summary_data = array( "writing_task_1"=>$writingTask1, "candidate_number"=>$candidate_number, "mock_key"=>$mock_key ); $summary_data1 = array( "writing_task_1"=>$bandscore ); }else if($component == "WritingTask2"){ $writingTask2 = $bandscore; $summary_data = array( "writing_task_2"=>$writingTask2, "candidate_number"=>$candidate_number, "mock_key"=>$mock_key ); $summary_data1 = array( "writing_task_2"=>$bandscore ); }else if($component == "GenReading"){ $generalreading = $bandscore; $summary_data = array( "generalreading"=>$generalreading, "candidate_number"=>$candidate_number, "mock_key"=>$mock_key ); $summary_data1 = array( "generalreading"=>$bandscore ); } if(!$results){ $success = $mock->add_mock($data); if(!$summary_results){ $mock->add_mock_summary($summary_data); $response = $mock->update_mock_summary($summary_data1,$mock_key,$candidate_number); }else{ $response = $mock->update_mock_summary($summary_data1,$mock_key,$candidate_number); } if($success){ echo json_encode( array("message"=>"success") ); } }else{ echo json_encode( array("message"=>"duplicate") ); } // echo json_encode( // array("full_name"=>" ".$full_name." ", // "component"=>" ".$component." ", // "marked_script"=>$marked_script) // ); }