#region generate form-data $formdata = array(); if (isset($exercise['choices'])) { $formtext = $exercise['choices']; foreach ($formtext as $formId => $choiceData2) { $form = new Form(); $form->setFormId($formId); $form->setExerciseId($exerciseId); $choiceText = $choiceData2; $choices = array(); foreach ($choiceText as $tempKey => $choiceData) { if (trim($choiceData) === '') { continue; } $choice = new Choice(); $choice->SetText(htmlentities(htmlentities(htmlspecialchars_decode($choiceData)))); $choice->SetFormId($formId); $choices[] = $choice; } if ($choices !== null && $choices !== array()) { $form->setChoices($choices); $formdata[] = $form; } } } #endregion if (isset($_FILES[$fileName]) || $formdata !== array()) { $error = 0; if (isset($_FILES[$fileName])) { $file = $_FILES[$fileName]; $error = $file['error'];
$replace = false; $replace = texify('$' . $mathTex . '$'); if ($replace === false) { $replace = '<img src="http://latex.codecogs.com/gif.latex?' . rawurlencode($mathTex) . '">'; } $solution = substr($solution, 0, $pos) . $replace . substr($solution, $pos2 + strlen($second)); } $pos = strpos($solution, $first, $pos + strlen($first) + strlen($second)); } $formId = isset($subexercise['formId']) ? $subexercise['formId'] : null; $form = Form::createForm($formId, $exerciseId, $solution, $task, isset($subexercise['type']) ? $subexercise['type'] : null); $choiceText = $subexercise['choice']; $choices = array(); foreach ($choiceText as $tempKey => $choiceData) { $choice = new Choice(); $choice->SetText($choiceData); $choices[$tempKey] = $choice; } if (isset($subexercise['correct'])) { $choiceCorrect = $subexercise['correct']; foreach ($choiceCorrect as $tempKey => $choiceData) { $keykey = $choiceData; if ($keykey == '') { $keykey = $tempKey; } if (isset($choices[$keykey])) { $choices[$keykey]->setCorrect(1); } } } if (isset($subexercise['choiceId'])) {