24 include_once
"./Modules/Survey/classes/inc.SurveyConstants.php";
63 $this->
object =& $a_object;
68 $this->ctrl->saveParameter($this,
"prvw");
69 $this->ctrl->saveParameter($this,
"pgov");
77 $cmd = $this->ctrl->getCmd();
78 $next_class = $this->ctrl->getNextClass($this);
81 if (strlen(
$cmd) == 0)
83 $this->ctrl->setParameter($this,
"qid",
$_GET[
"qid"]);
84 $this->ctrl->redirect($this,
"gotoPage");
136 if (!$rbacsystem->checkAccess(
"read", $this->object->ref_id))
139 $this->ilias->raiseError($this->lng->txt(
"cannot_read_survey"),$this->ilias->error_obj->MESSAGE);
142 if ($this->object->getAnonymize() && !$this->
object->isAccessibleWithoutCode())
146 $anonymize_key = $this->
object->getAnonymousId(
$_POST[
"anonymous_id"]);
149 $_SESSION[
"anonymous_id"][$this->
object->getId()] = $anonymize_key;
153 unset(
$_POST[
"cmd"][
"resume"]);
161 if ($this->object->getAnonymize() && !$this->
object->isAccessibleWithoutCode())
163 if ($this->object->checkSurveyCode(
$_POST[
"anonymous_id"]))
165 $_SESSION[
"anonymous_id"][$this->
object->getId()] =
$_POST[
"anonymous_id"];
170 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"infoScreen");
173 if ($this->object->isAccessibleWithoutCode())
175 $anonymous_id = $this->
object->getUserSurveyCode($ilUser->getId());
176 if (strlen($anonymous_id))
178 $_SESSION[
"anonymous_id"][$this->
object->getId()] = $anonymous_id;
182 $_SESSION[
"anonymous_id"][$this->
object->getId()] = $this->
object->createNewAccessCode();
189 $activepage = $this->
object->getLastActivePage(
$_SESSION[
"finished_id"][$this->object->getId()]);
193 if ($this->object->isSurveyStarted($ilUser->getId(),
$_SESSION[
"anonymous_id"][$this->
object->getId()]) === FALSE)
195 $_SESSION[
"finished_id"][$this->
object->getId()] = $this->
object->startSurvey($ilUser->getId(),
$_SESSION[
"anonymous_id"][$this->
object->getId()]);
197 if (strlen($activepage)) $this->ctrl->setParameter($this,
"qid", $activepage);
198 $this->ctrl->setParameter($this,
"activecommand",
"default");
199 $this->ctrl->redirect($this,
"redirectQuestion");
210 switch (
$_GET[
"activecommand"])
242 $this->ctrl->setParameter($this,
"activecommand",
"previous");
243 $this->ctrl->setParameter($this,
"qid",
$_GET[
"qid"]);
246 $this->ctrl->setParameter($this,
"direction",
"0");
250 $this->ctrl->setParameter($this,
"direction",
"-1");
252 $this->ctrl->redirect($this,
"redirectQuestion");
263 $this->ctrl->setParameter($this,
"activecommand",
"next");
264 $this->ctrl->setParameter($this,
"qid",
$_GET[
"qid"]);
267 $this->ctrl->setParameter($this,
"direction",
"0");
271 $this->ctrl->setParameter($this,
"direction",
"1");
273 $this->ctrl->redirect($this,
"redirectQuestion");
283 $this->ctrl->setParameter($this,
"activecommand",
"gotoPage");
284 $this->ctrl->setParameter($this,
"qid",
$_GET[
"qid"]);
285 $this->ctrl->setParameter($this,
"direction",
"0");
286 $this->ctrl->redirect($this,
"redirectQuestion");
298 global $ilUser,$rbacsystem;
303 $canStart = $this->
object->canStartSurvey(
$_SESSION[
"anonymous_id"][$this->object->getId()]);
304 if (!$canStart[
"result"])
307 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"infoScreen");
309 $survey_started = $this->
object->isSurveyStarted($ilUser->getId(),
$_SESSION[
"anonymous_id"][$this->
object->getId()]);
310 if ($survey_started === FALSE)
313 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"infoScreen");
316 else if (!$rbacsystem->checkAccess(
"write", $this->object->ref_id))
319 $this->ilias->raiseError($this->lng->txt(
"survey_cannot_preview_survey"),$this->ilias->error_obj->MESSAGE);
322 $page = $this->
object->getNextPage($activepage, $direction);
323 $constraint_true = 0;
326 if (count($page[0][
"constraints"]))
328 while (is_array($page) and ($constraint_true == 0) and (count($page[0][
"constraints"])))
330 $constraint_true = ($page[0][
'constraints'][0][
'conjunction'] == 0) ?
true :
false;
331 foreach ($page[0][
"constraints"] as $constraint)
335 $working_data = $this->
object->loadWorkingData($constraint[
"question"],
$_SESSION[
"finished_id"][$this->object->getId()]);
339 $working_data =
$_SESSION[
"preview_data"][$this->
object->getId()][$constraint[
"question"]];
341 if ($constraint[
'conjunction'] == 0)
344 $constraint_true = $constraint_true & $this->
object->checkConstraint($constraint, $working_data);
349 $constraint_true = $constraint_true | $this->
object->checkConstraint($constraint, $working_data);
352 if ($constraint_true == 0)
355 foreach($page as $page_question)
357 $qid = $page_question[
"question_id"];
362 $this->
object->deleteWorkingData($qid,
$_SESSION[
"finished_id"][$this->object->getId()]);
366 $_SESSION[
"preview_data"][$this->
object->getId()][$qid] = null;
370 $page = $this->
object->getNextPage($page[0][
"question_id"], $direction);
375 $first_question = -1;
378 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"infoScreen");
380 else if ($page === 1)
382 $this->
object->finishSurvey($ilUser->id,
$_SESSION[
"anonymous_id"][$this->object->getId()]);
383 if (array_key_exists(
"anonymous_id",
$_SESSION)) unset(
$_SESSION[
"anonymous_id"][$this->object->getId()]);
390 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.il_svy_svy_content.html",
"Modules/Survey");
392 if (!($this->object->getAnonymize() && $this->
object->isAccessibleWithoutCode() && (
$_SESSION[
"AccountId"] == ANONYMOUS_USER_ID)))
394 $this->tpl->setCurrentBlock(
"suspend_survey");
398 $this->tpl->setVariable(
"TEXT_SUSPEND", $this->lng->txt(
"cancel_survey"));
399 $this->tpl->setVariable(
"HREF_SUSPEND", $this->ctrl->getLinkTargetByClass(
"ilObjSurveyGUI",
"infoScreen"));
400 $this->tpl->setVariable(
"HREF_IMG_SUSPEND", $this->ctrl->getLinkTargetByClass(
"ilObjSurveyGUI",
"infoScreen"));
404 $this->ctrl->setParameterByClass(
"ilObjSurveyGUI",
"pgov",
$_REQUEST[
"pgov"]);
405 $this->tpl->setVariable(
"TEXT_SUSPEND", $this->lng->txt(
"survey_cancel_preview"));
406 $this->tpl->setVariable(
"HREF_SUSPEND", $this->ctrl->getLinkTargetByClass(
"ilObjSurveyGUI",
"questions"));
407 $this->tpl->setVariable(
"HREF_IMG_SUSPEND", $this->ctrl->getLinkTargetByClass(
"ilObjSurveyGUI",
"questions"));
410 $this->tpl->setVariable(
"ALT_IMG_SUSPEND", $this->lng->txt(
"cancel_survey"));
411 $this->tpl->setVariable(
"TITLE_IMG_SUSPEND", $this->lng->txt(
"cancel_survey"));
413 $this->tpl->parseCurrentBlock();
416 $this->tpl->setCurrentBlock(
"percentage");
417 $percentage = (int)(($page[0][
"position"])*100);
422 $this->tpl->setVariable(
"PERCENTAGE_ALT", $this->lng->txt(
"percentage"));
423 $this->tpl->setVariable(
"PERCENTAGE_VALUE", $percentage);
424 $this->tpl->setVariable(
"PERCENTAGE_UNFINISHED", 100-$percentage);
425 $this->tpl->parseCurrentBlock();
426 if (count($page) > 1 && $page[0][
"questionblock_show_blocktitle"])
428 $this->tpl->setCurrentBlock(
"questionblock_title");
429 $this->tpl->setVariable(
"TEXT_QUESTIONBLOCK_TITLE", $page[0][
"questionblock_title"]);
430 $this->tpl->parseCurrentBlock();
432 foreach ($page as
$data)
434 $this->tpl->setCurrentBlock(
"survey_content");
435 if ($data[
"heading"])
437 $this->tpl->setVariable(
"QUESTION_HEADING", $data[
"heading"]);
439 if ($first_question == -1) $first_question = $data[
"question_id"];
440 $question_gui = $this->
object->getQuestionGUI($data[
"type_tag"], $data[
"question_id"]);
443 $working_data =& $question_gui->object->getWorkingDataFromUserInput(
$_SESSION[
"postdata"]);
447 $working_data = $this->
object->loadWorkingData($data[
"question_id"],
$_SESSION[
"finished_id"][$this->object->getId()]);
449 $question_gui->object->setObligatory($data[
"obligatory"]);
450 $error_messages = array();
453 $error_messages =
$_SESSION[
"svy_errors"];
455 $show_questiontext = ($data[
"questionblock_show_questiontext"]) ? 1 : 0;
456 $question_output = $question_gui->getWorkingForm($working_data, $this->object->getShowQuestionTitles(), $show_questiontext, $error_messages[$data[
"question_id"]], $this->
object->getSurveyId());
457 $this->tpl->setVariable(
"QUESTION_OUTPUT", $question_output);
458 $this->ctrl->setParameter($this,
"qid", $data[
"question_id"]);
459 $this->tpl->parse(
"survey_content");
460 if ($data[
"obligatory"]) $required =
true;
464 $this->tpl->setCurrentBlock(
"required");
465 $this->tpl->setVariable(
"TEXT_REQUIRED", $this->lng->txt(
"required_field"));
466 $this->tpl->parseCurrentBlock();
471 $this->tpl->setVariable(
"FORM_ACTION", $this->ctrl->getFormAction($this,
"redirectQuestion"));
476 $this->
object->setPage(
$_SESSION[
"finished_id"][$this->object->getId()], $page[0][
'question_id']);
477 $this->
object->setStartTime(
$_SESSION[
"finished_id"][$this->object->getId()], $first_question);
491 if (!$rbacsystem->checkAccess(
"read", $this->object->ref_id))
494 $this->ilias->raiseError($this->lng->txt(
"cannot_read_survey"),$this->ilias->error_obj->MESSAGE);
499 $this->
object->setEndTime(
$_SESSION[
"finished_id"][$this->object->getId()]);
506 $page = $this->
object->getNextPage(
$_GET[
"qid"], 0);
507 foreach ($page as
$data)
511 if ($page_error && (strcmp($navigationDirection,
"previous") != 0))
513 if ($page_error == 1)
542 if (!$rbacsystem->checkAccess(
"read", $this->object->ref_id))
545 $this->ilias->raiseError($this->lng->txt(
"cannot_read_survey"),$this->ilias->error_obj->MESSAGE);
551 $page = $this->
object->getNextPage(
$_GET[
"qid"], 0);
552 foreach ($page as
$data)
556 if ($page_error && (strcmp($navigationDirection,
"previous") != 0))
558 if ($page_error == 1)
574 switch ($navigationDirection)
578 $activepage =
$_GET[
"qid"];
585 $activepage =
$_GET[
"qid"];
606 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
608 $error = $question->checkUserInput(
$_POST, $this->object->getSurveyId());
609 if (strlen($error) == 0)
613 $user_id = $ilUser->getId();
616 $this->
object->deleteWorkingData(
$data[
"question_id"],
$_SESSION[
"finished_id"][$this->object->getId()]);
618 if ($this->object->isSurveyStarted($user_id,
$_SESSION[
"anonymous_id"][$this->object->getId()]) ===
false)
620 $_SESSION[
"finished_id"][$this->
object->getId()] = $this->
object->startSurvey($user_id,
$_SESSION[
"anonymous_id"][$this->object->getId()]);
622 if ($this->object->getAnonymize())
626 $question->saveUserInput(
$_POST,
$_SESSION[
"finished_id"][$this->object->getId()]);
630 $_SESSION[
"preview_data"][$this->
object->getId()][
$data[
"question_id"]] =
631 $question->saveUserInput(
$_POST,
$_SESSION[
"finished_id"][$this->object->getId()],
true);
637 $_SESSION[
"svy_errors"][$question->getId()] = $error;
651 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"infoScreen");
663 unset(
$_SESSION[
"anonymous_id"][$this->object->getId()]);
664 if (strlen($this->object->getOutro()) == 0)
666 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"backToRepository");
670 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.il_svy_svy_finished.html",
"Modules/Survey");
671 $this->tpl->setVariable(
"TEXT_FINISHED", $this->object->prepareTextareaOutput($this->object->getOutro()));
672 $this->tpl->setVariable(
"BTN_EXIT", $this->lng->txt(
"exit"));
673 $this->tpl->setVariable(
"FORM_ACTION", $this->ctrl->getFormAction($this,
"runShowFinishedPage"));
688 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"backToRepository");
692 $this->ctrl->setParameterByClass(
"ilobjsurveygui",
"pgov",
$_REQUEST[
"pgov"]);
693 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"questions");
708 $prevpage = $this->
object->getNextPage($page[0][
"question_id"], -1);
709 $this->tpl->setCurrentBlock($navigationblock .
"_prev");
712 $this->tpl->setVariable(
"BTN_PREV", $this->lng->txt(
"survey_start"));
716 $this->tpl->setVariable(
"BTN_PREV", $this->lng->txt(
"survey_previous"));
718 $this->tpl->parseCurrentBlock();
719 $nextpage = $this->
object->getNextPage($page[0][
"question_id"], 1);
720 $this->tpl->setCurrentBlock($navigationblock .
"_next");
723 $this->tpl->setVariable(
"BTN_NEXT", $this->lng->txt(
"survey_finish"));
727 $this->tpl->setVariable(
"BTN_NEXT", $this->lng->txt(
"survey_next"));
729 $this->tpl->parseCurrentBlock();