• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Modules/Survey/classes/class.ilSurveyExecutionGUI.php

Go to the documentation of this file.
00001 <?php
00002  /*
00003    +----------------------------------------------------------------------------+
00004    | ILIAS open source                                                          |
00005    +----------------------------------------------------------------------------+
00006    | Copyright (c) 1998-2001 ILIAS open source, University of Cologne           |
00007    |                                                                            |
00008    | This program is free software; you can redistribute it and/or              |
00009    | modify it under the terms of the GNU General Public License                |
00010    | as published by the Free Software Foundation; either version 2             |
00011    | of the License, or (at your option) any later version.                     |
00012    |                                                                            |
00013    | This program is distributed in the hope that it will be useful,            |
00014    | but WITHOUT ANY WARRANTY; without even the implied warranty of             |
00015    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              |
00016    | GNU General Public License for more details.                               |
00017    |                                                                            |
00018    | You should have received a copy of the GNU General Public License          |
00019    | along with this program; if not, write to the Free Software                |
00020    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
00021    +----------------------------------------------------------------------------+
00022 */
00023 
00024 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
00025 
00037 class ilSurveyExecutionGUI
00038 {
00039         var $object;
00040         var $lng;
00041         var $tpl;
00042         var $ctrl;
00043         var $ilias;
00044         var $tree;
00045         
00054   function ilSurveyExecutionGUI($a_object)
00055   {
00056                 global $lng, $tpl, $ilCtrl, $ilias, $tree;
00057 
00058     $this->lng =& $lng;
00059     $this->tpl =& $tpl;
00060                 $this->ctrl =& $ilCtrl;
00061                 $this->ilias =& $ilias;
00062                 $this->object =& $a_object;
00063                 $this->tree =& $tree;
00064         }
00065         
00069         function &executeCommand()
00070         {
00071                 $cmd = $this->ctrl->getCmd();
00072                 $next_class = $this->ctrl->getNextClass($this);
00073 
00074                 $cmd = $this->getCommand($cmd);
00075                 switch($next_class)
00076                 {
00077                         default:
00078                                 $ret =& $this->$cmd();
00079                                 break;
00080                 }
00081                 return $ret;
00082         }
00083 
00091         function getCommand($cmd)
00092         {
00093                 return $cmd;
00094         }
00095 
00103         function resume()
00104         {
00105                 $this->start(true);
00106         }
00107         
00115         function start($resume = false)
00116         {
00117                 global $ilUser;
00118                 global $rbacsystem;
00119 
00120                 unset($_SESSION["svy_errors"]);
00121                 if (!$rbacsystem->checkAccess("read", $this->object->ref_id)) 
00122                 {
00123                         // only with read access it is possible to run the test
00124                         $this->ilias->raiseError($this->lng->txt("cannot_read_survey"),$this->ilias->error_obj->MESSAGE);
00125                 }
00126 
00127                 if ($this->object->getAnonymize() && !$this->object->isAccessibleWithoutCode())
00128                 {
00129                         if ($resume)
00130                         {
00131                                 $anonymize_key = $this->object->getAnonymousId($_POST["anonymous_id"]);
00132                                 if ($anonymize_key)
00133                                 {
00134                                         $_SESSION["anonymous_id"] = $anonymize_key;
00135                                 }
00136                                 else
00137                                 {
00138                                         unset($_POST["cmd"]["resume"]);
00139                                         ilUtil::sendInfo(sprintf($this->lng->txt("error_retrieving_anonymous_survey"), $_POST["anonymous_id"]));
00140                                 }
00141                         }
00142                 }
00143                 
00144                 $direction = 0;
00145 
00146                 if ($this->object->getAnonymize() && !$this->object->isAccessibleWithoutCode())
00147                 {
00148                         if ($this->object->checkSurveyCode($_POST["anonymous_id"]))
00149                         {
00150                                 $_SESSION["anonymous_id"] = $_POST["anonymous_id"];
00151                         }
00152                         else
00153                         {
00154                                 ilUtil::sendInfo(sprintf($this->lng->txt("error_retrieving_anonymous_survey"), $_POST["anonymous_id"]), true);
00155                                 $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
00156                         }
00157                 }
00158                 if ($this->object->isAccessibleWithoutCode())
00159                 {
00160                         $anonymous_id = $this->object->getUserSurveyCode($ilUser->getId());
00161                         if (strlen($anonymous_id))
00162                         {
00163                                 $_SESSION["anonymous_id"] = $anonymous_id;
00164                         }
00165                         else
00166                         {
00167                                 $_SESSION["anonymous_id"] = $this->object->createNewAccessCode();
00168                         }
00169                 }
00170                 
00171                 $activepage = "";
00172                 if ($resume)
00173                 {
00174                         $activepage = $this->object->getLastActivePage($_SESSION["finished_id"]);
00175                         $direction = 0;
00176                 }
00177                 // explicitly set the survey started!
00178                 if ($this->object->isSurveyStarted($ilUser->getId(), $_SESSION["anonymous_id"]) === FALSE)
00179                 {
00180                         $_SESSION["finished_id"] = $this->object->startSurvey($ilUser->getId(), $_SESSION["anonymous_id"]);
00181                 }
00182                 $this->outSurveyPage($activepage, $direction);
00183         }
00184 
00192         function previous()
00193         {
00194                 $this->navigate("previous");
00195         }
00196         
00204         function next()
00205         {
00206                 $this->navigate("next");
00207         }
00208         
00216         function outSurveyPage($activepage, $direction)
00217         {
00218                 global $ilUser;
00219                 
00220                 // security check if someone tries to go into a survey using an URL to one of the questions
00221                 $canStart = $this->object->canStartSurvey($_SESSION["anonymous_id"]);
00222                 if (!$canStart["result"])
00223                 {
00224                         ilUtil::sendInfo(implode("<br />", $canStart["messages"]), TRUE);
00225                         $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
00226                 }
00227                 $survey_started = $this->object->isSurveyStarted($ilUser->getId(), $_SESSION["anonymous_id"]);
00228                 if ($survey_started === FALSE)
00229                 {
00230                         ilUtil::sendInfo($this->lng->txt("survey_use_start_button"), TRUE);
00231                         $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
00232                 }
00233 
00234                 $page = $this->object->getNextPage($activepage, $direction);
00235                 $constraint_true = 0;
00236 
00237                 // check for constraints
00238                 if (count($page[0]["constraints"]))
00239                 {
00240                         while (is_array($page) and ($constraint_true == 0) and (count($page[0]["constraints"])))
00241                         {
00242                                 $constraint_true = 1;
00243                                 foreach ($page[0]["constraints"] as $constraint)
00244                                 {
00245                                         $working_data = $this->object->loadWorkingData($constraint["question"], $_SESSION["finished_id"]);
00246                                         $constraint_true = $constraint_true & $this->object->checkConstraint($constraint, $working_data);
00247                                 }
00248                                 if ($constraint_true == 0)
00249                                 {
00250                                         $page = $this->object->getNextPage($page[0]["question_id"], $direction);
00251                                 }
00252                         }
00253                 }
00254 
00255                 $qid = "";
00256                 if ($page === 0)
00257                 {
00258                         $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
00259                 }
00260                 else if ($page === 1)
00261                 {
00262                         $this->object->finishSurvey($ilUser->id, $_SESSION["anonymous_id"]);
00263                         if (array_key_exists("anonymous_id", $_SESSION)) unset($_SESSION["anonymous_id"]);
00264                         $this->runShowFinishedPage();
00265                         return;
00266                 }
00267                 else
00268                 {
00269                         $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_content.html", "Modules/Survey");
00270 
00271                         if (!($this->object->getAnonymize() && $this->object->isAccessibleWithoutCode() && ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)))
00272                         {
00273                                 $this->tpl->setCurrentBlock("suspend_survey");
00274                                 $this->tpl->setVariable("TEXT_SUSPEND", $this->lng->txt("cancel_survey"));
00275                                 $this->tpl->setVariable("HREF_SUSPEND", $this->ctrl->getLinkTargetByClass("ilObjSurveyGUI", "infoScreen"));
00276                                 $this->tpl->setVariable("HREF_IMG_SUSPEND", $this->ctrl->getLinkTargetByClass("ilObjSurveyGUI", "infoScreen"));
00277                                 $this->tpl->setVariable("ALT_IMG_SUSPEND", $this->lng->txt("cancel_survey"));
00278                                 $this->tpl->setVariable("TITLE_IMG_SUSPEND", $this->lng->txt("cancel_survey"));
00279                                 $this->tpl->setVariable("IMG_SUSPEND", ilUtil::getImagePath("cancel.gif"));
00280                                 $this->tpl->parseCurrentBlock();
00281                         }
00282                         $this->outNavigationButtons("top", $page);
00283                         $this->tpl->setCurrentBlock("percentage");
00284                         $percentage = (int)(($page[0]["position"])*100);
00285                         $this->tpl->setVariable("PERCENT_BAR_START", ilUtil::getImagePath("bar_start.gif"));
00286                         $this->tpl->setVariable("PERCENT_BAR_FILLED", ilUtil::getImagePath("bar_filled.gif"));
00287                         $this->tpl->setVariable("PERCENT_BAR_EMPTY", ilUtil::getImagePath("bar_empty.gif"));
00288                         $this->tpl->setVariable("PERCENT_BAR_END", ilUtil::getImagePath("bar_end.gif"));
00289                         $this->tpl->setVariable("PERCENTAGE_ALT", $this->lng->txt("percentage"));
00290                         $this->tpl->setVariable("PERCENTAGE_VALUE", $percentage);
00291                         $this->tpl->setVariable("PERCENTAGE_UNFINISHED", 100-$percentage);
00292                         $this->tpl->parseCurrentBlock();
00293                         if (count($page) > 1)
00294                         {
00295                                 $this->tpl->setCurrentBlock("questionblock_title");
00296                                 $this->tpl->setVariable("TEXT_QUESTIONBLOCK_TITLE", $page[0]["questionblock_title"]);
00297                                 $this->tpl->parseCurrentBlock();
00298                         }
00299                         foreach ($page as $data)
00300                         {
00301                                 $this->tpl->setCurrentBlock("survey_content");
00302                                 if ($data["heading"])
00303                                 {
00304                                         $this->tpl->setVariable("QUESTION_HEADING", $data["heading"]);
00305                                 }
00306                                 $question_gui = $this->object->getQuestionGUI($data["type_tag"], $data["question_id"]);
00307                                 if (is_array($_SESSION["svy_errors"]))
00308                                 {
00309                                         $working_data =& $question_gui->object->getWorkingDataFromUserInput($_POST);
00310                                 }
00311                                 else
00312                                 {
00313                                         $working_data = $this->object->loadWorkingData($data["question_id"], $_SESSION["finished_id"]);
00314                                 }
00315                                 $question_gui->object->setObligatory($data["obligatory"]);
00316                                 $error_messages = array();
00317                                 if (is_array($_SESSION["svy_errors"]))
00318                                 {
00319                                         $error_messages = $_SESSION["svy_errors"];
00320                                 }
00321                                 $show_questiontext = ($data["questionblock_show_questiontext"]) ? 1 : 0;
00322                                 $question_output = $question_gui->getWorkingForm($working_data, $this->object->getShowQuestionTitles(), $show_questiontext, $error_messages[$data["question_id"]]);
00323                                 $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
00324                                 $qid = "&qid=" . $data["question_id"];
00325                                 $this->tpl->parse("survey_content");
00326                         }
00327                         $this->outNavigationButtons("bottom", $page);
00328                         $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this) . $qid);
00329                 }
00330         }
00331         
00339         function navigate($navigationDirection = "next") 
00340         {
00341                 global $ilUser;
00342                 global $rbacsystem;
00343 
00344                 if (!$rbacsystem->checkAccess("read", $this->object->ref_id)) 
00345                 {
00346                         // only with read access it is possible to run the test
00347                         $this->ilias->raiseError($this->lng->txt("cannot_read_survey"),$this->ilias->error_obj->MESSAGE);
00348                 }
00349 
00350                 // check users input when it is a metric question
00351                 unset($_SESSION["svy_errors"]);
00352                 $page_error = 0;
00353                 $page = $this->object->getNextPage($_GET["qid"], 0);
00354                 foreach ($page as $data)
00355                 {
00356                         $page_error += $this->saveActiveQuestionData($data);
00357                 }
00358                 if ($page_error && (strcmp($navigationDirection, "previous") != 0))
00359                 {
00360                         if ($page_error == 1)
00361                         {
00362                                 ilUtil::sendInfo($this->lng->txt("svy_page_error"));
00363                         }
00364                         else
00365                         {
00366                                 ilUtil::sendInfo($this->lng->txt("svy_page_errors"));
00367                         }
00368                 }
00369                 else
00370                 {
00371                         $page_error = "";
00372                         unset($_SESSION["svy_errors"]);
00373                 }
00374 
00375                 $direction = 0;
00376                 switch ($navigationDirection)
00377                 {
00378                         case "next":
00379                         default:
00380                                 $activepage = $_GET["qid"];
00381                                 if (!$page_error)
00382                                 {
00383                                         $direction = 1;
00384                                 }
00385                                 break;
00386                         case "previous":
00387                                 $activepage = $_GET["qid"];
00388                                 if (!$page_error)
00389                                 {
00390                                         $direction = -1;
00391                                 }
00392                                 break;
00393                 }
00394                 $this->outSurveyPage($activepage, $direction);
00395         }
00396 
00404         function saveActiveQuestionData(&$data)
00405         {
00406                 global $ilUser;
00407                 
00408                 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
00409                 $question =& SurveyQuestion::_instanciateQuestion($data["question_id"]);
00410                 $error = $question->checkUserInput($_POST, $this->object->getSurveyId());
00411                 if (strlen($error) == 0)
00412                 {
00413                         $user_id = $ilUser->getId();
00414                         // delete old answers
00415                         $this->object->deleteWorkingData($data["question_id"], $_SESSION["finished_id"]);
00416 
00417                         if ($this->object->isSurveyStarted($user_id, $_SESSION["anonymous_id"]) === false)
00418                         {
00419                                 $_SESSION["finished_id"] = $this->object->startSurvey($user_id, $_SESSION["anonymous_id"]);
00420                         }
00421                         if ($this->object->getAnonymize())
00422                         {
00423                                 $user_id = 0;
00424                         }
00425                         $question->saveUserInput($_POST, $_SESSION["finished_id"]);
00426                         return 0;
00427                 }
00428                 else
00429                 {
00430                         $_SESSION["svy_errors"][$question->getId()] = $error;
00431                         return 1;
00432                 }
00433         }
00434         
00442         function cancel()
00443         {
00444                 $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
00445         }
00446         
00454         function runShowFinishedPage()
00455         {
00456                 unset($_SESSION["anonymous_id"]);
00457                 if (strlen($this->object->getOutro()) == 0)
00458                 {
00459                         $this->ctrl->redirectByClass("ilobjsurveygui", "backToRepository");
00460                 }
00461                 else
00462                 {
00463                         $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_finished.html", "Modules/Survey");
00464                         $this->tpl->setVariable("TEXT_FINISHED", $this->object->prepareTextareaOutput($this->object->getOutro()));
00465                         $this->tpl->setVariable("BTN_EXIT", $this->lng->txt("exit"));
00466                         $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00467                         $this->tpl->parseCurrentBlock();
00468                 }
00469         }
00470 
00478         function exitSurvey()
00479         {
00480                 $this->ctrl->redirectByClass("ilobjsurveygui", "backToRepository");
00481         }
00482         
00492         function outNavigationButtons($navigationblock = "top", $page)
00493         {
00494                 $prevpage = $this->object->getNextPage($page[0]["question_id"], -1);
00495                 $this->tpl->setCurrentBlock($navigationblock . "_prev");
00496                 if ($prevpage === 0)
00497                 {
00498                         $this->tpl->setVariable("BTN_PREV", $this->lng->txt("survey_start"));
00499                 }
00500                 else
00501                 {
00502                         $this->tpl->setVariable("BTN_PREV", $this->lng->txt("survey_previous"));
00503                 }
00504                 $this->tpl->parseCurrentBlock();
00505                 $nextpage = $this->object->getNextPage($page[0]["question_id"], 1);
00506                 $this->tpl->setCurrentBlock($navigationblock . "_next");
00507                 if ($nextpage === 1)
00508                 {
00509                         $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("survey_finish"));
00510                 }
00511                 else
00512                 {
00513                         $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("survey_next"));
00514                 }
00515                 $this->tpl->parseCurrentBlock();
00516         }
00517 }
00518 ?>

Generated on Fri Dec 13 2013 17:56:52 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1