From: Juliette W. <jv...@us...> - 2005-06-15 16:01:38
|
Update of /cvsroot/stack/stack-1-0 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18735 Modified Files: Tag: frontend_dev question_bank.php question_bank_util.php Added Files: Tag: frontend_dev upload_questions.php Log Message: Minor changes --- NEW FILE: upload_questions.php --- <?php 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']; 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>"; } else { $error['upload_xml_file']='<p>Could not extract a question from your uploaded file. Please edit your file carefully and try again.</p>'; } } } ?> Index: question_bank_util.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/Attic/question_bank_util.php,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** question_bank_util.php 15 Jun 2005 13:34:36 -0000 1.1.2.2 --- question_bank_util.php 15 Jun 2005 16:01:30 -0000 1.1.2.3 *************** *** 44,48 **** } ! function stack_get_questionInst() { $questionInst = NULL; // Get any $questionInst from the current $_SESSION --- 44,48 ---- } ! function getQuestionInst() { $questionInst = NULL; // Get any $questionInst from the current $_SESSION Index: question_bank.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/question_bank.php,v retrieving revision 1.3.2.5 retrieving revision 1.3.2.6 diff -C2 -d -r1.3.2.5 -r1.3.2.6 *** question_bank.php 15 Jun 2005 13:34:36 -0000 1.3.2.5 --- question_bank.php 15 Jun 2005 16:01:30 -0000 1.3.2.6 *************** *** 29,33 **** /////////////////////////////////////////////////////////////// include('stackstd.php'); ! $default_action = 'startover'; include($stack_root.'/frontend_general/process_input.php'); include('html/trypopupform.html'); --- 29,33 ---- /////////////////////////////////////////////////////////////// include('stackstd.php'); ! $default_action = 'questionbank_screen'; include($stack_root.'/frontend_general/process_input.php'); include('html/trypopupform.html'); *************** *** 64,71 **** // action = edit_metadata Edit all the meta data fields in the question bank. ! // action = startover Begin again. include('html/pagehead.php'); $get_question = FALSE; --- 64,79 ---- // action = edit_metadata Edit all the meta data fields in the question bank. ! // action = questionbank_screen Begin again. include('html/pagehead.php'); + if ('admin' == $user['username']) { + $admin = TRUE; + } + + if ('startover' == $action) { + $action = 'questionbank_screen'; + } + $get_question = FALSE; *************** *** 88,92 **** if ($get_question) { $question = stack_get_question($source); ! $questionInst = stack_get_questionInst(); } --- 96,100 ---- if ($get_question) { $question = stack_get_question($source); ! $questionInst = getQuestionInst(); } *************** *** 94,154 **** // (2.4) Uploaded file. if ('upload_xml_file' == $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']; ! ! 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>"; ! $action = 'startover'; ! ! } else { ! $error['upload_xml_file']='<p>Could not extract a question from your uploaded file. Please edit your file carefully and try again.</p>'; ! } ! ! } ! } } // End (2.4) --- 102,107 ---- // (2.4) Uploaded file. if ('upload_xml_file' == $action) { ! include('upload_questions.php'); ! $action = 'questionbank_screen'; } // End (2.4) *************** *** 170,174 **** if (NULL == $quiz) { echo "<p>Could not get any ticked questions! Please try again.</p>"; ! $action = 'startover'; } --- 123,127 ---- if (NULL == $quiz) { echo "<p>Could not get any ticked questions! Please try again.</p>"; ! $action = 'questionbank_screen'; } *************** *** 184,188 **** // (2.7) action = edit_metadata if ('edit_metadata' == $action ) { ! if ( 'admin' != $user['username'] ) { echo "<p><font color='red'>Warning!</font> You are not the admin user and any changes will not be stored in the database.</p>"; } else { --- 137,141 ---- // (2.7) action = edit_metadata if ('edit_metadata' == $action ) { ! if (!$admin) { echo "<p><font color='red'>Warning!</font> You are not the admin user and any changes will not be stored in the database.</p>"; } else { *************** *** 209,216 **** if ('delete_from_db' == $action) { $questionID = $_POST['questionID']; ! if ('admin'==$user['username']) { stack_db_dropquestion($questionID); } ! $action = 'startover'; } --- 162,169 ---- if ('delete_from_db' == $action) { $questionID = $_POST['questionID']; ! if (!$admin) { stack_db_dropquestion($questionID); } ! $action = 'questionbank_screen'; } *************** *** 242,251 **** if ('store_in_db' == $action) { stack_db_addquestion($question); ! $action = 'startover'; } if ('store_new_db' == $action) { stack_db_addquestion($question,TRUE); ! $action = 'startover'; } --- 195,204 ---- 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'; } *************** *** 346,350 **** ! if ('startover'==$action) { session_unregister('question'); --- 299,303 ---- ! if ('questionbank_screen'==$action) { session_unregister('question'); *************** *** 353,357 **** $options = ''; ! if ('admin'==$user['username']) { stack_db_listquestions('edit',$question_bank_filter); --- 306,310 ---- $options = ''; ! if (!$admin) { stack_db_listquestions('edit',$question_bank_filter); |