From: Chris S. <san...@us...> - 2005-06-21 17:37:38
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17304/scripts Modified Files: stackAuthor.php stackDatabase.php stackQuestion.php Log Message: Index: stackDatabase.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackDatabase.php,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** stackDatabase.php 21 Jun 2005 09:11:10 -0000 1.18 --- stackDatabase.php 21 Jun 2005 14:52:26 -0000 1.19 *************** *** 109,130 **** global $_PHP_SELF; - // Sort out how we are going to filter questions. - if ('' === $filter) { - $filter['kw'] = ''; - $filter['name'] = ''; - } if ('try' == $action) { ! $filter['kw'] = 'demo'; ! $filter['name'] = ''; } ! $filter_name = $filter['name']; ! $filter_kw = $filter['kw']; ! // Build the query to the database. $query = 'SELECT ! questionID, questionName, questionDescription, questionKeywords, DATE_FORMAT(questionDateLastEdited,"%k:%i, %d/%m/%y"), questionGUID ! FROM stackQuestion ORDER BY questionName, questionKeywords, questionID '; $result = stack_db_query($query); --- 109,124 ---- global $_PHP_SELF; // Sort out how we are going to filter questions. if ('try' == $action) { ! $filter['kw'] = 'demo'; ! $filter['name'] = ''; } ! $question_order = 'ORDER BY questionName, questionKeywords, questionID '; ! // Build the query to the database. $query = 'SELECT ! questionID, questionName, questionDescription, questionKeywords, DATE_FORMAT(questionDateLastEdited,"%k:%i, %d/%m/%y") ! FROM stackQuestion '.$question_order; $result = stack_db_query($query); *************** *** 132,155 **** if(0 != mysql_num_rows($result)) { ! echo "<form name='stackquestionsform' action='{$_PHP_SELF}' method='POST'>\n"; echo "<input type='hidden' name='action' value='edit' />"; ! echo '<table><thead><tr>'; ! if ('edit'==$action) { ! echo '<th></th><th>ID</th><th>Name</th> <th>Key words</th> <th></th><th>Last edit</th>'; ! } else { ! echo '<th></th><th>ID</th><th>Name</th> <th>Key words</th> <th></th><th></th><th></th>'; ! } ! if ('edit' == $action) { ! // Only allow the 'edit' to filter questions. ! echo "</tr>\n"; ! if ('edit_metadata' == $action) { ! echo "<th><a href=\"javascript:SelectQs('edit_metadata');\">Filter</a></th>"; ! } else { ! echo "<th><a href=\"javascript:SelectQs('questionbank_screen');\">Filter</a></th>"; ! } ! echo "<th></th><th><input type='text' name='bank_filter[name]' value='$filter_name' /> ! </th> <th> <input type='text' name='bank_filter[kw]' value='$filter_kw' /> ! </th> </tr></thead><tbody>"; ! } for ($i = 0; $i < mysql_num_rows($result); $i++) { $row = mysql_fetch_row($result); --- 126,138 ---- if(0 != mysql_num_rows($result)) { ! echo "<h2>Question bank</h2><form name='stackquestionsform' action='{$_PHP_SELF}' method='POST'>\n"; echo "<input type='hidden' name='action' value='edit' />"; ! echo '<table>'; ! ! // Print the head of the table, with the filter information. ! stack_db_question_filter_tablehead($action,$filter); ! ! echo '<tbody>'; ! for ($i = 0; $i < mysql_num_rows($result); $i++) { $row = mysql_fetch_row($result); *************** *** 163,171 **** // Decide how to filter questions ! $dispQ = stack_db_question_filter($qname,$qkeywords,$filter_name,$filter_kw); if (FALSE !== $dispQ) { - $guid = $row[5]; - // Display each row of the table if ('edit_metadata' != $action) { --- 146,152 ---- // Decide how to filter questions ! $dispQ = stack_db_question_filter($qname,$qkeywords,$filter['name'],$filter['kw'],$filter['case_sense']); if (FALSE !== $dispQ) { // Display each row of the table if ('edit_metadata' != $action) { *************** *** 225,284 **** * @return void */ ! function stack_db_listquestions_quiz($filter='') { // List all the questions in the database ! ! // Sort out how we are going to filter questions. ! if ('' === $filter) { ! $filter['kw'] = ''; ! $filter['name'] = ''; ! } ! $filter_name = $filter['name']; ! $filter_kw = $filter['kw']; ! $query = 'SELECT ! questionID, questionName, questionKeywords ! FROM stackQuestion ORDER BY questionName, questionKeywords, questionID '; ! $result = stack_db_query($query); ! if(0 != mysql_num_rows($result)) { ! ! echo '<table><thead><tr>'; ! echo "<tr><th>Add</th><th>Question no.</th><th>Name</th> <th>Keyword</th></tr>\n"; ! echo "\n</thead><tbody>\n"; ! for ($i = 0; $i < mysql_num_rows($result); $i++) { ! $row = mysql_fetch_row($result); ! $name = stripslashes($row[1]); ! $qkw = stripslashes($row[2]); ! $dispQ = stack_db_question_filter($name,$qkw,$filter_name,$filter_kw); ! if (FALSE !== $dispQ) { ! $qID = $row[0]; ! $qname = ''; ! if ('' != $name) { ! $name = "<a href=\"javascript:EditPopup('$qID');\">{$name}</a>"; ! } - echo "<tr><td><input type=\"checkbox\" name=\"questionsToAdd[$qID][add]\" value=\"ticked\" /></td>\n"; - echo "<td>$qID</td><td>$name</td><td>$qkw</td> </tr>\n"; ! } // End preg_match to display each line. ! } ! ! echo "</tbody></table>\n"; ! } ! else ! { echo "<p>You currently have no questions in your database.</p>"; } } /** * Decides whether to display a question based upon the name, keywords and filter. * --- 206,300 ---- * @return void */ ! function stack_db_listquestions_quiz($filter,$quizID) { // List all the questions in the database ! global $_PHP_SELF; ! $question_order = 'ORDER BY questionName, questionKeywords, questionID '; ! $query = 'SELECT questionID, questionName, questionKeywords FROM stackQuestion '.$question_order; ! $result = stack_db_query($query); ! if(0 != mysql_num_rows($result)) { ! ! echo "<h2>Add questions to a quiz</h2>\n<p>\n<form name='quizform' action='{$_PHP_SELF}' method='POST'> ! <input type='hidden' name='quizid' value='$quizID'>"; ! echo '<table>'; ! // Print the head of the table, with the filter information. ! stack_db_question_filter_tablehead('add_quiz',$filter,$quizID); ! echo "<tbody>\n"; ! for ($i = 0; $i < mysql_num_rows($result); $i++) { ! $row = mysql_fetch_row($result); ! $name = stripslashes($row[1]); ! $qkw = stripslashes($row[2]); ! $dispQ = stack_db_question_filter($name,$qkw,$filter['name'],$filter['kw'],$filter['case_sense']); ! if (FALSE !== $dispQ) { ! $qID = $row[0]; + $qname = ''; + if ('' != $name) { + $name = "<a href=\"javascript:EditPopup('$qID');\">{$name}</a>"; + } ! echo "<tr><td><input type=\"checkbox\" name=\"questionsToAdd[$qID][add]\" value=\"ticked\" /></td>\n"; ! echo "<td>$qID</td><td>$name</td><td>$qkw</td> </tr>\n"; ! } // End preg_match to display each line. ! ! } ! ! echo "</tbody></table>\n"; ! ! echo '<input type="hidden" name="action" value="quiz_edit" />'; ! echo "<input type=\"submit\" value=\"Add\" />\n</form>\n"; ! ! } else { echo "<p>You currently have no questions in your database.</p>"; } + } /** + * The HTML necessary for the top of the question bank table, to include the filter interactions. + * + * @return void + */ + function stack_db_question_filter_tablehead($action,$filter,$quizid=0) { + + echo "<thead>\n<tr>\n"; + if ('edit'==$action) { + echo '<th></th><th>ID</th><th>Name</th> <th>Key words</th> <th></th><th>Last edit</th>'; + } else { + echo '<th></th><th>ID</th><th>Name</th> <th>Key words</th> <th></th><th></th><th></th>'; + } + if ('edit' == $action or 'edit_metadata' == $action or 'add_quiz'==$action) { + // Only allow the 'edit' to filter questions. + echo "</tr>\n<th>"; + if ('edit_metadata' == $action) { + echo "<a href=\"javascript:SelectQs('edit_metadata');\">Filter</a>"; + } else if ('add_quiz' == $action) { + echo "<a href=\"javascript:takeaction('filter',{$quizid});\">Filter</a>"; + } else { + echo "<a href=\"javascript:SelectQs('questionbank_screen');\">Filter</a>"; + } + echo '</th><th></th>'; + echo '<th><input type="text" name="bank_filter[name]" value="'.$filter['name'].'" /></th>'; + echo '<th><input type="text" name="bank_filter[kw]" value="'.$filter['kw'].'" /></th>'; + if ($filter['case_sense']) { + echo "<th>Case sensitive <input type='checkbox' name='bank_filter[case_sense]' value='TRUE' checked='TRUE' /></th>"; + } else { + echo "<th>Case sensitive <input type='checkbox' name='bank_filter[case_sense]' value='TRUE' /></th>"; + } + echo "</tr></thead>\n"; + } + + } + + /** * Decides whether to display a question based upon the name, keywords and filter. * *************** *** 289,295 **** * @return $dispQ boolean */ ! function stack_db_question_filter($name,$kw,$filter_name,$filter_kw) { $dispQ = TRUE; if ('' != $filter_kw) { --- 305,325 ---- * @return $dispQ boolean */ ! function stack_db_question_filter($name,$kw,$filter_name,$filter_kw,$filter_case=FALSE) { $dispQ = TRUE; + + // This will need to wait for PHP 5 :-( + // if ($filter_case) { + // $foo = 'strpos'; + // } else { + // $foo = 'stripos'; + // } + + if (!$filter_case) { + $name = strtolower($name); + $kw = strtolower($kw); + $filter_name = strtolower($filter_name); + $filter_kw = strtolower($filter_kw); + } if ('' != $filter_kw) { Index: stackAuthor.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackAuthor.php,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** stackAuthor.php 20 Jun 2005 15:42:55 -0000 1.24 --- stackAuthor.php 21 Jun 2005 14:52:25 -0000 1.25 *************** *** 74,80 **** echo "<table cellpadding='4'><tr> ! <td> <b>Option</b> </td> ! <td> <b>Value</b> </td> ! <td> <b>Default</b> </td></tr>"; foreach( $options_list as $k => $opt) { --- 74,80 ---- echo "<table cellpadding='4'><tr> ! <td> <b>".get_string('stackQuestion_questionOptions','stack')."</b> </td> ! <td> <b>".get_string('stackOptions_edit_value','stack')."</b> </td> ! <td> <b>".get_string('stackOptions_edit_default','stack')."</b> </td></tr>"; foreach( $options_list as $k => $opt) { *************** *** 320,324 **** echo "<p><a href=\"javascript:EditQ('edit')\">Edit question</a> \n"; if (''==$errors) { ! echo "<a href=\"javascript:EditQ('preveiw')\">Try question</a> \n"; echo "<a href=\"javascript:EditQ('export_xml')\">Export as XML</a> \n"; if ('admin'==$user['username']) { --- 320,324 ---- echo "<p><a href=\"javascript:EditQ('edit')\">Edit question</a> \n"; if (''==$errors) { ! echo "<a href=\"javascript:EditQ('preview')\">Try question</a> \n"; echo "<a href=\"javascript:EditQ('export_xml')\">Export as XML</a> \n"; if ('admin'==$user['username']) { *************** *** 330,334 **** } ! $options_headings = array('Input methods','','','','Response Processing','','','','','','Output',''); $options_list = array('InsertStars','InformalSyntax','AllowInputTool','SyntaxHint','Forbid','Allow','MarkModMethod','FeedBackGenericCorrect','FeedBackGenericPCorrect','FeedBackGenericIncorrect','Display','ShowSol'); --- 330,334 ---- } ! $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','ShowSol'); *************** *** 418,425 **** echo "<tr>\n <td>No.</td>\n <td></td>\n ! <td><a href=\"javascript:HelpPopup('SAns','stackQuestionPotResp');\">SAns</a></td>\n ! <td><a href=\"javascript:HelpPopup('TAns','stackQuestionPotResp');\">TAns</a></td>\n ! <td><a href=\"javascript:HelpPopup('AnsTest','stackOptions');\">AnswerTest</a></td>\n ! <td><a href=\"javascript:HelpPopup('AnsTestOpt','stackOptions');\">AT opts</a></td> <td>Del</td>\n </tr>\n"; --- 418,425 ---- echo "<tr>\n <td>No.</td>\n <td></td>\n ! <td><a href=\"javascript:HelpPopup('SAns','stackQuestionPotResp');\">".get_string('stackQuestion_PR_SAns2','stack')."</a></td>\n ! <td><a href=\"javascript:HelpPopup('TAns','stackQuestionPotResp');\">".get_string('stackQuestion_PR_TAns2','stack')."</a></td>\n ! <td><a href=\"javascript:HelpPopup('AnsTest','stackOptions');\">".get_string('stackQuestion_PR_AnsTest','stack')."</a></td>\n ! <td><a href=\"javascript:HelpPopup('AnsTestOpt','stackOptions');\">".get_string('stackQuestion_PR_AnsTestOpts','stack')."</a></td> <td>Del</td>\n </tr>\n"; *************** *** 462,470 **** echo "<tr align=top><td>If...</td>\n ! <td><a href=\"javascript:HelpPopup('RawMarkMod','stackQuestionPotResp');\">Mark</a></td>\n ! <td><a href=\"javascript:HelpPopup('RawMark','stackQuestionPotResp');\">Value</a></td>\n ! <td><a href=\"javascript:HelpPopup('Penalty','stackQuestionPotResp');\">Penalty</a></td>\n ! <td colspan='2'><a href=\"javascript:HelpPopup('FeedBack','stackQuestionPotResp');\">Feedback</a></td>\n ! <td><a href=\"javascript:HelpPopup('ApLat','stackQuestionPotResp');\">Next</a></td>\n"; echo "<td></td></tr>\n"; --- 462,470 ---- echo "<tr align=top><td>If...</td>\n ! <td><a href=\"javascript:HelpPopup('RawMarkMod','stackQuestionPotResp');\">".get_string('stackQuestion_PR_RawMarkMod2','stack')."</a></td>\n ! <td><a href=\"javascript:HelpPopup('RawMark','stackQuestionPotResp');\">".get_string('Score','stack')."</a></td>\n ! <td><a href=\"javascript:HelpPopup('Penalty','stackQuestionPotResp');\">".get_string('stackQuestion_PR_Penalty','stack')."</a></td>\n ! <td colspan='2'><a href=\"javascript:HelpPopup('FeedBack','stackQuestionPotResp');\">".get_string('stackQuestion_PR_FeedBack','stack')."</a></td>\n ! <td><a href=\"javascript:HelpPopup('ApLat','stackQuestionPotResp');\">".get_string('stackQuestion_PR_ApLat2','stack')."</a></td>\n"; echo "<td></td></tr>\n"; *************** *** 489,493 **** echo "<tr><td></td> <td></td><td align ='right' colspan='2'><a href=\"javascript:HelpPopup('AnswerNote','stackQuestionPotResp');\">AnswerNote</a></td>"; $strin = $potresp['true']['AnswerNote']; ! stack_question_edit_input_textfield($bname,$strin,'AnswerNote',55,3); echo "</tr>"; --- 489,493 ---- echo "<tr><td></td> <td></td><td align ='right' colspan='2'><a href=\"javascript:HelpPopup('AnswerNote','stackQuestionPotResp');\">AnswerNote</a></td>"; $strin = $potresp['true']['AnswerNote']; ! stack_question_edit_input_textfield($bname,$strin,get_string('stackQuestion_PR_AnswerNote','stack'),55,3); echo "</tr>"; *************** *** 714,718 **** } ! $options_headings = array('Input methods','','','','Response Processing','','','','','','','','','','Output','',''); $options_list = array('InsertStars','InformalSyntax','AllowInputTool','SyntaxHint','AnsTest','AnsTestOpt','QuVal','Penalty','Forbid','Allow','MarkModMethod','FeedBackGenericCorrect','FeedBackGenericPCorrect','FeedBackGenericIncorrect','Display','ShowSol','Language'); $fieldname = 'quiz[quizOptions]'; --- 714,718 ---- } ! $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','MarkModMethod','FeedBackGenericCorrect','FeedBackGenericPCorrect','FeedBackGenericIncorrect','Display','ShowSol','Language'); $fieldname = 'quiz[quizOptions]'; Index: stackQuestion.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackQuestion.php,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** stackQuestion.php 20 Jun 2005 15:42:55 -0000 1.20 --- stackQuestion.php 21 Jun 2005 14:52:26 -0000 1.21 *************** *** 12,15 **** --- 12,240 ---- + //****************************************************** + //** Options + // + // descript = The string which is displayed on screen + // type = string, free string value + // = html, HTML text + // = email, email address (validates) + // = url, URL (validates) + // = list, + // = number, + // values = possible values, for a list this is an array. + // default = default value. There must be one! + //****************************************************** + + + // "Insert *s where needed"; + $stackOptions['InsertStars']['type'] = 'list'; + $stackOptions['InsertStars']['values'] = array('TRUE','FALSE'); + $stackOptions['InsertStars']['default'] = 'FALSE'; + + // 'Allow informal syntax'; + $stackOptions['InformalSyntax']['type'] = 'list'; + $stackOptions['InformalSyntax']['values'] = array('TRUE','FALSE'); + $stackOptions['InformalSyntax']['default'] = 'TRUE'; + + // 'Input tools'; + $stackOptions['AllowInputTool']['type'] = 'list'; + $stackOptions['AllowInputTool']['values'] = array('Form box','Form box + JOME'); + $stackOptions['AllowInputTool']['default'] = 'Form box + JOME'; + + // 'Syntax Hint'; + $stackOptions['SyntaxHint']['type'] = 'string'; + $stackOptions['SyntaxHint']['values'] = ''; + $stackOptions['SyntaxHint']['default'] = ''; + + // 'Display'; + $stackOptions['Display']['type'] = 'list'; + $stackOptions['Display']['values'] = array('String','LaTeX','MathML','LaTeX Source'); + $stackOptions['Display']['default'] = 'LaTeX'; + + // 'Language'; + $stackOptions['Language']['type'] = 'list'; + $stackOptions['Language']['values'] = array('en','es','nl'); + $stackOptions['Language']['default'] = 'en'; + + // 'Question value'; + $stackOptions['QuVal']['type'] = 'number'; + $stackOptions['QuVal']['values'] = ''; + $stackOptions['QuVal']['default'] = '1'; + + // 'Mark modification method'; + $stackOptions['MarkModMethod']['type'] = 'list'; + $stackOptions['MarkModMethod']['values'] = array('Penalty','Last Answer'); + $stackOptions['MarkModMethod']['default'] = 'Penalty'; + + // 'Question penalty'; + $stackOptions['Penalty']['type'] = 'number'; + $stackOptions['Penalty']['values'] = ''; + $stackOptions['Penalty']['default'] = '0.1'; + + // 'Forbidden words'; + $stackOptions['Forbid']['type'] = 'string'; + $stackOptions['Forbid']['values'] = ''; + $stackOptions['Forbid']['default'] = ''; + + // 'Allowed words'; + $stackOptions['Allow']['type'] = 'string'; + $stackOptions['Allow']['values'] = ''; + $stackOptions['Allow']['default'] = ''; + + // 'Answer test'; + $stackOptions['AnsTest']['type'] = 'list'; + $stackOptions['AnsTest']['values'] = ''; // This is automatically defined below, after the answer tests. + $stackOptions['AnsTest']['default'] = 'AlgEquiv'; + + // 'Answer test options'; + $stackOptions['AnsTestOpt']['type'] = 'string'; + $stackOptions['AnsTestOpt']['values'] = ''; + $stackOptions['AnsTestOpt']['default'] = ''; + + // "Teacher's email"; + $stackOptions['TeacherEmail']['type'] = 'string'; + $stackOptions['TeacherEmail']['values'] = ''; + $stackOptions['TeacherEmail']['default'] = ''; + + // 'Feedback: correct'; + $stackOptions['FeedBackGenericCorrect']['type'] = 'html'; + $stackOptions['FeedBackGenericCorrect']['values'] = ''; + $stackOptions['FeedBackGenericCorrect']['default'] = get_string('stackOptions_FeedBackGenericCorrect_def','stack',''); + + // 'Feedback: incorrect'; + $stackOptions['FeedBackGenericIncorrect']['type'] = 'html'; + $stackOptions['FeedBackGenericIncorrect']['values'] = ''; + $stackOptions['FeedBackGenericIncorrect']['default'] = get_string('stackOptions_FeedBackGenericIncorrect_def','stack',''); + + // 'Feedback: partially correct'; + $stackOptions['FeedBackGenericPCorrect']['type'] = 'html'; + $stackOptions['FeedBackGenericPCorrect']['values'] = ''; + $stackOptions['FeedBackGenericPCorrect']['default'] = get_string('stackOptions_FeedBackGenericPCorrect_def','stack',''); + + + // 'Show solution'; + $stackOptions['ShowSol']['type']='list'; + $stackOptions['ShowSol']['values']=array('Always','Never','On request','After correct answer'); + $stackOptions['ShowSol']['default']='On request'; + + /** + * Validates options, removing any blank or default values. + * This should also eventually validate the value of each option. + * + * @param array The options array + * @return void + */ + function stack_options_validate(&$options) { + global $stackOptions; + + // Do we have an array of options? + if (is_array($options)) { + + foreach ($stackOptions as $opt => $fields) { + if (array_key_exists($opt,$options)) { + // Option is set in the $options + if (''==trim($options[$opt]) or 'default'==trim($options[$opt])) { + // But, the option has no value, or is specified 'default' + unset($options[$opt]); // Get rid of this from the question. + } + } + } // end foreach + // Do we have anything left? + if (NULL == array_keys($options)) { + $options=NULL; + } + } + + } + + + /** + * Sets the cascading options, first taking the defaults, then using the subject + * quiz, and finally question values. + * + * @param array &$question The STACK question, required + * @param array &$quiz_options The STACK quiz options array *NOT* the whole quiz, optional + * @param array &$subject The STACK subject options array *NOT* the whole quiz, optional + * @return array The list of options + */ + function stack_options_set($question,$quiz_options=NULL,$subject=NULL) { + global $stackOptions; + + $options = array(); + + //(0) Set the default options. + foreach ($stackOptions as $opnam => $fields) { + $options[$opnam] = $fields['default']; + } + + //(1) Now look in the $question. + if (is_array($question)) { + if (array_key_exists('questionOptions',$question)) { + $qOpt = $question['questionOptions']; + + // Do we have any set options? + if (is_array($qOpt)){ + foreach ($stackOptions as $opt => $fields) { + if (array_key_exists($opt,$qOpt)) { + // Actually take the option which is set, and use it! + $options[$opt] = $qOpt[$opt]; + } + } // end foreach + } + } + } + + //(2) Now look in the $quiz_options + if (is_array($quiz_options)) { + foreach ($stackOptions as $opt => $fields) { + if (array_key_exists($opt,$quiz_options)) { + // Actually take the option which is set, and use it! + $options[$opt] = $quiz_options[$opt]; + } + } // end foreach + } + + return($options); + } + + /** + * Build an array of forbidden strings + * + * @param array $options The STACK option settings + * @return array The list of forbidden words + */ + function stack_options_forbidden($options) { + // Build an array of forbidden strings. + // The fields 'Forbid' and 'Allow' should be in the $options, + // Even if empty strings. + + if (''!= trim($options['Forbid']) ) { // There is at least one forbidden word + $forb = explode(',',$options['Forbid']); + $forb = array_unique(array_map('trim',$forb)); + } else { + $forb = ''; + } + + if (''!= trim($options['Allow']) ) { // There is at least one allowed word + $allow = explode(',',$options['Allow']); + $allow = array_unique(array_map('trim',$allow)); + } else { + $allow = ''; + } + + if (is_array($forb)) { // There are some forbidden words + if (is_array($allow)) {// There are some allowed words + $forbid = array_diff($forb,$allow); // Take out the allowed ones. + } else { + $forbid = $forb; + } + } else { + $forbid = ''; + } // No forbidden words + + return($forbid); + } + + //////////////////////////////////////////////////////////////////////// // $stackQuestion *************** *** 300,303 **** --- 525,536 ---- $stackAnswerTest['True']['imp'] = 'php'; + // Build a list of AnswerTests. + // and add these to the options. + $ats = ''; + foreach( $stackAnswerTest as $field => $q_field) + { $ats[] = $field; } + + $stackOptions['AnsTest']['values'] = $ats; + //****************************************************** *************** *** 642,873 **** - //****************************************************** - //** Options - // - // descript = The string which is displayed on screen - // type = string, free string value - // = html, HTML text - // = email, email address (validates) - // = url, URL (validates) - // = list, - // = number, - // values = possible values, for a list this is an array. - // default = default value. There must be one! - //****************************************************** - - - // "Insert *s where needed"; - $stackOptions['InsertStars']['type'] = 'list'; - $stackOptions['InsertStars']['values'] = array('TRUE','FALSE'); - $stackOptions['InsertStars']['default'] = 'FALSE'; - - // 'Allow informal syntax'; - $stackOptions['InformalSyntax']['type'] = 'list'; - $stackOptions['InformalSyntax']['values'] = array('TRUE','FALSE'); - $stackOptions['InformalSyntax']['default'] = 'TRUE'; - - // 'Input tools'; - $stackOptions['AllowInputTool']['type'] = 'list'; - $stackOptions['AllowInputTool']['values'] = array('Form box','Form box + JOME'); - $stackOptions['AllowInputTool']['default'] = 'Form box + JOME'; - - // 'Syntax Hint'; - $stackOptions['SyntaxHint']['type'] = 'string'; - $stackOptions['SyntaxHint']['values'] = ''; - $stackOptions['SyntaxHint']['default'] = ''; - - // 'Display'; - $stackOptions['Display']['type'] = 'list'; - $stackOptions['Display']['values'] = array('String','LaTeX','MathML','LaTeX Source'); - $stackOptions['Display']['default'] = 'LaTeX'; - - // 'Language'; - $stackOptions['Language']['type'] = 'list'; - $stackOptions['Language']['values'] = array('en','es','nl'); - $stackOptions['Language']['default'] = 'en'; - - // 'Question value'; - $stackOptions['QuVal']['type'] = 'number'; - $stackOptions['QuVal']['values'] = ''; - $stackOptions['QuVal']['default'] = '1'; - - // 'Mark modification method'; - $stackOptions['MarkModMethod']['type'] = 'list'; - $stackOptions['MarkModMethod']['values'] = array('Penalty','Last Answer'); - $stackOptions['MarkModMethod']['default'] = 'Penalty'; - - // 'Question penalty'; - $stackOptions['Penalty']['type'] = 'number'; - $stackOptions['Penalty']['values'] = ''; - $stackOptions['Penalty']['default'] = '0.1'; - - // 'Forbidden words'; - $stackOptions['Forbid']['type'] = 'string'; - $stackOptions['Forbid']['values'] = ''; - $stackOptions['Forbid']['default'] = ''; - - // 'Allowed words'; - $stackOptions['Allow']['type'] = 'string'; - $stackOptions['Allow']['values'] = ''; - $stackOptions['Allow']['default'] = ''; - - // Build a list of AnswerTests. - $ats = ''; - foreach( $stackAnswerTest as $field => $q_field) - { $ats[] = $field; } - - // 'Answer test'; - $stackOptions['AnsTest']['type'] = 'list'; - $stackOptions['AnsTest']['values'] = $ats; - $stackOptions['AnsTest']['default'] = 'AlgEquiv'; - - // 'Answer test options'; - $stackOptions['AnsTestOpt']['type'] = 'string'; - $stackOptions['AnsTestOpt']['values'] = ''; - $stackOptions['AnsTestOpt']['default'] = ''; - - // "Teacher's email"; - $stackOptions['TeacherEmail']['type'] = 'string'; - $stackOptions['TeacherEmail']['values'] = ''; - $stackOptions['TeacherEmail']['default'] = ''; - - // 'Feedback: correct'; - $stackOptions['FeedBackGenericCorrect']['type'] = 'html'; - $stackOptions['FeedBackGenericCorrect']['values'] = ''; - $stackOptions['FeedBackGenericCorrect']['default'] = get_string('stackOptions_FeedBackGenericCorrect_def','stack',''); - - // 'Feedback: incorrect'; - $stackOptions['FeedBackGenericIncorrect']['type'] = 'html'; - $stackOptions['FeedBackGenericIncorrect']['values'] = ''; - $stackOptions['FeedBackGenericIncorrect']['default'] = get_string('stackOptions_FeedBackGenericIncorrect_def','stack',''); - - // 'Feedback: partially correct'; - $stackOptions['FeedBackGenericPCorrect']['type'] = 'html'; - $stackOptions['FeedBackGenericPCorrect']['values'] = ''; - $stackOptions['FeedBackGenericPCorrect']['default'] = get_string('stackOptions_FeedBackGenericPCorrect_def','stack',''); - - - // 'Show solution'; - $stackOptions['ShowSol']['type']='list'; - $stackOptions['ShowSol']['values']=array('Always','Never','On request','After correct answer'); - $stackOptions['ShowSol']['default']='On request'; - - /** - * Validates options, removing any blank or default values. - * This should also eventually validate the value of each option. - * - * @param array The options array - * @return void - */ - function stack_options_validate(&$options) { - global $stackOptions; - - // Do we have an array of options? - if (is_array($options)) { - - foreach ($stackOptions as $opt => $fields) { - if (array_key_exists($opt,$options)) { - // Option is set in the $options - if (''==trim($options[$opt]) or 'default'==trim($options[$opt])) { - // But, the option has no value, or is specified 'default' - unset($options[$opt]); // Get rid of this from the question. - } - } - } // end foreach - // Do we have anything left? - if (NULL == array_keys($options)) { - $options=NULL; - } - } - - } - - - /** - * Sets the cascading options, first taking the defaults, then using the subject - * quiz, and finally question values. - * - * @param array &$question The STACK question, required - * @param array &$quiz_options The STACK quiz options array *NOT* the whole quiz, optional - * @param array &$subject The STACK subject options array *NOT* the whole quiz, optional - * @return array The list of options - */ - function stack_options_set($question,$quiz_options=NULL,$subject=NULL) { - global $stackOptions; - - $options = array(); - - //(0) Set the default options. - foreach ($stackOptions as $opnam => $fields) { - $options[$opnam] = $fields['default']; - } - - //(1) Now look in the $question. - if (is_array($question)) { - if (array_key_exists('questionOptions',$question)) { - $qOpt = $question['questionOptions']; - - // Do we have any set options? - if (is_array($qOpt)){ - foreach ($stackOptions as $opt => $fields) { - if (array_key_exists($opt,$qOpt)) { - // Actually take the option which is set, and use it! - $options[$opt] = $qOpt[$opt]; - } - } // end foreach - } - } - } - - //(2) Now look in the $quiz_options - if (is_array($quiz_options)) { - foreach ($stackOptions as $opt => $fields) { - if (array_key_exists($opt,$quiz_options)) { - // Actually take the option which is set, and use it! - $options[$opt] = $quiz_options[$opt]; - } - } // end foreach - } - - return($options); - } - - /** - * Build an array of forbidden strings - * - * @param array $options The STACK option settings - * @return array The list of forbidden words - */ - function stack_options_forbidden($options) { - // Build an array of forbidden strings. - // The fields 'Forbid' and 'Allow' should be in the $options, - // Even if empty strings. - - if (''!= trim($options['Forbid']) ) { // There is at least one forbidden word - $forb = explode(',',$options['Forbid']); - $forb = array_unique(array_map('trim',$forb)); - } else { - $forb = ''; - } - - if (''!= trim($options['Allow']) ) { // There is at least one allowed word - $allow = explode(',',$options['Allow']); - $allow = array_unique(array_map('trim',$allow)); - } else { - $allow = ''; - } - - if (is_array($forb)) { // There are some forbidden words - if (is_array($allow)) {// There are some allowed words - $forbid = array_diff($forb,$allow); // Take out the allowed ones. - } else { - $forbid = $forb; - } - } else { - $forbid = ''; - } // No forbidden words - - return($forbid); - } --- 875,878 ---- |