template improvements and simplifications for Questtypes ?Textinput? and ?Choiceinput?
This commit is contained in:
parent
a60c7a2c19
commit
8c8714a51e
4 changed files with 40 additions and 100 deletions
|
|
@ -1,32 +1,17 @@
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<p>
|
<p>
|
||||||
<?php
|
<?php $posStart = 0; ?>
|
||||||
$text = $t->t($task['text']);
|
<?php foreach($choiceLists as &$list) : ?>
|
||||||
|
<?php $posEnd = mb_strpos($task['text'], '[choiceinput]', $posStart, 'UTF-8'); ?>
|
||||||
// Insert comboboxes
|
<?=$t->t(mb_substr($task['text'], $posStart, $posEnd-$posStart, 'UTF-8'))?>
|
||||||
foreach(array_reverse($choiceLists) as &$list)
|
<select name="answers[]">
|
||||||
{
|
<?php foreach($list['values'] as &$choice) : ?>
|
||||||
// Get positions
|
<option value="<?=$choice['id']?>" <?php if(array_key_exists('answer', $list) && $list['answer'] == $choice['id']) : ?>selected="selected"<?php endif ?>><?=$choice['text']?></option>
|
||||||
$posStart = mb_strrpos($text, '[choiceinput]', 0, 'UTF-8');
|
<?php endforeach ?>
|
||||||
$posEnd = $posStart + mb_strlen('[choiceinput]', 'UTF-8');
|
</select>
|
||||||
|
<?php $posStart = $posEnd + mb_strlen('[choiceinput]', 'UTF-8'); ?>
|
||||||
// Create combobox
|
<?php endforeach ?>
|
||||||
$combobox = '<select name="answers[]">';
|
<?=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?>
|
||||||
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?>
|
|
||||||
</p>
|
</p>
|
||||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,14 @@
|
||||||
<p>
|
<p>
|
||||||
<?php
|
<?php $posStart = 0; ?>
|
||||||
$text = $t->t($task['text']);
|
<?php foreach($choiceLists as &$list) : ?>
|
||||||
|
<?php $posEnd = mb_strpos($task['text'], '[choiceinput]', $posStart, 'UTF-8'); ?>
|
||||||
// Insert comboboxes
|
<?=$t->t(mb_substr($task['text'], $posStart, $posEnd-$posStart, 'UTF-8'))?>
|
||||||
foreach(array_reverse($choiceLists) as &$list)
|
<select name="answers[]" disabled="disabled">
|
||||||
{
|
<?php foreach($list['values'] as &$choice) : ?>
|
||||||
// Get positions
|
<option value="<?=$choice['id']?>" <?php if(array_key_exists('answer', $list) && $list['answer'] == $choice['id']) : ?>selected="selected"<?php endif ?>><?=$choice['text']?></option>
|
||||||
$posStart = mb_strrpos($text, '[choiceinput]', 0, 'UTF-8');
|
<?php endforeach ?>
|
||||||
$posEnd = $posStart + mb_strlen('[choiceinput]', 'UTF-8');
|
</select>
|
||||||
|
<?php $posStart = $posEnd + mb_strlen('[choiceinput]', 'UTF-8'); ?>
|
||||||
// Create combobox
|
<?php endforeach ?>
|
||||||
$combobox = '<select name="answers[]" disabled="disabled">';
|
<?=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?>
|
||||||
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?>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,13 @@
|
||||||
<form method="post" class="textinput">
|
<form method="post" class="textinput">
|
||||||
<p>
|
<p>
|
||||||
<?php
|
<?php $posStart = 0; ?>
|
||||||
$text = $t->t($task['text']);
|
<?php foreach($fields as &$field) : ?>
|
||||||
|
<?php $posEnd = mb_strpos($task['text'], '[textinput]', $posStart, 'UTF-8'); ?>
|
||||||
// Insert input fields
|
<?=$t->t(mb_substr($task['text'], $posStart, $posEnd-$posStart, 'UTF-8'))?>
|
||||||
foreach(array_reverse($fields) as &$field)
|
<input type="text" name="answers[]" value="<?=(array_key_exists('answer', $field)) ? $field['answer'] : ''?>" <?php if($field['size'] != 'default') : ?>class="<?=$field['size']?>"<?php endif ?> />
|
||||||
{
|
<?php $posStart = $posEnd + mb_strlen('[textinput]', 'UTF-8'); ?>
|
||||||
// Get positions
|
<?php endforeach ?>
|
||||||
$posStart = mb_strrpos($text, '[textinput]', 0, 'UTF-8');
|
<?=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?>
|
||||||
$posEnd = $posStart + mb_strlen('[textinput]', 'UTF-8');
|
|
||||||
|
|
||||||
// Create input field
|
|
||||||
$class = ($field['size'] != 'default') ? $field['size'] : '';
|
|
||||||
$value = (array_key_exists('answer', $field)) ? $field['answer'] : '';
|
|
||||||
$inputField = sprintf(
|
|
||||||
'<input type="text" name="answers[]" value="%s" class="%s" />',
|
|
||||||
$value,
|
|
||||||
$class
|
|
||||||
);
|
|
||||||
|
|
||||||
// Insert input field
|
|
||||||
$text = mb_substr($text, 0, $posStart, 'UTF-8') . $inputField . mb_substr($text, $posEnd, mb_strlen($text)-$posEnd, 'UTF-8');
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<?=$text?>
|
|
||||||
</p>
|
</p>
|
||||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,10 @@
|
||||||
<p>
|
<p>
|
||||||
<?php
|
<?php $posStart = 0; ?>
|
||||||
$text = $t->t($task['text']);
|
<?php foreach($fields as &$field) : ?>
|
||||||
|
<?php $posEnd = mb_strpos($task['text'], '[textinput]', $posStart, 'UTF-8'); ?>
|
||||||
// Insert Character answers
|
<?=$t->t(mb_substr($task['text'], $posStart, $posEnd-$posStart, 'UTF-8'))?>
|
||||||
foreach(array_reverse($fields) as &$field)
|
<span style="background-color:grey"><?=$field['answer']?></span><?=($field['right']) ? '✓' : '✕'?>
|
||||||
{
|
<?php $posStart = $posEnd + mb_strlen('[textinput]', 'UTF-8'); ?>
|
||||||
// Get positions
|
<?php endforeach ?>
|
||||||
$posStart = mb_strrpos($text, '[textinput]', 0, 'UTF-8');
|
<?=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?>
|
||||||
$posEnd = $posStart + mb_strlen('[textinput]', 'UTF-8');
|
|
||||||
|
|
||||||
// Create field for Character answer
|
|
||||||
$answerField = sprintf(
|
|
||||||
'<span style="background-color:grey">%s</span>%s',
|
|
||||||
$field['answer'],
|
|
||||||
($field['right']) ? '✓' : '✕'
|
|
||||||
);
|
|
||||||
|
|
||||||
// Insert input field
|
|
||||||
$text = mb_substr($text, 0, $posStart, 'UTF-8') . $answerField . mb_substr($text, $posEnd, mb_strlen($text)-$posEnd, 'UTF-8');
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<?=$text?>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue