answerResponce == '') {
$ns->tablerender("Check answer", $this->answerResponce . '
');
header("Refresh:5");
return;
}
//load development area for main site admin only
if (check_class("Main Admin")&&false) {
$ns->tablerender('Start of Developments Area', '
');
require_once (e_PLUGIN . 'timekeeper/DevelopmentArea.php');
$ns->tablerender('End of Development Area', '
');
}
//Check user submitted answer
$submitButton = filter_input(INPUT_POST, 'Answered');
$answerText = filter_input(INPUT_POST, 'a1');
//print_a('-'.$answerText.'-');
if (isset($submitButton)&&!empty($answerText)) {
$AnswerChecker = new AnswerChecker();
$text = $AnswerChecker->checkAnswers();
$ns->tablerender("Check answer", $text . '
');
}
//print_a(['Development area'=>'head var','session'=>$_SESSION]);//============================= debug val
/////////////////////////////////////////
/// Student section
/////////////////////////////////////////
if (check_class("TIMEKEEPER_STUDENT")) {
$debugQ = false;
$countTotal = e107::getDb()->count("tkReport", "(id)", "username = '" . e107::getUser()->getLoginName() . "'");
$currentPercent = 0;
e107::getDb()->gen("SELECT COUNT(id) as cntr, CAST((SUM(correct)/COUNT(id)*10) as DECIMAL(5,2)) as percent
FROM e107.`e107_tkReport` WHERE username = '" . e107::getUser()->getLoginName() . "'
AND answereddatestamp >= unix_timestamp(CURRENT_DATE())
AND answereddatestamp <= unix_timestamp(CURRENT_DATE() + INTERVAL 1 DAY)");
$text .= '';
while ($row = e107::getDb()->fetch()) {
$currentPercent = (int)$row['percent'];
}
if(empty($_COOKIE['tkQuestion']))
{
// Instanciate the new queation engine with debug settings.
// 0 = Math
// 1 = English
$newQuestions = new subjects((int) ($countTotal / 26000), $currentPercent, $debugQ);
// get array of data for question
$rawQuestion = $newQuestions->getQuestion();
if ($debugQ) {
print_a(['rawQuestion'=>$rawQuestion,'countLevel'=>(int) ($countTotal / 26000),'rawPercent'=>$currentPercent,]);
}
setcookie('tkQuestion', base64_encode(json_encode($rawQuestion)), time()+7200);
}else if(json_decode($rawQuestion,true)==""){
setcookie('tkQuestion', "", time()+1);
header("Refresh:2");
print_a("Error: Blank question detected, resetting now. Please wait.");
}else{
//print_a('reuse session val.');
$cookieQuestion = $_COOKIE['tkQuestion'];
$rawQuestion = json_decode(base64_decode($cookieQuestion),true);
print_a(json_decode($rawQuestion,true));
}
include('forms.php');
$template = new forms($rawQuestion);
$tmpdata = $template->templater();
if ($debugQ) {
print_a($tmpdata);
}
// Get question from engine
$ns->tablerender("Question", $tmpdata);
// $this->MainEntry();
// $text = '';
// $subject = $this->subjectSelector();
// $year = $this->yearLevelSelector($subject);
//
//
// //Return random generated question
// $QG = new timekeeper_Question_Engine;
// $QG->subjectSelector = $subject;
// $QG->yearlevel = $year;
// $content = $QG->GetRandomQuestion();
// $text .= $content; //$this->renderQuestion($frm, $content);
// $ns->tablerender("Question (Do not use)", $text . '
');
}
/////////////////////////////////////////
/// Teacher section
/////////////////////////////////////////
if (check_class("TIMEKEEPER_TEACHER")) {
//$ns->tablerender("ExcelGenerator", $form->ExcelGenerator());
}
}
// private function subjectRandomizer() {
//
// $subjects = [
// 'english' => 0,
// 'pePd' => 0, //health-and-physical-education
// 'socialStudies' => 0, //humanities-and-social-sciences
// 'languages' => 0,
// 'mathematics' => 0,
// 'science' => 0,
// 'technologies' => 0,
// 'art' => 0,
// 'general' => 0 // general knowlage
// ];
// foreach ($this->activeSubjectsList as $key => $sub) {
// $subjects[$key] = $sub['timekeeper_percent'] + rand(0, 200 / $sub['timekeeper_yearLevel']);
// }
// //print_a($subjects);
// //print_a($this->activeSubjectsList);
// return $subjects;
// }
// private function subjectSelector() {
// $returnSubject = '';
// $returnScore = 0;
// foreach ($this->subjectRandomizer() as $sub => $score) {
// if ($returnScore <= $score && $score <> 0) {
// $returnSubject = $sub;
// $returnScore = $score;
// }
// }
// //print_a($returnSubject);
// // Add maths as the starting subject for new users
// if ($returnSubject === '') {
// $returnSubject = 'mathematics';
// }
// return $returnSubject;
// }
// private function yearLevelSelector($subject) {
// return 1;
// }
/**
* Main entry point for checking and updating the statistics and year levels.
*
* Description needed once finished....TODO
*
*/
// private function MainEntry() {
// $sql = e107::getDb();
// $userName = e107::getUser()->getLoginName();
//
// $this->GetActiveSubjects($sql, $userName);
// $this->GetActiveYearForSubjects($sql, $userName);
//
// $this->CheckSubjects($sql, $userName);
// }
/**
* Get a list of active subjects.
*
* Populate the private class variable $activeSubjectsList with an array of active subjects for use in statistics and question selection.
*
*/
// private function GetActiveSubjects($sql, $userName) {
// $this->activeSubjectsList = [];
//
// $sql->gen("SELECT DISTINCT `timekeeper_subject` FROM e107.e107_timekeeperReport WHERE `timekeeper_username`='$userName';");
// while ($row = $sql->fetch()) {
// $this->activeSubjectsList = array_merge($this->activeSubjectsList, [$row['timekeeper_subject'] => []]);
// }
// }
/**
* Get the year level and percentage for the active subjects
*
* Populate the private class variable $activeSubjectsList with the current year level and correct percentage for the current subjects.
*
*/
// private function GetActiveYearForSubjects($sql, $userName) {
//
// foreach ($this->activeSubjectsList as $subject => &$arrayHolder) {
// $selectQuery = '`timekeeper_username` = \'' . $userName . '\' AND `timekeeper_subject` = \'' . $subject . '\' ORDER BY `timekeeper_yearLevel` DESC';
// $arrayHolder = ($sql->retrieve('timekeeperStats', '`timekeeper_yearLevel`,`timekeeper_percent`', $selectQuery));
// }
// }
/**
* Check to see what subjects the user has answered questions for.
*
* This function gets a list of unique subjects from the `e107_timekeeperReport` database for the year level specified and uses that to get all answered questions for that subject to pass to 'UpdateYearAndStats'.
*
* @param int $yearlevel The year to check for records in the database.
*
*/
// private function CheckSubjects($sql, $userName) {
// $activeSubjects = array();
// $subjectToProcess = array();
//
// foreach ($this->activeSubjectsList as $subject => $dataArrays) {
// $tmpArray = array();
// $sql->gen("SELECT * FROM e107.e107_timekeeperReport WHERE `timekeeper_username`='$userName' AND `timekeeper_yearLevel`=" . $dataArrays['timekeeper_yearLevel'] . " AND `timekeeper_subject`= '" . $subject . "' ORDER BY 'timekeeper_answereddatestamp' DESC LIMIT 1000;");
// while ($row = $sql->fetch()) {
// array_push($tmpArray, $row);
// }
// $subjectToProcess = ['userName' => $userName, 'subject' => $subject, 'yearlevel' => $dataArrays['timekeeper_yearLevel'], 'rows' => $tmpArray];
// //print_a($subjectToProcess);
// $this->UpdateYearAndStats($sql, $subjectToProcess);
// }
// }
// private function BuildStatisticPdf($sql, $menuYear) {
// //print_a(['BuildStatisticMenu',$menuYear]);
// $userName = e107::getUser()->getLoginName();
// $sql->gen("SELECT `timekeeper_subject`,`timekeeper_percent`,`timekeeper_quantity` FROM e107_timekeeperStats WHERE `timekeeper_yearLevel`=$menuYear AND `timekeeper_username`='$userName';");
// $text = "