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)))
366 $this->tpl->setCurrentBlock(
"percentage");
367 $percentage = (int)(($page[0][
"position"])*100);
372 $this->tpl->setVariable(
"PERCENTAGE_ALT", $this->lng->txt(
"percentage"));
373 $this->tpl->setVariable(
"PERCENTAGE_VALUE", $percentage);
374 $this->tpl->setVariable(
"PERCENTAGE_UNFINISHED", 100-$percentage);
375 $this->tpl->parseCurrentBlock();
376 if (count($page) > 1)
378 $this->tpl->setCurrentBlock(
"questionblock_title");
379 $this->tpl->setVariable(
"TEXT_QUESTIONBLOCK_TITLE", $page[0][
"questionblock_title"]);
380 $this->tpl->parseCurrentBlock();
382 foreach ($page as
$data)
384 $this->tpl->setCurrentBlock(
"survey_content");
385 if ($data[
"heading"])
387 $this->tpl->setVariable(
"QUESTION_HEADING", $data[
"heading"]);
389 if ($first_question == -1) $first_question = $data[
"question_id"];
390 $question_gui = $this->
object->getQuestionGUI($data[
"type_tag"], $data[
"question_id"]);
393 $working_data =& $question_gui->object->getWorkingDataFromUserInput(
$_SESSION[
"postdata"]);
397 $working_data = $this->
object->loadWorkingData($data[
"question_id"],
$_SESSION[
"finished_id"][$this->object->getId()]);
399 $question_gui->object->setObligatory($data[
"obligatory"]);
400 $error_messages = array();
403 $error_messages =
$_SESSION[
"svy_errors"];
405 $show_questiontext = ($data[
"questionblock_show_questiontext"]) ? 1 : 0;
406 $question_output = $question_gui->getWorkingForm($working_data, $this->object->getShowQuestionTitles(), $show_questiontext, $error_messages[$data[
"question_id"]], $this->
object->getSurveyId());
407 $this->tpl->setVariable(
"QUESTION_OUTPUT", $question_output);
408 $this->ctrl->setParameter($this,
"qid", $data[
"question_id"]);
409 $this->tpl->parse(
"survey_content");
410 if ($data[
"obligatory"]) $required =
true;
414 $this->tpl->setCurrentBlock(
"required");
415 $this->tpl->setVariable(
"TEXT_REQUIRED", $this->lng->txt(
"required_field"));
416 $this->tpl->parseCurrentBlock();
420 $this->tpl->setVariable(
"FORM_ACTION", $this->ctrl->getFormAction($this,
"redirectQuestion"));
422 $this->
object->setPage(
$_SESSION[
"finished_id"][$this->object->getId()], $page[0][
'question_id']);
423 $this->
object->setStartTime(
$_SESSION[
"finished_id"][$this->object->getId()], $first_question);
436 if (!$rbacsystem->checkAccess(
"read", $this->object->ref_id))
439 $this->ilias->raiseError($this->lng->txt(
"cannot_read_survey"),$this->ilias->error_obj->MESSAGE);
442 $this->
object->setEndTime(
$_SESSION[
"finished_id"][$this->object->getId()]);
447 $page = $this->
object->getNextPage(
$_GET[
"qid"], 0);
448 foreach ($page as
$data)
452 if ($page_error && (strcmp($navigationDirection,
"previous") != 0))
454 if ($page_error == 1)
483 if (!$rbacsystem->checkAccess(
"read", $this->object->ref_id))
486 $this->ilias->raiseError($this->lng->txt(
"cannot_read_survey"),$this->ilias->error_obj->MESSAGE);
492 $page = $this->
object->getNextPage(
$_GET[
"qid"], 0);
493 foreach ($page as
$data)
497 if ($page_error && (strcmp($navigationDirection,
"previous") != 0))
499 if ($page_error == 1)
515 switch ($navigationDirection)
519 $activepage =
$_GET[
"qid"];
526 $activepage =
$_GET[
"qid"];
547 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
549 $error = $question->checkUserInput(
$_POST, $this->object->getSurveyId());
552 $user_id = $ilUser->getId();
554 $this->
object->deleteWorkingData(
$data[
"question_id"],
$_SESSION[
"finished_id"][$this->object->getId()]);
556 if ($this->object->isSurveyStarted($user_id,
$_SESSION[
"anonymous_id"][$this->object->getId()]) ===
false)
558 $_SESSION[
"finished_id"][$this->
object->getId()] = $this->
object->startSurvey($user_id,
$_SESSION[
"anonymous_id"][$this->object->getId()]);
560 if ($this->object->getAnonymize())
564 $question->saveUserInput(
$_POST,
$_SESSION[
"finished_id"][$this->object->getId()]);
583 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"infoScreen");
596 unset(
$_SESSION[
"anonymous_id"][$this->object->getId()]);
599 if ($this->object->getMailConfirmation())
601 include_once
"./Services/Mail/classes/class.ilMimeMail.php";
602 $email = $this->
object->ilias->account->getEmail();
603 $subject = $this->
object->getMailConfirmationSubject();
604 $body = $this->
object->getMailConfirmationBody();
605 $body = str_replace(
'[SURVEY_TITLE]',$this->object->getTitle(),$body);
606 $body = str_replace(
'[FULL_NAME]',$this->object->ilias->account->getFullname(),$body);
607 $body = str_replace(
'[LOGIN]',$this->object->ilias->account->getLogin(),$body);
608 $body = str_replace(
'[EMAIL]',$this->object->ilias->account->getEmail(),$body);
609 $body = str_replace(
'[MATRICULATION]',$this->object->ilias->account->getMatriculation(),$body);
610 $body = str_replace(
'[DATE]',date(
"c"),$body);
612 $mmail->autoCheck(
false);
613 $mmail->From($ilSetting->get(
"admin_email"));
614 $mmail->Subject($subject);
620 $redirect_after_survey = $this->
object->getRedirectAfterSurvey();
622 if (strlen($this->object->getOutro()) != 0)
625 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.il_svy_svy_finished.html",
"Modules/Survey");
626 $this->tpl->setVariable(
"TEXT_FINISHED", $this->object->prepareTextareaOutput($this->object->getOutro()));
627 $this->tpl->setVariable(
"BTN_EXIT", $this->lng->txt(
"exit"));
628 $this->tpl->setVariable(
"FORM_ACTION", $this->ctrl->getFormAction($this,
"runShowFinishedPage"));
632 if ($redirect_after_survey !=
"")
634 if (!$this->object->getRedirectOnlyKioskMode())
646 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"backToRepository");
652 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"backToRepository");
684 $redirect_after_survey = $this->
object->getRedirectAfterSurvey();
685 if ($redirect_after_survey !=
"")
687 if (!$this->object->getRedirectOnlyKioskMode())
699 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"backToRepository");
705 $this->ctrl->redirectByClass(
"ilobjsurveygui",
"backToRepository");
721 $prevpage = $this->
object->getNextPage($page[0][
"question_id"], -1);
722 $this->tpl->setCurrentBlock($navigationblock .
"_prev");
725 $this->tpl->setVariable(
"BTN_PREV", $this->lng->txt(
"survey_start"));
729 $this->tpl->setVariable(
"BTN_PREV", $this->lng->txt(
"survey_previous"));
731 $this->tpl->parseCurrentBlock();
732 $nextpage = $this->
object->getNextPage($page[0][
"question_id"], 1);
733 $this->tpl->setCurrentBlock($navigationblock .
"_next");
736 $this->tpl->setVariable(
"BTN_NEXT", $this->lng->txt(
"survey_finish"));
740 $this->tpl->setVariable(
"BTN_NEXT", $this->lng->txt(
"survey_next"));
742 $this->tpl->parseCurrentBlock();