template improvements and simplifications for Questtypes ?Textinput? and ?Choiceinput?
This commit is contained in:
parent
9a9dbe08de
commit
0570ac6427
4 changed files with 40 additions and 100 deletions
|
|
@ -1,32 +1,17 @@
|
|||
<form method="post">
|
||||
<p>
|
||||
<?php
|
||||
$text = $t->t($task['text']);
|
||||
|
||||
// Insert comboboxes
|
||||
foreach(array_reverse($choiceLists) as &$list)
|
||||
{
|
||||
// Get positions
|
||||
$posStart = mb_strrpos($text, '[choiceinput]', 0, 'UTF-8');
|
||||
$posEnd = $posStart + mb_strlen('[choiceinput]', 'UTF-8');
|
||||
|
||||
// Create combobox
|
||||
$combobox = '<select name="answers[]">';
|
||||
foreach($list['values'] as &$choice) {
|
||||
$combobox .= sprintf(
|
||||
'<option value="%s" %s>%s</option>',
|
||||
$choice['id'],
|
||||
(array_key_exists('answer', $list) && $list['answer'] == $choice['id']) ? 'selected="selected"' : null,
|
||||
$choice['text']
|
||||
);
|
||||
}
|
||||
$combobox .= '</select>';
|
||||
|
||||
// Insert input field
|
||||
$text = mb_substr($text, 0, $posStart, 'UTF-8') . $combobox . mb_substr($text, $posEnd, mb_strlen($text)-$posEnd, 'UTF-8');
|
||||
}
|
||||
?>
|
||||
<?=$text?>
|
||||
<?php $posStart = 0; ?>
|
||||
<?php foreach($choiceLists as &$list) : ?>
|
||||
<?php $posEnd = mb_strpos($task['text'], '[choiceinput]', $posStart, 'UTF-8'); ?>
|
||||
<?=$t->t(mb_substr($task['text'], $posStart, $posEnd-$posStart, 'UTF-8'))?>
|
||||
<select name="answers[]">
|
||||
<?php foreach($list['values'] as &$choice) : ?>
|
||||
<option value="<?=$choice['id']?>" <?php if(array_key_exists('answer', $list) && $list['answer'] == $choice['id']) : ?>selected="selected"<?php endif ?>><?=$choice['text']?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<?php $posStart = $posEnd + mb_strlen('[choiceinput]', 'UTF-8'); ?>
|
||||
<?php endforeach ?>
|
||||
<?=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?>
|
||||
</p>
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -1,29 +1,14 @@
|
|||
<p>
|
||||
<?php
|
||||
$text = $t->t($task['text']);
|
||||
|
||||
// Insert comboboxes
|
||||
foreach(array_reverse($choiceLists) as &$list)
|
||||
{
|
||||
// Get positions
|
||||
$posStart = mb_strrpos($text, '[choiceinput]', 0, 'UTF-8');
|
||||
$posEnd = $posStart + mb_strlen('[choiceinput]', 'UTF-8');
|
||||
|
||||
// Create combobox
|
||||
$combobox = '<select name="answers[]" disabled="disabled">';
|
||||
foreach($list['values'] as &$choice) {
|
||||
$combobox .= sprintf(
|
||||
'<option value="%s" %s>%s</option>',
|
||||
$choice['id'],
|
||||
(array_key_exists('answer', $list) && $list['answer'] == $choice['id']) ? 'selected="selected"' : null,
|
||||
$choice['text']
|
||||
);
|
||||
}
|
||||
$combobox .= '</select>';
|
||||
|
||||
// Insert input field
|
||||
$text = mb_substr($text, 0, $posStart, 'UTF-8') . $combobox . mb_substr($text, $posEnd, mb_strlen($text)-$posEnd, 'UTF-8');
|
||||
}
|
||||
?>
|
||||
<?=$text?>
|
||||
<?php $posStart = 0; ?>
|
||||
<?php foreach($choiceLists as &$list) : ?>
|
||||
<?php $posEnd = mb_strpos($task['text'], '[choiceinput]', $posStart, 'UTF-8'); ?>
|
||||
<?=$t->t(mb_substr($task['text'], $posStart, $posEnd-$posStart, 'UTF-8'))?>
|
||||
<select name="answers[]" disabled="disabled">
|
||||
<?php foreach($list['values'] as &$choice) : ?>
|
||||
<option value="<?=$choice['id']?>" <?php if(array_key_exists('answer', $list) && $list['answer'] == $choice['id']) : ?>selected="selected"<?php endif ?>><?=$choice['text']?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<?php $posStart = $posEnd + mb_strlen('[choiceinput]', 'UTF-8'); ?>
|
||||
<?php endforeach ?>
|
||||
<?=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?>
|
||||
</p>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue