From: Chris S. <san...@us...> - 2005-09-04 19:25:08
|
Update of /cvsroot/stack/stack-1-0 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12073 Modified Files: editquiz.php index.php quiz.php stackLib.php user.php Added Files: editsubject.php editzone.php Log Message: **MAJOR** changes: added the Subject layer over the top, --- NEW FILE: editzone.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 front end logic for the subject editting * TO DO: Some of the code in this file needs to be factored out into separate * algorithms- ideally we should have a function for each action on entry and * for display. * - Automatically generated subject metadata added * <TODO> 'Export XML' link when editing subject * @package frontend * @subpackage Stack */ /** * */ session_start(); require_once('stackConfig.php'); require_once('stackLib.php'); require_once("{$stack_root}/scripts/stackAuthor.php"); require_once("{$stack_root}/scripts/stackFrontend.php"); require_once("{$stack_root}/html/trypopupform.html"); require_once("{$stack_root}/html/helpform.php"); require_once("{$stack_root}/html/subjectjava.html"); /////////////////////////////////////////////////////////////// // (1) Process Input - this sets $action, etc /////////////////////////////////////////////////////////////// $default_action = ''; include('frontend_general/process_input.php'); $PostTo = 'editzone.php'; include('html/pagehead.php'); stack_user_ensureadmin($user); //////////////////////////////////////////////// // (2) Take any actions required on entry to the page //////////////////////////////////////////////// if ('zone_edit' == $action) { $zone = $_POST['zone']; if (array_key_exists('subjectOrder',$zone)) { $subjectOrder = $zone['subjectOrder']; $reveal_subject = array(); foreach ($subjectOrder as $sub) { if ('' === $sub['order']) { stack_db_subject_reorder($sub['subjectID'],''); } else { $reveal_subject[] = $sub; } } if (!empty($reveal_subject)) { stack_reorder($reveal_subject); foreach($reveal_subject as $key => $val) { stack_db_subject_reorder($val['subjectID'],$key); } } } } /////////////////////////////////////////////////////////////// // (3) Generate the HTML page /////////////////////////////////////////////////////////////// // Print the form listing the subjects. $subject_store = stack_db_subject_get(); $reveal_subject = array(); $hidden_subject = array(); foreach ($subject_store as $sub) { if ('' === $sub['subjectOrder']) { $hidden_subject[] = $sub; } else { $subo = $sub; $subo['order'] = $subo['subjectOrder']; $reveal_subject[] = $subo; } } $subject_store = array_merge($reveal_subject,$hidden_subject); echo "<form name='stackzoneeditform' action='$PostTo' method='POST'>\n"; echo "<h2>Revealed/hide subjects</h2>"; echo "<p>Subjects without an order are hidden from students, and hence not usable. Add an order to reveal the subject.</p>"; stack_zone_subjects_list($subject_store); // The end of the form! echo '<input type="hidden" name="action" value="zone_edit" />'; echo "<br /><input type=\"submit\" value=\"Edit\" />\n"; echo "</form>\n"; include('html/pagefoot.php'); ?> --- NEW FILE: editsubject.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 front end logic for the subject editting * TO DO: Some of the code in this file needs to be factored out into separate * algorithms- ideally we should have a function for each action on entry and * for display. * - Automatically generated subject metadata added * <TODO> 'Export XML' link when editing subject * @package frontend * @subpackage Stack */ /** * */ session_start(); require_once('stackConfig.php'); require_once('stackLib.php'); require_once("{$stack_root}/scripts/stackAuthor.php"); require_once("{$stack_root}/scripts/stackFrontend.php"); require_once("{$stack_root}/html/trypopupform.html"); require_once("{$stack_root}/html/helpform.php"); require_once("{$stack_root}/html/subjectjava.html"); /////////////////////////////////////////////////////////////// // (1) Process Input - this sets $action, etc /////////////////////////////////////////////////////////////// $default_action = 'subject_choose'; include('frontend_general/process_input.php'); $PostTo = 'editsubject.php'; $filter = ''; $subjectID = NULL; include('html/pagehead.php'); stack_user_ensureadmin($user); //////////////////////////////////////////////// // (2) Take any actions required on entry to the page //////////////////////////////////////////////// // Possible values of $action are // subject_edit Edit a subject // subject_choose Choose a subject // subject_new Create a new subject // subject_delete Delete a subject // subject_edit_add_quiz Choose which quiz to add to a subject. // This needs to sort out the $subject from the post if it exists. $subject = ''; $subjectID = ''; if ('subject_delete' == $action) { $subjectID = nsf($_POST, 'subjectID'); } else if ('subject_edit' == $action or 'subject_edit_add_quiz' == $action) { $subject = nsf($_POST, 'subject'); if ('' == $subject) { $subjectID = nsf($_POST, 'subjectID'); } else { $subjectID = nsf($subject,'subjectID'); } } else if ('subject_new' == $action) { $subjectID = stack_db_subject_update(array()); } if (('subject_edit' == $action or 'subject_edit_add_quiz' == $action) and '' == $subject) { $subject = stack_db_subject_get($subjectID); //show_array($subject); if (array_key_exists('quizzesToAdd',$_POST)) { if (is_array($_POST['quizzesToAdd'])) { $subject['quizzesToAdd'] = $_POST['quizzesToAdd']; } } } if ('subject_delete' == $action and $subjectID != '') { stack_db_subject_delete($subjectID); $action = 'subject_choose'; } if ('subject_edit' == $action) { // Do we need to add questions to the subject? if (array_key_exists('questionsToAdd',$_POST)) { $subject['quizzesToAdd'] = array_keys($_POST['quizzesToAdd']); } } if ('subject_edit' == $action or 'subject_edit_add_quiz' == $action) { stack_subject_validate($subject,$errors); stack_subject_edit($subject,$errors); } if ('subject_new' == $action) { $subject = stack_subject_new($subjectID); $action = 'subject_edit'; } // if ('subject_xml' == $action) { // // include_once("{$stack_root}/scripts/stackXML.php"); // // $subject = stack_db_subject_get($subjectID); // stack_xml_remove_subject_meta_defaults($subject); //Pass subject by reference and remove all default metadata // $name = stack_xml_write_subject($subject,"{$stack_root}/{$stack_tmpdir}/"); // } //////////////////////////////////////////////// // (3) Generate web page //////////////////////////////////////////////// // (3.1) Display any errors. if (is_array($errors)) { stack_errors_show($errors,'subject'); } // (3.2) Now take some action switch ($action) { case 'subject_xml': { echo "<p>Please download the file <a href='{$stack_web_url}tmp/{$name}'>$name</a>.</p>"; } case 'subject_choose': $subject_store = stack_db_subject_get(); stack_subject_selectform($subject_store, $PostTo); break; case 'import': { } case 'subject_report': $subjectID = nsf($_POST, 'subjectID'); stack_subject_report($subjectID); break; case 'subject_edit': stack_subject_edit_form($subject,$errors,$PostTo = ''); echo "<p>\n<form name='subjectform' action='$PostTo' method='POST'> <input type='hidden' name='subjectID' value='-1'> <input type='hidden' name='action' value='subject_choose'>"; break; case 'subject_edit_add_quiz': stack_db_list_quizzes_subject($subject['subjectID']); break; } include('html/pagefoot.php'); ?> Index: quiz.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/quiz.php,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** quiz.php 29 Aug 2005 18:41:03 -0000 1.31 --- quiz.php 4 Sep 2005 19:24:57 -0000 1.32 *************** *** 42,45 **** --- 42,50 ---- $quiz = ''; $quizInst = ''; + + $subject = ''; + if (array_key_exists('subject',$_SESSION)) { + $subject = $_SESSION['subject']; + } // $focus means "one question at a time"; *************** *** 142,148 **** $quiz_options = $quiz['quizOptions']; } $question = array(); ! $options = stack_options_set($question,$quiz_options); $quizmode = $options['QuizMode']; --- 147,158 ---- $quiz_options = $quiz['quizOptions']; } + + $subject_options = array(); + if (array_key_exists('subjectOptions',$subject)){ + $subject_options = $subject['subjectOptions']; + } $question = array(); ! $options = stack_options_set($question,$quiz_options,$subject_options); $quizmode = $options['QuizMode']; *************** *** 220,225 **** stack_question_validate($question,$errors["qu$key"]); ! $options = stack_options_set($question,$quiz_options); ! if ( '' == $errors["qu$key"] ) { // We add an offset to the quiz $seed here to make sure each question in the quiz --- 230,235 ---- stack_question_validate($question,$errors["qu$key"]); ! $options = stack_options_set($question,$quiz_options,$subject_options); ! if ( '' == $errors["qu$key"] ) { // We add an offset to the quiz $seed here to make sure each question in the quiz *************** *** 323,327 **** } ! $options = stack_options_set($qInst,$quiz_options); $this_attempt = stack_question_inst_mark($qInst,$options,$RawAns[$key],$errors["qu$key"]); --- 333,337 ---- } ! $options = stack_options_set($qInst,$quiz_options,$subject_options); $this_attempt = stack_question_inst_mark($qInst,$options,$RawAns[$key],$errors["qu$key"]); *************** *** 359,363 **** if ($implicit_validate) { ! $options = stack_options_set($qInst,$quiz_options); $this_attempt = stack_question_inst_mark($qInst,$options,$ra,$errors["qu$key"]); $this_attempt['Action'] = 'validate'; --- 369,373 ---- if ($implicit_validate) { ! $options = stack_options_set($qInst,$quiz_options,$subject_options); $this_attempt = stack_question_inst_mark($qInst,$options,$ra,$errors["qu$key"]); $this_attempt['Action'] = 'validate'; *************** *** 385,389 **** ) { ! $options = stack_options_set($qInst,$quiz_options); $this_attempt = stack_question_inst_mark($qInst,$options,$RawAns[$key],$errors["qu$key"]); --- 395,399 ---- ) { ! $options = stack_options_set($qInst,$quiz_options,$subject_options); $this_attempt = stack_question_inst_mark($qInst,$options,$RawAns[$key],$errors["qu$key"]); *************** *** 420,424 **** // Do treat this non-empty, different attempt as a validation ! $options = stack_options_set($qInst,$quiz_options); $this_attempt = stack_question_inst_mark($qInst,$options,$RawAns[$key],$errors["qu$key"]); $this_attempt['Action'] = 'validate'; --- 430,434 ---- // Do treat this non-empty, different attempt as a validation ! $options = stack_options_set($qInst,$quiz_options,$subject_options); $this_attempt = stack_question_inst_mark($qInst,$options,$RawAns[$key],$errors["qu$key"]); $this_attempt['Action'] = 'validate'; *************** *** 481,485 **** if ($mark_this) { ! $options = stack_options_set($qInst,$quiz_options); $this_attempt = stack_question_inst_mark($qInst,$options,$RawAns[$key],$errors["qu$key"]); $this_attempt['Action']='mark'; --- 491,495 ---- if ($mark_this) { ! $options = stack_options_set($qInst,$quiz_options,$subject_options); $this_attempt = stack_question_inst_mark($qInst,$options,$RawAns[$key],$errors["qu$key"]); $this_attempt['Action']='mark'; *************** *** 565,569 **** // Set up the information about this question. ! $options = stack_options_set($qInst,$quiz_options); $mark[$key]['max'] = $options['QuVal']; $qn = $key+1; --- 575,579 ---- // Set up the information about this question. ! $options = stack_options_set($qInst,$quiz_options,$subject_options); $mark[$key]['max'] = $options['QuVal']; $qn = $key+1; Index: stackLib.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/stackLib.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** stackLib.php 29 Aug 2005 18:41:03 -0000 1.2 --- stackLib.php 4 Sep 2005 19:24:57 -0000 1.3 *************** *** 31,34 **** --- 31,35 ---- require_once("{$stack_root}/scripts/stackQuestion.php"); require_once("{$stack_root}/scripts/stackQuiz.php"); + require_once("{$stack_root}/scripts/stacksubject.php"); require_once("{$stack_root}/scripts/stackUser.php"); Index: index.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/index.php,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** index.php 29 Aug 2005 18:41:03 -0000 1.27 --- index.php 4 Sep 2005 19:24:57 -0000 1.28 *************** *** 35,38 **** --- 35,39 ---- } require_once('stackLib.php'); + require_once($stack_root.'/scripts/stackFrontend.php'); /////////////////////////////////////////////////////////////// *************** *** 40,45 **** /////////////////////////////////////////////////////////////// - require_once($stack_root.'/scripts/stackFrontend.php'); - $default_action = 'loginscreen'; include($stack_root.'/frontend_general/process_input.php'); --- 41,44 ---- *************** *** 49,53 **** /////////////////////////////////////////////////////////////// - // 2.1 Check that XML schemas are up to date include_once("{$stack_root}/scripts/stackXML.php"); --- 48,51 ---- *************** *** 56,61 **** } - // 2.2 Check whether database needs updating - need to be logged in to get credentials - include_once("{$stack_root}/scripts/stackDatabase.php"); if (!stack_db_database_update() && stack_is_logged_in($user) and !stack_user_is_guest($user)) { $action = 'update_db'; --- 54,57 ---- *************** *** 70,73 **** --- 66,71 ---- $user = NULL; session_unregister('user'); + session_unregister('subject'); + session_unregister('quiz'); unset($_SESSION['user']); $_GET['expand'] = 0; *************** *** 93,97 **** echo "<h1>Welcome</h1> <p>Welcome to STACK, {$user['firstname']} {$user['lastname']}.</p>"; if ('admin' != $user['username']) { ! $action = 'choose_quiz'; } } --- 91,95 ---- echo "<h1>Welcome</h1> <p>Welcome to STACK, {$user['firstname']} {$user['lastname']}.</p>"; if ('admin' != $user['username']) { ! $action = 'choose_subject'; } } *************** *** 103,106 **** --- 101,115 ---- } + if ('choose_quiz' == $action) { + if (array_key_exists('subjectID',$_POST)) { + $subjectID = $_POST['subjectID']; + $subject = stack_db_subject_get($subjectID,FALSE); + $_SESSION['subject'] = $subject; + } else if (array_key_exists('subject',$_SESSION)) { + $subject = $_SESSION['subject']; + $subjectID = $subject['subjectID']; + } + } + switch ($action) { case 'loginscreen': *************** *** 144,150 **** break; case 'choose_quiz': ! $quiz_store = stack_db_quiz_get(); ! stack_quiz_student_select($quiz_store, $user); break; case 'update_schema': --- 153,169 ---- break; + case 'choose_subject': + stack_subject_student_select($user['id']); + break; case 'choose_quiz': ! if ('' == $subjectID) { ! echo "Please choose a subject first."; ! } else { ! echo '<h1>'.$subject['subjectName'].'</h1>'; ! echo $subject['subjectHTMLHead']; ! $quiz_store = stack_db_subject_quiz_list_student($subjectID); ! stack_quiz_student_select($quiz_store, $user); ! echo $subject['subjectHTMLFoot']; ! } break; case 'update_schema': Index: user.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/user.php,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** user.php 29 Aug 2005 18:41:03 -0000 1.6 --- user.php 4 Sep 2005 19:24:57 -0000 1.7 *************** *** 27,42 **** require_once('stackLib.php'); $default_action = 'none'; include($stack_root.'/frontend_general/process_input.php'); /////////////////////////////////////////////////////////////// // (2) Take any actions required /////////////////////////////////////////////////////////////// - // Note that we need to unset the user before printing the header. - if ('admin' != $user['username'] and $user['loggedin']) { - echo "Only the admin user may access this page."; - die(); - } if ('userupdate' == $action) { --- 27,42 ---- require_once('stackLib.php'); + require_once("{$stack_root}/scripts/stackFrontend.php"); + + $default_action = 'none'; include($stack_root.'/frontend_general/process_input.php'); + stack_user_ensureadmin($user); + /////////////////////////////////////////////////////////////// // (2) Take any actions required /////////////////////////////////////////////////////////////// if ('userupdate' == $action) { *************** *** 46,50 **** // Do we need analysis of one user? $userID = ''; ! if ('userupdate_choose' == $action or 'review' == $action) { $userID = $_POST['userID']; $user_stu = stack_db_user_get_ID($userID); --- 46,50 ---- // Do we need analysis of one user? $userID = ''; ! if ('userupdate_choose' == $action or 'review' == $action or 'delete' == $action) { $userID = $_POST['userID']; $user_stu = stack_db_user_get_ID($userID); *************** *** 64,68 **** switch ($action) { case 'none': ! echo "<h1>User management</h1>\n"; echo "<form name='stackuserform' action='' method='POST'>\n"; echo "<table>"; --- 64,68 ---- switch ($action) { case 'none': ! echo "<h1>User management</h1>\n Note, there is no 'undo' option."; echo "<form name='stackuserform' action='' method='POST'>\n"; echo "<table>"; *************** *** 86,90 **** break; case 'delete': ! echo 'Not yet implemented.'; break;} --- 86,91 ---- break; case 'delete': ! stack_db_user_delete($user_stu); ! echo "User deleted permanently. There is no 'undo' option."; break;} Index: editquiz.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/editquiz.php,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** editquiz.php 30 Aug 2005 13:51:54 -0000 1.20 --- editquiz.php 4 Sep 2005 19:24:57 -0000 1.21 *************** *** 51,65 **** $PostTo = 'editquiz.php'; $filter = ''; ! $quizid = NULL; include('html/pagehead.php'); ! ! if (!stack_user_is_admin($user) or !stack_is_logged_in($user)) { ! 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>"; ! include('html/pagefoot.php'); ! die(); ! } // Work out the correct value for any filter to be applied to the question --- 51,58 ---- $PostTo = 'editquiz.php'; $filter = ''; ! $quizid = NULL; include('html/pagehead.php'); ! stack_user_ensureadmin($user); // Work out the correct value for any filter to be applied to the question *************** *** 82,112 **** // quiz_report Gain a report of student's progress with this quiz. ! ! $quiz = ''; $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'; - } - - else if ('quiz_xml' == $action) { - $quizid_source = 'post'; - } - else if ('quiz_xml_db' == $action) { - $quizid_source = 'database'; - } - - if ('quiz_edit' == $action or 'quiz_edit_addqs' == $action) { $quiz = nsf($_POST, 'quiz'); if ('' == $quiz) { $quizid_source = 'post'; } } // Establish the $quizid - $quizid = ''; if ('quiz' == $quizid_source) { $quizid = nsf($quiz,'quizid'); --- 75,95 ---- // quiz_report Gain a report of student's progress with this quiz. ! $quiz = ''; $quizid_source = ''; ! $quizid = ''; ! ! if ('quiz_delete' == $action or 'filter' == $action or 'quiz_xml' == $action) { $quizid_source = 'post'; } else if ('quiz_edit' == $action or 'quiz_edit_addqs' == $action) { $quizid_source = 'quiz'; $quiz = nsf($_POST, 'quiz'); if ('' == $quiz) { $quizid_source = 'post'; } + } else if ('quiz_new' == $action or 'quiz_xml_db' == $action) { + $quizid_source = 'database'; } // Establish the $quizid if ('quiz' == $quizid_source) { $quizid = nsf($quiz,'quizid'); *************** *** 128,133 **** $filter_source = 'session'; } ! ! if ('quiz_delete' == $action and $quizid != '') { stack_db_quiz_delete($quizid); --- 111,115 ---- $filter_source = 'session'; } ! if ('quiz_delete' == $action and $quizid != '') { stack_db_quiz_delete($quizid); *************** *** 152,157 **** if ('quiz_new' == $action) { ! $quiz = stack_quiz_new($quizid); ! $action = 'quiz_edit'; } --- 134,138 ---- if ('quiz_new' == $action) { ! $quiz = stack_quiz_new($quizid); $action = 'quiz_edit'; } *************** *** 173,184 **** // (3.1) Display any errors. if (is_array($errors)) { ! echo "<font color=\"red\">Errors exist!</font><br/>"; ! if (array_key_exists('quiz',$errors)) { ! foreach($errors['quiz'] as $key => $val) { ! echo "The field $key, gave the following error."; ! echo $val; ! } ! } ! } --- 154,158 ---- // (3.1) Display any errors. if (is_array($errors)) { ! stack_errors_show($errors,'quiz'); } |