From: Chris S. <san...@us...> - 2005-09-12 08:07:56
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26368/scripts Modified Files: stackAuthor.php stackCAS.php stackQuestion.php stackQuiz.php Added Files: stackDoc.php stackZone.php Log Message: Index: stackAuthor.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackAuthor.php,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** stackAuthor.php 5 Sep 2005 13:40:56 -0000 1.43 --- stackAuthor.php 12 Sep 2005 08:07:47 -0000 1.44 *************** *** 391,396 **** } ! $options_headings = array(get_string('stackOptions_edit_inmeth','stack'),'','','',get_string('stackOptions_edit_resppro','stack'),'','','','','',get_string('stackOptions_edit_out','stack')); ! $options_list = array('InsertStars','InformalSyntax','AllowInputTool','SyntaxHint','Forbid','Allow','MarkModMethod','FeedBackGenericCorrect','FeedBackGenericPCorrect','FeedBackGenericIncorrect','Display'); stack_options_edit_form($options_headings,$options_list,$optval,'questionOptions',$prefix,$remoteCaller); --- 391,396 ---- } ! $options_headings = array(get_string('stackOptions_edit_inmeth','stack'),'','','','',get_string('stackOptions_edit_resppro','stack'),'','','','','',get_string('stackOptions_edit_out','stack')); ! $options_list = array('InsertStars','InformalSyntax','AllowInputTool','Floats','SyntaxHint','Forbid','Allow','MarkModMethod','FeedBackGenericCorrect','FeedBackGenericPCorrect','FeedBackGenericIncorrect','Display'); stack_options_edit_form($options_headings,$options_list,$optval,'questionOptions',$prefix,$remoteCaller); *************** *** 879,884 **** ! $options_headings = array(get_string('stackOptions_edit_inmeth','stack'),'','','',get_string('stackOptions_edit_resppro','stack'),'','','','','','','','',get_string('stackOptions_edit_out','stack'),''); ! $options_list = array('InsertStars','InformalSyntax','AllowInputTool','SyntaxHint','AnsTest','AnsTestOpt','QuVal','Penalty','Forbid','Allow','FeedBackGenericCorrect','FeedBackGenericPCorrect','FeedBackGenericIncorrect','Display','Language'); $fieldname = 'quiz'.'[quizOptions]'; --- 879,884 ---- ! $options_headings = array(get_string('stackOptions_edit_inmeth','stack'),'','','','',get_string('stackOptions_edit_resppro','stack'),'','','','','','','','',get_string('stackOptions_edit_out','stack'),'',''); ! $options_list = array('InsertStars','InformalSyntax','AllowInputTool','Floats','SyntaxHint','AnsTest','AnsTestOpt','QuVal','Penalty','Forbid','Allow','FeedBackGenericCorrect','FeedBackGenericPCorrect','FeedBackGenericIncorrect','Display','Complex no','Language'); $fieldname = 'quiz'.'[quizOptions]'; *************** *** 1299,1304 **** ! $options_headings = array('',get_string('stackOptions_edit_inmeth','stack'),'','','',get_string('stackOptions_edit_resppro','stack'),'','','','','','','','',get_string('stackOptions_edit_out','stack'),''); ! $options_list = array('QuizMode','InsertStars','InformalSyntax','AllowInputTool','SyntaxHint','AnsTest','AnsTestOpt','QuVal','Penalty','Forbid','Allow','FeedBackGenericCorrect','FeedBackGenericPCorrect','FeedBackGenericIncorrect','Display','Language'); $fieldname = 'subject'.'[subjectOptions]'; --- 1299,1304 ---- ! $options_headings = array('',get_string('stackOptions_edit_inmeth','stack'),'','','','',get_string('stackOptions_edit_resppro','stack'),'','','','','','','','',get_string('stackOptions_edit_out','stack'),'',''); ! $options_list = array('QuizMode','InsertStars','InformalSyntax','AllowInputTool','Floats','SyntaxHint','AnsTest','AnsTestOpt','QuVal','Penalty','Forbid','Allow','FeedBackGenericCorrect','FeedBackGenericPCorrect','FeedBackGenericIncorrect','Display','Complex no','Language'); $fieldname = 'subject'.'[subjectOptions]'; --- NEW FILE: stackZone.php --- <?php /** * This file contains most functions which deal with the zone. * * @package scripts * @subpackage Stack */ /* the stackZone data structure */ /** * Orders subjects according to the way they are listed on the screen. * @param array $subject_store * @return array $subject_store */ function stack_zone_subjects_order($subject_store) { $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); return $subject_store; } Index: stackQuestion.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackQuestion.php,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** stackQuestion.php 4 Sep 2005 19:24:57 -0000 1.34 --- stackQuestion.php 12 Sep 2005 08:07:47 -0000 1.35 *************** *** 24,27 **** --- 24,34 ---- // values = possible values, for a list this is an array. // default = default value. There must be one! + // CAS_KEY = The name of the variable to which this option will + // be assigned when it is in the CAS. + // The CAS is always called with these set up. + // CAS_TYPE = Tells us what to do with this. + // string, send as a string + // ex, send as an expression + // fun, apply a function to this value. //****************************************************** *************** *** 51,54 **** --- 58,79 ---- $stackOptions['Display']['values'] = array('String','LaTeX','MathML','LaTeX Source'); $stackOptions['Display']['default'] = 'LaTeX'; + $stackOptions['Display']['CAS_KEY'] = 'OPT_OUTPUT'; + $stackOptions['Display']['CAS_TYPE'] = 'string'; + + + // 'Complex j'; + $stackOptions['Complex no']['type'] = 'list'; + $stackOptions['Complex no']['values'] = array('i','j'); + $stackOptions['Complex no']['default'] = 'i'; + $stackOptions['Complex no']['CAS_KEY'] = 'make_complexJ'; + $stackOptions['Complex no']['CAS_TYPE'] = 'fun'; + + // 'Floats'; + $stackOptions['Floats']['type'] = 'list'; + $stackOptions['Floats']['values'] = array('TRUE','FALSE'); + $stackOptions['Floats']['default'] = 'TRUE'; + $stackOptions['Floats']['CAS_KEY'] = 'OPT_NoFloats'; + $stackOptions['Floats']['CAS_TYPE'] = 'ex'; + // 'Language'; *************** *** 122,125 **** --- 147,157 ---- $stackOptions['SubjectMode']['default'] = 'the class list only'; + // We need for efficiency reasons to sort out which options go to the CAS. + $stackOptionsCAS = ''; + foreach ($stackOptions as $optname => $opt) { + if (array_key_exists('CAS_KEY',$opt)) { // This is an option which goes to the CAS + $stackOptionsCAS[$optname] = array('CAS_KEY' => $opt['CAS_KEY'], 'CAS_TYPE' => $opt['CAS_TYPE']); + } + } //<PDK> sqlToSchemaMapping array maps basic SQL data types used in STAKCK to their respective XML schema data types *************** *** 1228,1236 **** * @param string $atest The name of the answer test * @param array $atest_ops The answer test options ! * @param string $disp The display option * @param array &$errors Repository for errors * @return array $stackQuestionAttempt data structure containing the information for this attempt. */ ! function stack_apply_answertest($sa,$ta,$atest,$atest_ops,$disp,&$errors) { global $stack_os,$stack_web_root,$stack_web_services,$stackAnswerTest; --- 1260,1268 ---- * @param string $atest The name of the answer test * @param array $atest_ops The answer test options ! * @param string $options The display option * @param array &$errors Repository for errors * @return array $stackQuestionAttempt data structure containing the information for this attempt. */ ! function stack_apply_answertest($sa,$ta,$atest,$atest_ops,$options,&$errors) { global $stack_os,$stack_web_root,$stack_web_services,$stackAnswerTest; *************** *** 1251,1255 **** if ('cas' == $stackAnswerTest[$atest]['imp']) { ! $this_attempt = CPProcessAnsTest($sa,$ta,$atest,$disp,$errors); } --- 1283,1287 ---- if ('cas' == $stackAnswerTest[$atest]['imp']) { ! $this_attempt = CPProcessAnsTest($sa,$ta,$atest,$options,$errors); } *************** *** 1264,1268 **** if ('' == $errs && '' != $atest_ops ) { ! $this_attempt = CPProcessAnsTest($sa,$ta,$atest,$disp,$errors); } else { // We have an error in the question. --- 1296,1300 ---- if ('' == $errs && '' != $atest_ops ) { ! $this_attempt = CPProcessAnsTest($sa,$ta,$atest,$options,$errors); } else { // We have an error in the question. *************** *** 1609,1613 **** $ta = $all_locs_Inst[$tan]['value']; ! $this_PRattempt = stack_apply_answertest($sa,$ta,$answertest[$prn],$answertestopt[$prn],$disp,$errors); if (array_key_exists('error', $this_PRattempt['Ans'] )) { --- 1641,1645 ---- $ta = $all_locs_Inst[$tan]['value']; ! $this_PRattempt = stack_apply_answertest($sa,$ta,$answertest[$prn],$answertestopt[$prn],$options,$errors); if (array_key_exists('error', $this_PRattempt['Ans'] )) { *************** *** 1700,1704 **** } ! $this_attempt = array_merge($this_attempt,stack_apply_answertest($RawAns,$CorrectAns,$at,$ato,$disp,$errors)); $this_attempt['RawAns']= $RawAns; --- 1732,1736 ---- } ! $this_attempt = array_merge($this_attempt,stack_apply_answertest($RawAns,$CorrectAns,$at,$ato,$options,$errors)); $this_attempt['RawAns']= $RawAns; Index: stackQuiz.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackQuiz.php,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** stackQuiz.php 7 Sep 2005 14:19:35 -0000 1.14 --- stackQuiz.php 12 Sep 2005 08:07:47 -0000 1.15 *************** *** 186,190 **** function stack_quiz_student_select($subjectID, $quiz_store, $user, $review=FALSE, $returnurl='') { global $stack_root; ! require_once("{$stack_root}/html/quizjava.html"); echo '<h2>'.get_string('quiz_choose','stack').'</h2>'; --- 186,194 ---- function stack_quiz_student_select($subjectID, $quiz_store, $user, $review=FALSE, $returnurl='') { global $stack_root; ! ! if (!$review) { ! include($stack_root.'/html/quizchoose.html'); ! require_once("{$stack_root}/html/quizjava.html"); ! } echo '<h2>'.get_string('quiz_choose','stack').'</h2>'; *************** *** 192,211 **** global $stackQuiz; if (is_array($quiz_store)) { ! echo "<script language=\"javascript\"> ! function quizreview(u,n,m) { ! document.forms.quizform.userid.value = u; ! document.forms.quizform.quizid.value = n; ! document.forms.quizform.subjectID.value = m; ! document.forms.quizform.submit(); ! } ! </script> ! <p>\n<form name='quizform' action='quiz.php' method='POST'> ! <input type='hidden' name='returnurl' value ='$returnurl' /> ! <input type='hidden' name='userid' value='-1' /> ! <input type='hidden' name='quizid' value='-1' /> ! <input type='hidden' name='subjectID' value='-1' /> ! <input type='hidden' name='action' value='review' />"; echo "\n<table cellpadding='2'>\n"; ! echo "\n<tr><th>{$stackQuiz['quizName']['descript']}</th><th>{$stackQuiz['quizDescription']['descript']}</th><th>Last mark (%)</th><th>{$stackQuiz['quizDueDate']['descript']}</th></tr>"; foreach ($quiz_store as $qs => $quiz) { --- 196,203 ---- global $stackQuiz; if (is_array($quiz_store)) { ! ! echo "\n<table cellpadding='2'>\n"; ! echo "\n<tr><th>{$stackQuiz['quizName']['descript']}</th><th>{$stackQuiz['quizDescription']['descript']}</th><th>Last mark (%)</th><th>{$stackQuiz['quizDueDate']['descript']}</th>\n</tr>\n"; foreach ($quiz_store as $qs => $quiz) { *************** *** 237,241 **** echo "</tr>\n"; } ! echo "\n</table>\n</form>\n</p>"; } else { echo '<p>'.get_string('quiz_nonetochoose','stack').'</p>'; --- 229,233 ---- echo "</tr>\n"; } ! echo "\n</table>\n</p>"; } else { echo '<p>'.get_string('quiz_nonetochoose','stack').'</p>'; --- NEW FILE: stackDoc.php --- <?php /** * This file contains most functions which deal with documentation. * * @package scripts * @subpackage Stack */ /** */ /** * Display an example of the stack question * * * @param $question The question to be displayed. * */ function stack_doc_dispexample($question) { global $stackQuestion; //show_array($question); echo "<table border='1'>\n"; foreach ($question as $key => $val) { $fieldname = 'stackQuestion_'.$key; $descript = get_string($fieldname,'stack'); echo "<tr>\n <td>"; echo "<a href=\"javascript:HelpPopup('$key','stackQuestion');\">{$descript}</a></td>\n"; echo " <td><tt>$val</tt> </td>\n</tr>\n"; } echo "</table>\n"; } /** * Display, with hyperlinking, the STACK question field name and a link to the help pop-up. * * * @param string $command The command to be displayed * @param string $stackhelp Optional: the help file which contains the field. */ function stack_doc_dispstackqfield($command,$stackhelp='stackQuestion') { global $stackQuestion,$stackQuestionPotResp,$stackOptions; if ('stackQuestion' == $stackhelp) { $fieldname = 'stackQuestion_'.$command; $descript = get_string($fieldname,'stack'); } else if ('stackQuestionPotResp' == $stackhelp) { $fieldname = 'stackQuestion_PR_'.$command; $descript = get_string($fieldname,'stack'); } else if ('stackOptions' == $stackhelp) { $fieldname = 'stackOptions_'.$command; $descript = get_string($fieldname,'stack'); } echo "<a href=\"javascript:HelpPopup('$command','$stackhelp');\">$descript</a> "; } /** * Display, with hyper-linking, the STACK command * * * @param string $command The command to be displayed */ function stack_doc_dispstackcommand($command) { echo "<a href=\"#STACK_command_{$command}\"><font color=\"orange\"><tt>$command</tt></font></a> "; } ?> Index: stackCAS.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackCAS.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** stackCAS.php 25 Aug 2005 16:06:17 -0000 1.2 --- stackCAS.php 12 Sep 2005 08:07:47 -0000 1.3 *************** *** 11,33 **** * to process a list of local variables. * ! * @param array $locvars List of local variables to be instantiated ! * @param int $t Timestamp identifier used to match CAS input and output ! * @param string $display The desired output format (a Stack Option) * @return string The command to send to the CAS */ ! function CASCodeInstantiate($locvars, $t, $seed, $displayopt) { // Generates Maxima specific code // We will use a maxima block. // BLOCK([v1,...,vk], state1,...statej) ! ! // Now we will get the student's display options ! $OPT_OUTPUT = $displayopt; $loclistA = ''; $loclistB = ''; - $cs ='cab:BLOCK([ C_op, OPT_OUTPUT'; // We know $locvars is non-empty, as we have put $answer into it! foreach ($locvars as $lk => $locv) { ! $key = $locv["key"]; $val = str_replace('?','qmchar',$locv["value"]); $loclistA.= ','.$key; --- 11,51 ---- * to process a list of local variables. * ! * @param array $locvars List of local variables to be instantiated ! * @param int $t Timestamp identifier used to match CAS input and output ! * @param int $seed The random number generation seed ! * @param array $options * @return string The command to send to the CAS */ ! function CASCodeInstantiate($locvars, $t, $seed, $options) { ! global $stackOptionsCAS; // Generates Maxima specific code // We will use a maxima block. // BLOCK([v1,...,vk], state1,...statej) ! $loclistA = ''; $loclistB = ''; + $cs ='cab:BLOCK([ RANDOM_SEED'; + + // Now we will add options + foreach ($stackOptionsCAS as $optname => $opt) { + $optkey = $opt['CAS_KEY']; + switch ($opt['CAS_TYPE']) { + case 'string': + $loclistA.= ', '.$optkey; + $loclistC.= ', '.$optkey.':"'.$options[$optname].'"'; + break; + case 'ex': + $loclistA.= ', '.$optkey; + $loclistC.= ', '.$optkey.':'.$options[$optname]; + break; + case 'fun': + $loclistC.= ', '.$optkey.'('.$options[$optname].')'; + break; + } + } // We know $locvars is non-empty, as we have put $answer into it! foreach ($locvars as $lk => $locv) { ! $key = $locv['key']; $val = str_replace('?','qmchar',$locv["value"]); $loclistA.= ','.$key; *************** *** 35,39 **** } ! $cs .= $loclistA.'], OPT_OUTPUT:"'.$OPT_OUTPUT.'", RANDOM_SEED:'.$seed; $cs .= ", print(\"[TimeStamp= [ $t ], Locals= [ \") "; --- 53,57 ---- } ! $cs .= $loclistA.'], RANDOM_SEED:'.$seed.$loclistC; $cs .= ", print(\"[TimeStamp= [ $t ], Locals= [ \") "; *************** *** 43,46 **** --- 61,65 ---- $cs .= ", RETURN(true) ); \n"; + //echo "<pre>".$cs."</pre>"; return($cs); } *************** *** 142,156 **** * @return string The command to send to the CAS */ ! function CASAnsTestCmd($exp1, $exp2, $t, $OPT_OUTPUT, $test) { // Generates the CAS command to mark a question ! global $stackAnswerTest; $exp1 = str_replace('?','qmchar',$exp1); $exp2 = str_replace('?','qmchar',$exp2); ! $cas_cmd = "cab:BLOCK([ ans,str,OPT_OUTPUT], OPT_OUTPUT:\"$OPT_OUTPUT\", "; $cas_cmd .= " print(\" [TimeStamp= [ $t ], Ans= [ error = [\")"; $cas_cmd .= ", cte(\"ans\",ERRCATCH(ans:$exp1)), "; $fname = $stackAnswerTest[$test]['function']; $cas_cmd .= " str:$fname(ans,$exp2), print(str), RETURN(true)); \n"; --- 161,198 ---- * @return string The command to send to the CAS */ ! function CASAnsTestCmd($exp1, $exp2, $t, $options, $test) { // Generates the CAS command to mark a question ! global $stackAnswerTest,$stackOptionsCAS; $exp1 = str_replace('?','qmchar',$exp1); $exp2 = str_replace('?','qmchar',$exp2); ! $loclistA = ''; ! $loclistB = ''; ! $cs ='cab:BLOCK([ RANDOM_SEED'; ! ! // Now we will add options ! foreach ($stackOptionsCAS as $optname => $opt) { ! $optkey = $opt['CAS_KEY']; ! switch ($opt['CAS_TYPE']) { ! case 'string': ! $loclistA.= ', '.$optkey; ! $loclistC.= ', '.$optkey.':"'.$options[$optname].'"'; ! break; ! case 'ex': ! $loclistA.= ', '.$optkey; ! $loclistC.= ', '.$optkey.':'.$options[$optname]; ! break; ! case 'fun': ! $loclistC.= ', '.$optkey.'('.$options[$optname].')'; ! break; ! } ! } ! ! $cas_cmd = "cab:BLOCK([ ans,str{$loclistA}] {$loclistC}, "; $cas_cmd .= " print(\" [TimeStamp= [ $t ], Ans= [ error = [\")"; $cas_cmd .= ", cte(\"ans\",ERRCATCH(ans:$exp1)), "; + $cas_cmd .= "str:stack_validate(ans), print(str),"; $fname = $stackAnswerTest[$test]['function']; $cas_cmd .= " str:$fname(ans,$exp2), print(str), RETURN(true)); \n"; *************** *** 169,197 **** function CASAnsTestParse($instr) { ! $unp = CASParsePreparse($instr); ! $unp['Ans'] = CASParsePreparse($unp['Ans']); ! if (''==$unp['Ans']['error']) { ! unset($unp['Ans']['error']); ! } ! // Sort out translations of the feedback. ! if (array_key_exists('FeedBack',$unp)) { ! $strin = str_replace("\n","",$unp['FeedBack'] ); ! $strin = str_replace('\\','\\\\',$strin); ! $strin = str_replace('$','\$',$strin); ! $strin = str_replace("<QUOT>",'"',$strin); ! //echo "STRIN: <pre>$strin</pre><br>"; ! ob_start(); ! eval($strin); ! $strin = ob_get_contents(); ! ob_end_clean(); ! ! $unp['FeedBack'] = $strin; ! } - return $unp; } --- 211,249 ---- function CASAnsTestParse($instr) { ! $unp = CASParsePreparse($instr); ! $unp['Ans'] = CASParsePreparse($unp['Ans']); ! if (''==$unp['Ans']['error']) { ! unset($unp['Ans']['error']); ! } ! if ('false' == $unp['ValidationValid']) { ! $unp['Valid'] = 'false'; ! $unp['AnswerNote'] = $unp['ValidationNote']; ! $unp['FeedBack'] = $unp['ValidationFeedBack']; ! } ! unset($unp['ValidationValid']); ! unset($unp['ValidationNote']); ! unset($unp['ValidationFeedBack']); ! // Sort out translations of the feedback. ! if (array_key_exists('FeedBack',$unp)) { ! $strin = str_replace("\n","",$unp['FeedBack'] ); ! $strin = str_replace('\\','\\\\',$strin); ! $strin = str_replace('$','\$',$strin); ! $strin = str_replace("<QUOT>",'"',$strin); ! //echo "STRIN: <pre>$strin</pre><br>"; ! ! ob_start(); ! eval($strin); ! $strin = ob_get_contents(); ! ob_end_clean(); ! ! $unp['FeedBack'] = $strin; ! } ! ! return $unp; } *************** *** 225,231 **** $t = time(); ! $display = $options['Display']; ! ! $varCommand = CASCodeInstantiate($locals, $t, $seed, $display); if ($varCommand != '') { --- 277,281 ---- $t = time(); ! $varCommand = CASCodeInstantiate($locals, $t, $seed, $options); if ($varCommand != '') { *************** *** 298,309 **** * @param string $exp2 A CAS expression, nominally the teachers's * @param string $test Which AnswerTest to apply. ! * @param array $options The only option needed is the Display, but other answer tests may in the future require their own options. * @return array $this_attempt An array structure, which is used to build the student's attempt. */ ! function CPProcessAnsTest($exp1,$exp2,$test,$disp,&$err) { // create a StackResponse object $t = time(); ! $varCommand = CASAnsTestCmd($exp1, $exp2, $t, $disp, $test); if ($varCommand != '') { --- 348,359 ---- * @param string $exp2 A CAS expression, nominally the teachers's * @param string $test Which AnswerTest to apply. ! * @param array $options * @return array $this_attempt An array structure, which is used to build the student's attempt. */ ! function CPProcessAnsTest($exp1,$exp2,$test,$options,&$err) { // create a StackResponse object $t = time(); ! $varCommand = CASAnsTestCmd($exp1, $exp2, $t, $options, $test); if ($varCommand != '') { |