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/inc.SurveyConstants.php";
00025
00037 class SurveyQuestionGUI
00038 {
00046 var $object;
00047 var $tpl;
00048 var $lng;
00049 var $errormessage;
00061 function SurveyQuestionGUI()
00062
00063 {
00064 global $lng, $tpl, $ilCtrl;
00065
00066 $this->lng =& $lng;
00067 $this->tpl =& $tpl;
00068 $this->ctrl =& $ilCtrl;
00069 $this->ctrl->saveParameter($this, "q_id");
00070 }
00071
00075 function &executeCommand()
00076 {
00077 $cmd = $this->ctrl->getCmd();
00078 $next_class = $this->ctrl->getNextClass($this);
00079
00080 $cmd = $this->getCommand($cmd);
00081 switch($next_class)
00082 {
00083 default:
00084 $ret =& $this->$cmd();
00085 break;
00086 }
00087 return $ret;
00088 }
00089
00090 function getCommand($cmd)
00091 {
00092 return $cmd;
00093 }
00094
00106 function &_getQuestionGUI($questiontype, $question_id = -1)
00107 {
00108 if (!$questiontype)
00109 {
00110 include_once "./survey/classes/class.SurveyQuestion.php";
00111 $questiontype = SurveyQuestion::_getQuestiontype($question_id);
00112 }
00113 switch ($questiontype)
00114 {
00115 case "qt_nominal":
00116 include_once "./survey/classes/class.SurveyNominalQuestionGUI.php";
00117 $question = new SurveyNominalQuestionGUI();
00118 break;
00119 case "qt_ordinal":
00120 include_once "./survey/classes/class.SurveyOrdinalQuestionGUI.php";
00121 $question = new SurveyOrdinalQuestionGUI();
00122 break;
00123 case "qt_metric":
00124 include_once "./survey/classes/class.SurveyMetricQuestionGUI.php";
00125 $question = new SurveyMetricQuestionGUI();
00126 break;
00127 case "qt_text":
00128 include_once "./survey/classes/class.SurveyTextQuestionGUI.php";
00129 $question = new SurveyTextQuestionGUI();
00130 break;
00131 }
00132 if ($question_id > 0)
00133 {
00134 $question->object->loadFromDb($question_id);
00135 }
00136
00137 return $question;
00138 }
00139
00140 function _getGUIClassNameForId($a_q_id)
00141 {
00142 include_once "./survey/classes/class.SurveyQuestion.php";
00143 include_once "./survey/classes/class.SurveyQuestionGUI.php";
00144 $q_type = SurveyQuestion::_getQuestiontype($a_q_id);
00145 $class_name = SurveyQuestionGUI::_getClassNameForQType($q_type);
00146 return $class_name;
00147 }
00148
00149 function _getClassNameForQType($q_type)
00150 {
00151 switch ($q_type)
00152 {
00153 case "qt_nominal":
00154 return "SurveyNominalQuestionGUI";
00155 break;
00156
00157 case "qt_ordinal":
00158 return "SurveyOrdinalQuestionGUI";
00159 break;
00160
00161 case "qt_metric":
00162 return "SurveyMetricQuestionGUI";
00163 break;
00164
00165 case "qt_text":
00166 return "SurveyTextQuestionGUI";
00167 break;
00168 }
00169 }
00170
00171 function originalSyncForm()
00172 {
00173 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_sync_original.html", true);
00174 $this->tpl->setCurrentBlock("adm_content");
00175 $this->tpl->setVariable("BUTTON_YES", $this->lng->txt("yes"));
00176 $this->tpl->setVariable("BUTTON_NO", $this->lng->txt("no"));
00177 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00178 $this->tpl->setVariable("TEXT_SYNC", $this->lng->txt("confirm_sync_questions"));
00179 $this->tpl->parseCurrentBlock();
00180 }
00181
00182 function sync()
00183 {
00184 $original_id = $this->object->original_id;
00185 if ($original_id)
00186 {
00187 $this->object->syncWithOriginal();
00188 }
00189 $this->ctrl->redirect($this, "editQuestion");
00190
00191
00192
00193
00194 }
00195
00196 function cancelSync()
00197 {
00198 $this->ctrl->redirect($this, "editQuestion");
00199
00200
00201
00202 }
00203
00211 function saveCategories()
00212 {
00213 global $ilUser;
00214
00215 $this->writeCategoryData(true);
00216 $_SESSION["spl_modified"] = false;
00217 sendInfo($this->lng->txt("saved_successfully"), true);
00218 $originalexists = $this->object->_questionExists($this->object->original_id);
00219 $_GET["q_id"] = $this->object->getId();
00220 include_once "./survey/classes/class.SurveyQuestion.php";
00221 if ($_GET["calling_survey"] && $originalexists && SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
00222 {
00223 $this->originalSyncForm();
00224 return;
00225 }
00226 else
00227 {
00228 $this->ctrl->redirect($this, "categories");
00229 }
00230 }
00231
00235 function save()
00236 {
00237 global $ilUser;
00238
00239 $old_id = $_GET["q_id"];
00240 $this->errormessage = $this->lng->txt("fill_out_all_required_fields");
00241 $result = $this->writePostData();
00242 if ($result == 0)
00243 {
00244 $ilUser->setPref("svy_lastquestiontype", $this->object->getQuestionType());
00245 $ilUser->writePref("svy_lastquestiontype", $this->object->getQuestionType());
00246 $this->object->saveToDb();
00247 $originalexists = $this->object->_questionExists($this->object->original_id);
00248 $_GET["q_id"] = $this->object->getId();
00249 include_once "./survey/classes/class.SurveyQuestion.php";
00250 if ($_GET["calling_survey"] && $originalexists && SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
00251 {
00252 $this->originalSyncForm();
00253 return;
00254 }
00255 elseif ($_GET["calling_survey"])
00256 {
00257 $_GET["ref_id"] = $_GET["calling_survey"];
00258 include_once "./classes/class.ilUtil.php";
00259 ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&ref_id=" . $_GET["calling_survey"] . "&cmd=questions");
00260 return;
00261 }
00262 elseif ($_GET["new_for_survey"] > 0)
00263 {
00264 $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
00265 $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
00266 $this->ctrl->setParameterByClass($_GET["cmdClass"], "new_for_survey", $_GET["new_for_survey"]);
00267 $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
00268 return;
00269 }
00270 else
00271 {
00272 sendInfo($this->lng->txt("msg_obj_modified"), true);
00273 $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
00274 $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
00275 $this->ctrl->setParameterByClass($_GET["cmdClass"], "new_for_survey", $_GET["new_for_survey"]);
00276 $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
00277 }
00278 }
00279 else
00280 {
00281 sendInfo($this->errormessage);
00282 }
00283 $this->editQuestion();
00284 }
00285
00286 function cancel()
00287 {
00288 if ($_GET["calling_survey"])
00289 {
00290 $_GET["ref_id"] = $_GET["calling_survey"];
00291 include_once "./classes/class.ilUtil.php";
00292 ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&cmd=questions&ref_id=".$_GET["calling_survey"]);
00293 }
00294 elseif ($_GET["new_for_survey"])
00295 {
00296 $_GET["ref_id"] = $_GET["new_for_survey"];
00297 include_once "./classes/class.ilUtil.php";
00298 ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&cmd=questions&ref_id=".$_GET["new_for_survey"]);
00299 }
00300 else
00301 {
00302 $this->ctrl->redirectByClass("ilobjsurveyquestionpoolgui", "questions");
00303 }
00304 }
00305
00313 function cancelDeleteCategory()
00314 {
00315 $this->ctrl->redirect($this, "editQuestion");
00316 }
00317
00318 function addMaterial()
00319 {
00320 global $tree;
00321
00322 include_once("./survey/classes/class.ilMaterialExplorer.php");
00323 switch ($_POST["internalLinkType"])
00324 {
00325 case "lm":
00326 $_SESSION["link_new_type"] = "lm";
00327 $_SESSION["search_link_type"] = "lm";
00328 break;
00329 case "glo":
00330 $_SESSION["link_new_type"] = "glo";
00331 $_SESSION["search_link_type"] = "glo";
00332 break;
00333 case "st":
00334 $_SESSION["link_new_type"] = "lm";
00335 $_SESSION["search_link_type"] = "st";
00336 break;
00337 case "pg":
00338 $_SESSION["link_new_type"] = "lm";
00339 $_SESSION["search_link_type"] = "pg";
00340 break;
00341 default:
00342 if (!$_SESSION["link_new_type"])
00343 {
00344 $_SESSION["link_new_type"] = "lm";
00345 }
00346 break;
00347 }
00348
00349 sendInfo($this->lng->txt("select_object_to_link"));
00350
00351 $exp = new ilMaterialExplorer($this->ctrl->getLinkTarget($this,'addMaterial'), get_class($this));
00352
00353 $exp->setExpand($_GET["expand"] ? $_GET["expand"] : $tree->readRootId());
00354 $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'addMaterial'));
00355 $exp->setTargetGet("ref_id");
00356 $exp->setRefId($this->cur_ref_id);
00357 $exp->addFilter($_SESSION["link_new_type"]);
00358 $exp->setSelectableType($_SESSION["link_new_type"]);
00359
00360
00361 $exp->setOutput(0);
00362
00363 $this->tpl->addBlockFile("ADM_CONTENT", "explorer", "tpl.il_svy_qpl_explorer.html", true);
00364 $this->tpl->setVariable("EXPLORER_TREE",$exp->getOutput());
00365 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00366 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00367 $this->tpl->parseCurrentBlock();
00368 }
00369
00370 function removeMaterial()
00371 {
00372 $this->object->material = array();
00373 $this->object->saveToDb();
00374 $this->editQuestion();
00375 }
00376
00377 function cancelExplorer()
00378 {
00379 unset($_SESSION["link_new_type"]);
00380 $this->editQuestion();
00381 }
00382
00383 function addPG()
00384 {
00385 $this->object->setMaterial("il__pg_" . $_GET["pg"]);
00386 unset($_SESSION["link_new_type"]);
00387 unset($_SESSION["search_link_type"]);
00388 sendInfo($this->lng->txt("material_added_successfully"));
00389 $this->editQuestion();
00390 }
00391
00392 function addST()
00393 {
00394 $this->object->setMaterial("il__st_" . $_GET["st"]);
00395 unset($_SESSION["link_new_type"]);
00396 unset($_SESSION["search_link_type"]);
00397 sendInfo($this->lng->txt("material_added_successfully"));
00398 $this->editQuestion();
00399 }
00400
00401 function addGIT()
00402 {
00403 $this->object->setMaterial("il__git_" . $_GET["git"]);
00404 unset($_SESSION["link_new_type"]);
00405 unset($_SESSION["search_link_type"]);
00406 sendInfo($this->lng->txt("material_added_successfully"));
00407 $this->editQuestion();
00408 }
00409
00410 function linkChilds()
00411 {
00412 switch ($_SESSION["search_link_type"])
00413 {
00414 case "pg":
00415 case "st":
00416 $_GET["q_id"] = $this->object->getId();
00417 $color_class = array("tblrow1", "tblrow2");
00418 $counter = 0;
00419 include_once("./content/classes/class.ilObjContentObject.php");
00420 $cont_obj =& new ilObjContentObject($_GET["source_id"], true);
00421
00422 $ctree =& $cont_obj->getLMTree();
00423 $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
00424 $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", true);
00425 foreach($nodes as $node)
00426 {
00427 if($node["type"] == $_SESSION["search_link_type"])
00428 {
00429 $this->tpl->setCurrentBlock("linktable_row");
00430 $this->tpl->setVariable("TEXT_LINK", $node["title"]);
00431 $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
00432 $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($node["type"])) . "&" . $node["type"] . "=" . $node["obj_id"]);
00433 $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
00434 $this->tpl->parseCurrentBlock();
00435 $counter++;
00436 }
00437 }
00438 $this->tpl->setCurrentBlock("link_selection");
00439 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00440 $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_SESSION["search_link_type"]));
00441 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00442 $this->tpl->parseCurrentBlock();
00443 break;
00444 case "glo":
00445 $_GET["q_id"] = $this->object->getId();
00446 $color_class = array("tblrow1", "tblrow2");
00447 $counter = 0;
00448 $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", true);
00449 include_once "./content/classes/class.ilObjGlossary.php";
00450 $glossary =& new ilObjGlossary($_GET["source_id"], true);
00451
00452 $terms = $glossary->getTermList();
00453 foreach($terms as $term)
00454 {
00455 $this->tpl->setCurrentBlock("linktable_row");
00456 $this->tpl->setVariable("TEXT_LINK", $term["term"]);
00457 $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
00458 $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "addGIT") . "&git=" . $term["id"]);
00459 $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
00460 $this->tpl->parseCurrentBlock();
00461 $counter++;
00462 }
00463 $this->tpl->setCurrentBlock("link_selection");
00464 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00465 $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("glossary_term"));
00466 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00467 $this->tpl->parseCurrentBlock();
00468 break;
00469 case "lm":
00470 $this->object->setMaterial("il__lm_" . $_GET["source_id"]);
00471 unset($_SESSION["link_new_type"]);
00472 unset($_SESSION["search_link_type"]);
00473 sendInfo($this->lng->txt("material_added_successfully"));
00474 $this->editQuestion();
00475 break;
00476 }
00477 }
00478
00479 function setQuestionTabsForClass($guiclass)
00480 {
00481 global $rbacsystem,$ilTabs;
00482
00483 $this->ctrl->setParameterByClass("$guiclass", "sel_question_types", $this->getQuestionType());
00484 $this->ctrl->setParameterByClass("$guiclass", "q_id", $_GET["q_id"]);
00485
00486 if (($_GET["calling_survey"] > 0) || ($_GET["new_for_survey"] > 0))
00487 {
00488 $ref_id = $_GET["calling_survey"];
00489 if (!strlen($ref_id)) $ref_id = $_GET["new_for_survey"];
00490 $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), "ilias.php?baseClass=ilObjSurveyGUI&ref_id=$ref_id&cmd=questions&new_id=".$_GET["q_id"]);
00491
00492 if ($_GET["q_id"])
00493 {
00494 $ilTabs->addTarget("preview",
00495 $this->ctrl->getLinkTargetByClass("$guiclass", "preview"), "preview",
00496 "$guiclass");
00497 }
00498
00499 if ($rbacsystem->checkAccess('edit', $_GET["ref_id"])) {
00500 $ilTabs->addTarget("edit_properties",
00501 $this->ctrl->getLinkTargetByClass("$guiclass", "editQuestion"),
00502 array("editQuestion", "cancelExplorer", "linkChilds", "addGIT", "addST",
00503 "addPG",
00504 "editQuestion", "addMaterial", "removeMaterial", "save", "cancel"
00505 ),
00506 "$guiclass");
00507 }
00508
00509 switch ($guiclass)
00510 {
00511 case "surveynominalquestiongui":
00512 case "surveyordinalquestiongui":
00513 if ($this->object->getId() > 0)
00514 {
00515 $ilTabs->addTarget("categories",
00516 $this->ctrl->getLinkTargetByClass("$guiclass", "categories"),
00517 array("categories", "addCategory", "insertBeforeCategory",
00518 "insertAfterCategory", "moveCategory", "deleteCategory",
00519 "saveCategories", "savePhrase", "addPhrase",
00520 "savePhrase", "addSelectedPhrase", "cancelViewPhrase", "confirmSavePhrase",
00521 "cancelSavePhrase",
00522 "confirmDeleteCategory", "cancelDeleteCategory"
00523 ),
00524 $guiclass
00525 );
00526 }
00527 break;
00528 }
00529 }
00530 else
00531 {
00532 if ($_GET["q_id"])
00533 {
00534 $ilTabs->addSubTabTarget("preview",
00535 $this->ctrl->getLinkTargetByClass("$guiclass", "preview"), "preview",
00536 "$guiclass");
00537 }
00538
00539 if ($rbacsystem->checkAccess('edit', $_GET["ref_id"])) {
00540 $ilTabs->addSubTabTarget("edit_properties",
00541 $this->ctrl->getLinkTargetByClass("$guiclass", "editQuestion"),
00542 array("editQuestion", "cancelExplorer", "linkChilds", "addGIT", "addST",
00543 "addPG",
00544 "editQuestion", "addMaterial", "removeMaterial", "save", "cancel"
00545 ),
00546 "$guiclass");
00547 }
00548
00549 switch ($guiclass)
00550 {
00551 case "surveynominalquestiongui":
00552 case "surveyordinalquestiongui":
00553 if ($this->object->getId() > 0)
00554 {
00555 $ilTabs->addSubTabTarget("categories",
00556 $this->ctrl->getLinkTargetByClass("$guiclass", "categories"),
00557 array("categories", "addCategory", "insertBeforeCategory",
00558 "insertAfterCategory", "moveCategory", "deleteCategory",
00559 "saveCategories", "savePhrase", "addPhrase",
00560 "savePhrase", "addSelectedPhrase", "cancelViewPhrase", "confirmSavePhrase",
00561 "cancelSavePhrase",
00562 "confirmDeleteCategory", "cancelDeleteCategory"
00563 ),
00564 $guiclass
00565 );
00566 }
00567 break;
00568 }
00569 }
00570 if ($this->object->getId() > 0) {
00571 $title = $this->lng->txt("edit") . " "" . $this->object->getTitle() . """;
00572 } else {
00573 $title = $this->lng->txt("create_new") . " " . $this->lng->txt($this->getQuestionType());
00574 }
00575 $this->tpl->setVariable("HEADER", $title);
00576 }
00577
00585 function addCategory()
00586 {
00587 $result = $this->writeCategoryData();
00588 if ($result == false)
00589 {
00590 sendInfo($this->lng->txt("fill_out_all_category_fields"));
00591 }
00592 $_SESSION["spl_modified"] = true;
00593 $this->categories($result);
00594 }
00595
00596
00606 function writeCategoryData($save = false)
00607 {
00608
00609 $this->object->categories->flushCategories();
00610 $complete = true;
00611 $array1 = array();
00612
00613 include_once "./classes/class.ilUtil.php";
00614 foreach ($_POST as $key => $value)
00615 {
00616 if (preg_match("/^category_(\d+)/", $key, $matches))
00617 {
00618 $array1[$matches[1]] = ilUtil::stripSlashes($value);
00619 if (strlen($array1[$matches[1]]) == 0) $complete = false;
00620 }
00621 }
00622 $this->object->categories->addCategoryArray($array1);
00623 if ($save)
00624 {
00625 $this->object->saveCategoriesToDb();
00626 }
00627 return $complete;
00628 }
00629
00637 function deleteCategory()
00638 {
00639 $this->writeCategoryData();
00640 $nothing_selected = true;
00641 if (array_key_exists("chb_category", $_POST))
00642 {
00643 if (count($_POST["chb_category"]))
00644 {
00645 $nothing_selected = false;
00646 $this->object->categories->removeCategories($_POST["chb_category"]);
00647 }
00648 }
00649 if ($nothing_selected) sendInfo($this->lng->txt("category_delete_select_none"));
00650 $_SESSION["spl_modified"] = true;
00651 $this->categories();
00652 }
00653
00661 function moveCategory()
00662 {
00663 $this->writeCategoryData();
00664 $nothing_selected = true;
00665 if (array_key_exists("chb_category", $_POST))
00666 {
00667 if (count($_POST["chb_category"]))
00668 {
00669 $nothing_selected = false;
00670 sendInfo($this->lng->txt("select_target_position_for_move"));
00671 $_SESSION["spl_move"] = $_POST["chb_category"];
00672 }
00673 }
00674 if ($nothing_selected) sendInfo($this->lng->txt("no_category_selected_for_move"));
00675 $this->categories();
00676 }
00677
00685 function insertBeforeCategory()
00686 {
00687 $result = $this->writeCategoryData();
00688 if (array_key_exists("chb_category", $_POST))
00689 {
00690 if (count($_POST["chb_category"]) == 1)
00691 {
00692
00693 $this->object->categories->removeCategories($_SESSION["spl_move"]);
00694 $newinsertindex = $this->object->categories->getCategoryIndex($_POST["category_".$_POST["chb_category"][0]]);
00695 if ($newinsertindex === false) $newinsertindex = 0;
00696 $move_categories = $_SESSION["spl_move"];
00697 natsort($move_categories);
00698 foreach (array_reverse($move_categories) as $index)
00699 {
00700 $this->object->categories->addCategoryAtPosition($_POST["category_$index"], $newinsertindex);
00701 }
00702 }
00703 }
00704 $_SESSION["spl_modified"] = true;
00705 unset($_SESSION["spl_move"]);
00706 $this->categories();
00707 }
00708
00716 function insertAfterCategory()
00717 {
00718 $result = $this->writeCategoryData();
00719 if (array_key_exists("chb_category", $_POST))
00720 {
00721 if (count($_POST["chb_category"]) == 1)
00722 {
00723
00724 $this->object->categories->removeCategories($_SESSION["spl_move"]);
00725 $newinsertindex = $this->object->categories->getCategoryIndex($_POST["category_".$_POST["chb_category"][0]]);
00726 if ($newinsertindex === false) $newinsertindex = 0;
00727 $move_categories = $_SESSION["spl_move"];
00728 natsort($move_categories);
00729 foreach (array_reverse($move_categories) as $index)
00730 {
00731 $this->object->categories->addCategoryAtPosition($_POST["category_$index"], $newinsertindex+1);
00732 }
00733 }
00734 }
00735 $_SESSION["spl_modified"] = true;
00736 unset($_SESSION["spl_move"]);
00737 $this->categories();
00738 }
00739 }
00740 ?>