From: Juliette W. <jv...@us...> - 2005-06-16 13:49:34
|
Update of /cvsroot/stack/stack-1-0 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21154 Modified Files: Tag: frontend_dev question_bank.php Log Message: More question bank tidying up changes Index: question_bank.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/question_bank.php,v retrieving revision 1.3.2.16 retrieving revision 1.3.2.17 diff -C2 -d -r1.3.2.16 -r1.3.2.17 *** question_bank.php 16 Jun 2005 13:09:24 -0000 1.3.2.16 --- question_bank.php 16 Jun 2005 13:49:22 -0000 1.3.2.17 *************** *** 68,73 **** // action = questionbank_screen Begin again. ! include('html/pagehead.php'); ! $admin = FALSE; if ('admin' == $user['username']) { --- 68,76 ---- // action = questionbank_screen Begin again. ! ! ////////////////////////////////////////////////////////////// ! // (2) Perform any actions on entering the page ! ////////////////////////////////////////////////////////////// ! $admin = FALSE; if ('admin' == $user['username']) { *************** *** 117,163 **** } ! // (2.1) edit, try or store. ! // There should be a question in the $POST or $SESSION if ($get_question) { $question = stack_get_question($source); $questionInst = stack_get_questionInst(); } ! ! // (2.2) Work out the correct value for any filter to be applied to the ! // question bank. $question_bank_filter = stack_get_questionbank_filter(); ! if ('upload_xml_file' == $action) { ! stack_import_questions_screen($errors); ! } ! 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_string($pq); ! ! // Sort out what has been uploaded. ! // (0) a single question. Edit this. ! if (array_key_exists('assessmentItem',$qu)) { ! $question = $qu['assessmentItem']; ! ! $action = 'edit'; ! // (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); ! } else { ! $error['upload_xml_file']='<p>Could not extract a question from your uploaded file. Please edit your file carefully and try again.</p>'; } - - } - } - - $action = 'questionbank_screen'; } --- 120,153 ---- } ! // Get the question, question options and question instance if required if ($get_question) { $question = stack_get_question($source); + $options = stack_options_set($question); $questionInst = stack_get_questionInst(); } ! // Work out the correct value for any filter to be applied to the question ! // bank $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_string($pq); ! // 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; ! } ! } } } *************** *** 173,180 **** 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); --- 163,166 ---- *************** *** 189,197 **** $name = stack_xml_write_question_file($question, "{$stack_root}/tmp/"); } - stack_print_download_export_screen($name); } ! ! // (2.5) action = edit_metadata ! if ('edit_metadata' == $action ) { if (!$admin) { stack_print_not_admin(); --- 175,181 ---- $name = stack_xml_write_question_file($question, "{$stack_root}/tmp/"); } } ! ! if ('edit_metadata' == $action ) { if (!$admin) { stack_print_not_admin(); *************** *** 205,271 **** } } ! ! session_unregister('question'); ! session_unregister('questionInst'); ! ! stack_print_edit_metadata_screen($question_bank_filter); ! ! } ! ! ////////////////////////////////////////////////// ! // (3) Now we have a $question, set up the context ! ////////////////////////////////////////////////// ! ! // Change 'edit_from_db' to 'edit'. We are done here. ! ! ! // Delete a $question if ('delete_from_db' == $action) { $questionID = $_POST['questionID']; ! if (!$admin) { stack_db_dropquestion($questionID); } $action = 'questionbank_screen'; } ! ! // These branches need the question to be validated if ('edit' == $action) { stack_question_validate($question,$errors); } ! // We ignored any quiz and subject options! ! $options = stack_options_set($question); ! ! // Store any $question ! if ('store_in_db' == $action) { ! stack_db_addquestion($question); ! $action = 'questionbank_screen'; ! } ! ! if ('store_new_db' == $action) { ! stack_db_addquestion($question,TRUE); ! $action = 'questionbank_screen'; } // Deal with actions connected with previewing questions include('qb_preview.php'); ! ! if ('questionbank_screen'==$action) ! { session_unregister('question'); session_unregister('questionInst'); - - stack_print_question_bank_screen($admin, $question_bank_filter); - } - - //(4.2) Edit questions - if ('edit' == $action) { - stack_print_edit_screen($question, $errors); } - - - include('html/pagefoot.php'); ?> --- 189,269 ---- } } ! } ! if ('delete_from_db' == $action) { $questionID = $_POST['questionID']; ! if ($admin) { stack_db_dropquestion($questionID); } $action = 'questionbank_screen'; } + + if ('store_in_db' == $action) { + stack_db_addquestion($question); + $action = 'questionbank_screen'; + } ! if ('store_new_db' == $action) { ! stack_db_addquestion($question,TRUE); ! $action = 'questionbank_screen'; ! } ! if ('edit' == $action) { stack_question_validate($question,$errors); } + + ////////////////////////////////////////////////////////////// + // (3) Print the page. + ////////////////////////////////////////////////////////////// ! include('html/pagehead.php'); ! ! switch ($action) { ! case 'uploaded_xml': ! if ($upload_successful) { ! stack_show_uploaded_questions_screen($quiz); ! } else { ! stack_upload_error_screen(); ! } ! break; ! case 'upload_xml_file': ! stack_import_questions_screen($errors); ! break; ! case 'export_xml': ! if (NULL == $questions_to_export) { ! stack_print_questionbank_no_questions_screen(); ! $action = 'questionbank_screen'; ! } ! stack_print_download_export_screen($name); ! break; ! case 'edit_metadata': ! stack_print_edit_metadata_screen($question_bank_filter); ! break; } // Deal with actions connected with previewing questions include('qb_preview.php'); ! ! switch ($action) { ! case 'questionbank_screen': ! stack_print_question_bank_screen($admin, $question_bank_filter); ! break; ! case 'edit': ! stack_print_edit_screen($question, $errors); ! break; ! } ! ! include('html/pagefoot.php'); ! ////////////////////////////////////////////////////////////// ! // (3) Deal with any actions on leaving the page ! ////////////////////////////////////////////////////////////// ! ! ! if ('questionbank_screen'==$action or 'edit_metadata' == $action) ! { session_unregister('question'); session_unregister('questionInst'); } ?> |