/**
 * Output of the active survey question to the screen
 *
 * Output of the active survey question to the screen
 *
 * @access private
 */
 function outSurveyPage($activepage = NULL, $direction = NULL)
 {
     global $ilUser;
     $this->checkAuth();
     $page = $this->object->getNextPage($activepage, $direction);
     $constraint_true = 0;
     // check for constraints
     if (count($page[0]["constraints"])) {
         while (is_array($page) and $constraint_true == 0 and count($page[0]["constraints"])) {
             $constraint_true = $page[0]['constraints'][0]['conjunction'] == 0 ? true : false;
             foreach ($page[0]["constraints"] as $constraint) {
                 if (!$this->preview) {
                     $working_data = $this->object->loadWorkingData($constraint["question"], $_SESSION["finished_id"][$this->object->getId()]);
                 } else {
                     $working_data = $_SESSION["preview_data"][$this->object->getId()][$constraint["question"]];
                 }
                 if ($constraint['conjunction'] == 0) {
                     // and
                     $constraint_true = $constraint_true & $this->object->checkConstraint($constraint, $working_data);
                 } else {
                     // or
                     $constraint_true = $constraint_true | $this->object->checkConstraint($constraint, $working_data);
                 }
             }
             if ($constraint_true == 0) {
                 // #11047 - we are skipping the page, so we have to get rid of existing answers for that question(s)
                 foreach ($page as $page_question) {
                     $qid = $page_question["question_id"];
                     // see saveActiveQuestionData()
                     if (!$this->preview) {
                         $this->object->deleteWorkingData($qid, $_SESSION["finished_id"][$this->object->getId()]);
                     } else {
                         $_SESSION["preview_data"][$this->object->getId()][$qid] = null;
                     }
                 }
                 $page = $this->object->getNextPage($page[0]["question_id"], $direction);
             }
         }
     }
     $first_question = -1;
     if ($page === 0) {
         $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
     } else {
         if ($page === 1) {
             $state = $this->object->getUserSurveyExecutionStatus();
             if ($this->preview || !$state["runs"][$_SESSION["finished_id"][$this->object->getId()]]["finished"]) {
                 $this->showFinishConfirmation();
             } else {
                 $this->runShowFinishedPage();
             }
             return;
         } else {
             global $ilHelp;
             $ilHelp->setScreenIdComponent("svy");
             $ilHelp->setScreenId("quest_presentation");
             $required = false;
             $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_content.html", "Modules/Survey");
             if ($this->object->get360Mode()) {
                 $appr_id = $_SESSION["appr_id"][$this->object->getId()];
                 include_once "Services/User/classes/class.ilUserUtil.php";
                 $this->tpl->setTitle($this->object->getTitle() . " (" . $this->lng->txt("survey_360_appraisee") . ": " . ilUserUtil::getNamePresentation($appr_id) . ")");
             }
             if (!($this->object->getAnonymize() && $this->object->isAccessibleWithoutCode() && $ilUser->getId() == ANONYMOUS_USER_ID)) {
                 $this->tpl->setCurrentBlock("suspend_survey");
                 if (!$this->preview) {
                     $this->tpl->setVariable("TEXT_SUSPEND", $this->lng->txt("cancel_survey"));
                     $this->tpl->setVariable("HREF_SUSPEND", $this->ctrl->getLinkTargetByClass("ilObjSurveyGUI", "infoScreen"));
                 } else {
                     $this->ctrl->setParameterByClass("ilObjSurveyGUI", "pgov", $_REQUEST["pgov"]);
                     $this->tpl->setVariable("TEXT_SUSPEND", $this->lng->txt("survey_cancel_preview"));
                     $this->tpl->setVariable("HREF_SUSPEND", $this->ctrl->getLinkTargetByClass(array("ilObjSurveyGUI", "ilSurveyEditorGUI"), "questions"));
                 }
                 $this->tpl->setVariable("ALT_IMG_SUSPEND", $this->lng->txt("cancel_survey"));
                 $this->tpl->setVariable("TITLE_IMG_SUSPEND", $this->lng->txt("cancel_survey"));
                 $this->tpl->parseCurrentBlock();
             }
             $this->outNavigationButtons("top", $page);
             $this->tpl->setCurrentBlock("percentage");
             $percentage = (int) ($page[0]["position"] * 100);
             include_once "Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
             $pbar = ilProgressBar::getInstance();
             $pbar->setCurrent($percentage);
             $this->tpl->setVariable("NEW_PBAR", $pbar->render());
             $this->tpl->parseCurrentBlock();
             if (count($page) > 1 && $page[0]["questionblock_show_blocktitle"]) {
                 $this->tpl->setCurrentBlock("questionblock_title");
                 $this->tpl->setVariable("TEXT_QUESTIONBLOCK_TITLE", $page[0]["questionblock_title"]);
                 $this->tpl->parseCurrentBlock();
             }
             foreach ($page as $data) {
                 $this->tpl->setCurrentBlock("survey_content");
                 if ($data["heading"]) {
                     $this->tpl->setVariable("QUESTION_HEADING", $data["heading"]);
                 }
                 if ($first_question == -1) {
                     $first_question = $data["question_id"];
                 }
                 $question_gui = $this->object->getQuestionGUI($data["type_tag"], $data["question_id"]);
                 if (is_array($_SESSION["svy_errors"])) {
                     $working_data =& $question_gui->object->getWorkingDataFromUserInput($_SESSION["postdata"]);
                 } else {
                     $working_data = $this->object->loadWorkingData($data["question_id"], $_SESSION["finished_id"][$this->object->getId()]);
                 }
                 $question_gui->object->setObligatory($data["obligatory"]);
                 $error_messages = array();
                 if (is_array($_SESSION["svy_errors"])) {
                     $error_messages = $_SESSION["svy_errors"];
                 }
                 $show_questiontext = $data["questionblock_show_questiontext"] ? 1 : 0;
                 $question_output = $question_gui->getWorkingForm($working_data, $this->object->getShowQuestionTitles(), $show_questiontext, $error_messages[$data["question_id"]], $this->object->getSurveyId());
                 $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
                 $this->ctrl->setParameter($this, "qid", $data["question_id"]);
                 $this->tpl->parse("survey_content");
                 if ($data["obligatory"]) {
                     $required = true;
                 }
             }
             if ($required) {
                 $this->tpl->setCurrentBlock("required");
                 $this->tpl->setVariable("TEXT_REQUIRED", $this->lng->txt("required_field"));
                 $this->tpl->parseCurrentBlock();
             }
             $this->outNavigationButtons("bottom", $page);
             $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "redirectQuestion"));
         }
     }
     if (!$this->preview) {
         $this->object->setPage($_SESSION["finished_id"][$this->object->getId()], $page[0]['question_id']);
         $this->object->setStartTime($_SESSION["finished_id"][$this->object->getId()], $first_question);
     }
 }
 /**
  * Fill table row
  */
 protected function fillRow($a_set)
 {
     global $lng, $objDefinition;
     $obj_id = $a_set["obj_id"];
     $ref_id = $a_set["ref_id"];
     $type = $a_set['type'];
     $title = $a_set['title'];
     $description = $a_set['description'];
     $relevance = $a_set['relevance'];
     if (!$type) {
         return false;
     }
     include_once './Services/Search/classes/Lucene/class.ilLuceneSearchObjectListGUIFactory.php';
     $item_list_gui = ilLuceneSearchObjectListGUIFactory::factory($type);
     $item_list_gui->initItem($ref_id, $obj_id, $title, $description);
     $item_list_gui->setContainerObject($this->parent_obj);
     $item_list_gui->setSearchFragment($this->presenter->lookupContent($obj_id, 0));
     $item_list_gui->setSeparateCommands(true);
     ilObjectActivation::addListGUIActivationProperty($item_list_gui, $a_set);
     $this->presenter->appendAdditionalInformation($item_list_gui, $ref_id, $obj_id, $type);
     $this->tpl->setVariable("ACTION_HTML", $item_list_gui->getCommandsHTML());
     if ($html = $item_list_gui->getListItemHTML($ref_id, $obj_id, $title, $description)) {
         $item_html[$ref_id]['html'] = $html;
         $item_html[$ref_id]['type'] = $type;
     }
     $this->tpl->setVariable("HREF_IMG", $item_list_gui->default_command["link"]);
     global $lng;
     if ($this->enabledRelevance()) {
         include_once "Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
         $pbar = ilProgressBar::getInstance();
         $pbar->setCurrent($relevance);
         $this->tpl->setCurrentBlock('relev');
         $this->tpl->setVariable('REL_PBAR', $pbar->render());
         $this->tpl->parseCurrentBlock();
     }
     $this->tpl->setVariable("ITEM_HTML", $html);
     if (!$objDefinition->isPlugin($type)) {
         $type_txt = $lng->txt('icon') . ' ' . $lng->txt('obj_' . $type);
         $icon = ilObject::_getIcon($obj_id, 'small', $type);
     } else {
         include_once "./Services/Component/classes/class.ilPlugin.php";
         $type_txt = ilPlugin::lookupTxt("rep_robj", $type, "obj_" . $type);
         $icon = ilObject::_getIcon($obj_id, 'small', $type);
     }
     $this->tpl->setVariable("TYPE_IMG", ilUtil::img($icon, $type_txt));
 }
 /**
  * Append relevance 
  * @return
  */
 protected function appendRelevance($a_obj_id)
 {
     if ($this->getMode() != self::MODE_LUCENE) {
         return '';
     }
     if (!(int) $this->getRelevance($a_obj_id)) {
         return '';
     }
     include_once './Services/Search/classes/class.ilSearchSettings.php';
     if (!ilSearchSettings::getInstance()->isRelevanceVisible()) {
         return '';
     }
     $tpl = new ilTemplate('tpl.lucene_relevance.html', true, true, 'Services/Search');
     include_once "Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
     $pbar = ilProgressBar::getInstance();
     $pbar->setCurrent($this->getRelevance());
     $this->tpl->setCurrentBlock('relevance');
     $this->tpl->setVariable('REL_PBAR', $pbar->render());
     $this->tpl->parseCurrentBlock();
     $html = $tpl->get();
     return $html;
 }
 /**
  * insert relevance 
  * @param
  * @return
  */
 public function insertRelevance()
 {
     global $lng;
     if (!$this->enabledRelevance() or !(int) $this->getRelevance()) {
         return false;
     }
     include_once "Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
     $pbar = ilProgressBar::getInstance();
     $pbar->setCurrent($this->getRelevance());
     $this->tpl->setCurrentBlock('relevance');
     $this->tpl->setVariable('REL_PBAR', $pbar->render());
     $this->tpl->parseCurrentBlock();
 }
 protected function parseRelevance($sub_item)
 {
     if (!ilSearchSettings::getInstance()->isSubRelevanceVisible() || !ilSearchSettings::enabledLucene()) {
         return '';
     }
     $relevance = $this->getHighlighter()->getRelevance($this->getObjId(), $sub_item);
     $this->tpl->addBlockFile('SUB_REL', 'sub_rel', 'tpl.lucene_sub_relevance.html', 'Services/Search');
     include_once "Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
     $pbar = ilProgressBar::getInstance();
     $pbar->setCurrent($relevance);
     $this->tpl->setCurrentBlock('relevance');
     $this->tpl->setVariable('REL_PBAR', $pbar->render());
     $this->tpl->parseCurrentBlock();
 }
 function fillRow($a_poll)
 {
     global $ilCtrl, $lng, $ilUser, $tpl;
     // handle messages
     $mess = $this->poll_block->getMessage($ilUser->getId());
     if ($mess) {
         $this->tpl->setVariable("TXT_QUESTION", $mess);
         return;
     }
     // nested form problem
     if (!$_SESSION["il_cont_admin_panel"]) {
         // vote
         if ($this->poll_block->mayVote($ilUser->getId())) {
             $this->tpl->setCurrentBlock("mode_info_bl");
             if ($this->poll_block->getPoll()->getNonAnonymous()) {
                 $mode_info = $lng->txt("poll_non_anonymous_warning");
             } else {
                 $mode_info = $lng->txt("poll_anonymous_warning");
             }
             $this->tpl->setVariable("MODE_INFO", $mode_info);
             $this->tpl->parseCurrentBlock();
             $is_multi_answer = $this->poll_block->getPoll()->getMaxNumberOfAnswers() > 1;
             if (isset($_SESSION["last_poll_vote"][$this->poll_block->getPoll()->getId()])) {
                 $last_vote = $_SESSION["last_poll_vote"][$this->poll_block->getPoll()->getId()];
                 unset($_SESSION["last_poll_vote"][$this->poll_block->getPoll()->getId()]);
                 if ($is_multi_answer) {
                     $error = sprintf($lng->txt("poll_vote_error_multi"), $this->poll_block->getPoll()->getMaxNumberOfAnswers());
                 } else {
                     $error = $lng->txt("poll_vote_error_single");
                 }
                 $this->tpl->setCurrentBlock("error_bl");
                 $this->tpl->setVariable("FORM_ERROR", $error);
                 $this->tpl->parseCurrentBlock();
             }
             $this->tpl->setCurrentBlock("answer");
             foreach ($a_poll->getAnswers() as $item) {
                 if (!$is_multi_answer) {
                     $this->tpl->setVariable("ANSWER_INPUT", "radio");
                     $this->tpl->setVariable("ANSWER_NAME", "aw");
                 } else {
                     $this->tpl->setVariable("ANSWER_INPUT", "checkbox");
                     $this->tpl->setVariable("ANSWER_NAME", "aw[]");
                     if (is_array($last_vote) && in_array($item["id"], $last_vote)) {
                         $this->tpl->setVariable("ANSWER_STATUS", 'checked="checked"');
                     }
                 }
                 $this->tpl->setVariable("VALUE_ANSWER", $item["id"]);
                 $this->tpl->setVariable("TXT_ANSWER_VOTE", nl2br($item["answer"]));
                 $this->tpl->parseCurrentBlock();
             }
             $ilCtrl->setParameterByClass($this->getRepositoryObjectGUIName(), "ref_id", $this->getRefId());
             $url = $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", $this->getRepositoryObjectGUIName()), "vote");
             $ilCtrl->clearParametersByClass($this->getRepositoryObjectGUIName());
             $url .= "#poll" . $a_poll->getID();
             $this->tpl->setVariable("URL_FORM", $url);
             $this->tpl->setVariable("CMD_FORM", "vote");
             $this->tpl->setVariable("TXT_SUBMIT", $lng->txt("poll_vote"));
             if ($this->poll_block->getPoll()->getVotingPeriod()) {
                 $this->tpl->setVariable("TXT_VOTING_PERIOD", sprintf($lng->txt("poll_voting_period_info"), ilDatePresentation::formatDate(new ilDateTime($this->poll_block->getPoll()->getVotingPeriodEnd(), IL_CAL_UNIX))));
             }
         }
         // result
         if ($this->poll_block->maySeeResults($ilUser->getId())) {
             if (!$this->poll_block->mayNotResultsYet($ilUser->getId())) {
                 $answers = array();
                 foreach ($a_poll->getAnswers() as $item) {
                     $answers[$item["id"]] = $item["answer"];
                 }
                 $perc = $this->poll_block->getPoll()->getVotePercentages();
                 $total = $perc["total"];
                 $perc = $perc["perc"];
                 $this->tpl->setVariable("TOTAL_ANSWERS", sprintf($lng->txt("poll_population"), $total));
                 if ($total) {
                     // sort results by votes / original position
                     if ($this->poll_block->getPoll()->getSortResultByVotes()) {
                         $order = array_keys(ilUtil::sortArray($perc, "abs", "desc", true, true));
                         foreach (array_keys($answers) as $answer_id) {
                             if (!in_array($answer_id, $order)) {
                                 $order[] = $answer_id;
                             }
                         }
                     } else {
                         $order = array_keys($answers);
                     }
                     // pie chart
                     if ($this->poll_block->showResultsAs() == ilObjPoll::SHOW_RESULTS_AS_PIECHART) {
                         include_once "./Services/Chart/classes/class.ilChart.php";
                         $chart = ilChart::getInstanceByType(ilCHart::TYPE_PIE, "poll_results_pie_" . $this->getRefId());
                         $chart->setSize("100%", 200);
                         $chart->setAutoResize(true);
                         $chart_data = $chart->getDataInstance();
                         foreach ($order as $answer_id) {
                             $chart_data->addPoint(round($perc[$answer_id]["perc"]), nl2br($answers[$answer_id]));
                         }
                         // disable legend, use inner labels - currently not preferred
                         // $chart_data->setLabelRadius(0.8);
                         $chart->addData($chart_data);
                         $pie_legend_id = "poll_legend_" . $this->getRefId();
                         $legend = new ilChartLegend();
                         $legend->setContainer($pie_legend_id);
                         $chart->setLegend($legend);
                         $this->tpl->setVariable("PIE_LEGEND_ID", $pie_legend_id);
                         $this->tpl->setVariable("PIE_CHART", $chart->getHTML());
                     } else {
                         include_once "Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
                         $this->tpl->setCurrentBlock("answer_result");
                         foreach ($order as $answer_id) {
                             $pbar = ilProgressBar::getInstance();
                             $pbar->setCurrent(round($perc[$answer_id]["perc"]));
                             $this->tpl->setVariable("PERC_ANSWER_RESULT", $pbar->render());
                             $this->tpl->setVariable("TXT_ANSWER_RESULT", nl2br($answers[$answer_id]));
                             $this->tpl->parseCurrentBlock();
                         }
                     }
                 }
             } else {
                 $rel = ilDatePresentation::useRelativeDates();
                 ilDatePresentation::setUseRelativeDates(false);
                 $end = $this->poll_block->getPoll()->getVotingPeriodEnd();
                 $end = ilDatePresentation::formatDate(new ilDateTime($end, IL_CAL_UNIX));
                 ilDatePresentation::setUseRelativeDates($rel);
                 // #14607
                 $info = "";
                 if ($this->poll_block->getPoll()->hasUserVoted($ilUser->getId())) {
                     $info .= $lng->txt("poll_block_message_already_voted") . " ";
                 }
                 $this->tpl->setVariable("TOTAL_ANSWERS", $info . sprintf($lng->txt("poll_block_results_available_on"), $end));
             }
         } else {
             if ($this->poll_block->getPoll()->hasUserVoted($ilUser->getId())) {
                 $this->tpl->setVariable("TOTAL_ANSWERS", $lng->txt("poll_block_message_already_voted"));
             }
         }
     }
     $this->tpl->setVariable("ANCHOR_ID", $a_poll->getID());
     $this->tpl->setVariable("TXT_QUESTION", nl2br(trim($a_poll->getQuestion())));
     $desc = trim($a_poll->getDescription());
     if ($desc) {
         $this->tpl->setVariable("TXT_DESC", nl2br($desc));
     }
     $img = $a_poll->getImageFullPath();
     if ($img) {
         $this->tpl->setVariable("URL_IMAGE", $img);
     }
     if ($this->poll_block->showComments()) {
         $this->tpl->setCurrentBlock("comment_link");
         $this->tpl->setVariable("LANG_COMMENTS", $lng->txt('poll_comments'));
         $this->tpl->setVariable("COMMENT_JSCALL", $this->commentJSCall());
         $this->tpl->setVariable("COMMENTS_COUNT_ID", $this->getRefId());
         $comments_count = $this->getNumberOfComments($this->getRefId());
         if ($comments_count > 0) {
             $this->tpl->setVariable("COMMENTS_COUNT", "(" . $comments_count . ")");
         }
         if (!self::$js_init) {
             $redraw_url = $ilCtrl->getLinkTarget($this, "getNumberOfCommentsForRedraw", "", true, false);
             $this->tpl->setVariable("COMMENTS_REDRAW_URL", $redraw_url);
             $tpl->addJavaScript("Modules/Poll/js/ilPoll.js");
             self::$js_init = true;
         }
     }
 }
 /**
  * Get relevance html
  */
 public function getRelevanceHTML($a_rel)
 {
     $tpl = new ilTemplate('tpl.lucene_relevance.html', true, true, 'Services/Search');
     include_once "Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
     $pbar = ilProgressBar::getInstance();
     $pbar->setCurrent($a_rel);
     $tpl->setCurrentBlock('relevance');
     $tpl->setVariable('REL_PBAR', $pbar->render());
     $tpl->parseCurrentBlock();
     return $tpl->get();
 }