$str = '';\r
switch ($this->parent->quiztype) {\r
case 'jcloze':\r
- $str .= "I = new Array();\n";\r
$tags = 'data,gap-fill,question-record';\r
while (($question="[$q]['#']") && $this->parent->xml_value($tags, $question)) {\r
$a = 0;\r
$aa = 0;\r
while (($answer=$question."['answer'][$a]['#']") && $this->parent->xml_value($tags, $answer)) {\r
$text = $this->js_value($tags, $answer."['text'][0]['#']", true);\r
- if ($text) {\r
+ if (strlen($text)) {\r
if ($aa==0) { // first time only\r
+ $str .= "\n";\r
$str .= "I[$q] = new Array();\n";\r
$str .= "I[$q][1] = new Array();\n";\r
}\r
// add clue, if any answers were found\r
if ($aa) {\r
$clue = $this->js_value($tags, $question."['clue'][0]['#']", true);\r
- $str .= "I[$q][2]='$clue';\n";\r
+ $str .= "I[$q][2] = '$clue';\n";\r
}\r
$q++;\r
}\r
$correct = $this->int_value($tags, $answer."['correct'][0]['#']");\r
$percent = $this->int_value($tags, $answer."['percent-correct'][0]['#']");\r
$include = $this->int_value($tags, $answer."['include-in-mc-options'][0]['#']");\r
- if ($text) {\r
+ if (strlen($text)) {\r
if ($aa==0) { // first time only\r
- $str .= "I[$q]=new Array();\n";\r
- $str .= "I[$q][0]=$weighting;\n";\r
- $str .= "I[$q][1]='$clue';\n";\r
- $str .= "I[$q][2]='".($question_type-1)."';\n";\r
- $str .= "I[$q][3]=new Array();\n";\r
+ $str .= "\n";\r
+ $str .= "I[$q] = new Array();\n";\r
+ $str .= "I[$q][0] = $weighting;\n";\r
+ $str .= "I[$q][1] = '$clue';\n";\r
+ $str .= "I[$q][2] = '".($question_type-1)."';\n";\r
+ $str .= "I[$q][3] = new Array();\n";\r
}\r
- $str .= "I[$q][3][$aa]=new Array('$text','$feedback',$correct,$percent,$include);\n";\r
+ $str .= "I[$q][3][$aa] = new Array('$text','$feedback',$correct,$percent,$include);\n";\r
$aa++;\r
}\r
$a++;\r
$includeclues = $this->v6_expand_Clues();\r
$cluecaption = $this->v6_expand_ClueCaption();\r
\r
+ // detect if cloze starts with gap\r
+ $strpos = strpos($this->parent->source, '<gap-fill><question-record>');\r
+ if (is_numeric($strpos)) {\r
+ $startwithgap = true;\r
+ } else {\r
+ $startwithgap = false;\r
+ }\r
+\r
// initialize loop values\r
$q = 0;\r
$tags = 'data,gap-fill';\r
\r
// loop through text and gaps\r
- while ($text = $this->parent->xml_value($tags, "[0]['#'][$q]")) {\r
- $str .= $text;\r
+ do {\r
+ $text = $this->parent->xml_value($tags, "[0]['#'][$q]");\r
+ $gap = '';\r
if (($question="[$q]['#']") && $this->parent->xml_value("$tags,question-record", $question)) {\r
- $str .= '<span class="GapSpan" id="GapSpan'.$q.'">';\r
+ $gap .= '<span class="GapSpan" id="GapSpan'.$q.'">';\r
if ($this->v6_use_DropDownList()) {\r
- $str .= '<select id="Gap'.$q.'"><option value=""></option>'.$dropdownlist.'</select>';\r
+ $gap .= '<select id="Gap'.$q.'"><option value=""></option>'.$dropdownlist.'</select>';\r
} else {\r
- $str .= '<input type="text" id="Gap'.$q.'" onfocus="TrackFocus('.$q.')" onblur="LeaveGap()" class="GapBox" size="6"></input>';\r
+ $gap .= '<input type="text" id="Gap'.$q.'" onfocus="TrackFocus('.$q.')" onblur="LeaveGap()" class="GapBox" size="6"></input>';\r
}\r
if ($includeclues) {\r
$clue = $this->parent->xml_value("$tags,question-record", $question."['clue'][0]['#']");\r
if (strlen($clue)) {\r
- $str .= '<button style="line-height: 1.0" class="FuncButton" onfocus="FuncBtnOver(this)" onmouseover="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseout="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" onclick="ShowClue('.$q.')">'.$cluecaption.'</button>';\r
+ $gap .= '<button style="line-height: 1.0" class="FuncButton" onfocus="FuncBtnOver(this)" onmouseover="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseout="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" onclick="ShowClue('.$q.')">'.$cluecaption.'</button>';\r
}\r
}\r
- $str .= '</span>';\r
+ $gap .= '</span>';\r
+ }\r
+ if ($startwithgap) {\r
+ $str .= "$gap$text";\r
+ } else {\r
+ $str .= "$text$gap";\r
}\r
$q++;\r
- }\r
+ } while (strlen($text) || strlen($gap));\r
\r
return $str;\r
}\r