4 require_once
'./Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
5 require_once
'./Modules/TestQuestionPool/interfaces/interface.ilGuiQuestionScoringAdjustable.php';
6 require_once
'./Modules/TestQuestionPool/interfaces/interface.ilGuiAnswerScoringAdjustable.php';
7 include_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
39 include_once
'./Modules/TestQuestionPool/classes/class.assImagemapQuestion.php';
43 $this->
object->loadFromDb($id);
45 $assessmentSetting =
new ilSetting(
"assessment");
46 $this->linecolor = (strlen($assessmentSetting->get(
"imap_line_color"))) ?
"#" . $assessmentSetting->get(
"imap_line_color") :
"#FF0000";
51 if (isset(
$_POST[
"imagemap"]) ||
52 isset(
$_POST[
"imagemap_x"]) ||
53 isset(
$_POST[
"imagemap_y"]))
55 $this->ctrl->setCmd(
"getCoords");
71 $hasErrors = (!$always) ? $this->
editQuestion(
true) :
false;
85 if (!
$_POST[
'image_delete'])
87 $this->
object->flushAnswers();
88 if (is_array(
$_POST[
'image'][
'coords'][
'name'] ))
90 foreach (
$_POST[
'image'][
'coords'][
'name'] as $idx => $name)
92 if( $this->object->getIsMultipleChoice() && isset(
$_POST[
'image'][
'coords'][
'points_unchecked']) )
94 $pointsUnchecked =
$_POST[
'image'][
'coords'][
'points_unchecked'][$idx];
98 $pointsUnchecked = 0.0;
101 $this->
object->addAnswer(
103 $_POST[
'image'][
'coords'][
'points'][$idx],
105 $_POST[
'image'][
'coords'][
'coords'][$idx],
106 $_POST[
'image'][
'coords'][
'shape'][$idx],
111 if (strlen( $_FILES[
'imagemapfile'][
'tmp_name'] ))
113 if ($this->object->getSelfAssessmentEditingMode() && $this->
object->getId() < 1)
114 $this->object->createNewQuestion();
115 $this->
object->uploadImagemap( $_FILES[
'imagemapfile'][
'tmp_name'] );
122 if (
$_POST[
'image_delete'])
124 $this->
object->deleteImage();
128 if (strlen( $_FILES[
'image'][
'tmp_name'] ) == 0)
130 $this->
object->setImageFilename(
$_POST[
"image_name"] );
133 if (strlen( $_FILES[
'image'][
'tmp_name'] ))
135 if ($this->object->getSelfAssessmentEditingMode() && $this->
object->getId() < 1)
136 $this->object->createNewQuestion();
137 $this->
object->setImageFilename( $_FILES[
'image'][
'name'], $_FILES[
'image'][
'tmp_name'] );
148 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
150 $form->setFormAction($this->ctrl->getFormAction($this));
152 $form->setMultipart(TRUE);
153 $form->setTableWidth(
"100%");
154 $form->setId(
"assimagemap");
166 $form->setValuesByPost();
167 $errors = !$form->checkInput();
168 $form->setValuesByPost();
170 if (
$errors) $checkonly =
false;
173 if (!$checkonly) $this->tpl->setVariable(
"QUESTION_DATA", $form->getHTML());
187 $radioGroup =
new ilRadioGroupInputGUI($this->lng->txt(
'tst_imap_qst_mode' ),
'is_multiple_choice');
188 $radioGroup->
setValue( $this->object->getIsMultipleChoice() );
189 $modeSingleChoice =
new ilRadioOption($this->lng->txt(
'tst_imap_qst_mode_sc'),
191 $modeMultipleChoice =
new ilRadioOption($this->lng->txt(
'tst_imap_qst_mode_mc'),
193 $radioGroup->addOption( $modeSingleChoice );
194 $radioGroup->addOption( $modeMultipleChoice );
198 include_once
"./Modules/TestQuestionPool/classes/class.ilImagemapFileInputGUI.php";
201 $image->setRequired(
true );
203 if (strlen( $this->object->getImageFilename() ))
205 $image->setImage( $this->object->getImagePathWeb() . $this->
object->getImageFilename() );
206 $image->setValue( $this->object->getImageFilename() );
207 $image->setAreas( $this->object->getAnswers() );
208 $assessmentSetting =
new ilSetting(
"assessment");
209 $linecolor = (strlen( $assessmentSetting->get(
"imap_line_color" )
210 )) ?
"\"#" . $assessmentSetting->get(
"imap_line_color" ) .
"\"" :
"\"#FF0000\"";
212 $image->setImagePath( $this->object->getImagePath() );
213 $image->setImagePathWeb( $this->object->getImagePathWeb() );
218 $imagemapfile =
new ilFileInputGUI($this->lng->txt(
'add_imagemap' ),
'imagemapfile');
220 $form->
addItem( $imagemapfile );
248 $coords = join(
$_POST[
'image'][
'mapcoords'],
",");
252 if (preg_match(
"/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/",
$_POST[
'image'][
'mapcoords'][0] .
" " .
$_POST[
'image'][
'mapcoords'][1], $matches))
254 $coords =
"$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
259 $coords = join($_POST[
'image'][
'mapcoords'],
",");
263 $this->
object->addAnswer(
$_POST[
"shapetitle"], 0, count($this->object->getAnswers()), $coords,
$_POST[
"shape"]);
264 $this->
object->saveToDb();
265 $this->ctrl->redirect($this,
'editQuestion');
270 $shape = (strlen($shape)) ? $shape :
$_POST[
'shape'];
271 include_once
"./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
273 $this->tpl->addBlockFile(
"QUESTION_DATA",
"question_data",
"tpl.il_as_qpl_imagemap_question.html",
"Modules/TestQuestionPool");
275 if (is_array(
$_POST[
'image'][
'mapcoords']))
277 foreach (
$_POST[
'image'][
'mapcoords'] as $value)
279 array_push($coords, $value);
282 if (is_array(
$_POST[
'cmd'][
'areaEditor'][
'image']))
284 array_push($coords,
$_POST[
'cmd'][
'areaEditor'][
'image'][0] .
"," .
$_POST[
'cmd'][
'areaEditor'][
'image'][1]);
286 foreach ($coords as $value)
288 $this->tpl->setCurrentBlock(
"hidden");
289 $this->tpl->setVariable(
"HIDDEN_NAME",
'image[mapcoords][]');
290 $this->tpl->setVariable(
"HIDDEN_VALUE", $value);
291 $this->tpl->parseCurrentBlock();
294 $this->tpl->setCurrentBlock(
"hidden");
295 $this->tpl->setVariable(
"HIDDEN_NAME",
'shape');
296 $this->tpl->setVariable(
"HIDDEN_VALUE", $shape);
297 $this->tpl->parseCurrentBlock();
300 foreach ($this->object->answers as $index => $answer)
302 $preview->addArea($index, $answer->getArea(), $answer->getCoords(), $answer->getAnswertext(),
"",
"",
true,
$this->linecolor);
305 $disabled_save =
" disabled=\"disabled\"";
310 if (count($coords) == 0)
314 else if (count($coords) == 1)
317 $preview->addPoint(
$preview->getAreaCount(), join($coords,
","), TRUE,
"blue");
319 else if (count($coords) == 2)
321 $c = join($coords,
",");
327 if (count($coords) == 0)
331 else if (count($coords) == 1)
334 $preview->addPoint(
$preview->getAreaCount(), join($coords,
","), TRUE,
"blue");
336 else if (count($coords) == 2)
338 if (preg_match(
"/(\d+)\s*,\s*(\d+)\s+(\d+)\s*,\s*(\d+)/", $coords[0] .
" " . $coords[1], $matches))
340 $c =
"$matches[1],$matches[2]," . (int)sqrt((($matches[3]-$matches[1])*($matches[3]-$matches[1]))+(($matches[4]-$matches[2])*($matches[4]-$matches[2])));
347 if (count($coords) == 0)
351 else if (count($coords) == 1)
354 $preview->addPoint(
$preview->getAreaCount(), join($coords,
","), TRUE,
"blue");
356 else if (count($coords) > 1)
360 $c = join($coords,
",");
369 $imagepath = $this->
object->getImagePathWeb() .
$preview->getPreviewFilename($this->object->getImagePath(), $this->
object->getImageFilename()) .
"?img=" . time();
372 $this->tpl->setCurrentBlock(
"maparea");
373 $this->tpl->setVariable(
"IMAGE_SOURCE",
"$imagepath");
374 $this->tpl->setVariable(
"IMAGEMAP_NAME",
"image");
375 $this->tpl->parseCurrentBlock();
379 $this->tpl->setCurrentBlock(
"imagearea");
380 $this->tpl->setVariable(
"IMAGE_SOURCE",
"$imagepath");
381 $this->tpl->setVariable(
"ALT_IMAGE", $this->lng->txt(
"imagemap"));
382 $this->tpl->parseCurrentBlock();
385 if (strlen(
$_POST[
'shapetitle']))
387 $this->tpl->setCurrentBlock(
"shapetitle");
388 $this->tpl->setVariable(
"VALUE_SHAPETITLE",
$_POST[
"shapetitle"]);
389 $this->tpl->parseCurrentBlock();
392 $this->tpl->setVariable(
"TEXT_IMAGEMAP", $this->lng->txt(
"imagemap"));
393 $this->tpl->setVariable(
"TEXT_SHAPETITLE", $this->lng->txt(
"name"));
394 $this->tpl->setVariable(
"CANCEL", $this->lng->txt(
"cancel"));
395 $this->tpl->setVariable(
"SAVE", $this->lng->txt(
"save"));
396 $this->tpl->setVariable(
"DISABLED_SAVE", $disabled_save);
400 $this->tpl->setVariable(
"FORMACTION", $this->ctrl->getFormaction($this,
'addRect'));
403 $this->tpl->setVariable(
"FORMACTION", $this->ctrl->getFormaction($this,
'addCircle'));
406 $this->tpl->setVariable(
"FORMACTION", $this->ctrl->getFormaction($this,
'addPoly'));
414 $position = key(
$_POST[
'cmd'][
'removeArea'][
'image']);
415 $this->
object->deleteArea($position);
422 $this->ctrl->redirect($this,
'editQuestion');
425 function outQuestionForTest($formaction, $active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
427 $test_output = $this->
getTestOutput($active_id,
$pass, $is_postponed, $use_post_solutions, $show_feedback);
428 $this->tpl->setVariable(
"QUESTION_OUTPUT", $test_output);
430 #$this->ctrl->setParameterByClass($this->getTargetGuiClass(), "formtimestamp", time());
431 #$formaction = $this->ctrl->getLinkTargetByClass($this->getTargetGuiClass(), "selectImagemapRegion");
432 include_once
"./Modules/Test/classes/class.ilObjTest.php";
436 $info =& $this->
object->getSolutionValues($active_id,
$pass);
440 $info =& $this->
object->getSolutionValues($active_id, NULL);
444 if (strcmp($info[0][
"value1"],
"") != 0)
446 $formaction .=
"&selImage=" . $info[0][
"value1"];
449 $this->tpl->setVariable(
"FORMACTION", $formaction);
468 $graphicalOutput = FALSE,
469 $result_output = FALSE,
470 $show_question_only = TRUE,
471 $show_feedback = FALSE,
472 $show_correct_solution = FALSE,
473 $show_manual_scoring = FALSE,
474 $show_question_text = TRUE
477 $imagepath = $this->
object->getImagePathWeb() . $this->
object->getImageFilename();
478 $solutions = array();
479 if (($active_id > 0) && (!$show_correct_solution))
481 include_once
"./Modules/Test/classes/class.ilObjTest.php";
486 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
490 if(!$this->object->getIsMultipleChoice())
494 foreach ($this->object->answers as $index => $answer)
496 if ($answer->getPoints() > $max_points)
498 $max_points = $answer->getPoints();
499 $found_index = $index;
502 array_push($solutions, array(
"value1" => $found_index));
507 foreach($this->object->answers as $index => $answer)
509 $points_checked = $answer->getPoints();
510 $points_unchecked = $answer->getPointsUnchecked();
511 if($points_checked > $points_unchecked)
513 if($points_checked > 0)
515 array_push($solutions, array(
"value1" => $index));
522 if (is_array($solutions))
524 include_once
"./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
526 foreach ($solutions as $idx => $solution_value)
528 if (strcmp($solution_value[
"value1"],
"") != 0)
530 $preview->addArea($solution_value[
"value1"], $this->object->answers[$solution_value[
"value1"]]->getArea(), $this->
object->answers[$solution_value[
"value1"]]->getCoords(), $this->
object->answers[$solution_value[
"value1"]]->getAnswertext(),
"",
"",
true,
$this->linecolor);
531 $solution_id = $solution_value[
"value1"];
535 $imagepath = $this->
object->getImagePathWeb() .
$preview->getPreviewFilename($this->object->getImagePath(), $this->
object->getImageFilename());
539 include_once
"./Services/UICore/classes/class.ilTemplate.php";
540 $template =
new ilTemplate(
"tpl.il_as_qpl_imagemap_question_output_solution.html", TRUE, TRUE,
"Modules/TestQuestionPool");
541 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",TRUE, TRUE,
"Modules/TestQuestionPool");
542 $questiontext = $this->
object->getQuestion();
543 if ($show_question_text==
true)
545 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
547 $template->setVariable(
"IMG_SRC",
"$imagepath");
548 $template->setVariable(
"IMG_ALT", $this->lng->txt(
"imagemap"));
549 $template->setVariable(
"IMG_TITLE", $this->lng->txt(
"imagemap"));
550 if (($active_id > 0) && (!$show_correct_solution))
552 if ($graphicalOutput)
555 $reached_points = $this->
object->getReachedPoints($active_id,
$pass);
556 if ($reached_points == $this->object->getMaximumPoints())
558 $template->setCurrentBlock(
"icon_ok");
560 $template->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
561 $template->parseCurrentBlock();
565 $template->setCurrentBlock(
"icon_ok");
566 if ($reached_points > 0)
569 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_not_correct_but_positive"));
574 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
576 $template->parseCurrentBlock();
583 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
584 $this->object->getId(), $solution_id
589 $template->setCurrentBlock(
"feedback");
590 $template->setVariable(
"FEEDBACK", $fb);
591 $template->parseCurrentBlock();
595 $questionoutput = $template->get();
597 if (strlen($feedback)) $solutiontemplate->setVariable(
"FEEDBACK", $feedback);
598 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
600 $solutionoutput = $solutiontemplate->get();
601 if (!$show_question_only)
604 $solutionoutput =
'<div class="ilc_question_Standard">'.$solutionoutput.
"</div>";
606 return $solutionoutput;
611 $imagepath = $this->
object->getImagePathWeb() . $this->
object->getImageFilename();
613 include_once
"./Services/UICore/classes/class.ilTemplate.php";
614 $template =
new ilTemplate(
"tpl.il_as_qpl_imagemap_question_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
616 foreach ($this->object->answers as $answer_id => $answer)
618 $template->setCurrentBlock(
"imagemap_area");
619 $template->setVariable(
"HREF_AREA", $formaction);
620 $template->setVariable(
"SHAPE", $answer->getArea());
621 $template->setVariable(
"COORDS", $answer->getCoords());
624 $template->parseCurrentBlock();
626 $questiontext = $this->
object->getQuestion();
627 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
628 $template->setVariable(
"IMG_SRC",
"$imagepath");
629 $template->setVariable(
"IMG_ALT", $this->lng->txt(
"imagemap"));
630 $template->setVariable(
"IMG_TITLE", $this->lng->txt(
"imagemap"));
631 $questionoutput = $template->get();
632 if (!$show_question_only)
637 return $questionoutput;
640 function getTestOutput($active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
644 if($this->object->getIsMultipleChoice())
646 $user_solution = array();
651 include_once
"./Modules/Test/classes/class.ilObjTest.php";
656 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
657 foreach ($solutions as $idx => $solution_value)
659 if($this->object->getIsMultipleChoice())
661 $user_solution[] = $solution_value[
"value1"];
665 $user_solution = $solution_value[
"value1"];
670 $imagepath = $this->
object->getImagePathWeb() . $this->
object->getImageFilename();
674 include_once
"./Modules/Test/classes/class.ilObjTest.php";
679 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
680 include_once
"./Modules/TestQuestionPool/classes/class.ilImagemapPreview.php";
682 foreach ($solutions as $idx => $solution_value)
684 if (strcmp($solution_value[
"value1"],
"") != 0)
686 $preview->addArea($solution_value[
"value1"], $this->object->answers[$solution_value[
"value1"]]->getArea(), $this->
object->answers[$solution_value[
"value1"]]->getCoords(), $this->
object->answers[$solution_value[
"value1"]]->getAnswertext(),
"",
"",
true,
$this->linecolor);
690 $imagepath = $this->
object->getImagePathWeb() .
$preview->getPreviewFilename($this->object->getImagePath(), $this->
object->getImageFilename());
694 include_once
"./Services/UICore/classes/class.ilTemplate.php";
695 $template =
new ilTemplate(
"tpl.il_as_qpl_imagemap_question_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
696 $this->ctrl->setParameterByClass($this->
getTargetGuiClass(),
"formtimestamp", time());
697 $hrefArea = $this->ctrl->getLinkTargetByClass($this->
getTargetGuiClass(),
"handleQuestionAction");
698 foreach ($this->object->answers as $answer_id => $answer)
700 $template->setCurrentBlock(
"imagemap_area");
701 $parameter =
"&selImage=$answer_id";
702 if(is_array($user_solution) && in_array($answer_id, $user_solution))
704 $parameter =
"&remImage=$answer_id";
706 $template->setVariable(
"HREF_AREA", $hrefArea . $parameter);
707 $template->setVariable(
"SHAPE", $answer->getArea());
708 $template->setVariable(
"COORDS", $answer->getCoords());
711 $template->parseCurrentBlock();
714 if(!$this->object->getIsMultipleChoice() && strlen($user_solution) && $user_solution == $answer_id)
716 $feedback = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
717 $this->object->getId(), $answer_id
719 if (strlen($feedback))
721 $template->setCurrentBlock(
"feedback");
722 $template->setVariable(
"FEEDBACK", $feedback);
723 $template->parseCurrentBlock();
728 $questiontext = $this->
object->getQuestion();
729 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
730 $template->setVariable(
"IMG_SRC",
"$imagepath");
731 $template->setVariable(
"IMG_ALT", $this->lng->txt(
"imagemap"));
732 $template->setVariable(
"IMG_TITLE", $this->lng->txt(
"imagemap"));
733 $questionoutput = $template->get();
734 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
747 global $rbacsystem, $ilTabs;
749 $this->ctrl->setParameterByClass(
"ilAssQuestionPageGUI",
"q_id",
$_GET[
"q_id"]);
750 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
751 $q_type = $this->
object->getQuestionType();
755 $classname = $q_type .
"GUI";
756 $this->ctrl->setParameterByClass(strtolower($classname),
"sel_question_types", $q_type);
757 $this->ctrl->setParameterByClass(strtolower($classname),
"q_id",
$_GET[
"q_id"]);
762 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
765 $ilTabs->addTarget(
"edit_page",
766 $this->ctrl->getLinkTargetByClass(
"ilAssQuestionPageGUI",
"edit"),
767 array(
"edit",
"insert",
"exec_pg"),
768 "",
"", $force_active);
772 $ilTabs->addTarget(
"preview",
773 $this->ctrl->getLinkTargetByClass(
"ilAssQuestionPageGUI",
"preview"),
775 "ilAssQuestionPageGUI",
"", $force_active);
778 $force_active =
false;
779 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
782 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
783 if (array_key_exists(
"imagemap_x",
$_POST))
785 $force_active =
true;
788 $ilTabs->addTarget(
"edit_question",
790 array(
"editQuestion",
"save",
"addArea",
"addRect",
"addCircle",
"addPoly",
791 "uploadingImage",
"uploadingImagemap",
"areaEditor",
792 "removeArea",
"saveShape",
"saveEdit",
"originalSyncForm"),
793 $classname,
"", $force_active);
804 $ilTabs->addTarget(
"solution_hint",
805 $this->ctrl->getLinkTargetByClass($classname,
"suggestedsolution"),
806 array(
"suggestedsolution",
"saveSuggestedSolution",
"outSolutionExplorer",
"cancel",
807 "addSuggestedSolution",
"cancelExplorer",
"linkChilds",
"removeSuggestedSolution"
817 $ilTabs->addTarget(
"statistics",
818 $this->ctrl->getLinkTargetByClass($classname,
"assessment"),
823 if ((
$_GET[
"calling_test"] > 0) || (
$_GET[
"test_ref_id"] > 0))
828 global $___test_express_mode;
830 if (!
$_GET[
'test_express_mode'] && !$___test_express_mode) {
831 $ilTabs->setBackTarget($this->lng->txt(
"backtocallingtest"),
"ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
835 $ilTabs->setBackTarget($this->lng->txt(
"backtocallingtest"), $link);
840 $ilTabs->setBackTarget($this->lng->txt(
"qpl"), $this->ctrl->getLinkTargetByClass(
"ilobjquestionpoolgui",
"questions"));
846 $output =
'<table class="ilTstSpecificFeedbackTable"><tbody>';
848 foreach($this->object->getAnswers() as $idx => $answer)
850 $feedback = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
851 $this->object->getId(), $idx
854 $output .=
"<tr><td><b><i>{$answer->getAnswerText()}</i></b></td><td>{$feedback}</td></tr>";
857 $output .=
'</tbody></table>';
859 return $this->
object->prepareTextareaOutput($output, TRUE);