From: Juliette W. <jv...@us...> - 2005-06-16 16:51:02
|
Update of /cvsroot/stack/stack-1-0 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23419 Modified Files: Tag: frontend_dev editquiz.php index.php question_bank.php Log Message: I've broken some of the edit quiz code but want to save this before I leave work this evening! Index: editquiz.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/editquiz.php,v retrieving revision 1.10.2.6 retrieving revision 1.10.2.7 diff -C2 -d -r1.10.2.6 -r1.10.2.7 *** editquiz.php 16 Jun 2005 11:44:44 -0000 1.10.2.6 --- editquiz.php 16 Jun 2005 16:50:49 -0000 1.10.2.7 *************** *** 15,18 **** --- 15,19 ---- 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"); *************** *** 25,47 **** $default_action = 'quiz_choose'; include('frontend_general/process_input.php'); ! //$menu = new ListMenu('/'.$stack_basepath.'/',"html/stack-menu.txt"); ! $PostTo = 'editquiz.php'; ! $filter = ''; ! ! // $title = "Manage STACK quizzes"; ! // HACK: this should be $options['Display'], below but it is unset ! // stack_page_header($title,'LaTeX'); ! ! include('html/pagehead.php'); ! ! if ('admin' != $user['username'] or !$user['loggedin']) { ! echo "<h1>Not permitted!</h1>"; ! echo "<p>You need to be logged in as the admin to edit quizzes, but seem to be user {$user['username']}."; ! echo "<p>Please login <a href='index.php?action=login'>here</a></p>"; ! stack_page_footer(); die(); ! } //////////////////////////////////////////////// --- 26,42 ---- $default_action = 'quiz_choose'; include('frontend_general/process_input.php'); + include('frontend_general/frontend_util.php'); + include('frontend_general/edit_quiz_util.php'); + $PostTo = 'editquiz.php'; + $filter = ''; + $quizID = NULL; + include('html/pagehead.php'); ! if (!stack_user_is_admin($user) or !stack_is_logged_in($user)) { ! stack_quiz_edit_not_admin($user); ! include('html/pagefoot.php'); die(); ! } //////////////////////////////////////////////// *************** *** 58,92 **** // show_array($_POST); ! //////////////////////////////////////////////// ! // (3) Process incoming data ! //////////////////////////////////////////////// ! ! //show_array($_POST); ! ! if ('quiz_delete' == $action) { ! ! if (array_key_exists('quizID',$_POST)){ ! $quizID = $_POST['quizID']; ! stack_db_quiz_delete($quizID); ! $action = 'quiz_choose'; ! } ! } ! ! $question_bank_filter = ''; ! if (array_key_exists('bank_filter',$_SESSION)) { ! $question_bank_filter = $_SESSION['bank_filter']; } ! ! if ('filter' == $action) { ! ! if (array_key_exists('quizID',$_POST)){ ! $quizID = $_POST['quizID']; ! $question_bank_filter = $_POST['bank_filter']; ! $action = 'quiz_edit_addqs'; ! $_SESSION['bank_filter'] = $question_bank_filter; ! } ! } ! ! if ('quiz_edit' == $action or 'quiz_edit_addqs' == $action) { if (array_key_exists('quiz',$_POST)) { --- 53,69 ---- // show_array($_POST); ! echo "Action is $action"; ! $quizid_source = ''; ! if ('quiz_delete' == $action or 'filter' == $action) { ! $quizid_source = 'post'; ! } else if ('quiz_edit' == $action or 'quiz_edit_addqs' == $action) { ! $quizid_source = 'quiz'; ! } else if ('quiz_new' == $action) { ! $quizid_source = 'database'; } ! ! $quizID = stack_get_quizID($quizid_source); ! ! if ('quiz_edit' == $action or 'quiz_edit_addqs' == $action) { if (array_key_exists('quiz',$_POST)) { *************** *** 100,122 **** } if ('quiz_edit' == $action) { ! // Do we need to add questions to the quiz? if (array_key_exists('questionsToAdd',$_POST)) { - $quiz['questionsToAdd'] = array_keys($_POST['questionsToAdd']); - } } if ('quiz_edit' == $action or 'quiz_edit_addqs' == $action) { - stack_quiz_edit($quiz,$errors); - } if ('quiz_new' == $action) { - - $quizID = stack_db_quiz_update(array()); $quiz['quizID'] = $quizID; $action = 'quiz_edit'; --- 77,117 ---- } + + echo $quizID; + + if ('filter' == $action) { + $filter_source = 'post'; + } else { + $filter_source = 'session'; + } + + $question_bank_filter = stack_get_question_bank_filter($filter_source); + + if ('quiz_delete' == $action and $quizID != NULL) { + stack_db_quiz_delete($quizID); + $action = 'quiz_choose'; + } + + if ('filter' == $action and $quizID != NULL) { + $action = 'quiz_edit_addqs'; + stack_set_session_question_bank_filter($question_bank_filter); + } + + if ('quiz_edit' == $action or 'quiz_edit_addqs' == $action) { + $quiz = stack_get_quiz(); + } if ('quiz_edit' == $action) { ! // Do we need to add questions to the quiz? if (array_key_exists('questionsToAdd',$_POST)) { $quiz['questionsToAdd'] = array_keys($_POST['questionsToAdd']); } } if ('quiz_edit' == $action or 'quiz_edit_addqs' == $action) { stack_quiz_edit($quiz,$errors); } if ('quiz_new' == $action) { $quiz['quizID'] = $quizID; $action = 'quiz_edit'; *************** *** 127,200 **** //////////////////////////////////////////////// ! echo "<font color=\"red\">"; show_array($errors); ! echo "</font>"; ! ! ! if ('quiz_choose' == $action) { ! ! $quiz_store = stack_db_quiz_get(); ! ! if (is_array($quiz_store)) { ! echo "<p>\n<form name='quizform' action='$PostTo' method='POST'> ! <input type='hidden' name='quizID' value='-1' /> ! <input type='hidden' name='action' value='quiz_choose' />"; ! ! echo "\n<table cellpadding='2'>\n"; ! echo "\n<tr><th></th><th>{$stackQuiz['quizName']['descript']}</th><th>{$stackQuiz['quizDescription']['descript']}</th><th></th></tr>"; ! foreach ($quiz_store as $qs => $quiz) ! { ! $qname = $quiz['quizName']; ! if ('' == trim($qname)) { ! $qname = '[empty]'; ! } ! $qID = $quiz['quizID']; ! echo "<tr><td>{$qID}</td><td><a href=\"javascript:takeaction('quiz_edit','$qID');\">{$qname}</a></td>\n"; ! echo "<td>".$quiz['quizDescription']."</td>\n"; ! echo "<td><a href=\"javascript:takeaction('quiz_delete','$qID');\"><font color='red'>Del</font></a></td></tr>\n"; ! } ! echo "\n</table>\n\n</p>"; ! ! } else { ! echo "<p>You have no quizzes available to try.</p>"; ! ! echo "<p>\n<form name='quizform' action='$PostTo' method='POST'> ! <input type='hidden' name='quizID' value='-1' /> ! <input type='hidden' name='action' value='quiz_choose' />"; ! ! } ! ! ! ! } ! ! if ('quiz_edit' == $action) { ! ! stack_quiz_edit_form($quiz,$errors,$PostTo = ''); ! ! echo "<p>\n<form name='quizform' action='$PostTo' method='POST'> ! <input type='hidden' name='quizID' value='-1'> ! <input type='hidden' name='action' value='quiz_choose'>"; ! ! } ! ! ! if ('quiz_edit_addqs' == $action) { ! ! echo "<p>\n<form name='quizform' action='$PostTo' method='POST'> ! <input type='hidden' name='quizID' value='$quizID'>"; ! ! echo "<a href=\"javascript:takeaction('filter',{$quizID});\">Filter</a> "; ! echo "Name = <input type='text' name='bank_filter[name]' value='{$question_bank_filter['name']}' />"; ! echo " Keyword = <input type='text' name='bank_filter[kw]' value='{$question_bank_filter['kw']}' />"; ! ! stack_db_listquestions_quiz($question_bank_filter); ! ! echo '<input type="hidden" name="action" value="quiz_edit" />'; ! echo "<input type=\"submit\" value=\"Add\" />\n</form>\n"; ! ! ! } ! // echo "<a href=\"javascript:takeaction('quiz_new','0');\">New quiz</a>"; include('html/pagefoot.php'); --- 122,140 ---- //////////////////////////////////////////////// ! stack_quiz_edit_errors($errors); ! switch ($action) { ! case 'quiz_choose': ! $quiz_store = stack_db_quiz_get(); ! stack_select_quiz_screen($quiz_store, $PostTo); ! break; ! case 'quiz_edit': ! stack_quiz_edit_screen($quiz,$errors,$PostTo); ! break; ! case 'quiz_edit_addqs': ! stack_add_questions_screen($PostTo, $quizID, $question_bank_filter); ! break; ! } ! include('html/pagefoot.php'); Index: question_bank.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/question_bank.php,v retrieving revision 1.3.2.18 retrieving revision 1.3.2.19 diff -C2 -d -r1.3.2.18 -r1.3.2.19 *** question_bank.php 16 Jun 2005 14:30:17 -0000 1.3.2.18 --- question_bank.php 16 Jun 2005 16:50:49 -0000 1.3.2.19 *************** *** 45,76 **** $RawAns = ''; - //////////////////////////////////////////////// - // (1) Decide what we are trying to do. - //////////////////////////////////////////////// - - // action = edit_new Edit a blank question - // action = edit Edit a question, in $SESSION or $POST - // action = edit_from_db Get a question from db and edit. - // action = preview Try a question in $SESSION or $POST. - // action = preview_from_db Get a question from db. Instantiate and try. - // action = new_version Try a new version of this question. - // action = validate Validate the response to the current question. - // action = mark Mark the response to the current question. - // action = save Store a question in the db. - // action = save_as Store as a new question in the db. - // action = delete Delete a question from the db. - // action = export_xml Export current question as xml. - // action = export_xml_db Export single question as xml from the database. - // action = export_xml_list Export the list of selected questions as a single XML file - // action = import Deal with an uploaded file. - // action = edit_metadata Edit all the meta data fields in the question bank. - - // action = questionbank_screen Begin again. - - ////////////////////////////////////////////////////////////// // (2) Perform any actions on entering the page ////////////////////////////////////////////////////////////// $admin = FALSE; if ('admin' == $user['username']) { --- 45,72 ---- $RawAns = ''; ////////////////////////////////////////////////////////////// // (2) Perform any actions on entering the page ////////////////////////////////////////////////////////////// + // Possible values for $action at this point are + // edit_new Edit a blank question + // edit Edit a question, in $SESSION or $POST + // edit_from_db Get a question from db and edit. + // preview Try a question in $SESSION or $POST. + // preview_from_db Get a question from db. Instantiate and try. + // new_version Try a new version of this question. + // validate Validate the response to the current question. + // mark Mark the response to the current question. + // save Store a question in the db. + // save_as Store as a new question in the db. + // delete Delete a question from the db. + // export_xml Export current question as xml. + // 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 Deal with an uploaded file. + // edit_metadata Edit all the meta data fields in the question bank. + // questionbank_screen Begin again. + + $admin = FALSE; if ('admin' == $user['username']) { *************** *** 165,169 **** } else { stack_question_validate($question,$errors); - include_once("{$stack_root}/scripts/stackXML.php"); } --- 161,164 ---- *************** *** 191,215 **** } ! if ('delete' == $action) { ! $questionID = $_POST['questionID']; ! if ($admin) { ! stack_db_dropquestion($questionID); ! } ! $action = 'questionbank_screen'; ! } ! ! if ('save' == $action) { ! stack_db_addquestion($question); ! $action = 'questionbank_screen'; } - if ('save_as' == $action) { - stack_db_addquestion($question,TRUE); - $action = 'questionbank_screen'; - } - - if ('edit' == $action) { - stack_question_validate($question,$errors); - } ////////////////////////////////////////////////////////////// --- 186,210 ---- } ! switch ($action) { ! case 'delete': ! $questionID = $_POST['questionID']; ! if ($admin) { ! stack_db_dropquestion($questionID); ! } ! $action = 'questionbank_screen'; ! break; ! case 'save': ! stack_db_addquestion($question); ! $action = 'questionbank_screen'; ! break; ! case 'save_as': ! stack_db_addquestion($question,TRUE); ! $action = 'questionbank_screen'; ! break; ! case 'edit': ! stack_question_validate($question,$errors); ! break; } ////////////////////////////////////////////////////////////// Index: index.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/index.php,v retrieving revision 1.17.2.7 retrieving revision 1.17.2.8 diff -C2 -d -r1.17.2.7 -r1.17.2.8 *** index.php 16 Jun 2005 14:30:16 -0000 1.17.2.7 --- index.php 16 Jun 2005 16:50:49 -0000 1.17.2.8 *************** *** 20,29 **** */ - - /* - * This page displays the login screen. It is the first page accessed by a - * STACK user. - */ - /////////////////////////////////////////////////////////////// // (1) Process Input - this sets $action, $user and $username --- 20,23 ---- *************** *** 34,38 **** $default_action = 'loginscreen'; include($stack_root.'/frontend_general/process_input.php'); ! include($stack_root.'/frontend_general/front_end_display.php'); /////////////////////////////////////////////////////////////// --- 28,33 ---- $default_action = 'loginscreen'; include($stack_root.'/frontend_general/process_input.php'); ! include_once($stack_root.'/frontend_general/front_end_display.php'); ! include_once($stack_root.'/frontend_general/frontend_util.php'); /////////////////////////////////////////////////////////////// *************** *** 90,97 **** } - - - - if ('error' == $action) { stack_login_error_screen($error); --- 85,88 ---- |