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,29 +1,13 @@
|
|||
<form method="post" class="textinput">
|
||||
<p>
|
||||
<?php
|
||||
$text = $t->t($task['text']);
|
||||
|
||||
// Insert input fields
|
||||
foreach(array_reverse($fields) as &$field)
|
||||
{
|
||||
// Get positions
|
||||
$posStart = mb_strrpos($text, '[textinput]', 0, '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?>
|
||||
<?php $posStart = 0; ?>
|
||||
<?php foreach($fields as &$field) : ?>
|
||||
<?php $posEnd = mb_strpos($task['text'], '[textinput]', $posStart, 'UTF-8'); ?>
|
||||
<?=$t->t(mb_substr($task['text'], $posStart, $posEnd-$posStart, 'UTF-8'))?>
|
||||
<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'); ?>
|
||||
<?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,24 +1,10 @@
|
|||
<p>
|
||||
<?php
|
||||
$text = $t->t($task['text']);
|
||||
|
||||
// Insert Character answers
|
||||
foreach(array_reverse($fields) as &$field)
|
||||
{
|
||||
// Get positions
|
||||
$posStart = mb_strrpos($text, '[textinput]', 0, '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?>
|
||||
<?php $posStart = 0; ?>
|
||||
<?php foreach($fields as &$field) : ?>
|
||||
<?php $posEnd = mb_strpos($task['text'], '[textinput]', $posStart, 'UTF-8'); ?>
|
||||
<?=$t->t(mb_substr($task['text'], $posStart, $posEnd-$posStart, 'UTF-8'))?>
|
||||
<span style="background-color:grey"><?=$field['answer']?></span><?=($field['right']) ? '✓' : '✕'?>
|
||||
<?php $posStart = $posEnd + mb_strlen('[textinput]', '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