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'])) {
78 $answer->setPosition(
$index);
79 $answer->setAnswertext(
$value);
80 $answer->setImageFile($a_value[
'imagename'][
$index]);
82 if (strlen($a_value[
'correctness'][$index])) {
83 $answer->setCorrectness((
bool) $a_value[
'correctness'][$index]);
86 $answer->setThumbPrefix($this->qstObject->getThumbPrefix());
87 $answer->setImageFsDir($this->qstObject->getImagePath());
88 $answer->setImageWebDir($this->qstObject->getImagePathWeb());
90 $this->values[] = $answer;
101 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
114 if (is_array($foundvalues)) {
116 if (is_array($foundvalues[
'answer'])) {
117 foreach ($foundvalues[
'answer'] as $aidx => $answervalue) {
118 if (((strlen($answervalue)) == 0) && (strlen($foundvalues[
'imagename'][$aidx]) == 0)) {
119 $this->
setAlert($lng->txt(
"msg_input_is_required"));
126 if (!isset($foundvalues[
'correctness']) || count($foundvalues[
'correctness']) < count($foundvalues[
'answer'])) {
127 $this->
setAlert($lng->txt(
"msg_input_is_required"));
135 $this->
setAlert($lng->txt(
"msg_input_is_required"));
145 public function insert($a_tpl)
147 $tpl =
new ilTemplate(
"tpl.prop_kprimchoicewizardinput.html",
true,
true,
"Modules/TestQuestionPool");
149 foreach ($this->values as
$value) {
155 if (!$this->hideImages) {
156 if (strlen($value->getImageFile())) {
157 $imagename = $value->getImageWebPath();
159 if (($this->
getSingleline()) && ($this->qstObject->getThumbSize())) {
160 if (@file_exists($value->getThumbFsPath())) {
161 $imagename = $value->getThumbWebPath();
165 $tpl->setCurrentBlock(
'image');
166 $tpl->setVariable(
'SRC_IMAGE', $imagename);
167 $tpl->setVariable(
'IMAGE_NAME', $value->getImageFile());
169 $tpl->setVariable(
"TXT_DELETE_EXISTING", $this->lng->txt(
"delete_existing_file"));
170 $tpl->setVariable(
"IMAGE_ROW_NUMBER", $value->getPosition());
172 $tpl->parseCurrentBlock();
174 $tpl->setCurrentBlock(
'addimage');
175 $tpl->setVariable(
"IMAGE_BROWSE", $this->lng->txt(
'select_file'));
176 $tpl->setVariable(
"IMAGE_ID", $this->
getPostVar() .
"[image][{$value->getPosition()}]");
177 $tpl->setVariable(
"IMAGE_SUBMIT", $this->lng->txt(
"upload"));
178 $tpl->setVariable(
"IMAGE_ROW_NUMBER", $value->getPosition());
180 $tpl->parseCurrentBlock();
183 $tpl->setCurrentBlock(
"prop_text_propval");
185 $tpl->parseCurrentBlock();
187 $tpl->setCurrentBlock(
'singleline');
189 $tpl->setVariable(
"SINGLELINE_ID", $this->
getPostVar() .
"[answer][{$value->getPosition()}]");
190 $tpl->setVariable(
"SINGLELINE_ROW_NUMBER", $value->getPosition());
194 $tpl->setVariable(
"DISABLED_SINGLELINE",
" disabled=\"disabled\"");
196 $tpl->parseCurrentBlock();
198 $tpl->setCurrentBlock(
'multiline');
200 $tpl->setVariable(
"MULTILINE_ID", $this->
getPostVar() .
"[answer][{$value->getPosition()}]");
201 $tpl->setVariable(
"MULTILINE_ROW_NUMBER", $value->getPosition());
204 $tpl->setVariable(
"DISABLED_MULTILINE",
" disabled=\"disabled\"");
206 $tpl->parseCurrentBlock();
209 $tpl->setCurrentBlock(
"move");
210 $tpl->setVariable(
"CMD_UP",
"cmd[up" . $this->
getFieldId() .
"][{$value->getPosition()}]");
211 $tpl->setVariable(
"CMD_DOWN",
"cmd[down" . $this->
getFieldId() .
"][{$value->getPosition()}]");
212 $tpl->setVariable(
"UP_ID",
"up_{$this->getPostVar()}[{$value->getPosition()}]");
213 $tpl->setVariable(
"DOWN_ID",
"down_{$this->getPostVar()}[{$value->getPosition()}]");
216 $tpl->parseCurrentBlock();
219 $tpl->setCurrentBlock(
"row");
222 $tpl->setVariable(
"ROW_NUMBER", $value->getPosition());
223 $tpl->setVariable(
"ID", $this->
getPostVar() .
"[answer][{$value->getPosition()}]");
226 "CORRECTNESS_TRUE_ID",
227 $this->
getPostVar() .
"[correctness][{$value->getPosition()}][true]" 230 "CORRECTNESS_FALSE_ID",
231 $this->
getPostVar() .
"[correctness][{$value->getPosition()}][false]" 233 $tpl->setVariable(
"CORRECTNESS_TRUE_VALUE", 1);
234 $tpl->setVariable(
"CORRECTNESS_FALSE_VALUE", 0);
236 if ($value->getCorrectness() !== null) {
237 if ($value->getCorrectness()) {
238 $tpl->setVariable(
'CORRECTNESS_TRUE_SELECTED',
' checked="checked"');
240 $tpl->setVariable(
'CORRECTNESS_FALSE_SELECTED',
' checked="checked"');
245 $tpl->setVariable(
"DISABLED_CORRECTNESS",
" disabled=\"disabled\"");
248 $tpl->parseCurrentBlock();
252 if (!$this->hideImages) {
254 $suff_str = $delim =
"";
256 $suff_str.= $delim .
"." .
$suffix;
259 $tpl->setCurrentBlock(
'allowed_image_suffixes');
260 $tpl->setVariable(
"TXT_ALLOWED_SUFFIXES", $this->lng->txt(
"file_allowed_suffixes") .
" " . $suff_str);
261 $tpl->parseCurrentBlock();
264 $tpl->setCurrentBlock(
"image_heading");
265 $tpl->setVariable(
"ANSWER_IMAGE", $this->lng->txt(
'answer_image'));
267 $tpl->parseCurrentBlock();
271 foreach ($this->qstObject->getValidOptionLabels() as $optionLabel) {
272 if ($this->qstObject->isCustomOptionLabel($optionLabel)) {
276 $tpl->setCurrentBlock(
'option_label_translations');
277 $tpl->setVariable(
'OPTION_LABEL', $optionLabel);
278 $tpl->setVariable(
'TRANSLATION_TRUE', $this->qstObject->getTrueOptionLabelTranslation($this->lng, $optionLabel));
279 $tpl->setVariable(
'TRANSLATION_FALSE', $this->qstObject->getFalseOptionLabelTranslation($this->lng, $optionLabel));
280 $tpl->parseCurrentBlock();
284 $tpl->setVariable(
"DELETE_IMAGE_HEADER", $this->lng->txt(
'delete_image_header'));
285 $tpl->setVariable(
"DELETE_IMAGE_QUESTION", $this->lng->txt(
'delete_image_question'));
286 $tpl->setVariable(
"ANSWER_TEXT", $this->lng->txt(
'answer_text'));
288 $tpl->setVariable(
"OPTIONS_TEXT", $this->lng->txt(
'options'));
294 $a_tpl->setCurrentBlock(
"prop_generic");
295 $a_tpl->setVariable(
"PROP_GENERIC",
$tpl->get());
296 $a_tpl->parseCurrentBlock();
298 include_once
"./Services/YUI/classes/class.ilYuiUtil.php";
299 $this->tpl->addJavascript(
"./Services/Form/js/ServiceFormWizardInput.js");
300 $this->tpl->addJavascript(
"./Modules/TestQuestionPool/templates/default/kprimchoicewizard.js");
301 $this->tpl->addJavascript(
'Modules/TestQuestionPool/js/ilAssKprimChoice.js');
306 if (is_array($_FILES) && count($_FILES) && $this->
getSingleline()) {
307 if (!$this->hideImages) {
308 if (is_array($_FILES[$this->
getPostVar()][
'error'][
'image'])) {
313 case UPLOAD_ERR_INI_SIZE:
314 $this->
setAlert($this->lng->txt(
"form_msg_file_size_exceeds"));
318 case UPLOAD_ERR_FORM_SIZE:
319 $this->
setAlert($this->lng->txt(
"form_msg_file_size_exceeds"));
323 case UPLOAD_ERR_PARTIAL:
324 $this->
setAlert($this->lng->txt(
"form_msg_file_partially_uploaded"));
328 case UPLOAD_ERR_NO_FILE:
330 if ((!strlen($foundvalues[
'imagename'][
$index])) && (!strlen($foundvalues[
'answer'][$index]))) {
331 $this->
setAlert($this->lng->txt(
"form_msg_file_no_upload"));
337 case UPLOAD_ERR_NO_TMP_DIR:
338 $this->
setAlert($this->lng->txt(
"form_msg_file_missing_tmp_dir"));
342 case UPLOAD_ERR_CANT_WRITE:
343 $this->
setAlert($this->lng->txt(
"form_msg_file_cannot_write_to_disk"));
347 case UPLOAD_ERR_EXTENSION:
348 $this->
setAlert($this->lng->txt(
"form_msg_file_upload_stopped_ext"));
356 $this->
setAlert($this->lng->txt(
"form_msg_file_no_upload"));
361 if (is_array($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'])) {
362 foreach ($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'] as
$index => $tmpname) {
365 $suffix = $filename_arr[
"extension"];
369 if (strlen($tmpname) && is_array($this->
getSuffixes())) {
371 $this->
setAlert($this->lng->txt(
"form_msg_file_wrong_file_type"));
378 if (is_array($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'])) {
379 foreach ($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'] as
$index => $tmpname) {
386 if (!preg_match(
"/^image/", $mimetype)) {
387 $_FILES[$this->
getPostVar()][
'error'][
'image'][
$index] = self::CUSTOM_UPLOAD_ERR;
388 $this->
setAlert($this->lng->txt(
"form_msg_file_wrong_mime_type"));
395 if (is_array($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'])) {
396 foreach ($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'] as
$index => $tmpname) {
399 $suffix = $filename_arr[
"extension"];
403 if (strlen($tmpname)) {
405 if ($vir[0] ==
false) {
406 $_FILES[$this->
getPostVar()][
'error'][
'image'][
$index] = self::CUSTOM_UPLOAD_ERR;
407 $this->
setAlert($this->lng->txt(
"form_msg_file_virus_found") .
"<br />" . $vir[1]);
421 foreach ($_FILES[$this->
getPostVar()][
'error'][
'image'] as
$index => $err) {
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.