ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSurveyExecutionGUI.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
36 {
40  protected $rbacsystem;
41 
45  protected $user;
46 
50  protected $help;
51 
55  protected $toolbar;
56 
57  public $object;
58  public $lng;
59  public $tpl;
60  public $ctrl;
61  public $tree;
62  public $preview;
63 
67  protected $log;
68 
77  public function __construct($a_object)
78  {
79  global $DIC;
80 
81  $this->rbacsystem = $DIC->rbac()->system();
82  $this->user = $DIC->user();
83  $this->help = $DIC["ilHelp"];
84  $this->toolbar = $DIC->toolbar();
85  $lng = $DIC->language();
86  $tpl = $DIC["tpl"];
87  $ilCtrl = $DIC->ctrl();
88  $tree = $DIC->repositoryTree();
89 
90  $this->lng = $lng;
91  $this->tpl = $tpl;
92  $this->ctrl = $ilCtrl;
93  $this->object = $a_object;
94  $this->tree = $tree;
95 
96  $this->external_rater_360 = false;
97  if ($this->object->get360Mode() &&
98  $_SESSION["anonymous_id"][$this->object->getId()] &&
100  $this->object->getRefId(),
101  $_SESSION["anonymous_id"][$this->object->getId()]
102  )) {
103  $this->external_rater_360 = true;
104  }
105 
106  // stay in preview mode
107  $this->preview = (bool) $_REQUEST["prvw"];
108  $this->ctrl->saveParameter($this, "prvw");
109  $this->ctrl->saveParameter($this, "pgov");
110 
111  $this->log = ilLoggerFactory::getLogger("svy");
112  }
113 
117  public function executeCommand()
118  {
119  // record read event for lp
121  'svy',
122  $this->object->getRefId(),
123  $this->object->getId(),
124  $GLOBALS['DIC']->user()->getId()
125  );
126 
127  $cmd = $this->ctrl->getCmd();
128  $next_class = $this->ctrl->getNextClass($this);
129 
130  $cmd = $this->getCommand($cmd);
131 
132  $this->log->debug("- cmd= " . $cmd);
133 
134  if (strlen($cmd) == 0) {
135  $this->ctrl->setParameter($this, "qid", $_GET["qid"]);
136  $this->ctrl->redirect($this, "gotoPage");
137  }
138  switch ($next_class) {
139  default:
140  $ret =&$this->$cmd();
141  break;
142  }
143  return $ret;
144  }
145 
146  protected function checkAuth($a_may_start = false, $a_ignore_status = false)
147  {
150 
151  if ($this->preview) {
152  if (!$rbacsystem->checkAccess("write", $this->object->ref_id)) {
153  // only with write access it is possible to preview the survey
154  include_once "Modules/Survey/exceptions/class.ilSurveyException.php";
155  throw new ilSurveyException($this->lng->txt("survey_cannot_preview_survey"));
156  }
157 
158  return true;
159  }
160 
161  if (!$this->external_rater_360 &&
162  !$rbacsystem->checkAccess("read", $this->object->ref_id)) {
163  // only with read access it is possible to run the test
164  include_once "Modules/Survey/exceptions/class.ilSurveyException.php";
165  throw new ilSurveyException($this->lng->txt("cannot_read_survey"));
166  }
167 
168  $user_id = $ilUser->getId();
169 
170  // check existing code
171  // see ilObjSurveyGUI::infoScreen()
172  $anonymous_id = $anonymous_code = null;
173  if ($this->object->getAnonymize() || !$this->object->isAccessibleWithoutCode()) {
174  $anonymous_code = $_SESSION["anonymous_id"][$this->object->getId()];
175  $anonymous_id = $this->object->getAnonymousIdByCode($anonymous_code);
176  if (!$anonymous_id) {
177  ilUtil::sendFailure(sprintf($this->lng->txt("error_retrieving_anonymous_survey"), $anonymous_code, true));
178  $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
179  }
180  }
181 
182  // appraisee validation
183  $appr_id = 0;
184  if ($this->object->get360Mode()) {
185  $appr_id = $_REQUEST["appr_id"];
186  if (!$appr_id) {
187  $appr_id = $_SESSION["appr_id"][$this->object->getId()];
188  }
189  // check if appraisee is valid
190  if ($anonymous_id) {
191  $appraisees = $this->object->getAppraiseesToRate(0, $anonymous_id);
192  }
193  if (!$appraisees && $user_id != ANONYMOUS_USER_ID) {
194  $appraisees = $this->object->getAppraiseesToRate($user_id);
195  }
196  if (!in_array($appr_id, $appraisees)) {
197  ilUtil::sendFailure($this->lng->txt("survey_360_execution_invalid_appraisee"), true);
198  $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
199  }
200  }
201  $_SESSION["appr_id"][$this->object->getId()] = $appr_id;
202 
203  if (!$a_ignore_status) {
204  $status = $this->object->isSurveyStarted($user_id, $anonymous_code, $appr_id);
205  // completed
206  if ($status === 1) {
207  ilUtil::sendFailure($this->lng->txt("already_completed_survey"), true);
208  $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
209  }
210  // starting
211  elseif ($status === false) {
212  if ($a_may_start) {
213  $_SESSION["finished_id"][$this->object->getId()] =
214  $this->object->startSurvey($user_id, $anonymous_code, $appr_id);
215  } else {
216  ilUtil::sendFailure($this->lng->txt("survey_use_start_button"), true);
217  $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
218  }
219  }
220  // resuming
221  else {
222  // nothing todo
223  }
224  }
225 
226  // validate finished id
227  if ($this->object->getActiveID($user_id, $anonymous_code, $appr_id) !=
228  $_SESSION["finished_id"][$this->object->getId()]) {
229  ilUtil::sendFailure($this->lng->txt("cannot_read_survey"), true);
230  $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
231  }
232  }
233 
241  public function getCommand($cmd)
242  {
243  return $cmd;
244  }
245 
253  public function resume()
254  {
255  $this->start(true);
256  }
257 
265  public function start($resume = false)
266  {
267  if ($this->preview) {
268  unset($_SESSION["preview_data"]);
269  }
270  unset($_SESSION["svy_errors"]);
271 
272  $this->checkAuth(!$resume);
273 
274  $activepage = "";
275  if ($resume) {
276  $activepage = $this->object->getLastActivePage($_SESSION["finished_id"][$this->object->getId()]);
277  }
278 
279  if (strlen($activepage)) {
280  $this->ctrl->setParameter($this, "qid", $activepage);
281  }
282  $this->ctrl->setParameter($this, "activecommand", "default");
283  $this->ctrl->redirect($this, "redirectQuestion");
284  }
285 
292  public function redirectQuestion()
293  {
294  switch ($_GET["activecommand"]) {
295  case "next":
296  $this->outSurveyPage($_GET["qid"], $_GET["direction"]);
297  break;
298  case "previous":
299  $this->outSurveyPage($_GET["qid"], $_GET["direction"]);
300  break;
301  case "gotoPage":
302  $this->outSurveyPage($_GET["qid"], $_GET["direction"]);
303  break;
304  case "default":
305  $this->outSurveyPage($_GET["qid"]);
306  break;
307  default:
308  // don't save input, go to the first page
309  $this->outSurveyPage();
310  break;
311  }
312  }
313 
314  public function previousNoSave()
315  {
316  $this->previous(false);
317  }
318 
326  public function previous($a_save_input = true)
327  {
328  if ($a_save_input) {
329  // #16209
330  $has_error = $this->saveUserInput("previous");
331  }
332  $this->ctrl->setParameter($this, "activecommand", "previous");
333  $this->ctrl->setParameter($this, "qid", $_GET["qid"]);
334  if (strlen($has_error)) {
335  $this->ctrl->setParameter($this, "direction", "0");
336  } else {
337  $this->ctrl->setParameter($this, "direction", "-1");
338  }
339  $this->ctrl->redirect($this, "redirectQuestion");
340  }
341 
347  public function next()
348  {
349  $result = $this->saveUserInput("next");
350  $this->ctrl->setParameter($this, "activecommand", "next");
351  $this->ctrl->setParameter($this, "qid", $_GET["qid"]);
352  if (strlen($result)) {
353  $this->ctrl->setParameter($this, "direction", "0");
354  } else {
355  $this->ctrl->setParameter($this, "direction", "1");
356  }
357  $this->ctrl->redirect($this, "redirectQuestion");
358  }
359 
365  public function gotoPage()
366  {
367  $this->ctrl->setParameter($this, "activecommand", "gotoPage");
368  $this->ctrl->setParameter($this, "qid", $_GET["qid"]);
369  $this->ctrl->setParameter($this, "direction", "0");
370  $this->ctrl->redirect($this, "redirectQuestion");
371  }
372 
380  public function outSurveyPage($activepage = null, $direction = null)
381  {
383 
384  $this->checkAuth();
385 
386  $page = $this->object->getNextPage($activepage, $direction);
387  $constraint_true = 0;
388 
389  // check for constraints
390  if (is_array($page[0]["constraints"]) && count($page[0]["constraints"])) {
391  $this->log->debug("Page constraints= ", $page[0]["constraints"]);
392 
393  while (is_array($page) and ($constraint_true == 0) and (count($page[0]["constraints"]))) {
394  $constraint_true = ($page[0]['constraints'][0]['conjunction'] == 0) ? true : false;
395  foreach ($page[0]["constraints"] as $constraint) {
396  if (!$this->preview) {
397  $working_data = $this->object->loadWorkingData($constraint["question"], $_SESSION["finished_id"][$this->object->getId()]);
398  } else {
399  $working_data = $_SESSION["preview_data"][$this->object->getId()][$constraint["question"]];
400  }
401  if ($constraint['conjunction'] == 0) {
402  // and
403  $constraint_true = $constraint_true & $this->object->checkConstraint($constraint, $working_data);
404  } else {
405  // or
406  $constraint_true = $constraint_true | $this->object->checkConstraint($constraint, $working_data);
407  }
408  }
409  if ($constraint_true == 0) {
410  // #11047 - we are skipping the page, so we have to get rid of existing answers for that question(s)
411  foreach ($page as $page_question) {
412  $qid = $page_question["question_id"];
413 
414  // see saveActiveQuestionData()
415  if (!$this->preview) {
416  $this->object->deleteWorkingData($qid, $_SESSION["finished_id"][$this->object->getId()]);
417  } else {
418  $_SESSION["preview_data"][$this->object->getId()][$qid] = null;
419  }
420  }
421 
422  $page = $this->object->getNextPage($page[0]["question_id"], $direction);
423  }
424  }
425  }
426 
427  $first_question = -1;
428  if ($page === 0) {
429  $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
430  } elseif ($page === 1) {
431  $state = $this->object->getUserSurveyExecutionStatus();
432  if ($this->preview ||
433  !$state["runs"][$_SESSION["finished_id"][$this->object->getId()]]["finished"]) {
434  $this->showFinishConfirmation();
435  } else {
436  $this->runShowFinishedPage();
437  }
438  return;
439  } else {
440  $ilHelp = $this->help;
441  $ilHelp->setScreenIdComponent("svy");
442  $ilHelp->setScreenId("quest_presentation");
443 
444  if ($ilUser->getId() != ANONYMOUS_USER_ID) {
445  include_once "Services/Tracking/classes/class.ilLearningProgress.php";
446  ilLearningProgress::_tracProgress($ilUser->getId(), $this->object->getId(), $this->object->ref_id, "svy");
447  }
448 
449  $required = false;
450  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_content.html", "Modules/Survey");
451 
452  if ($this->object->get360Mode()) {
453  $appr_id = $_SESSION["appr_id"][$this->object->getId()];
454 
455  include_once "Services/User/classes/class.ilUserUtil.php";
456  $this->tpl->setTitle($this->object->getTitle() . " (" .
457  $this->lng->txt("survey_360_appraisee") . ": " .
458  ilUserUtil::getNamePresentation($appr_id) . ")");
459  }
460 
461  if (!($this->object->getAnonymize() && $this->object->isAccessibleWithoutCode() && ($ilUser->getId() == ANONYMOUS_USER_ID))) {
462  $this->tpl->setCurrentBlock("suspend_survey");
463 
464  if (!$this->preview) {
465  $this->tpl->setVariable("TEXT_SUSPEND", $this->lng->txt("cancel_survey"));
466  $this->tpl->setVariable("HREF_SUSPEND", $this->ctrl->getLinkTargetByClass("ilObjSurveyGUI", "infoScreen"));
467  } else {
468  $this->ctrl->setParameterByClass("ilObjSurveyGUI", "pgov", $_REQUEST["pgov"]);
469  $this->tpl->setVariable("TEXT_SUSPEND", $this->lng->txt("survey_cancel_preview"));
470  $this->tpl->setVariable("HREF_SUSPEND", $this->ctrl->getLinkTargetByClass(array("ilObjSurveyGUI", "ilSurveyEditorGUI"), "questions"));
471  }
472 
473  $this->tpl->setVariable("ALT_IMG_SUSPEND", $this->lng->txt("cancel_survey"));
474  $this->tpl->setVariable("TITLE_IMG_SUSPEND", $this->lng->txt("cancel_survey"));
475  $this->tpl->parseCurrentBlock();
476  }
477  $this->outNavigationButtons("top", $page);
478 
479 
480  $this->tpl->setCurrentBlock("percentage");
481 
482  $percentage = (int) (($page[0]["position"])*100);
483 
484  include_once "Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
485  $pbar = ilProgressBar::getInstance();
486  $pbar->setCurrent($percentage);
487  $this->tpl->setVariable("NEW_PBAR", $pbar->render());
488 
489  $this->tpl->parseCurrentBlock();
490 
491 
492  if (count($page) > 1 && $page[0]["questionblock_show_blocktitle"]) {
493  $this->tpl->setCurrentBlock("questionblock_title");
494  $this->tpl->setVariable("TEXT_QUESTIONBLOCK_TITLE", $page[0]["questionblock_title"]);
495  $this->tpl->parseCurrentBlock();
496  }
497  foreach ($page as $data) {
498  $this->tpl->setCurrentBlock("survey_content");
499  if ($data["heading"]) {
500  $this->tpl->setVariable("QUESTION_HEADING", $data["heading"]);
501  }
502  if ($first_question == -1) {
503  $first_question = $data["question_id"];
504  }
505  $question_gui = $this->object->getQuestionGUI($data["type_tag"], $data["question_id"]);
506  if (is_array($_SESSION["svy_errors"])) {
507  $working_data =&$question_gui->object->getWorkingDataFromUserInput($_SESSION["postdata"]);
508  } else {
509  $working_data = $this->object->loadWorkingData($data["question_id"], $_SESSION["finished_id"][$this->object->getId()]);
510  }
511  $question_gui->object->setObligatory($data["obligatory"]);
513  if (is_array($_SESSION["svy_errors"])) {
514  $error_messages = $_SESSION["svy_errors"];
515  }
516  $show_questiontext = ($data["questionblock_show_questiontext"]) ? 1 : 0;
517  $question_output = $question_gui->getWorkingForm($working_data, $this->object->getShowQuestionTitles(), $show_questiontext, $error_messages[$data["question_id"]], $this->object->getSurveyId());
518  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
519  $this->ctrl->setParameter($this, "qid", $data["question_id"]);
520  $this->tpl->parse("survey_content");
521  if ($data["obligatory"]) {
522  $required = true;
523  }
524  }
525  if ($required) {
526  $this->tpl->setCurrentBlock("required");
527  $this->tpl->setVariable("TEXT_REQUIRED", $this->lng->txt("required_field"));
528  $this->tpl->parseCurrentBlock();
529  }
530 
531  $this->outNavigationButtons("bottom", $page);
532 
533  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "redirectQuestion"));
534  }
535 
536  if (!$this->preview) {
537  $this->object->setPage($_SESSION["finished_id"][$this->object->getId()], $page[0]['question_id']);
538  $this->object->setStartTime($_SESSION["finished_id"][$this->object->getId()], $first_question);
539  }
540  }
541 
547  public function saveUserInput($navigationDirection = "next")
548  {
549  if (!$this->preview) {
550  $this->object->setEndTime($_SESSION["finished_id"][$this->object->getId()]);
551  }
552 
553  // check users input when it is a metric question
554  unset($_SESSION["svy_errors"]);
555  $_SESSION["postdata"] = $_POST;
556  $page_error = 0;
557  $page = $this->object->getNextPage($_GET["qid"], 0);
558  foreach ($page as $data) {
559  $page_error += $this->saveActiveQuestionData($data);
560  }
561  if ($page_error && (strcmp($navigationDirection, "previous") != 0)) {
562  if ($page_error == 1) {
563  ilUtil::sendFailure($this->lng->txt("svy_page_error"), true);
564  } else {
565  ilUtil::sendFailure($this->lng->txt("svy_page_errors"), true);
566  }
567  } else {
568  $page_error = "";
569  unset($_SESSION["svy_errors"]);
570  }
571  return $page_error;
572  }
573 
581  /*
582  function navigate($navigationDirection = "next")
583  {
584  // check users input when it is a metric question
585  unset($_SESSION["svy_errors"]);
586  $page_error = 0;
587  $page = $this->object->getNextPage($_GET["qid"], 0);
588  foreach ($page as $data)
589  {
590  $page_error += $this->saveActiveQuestionData($data);
591  }
592  if ($page_error && (strcmp($navigationDirection, "previous") != 0))
593  {
594  if ($page_error == 1)
595  {
596  ilUtil::sendFailure($this->lng->txt("svy_page_error"));
597  }
598  else
599  {
600  ilUtil::sendFailure($this->lng->txt("svy_page_errors"));
601  }
602  }
603  else
604  {
605  $page_error = "";
606  unset($_SESSION["svy_errors"]);
607  }
608 
609  $direction = 0;
610  switch ($navigationDirection)
611  {
612  case "next":
613  default:
614  $activepage = $_GET["qid"];
615  if (!$page_error)
616  {
617  $direction = 1;
618  }
619  break;
620  case "previous":
621  $activepage = $_GET["qid"];
622  if (!$page_error)
623  {
624  $direction = -1;
625  }
626  break;
627  }
628  $this->outSurveyPage($activepage, $direction);
629  }
630 */
631 
639  public function saveActiveQuestionData(&$data)
640  {
642 
643  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
644  $question =&SurveyQuestion::_instanciateQuestion($data["question_id"]);
645  $error = $question->checkUserInput($_POST, $this->object->getSurveyId());
646  if (strlen($error) == 0) {
647  if (!$this->preview) {
648  // delete old answers
649  $this->object->deleteWorkingData($data["question_id"], $_SESSION["finished_id"][$this->object->getId()]);
650 
651  $question->saveUserInput($_POST, $_SESSION["finished_id"][$this->object->getId()]);
652  } else {
653  $_SESSION["preview_data"][$this->object->getId()][$data["question_id"]] =
654  $question->saveUserInput($_POST, $_SESSION["finished_id"][$this->object->getId()], true);
655  }
656  return 0;
657  } else {
658  $_SESSION["svy_errors"][$question->getId()] = $error;
659  return 1;
660  }
661  }
662 
670  public function cancel()
671  {
672  $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
673  }
674 
682  public function runShowFinishedPage()
683  {
684  $ilToolbar = $this->toolbar;
686 
687  $has_button = false;
688 
689  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
690 
691  if (!$this->preview) {
692  if ($this->object->hasViewOwnResults()) {
693  $button = ilLinkButton::getInstance();
694  $button->setCaption("svy_view_own_results");
695  $button->setUrl($this->ctrl->getLinkTarget($this, "viewUserResults"));
696  $ilToolbar->addButtonInstance($button);
697 
698  $has_button = true;
699  }
700 
701  if ($this->object->hasMailConfirmation()) {
702  if ($has_button) {
703  $ilToolbar->addSeparator();
704  }
705 
706  if ($ilUser->getId() == ANONYMOUS_USER_ID ||
707  !$ilUser->getEmail()) {
708  require_once "Services/Form/classes/class.ilTextInputGUI.php";
709  $mail = new ilTextInputGUI($this->lng->txt("email"), "mail");
710  $mail->setSize(25);
711  $ilToolbar->addInputItem($mail, true);
712  }
713 
714  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "mailUserResults"));
715 
716  include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
717  $button = ilSubmitButton::getInstance();
718  $button->setCaption("svy_mail_send_confirmation");
719  $button->setCommand("mailUserResults");
720  $ilToolbar->addButtonInstance($button);
721 
722  $has_button = true;
723  }
724 
725  // #6307
726  include_once "Modules/Survey/classes/class.ilObjSurveyAccess.php";
727  if (ilObjSurveyAccess::_hasEvaluationAccess($this->object->getId(), $ilUser->getId())) {
728  $button = ilLinkButton::getInstance();
729  $button->setCaption("svy_results");
730  $button->setUrl($this->ctrl->getLinkTargetByClass("ilObjSurveyGUI", "evaluation"));
731  $ilToolbar->addButtonInstance($button);
732 
733  $has_button = true;
734  }
735  }
736 
737  if (!$has_button &&
738  strlen($this->object->getOutro()) == 0) {
739  $this->exitSurvey();
740  } else {
741  if ($has_button) {
742  $ilToolbar->addSeparator();
743  }
744 
745  $button = ilLinkButton::getInstance();
746  $button->setCaption("survey_execution_exit");
747  $button->setUrl($this->ctrl->getLinkTarget($this, "exitSurvey"));
748  $ilToolbar->addButtonInstance($button);
749 
750  if (strlen($this->object->getOutro())) {
751  include_once "Services/UIComponent/Panel/classes/class.ilPanelGUI.php";
752  $panel = ilPanelGUI::getInstance();
753  $panel->setBody($this->object->prepareTextareaOutput($this->object->getOutro()));
754  $this->tpl->setContent($panel->getHTML());
755  }
756  }
757  }
758 
759  public function backToRepository()
760  {
761  $tree = $this->tree;
762 
763  // #14971
764  if ($this->object->get360Mode()) {
765  $target_ref_id = $this->object->getRefId();
766  } else {
767  // #11534
768  $target_ref_id = $tree->getParentId($this->object->getRefId());
769  }
770 
771  include_once "Services/Link/classes/class.ilLink.php";
772  ilUtil::redirect(ilLink::_getLink($target_ref_id));
773  }
774 
782  public function exitSurvey()
783  {
784  if (!$this->preview) {
785  $this->backToRepository();
786  } else {
787  // #12841
788  $this->ctrl->setParameterByClass("ilsurveyeditorgui", "pgov", $_REQUEST["pgov"]);
789  $this->ctrl->redirectByClass(array("ilobjsurveygui", "ilsurveyeditorgui"), "questions");
790  }
791  }
792 
802  public function outNavigationButtons($navigationblock = "top", $page)
803  {
804  $prevpage = $this->object->getNextPage($page[0]["question_id"], -1);
805  $this->tpl->setCurrentBlock($navigationblock . "_prev");
806  if ($prevpage === 0) {
807  $this->tpl->setVariable("BTN_PREV", $this->lng->txt("survey_start"));
808  } else {
809  $this->tpl->setVariable("BTN_PREV", $this->lng->txt("survey_previous"));
810  }
811  $this->tpl->parseCurrentBlock();
812  $nextpage = $this->object->getNextPage($page[0]["question_id"], 1);
813  $this->tpl->setCurrentBlock($navigationblock . "_next");
814  if ($nextpage === 1) {
815  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("survey_finish"));
816  } else {
817  $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("survey_next"));
818  }
819  $this->tpl->parseCurrentBlock();
820  }
821 
822  public function preview()
823  {
824  $this->outSurveyPage();
825  }
826 
827  public function viewUserResults()
828  {
829  $ilToolbar = $this->toolbar;
830 
831  if (!$this->object->hasViewOwnResults()) {
832  $this->backToRepository();
833  }
834 
835  $this->checkAuth(false, true);
836 
837  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
838  $button = ilLinkButton::getInstance();
839  $button->setCaption("btn_back");
840  $button->setUrl($this->ctrl->getLinkTarget($this, "runShowFinishedPage"));
841  $ilToolbar->addButtonInstance($button);
842 
843  $survey_gui = new ilObjSurveyGUI();
844  $html = $survey_gui->getUserResultsTable($_SESSION["finished_id"][$this->object->getId()]);
845  $this->tpl->setContent($html);
846  }
847 
848  public function mailUserResults()
849  {
851 
852  if (!$this->object->hasMailConfirmation()) {
853  $this->backToRepository();
854  }
855 
856  $this->checkAuth(false, true);
857 
858  $recipient = $_POST["mail"];
859  if (!$recipient) {
860  $recipient = $ilUser->getEmail();
861  }
862  if (!ilUtil::is_email($recipient)) {
863  $this->ctrl->redirect($this, "runShowFinishedPage");
864  }
865 
866  $survey_gui = new ilObjSurveyGUI();
867  $survey_gui->sendUserResultsMail(
868  $_SESSION["finished_id"][$this->object->getId()],
869  $recipient
870  );
871 
872  ilUtil::sendSuccess($this->lng->txt("mail_sent"), true);
873  $this->ctrl->redirect($this, "runShowFinishedPage");
874  }
875 
876  public function showFinishConfirmation()
877  {
878  $tpl = $this->tpl;
879 
880  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
881  $cgui = new ilConfirmationGUI();
882  $cgui->setHeaderText($this->lng->txt("survey_execution_sure_finish"));
883 
884  $cgui->setFormAction($this->ctrl->getFormAction($this, "confirmedFinish"));
885  $cgui->setCancel($this->lng->txt("cancel"), "previousNoSave");
886  $cgui->setConfirm($this->lng->txt("confirm"), "confirmedFinish");
887 
888  $tpl->setContent($cgui->getHTML());
889  }
890 
891  public function confirmedFinish()
892  {
894 
895  if (!$this->preview) {
896  $this->object->finishSurvey($_SESSION["finished_id"][$this->object->getId()]);
897 
898  if ($ilUser->getId() != ANONYMOUS_USER_ID) {
899  include_once "Services/Tracking/classes/class.ilLPStatusWrapper.php";
900  ilLPStatusWrapper::_updateStatus($this->object->getId(), $ilUser->getId());
901  }
902 
903  if ($this->object->getMailNotification()) {
904  $this->object->sendNotificationMail(
905  $ilUser->getId(),
906  $_SESSION["anonymous_id"][$this->object->getId()],
907  $_SESSION["appr_id"][$this->object->getId()]
908  );
909  }
910  }
911 
912  /*
913  unset($_SESSION["anonymous_id"][$this->object->getId()]);
914  unset($_SESSION["appr_id"][$this->object->getId()]);
915  unset($_SESSION["finished_id"][$this->object->getId()]);
916  */
917 
918  $this->ctrl->redirect($this, "runShowFinishedPage");
919  }
920 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static _recordReadEvent( $a_type, $a_ref_id, $obj_id, $usr_id, $isCatchupWriteEvents=true, $a_ext_rc=false, $a_ext_time=false)
Records a read event and catches up with write events.
getCommand($cmd)
Retrieves the ilCtrl command.
$error_messages
__construct($a_object)
ilSurveyExecutionGUI constructor
$_SESSION["AccountId"]
$result
outNavigationButtons($navigationblock="top", $page)
Creates the navigation buttons for a survey.
global $DIC
Definition: saml.php:7
static validateExternalRaterCode($a_ref_id, $a_code)
static is_email($a_email, ilMailRfc822AddressParserFactory $mailAddressParserFactory=null)
This preg-based function checks whether an e-mail address is formally valid.
$_GET["client_id"]
saveActiveQuestionData(&$data)
Survey navigation.
exitSurvey()
Exits the survey after finishing it.
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
saveUserInput($navigationDirection="next")
Save the user&#39;s input.
static _tracProgress($a_user_id, $a_obj_id, $a_ref_id, $a_obj_type='')
redirectQuestion()
Called when a user answered a page to perform a redirect after POST.
Survey exception class.
user()
Definition: user.php:4
global $ilCtrl
Definition: ilias.php:18
Class ilObjSurveyGUI.
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
$error
Definition: Error.php:17
next()
Navigates to the next pages.
static getInstance()
Factory.
gotoPage()
Go to a specific page without saving.
Survey execution graphical output.
checkAuth($a_may_start=false, $a_ignore_status=false)
runShowFinishedPage()
Creates the finished page for a running survey.
setSize($a_size)
Set Size.
This class represents a text property in a property form.
$ilUser
Definition: imgupload.php:18
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
previous($a_save_input=true)
Navigates to the previous pages.
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static _hasEvaluationAccess($a_obj_id, $user_id)
static getInstance()
Get instance.
start($resume=false)
Starts the survey.
Create new PHPExcel object
obj_idprivate
$ret
Definition: parser.php:6
static getLogger($a_component_id)
Get component logger.
static redirect($a_script)
$_POST["username"]
$html
Definition: example_001.php:87
outSurveyPage($activepage=null, $direction=null)
Output of the active survey question to the screen.
Confirmation screen class.