From: pkiddie <pk...@us...> - 2005-08-22 17:20:37
|
Update of /cvsroot/stack/stack-1-0 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3139 Modified Files: Tag: development_xmlrqp editquiz.php import.php index.php question_bank.php Log Message: Code comments added Schema version checking added to index.php Index: import.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/Attic/import.php,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -C2 -d -r1.1.2.6 -r1.1.2.7 *** import.php 19 Aug 2005 14:05:14 -0000 1.1.2.6 --- import.php 22 Aug 2005 17:20:18 -0000 1.1.2.7 *************** *** 1,122 **** <?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; ! $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 --- 1,113 ---- <?php ! /** ! * ! * Welcome to STACK. A system for teaching and assessment using a ! * computer algebra kernel. ! * <br> ! * This file is licensed under the GPL License. ! * <br> ! * A copy of the license is in your STACK distribution called ! * license.txt. If you are missing this file you can obtain ! * it from: ! * http://www.stack.bham.ac.uk/license.txt ! * <br> ! * Copyright (c) 2005, Christopher James Sangwin ! * ! * @author Chris Sangwin C.J...@bh... ! * @author Laura Naismith L.N...@bh... ! * @author Juliette White jv...@jv... ! * ! * 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 ! * <TODO> Returning the user to the correct page ! * <TODO> Errors should be placed into 'localised' documentation ! * <TODO> Is this right quiz GUID behaviour? ! * <TODO> Error errc and errs behaviour ! * <TODO> Quiz validation always returns true - stub function stack_quiz_validate ! * ! * @package frontend ! * @subpackage Stack ! */ 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"); ! //$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)) { //Only allow import where logged in user is admin stack_display_editquiz_error_not_admin($user); include('html/pagefoot.php'); die(); } ! $upload_successful = FALSE; ! $errors = ''; ! if ($action == 'uploaded_xml') { ! if (array_key_exists('xmlfile',$_FILES)) { ! if (is_uploaded_file($_FILES['xmlfile']['tmp_name'])) { //Check a file has actually been uploaded ! if (findtype($_FILES['xmlfile']['name'])=='xml') { //Only allow the uploading of files with 'xml' extension ! include_once("{$stack_root}/scripts/stackXML.php"); ! $imported = stack_xml_parse_file($_FILES['xmlfile']['tmp_name'],$errors); //Returns an array corresponding to 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 />"); ! } ! ! //Import is an array of values ! else { ! $upload_successful = TRUE; ! } ! } ! else { //extension is not XML ! echo("<font color=\"red\">The selected file is not an XML file</font><br /><br />"); } } ! ! else { //no file selected to upload ! echo("<font color=\"red\">You have not selected an XML file to upload</font><br /><br />"); ! } } + } + + //Provides front-end logic depending on POST variable '$action' + switch ($action) { + case 'uploaded_xml': + if ($upload_successful) { + stack_display_parse_imported($imported); + break; + } + + else { //!upload_successful + $action='import'; + } + + case 'import': //initial import page + stack_display_import(); + break; + } /** ! * Returns the extension of the uploaded file * * @param string $file The filename of the file uploaded *************** *** 132,206 **** /** - * Displays the form for importing a file ! * @return void - */ ! ! function stack_display_import($errors) { ! ! echo nsf($errors,'import'); echo "Select an XML 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); --- 123,178 ---- /** * Displays the form for importing a file ! * * @return void */ ! function stack_display_import() { echo "Select an XML 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"; } /** ! * Parses the head element in order to detect what has just been uploaded - a quiz, question, or list of questions. ! * A quiz will have <mathQuiz> element and mathQuiz level metadata and options ! * A list of questions will have a <mathQuiz> element without mathQuiz level metadata and options ! * A question will have an <assessmentItem> element. ! * ! * @param array $imported The imported XML file in array format * @return void */ function stack_display_parse_imported($imported) { global $stackQuiz; ! //1. Decide what has been imported ! if (array_key_exists('mathQuiz',$imported)) //If it is a quiz/list of questions { $quiz = $imported['mathQuiz']; $isQuiz=false; ! ! //Check for quiz level components, like a GUID foreach($stackQuiz as $arrayKey=>$quizField) { ! if (array_key_exists($arrayKey,$quiz)) //If one quiz level metadata element exists, then it must be a quiz { $isQuiz = true; ! break; //no need to keep iterating } } ! //We are ready to decide if its a quiz or list of questions if ($isQuiz) { stack_display_show_imported_quiz($quiz); } ! else //!isQuiz { ! //List of questions $quiz=$imported['mathQuiz']['assessmentItem']; stack_display_show_imported_qulist($quiz); *************** *** 208,226 **** } ! //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) { --- 180,204 ---- } ! else if (array_key_exists('assessmentItem',$imported)) //A single question { $question = $imported['assessmentItem']; stack_display_show_imported_question($question); } ! else //If neither <mathQuiz> or <assessmentItem> is head element ! { //do not continue to parse array ! 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 />"); ! $action='import'; } } + /** + * Performs the actual import of a quiz file into STACK, and provided the front-end interaction + * to show a successful/unsuccessful import + * + * @param array $quiz A mathQuiz array + * @return void + */ function stack_display_show_imported_quiz($quiz) { *************** *** 232,241 **** 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)) { --- 210,218 ---- echo '</tr></thead><tbody>'; $errs = NULL; $errc = FALSE; ! stack_quiz_validate($quiz,$errs); // Validate quiz (TODO) ! stack_xml_reinstate_quiz_meta_defaults($quiz); // Reinstate any default (empty) metadata fields /*if (nsf($errs,$key)) { *************** *** 245,257 **** }*/ ! //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>"; --- 222,234 ---- }*/ ! //Each imported quiz should have a unique GUID; generate a new one here if (array_key_exists('quizGUID',$quiz)) { $quiz['quizGUID']=stack_generate_guid($stack_web_url) ; } ! //Add quiz to database & retrieve its new quizID to add question to respective quiz ! $quiz['quizid'] = stack_db_quiz_update($quiz); ! //Show quiz details on screen echo "<tr>\n <td>".sf($quiz,'quizid')."</td> <td>".sf($quiz,'quizName')." </td> <td>".sf($quiz,'quizDescription')." </td> <td>".sf($quiz,'quizKeywords')." </td>"; *************** *** 272,276 **** 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>'; --- 249,253 ---- echo "</tbody></table>\n"; //end of quiz table ! echo "<h2>Details of questions uploaded</h2>"; //Start of questions within quiz table echo '<table><thead><tr>'; echo '<th>ID</th><th>Name</th> <th>Description</th> <th>Key words</th> <th></th>'; *************** *** 279,288 **** $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; --- 256,265 ---- $errs = NULL; ! $quizQuestions = $quiz['assessmentItem']; //Point to assessmentItems only ! foreach ($quizQuestions as $key => $qu) { //Iterate through each question stack_question_validate($quizQuestions[$key],$errs[$key]); ! stack_xml_reinstate_question_meta_defaults($qu); //Reinstate any missing question metadata ! $qu['questionID'] = stack_db_question_add($qu); //Add question to db, and retrieve its new ID 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; *************** *** 305,314 **** //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> --- 282,291 ---- //For each valid question we must also add the question to the database ! stack_db_quiz_add_question($quiz['quizid'],$qu['questionID']); //For each question, add link from quiz to question } echo "</tr>\n"; } ! echo "</tbody></table>\n"; //end of question table //<TODO: Chris to implement these links> *************** *** 317,320 **** --- 294,304 ---- } + /** + * Performs the actual import of a question list file into STACK, and provide the front-end interaction + * to show a successful/unsuccessful import + * + * @param array $quiz A mathQuiz array + * @return void + */ function stack_display_show_imported_qulist($quiz) { *************** *** 326,330 **** $errs = NULL; ! foreach ($quiz as $key => $qu) { stack_question_validate($quiz[$key],$errs[$key]); --- 310,314 ---- $errs = NULL; ! foreach ($quiz as $key => $qu) { //Iterate through each question stack_question_validate($quiz[$key],$errs[$key]); *************** *** 359,362 **** --- 343,353 ---- } + /** + * Performs the actual import of a question file into STACK, and provide the front-end interaction + * to show a successful/unsuccessful import + * + * @param array $quiz A mathQuiz array + * @return void + */ function stack_display_show_imported_question($question) { *************** *** 368,372 **** 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 --- 359,362 ---- *************** *** 396,403 **** echo "<p><a href=\"javascript:void(0);\">Edit imported question</a> "; echo "<p><a href=\"javascript:void(0);\">View list of questions</a> "; - } - - ?> --- 386,390 ---- Index: editquiz.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/editquiz.php,v retrieving revision 1.13.2.5 retrieving revision 1.13.2.6 diff -C2 -d -r1.13.2.5 -r1.13.2.6 *** editquiz.php 19 Aug 2005 19:49:31 -0000 1.13.2.5 --- editquiz.php 22 Aug 2005 17:20:18 -0000 1.13.2.6 *************** *** 23,26 **** --- 23,28 ---- * algorithms- ideally we should have a function for each action on entry and * for display. + * - Automatically generated quiz metadata added + * <TODO> 'Export XML' link when editing quiz * @package frontend * @subpackage Stack *************** *** 99,104 **** if ('quiz_edit' == $action or 'quiz_edit_addqs' == $action) { - //show_array($_POST); - //How do we preserve hidden metadata in the quiz?? $quiz_source = 'post'; $quiz = stack_get_quiz('post', $quizid); --- 101,104 ---- *************** *** 145,149 **** if ('quiz_new' == $action) { $quiz['quizid'] = $quizid; ! //<TODO> Automatically generated quiz metadata $quiz['quizGUID'] = stack_generate_guid($stack_web_url); $quiz['quizFormat'] = 'text/xml; charset="utf-8"'; --- 145,150 ---- if ('quiz_new' == $action) { $quiz['quizid'] = $quizid; ! ! //Automatically generated quiz metadata added $quiz['quizGUID'] = stack_generate_guid($stack_web_url); $quiz['quizFormat'] = 'text/xml; charset="utf-8"'; Index: question_bank.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/question_bank.php,v retrieving revision 1.8.2.9 retrieving revision 1.8.2.10 diff -C2 -d -r1.8.2.9 -r1.8.2.10 *** question_bank.php 19 Aug 2005 19:49:31 -0000 1.8.2.9 --- question_bank.php 22 Aug 2005 17:20:18 -0000 1.8.2.10 *************** *** 22,25 **** --- 22,26 ---- * algorithms- ideally we should have a function for each action on entry and * for display. + * - Removed all references to import quiz * @package frontend * @subpackage Stack *************** *** 65,70 **** // export_xml_db Export single question as xml from the database. // export_xml_list Export the list of selected questions as a single XML file - // import Present a form to add file name to upload. - // uploaded_xml Deal with an uploaded file. // edit_metadata Edit all the meta data fields in the question bank. // questionbank_screen Begin again. --- 66,69 ---- *************** *** 131,155 **** // bank. This is not needed by all actions, but it is harmless to set it. $question_bank_filter = stack_get_questionbank_filter(); - - $upload_successful = FALSE; - if ('uploaded_xml' == $action) { - if (array_key_exists('xmlfile',$_FILES)) { - if (is_uploaded_file($_FILES['xmlfile']['tmp_name'])) { - - //$pq = file_get_contents($_FILES['xmlfile']['tmp_name']); - include_once("{$stack_root}/scripts/stackXML.php"); - $qu = stack_xml_parse_question_file($_FILES['xmlfile']['tmp_name']); - // If a single question has been uploaded, edit it, if multiple - // questions store them in the database - if (array_key_exists('assessmentItem',$qu)) { - $question = $qu['assessmentItem']; - $action = 'edit'; - } else if (array_key_exists('mathQuiz',$qu)) { - $quiz = $qu['mathQuiz']['assessmentItem']; - $upload_successful = TRUE; - } - } - } - } if ('export_xml' == $action) { --- 130,133 ---- *************** *** 213,227 **** $action = 'questionbank_screen'; break; - case 'uploaded_xml': - if ($upload_successful) { - stack_display_qb_show_imported($quiz); - } else { - echo '<p>Could not extract a question or quiz from your uploaded file. Please edit your file carefully and try again.</p>'; - } - $action = 'questionbank_screen'; - break; - case 'import': - stack_display_qb_import($errors); - break; case 'export_xml': if (NULL == $questions_to_export) { --- 191,194 ---- Index: index.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/index.php,v retrieving revision 1.23.2.2 retrieving revision 1.23.2.3 diff -C2 -d -r1.23.2.2 -r1.23.2.3 *** index.php 16 Aug 2005 15:51:35 -0000 1.23.2.2 --- index.php 22 Aug 2005 17:20:18 -0000 1.23.2.3 *************** *** 22,25 **** --- 22,26 ---- * algorithms- ideally we should have a function for each action on entry and * for display. + * - Added logic to view installation instructions if stackstd.php not dectected * @package Stack */ *************** *** 49,52 **** --- 50,60 ---- include($stack_root.'/frontend_general/process_input.php'); + //Initialisation + include_once('/scripts/stackXML.php'); + //1. Check that XML schemas are up to date + if (!stack_xml_check_schema_version("{$stack_root}/schemas/")) + { + stack_xml_update_schema("{$stack_root}/schemas/"); + } /////////////////////////////////////////////////////////////// |