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 "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
00025 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
00026
00038 class SurveyOrdinalQuestionGUI extends SurveyQuestionGUI
00039 {
00040
00049 function SurveyOrdinalQuestionGUI(
00050 $id = -1
00051 )
00052
00053 {
00054 $this->SurveyQuestionGUI();
00055 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyOrdinalQuestion.php";
00056 $this->object = new SurveyOrdinalQuestion();
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_ordinal.html", "Modules/SurveyQuestionPool");
00073 $this->tpl->addBlockFile("OTHER_QUESTION_DATA", "other_question_data", "tpl.il_svy_qpl_other_question_data.html", "Modules/SurveyQuestionPool");
00074 $internallinks = array(
00075 "lm" => $this->lng->txt("obj_lm"),
00076 "st" => $this->lng->txt("obj_st"),
00077 "pg" => $this->lng->txt("obj_pg"),
00078 "glo" => $this->lng->txt("glossary_term")
00079 );
00080 foreach ($internallinks as $key => $value)
00081 {
00082 $this->tpl->setCurrentBlock("internallink");
00083 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00084 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00085 $this->tpl->parseCurrentBlock();
00086 }
00087
00088 $this->tpl->setCurrentBlock("adm_content");
00089 $this->tpl->setVariable("TEXT_MATERIAL", $this->lng->txt("material"));
00090 if (count($this->object->material))
00091 {
00092 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
00093 $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
00094 $this->tpl->setVariable("TEXT_VALUE_MATERIAL", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("material"). "</a> ");
00095 $this->tpl->setVariable("BUTTON_REMOVE_MATERIAL", $this->lng->txt("remove"));
00096 $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("change"));
00097 $this->tpl->setVariable("VALUE_MATERIAL", $this->object->material["internal_link"]);
00098 $this->tpl->setVariable("VALUE_MATERIAL_TITLE", $this->object->material["title"]);
00099 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00100 }
00101 else
00102 {
00103 $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("add"));
00104 }
00105 $this->tpl->setVariable("TEXT_ORIENTATION", $this->lng->txt("orientation"));
00106 switch ($this->object->getOrientation())
00107 {
00108 case 0:
00109 $this->tpl->setVariable("CHECKED_VERTICAL", " checked=\"checked\"");
00110 break;
00111 case 1:
00112 $this->tpl->setVariable("CHECKED_HORIZONTAL", " checked=\"checked\"");
00113 break;
00114 case 2:
00115 $this->tpl->setVariable("CHECKED_COMBOBOX", " checked=\"checked\"");
00116 break;
00117 }
00118 $this->tpl->setVariable("TXT_VERTICAL", $this->lng->txt("vertical"));
00119 $this->tpl->setVariable("TXT_HORIZONTAL", $this->lng->txt("horizontal"));
00120 $this->tpl->setVariable("TXT_COMBOBOX", $this->lng->txt("combobox"));
00121 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00122 $this->tpl->setVariable("VALUE_TITLE", $this->object->getTitle());
00123 $this->tpl->setVariable("VALUE_DESCRIPTION", $this->object->getDescription());
00124 $this->tpl->setVariable("VALUE_AUTHOR", $this->object->getAuthor());
00125 $questiontext = $this->object->getQuestiontext();
00126 $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
00127 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00128 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00129 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
00130 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00131 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("questiontype"));
00132 $this->tpl->setVariable("TEXT_OBLIGATORY", $this->lng->txt("obligatory"));
00133 if ($this->object->getObligatory())
00134 {
00135 $this->tpl->setVariable("CHECKED_OBLIGATORY", " checked=\"checked\"");
00136 }
00137 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00138 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00139 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00140 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt($this->getQuestionType()));
00141 $this->tpl->parseCurrentBlock();
00142 include_once "./Services/RTE/classes/class.ilRTE.php";
00143 $rtestring = ilRTE::_getRTEClassname();
00144 include_once "./Services/RTE/classes/class.$rtestring.php";
00145 $rte = new $rtestring();
00146 $rte->addPlugin("latex");
00147 $rte->addButton("latex"); $rte->addButton("pastelatex");
00148 $rte->removePlugin("ibrowser");
00149 include_once "./classes/class.ilObject.php";
00150 $obj_id = $_GET["q_id"];
00151 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00152 $rte->addRTESupport($obj_id, $obj_type, "survey");
00153
00154 }
00155
00163 function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "")
00164 {
00165 $template = new ilTemplate("tpl.il_svy_out_ordinal.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
00166 if (count($this->object->material))
00167 {
00168 $template->setCurrentBlock("material_ordinal");
00169 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
00170 $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
00171 $template->setVariable("TEXT_MATERIAL", $this->lng->txt("material") . ": <a href=\"$href\" target=\"content\">" . $this->object->material["title"]. "</a> ");
00172 $template->parseCurrentBlock();
00173 }
00174 switch ($this->object->orientation)
00175 {
00176 case 0:
00177
00178 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
00179 {
00180 $category = $this->object->categories->getCategory($i);
00181 $template->setCurrentBlock("ordinal_row");
00182 $template->setVariable("TEXT_ORDINAL", ilUtil::prepareFormOutput($category));
00183 $template->setVariable("VALUE_ORDINAL", $i);
00184 $template->setVariable("QUESTION_ID", $this->object->getId());
00185 if (is_array($working_data))
00186 {
00187 if (strcmp($working_data[0]["value"], "") != 0)
00188 {
00189 if ($working_data[0]["value"] == $i)
00190 {
00191 $template->setVariable("CHECKED_ORDINAL", " checked=\"checked\"");
00192 }
00193 }
00194 }
00195 $template->parseCurrentBlock();
00196 }
00197 break;
00198 case 1:
00199
00200 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
00201 {
00202 $category = $this->object->categories->getCategory($i);
00203 $template->setCurrentBlock("radio_col_ordinal");
00204 $template->setVariable("VALUE_ORDINAL", $i);
00205 $template->setVariable("QUESTION_ID", $this->object->getId());
00206 if (is_array($working_data))
00207 {
00208 if (strcmp($working_data[0]["value"], "") != 0)
00209 {
00210 if ($working_data[0]["value"] == $i)
00211 {
00212 $template->setVariable("CHECKED_ORDINAL", " checked=\"checked\"");
00213 }
00214 }
00215 }
00216 $template->parseCurrentBlock();
00217 }
00218 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
00219 {
00220 $category = $this->object->categories->getCategory($i);
00221 $template->setCurrentBlock("text_col_ordinal");
00222 $template->setVariable("VALUE_ORDINAL", $i);
00223 $template->setVariable("TEXT_ORDINAL", ilUtil::prepareFormOutput($category));
00224 $template->setVariable("QUESTION_ID", $this->object->getId());
00225 $template->parseCurrentBlock();
00226 }
00227 break;
00228 case 2:
00229
00230 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
00231 {
00232 $category = $this->object->categories->getCategory($i);
00233 $template->setCurrentBlock("comborow");
00234 $template->setVariable("TEXT_ORDINAL", $category);
00235 $template->setVariable("VALUE_ORDINAL", $i);
00236 if (is_array($working_data))
00237 {
00238 if (strcmp($working_data[0]["value"], "") != 0)
00239 {
00240 if ($working_data[0]["value"] == $i)
00241 {
00242 $template->setVariable("SELECTED_ORDINAL", " selected=\"selected\"");
00243 }
00244 }
00245 }
00246 $template->parseCurrentBlock();
00247 }
00248 $template->setCurrentBlock("combooutput");
00249 $template->setVariable("QUESTION_ID", $this->object->getId());
00250 $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
00251 $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
00252 $template->parseCurrentBlock();
00253 break;
00254 }
00255 if ($question_title)
00256 {
00257 $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
00258 }
00259 $template->setCurrentBlock("question_data_ordinal");
00260 if (strcmp($error_message, "") != 0)
00261 {
00262 $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
00263 }
00264 if ($show_questiontext)
00265 {
00266 $questiontext = $this->object->getQuestiontext();
00267 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00268 }
00269 if (! $this->object->getObligatory())
00270 {
00271 $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
00272 }
00273 $template->parseCurrentBlock();
00274 return $template->get();
00275 }
00276
00284 function getPrintView($question_title = 1, $show_questiontext = 1)
00285 {
00286 $template = new ilTemplate("tpl.il_svy_qpl_ordinal_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
00287 switch ($this->object->orientation)
00288 {
00289 case 0:
00290
00291 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
00292 {
00293 $category = $this->object->categories->getCategory($i);
00294 $template->setCurrentBlock("ordinal_row");
00295 $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
00296 $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
00297 $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
00298 $template->setVariable("TEXT_ORDINAL", ilUtil::prepareFormOutput($category));
00299 $template->parseCurrentBlock();
00300 }
00301 break;
00302 case 1:
00303
00304 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
00305 {
00306 $category = $this->object->categories->getCategory($i);
00307 $template->setCurrentBlock("radio_col_ordinal");
00308 $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
00309 $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
00310 $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
00311 $template->parseCurrentBlock();
00312 }
00313 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
00314 {
00315 $category = $this->object->categories->getCategory($i);
00316 $template->setCurrentBlock("text_col_ordinal");
00317 $template->setVariable("TEXT_ORDINAL", $category);
00318 $template->parseCurrentBlock();
00319 }
00320 break;
00321 case 2:
00322
00323 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
00324 {
00325 $category = $this->object->categories->getCategory($i);
00326 $template->setCurrentBlock("comborow");
00327 $template->setVariable("TEXT_ORDINAL", ilUtil::prepareFormOutput($category));
00328 $template->setVariable("VALUE_ORDINAL", $i);
00329 if (is_array($working_data))
00330 {
00331 if (strcmp($working_data[0]["value"], "") != 0)
00332 {
00333 if ($working_data[0]["value"] == $i)
00334 {
00335 $template->setVariable("SELECTED_ORDINAL", " selected=\"selected\"");
00336 }
00337 }
00338 }
00339 $template->parseCurrentBlock();
00340 }
00341 $template->setCurrentBlock("combooutput");
00342 $template->setVariable("QUESTION_ID", $this->object->getId());
00343 $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
00344 $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
00345 $template->parseCurrentBlock();
00346 break;
00347 }
00348 if ($question_title)
00349 {
00350 $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
00351 }
00352 if ($show_questiontext)
00353 {
00354 $questiontext = $this->object->getQuestiontext();
00355 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00356 }
00357 if (! $this->object->getObligatory())
00358 {
00359 $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
00360 }
00361 $template->parseCurrentBlock();
00362 return $template->get();
00363 }
00364
00372 function preview()
00373 {
00374 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", "Modules/SurveyQuestionPool");
00375 $question_output = $this->getWorkingForm();
00376 $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
00377 $this->tpl->parseCurrentBlock();
00378 }
00379
00388 function writePostData()
00389 {
00390 $result = 0;
00391 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00392 $result = 1;
00393
00394
00395 if ($_POST["id"] > 0)
00396 $this->object->setId($_POST["id"]);
00397 include_once "./Services/Utilities/classes/class.ilUtil.php";
00398 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00399 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00400 $this->object->setDescription(ilUtil::stripSlashes($_POST["description"]));
00401 $this->object->setOrientation($_POST["orientation"]);
00402 if (strlen($_POST["material"]))
00403 {
00404 $this->object->setMaterial($_POST["material"], 0, ilUtil::stripSlashes($_POST["material_title"]));
00405 }
00406 include_once "./classes/class.ilObjAdvancedEditing.php";
00407 $questiontext = ilUtil::stripSlashes($_POST["question"], true, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("survey"));
00408 $this->object->setQuestiontext($questiontext);
00409 if ($_POST["obligatory"])
00410 {
00411 $this->object->setObligatory(1);
00412 }
00413 else
00414 {
00415 $this->object->setObligatory(0);
00416 }
00417
00418 if ($saved) {
00419
00420
00421
00422
00423 $this->object->saveToDb();
00424 }
00425 return $result;
00426 }
00427
00435 function categories($add = false)
00436 {
00437 if ($this->object->getId() < 1)
00438 {
00439 ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_category"), true);
00440 $this->ctrl->redirect($this, "editQuestion");
00441 }
00442 if (strcmp($this->ctrl->getCmd(), "categories") == 0) $_SESSION["spl_modified"] = false;
00443 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_ordinal_answers.html", "Modules/SurveyQuestionPool");
00444
00445 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
00446 {
00447 $this->tpl->setCurrentBlock("cat_selector");
00448 $this->tpl->setVariable("CATEGORY_ORDER", $i);
00449 $this->tpl->parseCurrentBlock();
00450 $this->tpl->setCurrentBlock("categories");
00451 $category = $this->object->categories->getCategory($i);
00452 $this->tpl->setVariable("CATEGORY_ORDER", $i);
00453 $this->tpl->setVariable("CATEGORY_NUMBER", $i+1);
00454 $this->tpl->setVariable("VALUE_CATEGORY", ilUtil::prepareFormOutput($category));
00455 $this->tpl->setVariable("TEXT_CATEGORY", $this->lng->txt("category"));
00456 $this->tpl->parseCurrentBlock();
00457 }
00458
00459 if ($add)
00460 {
00461 $nrOfCategories = $_POST["nrOfCategories"];
00462 if ($nrOfCategories < 1) $nrOfCategories = 1;
00463
00464 for ($i = 1; $i <= $nrOfCategories; $i++)
00465 {
00466 $this->tpl->setCurrentBlock("categories");
00467 $this->tpl->setVariable("CATEGORY_ORDER", $this->object->categories->getCategoryCount() + $i - 1);
00468 $this->tpl->setVariable("TEXT_CATEGORY", $this->lng->txt("category"));
00469 $this->tpl->parseCurrentBlock();
00470 }
00471 }
00472
00473 if (is_array($_SESSION["spl_move"]))
00474 {
00475 if (count($_SESSION["spl_move"]))
00476 {
00477 $this->tpl->setCurrentBlock("move_buttons");
00478 $this->tpl->setVariable("INSERT_BEFORE", $this->lng->txt("insert_before"));
00479 $this->tpl->setVariable("INSERT_AFTER", $this->lng->txt("insert_after"));
00480 $this->tpl->parseCurrentBlock();
00481 }
00482 }
00483
00484 include_once "./Services/Utilities/classes/class.ilUtil.php";
00485 if ($this->object->categories->getCategoryCount() == 0)
00486 {
00487 if (!$add)
00488 {
00489 $this->tpl->setCurrentBlock("nocategories");
00490 $this->tpl->setVariable("NO_CATEGORIES", $this->lng->txt("question_contains_no_categories"));
00491 $this->tpl->parseCurrentBlock();
00492 }
00493 }
00494 else
00495 {
00496 $this->tpl->setCurrentBlock("selectall");
00497 $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
00498 $this->tpl->parseCurrentBlock();
00499 $this->tpl->setCurrentBlock("existingcategories");
00500 $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00501 $this->tpl->setVariable("MOVE", $this->lng->txt("move"));
00502 $this->tpl->setVariable("VALUE_SAVE_PHRASE", $this->lng->txt("save_phrase"));
00503 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
00504 $this->tpl->parseCurrentBlock();
00505 }
00506
00507 for ($i = 1; $i < 10; $i++)
00508 {
00509 $this->tpl->setCurrentBlock("numbers");
00510 $this->tpl->setVariable("VALUE_NUMBER", $i);
00511 if ($i == 1)
00512 {
00513 $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("category"));
00514 }
00515 else
00516 {
00517 $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("categories"));
00518 }
00519 $this->tpl->parseCurrentBlock();
00520 }
00521
00522 $this->tpl->setCurrentBlock("adm_content");
00523 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00524 $this->tpl->setVariable("VALUE_ADD_CATEGORY", $this->lng->txt("add"));
00525 $this->tpl->setVariable("VALUE_ADD_PHRASE", $this->lng->txt("add_phrase"));
00526 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00527 if ($_SESSION["spl_modified"])
00528 {
00529 $this->tpl->setVariable("FORM_DATA_MODIFIED_PRESS_SAVE", $this->lng->txt("form_data_modified_press_save"));
00530 }
00531 $questiontext = $this->object->getQuestiontext();
00532 $this->tpl->setVariable("QUESTION_TEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00533 $this->tpl->parseCurrentBlock();
00534 }
00535
00536 function setQuestionTabs()
00537 {
00538 $this->setQuestionTabsForClass("surveyordinalquestiongui");
00539 }
00540
00548 function addPhrase()
00549 {
00550 $this->writeCategoryData(true);
00551 $this->ctrl->setParameterByClass(get_class($this), "q_id", $this->object->getId());
00552 $this->ctrl->setParameterByClass("ilobjsurveyquestionpoolgui", "q_id", $this->object->getId());
00553
00554 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase.html", "Modules/SurveyQuestionPool");
00555
00556
00557 $this->tpl->setCurrentBlock("hidden");
00558 $this->tpl->setVariable("HIDDEN_NAME", "id");
00559 $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
00560 $this->tpl->parseCurrentBlock();
00561
00562 include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyPhrases.php";
00563 $phrases =& ilSurveyPhrases::_getAvailablePhrases();
00564 $colors = array("tblrow1", "tblrow2");
00565 $counter = 0;
00566 foreach ($phrases as $phrase_id => $phrase_array)
00567 {
00568 $this->tpl->setCurrentBlock("phraserow");
00569 $this->tpl->setVariable("COLOR_CLASS", $colors[$counter++ % 2]);
00570 $this->tpl->setVariable("PHRASE_VALUE", $phrase_id);
00571 $this->tpl->setVariable("PHRASE_NAME", $phrase_array["title"]);
00572 $categories =& ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
00573 $this->tpl->setVariable("PHRASE_CONTENT", join($categories, ","));
00574 $this->tpl->parseCurrentBlock();
00575 }
00576
00577 $this->tpl->setCurrentBlock("adm_content");
00578 $this->tpl->setVariable("TEXT_CANCEL", $this->lng->txt("cancel"));
00579 $this->tpl->setVariable("TEXT_PHRASE", $this->lng->txt("phrase"));
00580 $this->tpl->setVariable("TEXT_CONTENT", $this->lng->txt("categories"));
00581 $this->tpl->setVariable("TEXT_ADD_PHRASE", $this->lng->txt("add_phrase"));
00582 $this->tpl->setVariable("TEXT_INTRODUCTION",$this->lng->txt("add_phrase_introduction"));
00583 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00584 $this->tpl->parseCurrentBlock();
00585 }
00586
00594 function cancelViewPhrase()
00595 {
00596 $this->ctrl->redirect($this, "categories");
00597 }
00598
00606 function addSelectedPhrase()
00607 {
00608 if (strcmp($_POST["phrases"], "") == 0)
00609 {
00610 ilUtil::sendInfo($this->lng->txt("select_phrase_to_add"));
00611 $this->addPhrase();
00612 }
00613 else
00614 {
00615 if (strcmp($this->object->getPhrase($_POST["phrases"]), "dp_standard_numbers") != 0)
00616 {
00617 $this->object->addPhrase($_POST["phrases"]);
00618 $this->object->saveCategoriesToDb();
00619 }
00620 else
00621 {
00622 $this->addStandardNumbers();
00623 return;
00624 }
00625 $this->ctrl->redirect($this, "categories");
00626 }
00627 }
00628
00636 function addStandardNumbers()
00637 {
00638 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase_standard_numbers.html", "Modules/SurveyQuestionPool");
00639
00640
00641 $this->tpl->setCurrentBlock("hidden");
00642 $this->tpl->setVariable("HIDDEN_NAME", "id");
00643 $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
00644 $this->tpl->parseCurrentBlock();
00645
00646 $this->tpl->setCurrentBlock("adm_content");
00647 $this->tpl->setVariable("ADD_STANDARD_NUMBERS", $this->lng->txt("add_standard_numbers"));
00648 $this->tpl->setVariable("TEXT_ADD_LIMITS", $this->lng->txt("add_limits_for_standard_numbers"));
00649 $this->tpl->setVariable("TEXT_LOWER_LIMIT",$this->lng->txt("lower_limit"));
00650 $this->tpl->setVariable("TEXT_UPPER_LIMIT",$this->lng->txt("upper_limit"));
00651 $this->tpl->setVariable("VALUE_LOWER_LIMIT", $_POST["lower_limit"]);
00652 $this->tpl->setVariable("VALUE_UPPER_LIMIT", $_POST["upper_limit"]);
00653 $this->tpl->setVariable("BTN_ADD",$this->lng->txt("add_phrase"));
00654 $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
00655 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00656 $this->tpl->parseCurrentBlock();
00657 }
00658
00666 function cancelStandardNumbers()
00667 {
00668 $this->ctrl->redirect($this, "categories");
00669 }
00670
00678 function insertStandardNumbers()
00679 {
00680 if ((strcmp($_POST["lower_limit"], "") == 0) or (strcmp($_POST["upper_limit"], "") == 0))
00681 {
00682 ilUtil::sendInfo($this->lng->txt("missing_upper_or_lower_limit"));
00683 $this->addStandardNumbers();
00684 }
00685 else if ((int)$_POST["upper_limit"] <= (int)$_POST["lower_limit"])
00686 {
00687 ilUtil::sendInfo($this->lng->txt("upper_limit_must_be_greater"));
00688 $this->addStandardNumbers();
00689 }
00690 else
00691 {
00692 $this->object->addStandardNumbers($_POST["lower_limit"], $_POST["upper_limit"]);
00693 $this->object->saveCategoriesToDb();
00694 $this->ctrl->redirect($this, "categories");
00695 }
00696 }
00697
00705 function savePhrase()
00706 {
00707 $this->writeCategoryData(true);
00708 $nothing_selected = true;
00709 if (array_key_exists("chb_category", $_POST))
00710 {
00711 if (count($_POST["chb_category"]))
00712 {
00713 $nothing_selected = false;
00714 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_savephrase.html", "Modules/SurveyQuestionPool");
00715 $rowclass = array("tblrow1", "tblrow2");
00716 $counter = 0;
00717 foreach ($_POST["chb_category"] as $category)
00718 {
00719 $this->tpl->setCurrentBlock("row");
00720 $this->tpl->setVariable("TXT_TITLE", $this->object->categories->getCategory($category));
00721 $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
00722 $this->tpl->parseCurrentBlock();
00723 $this->tpl->setCurrentBlock("hidden");
00724 $this->tpl->setVariable("HIDDEN_NAME", "chb_category[]");
00725 $this->tpl->setVariable("HIDDEN_VALUE", $category);
00726 $this->tpl->parseCurrentBlock();
00727 }
00728
00729 $this->tpl->setCurrentBlock("adm_content");
00730 $this->tpl->setVariable("SAVE_PHRASE_INTRODUCTION", $this->lng->txt("save_phrase_introduction"));
00731 $this->tpl->setVariable("TEXT_PHRASE_TITLE", $this->lng->txt("enter_phrase_title"));
00732 $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("category"));
00733 $this->tpl->setVariable("VALUE_PHRASE_TITLE", $_POST["phrase_title"]);
00734 $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
00735 $this->tpl->setVariable("BTN_CONFIRM",$this->lng->txt("confirm"));
00736 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00737 $this->tpl->parseCurrentBlock();
00738 }
00739 }
00740 if ($nothing_selected)
00741 {
00742 ilUtil::sendInfo($this->lng->txt("check_category_to_save_phrase"), true);
00743 $this->ctrl->redirect($this, "categories");
00744 }
00745 }
00746
00754 function cancelSavePhrase()
00755 {
00756 $this->ctrl->redirect($this, "categories");
00757 }
00758
00766 function confirmSavePhrase()
00767 {
00768 if (!$_POST["phrase_title"])
00769 {
00770 ilUtil::sendInfo($this->lng->txt("qpl_savephrase_empty"));
00771 $this->savePhrase();
00772 return;
00773 }
00774
00775 if ($this->object->phraseExists($_POST["phrase_title"]))
00776 {
00777 ilUtil::sendInfo($this->lng->txt("qpl_savephrase_exists"));
00778 $this->savePhrase();
00779 return;
00780 }
00781
00782 $this->object->savePhrase($_POST["chb_category"], $_POST["phrase_title"]);
00783 ilUtil::sendInfo($this->lng->txt("phrase_saved"), true);
00784 $this->ctrl->redirect($this, "categories");
00785 }
00786
00794 function saveCategories()
00795 {
00796 global $ilUser;
00797
00798 $this->writeCategoryData(true);
00799 $_SESSION["spl_modified"] = false;
00800 ilUtil::sendInfo($this->lng->txt("saved_successfully"), true);
00801 $originalexists = $this->object->_questionExists($this->object->original_id);
00802 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00803 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
00804 if ($_GET["calling_survey"] && $originalexists && SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
00805 {
00806 $this->originalSyncForm();
00807 return;
00808 }
00809 else
00810 {
00811 $this->ctrl->redirect($this, "categories");
00812 }
00813 }
00814
00822 function addCategory()
00823 {
00824 $result = $this->writeCategoryData();
00825 if ($result == false)
00826 {
00827 ilUtil::sendInfo($this->lng->txt("fill_out_all_category_fields"));
00828 }
00829 $_SESSION["spl_modified"] = true;
00830 $this->categories($result);
00831 }
00832
00842 function writeCategoryData($save = false)
00843 {
00844
00845 $this->object->categories->flushCategories();
00846 $complete = true;
00847 $array1 = array();
00848
00849 include_once "./Services/Utilities/classes/class.ilUtil.php";
00850 foreach ($_POST as $key => $value)
00851 {
00852 if (preg_match("/^category_(\d+)/", $key, $matches))
00853 {
00854 $array1[$matches[1]] = ilUtil::stripSlashes($value);
00855 if (strlen($array1[$matches[1]]) == 0) $complete = false;
00856 }
00857 }
00858 $this->object->categories->addCategoryArray($array1);
00859 if ($save)
00860 {
00861 $this->object->saveCategoriesToDb();
00862 }
00863 return $complete;
00864 }
00865
00873 function deleteCategory()
00874 {
00875 $this->writeCategoryData();
00876 $nothing_selected = true;
00877 if (array_key_exists("chb_category", $_POST))
00878 {
00879 if (count($_POST["chb_category"]))
00880 {
00881 $nothing_selected = false;
00882 $this->object->categories->removeCategories($_POST["chb_category"]);
00883 }
00884 }
00885 if ($nothing_selected) ilUtil::sendInfo($this->lng->txt("category_delete_select_none"));
00886 $_SESSION["spl_modified"] = true;
00887 $this->categories();
00888 }
00889
00897 function moveCategory()
00898 {
00899 $this->writeCategoryData();
00900 $nothing_selected = true;
00901 if (array_key_exists("chb_category", $_POST))
00902 {
00903 if (count($_POST["chb_category"]))
00904 {
00905 $nothing_selected = false;
00906 ilUtil::sendInfo($this->lng->txt("select_target_position_for_move"));
00907 $_SESSION["spl_move"] = $_POST["chb_category"];
00908 }
00909 }
00910 if ($nothing_selected) ilUtil::sendInfo($this->lng->txt("no_category_selected_for_move"));
00911 $this->categories();
00912 }
00913
00921 function insertBeforeCategory()
00922 {
00923 $result = $this->writeCategoryData();
00924 if (array_key_exists("chb_category", $_POST))
00925 {
00926 if (count($_POST["chb_category"]) == 1)
00927 {
00928
00929 $this->object->categories->removeCategories($_SESSION["spl_move"]);
00930 $newinsertindex = $this->object->categories->getCategoryIndex($_POST["category_".$_POST["chb_category"][0]]);
00931 if ($newinsertindex === false) $newinsertindex = 0;
00932 $move_categories = $_SESSION["spl_move"];
00933 natsort($move_categories);
00934 foreach (array_reverse($move_categories) as $index)
00935 {
00936 $this->object->categories->addCategoryAtPosition($_POST["category_$index"], $newinsertindex);
00937 }
00938 $_SESSION["spl_modified"] = true;
00939 unset($_SESSION["spl_move"]);
00940 }
00941 else
00942 {
00943 ilUtil::sendInfo("wrong_categories_selected_for_insert");
00944 }
00945 }
00946 $this->categories();
00947 }
00948
00956 function insertAfterCategory()
00957 {
00958 $result = $this->writeCategoryData();
00959 if (array_key_exists("chb_category", $_POST))
00960 {
00961 if (count($_POST["chb_category"]) == 1)
00962 {
00963
00964 $this->object->categories->removeCategories($_SESSION["spl_move"]);
00965 $newinsertindex = $this->object->categories->getCategoryIndex($_POST["category_".$_POST["chb_category"][0]]);
00966 if ($newinsertindex === false) $newinsertindex = 0;
00967 $move_categories = $_SESSION["spl_move"];
00968 natsort($move_categories);
00969 foreach (array_reverse($move_categories) as $index)
00970 {
00971 $this->object->categories->addCategoryAtPosition($_POST["category_$index"], $newinsertindex+1);
00972 }
00973 $_SESSION["spl_modified"] = true;
00974 unset($_SESSION["spl_move"]);
00975 }
00976 else
00977 {
00978 ilUtil::sendInfo("wrong_categories_selected_for_insert");
00979 }
00980 }
00981 $this->categories();
00982 }
00983
00992 function getCumulatedResultRow($counter, $css_class, $survey_id)
00993 {
00994 include_once "./classes/class.ilTemplate.php";
00995 if (count($this->cumulated) == 0)
00996 {
00997 include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
00998 $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
00999 $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
01000 }
01001 $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_row.html", TRUE, TRUE, "Modules/Survey");
01002 $template->setVariable("QUESTION_TITLE", ($counter+1) . ". ".$this->object->getTitle());
01003 $maxlen = 37;
01004 $questiontext = preg_replace("/<[^>]+?>/ims", "", $this->object->getQuestiontext());
01005 if (strlen($questiontext) > $maxlen + 3)
01006 {
01007 $questiontext = substr($questiontext, 0, $maxlen) . "...";
01008 }
01009 $template->setVariable("QUESTION_TEXT", $questiontext);
01010 $template->setVariable("USERS_ANSWERED", $this->cumulated["USERS_ANSWERED"]);
01011 $template->setVariable("USERS_SKIPPED", $this->cumulated["USERS_SKIPPED"]);
01012 $template->setVariable("QUESTION_TYPE", $this->lng->txt($this->cumulated["QUESTION_TYPE"]));
01013 $template->setVariable("MODE", $this->cumulated["MODE"]);
01014 $template->setVariable("MODE_NR_OF_SELECTIONS", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
01015 $template->setVariable("MEDIAN", $this->cumulated["MEDIAN"]);
01016 $template->setVariable("ARITHMETIC_MEAN", $this->cumulated["ARITHMETIC_MEAN"]);
01017 $template->setVariable("COLOR_CLASS", $css_class);
01018 return $template->get();
01019 }
01020
01031 function getCumulatedResultsDetails($survey_id, $counter)
01032 {
01033 if (count($this->cumulated) == 0)
01034 {
01035 include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
01036 $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
01037 $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
01038 }
01039
01040 $output = "";
01041 include_once "./classes/class.ilTemplate.php";
01042 $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
01043
01044 $template->setCurrentBlock("detail_row");
01045 $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
01046 $questiontext = $this->object->getQuestiontext();
01047 $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
01048 $template->parseCurrentBlock();
01049 $template->setCurrentBlock("detail_row");
01050 $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
01051 $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
01052 $template->parseCurrentBlock();
01053 $template->setCurrentBlock("detail_row");
01054 $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
01055 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
01056 $template->parseCurrentBlock();
01057 $template->setCurrentBlock("detail_row");
01058 $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
01059 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
01060 $template->parseCurrentBlock();
01061
01062 $template->setCurrentBlock("detail_row");
01063 $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
01064 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE"]);
01065 $template->parseCurrentBlock();
01066 $template->setCurrentBlock("detail_row");
01067 $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
01068 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
01069 $template->parseCurrentBlock();
01070 $template->setCurrentBlock("detail_row");
01071 $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
01072 $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MEDIAN"]);
01073 $template->parseCurrentBlock();
01074
01075 $template->setCurrentBlock("detail_row");
01076 $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
01077 $categories = "";
01078 foreach ($this->cumulated["variables"] as $key => $value)
01079 {
01080 $categories .= "<li>" . $this->lng->txt("title") . ":" . "<span class=\"bold\">" . $value["title"] . "</span><br />" .
01081 $this->lng->txt("category_nr_selected") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
01082 $this->lng->txt("percentage_of_selections") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
01083 }
01084 $categories = "<ol>$categories</ol>";
01085 $template->setVariable("TEXT_OPTION_VALUE", $categories);
01086 $template->parseCurrentBlock();
01087
01088
01089 $template->setCurrentBlock("chart");
01090 $template->setVariable("TEXT_CHART", $this->lng->txt("chart"));
01091 $template->setVariable("ALT_CHART", $data["title"] . "( " . $this->lng->txt("chart") . ")");
01092 $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "survey", $survey_id);
01093 $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "question", $this->object->getId());
01094 $template->setVariable("CHART", $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "outChart"));
01095 $template->parseCurrentBlock();
01096
01097 $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
01098 return $template->get();
01099 }
01100 }
01101 ?>