24 include_once
"./Modules/Survey/classes/inc.SurveyConstants.php";
62 $this->
object =& $a_object;
71 $cmd = $this->ctrl->getCmd();
72 $next_class = $this->ctrl->getNextClass($this);
75 if (strlen(
$cmd) == 0)
77 $this->ctrl->setParameter($this,
"qid",
$_GET[
"qid"]);
78 $this->ctrl->redirect($this,
"gotoPage");
126 if (!$rbacsystem->checkAccess(
"read", $this->object->ref_id))
129 $this->ilias->raiseError($this->lng->txt(
"cannot_read_survey"),$this->ilias->error_obj->MESSAGE);
132 if ($this->object->getAnonymize() && !$this->
object->isAccessibleWithoutCode())
136 $anonymize_key = $this->
object->getAnonymousId($_POST[
"anonymous_id"]);
139 $_SESSION[
"anonymous_id"] = $anonymize_key;
143 unset($_POST[
"cmd"][
"resume"]);
144 ilUtil::sendInfo(sprintf($this->lng->txt(
"error_retrieving_anonymous_survey"), $_POST[
"anonymous_id"]));
151 if ($this->object->getAnonymize() && !$this->
object->isAccessibleWithoutCode())
153 if ($this->object->checkSurveyCode($_POST[
"anonymous_id"]))
155 $_SESSION[
"anonymous_id"] = $_POST[
"anonymous_id"];
159 ilUtil::sendInfo(sprintf($this->lng->txt(
"error_retrieving_anonymous_survey"), $_POST[
"anonymous_id"]),
true);
160 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"infoScreen");
163 if ($this->object->isAccessibleWithoutCode())
165 $anonymous_id = $this->
object->getUserSurveyCode($ilUser->getId());
166 if (strlen($anonymous_id))
168 $_SESSION[
"anonymous_id"] = $anonymous_id;
172 $_SESSION[
"anonymous_id"] = $this->
object->createNewAccessCode();
179 $activepage = $this->
object->getLastActivePage(
$_SESSION[
"finished_id"]);
183 if ($this->object->isSurveyStarted($ilUser->getId(),
$_SESSION[
"anonymous_id"]) === FALSE)
185 $_SESSION[
"finished_id"] = $this->
object->startSurvey($ilUser->getId(),
$_SESSION[
"anonymous_id"]);
187 if (strlen($activepage)) $this->ctrl->setParameter($this,
"qid", $activepage);
188 $this->ctrl->setParameter($this,
"activecommand",
"default");
189 $this->ctrl->redirect($this,
"redirectQuestion");
200 switch (
$_GET[
"activecommand"])
232 $this->ctrl->setParameter($this,
"activecommand",
"previous");
233 $this->ctrl->setParameter($this,
"qid",
$_GET[
"qid"]);
236 $this->ctrl->setParameter($this,
"direction",
"0");
240 $this->ctrl->setParameter($this,
"direction",
"-1");
242 $this->ctrl->redirect($this,
"redirectQuestion");
253 $this->ctrl->setParameter($this,
"activecommand",
"next");
254 $this->ctrl->setParameter($this,
"qid",
$_GET[
"qid"]);
257 $this->ctrl->setParameter($this,
"direction",
"0");
261 $this->ctrl->setParameter($this,
"direction",
"1");
263 $this->ctrl->redirect($this,
"redirectQuestion");
273 $this->ctrl->setParameter($this,
"activecommand",
"gotoPage");
274 $this->ctrl->setParameter($this,
"qid",
$_GET[
"qid"]);
275 $this->ctrl->setParameter($this,
"direction",
"0");
276 $this->ctrl->redirect($this,
"redirectQuestion");
291 $canStart = $this->
object->canStartSurvey(
$_SESSION[
"anonymous_id"]);
292 if (!$canStart[
"result"])
295 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"infoScreen");
297 $survey_started = $this->
object->isSurveyStarted($ilUser->getId(),
$_SESSION[
"anonymous_id"]);
298 if ($survey_started === FALSE)
301 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"infoScreen");
304 $page = $this->
object->getNextPage($activepage, $direction);
305 $constraint_true = 0;
308 if (count($page[0][
"constraints"]))
310 while (is_array($page) and ($constraint_true == 0) and (count($page[0][
"constraints"])))
312 $constraint_true = 1;
313 foreach ($page[0][
"constraints"] as $constraint)
315 $working_data = $this->
object->loadWorkingData($constraint[
"question"],
$_SESSION[
"finished_id"]);
316 $constraint_true = $constraint_true & $this->
object->checkConstraint($constraint, $working_data);
318 if ($constraint_true == 0)
320 $page = $this->
object->getNextPage($page[0][
"question_id"], $direction);
327 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"infoScreen");
329 else if ($page === 1)
331 $this->
object->finishSurvey($ilUser->id,
$_SESSION[
"anonymous_id"]);
338 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.il_svy_svy_content.html",
"Modules/Survey");
340 if (!($this->object->getAnonymize() && $this->
object->isAccessibleWithoutCode() && (
$_SESSION[
"AccountId"] == ANONYMOUS_USER_ID)))
342 $this->tpl->setCurrentBlock(
"suspend_survey");
343 $this->tpl->setVariable(
"TEXT_SUSPEND", $this->lng->txt(
"cancel_survey"));
344 $this->tpl->setVariable(
"HREF_SUSPEND", $this->ctrl->getLinkTargetByClass(
"ilObjSurveyGUI",
"infoScreen"));
345 $this->tpl->setVariable(
"HREF_IMG_SUSPEND", $this->ctrl->getLinkTargetByClass(
"ilObjSurveyGUI",
"infoScreen"));
346 $this->tpl->setVariable(
"ALT_IMG_SUSPEND", $this->lng->txt(
"cancel_survey"));
347 $this->tpl->setVariable(
"TITLE_IMG_SUSPEND", $this->lng->txt(
"cancel_survey"));
349 $this->tpl->parseCurrentBlock();
352 $this->tpl->setCurrentBlock(
"percentage");
353 $percentage = (int)(($page[0][
"position"])*100);
358 $this->tpl->setVariable(
"PERCENTAGE_ALT", $this->lng->txt(
"percentage"));
359 $this->tpl->setVariable(
"PERCENTAGE_VALUE", $percentage);
360 $this->tpl->setVariable(
"PERCENTAGE_UNFINISHED", 100-$percentage);
361 $this->tpl->parseCurrentBlock();
362 if (count($page) > 1)
364 $this->tpl->setCurrentBlock(
"questionblock_title");
365 $this->tpl->setVariable(
"TEXT_QUESTIONBLOCK_TITLE", $page[0][
"questionblock_title"]);
366 $this->tpl->parseCurrentBlock();
368 foreach ($page as
$data)
370 $this->tpl->setCurrentBlock(
"survey_content");
371 if ($data[
"heading"])
373 $this->tpl->setVariable(
"QUESTION_HEADING", $data[
"heading"]);
375 $question_gui = $this->
object->getQuestionGUI($data[
"type_tag"], $data[
"question_id"]);
378 $working_data =& $question_gui->object->getWorkingDataFromUserInput(
$_SESSION[
"postdata"]);
382 $working_data = $this->
object->loadWorkingData($data[
"question_id"],
$_SESSION[
"finished_id"]);
384 $question_gui->object->setObligatory($data[
"obligatory"]);
385 $error_messages = array();
388 $error_messages =
$_SESSION[
"svy_errors"];
390 $show_questiontext = ($data[
"questionblock_show_questiontext"]) ? 1 : 0;
391 $question_output = $question_gui->getWorkingForm($working_data, $this->object->getShowQuestionTitles(), $show_questiontext, $error_messages[$data[
"question_id"]], $this->
object->getSurveyId());
392 $this->tpl->setVariable(
"QUESTION_OUTPUT", $question_output);
393 $this->ctrl->setParameter($this,
"qid", $data[
"question_id"]);
394 $this->tpl->parse(
"survey_content");
397 $this->tpl->setVariable(
"FORM_ACTION", $this->ctrl->getFormAction($this,
"redirectQuestion"));
411 if (!$rbacsystem->checkAccess(
"read", $this->object->ref_id))
414 $this->ilias->raiseError($this->lng->txt(
"cannot_read_survey"),$this->ilias->error_obj->MESSAGE);
421 $page = $this->
object->getNextPage(
$_GET[
"qid"], 0);
422 foreach ($page as
$data)
426 if ($page_error && (strcmp($navigationDirection,
"previous") != 0))
428 if ($page_error == 1)
457 if (!$rbacsystem->checkAccess(
"read", $this->object->ref_id))
460 $this->ilias->raiseError($this->lng->txt(
"cannot_read_survey"),$this->ilias->error_obj->MESSAGE);
466 $page = $this->
object->getNextPage(
$_GET[
"qid"], 0);
467 foreach ($page as
$data)
471 if ($page_error && (strcmp($navigationDirection,
"previous") != 0))
473 if ($page_error == 1)
489 switch ($navigationDirection)
493 $activepage =
$_GET[
"qid"];
500 $activepage =
$_GET[
"qid"];
521 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
523 $error = $question->checkUserInput($_POST, $this->object->getSurveyId());
524 if (strlen($error) == 0)
526 $user_id = $ilUser->getId();
528 $this->
object->deleteWorkingData(
$data[
"question_id"],
$_SESSION[
"finished_id"]);
530 if ($this->object->isSurveyStarted($user_id,
$_SESSION[
"anonymous_id"]) ===
false)
532 $_SESSION[
"finished_id"] = $this->
object->startSurvey($user_id,
$_SESSION[
"anonymous_id"]);
534 if ($this->object->getAnonymize())
538 $question->saveUserInput($_POST,
$_SESSION[
"finished_id"]);
543 $_SESSION[
"svy_errors"][$question->getId()] = $error;
557 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"infoScreen");
570 if (strlen($this->object->getOutro()) == 0)
572 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"backToRepository");
576 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.il_svy_svy_finished.html",
"Modules/Survey");
577 $this->tpl->setVariable(
"TEXT_FINISHED", $this->object->prepareTextareaOutput($this->object->getOutro()));
578 $this->tpl->setVariable(
"BTN_EXIT", $this->lng->txt(
"exit"));
579 $this->tpl->setVariable(
"FORM_ACTION", $this->ctrl->getFormAction($this,
"runShowFinishedPage"));
592 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"backToRepository");
606 $prevpage = $this->
object->getNextPage($page[0][
"question_id"], -1);
607 $this->tpl->setCurrentBlock($navigationblock .
"_prev");
610 $this->tpl->setVariable(
"BTN_PREV", $this->lng->txt(
"survey_start"));
614 $this->tpl->setVariable(
"BTN_PREV", $this->lng->txt(
"survey_previous"));
616 $this->tpl->parseCurrentBlock();
617 $nextpage = $this->
object->getNextPage($page[0][
"question_id"], 1);
618 $this->tpl->setCurrentBlock($navigationblock .
"_next");
621 $this->tpl->setVariable(
"BTN_NEXT", $this->lng->txt(
"survey_finish"));
625 $this->tpl->setVariable(
"BTN_NEXT", $this->lng->txt(
"survey_next"));
627 $this->tpl->parseCurrentBlock();