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.SurveyOrdinalQuestion.php";
00025 require_once "./survey/classes/class.SurveyQuestionGUI.php";
00026
00038 class SurveyOrdinalQuestionGUI extends SurveyQuestionGUI {
00039
00048 function SurveyOrdinalQuestionGUI(
00049 $id = -1
00050 )
00051
00052 {
00053 $this->SurveyQuestionGUI();
00054 $this->object = new SurveyOrdinalQuestion();
00055 if ($id >= 0)
00056 {
00057 $this->object->loadFromDb($id);
00058 }
00059 }
00060
00069 function getQuestionType()
00070 {
00071 return "qt_ordinal";
00072 }
00073
00081 function showDeleteCategoryForm()
00082 {
00083 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_confirm_remove_categories.html", true);
00084 $rowclass = array("tblrow1", "tblrow2");
00085 $counter = 0;
00086 foreach ($_POST as $key => $value) {
00087 if (preg_match("/chb_category_(\d+)/", $key, $matches)) {
00088 $this->tpl->setCurrentBlock("row");
00089 $this->tpl->setVariable("TXT_TITLE", $_POST["category_$matches[1]"]);
00090 $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
00091 $this->tpl->parseCurrentBlock();
00092 $this->tpl->setCurrentBlock("hidden");
00093 $this->tpl->setVariable("HIDDEN_NAME", $key);
00094 $this->tpl->setVariable("HIDDEN_VALUE", $value);
00095 $this->tpl->parseCurrentBlock();
00096 $counter++;
00097 }
00098 }
00099
00100
00101 $this->tpl->setCurrentBlock("hidden");
00102 $this->tpl->setVariable("HIDDEN_NAME", "id");
00103 $this->tpl->setVariable("HIDDEN_VALUE", $_POST["id"]);
00104 $this->tpl->parseCurrentBlock();
00105
00106 $this->tpl->setCurrentBlock("adm_content");
00107 $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("category"));
00108 $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
00109 $this->tpl->setVariable("BTN_CONFIRM",$this->lng->txt("confirm"));
00110 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00111 $this->tpl->parseCurrentBlock();
00112 }
00113
00121 function editQuestion() {
00122 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_ordinal.html", true);
00123 $this->tpl->addBlockFile("OTHER_QUESTION_DATA", "other_question_data", "tpl.il_svy_qpl_other_question_data.html", true);
00124
00125 for ($i = 0; $i < $this->object->getCategoryCount(); $i++) {
00126 $this->tpl->setCurrentBlock("cat_selector");
00127 $this->tpl->setVariable("CATEGORY_ORDER", $i);
00128 $this->tpl->parseCurrentBlock();
00129 $this->tpl->setCurrentBlock("categories");
00130 $category = $this->object->getCategory($i);
00131 $this->tpl->setVariable("CATEGORY_ORDER", $i);
00132 $this->tpl->setVariable("CATEGORY_NUMBER", $i+1);
00133 $this->tpl->setVariable("VALUE_CATEGORY", $category);
00134 $this->tpl->setVariable("TEXT_CATEGORY", $this->lng->txt("category"));
00135 $this->tpl->parseCurrentBlock();
00136 }
00137 if (strcmp($_POST["cmd"]["addCategory"], "") != 0) {
00138
00139 $this->tpl->setCurrentBlock("categories");
00140 $this->tpl->setVariable("CATEGORY_ORDER", $this->object->getCategoryCount());
00141 $this->tpl->setVariable("TEXT_CATEGORY", $this->lng->txt("category"));
00142 $this->tpl->parseCurrentBlock();
00143 }
00144
00145 $internallinks = array(
00146 "lm" => $this->lng->txt("obj_lm"),
00147 "st" => $this->lng->txt("obj_st"),
00148 "pg" => $this->lng->txt("obj_pg"),
00149 "glo" => $this->lng->txt("glossary_term")
00150 );
00151 foreach ($internallinks as $key => $value)
00152 {
00153 $this->tpl->setCurrentBlock("internallink");
00154 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00155 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00156 $this->tpl->parseCurrentBlock();
00157 }
00158
00159 $this->tpl->setCurrentBlock("adm_content");
00160 $this->tpl->setVariable("TEXT_MATERIAL", $this->lng->txt("material"));
00161 if (count($this->object->material))
00162 {
00163 $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
00164 $this->tpl->setVariable("TEXT_VALUE_MATERIAL", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("material"). "</a> ");
00165 $this->tpl->setVariable("BUTTON_REMOVE_MATERIAL", $this->lng->txt("remove"));
00166 $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("change"));
00167 $this->tpl->setVariable("VALUE_MATERIAL", $this->object->material["internal_link"]);
00168 $this->tpl->setVariable("VALUE_MATERIAL_TITLE", $this->object->material["title"]);
00169 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00170 }
00171 else
00172 {
00173 $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("add"));
00174 }
00175 $this->tpl->setVariable("TEXT_ORIENTATION", $this->lng->txt("orientation"));
00176 switch ($this->object->getOrientation())
00177 {
00178 case 0:
00179 $this->tpl->setVariable("SELECTED_VERTICAL", " selected=\"selected\"");
00180 break;
00181 case 1:
00182 $this->tpl->setVariable("SELECTED_HORIZONTAL", " selected=\"selected\"");
00183 break;
00184 case 2:
00185 $this->tpl->setVariable("SELECTED_COMBOBOX", " selected=\"selected\"");
00186 break;
00187 }
00188 $this->tpl->setVariable("TXT_VERTICAL", $this->lng->txt("vertical"));
00189 $this->tpl->setVariable("TXT_HORIZONTAL", $this->lng->txt("horizontal"));
00190 $this->tpl->setVariable("TXT_COMBOBOX", $this->lng->txt("combobox"));
00191 $this->tpl->setCurrentBlock("adm_content");
00192 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00193 $this->tpl->setVariable("VALUE_TITLE", $this->object->getTitle());
00194 $this->tpl->setVariable("VALUE_DESCRIPTION", $this->object->getDescription());
00195 $this->tpl->setVariable("VALUE_AUTHOR", $this->object->getAuthor());
00196 $questiontext = $this->object->getQuestiontext();
00197 $questiontext = str_replace("<br />", "\n", $questiontext);
00198 $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
00199 $this->tpl->setVariable("VALUE_SAVE_PHRASE", $this->lng->txt("save_phrase"));
00200 $this->tpl->setVariable("VALUE_ADD_PHRASE", $this->lng->txt("add_phrase"));
00201 $this->tpl->setVariable("VALUE_ADD_CATEGORY", $this->lng->txt("add_category"));
00202 $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00203 $this->tpl->setVariable("MOVE", $this->lng->txt("move"));
00204 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00205 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00206 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
00207 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00208 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("questiontype"));
00209 $this->tpl->setVariable("TEXT_OBLIGATORY", $this->lng->txt("obligatory"));
00210 if ($this->object->getObligatory())
00211 {
00212 $this->tpl->setVariable("CHECKED_OBLIGATORY", " checked=\"checked\"");
00213 }
00214 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00215 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00216 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00217 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00218 $this->tpl->parseCurrentBlock();
00219 }
00220
00228 function outWorkingForm($working_data = "", $question_title = 1, $error_message = "")
00229 {
00230 if (count($this->object->material))
00231 {
00232 $this->tpl->setCurrentBlock("material_ordinal");
00233 $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
00234 $this->tpl->setVariable("TEXT_MATERIAL", $this->lng->txt("material") . ": <a href=\"$href\" target=\"content\">" . $this->object->material["title"]. "</a> ");
00235 $this->tpl->parseCurrentBlock();
00236 }
00237 switch ($this->object->orientation)
00238 {
00239 case 0:
00240
00241 for ($i = 0; $i < $this->object->getCategoryCount(); $i++) {
00242 $category = $this->object->getCategory($i);
00243 $this->tpl->setCurrentBlock("ordinal_row");
00244 $this->tpl->setVariable("TEXT_ORDINAL", $category);
00245 $this->tpl->setVariable("VALUE_ORDINAL", $i);
00246 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00247 if (is_array($working_data))
00248 {
00249 if (strcmp($working_data[0]["value"], "") != 0)
00250 {
00251 if ($working_data[0]["value"] == $i)
00252 {
00253 $this->tpl->setVariable("CHECKED_ORDINAL", " checked=\"checked\"");
00254 }
00255 }
00256 }
00257 $this->tpl->parseCurrentBlock();
00258 }
00259 break;
00260 case 1:
00261
00262 for ($i = 0; $i < $this->object->getCategoryCount(); $i++)
00263 {
00264 $category = $this->object->getCategory($i);
00265 $this->tpl->setCurrentBlock("radio_col_ordinal");
00266 $this->tpl->setVariable("VALUE_ORDINAL", $i);
00267 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00268 if (is_array($working_data))
00269 {
00270 if (strcmp($working_data[0]["value"], "") != 0)
00271 {
00272 if ($working_data[0]["value"] == $i)
00273 {
00274 $this->tpl->setVariable("CHECKED_ORDINAL", " checked=\"checked\"");
00275 }
00276 }
00277 }
00278 $this->tpl->parseCurrentBlock();
00279 }
00280 for ($i = 0; $i < $this->object->getCategoryCount(); $i++)
00281 {
00282 $category = $this->object->getCategory($i);
00283 $this->tpl->setCurrentBlock("text_col_ordinal");
00284 $this->tpl->setVariable("VALUE_ORDINAL", $i);
00285 $this->tpl->setVariable("TEXT_ORDINAL", $category);
00286 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00287 $this->tpl->parseCurrentBlock();
00288 }
00289 break;
00290 case 2:
00291
00292 for ($i = 0; $i < $this->object->getCategoryCount(); $i++) {
00293 $category = $this->object->getCategory($i);
00294 $this->tpl->setCurrentBlock("comborow");
00295 $this->tpl->setVariable("TEXT_ORDINAL", $category);
00296 $this->tpl->setVariable("VALUE_ORDINAL", $i);
00297 if (is_array($working_data))
00298 {
00299 if (strcmp($working_data[0]["value"], "") != 0)
00300 {
00301 if ($working_data[0]["value"] == $i)
00302 {
00303 $this->tpl->setVariable("SELECTED_ORDINAL", " selected=\"selected\"");
00304 }
00305 }
00306 }
00307 $this->tpl->parseCurrentBlock();
00308 }
00309 $this->tpl->setCurrentBlock("combooutput");
00310 $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
00311 $this->tpl->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
00312 $this->tpl->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
00313 $this->tpl->parseCurrentBlock();
00314 break;
00315 }
00316 if ($question_title)
00317 {
00318 $this->tpl->setVariable("QUESTION_TITLE", $this->object->getTitle());
00319 }
00320 $this->tpl->setCurrentBlock("question_data_ordinal");
00321 if (strcmp($error_message, "") != 0)
00322 {
00323 $this->tpl->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
00324 }
00325 $this->tpl->setVariable("QUESTIONTEXT", $this->object->getQuestiontext());
00326 if ($this->object->getObligatory())
00327 {
00328 $this->tpl->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_obligatory"));
00329 }
00330 $this->tpl->parseCurrentBlock();
00331 }
00332
00340 function preview()
00341 {
00342 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", true);
00343 $this->tpl->addBlockFile("ORDINAL", "ordinal", "tpl.il_svy_out_ordinal.html", true);
00344 $this->outWorkingForm();
00345 $this->tpl->parseCurrentBlock();
00346 }
00347
00356 function writePostData() {
00357 $result = 0;
00358 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00359 $result = 1;
00360
00361
00362 if ($_POST["id"] > 0)
00363 $this->object->setId($_POST["id"]);
00364
00365 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00366 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00367 $this->object->setDescription(ilUtil::stripSlashes($_POST["description"]));
00368 $this->object->setOrientation($_POST["orientation"]);
00369 if (strlen($_POST["material"]))
00370 {
00371 $this->object->setMaterial($_POST["material"], 0, ilUtil::stripSlashes($_POST["material_title"]));
00372 }
00373 $questiontext = ilUtil::stripSlashes($_POST["question"]);
00374 $questiontext = str_replace("\n", "<br />", $questiontext);
00375 $this->object->setQuestiontext($questiontext);
00376 if ($_POST["obligatory"])
00377 {
00378 $this->object->setObligatory(1);
00379 }
00380 else
00381 {
00382 $this->object->setObligatory(0);
00383 }
00384
00385
00386 $this->object->flushCategories();
00387
00388 $array1 = array();
00389
00390 foreach ($_POST as $key => $value) {
00391 if (preg_match("/^category_(\d+)/", $key, $matches)) {
00392 array_push($array1, ilUtil::stripSlashes($value));
00393 }
00394 }
00395 $this->object->addCategoryArray($array1);
00396
00397 if ($saved) {
00398
00399
00400
00401
00402 $this->object->saveToDb();
00403 }
00404 return $result;
00405 }
00406
00407
00408 function setQuestionTabs()
00409 {
00410 $this->setQuestionTabsForClass("surveyordinalquestiongui");
00411 }
00412 }
00413 ?>