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

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 "./survey/classes/inc.SurveyConstants.php";
00025 
00038 class ilSurveyExecutionGUI
00039 {
00040         var $object;
00041         var $lng;
00042         var $tpl;
00043         var $ctrl;
00044         var $ilias;
00045         var $tree;
00046         
00055   function ilSurveyExecutionGUI($a_object)
00056   {
00057                 global $lng, $tpl, $ilCtrl, $ilias, $tree;
00058 
00059     $this->lng =& $lng;
00060     $this->tpl =& $tpl;
00061                 $this->ctrl =& $ilCtrl;
00062                 $this->ilias =& $ilias;
00063                 $this->object =& $a_object;
00064                 $this->tree =& $tree;
00065         }
00066         
00070         function &executeCommand()
00071         {
00072                 $cmd = $this->ctrl->getCmd();
00073                 $next_class = $this->ctrl->getNextClass($this);
00074 
00075                 $cmd = $this->getCommand($cmd);
00076                 switch($next_class)
00077                 {
00078                         default:
00079                                 $ret =& $this->$cmd();
00080                                 break;
00081                 }
00082                 return $ret;
00083         }
00084 
00092         function getCommand($cmd)
00093         {
00094                 return $cmd;
00095         }
00096 
00104         function resume()
00105         {
00106                 $this->start(true);
00107         }
00108         
00116         function start($resume = false)
00117         {
00118                 global $ilUser;
00119                 global $rbacsystem;
00120 
00121                 unset($_SESSION["svy_errors"]);
00122                 if (!$rbacsystem->checkAccess("read", $this->object->ref_id)) 
00123                 {
00124                         // only with read access it is possible to run the test
00125                         $this->ilias->raiseError($this->lng->txt("cannot_read_survey"),$this->ilias->error_obj->MESSAGE);
00126                 }
00127 
00128                 if ($this->object->getAnonymize() && !$this->object->isAccessibleWithoutCode())
00129                 {
00130                         if ($resume)
00131                         {
00132                                 $anonymize_key = $this->object->getAnonymousId($_POST["anonymous_id"]);
00133                                 if ($anonymize_key)
00134                                 {
00135                                         $_SESSION["anonymous_id"] = $anonymize_key;
00136                                 }
00137                                 else
00138                                 {
00139                                         unset($_POST["cmd"]["resume"]);
00140                                         sendInfo(sprintf($this->lng->txt("error_retrieving_anonymous_survey"), $_POST["anonymous_id"]));
00141                                 }
00142                         }
00143                 }
00144                 
00145                 $direction = 0;
00146 
00147                 if ($this->object->getAnonymize() && !$this->object->isAccessibleWithoutCode())
00148                 {
00149                         if ($this->object->checkSurveyCode($_POST["anonymous_id"]))
00150                         {
00151                                 $_SESSION["anonymous_id"] = $_POST["anonymous_id"];
00152                         }
00153                         else
00154                         {
00155                                 sendInfo(sprintf($this->lng->txt("error_retrieving_anonymous_survey"), $_POST["anonymous_id"]), true);
00156                                 $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
00157                         }
00158                 }
00159                 if ($this->object->isAccessibleWithoutCode())
00160                 {
00161                         $anonymous_id = $this->object->getUserSurveyCode($ilUser->getId());
00162                         if (strlen($anonymous_id))
00163                         {
00164                                 $_SESSION["anonymous_id"] = $anonymous_id;
00165                         }
00166                         else
00167                         {
00168                                 $_SESSION["anonymous_id"] = $this->object->createNewAccessCode();
00169                         }
00170                 }
00171                 
00172                 $activepage = "";
00173                 if ($resume)
00174                 {
00175                         $activepage = $this->object->getLastActivePage($ilUser->id);
00176                         $direction = 0;
00177                 }
00178                 // explicitly set the survey started!
00179                 if ($this->object->isSurveyStarted($ilUser->getId(), $_SESSION["anonymous_id"]) === FALSE)
00180                 {
00181                         $this->object->startSurvey($ilUser->getId(), $_SESSION["anonymous_id"]);
00182                 }
00183                 $this->outSurveyPage($activepage, $direction);
00184         }
00185 
00193         function previous()
00194         {
00195                 $this->navigate("previous");
00196         }
00197         
00205         function next()
00206         {
00207                 $this->navigate("next");
00208         }
00209         
00217         function outSurveyPage($activepage, $direction)
00218         {
00219                 global $ilUser;
00220 
00221                 // security check if someone tries to go into a survey using an URL to one of the questions
00222                 $canStart = $this->object->canStartSurvey($_SESSION["anonymous_id"]);
00223                 if (!$canStart["result"])
00224                 {
00225                         sendInfo(implode("<br />", $canStart["messages"]), TRUE);
00226                         $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
00227                 }
00228                 $survey_started = $this->object->isSurveyStarted($ilUser->getId(), $_SESSION["anonymous_id"]);
00229                 if ($survey_started === FALSE)
00230                 {
00231                         sendInfo($this->lng->txt("survey_use_start_button"), TRUE);
00232                         $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
00233                 }
00234                 
00235                 $page = $this->object->getNextPage($activepage, $direction);
00236                 $constraint_true = 0;
00237 
00238                 // check for constraints
00239                 if (count($page[0]["constraints"]))
00240                 {
00241                         while (is_array($page) and ($constraint_true == 0) and (count($page[0]["constraints"])))
00242                         {
00243                                 $constraint_true = 1;
00244                                 foreach ($page[0]["constraints"] as $constraint)
00245                                 {
00246                                         $working_data = $this->object->loadWorkingData($constraint["question"], $ilUser->id);
00247                                         $constraint_true = $constraint_true & $this->object->checkConstraint($constraint, $working_data);
00248                                 }
00249                                 if ($constraint_true == 0)
00250                                 {
00251                                         $page = $this->object->getNextPage($page[0]["question_id"], $direction);
00252                                 }
00253                         }
00254                 }
00255 
00256                 $qid = "";
00257                 if ($page === 0)
00258                 {
00259                         $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
00260                 }
00261                 else if ($page === 1)
00262                 {
00263                         $this->object->finishSurvey($ilUser->id, $_SESSION["anonymous_id"]);
00264                         if (array_key_exists("anonymous_id", $_SESSION)) unset($_SESSION["anonymous_id"]);
00265                         if (array_key_exists("accesscode", $_SESSION)) unset($_SESSION["accesscode"]);
00266                         $this->runShowFinishedPage();
00267                         return;
00268                 }
00269                 else
00270                 {
00271                         $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_content.html", true);
00272 
00273                         if (!($this->object->getAnonymize() && $this->object->isAccessibleWithoutCode() && ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)))
00274                         {
00275                                 $this->tpl->setCurrentBlock("suspend_survey");
00276                                 $this->tpl->setVariable("TEXT_SUSPEND", $this->lng->txt("cancel_survey"));
00277                                 $this->tpl->setVariable("HREF_SUSPEND", $this->ctrl->getLinkTargetByClass("ilObjSurveyGUI", "infoScreen"));
00278                                 $this->tpl->setVariable("HREF_IMG_SUSPEND", $this->ctrl->getLinkTargetByClass("ilObjSurveyGUI", "infoScreen"));
00279                                 $this->tpl->setVariable("ALT_IMG_SUSPEND", $this->lng->txt("cancel_survey"));
00280                                 $this->tpl->setVariable("TITLE_IMG_SUSPEND", $this->lng->txt("cancel_survey"));
00281                                 $this->tpl->setVariable("IMG_SUSPEND", ilUtil::getImagePath("cancel.gif"));
00282                                 $this->tpl->parseCurrentBlock();
00283                         }
00284                         $this->outNavigationButtons("top", $page);
00285                         $this->tpl->addBlockFile("NOMINAL_QUESTION", "nominal_question", "tpl.il_svy_out_nominal.html", true);
00286                         $this->tpl->addBlockFile("ORDINAL_QUESTION", "ordinal_question", "tpl.il_svy_out_ordinal.html", true);
00287                         $this->tpl->addBlockFile("METRIC_QUESTION", "metric_question", "tpl.il_svy_out_metric.html", true);
00288                         $this->tpl->addBlockFile("TEXT_QUESTION", "text_question", "tpl.il_svy_out_text.html", true);
00289                         $this->tpl->setCurrentBlock("percentage");
00290                         $percentage = (int)(($page[0]["position"])*100);
00291                         $this->tpl->setVariable("PERCENT_BAR_START", ilUtil::getImagePath("bar_start.gif"));
00292                         $this->tpl->setVariable("PERCENT_BAR_FILLED", ilUtil::getImagePath("bar_filled.gif"));
00293                         $this->tpl->setVariable("PERCENT_BAR_EMPTY", ilUtil::getImagePath("bar_empty.gif"));
00294                         $this->tpl->setVariable("PERCENT_BAR_END", ilUtil::getImagePath("bar_end.gif"));
00295                         $this->tpl->setVariable("PERCENTAGE_ALT", $this->lng->txt("percentage"));
00296                         $this->tpl->setVariable("PERCENTAGE_VALUE", $percentage);
00297                         $this->tpl->setVariable("PERCENTAGE_UNFINISHED", 100-$percentage);
00298                         $this->tpl->parseCurrentBlock();
00299                         if (count($page) > 1)
00300                         {
00301                                 $this->tpl->setCurrentBlock("questionblock_title");
00302                                 $this->tpl->setVariable("TEXT_QUESTIONBLOCK_TITLE", $page[0]["questionblock_title"]);
00303                                 $this->tpl->parseCurrentBlock();
00304                         }
00305                         foreach ($page as $data)
00306                         {
00307                                 $this->tpl->setCurrentBlock("survey_content");
00308                                 if ($data["heading"])
00309                                 {
00310                                         $this->tpl->setVariable("QUESTION_HEADING", $data["heading"]);
00311                                 }
00312                                 $question_gui = $this->object->getQuestionGUI($data["type_tag"], $data["question_id"]);
00313                                 $working_data = $this->object->loadWorkingData($data["question_id"], $ilUser->id);
00314                                 $question_gui->object->setObligatory($data["obligatory"]);
00315                                 $error_messages = array();
00316                                 if (is_array($_SESSION["svy_errors"]))
00317                                 {
00318                                         $error_messages = $_SESSION["svy_errors"];
00319                                 }
00320                                 $question_gui->outWorkingForm($working_data, $this->object->getShowQuestionTitles(), $error_messages[$data["question_id"]]);
00321                                 $qid = "&qid=" . $data["question_id"];
00322                                 $this->tpl->parse("survey_content");
00323                         }
00324                         $this->outNavigationButtons("bottom", $page);
00325                         $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this) . $qid);
00326                 }
00327         }
00328         
00336         function navigate($navigationDirection = "next") 
00337         {
00338                 global $ilUser;
00339                 global $rbacsystem;
00340 
00341                 if (!$rbacsystem->checkAccess("read", $this->object->ref_id)) 
00342                 {
00343                         // only with read access it is possible to run the test
00344                         $this->ilias->raiseError($this->lng->txt("cannot_read_survey"),$this->ilias->error_obj->MESSAGE);
00345                 }
00346 
00347                 // check users input when it is a metric question
00348                 unset($_SESSION["svy_errors"]);
00349                 $page_error = 0;
00350                 $page = $this->object->getNextPage($_GET["qid"], 0);
00351                 foreach ($page as $data)
00352                 {
00353                         $page_error += $this->saveActiveQuestionData($data);
00354                 }
00355                 if ($page_error && (strcmp($navigationDirection, "previous") != 0))
00356                 {
00357                         if ($page_error == 1)
00358                         {
00359                                 sendInfo($this->lng->txt("svy_page_error"));
00360                         }
00361                         else
00362                         {
00363                                 sendInfo($this->lng->txt("svy_page_errors"));
00364                         }
00365                 }
00366                 else
00367                 {
00368                         $page_error = "";
00369                 }
00370 
00371                 $direction = 0;
00372                 switch ($navigationDirection)
00373                 {
00374                         case "next":
00375                         default:
00376                                 $activepage = $_GET["qid"];
00377                                 if (!$page_error)
00378                                 {
00379                                         $direction = 1;
00380                                 }
00381                                 break;
00382                         case "previous":
00383                                 $activepage = $_GET["qid"];
00384                                 if (!$page_error)
00385                                 {
00386                                         $direction = -1;
00387                                 }
00388                                 break;
00389                 }
00390                 $this->outSurveyPage($activepage, $direction);
00391         }
00392 
00400         function saveActiveQuestionData(&$data)
00401         {
00402                 global $ilUser;
00403                 
00404                 include_once "./survey/classes/class.SurveyQuestion.php";
00405                 $question =& SurveyQuestion::_instanciateQuestion($data["question_id"]);
00406                 $error = $question->checkUserInput($_POST);
00407                 if (strlen($error) == 0)
00408                 {
00409                         $user_id = $ilUser->getId();
00410                         // delete old answers
00411                         $this->object->deleteWorkingData($data["question_id"], $user_id);
00412 
00413                         if ($this->object->isSurveyStarted($user_id, $_SESSION["anonymous_id"]) === FALSE)
00414                         {
00415                                 $this->object->startSurvey($user_id, $_SESSION["anonymous_id"]);
00416                         }
00417                         if ($this->object->getAnonymize())
00418                         {
00419                                 $user_id = 0;
00420                         }
00421                         $question->saveUserInput($_POST, $this->object->getSurveyId(), $user_id, $_SESSION["anonymous_id"]);
00422                         return 0;
00423                 }
00424                 else
00425                 {
00426                         $_SESSION["svy_errors"][$question->getId()] = $error;
00427                         return 1;
00428                 }
00429         }
00430         
00438         function cancel()
00439         {
00440                 $this->ctrl->redirectByClass("ilobjsurveygui", "infoScreen");
00441         }
00442         
00450         function runShowFinishedPage()
00451         {
00452                 unset($_SESSION["anonymous_id"]);
00453                 if (strlen($this->object->getOutro()) == 0)
00454                 {
00455                         $this->ctrl->redirectByClass("ilobjsurveygui", "backToRepository");
00456                 }
00457                 else
00458                 {
00459                         $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_finished.html", true);
00460                         $this->tpl->setVariable("TEXT_FINISHED", $this->object->prepareTextareaOutput($this->object->getOutro()));
00461                         $this->tpl->setVariable("BTN_EXIT", $this->lng->txt("exit"));
00462                         $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00463                         $this->tpl->parseCurrentBlock();
00464                 }
00465         }
00466 
00474         function exitSurvey()
00475         {
00476                 $this->ctrl->redirectByClass("ilobjsurveygui", "backToRepository");
00477         }
00478         
00488         function outNavigationButtons($navigationblock = "top", $page)
00489         {
00490                 $prevpage = $this->object->getNextPage($page[0]["question_id"], -1);
00491                 $this->tpl->setCurrentBlock($navigationblock . "_prev");
00492                 if ($prevpage === 0)
00493                 {
00494                         $this->tpl->setVariable("BTN_PREV", $this->lng->txt("survey_start"));
00495                 }
00496                 else
00497                 {
00498                         $this->tpl->setVariable("BTN_PREV", $this->lng->txt("survey_previous"));
00499                 }
00500                 $this->tpl->parseCurrentBlock();
00501                 $nextpage = $this->object->getNextPage($page[0]["question_id"], 1);
00502                 $this->tpl->setCurrentBlock($navigationblock . "_next");
00503                 if ($nextpage === 1)
00504                 {
00505                         $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("survey_finish"));
00506                 }
00507                 else
00508                 {
00509                         $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("survey_next"));
00510                 }
00511                 $this->tpl->parseCurrentBlock();
00512         }
00513         
00514 }
00515 ?>

Generated on Fri Dec 13 2013 13:52:15 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1