From: pkiddie <pk...@us...> - 2005-08-16 22:43:43
|
Update of /cvsroot/stack/stack-1-0 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23459 Modified Files: Tag: development_xmlrqp import.php Log Message: ShowSol removed from documentation Importing questions and question lists New functions in stackXML to define an order schema attribute, and keyval order attribute. Use of attributes in potential responses and questionVars Index: import.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/Attic/import.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.php 16 Aug 2005 15:24:16 -0000 1.1.2.2 --- import.php 16 Aug 2005 22:43:28 -0000 1.1.2.3 *************** *** 1,138 **** ! <?php ! ! /** Provides the front end interactions for the import functionality, and then returns the user to the correct page, i.e. if they ! are uploading a question,quiz or list of questions ! */ ! ! session_start(); ! ! require_once("other/ListMenu.php"); ! require_once("stackstd.php"); ! ! require_once("{$stack_root}/html/trypopupform.html"); ! require_once("{$stack_root}/frontend_general/editquiz_display.php"); ! require_once("{$stack_root}/html/helpform.php"); ! require_once("{$stack_root}/html/quizjava.html"); ! require_once("{$stack_root}/scripts/stackAuthor.php"); ! ! ! /////////////////////////////////////////////////////////////// ! // (1) Process Input - this sets $action, $user and $username ! /////////////////////////////////////////////////////////////// ! $default_action = 'import'; ! include('frontend_general/process_input.php'); ! ! //include_once('frontend_general/edit_quiz_util.php'); ! $PostTo = 'import.php'; ! $filter = ''; ! $quizid = NULL; ! ! include('html/pagehead.php'); ! ! if (!stack_user_is_admin($user) or !stack_is_logged_in($user)) { ! stack_display_editquiz_error_not_admin($user); ! include('html/pagefoot.php'); ! die(); ! } ! ! $upload_successful = FALSE; ! if ($action == 'uploaded_xml') { ! if (array_key_exists('xmlfile',$_FILES)) { ! if (is_uploaded_file($_FILES['xmlfile']['tmp_name'])) { ! ! include_once("{$stack_root}/scripts/stackXML.php"); ! $qu = stack_xml_parse_file($_FILES['xmlfile']['tmp_name']); ! // If a single question has been uploaded, edit it, if multiple ! // questions store them in the database ! show_array($qu); ! ! if (array_key_exists('assessmentItem',$qu)) { ! $imported= $qu['assessmentItem']; ! //$action = 'edit'; ! //$upload_successful = TRUE; ! ! } else if (array_key_exists('mathQuiz',$qu)) { ! $imported = $qu['mathQuiz']; ! //We need to be able to discern between a quiz and a list of questions. ! //A quiz will have arraykeys other than assessment items ! } ! ! $upload_successful = TRUE; ! } ! } ! } ! ! switch ($action) { ! case 'import': ! stack_display_import($errors); ! break; ! ! case 'uploaded_xml': ! if ($upload_successful) { ! stack_display_show_imported($imported); ! } ! break; ! } ! ! /** ! * Displays the form for importing a file ! * @return void ! */ ! function stack_display_import($errors) { ! echo nsf($errors,'import'); ! echo "Select a file to upload and edit: ! <br /> ! <form enctype='multipart/form-data' action=\"import.php\"' method='POST'><br />\n ! <input type ='file' name='xmlfile' />\n ! <input type ='hidden' name='action' value='uploaded_xml' /> ! <input type ='submit' name='go' value='Upload'> ! </form>\n\n"; ! } ! ! /** ! * Displays the imported questions ! * @param array $quiz The imported quiz ! * @return void ! */ ! function stack_display_show_imported($imported) { ! show_array($imported); ! //if (array_key_exists('assessmentItem',$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 ($question 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>"; ! echo "</tr></tbody></table>\n\n"; ! echo stack_question_errstr($errs[$key]); ! echo "\n\n<table><thead><tr>"; ! echo '<th>ID</th><th>Name</th> <th>Description</th> <th>Key words</th> <th></th>'; ! echo '</tr></thead><tbody>'; ! } else { ! echo "<td><font color=\"greed\">Valid question</font></td>"; ! } ! echo "</tr>\n"; ! } ! ! echo "</tbody></table>\n"; ! echo "<h2>Current database of questions</h2>";*/ ! } ! ! ?> --- 1,412 ---- ! <?php ! ! ! ! /** Provides the front end interactions for the import functionality, and then returns the user to the correct page, i.e. if they ! ! are uploading a question,quiz or list of questions ! ! */ ! ! ! ! session_start(); ! ! require_once("other/ListMenu.php"); ! ! include('stackstd.php'); ! ! ! ! require_once("{$stack_root}/html/trypopupform.html"); ! ! require_once("{$stack_root}/frontend_general/editquiz_display.php"); ! ! require_once("{$stack_root}/html/helpform.php"); ! ! require_once("{$stack_root}/html/quizjava.html"); ! ! require_once("{$stack_root}/scripts/stackAuthor.php"); ! ! ! ! ! ! /////////////////////////////////////////////////////////////// ! ! // (1) Process Input - this sets $action, $user and $username ! ! /////////////////////////////////////////////////////////////// ! ! $default_action = 'import'; ! ! include('frontend_general/process_input.php'); ! ! ! ! //include_once('frontend_general/edit_quiz_util.php'); ! ! $PostTo = 'import.php'; ! ! $filter = ''; ! ! $quizid = NULL; ! ! ! ! include('html/pagehead.php'); ! ! ! ! if (!stack_user_is_admin($user) or !stack_is_logged_in($user)) { ! ! stack_display_editquiz_error_not_admin($user); ! ! include('html/pagefoot.php'); ! ! die(); ! ! } ! ! ! ! $upload_successful = FALSE; ! ! if ($action == 'uploaded_xml') { ! ! if (array_key_exists('xmlfile',$_FILES)) { ! ! if (is_uploaded_file($_FILES['xmlfile']['tmp_name'])) { ! ! ! ! include_once("{$stack_root}/scripts/stackXML.php"); ! ! $imported = stack_xml_parse_file($_FILES['xmlfile']['tmp_name']); ! ! // If a single question has been uploaded, edit it, if multiple ! ! // questions store them in the database ! ! $upload_successful = TRUE; ! ! } ! ! } ! ! } ! ! ! ! switch ($action) { ! ! case 'import': ! ! stack_display_import($errors); ! ! break; ! ! ! ! case 'uploaded_xml': ! ! if ($upload_successful) { ! ! stack_display_parse_imported($imported); ! ! } ! ! break; ! ! } ! ! ! ! /** ! ! * Displays the form for importing a file ! ! * @return void ! ! */ ! ! function stack_display_import($errors) { ! ! echo nsf($errors,'import'); ! ! echo "Select a file to upload and edit: ! ! <br /> ! ! <form enctype='multipart/form-data' action=\"import.php\"' method='POST'><br />\n ! ! <input type ='file' name='xmlfile' />\n ! ! <input type ='hidden' name='action' value='uploaded_xml' /> ! ! <input type ='submit' name='go' value='Upload'> ! ! </form>\n\n"; ! ! } ! ! ! ! /** ! ! * Displays the imported questions ! ! * @param array $quiz The imported quiz ! ! * @return void ! ! */ ! ! function stack_display_parse_imported($imported) { ! ! global $stackQuiz; ! //show_array($imported); ! ! //First decide what has been imported ! //If it is a quiz/list of questions ! if (array_key_exists('mathQuiz',$imported)) ! { ! $quiz = $imported['mathQuiz']; ! ! $isQuiz=false; ! //Now check for quiz level components, like a GUID ! foreach($stackQuiz as $arrayKey=>$quizField) ! { ! show_array($arrayKey); ! show_array($imported); ! if (array_key_exists($arrayKey,$quiz)) ! { ! print_r("true"); ! $isQuiz = true; ! break; ! } ! } ! ! //At this point we are ready to decide if its a quiz or list of questions ! if ($isQuiz) { ! stack_display_show_imported_quiz($quiz); ! } ! ! else ! { ! //No quiz level metadata/options, thus is a list of questions ! $quiz=$imported['mathQuiz']['assessmentItem']; ! stack_display_show_imported_qulist($quiz); ! } ! } ! ! //Just double check it is a question ! else if (array_key_exists('assessmentItem',$imported)) ! { ! $question = $imported['assessmentItem']; ! ! stack_display_show_imported_question($question); ! } ! ! else ! { ! echo("No valid data could be read from this file"); ! } ! ! } ! ! function stack_display_show_imported_quiz($quiz) ! { ! echo "<h2>Details of quiz 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>'; ! ! //Validate quiz ! ! //Add quiz to database ! ! //Show quiz stuff to screen ! echo "<tr>\n <td>".sf($quiz,'quizID')."</td> <td>".sf($quiz,'quizName')." </td> <td>".sf($quiz,'quizDescription')." </td> <td>".sf($quiz,'quizKeywords')." </td>"; ! ! $errs = NULL; ! ! show_array($quiz); ! ! //Work on each question ! foreach ($quiz as $key => $qu) { ! ! /*if $key==('assessmentItem') ! stack_question_validate($quiz[$key],$errs[$key]); ! ! $qu['questionID'] = stack_db_question_add($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>"; ! ! echo "</tr></tbody></table>\n\n"; ! ! echo stack_question_errstr($errs[$key]); ! ! echo "\n\n<table><thead><tr>"; ! ! echo '<th>ID</th><th>Name</th> <th>Description</th> <th>Key words</th> <th></th>'; ! ! echo '</tr></thead><tbody>'; ! ! } else { ! ! echo "<td><font color=\"greed\">Valid question</font></td>"; ! ! } ! ! echo "</tr>\n"; ! ! }*/ ! } ! ! ! ! echo "</tbody></table>\n"; ! ! } ! ! function stack_display_show_imported_qulist($quiz) ! { ! 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) { ! ! show_array($qu); ! ! stack_question_validate($quiz[$key],$errs[$key]); ! ! $qu['questionID'] = stack_db_question_add($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>"; ! ! echo "</tr></tbody></table>\n\n"; ! ! echo stack_question_errstr($errs[$key]); ! ! echo "\n\n<table><thead><tr>"; ! ! echo '<th>ID</th><th>Name</th> <th>Description</th> <th>Key words</th> <th></th>'; ! ! echo '</tr></thead><tbody>'; ! ! } else { ! ! echo "<td><font color=\"greed\">Valid question</font></td>"; ! ! } ! ! echo "</tr>\n"; ! ! } ! ! ! ! echo "</tbody></table>\n"; ! } ! ! function stack_display_show_imported_question($question) ! { ! ! 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>'; ! ! show_array($question); ! ! stack_question_validate($question,$errs); ! ! $question['questionID'] = stack_db_question_add($question); ! ! echo "<tr>\n <td>".sf($question,'questionID')."</td> <td>".sf($question,'questionName')." </td> <td>".sf($question,'questionDescription')." </td> <td>".sf($question,'questionKeywords')." </td>"; ! ! $errc = FALSE; ! ! if (!empty($errs)) { ! ! $errc = TRUE; ! ! } ! ! if ($errc) { ! ! echo "<td><font color=\"red\">Invalid question</font></td>"; ! ! echo "</tr></tbody></table>\n\n"; ! ! echo stack_question_errstr($errs); ! ! echo "\n\n<table><thead><tr>"; ! ! echo '<th>ID</th><th>Name</th> <th>Description</th> <th>Key words</th> <th></th>'; ! ! echo '</tr></thead><tbody>'; ! ! } else { ! ! echo "<td><font color=\"greed\">Valid question</font></td>"; ! ! } ! ! echo "</tr>\n"; ! ! ! ! echo "</tbody></table>\n"; ! ! } ! ! ! ?> ! |