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"][$this->
object->getId()] = $anonymize_key;
143 unset(
$_POST[
"cmd"][
"resume"]);
151 if ($this->object->getAnonymize() && !$this->
object->isAccessibleWithoutCode())
153 if ($this->object->checkSurveyCode(
$_POST[
"anonymous_id"]))
155 $_SESSION[
"anonymous_id"][$this->
object->getId()] =
$_POST[
"anonymous_id"];
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"][$this->
object->getId()] = $anonymous_id;
172 $_SESSION[
"anonymous_id"][$this->
object->getId()] = $this->
object->createNewAccessCode();
179 $activepage = $this->
object->getLastActivePage(
$_SESSION[
"finished_id"][$this->object->getId()]);
183 if ($this->object->isSurveyStarted($ilUser->getId(),
$_SESSION[
"anonymous_id"][$this->
object->getId()]) === FALSE)
185 $_SESSION[
"finished_id"][$this->
object->getId()] = $this->
object->startSurvey($ilUser->getId(),
$_SESSION[
"anonymous_id"][$this->
object->getId()]);
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"][$this->object->getId()]);
292 if (!$canStart[
"result"])
295 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"infoScreen");
297 $survey_started = $this->
object->isSurveyStarted($ilUser->getId(),
$_SESSION[
"anonymous_id"][$this->
object->getId()]);
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 = ($page[0][
'constraints'][0][
'conjunction'] == 0) ?
true :
false;
313 foreach ($page[0][
"constraints"] as $constraint)
315 $working_data = $this->
object->loadWorkingData($constraint[
"question"],
$_SESSION[
"finished_id"][$this->object->getId()]);
316 if ($constraint[
'conjunction'] == 0)
319 $constraint_true = $constraint_true & $this->
object->checkConstraint($constraint, $working_data);
324 $constraint_true = $constraint_true | $this->
object->checkConstraint($constraint, $working_data);
327 if ($constraint_true == 0)
329 $page = $this->
object->getNextPage($page[0][
"question_id"], $direction);
334 $first_question = -1;
337 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"infoScreen");
339 else if ($page === 1)
341 $this->
object->finishSurvey($ilUser->id,
$_SESSION[
"anonymous_id"][$this->object->getId()]);
342 if (array_key_exists(
"anonymous_id",
$_SESSION)) unset(
$_SESSION[
"anonymous_id"][$this->object->getId()]);
349 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.il_svy_svy_content.html",
"Modules/Survey");
351 if (!($this->object->getAnonymize() && $this->
object->isAccessibleWithoutCode() && (
$_SESSION[
"AccountId"] == ANONYMOUS_USER_ID)))
353 $this->tpl->setCurrentBlock(
"suspend_survey");
354 $this->tpl->setVariable(
"TEXT_SUSPEND", $this->lng->txt(
"cancel_survey"));
355 $this->tpl->setVariable(
"HREF_SUSPEND", $this->ctrl->getLinkTargetByClass(
"ilObjSurveyGUI",
"infoScreen"));
356 $this->tpl->setVariable(
"HREF_IMG_SUSPEND", $this->ctrl->getLinkTargetByClass(
"ilObjSurveyGUI",
"infoScreen"));
357 $this->tpl->setVariable(
"ALT_IMG_SUSPEND", $this->lng->txt(
"cancel_survey"));
358 $this->tpl->setVariable(
"TITLE_IMG_SUSPEND", $this->lng->txt(
"cancel_survey"));
360 $this->tpl->parseCurrentBlock();
363 $this->tpl->setCurrentBlock(
"percentage");
364 $percentage = (int)(($page[0][
"position"])*100);
369 $this->tpl->setVariable(
"PERCENTAGE_ALT", $this->lng->txt(
"percentage"));
370 $this->tpl->setVariable(
"PERCENTAGE_VALUE", $percentage);
371 $this->tpl->setVariable(
"PERCENTAGE_UNFINISHED", 100-$percentage);
372 $this->tpl->parseCurrentBlock();
373 if (count($page) > 1)
375 $this->tpl->setCurrentBlock(
"questionblock_title");
376 $this->tpl->setVariable(
"TEXT_QUESTIONBLOCK_TITLE", $page[0][
"questionblock_title"]);
377 $this->tpl->parseCurrentBlock();
379 foreach ($page as
$data)
381 $this->tpl->setCurrentBlock(
"survey_content");
382 if ($data[
"heading"])
384 $this->tpl->setVariable(
"QUESTION_HEADING", $data[
"heading"]);
386 if ($first_question == -1) $first_question = $data[
"question_id"];
387 $question_gui = $this->
object->getQuestionGUI($data[
"type_tag"], $data[
"question_id"]);
390 $working_data =& $question_gui->object->getWorkingDataFromUserInput(
$_SESSION[
"postdata"]);
394 $working_data = $this->
object->loadWorkingData($data[
"question_id"],
$_SESSION[
"finished_id"][$this->object->getId()]);
396 $question_gui->object->setObligatory($data[
"obligatory"]);
397 $error_messages = array();
400 $error_messages =
$_SESSION[
"svy_errors"];
402 $show_questiontext = ($data[
"questionblock_show_questiontext"]) ? 1 : 0;
403 $question_output = $question_gui->getWorkingForm($working_data, $this->object->getShowQuestionTitles(), $show_questiontext, $error_messages[$data[
"question_id"]], $this->
object->getSurveyId());
404 $this->tpl->setVariable(
"QUESTION_OUTPUT", $question_output);
405 $this->ctrl->setParameter($this,
"qid", $data[
"question_id"]);
406 $this->tpl->parse(
"survey_content");
407 if ($data[
"obligatory"]) $required =
true;
411 $this->tpl->setCurrentBlock(
"required");
412 $this->tpl->setVariable(
"TEXT_REQUIRED", $this->lng->txt(
"required_field"));
413 $this->tpl->parseCurrentBlock();
417 $this->tpl->setVariable(
"FORM_ACTION", $this->ctrl->getFormAction($this,
"redirectQuestion"));
419 $this->
object->setPage(
$_SESSION[
"finished_id"][$this->object->getId()], $page[0][
'question_id']);
420 $this->
object->setStartTime(
$_SESSION[
"finished_id"][$this->object->getId()], $first_question);
433 if (!$rbacsystem->checkAccess(
"read", $this->object->ref_id))
436 $this->ilias->raiseError($this->lng->txt(
"cannot_read_survey"),$this->ilias->error_obj->MESSAGE);
439 $this->
object->setEndTime(
$_SESSION[
"finished_id"][$this->object->getId()]);
444 $page = $this->
object->getNextPage(
$_GET[
"qid"], 0);
445 foreach ($page as
$data)
449 if ($page_error && (strcmp($navigationDirection,
"previous") != 0))
451 if ($page_error == 1)
480 if (!$rbacsystem->checkAccess(
"read", $this->object->ref_id))
483 $this->ilias->raiseError($this->lng->txt(
"cannot_read_survey"),$this->ilias->error_obj->MESSAGE);
489 $page = $this->
object->getNextPage(
$_GET[
"qid"], 0);
490 foreach ($page as
$data)
494 if ($page_error && (strcmp($navigationDirection,
"previous") != 0))
496 if ($page_error == 1)
512 switch ($navigationDirection)
516 $activepage =
$_GET[
"qid"];
523 $activepage =
$_GET[
"qid"];
544 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
546 $error = $question->checkUserInput(
$_POST, $this->object->getSurveyId());
547 if (strlen($error) == 0)
549 $user_id = $ilUser->getId();
551 $this->
object->deleteWorkingData(
$data[
"question_id"],
$_SESSION[
"finished_id"][$this->object->getId()]);
553 if ($this->object->isSurveyStarted($user_id,
$_SESSION[
"anonymous_id"][$this->object->getId()]) ===
false)
555 $_SESSION[
"finished_id"][$this->
object->getId()] = $this->
object->startSurvey($user_id,
$_SESSION[
"anonymous_id"][$this->object->getId()]);
557 if ($this->object->getAnonymize())
561 $question->saveUserInput(
$_POST,
$_SESSION[
"finished_id"][$this->object->getId()]);
566 $_SESSION[
"svy_errors"][$question->getId()] = $error;
580 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"infoScreen");
592 unset(
$_SESSION[
"anonymous_id"][$this->object->getId()]);
593 if (strlen($this->object->getOutro()) == 0)
595 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"backToRepository");
599 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.il_svy_svy_finished.html",
"Modules/Survey");
600 $this->tpl->setVariable(
"TEXT_FINISHED", $this->object->prepareTextareaOutput($this->object->getOutro()));
601 $this->tpl->setVariable(
"BTN_EXIT", $this->lng->txt(
"exit"));
602 $this->tpl->setVariable(
"FORM_ACTION", $this->ctrl->getFormAction($this,
"runShowFinishedPage"));
615 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"backToRepository");
629 $prevpage = $this->
object->getNextPage($page[0][
"question_id"], -1);
630 $this->tpl->setCurrentBlock($navigationblock .
"_prev");
633 $this->tpl->setVariable(
"BTN_PREV", $this->lng->txt(
"survey_start"));
637 $this->tpl->setVariable(
"BTN_PREV", $this->lng->txt(
"survey_previous"));
639 $this->tpl->parseCurrentBlock();
640 $nextpage = $this->
object->getNextPage($page[0][
"question_id"], 1);
641 $this->tpl->setCurrentBlock($navigationblock .
"_next");
644 $this->tpl->setVariable(
"BTN_NEXT", $this->lng->txt(
"survey_finish"));
648 $this->tpl->setVariable(
"BTN_NEXT", $this->lng->txt(
"survey_next"));
650 $this->tpl->parseCurrentBlock();