From: pkiddie <pk...@us...> - 2005-08-19 14:05:23
|
Update of /cvsroot/stack/stack-1-0 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1372 Modified Files: Tag: development_xmlrqp import.php Log Message: STACK now uses new import script, and deals with questions, quizzes and question lists All echo'ing to screen removed Only accepts valid XML files, reporting to user any errors found Index: import.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/Attic/import.php,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -C2 -d -r1.1.2.5 -r1.1.2.6 *** import.php 17 Aug 2005 16:48:46 -0000 1.1.2.5 --- import.php 19 Aug 2005 14:05:14 -0000 1.1.2.6 *************** *** 69,126 **** } ! ! ! $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; ! } - /** --- 69,134 ---- } ! $upload_successful = FALSE; ! $errors = ''; if ($action == 'uploaded_xml') { if (array_key_exists('xmlfile',$_FILES)) { if (is_uploaded_file($_FILES['xmlfile']['tmp_name'])) { ! if (findtype($_FILES['xmlfile']['name'])=='xml') { //Only allow the uploading of XML files ! include_once("{$stack_root}/scripts/stackXML.php"); ! $imported = stack_xml_parse_file($_FILES['xmlfile']['tmp_name'],$errors); //Returns an array version of imported XML ! ! //Incorrect XML file input, no [mathQuiz] or [assessmentItem] head element ! if (!$imported) { ! $upload_successful = FALSE; ! echo("<font color=\"red\">The XML file uploaded is not a question, question list or quiz</font><br />"); ! echo("<b>Further information: $errors</b><br /><br />"); ! } ! else { ! $upload_successful = TRUE; ! } ! } ! ! else ! { ! echo("<font color=\"red\">The selected file is not an XML file</font><br /><br />"); ! } } ! ! else { ! echo("<font color=\"red\">You have not selected an XML file to upload</font><br /><br />"); ! } } } switch ($action) { case 'uploaded_xml': + if ($upload_successful) { + stack_display_parse_imported($imported); + break; + } + + else { + $action='import'; + } + + case 'import': + stack_display_import($errors); + break; + } ! /** ! * This function returns the file extension of the file uploaded. ! * ! * @param string $file The filename of the file uploaded ! * @return string $type The uploaded file's extension ! */ ! function findtype($file) { ! $revfile = strrev($file); ! $type = strtolower( strrev(substr($revfile,0,strpos($revfile,"."))) ); ! return $type; ! } /** *************** *** 135,139 **** echo nsf($errors,'import'); ! echo "Select a file to upload and edit: <br /> --- 143,147 ---- echo nsf($errors,'import'); ! echo "Select an XML file to upload and edit: <br /> *************** *** 148,152 **** </form>\n\n"; - } --- 156,159 ---- *************** *** 178,186 **** foreach($stackQuiz as $arrayKey=>$quizField) { ! show_array($arrayKey); ! show_array($imported); if (array_key_exists($arrayKey,$quiz)) { ! print_r("true"); $isQuiz = true; break; --- 185,193 ---- foreach($stackQuiz as $arrayKey=>$quizField) { ! //show_array($arrayKey); ! //show_array($imported); if (array_key_exists($arrayKey,$quiz)) { ! //print_r("true"); $isQuiz = true; break; *************** *** 218,291 **** 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"; ! } --- 225,318 ---- function stack_display_show_imported_quiz($quiz) { + global $stack_web_url; + 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 + $errs = NULL; + $errc = FALSE; ! stack_quiz_validate($quiz,$errs); ! stack_xml_reinstate_quiz_meta_defaults($quiz); //Reinstate any default (empty) metadata fields ! /*if (nsf($errs,$key)) { ! if (is_array($errs[$key])) { ! $errc = TRUE; ! } ! }*/ ! //Add quiz to database, retrieve its new quizID, to add each question to the quiz ! //Each quiz should have a unique ID, so will generate a new one here ! if (array_key_exists('quizGUID',$quiz)) { ! $quiz['quizGUID']=stack_generate_guid($stack_web_url) ; ! } ! ! $quiz['quizid'] = stack_db_quiz_update($quiz); //retrieve the quiz id to add questions to that quiz ! //Show quiz details on screen screen ! echo "<tr>\n <td>".sf($quiz,'quizid')."</td> <td>".sf($quiz,'quizName')." </td> <td>".sf($quiz,'quizDescription')." </td> <td>".sf($quiz,'quizKeywords')." </td>"; ! ! if ($errc) ! { ! echo "<td><font color=\"red\">Invalid quiz</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 quiz</font></td>"; ! } ! ! echo "</tr>\n"; ! echo "</tbody></table>\n"; //end of quiz table ! 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; + $quizQuestions = $quiz['assessmentItem']; //now point to assessment items only + + foreach ($quizQuestions as $key => $qu) { + stack_question_validate($quizQuestions[$key],$errs[$key]); + stack_xml_reinstate_question_meta_defaults($qu); //Reinstate any missing metadata in order to all fields to database + $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>"; ! ! //For each valid question we must also add the question to the database ! stack_db_quiz_add_question($quiz['quizid'],$qu['questionID']); } echo "</tr>\n"; } echo "</tbody></table>\n"; ! ! //<TODO: Chris to implement these links> ! echo "<p><a href=\"javascript:void(0);\">Edit imported quiz</a> "; ! echo "<p><a href=\"javascript:void(0);\">View list of quizzes</a> "; } *************** *** 293,419 **** { 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]); stack_xml_reinstate_question_meta_defaults($qu); //Reinstate any missing metadata in order to all fields to database - - show_array($qu); - $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) { ! include("{$stack_root}/html/qselectform.php"); ! ! echo "<h2>Details of the 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); ! ! stack_xml_reinstate_question_meta_defaults($question); //Reinstate any missing metadata in order to all fields to database ! ! $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"; ! echo "<p><a href=\"javascript:SelectQs('export_xml_list');\">Edit imported question</a> "; ! echo "<p><a href=\"javascript:SelectQs('edit_metadata');\">View list of questions</a> "; } --- 320,399 ---- { 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]); stack_xml_reinstate_question_meta_defaults($qu); //Reinstate any missing metadata in order to all fields to database $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"; + + //<TODO: Chris to implement these links> + echo "<p><a href=\"javascript:void(0);\">View list of questions</a> "; } function stack_display_show_imported_question($question) { + //include("{$stack_root}/html/qselectform.php"); ! echo "<h2>Details of the uploaded question</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); ! stack_xml_reinstate_question_meta_defaults($question); //Reinstate any missing metadata in order to all fields to database ! $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"; ! //<TODO: Chris to implement these links> ! echo "<p><a href=\"javascript:void(0);\">Edit imported question</a> "; ! echo "<p><a href=\"javascript:void(0);\">View list of questions</a> "; } |