4 require_once
'Modules/TestQuestionPool/classes/class.ilSingleChoiceWizardInputGUI.php';
5 require_once
'Modules/TestQuestionPool/classes/class.ilAssKprimChoiceAnswer.php';
6 require_once
'Services/MediaObjects/classes/class.ilObjMediaObject.php';
38 parent::__construct($a_title, $a_postvar);
47 $this->ignoreMissingUploadsEnabled =
false;
72 $this->values =
array();
74 if( is_array($a_value) && is_array($a_value[
'answer']) )
76 foreach ($a_value[
'answer'] as $index =>
$value)
80 $answer->setPosition($index);
81 $answer->setAnswertext(
$value);
82 $answer->setImageFile($a_value[
'imagename'][$index]);
84 if( strlen($a_value[
'correctness'][$index]) )
86 $answer->setCorrectness((
bool)$a_value[
'correctness'][$index]);
89 $answer->setThumbPrefix($this->qstObject->getThumbPrefix());
90 $answer->setImageFsDir($this->qstObject->getImagePath());
91 $answer->setImageWebDir($this->qstObject->getImagePathWeb());
93 $this->values[] = $answer;
104 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
116 if( is_array($foundvalues) )
119 if (is_array($foundvalues[
'answer']))
121 foreach ($foundvalues[
'answer'] as $aidx => $answervalue)
123 if (((strlen($answervalue)) == 0) && (strlen($foundvalues[
'imagename'][$aidx]) == 0))
125 $this->
setAlert($lng->txt(
"msg_input_is_required"));
132 if( !isset($foundvalues[
'correctness']) || count($foundvalues[
'correctness']) < count($foundvalues[
'answer']) )
134 $this->
setAlert($lng->txt(
"msg_input_is_required"));
145 $this->
setAlert($lng->txt(
"msg_input_is_required"));
155 public function insert($a_tpl)
157 $tpl =
new ilTemplate(
"tpl.prop_kprimchoicewizardinput.html",
true,
true,
"Modules/TestQuestionPool");
159 foreach ($this->values as
$value)
167 if (!$this->hideImages)
169 if (strlen($value->getImageFile()))
171 $imagename = $value->getImageWebPath();
173 if (($this->
getSingleline()) && ($this->qstObject->getThumbSize()))
175 if (@file_exists($value->getThumbFsPath()))
177 $imagename = $value->getThumbWebPath();
181 $tpl->setCurrentBlock(
'image');
182 $tpl->setVariable(
'SRC_IMAGE', $imagename);
183 $tpl->setVariable(
'IMAGE_NAME', $value->getImageFile());
185 $tpl->setVariable(
"TXT_DELETE_EXISTING", $this->lng->txt(
"delete_existing_file"));
186 $tpl->setVariable(
"IMAGE_ROW_NUMBER", $value->getPosition());
188 $tpl->parseCurrentBlock();
190 $tpl->setCurrentBlock(
'addimage');
191 $tpl->setVariable(
"IMAGE_BROWSE", $this->lng->txt(
'select_file'));
192 $tpl->setVariable(
"IMAGE_ID", $this->
getPostVar() .
"[image][{$value->getPosition()}]");
193 $tpl->setVariable(
"IMAGE_SUBMIT", $this->lng->txt(
"upload"));
194 $tpl->setVariable(
"IMAGE_ROW_NUMBER", $value->getPosition());
196 $tpl->parseCurrentBlock();
199 $tpl->setCurrentBlock(
"prop_text_propval");
201 $tpl->parseCurrentBlock();
203 $tpl->setCurrentBlock(
'singleline');
205 $tpl->setVariable(
"SINGLELINE_ID", $this->
getPostVar() .
"[answer][{$value->getPosition()}]");
206 $tpl->setVariable(
"SINGLELINE_ROW_NUMBER", $value->getPosition());
211 $tpl->setVariable(
"DISABLED_SINGLELINE",
" disabled=\"disabled\"");
213 $tpl->parseCurrentBlock();
217 $tpl->setCurrentBlock(
'multiline');
219 $tpl->setVariable(
"MULTILINE_ID", $this->
getPostVar() .
"[answer][{$value->getPosition()}]");
220 $tpl->setVariable(
"MULTILINE_ROW_NUMBER", $value->getPosition());
224 $tpl->setVariable(
"DISABLED_MULTILINE",
" disabled=\"disabled\"");
226 $tpl->parseCurrentBlock();
230 $tpl->setCurrentBlock(
"move");
231 $tpl->setVariable(
"CMD_UP",
"cmd[up" . $this->
getFieldId() .
"][{$value->getPosition()}]");
232 $tpl->setVariable(
"CMD_DOWN",
"cmd[down" . $this->
getFieldId() .
"][{$value->getPosition()}]");
233 $tpl->setVariable(
"UP_ID",
"up_{$this->getPostVar()}[{$value->getPosition()}]");
234 $tpl->setVariable(
"DOWN_ID",
"down_{$this->getPostVar()}[{$value->getPosition()}]");
237 $tpl->parseCurrentBlock();
240 $tpl->setCurrentBlock(
"row");
243 $tpl->setVariable(
"ROW_NUMBER", $value->getPosition());
244 $tpl->setVariable(
"ID", $this->
getPostVar() .
"[answer][{$value->getPosition()}]");
247 "CORRECTNESS_TRUE_ID", $this->
getPostVar() .
"[correctness][{$value->getPosition()}][true]" 250 "CORRECTNESS_FALSE_ID", $this->
getPostVar() .
"[correctness][{$value->getPosition()}][false]" 252 $tpl->setVariable(
"CORRECTNESS_TRUE_VALUE", 1);
253 $tpl->setVariable(
"CORRECTNESS_FALSE_VALUE", 0);
255 if( $value->getCorrectness() !== null )
257 if( $value->getCorrectness() )
259 $tpl->setVariable(
'CORRECTNESS_TRUE_SELECTED',
' checked="checked"');
263 $tpl->setVariable(
'CORRECTNESS_FALSE_SELECTED',
' checked="checked"');
269 $tpl->setVariable(
"DISABLED_CORRECTNESS",
" disabled=\"disabled\"");
272 $tpl->parseCurrentBlock();
277 if (!$this->hideImages)
281 $suff_str = $delim =
"";
284 $suff_str.= $delim.
".".
$suffix;
287 $tpl->setCurrentBlock(
'allowed_image_suffixes');
288 $tpl->setVariable(
"TXT_ALLOWED_SUFFIXES", $this->lng->txt(
"file_allowed_suffixes").
" ".$suff_str);
289 $tpl->parseCurrentBlock();
292 $tpl->setCurrentBlock(
"image_heading");
293 $tpl->setVariable(
"ANSWER_IMAGE", $this->lng->txt(
'answer_image'));
295 $tpl->parseCurrentBlock();
299 foreach($this->qstObject->getValidOptionLabels() as $optionLabel)
301 if( $this->qstObject->isCustomOptionLabel($optionLabel) )
306 $tpl->setCurrentBlock(
'option_label_translations');
307 $tpl->setVariable(
'OPTION_LABEL', $optionLabel);
308 $tpl->setVariable(
'TRANSLATION_TRUE', $this->qstObject->getTrueOptionLabelTranslation($this->lng, $optionLabel));
309 $tpl->setVariable(
'TRANSLATION_FALSE', $this->qstObject->getFalseOptionLabelTranslation($this->lng, $optionLabel));
310 $tpl->parseCurrentBlock();
314 $tpl->setVariable(
"DELETE_IMAGE_HEADER", $this->lng->txt(
'delete_image_header'));
315 $tpl->setVariable(
"DELETE_IMAGE_QUESTION", $this->lng->txt(
'delete_image_question'));
316 $tpl->setVariable(
"ANSWER_TEXT", $this->lng->txt(
'answer_text'));
318 $tpl->setVariable(
"OPTIONS_TEXT", $this->lng->txt(
'options'));
324 $a_tpl->setCurrentBlock(
"prop_generic");
325 $a_tpl->setVariable(
"PROP_GENERIC",
$tpl->get());
326 $a_tpl->parseCurrentBlock();
328 include_once
"./Services/YUI/classes/class.ilYuiUtil.php";
329 $this->tpl->addJavascript(
"./Services/Form/js/ServiceFormWizardInput.js");
330 $this->tpl->addJavascript(
"./Modules/TestQuestionPool/templates/default/kprimchoicewizard.js");
331 $this->tpl->addJavascript(
'Modules/TestQuestionPool/js/ilAssKprimChoice.js');
336 if (is_array($_FILES) && count($_FILES) && $this->
getSingleline())
338 if (!$this->hideImages)
340 if (is_array($_FILES[$this->
getPostVar()][
'error'][
'image']))
342 foreach ($_FILES[$this->
getPostVar()][
'error'][
'image'] as $index =>
$error)
349 case UPLOAD_ERR_INI_SIZE:
350 $this->
setAlert($this->lng->txt(
"form_msg_file_size_exceeds"));
354 case UPLOAD_ERR_FORM_SIZE:
355 $this->
setAlert($this->lng->txt(
"form_msg_file_size_exceeds"));
359 case UPLOAD_ERR_PARTIAL:
360 $this->
setAlert($this->lng->txt(
"form_msg_file_partially_uploaded"));
364 case UPLOAD_ERR_NO_FILE:
367 if ((!strlen($foundvalues[
'imagename'][$index])) && (!strlen($foundvalues[
'answer'][$index])))
369 $this->
setAlert($this->lng->txt(
"form_msg_file_no_upload"));
375 case UPLOAD_ERR_NO_TMP_DIR:
376 $this->
setAlert($this->lng->txt(
"form_msg_file_missing_tmp_dir"));
380 case UPLOAD_ERR_CANT_WRITE:
381 $this->
setAlert($this->lng->txt(
"form_msg_file_cannot_write_to_disk"));
385 case UPLOAD_ERR_EXTENSION:
386 $this->
setAlert($this->lng->txt(
"form_msg_file_upload_stopped_ext"));
397 $this->
setAlert($this->lng->txt(
"form_msg_file_no_upload"));
402 if (is_array($_FILES[$this->
getPostVar()][
'tmp_name'][
'image']))
404 foreach ($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'] as $index => $tmpname)
408 $suffix = $filename_arr[
"extension"];
409 $mimetype = $_FILES[$this->
getPostVar()][
'type'][
'image'][$index];
410 $size_bytes = $_FILES[$this->
getPostVar()][
'size'][
'image'][$index];
412 if (strlen($tmpname) && is_array($this->
getSuffixes()))
416 $this->
setAlert($this->lng->txt(
"form_msg_file_wrong_file_type"));
423 if (is_array($_FILES[$this->
getPostVar()][
'tmp_name'][
'image']))
425 foreach ($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'] as $index => $tmpname)
427 if( $_FILES[$this->
getPostVar()][
'error'][
'image'][$index] > 0 )
434 if( !preg_match(
"/^image/", $mimetype) )
436 $_FILES[$this->
getPostVar()][
'error'][
'image'][$index] = self::CUSTOM_UPLOAD_ERR;
437 $this->
setAlert($this->lng->txt(
"form_msg_file_wrong_mime_type"));
444 if (is_array($_FILES[$this->
getPostVar()][
'tmp_name'][
'image']))
446 foreach ($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'] as $index => $tmpname)
450 $suffix = $filename_arr[
"extension"];
451 $mimetype = $_FILES[$this->
getPostVar()][
'type'][
'image'][$index];
452 $size_bytes = $_FILES[$this->
getPostVar()][
'size'][
'image'][$index];
454 if (strlen($tmpname))
457 if ($vir[0] ==
false)
459 $_FILES[$this->
getPostVar()][
'error'][
'image'][$index] = self::CUSTOM_UPLOAD_ERR;
460 $this->
setAlert($this->lng->txt(
"form_msg_file_virus_found").
"<br />".$vir[1]);
474 foreach($_FILES[$this->
getPostVar()][
'error'][
'image'] as $index => $err)
482 'position' => $index,
483 'tmp_name' => $_FILES[$this->
getPostVar()][
'tmp_name'][
'image'][$index],
484 'name' => $_FILES[$this->
getPostVar()][
'name'][
'image'][$index],
485 'type' => $_FILES[$this->
getPostVar()][
'type'][
'image'][$index],
486 'size' => $_FILES[$this->
getPostVar()][
'size'][
'image'][$index]
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getMaxLength()
Get Max Length.
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
static _getUsedHTMLTagsAsString($a_module="")
Returns a string of all allowed HTML tags for text editing.
static get($a_glyph, $a_text="")
Get glyph html.
special template class to simplify handling of ITX/PEAR
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
Create styles array
The data for the language used.