From: Juliette W. <jv...@us...> - 2005-06-16 12:35:43
|
Update of /cvsroot/stack/stack-1-0 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8925 Modified Files: Tag: frontend_dev import_question_screen.php qb_display.php qb_export.php question_bank_util.php upload_questions.php Log Message: Tidying up export and import code Index: qb_export.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/Attic/qb_export.php,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** qb_export.php 16 Jun 2005 10:59:34 -0000 1.1.2.2 --- qb_export.php 16 Jun 2005 12:35:34 -0000 1.1.2.3 *************** *** 1,36 **** <?php if ('export_xml_list'==$action) { ! $quiz = NULL; ! if (array_key_exists('checked',$_POST)) { ! if (is_array($_POST['checked'])) { ! foreach ($_POST['checked'] as $quID => $val) { ! if ('ticked' == $val) { ! $quiz[] = $quID; ! } ! } ! } ! } ! ! if (NULL == $quiz) { ! stack_print_questionbank_no_questions_screen(); ! $action = 'questionbank_screen'; ! } ! ! include_once("{$stack_root}/scripts/stackXML.php"); ! ! $name = stack_xml_write_quiz_file($quiz, "{$stack_root}/tmp/"); ! ! stack_print_download_export_screen($name); } if ('export_xml'==$action) { ! echo "export_xml"; ! stack_question_validate($question,$errors); ! include_once("{$stack_root}/scripts/stackXML.php"); ! $name = stack_xml_write_question_file($question, "{$stack_root}/tmp/"); stack_print_download_export_screen($name); } ?> --- 1,34 ---- <?php + $multiple_questions = FALSE; + if ('export_xml_list'==$action) { ! $multiple_questions = TRUE; ! $action = 'export_xml'; } if ('export_xml'==$action) { ! if ($multiple_questions) { ! $questions_to_export = stack_get_selected_questions(); ! if (NULL == $questions_to_export) { ! stack_print_questionbank_no_questions_screen(); ! $action = 'questionbank_screen'; ! } ! } else { ! stack_question_validate($question,$errors); ! include_once("{$stack_root}/scripts/stackXML.php"); ! } ! include_once("{$stack_root}/scripts/stackXML.php"); + if ($multiple_questions) { + $name = stack_xml_write_quiz_file($questions_to_export, "{$stack_root}/tmp/"); + } else { + $name = stack_xml_write_question_file($question, "{$stack_root}/tmp/"); + } stack_print_download_export_screen($name); } + + + ?> Index: qb_display.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/Attic/qb_display.php,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** qb_display.php 16 Jun 2005 10:59:34 -0000 1.1.2.3 --- qb_display.php 16 Jun 2005 12:35:34 -0000 1.1.2.4 *************** *** 53,55 **** --- 53,102 ---- } + + function stack_import_questions_screen($errors) { + echo nsf($errors,'upload_xml_file'); + echo "Select a file to upload and edit: + <br /> + <form enctype='multipart/form-data' action=\"question_bank.php\"' method='POST'><br />\n + <input type ='file' name='xmlfile' />\n + <input type ='hidden' name='action' value='upload_xml_file' /> + <input type ='submit' name='go' value='Upload'> + </form>\n\n"; + } + + + function stack_show_uploaded_questions_screen($quiz, $qu) { + + echo "<h2>Details of questions uploaded</h2>"; + echo '<table><thead><tr>'; + echo '<th>ID</th><th>Name</th> <th>Description</th> <th>Key words</th> <th></th>'; + echo '</tr></thead><tbody>'; + + $errs = NULL; + + foreach ($quiz as $key => $qu) { + + stack_question_validate($quiz[$key],$errs[$key]); + $qu['questionID'] = stack_db_addquestion($qu); + echo "<tr>\n <td>".sf($qu,'questionID')."</td> <td>".sf($qu,'questionName')." </td> <td>".sf($qu,'questionDescription')." </td> <td>".sf($qu,'questionKeywords')." </td>"; + $errc = FALSE; + if (nsf($errs,$key)) { + if (is_array($errs[$key])) { + $errc = TRUE; + } + } + if ($errc) { + echo "<td><font color=\"red\">Invalid question</font></td>"; + } else { + echo "<td><font color=\"greed\">Valid question</font></td>"; + } + echo "</tr>\n"; + } + + // HACK: we need error trapping here. + // HACK: we should return to the user details of what has been uploaded! + + echo "</tbody></table>\n"; + echo "<h2>Current database of questions</h2>"; + } ?> Index: upload_questions.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/Attic/upload_questions.php,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** upload_questions.php 15 Jun 2005 16:01:30 -0000 1.1.2.1 --- upload_questions.php 16 Jun 2005 12:35:34 -0000 1.1.2.2 *************** *** 1,4 **** --- 1,7 ---- <?php + + include_once('qb_display.php'); + if (array_key_exists('xmlfile',$_FILES)) { if (is_uploaded_file($_FILES['xmlfile']['tmp_name'])) { *************** *** 16,55 **** // (1) a quiz of questions. Store each in the database. } else if (array_key_exists('mathQuiz',$qu)) { - $quiz = $qu['mathQuiz']['assessmentItem']; ! ! echo "<h2>Details of questions uploaded</h2>"; ! echo '<table><thead><tr>'; ! echo '<th>ID</th><th>Name</th> <th>Description</th> <th>Key words</th> <th></th>'; ! echo '</tr></thead><tbody>'; ! ! $errs = NULL; ! ! foreach ($quiz as $key => $qu) { ! ! stack_question_validate($quiz[$key],$errs[$key]); ! $qu['questionID'] = stack_db_addquestion($qu); ! echo "<tr>\n <td>".sf($qu,'questionID')."</td> <td>".sf($qu,'questionName')." </td> <td>".sf($qu,'questionDescription')." </td> <td>".sf($qu,'questionKeywords')." </td>"; ! $errc = FALSE; ! if (nsf($errs,$key)) { ! if (is_array($errs[$key])) { ! $errc = TRUE; ! } ! } ! if ($errc) { ! echo "<td><font color=\"red\">Invalid question</font></td>"; ! } else { ! echo "<td><font color=\"greed\">Valid question</font></td>"; ! } ! echo "</tr>\n"; ! } ! ! // HACK: we need error trapping here. ! // HACK: we should return to the user details of what has been uploaded! ! ! echo "</tbody></table>\n"; ! echo "<h2>Current database of questions</h2>"; ! ! } else { $error['upload_xml_file']='<p>Could not extract a question from your uploaded file. Please edit your file carefully and try again.</p>'; --- 19,24 ---- // (1) a quiz of questions. Store each in the database. } else if (array_key_exists('mathQuiz',$qu)) { $quiz = $qu['mathQuiz']['assessmentItem']; ! stack_show_uploaded_questions_screen($quiz. $qu); } else { $error['upload_xml_file']='<p>Could not extract a question from your uploaded file. Please edit your file carefully and try again.</p>'; Index: question_bank_util.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/Attic/question_bank_util.php,v retrieving revision 1.1.2.7 retrieving revision 1.1.2.8 diff -C2 -d -r1.1.2.7 -r1.1.2.8 *** question_bank_util.php 16 Jun 2005 10:59:34 -0000 1.1.2.7 --- question_bank_util.php 16 Jun 2005 12:35:34 -0000 1.1.2.8 *************** *** 121,124 **** --- 121,138 ---- } + function stack_get_selected_questions() { + $quiz = NULL; + if (array_key_exists('checked',$_POST)) { + if (is_array($_POST['checked'])) { + foreach ($_POST['checked'] as $quID => $val) { + if ('ticked' == $val) { + $quiz[] = $quID; + } + } + } + } + + return $quiz; + } Index: import_question_screen.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/Attic/import_question_screen.php,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** import_question_screen.php 16 Jun 2005 11:44:44 -0000 1.1.2.2 --- import_question_screen.php 16 Jun 2005 12:35:34 -0000 1.1.2.3 *************** *** 26,29 **** --- 26,30 ---- $default_action = ''; include($stack_root.'/frontend_general/process_input.php'); + include_once('qb_display.php'); ////////////////////////////////////////////////////////////// *************** *** 33,49 **** include('html/pagehead.php'); ! ! if ('upload_xml_file' == $action) { ! echo nsf($errors,'upload_xml_file'); ! ! ! echo "Select a file to upload and edit: ! <br /> ! <form enctype='multipart/form-data' action=\"question_bank.php\"' method='POST'><br />\n ! <input type ='file' name='xmlfile' />\n ! <input type ='hidden' name='action' value='upload_xml_file' /> ! <input type ='submit' name='go' value='Upload'> ! </form>\n\n"; ! } include('html/pagefoot.php'); --- 34,40 ---- include('html/pagehead.php'); ! if ('upload_xml_file' == $action) { ! stack_import_questions_screen($errors); ! } include('html/pagefoot.php'); |