From: Juliette W. <jv...@us...> - 2005-06-15 16:58:46
|
Update of /cvsroot/stack/stack-1-0 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19335 Modified Files: Tag: frontend_dev question_bank.php question_bank_util.php Added Files: Tag: frontend_dev qb_preview.php Log Message: Separated out some of the preview code from the question bank. There are quite a few errors still to fix. Index: question_bank_util.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/Attic/question_bank_util.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 *** question_bank_util.php 15 Jun 2005 16:01:30 -0000 1.1.2.3 --- question_bank_util.php 15 Jun 2005 16:58:36 -0000 1.1.2.4 *************** *** 85,88 **** --- 85,89 ---- // $source should be 'from database', 'new' or 'default' function stack_get_question($source) { + $question = NULL; *************** *** 95,99 **** $questionID = $_POST['questionID']; $question=stack_db_getquestion($questionID); ! } else if ('new' == $source) { $question['questionID']='0'; $question['questionAnsKey']='ans1'; --- 96,102 ---- $questionID = $_POST['questionID']; $question=stack_db_getquestion($questionID); ! } ! ! if ('new' == $source or NULL == $question) { $question['questionID']='0'; $question['questionAnsKey']='ans1'; --- NEW FILE: qb_preview.php --- <?php if ('new_version' == $action) { foreach ($stackQuestion as $qfield => $val) { if (array_key_exists($qfield,$questionInst)) { $question[$qfield] = $questionInst[$qfield]; } } unset($questionInst); $action = 'try'; } // These branches need the question to be validated if ('edit' == $action or 'try'==$action or 'export_xml'==$action) { stack_question_validate($question,$errors); } // Have the questions been marked? if ('mark' == $action or 'validate' == $action) { if (array_key_exists('RawAns',$_POST) ){ $RawAns=$_POST['RawAns']; } else { $error['RawAns'] = '<font color="red">You have not entered an answer!</font>'; } } if ('try'==$action && $database) { if (''==$errors) { $action='validate'; if (array_key_exists('seed',$_POST)) { $seed=$_POST['seed']; } else { // HACK: this should involve the concept of a user! $seed = time(); } $questionInst = stack_question_inst($question,$seed,$options,$errors); // For the purposes of this test, fill in the correct answer // Which must exist! // $RawAns = $questionInst['questionAnsInst']['value']; if (array_key_exists('RawAns',$_POST)) { $RawAns=$_POST['RawAns']; } if (''!=$errors) { $action='edit'; } } else { echo "Could not instantiate the question, because of errors. <br />Try to edit the question instead."; $action='edit'; } } // If we have just taken a question from the edit from, we need to instantiate it. if ('try'==$action) { if (''==$errors) { $action='mark'; $seed = time(); // HACK: this should involve the concept of a user! $questionInst = stack_question_inst($question,$seed,$options,$errors); // For the purposes of this test, fill in the correct answer // Which must exist! $RawAns = $questionInst['questionAnsInst']['value']; } if (''!=$errors) { $action='edit'; echo '<p>Could not instantiate the question, because of errors. <br />Try to edit the question instead.</p>'; //show_array($errors); } } // Now deal with a student's answer if ('mark'==$action or 'validate'==$action) { $this_attempt = stack_question_inst_mark($questionInst,$options,$RawAns,$errors); $this_attempt['Action']=$action; stack_question_add_attempt($questionInst,$this_attempt,$errors); } ?> Index: question_bank.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/question_bank.php,v retrieving revision 1.3.2.7 retrieving revision 1.3.2.8 diff -C2 -d -r1.3.2.7 -r1.3.2.8 *** question_bank.php 15 Jun 2005 16:39:53 -0000 1.3.2.7 --- question_bank.php 15 Jun 2005 16:58:36 -0000 1.3.2.8 *************** *** 189,210 **** } - // Change the $questionInst, to a $question - if ('new_version' == $action) { - - foreach ($stackQuestion as $qfield => $val) - { - if (array_key_exists($qfield,$questionInst)) - { - $question[$qfield] = $questionInst[$qfield]; - } - } - unset($questionInst); - - $action = 'try'; - } - // These branches need the question to be validated ! if ('edit' == $action or 'try'==$action or 'export_xml'==$action) { stack_question_validate($question,$errors); } --- 189,195 ---- } // These branches need the question to be validated ! if ('edit' == $action or 'export_xml'==$action) { stack_question_validate($question,$errors); } *************** *** 224,299 **** } ! // Have the questions been marked? ! if ('mark' == $action or 'validate' == $action) { ! ! if (array_key_exists('RawAns',$_POST) ){ ! $RawAns=$_POST['RawAns']; ! } ! else { ! $error['RawAns'] = '<font color="red">You have not entered an answer!</font>'; } ! } ! ! // If we have just taken a question from the db, we need to instantiate it. ! if ('try'==$action && $database) { ! if (''==$errors) { ! $action='validate'; ! ! if (array_key_exists('seed',$_POST)) { ! $seed=$_POST['seed']; ! } else { ! // HACK: this should involve the concept of a user! ! $seed = time(); ! } ! ! $questionInst = stack_question_inst($question,$seed,$options,$errors); ! // For the purposes of this test, fill in the correct answer ! // Which must exist! ! // $RawAns = $questionInst['questionAnsInst']['value']; ! ! if (array_key_exists('RawAns',$_POST)) { ! $RawAns=$_POST['RawAns']; ! } ! ! if (''!=$errors) { ! $action='edit'; ! } ! ! } ! else { ! echo "Could not instantiate the question, because of errors. ! <br />Try to edit the question instead."; ! $action='edit'; ! } ! } ! ! // If we have just taken a question from the edit from, we need to instantiate it. ! if ('try'==$action) { ! if (''==$errors) { ! $action='mark'; ! $seed = time(); // HACK: this should involve the concept of a user! ! $questionInst = stack_question_inst($question,$seed,$options,$errors); ! // For the purposes of this test, fill in the correct answer ! // Which must exist! ! $RawAns = $questionInst['questionAnsInst']['value']; ! } ! ! if (''!=$errors) { ! $action='edit'; ! echo '<p>Could not instantiate the question, because of errors. ! <br />Try to edit the question instead.</p>'; ! //show_array($errors); ! } ! ! } ! ! // Now deal with a student's answer ! if ('mark'==$action or 'validate'==$action) { ! ! $this_attempt = stack_question_inst_mark($questionInst,$options,$RawAns,$errors); ! $this_attempt['Action']=$action; ! stack_question_add_attempt($questionInst,$this_attempt,$errors); ! ! } ! //////////////////////////////////////////////// // (4) Go somewhere next. --- 209,214 ---- } ! // Deal with actions connected with previewing questions ! include('qb_preview.php'); //////////////////////////////////////////////// // (4) Go somewhere next. |