function array2Html($array, $table = true) { $out = ''; foreach ($array as $key => $value) { if (is_array($value)) { if (!isset($tableHeader)) { $tableHeader = '<th>' . implode('</th><th>', array_keys($value)) . '</th>'; } array_keys($value); $out .= '<tr>'; $out .= array2Html($value, false); $out .= '</tr>'; } else { $out .= "<td>{$value}</td>"; } } if ($table) { return '<table border="1">' . $tableHeader . $out . '</table>'; } else { return $out; } }
function version2Html($versionTextForTable, $product) { // This function creates an html data out of the version text, given the revelant information. // // param versionTextForTable : String of a single versions content // param product : the product name // return htmlTable : a string representation of an html table switch ($product) { case "Metafer": $versionNoteId = "/.{1,3}-\\d{1,6}-\\d{1,3}/"; // If the text contains any strings of the format if (preg_match_all($versionNoteId, $versionTextForTable, $versionNoteIdArray)) { $count = count($versionNoteIdArray[0]); for ($i = 0; $i < $count; $i++) { $beginDelimiter = $versionNoteIdArray[0][$i]; if (isset($versionNoteIdArray[0][$i + 1])) { $endDelimiter = $versionNoteIdArray[0][$i + 1]; } else { $endDelimiter = 'Version\\s.+\\s+finished'; } $output = preg_split('/(' . preg_quote($beginDelimiter) . '|' . preg_quote($endDelimiter) . ')/', $versionTextForTable); $noteType[$i] = preg_replace('/\\)(\\s*.+)+/', '', preg_replace('/^(\\s*:*\\s*\\()/', '', $output[1])); //fishes out the CIR/SFI, etc if (!preg_match('/[CIR|IBR|SFI|CCR]\\s\\d+\\/\\d+/', $noteType[$i])) { // if no noteType is available it is classified as N/A $noteType[$i] = "N/A"; } $noteText[$i] = preg_replace('/^(\\s*:*\\s*\\(.{1,4}\\s*\\d+\\/\\d+\\))/', '', $output[1]); // Fishes out the note text } } // Table Creation $numNoteIds = count($versionNoteIdArray[0]); $arrayForTable = array(); for ($i = 0; $i < $numNoteIds; $i++) { $arrayForTable[$i] = array('Note Id' => $versionNoteIdArray[0][$i], 'Note Type' => $noteType[$i], 'Note text' => nl2br(htmlspecialchars($noteText[$i])), 'Note Comments' => ''); } $htmlTable = array2Html($arrayForTable); break; case "VSViewer": $versionNoteId = "/.{1,3}-\\d{1,6}-\\d{1,3}/"; // If the text contains any strings of the format if (preg_match_all($versionNoteId, $versionTextForTable, $versionNoteIdArray)) { $count = count($versionNoteIdArray[0]); for ($i = 0; $i < $count; $i++) { $beginDelimiter = $versionNoteIdArray[0][$i]; if (isset($versionNoteIdArray[0][$i + 1])) { $endDelimiter = $versionNoteIdArray[0][$i + 1]; } else { $endDelimiter = 'Version\\s.+\\s+finished'; } $output = preg_split('/(' . preg_quote($beginDelimiter) . '|' . preg_quote($endDelimiter) . ')/', $versionTextForTable); $noteType[$i] = preg_replace('/\\)(\\s*.+)+/', '', preg_replace('/^(\\s*:*\\s*\\()/', '', $output[1])); //fishes out the CIR/SFI, etc if (!preg_match('/[CIR|IBR|SFI|CCR]\\s\\d+\\/\\d+/', $noteType[$i])) { // if no noteType is available it is classified as N/A $noteType[$i] = "N/A"; } // $noteText[$i] =(preg_replace('/^(\s*:\s*\(.+\)\s)/', '', $output[1])); // Fishes out the note text // $noteText[$i] =(preg_replace('/^(\s*:\s*\([CIR|IBR|SFI|CCR]\s\d+\/\d+\)\s)/', '', $output[1])); // Fishes out the note text $noteText[$i] = preg_replace('/^(\\s*:*\\s*\\(.{1,4}\\s*\\d+\\/\\d+\\))/', '', $output[1]); // Fishes out the note text } } // Table Creation $numNoteIds = count($versionNoteIdArray[0]); $arrayForTable = array(); for ($i = 0; $i < $numNoteIds; $i++) { $arrayForTable[$i] = array('Note Id' => $versionNoteIdArray[0][$i], 'Note Type' => $noteType[$i], 'Note text' => nl2br(htmlspecialchars($noteText[$i])), 'Note Comments' => ''); } $htmlTable = array2Html($arrayForTable); break; case "MetaClientServer": $versionNoteId = "/.{1,3}-\\d{1,6}-\\d{1,3}/"; // If the text contains any strings of the format if (preg_match_all($versionNoteId, $versionTextForTable, $versionNoteIdArray)) { $count = count($versionNoteIdArray[0]); for ($i = 0; $i < $count; $i++) { $beginDelimiter = $versionNoteIdArray[0][$i]; if (isset($versionNoteIdArray[0][$i + 1])) { $endDelimiter = $versionNoteIdArray[0][$i + 1]; } else { $endDelimiter = 'Version\\s.+\\s+finished'; } $output = preg_split('/(' . preg_quote($beginDelimiter) . '|' . preg_quote($endDelimiter) . ')/', $versionTextForTable); $noteType[$i] = preg_replace('/\\)(\\s*.+)+/', '', preg_replace('/^(\\s*:*\\s*\\()/', '', $output[1])); //fishes out the CIR/SFI, etc if (!preg_match('/[CIR|IBR|SFI|CCR]\\s\\d+\\/\\d+/', $noteType[$i])) { // if no noteType is available it is classified as N/A $noteType[$i] = "N/A"; } // $noteText[$i] =(preg_replace('/^(\s*:\s*\(.+\)\s)/', '', $output[1])); // Fishes out the note text // $noteText[$i] =(preg_replace('/^(\s*:\s*\([CIR|IBR|SFI|CCR]\s\d+\/\d+\)\s)/', '', $output[1])); // Fishes out the note text $noteText[$i] = preg_replace('/^(\\s*:*\\s*\\(.{1,4}\\s*\\d+\\/\\d+\\))/', '', $output[1]); // Fishes out the note text } } // Table Creation $numNoteIds = count($versionNoteIdArray[0]); $arrayForTable = array(); for ($i = 0; $i < $numNoteIds; $i++) { $arrayForTable[$i] = array('Note Id' => $versionNoteIdArray[0][$i], 'Note Type' => $noteType[$i], 'Note text' => nl2br(htmlspecialchars($noteText[$i])), 'Note Comments' => ''); } $htmlTable = array2Html($arrayForTable); break; case "Metasetup": $versionNoteId = "/.{1,3}-\\d{1,6}-\\d{1,3}/"; // If the text contains any strings of the format if (preg_match_all($versionNoteId, $versionTextForTable, $versionNoteIdArray)) { $count = count($versionNoteIdArray[0]); for ($i = 0; $i < $count; $i++) { $beginDelimiter = $versionNoteIdArray[0][$i]; if (isset($versionNoteIdArray[0][$i + 1])) { $endDelimiter = $versionNoteIdArray[0][$i + 1]; } else { $endDelimiter = '(\\/\\/--------------*\\n)$'; } $output = preg_split('/(' . preg_quote($beginDelimiter) . '|' . preg_quote($endDelimiter) . ')/', $versionTextForTable); $noteText[$i] = preg_replace('/\\s*\\/\\/------------*\\n*/', '', preg_replace('/^(\\s*:\\s*\\(.+\\)\\s)/', '', $output[1])); // Fishes out the note text // $noteType[$i] = (preg_replace('/(\)(\s*.+)+)/', '', preg_replace('/^(\s*:\s+\()/', '', $output[1]))); //fishes out the note code // if (!(preg_match('/[CIR|IBR|SFI|CCR]\s\d+\/\d+/', $noteType[$i]))) { // if no noteType is available it is classified as N/A // $noteType[$i] = "N/A"; // } } } // Table Creation $numNoteIds = count($versionNoteIdArray[0]); $arrayForTable = array(); for ($i = 0; $i < $numNoteIds; $i++) { $arrayForTable[$i] = array('Note Id' => $versionNoteIdArray[0][$i], 'Note text' => nl2br(htmlspecialchars($noteText[$i])), 'Note Comments' => ''); } $htmlTable = array2Html($arrayForTable); break; case "IkarosIsis": $versionNoteId = "/.{1,3}-\\d{1,6}[-\\d{1,3}]*/"; // If the text contains any strings of the format if (preg_match_all($versionNoteId, $versionTextForTable, $versionNoteIdArray)) { $count = count($versionNoteIdArray[0]); for ($i = 0; $i < $count; $i++) { $beginDelimiter = $versionNoteIdArray[0][$i]; if (isset($versionNoteIdArray[0][$i + 1])) { $endDelimiter = $versionNoteIdArray[0][$i + 1]; } else { $endDelimiter = 'Version\\s.+\\s+finished'; } $output = preg_split('/(' . preg_quote($beginDelimiter) . '|' . preg_quote($endDelimiter) . ')/', $versionTextForTable); $noteText[$i] = preg_replace('/^(\\s*:*\\s*\\(.+\\)\\s)/', '', $output[1]); // Fishes out the note text $noteType[$i] = preg_replace('/(\\)(\\s*.+)+)/', '', preg_replace('/^(\\s*:*\\s+\\()/', '', $output[1])); //fishes out the note code if (!preg_match('/[CIR|IBR|SFI|CCR]\\s\\d+\\/\\d+/', $noteType[$i])) { // if no noteType is available it is classified as N/A $noteType[$i] = "N/A"; } } } // Table Creation $numNoteIds = count($versionNoteIdArray[0]); $arrayForTable = array(); for ($i = 0; $i < $numNoteIds; $i++) { $arrayForTable[$i] = array('Note Id' => $versionNoteIdArray[0][$i], 'Note Type' => $noteType[$i], 'Note text' => nl2br(htmlspecialchars($noteText[$i])), 'Note Comments' => ''); } $htmlTable = array2Html($arrayForTable); break; default: die("Error determining product of relhis. Product Name input is:\n Metafer\n VSViewer\n MetaClientServer\n Metasetup\n IkarosIsis\n"); } return $htmlTable; }
} } $out .= '</tr>'; } return $out . '</table>'; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (p('action') == "logResult") { $stmt = $db->prepare("INSERT INTO result (student, quiz, time_taken, score) VALUES (?,?,?,?)"); $stmt->execute(array(p('student'), p('quiz'), p('time_taken'), p('score'))); //echo print_r($_POST); //echo print_r(getStudentScores($studentId)); //$stmt->rowCount(); $scores = getStudentScores($studentId); checkIfMastered($scores); echo array2Html($scores); } exit; } else { if ($_SERVER['REQUEST_METHOD'] === 'GET') { } } ?> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script type="text/javascript" src="mespeak.js"></script> <script src="https://www.google.com/jsapi"></script> <script type="text/javascript"> meSpeak.loadConfig("mespeak_config.json");