From: Juliette W. <jv...@us...> - 2005-06-16 13:09:33
|
Update of /cvsroot/stack/stack-1-0/frontend_general In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28349/frontend_general Modified Files: Tag: frontend_dev qb_display.php Added Files: Tag: frontend_dev question_bank_util.php Log Message: Put code back into question_bank.php Index: qb_display.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/frontend_general/Attic/qb_display.php,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** qb_display.php 16 Jun 2005 11:44:45 -0000 1.1.2.1 --- qb_display.php 16 Jun 2005 13:09:23 -0000 1.1.2.2 *************** *** 53,55 **** --- 53,103 ---- } + + + function stack_import_questions_screen($errors) { + echo nsf($errors,'upload_xml_file'); + echo "Select a file to upload and edit: + <br /> + <form enctype='multipart/form-data' action=\"question_bank.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"; + } + + + function stack_show_uploaded_questions_screen($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) { + + 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>"; + } else { + echo "<td><font color=\"greed\">Valid question</font></td>"; + } + echo "</tr>\n"; + } + + // HACK: we need error trapping here. + // HACK: we should return to the user details of what has been uploaded! + + echo "</tbody></table>\n"; + echo "<h2>Current database of questions</h2>"; + } ?> --- NEW FILE: question_bank_util.php --- <?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... * * * This file contains the logic of interactions with the site as * an editor of questions and the question bank. * * @package frontend * @subpackage Stack */ function stack_get_question_from_session() { global $stackQuestion; $question = NULL; // Get any $question from the current $_SESSION if (array_key_exists('question',$_SESSION)) { foreach ($stackQuestion as $qfield => $val) { if (array_key_exists($qfield,$_SESSION['question'])) { if ('' != $_SESSION['question'][$qfield]) { $question[$qfield] = $_SESSION['question'][$qfield]; } } } unset($_SESSION['question']); } return $question; } function stack_get_questionInst() { $questionInst = NULL; // Get any $questionInst from the current $_SESSION if (array_key_exists('questionInst',$_SESSION)) { $questionInst=$_SESSION['questionInst']; unset($_SESSION['questionInst']); } return $questionInst; } function stack_get_question_from_post() { global $stackQuestion; $question = NULL; // Get any $_POSTED data // This should over write any $_SESSION data, as it may have been entered in a form. foreach($stackQuestion as $qfield => $attribs) { if (array_key_exists($qfield,$_POST) ) { if ('questionOptions' == $qfield) { $question[$qfield] = $_POST[$qfield]; } else if ('questionPotResp' == $qfield ) { $question[$qfield] = $_POST[$qfield]; } else if ( '' !=trim($_POST[$qfield]) ) { // We need this: all fields on form will be present in $_POST. $question[$qfield] = $_POST[$qfield]; } } } return $question; } // $source should be 'from database', 'new' or 'default' function stack_get_question($source) { $question = NULL; // $_POSTED data should over write any $_SESSION data, as it may have been // entered in a form. if ('default' == $source) { $question = stack_get_question_from_session(); $question = stack_get_question_from_post(); } else if ('database' == $source) { $questionID = $_POST['questionID']; $question=stack_db_getquestion($questionID); } if ('new' == $source or NULL == $question) { $question['questionID']='0'; $question['questionAnsKey']='ans1'; } return $question; } // This function also sets $SESSION['bank_filter'] if required function stack_get_questionbank_filter() { $question_bank_filter = ''; if (array_key_exists('bank_filter',$_SESSION)) { $question_bank_filter = $_SESSION['bank_filter']; } if (array_key_exists('bank_filter',$_POST)) { $question_bank_filter = $_POST['bank_filter']; $_SESSION['bank_filter'] = $question_bank_filter; } return $question_bank_filter; } function stack_get_selected_questions() { $quiz = NULL; if (array_key_exists('checked',$_POST)) { if (is_array($_POST['checked'])) { foreach ($_POST['checked'] as $quID => $val) { if ('ticked' == $val) { $quiz[] = $quID; } } } } return $quiz; } ?> |