From: pkiddie <pk...@us...> - 2005-08-25 15:46:30
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12713/scripts Modified Files: Tag: development_xmlrqp stackAuthor.php stackXML.php Log Message: Latest version of DOMIT. Dynamic schemas saved to users temp_logfiles directory, as they may need updating over time, and server has write permissions Removed old schema related stuff Fixed bug in import code Index: stackAuthor.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackAuthor.php,v retrieving revision 1.29.2.13 retrieving revision 1.29.2.14 diff -C2 -d -r1.29.2.13 -r1.29.2.14 *** stackAuthor.php 22 Aug 2005 17:20:18 -0000 1.29.2.13 --- stackAuthor.php 25 Aug 2005 15:46:21 -0000 1.29.2.14 *************** *** 160,163 **** --- 160,393 ---- } + function stack_question_edit_form_rqp($question,&$errors,$PostTo = '') { + global $_PHP_SELF; + + $html = ''; + //show_array($question); + + if (empty($PostTo)) { + $PostTo=$_PHP_SELF; + } + + // Timestamp this edit + $html .= "<form name='stackeditqform' action='$PostTo' method='POST'>\n"; + + $html .=stack_question_edit_form_substance_rqp($question,$errors); + + $html .= "<input type='hidden' name='action' value='' />\n"; + $html .= "<submit name='dummy' value=''>"; + $html .= "</form>\n\n\n"; // form in which questions are edited. + + return $html; + } + + /** + * Build the substance of the form to edit a STACK question. + * This needs to be wrapped in a <form> </form> structure. + * + * @param array $question The STACK question + * @param array &$errors Repository for errors + * @return void + */ + function stack_question_edit_form_substance_rqp($question,&$errors) { + global $stack_stand_alone,$stackQuestion,$stackOptions,$debug,$user; + + $t=time(); + $dts = strftime('%c',$t); // Format the string. + $html = ''; + + if (array_key_exists('questionOptions',$question)) { // option set in question + $question_options = $question['questionOptions']; + } else { + $question_options = array(); + } + $optval = stack_options_formvals_set($question_options); + + // Add all the metadata to the question + + // hidden metadata + $html .= "\n<hr />\n + <input type='hidden' name='questionID' value='".sf($question,'questionID')."' />\n + <input type='hidden' name='questionGUID' value='".sf($question,'questionGUID')."' />\n + <input type='hidden' name='questionDateLastEdited' value='$t' />\n + <input type='hidden' name='questionUserLastEdited' value='".sf($question,'questionUserLastEdited')."' />\n + <input type='hidden' name='questionPublisher' value='".sf($question,'questionPublisher')."' />\n + <input type='hidden' name='type' value='".sf($question,'type')."' />\n + <input type='hidden' name='questionFormat' value='".sf($question,'questionFormat')."' />\n + + <table cellboarder='0' cellpadding='2'> + <tr> <td>".get_string('stackQuestion_questionName','stack','').":</td> + <td><input type='input' name='questionName' value='".sf($question,'questionName')."' size='25' /> (ID: ".sf($question,'questionID').") </td> </tr> + <tr> <td>".get_string('stackQuestion_questionDescription','stack','').":</td> + <td><input type='input' name='questionDescription' value='".sf($question,'questionDescription')."' size='60' /></tr> + <tr> <td>".get_string('stackQuestion_questionKeywords','stack','').":</td> + <td><input type='input' name='questionKeywords' value='".sf($question,'questionKeywords')."' size='60' /></tr> + + </table> "; + + // HACK: the field type in the database does not + // allow these to be edited yet. + // <tr> <td> Last edited by: </td> + // <td> <input type='input' name='questionUserLastEdited' value='".stack_s($question['questionUserLastEdited'])."' size='40' /> on $dts.</td> + // </tr> + + $html .= "\n<hr />\n"; + + // Buttons to go somewhere next + if ($stack_stand_alone) { + $html .= "<a href=\"javascript:EditQ('edit')\">Edit question</a> \n"; + if (''==$errors) { + $html .= "<a href=\"javascript:EditQ('preview')\">Try question</a> \n"; + $html .= "<a href=\"javascript:EditQ('export_xml')\">Export as XML</a> \n"; + if ('admin'==$user['username']) { + $html .= "<a href=\"javascript:EditQ('save')\">Store question</a>\n + <a href=\"javascript:EditQ('save_as')\">Store as a new question </a>\n"; + } + } + $html .= "</p>"; + } + + // Add the meat of the question. + $qfield='questionVarsRaw'; + $html .= "<b>".stack_question_edit_dispquestionfield($qfield)."</b><br />"; + + // Replace all \n's with ;'s + if (array_key_exists($qfield,$question)) { + $strout = str_replace(";","\n",$question[$qfield]); + } else { $strout = ''; } + stack_question_edit_form_field($qfield,$strout,$errors); + $html .= "\n\n<br />\n"; + + $qfield='questionStem'; + $html .= "<b>".stack_question_edit_dispquestionfield($qfield)."</b><br />"; + @stack_question_edit_form_field($qfield,$question[$qfield],$errors); + + $html .= "<p><table align=top><tr align=top>\n"; + if (array_key_exists('questionPotResp',$question)) { + $html .= " <td><b>".stack_question_edit_dispquestionfield('questionAns')."</b></td>\n"; + $html .= "<td> </td></tr>\n\n<tr align=top>\n <td align=top>"; + $qfield='questionAns'; + @stack_question_edit_form_field($qfield,$question[$qfield],$errors); + $html .= "</td>\n <td> </td></tr>"; + } else { + // The questionAns and associated fields + + $html .= " <td><b>".stack_question_edit_dispquestionfield('questionAns')."</b></td>\n"; + $html .= " <td><b>".stack_question_edit_dispoptionfield('AnsTest')."</b></td>\n"; + $html .= " <td><b>".stack_question_edit_dispoptionfield('AnsTestOpt')."</b></td>\n"; + $html .= "</tr>\n\n<tr align=top>\n <td align=top>"; + + $qfield='questionAns'; + @stack_question_edit_form_field($qfield,$question[$qfield],$errors); + $html .= "</td>\n <td align=top>\n"; + + $opt = 'AnsTest'; + $opt_name = "questionOptions[{$opt}]"; + @stack_question_edit_option_form($opt_name,$opt,$optval[$opt]); + $html .= "</td>\n <td align=top>\n"; + + $opt = 'AnsTestOpt'; + $opt_name = "questionOptions[{$opt}]"; + @stack_question_edit_option_form($opt_name,$opt,$optval[$opt],20); + $html .= "</td>\n</tr>"; + + $html .= "<tr align=top><td></td> + <td>({$stackOptions['AnsTest']['default']})</td> + <td>{$stackOptions['AnsTestOpt']['default']}</td></tr>"; + } + + $html .= "<tr align=top>\n"; + $html .= " <td> <b>".stack_question_edit_dispoptionfield('QuVal')."</b></td>\n"; + $html .= " <td> <b>".stack_question_edit_dispoptionfield('Penalty')."</b></td>\n"; + $html .= "<td></td><td></td></tr>\n<tr>\n <td>"; + + $opt = 'QuVal'; + $opt_name = "questionOptions[{$opt}]"; + @stack_question_edit_option_form($opt_name,$opt,$optval[$opt]); + $html .= " ({$stackOptions[$opt]['default']})</td>\n <td>\n"; + + $opt = 'Penalty'; + $opt_name = "questionOptions[{$opt}]"; + @stack_question_edit_option_form($opt_name,$opt,$optval[$opt]); + $html .= " ({$stackOptions[$opt]['default']})</td>\n <td>\n"; + + $html .= "</table></p>\n\n"; + + // Potential responses + $html .= "<br /><a href=\"javascript:EditQ('edit')\">Edit</a> and add \n"; + $html .= '<input type="input" name="questionPotResp[add]" value="0" size="3" />'; + $html .= " potential responses<a href=\"javascript:HelpPopup('all','author_potresp');\"><img align=\"middle\" border=\"0\" height=\"17\" width=\"17\" src=\"pics/help.gif\" /></a> (distractors etc).<br />"; + + if (array_key_exists('questionPotResp',$question)) { + if (array_key_exists('0',$question['questionPotResp'])) { + // Add the AnsKey field + $qfield='questionAnsKey'; + $html .= '<p><b>'.stack_question_edit_dispquestionfield($qfield).'</b><br />'; + @stack_question_edit_form_field($qfield,$question[$qfield],$errors); + $html .= '</p>'; + + // Add the AnsVars field, isnce this may now be used. + $qfield='questionAnsVarsRaw'; + $html .= '<b>'.stack_question_edit_dispquestionfield($qfield).'</b><br />'; + $strout = ''; + if (array_key_exists($qfield,$question)) { + $strout = str_replace(";","\n",$question[$qfield]); + } + @stack_question_edit_form_field($qfield,$strout,$errors); + $html .= "\n\n<br />\n"; + + $html .= '<p>'; + $npr = count($question['questionPotResp']); + foreach ($question['questionPotResp'] as $key => $potresp) { + $potresp['order']=$key; + @stack_question_edit_potresp($key,$potresp,$npr,$errors); + } + $html .= '</p>'; + + } // end questionPotResp + } else { // This needs its default, non-empty value. + $html .= "<input type='hidden' name='questionAnsKey' value='".stack_s($question['questionAnsKey'])."' />\n"; + } + + $qfield='questionSol'; + $html .= '<b>'.stack_question_edit_dispquestionfield($qfield).'</b><br />'; + @stack_question_edit_form_field($qfield,$question[$qfield],$errors); + $html .= "\n\n<br />\n"; + + $qfield='questionNote'; + $html .= '<b>'.stack_question_edit_dispquestionfield($qfield).'</b><br />'; + @stack_question_edit_form_field($qfield,$question[$qfield],$errors); + $html .= "\n\n<br />\n"; + + // Buttons to go somewhere next + if ($stack_stand_alone) { + $html .= "<p><a href=\"javascript:EditQ('edit')\">Edit question</a> \n"; + if (''==$errors) { + $html .= "<a href=\"javascript:EditQ('preview')\">Try question</a> \n"; + $html .= "<a href=\"javascript:EditQ('export_xml')\">Export as XML</a> \n"; + if ('admin'==$user['username']) { + $html .= "<a href=\"javascript:EditQ('save')\">Store question</a>\n + <a href=\"javascript:EditQ('save_as')\">Store as a new question</a>\n"; + } + } + $html .= "</p>"; + } + + $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'); + + $html .= "\n<hr />\n"; + + //List of metadata to display + $metadata_list = array('questionLanguage','questionLearningContext','questionDifficulty','questionCompetency', + 'questionCompetencyLevel','questionTimeAllocated','questionExcerciseType','questionRights'); + stack_question_metadata_edit_form($question,$metadata_list); //Create all metadata fields on question form + + $html .= "\n<hr />\n"; + + return $html; + } // end of edit_form_table /** Index: stackXML.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackXML.php,v retrieving revision 1.13.2.20 retrieving revision 1.13.2.21 diff -C2 -d -r1.13.2.20 -r1.13.2.21 *** stackXML.php 23 Aug 2005 10:18:08 -0000 1.13.2.20 --- stackXML.php 25 Aug 2005 15:46:21 -0000 1.13.2.21 *************** *** 56,59 **** --- 56,61 ---- define ('quizSchemaName',"stack_quiz.xsd"); + define ('schemaBaseDir',"{$stack_logfiles}/schemas"); + /** * Writes a single stackQuestion data structure as XML, and returns the containing *************** *** 95,99 **** * @return DOMIT_Element $questionFrag The root assessmentItem node with child question elements */ ! function stack_xml_create_question_frag_new($question) { global $stackQuestion, $stack_ver, $xmlNamespaces; --- 97,101 ---- * @return DOMIT_Element $questionFrag The root assessmentItem node with child question elements */ ! function &stack_xml_create_question_frag_new($question) { global $stackQuestion, $stack_ver, $xmlNamespaces; *************** *** 355,359 **** * @return DOMIT_Element $quizFrag The root mathQuiz node with child quiz elements */ ! function stack_xml_create_quiz_frag_new($quiz) { global $stackQuiz, $xmlNamespaces; --- 357,361 ---- * @return DOMIT_Element $quizFrag The root mathQuiz node with child quiz elements */ ! function &stack_xml_create_quiz_frag_new($quiz) { global $stackQuiz, $xmlNamespaces; *************** *** 564,568 **** * @return DOMIT_Element $quListFrag The root mathQuiz node. */ ! function stack_xml_create_question_list_frag() { $xmlDoc = &new DOMIT_Document(); --- 566,570 ---- * @return DOMIT_Element $quListFrag The root mathQuiz node. */ ! function &stack_xml_create_question_list_frag() { $xmlDoc = &new DOMIT_Document(); *************** *** 599,603 **** //Now must give location of schema from which this instance has been derived from $schemaLocationAttr = &new DOMIT_Attr('xsi:noNamespaceSchemaLocation'); ! $schemaLocationAttr->nodeValue="{$stack_root}/schemas/".questionSchemaName; //Use 'define' above //Used to ensure latest schema version is used --- 601,605 ---- //Now must give location of schema from which this instance has been derived from $schemaLocationAttr = &new DOMIT_Attr('xsi:noNamespaceSchemaLocation'); ! $schemaLocationAttr->nodeValue=schemaBaseDir.'/'.questionSchemaName; //Use 'define' above //Used to ensure latest schema version is used *************** *** 637,641 **** //Now must give location of schema from which this instance has been derived from $schemaLocationAttr = &new DOMIT_Attr('xsi:noNamespaceSchemaLocation'); ! $schemaLocationAttr->nodeValue="{$stack_root}/schemas/".quizSchemaName; //Use 'define' above //Used to ensure latest schema version is used --- 639,643 ---- //Now must give location of schema from which this instance has been derived from $schemaLocationAttr = &new DOMIT_Attr('xsi:noNamespaceSchemaLocation'); ! $schemaLocationAttr->nodeValue=schemaBaseDir.'/'.quizSchemaName; //Use 'define' above //Used to ensure latest schema version is used *************** *** 791,796 **** //In the first instance, check what type of file we are dealing with //Retrieve the document element ! $headElement = $xmlDoc->documentElement; ! //Now retrieve the version number attached to the XML file being imported, and check for equality $importXmlVersion = $headElement->getAttribute('version'); --- 793,798 ---- //In the first instance, check what type of file we are dealing with //Retrieve the document element ! $headElement = &$xmlDoc->documentElement; ! //Now retrieve the version number attached to the XML file being imported, and check for equality $importXmlVersion = $headElement->getAttribute('version'); *************** *** 802,811 **** else { //XML file has a version attached to it, ! $schemaVersion = stack_xml_check_schema_version("{$stack_root}/schemas/"); //Check that XML matches version with schema if ($importXmlVersion==$schemaVersion) { switch ($headElement->nodeName) ! { case('assessmentItem'): { --- 804,813 ---- else { //XML file has a version attached to it, ! $schemaVersion = stack_xml_check_schema_version(schemaBaseDir); //Check that XML matches version with schema if ($importXmlVersion==$schemaVersion) { switch ($headElement->nodeName) ! { case('assessmentItem'): { *************** *** 848,851 **** --- 850,883 ---- /** + * Begins the recursive algorithm responsible for a importing a question XML file into a multidimensional array. Returns + * the final data structure + * + * @param DOMIT_Document $questionXmlDoc The DOM XML document representing the question + * @return array $question A question data structure + */ + function stack_xml_parse_question($questionXmlDoc) + { + $question = array(); + $elements = &$questionXmlDoc->documentElement; + stack_xml_parse_element_into_array($elements,$question['assessmentItem'],'stackQuestion'); + return $question; + } + + /** + * Begins the recursive algorithm responsible for a importing a quiz XML file into a multidimensional array. Returns + * the final data structure + * + * @param DOMIT_Document $quizXmlDoc The DOM XML document representing the quiz + * @return array $quiz A quiz data structure + */ + function stack_xml_parse_quiz($quizXmlDoc) + { + $quiz = array(); + $elements = &$quizXmlDoc->documentElement; + stack_xml_parse_element_into_array($elements,$quiz['mathQuiz'],'stackQuiz'); + return $quiz; + } + + /** * Maps an element from a particular namespace, i.e. dc:keyword, onto the correct stackQuestion or stackQuiz data structure keyword, * i.e. questionKeywords or quizKeywords, when exporting/importing XML *************** *** 899,932 **** /** - * Begins the recursive algorithm responsible for a importing a question XML file into a multidimensional array. Returns - * the final data structure - * - * @param DOMIT_Document $questionXmlDoc The DOM XML document representing the question - * @return array $question A question data structure - */ - function stack_xml_parse_question(&$questionXmlDoc) - { - $question = array(); - $elements = &$questionXmlDoc->documentElement; - stack_xml_parse_element_into_array($elements,$question['assessmentItem'],'stackQuestion'); - return $question; - } - - /** - * Begins the recursive algorithm responsible for a importing a quiz XML file into a multidimensional array. Returns - * the final data structure - * - * @param DOMIT_Document $quizXmlDoc The DOM XML document representing the quiz - * @return array $quiz A quiz data structure - */ - function stack_xml_parse_quiz(&$quizXmlDoc) - { - $quiz = array(); - $elements = &$questionXmlDoc->documentElement; - stack_xml_parse_element_into_array($elements,$quiz['mathQuiz'],'stackQuiz'); - return $quiz; - } - - /** * Actually creates the stackQuestion/stackQuiz data structure as required by validation. Is a recursive function that iterates through * the XML tree specified --- 931,934 ---- *************** *** 936,940 **** * @return string $arrayType The type of data structure: stackQuestion, stackQuiz */ ! function stack_xml_parse_element_into_array(&$element,&$array,$arrayType) { $children = &$element->childNodes; //Retrieve all child nodes --- 938,942 ---- * @return string $arrayType The type of data structure: stackQuestion, stackQuiz */ ! function stack_xml_parse_element_into_array($element,&$array,$arrayType) { $children = &$element->childNodes; //Retrieve all child nodes *************** *** 946,950 **** $node = &$children[$i]; $nodeName = $node->nodeName; - //Check whether node is metadata and if so resolve to equivalent question field $nodeName = stack_xml_map_element_ns($node,$arrayType); --- 948,951 ---- *************** *** 1318,1326 **** $questionFrag->appendChild($headElement); ! //Append root schema node onto DOM object and save ! $dom->appendChild($questionFrag); ! $success = $dom->saveXML($directory."/".quizSchemaName,true); ! ! return $success; } --- 1319,1340 ---- $questionFrag->appendChild($headElement); ! $dirSuccess = true; ! //Before we attempt to write out the schemas, we must create the schemas directory within $stack_logfiles ! if (!file_exists(schemaBaseDir)) ! { ! $dirSuccess = mkdir($directory); ! } ! ! if ($dirSuccess) { //if directory could be created, go on to create XML schema file ! //Append root schema node onto DOM object and save ! $dom->appendChild($questionFrag); ! $success = $dom->saveXML($directory."/".quizSchemaName,true); ! ! return $success; ! } ! ! else { //if directory could not be created - check permissions! ! return $dirSuccess; ! } } *************** *** 1342,1355 **** $questionFrag = &stack_xml_create_question_schema_frag(); - $headElement = &stack_xml_create_enclosing_schema_type('assessmentItem',$xmlElements,TRUE); $questionFrag->appendChild($headElement); ! //Append root schema node onto DOM object and save ! $dom->appendChild($questionFrag); ! $success = $dom->saveXML($directory."/".questionSchemaName,true); ! return $success; } --- 1356,1381 ---- $questionFrag = &stack_xml_create_question_schema_frag(); $headElement = &stack_xml_create_enclosing_schema_type('assessmentItem',$xmlElements,TRUE); $questionFrag->appendChild($headElement); ! $dirSuccess = true; ! //Before we attempt to write out the schemas, we must create the schemas directory within $stack_logfiles ! if (!file_exists(schemaBaseDir)) ! { ! $dirSuccess = mkdir($directory); ! } ! if ($dirSuccess) { ! //Append root schema node onto DOM object and save ! $dom->appendChild($questionFrag); ! $success = $dom->saveXML($directory."/".questionSchemaName,true); ! ! return $success; ! } ! ! else { ! return $dirSuccess; ! } } |