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

survey/classes/class.ilObjSurveyGUI.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 
00036 require_once "./classes/class.ilObjectGUI.php";
00037 require_once "./classes/class.ilMetaDataGUI.php";
00038 require_once "./classes/class.ilUtil.php";
00039 require_once "./classes/class.ilSearch.php";
00040 require_once "./classes/class.ilObjUser.php";
00041 require_once "./classes/class.ilObjGroup.php";
00042 require_once "./survey/classes/class.SurveySearch.php";
00043 
00044 define ("TYPE_XLS", "latin1");
00045 define ("TYPE_XLS_MAC", "macos");
00046 define ("TYPE_SPSS", "csv");
00047 define ("TYPE_PRINT", "prnt");
00048 
00049 
00050 class ilObjSurveyGUI extends ilObjectGUI
00051 {
00056         function ilObjSurveyGUI($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
00057         {
00058     global $lng, $ilCtrl;
00059                 $this->type = "svy";
00060                 $lng->loadLanguageModule("survey");
00061                 $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference, false);
00062                 if (!defined("ILIAS_MODULE"))
00063                 {
00064                         $this->setTabTargetScript("adm_object.php");
00065                 }
00066                 else
00067                 {
00068                         $this->setTabTargetScript("survey.php");
00069                 }
00070                 if ($a_prepare_output) {
00071                         $this->prepareOutput();
00072                 }
00073 
00074                 $this->ctrl =& $ilCtrl;
00075                 $this->ctrl->saveParameter($this, "ref_id");
00076         }
00077 
00083         function getCallingScript()
00084         {
00085                 return "survey.php";
00086         }
00087         
00091         function &executeCommand()
00092         {
00093                 $cmd = $this->ctrl->getCmd("properties");
00094                 $next_class = $this->ctrl->getNextClass($this);
00095                 $this->ctrl->setReturn($this, "properties");
00096 
00097                 //echo "<br>nextclass:$next_class:cmd:$cmd:qtype=$q_type";
00098                 switch($next_class)
00099                 {
00100                         default:
00101                                 if (($cmd != "run") and ($cmd != "evaluation") and ($cmd != "evaluationdetails") and ($cmd != "evaluationuser"))
00102                                 {
00103                                         $this->setAdminTabs();
00104                                 }
00105                                 $cmd.= "Object";
00106                                 $ret =& $this->$cmd();
00107                                 break;
00108                 }
00109         }
00110 
00115         function saveObject()
00116         {
00117                 global $rbacadmin;
00118 
00119                 // create and insert forum in objecttree
00120                 $newObj = parent::saveObject();
00121                 // always send a message
00122                 sendInfo($this->lng->txt("object_added"),true);
00123                 
00124                 ilUtil::redirect($this->getReturnLocation("save",$this->ctrl->getTargetScript()."?".$this->link_params));
00125                 exit();
00126         }
00127 
00128         function updateObject() {
00129                 $this->object->updateTitleAndDescription();
00130                 $this->update = $this->object->update();
00131                 $this->object->saveToDb();
00132                 if (strcmp($_SESSION["info"], "") != 0)
00133                 {
00134                         sendInfo($_SESSION["info"] . "<br />" . $this->lng->txt("msg_obj_modified"), true);
00135                 }
00136                 else
00137                 {
00138                         sendInfo($this->lng->txt("msg_obj_modified"), true);
00139                 }
00140                 ilUtil::redirect($this->getReturnLocation("update",$this->ctrl->getTargetScript()."?".$this->link_params));
00141         }
00142         
00150   function getAddParameter()
00151   {
00152     return "?ref_id=" . $_GET["ref_id"] . "&cmd=" . $_GET["cmd"];
00153   }
00154 
00155         function writePropertiesFormData()
00156         {
00157                 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00158                 $this->object->setDescription(ilUtil::stripSlashes($_POST["description"]));
00159                 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00160                 $result = $this->object->setStatus($_POST["status"]);
00161                 if ($result)
00162                 {
00163                         sendInfo($result, true);
00164                 }
00165                 $this->object->setEvaluationAccess($_POST["evaluation_access"]);
00166                 $this->object->setStartDate(sprintf("%04d-%02d-%02d", $_POST["start_date"]["y"], $_POST["start_date"]["m"], $_POST["start_date"]["d"]));
00167                 $this->object->setStartDateEnabled($_POST["checked_start_date"]);
00168                 $this->object->setEndDate(sprintf("%04d-%02d-%02d", $_POST["end_date"]["y"], $_POST["end_date"]["m"], $_POST["end_date"]["d"]));
00169                 $this->object->setEndDateEnabled($_POST["checked_end_date"]);
00170                 $this->object->setIntroduction(ilUtil::stripSlashes($_POST["introduction"]));
00171                 $this->object->setAnonymize($_POST["anonymize"]);
00172                 if ($_POST["showQuestionTitles"])
00173                 {
00174                         $this->object->showQuestionTitles();
00175                 }
00176                 else
00177                 {
00178                         $this->object->hideQuestionTitles();
00179                 }
00180         }
00181 
00189         function runObject() {
00190                 global $ilUser;
00191                 global $rbacsystem;
00192 
00193                 if (!$rbacsystem->checkAccess("read", $this->ref_id)) 
00194                 {
00195                         // only with read access it is possible to run the test
00196                         $this->ilias->raiseError($this->lng->txt("cannot_read_survey"),$this->ilias->error_obj->MESSAGE);
00197                 }
00198 
00199                 if ($_POST["cmd"]["exit"])
00200                 {
00201                         $path = $this->tree->getPathFull($this->object->getRefID());
00202                         ilUtil::redirect($this->getReturnLocation("cancel",ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH)."/repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
00203                         exit();
00204                 }
00205 
00206     $add_parameter = $this->getAddParameter();
00207                 $this->tpl->addBlockFile("CONTENT", "content", "tpl.il_svy_svy_content.html", true);
00208                 $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
00209                 $title = $this->object->getTitle();
00210 
00211                 // catch feedback message
00212                 sendInfo();
00213 
00214                 $this->setLocator();
00215 
00216                 if (!empty($title))
00217                 {
00218                         $this->tpl->setVariable("HEADER", $title);
00219                 }
00220 
00221                 if ($this->object->getAnonymize())
00222                 {
00223                         if ($_POST["cmd"]["resume"])
00224                         {
00225                                 $anonymize_key = $this->object->getAnonymousId($_POST["anonymous_id"]);
00226                                 if ($anonymize_key)
00227                                 {
00228                                         $_SESSION["anonymous_id"] = $anonymize_key;
00229                                 }
00230                                 else
00231                                 {
00232                                         unset($_POST["cmd"]["resume"]);
00233                                         sendInfo(sprintf($this->lng->txt("error_retrieving_anonymous_survey"), $_POST["anonymous_id"]));
00234                                 }
00235                         }
00236                 }
00237                 $direction = 0;
00238                 $page_error = 0;
00239                 $error_messages = array();
00240                 if ($_POST["cmd"]["start"] or $_POST["cmd"]["previous"] or $_POST["cmd"]["next"] or $_POST["cmd"]["resume"])
00241                 {
00242                         if (($_POST["cmd"]["start"]) || ($_POST["cmd"]["resume"]))
00243                         {
00244                                 if ($this->object->getAnonymize())
00245                                 {
00246                                         if ($this->object->checkSurveyCode($_POST["anonymous_id"]))
00247                                         {
00248                                                 $_SESSION["anonymous_id"] = $_POST["anonymous_id"];
00249                                         }
00250                                         else
00251                                         {
00252                                                 sendInfo(sprintf($this->lng->txt("error_retrieving_anonymous_survey"), $_POST["anonymous_id"]), true);
00253                                                 $this->ctrl->redirect($this, "run");
00254                                         }
00255                                 }
00256                         }
00257                         $activepage = "";
00258                         $direction = 0;
00259                         if ($_POST["cmd"]["resume"])
00260                         {
00261                                 $activepage = $this->object->getLastActivePage($ilUser->id);
00262                                 $direction = 0;
00263                         }
00264                         if ($_POST["cmd"]["previous"] or $_POST["cmd"]["next"])
00265                         {
00266                                 // check users input when it is a metric question
00267                                 $page = $this->object->getNextPage($_GET["qid"], 0);
00268                                 foreach ($page as $data)
00269                                 {
00270                                         $save_answer = 0;
00271                                         $error = 0;
00272                                         if (strcmp($data["type_tag"], "qt_metric") == 0)
00273                                         {
00274                                                 // there is a metric question -> check input
00275                                                 $variables =& $this->object->getVariables($data["question_id"]);
00276                                                 $entered_value = $_POST[$data["question_id"] . "_metric_question"];
00277                                                 // replace german notation with international notation
00278                                                 $entered_value = str_replace(",", ".", $entered_value);
00279                                                 $_POST[$data["question_id"] . "_metric_question"] = $entered_value;
00280                                                 if (((($entered_value < $variables[0]->value1) or (($entered_value > $variables[0]->value2) and ($variables[0]->value2 > 0)))) && $data["obligatory"])
00281                                                 {
00282                                                         // there is an error: value is not in bounds
00283                                                         $error_messages[$data["question_id"]] = $this->lng->txt("metric_question_out_of_bounds");
00284                                                         $error = 1;
00285                                                 }
00286                                                 if (!is_numeric($entered_value) && ($data["obligatory"]))
00287                                                 {
00288                                                         $error_messages[$data["question_id"]] = $this->lng->txt("metric_question_not_a_value");
00289                                                         $error = 1;
00290                                                 }
00291                                                 if ((strcmp($entered_value, "") == 0) && ($data["obligatory"]))
00292                                                 {
00293                                                         // there is an error: value is not in bounds
00294                                                         $error_messages[$data["question_id"]] = $this->lng->txt("metric_question_out_of_bounds");
00295                                                         $error = 1;
00296                                                 }
00297                                                 if (($data["subtype"] == SUBTYPE_RATIO_ABSOLUTE) && (intval($entered_value) != doubleval($entered_value)) && ($data["obligatory"]))
00298                                                 {
00299                                                         $error_messages[$data["question_id"]] = $this->lng->txt("metric_question_floating_point");
00300                                                         $error = 1;
00301                                                 }
00302                                                 if (($error == 0) && (strcmp($entered_value, "") != 0))
00303                                                 {
00304                                                         $save_answer = 1;
00305                                                 }
00306                                         }
00307                                         if (strcmp($data["type_tag"], "qt_nominal") == 0)
00308                                         {
00309                                                 $variables =& $this->object->getVariables($data["question_id"]);
00310                                                 $save_answer = 1;
00311                                                 $entered_value = $_POST[$data["question_id"] . "_value"];
00312                                                 if ($data["subtype"] == SUBTYPE_MCSR)
00313                                                 {
00314                                                         if ($data["obligatory"])
00315                                                         {
00316                                                                 if (strcmp($entered_value, "") == 0)
00317                                                                 {
00318                                                                         $error_messages[$data["question_id"]] = $this->lng->txt("nominal_question_not_checked");
00319                                                                         $error = 1;
00320                                                                         $save_answer = 0;
00321                                                                 }
00322                                                         }
00323                                                 }
00324                                                 else
00325                                                 {
00326                                                         if ($data["obligatory"])
00327                                                         {
00328                                                                 if (!is_array($entered_value))
00329                                                                 {
00330                                                                         $error_messages[$data["question_id"]] = $this->lng->txt("nominal_question_mr_not_checked");
00331                                                                         $error = 1;
00332                                                                         $save_answer = 0;
00333                                                                 }
00334                                                         }
00335                                                 }
00336                                         }
00337                                         if (strcmp($data["type_tag"], "qt_ordinal") == 0)
00338                                         {
00339                                                 $variables =& $this->object->getVariables($data["question_id"]);
00340                                                 if ((strcmp($_POST[$data["question_id"] . "_value"], "") == 0) && ($data["obligatory"]))
00341                                                 {
00342                                                         // none of the radio buttons was checked
00343                                                         $error_messages[$data["question_id"]] = $this->lng->txt("ordinal_question_not_checked");
00344                                                         $error = 1;
00345                                                 }
00346                                                 if ((strcmp($_POST[$data["question_id"] . "_value"], "") == 0) && !$error)
00347                                                 {
00348                                                         $save_answer = 0;
00349                                                 }
00350                                                 else
00351                                                 {
00352                                                         $save_answer = 1;
00353                                                 }
00354                                         }
00355                                         if (strcmp($data["type_tag"], "qt_text") == 0)
00356                                         {
00357                                                 $variables =& $this->object->getVariables($data["question_id"]);
00358                                                 if ((strcmp($_POST[$data["question_id"] . "_text_question"], "") == 0) && ($data["obligatory"]))
00359                                                 {
00360                                                         // none of the radio buttons was checked
00361                                                         $error_messages[$data["question_id"]] = $this->lng->txt("text_question_not_filled_out");
00362                                                         $error = 1;
00363                                                 }
00364                                                 if ((strcmp($_POST[$data["question_id"] . "_text_question"], "") == 0) && (!$data["obligatory"]))
00365                                                 {
00366                                                         $save_answer = 0;
00367                                                 }
00368                                                 else
00369                                                 {
00370                                                         $save_answer = 1;
00371                                                         $maxchars = SurveyTextQuestion::_getMaxChars($data["question_id"]);
00372                                                         if ($maxchars)
00373                                                         {
00374                                                                 $_POST[$data["question_id"] . "_text_question"] = substr($_POST[$data["question_id"] . "_text_question"], 0, $maxchars);
00375                                                         }
00376                                                 }
00377                                         }
00378                                         $page_error += $error;
00379                                         if ((!$error) && ($save_answer))
00380                                         {
00381                                                 // save user input
00382                                                 $this->object->deleteWorkingData($data["question_id"], $ilUser->id);
00383                                                 switch ($data["type_tag"])
00384                                                 {
00385                                                         case "qt_nominal":
00386                                                                 if ($data["subtype"] == SUBTYPE_MCSR)
00387                                                                 {
00388                                                                         $this->object->saveWorkingData($data["question_id"], $ilUser->id, $_SESSION["anonymous_id"], $_POST[$data["question_id"] . "_value"]);
00389                                                                 }
00390                                                                 else
00391                                                                 {
00392                                                                         if (is_array($_POST[$data["question_id"] . "_value"]))
00393                                                                         {
00394                                                                                 foreach ($_POST[$data["question_id"] . "_value"] as $value)
00395                                                                                 {
00396                                                                                         $this->object->saveWorkingData($data["question_id"], $ilUser->id, $_SESSION["anonymous_id"], $value);
00397                                                                                 }
00398                                                                         }
00399                                                                         else
00400                                                                         {
00401                                                                                 $this->object->saveWorkingData($data["question_id"], $ilUser->id, $_SESSION["anonymous_id"]);
00402                                                                         }
00403                                                                 }
00404                                                                 break;
00405                                                         case "qt_ordinal":
00406                                                                 $this->object->saveWorkingData($data["question_id"], $ilUser->id, $_SESSION["anonymous_id"], $_POST[$data["question_id"] . "_value"]);
00407                                                                 break;
00408                                                         case "qt_metric":
00409                                                                 $this->object->saveWorkingData($data["question_id"], $ilUser->id, $_SESSION["anonymous_id"], $_POST[$data["question_id"] . "_metric_question"]);
00410                                                                 break;
00411                                                         case "qt_text":
00412                                                                 $this->object->saveWorkingData($data["question_id"], $ilUser->id, $_SESSION["anonymous_id"], 0, ilUtil::stripSlashes($_POST[$data["question_id"] . "_text_question"]));
00413                                                                 break;
00414                                                 }
00415                                         }
00416                                 }
00417                         }
00418                         if ($page_error)
00419                         {
00420                                 if ($page_error == 1)
00421                                 {
00422                                         sendInfo($this->lng->txt("svy_page_error"));
00423                                 }
00424                                 else
00425                                 {
00426                                         sendInfo($this->lng->txt("svy_page_errors"));
00427                                 }
00428                         }
00429 
00430                         if ($_POST["cmd"]["previous"])
00431                         {
00432                                 $activepage = $_GET["qid"];
00433                                 if (!$page_error)
00434                                 {
00435                                         $direction = -1;
00436                                 }
00437                         }
00438                         else if ($_POST["cmd"]["next"])
00439                         {
00440                                 $activepage = $_GET["qid"];
00441                                 if (!$page_error)
00442                                 {
00443                                         $direction = 1;
00444                                 }
00445                         }
00446 
00447                         $page = $this->object->getNextPage($activepage, $direction);
00448                         $constraint_true = 0;
00449                         // check for constraints
00450                         if (count($page[0]["constraints"]))
00451                         {
00452                                 while (is_array($page) and ($constraint_true == 0) and (count($page[0]["constraints"])))
00453                                 {
00454                                         $constraint_true = 1;
00455                                         foreach ($page[0]["constraints"] as $constraint)
00456                                         {
00457                                                 $working_data = $this->object->loadWorkingData($constraint["question"], $ilUser->id);
00458                                                 $constraint_true = $constraint_true & $this->object->checkConstraint($constraint, $working_data);
00459                                         }
00460                                         if ($constraint_true == 0)
00461                                         {
00462                                                 $page = $this->object->getNextPage($page[0]["question_id"], $direction);
00463                                         }
00464                                 }
00465                         }
00466 
00467                         $qid = "";
00468                         if ($page === 0)
00469                         {
00470                                 $this->runShowIntroductionPage();
00471                                 return;
00472                         }
00473                         else if ($page === 1)
00474                         {
00475                                 $this->object->finishSurvey($ilUser->id, $_SESSION["anonymous_id"]);
00476                                 $this->runShowFinishedPage();
00477                                 return;
00478                         }
00479                         else
00480                         {
00481                                 $this->outNavigationButtons("top", $page);
00482                                 $this->tpl->addBlockFile("NOMINAL_QUESTION", "nominal_question", "tpl.il_svy_out_nominal.html", true);
00483                                 $this->tpl->addBlockFile("ORDINAL_QUESTION", "ordinal_question", "tpl.il_svy_out_ordinal.html", true);
00484                                 $this->tpl->addBlockFile("METRIC_QUESTION", "metric_question", "tpl.il_svy_out_metric.html", true);
00485                                 $this->tpl->addBlockFile("TEXT_QUESTION", "text_question", "tpl.il_svy_out_text.html", true);
00486                                 $this->tpl->setCurrentBlock("percentage");
00487                                 $this->tpl->setVariable("PERCENTAGE", (int)(($page[0]["position"])*200));
00488                                 $this->tpl->setVariable("PERCENTAGE_VALUE", (int)(($page[0]["position"])*100));
00489                                 $this->tpl->setVariable("HUNDRED_PERCENT", "200");
00490                                 $this->tpl->setVariable("TEXT_COMPLETED", $this->lng->txt("completed") . ": ");
00491                                 $this->tpl->parseCurrentBlock();
00492                                 if (count($page) > 1)
00493                                 {
00494                                         $this->tpl->setCurrentBlock("questionblock_title");
00495                                         $this->tpl->setVariable("TEXT_QUESTIONBLOCK_TITLE", $this->lng->txt("questionblock") . ": " . $page[0]["questionblock_title"]);
00496                                         $this->tpl->parseCurrentBlock();
00497                                 }
00498                                 foreach ($page as $data)
00499                                 {
00500                                         $this->tpl->setCurrentBlock("survey_content");
00501                                         if ($data["heading"])
00502                                         {
00503                                                 $this->tpl->setVariable("QUESTION_HEADING", $data["heading"]);
00504                                         }
00505                                         $question_gui = $this->object->getQuestionGUI($data["type_tag"], $data["question_id"]);
00506                                         $working_data = $this->object->loadWorkingData($data["question_id"], $ilUser->id);
00507                                         $question_gui->object->setObligatory($data["obligatory"]);
00508                                         $question_gui->outWorkingForm($working_data, $this->object->getShowQuestionTitles(), $error_messages[$data["question_id"]]);
00509                                         $qid = "&qid=" . $data["question_id"];
00510                                         $this->tpl->parse("survey_content");
00511                                 }
00512                                 $this->outNavigationButtons("bottom", $page);
00513                         }
00514                         $this->tpl->setCurrentBlock("content");
00515                         $this->tpl->setVariable("FORM_ACTION", $this->getCallingScript() . "$add_parameter$qid");
00516                         $this->tpl->parseCurrentBlock();
00517                 }
00518                 else
00519                 {
00520                         $this->runShowIntroductionPage();
00521                 }
00522         }
00523 
00533         function outNavigationButtons($navigationblock = "top", $page)
00534         {
00535                 $prevpage = $this->object->getNextPage($page[0]["question_id"], -1);
00536                 $this->tpl->setCurrentBlock($navigationblock . "_prev");
00537                 if ($prevpage === 0)
00538                 {
00539                         $this->tpl->setVariable("BTN_PREV", $this->lng->txt("survey_start"));
00540                 }
00541                 else
00542                 {
00543                         $this->tpl->setVariable("BTN_PREV", $this->lng->txt("survey_previous"));
00544                 }
00545                 $this->tpl->parseCurrentBlock();
00546                 $nextpage = $this->object->getNextPage($page[0]["question_id"], 1);
00547                 $this->tpl->setCurrentBlock($navigationblock . "_next");
00548                 if ($nextpage === 1)
00549                 {
00550                         $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("survey_finish"));
00551                 }
00552                 else
00553                 {
00554                         $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("survey_next"));
00555                 }
00556                 $this->tpl->parseCurrentBlock();
00557         }
00558 
00566         function runShowIntroductionPage()
00567         {
00568                 global $ilUser;
00569                 global $rbacsystem;
00570                 if (($this->object->getAnonymize()) && (strcmp($ilUser->login, "anonymous") == 0))
00571                 {
00572                         $survey_started = false;
00573                 }
00574                 else
00575                 {
00576                         $survey_started = $this->object->isSurveyStarted($ilUser->id, $this->object->getUserSurveyCode());
00577                 }
00578                 // show introduction page
00579     $add_parameter = $this->getAddParameter();
00580                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_introduction.html", true);
00581                 if ((strcmp($ilUser->login, "anonymous") == 0) && (!$this->object->getAnonymize()))
00582                 {
00583                         if ($_POST["cmd"]["cancel"]) 
00584                         {
00585                                 $path = $this->tree->getPathFull($this->object->getRefID());
00586                                 ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
00587                                 return;
00588                         }
00589                         $this->tpl->setCurrentBlock("back");
00590                         $this->tpl->setVariable("BTN_BACK", $this->lng->txt("back"));
00591                         $this->tpl->parseCurrentBlock();
00592                         $this->tpl->setCurrentBlock("adm_content");
00593                         $this->tpl->setVariable("TEXT_INTRODUCTION", $this->lng->txt("anonymous_with_personalized_survey"));
00594                         $this->tpl->parseCurrentBlock();
00595                         return;
00596                 }
00597 
00598                 if ($this->object->getAnonymize())
00599                 {
00600                         $this->tpl->setCurrentBlock("start");
00601                         $anonymize_key = $this->object->getUserSurveyCode();
00602                         if (strcmp($ilUser->login, "anonymous") == 0)
00603                         {
00604                                 $this->tpl->setVariable("TEXT_ANONYMIZE", $this->lng->txt("anonymize_anonymous_introduction"));
00605                         }
00606                         else
00607                         if ($survey_started === 0)
00608                         {
00609                                 $this->tpl->setVariable("TEXT_ANONYMIZE", $this->lng->txt("anonymize_resume_introduction"));
00610                         }
00611                         elseif ($survey_started === false)
00612                         {
00613                                 $this->tpl->setVariable("TEXT_ANONYMIZE", sprintf($this->lng->txt("anonymize_key_introduction"), $anonymize_key));
00614                         }
00615                         $this->tpl->setVariable("ENTER_ANONYMOUS_ID", $this->lng->txt("enter_anonymous_id"));
00616                         $this->tpl->setVariable("ANONYMOUS_ID_VALUE", $_GET["accesscode"]);
00617                         $this->tpl->parseCurrentBlock();
00618                 }
00619                 $this->tpl->setCurrentBlock("start");
00620                 $canStart = $this->object->canStartSurvey();
00621                 if ($survey_started === 1)
00622                 {
00623                         sendInfo($this->lng->txt("already_completed_survey"));
00624                         $this->tpl->setCurrentBlock("start");
00625                         $this->tpl->setVariable("BTN_START", $this->lng->txt("start_survey"));
00626                         $this->tpl->setVariable("DISABLED", " disabled=\"disabled\"");
00627                         $this->tpl->parseCurrentBlock();
00628                 }
00629                 if ($survey_started === 0)
00630                 {
00631                         $this->tpl->setCurrentBlock("resume");
00632                         $this->tpl->setVariable("BTN_RESUME", $this->lng->txt("resume_survey"));
00633                         switch ($canStart)
00634                         {
00635                                 case SURVEY_START_START_DATE_NOT_REACHED:
00636                                         sendInfo($this->lng->txt("start_date_not_reached") . " (".ilFormat::formatDate(ilFormat::ftimestamp2dateDB($this->object->getStartYear().$this->object->getStartMonth().$this->object->getStartDay()."000000"), "date") . ")");
00637                                         $this->tpl->setVariable("DISABLED", " disabled=\"disabled\"");
00638                                         break;
00639                                 case SURVEY_START_END_DATE_REACHED:
00640                                         sendInfo($this->lng->txt("end_date_reached") . " (".ilFormat::formatDate(ilFormat::ftimestamp2dateDB($this->object->getEndYear().$this->object->getEndMonth().$this->object->getEndDay()."000000"), "date") . ")");
00641                                         $this->tpl->setVariable("DISABLED", " disabled=\"disabled\"");
00642                                         break;
00643                                 case SURVEY_START_OFFLINE:
00644                                         sendInfo($this->lng->txt("survey_is_offline"));
00645                                         $this->tpl->setVariable("DISABLED", " disabled=\"disabled\"");
00646                                         break;
00647                         }
00648                         $this->tpl->parseCurrentBlock();
00649                 }
00650                 if ($survey_started === false)
00651                 {
00652                         $this->tpl->setCurrentBlock("start");
00653                         $this->tpl->setVariable("BTN_START", $this->lng->txt("start_survey"));
00654                         if (!$rbacsystem->checkAccess('participate', $this->object->getRefId()))
00655                         {
00656                                 sendInfo($this->lng->txt("cannot_participate_survey"));
00657                                 $this->tpl->setVariable("DISABLED", " disabled=\"disabled\"");
00658                         }
00659                         switch ($canStart)
00660                         {
00661                                 case SURVEY_START_START_DATE_NOT_REACHED:
00662                                         sendInfo($this->lng->txt("start_date_not_reached") . " (".ilFormat::formatDate(ilFormat::ftimestamp2dateDB($this->object->getStartYear().$this->object->getStartMonth().$this->object->getStartDay()."000000"), "date") . ")");
00663                                         $this->tpl->setVariable("DISABLED", " disabled=\"disabled\"");
00664                                         break;
00665                                 case SURVEY_START_END_DATE_REACHED:
00666                                         sendInfo($this->lng->txt("end_date_reached") . " (".ilFormat::formatDate(ilFormat::ftimestamp2dateDB($this->object->getEndYear().$this->object->getEndMonth().$this->object->getEndDay()."000000"), "date") . ")");
00667                                         $this->tpl->setVariable("DISABLED", " disabled=\"disabled\"");
00668                                         break;
00669                                 case SURVEY_START_OFFLINE:
00670                                         sendInfo($this->lng->txt("survey_is_offline"));
00671                                         $this->tpl->setVariable("DISABLED", " disabled=\"disabled\"");
00672                                         break;
00673                         }
00674                         $this->tpl->parseCurrentBlock();
00675                 }
00676                 $this->tpl->parseCurrentBlock();
00677                 $this->tpl->setCurrentBlock("adm_content");
00678                 $introduction = $this->object->getIntroduction();
00679                 $introduction = preg_replace("/\n/i", "<br />", $introduction);
00680                 $this->tpl->setVariable("TEXT_INTRODUCTION", $introduction);
00681                 $this->tpl->setVariable("FORM_ACTION", $this->getCallingScript() . "$add_parameter");
00682                 $this->tpl->parseCurrentBlock();
00683         }
00684 
00692         function runShowFinishedPage()
00693         {
00694                 // show introduction page
00695                 unset($_SESSION["anonymous_id"]);
00696     $add_parameter = $this->getAddParameter();
00697                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_finished.html", true);
00698                 $this->tpl->setVariable("TEXT_FINISHED", $this->lng->txt("survey_finished"));
00699                 $this->tpl->setVariable("BTN_EXIT", $this->lng->txt("exit"));
00700                 $this->tpl->setVariable("FORM_ACTION", $this->getCallingScript() . "$add_parameter");
00701                 $this->tpl->parseCurrentBlock();
00702         }
00703 
00711   function propertiesObject()
00712   {
00713                 global $rbacsystem;
00714 
00715                 $this->lng->loadLanguageModule("jscalendar");
00716                 $this->tpl->addBlockFile("CALENDAR_LANG_JAVASCRIPT", "calendar_javascript", "tpl.calendar.html");
00717                 $this->tpl->setCurrentBlock("calendar_javascript");
00718                 $this->tpl->setVariable("FULL_SUNDAY", $this->lng->txt("l_su"));
00719                 $this->tpl->setVariable("FULL_MONDAY", $this->lng->txt("l_mo"));
00720                 $this->tpl->setVariable("FULL_TUESDAY", $this->lng->txt("l_tu"));
00721                 $this->tpl->setVariable("FULL_WEDNESDAY", $this->lng->txt("l_we"));
00722                 $this->tpl->setVariable("FULL_THURSDAY", $this->lng->txt("l_th"));
00723                 $this->tpl->setVariable("FULL_FRIDAY", $this->lng->txt("l_fr"));
00724                 $this->tpl->setVariable("FULL_SATURDAY", $this->lng->txt("l_sa"));
00725                 $this->tpl->setVariable("SHORT_SUNDAY", $this->lng->txt("s_su"));
00726                 $this->tpl->setVariable("SHORT_MONDAY", $this->lng->txt("s_mo"));
00727                 $this->tpl->setVariable("SHORT_TUESDAY", $this->lng->txt("s_tu"));
00728                 $this->tpl->setVariable("SHORT_WEDNESDAY", $this->lng->txt("s_we"));
00729                 $this->tpl->setVariable("SHORT_THURSDAY", $this->lng->txt("s_th"));
00730                 $this->tpl->setVariable("SHORT_FRIDAY", $this->lng->txt("s_fr"));
00731                 $this->tpl->setVariable("SHORT_SATURDAY", $this->lng->txt("s_sa"));
00732                 $this->tpl->setVariable("FULL_JANUARY", $this->lng->txt("l_01"));
00733                 $this->tpl->setVariable("FULL_FEBRUARY", $this->lng->txt("l_02"));
00734                 $this->tpl->setVariable("FULL_MARCH", $this->lng->txt("l_03"));
00735                 $this->tpl->setVariable("FULL_APRIL", $this->lng->txt("l_04"));
00736                 $this->tpl->setVariable("FULL_MAY", $this->lng->txt("l_05"));
00737                 $this->tpl->setVariable("FULL_JUNE", $this->lng->txt("l_06"));
00738                 $this->tpl->setVariable("FULL_JULY", $this->lng->txt("l_07"));
00739                 $this->tpl->setVariable("FULL_AUGUST", $this->lng->txt("l_08"));
00740                 $this->tpl->setVariable("FULL_SEPTEMBER", $this->lng->txt("l_09"));
00741                 $this->tpl->setVariable("FULL_OCTOBER", $this->lng->txt("l_10"));
00742                 $this->tpl->setVariable("FULL_NOVEMBER", $this->lng->txt("l_11"));
00743                 $this->tpl->setVariable("FULL_DECEMBER", $this->lng->txt("l_12"));
00744                 $this->tpl->setVariable("SHORT_JANUARY", $this->lng->txt("s_01"));
00745                 $this->tpl->setVariable("SHORT_FEBRUARY", $this->lng->txt("s_02"));
00746                 $this->tpl->setVariable("SHORT_MARCH", $this->lng->txt("s_03"));
00747                 $this->tpl->setVariable("SHORT_APRIL", $this->lng->txt("s_04"));
00748                 $this->tpl->setVariable("SHORT_MAY", $this->lng->txt("s_05"));
00749                 $this->tpl->setVariable("SHORT_JUNE", $this->lng->txt("s_06"));
00750                 $this->tpl->setVariable("SHORT_JULY", $this->lng->txt("s_07"));
00751                 $this->tpl->setVariable("SHORT_AUGUST", $this->lng->txt("s_08"));
00752                 $this->tpl->setVariable("SHORT_SEPTEMBER", $this->lng->txt("s_09"));
00753                 $this->tpl->setVariable("SHORT_OCTOBER", $this->lng->txt("s_10"));
00754                 $this->tpl->setVariable("SHORT_NOVEMBER", $this->lng->txt("s_11"));
00755                 $this->tpl->setVariable("SHORT_DECEMBER", $this->lng->txt("s_12"));
00756                 $this->tpl->setVariable("ABOUT_CALENDAR", $this->lng->txt("about_calendar"));
00757                 $this->tpl->setVariable("ABOUT_CALENDAR_LONG", $this->lng->txt("about_calendar_long"));
00758                 $this->tpl->setVariable("ABOUT_TIME_LONG", $this->lng->txt("about_time"));
00759                 $this->tpl->setVariable("PREV_YEAR", $this->lng->txt("prev_year"));
00760                 $this->tpl->setVariable("PREV_MONTH", $this->lng->txt("prev_month"));
00761                 $this->tpl->setVariable("GO_TODAY", $this->lng->txt("go_today"));
00762                 $this->tpl->setVariable("NEXT_MONTH", $this->lng->txt("next_month"));
00763                 $this->tpl->setVariable("NEXT_YEAR", $this->lng->txt("next_year"));
00764                 $this->tpl->setVariable("SEL_DATE", $this->lng->txt("select_date"));
00765                 $this->tpl->setVariable("DRAG_TO_MOVE", $this->lng->txt("drag_to_move"));
00766                 $this->tpl->setVariable("PART_TODAY", $this->lng->txt("part_today"));
00767                 $this->tpl->setVariable("DAY_FIRST", $this->lng->txt("day_first"));
00768                 $this->tpl->setVariable("CLOSE", $this->lng->txt("close"));
00769                 $this->tpl->setVariable("TODAY", $this->lng->txt("today"));
00770                 $this->tpl->setVariable("TIME_PART", $this->lng->txt("time_part"));
00771                 $this->tpl->setVariable("DEF_DATE_FORMAT", $this->lng->txt("def_date_format"));
00772                 $this->tpl->setVariable("TT_DATE_FORMAT", $this->lng->txt("tt_date_format"));
00773                 $this->tpl->setVariable("WK", $this->lng->txt("wk"));
00774                 $this->tpl->setVariable("TIME", $this->lng->txt("time"));
00775                 $this->tpl->parseCurrentBlock();
00776                 $this->tpl->setCurrentBlock("CalendarJS");
00777                 $this->tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR", ilUtil::getJSPath("calendar.js"));
00778                 $this->tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR_SETUP", ilUtil::getJSPath("calendar-setup.js"));
00779                 $this->tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR_STYLESHEET", ilUtil::getJSPath("calendar.css"));
00780                 $this->tpl->parseCurrentBlock();
00781 
00782                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
00783                 {
00784                         // allow only read and write access
00785                         sendInfo($this->lng->txt("cannot_edit_survey"), true);
00786                         $path = $this->tree->getPathFull($this->object->getRefID());
00787                         ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
00788                         return;
00789                 }
00790 
00791     $add_parameter = $this->getAddParameter();
00792                 if ($_POST["cmd"]["save"])
00793                 {
00794                         $this->writePropertiesFormData();
00795                 }
00796     if ($_POST["cmd"]["save"]) {
00797                         $this->updateObject();
00798     }
00799     if ($_POST["cmd"]["cancel"]) {
00800       sendInfo($this->lng->txt("msg_cancel"), true);
00801                         $path = $this->tree->getPathFull($this->object->getRefID());
00802                         ilUtil::redirect($this->getReturnLocation("cancel",ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH)."/repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
00803       exit();
00804     }
00805 
00806                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_properties.html", true);
00807                 $this->tpl->setCurrentBlock("adm_content");
00808                 $this->tpl->setVariable("FORM_ACTION", $this->getCallingScript() . $add_parameter);
00809                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00810                 $this->tpl->setVariable("VALUE_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
00811                 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00812                 $this->tpl->setVariable("VALUE_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor()));
00813                 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
00814                 $this->tpl->setVariable("VALUE_DESCRIPTION", ilUtil::prepareFormOutput($this->object->getDescription()));
00815                 $this->tpl->setVariable("TEXT_INTRODUCTION", $this->lng->txt("introduction"));
00816                 $this->tpl->setVariable("VALUE_INTRODUCTION", ilUtil::prepareFormOutput($this->object->getIntroduction()));
00817                 $this->tpl->setVariable("TEXT_STATUS", $this->lng->txt("status"));
00818                 $this->tpl->setVariable("TEXT_START_DATE", $this->lng->txt("start_date"));
00819                 $this->tpl->setVariable("VALUE_START_DATE", ilUtil::makeDateSelect("start_date", $this->object->getStartYear(), $this->object->getStartMonth(), $this->object->getStartDay()));
00820                 $this->tpl->setVariable("IMG_START_DATE_CALENDAR", ilUtil::getImagePath("calendar.png"));
00821                 $this->tpl->setVariable("TXT_START_DATE_CALENDAR", $this->lng->txt("open_calendar"));
00822                 $this->tpl->setVariable("TEXT_END_DATE", $this->lng->txt("end_date"));
00823                 $this->tpl->setVariable("VALUE_END_DATE", ilUtil::makeDateSelect("end_date", $this->object->getEndYear(), $this->object->getEndMonth(), $this->object->getEndDay()));
00824                 $this->tpl->setVariable("IMG_END_DATE_CALENDAR", ilUtil::getImagePath("calendar.png"));
00825                 $this->tpl->setVariable("TXT_END_DATE_CALENDAR", $this->lng->txt("open_calendar"));
00826                 $this->tpl->setVariable("TEXT_EVALUATION_ACCESS", $this->lng->txt("evaluation_access"));
00827                 $this->tpl->setVariable("VALUE_OFFLINE", $this->lng->txt("offline"));
00828                 $this->tpl->setVariable("VALUE_ONLINE", $this->lng->txt("online"));
00829                 $this->tpl->setVariable("TEXT_ENABLED", $this->lng->txt("enabled"));
00830                 $this->tpl->setVariable("VALUE_OFF", $this->lng->txt("off"));
00831                 $this->tpl->setVariable("VALUE_ON", $this->lng->txt("on"));
00832                 $this->tpl->setVariable("TEXT_ANONYMIZATION", $this->lng->txt("anonymize_survey"));
00833                 $this->tpl->setVariable("TEXT_ANONYMIZATION_EXPLANATION", $this->lng->txt("anonymize_survey_explanation"));
00834                 $this->tpl->setVariable("ANON_VALUE_OFF", $this->lng->txt("off"));
00835                 $this->tpl->setVariable("ANON_VALUE_ON", $this->lng->txt("on"));
00836                 
00837                 if ($this->object->getAnonymize())
00838                 {
00839                         $this->tpl->setVariable("ANON_SELECTED_ON", " selected=\"selected\"");
00840                 }
00841                 else
00842                 {
00843                         $this->tpl->setVariable("ANON_SELECTED_OFF", " selected=\"selected\"");
00844                 }
00845                 
00846                 if ($this->object->getEndDateEnabled())
00847                 {
00848                         $this->tpl->setVariable("CHECKED_END_DATE", " checked=\"checked\"");
00849                 }
00850                 if ($this->object->getStartDateEnabled())
00851                 {
00852                         $this->tpl->setVariable("CHECKED_START_DATE", " checked=\"checked\"");
00853                 }
00854 
00855                 if ($this->object->getEvaluationAccess() == EVALUATION_ACCESS_ON)
00856                 {
00857                         $this->tpl->setVariable("SELECTED_ON", " selected=\"selected\"");
00858                 }
00859                 else
00860                 {
00861                         $this->tpl->setVariable("SELECTED_OFF", " selected=\"selected\"");
00862                 }
00863                 if ($this->object->getStatus() == STATUS_ONLINE)
00864                 {
00865                         $this->tpl->setVariable("SELECTED_ONLINE", " selected=\"selected\"");
00866                 }
00867                 else
00868                 {
00869                         $this->tpl->setVariable("SELECTED_OFFLINE", " selected=\"selected\"");
00870                 }
00871                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00872     if ($rbacsystem->checkAccess("write", $this->ref_id)) {
00873                         $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00874                         $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
00875                 }
00876                 $this->tpl->setVariable("TEXT_SHOW_QUESTIONTITLES", $this->lng->txt("svy_show_questiontitles"));
00877                 if ($this->object->getShowQuestionTitles())
00878                 {
00879                         $this->tpl->setVariable("QUESTIONTITLES_CHECKED", " checked=\"checked\"");
00880                 }
00881     $this->tpl->parseCurrentBlock();
00882   }
00883 
00891         function questionBrowser() {
00892     global $rbacsystem;
00893 
00894     $add_parameter = $this->getAddParameter() . "&insert_question=1";
00895 
00896                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_questionbrowser.html", true);
00897     $this->tpl->addBlockFile("A_BUTTONS", "a_buttons", "tpl.il_svy_qpl_action_buttons.html", true);
00898     $this->tpl->addBlockFile("FILTER_QUESTION_MANAGER", "filter_questions", "tpl.il_svy_svy_filter_questions.html", true);
00899 
00900                 $questionpools =& $this->object->getQuestionpoolTitles();
00901 
00902                 $filter_type = $_GET["sel_filter_type"];
00903                 if (!$filter_type)
00904                 {
00905                         $filter_type = $_POST["sel_filter_type"];
00906                 }
00907                 if (strcmp($_POST["cmd"]["resetFilter"], "") != 0)
00908                 {
00909                         $filter_type = "";
00910                 }
00911                 $add_parameter .= "&sel_filter_type=$filter_type";
00912 
00913                 $filter_text = $_GET["filter_text"];
00914                 if (!$filter_text)
00915                 {
00916                         $filter_text = $_POST["filter_text"];
00917                 }
00918                 if (strcmp($_POST["cmd"]["resetFilter"], "") != 0)
00919                 {
00920                         $filter_text = "";
00921                 }
00922                 $add_parameter .= "&filter_text=$filter_text";
00923 
00924                 $browsequestions = 1;
00925                 if (strcmp($_POST["cmd"]["datatype"], "") != 0)
00926                 {
00927                         $browsequestions = $_POST["datatype"];
00928                 }
00929                 else
00930                 {
00931                         if (strcmp($_GET["browsetype"], "") != 0)
00932                         {
00933                                 $browsequestions = $_GET["browsetype"];
00934                         }
00935                 }
00936                 $add_parameter .= "&browsetype=$browsequestions";
00937 
00938                 $filter_fields = array(
00939                         "title" => $this->lng->txt("title"),
00940                         "comment" => $this->lng->txt("description"),
00941                         "author" => $this->lng->txt("author"),
00942                 );
00943                 $this->tpl->setCurrentBlock("filterrow");
00944                 foreach ($filter_fields as $key => $value) {
00945                         $this->tpl->setVariable("VALUE_FILTER_TYPE", "$key");
00946                         $this->tpl->setVariable("NAME_FILTER_TYPE", "$value");
00947                         if (strcmp($_POST["cmd"]["resetFilter"], "") == 0) {
00948                                 if (strcmp($filter_type, $key) == 0) {
00949                                         $this->tpl->setVariable("VALUE_FILTER_SELECTED", " selected=\"selected\"");
00950                                 }
00951                         }
00952                         $this->tpl->parseCurrentBlock();
00953                 }
00954 
00955                 $filter_question_type = $_POST["sel_question_type"];
00956                 if (!$filter_question_type)
00957                 {
00958                         $filter_question_type = $_GET["sel_question_type"];
00959                 }
00960                 if (strcmp($_POST["cmd"]["resetFilter"], "") != 0)
00961                 {
00962                         $filter_question_type = "";
00963                 }
00964                 $add_parameter .= "&sel_question_type=$filter_question_type";
00965 
00966                 if ($browsequestions)
00967                 {
00968                         $questiontypes =& $this->object->_getQuestiontypes();
00969                         foreach ($questiontypes as $key => $value)
00970                         {
00971                                 $this->tpl->setCurrentBlock("questiontype_row");
00972                                 $this->tpl->setVariable("VALUE_QUESTION_TYPE", $value);
00973                                 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt($value));
00974                                 if (strcmp($filter_question_type, $value) == 0)
00975                                 {
00976                                         $this->tpl->setVariable("SELECTED_QUESTION_TYPE", " selected=\"selected\"");
00977                                 }
00978                                 $this->tpl->parseCurrentBlock();
00979                         }
00980                 }
00981                 
00982                 if ($_POST["cmd"]["filter"])
00983                 {
00984                         $filter_questionpool = $_POST["sel_questionpool"];
00985                 }
00986                 else
00987                 {
00988                         $filter_questionpool = $_GET["sel_questionpool"];
00989                 }
00990                 if (strcmp($_POST["cmd"]["resetFilter"], "") != 0)
00991                 {
00992                         $filter_questionpool = "";
00993                 }
00994                 $add_parameter .= "&sel_questionpool=$filter_questionpool";
00995                 
00996                 if ($browsequestions)
00997                 {
00998                         foreach ($questionpools as $key => $value)
00999                         {
01000                                 $this->tpl->setCurrentBlock("questionpool_row");
01001                                 $this->tpl->setVariable("VALUE_QUESTIONPOOL", $key);
01002                                 $this->tpl->setVariable("TEXT_QUESTIONPOOL", $value);
01003                                 if (strcmp($filter_questionpool, $key) == 0)
01004                                 {
01005                                         $this->tpl->setVariable("SELECTED_QUESTIONPOOL", " selected=\"selected\"");
01006                                 }
01007                                 $this->tpl->parseCurrentBlock();
01008                         }
01009                 }
01010 
01011                 if ($browsequestions)
01012                 {
01013                         $this->tpl->setCurrentBlock("question_filters");
01014                         $this->tpl->setVariable("SHOW_QUESTION_TYPES", $this->lng->txt("filter_show_question_types"));
01015                         $this->tpl->setVariable("TEXT_ALL_QUESTION_TYPES", $this->lng->txt("filter_all_question_types"));
01016                         $this->tpl->setVariable("SHOW_QUESTIONPOOLS", $this->lng->txt("filter_show_questionpools"));
01017                         $this->tpl->setVariable("TEXT_ALL_QUESTIONPOOLS", $this->lng->txt("filter_all_questionpools"));
01018                         $this->tpl->parseCurrentBlock();
01019                 }
01020 
01021                 $this->tpl->setCurrentBlock("filter_questions");
01022     $this->tpl->setVariable("FILTER_TEXT", $this->lng->txt("filter"));
01023     $this->tpl->setVariable("TEXT_FILTER_BY", $this->lng->txt("by"));
01024     if (!$_POST["cmd"]["reset"]) {
01025       $this->tpl->setVariable("VALUE_FILTER_TEXT", $filter_text);
01026     }
01027     $this->tpl->setVariable("VALUE_SUBMIT_FILTER", $this->lng->txt("set_filter"));
01028     $this->tpl->setVariable("VALUE_RESET_FILTER", $this->lng->txt("reset_filter"));
01029     $this->tpl->setVariable("OPTION_QUESTIONS", $this->lng->txt("questions"));
01030     $this->tpl->setVariable("OPTION_QUESTIONBLOCKS", $this->lng->txt("questionblocks"));
01031                 if ($browsequestions)
01032                 {
01033             $this->tpl->setVariable("SELECTED_QUESTIONS", " selected=\"selected\"");
01034                 }
01035                 else
01036                 {
01037             $this->tpl->setVariable("SELECTED_QUESTIONBLOCKS", " selected=\"selected\"");
01038                 }
01039     $this->tpl->setVariable("TEXT_DATATYPE", $this->lng->txt("display_all_available"));
01040                 $this->tpl->setVariable("BTN_CHANGE", $this->lng->txt("change"));
01041     $this->tpl->parseCurrentBlock();
01042 
01043                 if ($_POST["cmd"]["reset"])
01044                 {
01045                         $_POST["filter_text"] = "";
01046                 }
01047                 $startrow = 0;
01048                 if ($_GET["prevrow"])
01049                 {
01050                         $startrow = $_GET["prevrow"];
01051                 }
01052                 if ($_GET["nextrow"])
01053                 {
01054                         $startrow = $_GET["nextrow"];
01055                 }
01056                 if ($_GET["startrow"])
01057                 {
01058                         $startrow = $_GET["startrow"];
01059                 }
01060                 if (!$_GET["sort"])
01061                 {
01062                         // default sort order
01063                         $_GET["sort"] = array("title" => "ASC");
01064                 }
01065                 if ($browsequestions)
01066                 {
01067                         $table = $this->object->getQuestionsTable($_GET["sort"], $filter_text, $filter_type, $startrow, 1, $filter_question_type, $filter_questionpool);
01068                 }
01069                 else
01070                 {
01071                         $table = $this->object->getQuestionblocksTable($_GET["sort"], $filter_text, $filter_type, $startrow);
01072                 }
01073     $colors = array("tblrow1", "tblrow2");
01074     $counter = 0;
01075                 $questionblock_id = 0;
01076                 if ($browsequestions)
01077                 {
01078                         foreach ($table["rows"] as $data)
01079                         {
01080                                 if ($rbacsystem->checkAccess("write", $data["ref_id"])) {
01081                                         $this->tpl->setCurrentBlock("QTab");
01082                                         if ($data["complete"]) {
01083                                                 // make only complete questions selectable
01084                                                 $this->tpl->setVariable("QUESTION_ID", $data["question_id"]);
01085                                         }
01086                                         $this->tpl->setVariable("QUESTION_TITLE", "<strong>" . $data["title"] . "</strong>");
01087                                         $this->tpl->setVariable("PREVIEW", "[<a href=\"" . "questionpool.php?ref_id=" . $data["ref_id"] . "&cmd=preview&preview=" . $data["question_id"] . " \" target=\"_blank\">" . $this->lng->txt("preview") . "</a>]");
01088                                         $this->tpl->setVariable("QUESTION_COMMENT", $data["description"]);
01089                                         $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt($data["type_tag"]));
01090                                         $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
01091                                         $this->tpl->setVariable("QUESTION_CREATED", ilFormat::formatDate(ilFormat::ftimestamp2dateDB($data["created"]), "date"));
01092                                         $this->tpl->setVariable("QUESTION_UPDATED", ilFormat::formatDate(ilFormat::ftimestamp2dateDB($data["TIMESTAMP14"]), "date"));
01093                                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01094                                         $this->tpl->setVariable("QUESTION_POOL", $questionpools[$data["obj_fi"]]);
01095                                         $this->tpl->parseCurrentBlock();
01096                                         $counter++;
01097                                 }
01098                         }
01099                         if ($table["rowcount"] > count($table["rows"]))
01100                         {
01101                                 $nextstep = $table["nextrow"] + $table["step"];
01102                                 if ($nextstep > $table["rowcount"])
01103                                 {
01104                                         $nextstep = $table["rowcount"];
01105                                 }
01106                                 $sort = "";
01107                                 if (is_array($_GET["sort"]))
01108                                 {
01109                                         $key = key($_GET["sort"]);
01110                                         $sort = "&sort[$key]=" . $_GET["sort"]["$key"];
01111                                 }
01112                                 $counter = 1;
01113                                 for ($i = 0; $i < $table["rowcount"]; $i += $table["step"])
01114                                 {
01115                                         $this->tpl->setCurrentBlock("pages_questions");
01116                                         if ($table["startrow"] == $i)
01117                                         {
01118                                                 $this->tpl->setVariable("PAGE_NUMBER", "<span class=\"inactivepage\">$counter</span>");
01119                                         }
01120                                         else
01121                                         {
01122                                                 $this->tpl->setVariable("PAGE_NUMBER", "<a href=\"" . $this->getCallingScript() . $add_parameter . "$sort&nextrow=$i" . "\">$counter</a>");
01123                                         }
01124                                         $this->tpl->parseCurrentBlock();
01125                                         $counter++;
01126                                 }
01127                                 $this->tpl->setCurrentBlock("questions_navigation_bottom");
01128                                 $this->tpl->setVariable("TEXT_ITEM", $this->lng->txt("item"));
01129                                 $this->tpl->setVariable("TEXT_ITEM_START", $table["startrow"] + 1);
01130                                 $end = $table["startrow"] + $table["step"];
01131                                 if ($end > $table["rowcount"])
01132                                 {
01133                                         $end = $table["rowcount"];
01134                                 }
01135                                 $this->tpl->setVariable("TEXT_ITEM_END", $end);
01136                                 $this->tpl->setVariable("TEXT_OF", strtolower($this->lng->txt("of")));
01137                                 $this->tpl->setVariable("TEXT_ITEM_COUNT", $table["rowcount"]);
01138                                 $this->tpl->setVariable("TEXT_PREVIOUS", $this->lng->txt("previous"));
01139                                 $this->tpl->setVariable("TEXT_NEXT", $this->lng->txt("next"));
01140                                 $this->tpl->setVariable("HREF_PREV_ROWS", $this->getCallingScript() . $add_parameter . "$sort&prevrow=" . $table["prevrow"]);
01141                                 $this->tpl->setVariable("HREF_NEXT_ROWS", $this->getCallingScript() . $add_parameter . "$sort&nextrow=" . $table["nextrow"]);
01142                                 $this->tpl->parseCurrentBlock();
01143                         }
01144                 }
01145                 else
01146                 {
01147                         foreach ($table["rows"] as $data)
01148                         {
01149                                 $this->tpl->setCurrentBlock("questionblock_row");
01150                                 $this->tpl->setVariable("QUESTIONBLOCK_ID", $data["questionblock_id"]);
01151                                 $this->tpl->setVariable("QUESTIONBLOCK_TITLE", "<strong>" . $data["title"] . "</strong>");
01152                                 $this->tpl->setVariable("SURVEY_TITLE", $data["surveytitle"]);
01153                                 $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01154                                 $this->tpl->setVariable("QUESTIONS_TITLE", $data["questions"]);
01155                                 $this->tpl->parseCurrentBlock();
01156                                 $counter++;
01157                         }
01158                         if ($table["rowcount"] > count($table["rows"]))
01159                         {
01160                                 $nextstep = $table["nextrow"] + $table["step"];
01161                                 if ($nextstep > $table["rowcount"])
01162                                 {
01163                                         $nextstep = $table["rowcount"];
01164                                 }
01165                                 $sort = "";
01166                                 if (is_array($_GET["sort"]))
01167                                 {
01168                                         $key = key($_GET["sort"]);
01169                                         $sort = "&sort[$key]=" . $_GET["sort"]["$key"];
01170                                 }
01171                                 $counter = 1;
01172                                 for ($i = 0; $i < $table["rowcount"]; $i += $table["step"])
01173                                 {
01174                                         $this->tpl->setCurrentBlock("pages_questionblocks");
01175                                         if ($table["startrow"] == $i)
01176                                         {
01177                                                 $this->tpl->setVariable("PAGE_NUMBER", "<strong>$counter</strong>");
01178                                         }
01179                                         else
01180                                         {
01181                                                 $this->tpl->setVariable("PAGE_NUMBER", "<a href=\"" . $this->getCallingScript() . $add_parameter . "$sort&nextrow=$i" . "\">$counter</a>");
01182                                         }
01183                                         $this->tpl->parseCurrentBlock();
01184                                         $counter++;
01185                                 }
01186                                 $this->tpl->setCurrentBlock("questionblocks_navigation_bottom");
01187                                 $this->tpl->setVariable("TEXT_ITEM", $this->lng->txt("item"));
01188                                 $this->tpl->setVariable("TEXT_ITEM_START", $table["startrow"] + 1);
01189                                 $end = $table["startrow"] + $table["step"];
01190                                 if ($end > $table["rowcount"])
01191                                 {
01192                                         $end = $table["rowcount"];
01193                                 }
01194                                 $this->tpl->setVariable("TEXT_ITEM_END", $end);
01195                                 $this->tpl->setVariable("TEXT_OF", strtolower($this->lng->txt("of")));
01196                                 $this->tpl->setVariable("TEXT_ITEM_COUNT", $table["rowcount"]);
01197                                 $this->tpl->setVariable("TEXT_PREVIOUS", $this->lng->txt("previous"));
01198                                 $this->tpl->setVariable("TEXT_NEXT", $this->lng->txt("next"));
01199                                 $this->tpl->setVariable("HREF_PREV_ROWS", $this->getCallingScript() . $add_parameter . "$sort&prevrow=" . $table["prevrow"]);
01200                                 $this->tpl->setVariable("HREF_NEXT_ROWS", $this->getCallingScript() . $add_parameter . "$sort&nextrow=" . $table["nextrow"]);
01201                                 $this->tpl->parseCurrentBlock();
01202                         }
01203                 }
01204 
01205     // if there are no questions, display a message
01206     if ($counter == 0) {
01207       $this->tpl->setCurrentBlock("Emptytable");
01208                         if ($browsequestions)
01209                         {
01210         $this->tpl->setVariable("TEXT_EMPTYTABLE", $this->lng->txt("no_questions_available"));
01211                         }
01212                         else
01213                         {
01214         $this->tpl->setVariable("TEXT_EMPTYTABLE", $this->lng->txt("no_questionblocks_available"));
01215                         }
01216       $this->tpl->parseCurrentBlock();
01217     }
01218                 else
01219                 {
01220                         // create edit buttons & table footer
01221                         $this->tpl->setCurrentBlock("selection");
01222                         $this->tpl->setVariable("INSERT", $this->lng->txt("insert"));
01223                         $this->tpl->parseCurrentBlock();
01224 
01225                         $this->tpl->setCurrentBlock("Footer");
01226                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"\">");
01227                         $this->tpl->parseCurrentBlock();
01228                 }
01229     // define the sort column parameters
01230     $sort = array(
01231       "title" => $_GET["sort"]["title"],
01232       "description" => $_GET["sort"]["description"],
01233       "type" => $_GET["sort"]["type"],
01234       "author" => $_GET["sort"]["author"],
01235       "created" => $_GET["sort"]["created"],
01236       "updated" => $_GET["sort"]["updated"],
01237                         "qpl" => $_GET["sort"]["qpl"],
01238                         "svy" => $_GET["sort"]["svy"]
01239     );
01240     foreach ($sort as $key => $value) {
01241       if (strcmp($value, "ASC") == 0) {
01242         $sort[$key] = "DESC";
01243       } else {
01244         $sort[$key] = "ASC";
01245       }
01246     }
01247 
01248                 if ($browsequestions)
01249                 {
01250                         $this->tpl->setCurrentBlock("questions_header");
01251                         $this->tpl->setVariable("QUESTION_TITLE", "<a href=\"" . $this->getCallingScript() . "$add_parameter&startrow=" . $table["startrow"] . "&sort[title]=" . $sort["title"] . "\">" . $this->lng->txt("title") . "</a>" . $table["images"]["title"]);
01252                         $this->tpl->setVariable("QUESTION_COMMENT", "<a href=\"" . $this->getCallingScript() . "$add_parameter&startrow=" . $table["startrow"] . "&sort[description]=" . $sort["description"] . "\">" . $this->lng->txt("description") . "</a>". $table["images"]["description"]);
01253                         $this->tpl->setVariable("QUESTION_TYPE", "<a href=\"" . $this->getCallingScript() . "$add_parameter&startrow=" . $table["startrow"] . "&sort[type]=" . $sort["type"] . "\">" . $this->lng->txt("question_type") . "</a>" . $table["images"]["type"]);
01254                         $this->tpl->setVariable("QUESTION_AUTHOR", "<a href=\"" . $this->getCallingScript() . "$add_parameter&startrow=" . $table["startrow"] . "&sort[author]=" . $sort["author"] . "\">" . $this->lng->txt("author") . "</a>" . $table["images"]["author"]);
01255                         $this->tpl->setVariable("QUESTION_CREATED", "<a href=\"" . $this->getCallingScript() . "$add_parameter&startrow=" . $table["startrow"] . "&sort[created]=" . $sort["created"] . "\">" . $this->lng->txt("create_date") . "</a>" . $table["images"]["created"]);
01256                         $this->tpl->setVariable("QUESTION_UPDATED", "<a href=\"" . $this->getCallingScript() . "$add_parameter&startrow=" . $table["startrow"] . "&sort[updated]=" . $sort["updated"] . "\">" . $this->lng->txt("last_update") . "</a>" . $table["images"]["updated"]);
01257                         $this->tpl->setVariable("QUESTION_POOL", "<a href=\"" . $this->getCallingScript() . "$add_parameter&startrow=" . $table["startrow"] . "&sort[qpl]=" . $sort["qpl"] . "\">" . $this->lng->txt("obj_spl") . "</a>" . $table["images"]["qpl"]);
01258                         $this->tpl->parseCurrentBlock();
01259                 }
01260                 else
01261                 {
01262                         $this->tpl->setCurrentBlock("questionblocks_header");
01263                         $this->tpl->setVariable("QUESTIONBLOCK_TITLE", "<a href=\"" . $this->getCallingScript() . "$add_parameter&startrow=" . $table["startrow"] . "&sort[title]=" . $sort["title"] . "\">" . $this->lng->txt("title") . "</a>" . $table["images"]["title"]);
01264                         $this->tpl->setVariable("SURVEY_TITLE", "<a href=\"" . $this->getCallingScript() . "$add_parameter&startrow=" . $table["startrow"] . "&sort[svy]=" . $sort["svy"] . "\">" . $this->lng->txt("obj_svy") . "</a>" . $table["images"]["svy"]);
01265                         $this->tpl->setVariable("QUESTIONS_TITLE", $this->lng->txt("contains"));
01266                         $this->tpl->parseCurrentBlock();
01267                 }
01268     $this->tpl->setCurrentBlock("adm_content");
01269     // create table header
01270     $this->tpl->setVariable("BUTTON_BACK", $this->lng->txt("back"));
01271     $this->tpl->setVariable("FORM_ACTION", $this->getCallingScript() . $add_parameter);
01272     $this->tpl->parseCurrentBlock();
01273         }
01274 
01282         function searchQuestionsForm()
01283         {
01284                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_search_questions.html", true);
01285 
01286                 if ($_POST["cmd"]["search"])
01287                 {
01288                         $search = new SurveySearch(ilUtil::stripSlashes($_POST["search_term"]), $_POST["concat"], $_POST["search_field"], $_POST["search_type"]);
01289                         $search->search();
01290                         if (count($search->search_results))
01291                         {
01292                                 $classes = array("tblrow1", "tblrow2");
01293                                 $counter = 0;
01294                                 $titles = $this->object->getQuestionpoolTitles();
01295                                 $forbidden_pools =& $this->object->getForbiddenQuestionpools();
01296                                 $existing_questions =& $this->object->getExistingQuestions();
01297                                 foreach ($search->search_results as $data)
01298                                 {
01299                                         if ((!in_array($data["question_id"], $existing_questions)) && (!in_array($data["obj_fi"], $forbidden_pools)))
01300                                         {
01301                                                 $this->tpl->setCurrentBlock("result_row");
01302                                                 $this->tpl->setVariable("COLOR_CLASS", $classes[$counter % 2]);
01303                                                 $this->tpl->setVariable("QUESTION_ID", $data["question_id"]);
01304                                                 $this->tpl->setVariable("QUESTION_TITLE", $data["title"]);
01305                                                 $this->tpl->setVariable("QUESTION_DESCRIPTION", $data["description"]);
01306                                                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt($data["type_tag"]));
01307                                                 $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
01308                                                 $this->tpl->setVariable("QUESTION_POOL", $titles[$data["ref_id"]]);
01309                                                 $this->tpl->parseCurrentBlock();
01310                                                 $counter++;
01311                                         }
01312                                 }
01313                                 $this->tpl->setCurrentBlock("search_results");
01314                                 $this->tpl->setVariable("RESULT_IMAGE", ilUtil::getImagePath("icon_spl_b.gif"));
01315                                 $this->tpl->setVariable("ALT_IMAGE", $this->lng->txt("found_questions"));
01316                                 $this->tpl->setVariable("TEXT_QUESTION_TITLE", $this->lng->txt("title"));
01317                                 $this->tpl->setVariable("TEXT_QUESTION_DESCRIPTION", $this->lng->txt("description"));
01318                                 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("question_type"));
01319                                 $this->tpl->setVariable("TEXT_QUESTION_AUTHOR", $this->lng->txt("author"));
01320                                 $this->tpl->setVariable("TEXT_QUESTION_POOL", $this->lng->txt("obj_spl"));
01321                                 $this->tpl->setVariable("BTN_INSERT", $this->lng->txt("insert"));
01322                                 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"\">");
01323                                 $this->tpl->setVariable("FOUND_QUESTIONS", $this->lng->txt("found_questions"));
01324                                 $this->tpl->parseCurrentBlock();
01325                         }
01326                         else
01327                         {
01328                                 sendInfo($this->lng->txt("no_search_results"));
01329                         }
01330                 }
01331 
01332                 sendInfo();
01333                 $add_parameter = $this->getAddParameter();
01334                 $questiontypes = &$this->object->getQuestiontypes();
01335                 foreach ($questiontypes as $questiontype)
01336                 {
01337                         $this->tpl->setCurrentBlock("questiontypes");
01338                         $this->tpl->setVariable("VALUE_QUESTION_TYPE", $questiontype);
01339                         $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt($questiontype));
01340                         if (strcmp($_POST["search_type"], $questiontype) == 0)
01341                         {
01342                                 $this->tpl->setVariable("SELECTED_SEARCH_TYPE", " selected=\"selected\"");
01343                         }
01344                         $this->tpl->parseCurrentBlock();
01345                 }
01346                 $this->tpl->setCurrentBlock("adm_content");
01347                 switch ($_POST["search_field"])
01348                 {
01349                         case "title":
01350                                 $this->tpl->setVariable("CHECKED_TITLE", " selected=\"selected\"");
01351                                 break;
01352                         case "description":
01353                                 $this->tpl->setVariable("CHECKED_DESCRIPTION", " selected=\"selected\"");
01354                                 break;
01355                         case "author":
01356                                 $this->tpl->setVariable("CHECKED_AUTHOR", " selected=\"selected\"");
01357                                 break;
01358                         case "questiontext":
01359                                 $this->tpl->setVariable("CHECKED_QUESTIONTEXT", " selected=\"selected\"");
01360                                 break;
01361                         case "default":
01362                                 $this->tpl->setVariable("CHECKED_ALL", " selected=\"selected\"");
01363                                 break;
01364                 }
01365                 $this->tpl->setVariable("TEXT_SEARCH_TERM", $this->lng->txt("search_term"));
01366                 $this->tpl->setVariable("VALUE_SEARCH_TERM", $_POST["search_term"]);
01367                 $this->tpl->setVariable("TEXT_CONCATENATION", $this->lng->txt("concatenation"));
01368                 $this->tpl->setVariable("TEXT_AND", $this->lng->txt("and"));
01369                 $this->tpl->setVariable("TEXT_OR", $this->lng->txt("or"));
01370                 if ($_POST["concat"] == 1)
01371                 {
01372                         $this->tpl->setVariable("CHECKED_OR", " checked=\"checked\"");
01373                 }
01374                 else
01375                 {
01376                         $this->tpl->setVariable("CHECKED_AND", " checked=\"checked\"");
01377                 }
01378                 $this->tpl->setVariable("TEXT_SEARCH_FOR", $this->lng->txt("search_for"));
01379                 $this->tpl->setVariable("SEARCH_FIELD_ALL", $this->lng->txt("search_field_all"));
01380                 $this->tpl->setVariable("SEARCH_FIELD_TITLE", $this->lng->txt("title"));
01381                 $this->tpl->setVariable("SEARCH_FIELD_DESCRIPTION", $this->lng->txt("description"));
01382                 $this->tpl->setVariable("SEARCH_FIELD_AUTHOR", $this->lng->txt("author"));
01383                 $this->tpl->setVariable("SEARCH_FIELD_QUESTIONTEXT", $this->lng->txt("question"));
01384                 $this->tpl->setVariable("SEARCH_TYPE_ALL", $this->lng->txt("search_type_all"));
01385                 $this->tpl->setVariable("BTN_SEARCH", $this->lng->txt("search"));
01386                 $this->tpl->setVariable("FORM_ACTION", $this->getCallingScript() . $add_parameter . "&search_question=1&browsetype=1&insert_question=1");
01387                 $this->tpl->parseCurrentBlock();
01388         }
01389 
01397         function insertQuestionsForm($checked_questions)
01398         {
01399                 sendInfo();
01400                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_insert_questions.html", true);
01401                 $colors = array("tblrow1", "tblrow2");
01402                 $counter = 0;
01403                 if ($_GET["browsetype"] == 1)
01404                 {
01405                         $questions = &$this->object->getQuestions($checked_questions);
01406                         if (count($questions))
01407                         {
01408                                 foreach ($questions as $data)
01409                                 {
01410                                         if (in_array($data["question_id"], $checked_questions))
01411                                         {
01412                                                 $this->tpl->setCurrentBlock("row");
01413                                                 $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01414                                                 $this->tpl->setVariable("TEXT_TITLE", $data["title"]);
01415                                                 $this->tpl->setVariable("TEXT_DESCRIPTION", $data["description"]);
01416                                                 $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt($data["type_tag"]));
01417                                                 $this->tpl->parseCurrentBlock();
01418                                                 $counter++;
01419                                         }
01420                                 }
01421                         }
01422                 }
01423                 else
01424                 {
01425                         $questionblocks = &$this->object->getQuestionblocks($checked_questions);
01426                         if (count($questionblocks))
01427                         {
01428                                 foreach ($questionblocks as $questionblock_id => $data)
01429                                 {
01430                                         if (in_array($questionblock_id, $checked_questions))
01431                                         {
01432                                                 $this->tpl->setCurrentBlock("row");
01433                                                 $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01434                                                 $this->tpl->setVariable("TEXT_TITLE", $data[key($data)]["title"]);
01435                                                 $this->tpl->setVariable("TEXT_TYPE", $data[key($data)]["surveytitle"]);
01436                                                 $contains = array();
01437                                                 foreach ($data as $key => $value)
01438                                                 {
01439                                                         array_push($contains, $value["sequence"] . ". " . $value["questiontitle"]);
01440                                                 }
01441                                                 $this->tpl->setVariable("TEXT_DESCRIPTION", join($contains, ", "));
01442                                                 $this->tpl->parseCurrentBlock();
01443                                                 $counter++;
01444                                         }
01445                                 }
01446                         }
01447                 }
01448                 foreach ($checked_questions as $id)
01449                 {
01450                         $this->tpl->setCurrentBlock("hidden");
01451                         $this->tpl->setVariable("HIDDEN_NAME", "id_$id");
01452                         $this->tpl->setVariable("HIDDEN_VALUE", "1");
01453                         $this->tpl->parseCurrentBlock();
01454                 }
01455 
01456                 $this->tpl->setCurrentBlock("adm_content");
01457                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
01458                 if ($_GET["browsetype"] == 1)
01459                 {
01460                         $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
01461                         $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("question_type"));
01462                 }
01463                 else
01464                 {
01465                         $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("contains"));
01466                         $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("obj_svy"));
01467                 }
01468                 $this->tpl->setVariable("BTN_CONFIRM", $this->lng->txt("confirm"));
01469                 $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
01470                 $this->ctrl->setParameterByClass(get_class($this), "browsetype", $_GET["browsetype"]);
01471                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
01472                 $this->tpl->parseCurrentBlock();
01473         }
01474 
01484         function removeQuestionsForm($checked_questions, $checked_questionblocks)
01485         {
01486                 sendInfo();
01487                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_remove_questions.html", true);
01488                 $colors = array("tblrow1", "tblrow2");
01489                 $counter = 0;
01490                 $surveyquestions =& $this->object->getSurveyQuestions();
01491                 foreach ($surveyquestions as $question_id => $data)
01492                 {
01493                         if (in_array($data["question_id"], $checked_questions) or (in_array($data["questionblock_id"], $checked_questionblocks)))
01494                         {
01495                                 $this->tpl->setCurrentBlock("row");
01496                                 $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01497                                 $this->tpl->setVariable("TEXT_TITLE", $data["title"]);
01498                                 $this->tpl->setVariable("TEXT_DESCRIPTION", $data["description"]);
01499                                 $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt($data["type_tag"]));
01500                                 $this->tpl->setVariable("TEXT_QUESTIONBLOCK", $data["questionblock_title"]);
01501                                 $this->tpl->parseCurrentBlock();
01502                                 $counter++;
01503                         }
01504                 }
01505                 foreach ($checked_questions as $id)
01506                 {
01507                         $this->tpl->setCurrentBlock("hidden");
01508                         $this->tpl->setVariable("HIDDEN_NAME", "id_$id");
01509                         $this->tpl->setVariable("HIDDEN_VALUE", "$id");
01510                         $this->tpl->parseCurrentBlock();
01511                 }
01512                 foreach ($checked_questionblocks as $id)
01513                 {
01514                         $this->tpl->setCurrentBlock("hidden");
01515                         $this->tpl->setVariable("HIDDEN_NAME", "id_qb_$id");
01516                         $this->tpl->setVariable("HIDDEN_VALUE", "$id");
01517                         $this->tpl->parseCurrentBlock();
01518                 }
01519                 $this->tpl->setCurrentBlock("adm_content");
01520                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
01521                 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
01522                 $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("question_type"));
01523                 $this->tpl->setVariable("TEXT_QUESTIONBLOCK", $this->lng->txt("questionblock"));
01524                 $this->tpl->setVariable("BTN_CONFIRM", $this->lng->txt("confirm"));
01525                 $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
01526                 $this->tpl->setVariable("FORM_ACTION", $this->getCallingScript() . $this->getAddParameter());
01527                 $this->tpl->parseCurrentBlock();
01528         }
01529 
01530 
01539         function defineQuestionblock($questionblock_id = "")
01540         {
01541                 sendInfo();
01542                 if ($questionblock_id)
01543                 {
01544                         $questionblock = $this->object->getQuestionblock($questionblock_id);
01545                 }
01546                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_define_questionblock.html", true);
01547                 foreach ($_POST as $key => $value)
01548                 {
01549                         if (preg_match("/cb_(\d+)/", $key, $matches))
01550                         {
01551                                 $this->tpl->setCurrentBlock("hidden");
01552                                 $this->tpl->setVariable("HIDDEN_NAME", "cb_$matches[1]");
01553                                 $this->tpl->setVariable("HIDDEN_VALUE", $matches[1]);
01554                                 $this->tpl->parseCurrentBlock();
01555                         }
01556                 }
01557                 if ($questionblock_id)
01558                 {
01559                         $this->tpl->setCurrentBlock("hidden");
01560                         $this->tpl->setVariable("HIDDEN_NAME", "questionblock_id");
01561                         $this->tpl->setVariable("HIDDEN_VALUE", $questionblock_id);
01562                         $this->tpl->parseCurrentBlock();
01563                 }
01564                 $this->tpl->setCurrentBlock("adm_content");
01565                 $this->tpl->setVariable("DEFINE_QUESTIONBLOCK_HEADING", $this->lng->txt("define_questionblock"));
01566                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
01567                 if ($questionblock_id)
01568                 {
01569                         $this->tpl->setVariable("VALUE_TITLE", $questionblock["title"]);
01570                 }
01571                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
01572                 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
01573                 $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
01574                 $this->tpl->setVariable("FORM_ACTION", $this->getCallingScript() . $this->getAddParameter());
01575                 $this->tpl->parseCurrentBlock();
01576         }
01577 
01585         function questionpoolSelectForm()
01586         {
01587                 global $ilUser;
01588     $add_parameter = $this->getAddParameter();
01589                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_qpl_select.html", true);
01590                 $questionpools =& $this->object->getAvailableQuestionpools();
01591                 foreach ($questionpools as $key => $value)
01592                 {
01593                         $this->tpl->setCurrentBlock("option");
01594                         $this->tpl->setVariable("VALUE_OPTION", $key);
01595                         $this->tpl->setVariable("TEXT_OPTION", $value);
01596                         $this->tpl->parseCurrentBlock();
01597                 }
01598                 $this->tpl->setCurrentBlock("hidden");
01599                 $this->tpl->setVariable("HIDDEN_NAME", "sel_question_types");
01600                 $this->tpl->setVariable("HIDDEN_VALUE", $_POST["sel_question_types"]);
01601                 $this->tpl->parseCurrentBlock();
01602                 $this->tpl->setCurrentBlock("adm_content");
01603                 $this->tpl->setVariable("FORM_ACTION", $this->getCallingScript() . $add_parameter);
01604                 $this->tpl->setVariable("TXT_QPL_SELECT", $this->lng->txt("select_questionpool"));
01605                 if (count($questionpools))
01606                 {
01607                         $this->tpl->setVariable("BTN_SUBMIT", $this->lng->txt("submit"));
01608                 }
01609                 else
01610                 {
01611                         sendInfo($this->lng->txt("create_questionpool_before_add_question"));
01612                 }
01613                 $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
01614                 $this->tpl->parseCurrentBlock();
01615         }
01616 
01626         function constraintsForm($checked_questions, $checked_questionblocks)
01627         {
01628                 global $rbacsystem;
01629                 sendInfo();
01630                 $pages =& $this->object->getSurveyPages();
01631                 $all_questions =& $this->object->getSurveyQuestions();
01632                 $add_constraint = 0;
01633                 $delete_constraint = 0;
01634                 $constraint_question = -1;
01635                 foreach ($_POST as $key => $value) {
01636                         if (preg_match("/add_constraint_(\d+)/", $key, $matches)) {
01637                                 $add_constraint = 1;
01638                                 $constraint_question = $matches[1];
01639                         }
01640                 }
01641                 if ($_POST["cmd"]["save_constraint"])
01642                 {
01643                         foreach ($checked_questions as $id)
01644                         {
01645                                 foreach ($pages as $question_array)
01646                                 {
01647                                         foreach ($question_array as $question_data)
01648                                         {
01649                                                 if ($question_data["question_id"] == $id)
01650                                                 {
01651                                                         $this->object->addConstraint($question_data["question_id"], $_POST["q"], $_POST["r"], $_POST["v"]);
01652                                                 }
01653                                         }
01654                                 }
01655                         }
01656                         foreach ($checked_questionblocks as $id)
01657                         {
01658                                 foreach ($pages as $question_array)
01659                                 {
01660                                         if ($question_array[0]["questionblock_id"] == $id)
01661                                         {
01662                                                 foreach ($question_array as $question_data)
01663                                                 {
01664                                                         $this->object->addConstraint($question_data["question_id"], $_POST["q"], $_POST["r"], $_POST["v"]);
01665                                                 }
01666                                         }
01667                                 }
01668                         }
01669                         $add_constraint = 0;
01670                 }
01671                 else if ($_POST["cmd"]["cancel_add_constraint"])
01672                 {
01673                         // do nothing, just cancel the form
01674                         $add_constraint = 0;
01675                 }
01676                 else
01677                 {
01678                 }
01679                 if ($add_constraint)
01680                 {
01681                         $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_add_constraint.html", true);
01682                         $found = 0;
01683                         if ($_POST["cmd"]["select_relation"] or $_POST["cmd"]["select_value"])
01684                         {
01685                                 $this->tpl->setCurrentBlock("option_q");
01686                                 $this->tpl->setVariable("OPTION_VALUE", $_POST["q"]);
01687                                 $this->tpl->setVariable("OPTION_TEXT", $all_questions[$_POST["q"]]["title"] . " (" . $this->lng->txt($all_questions[$_POST["q"]]["type_tag"]) . ")");
01688                                 $this->tpl->parseCurrentBlock();
01689                         }
01690                         else
01691                         {
01692                                 foreach ($pages as $question_array)
01693                                 {
01694                                         if (!$found)
01695                                         {
01696                                                 foreach ($question_array as $question)
01697                                                 {
01698                                                         if ($question["question_id"] == $constraint_question)
01699                                                         {
01700                                                                 $found = 1;
01701                                                         }
01702                                                 }
01703                                                 if (!$found)
01704                                                 {
01705                                                         foreach ($question_array as $question)
01706                                                         {
01707                                                                 $this->tpl->setCurrentBlock("option_q");
01708                                                                 $this->tpl->setVariable("OPTION_VALUE", $question["question_id"]);
01709                                                                 $this->tpl->setVariable("OPTION_TEXT", $question["title"] . " (" . $this->lng->txt($question["type_tag"]) . ")");
01710                                                                 if ($question["question_id"] == $_POST["q"])
01711                                                                 {
01712                                                                         $this->tpl->setVariable("OPTION_CHECKED", " selected=\"selected\"");
01713                                                                 }
01714                                                                 $this->tpl->parseCurrentBlock();
01715                                                         }
01716                                                 }
01717                                         }
01718                                 }
01719                         }
01720                         foreach ($_POST as $key => $value) {
01721                                 if (preg_match("/add_constraint_(\d+)/", $key, $matches)) {
01722                                         $this->tpl->setCurrentBlock("hidden");
01723                                         $this->tpl->setVariable("HIDDEN_NAME", $key);
01724                                         $this->tpl->setVariable("HIDDEN_VALUE", $value);
01725                                         $this->tpl->parseCurrentBlock();
01726                                         foreach ($checked_questions as $id)
01727                                         {
01728                                                 $this->tpl->setCurrentBlock("hidden");
01729                                                 $this->tpl->setVariable("HIDDEN_NAME", "cb_$id");
01730                                                 $this->tpl->setVariable("HIDDEN_VALUE", "$id");
01731                                                 $this->tpl->parseCurrentBlock();
01732                                         }
01733                                         foreach ($checked_questionblocks as $id)
01734                                         {
01735                                                 $this->tpl->setCurrentBlock("hidden");
01736                                                 $this->tpl->setVariable("HIDDEN_NAME", "cb_qb_$id");
01737                                                 $this->tpl->setVariable("HIDDEN_VALUE", "$id");
01738                                                 $this->tpl->parseCurrentBlock();
01739                                         }
01740                                 }
01741                         }
01742                         $continue_command = "select_relation";
01743                         $back_command = "cancel_add_constraint";
01744                         if ($_POST["cmd"]["select_relation"] or $_POST["cmd"]["select_value"])
01745                         {
01746                                 $relations = $this->object->getAllRelations();
01747                                 switch ($all_questions[$_POST["q"]]["type_tag"])
01748                                 {
01749                                         case "qt_nominal":
01750                                                 foreach ($relations as $rel_id => $relation)
01751                                                 {
01752                                                         if ((strcmp($relation["short"], "=") == 0) or (strcmp($relation["short"], "<>") == 0))
01753                                                         {
01754                                                                 $this->tpl->setCurrentBlock("option_r");
01755                                                                 $this->tpl->setVariable("OPTION_VALUE", $rel_id);
01756                                                                 $this->tpl->setVariable("OPTION_TEXT", $relation["short"]);
01757                                                                 if ($rel_id == $_POST["r"])
01758                                                                 {
01759                                                                         $this->tpl->setVariable("OPTION_CHECKED", " selected=\"selected\"");
01760                                                                 }
01761                                                                 $this->tpl->parseCurrentBlock();
01762                                                         }
01763                                                 }
01764                                                 break;
01765                                         case "qt_ordinal":
01766                                         case "qt_metric":
01767                                                 foreach ($relations as $rel_id => $relation)
01768                                                 {
01769                                                         $this->tpl->setCurrentBlock("option_r");
01770                                                         $this->tpl->setVariable("OPTION_VALUE", $rel_id);
01771                                                         $this->tpl->setVariable("OPTION_TEXT", $relation["short"]);
01772                                                         if ($rel_id == $_POST["r"])
01773                                                         {
01774                                                                 $this->tpl->setVariable("OPTION_CHECKED", " selected=\"selected\"");
01775                                                         }
01776                                                         $this->tpl->parseCurrentBlock();
01777                                                 }
01778                                                 break;
01779                                 }
01780                                 $this->tpl->setCurrentBlock("select_relation");
01781                                 $this->tpl->setVariable("SELECT_RELATION", $this->lng->txt("select_relation"));
01782                                 $this->tpl->parseCurrentBlock();
01783                                 $continue_command = "select_value";
01784                                 $back_command = "begin_add_constraint";
01785                         }
01786                         if ($_POST["cmd"]["select_value"])
01787                         {
01788                                 $variables =& $this->object->getVariables($_POST["q"]);
01789                                 switch ($all_questions[$_POST["q"]]["type_tag"])
01790                                 {
01791                                         case "qt_nominal":
01792                                         case "qt_ordinal":
01793                                                 foreach ($variables as $sequence => $row)
01794                                                 {
01795                                                         $this->tpl->setCurrentBlock("option_v");
01796                                                         $this->tpl->setVariable("OPTION_VALUE", $sequence);
01797                                                         $this->tpl->setVariable("OPTION_TEXT", ($sequence+1) . " - " . $row->title);
01798                                                         $this->tpl->parseCurrentBlock();
01799                                                 }
01800                                                 break;
01801                                         case "qt_metric":
01802                                                         $this->tpl->setCurrentBlock("textfield");
01803                                                         $this->tpl->setVariable("TEXTFIELD_VALUE", "");
01804                                                         $this->tpl->parseCurrentBlock();
01805                                                 break;
01806                                 }
01807                                 $this->tpl->setCurrentBlock("select_value");
01808                                 if (strcmp($all_questions[$_POST["q"]]["type_tag"], "qt_metric") == 0)
01809                                 {
01810                                         $this->tpl->setVariable("SELECT_VALUE", $this->lng->txt("enter_value"));
01811                                 }
01812                                 else
01813                                 {
01814                                         $this->tpl->setVariable("SELECT_VALUE", $this->lng->txt("select_value"));
01815                                 }
01816                                 $this->tpl->parseCurrentBlock();
01817                                 $continue_command = "save_constraint";
01818                                 $back_command = "select_relation";
01819                         }
01820                         $this->tpl->setCurrentBlock("buttons");
01821                         $this->tpl->setVariable("BTN_CONTINUE", $this->lng->txt("continue"));
01822                         $this->tpl->setVariable("COMMAND", "$continue_command");
01823                         $this->tpl->setVariable("BTN_BACK", $this->lng->txt("back"));
01824                         $this->tpl->setVariable("COMMAND_BACK", "$back_command");
01825                         $this->tpl->parseCurrentBlock();
01826                         $this->tpl->setCurrentBlock("adm_content");
01827                         $textoutput = "";
01828                         foreach ($checked_questions as $id)
01829                         {
01830                                 foreach ($pages as $question_array)
01831                                 {
01832                                         foreach ($question_array as $question_data)
01833                                         {
01834                                                 if ($question_data["question_id"] == $id)
01835                                                 {
01836                                                         if ($textoutput)
01837                                                         {
01838                                                                 $textoutput .= "<br>";
01839                                                         }
01840                                                         $textoutput .= $question_data["title"] . ": " . $question_data["questiontext"];
01841                                                 }
01842                                         }
01843                                 }
01844                         }
01845                         foreach ($checked_questionblocks as $id)
01846                         {
01847                                 foreach ($pages as $question_array)
01848                                 {
01849                                         if ($question_array[0]["questionblock_id"] == $id)
01850                                         {
01851                                                 if ($textoutput)
01852                                                 {
01853                                                         $textoutput .= "<br>";
01854                                                 }
01855                                                 $textoutput .= $this->lng->txt("questionblock") . ": " . $question_array[0]["questionblock_title"];
01856                                         }
01857                                 }
01858                         }
01859                         $this->tpl->setVariable("CONSTRAINT_QUESTION_TEXT", "$textoutput");
01860                         $this->tpl->setVariable("SELECT_PRIOR_QUESTION", $this->lng->txt("select_prior_question"));
01861                         $this->tpl->setVariable("FORM_ACTION", $this->getCallingScript() . $this->getAddParameter());
01862                         $this->tpl->parseCurrentBlock();
01863                 }
01864                 else
01865                 {
01866                         foreach ($_POST as $key => $value)
01867                         {
01868                                 if (preg_match("/delete_constraint_(\d+)_(\d+)/", $key, $matches)) {
01869                                         foreach ($pages as $question_array)
01870                                         {
01871                                                 $found = 0;
01872                                                 foreach ($question_array as $question_data)
01873                                                 {
01874                                                         if ($question_data["question_id"] == $matches[2])
01875                                                         {
01876                                                                 $found = 1;
01877                                                         }
01878                                                 }
01879                                                 if ($found)
01880                                                 {
01881                                                         foreach ($question_array as $question_id => $question_data)
01882                                                         {
01883                                                                 $this->object->deleteConstraint($matches[1], $question_data["question_id"]);
01884                                                         }
01885                                                 }
01886                                         }
01887                                 }
01888                         }
01889                         $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_constraints.html", true);
01890                         $colors = array("tblrow1", "tblrow2");
01891                         $counter = 0;
01892                         foreach ($pages as $question_array)
01893                         {
01894                                 if (count($question_array) > 1)
01895                                 {
01896                                         // question block
01897                                         $data = $question_array[0];
01898                                 }
01899                                 else
01900                                 {
01901                                         // question
01902                                         $data = $question_array[0];
01903                                 }
01904                                 if (in_array($data["questionblock_id"], $checked_questionblocks) or (in_array($data["question_id"], $checked_questions)))
01905                                 {
01906                                         $counter = 0;
01907                                         $constraints = $this->object->getConstraints($data["question_id"]);
01908                                         if (count($constraints))
01909                                         {
01910                                                 foreach ($constraints as $constraint)
01911                                                 {
01912                                                         $value = "";
01913                                                         $variables =& $this->object->getVariables($constraint["question"]);
01914                                                         switch ($all_questions[$constraint["question"]]["type_tag"])
01915                                                         {
01916                                                                 case "qt_metric":
01917                                                                         $value = $constraint["value"];
01918                                                                         break;
01919                                                                 case "qt_nominal":
01920                                                                 case "qt_ordinal":
01921                                                                         $value = sprintf("%d", $constraint["value"]+1) . " - " . $variables[$constraint["value"]]->title;
01922                                                                         break;
01923                                                         }
01924                                                         $this->tpl->setCurrentBlock("constraint");
01925                                                         $this->tpl->setVariable("CONSTRAINT_TEXT", $all_questions[$constraint["question"]]["title"] . " " . $constraint["short"] . " $value");
01926                                                         if ($rbacsystem->checkAccess("write", $this->ref_id) and ($this->object->isOffline())) {
01927                                                                 $this->tpl->setVariable("CONSTRAINT_ID", $constraint["id"]);
01928                                                                 $this->tpl->setVariable("CONSTRAINT_QUESTION_ID", $constraint["question"]);
01929                                                                 $this->tpl->setVariable("BTN_DELETE", $this->lng->txt("delete"));
01930                                                         }
01931                                                         $this->tpl->parseCurrentBlock();
01932                                                 }
01933                                         }
01934                                         else
01935                                         {
01936                                                 $this->tpl->setCurrentBlock("empty_row");
01937                                                 $this->tpl->setVariable("EMPTY_TEXT", $this->lng->txt("no_available_constraints"));
01938                                                 $this->tpl->parseCurrentBlock();
01939                                         }
01940                                         $this->tpl->setCurrentBlock("question");
01941                                         if ($data["questionblock_id"])
01942                                         {
01943                                                 $this->tpl->setVariable("QUESTION_IDENTIFIER", $this->lng->txt("questionblock") . ": " . $data["questionblock_title"]);
01944                                         }
01945                                         else
01946                                         {
01947                                                 $this->tpl->setVariable("QUESTION_IDENTIFIER", $this->lng->txt($data["type_tag"]) . ": " . $data["title"]);
01948                                         }
01949                                         if ($rbacsystem->checkAccess("write", $this->ref_id) and ($this->object->isOffline())) {
01950                                                 $this->tpl->setVariable("ADD_QUESTION_ID", $data["question_id"]);
01951                                                 $this->tpl->setVariable("BTN_ADD", $this->lng->txt("add"));
01952                                         }
01953                                         $this->tpl->setVariable("QUESTION_ID", $data["question_id"]);
01954                                         $this->tpl->setVariable("BTN_BACK", $this->lng->txt("back"));
01955                                         $this->tpl->parseCurrentBlock();
01956                                 }
01957                         }
01958                         foreach ($checked_questions as $id)
01959                         {
01960                                 $this->tpl->setCurrentBlock("hidden");
01961                                 $this->tpl->setVariable("HIDDEN_NAME", "cb_$id");
01962                                 $this->tpl->setVariable("HIDDEN_VALUE", "$id");
01963                                 $this->tpl->parseCurrentBlock();
01964                         }
01965                         foreach ($checked_questionblocks as $id)
01966                         {
01967                                 $this->tpl->setCurrentBlock("hidden");
01968                                 $this->tpl->setVariable("HIDDEN_NAME", "cb_qb_$id");
01969                                 $this->tpl->setVariable("HIDDEN_VALUE", "$id");
01970                                 $this->tpl->parseCurrentBlock();
01971                         }
01972 
01973                         $this->tpl->setCurrentBlock("adm_content");
01974                         if ($rbacsystem->checkAccess("write", $this->ref_id) and ($this->object->isOffline())) {
01975                                 $this->tpl->setVariable("TEXT_EDIT_CONSTRAINTS", $this->lng->txt("edit_constraints_introduction"));
01976                         }
01977                         else
01978                         {
01979                                 $this->tpl->setVariable("TEXT_EDIT_CONSTRAINTS", $this->lng->txt("view_constraints_introduction"));
01980                         }
01981                         $this->tpl->setVariable("FORM_ACTION", $this->getCallingScript() . $this->getAddParameter());
01982                         $this->tpl->parseCurrentBlock();
01983                 }
01984         }
01985 
01994         function addHeadingObject($question_id = "")
01995         {
01996     $add_parameter = $this->getAddParameter();
01997                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_heading.html", true);
01998                 $survey_questions =& $this->object->getSurveyQuestions();
01999                 if ($question_id)
02000                 {
02001                         $_POST["insertbefore"] = $question_id;
02002                         $_POST["heading"] = $survey_questions[$question_id]["heading"];
02003                 }
02004                 foreach ($survey_questions as $key => $value)
02005                 {
02006                         $this->tpl->setCurrentBlock("insertbefore_row");
02007                         $this->tpl->setVariable("VALUE_OPTION", $key);
02008                         $option = $this->lng->txt("before") . ": \"" . $value["title"] . "\"";
02009                         if (strlen($option) > 80)
02010                         {
02011                                 $option = preg_replace("/^(.{40}).*(.{40})$/", "\\1 [...] \\2", $option);
02012                         }
02013                         $this->tpl->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($option));
02014                         if ($key == $_POST["insertbefore"])
02015                         {
02016                                 $this->tpl->setVariable("SELECTED_OPTION", " selected=\"selected\"");
02017                         }
02018                         $this->tpl->parseCurrentBlock();
02019                 }
02020                 if ($question_id)
02021                 {
02022                         $this->tpl->setCurrentBlock("hidden");
02023                         $this->tpl->setVariable("INSERTBEFORE_ORIGINAL", $question_id);
02024                         $this->tpl->parseCurrentBlock();
02025                 }
02026                 $this->tpl->setCurrentBlock("adm_content");
02027                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
02028                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
02029                 if ($question_id)
02030                 {
02031                         $this->tpl->setVariable("TEXT_ADD_HEADING", $this->lng->txt("edit_heading"));
02032                         $this->tpl->setVariable("SELECT_DISABLED", " disabled=\"disabled\"");
02033                 }
02034                 else
02035                 {
02036                         $this->tpl->setVariable("TEXT_ADD_HEADING", $this->lng->txt("add_heading"));
02037                 }
02038                 $this->tpl->setVariable("TEXT_HEADING", $this->lng->txt("heading"));
02039                 $this->tpl->setVariable("VALUE_HEADING", $_POST["heading"]);
02040                 $this->tpl->setVariable("TEXT_INSERT", $this->lng->txt("insert"));
02041                 $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
02042                 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
02043                 $this->tpl->parseCurrentBlock();
02044         }
02045 
02053         function confirmInsertQuestionObject()
02054         {
02055                 // insert questions from test after confirmation
02056                 foreach ($_POST as $key => $value) {
02057                         if (preg_match("/id_(\d+)/", $key, $matches)) {
02058                                 if ($_GET["browsetype"] == 1)
02059                                 {
02060                                         $this->object->insertQuestion($matches[1]);
02061                                 }
02062                                 else
02063                                 {
02064                                         $this->object->insertQuestionBlock($matches[1]);
02065                                 }
02066                         }
02067                 }
02068                 $this->object->saveCompletionStatus();
02069                 sendInfo($this->lng->txt("questions_inserted"), true);
02070                 $this->ctrl->redirect($this, "questions");
02071         }
02072         
02080         function cancelInsertQuestionObject()
02081         {
02082                 $this->ctrl->redirect($this, "questions");
02083         }
02084 
02092         function saveHeadingObject()
02093         {
02094                 if ($_POST["heading"])
02095                 {
02096                         $insertbefore = $_POST["insertbefore"];
02097                         if (!$insertbefore)
02098                         {
02099                                 $insertbefore = $_POST["insertbefore_original"];
02100                         }
02101                         $this->object->saveHeading($_POST["heading"], $insertbefore);
02102                         $this->ctrl->redirect($this, "questions");
02103                 }
02104                 else
02105                 {
02106                         sendInfo($this->lng->txt("error_add_heading"));
02107                         $this->addHeadingObject();
02108                         return;
02109                 }
02110         }
02111         
02119         function cancelHeadingObject()
02120         {
02121                 $this->ctrl->redirect($this, "questions");
02122         }
02123 
02131         function confirmRemoveHeadingObject()
02132         {
02133                 $this->object->saveHeading("", $_POST["removeheading"]);
02134                 $this->ctrl->redirect($this, "questions");
02135         }
02136         
02144         function cancelRemoveHeadingObject()
02145         {
02146                 $this->ctrl->redirect($this, "questions");
02147         }
02148         
02156         function confirmRemoveHeadingForm()
02157         {
02158                 sendInfo($this->lng->txt("confirm_remove_heading"));
02159                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_confirm_removeheading.html", true);
02160                 $this->tpl->setCurrentBlock("adm_content");
02161                 $this->tpl->setVariable("BTN_CONFIRM_REMOVE", $this->lng->txt("confirm"));
02162                 $this->tpl->setVariable("BTN_CANCEL_REMOVE", $this->lng->txt("cancel"));
02163                 $this->tpl->setVariable("REMOVE_HEADING", $_GET["removeheading"]);
02164                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
02165                 $this->tpl->parseCurrentBlock();
02166         }
02167         
02168         
02176         function questionsObject() {
02177                 global $rbacsystem;
02178 
02179                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
02180                 {
02181                         // allow only read and write access
02182                         sendInfo($this->lng->txt("cannot_edit_survey"), true);
02183                         $path = $this->tree->getPathFull($this->object->getRefID());
02184                         ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
02185                         return;
02186                 }
02187                 if ($_GET["new_id"] > 0)
02188                 {
02189                         // add a question to the survey previous created in a questionpool
02190                         $this->object->insertQuestion($_GET["new_id"]);
02191                 }
02192                 
02193                 if ($_GET["eqid"] and $_GET["eqpl"])
02194                 {
02195                         ilUtil::redirect("questionpool.php?ref_id=" . $_GET["eqpl"] . "&cmd=editQuestionForSurvey&calling_survey=".$_GET["ref_id"]."&q_id=" . $_GET["eqid"]);
02196                 }
02197 
02198 
02199                 $_SESSION["calling_survey"] = $this->object->getRefId();
02200                 unset($_SESSION["survey_id"]);
02201     $add_parameter = $this->getAddParameter();
02202 
02203                 if ($_GET["editheading"])
02204                 {
02205                         $this->addHeadingObject($_GET["editheading"]);
02206                         return;
02207                 }
02208                 
02209                 if ($_GET["up"] > 0)
02210                 {
02211                         $this->object->moveUpQuestion($_GET["up"]);
02212                 }
02213                 if ($_GET["down"] > 0)
02214                 {
02215                         $this->object->moveDownQuestion($_GET["down"]);
02216                 }
02217                 if ($_GET["qbup"] > 0)
02218                 {
02219                         $this->object->moveUpQuestionblock($_GET["qbup"]);
02220                 }
02221                 if ($_GET["qbdown"] > 0)
02222                 {
02223                         $this->object->moveDownQuestionblock($_GET["qbdown"]);
02224                 }
02225                 
02226                 if ($_POST["cmd"]["addHeading"])
02227                 {
02228                         $this->addHeadingObject();
02229                         return;
02230                 }
02231                 
02232                 if ($_POST["cmd"]["saveObligatory"])
02233                 {
02234                         $obligatory = array();
02235                         foreach ($_POST as $key => $value)
02236                         {
02237                                 if (preg_match("/obligatory_(\d+)/", $key, $matches))
02238                                 {
02239                                         $obligatory[$matches[1]] = 1;
02240                                 }
02241                         }
02242                         $this->object->setObligatoryStates($obligatory);
02243                 }
02244                 
02245                 if ($_POST["cmd"]["insert_before"] or $_POST["cmd"]["insert_after"])
02246                 {
02247                         // get all questions to move
02248                         $move_questions = array();
02249                         foreach ($_POST as $key => $value)
02250                         {
02251                                 if (preg_match("/^move_(\d+)$/", $key, $matches))
02252                                 {
02253                                         array_push($move_questions, $value);
02254                                 }
02255                         }
02256                         // get insert point
02257                         $insert_id = -1;
02258                         foreach ($_POST as $key => $value)
02259                         {
02260                                 if (preg_match("/^cb_(\d+)$/", $key, $matches))
02261                                 {
02262                                         if ($insert_id < 0)
02263                                         {
02264                                                 $insert_id = $matches[1];
02265                                         }
02266                                 }
02267                                 if (preg_match("/^cb_qb_(\d+)$/", $key, $matches))
02268                                 {
02269                                         if ($insert_id < 0)
02270                                         {
02271                                                 $ids =& $this->object->getQuestionblockQuestionIds($matches[1]);
02272                                                 if (count($ids))
02273                                                 {
02274                                                         if ($_POST["cmd"]["insert_before"])
02275                                                         {
02276                                                                 $insert_id = $ids[0];
02277                                                         }
02278                                                         else if ($_POST["cmd"]["insert_after"])
02279                                                         {
02280                                                                 $insert_id = $ids[count($ids)-1];
02281                                                         }
02282                                                 }
02283                                         }
02284                                 }
02285                         }
02286                         if ($insert_id <= 0)
02287                         {
02288                                 sendInfo($this->lng->txt("no_target_selected_for_move"));
02289                         }
02290                         else
02291                         {
02292                                 $insert_mode = 1;
02293                                 if ($_POST["cmd"]["insert_before"])
02294                                 {
02295                                         $insert_mode = 0;
02296                                 }
02297                                 $this->object->moveQuestions($move_questions, $insert_id, $insert_mode);
02298                         }
02299                 }
02300 
02301                 if ($_GET["removeheading"])
02302                 {
02303                         $this->confirmRemoveHeadingForm();
02304                         return;
02305                 }
02306                 
02307                 if ($_GET["editblock"])
02308                 {
02309                         $this->defineQuestionblock($_GET["editblock"]);
02310                         return;
02311                 }
02312 
02313                 if ($_POST["cmd"]["questionblock"])
02314                 {
02315                         $questionblock = array();
02316                         foreach ($_POST as $key => $value)
02317                         {
02318                                 if (preg_match("/cb_(\d+)/", $key, $matches))
02319                                 {
02320                                         array_push($questionblock, $value);
02321                                 }
02322                         }
02323                         if (count($questionblock) < 2)
02324                         {
02325         sendInfo($this->lng->txt("qpl_define_questionblock_select_missing"));
02326                         }
02327                         else
02328                         {
02329                                 $this->defineQuestionblock();
02330                                 return;
02331                         }
02332                 }
02333 
02334                 if ($_POST["cmd"]["unfold"])
02335                 {
02336                         $unfoldblocks = array();
02337                         foreach ($_POST as $key => $value)
02338                         {
02339                                 if (preg_match("/cb_qb_(\d+)/", $key, $matches))
02340                                 {
02341                                         array_push($unfoldblocks, $matches[1]);
02342                                 }
02343                         }
02344                         if (count($unfoldblocks))
02345                         {
02346                                 $this->object->unfoldQuestionblocks($unfoldblocks);
02347                         }
02348                         else
02349                         {
02350         sendInfo($this->lng->txt("qpl_unfold_select_none"));
02351                         }
02352                 }
02353 
02354                 if ($_POST["cmd"]["save_questionblock"])
02355                 {
02356                         if ($_POST["title"])
02357                         {
02358                                 if ($_POST["questionblock_id"])
02359                                 {
02360                                         $this->object->modifyQuestionblock($_POST["questionblock_id"], ilUtil::stripSlashes($_POST["title"]));
02361                                 }
02362                                 else
02363                                 {
02364                                         $questionblock = array();
02365                                         foreach ($_POST as $key => $value)
02366                                         {
02367                                                 if (preg_match("/cb_(\d+)/", $key, $matches))
02368                                                 {
02369                                                         array_push($questionblock, $value);
02370                                                 }
02371                                         }
02372                                         $this->object->createQuestionblock(ilUtil::stripSlashes($_POST["title"]), $questionblock);
02373                                 }
02374                         }
02375                         else
02376                         {
02377                                 sendInfo($this->lng->txt("enter_questionblock_title"));
02378                                 $this->defineQuestionblock();
02379                                 return;
02380                         }
02381                 }
02382 
02383                 $add_constraint = 0;
02384                 $delete_constraint = 0;
02385                 foreach ($_POST as $key => $value) {
02386                         if (preg_match("/add_constraint_(\d+)/", $key, $matches)) {
02387                                 $add_constraint = 1;
02388                         }
02389                 }
02390                 foreach ($_POST as $key => $value) {
02391                         if (preg_match("/delete_constraint_(\d+)_(\d+)/", $key, $matches)) {
02392                                 $delete_constraint = 1;
02393                         }
02394                 }
02395                 if ($_POST["cmd"]["constraints"] or $add_constraint or $delete_constraint or $_GET["constraints"])
02396                 {
02397                         $checked_questions = array();
02398                         $checked_questionblocks = array();
02399                         if ($_GET["constraints"])
02400                         {
02401                                 $survey_questions =& $this->object->getSurveyQuestions();
02402                                 if (strcmp($survey_questions[$_GET["constraints"]]["questionblock_id"], "") == 0)
02403                                 {
02404                                         array_push($checked_questions, $_GET["constraints"]);
02405                                 }
02406                                 else
02407                                 {
02408                                         array_push($checked_questionblocks, $survey_questions[$_GET["constraints"]]["questionblock_id"]);
02409                                 }
02410                         }
02411                         foreach ($_POST as $key => $value) {
02412                                 if (preg_match("/cb_(\d+)/", $key, $matches)) {
02413                                         array_push($checked_questions, $matches[1]);
02414                                 }
02415                                 if (preg_match("/cb_qb_(\d+)/", $key, $matches)) {
02416                                         array_push($checked_questionblocks, $matches[1]);
02417                                 }
02418                         }
02419                         if ($_POST["cmd"]["constraints"] and (count($checked_questions)+count($checked_questionblocks) == 0))
02420                         {
02421                                 sendInfo($this->lng->txt("no_constraints_checked"));
02422                         }
02423                         else
02424                         {
02425                                 $this->constraintsForm($checked_questions, $checked_questionblocks);
02426                                 return;
02427                         }
02428                 }
02429 
02430                 if ($_POST["cmd"]["create_question"]) {
02431                         $this->questionpoolSelectForm();
02432                         return;
02433                 }
02434 
02435                 if ($_POST["cmd"]["create_question_execute"])
02436                 {
02437                         ilUtil::redirect("questionpool.php?ref_id=" . $_POST["sel_spl"] . "&cmd=createQuestionForSurvey&new_for_survey=".$_GET["ref_id"]."&sel_question_types=".$_POST["sel_question_types"]);
02438                         exit();
02439                 }
02440 
02441                 if ($_GET["add"])
02442                 {
02443                         // called after a new question was created from a questionpool
02444                         $selected_array = array();
02445                         array_push($selected_array, $_GET["add"]);
02446 //                      $total = $this->object->evalTotalPersons();
02447 //                      if ($total) {
02448                                 // the test was executed previously
02449 //                              sendInfo(sprintf($this->lng->txt("tst_insert_questions_and_results"), $total));
02450 //                      } else {
02451                                 sendInfo($this->lng->txt("ask_insert_questions"));
02452 //                      }
02453                         $this->insertQuestionsForm($selected_array);
02454                         return;
02455                 }
02456 
02457                 if (($_POST["cmd"]["search_question"]) or ($_GET["search_question"]) and (!$_POST["cmd"]["insert"]))
02458                 {
02459                         $this->searchQuestionsForm();
02460                         return;
02461                 }
02462 
02463                 if (($_POST["cmd"]["insert_question"]) or ($_GET["insert_question"])) {
02464                         $show_questionbrowser = true;
02465                         if ($_POST["cmd"]["insert"]) {
02466                                 // insert selected questions into test
02467                                 $selected_array = array();
02468                                 foreach ($_POST as $key => $value) {
02469                                         if (preg_match("/cb_(\d+)/", $key, $matches)) {
02470                                                 array_push($selected_array, $matches[1]);
02471                                         }
02472                                 }
02473                                 if (!count($selected_array)) {
02474                                         if ($_GET["browsetype"] == 1)
02475                                         {
02476                                                 sendInfo($this->lng->txt("insert_missing_question"));
02477                                         }
02478                                         else
02479                                         {
02480                                                 sendInfo($this->lng->txt("insert_missing_questionblock"));
02481                                         }
02482                                 } else {
02483 //                                      $total = $this->object->evalTotalPersons();
02484 //                                      if ($total) {
02485                                                 // the test was executed previously
02486 //                                              sendInfo(sprintf($this->lng->txt("tst_insert_questions_and_results"), $total));
02487 //                                      } else {
02488                                                 if ($_GET["browsetype"] == 1)
02489                                                 {
02490                                                         sendInfo($this->lng->txt("ask_insert_questions"));
02491                                                 }
02492                                                 else
02493                                                 {
02494                                                         sendInfo($this->lng->txt("ask_insert_questionblocks"));
02495                                                 }
02496 //                                      }
02497                                         $this->insertQuestionsForm($selected_array);
02498                                         return;
02499                                 }
02500                         }
02501                         if ($_POST["cmd"]["back"]) {
02502                                 $show_questionbrowser = false;
02503                         }
02504                         if ($show_questionbrowser) {
02505                                 $this->questionBrowser();
02506                                 return;
02507                         }
02508                 }
02509 
02510                 if (strlen($_POST["cmd"]["confirm_remove"]) > 0)
02511                 {
02512                         // remove questions from test after confirmation
02513                         sendInfo($this->lng->txt("questions_removed"));
02514                         $checked_questions = array();
02515                         $checked_questionblocks = array();
02516                         foreach ($_POST as $key => $value) {
02517                                 if (preg_match("/id_(\d+)/", $key, $matches)) {
02518                                         array_push($checked_questions, $matches[1]);
02519                                 }
02520                                 if (preg_match("/id_qb_(\d+)/", $key, $matches)) {
02521                                         array_push($checked_questionblocks, $matches[1]);
02522                                 }
02523                         }
02524                         $this->object->removeQuestions($checked_questions, $checked_questionblocks);
02525                         $this->object->saveCompletionStatus();
02526                 }
02527 
02528                 if (strlen($_POST["cmd"]["remove"]) > 0) {
02529                         $checked_questions = array();
02530                         $checked_questionblocks = array();
02531                         foreach ($_POST as $key => $value) {
02532                                 if (preg_match("/cb_(\d+)/", $key, $matches)) {
02533                                         array_push($checked_questions, $matches[1]);
02534                                 }
02535                                 if (preg_match("/cb_qb_(\d+)/", $key, $matches))
02536                                 {
02537                                         array_push($checked_questionblocks, $matches[1]);
02538                                 }
02539                         }
02540                         if (count($checked_questions) + count($checked_questionblocks) > 0) {
02541                                 sendInfo($this->lng->txt("remove_questions"));
02542                                 $this->removeQuestionsForm($checked_questions, $checked_questionblocks);
02543                                 return;
02544                         } else {
02545                                 sendInfo($this->lng->txt("no_question_selected_for_removal"));
02546                         }
02547                 }
02548 
02549                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_questions.html", true);
02550 
02551                 $survey_questions =& $this->object->getSurveyQuestions();
02552                 $questionblock_titles =& $this->object->getQuestionblockTitles();
02553                 $questionpools =& $this->object->getQuestionpoolTitles();
02554                 $colors = array("tblrow1", "tblrow2");
02555                 $counter = 0;
02556                 $title_counter = 0;
02557                 $obligatory = "<img src=\"" . ilUtil::getImagePath("obligatory.gif", true) . "\" alt=\"" . $this->lng->txt("question_obligatory") . "\" title=\"" . $this->lng->txt("question_obligatory") . "\" />";
02558                 if (count($survey_questions) > 0)
02559                 {
02560                         foreach ($survey_questions as $question_id => $data)
02561                         {
02562                                 $title_counter++;
02563                                 if (($data["questionblock_id"] > 0) and ($data["questionblock_id"] != $last_questionblock_id))
02564                                 {
02565                                         if (($data["questionblock_id"] != $last_questionblock_id) and (strcmp($last_questionblock_id, "") != 0))
02566                                         {
02567                                                 $counter++;
02568                                         }
02569                                         $this->tpl->setCurrentBlock("block");
02570                                         $this->tpl->setVariable("TEXT_QUESTIONBLOCK", $this->lng->txt("questionblock") . ": " . $data["questionblock_title"]);
02571                                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
02572                                         if ($rbacsystem->checkAccess("write", $this->ref_id) and ($this->object->isOffline())) {
02573                                                 if ($data["question_id"] != $this->object->questions[0])
02574                                                 {
02575                                                         $this->tpl->setVariable("BUTTON_UP", "<a href=\"" . $this->getCallingScript() . "$add_parameter&qbup=" . $data["questionblock_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_up.gif") . "\" alt=\"" . $this->lng->txt("up") . "\" title=\"" . $this->lng->txt("up") . "\" border=\"0\" /></a>");
02576                                                 }
02577                                                 $akeys = array_keys($survey_questions);
02578                                                 if ($data["questionblock_id"] != $survey_questions[$akeys[count($akeys)-1]]["questionblock_id"])
02579                                                 {
02580                                                         $this->tpl->setVariable("BUTTON_DOWN", "<a href=\"" . $this->getCallingScript() . "$add_parameter&qbdown=" . $data["questionblock_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_down.gif") . "\" alt=\"" . $this->lng->txt("down") . "\" title=\"" . $this->lng->txt("down") . "\" border=\"0\" /></a>");
02581                                                 }
02582                                                 $this->tpl->setVariable("TEXT_EDIT", "<img src=\"" . ilUtil::getImagePath("icon_pencil.gif") . "\" alt=\"" . $this->lng->txt("edit") . "\" title=\"" . $this->lng->txt("edit") . "\" border=\"0\" />");
02583                                                 $this->tpl->setVariable("HREF_EDIT", $this->getCallingScript() . "$add_parameter&editblock=" . $data["questionblock_id"]);
02584                                         }
02585                                         if (count($data["constraints"]))
02586                                         {
02587                                                 $this->tpl->setVariable("QUESTION_CONSTRAINTS", "<a href=\"" . $this->getCallingScript() . "$add_parameter&constraints=" . $data["question_id"] . "\">" . $this->lng->txt("questionblock_has_constraints") . "</a>");
02588                                         }
02589                                         $this->tpl->parseCurrentBlock();
02590                                         $this->tpl->setCurrentBlock("QTab");
02591                                         $this->tpl->setVariable("QUESTION_ID", "qb_" . $data["questionblock_id"]);
02592                                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
02593                                         $this->tpl->parseCurrentBlock();
02594                                         $counter++;
02595                                 }
02596                                 if ($data["heading"])
02597                                 {
02598                                         $this->tpl->setCurrentBlock("heading");
02599                                         $this->tpl->setVariable("TEXT_HEADING", $data["heading"]);
02600                                         $this->tpl->setVariable("COLOR_CLASS", "std");
02601                                         if ($rbacsystem->checkAccess("write", $this->ref_id) and ($this->object->isOffline())) {
02602                                                 $this->tpl->setVariable("TEXT_EDIT", "<img src=\"" . ilUtil::getImagePath("icon_pencil.gif") . "\" alt=\"" . $this->lng->txt("edit") . "\" title=\"" . $this->lng->txt("edit") . "\" border=\"0\" />");
02603                                                 $this->tpl->setVariable("HREF_EDIT", $this->getCallingScript() . "$add_parameter&editheading=" . $data["question_id"]);
02604                                                 $this->tpl->setVariable("TEXT_DELETE", "<img src=\"" . ilUtil::getImagePath("delete.gif") . "\" alt=\"" . $this->lng->txt("remove") . "\" title=\"" . $this->lng->txt("remove") . "\" border=\"0\" />");
02605                                                 $this->tpl->setVariable("HREF_DELETE", $this->getCallingScript() . "$add_parameter&removeheading=" . $data["question_id"]);
02606                                         }
02607                                         $this->tpl->parseCurrentBlock();
02608                                         $this->tpl->setCurrentBlock("QTab");
02609 //                                      $this->tpl->setVariable("QUESTION_ID", "qb_" . $data["questionblock_id"]);
02610                                         $this->tpl->setVariable("COLOR_CLASS", "std");
02611                                         $this->tpl->parseCurrentBlock();
02612                                 }
02613                                 if (!$data["questionblock_id"])
02614                                 {
02615                                         $this->tpl->setCurrentBlock("checkable");
02616                                         $this->tpl->setVariable("QUESTION_ID", $data["question_id"]);
02617                                         $this->tpl->parseCurrentBlock();
02618                                 }
02619                                 $this->tpl->setCurrentBlock("QTab");
02620                                 $ref_id = SurveyQuestion::_getRefIdFromObjId($data["obj_fi"]);
02621                                 if ($rbacsystem->checkAccess("write", $this->ref_id) and ($this->object->isOffline())) 
02622                                 {
02623                                         $q_id = $data["question_id"];
02624                                         $qpl_ref_id = $this->object->_getRefIdFromObjId($data["obj_fi"]);
02625                                         $this->tpl->setVariable("QUESTION_TITLE", "$title_counter. <a href=\"" . $this->getCallingScript() . $add_parameter . "&eqid=$q_id&eqpl=$qpl_ref_id" . "\">" . $data["title"] . "</a>");
02626 //                                      $this->tpl->setVariable("QUESTION_TITLE", "$title_counter. <a href=\"questionpool.php?ref_id=" . $ref_id . "&cmd=questions&edit=" . $data["question_id"] . "\">" . $data["title"] . "</a>");
02627                                 }
02628                                 else
02629                                 {
02630                                         $this->tpl->setVariable("QUESTION_TITLE", "$title_counter. ". $data["title"]);
02631                                 }
02632 
02633                                 if ($rbacsystem->checkAccess("write", $this->ref_id) and ($this->object->isOffline())) 
02634                                 {
02635                                         $obligatory_checked = "";
02636                                         if ($data["obligatory"] == 1)
02637                                         {
02638                                                 $obligatory_checked = " checked=\"checked\"";
02639                                         }
02640                                         $this->tpl->setVariable("QUESTION_OBLIGATORY", "<input type=\"checkbox\" name=\"obligatory_" . $data["question_id"] . "\" value=\"1\"$obligatory_checked />");
02641                                 }
02642                                 else
02643                                 {
02644                                         if ($data["obligatory"] == 1)
02645                                         {
02646                                                 $this->tpl->setVariable("QUESTION_OBLIGATORY", $obligatory);
02647                                         }
02648                                 }
02649                                 $this->tpl->setVariable("QUESTION_COMMENT", $data["description"]);
02650                                 if ($rbacsystem->checkAccess("write", $this->ref_id) and ($this->object->isOffline())) {
02651                                         if (!$data["questionblock_id"])
02652                                         {
02653                                                 // up/down buttons for non-questionblock questions
02654                                                 if ($data["question_id"] != $this->object->questions[0])
02655                                                 {
02656                                                         $this->tpl->setVariable("BUTTON_UP", "<a href=\"" . $this->getCallingScript() . "$add_parameter&up=" . $data["question_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_up.gif") . "\" alt=\"Up\" border=\"0\" /></a>");
02657                                                 }
02658                                                 if ($data["question_id"] != $this->object->questions[count($this->object->questions)-1])
02659                                                 {
02660                                                         $this->tpl->setVariable("BUTTON_DOWN", "<a href=\"" . $this->getCallingScript() . "$add_parameter&down=" . $data["question_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_down.gif") . "\" alt=\"Down\" border=\"0\" /></a>");
02661                                                 }
02662                                         }
02663                                         else
02664                                         {
02665                                                 // up/down buttons for questionblock questions
02666                                                 if ($data["questionblock_id"] == $last_questionblock_id)
02667                                                 {
02668                                                         $this->tpl->setVariable("BUTTON_UP", "<a href=\"" . $this->getCallingScript() . "$add_parameter&up=" . $data["question_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_up.gif") . "\" alt=\"Up\" border=\"0\" /></a>");
02669                                                 }
02670                                                 $tmp_questions = array_keys($survey_questions);
02671                                                 $blockkey = array_search($question_id, $tmp_questions);
02672                                                 if (($blockkey !== FALSE) && ($blockkey < count($tmp_questions)-1))
02673                                                 {
02674                                                         if ($data["questionblock_id"] == $survey_questions[$tmp_questions[$blockkey+1]]["questionblock_id"])
02675                                                         {
02676                                                                 $this->tpl->setVariable("BUTTON_DOWN", "<a href=\"" . $this->getCallingScript() . "$add_parameter&down=" . $data["question_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_down.gif") . "\" alt=\"Down\" border=\"0\" /></a>");
02677                                                         }
02678                                                 }
02679                                         }
02680                                 }
02681                                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt($data["type_tag"]));
02682                                 $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
02683                                 if (count($data["constraints"]) and (strcmp($data["questionblock_id"], "") == 0))
02684                                 {
02685                                         $this->tpl->setVariable("QUESTION_CONSTRAINTS", "<a href=\"" . $this->getCallingScript() . "$add_parameter&constraints=" . $data["question_id"] . "\">" . $this->lng->txt("question_has_constraints") . "</a>");
02686                                 }
02687                                 $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
02688                                 if (!$data["questionblock_id"])
02689                                 {
02690                                         $counter++;
02691                                 }
02692                                 $this->tpl->parseCurrentBlock();
02693                                 $last_questionblock_id = $data["questionblock_id"];
02694                         }
02695                 }
02696 
02697                 $checked_move = 0;
02698                 if ($_POST["cmd"]["move"])
02699                 {
02700                         foreach ($_POST as $key => $value)
02701                         {
02702                                 if (preg_match("/cb_(\d+)/", $key, $matches))
02703                                 {
02704                                         $checked_move++;
02705                                         $this->tpl->setCurrentBlock("move");
02706                                         $this->tpl->setVariable("MOVE_COUNTER", $matches[1]);
02707                                         $this->tpl->setVariable("MOVE_VALUE", $matches[1]);
02708                                         $this->tpl->parseCurrentBlock();
02709                                 }
02710                                 if (preg_match("/cb_qb_(\d+)/", $key, $matches))
02711                                 {
02712                                         $checked_move++;
02713                                         $ids = $this->object->getQuestionblockQuestionIds($matches[1]);
02714                                         foreach ($ids as $qkey => $qid)
02715                                         {
02716                                                 $this->tpl->setCurrentBlock("move");
02717                                                 $this->tpl->setVariable("MOVE_COUNTER", $qid);
02718                                                 $this->tpl->setVariable("MOVE_VALUE", $qid);
02719                                                 $this->tpl->parseCurrentBlock();
02720                                         }
02721                                 }
02722                         }
02723                         if ($checked_move)
02724                         {
02725                                 sendInfo($this->lng->txt("select_target_position_for_move_question"));
02726                                 $this->tpl->setCurrentBlock("move_buttons");
02727                                 $this->tpl->setVariable("INSERT_BEFORE", $this->lng->txt("insert_before"));
02728                                 $this->tpl->setVariable("INSERT_AFTER", $this->lng->txt("insert_after"));
02729                                 $this->tpl->parseCurrentBlock();
02730                         }
02731                         else
02732                         {
02733                                 sendInfo($this->lng->txt("no_question_selected_for_move"));
02734                         }
02735                 }
02736 
02737 
02738                 if ($counter == 0) {
02739                         $this->tpl->setCurrentBlock("Emptytable");
02740                         $this->tpl->setVariable("TEXT_EMPTYTABLE", $this->lng->txt("no_questions_available"));
02741                         $this->tpl->parseCurrentBlock();
02742                 } else {
02743             if ($rbacsystem->checkAccess("write", $this->ref_id) and (!$this->object->getStatus() == STATUS_ONLINE)) {
02744                                 $this->tpl->setCurrentBlock("QFooter");
02745                                 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"\">");
02746                                 $this->tpl->setVariable("REMOVE", $this->lng->txt("remove_question"));
02747                                 $this->tpl->setVariable("MOVE", $this->lng->txt("move"));
02748                                 $this->tpl->setVariable("SAVE", $this->lng->txt("save_obligatory_state"));
02749                                 $this->tpl->setVariable("QUESTIONBLOCK", $this->lng->txt("define_questionblock"));
02750                                 $this->tpl->setVariable("UNFOLD", $this->lng->txt("unfold"));
02751                                 $this->tpl->setVariable("CONSTRAINTS", $this->lng->txt("constraints"));
02752                                 $this->tpl->setVariable("HEADING", $this->lng->txt("add_heading"));
02753                                 $this->tpl->parseCurrentBlock();
02754                         }
02755                 }
02756 
02757     if ($rbacsystem->checkAccess("write", $this->ref_id) and (!$this->object->getStatus() == STATUS_ONLINE)) {
02758                         $this->tpl->setCurrentBlock("QTypes");
02759                         $query = "SELECT * FROM survey_questiontype";
02760                         $query_result = $this->ilias->db->query($query);
02761                         while ($data = $query_result->fetchRow(DB_FETCHMODE_OBJECT))
02762                         {
02763                                 $this->tpl->setVariable("QUESTION_TYPE_ID", $data->type_tag);
02764                                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt($data->type_tag));
02765                                 $this->tpl->parseCurrentBlock();
02766                         }
02767                         $this->tpl->parseCurrentBlock();
02768                 }
02769                 $this->tpl->setCurrentBlock("adm_content");
02770                 $this->tpl->setVariable("FORM_ACTION", $this->getCallingScript() . $add_parameter);
02771                 $this->tpl->setVariable("QUESTION_TITLE", $this->lng->txt("title"));
02772                 $this->tpl->setVariable("QUESTION_COMMENT", $this->lng->txt("description"));
02773                 $this->tpl->setVariable("QUESTION_OBLIGATORY", $this->lng->txt("obligatory"));
02774                 $this->tpl->setVariable("QUESTION_CONSTRAINTS", $this->lng->txt("constraints"));
02775                 $this->tpl->setVariable("QUESTION_SEQUENCE", $this->lng->txt("sequence"));
02776                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("question_type"));
02777                 $this->tpl->setVariable("QUESTION_AUTHOR", $this->lng->txt("author"));
02778                 $this->tpl->setVariable("TEXT_EDIT", $this->lng->txt("edit"));
02779 
02780     if ($rbacsystem->checkAccess("write", $this->ref_id) and (!$this->object->getStatus() == STATUS_ONLINE)) {
02781                         $this->tpl->setVariable("BUTTON_INSERT_QUESTION", $this->lng->txt("browse_for_questions"));
02782                         $this->tpl->setVariable("BUTTON_SEARCH_QUESTION", $this->lng->txt("search_questions"));
02783                         $this->tpl->setVariable("TEXT_OR", " " . strtolower($this->lng->txt("or")));
02784                         $this->tpl->setVariable("TEXT_CREATE_NEW", " " . strtolower($this->lng->txt("or")) . " " . $this->lng->txt("create_new"));
02785                         $this->tpl->setVariable("BUTTON_CREATE_QUESTION", $this->lng->txt("create"));
02786                 }
02787                 if ($this->object->getStatus() == STATUS_ONLINE)
02788                 {
02789                         sendInfo($this->lng->txt("survey_online_warning"));
02790                 }
02791 
02792                 $this->tpl->parseCurrentBlock();
02793         }
02794 
02795         function printEvaluationObject()
02796         {
02797                 if (strcmp($_POST["evaltype"], "user") == 0)
02798                 {
02799                         $this->evaluationuserObject(1);
02800                 }
02801                 else
02802                 {
02803                         $this->evaluationObject($_POST["detail"], 1);
02804                 }
02805                 exit;
02806         }
02807 
02808         function evaluationuserObject($print = 0)
02809         {
02810                 if (!is_array($_POST))
02811                 {
02812                         $_POST = array();
02813                 }
02814                 $result = @include_once 'Spreadsheet/Excel/Writer.php';
02815                 if (!$result)
02816                 {
02817                         include_once './classes/Spreadsheet/Excel/Writer.php';
02818                 }
02819                 $format_bold = "";
02820                 $format_percent = "";
02821                 $format_datetime = "";
02822                 $format_title = "";
02823                 $format_title_plain = "";
02824                 if ($print)
02825                 {
02826                         unset($_POST["export_format"]);
02827                 }
02828                 $object_title = preg_replace("/[^a-zA-Z0-9\s]/", "", $this->object->getTitle());
02829                 $surveyname = preg_replace("/\s/", "_", $object_title);
02830 
02831                 if (!$_POST["export_format"])
02832                 {
02833                         $_POST["export_format"] = TYPE_PRINT;
02834                 }
02835 
02836                 $eval =& $this->object->getEvaluationForAllUsers();
02837                 if (!$print)
02838                 {
02839                         $this->setEvalTabs();
02840                         sendInfo();
02841                         $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_evaluation_user.html", true);
02842                 }
02843                 else
02844                 {
02845                         $this->tpl = new ilTemplate("./survey/templates/default/tpl.il_svy_svy_evaluationuser_preview.html", true, true);
02846                 }
02847                 $counter = 0;
02848                 $classes = array("tblrow1top", "tblrow2top");
02849                 $csvrow = array();
02850                 $questions =& $this->object->getSurveyQuestions(true);
02851                 $this->tpl->setCurrentBlock("headercell");
02852                 $this->tpl->setVariable("TEXT_HEADER_CELL", $this->lng->txt("username"));
02853                 $this->tpl->parseCurrentBlock();
02854                 if (array_key_exists("export_format", $_POST))
02855                 {
02856                         array_push($csvrow, $this->lng->txt("username"));
02857                 }
02858                 $char = "A";
02859                 $cellcounter = 1;
02860                 foreach ($questions as $question_id => $question_data)
02861                 {
02862                         $this->tpl->setCurrentBlock("headercell");
02863                         $this->tpl->setVariable("TEXT_HEADER_CELL", $char);
02864                         $this->tpl->parseCurrentBlock();
02865                         $this->tpl->setCurrentBlock("legendrow");
02866                         $this->tpl->setVariable("TEXT_KEY", $char++);
02867                         $this->tpl->setVariable("TEXT_VALUE", $question_data["title"]);
02868                         if (array_key_exists("export_format", $_POST))
02869                         {
02870                                 array_push($csvrow, $question_data["title"]);
02871                                 switch ($question_data["questiontype_fi"])
02872                                 {
02873                                         case 1:
02874                                                 if ($question_data["subtype"] == SUBTYPE_MCMR)
02875                                                 {
02876                                                         foreach ($question_data["answers"] as $cat => $cattext)
02877                                                         {
02878                                                                 array_push($csvrow, ($cat+1) . " - $cattext");
02879                                                         }
02880                                                 }
02881                                                 break;
02882                                         case 2:
02883                                         case 3:
02884                                         case 4:
02885                                                 break;
02886                                 }
02887                         }
02888                         $this->tpl->parseCurrentBlock();
02889                 }
02890                 $csvfile = array();
02891                 array_push($csvfile, $csvrow);
02892 
02893                 foreach ($eval as $user_id => $resultset)
02894                 {
02895                         $csvrow = array();
02896                         $this->tpl->setCurrentBlock("bodycell");
02897                         $this->tpl->setVariable("COLOR_CLASS", $classes[$counter % 2]);
02898                         $this->tpl->setVariable("TEXT_BODY_CELL", $resultset["name"]);
02899                         array_push($csvrow, $resultset["name"]);
02900                         $this->tpl->parseCurrentBlock();
02901                         foreach ($questions as $question_id => $question_data)
02902                         {
02903                                 // csv output
02904                                 if (array_key_exists("export_format", $_POST))
02905                                 {
02906                                         switch ($question_data["questiontype_fi"])
02907                                         {
02908                                                 case 1:
02909                                                         // nominal question
02910                                                         if (count($resultset["answers"][$question_id]))
02911                                                         {
02912                                                                 if ($question_data["subtype"] == SUBTYPE_MCMR)
02913                                                                 {
02914                                                                         array_push($csvrow, "");
02915                                                                         foreach ($question_data["answers"] as $cat => $cattext)
02916                                                                         {
02917                                                                                 $found = 0;
02918                                                                                 foreach ($resultset["answers"][$question_id] as $answerdata)
02919                                                                                 {
02920                                                                                         if (strcmp($cat, $answerdata["value"]) == 0)
02921                                                                                         {
02922                                                                                                 $found = 1;
02923                                                                                         }
02924                                                                                 }
02925                                                                                 if ($found)
02926                                                                                 {
02927                                                                                         array_push($csvrow, "1");
02928                                                                                 }
02929                                                                                 else
02930                                                                                 {
02931                                                                                         array_push($csvrow, "0");
02932                                                                                 }
02933                                                                         }
02934                                                                 }
02935                                                                 else
02936                                                                 {
02937                                                                         array_push($csvrow, $resultset["answers"][$question_id][0]["value"]);
02938                                                                 }
02939                                                         }
02940                                                         else
02941                                                         {
02942                                                                 array_push($csvrow, $this->lng->txt("skipped"));
02943                                                                 if ($question_data["subtype"] == SUBTYPE_MCMR)
02944                                                                 {
02945                                                                         foreach ($question_data["answers"] as $cat => $cattext)
02946                                                                         {
02947                                                                                 array_push($csvrow, "");
02948                                                                         }
02949                                                                 }
02950                                                         }
02951                                                         break;
02952                                                 case 2:
02953                                                         // ordinal question
02954                                                         if (count($resultset["answers"][$question_id]))
02955                                                         {
02956                                                                 foreach ($resultset["answers"][$question_id] as $key => $answer)
02957                                                                 {
02958                                                                         array_push($csvrow, $answer["value"]);
02959                                                                 }
02960                                                         }
02961                                                         else
02962                                                         {
02963                                                                 array_push($csvrow, $this->lng->txt("skipped"));
02964                                                         }
02965                                                         break;
02966                                                 case 3:
02967                                                         // metric question
02968                                                         if (count($resultset["answers"][$question_id]))
02969                                                         {
02970                                                                 foreach ($resultset["answers"][$question_id] as $key => $answer)
02971                                                                 {
02972                                                                         array_push($csvrow, $answer["value"]);
02973                                                                 }
02974                                                         }
02975                                                         else
02976                                                         {
02977                                                                 array_push($csvrow, $this->lng->txt("skipped"));
02978                                                         }
02979                                                         break;
02980                                                 case 4:
02981                                                         // text question
02982                                                         if (count($resultset["answers"][$question_id]))
02983                                                         {
02984                                                                 foreach ($resultset["answers"][$question_id] as $key => $answer)
02985                                                                 {
02986                                                                         array_push($csvrow, $answer["textanswer"]);
02987                                                                 }
02988                                                         }
02989                                                         else
02990                                                         {
02991                                                                 array_push($csvrow, $this->lng->txt("skipped"));
02992                                                         }
02993                                                         break;
02994                                         }
02995                                 }
02996                                 // html output
02997                                 if (count($resultset["answers"][$question_id]))
02998                                 {
02999                                         $answervalues = array();
03000                                         foreach ($resultset["answers"][$question_id] as $key => $answer)
03001                                         {
03002                                                 switch ($question_data["questiontype_fi"])
03003                                                 {
03004                                                         case 1:
03005                                                                 // nominal question
03006                                                                 if (strcmp($answer["value"], "") != 0)
03007                                                                 {
03008                                                                         array_push($answervalues, ($answer["value"]+1) . " - " . ilUtil::prepareFormOutput($questions[$question_id]["answers"][$answer["value"]]));
03009                                                                 }
03010                                                                 break;
03011                                                         case 2:
03012                                                                 // ordinal question
03013                                                                 array_push($answervalues, ($answer["value"]+1) . " - " . ilUtil::prepareFormOutput($questions[$question_id]["answers"][$answer["value"]]));
03014                                                                 break;
03015                                                         case 3:
03016                                                                 // metric question
03017                                                                 array_push($answervalues, $answer["value"]);
03018                                                                 break;
03019                                                         case 4:
03020                                                                 // text question
03021                                                                 array_push($answervalues, $answer["textanswer"]);
03022                                                                 break;
03023                                                 }
03024                                         }
03025                                         $this->tpl->setCurrentBlock("bodycell");
03026                                         $this->tpl->setVariable("COLOR_CLASS", $classes[$counter % 2]);
03027                                         $this->tpl->setVariable("TEXT_BODY_CELL", join($answervalues, "<br />"));
03028                                         $this->tpl->parseCurrentBlock();
03029                                 }
03030                                 else
03031                                 {
03032                                         $this->tpl->setCurrentBlock("bodycell");
03033                                         $this->tpl->setVariable("COLOR_CLASS", $classes[$counter % 2]);
03034                                         $this->tpl->setVariable("TEXT_BODY_CELL", $this->lng->txt("skipped"));
03035                                         $this->tpl->parseCurrentBlock();
03036                                 }
03037                         }
03038                         $this->tpl->setCurrentBlock("row");
03039                         $this->tpl->parse("row");
03040                         $counter++;
03041                         array_push($csvfile, $csvrow);
03042                 }
03043                 if (!$print)
03044                 {
03045                         $this->tpl->setCurrentBlock("adm_content");
03046                 }
03047                 else
03048                 {
03049                         $this->tpl->setCurrentBlock("__global__");
03050                         $this->tpl->setVariable("TXT_STATISTICAL_EVALUATION", $this->lng->txt("svy_statistical_evaluation") . " " . $this->lng->txt("of") . " " . $this->object->getTitle());
03051                         $this->tpl->setVariable("PRINT_CSS", "./templates/default/print.css");
03052                         $this->tpl->setVariable("PRINT_TYPE", "summary");
03053                 }
03054                 $this->tpl->setVariable("EXPORT_DATA", $this->lng->txt("export_data_as"));
03055                 $this->tpl->setVariable("TEXT_EXCEL", $this->lng->txt("exp_type_excel"));
03056                 $this->tpl->setVariable("TEXT_EXCEL_MAC", $this->lng->txt("exp_type_excel_mac"));
03057                 $this->tpl->setVariable("TEXT_CSV", $this->lng->txt("exp_type_csv"));
03058                 $this->tpl->setVariable("BTN_EXPORT", $this->lng->txt("export"));
03059                 $this->tpl->setVariable("BTN_PRINT", $this->lng->txt("print"));
03060                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
03061                 $this->tpl->setVariable("PRINT_ACTION", $this->ctrl->getFormAction($this));
03062                 $this->tpl->setVariable("TEXT_LEGEND", $this->lng->txt("legend"));
03063                 $this->tpl->setVariable("TEXT_LEGEND_LINK", $this->lng->txt("eval_legend_link"));
03064                 $this->tpl->setVariable("CMD_EXPORT", "evaluationuser");
03065                 $this->tpl->parseCurrentBlock();
03066                 switch ($_POST["export_format"])
03067                 {
03068                         case TYPE_XLS:
03069                         case TYPE_XLS_MAC:
03070                                 // Let's send the file
03071                                 // Creating a workbook
03072                                 include_once ("./classes/class.ilExcelUtils.php");
03073                                 $workbook = new Spreadsheet_Excel_Writer();
03074 
03075                                 // sending HTTP headers
03076                                 $workbook->send("$surveyname.xls");
03077 
03078                                 // Creating a worksheet
03079                                 $format_bold =& $workbook->addFormat();
03080                                 $format_bold->setBold();
03081                                 $format_percent =& $workbook->addFormat();
03082                                 $format_percent->setNumFormat("0.00%");
03083                                 $format_datetime =& $workbook->addFormat();
03084                                 $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
03085                                 $format_title =& $workbook->addFormat();
03086                                 $format_title->setBold();
03087                                 $format_title->setColor('black');
03088                                 $format_title->setPattern(1);
03089                                 $format_title->setFgColor('silver');
03090                                 $format_title_plain =& $workbook->addFormat();
03091                                 $format_title_plain->setColor('black');
03092                                 $format_title_plain->setPattern(1);
03093                                 $format_title_plain->setFgColor('silver');
03094                                 // Creating a worksheet
03095                                 $mainworksheet =& $workbook->addWorksheet();
03096                                 $row = 0;
03097                                 foreach ($csvfile as $csvrow)
03098                                 {
03099                                         $col = 0;
03100                                         if ($row == 0)
03101                                         {
03102                                                 foreach ($csvrow as $text)
03103                                                 {
03104                                                         $mainworksheet->writeString($row, $col++, ilExcelUtils::_convert_text($text, $_POST["export_format"]), $format_title);
03105                                                 }
03106                                         }
03107                                         else
03108                                         {
03109                                                 foreach ($csvrow as $text)
03110                                                 {
03111                                                         if (is_numeric($text))
03112                                                         {
03113                                                                 $mainworksheet->writeNumber($row, $col++, $text);
03114                                                         }
03115                                                         else
03116                                                         {
03117                                                                 $mainworksheet->writeString($row, $col++, ilExcelUtils::_convert_text($text, $_POST["export_format"]));
03118                                                         }
03119                                                 }
03120                                         }
03121                                         $row++;
03122                                 }
03123                                 $workbook->close();
03124                                 exit();
03125                                 break;
03126                         case TYPE_SPSS:
03127                                 $csv = "";
03128                                 $separator = ";";
03129                                 foreach ($csvfile as $csvrow)
03130                                 {
03131                                         $csvrow =& $this->object->processCSVRow($csvrow, TRUE, $separator);
03132                                         $csv .= join($csvrow, $separator) . "\n";
03133                                 }
03134                                 ilUtil::deliverData($csv, "$surveyname.csv");
03135                                 exit();
03136                                 break;
03137                 }
03138                 if ($print)
03139                 {
03140                         $this->tpl->show();
03141                 }
03142         }
03143         
03144         function evaluationdetailsObject()
03145         {
03146                 $this->evaluationObject(1);
03147         }
03148         
03156         function evaluationObject($details = 0, $print = 0)
03157         {
03158                 global $ilUser;
03159 
03160                 $result = @include_once 'Spreadsheet/Excel/Writer.php';
03161                 if (!$result)
03162                 {
03163                         include_once './classes/Spreadsheet/Excel/Writer.php';
03164                 }
03165                 $format_bold = "";
03166                 $format_percent = "";
03167                 $format_datetime = "";
03168                 $format_title = "";
03169                 if ($print)
03170                 {
03171                         unset($_POST["export_format"]);
03172                 }
03173                 $object_title = preg_replace("/[^a-zA-Z0-9\s]/", "", $this->object->getTitle());
03174                 $surveyname = preg_replace("/\s/", "_", $object_title);
03175 
03176                 if (!$_POST["export_format"])
03177                 {
03178                         $_POST["export_format"] = TYPE_PRINT;
03179                 }
03180                 switch ($_POST["export_format"])
03181                 {
03182                         case TYPE_XLS:
03183                         case TYPE_XLS_MAC:
03184                                 // Creating a workbook
03185                                 $workbook = new Spreadsheet_Excel_Writer();
03186 
03187                                 // sending HTTP headers
03188                                 $workbook->send("$surveyname.xls");
03189 
03190                                 // Creating a worksheet
03191                                 $format_bold =& $workbook->addFormat();
03192                                 $format_bold->setBold();
03193                                 $format_percent =& $workbook->addFormat();
03194                                 $format_percent->setNumFormat("0.00%");
03195                                 $format_datetime =& $workbook->addFormat();
03196                                 $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
03197                                 $format_title =& $workbook->addFormat();
03198                                 $format_title->setBold();
03199                                 $format_title->setColor('black');
03200                                 $format_title->setPattern(1);
03201                                 $format_title->setFgColor('silver');
03202                                 // Creating a worksheet
03203                                 include_once ("./classes/class.ilExcelUtils.php");
03204                                 $mainworksheet =& $workbook->addWorksheet();
03205                                 $mainworksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title"), $_POST["export_format"]), $format_bold);
03206                                 $mainworksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->lng->txt("question"), $_POST["export_format"]), $format_bold);
03207                                 $mainworksheet->writeString(0, 2, ilExcelUtils::_convert_text($this->lng->txt("question_type"), $_POST["export_format"]), $format_bold);
03208                                 $mainworksheet->writeString(0, 3, ilExcelUtils::_convert_text($this->lng->txt("users_answered"), $_POST["export_format"]), $format_bold);
03209                                 $mainworksheet->writeString(0, 4, ilExcelUtils::_convert_text($this->lng->txt("users_skipped"), $_POST["export_format"]), $format_bold);
03210                                 $mainworksheet->writeString(0, 5, ilExcelUtils::_convert_text($this->lng->txt("mode"), $_POST["export_format"]), $format_bold);
03211                                 $mainworksheet->writeString(0, 6, ilExcelUtils::_convert_text($this->lng->txt("mode_text"), $_POST["export_format"]), $format_bold);
03212                                 $mainworksheet->writeString(0, 7, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections"), $_POST["export_format"]), $format_bold);
03213                                 $mainworksheet->writeString(0, 8, ilExcelUtils::_convert_text($this->lng->txt("median"), $_POST["export_format"]), $format_bold);
03214                                 $mainworksheet->writeString(0, 9, ilExcelUtils::_convert_text($this->lng->txt("arithmetic_mean"), $_POST["export_format"]), $format_bold);
03215                                 break;
03216                         case (TYPE_SPSS || TYPE_PRINT):
03217                                 $csvfile = array();
03218                                 $csvrow = array();
03219                                 array_push($csvrow, $this->lng->txt("title"));
03220                                 array_push($csvrow, $this->lng->txt("question"));
03221                                 array_push($csvrow, $this->lng->txt("question_type"));
03222                                 array_push($csvrow, $this->lng->txt("users_answered"));
03223                                 array_push($csvrow, $this->lng->txt("users_skipped"));
03224                                 array_push($csvrow, $this->lng->txt("mode"));
03225 
03226                                 //array_push($csvrow, $this->lng->txt("mode_text"));
03227 
03228 
03229                                 array_push($csvrow, $this->lng->txt("mode_nr_of_selections"));
03230                                 array_push($csvrow, $this->lng->txt("median"));
03231                                 array_push($csvrow, $this->lng->txt("arithmetic_mean"));
03232                                 array_push($csvfile, $csvrow);
03233                                 break;
03234                 }
03235 
03236                 if (!$print)
03237                 {
03238                         $this->setEvalTabs();
03239                         sendInfo();
03240                         $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_evaluation.html", true);
03241                 }
03242                 else
03243                 {
03244                         $this->tpl = new ilTemplate("./survey/templates/default/tpl.il_svy_svy_evaluation_preview.html", true, true);
03245                 }
03246                 $counter = 0;
03247                 $classes = array("tblrow1", "tblrow2");
03248                 $questions =& $this->object->getSurveyQuestions();
03249                 foreach ($questions as $data)
03250                 {
03251                         $eval = $this->object->getEvaluation($data["question_id"], $ilUser->id);
03252                         $this->tpl->setCurrentBlock("row");
03253                         $this->tpl->setVariable("QUESTION_TITLE", ($counter+1) . ". " . $data["title"]);
03254                         $maxlen = 37;
03255                         if (strlen($data["questiontext"]) > $maxlen + 3)
03256                         {
03257                                 $questiontext = substr($data["questiontext"], 0, $maxlen) . "...";
03258                         }
03259                         else
03260                         {
03261                                 $questiontext = $data["questiontext"];
03262                         }
03263                         $this->tpl->setVariable("QUESTION_TEXT", $questiontext);
03264                         $this->tpl->setVariable("USERS_ANSWERED", $eval["USERS_ANSWERED"]);
03265                         $this->tpl->setVariable("USERS_SKIPPED", $eval["USERS_SKIPPED"]);
03266                         $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt($eval["QUESTION_TYPE"]));
03267                         $this->tpl->setVariable("MODE", $eval["MODE"]);
03268                         $this->tpl->setVariable("MODE_NR_OF_SELECTIONS", $eval["MODE_NR_OF_SELECTIONS"]);
03269                         $this->tpl->setVariable("MEDIAN", $eval["MEDIAN"]);
03270                         $this->tpl->setVariable("ARITHMETIC_MEAN", $eval["ARITHMETIC_MEAN"]);
03271                         $this->tpl->setVariable("COLOR_CLASS", $classes[$counter % 2]);
03272                         switch ($_POST["export_format"])
03273                         {
03274                                 case TYPE_XLS:
03275                                 case TYPE_XLS_MAC:
03276                                         include_once ("./classes/class.ilExcelUtils.php");
03277                                         $mainworksheet->writeString($counter+1, 0, ilExcelUtils::_convert_text($data["title"], $_POST["export_format"]));
03278                                         $mainworksheet->writeString($counter+1, 1, ilExcelUtils::_convert_text($data["questiontext"], $_POST["export_format"]));
03279                                         $mainworksheet->writeString($counter+1, 2, ilExcelUtils::_convert_text($this->lng->txt($eval["QUESTION_TYPE"]), $_POST["export_format"]));
03280                                         $mainworksheet->write($counter+1, 3, $eval["USERS_ANSWERED"]);
03281                                         $mainworksheet->write($counter+1, 4, $eval["USERS_SKIPPED"]);
03282                                         preg_match("/(.*?)\s+-\s+(.*)/", $eval["MODE"], $matches);
03283                                         switch ($eval["QUESTION_TYPE"])
03284                                         {
03285                                                 case "qt_metric":
03286                                                         $mainworksheet->write($counter+1, 5, $eval["MODE"]);
03287                                                         $mainworksheet->write($counter+1, 6, $eval["MODE"]);
03288                                                         break;
03289                                                 default:
03290                                                         $mainworksheet->write($counter+1, 5, $matches[1]);
03291                                                         $mainworksheet->write($counter+1, 6, $matches[2]);
03292                                                         break;
03293                                         }
03294                                         $mainworksheet->write($counter+1, 7, $eval["MODE_NR_OF_SELECTIONS"]);
03295                                         $mainworksheet->write($counter+1, 8, $eval["MEDIAN"]);
03296                                         $mainworksheet->write($counter+1, 9, $eval["ARITHMETIC_MEAN"]);
03297                                         break;
03298                                 case (TYPE_SPSS || TYPE_PRINT):
03299                                         $csvrow = array();
03300                                         array_push($csvrow, $data["title"]);
03301                                         array_push($csvrow, $data["questiontext"]);
03302                                         array_push($csvrow, $this->lng->txt($eval["QUESTION_TYPE"]));
03303                                         array_push($csvrow, $eval["USERS_ANSWERED"]);
03304                                         array_push($csvrow, $eval["USERS_SKIPPED"]);
03305                                         array_push($csvrow, $eval["MODE"]);
03306                                         array_push($csvrow, $eval["MODE_NR_OF_SELECTIONS"]);
03307                                         array_push($csvrow, $eval["MEDIAN"]);
03308                                         array_push($csvrow, $eval["ARITHMETIC_MEAN"]);
03309                                         array_push($csvfile, $csvrow);
03310                                         break;
03311                         }
03312                         $this->tpl->parseCurrentBlock();
03313                         if ($details)
03314                         {
03315                                 $printDetail = array();
03316                                 switch ($_POST["export_format"])
03317                                 {
03318                                         case TYPE_XLS:
03319                                         case TYPE_XLS_MAC:
03320                                                 include_once ("./classes/class.ilExcelUtils.php");
03321                                                 $worksheet =& $workbook->addWorksheet();
03322                                                 $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title"), $_POST["export_format"]), $format_bold);
03323                                                 $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($data["title"], $_POST["export_format"]));
03324                                                 $worksheet->writeString(1, 0, ilExcelUtils::_convert_text($this->lng->txt("question"), $_POST["export_format"]), $format_bold);
03325                                                 $worksheet->writeString(1, 1, ilExcelUtils::_convert_text($data["questiontext"], $_POST["export_format"]));
03326                                                 $worksheet->writeString(2, 0, ilExcelUtils::_convert_text($this->lng->txt("question_type"), $_POST["export_format"]), $format_bold);
03327                                                 $worksheet->writeString(2, 1, ilExcelUtils::_convert_text($this->lng->txt($eval["QUESTION_TYPE"]), $_POST["export_format"]));
03328                                                 $worksheet->writeString(3, 0, ilExcelUtils::_convert_text($this->lng->txt("users_answered"), $_POST["export_format"]), $format_bold);
03329                                                 $worksheet->write(3, 1, $eval["USERS_ANSWERED"]);
03330                                                 $worksheet->writeString(4, 0, ilExcelUtils::_convert_text($this->lng->txt("users_skipped"), $_POST["export_format"]), $format_bold);
03331                                                 $worksheet->write(4, 1, $eval["USERS_SKIPPED"]);
03332                                                 $rowcounter = 5;
03333                                                 break;
03334                                         case TYPE_PRINT:
03335                                                 array_push($printDetail, $this->lng->txt("title"));
03336                                                 array_push($printDetail, $data["title"]);
03337                                                 array_push($printDetail, $this->lng->txt("question"));
03338                                                 array_push($printDetail, $data["questiontext"]);
03339                                                 array_push($printDetail, $this->lng->txt("question_type"));
03340                                                 array_push($printDetail, $this->lng->txt($eval["QUESTION_TYPE"]));
03341                                                 array_push($printDetail, $this->lng->txt("users_answered"));
03342                                                 array_push($printDetail, $eval["USERS_ANSWERED"]);
03343                                                 array_push($printDetail, $this->lng->txt("users_skipped"));
03344                                                 array_push($printDetail, $eval["USERS_SKIPPED"]);
03345                                                 break;
03346                                 }
03347                                 $this->tpl->setCurrentBlock("detail");
03348                                 $this->tpl->setVariable("QUESTION_TITLE", $data["title"]);
03349                                 $this->tpl->setVariable("TEXT_QUESTION_TEXT", $this->lng->txt("question"));
03350                                 $this->tpl->setVariable("QUESTION_TEXT", $data["questiontext"]);
03351                                 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("question_type"));
03352                                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt($eval["QUESTION_TYPE"]));
03353                                 $this->tpl->setVariable("TEXT_USERS_ANSWERED", $this->lng->txt("users_answered"));
03354                                 $this->tpl->setVariable("USERS_ANSWERED", $eval["USERS_ANSWERED"]);
03355                                 $this->tpl->setVariable("TEXT_USERS_SKIPPED", $this->lng->txt("users_skipped"));
03356                                 $this->tpl->setVariable("USERS_SKIPPED", $eval["USERS_SKIPPED"]);
03357                                 switch ($eval["QUESTION_TYPE"])
03358                                 {
03359                                         case "qt_ordinal":
03360                                                 switch ($_POST["export_format"])
03361                                                 {
03362                                                         case TYPE_XLS:
03363                                                         case TYPE_XLS_MAC:
03364                                                                 preg_match("/(.*?)\s+-\s+(.*)/", $eval["MODE"], $matches);
03365                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("mode"), $format_bold);
03366                                                                 $worksheet->write($rowcounter++, 1, $matches[1]);
03367                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("mode_text"), $format_bold);
03368                                                                 $worksheet->write($rowcounter++, 1, $matches[2]);
03369                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("mode_nr_of_selections"), $format_bold);
03370                                                                 $worksheet->write($rowcounter++, 1, $eval["MODE_NR_OF_SELECTIONS"]);
03371                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("median"), $format_bold);
03372                                                                 $worksheet->write($rowcounter++, 1, $eval["MEDIAN"]);
03373                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("categories"), $format_bold);
03374                                                                 $worksheet->write($rowcounter, 1, $this->lng->txt("title"), $format_title);
03375                                                                 $worksheet->write($rowcounter, 2, $this->lng->txt("value"), $format_title);
03376                                                                 $worksheet->write($rowcounter, 3, $this->lng->txt("category_nr_selected"), $format_title);
03377                                                                 $worksheet->write($rowcounter++, 4, $this->lng->txt("percentage_of_selections"), $format_title);
03378                                                                 break;
03379                                                 }
03380                                                 $this->tpl->setVariable("TEXT_MODE", $this->lng->txt("mode"));
03381                                                 $this->tpl->setVariable("MODE", $eval["MODE"]);
03382                                                 $this->tpl->setVariable("TEXT_MODE_NR_OF_SELECTIONS", $this->lng->txt("mode_nr_of_selections"));
03383                                                 $this->tpl->setVariable("MODE_NR_OF_SELECTIONS", $eval["MODE_NR_OF_SELECTIONS"]);
03384                                                 $this->tpl->setVariable("TEXT_MEDIAN", $this->lng->txt("median"));
03385                                                 $this->tpl->setVariable("MEDIAN", $eval["MEDIAN"]);
03386                                                 $this->tpl->setVariable("TEXT_CATEGORIES", $this->lng->txt("categories"));
03387                                                 $categories = "";
03388                                                 foreach ($eval["variables"] as $key => $value)
03389                                                 {
03390                                                         $categories .= "<li>" . $this->lng->txt("title") . ":" . "<span class=\"bold\">" . $value["title"] . "</span><br />" .
03391                                                                 $this->lng->txt("category_nr_selected") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
03392                                                                 $this->lng->txt("percentage_of_selections") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
03393                                                                 switch ($_POST["export_format"])
03394                                                                 {
03395                                                                         case TYPE_XLS:
03396                                                                         case TYPE_XLS_MAC:
03397                                                                                 $worksheet->write($rowcounter, 1, $value["title"]);
03398                                                                                 $worksheet->write($rowcounter, 2, $key+1);
03399                                                                                 $worksheet->write($rowcounter, 3, $value["selected"]);
03400                                                                                 $worksheet->write($rowcounter++, 4, $value["percentage"], $format_percent);
03401                                                                                 break;
03402                                                                 }
03403                                                 }
03404                                                 $categories = "<ol>$categories</ol>";
03405                                                 $this->tpl->setVariable("VALUE_CATEGORIES", $categories);
03406                                                 
03407                                                 // display chart for ordinal question for array $eval["variables"]
03408                                                 $this->tpl->setVariable("TEXT_CHART", $this->lng->txt("chart"));
03409                                                 $this->tpl->setVariable("ALT_CHART", $data["title"] . "( " . $this->lng->txt("chart") . ")");
03410                                                 $this->tpl->setVariable("CHART","displaychart.php?grName=" . urlencode($data["title"]) . 
03411                                                         "&type=bars" . 
03412                                                         "&x=" . urlencode($this->lng->txt("answers")) . 
03413                                                         "&y=" . urlencode($this->lng->txt("users_answered")) . 
03414                                                         "&arr=".base64_encode(serialize($eval["variables"])));
03415                                                 switch ($_POST["export_format"])
03416                                                 {
03417                                                         case TYPE_PRINT:
03418                                                                 array_push($printDetail, $this->lng->txt("mode"));
03419                                                                 array_push($printDetail, $eval["MODE"]);
03420                                                                 array_push($printDetail, $this->lng->txt("mode_nr_of_selections"));
03421                                                                 array_push($printDetail, $eval["MODE_NR_OF_SELECTIONS"]);
03422                                                                 array_push($printDetail, $this->lng->txt("median"));
03423                                                                 array_push($printDetail, $eval["MEDIAN"]);
03424                                                                 array_push($printDetail, $this->lng->txt("categories"));
03425                                                                 array_push($printDetail, $categories);
03426                                                                 break;
03427                                                 }
03428                                                 break;
03429                                         case "qt_nominal":
03430                                                 switch ($_POST["export_format"])
03431                                                 {
03432                                                         case TYPE_XLS:
03433                                                         case TYPE_XLS_MAC:
03434                                                                 preg_match("/(.*?)\s+-\s+(.*)/", $eval["MODE"], $matches);
03435                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("mode"), $format_bold);
03436                                                                 $worksheet->write($rowcounter++, 1, $matches[1]);
03437                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("mode_text"), $format_bold);
03438                                                                 $worksheet->write($rowcounter++, 1, $matches[2]);
03439                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("mode_nr_of_selections"), $format_bold);
03440                                                                 $worksheet->write($rowcounter++, 1, $eval["MODE_NR_OF_SELECTIONS"]);
03441                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("categories"), $format_bold);
03442                                                                 $worksheet->write($rowcounter, 1, $this->lng->txt("title"), $format_title);
03443                                                                 $worksheet->write($rowcounter, 2, $this->lng->txt("value"), $format_title);
03444                                                                 $worksheet->write($rowcounter, 3, $this->lng->txt("category_nr_selected"), $format_title);
03445                                                                 $worksheet->write($rowcounter++, 4, $this->lng->txt("percentage_of_selections"), $format_title);
03446                                                                 break;
03447                                                 }
03448                                                 array_push($printDetail, $this->lng->txt("subtype"));
03449                                                 $this->tpl->setVariable("TEXT_QUESTION_SUBTYPE", $this->lng->txt("subtype"));
03450                                                 $charttype = "bars";
03451                                                 switch ($data["subtype"])
03452                                                 {
03453                                                         case SUBTYPE_MCSR:
03454                                                                 $this->tpl->setVariable("QUESTION_SUBTYPE", $this->lng->txt("multiple_choice_single_response"));
03455                                                                 array_push($printDetail, $this->lng->txt("multiple_choice_single_response"));
03456                                                                 break;
03457                                                         case SUBTYPE_MCMR:
03458                                                                 $charttype = "pie";
03459                                                                 $this->tpl->setVariable("QUESTION_SUBTYPE", $this->lng->txt("multiple_choice_multiple_response"));
03460                                                                 array_push($printDetail, $this->lng->txt("multiple_choice_multiple_response"));
03461                                                                 break;
03462                                                 }
03463                                                 $this->tpl->setVariable("TEXT_MODE", $this->lng->txt("mode"));
03464                                                 $this->tpl->setVariable("MODE", $eval["MODE"]);
03465                                                 $this->tpl->setVariable("TEXT_MODE_NR_OF_SELECTIONS", $this->lng->txt("mode_nr_of_selections"));
03466                                                 $this->tpl->setVariable("MODE_NR_OF_SELECTIONS", $eval["MODE_NR_OF_SELECTIONS"]);
03467                                                 $this->tpl->setVariable("TEXT_CATEGORIES", $this->lng->txt("categories"));
03468                                                 $categories = "";
03469                                                 foreach ($eval["variables"] as $key => $value)
03470                                                 {
03471                                                         $categories .= "<li>" . $this->lng->txt("title") . ":" . "<span class=\"bold\">" . $value["title"] . "</span><br />" .
03472                                                                 $this->lng->txt("category_nr_selected") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
03473                                                                 $this->lng->txt("percentage_of_selections") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
03474                                                         switch ($_POST["export_format"])
03475                                                         {
03476                                                                 case TYPE_XLS:
03477                                                                 case TYPE_XLS_MAC:
03478                                                                         $worksheet->write($rowcounter, 1, $value["title"]);
03479                                                                         $worksheet->write($rowcounter, 2, $key+1);
03480                                                                         $worksheet->write($rowcounter, 3, $value["selected"]);
03481                                                                         $worksheet->write($rowcounter++, 4, $value["percentage"], $format_percent);
03482                                                                         break;
03483                                                         }
03484                                                 }
03485                                                 $categories = "<ol>$categories</ol>";
03486                                                 $this->tpl->setVariable("VALUE_CATEGORIES", $categories);
03487 
03488                                                 // display chart for nominal question for array $eval["variables"]
03489                                                 $this->tpl->setVariable("TEXT_CHART", $this->lng->txt("chart"));
03490                                                 $this->tpl->setVariable("ALT_CHART", $data["title"] . "( " . $this->lng->txt("chart") . ")");
03491                                                 $this->tpl->setVariable("CHART","displaychart.php?grName=" . urlencode($data["title"]) . 
03492                                                         "&type=$charttype" . 
03493                                                         "&x=" . urlencode($this->lng->txt("answers")) . 
03494                                                         "&y=" . urlencode($this->lng->txt("users_answered")) . 
03495                                                         "&arr=".base64_encode(serialize($eval["variables"])));
03496 
03497                                                 switch ($_POST["export_format"])
03498                                                 {
03499                                                         case TYPE_PRINT:
03500                                                                 array_push($printDetail, $this->lng->txt("mode"));
03501                                                                 array_push($printDetail, $eval["MODE"]);
03502                                                                 array_push($printDetail, $this->lng->txt("mode_nr_of_selections"));
03503                                                                 array_push($printDetail, $eval["MODE_NR_OF_SELECTIONS"]);
03504                                                                 array_push($printDetail, $this->lng->txt("categories"));
03505                                                                 array_push($printDetail, $categories);
03506                                                                 break;
03507                                                 }
03508                                                 break;
03509                                         case "qt_metric":
03510                                                 switch ($_POST["export_format"])
03511                                                 {
03512                                                         case TYPE_XLS:
03513                                                         case TYPE_XLS_MAC:
03514                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("subtype"), $format_bold);
03515                                                                 switch ($data["subtype"])
03516                                                                 {
03517                                                                         case SUBTYPE_NON_RATIO:
03518                                                                                 $worksheet->write($rowcounter++, 1, $this->lng->txt("non_ratio"), $format_bold);
03519                                                                                 break;
03520                                                                         case SUBTYPE_RATIO_NON_ABSOLUTE:
03521                                                                                 $worksheet->write($rowcounter++, 1, $this->lng->txt("ratio_non_absolute"), $format_bold);
03522                                                                                 break;
03523                                                                         case SUBTYPE_RATIO_ABSOLUTE:
03524                                                                                 $worksheet->write($rowcounter++, 1, $this->lng->txt("ratio_absolute"), $format_bold);
03525                                                                                 break;
03526                                                                 }
03527                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("mode"), $format_bold);
03528                                                                 $worksheet->write($rowcounter++, 1, $eval["MODE"]);
03529                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("mode_text"), $format_bold);
03530                                                                 $worksheet->write($rowcounter++, 1, $eval["MODE"]);
03531                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("mode_nr_of_selections"), $format_bold);
03532                                                                 $worksheet->write($rowcounter++, 1, $eval["MODE_NR_OF_SELECTIONS"]);
03533                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("median"), $format_bold);
03534                                                                 $worksheet->write($rowcounter++, 1, $eval["MEDIAN"]);
03535                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("arithmetic_mean"), $format_bold);
03536                                                                 $worksheet->write($rowcounter++, 1, $eval["ARITHMETIC_MEAN"]);
03537                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("values"), $format_bold);
03538                                                                 $worksheet->write($rowcounter, 1, $this->lng->txt("value"), $format_title);
03539                                                                 $worksheet->write($rowcounter, 2, $this->lng->txt("category_nr_selected"), $format_title);
03540                                                                 $worksheet->write($rowcounter++, 3, $this->lng->txt("percentage_of_selections"), $format_title);
03541                                                                 break;
03542                                                 }
03543                                                 $this->tpl->setVariable("TEXT_QUESTION_SUBTYPE", $this->lng->txt("subtype"));
03544                                                 array_push($printDetail, $this->lng->txt("subtype"));
03545                                                 switch ($data["subtype"])
03546                                                 {
03547                                                         case SUBTYPE_NON_RATIO:
03548                                                                 $this->tpl->setVariable("QUESTION_SUBTYPE", $this->lng->txt("non_ratio"));
03549                                                                 array_push($printDetail, $this->lng->txt("non_ratio"));
03550                                                                 break;
03551                                                         case SUBTYPE_RATIO_NON_ABSOLUTE:
03552                                                                 $this->tpl->setVariable("QUESTION_SUBTYPE", $this->lng->txt("ratio_non_absolute"));
03553                                                                 array_push($printDetail, $this->lng->txt("ratio_non_absolute"));
03554                                                                 break;
03555                                                         case SUBTYPE_RATIO_ABSOLUTE:
03556                                                                 $this->tpl->setVariable("QUESTION_SUBTYPE", $this->lng->txt("ratio_absolute"));
03557                                                                 array_push($printDetail, $this->lng->txt("ratio_absolute"));
03558                                                                 break;
03559                                                 }
03560                                                 $this->tpl->setVariable("TEXT_MODE", $this->lng->txt("mode"));
03561                                                 $this->tpl->setVariable("MODE", $eval["MODE"]);
03562                                                 $this->tpl->setVariable("TEXT_MODE_NR_OF_SELECTIONS", $this->lng->txt("mode_nr_of_selections"));
03563                                                 $this->tpl->setVariable("MODE_NR_OF_SELECTIONS", $eval["MODE_NR_OF_SELECTIONS"]);
03564                                                 $this->tpl->setVariable("TEXT_MEDIAN", $this->lng->txt("median"));
03565                                                 $this->tpl->setVariable("MEDIAN", $eval["MEDIAN"]);
03566                                                 $this->tpl->setVariable("TEXT_ARITHMETIC_MEAN", $this->lng->txt("arithmetic_mean"));
03567                                                 $this->tpl->setVariable("ARITHMETIC_MEAN", $eval["ARITHMETIC_MEAN"]);
03568                                                 $this->tpl->setVariable("TEXT_VALUES", $this->lng->txt("values"));
03569                                                 $values = "";
03570                                                 foreach ($eval["values"] as $key => $value)
03571                                                 {
03572                                                         $values .= "<li>" . $this->lng->txt("value") . ": " . "<span class=\"bold\">" . $value["value"] . "</span><br />" .
03573                                                                 $this->lng->txt("value_nr_entered") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
03574                                                                 $this->lng->txt("percentage_of_entered_values") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
03575                                                         switch ($_POST["export_format"])
03576                                                         {
03577                                                                 case TYPE_XLS:
03578                                                                 case TYPE_XLS_MAC:
03579                                                                         $worksheet->write($rowcounter, 1, $value["value"]);
03580                                                                         $worksheet->write($rowcounter, 2, $value["selected"]);
03581                                                                         $worksheet->write($rowcounter++, 3, $value["percentage"], $format_percent);
03582                                                                         break;
03583                                                         }
03584                                                 }
03585                                                 $values = "<ol>$values</ol>";
03586                                                 $this->tpl->setVariable("VALUE_VALUES", $values);
03587 
03588                                                 // display chart for metric question for array $eval["values"]
03589                                                 $this->tpl->setVariable("TEXT_CHART", $this->lng->txt("chart"));
03590                                                 $this->tpl->setVariable("ALT_CHART", $data["title"] . "( " . $this->lng->txt("chart") . ")");
03591                                                 $this->tpl->setVariable("CHART","displaychart.php?grName=" . urlencode($data["title"]) . 
03592                                                         "&type=bars" . 
03593                                                         "&x=" . urlencode($this->lng->txt("answers")) . 
03594                                                         "&y=" . urlencode($this->lng->txt("users_answered")) . 
03595                                                         "&arr=".base64_encode(serialize($eval["values"])));
03596 
03597                                                 switch ($_POST["export_format"])
03598                                                 {
03599                                                         case TYPE_PRINT:
03600                                                                 array_push($printDetail, $this->lng->txt("mode"));
03601                                                                 array_push($printDetail, $eval["MODE"]);
03602                                                                 array_push($printDetail, $this->lng->txt("mode_nr_of_selections"));
03603                                                                 array_push($printDetail, $eval["MODE_NR_OF_SELECTIONS"]);
03604                                                                 array_push($printDetail, $this->lng->txt("median"));
03605                                                                 array_push($printDetail, $eval["MEDIAN"]);
03606                                                                 array_push($printDetail, $this->lng->txt("values"));
03607                                                                 array_push($printDetail, $values);
03608                                                                 break;
03609                                                 }
03610                                                 break;
03611                                         case "qt_text":
03612                                                 switch ($_POST["export_format"])
03613                                                 {
03614                                                         case TYPE_XLS:
03615                                                         case TYPE_XLS_MAC:
03616                                                                 $worksheet->write($rowcounter, 0, $this->lng->txt("given_answers"), $format_bold);
03617                                                                 break;
03618                                                 }
03619                                                 $this->tpl->setVariable("TEXT_TEXTVALUES", $this->lng->txt("given_answers"));
03620                                                 $textvalues = "";
03621                                                 foreach ($eval["textvalues"] as $textvalue)
03622                                                 {
03623                                                         $textvalues .= "<li>" . preg_replace("/\n/", "<br>", $textvalue) . "</li>";
03624                                                         switch ($_POST["export_format"])
03625                                                         {
03626                                                                 case TYPE_XLS:
03627                                                                 case TYPE_XLS_MAC:
03628                                                                         $worksheet->write($rowcounter++, 1, $textvalue);
03629                                                                         break;
03630                                                         }
03631                                                 }
03632                                                 $textvalues = "<ul>$textvalues</ul>";
03633                                                 $this->tpl->setVariable("VALUE_TEXTVALUES", $textvalues);
03634                                                 switch ($_POST["export_format"])
03635                                                 {
03636                                                         case TYPE_PRINT:
03637                                                                 array_push($printDetail, $this->lng->txt("given_answers"));
03638                                                                 array_push($printDetail, $textvalues);
03639                                                                 break;
03640                                                 }
03641                                                 break;
03642                                 }
03643 
03644                                 if ($_POST["export_format"]==TYPE_PRINT)
03645                                 {
03646                                         $printdetail_file = array();
03647                                         array_push($printdetail_file, $printDetail);
03648                                         $s_question = $counter+1;
03649                                         $_SESSION[$this->lng->txt("question").$s_question] = $printdetail_file;
03650                                         $this->tpl->setVariable("PRINT_ACTION", $this->getCallingScript() . "?ref_id=" . $_GET["ref_id"] . "&cmd=printEvaluation&".$this->lng->txt("question")."=".$s_question);
03651                                         $this->tpl->setVariable("PRINT_TEXT", $this->lng->txt("print"));
03652                                         $this->tpl->setVariable("PRINT_IMAGE", ilUtil::getImagePath("icon_print.gif"));
03653                                 }
03654                                 $this->tpl->parseCurrentBlock();
03655                         }
03656                         $counter++;
03657                 }
03658                 if ($_POST["export_format"]==TYPE_PRINT)
03659                 {
03660                         $_SESSION["print_eval"] = $csvfile;
03661                 }
03662 
03663 
03664                 switch ($_POST["export_format"])
03665                 {
03666                         case TYPE_XLS:
03667                         case TYPE_XLS_MAC:
03668                                 // Let's send the file
03669                                 $workbook->close();
03670                                 exit();
03671                                 break;
03672                         case TYPE_SPSS:
03673                                 $csv = "";
03674                                 $separator = ";";
03675                                 foreach ($csvfile as $csvrow)
03676                                 {
03677                                         $csvrow =& $this->object->processCSVRow($csvrow, TRUE, $separator);
03678                                         $csv .= join($csvrow, $separator) . "\n";
03679                                 }
03680                                 ilUtil::deliverData($csv, "$surveyname.csv");
03681                                 exit();
03682                                 break;
03683                 }
03684                 if (!$print)
03685                 {
03686                         $this->tpl->setCurrentBlock("adm_content");
03687                 }
03688                 else
03689                 {
03690                         $this->tpl->setCurrentBlock("__global__");
03691                         $this->tpl->setVariable("TXT_STATISTICAL_EVALUATION", $this->lng->txt("svy_statistical_evaluation") . " " . $this->lng->txt("of") . " " . $this->object->getTitle());
03692                         $this->tpl->setVariable("PRINT_CSS", "./templates/default/print.css");
03693                         $this->tpl->setVariable("PRINT_TYPE", "summary");
03694                 }
03695                 $this->tpl->setVariable("QUESTION_TITLE", $this->lng->txt("title"));
03696                 $this->tpl->setVariable("QUESTION_TEXT", $this->lng->txt("question"));
03697                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("question_type"));
03698                 $this->tpl->setVariable("USERS_ANSWERED", $this->lng->txt("users_answered"));
03699                 $this->tpl->setVariable("USERS_SKIPPED", $this->lng->txt("users_skipped"));
03700                 $this->tpl->setVariable("MODE", $this->lng->txt("mode"));
03701                 $this->tpl->setVariable("MODE_NR_OF_SELECTIONS", $this->lng->txt("mode_nr_of_selections"));
03702                 $this->tpl->setVariable("MEDIAN", $this->lng->txt("median"));
03703                 $this->tpl->setVariable("ARITHMETIC_MEAN", $this->lng->txt("arithmetic_mean"));
03704                 $this->tpl->setVariable("EXPORT_DATA", $this->lng->txt("export_data_as"));
03705                 $this->tpl->setVariable("TEXT_EXCEL", $this->lng->txt("exp_type_excel"));
03706                 $this->tpl->setVariable("TEXT_EXCEL_MAC", $this->lng->txt("exp_type_excel_mac"));
03707                 $this->tpl->setVariable("TEXT_CSV", $this->lng->txt("exp_type_csv"));
03708                 $this->tpl->setVariable("VALUE_DETAIL", $details);
03709                 $this->tpl->setVariable("BTN_EXPORT", $this->lng->txt("export"));
03710                 $this->tpl->setVariable("BTN_PRINT", $this->lng->txt("print"));
03711                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
03712                 $this->tpl->setVariable("PRINT_ACTION", $this->ctrl->getFormAction($this));
03713                 if ($details)
03714                 {
03715                         $this->tpl->setVariable("CMD_EXPORT", "evaluationdetails");
03716                 }
03717                 else
03718                 {
03719                         $this->tpl->setVariable("CMD_EXPORT", "evaluation");
03720                 }
03721                 $this->tpl->parseCurrentBlock();
03722                 if ($print)
03723                 {
03724                         $this->tpl->show();
03725                 }
03726         }
03727 
03735         function writeInviteFormData()
03736         {
03737                 global $ilUser;
03738 
03739                 $message = "";
03740                 $this->object->setInvitationAndMode($_POST["invitation"], $_POST["mode"]);
03741                 if ($_POST["cmd"]["disinvite"])
03742                 {
03743                         // disinvite users
03744                         if (is_array($_POST["invited_users"]))
03745                         {
03746                                 foreach ($_POST["invited_users"] as $user_id)
03747                                 {
03748                                         $this->object->disinviteUser($user_id);
03749                                 }
03750                         }
03751                         // disinvite groups
03752                         if (is_array($_POST["invited_groups"]))
03753                         {
03754                                 foreach ($_POST["invited_groups"] as $group_id)
03755                                 {
03756                                         $this->object->disinviteGroup($group_id);
03757                                 }
03758                         }
03759                 }
03760 
03761                 if ($_POST["cmd"]["add"])
03762                 {
03763                         // add users to invitation
03764                         if (is_array($_POST["user_select"]))
03765                         {
03766                                 foreach ($_POST["user_select"] as $user_id)
03767                                 {
03768                                         $this->object->inviteUser($user_id);
03769                                 }
03770                         }
03771                         // add groups to invitation
03772                         if (is_array($_POST["group_select"]))
03773                         {
03774                                 foreach ($_POST["group_select"] as $group_id)
03775                                 {
03776                                         $this->object->inviteGroup($group_id);
03777                                 }
03778                         }
03779                 }
03780 
03781                 if ($_POST["cmd"]["search"])
03782                 {
03783                         if (is_array($_POST["search_for"]))
03784                         {
03785                                 if (in_array("usr", $_POST["search_for"]) or in_array("grp", $_POST["search_for"]))
03786                                 {
03787                                         $search =& new ilSearch($ilUser->id);
03788                                         $search->setSearchString($_POST["search_term"]);
03789                                         $search->setCombination($_POST["concatenation"]);
03790                                         $search->setSearchFor($_POST["search_for"]);
03791                                         $search->setSearchType("new");
03792                                         if($search->validate($message))
03793                                         {
03794                                                 $search->performSearch();
03795                                         }
03796                                         if ($message)
03797                                         {
03798                                                 sendInfo($message);
03799                                         }
03800                                         if(!$search->getNumberOfResults() && $search->getSearchFor())
03801                                         {
03802                                                 sendInfo($this->lng->txt("search_no_match"));
03803                                                 return;
03804                                         }
03805                                         $buttons = array("add");
03806                                         $invited_users = $this->object->getInvitedUsers();
03807                                         if ($searchresult = $search->getResultByType("usr"))
03808                                         {
03809                                                 $users = array();
03810                                                 foreach ($searchresult as $result_array)
03811                                                 {
03812                                                         if (!in_array($result_array["id"], $invited_users))
03813                                                         {
03814                                                                 array_push($users, $result_array["id"]);
03815                                                         }
03816                                                 }
03817                                                 $this->outUserGroupTable("usr", $users, "user_result", "user_row", $this->lng->txt("search_user"), $buttons);
03818                                         }
03819                                         $searchresult = array();
03820                                         $invited_groups = $this->object->getInvitedGroups();
03821                                         if ($searchresult = $search->getResultByType("grp"))
03822                                         {
03823                                                 $groups = array();
03824                                                 foreach ($searchresult as $result_array)
03825                                                 {
03826                                                         if (!in_array($result_array["id"], $invited_groups))
03827                                                         {
03828                                                                 array_push($groups, $result_array["id"]);
03829                                                         }
03830                                                 }
03831                                                 $this->outUserGroupTable("grp", $groups, "group_result", "group_row", $this->lng->txt("search_group"), $buttons);
03832                                         }
03833                                 }
03834                         }
03835                         else
03836                         {
03837                                 sendInfo($this->lng->txt("no_user_or_group_selected"));
03838                         }
03839                 }
03840         }
03841 
03849         function outUserGroupTable($a_type, $id_array, $block_result, $block_row, $title_text, $buttons)
03850         {
03851                 global $rbacsystem;
03852                 
03853                 $rowclass = array("tblrow1", "tblrow2");
03854                 switch($a_type)
03855                 {
03856                         case "usr":
03857                                 foreach ($id_array as $user_id)
03858                                 {
03859                                         $counter = 0;
03860                                         $user = new ilObjUser($user_id);
03861                                         $this->tpl->setCurrentBlock($block_row);
03862                                         $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
03863                                         $this->tpl->setVariable("COUNTER", $user->getId());
03864                                         $this->tpl->setVariable("VALUE_LOGIN", $user->getLogin());
03865                                         $this->tpl->setVariable("VALUE_FIRSTNAME", $user->getFirstname());
03866                                         $this->tpl->setVariable("VALUE_LASTNAME", $user->getLastname());
03867                                         $counter++;
03868                                         $this->tpl->parseCurrentBlock();
03869                                 }
03870                                 $this->tpl->setCurrentBlock($block_result);
03871                                 $this->tpl->setVariable("TEXT_USER_TITLE", "<img src=\"" . ilUtil::getImagePath("icon_usr_b.gif") . "\" alt=\"\" /> " . $title_text);
03872                                 $this->tpl->setVariable("TEXT_LOGIN", $this->lng->txt("login"));
03873                                 $this->tpl->setVariable("TEXT_FIRSTNAME", $this->lng->txt("firstname"));
03874                                 $this->tpl->setVariable("TEXT_LASTNAME", $this->lng->txt("lastname"));
03875                                 if ($rbacsystem->checkAccess('invite', $this->object->getRefId()))
03876                                 {
03877                                         foreach ($buttons as $cat)
03878                                         {
03879                                                 $this->tpl->setVariable("VALUE_" . strtoupper($cat), $this->lng->txt($cat));
03880                                         }
03881                                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"\">");
03882                                 }
03883                                 $this->tpl->parseCurrentBlock();
03884                                 break;
03885                         case "grp":
03886                                 foreach ($id_array as $group_id)
03887                                 {
03888                                         $counter = 0;
03889                                         $group = new ilObjGroup($group_id);
03890                                         $this->tpl->setCurrentBlock($block_row);
03891                                         $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
03892                                         $this->tpl->setVariable("COUNTER", $group->getRefId());
03893                                         $this->tpl->setVariable("VALUE_TITLE", $group->getTitle());
03894                                         $this->tpl->setVariable("VALUE_DESCRIPTION", $group->getDescription());
03895                                         $counter++;
03896                                         $this->tpl->parseCurrentBlock();
03897                                 }
03898                                 $this->tpl->setCurrentBlock($block_result);
03899                                 $this->tpl->setVariable("TEXT_GROUP_TITLE", "<img src=\"" . ilUtil::getImagePath("icon_grp_b.gif") . "\" alt=\"\" /> " . $title_text);
03900                                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
03901                                 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
03902                                 if ($rbacsystem->checkAccess('invite', $this->object->getRefId()))
03903                                 {
03904                                         foreach ($buttons as $cat)
03905                                         {
03906                                                 $this->tpl->setVariable("VALUE_" . strtoupper($cat), $this->lng->txt($cat));
03907                                         }
03908                                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"\">");
03909                                 }
03910                                 $this->tpl->parseCurrentBlock();
03911                                 break;
03912                 }
03913         }
03914 
03922         function inviteObject()
03923         {
03924                 global $rbacsystem;
03925 
03926                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
03927                 {
03928                         // allow only read and write access
03929                         sendInfo($this->lng->txt("cannot_edit_survey"), true);
03930                         $path = $this->tree->getPathFull($this->object->getRefID());
03931                         ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
03932                         return;
03933                 }
03934                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_invite.html", true);
03935 
03936                 if ($this->object->getStatus() == STATUS_OFFLINE)
03937                 {
03938                         $this->tpl->setCurrentBlock("survey_offline");
03939                         $this->tpl->setVariable("SURVEY_OFFLINE_MESSAGE", $this->lng->txt("survey_offline_message"));
03940                         $this->tpl->parseCurrentBlock();
03941                         return;
03942                 }
03943                 if ($_POST["cmd"]["cancel"])
03944                 {
03945                         $path = $this->tree->getPathFull($this->object->getRefID());
03946                         ilUtil::redirect($this->getReturnLocation("cancel",ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH)."/repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
03947                         exit();
03948                 }
03949                 if (count($_POST))
03950                 {
03951                         $this->writeInviteFormData();
03952                 }
03953                 if ($_POST["cmd"]["save"])
03954                 {
03955                         $this->object->saveToDb();
03956                 }
03957                 if (($this->object->getInvitationMode() == MODE_PREDEFINED_USERS) and ($this->object->getInvitation() == INVITATION_ON))
03958                 {
03959                         if ($rbacsystem->checkAccess('invite', $this->ref_id))
03960                         {
03961                                 $this->tpl->setCurrentBlock("invitation");
03962                                 $this->tpl->setVariable("SEARCH_INVITATION", $this->lng->txt("search_invitation"));
03963                                 $this->tpl->setVariable("SEARCH_TERM", $this->lng->txt("search_term"));
03964                                 $this->tpl->setVariable("SEARCH_FOR", $this->lng->txt("search_for"));
03965                                 $this->tpl->setVariable("SEARCH_USERS", $this->lng->txt("search_users"));
03966                                 $this->tpl->setVariable("SEARCH_GROUPS", $this->lng->txt("search_groups"));
03967                                 $this->tpl->setVariable("TEXT_CONCATENATION", $this->lng->txt("concatenation"));
03968                                 $this->tpl->setVariable("TEXT_AND", $this->lng->txt("and"));
03969                                 $this->tpl->setVariable("TEXT_OR", $this->lng->txt("or"));
03970                                 $this->tpl->setVariable("VALUE_SEARCH_TERM", $_POST["search_term"]);
03971                                 if (is_array($_POST["search_for"]))
03972                                 {
03973                                         if (in_array("usr", $_POST["search_for"]))
03974                                         {
03975                                                 $this->tpl->setVariable("CHECKED_USERS", " checked=\"checked\"");
03976                                         }
03977                                         if (in_array("grp", $_POST["search_for"]))
03978                                         {
03979                                                 $this->tpl->setVariable("CHECKED_GROUPS", " checked=\"checked\"");
03980                                         }
03981                                 }
03982                                 if (strcmp($_POST["concatenation"], "and") == 0)
03983                                 {
03984                                         $this->tpl->setVariable("CHECKED_AND", " checked=\"checked\"");
03985                                 }
03986                                 else if (strcmp($_POST["concatenation"], "or") == 0)
03987                                 {
03988                                         $this->tpl->setVariable("CHECKED_OR", " checked=\"checked\"");
03989                                 }
03990                                 $this->tpl->setVariable("SEARCH", $this->lng->txt("search"));
03991                                 $this->tpl->parseCurrentBlock();
03992                         }
03993                 }
03994                 if ($this->object->getInvitationMode() == MODE_PREDEFINED_USERS)
03995                 {
03996                         $invited_users = $this->object->getInvitedUsers();
03997                         $invited_groups = $this->object->getInvitedGroups();
03998                         $buttons = array("disinvite");
03999                         if (count($invited_users))
04000                         {
04001                                 $this->outUserGroupTable("usr", $invited_users, "invited_user_result", "invited_user_row", $this->lng->txt("invited_users"), $buttons);
04002                         }
04003                         if (count($invited_groups))
04004                         {
04005                                 $this->outUserGroupTable("grp", $invited_groups, "invited_group_result", "invited_group_row", $this->lng->txt("invited_groups"), $buttons);
04006                         }
04007                 }
04008                 if ($this->object->getInvitation() == INVITATION_ON)
04009                 {
04010                         $this->tpl->setCurrentBlock("invitation_mode");
04011                         $this->tpl->setVariable("TEXT_MODE", $this->lng->txt("invitation_mode"));
04012                         $this->tpl->setVariable("VALUE_UNLIMITED", $this->lng->txt("unlimited_users"));
04013                         $this->tpl->setVariable("VALUE_PREDEFINED", $this->lng->txt("predefined_users"));
04014                         if ($this->object->getInvitationMode() == MODE_PREDEFINED_USERS)
04015                         {
04016                                 $this->tpl->setVariable("SELECTED_PREDEFINED", " selected=\"selected\"");
04017                         }
04018                         else
04019                         {
04020                                 $this->tpl->setVariable("SELECTED_UNLIMITED", " selected=\"selected\"");
04021                         }
04022                         $this->tpl->parseCurrentBlock();
04023                 }
04024                 $this->tpl->setCurrentBlock("adm_content");
04025                 $this->tpl->setVariable("TEXT_INVITATION", $this->lng->txt("invitation"));
04026                 $this->tpl->setVariable("VALUE_ON", $this->lng->txt("on"));
04027                 $this->tpl->setVariable("VALUE_OFF", $this->lng->txt("off"));
04028                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
04029                 if ($this->object->getInvitation() == INVITATION_ON)
04030                 {
04031                         $this->tpl->setVariable("SELECTED_ON", " selected=\"selected\"");
04032                 }
04033                 else
04034                 {
04035                         $this->tpl->setVariable("SELECTED_OFF", " selected=\"selected\"");
04036                 }
04037     if ($rbacsystem->checkAccess("write", $this->ref_id) or $rbacsystem->checkAccess('invite', $this->ref_id)) {
04038                         $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
04039                         $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
04040                 }
04041                 $this->tpl->parseCurrentBlock();
04042         }
04043 
04051         function deleteAllUserDataObject()
04052         {
04053                 sendInfo($this->lng->txt("confirm_delete_all_user_data"));
04054                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_maintenance.html", true);
04055                 $this->tpl->setCurrentBlock("confirm_delete");
04056                 $this->tpl->setVariable("BTN_CONFIRM_DELETE_ALL", $this->lng->txt("confirm"));
04057                 $this->tpl->setVariable("BTN_CANCEL_DELETE_ALL", $this->lng->txt("cancel"));
04058                 $this->tpl->parseCurrentBlock();
04059                 $this->tpl->setCurrentBlock("adm_content");
04060                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
04061                 $this->tpl->parseCurrentBlock();
04062         }
04063         
04071         function confirmDeleteAllUserDataObject()
04072         {
04073                 $this->object->deleteAllUserData();
04074                 sendInfo($this->lng->txt("svy_all_user_data_deleted"), true);
04075                 $this->ctrl->redirect($this, "maintenance");
04076         }
04077         
04085         function cancelDeleteAllUserDataObject()
04086         {
04087                 $this->ctrl->redirect($this, "maintenance");
04088         }
04089         
04097         function maintenanceObject()
04098         {
04099                 global $rbacsystem;
04100 
04101                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
04102                 {
04103                         // allow only read and write access
04104                         sendInfo($this->lng->txt("cannot_edit_survey"), true);
04105                         $path = $this->tree->getPathFull($this->object->getRefID());
04106                         ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
04107                         return;
04108                 }
04109 
04110                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_maintenance.html", true);
04111 
04112                 if ($rbacsystem->checkAccess("write", $this->ref_id))
04113                 {
04114                         $this->tpl->setCurrentBlock("delete_button");
04115                         $this->tpl->setVariable("BTN_DELETE_ALL", $this->lng->txt("svy_delete_all_user_data"));
04116                         $this->tpl->parseCurrentBlock();
04117                         $this->tpl->setCurrentBlock("adm_content");
04118                         $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
04119                         $this->tpl->parseCurrentBlock();
04120                 }
04121                 else
04122                 {
04123                         sendInfo($this->lng->txt("cannot_maintain_survey"));
04124                 }
04125         }       
04126 
04134         function statusObject()
04135         {
04136                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_status.html", true);
04137                 if (!$this->object->isComplete())
04138                 {
04139                         if (count($this->object->questions) == 0)
04140                         {
04141                                 $this->tpl->setCurrentBlock("list_element");
04142                                 $this->tpl->setVariable("TEXT_ELEMENT", $this->lng->txt("svy_missing_questions"));
04143                                 $this->tpl->parseCurrentBlock();
04144                         }
04145                         if (strcmp($this->object->author, "") == 0)
04146                         {
04147                                 $this->tpl->setCurrentBlock("list_element");
04148                                 $this->tpl->setVariable("TEXT_ELEMENT", $this->lng->txt("svy_missing_author"));
04149                                 $this->tpl->parseCurrentBlock();
04150                         }
04151                         if (strcmp($this->object->title, "") == 0)
04152                         {
04153                                 $this->tpl->setCurrentBlock("list_element");
04154                                 $this->tpl->setVariable("TEXT_ELEMENT", $this->lng->txt("svy_missing_author"));
04155                                 $this->tpl->parseCurrentBlock();
04156                         }
04157                         $this->tpl->setCurrentBlock("status_list");
04158                         $this->tpl->setVariable("TEXT_MISSING_ELEMENTS", $this->lng->txt("svy_status_missing_elements"));
04159                         $this->tpl->parseCurrentBlock();
04160                 }
04161                 $this->tpl->setCurrentBlock("adm_content");
04162                 if ($this->object->isComplete())
04163                 {
04164                         $this->tpl->setVariable("TEXT_STATUS_MESSAGE", $this->lng->txt("svy_status_ok"));
04165                         $this->tpl->setVariable("STATUS_CLASS", "bold");
04166                 }
04167                 else
04168                 {
04169                         $this->tpl->setVariable("TEXT_STATUS_MESSAGE", $this->lng->txt("svy_status_missing"));
04170                         $this->tpl->setVariable("STATUS_CLASS", "warning");
04171                 }
04172                 $this->tpl->parseCurrentBlock();
04173         }       
04174 
04183         function setLocator($a_tree = "", $a_id = "", $scriptname="repository.php")
04184         {
04185                 //              global $ilias_locator;
04186           $ilias_locator = new ilLocatorGUI(false);
04187                 if (!is_object($a_tree))
04188                 {
04189                         $a_tree =& $this->tree;
04190                 }
04191                 if (!($a_id))
04192                 {
04193                         $a_id = $_GET["ref_id"];
04194                 }
04195 
04196                 //$this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html");
04197 
04198                 $path = $a_tree->getPathFull($a_id);
04199                 //check if object isn't in tree, this is the case if parent_parent is set
04200                 // TODO: parent_parent no longer exist. need another marker
04201                 if ($a_parent_parent)
04202                 {
04203                         //$subObj = getObject($a_ref_id);
04204                         $subObj =& $this->ilias->obj_factory->getInstanceByRefId($a_ref_id);
04205 
04206                         $path[] = array(
04207                                 "id"     => $a_ref_id,
04208                                 "title"  => $this->lng->txt($subObj->getTitle())
04209                                 );
04210                 }
04211 
04212                 // this is a stupid workaround for a bug in PEAR:IT
04213                 $modifier = 1;
04214 
04215                 if (isset($_GET["obj_id"]))
04216                 {
04217                         $modifier = 0;
04218                 }
04219 
04220                 // ### AA 03.11.10 added new locator GUI class ###
04221                 $i = 1;
04222                 if (!defined("ILIAS_MODULE")) {
04223                         foreach ($path as $key => $row)
04224                         {
04225                                 $ilias_locator->navigate($i++, $row["title"], ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/adm_object.php?ref_id=".$row["child"],"");
04226                         }
04227                 } else {
04228                         foreach ($path as $key => $row)
04229                         {
04230                                 if (strcmp($row["title"], "ILIAS") == 0) {
04231                                         $row["title"] = $this->lng->txt("repository");
04232                                 }
04233                                 if ($this->ref_id == $row["child"]) {
04234                                         if ($_GET["cmd"]) {
04235                                                 $param = "&cmd=" . $_GET["cmd"];
04236                                         } else {
04237                                                 $param = "";
04238                                         }
04239                                         $ilias_locator->navigate($i++, $row["title"], ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/survey/survey.php" . "?ref_id=".$row["child"] . $param,"target=\"bottom\"");
04240                                 } else {
04241                                         $ilias_locator->navigate($i++, $row["title"], ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/" . $scriptname."?cmd=frameset&ref_id=".$row["child"],"target=\"bottom\"");
04242                                 }
04243                         }
04244 
04245                         if (isset($_GET["obj_id"]))
04246                         {
04247                                 $obj_data =& $this->ilias->obj_factory->getInstanceByObjId($_GET["obj_id"]);
04248                                 $ilias_locator->navigate($i++,$obj_data->getTitle(),$scriptname."?cmd=frameset&ref_id=".$_GET["ref_id"]."&obj_id=".$_GET["obj_id"],"target=\"bottom\"");
04249                         }
04250                 }
04251     $ilias_locator->output();
04252         }
04253 
04254         function editMetaObject()
04255         {
04256                 $meta_gui =& new ilMetaDataGUI();
04257                 $meta_gui->setObject($this->object);
04258                 $meta_gui->edit("ADM_CONTENT", "adm_content",
04259                         $this->getTabTargetScript()."?ref_id=".$_GET["ref_id"]."&cmd=saveMeta");
04260         }
04261 
04262         function saveMetaObject()
04263         {
04264                 $meta_gui =& new ilMetaDataGUI();
04265                 $meta_gui->setObject($this->object);
04266                 $meta_gui->save($_POST["meta_section"]);
04267                 if (!strcmp($_POST["meta_section"], "General")) {
04268                         $meta = $_POST["meta"];
04269                         $this->object->setTitle(ilUtil::stripSlashes($meta["Title"]["Value"]));
04270                         $this->object->setDescription(ilUtil::stripSlashes($meta["Description"][0]["Value"]));
04271                         $this->object->update();
04272                 }
04273                 ilUtil::redirect($this->getTabTargetScript()."?ref_id=".$_GET["ref_id"]."&cmd=editMeta");
04274         }
04275 
04276         // called by administration
04277         function chooseMetaSectionObject($a_script = "",
04278                 $a_templ_var = "ADM_CONTENT", $a_templ_block = "adm_content")
04279         {
04280                 if ($a_script == "")
04281                 {
04282                         $a_script = $this->getTabTargetScript()."?ref_id=".$_GET["ref_id"];
04283                 }
04284                 $meta_gui =& new ilMetaDataGUI();
04285                 $meta_gui->setObject($this->object);
04286                 $meta_gui->edit($a_templ_var, $a_templ_block, $a_script, $_REQUEST["meta_section"]);
04287         }
04288 
04289         // called by editor
04290         function chooseMetaSection()
04291         {
04292                 $this->chooseMetaSectionObject($this->getTabTargetScript()."?ref_id=".
04293                         $this->object->getRefId());
04294         }
04295 
04296         function addMetaObject($a_script = "",
04297                 $a_templ_var = "ADM_CONTENT", $a_templ_block = "adm_content")
04298         {
04299                 if ($a_script == "")
04300                 {
04301                         $a_script = $this->getTabTargetScript()."?ref_id=".$_GET["ref_id"];
04302                 }
04303                 $meta_gui =& new ilMetaDataGUI();
04304                 $meta_gui->setObject($this->object);
04305                 $meta_name = $_POST["meta_name"] ? $_POST["meta_name"] : $_GET["meta_name"];
04306                 $meta_index = $_POST["meta_index"] ? $_POST["meta_index"] : $_GET["meta_index"];
04307                 if ($meta_index == "")
04308                         $meta_index = 0;
04309                 $meta_path = $_POST["meta_path"] ? $_POST["meta_path"] : $_GET["meta_path"];
04310                 $meta_section = $_POST["meta_section"] ? $_POST["meta_section"] : $_GET["meta_section"];
04311                 if ($meta_name != "")
04312                 {
04313                         $meta_gui->meta_obj->add($meta_name, $meta_path, $meta_index);
04314                 }
04315                 else
04316                 {
04317                         sendInfo($this->lng->txt("meta_choose_element"), true);
04318                 }
04319                 $meta_gui->edit($a_templ_var, $a_templ_block, $a_script, $meta_section);
04320         }
04321 
04322         function addMeta()
04323         {
04324                 $this->addMetaObject($this->getTabTargetScript()."?ref_id=".
04325                         $this->object->getRefId());
04326         }
04327 
04328         function deleteMetaObject($a_script = "",
04329                 $a_templ_var = "ADM_CONTENT", $a_templ_block = "adm_content")
04330         {
04331                 if ($a_script == "")
04332                 {
04333                         $a_script = $this->getTabTargetScript()."?ref_id=".$_GET["ref_id"];
04334                 }
04335                 $meta_gui =& new ilMetaDataGUI();
04336                 $meta_gui->setObject($this->object);
04337                 $meta_index = $_POST["meta_index"] ? $_POST["meta_index"] : $_GET["meta_index"];
04338                 $meta_gui->meta_obj->delete($_GET["meta_name"], $_GET["meta_path"], $meta_index);
04339                 $meta_gui->edit($a_templ_var, $a_templ_block, $a_script, $_GET["meta_section"]);
04340         }
04341 
04342         function deleteMeta()
04343         {
04344                 $this->deleteMetaObject($this->getTabTargetScript()."?ref_id=".
04345                         $this->object->getRefId());
04346         }
04347 
04348         function prepareOutput()
04349         {
04350                 $this->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
04351                 $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
04352                 $title = $this->object->getTitle();
04353                 // catch feedback message
04354                 sendInfo();
04355 
04356                 if (!empty($title))
04357                 {
04358                         $this->tpl->setVariable("HEADER", $title);
04359                 }
04360                 if (!defined("ILIAS_MODULE"))
04361                 {
04362                         $this->setAdminTabs($_POST["new_type"]);
04363                 }
04364                 $this->setLocator();
04365 
04366         }
04367         
04368         /*
04369         * list all export files
04370         */
04371         function exportObject()
04372         {
04373                 global $tree;
04374                 global $rbacsystem;
04375 
04376                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
04377                 {
04378                         // allow only read and write access
04379                         sendInfo($this->lng->txt("cannot_edit_survey"), true);
04380                         $path = $this->tree->getPathFull($this->object->getRefID());
04381                         ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?ref_id=" . $path[count($path) - 2]["child"]));
04382                         return;
04383                 }
04384 
04385                 //$this->setTabs();
04386 
04387                 //add template for view button
04388                 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
04389 
04390                 // create export file button
04391                 $this->tpl->setCurrentBlock("btn_cell");
04392                 $this->tpl->setVariable("BTN_LINK", "survey.php?ref_id=".$_GET["ref_id"]."&cmd=createExportFile");
04393                 $this->tpl->setVariable("BTN_TXT", $this->lng->txt("svy_create_export_file"));
04394                 $this->tpl->parseCurrentBlock();
04395 
04396                 $export_dir = $this->object->getExportDirectory();
04397                 $export_files = $this->object->getExportFiles($export_dir);
04398 
04399                 // create table
04400                 require_once("classes/class.ilTableGUI.php");
04401                 $tbl = new ilTableGUI();
04402 
04403                 // load files templates
04404                 $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.table.html");
04405 
04406                 // load template for table content data
04407                 $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.export_file_row.html", true);
04408 
04409                 $num = 0;
04410 
04411                 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
04412 
04413                 $tbl->setTitle($this->lng->txt("svy_export_files"));
04414 
04415                 $tbl->setHeaderNames(array("<input type=\"checkbox\" name=\"chb_check_all\" value=\"1\" onclick=\"setCheckboxes('ObjectItems', 'file', document.ObjectItems.chb_check_all.checked);\" />", $this->lng->txt("svy_file"),
04416                         $this->lng->txt("svy_size"), $this->lng->txt("date") ));
04417 
04418                 $tbl->enabled["sort"] = false;
04419                 $tbl->setColumnWidth(array("1%", "49%", "25%", "25%"));
04420 
04421                 // control
04422                 $tbl->setOrderColumn($_GET["sort_by"]);
04423                 $tbl->setOrderDirection($_GET["sort_order"]);
04424                 $tbl->setLimit($_GET["limit"]);
04425                 $tbl->setOffset($_GET["offset"]);
04426                 $tbl->setMaxCount($this->maxcount);             // ???
04427 
04428                 $this->tpl->setVariable("COLUMN_COUNTS", 4);
04429 
04430                 // delete button
04431                 $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
04432                 $this->tpl->setCurrentBlock("tbl_action_btn");
04433                 $this->tpl->setVariable("BTN_NAME", "confirmDeleteExportFile");
04434                 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("delete"));
04435                 $this->tpl->parseCurrentBlock();
04436 
04437                 $this->tpl->setCurrentBlock("tbl_action_btn");
04438                 $this->tpl->setVariable("BTN_NAME", "downloadExportFile");
04439                 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("download"));
04440                 $this->tpl->parseCurrentBlock();
04441 
04442                 // footer
04443                 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
04444                 //$tbl->disable("footer");
04445 
04446                 $tbl->setMaxCount(count($export_files));
04447                 $export_files = array_slice($export_files, $_GET["offset"], $_GET["limit"]);
04448 
04449                 $tbl->render();
04450                 if(count($export_files) > 0)
04451                 {
04452                         $i=0;
04453                         foreach($export_files as $exp_file)
04454                         {
04455                                 $this->tpl->setCurrentBlock("tbl_content");
04456                                 $this->tpl->setVariable("TXT_FILENAME", $exp_file);
04457 
04458                                 $css_row = ilUtil::switchColor($i++, "tblrow1", "tblrow2");
04459                                 $this->tpl->setVariable("CSS_ROW", $css_row);
04460 
04461                                 $this->tpl->setVariable("TXT_SIZE", filesize($export_dir."/".$exp_file));
04462                                 $this->tpl->setVariable("CHECKBOX_ID", $exp_file);
04463 
04464                                 $file_arr = explode("__", $exp_file);
04465                                 $this->tpl->setVariable("TXT_DATE", date("Y-m-d H:i:s",$file_arr[0]));
04466 
04467                                 $this->tpl->parseCurrentBlock();
04468                         }
04469                 } //if is_array
04470                 else
04471                 {
04472                         $this->tpl->setCurrentBlock("notfound");
04473                         $this->tpl->setVariable("TXT_OBJECT_NOT_FOUND", $this->lng->txt("obj_not_found"));
04474                         $this->tpl->setVariable("NUM_COLS", 3);
04475                         $this->tpl->parseCurrentBlock();
04476                 }
04477 
04478                 $this->tpl->parseCurrentBlock();
04479         }
04480 
04484         function createExportFileObject()
04485         {
04486                 global $rbacsystem;
04487                 
04488                 if ($rbacsystem->checkAccess("write", $this->ref_id))
04489                 {
04490                         require_once("./survey/classes/class.ilSurveyExport.php");
04491                         $survey_exp = new ilSurveyExport($this->object);
04492                         $survey_exp->buildExportFile();
04493                         ilUtil::redirect("survey.php?cmd=export&ref_id=".$_GET["ref_id"]);
04494                 }
04495                 else
04496                 {
04497                         sendInfo("cannot_export_survey");
04498                 }
04499         }
04500 
04506         function importObject()
04507         {
04508                 $this->getTemplateFile("import", "svy");
04509                 $this->tpl->setCurrentBlock("option_qpl");
04510                 require_once("./survey/classes/class.ilObjSurvey.php");
04511                 $svy = new ilObjSurvey();
04512                 $questionpools =& $svy->getAvailableQuestionpools(true);
04513                 if (count($questionpools) == 0)
04514                 {
04515                 }
04516                 else
04517                 {
04518                         foreach ($questionpools as $key => $value)
04519                         {
04520                                 $this->tpl->setCurrentBlock("option_spl");
04521                                 $this->tpl->setVariable("OPTION_VALUE", $key);
04522                                 $this->tpl->setVariable("TXT_OPTION", $value);
04523                                 $this->tpl->parseCurrentBlock();
04524                         }
04525                 }
04526                 $this->tpl->setVariable("TXT_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool"));
04527                 $this->tpl->setVariable("OPTION_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_option"));
04528                 $this->tpl->setVariable("FORMACTION", "adm_object.php?&ref_id=".$_GET["ref_id"]."&cmd=gateway&new_type=".$this->type);
04529                 $this->tpl->setVariable("BTN_NAME", "upload");
04530                 $this->tpl->setVariable("TXT_UPLOAD", $this->lng->txt("upload"));
04531                 $this->tpl->setVariable("TXT_IMPORT_TST", $this->lng->txt("import_tst"));
04532                 $this->tpl->setVariable("TXT_SELECT_MODE", $this->lng->txt("select_mode"));
04533                 $this->tpl->setVariable("TXT_SELECT_FILE", $this->lng->txt("select_file"));
04534 
04535         }
04536 
04543         function uploadObject($redirect = true)
04544         {
04545                 if ($_POST["spl"] < 1)
04546                 {
04547                         sendInfo($this->lng->txt("svy_select_questionpools"));
04548                         $this->importObject();
04549                         return;
04550                 }
04551                 if (strcmp($_FILES["xmldoc"]["tmp_name"], "") == 0)
04552                 {
04553                         sendInfo($this->lng->txt("svy_select_file_for_import"));
04554                         $this->importObject();
04555                         return;
04556                 }
04557                 include_once("./survey/classes/class.ilObjSurvey.php");
04558                 $newObj = new ilObjSurvey();
04559                 $newObj->setType($_GET["new_type"]);
04560                 $newObj->setTitle("dummy");
04561                 $newObj->setDescription("dummy");
04562                 $newObj->create(true);
04563                 $newObj->createReference();
04564                 $newObj->putInTree($_GET["ref_id"]);
04565                 $newObj->setPermissions($_GET["ref_id"]);
04566                 $newObj->notify("new",$_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$newObj->getRefId());
04567 
04568                 // copy uploaded file to import directory
04569                 $newObj->importObject($_FILES["xmldoc"], $_POST["spl"]);
04570 
04571                 /* update title and description in object data */
04572                 if (is_object($newObj->meta_data))
04573                 {
04574                         $newObj->meta_data->read();
04575                         $newObj->meta_data->setTitle($newObj->getTitle());
04576                         $newObj->meta_data->setDescription($newObj->getDescription());
04577                         ilObject::_writeTitle($newObj->getID(), $newObj->getTitle());
04578                         ilObject::_writeDescription($newObj->getID(), $newObj->getDescription());
04579                 }
04580 
04581                 $newObj->update();
04582                 $newObj->saveToDb();
04583                 if ($redirect)
04584                 {
04585                         ilUtil::redirect($this->getReturnLocation("upload",$this->ctrl->getTargetScript()."?".$this->link_params));
04586                 }
04587         }
04588 
04592         function createObject()
04593         {
04594                 global $rbacsystem;
04595                 $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
04596                 if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
04597                 {
04598                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
04599                 }
04600                 else
04601                 {
04602                         $this->getTemplateFile("create", $new_type);
04603 
04604                         require_once("./survey/classes/class.ilObjSurvey.php");
04605                         $svy = new ilObjSurvey();
04606                         
04607                         $surveys =& ilObjSurvey::_getAvailableSurveys(true);
04608                         if (count($surveys) > 0)
04609                         {
04610                                 foreach ($surveys as $key => $value)
04611                                 {
04612                                         $this->tpl->setCurrentBlock("option_svy");
04613                                         $this->tpl->setVariable("OPTION_VALUE_SVY", $key);
04614                                         $this->tpl->setVariable("TXT_OPTION_SVY", $value);
04615                                         if ($_POST["svy"] == $key)
04616                                         {
04617                                                 $this->tpl->setVariable("OPTION_SELECTED_SVY", " selected=\"selected\"");                               
04618                                         }
04619                                         $this->tpl->parseCurrentBlock();
04620                                 }
04621                         }
04622                         
04623                         $questionpools =& $svy->getAvailableQuestionpools(true);
04624                         if (count($questionpools) > 0)
04625                         {
04626                                 foreach ($questionpools as $key => $value)
04627                                 {
04628                                         $this->tpl->setCurrentBlock("option_spl");
04629                                         $this->tpl->setVariable("OPTION_VALUE", $key);
04630                                         $this->tpl->setVariable("TXT_OPTION", $value);
04631                                         if ($_POST["spl"] == $key)
04632                                         {
04633                                                 $this->tpl->setVariable("OPTION_SELECTED", " selected=\"selected\"");                           
04634                                         }
04635                                         $this->tpl->parseCurrentBlock();
04636                                 }
04637                         }
04638                         // fill in saved values in case of error
04639                         $data = array();
04640                         $data["fields"] = array();
04641                         $data["fields"]["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
04642                         $data["fields"]["desc"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["desc"]);
04643 
04644                         foreach ($data["fields"] as $key => $val)
04645                         {
04646                                 $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
04647                                 $this->tpl->setVariable(strtoupper($key), $val);
04648 
04649                                 if ($this->prepare_output)
04650                                 {
04651                                         $this->tpl->parseCurrentBlock();
04652                                 }
04653                         }
04654 
04655                         $this->tpl->setVariable("FORMACTION", $this->getFormAction("save","adm_object.php?cmd=gateway&ref_id=".
04656                                                                                                                                            $_GET["ref_id"]."&new_type=".$new_type));
04657                         $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($new_type."_new"));
04658                         $this->tpl->setVariable("TXT_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_short"));
04659                         $this->tpl->setVariable("OPTION_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_option"));
04660                         $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
04661                         $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($new_type."_add"));
04662                         $this->tpl->setVariable("CMD_SUBMIT", "save");
04663                         $this->tpl->setVariable("TARGET", $this->getTargetFrame("save"));
04664                         $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
04665 
04666                         $this->tpl->setVariable("TXT_IMPORT_SVY", $this->lng->txt("import_svy"));
04667                         $this->tpl->setVariable("TXT_SVY_FILE", $this->lng->txt("svy_upload_file"));
04668                         $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
04669 
04670                         $this->tpl->setVariable("TXT_DUPLICATE_SVY", $this->lng->txt("duplicate_svy"));
04671                         $this->tpl->setVariable("TXT_SELECT_SVY", $this->lng->txt("obj_svy"));
04672                         $this->tpl->setVariable("OPTION_SELECT_SVY", $this->lng->txt("select_svy_option"));
04673                         $this->tpl->setVariable("TXT_DUPLICATE", $this->lng->txt("duplicate"));
04674                 }
04675         }
04676         
04680         function cloneAllObject()
04681         {
04682                 if ($_POST["svy"] < 1)
04683                 {
04684                         sendInfo($this->lng->txt("svy_select_surveys"));
04685                         $this->createObject();
04686                         return;
04687                 }
04688                 require_once "./survey/classes/class.ilObjSurvey.php";
04689                 ilObjSurvey::_clone($_POST["svy"]);
04690                 ilUtil::redirect($this->getReturnLocation("cloneAll",$this->ctrl->getTargetScript()."?".$this->link_params));
04691         }
04692         
04696         function importFileObject()
04697         {
04698                 if ($_POST["spl"] < 1)
04699                 {
04700                         sendInfo($this->lng->txt("svy_select_questionpools"));
04701                         $this->createObject();
04702                         return;
04703                 }
04704                 if (strcmp($_FILES["xmldoc"]["tmp_name"], "") == 0)
04705                 {
04706                         sendInfo($this->lng->txt("svy_select_file_for_import"));
04707                         $this->createObject();
04708                         return;
04709                 }
04710                 $this->uploadObject(false);
04711                 ilUtil::redirect($this->getReturnLocation("importFile",$this->ctrl->getTargetScript()."?".$this->link_params));
04712         }
04713 
04717         function downloadExportFileObject()
04718         {
04719                 if(!isset($_POST["file"]))
04720                 {
04721                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
04722                 }
04723 
04724                 if (count($_POST["file"]) > 1)
04725                 {
04726                         $this->ilias->raiseError($this->lng->txt("select_max_one_item"),$this->ilias->error_obj->MESSAGE);
04727                 }
04728 
04729 
04730                 $export_dir = $this->object->getExportDirectory();
04731                 ilUtil::deliverFile($export_dir."/".$_POST["file"][0],
04732                         $_POST["file"][0]);
04733         }
04734 
04738         function confirmDeleteExportFileObject()
04739         {
04740                 if(!isset($_POST["file"]))
04741                 {
04742                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
04743                 }
04744 
04745                 //$this->setTabs();
04746 
04747                 // SAVE POST VALUES
04748                 $_SESSION["ilExportFiles"] = $_POST["file"];
04749 
04750                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.confirm_deletion.html", true);
04751 
04752                 sendInfo($this->lng->txt("info_delete_sure"));
04753 
04754                 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
04755 
04756                 // BEGIN TABLE HEADER
04757                 $this->tpl->setCurrentBlock("table_header");
04758                 $this->tpl->setVariable("TEXT",$this->lng->txt("objects"));
04759                 $this->tpl->parseCurrentBlock();
04760 
04761                 // BEGIN TABLE DATA
04762                 $counter = 0;
04763                 foreach($_POST["file"] as $file)
04764                 {
04765                                 $this->tpl->setCurrentBlock("table_row");
04766                                 $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
04767                                 $this->tpl->setVariable("TEXT_CONTENT", $file);
04768                                 $this->tpl->parseCurrentBlock();
04769                 }
04770 
04771                 // cancel/confirm button
04772                 $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
04773                 $buttons = array( "cancelDeleteExportFile"  => $this->lng->txt("cancel"),
04774                         "deleteExportFile"  => $this->lng->txt("confirm"));
04775                 foreach ($buttons as $name => $value)
04776                 {
04777                         $this->tpl->setCurrentBlock("operation_btn");
04778                         $this->tpl->setVariable("BTN_NAME",$name);
04779                         $this->tpl->setVariable("BTN_VALUE",$value);
04780                         $this->tpl->parseCurrentBlock();
04781                 }
04782         }
04783 
04784 
04788         function cancelDeleteExportFileObject()
04789         {
04790                 session_unregister("ilExportFiles");
04791                 ilUtil::redirect("survey.php?cmd=export&ref_id=".$_GET["ref_id"]);
04792         }
04793 
04794 
04798         function deleteExportFileObject()
04799         {
04800                 $export_dir = $this->object->getExportDirectory();
04801                 foreach($_SESSION["ilExportFiles"] as $file)
04802                 {
04803                         $exp_file = $export_dir."/".$file;
04804                         $exp_dir = $export_dir."/".substr($file, 0, strlen($file) - 4);
04805                         if (@is_file($exp_file))
04806                         {
04807                                 unlink($exp_file);
04808                         }
04809                         if (@is_dir($exp_dir))
04810                         {
04811                                 ilUtil::delDir($exp_dir);
04812                         }
04813                 }
04814                 ilUtil::redirect("survey.php?cmd=export&ref_id=".$_GET["ref_id"]);
04815         }
04816 
04817         function setEvalTabs()
04818         {
04819                 global $rbacsystem;
04820 
04821                 include_once "./classes/class.ilTabsGUI.php";
04822                 $tabs_gui =& new ilTabsGUI();
04823                 
04824                 $tabs_gui->addTarget("svy_eval_cumulated", $this->ctrl->getLinkTargetByClass(get_class($this), "evaluation"), "evaluation",     "ilobjsurveygui");
04825                 $tabs_gui->addTarget("svy_eval_detail", $this->ctrl->getLinkTargetByClass(get_class($this), "evaluationdetails"), "evaluationdetails",  "ilobjsurveygui");
04826                 $tabs_gui->addTarget("svy_eval_user", $this->ctrl->getLinkTargetByClass(get_class($this), "evaluationuser"), "evaluationuser",  "ilobjsurveygui");
04827                 $this->tpl->setVariable("TABS", $tabs_gui->getHTML());
04828         }
04829         
04830         function codesObject()
04831         {
04832                 global $rbacsystem;
04833 
04834                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
04835                 {
04836                         // allow only read and write access
04837                         sendInfo($this->lng->txt("cannot_edit_survey"), true);
04838                         $path = $this->tree->getPathFull($this->object->getRefID());
04839                         ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?ref_id=" . $path[count($path) - 2]["child"]));
04840                         return;
04841                 }
04842                 
04843                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_codes.html", true);
04844                 if ($rbacsystem->checkAccess("write", $this->ref_id))
04845                 {
04846                         $color_class = array("tblrow1", "tblrow2");
04847                         $survey_codes =& $this->object->getSurveyCodes();
04848                         if (count($survey_codes) == 0)
04849                         {
04850                                 $this->tpl->setCurrentBlock("emptyrow");
04851                                 $this->tpl->setVariable("COLOR_CLASS", "tblrow1");
04852                                 $this->tpl->setVariable("NO_CODES", $this->lng->txt("survey_code_no_codes"));
04853                                 $this->tpl->parseCurrentBlock();
04854                         }
04855                         else
04856                         {
04857                                 foreach ($survey_codes as $key => $row)
04858                                 {
04859                                         $this->tpl->setCurrentBlock("coderow");
04860                                         $this->tpl->setVariable("COLOR_CLASS", $color_class[$key % 2]);
04861                                         $this->tpl->setVariable("SURVEY_CODE", $row["survey_key"]);
04862                                         $this->tpl->setVariable("CODE_CREATED", ilFormat::formatDate(ilFormat::ftimestamp2dateDB($row["TIMESTAMP14"]), "date"));
04863                                         $state = "<span class=\"smallred\">" . $this->lng->txt("not_used") . "</span>";
04864                                         if ($this->object->isSurveyCodeUsed($row["survey_key"]))
04865                                         {
04866                                                 $state = "<span class=\"smallgreen\">" . $this->lng->txt("used") . "</span>";
04867                                         }
04868                                         else
04869                                         {
04870                                                 $this->tpl->setVariable("CODE_URL_NAME", $this->lng->txt("survey_code_url_name"));
04871                                                 //$this->tpl->setVariable("CODE_URL", ILIAS_HTTP_PATH."/survey/survey.php?cmd=run&ref_id=".$this->object->getRefId() . "&accesscode=".$row["survey_key"]);
04872                                                 $this->tpl->setVariable("CODE_URL", ILIAS_HTTP_PATH."/goto.php?cmd=run&target=svy_".$this->object->getRefId() . "&client_id=" . CLIENT_ID . "&accesscode=".$row["survey_key"]);
04873                                         }
04874                                         $this->tpl->setVariable("CODE_USED", $state);
04875                                         $this->tpl->parseCurrentBlock();
04876                                 }
04877                         }
04878                         $this->tpl->setCurrentBlock("adm_content");
04879                         $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
04880                         $this->tpl->setVariable("SURVEY_CODE", $this->lng->txt("survey_code"));
04881                         $this->tpl->setVariable("CODE_CREATED", $this->lng->txt("create_date"));
04882                         $this->tpl->setVariable("CODE_USED", $this->lng->txt("survey_code_used"));
04883                         $this->tpl->setVariable("CODE_URL", $this->lng->txt("survey_code_url"));
04884                         $this->tpl->setVariable("TEXT_CREATE", $this->lng->txt("create"));
04885                         $this->tpl->setVariable("TEXT_SURVEY_CODES", $this->lng->txt("new_survey_codes"));
04886                         $this->tpl->parseCurrentBlock();
04887                 }
04888                 else
04889                 {
04890                         sendInfo($this->lng->txt("cannot_create_survey_codes"));
04891                 }
04892         }
04893         
04894         function createSurveyCodesObject()
04895         {
04896                 if (preg_match("/\d+/", $_POST["nrOfCodes"]))
04897                 {
04898                         $this->object->createSurveyCodes($_POST["nrOfCodes"]);
04899                 }
04900                 else
04901                 {
04902                         sendInfo($this->lng->txt("enter_valid_number_of_codes"), true);
04903                 }
04904                 $this->ctrl->redirect($this, "codes");
04905         }
04906 
04907 } // END class.ilObjSurveyGUI
04908 ?>

Generated on Fri Dec 13 2013 09:06:38 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1