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 require_once "./survey/classes/class.SurveyNominalQuestion.php";
00025 require_once "./survey/classes/class.SurveyQuestionGUI.php";
00026
00038 class SurveyNominalQuestionGUI extends SurveyQuestionGUI {
00039
00048 function SurveyNominalQuestionGUI(
00049 $id = -1
00050 )
00051
00052 {
00053 $this->SurveyQuestionGUI();
00054 $this->object = new SurveyNominalQuestion();
00055 if ($id >= 0)
00056 {
00057 $this->object->loadFromDb($id);
00058 }
00059 }
00060
00069 function getQuestionType()
00070 {
00071 return "qt_nominal";
00072 }
00073
00081 function editQuestion() {
00082 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_nominal.html", true);
00083 $this->tpl->addBlockFile("OTHER_QUESTION_DATA", "other_question_data", "tpl.il_svy_qpl_other_question_data.html", true);
00084
00085 for ($i = 0; $i < $this->object->getCategoryCount(); $i++) {
00086 $this->tpl->setCurrentBlock("cat_selector");
00087 $this->tpl->setVariable("CATEGORY_ORDER", $i);
00088 $this->tpl->parseCurrentBlock();
00089 $this->tpl->setCurrentBlock("categories");
00090 $category = $this->object->getCategory($i);
00091 $this->tpl->setVariable("CATEGORY_ORDER", $i);
00092 $this->tpl->setVariable("CATEGORY_NUMBER", $i+1);
00093 $this->tpl->setVariable("VALUE_CATEGORY", $category);
00094 $this->tpl->setVariable("TEXT_CATEGORY", $this->lng->txt("category"));
00095 $this->tpl->parseCurrentBlock();
00096 }
00097 if (strcmp($_POST["cmd"]["addCategory"], "") != 0) {
00098
00099 $this->tpl->setCurrentBlock("categories");
00100 $this->tpl->setVariable("CATEGORY_ORDER", $this->object->getCategoryCount());
00101 $this->tpl->setVariable("TEXT_CATEGORY", $this->lng->txt("category"));
00102 $this->tpl->parseCurrentBlock();
00103 }
00104
00105 $this->tpl->setVariable("TEXT_ORIENTATION", $this->lng->txt("orientation"));
00106 switch ($this->object->getOrientation())
00107 {
00108 case 0:
00109 $this->tpl->setVariable("SELECTED_VERTICAL", " selected=\"selected\"");
00110 break;
00111 case 1:
00112 $this->tpl->setVariable("SELECTED_HORIZONTAL", " selected=\"selected\"");
00113 break;
00114 case 2:
00115 $this->tpl->setVariable("SELECTED_COMBOBOX", " selected=\"selected\"");
00116 break;
00117 }
00118 $this->tpl->setVariable("TXT_VERTICAL", $this->lng->txt("vertical"));
00119 $this->tpl->setVariable("TXT_HORIZONTAL", $this->lng->txt("horizontal"));
00120 if ($this->object->getSubtype() == SUBTYPE_MCSR)
00121 {
00122 $this->tpl->setVariable("TXT_COMBOBOX", $this->lng->txt("combobox"));
00123 }
00124
00125 $internallinks = array(
00126 "lm" => $this->lng->txt("obj_lm"),
00127 "st" => $this->lng->txt("obj_st"),
00128 "pg" => $this->lng->txt("obj_pg"),
00129 "glo" => $this->lng->txt("glossary_term")
00130 );
00131 foreach ($internallinks as $key => $value)
00132 {
00133 $this->tpl->setCurrentBlock("internallink");
00134 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00135 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00136 $this->tpl->parseCurrentBlock();
00137 }
00138
00139 $this->tpl->setCurrentBlock("adm_content");
00140 $this->tpl->setVariable("TEXT_MATERIAL", $this->lng->txt("material"));
00141 if (count($this->object->material))
00142 {
00143 $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
00144 $this->tpl->setVariable("TEXT_VALUE_MATERIAL", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("material"). "</a> ");
00145 $this->tpl->setVariable("BUTTON_REMOVE_MATERIAL", $this->lng->txt("remove"));
00146 $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("change"));
00147 $this->tpl->setVariable("VALUE_MATERIAL", $this->object->material["internal_link"]);
00148 $this->tpl->setVariable("VALUE_MATERIAL_TITLE", $this->object->material["title"]);
00149 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00150 }
00151 else
00152 {
00153 $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("add"));
00154 }
00155 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00156 $this->tpl->setVariable("VALUE_TITLE", $this->object->getTitle());
00157 $this->tpl->setVariable("VALUE_DESCRIPTION", $this->object->getDescription());
00158 $this->tpl->setVariable("VALUE_AUTHOR", $this->object->getAuthor());
00159 $questiontext = $this->object->getQuestiontext();
00160 $questiontext = str_replace("<br />", "\n", $questiontext);
00161 $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
00162 $this->tpl->setVariable("VALUE_ADD_CATEGORY", $this->lng->txt("add_category"));
00163 $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00164 $this->tpl->setVariable("MOVE", $this->lng->txt("move"));
00165 $this->tpl->setVariable("TXT_SR", $this->lng->txt("multiple_choice_single_response"));
00166 $this->tpl->setVariable("TXT_MR", $this->lng->txt("multiple_choice_multiple_response"));
00167 if ($this->object->getSubtype() == SUBTYPE_MCSR)
00168 {
00169 $this->tpl->setVariable("SELECTED_SR", " selected=\"selected\"");
00170 }
00171 else
00172 {
00173 $this->tpl->setVariable("SELECTED_MR", " selected=\"selected\"");
00174 }
00175 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00176 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00177 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
00178 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00179 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("questiontype"));
00180 $this->tpl->setVariable("TEXT_OBLIGATORY", $this->lng->txt("obligatory"));
00181 if ($this->object->getObligatory())
00182 {
00183 $this->tpl->setVariable("CHECKED_OBLIGATORY", " checked=\"checked\"");
00184 }
00185 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00186 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00187 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00188 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00189 $this->tpl->parseCurrentBlock();
00190 }
00191
00199 function outWorkingForm($working_data = "", $question_title = 1, $error_message = "")
00200 {
00201 if (count($this->object->material))
00202 {
00203 $this->tpl->setCurrentBlock("material_nominal");
00204 $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
00205 $this->tpl->setVariable("TEXT_MATERIAL", $this->lng->txt("material") . ": <a href=\"$href\" target=\"content\">" . $this->object->material["title"]. "</a> ");
00206 $this->tpl->parseCurrentBlock();
00207 }
00208 switch ($this->object->getOrientation())
00209 {
00210 case 0:
00211
00212 for ($i = 0; $i < $this->object->getCategoryCount(); $i++) {
00213 $category = $this->object->getCategory($i);
00214 if ($this->object->getSubtype() == SUBTYPE_MCSR)
00215 {
00216 $this->tpl->setCurrentBlock("nominal_row_sr");
00217 $this->tpl->setVariable("TEXT_NOMINAL", $category);
00218 $this->tpl->setVariable("VALUE_NOMINAL", $i);
00219 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00220 if (is_array($working_data))
00221 {
00222 if (strcmp($working_data[0]["value"], "") != 0)
00223 {
00224 if ($working_data[0]["value"] == $i)
00225 {
00226 $this->tpl->setVariable("CHECKED_NOMINAL", " checked=\"checked\"");
00227 }
00228 }
00229 }
00230 $this->tpl->parseCurrentBlock();
00231 }
00232 else
00233 {
00234 $this->tpl->setCurrentBlock("nominal_row_mr");
00235 $this->tpl->setVariable("TEXT_NOMINAL", $category);
00236 $this->tpl->setVariable("VALUE_NOMINAL", $i);
00237 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00238 if (is_array($working_data))
00239 {
00240 foreach ($working_data as $row)
00241 {
00242 if (strcmp($row["value"], "") != 0)
00243 {
00244 if ($row["value"] == $i)
00245 {
00246 $this->tpl->setVariable("CHECKED_NOMINAL", " checked=\"checked\"");
00247 }
00248 }
00249 }
00250 }
00251 $this->tpl->parseCurrentBlock();
00252 }
00253 }
00254 break;
00255 case 1:
00256
00257 if ($this->object->getSubtype() == SUBTYPE_MCSR)
00258 {
00259 for ($i = 0; $i < $this->object->getCategoryCount(); $i++)
00260 {
00261 $category = $this->object->getCategory($i);
00262 $this->tpl->setCurrentBlock("radio_col_nominal");
00263 $this->tpl->setVariable("VALUE_NOMINAL", $i);
00264 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00265 if (is_array($working_data))
00266 {
00267 if (strcmp($working_data[0]["value"], "") != 0)
00268 {
00269 if ($working_data[0]["value"] == $i)
00270 {
00271 $this->tpl->setVariable("CHECKED_NOMINAL", " checked=\"checked\"");
00272 }
00273 }
00274 }
00275 $this->tpl->parseCurrentBlock();
00276 }
00277 for ($i = 0; $i < $this->object->getCategoryCount(); $i++)
00278 {
00279 $category = $this->object->getCategory($i);
00280 $this->tpl->setCurrentBlock("text_col_nominal");
00281 $this->tpl->setVariable("VALUE_NOMINAL", $i);
00282 $this->tpl->setVariable("TEXT_NOMINAL", $category);
00283 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00284 $this->tpl->parseCurrentBlock();
00285 }
00286 }
00287 else
00288 {
00289 for ($i = 0; $i < $this->object->getCategoryCount(); $i++)
00290 {
00291 $category = $this->object->getCategory($i);
00292 $this->tpl->setCurrentBlock("checkbox_col_nominal");
00293 $this->tpl->setVariable("VALUE_NOMINAL", $i);
00294 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00295 if (is_array($working_data))
00296 {
00297 if (strcmp($working_data[0]["value"], "") != 0)
00298 {
00299 if ($working_data[0]["value"] == $i)
00300 {
00301 $this->tpl->setVariable("CHECKED_NOMINAL", " checked=\"checked\"");
00302 }
00303 }
00304 }
00305 $this->tpl->parseCurrentBlock();
00306 }
00307 for ($i = 0; $i < $this->object->getCategoryCount(); $i++)
00308 {
00309 $category = $this->object->getCategory($i);
00310 $this->tpl->setCurrentBlock("text_col_nominal_mr");
00311 $this->tpl->setVariable("VALUE_NOMINAL", $i);
00312 $this->tpl->setVariable("TEXT_NOMINAL", $category);
00313 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00314 $this->tpl->parseCurrentBlock();
00315 }
00316 }
00317 break;
00318 case 2:
00319
00320 for ($i = 0; $i < $this->object->getCategoryCount(); $i++) {
00321 $category = $this->object->getCategory($i);
00322 $this->tpl->setCurrentBlock("comborow_nominal");
00323 $this->tpl->setVariable("TEXT_NOMINAL", $category);
00324 $this->tpl->setVariable("VALUE_NOMINAL", $i);
00325 if (is_array($working_data))
00326 {
00327 if (strcmp($working_data[0]["value"], "") != 0)
00328 {
00329 if ($working_data[0]["value"] == $i)
00330 {
00331 $this->tpl->setVariable("SELECTED_NOMINAL", " selected=\"selected\"");
00332 }
00333 }
00334 }
00335 $this->tpl->parseCurrentBlock();
00336 }
00337 $this->tpl->setCurrentBlock("combooutput_nominal");
00338 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00339 $this->tpl->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
00340 $this->tpl->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
00341 $this->tpl->parseCurrentBlock();
00342 break;
00343 }
00344
00345 $this->tpl->setCurrentBlock("question_data_nominal");
00346 if (strcmp($error_message, "") != 0)
00347 {
00348 $this->tpl->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
00349 }
00350 $this->tpl->setVariable("QUESTIONTEXT", $this->object->getQuestiontext());
00351 if ($this->object->getObligatory())
00352 {
00353 $this->tpl->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_obligatory"));
00354 }
00355 if ($question_title)
00356 {
00357 $this->tpl->setVariable("QUESTION_TITLE", $this->object->getTitle());
00358 }
00359 $this->tpl->parseCurrentBlock();
00360 }
00361
00369 function preview()
00370 {
00371 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", true);
00372 $this->tpl->addBlockFile("NOMINAL", "nominal", "tpl.il_svy_out_nominal.html", true);
00373 $this->outWorkingForm();
00374 $this->tpl->parseCurrentBlock();
00375 }
00376
00385 function writePostData() {
00386 $result = 0;
00387 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00388 $result = 1;
00389
00390
00391 if ($_POST["id"] > 0)
00392 $this->object->setId($_POST["id"]);
00393
00394 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00395 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00396 $this->object->setDescription(ilUtil::stripSlashes($_POST["description"]));
00397 if (strlen($_POST["material"]))
00398 {
00399 $this->object->setMaterial($_POST["material"], 0, ilUtil::stripSlashes($_POST["material_title"]));
00400 }
00401 $this->object->setSubtype($_POST["type"]);
00402 $this->object->setOrientation($_POST["orientation"]);
00403 $questiontext = ilUtil::stripSlashes($_POST["question"]);
00404 $questiontext = str_replace("\n", "<br />", $questiontext);
00405 $this->object->setQuestiontext($questiontext);
00406 if ($_POST["obligatory"])
00407 {
00408 $this->object->setObligatory(1);
00409 }
00410 else
00411 {
00412 $this->object->setObligatory(0);
00413 }
00414
00415
00416 $this->object->flushCategories();
00417
00418 $array1 = array();
00419
00420 foreach ($_POST as $key => $value) {
00421 if (preg_match("/^category_(\d+)/", $key, $matches)) {
00422 array_push($array1, ilUtil::stripSlashes($value));
00423 }
00424 }
00425 $this->object->addCategoryArray($array1);
00426
00427 if ($saved) {
00428
00429
00430
00431
00432 $this->object->saveToDb();
00433 }
00434 return $result;
00435 }
00436
00437 function setQuestionTabs()
00438 {
00439 $this->setQuestionTabsForClass("surveynominalquestiongui");
00440 }
00441
00442 }
00443 ?>