$entry) { // the order is id, question and the number of times each of the six answers was picked $fileData = $fileData . $id . ";"; for ($i = 0; $i < 6; $i++) $fileData = $fileData . $entry[$i] . ";"; $fileData = $fileData . $entry[6] . "\n"; } // write tutor data block identifier $fileData = $fileData . "###TutorData###\n"; // write all tutor data to the file foreach($tutorData as $id => $entry) { // the order is tutor name and the number of times each of the six answers was picked $fileData = $fileData . $id . ";"; for ($i = 0; $i < 5; $i++) $fileData = $fileData . $entry[$i] . ";"; $fileData = $fileData . $entry[5] . "\n"; } // write comment data block identifier $fileData = $fileData . "###CommentData###"; // write comment data foreach($commentData as $comment) // each comment is escapd by a new line containing three tilde characters $fileData = $fileData . "\n" . $comment . "\n~~~"; // write the generated data to the file and close it fwrite($handle, $fileData); fclose($handle); return true; } /** * Add the question data from the specified questionnaire form data to an existing form data array. * * @param array $formData The list of all form elements which for most cases will simply be the * $_POST array that has been submitted by the questionnaire form. * Passed by reference. * @param array $commentData The list of existing question data that will be appended by the question * Data of the form. Passed by reference. */ function AddQuestionData(&$formData, &$questionData, &$questionnaire) { foreach($formData as $id => $value) { if (!isset($questionnaire[$id])) continue; // get the type of the element with the same id as the form element from the questionnaire $type = $questionnaire[$id][0]; // check if the element is a question on continue with the next one if that is not the case if ($type != "Question") continue; // if there is not field for the current element in the question dsta array, create a new // blank field containing the question and zeros for the number of times each answer was picked if (array_key_exists($id, $questionData) == false) $questionData[$id] = array($questionnaire[$id][1], 0, 0, 0, 0, 0, 0); // increment the answer that was selected in the formular by one $questionData[$id][(int)$value]++; } } /** * Add the tutor data from the specified questionnaire form data to an existing tutor data array. * * @param array $formData The list of all form elements which for most cases will simply be the * $_POST array that has been submitted by the questionnaire form. * Passed by reference. * @param array $commentData The list of existing tutor data that will be appended by the tutor * Data of the form. Passed by reference. */ function AddTutorData(&$formData, &$tutorData) { // get the name of the tutor from the form $tutorName = $formData["tutorName"]; // get the selected answer of the tutorRating from the form $tutorValue = $formData["tutorRating"]; // if there is no field for the current tutor in the tutor array, create a new // nlank one with zeros for the number of times each answer was picked if (array_key_exists($tutorName, $tutorData) == false) $tutorData[$tutorName] = array(0, 0, 0, 0, 0, 0); // increment the answer that was selected in the form by one $tutorData[$tutorName][$tutorValue - 1]++; } /** * Add the comment data from the specified questionnaire form data to an existing comment data array. * * @param array $formData The list of all form elements which for most cases will simply be the * $_POST array that has been submitted by the questionnaire form. * Passed by reference. * @param array $commentData The list of existing comments that will be appended by the comment * Data of the form. Passed by reference. */ function AddCommentData(&$formData, &$commentData) { // if the comment field was filled, the comment // array is appended by the new comment if (array_key_exists("comment", $formData) && trim($formData["comment"]) != "") array_push($commentData, $formData["comment"]); } ?>