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

Modules/SurveyQuestionPool/classes/class.SurveyNominalQuestionGUI.php

Go to the documentation of this file.
00001 <?php
00002  /*
00003    +----------------------------------------------------------------------------+
00004    | ILIAS open source                                                          |
00005    +----------------------------------------------------------------------------+
00006    | Copyright (c) 1998-2001 ILIAS open source, University of Cologne           |
00007    |                                                                            |
00008    | This program is free software; you can redistribute it and/or              |
00009    | modify it under the terms of the GNU General Public License                |
00010    | as published by the Free Software Foundation; either version 2             |
00011    | of the License, or (at your option) any later version.                     |
00012    |                                                                            |
00013    | This program is distributed in the hope that it will be useful,            |
00014    | but WITHOUT ANY WARRANTY; without even the implied warranty of             |
00015    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              |
00016    | GNU General Public License for more details.                               |
00017    |                                                                            |
00018    | You should have received a copy of the GNU General Public License          |
00019    | along with this program; if not, write to the Free Software                |
00020    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
00021    +----------------------------------------------------------------------------+
00022 */
00023 
00024 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
00025 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
00026 
00038 class SurveyNominalQuestionGUI extends SurveyQuestionGUI 
00039 {
00040 
00049   function SurveyNominalQuestionGUI(
00050                 $id = -1
00051   )
00052 
00053   {
00054                 $this->SurveyQuestionGUI();
00055                 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyNominalQuestion.php";
00056                 $this->object = new SurveyNominalQuestion();
00057                 if ($id >= 0)
00058                 {
00059                         $this->object->loadFromDb($id);
00060                 }
00061         }
00062 
00070   function editQuestion() 
00071         {
00072                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_nominal.html", "Modules/SurveyQuestionPool");
00073           $this->tpl->addBlockFile("OTHER_QUESTION_DATA", "other_question_data", "tpl.il_svy_qpl_other_question_data.html", "Modules/SurveyQuestionPool");
00074                 $this->tpl->setVariable("TEXT_ORIENTATION", $this->lng->txt("orientation"));
00075                 switch ($this->object->getOrientation())
00076                 {
00077                         case 0:
00078                                 $this->tpl->setVariable("CHECKED_VERTICAL", " checked=\"checked\"");
00079                                 break;
00080                         case 1:
00081                                 $this->tpl->setVariable("CHECKED_HORIZONTAL", " checked=\"checked\"");
00082                                 break;
00083                         case 2:
00084                                 $this->tpl->setVariable("CHECKED_COMBOBOX", " checked=\"checked\"");
00085                                 break;
00086                 }
00087                 $this->tpl->setVariable("TXT_VERTICAL", $this->lng->txt("vertical"));
00088                 $this->tpl->setVariable("TXT_HORIZONTAL", $this->lng->txt("horizontal"));
00089                 if ($this->object->getSubtype() == SUBTYPE_MCSR)
00090                 {
00091                         $this->tpl->setVariable("TXT_COMBOBOX", $this->lng->txt("combobox"));
00092                 }
00093 
00094                 $internallinks = array(
00095                         "lm" => $this->lng->txt("obj_lm"),
00096                         "st" => $this->lng->txt("obj_st"),
00097                         "pg" => $this->lng->txt("obj_pg"),
00098                         "glo" => $this->lng->txt("glossary_term")
00099                 );
00100                 foreach ($internallinks as $key => $value)
00101                 {
00102                         $this->tpl->setCurrentBlock("internallink");
00103                         $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00104                         $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00105                         $this->tpl->parseCurrentBlock();
00106                 }
00107                 
00108                 $this->tpl->setCurrentBlock("adm_content");
00109                 $this->tpl->setVariable("TEXT_MATERIAL", $this->lng->txt("material"));
00110                 if (count($this->object->material))
00111                 {
00112                         include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
00113                         $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
00114                         $this->tpl->setVariable("TEXT_VALUE_MATERIAL", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("material"). "</a> ");
00115                         $this->tpl->setVariable("BUTTON_REMOVE_MATERIAL", $this->lng->txt("remove"));
00116                         $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("change"));
00117                         $this->tpl->setVariable("VALUE_MATERIAL", $this->object->material["internal_link"]);
00118                         $this->tpl->setVariable("VALUE_MATERIAL_TITLE", $this->object->material["title"]);
00119                         $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00120                 }
00121                 else
00122                 {
00123                         $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("add"));
00124                 }
00125                 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00126                 $this->tpl->setVariable("VALUE_TITLE", $this->object->getTitle());
00127                 $this->tpl->setVariable("VALUE_DESCRIPTION", $this->object->getDescription());
00128                 $this->tpl->setVariable("VALUE_AUTHOR", $this->object->getAuthor());
00129                 $questiontext = $this->object->getQuestiontext();
00130                 $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
00131                 $this->tpl->setVariable("TXT_SR", $this->lng->txt("multiple_choice_single_response"));
00132                 $this->tpl->setVariable("TXT_MR", $this->lng->txt("multiple_choice_multiple_response"));
00133                 $this->tpl->setVariable("TEXT_SUBTYPE", $this->lng->txt("subtype"));
00134                 $this->tpl->setVariable("DESCRIPTION_QUESTION_TYPE", $this->lng->txt("multiple_choice_subtype_description"));
00135                 if ($this->object->getSubtype() == SUBTYPE_MCSR)
00136                 {
00137                         $this->tpl->setVariable("CHECKED_SR", " checked=\"checked\"");
00138                 }
00139                 else
00140                 {
00141                         $this->tpl->setVariable("CHECKED_MR", " checked=\"checked\"");
00142                 }
00143                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00144                 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00145                 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
00146                 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00147                 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("questiontype"));
00148                 $this->tpl->setVariable("TEXT_OBLIGATORY", $this->lng->txt("obligatory"));
00149                 if ($this->object->getObligatory())
00150                 {
00151                         $this->tpl->setVariable("CHECKED_OBLIGATORY", " checked=\"checked\"");
00152                 }
00153                 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00154                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00155                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00156                 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt($this->getQuestionType()));
00157                 $this->tpl->parseCurrentBlock();
00158                 include_once "./Services/RTE/classes/class.ilRTE.php";
00159                 $rtestring = ilRTE::_getRTEClassname();
00160                 include_once "./Services/RTE/classes/class.$rtestring.php";
00161                 $rte = new $rtestring();
00162                 $rte->addPlugin("latex");
00163                 $rte->addButton("latex"); $rte->addButton("pastelatex");
00164                 $rte->removePlugin("ibrowser");
00165                 include_once "./classes/class.ilObject.php";
00166                 $obj_id = $_GET["q_id"];
00167                 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00168                 $rte->addRTESupport($obj_id, $obj_type, "survey");
00169   }
00170 
00178         function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "")
00179         {
00180                 $template = new ilTemplate("tpl.il_svy_out_nominal.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
00181                 if (count($this->object->material))
00182                 {
00183                         $template->setCurrentBlock("material_nominal");
00184                         include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
00185                         $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
00186                         $template->setVariable("TEXT_MATERIAL", $this->lng->txt("material") . ": <a href=\"$href\" target=\"content\">" . $this->object->material["title"]. "</a> ");
00187                         $template->parseCurrentBlock();
00188                 }
00189                 switch ($this->object->getOrientation())
00190                 {
00191                         case 0:
00192                                 // vertical orientation
00193                                 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++) {
00194                                         $category = $this->object->categories->getCategory($i);
00195                                         if ($this->object->getSubtype() == SUBTYPE_MCSR)
00196                                         {
00197                                                 $template->setCurrentBlock("nominal_row_sr");
00198                                                 $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
00199                                                 $template->setVariable("VALUE_NOMINAL", $i);
00200                                                 $template->setVariable("QUESTION_ID", $this->object->getId());
00201                                                 if (is_array($working_data))
00202                                                 {
00203                                                         foreach ($working_data as $value)
00204                                                         {
00205                                                                 if (strlen($value["value"]))
00206                                                                 {
00207                                                                         if ($value["value"] == $i)
00208                                                                         {
00209                                                                                 $template->setVariable("CHECKED_NOMINAL", " checked=\"checked\"");
00210                                                                         }
00211                                                                 }
00212                                                         }
00213                                                 }
00214                                                 $template->parseCurrentBlock();
00215                                         }
00216                                         else
00217                                         {
00218                                                 $template->setCurrentBlock("nominal_row_mr");
00219                                                 $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
00220                                                 $template->setVariable("VALUE_NOMINAL", $i);
00221                                                 $template->setVariable("QUESTION_ID", $this->object->getId());
00222                                                 if (is_array($working_data))
00223                                                 {
00224                                                         foreach ($working_data as $value)
00225                                                         {
00226                                                                 if (strlen($value["value"]))
00227                                                                 {
00228                                                                         if ($value["value"] == $i)
00229                                                                         {
00230                                                                                 $template->setVariable("CHECKED_NOMINAL", " checked=\"checked\"");
00231                                                                         }
00232                                                                 }
00233                                                         }
00234                                                 }
00235                                                 $template->parseCurrentBlock();
00236                                         }
00237                                 }
00238                                 break;
00239                         case 1:
00240                                 // horizontal orientation
00241                                 if ($this->object->getSubtype() == SUBTYPE_MCSR)
00242                                 {
00243                                         for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++) 
00244                                         {
00245                                                 $category = $this->object->categories->getCategory($i);
00246                                                 $template->setCurrentBlock("radio_col_nominal");
00247                                                 $template->setVariable("VALUE_NOMINAL", $i);
00248                                                 $template->setVariable("QUESTION_ID", $this->object->getId());
00249                                                 if (is_array($working_data))
00250                                                 {
00251                                                         foreach ($working_data as $value)
00252                                                         {
00253                                                                 if (strlen($value["value"]))
00254                                                                 {
00255                                                                         if ($value["value"] == $i)
00256                                                                         {
00257                                                                                 $template->setVariable("CHECKED_NOMINAL", " checked=\"checked\"");
00258                                                                         }
00259                                                                 }
00260                                                         }
00261                                                 }
00262                                                 $template->parseCurrentBlock();
00263                                         }
00264                                         for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++) 
00265                                         {
00266                                                 $category = $this->object->categories->getCategory($i);
00267                                                 $template->setCurrentBlock("text_col_nominal");
00268                                                 $template->setVariable("VALUE_NOMINAL", $i);
00269                                                 $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
00270                                                 $template->setVariable("QUESTION_ID", $this->object->getId());
00271                                                 $template->parseCurrentBlock();
00272                                         }
00273                                 }
00274                                 else
00275                                 {
00276                                         for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++) 
00277                                         {
00278                                                 $category = $this->object->categories->getCategory($i);
00279                                                 $template->setCurrentBlock("checkbox_col_nominal");
00280                                                 $template->setVariable("VALUE_NOMINAL", $i);
00281                                                 $template->setVariable("QUESTION_ID", $this->object->getId());
00282                                                 if (is_array($working_data))
00283                                                 {
00284                                                         foreach ($working_data as $value)
00285                                                         {
00286                                                                 if (strlen($value["value"]))
00287                                                                 {
00288                                                                         if ($value["value"] == $i)
00289                                                                         {
00290                                                                                 $template->setVariable("CHECKED_NOMINAL", " checked=\"checked\"");
00291                                                                         }
00292                                                                 }
00293                                                         }
00294                                                 }
00295                                                 $template->parseCurrentBlock();
00296                                         }
00297                                         for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++) 
00298                                         {
00299                                                 $category = $this->object->categories->getCategory($i);
00300                                                 $template->setCurrentBlock("text_col_nominal_mr");
00301                                                 $template->setVariable("VALUE_NOMINAL", $i);
00302                                                 $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
00303                                                 $template->setVariable("QUESTION_ID", $this->object->getId());
00304                                                 $template->parseCurrentBlock();
00305                                         }
00306                                 }
00307                                 break;
00308                         case 2:
00309                                 // combobox output
00310                                 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++) 
00311                                 {
00312                                         $category = $this->object->categories->getCategory($i);
00313                                         $template->setCurrentBlock("comborow_nominal");
00314                                         $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
00315                                         $template->setVariable("VALUE_NOMINAL", $i);
00316                                         if (is_array($working_data))
00317                                         {
00318                                                 foreach ($working_data as $value)
00319                                                 {
00320                                                         if (strlen($value["value"]))
00321                                                         {
00322                                                                 if ($value["value"] == $i)
00323                                                                 {
00324                                                                         $template->setVariable("SELECTED_NOMINAL", " selected=\"selected\"");
00325                                                                 }
00326                                                         }
00327                                                 }
00328                                         }
00329                                         $template->parseCurrentBlock();
00330                                 }
00331                                 $template->setCurrentBlock("combooutput_nominal");
00332                                 $template->setVariable("QUESTION_ID", $this->object->getId());
00333                                 $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
00334                                 $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
00335                                 $template->parseCurrentBlock();
00336                                 break;
00337                 }
00338                 
00339                 $template->setCurrentBlock("question_data_nominal");
00340                 if (strcmp($error_message, "") != 0)
00341                 {
00342                         $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
00343                 }
00344                 if ($show_questiontext)
00345                 {
00346                         $questiontext = $this->object->getQuestiontext();
00347                         $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00348                 }
00349                 if (! $this->object->getObligatory())
00350                 {
00351                         $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
00352                 }
00353                 if ($question_title)
00354                 {
00355                         $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
00356                 }
00357                 $template->parseCurrentBlock();
00358                 return $template->get();
00359         }
00360 
00368         function getPrintView($question_title = 1, $show_questiontext = 1)
00369         {
00370                 $template = new ilTemplate("tpl.il_svy_qpl_nominal_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
00371                 switch ($this->object->getOrientation())
00372                 {
00373                         case 0:
00374                                 // vertical orientation
00375                                 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++) {
00376                                         $category = $this->object->categories->getCategory($i);
00377                                         if ($this->object->getSubtype() == SUBTYPE_MCSR)
00378                                         {
00379                                                 $template->setCurrentBlock("nominal_row_sr");
00380                                                 $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
00381                                                 $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
00382                                                 $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
00383                                                 $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
00384                                                 $template->parseCurrentBlock();
00385                                         }
00386                                         else
00387                                         {
00388                                                 $template->setCurrentBlock("nominal_row_mr");
00389                                                 $template->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.gif")));
00390                                                 $template->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
00391                                                 $template->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
00392                                                 $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
00393                                                 $template->parseCurrentBlock();
00394                                         }
00395                                 }
00396                                 break;
00397                         case 1:
00398                                 // horizontal orientation
00399                                 if ($this->object->getSubtype() == SUBTYPE_MCSR)
00400                                 {
00401                                         for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++) 
00402                                         {
00403                                                 $category = $this->object->categories->getCategory($i);
00404                                                 $template->setCurrentBlock("radio_col_nominal");
00405                                                 $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
00406                                                 $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
00407                                                 $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
00408                                                 $template->parseCurrentBlock();
00409                                         }
00410                                         for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++) 
00411                                         {
00412                                                 $category = $this->object->categories->getCategory($i);
00413                                                 $template->setCurrentBlock("text_col_nominal");
00414                                                 $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
00415                                                 $template->parseCurrentBlock();
00416                                         }
00417                                 }
00418                                 else
00419                                 {
00420                                         for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++) 
00421                                         {
00422                                                 $category = $this->object->categories->getCategory($i);
00423                                                 $template->setCurrentBlock("checkbox_col_nominal");
00424                                                 $template->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.gif")));
00425                                                 $template->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
00426                                                 $template->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
00427                                                 $template->parseCurrentBlock();
00428                                         }
00429                                         for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++) 
00430                                         {
00431                                                 $category = $this->object->categories->getCategory($i);
00432                                                 $template->setCurrentBlock("text_col_nominal_mr");
00433                                                 $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
00434                                                 $template->parseCurrentBlock();
00435                                         }
00436                                 }
00437                                 break;
00438                         case 2:
00439                                 // combobox output
00440                                 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++) 
00441                                 {
00442                                         $category = $this->object->categories->getCategory($i);
00443                                         $template->setCurrentBlock("comborow_nominal");
00444                                         $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
00445                                         $template->setVariable("VALUE_NOMINAL", $i);
00446                                         $template->parseCurrentBlock();
00447                                 }
00448                                 $template->setCurrentBlock("combooutput_nominal");
00449                                 $template->setVariable("QUESTION_ID", $this->object->getId());
00450                                 $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
00451                                 $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
00452                                 $template->parseCurrentBlock();
00453                                 break;
00454                 }
00455                 
00456                 if ($show_questiontext)
00457                 {
00458                         $questiontext = $this->object->getQuestiontext();
00459                         $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00460                 }
00461                 if (! $this->object->getObligatory())
00462                 {
00463                         $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
00464                 }
00465                 if ($question_title)
00466                 {
00467                         $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
00468                 }
00469                 $template->parseCurrentBlock();
00470                 return $template->get();
00471         }
00472         
00480         function preview()
00481         {
00482                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", "Modules/SurveyQuestionPool");
00483                 $question_output = $this->getWorkingForm();
00484                 $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
00485                 $this->tpl->parseCurrentBlock();
00486         }
00487 
00496   function writePostData() 
00497         {
00498     $result = 0;
00499     if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00500       $result = 1;
00501 
00502     // Set the question id from a hidden form parameter
00503     if ($_POST["id"] > 0)
00504       $this->object->setId($_POST["id"]);
00505                 include_once "./Services/Utilities/classes/class.ilUtil.php";
00506     $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00507     $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00508     $this->object->setDescription(ilUtil::stripSlashes($_POST["description"]));
00509                 if (strlen($_POST["material"]))
00510                 {
00511                         $this->object->setMaterial($_POST["material"], 0, ilUtil::stripSlashes($_POST["material_title"]));
00512                 }
00513                 $this->object->setSubtype($_POST["type"]);
00514                 $this->object->setOrientation($_POST["orientation"]);
00515                 include_once "./classes/class.ilObjAdvancedEditing.php";
00516                 $questiontext = ilUtil::stripSlashes($_POST["question"], true, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("survey"));
00517                 $this->object->setQuestiontext($questiontext);
00518                 if ($_POST["obligatory"])
00519                 {
00520                         $this->object->setObligatory(1);
00521                 }
00522                 else
00523                 {
00524                         $this->object->setObligatory(0);
00525                 }
00526 
00527                 if ($saved) 
00528                 {
00529                         // If the question was saved automatically before an upload, we have to make
00530                         // sure, that the state after the upload is saved. Otherwise the user could be
00531                         // irritated, if he presses cancel, because he only has the question state before
00532                         // the upload process.
00533                         $this->object->saveToDb("", false);
00534                 }
00535     return $result;
00536   }
00537         
00545         function categories($add = false)
00546         {
00547                 if ($this->object->getId() < 1) 
00548                 {
00549                         ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_category"), true);
00550                         $this->ctrl->redirect($this, "editQuestion");
00551                 }
00552                 if (strcmp($this->ctrl->getCmd(), "categories") == 0) $_SESSION["spl_modified"] = false;
00553                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_nominal_answers.html", "Modules/SurveyQuestionPool");
00554     // output of existing single response answers
00555                 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++) 
00556                 {
00557                         $this->tpl->setCurrentBlock("cat_selector");
00558                         $this->tpl->setVariable("CATEGORY_ORDER", $i);
00559                         $this->tpl->parseCurrentBlock();
00560                         $this->tpl->setCurrentBlock("categories");
00561                         $category = $this->object->categories->getCategory($i);
00562                         $this->tpl->setVariable("CATEGORY_ORDER", $i);
00563                         $this->tpl->setVariable("CATEGORY_NUMBER", $i+1);
00564                         $this->tpl->setVariable("VALUE_CATEGORY", $category);
00565                         $this->tpl->setVariable("TEXT_CATEGORY", $this->lng->txt("category"));
00566                         $this->tpl->parseCurrentBlock();
00567                 }
00568                 
00569                 if ($add)
00570                 {
00571                         $nrOfCategories = $_POST["nrOfCategories"];
00572                         if ($nrOfCategories < 1) $nrOfCategories = 1;
00573                         // Create template for a new category
00574                         for ($i = 1; $i <= $nrOfCategories; $i++)
00575                         {
00576                                 $this->tpl->setCurrentBlock("categories");
00577                                 $this->tpl->setVariable("CATEGORY_ORDER", $this->object->categories->getCategoryCount() + $i - 1);
00578                                 $this->tpl->setVariable("TEXT_CATEGORY", $this->lng->txt("category"));
00579                                 $this->tpl->parseCurrentBlock();
00580                         }
00581                 }
00582 
00583                 if (is_array($_SESSION["spl_move"]))
00584                 {
00585                         if (count($_SESSION["spl_move"]))
00586                         {
00587                                 $this->tpl->setCurrentBlock("move_buttons");
00588                                 $this->tpl->setVariable("INSERT_BEFORE", $this->lng->txt("insert_before"));
00589                                 $this->tpl->setVariable("INSERT_AFTER", $this->lng->txt("insert_after"));
00590                                 $this->tpl->parseCurrentBlock();
00591                         }
00592                 }
00593                 
00594                 include_once "./Services/Utilities/classes/class.ilUtil.php";
00595                 if ($this->object->categories->getCategoryCount() == 0)
00596                 {
00597                         if (!$add)
00598                         {
00599                                 $this->tpl->setCurrentBlock("nocategories");
00600                                 $this->tpl->setVariable("NO_CATEGORIES", $this->lng->txt("question_contains_no_categories"));
00601                                 $this->tpl->parseCurrentBlock();
00602                         }
00603                 }
00604                 else
00605                 {
00606                         $this->tpl->setCurrentBlock("selectall");
00607                         $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
00608                         $this->tpl->parseCurrentBlock();
00609                         $this->tpl->setCurrentBlock("existingcategories");
00610                         $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00611                         $this->tpl->setVariable("MOVE", $this->lng->txt("move"));
00612                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
00613                         $this->tpl->parseCurrentBlock();
00614                 }
00615 
00616                 for ($i = 1; $i < 10; $i++)
00617                 {
00618                         $this->tpl->setCurrentBlock("numbers");
00619                         $this->tpl->setVariable("VALUE_NUMBER", $i);
00620                         if ($i == 1)
00621                         {
00622                                 $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("category"));
00623                         }
00624                         else
00625                         {
00626                                 $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("categories"));
00627                         }
00628                         $this->tpl->parseCurrentBlock();
00629                 }
00630                 
00631                 $this->tpl->setCurrentBlock("adm_content");
00632                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00633                 $this->tpl->setVariable("VALUE_ADD_CATEGORY", $this->lng->txt("add"));
00634                 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00635                 if ($_SESSION["spl_modified"])
00636                 {
00637                         $this->tpl->setVariable("FORM_DATA_MODIFIED_PRESS_SAVE", $this->lng->txt("form_data_modified_press_save"));
00638                 }
00639                 $questiontext = $this->object->getQuestiontext();
00640                 $this->tpl->setVariable("QUESTION_TEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00641                 $this->tpl->parseCurrentBlock();
00642         }
00643         
00644         function setQuestionTabs()
00645         {
00646                 $this->setQuestionTabsForClass("surveynominalquestiongui");
00647         }
00648 
00656         function saveCategories()
00657         {
00658                 global $ilUser;
00659                 
00660                 $this->writeCategoryData(true);
00661                 $_SESSION["spl_modified"] = false;
00662                 ilUtil::sendInfo($this->lng->txt("saved_successfully"), true);
00663                 $originalexists = $this->object->_questionExists($this->object->original_id);
00664                 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00665                 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
00666                 if ($_GET["calling_survey"] && $originalexists && SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
00667                 {
00668                         $this->originalSyncForm();
00669                         return;
00670                 }
00671                 else
00672                 {
00673                         $this->ctrl->redirect($this, "categories");
00674                 }
00675         }
00676 
00684         function addCategory()
00685         {
00686                 $result = $this->writeCategoryData();
00687                 if ($result == false)
00688                 {
00689                         ilUtil::sendInfo($this->lng->txt("fill_out_all_category_fields"));
00690                 }
00691                 $_SESSION["spl_modified"] = true;
00692                 $this->categories($result);
00693         }
00694         
00704         function writeCategoryData($save = false)
00705         {
00706     // Delete all existing categories and create new categories from the form data
00707     $this->object->categories->flushCategories();
00708                 $complete = true;
00709                 $array1 = array();
00710     // Add all categories from the form into the object
00711                 include_once "./Services/Utilities/classes/class.ilUtil.php";
00712                 foreach ($_POST as $key => $value) 
00713                 {
00714                         if (preg_match("/^category_(\d+)/", $key, $matches)) 
00715                         {
00716                                 $array1[$matches[1]] = ilUtil::stripSlashes($value);
00717                                 if (strlen($array1[$matches[1]]) == 0) $complete = false;
00718                         }
00719                 }
00720                 $this->object->categories->addCategoryArray($array1);
00721                 if ($save)
00722                 {       
00723                         $this->object->saveCategoriesToDb();
00724                 }
00725                 return $complete;
00726         }
00727         
00735         function deleteCategory()
00736         {
00737                 $this->writeCategoryData();
00738                 $nothing_selected = true;
00739                 if (array_key_exists("chb_category", $_POST))
00740                 {
00741                         if (count($_POST["chb_category"]))
00742                         {
00743                                 $nothing_selected = false;
00744                                 $this->object->categories->removeCategories($_POST["chb_category"]);
00745                         }
00746                 }
00747                 if ($nothing_selected) ilUtil::sendInfo($this->lng->txt("category_delete_select_none"));
00748                 $_SESSION["spl_modified"] = true;
00749                 $this->categories();
00750         }
00751         
00759         function moveCategory()
00760         {
00761                 $this->writeCategoryData();
00762                 $nothing_selected = true;
00763                 if (array_key_exists("chb_category", $_POST))
00764                 {
00765                         if (count($_POST["chb_category"]))
00766                         {
00767                                 $nothing_selected = false;
00768                                 ilUtil::sendInfo($this->lng->txt("select_target_position_for_move"));
00769                                 $_SESSION["spl_move"] = $_POST["chb_category"];
00770                         }
00771                 }
00772                 if ($nothing_selected) ilUtil::sendInfo($this->lng->txt("no_category_selected_for_move"));
00773                 $this->categories();
00774         }
00775         
00783         function insertBeforeCategory()
00784         {
00785                 $result = $this->writeCategoryData();
00786                 if (array_key_exists("chb_category", $_POST))
00787                 {
00788                         if (count($_POST["chb_category"]) == 1)
00789                         {
00790                                 // one entry is selected, moving is allowed
00791                                 $this->object->categories->removeCategories($_SESSION["spl_move"]);
00792                                 $newinsertindex = $this->object->categories->getCategoryIndex($_POST["category_".$_POST["chb_category"][0]]);
00793                                 if ($newinsertindex === false) $newinsertindex = 0;
00794                                 $move_categories = $_SESSION["spl_move"];
00795                                 natsort($move_categories);
00796                                 foreach (array_reverse($move_categories) as $index)
00797                                 {
00798                                         $this->object->categories->addCategoryAtPosition($_POST["category_$index"], $newinsertindex);
00799                                 }
00800                                 $_SESSION["spl_modified"] = true;
00801                                 unset($_SESSION["spl_move"]);
00802                         }
00803                         else
00804                         {
00805                                 ilUtil::sendInfo("wrong_categories_selected_for_insert");
00806                         }
00807                 }
00808                 $this->categories();
00809         }
00810         
00818         function insertAfterCategory()
00819         {
00820                 $result = $this->writeCategoryData();
00821                 if (array_key_exists("chb_category", $_POST))
00822                 {
00823                         if (count($_POST["chb_category"]) == 1)
00824                         {
00825                                 // one entry is selected, moving is allowed
00826                                 $this->object->categories->removeCategories($_SESSION["spl_move"]);
00827                                 $newinsertindex = $this->object->categories->getCategoryIndex($_POST["category_".$_POST["chb_category"][0]]);
00828                                 if ($newinsertindex === false) $newinsertindex = 0;
00829                                 $move_categories = $_SESSION["spl_move"];
00830                                 natsort($move_categories);
00831                                 foreach (array_reverse($move_categories) as $index)
00832                                 {
00833                                         $this->object->categories->addCategoryAtPosition($_POST["category_$index"], $newinsertindex+1);
00834                                 }
00835                                 $_SESSION["spl_modified"] = true;
00836                                 unset($_SESSION["spl_move"]);
00837                         }
00838                         else
00839                         {
00840                                 ilUtil::sendInfo("wrong_categories_selected_for_insert");
00841                         }
00842                 }
00843                 $this->categories();
00844         }
00845 
00854         function getCumulatedResultRow($counter, $css_class, $survey_id)
00855         {
00856                 include_once "./classes/class.ilTemplate.php";
00857                 if (count($this->cumulated) == 0)
00858                 {
00859                         include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
00860                         $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
00861                         $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
00862                 }
00863                 $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_row.html", TRUE, TRUE, "Modules/Survey");
00864                 $template->setVariable("QUESTION_TITLE", ($counter+1) . ". ".$this->object->getTitle());
00865                 $maxlen = 37;
00866                 $questiontext = preg_replace("/<[^>]+?>/ims", "", $this->object->getQuestiontext());
00867                 if (strlen($questiontext) > $maxlen + 3)
00868                 {
00869                         $questiontext = substr($questiontext, 0, $maxlen) . "...";
00870                 }
00871                 $template->setVariable("QUESTION_TEXT", $questiontext);
00872                 $template->setVariable("USERS_ANSWERED", $this->cumulated["USERS_ANSWERED"]);
00873                 $template->setVariable("USERS_SKIPPED", $this->cumulated["USERS_SKIPPED"]);
00874                 $template->setVariable("QUESTION_TYPE", $this->lng->txt($this->cumulated["QUESTION_TYPE"]));
00875                 $template->setVariable("MODE", $this->cumulated["MODE"]);
00876                 $template->setVariable("MODE_NR_OF_SELECTIONS", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
00877                 $template->setVariable("MEDIAN", $this->cumulated["MEDIAN"]);
00878                 $template->setVariable("ARITHMETIC_MEAN", $this->cumulated["ARITHMETIC_MEAN"]);
00879                 $template->setVariable("COLOR_CLASS", $css_class);
00880                 return $template->get();
00881         }
00882 
00893         function getCumulatedResultsDetails($survey_id, $counter)
00894         {
00895                 if (count($this->cumulated) == 0)
00896                 {
00897                         include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
00898                         $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
00899                         $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
00900                 }
00901                 
00902                 $output = "";
00903                 include_once "./classes/class.ilTemplate.php";
00904                 $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
00905 
00906                 $template->setCurrentBlock("detail_row");
00907                 $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
00908                 $questiontext = $this->object->getQuestiontext();
00909                 $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
00910                 $template->parseCurrentBlock();
00911                 $template->setCurrentBlock("detail_row");
00912                 $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
00913                 $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
00914                 $template->parseCurrentBlock();
00915                 $template->setCurrentBlock("detail_row");
00916                 $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
00917                 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
00918                 $template->parseCurrentBlock();
00919                 $template->setCurrentBlock("detail_row");
00920                 $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
00921                 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
00922                 $template->parseCurrentBlock();
00923                 
00924                 $template->setCurrentBlock("detail_row");
00925                 $template->setVariable("TEXT_OPTION", $this->lng->txt("subtype"));
00926                 switch ($this->object->getSubType())
00927                 {
00928                         case SUBTYPE_MCSR:
00929                                 $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("multiple_choice_single_response"));
00930                                 break;
00931                         case SUBTYPE_MCMR:
00932                                 $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("multiple_choice_multiple_response"));
00933                                 break;
00934                 }
00935                 $template->parseCurrentBlock();
00936 
00937                 $template->setCurrentBlock("detail_row");
00938                 $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
00939                 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE"]);
00940                 $template->parseCurrentBlock();
00941                 $template->setCurrentBlock("detail_row");
00942                 $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
00943                 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
00944                 $template->parseCurrentBlock();
00945                 
00946                 $template->setCurrentBlock("detail_row");
00947                 $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
00948                 $categories = "";
00949                 if (is_array($this->cumulated["variables"]))
00950                 {
00951                         foreach ($this->cumulated["variables"] as $key => $value)
00952                         {
00953                                 $categories .= "<li>" . $this->lng->txt("title") . ":" . "<span class=\"bold\">" . $value["title"] . "</span><br />" .
00954                                         $this->lng->txt("category_nr_selected") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
00955                                         $this->lng->txt("percentage_of_selections") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
00956                         }
00957                 }
00958                 $categories = "<ol>$categories</ol>";
00959                 $template->setVariable("TEXT_OPTION_VALUE", $categories);
00960                 $template->parseCurrentBlock();
00961                 
00962                 // display chart for nominal question for array $eval["variables"]
00963                 $template->setCurrentBlock("chart");
00964                 $template->setVariable("TEXT_CHART", $this->lng->txt("chart"));
00965                 $template->setVariable("ALT_CHART", $data["title"] . "( " . $this->lng->txt("chart") . ")");
00966                 $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "survey", $survey_id);
00967                 $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "question", $this->object->getId());
00968                 $template->setVariable("CHART", $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "outChart"));
00969                 $template->parseCurrentBlock();
00970                 
00971                 $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
00972                 return $template->get();
00973         }
00974 
00975                 
00976 }
00977 ?>

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