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';
45 $this->files = array();
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"));
152 public function insert(&$a_tpl)
154 $tpl =
new ilTemplate(
"tpl.prop_kprimchoicewizardinput.html",
true,
true,
"Modules/TestQuestionPool");
156 foreach ($this->values as
$value)
164 if (!$this->hideImages)
166 if (strlen($value->getImageFile()))
168 $imagename = $value->getImageWebPath();
170 if (($this->
getSingleline()) && ($this->qstObject->getThumbSize()))
172 if (@file_exists($value->getThumbFsPath()))
174 $imagename = $value->getThumbWebPath();
178 $tpl->setCurrentBlock(
'image');
179 $tpl->setVariable(
'SRC_IMAGE', $imagename);
180 $tpl->setVariable(
'IMAGE_NAME', $value->getImageFile());
182 $tpl->setVariable(
"TXT_DELETE_EXISTING", $this->lng->txt(
"delete_existing_file"));
183 $tpl->setVariable(
"IMAGE_ROW_NUMBER", $value->getPosition());
185 $tpl->parseCurrentBlock();
187 $tpl->setCurrentBlock(
'addimage');
188 $tpl->setVariable(
"IMAGE_ID", $this->
getPostVar() .
"[image][{$value->getPosition()}]");
189 $tpl->setVariable(
"IMAGE_SUBMIT", $this->lng->txt(
"upload"));
190 $tpl->setVariable(
"IMAGE_ROW_NUMBER", $value->getPosition());
192 $tpl->parseCurrentBlock();
195 $tpl->setCurrentBlock(
"prop_text_propval");
197 $tpl->parseCurrentBlock();
199 $tpl->setCurrentBlock(
'singleline');
201 $tpl->setVariable(
"SINGLELINE_ID", $this->
getPostVar() .
"[answer][{$value->getPosition()}]");
202 $tpl->setVariable(
"SINGLELINE_ROW_NUMBER", $value->getPosition());
207 $tpl->setVariable(
"DISABLED_SINGLELINE",
" disabled=\"disabled\"");
209 $tpl->parseCurrentBlock();
213 $tpl->setCurrentBlock(
'multiline');
215 $tpl->setVariable(
"MULTILINE_ID", $this->
getPostVar() .
"[answer][{$value->getPosition()}]");
216 $tpl->setVariable(
"MULTILINE_ROW_NUMBER", $value->getPosition());
220 $tpl->setVariable(
"DISABLED_MULTILINE",
" disabled=\"disabled\"");
222 $tpl->parseCurrentBlock();
226 $tpl->setCurrentBlock(
"move");
227 $tpl->setVariable(
"CMD_UP",
"cmd[up" . $this->
getFieldId() .
"][{$value->getPosition()}]");
228 $tpl->setVariable(
"CMD_DOWN",
"cmd[down" . $this->
getFieldId() .
"][{$value->getPosition()}]");
229 $tpl->setVariable(
"UP_ID",
"up_{$this->getPostVar()}[{$value->getPosition()}]");
230 $tpl->setVariable(
"DOWN_ID",
"down_{$this->getPostVar()}[{$value->getPosition()}]");
233 $tpl->parseCurrentBlock();
236 $tpl->setCurrentBlock(
"row");
239 $tpl->setVariable(
"ROW_NUMBER", $value->getPosition());
240 $tpl->setVariable(
"ID", $this->
getPostVar() .
"[answer][{$value->getPosition()}]");
243 "CORRECTNESS_TRUE_ID", $this->
getPostVar() .
"[correctness][{$value->getPosition()}][true]"
246 "CORRECTNESS_FALSE_ID", $this->
getPostVar() .
"[correctness][{$value->getPosition()}][false]"
248 $tpl->setVariable(
"CORRECTNESS_TRUE_VALUE", 1);
249 $tpl->setVariable(
"CORRECTNESS_FALSE_VALUE", 0);
251 if( $value->getCorrectness() !== null )
253 if( $value->getCorrectness() )
255 $tpl->setVariable(
'CORRECTNESS_TRUE_SELECTED',
' checked="checked"');
259 $tpl->setVariable(
'CORRECTNESS_FALSE_SELECTED',
' checked="checked"');
265 $tpl->setVariable(
"DISABLED_CORRECTNESS",
" disabled=\"disabled\"");
268 $tpl->parseCurrentBlock();
273 if (!$this->hideImages)
277 $suff_str = $delim =
"";
280 $suff_str.= $delim.
".".
$suffix;
283 $tpl->setCurrentBlock(
'allowed_image_suffixes');
284 $tpl->setVariable(
"TXT_ALLOWED_SUFFIXES", $this->lng->txt(
"file_allowed_suffixes").
" ".$suff_str);
285 $tpl->parseCurrentBlock();
288 $tpl->setCurrentBlock(
"image_heading");
289 $tpl->setVariable(
"ANSWER_IMAGE", $this->lng->txt(
'answer_image'));
291 $tpl->parseCurrentBlock();
295 foreach($this->qstObject->getValidOptionLabels() as $optionLabel)
297 if( $this->qstObject->isCustomOptionLabel($optionLabel) )
302 $tpl->setCurrentBlock(
'option_label_translations');
303 $tpl->setVariable(
'OPTION_LABEL', $optionLabel);
304 $tpl->setVariable(
'TRANSLATION_TRUE', $this->qstObject->getTrueOptionLabelTranslation($this->lng, $optionLabel));
305 $tpl->setVariable(
'TRANSLATION_FALSE', $this->qstObject->getFalseOptionLabelTranslation($this->lng, $optionLabel));
306 $tpl->parseCurrentBlock();
310 $tpl->setVariable(
"DELETE_IMAGE_HEADER", $this->lng->txt(
'delete_image_header'));
311 $tpl->setVariable(
"DELETE_IMAGE_QUESTION", $this->lng->txt(
'delete_image_question'));
312 $tpl->setVariable(
"ANSWER_TEXT", $this->lng->txt(
'answer_text'));
314 $tpl->setVariable(
"OPTIONS_TEXT", $this->lng->txt(
'options'));
320 $a_tpl->setCurrentBlock(
"prop_generic");
321 $a_tpl->setVariable(
"PROP_GENERIC",
$tpl->get());
322 $a_tpl->parseCurrentBlock();
324 include_once
"./Services/YUI/classes/class.ilYuiUtil.php";
325 $this->tpl->addJavascript(
"./Services/Form/js/ServiceFormWizardInput.js");
326 $this->tpl->addJavascript(
"./Modules/TestQuestionPool/templates/default/kprimchoicewizard.js");
327 $this->tpl->addJavascript(
'Modules/TestQuestionPool/js/ilAssKprimChoice.js');
332 if (is_array($_FILES) && count($_FILES) && $this->
getSingleline())
334 if (!$this->hideImages)
336 if (is_array($_FILES[$this->
getPostVar()][
'error'][
'image']))
338 foreach ($_FILES[$this->
getPostVar()][
'error'][
'image'] as $index => $error)
345 case UPLOAD_ERR_INI_SIZE:
346 $this->
setAlert($this->lng->txt(
"form_msg_file_size_exceeds"));
350 case UPLOAD_ERR_FORM_SIZE:
351 $this->
setAlert($this->lng->txt(
"form_msg_file_size_exceeds"));
355 case UPLOAD_ERR_PARTIAL:
356 $this->
setAlert($this->lng->txt(
"form_msg_file_partially_uploaded"));
360 case UPLOAD_ERR_NO_FILE:
363 if ((!strlen($foundvalues[
'imagename'][$index])) && (!strlen($foundvalues[
'answer'][$index])))
365 $this->
setAlert($this->lng->txt(
"form_msg_file_no_upload"));
371 case UPLOAD_ERR_NO_TMP_DIR:
372 $this->
setAlert($this->lng->txt(
"form_msg_file_missing_tmp_dir"));
376 case UPLOAD_ERR_CANT_WRITE:
377 $this->
setAlert($this->lng->txt(
"form_msg_file_cannot_write_to_disk"));
381 case UPLOAD_ERR_EXTENSION:
382 $this->
setAlert($this->lng->txt(
"form_msg_file_upload_stopped_ext"));
393 $this->
setAlert($this->lng->txt(
"form_msg_file_no_upload"));
398 if (is_array($_FILES[$this->
getPostVar()][
'tmp_name'][
'image']))
400 foreach ($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'] as $index => $tmpname)
404 $suffix = $filename_arr[
"extension"];
405 $mimetype = $_FILES[$this->
getPostVar()][
'type'][
'image'][$index];
406 $size_bytes = $_FILES[$this->
getPostVar()][
'size'][
'image'][$index];
408 if (strlen($tmpname) && is_array($this->
getSuffixes()))
410 if (!in_array(strtolower($suffix), $this->
getSuffixes()))
412 $this->
setAlert($this->lng->txt(
"form_msg_file_wrong_file_type"));
419 if (is_array($_FILES[$this->
getPostVar()][
'tmp_name'][
'image']))
421 foreach ($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'] as $index => $tmpname)
423 if( $_FILES[$this->
getPostVar()][
'error'][
'image'][$index] > 0 )
430 if( !preg_match(
"/^image/", $mimetype) )
433 $this->
setAlert($this->lng->txt(
"form_msg_file_wrong_mime_type"));
440 if (is_array($_FILES[$this->
getPostVar()][
'tmp_name'][
'image']))
442 foreach ($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'] as $index => $tmpname)
446 $suffix = $filename_arr[
"extension"];
447 $mimetype = $_FILES[$this->
getPostVar()][
'type'][
'image'][$index];
448 $size_bytes = $_FILES[$this->
getPostVar()][
'size'][
'image'][$index];
450 if (strlen($tmpname))
453 if ($vir[0] ==
false)
456 $this->
setAlert($this->lng->txt(
"form_msg_file_virus_found").
"<br />".$vir[1]);
470 foreach($_FILES[$this->
getPostVar()][
'error'][
'image'] as $index => $err)
477 $this->files[$index] = array(
478 'position' => $index,
479 'tmp_name' => $_FILES[$this->
getPostVar()][
'tmp_name'][
'image'][$index],
480 'name' => $_FILES[$this->
getPostVar()][
'name'][
'image'][$index],
481 'type' => $_FILES[$this->
getPostVar()][
'type'][
'image'][$index],
482 'size' => $_FILES[$this->
getPostVar()][
'size'][
'image'][$index]