00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 include_once "./survey/classes/class.SurveyQuestionGUI.php";
00025 include_once "./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 "./survey/classes/class.SurveyNominalQuestion.php";
00056 $this->object = new SurveyNominalQuestion();
00057 if ($id >= 0)
00058 {
00059 $this->object->loadFromDb($id);
00060 }
00061 }
00062
00071 function getQuestionType()
00072 {
00073 return "qt_nominal";
00074 }
00075
00083 function editQuestion()
00084 {
00085 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_nominal.html", true);
00086 $this->tpl->addBlockFile("OTHER_QUESTION_DATA", "other_question_data", "tpl.il_svy_qpl_other_question_data.html", true);
00087 $this->tpl->setVariable("TEXT_ORIENTATION", $this->lng->txt("orientation"));
00088 switch ($this->object->getOrientation())
00089 {
00090 case 0:
00091 $this->tpl->setVariable("SELECTED_VERTICAL", " selected=\"selected\"");
00092 break;
00093 case 1:
00094 $this->tpl->setVariable("SELECTED_HORIZONTAL", " selected=\"selected\"");
00095 break;
00096 case 2:
00097 $this->tpl->setVariable("SELECTED_COMBOBOX", " selected=\"selected\"");
00098 break;
00099 }
00100 $this->tpl->setVariable("TXT_VERTICAL", $this->lng->txt("vertical"));
00101 $this->tpl->setVariable("TXT_HORIZONTAL", $this->lng->txt("horizontal"));
00102 if ($this->object->getSubtype() == SUBTYPE_MCSR)
00103 {
00104 $this->tpl->setVariable("TXT_COMBOBOX", $this->lng->txt("combobox"));
00105 }
00106
00107 $internallinks = array(
00108 "lm" => $this->lng->txt("obj_lm"),
00109 "st" => $this->lng->txt("obj_st"),
00110 "pg" => $this->lng->txt("obj_pg"),
00111 "glo" => $this->lng->txt("glossary_term")
00112 );
00113 foreach ($internallinks as $key => $value)
00114 {
00115 $this->tpl->setCurrentBlock("internallink");
00116 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00117 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00118 $this->tpl->parseCurrentBlock();
00119 }
00120
00121 $this->tpl->setCurrentBlock("adm_content");
00122 $this->tpl->setVariable("TEXT_MATERIAL", $this->lng->txt("material"));
00123 if (count($this->object->material))
00124 {
00125 include_once "./survey/classes/class.SurveyQuestion.php";
00126 $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
00127 $this->tpl->setVariable("TEXT_VALUE_MATERIAL", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("material"). "</a> ");
00128 $this->tpl->setVariable("BUTTON_REMOVE_MATERIAL", $this->lng->txt("remove"));
00129 $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("change"));
00130 $this->tpl->setVariable("VALUE_MATERIAL", $this->object->material["internal_link"]);
00131 $this->tpl->setVariable("VALUE_MATERIAL_TITLE", $this->object->material["title"]);
00132 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00133 }
00134 else
00135 {
00136 $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("add"));
00137 }
00138 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00139 $this->tpl->setVariable("VALUE_TITLE", $this->object->getTitle());
00140 $this->tpl->setVariable("VALUE_DESCRIPTION", $this->object->getDescription());
00141 $this->tpl->setVariable("VALUE_AUTHOR", $this->object->getAuthor());
00142 $questiontext = $this->object->getQuestiontext();
00143 $questiontext = str_replace("<br />", "\n", $questiontext);
00144 $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
00145 $this->tpl->setVariable("TXT_SR", $this->lng->txt("multiple_choice_single_response"));
00146 $this->tpl->setVariable("TXT_MR", $this->lng->txt("multiple_choice_multiple_response"));
00147 if ($this->object->getSubtype() == SUBTYPE_MCSR)
00148 {
00149 $this->tpl->setVariable("SELECTED_SR", " selected=\"selected\"");
00150 }
00151 else
00152 {
00153 $this->tpl->setVariable("SELECTED_MR", " selected=\"selected\"");
00154 }
00155 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00156 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00157 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
00158 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00159 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("questiontype"));
00160 $this->tpl->setVariable("TEXT_OBLIGATORY", $this->lng->txt("obligatory"));
00161 if ($this->object->getObligatory())
00162 {
00163 $this->tpl->setVariable("CHECKED_OBLIGATORY", " checked=\"checked\"");
00164 }
00165 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00166 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00167 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00168 $this->tpl->parseCurrentBlock();
00169 }
00170
00178 function outWorkingForm($working_data = "", $question_title = 1, $error_message = "")
00179 {
00180 if (count($this->object->material))
00181 {
00182 $this->tpl->setCurrentBlock("material_nominal");
00183 include_once "./survey/classes/class.SurveyQuestion.php";
00184 $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
00185 $this->tpl->setVariable("TEXT_MATERIAL", $this->lng->txt("material") . ": <a href=\"$href\" target=\"content\">" . $this->object->material["title"]. "</a> ");
00186 $this->tpl->parseCurrentBlock();
00187 }
00188 switch ($this->object->getOrientation())
00189 {
00190 case 0:
00191
00192 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++) {
00193 $category = $this->object->categories->getCategory($i);
00194 if ($this->object->getSubtype() == SUBTYPE_MCSR)
00195 {
00196 $this->tpl->setCurrentBlock("nominal_row_sr");
00197 $this->tpl->setVariable("TEXT_NOMINAL", $category);
00198 $this->tpl->setVariable("VALUE_NOMINAL", $i);
00199 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00200 if (is_array($working_data))
00201 {
00202 if (strcmp($working_data[0]["value"], "") != 0)
00203 {
00204 if ($working_data[0]["value"] == $i)
00205 {
00206 $this->tpl->setVariable("CHECKED_NOMINAL", " checked=\"checked\"");
00207 }
00208 }
00209 }
00210 $this->tpl->parseCurrentBlock();
00211 }
00212 else
00213 {
00214 $this->tpl->setCurrentBlock("nominal_row_mr");
00215 $this->tpl->setVariable("TEXT_NOMINAL", $category);
00216 $this->tpl->setVariable("VALUE_NOMINAL", $i);
00217 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00218 if (is_array($working_data))
00219 {
00220 foreach ($working_data as $row)
00221 {
00222 if (strcmp($row["value"], "") != 0)
00223 {
00224 if ($row["value"] == $i)
00225 {
00226 $this->tpl->setVariable("CHECKED_NOMINAL", " checked=\"checked\"");
00227 }
00228 }
00229 }
00230 }
00231 $this->tpl->parseCurrentBlock();
00232 }
00233 }
00234 break;
00235 case 1:
00236
00237 if ($this->object->getSubtype() == SUBTYPE_MCSR)
00238 {
00239 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
00240 {
00241 $category = $this->object->categories->getCategory($i);
00242 $this->tpl->setCurrentBlock("radio_col_nominal");
00243 $this->tpl->setVariable("VALUE_NOMINAL", $i);
00244 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00245 if (is_array($working_data))
00246 {
00247 if (strcmp($working_data[0]["value"], "") != 0)
00248 {
00249 if ($working_data[0]["value"] == $i)
00250 {
00251 $this->tpl->setVariable("CHECKED_NOMINAL", " checked=\"checked\"");
00252 }
00253 }
00254 }
00255 $this->tpl->parseCurrentBlock();
00256 }
00257 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
00258 {
00259 $category = $this->object->categories->getCategory($i);
00260 $this->tpl->setCurrentBlock("text_col_nominal");
00261 $this->tpl->setVariable("VALUE_NOMINAL", $i);
00262 $this->tpl->setVariable("TEXT_NOMINAL", $category);
00263 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00264 $this->tpl->parseCurrentBlock();
00265 }
00266 }
00267 else
00268 {
00269 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
00270 {
00271 $category = $this->object->categories->getCategory($i);
00272 $this->tpl->setCurrentBlock("checkbox_col_nominal");
00273 $this->tpl->setVariable("VALUE_NOMINAL", $i);
00274 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00275 if (is_array($working_data))
00276 {
00277 if (strcmp($working_data[0]["value"], "") != 0)
00278 {
00279 if ($working_data[0]["value"] == $i)
00280 {
00281 $this->tpl->setVariable("CHECKED_NOMINAL", " checked=\"checked\"");
00282 }
00283 }
00284 }
00285 $this->tpl->parseCurrentBlock();
00286 }
00287 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
00288 {
00289 $category = $this->object->categories->getCategory($i);
00290 $this->tpl->setCurrentBlock("text_col_nominal_mr");
00291 $this->tpl->setVariable("VALUE_NOMINAL", $i);
00292 $this->tpl->setVariable("TEXT_NOMINAL", $category);
00293 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00294 $this->tpl->parseCurrentBlock();
00295 }
00296 }
00297 break;
00298 case 2:
00299
00300 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
00301 {
00302 $category = $this->object->categories->getCategory($i);
00303 $this->tpl->setCurrentBlock("comborow_nominal");
00304 $this->tpl->setVariable("TEXT_NOMINAL", $category);
00305 $this->tpl->setVariable("VALUE_NOMINAL", $i);
00306 if (is_array($working_data))
00307 {
00308 if (strcmp($working_data[0]["value"], "") != 0)
00309 {
00310 if ($working_data[0]["value"] == $i)
00311 {
00312 $this->tpl->setVariable("SELECTED_NOMINAL", " selected=\"selected\"");
00313 }
00314 }
00315 }
00316 $this->tpl->parseCurrentBlock();
00317 }
00318 $this->tpl->setCurrentBlock("combooutput_nominal");
00319 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00320 $this->tpl->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
00321 $this->tpl->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
00322 $this->tpl->parseCurrentBlock();
00323 break;
00324 }
00325
00326 $this->tpl->setCurrentBlock("question_data_nominal");
00327 if (strcmp($error_message, "") != 0)
00328 {
00329 $this->tpl->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
00330 }
00331 $this->tpl->setVariable("QUESTIONTEXT", $this->object->getQuestiontext());
00332 if (! $this->object->getObligatory())
00333 {
00334 $this->tpl->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
00335 }
00336 if ($question_title)
00337 {
00338 $this->tpl->setVariable("QUESTION_TITLE", $this->object->getTitle());
00339 }
00340 $this->tpl->parseCurrentBlock();
00341 }
00342
00350 function preview()
00351 {
00352 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", true);
00353 $this->tpl->addBlockFile("NOMINAL", "nominal", "tpl.il_svy_out_nominal.html", true);
00354 $this->outWorkingForm();
00355 $this->tpl->parseCurrentBlock();
00356 }
00357
00366 function writePostData()
00367 {
00368 $result = 0;
00369 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00370 $result = 1;
00371
00372
00373 if ($_POST["id"] > 0)
00374 $this->object->setId($_POST["id"]);
00375 include_once "./classes/class.ilUtil.php";
00376 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00377 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00378 $this->object->setDescription(ilUtil::stripSlashes($_POST["description"]));
00379 if (strlen($_POST["material"]))
00380 {
00381 $this->object->setMaterial($_POST["material"], 0, ilUtil::stripSlashes($_POST["material_title"]));
00382 }
00383 $this->object->setSubtype($_POST["type"]);
00384 $this->object->setOrientation($_POST["orientation"]);
00385 $questiontext = ilUtil::stripSlashes($_POST["question"]);
00386 $questiontext = str_replace("\n", "<br />", $questiontext);
00387 $this->object->setQuestiontext($questiontext);
00388 if ($_POST["obligatory"])
00389 {
00390 $this->object->setObligatory(1);
00391 }
00392 else
00393 {
00394 $this->object->setObligatory(0);
00395 }
00396
00397 if ($saved)
00398 {
00399
00400
00401
00402
00403 $this->object->saveToDb("", false);
00404 }
00405 return $result;
00406 }
00407
00415 function categories($add = false)
00416 {
00417 if ($this->object->getId() < 1)
00418 {
00419 sendInfo($this->lng->txt("fill_out_all_required_fields_add_category"), true);
00420 $this->ctrl->redirect($this, "editQuestion");
00421 }
00422 if (strcmp($this->ctrl->getCmd(), "categories") == 0) $_SESSION["spl_modified"] = false;
00423 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_nominal_answers.html", true);
00424
00425 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
00426 {
00427 $this->tpl->setCurrentBlock("cat_selector");
00428 $this->tpl->setVariable("CATEGORY_ORDER", $i);
00429 $this->tpl->parseCurrentBlock();
00430 $this->tpl->setCurrentBlock("categories");
00431 $category = $this->object->categories->getCategory($i);
00432 $this->tpl->setVariable("CATEGORY_ORDER", $i);
00433 $this->tpl->setVariable("CATEGORY_NUMBER", $i+1);
00434 $this->tpl->setVariable("VALUE_CATEGORY", $category);
00435 $this->tpl->setVariable("TEXT_CATEGORY", $this->lng->txt("category"));
00436 $this->tpl->parseCurrentBlock();
00437 }
00438
00439 if ($add)
00440 {
00441 $nrOfCategories = $_POST["nrOfCategories"];
00442 if ($nrOfCategories < 1) $nrOfCategories = 1;
00443
00444 for ($i = 1; $i <= $nrOfCategories; $i++)
00445 {
00446 $this->tpl->setCurrentBlock("categories");
00447 $this->tpl->setVariable("CATEGORY_ORDER", $this->object->categories->getCategoryCount() + $i - 1);
00448 $this->tpl->setVariable("TEXT_CATEGORY", $this->lng->txt("category"));
00449 $this->tpl->parseCurrentBlock();
00450 }
00451 }
00452
00453 if (is_array($_SESSION["spl_move"]))
00454 {
00455 if (count($_SESSION["spl_move"]))
00456 {
00457 $this->tpl->setCurrentBlock("move_buttons");
00458 $this->tpl->setVariable("INSERT_BEFORE", $this->lng->txt("insert_before"));
00459 $this->tpl->setVariable("INSERT_AFTER", $this->lng->txt("insert_after"));
00460 $this->tpl->parseCurrentBlock();
00461 }
00462 }
00463
00464 include_once "./classes/class.ilUtil.php";
00465 if ($this->object->categories->getCategoryCount() == 0)
00466 {
00467 if (!$add)
00468 {
00469 $this->tpl->setCurrentBlock("nocategories");
00470 $this->tpl->setVariable("NO_CATEGORIES", $this->lng->txt("question_contains_no_categories"));
00471 $this->tpl->parseCurrentBlock();
00472 }
00473 }
00474 else
00475 {
00476 $this->tpl->setCurrentBlock("selectall");
00477 $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
00478 $this->tpl->parseCurrentBlock();
00479 $this->tpl->setCurrentBlock("existingcategories");
00480 $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00481 $this->tpl->setVariable("MOVE", $this->lng->txt("move"));
00482 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
00483 $this->tpl->parseCurrentBlock();
00484 }
00485
00486 for ($i = 1; $i < 10; $i++)
00487 {
00488 $this->tpl->setCurrentBlock("numbers");
00489 $this->tpl->setVariable("VALUE_NUMBER", $i);
00490 if ($i == 1)
00491 {
00492 $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("category"));
00493 }
00494 else
00495 {
00496 $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("categories"));
00497 }
00498 $this->tpl->parseCurrentBlock();
00499 }
00500
00501 $this->tpl->setCurrentBlock("adm_content");
00502 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00503 $this->tpl->setVariable("VALUE_ADD_CATEGORY", $this->lng->txt("add"));
00504 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00505 if ($_SESSION["spl_modified"])
00506 {
00507 $this->tpl->setVariable("FORM_DATA_MODIFIED_PRESS_SAVE", $this->lng->txt("form_data_modified_press_save"));
00508 }
00509 $this->tpl->setVariable("QUESTION_TEXT", ilUtil::prepareFormOutput($this->object->getQuestiontext()));
00510 $this->tpl->parseCurrentBlock();
00511 }
00512
00513 function setQuestionTabs()
00514 {
00515 $this->setQuestionTabsForClass("surveynominalquestiongui");
00516 }
00517 }
00518 ?>