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 $questiontypegui = $questiontype . "GUI";
00114 include_once "./survey/classes/class.$questiontypegui.php";
00115 $question = new $questiontypegui();
00116 if ($question_id > 0)
00117 {
00118 $question->object->loadFromDb($question_id);
00119 }
00120
00121 return $question;
00122 }
00123
00124 function _getGUIClassNameForId($a_q_id)
00125 {
00126 include_once "./survey/classes/class.SurveyQuestion.php";
00127 include_once "./survey/classes/class.SurveyQuestionGUI.php";
00128 $q_type = SurveyQuestion::_getQuestiontype($a_q_id);
00129 $class_name = SurveyQuestionGUI::_getClassNameForQType($q_type);
00130 return $class_name;
00131 }
00132
00133 function _getClassNameForQType($q_type)
00134 {
00135 return $q_type;
00136 }
00137
00138 function originalSyncForm()
00139 {
00140 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_sync_original.html", true);
00141 $this->tpl->setCurrentBlock("adm_content");
00142 $this->tpl->setVariable("BUTTON_YES", $this->lng->txt("yes"));
00143 $this->tpl->setVariable("BUTTON_NO", $this->lng->txt("no"));
00144 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00145 $this->tpl->setVariable("TEXT_SYNC", $this->lng->txt("confirm_sync_questions"));
00146 $this->tpl->parseCurrentBlock();
00147 }
00148
00149 function sync()
00150 {
00151 $original_id = $this->object->original_id;
00152 if ($original_id)
00153 {
00154 $this->object->syncWithOriginal();
00155 }
00156 $this->ctrl->redirect($this, "editQuestion");
00157
00158
00159
00160
00161 }
00162
00163 function cancelSync()
00164 {
00165 $this->ctrl->redirect($this, "editQuestion");
00166
00167
00168
00169 }
00170
00178 function saveCategories()
00179 {
00180 global $ilUser;
00181
00182 $this->writeCategoryData(true);
00183 $_SESSION["spl_modified"] = false;
00184 sendInfo($this->lng->txt("saved_successfully"), true);
00185 $originalexists = $this->object->_questionExists($this->object->original_id);
00186 $_GET["q_id"] = $this->object->getId();
00187 include_once "./survey/classes/class.SurveyQuestion.php";
00188 if ($_GET["calling_survey"] && $originalexists && SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
00189 {
00190 $this->originalSyncForm();
00191 return;
00192 }
00193 else
00194 {
00195 $this->ctrl->redirect($this, "categories");
00196 }
00197 }
00198
00202 function save()
00203 {
00204 global $ilUser;
00205
00206 $old_id = $_GET["q_id"];
00207 $this->errormessage = $this->lng->txt("fill_out_all_required_fields");
00208 $result = $this->writePostData();
00209 if ($result == 0)
00210 {
00211 $ilUser->setPref("svy_lastquestiontype", $this->object->getQuestionType());
00212 $ilUser->writePref("svy_lastquestiontype", $this->object->getQuestionType());
00213 $this->object->saveToDb();
00214 $originalexists = $this->object->_questionExists($this->object->original_id);
00215 $_GET["q_id"] = $this->object->getId();
00216 include_once "./survey/classes/class.SurveyQuestion.php";
00217 if ($_GET["calling_survey"] && $originalexists && SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
00218 {
00219 $this->originalSyncForm();
00220 return;
00221 }
00222 elseif ($_GET["calling_survey"])
00223 {
00224 $_GET["ref_id"] = $_GET["calling_survey"];
00225 include_once "./classes/class.ilUtil.php";
00226 ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&ref_id=" . $_GET["calling_survey"] . "&cmd=questions");
00227 return;
00228 }
00229 elseif ($_GET["new_for_survey"] > 0)
00230 {
00231 $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
00232 $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
00233 $this->ctrl->setParameterByClass($_GET["cmdClass"], "new_for_survey", $_GET["new_for_survey"]);
00234 $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
00235 return;
00236 }
00237 else
00238 {
00239 sendInfo($this->lng->txt("msg_obj_modified"), true);
00240 $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
00241 $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
00242 $this->ctrl->setParameterByClass($_GET["cmdClass"], "new_for_survey", $_GET["new_for_survey"]);
00243 $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
00244 }
00245 }
00246 else
00247 {
00248 sendInfo($this->errormessage);
00249 }
00250 $this->editQuestion();
00251 }
00252
00253 function cancel()
00254 {
00255 if ($_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&cmd=questions&ref_id=".$_GET["calling_survey"]);
00260 }
00261 elseif ($_GET["new_for_survey"])
00262 {
00263 $_GET["ref_id"] = $_GET["new_for_survey"];
00264 include_once "./classes/class.ilUtil.php";
00265 ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&cmd=questions&ref_id=".$_GET["new_for_survey"]);
00266 }
00267 else
00268 {
00269 $this->ctrl->redirectByClass("ilobjsurveyquestionpoolgui", "questions");
00270 }
00271 }
00272
00280 function cancelDeleteCategory()
00281 {
00282 $this->ctrl->redirect($this, "editQuestion");
00283 }
00284
00285 function addMaterial()
00286 {
00287 global $tree;
00288
00289 include_once("./survey/classes/class.ilMaterialExplorer.php");
00290 switch ($_POST["internalLinkType"])
00291 {
00292 case "lm":
00293 $_SESSION["link_new_type"] = "lm";
00294 $_SESSION["search_link_type"] = "lm";
00295 break;
00296 case "glo":
00297 $_SESSION["link_new_type"] = "glo";
00298 $_SESSION["search_link_type"] = "glo";
00299 break;
00300 case "st":
00301 $_SESSION["link_new_type"] = "lm";
00302 $_SESSION["search_link_type"] = "st";
00303 break;
00304 case "pg":
00305 $_SESSION["link_new_type"] = "lm";
00306 $_SESSION["search_link_type"] = "pg";
00307 break;
00308 default:
00309 if (!$_SESSION["link_new_type"])
00310 {
00311 $_SESSION["link_new_type"] = "lm";
00312 }
00313 break;
00314 }
00315
00316 sendInfo($this->lng->txt("select_object_to_link"));
00317
00318 $exp = new ilMaterialExplorer($this->ctrl->getLinkTarget($this,'addMaterial'), get_class($this));
00319
00320 $exp->setExpand($_GET["expand"] ? $_GET["expand"] : $tree->readRootId());
00321 $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'addMaterial'));
00322 $exp->setTargetGet("ref_id");
00323 $exp->setRefId($this->cur_ref_id);
00324 $exp->addFilter($_SESSION["link_new_type"]);
00325 $exp->setSelectableType($_SESSION["link_new_type"]);
00326
00327
00328 $exp->setOutput(0);
00329
00330 $this->tpl->addBlockFile("ADM_CONTENT", "explorer", "tpl.il_svy_qpl_explorer.html", true);
00331 $this->tpl->setVariable("EXPLORER_TREE",$exp->getOutput());
00332 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00333 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00334 $this->tpl->parseCurrentBlock();
00335 }
00336
00337 function removeMaterial()
00338 {
00339 $this->object->material = array();
00340 $this->object->saveToDb();
00341 $this->editQuestion();
00342 }
00343
00344 function cancelExplorer()
00345 {
00346 unset($_SESSION["link_new_type"]);
00347 $this->editQuestion();
00348 }
00349
00350 function addPG()
00351 {
00352 $this->object->setMaterial("il__pg_" . $_GET["pg"]);
00353 unset($_SESSION["link_new_type"]);
00354 unset($_SESSION["search_link_type"]);
00355 sendInfo($this->lng->txt("material_added_successfully"));
00356 $this->editQuestion();
00357 }
00358
00359 function addST()
00360 {
00361 $this->object->setMaterial("il__st_" . $_GET["st"]);
00362 unset($_SESSION["link_new_type"]);
00363 unset($_SESSION["search_link_type"]);
00364 sendInfo($this->lng->txt("material_added_successfully"));
00365 $this->editQuestion();
00366 }
00367
00368 function addGIT()
00369 {
00370 $this->object->setMaterial("il__git_" . $_GET["git"]);
00371 unset($_SESSION["link_new_type"]);
00372 unset($_SESSION["search_link_type"]);
00373 sendInfo($this->lng->txt("material_added_successfully"));
00374 $this->editQuestion();
00375 }
00376
00377 function linkChilds()
00378 {
00379 switch ($_SESSION["search_link_type"])
00380 {
00381 case "pg":
00382 include_once "./content/classes/class.ilLMPageObject.php";
00383 include_once("./content/classes/class.ilObjContentObject.php");
00384 $cont_obj =& new ilObjContentObject($_GET["source_id"], true);
00385 $pages = ilLMPageObject::getPageList($cont_obj->getId());
00386 $_GET["q_id"] = $this->object->getId();
00387 $color_class = array("tblrow1", "tblrow2");
00388 $counter = 0;
00389 $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", true);
00390 foreach($pages as $page)
00391 {
00392 if($page["type"] == $_SESSION["search_link_type"])
00393 {
00394 $this->tpl->setCurrentBlock("linktable_row");
00395 $this->tpl->setVariable("TEXT_LINK", $page["title"]);
00396 $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
00397 $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($page["type"])) . "&" . $page["type"] . "=" . $page["obj_id"]);
00398 $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
00399 $this->tpl->parseCurrentBlock();
00400 $counter++;
00401 }
00402 }
00403 $this->tpl->setCurrentBlock("link_selection");
00404 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00405 $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_SESSION["search_link_type"]));
00406 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00407 $this->tpl->parseCurrentBlock();
00408 break;
00409 case "st":
00410 $_GET["q_id"] = $this->object->getId();
00411 $color_class = array("tblrow1", "tblrow2");
00412 $counter = 0;
00413 include_once("./content/classes/class.ilObjContentObject.php");
00414 $cont_obj =& new ilObjContentObject($_GET["source_id"], true);
00415
00416 $ctree =& $cont_obj->getLMTree();
00417 $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
00418 $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", true);
00419 foreach($nodes as $node)
00420 {
00421 if($node["type"] == $_SESSION["search_link_type"])
00422 {
00423 $this->tpl->setCurrentBlock("linktable_row");
00424 $this->tpl->setVariable("TEXT_LINK", $node["title"]);
00425 $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
00426 $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($node["type"])) . "&" . $node["type"] . "=" . $node["obj_id"]);
00427 $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
00428 $this->tpl->parseCurrentBlock();
00429 $counter++;
00430 }
00431 }
00432 $this->tpl->setCurrentBlock("link_selection");
00433 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00434 $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_SESSION["search_link_type"]));
00435 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00436 $this->tpl->parseCurrentBlock();
00437 break;
00438 case "glo":
00439 $_GET["q_id"] = $this->object->getId();
00440 $color_class = array("tblrow1", "tblrow2");
00441 $counter = 0;
00442 $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", true);
00443 include_once "./content/classes/class.ilObjGlossary.php";
00444 $glossary =& new ilObjGlossary($_GET["source_id"], true);
00445
00446 $terms = $glossary->getTermList();
00447 foreach($terms as $term)
00448 {
00449 $this->tpl->setCurrentBlock("linktable_row");
00450 $this->tpl->setVariable("TEXT_LINK", $term["term"]);
00451 $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
00452 $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "addGIT") . "&git=" . $term["id"]);
00453 $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
00454 $this->tpl->parseCurrentBlock();
00455 $counter++;
00456 }
00457 $this->tpl->setCurrentBlock("link_selection");
00458 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00459 $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("glossary_term"));
00460 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00461 $this->tpl->parseCurrentBlock();
00462 break;
00463 case "lm":
00464 $this->object->setMaterial("il__lm_" . $_GET["source_id"]);
00465 unset($_SESSION["link_new_type"]);
00466 unset($_SESSION["search_link_type"]);
00467 sendInfo($this->lng->txt("material_added_successfully"));
00468 $this->editQuestion();
00469 break;
00470 }
00471 }
00472
00473 function setQuestionTabsForClass($guiclass)
00474 {
00475 global $rbacsystem,$ilTabs;
00476 $this->ctrl->setParameterByClass("$guiclass", "sel_question_types", $this->getQuestionType());
00477 $this->ctrl->setParameterByClass("$guiclass", "q_id", $_GET["q_id"]);
00478
00479 if (($_GET["calling_survey"] > 0) || ($_GET["new_for_survey"] > 0))
00480 {
00481 $ref_id = $_GET["calling_survey"];
00482 if (!strlen($ref_id)) $ref_id = $_GET["new_for_survey"];
00483 $addurl = "";
00484 if (strlen($_GET["new_for_survey"]))
00485 {
00486 $addurl = "&new_id=" . $_GET["q_id"];
00487 }
00488 $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), "ilias.php?baseClass=ilObjSurveyGUI&ref_id=$ref_id&cmd=questions" . $addurl);
00489 }
00490 else
00491 {
00492 $ilTabs->setBackTarget($this->lng->txt("spl"), $this->ctrl->getLinkTargetByClass("ilObjSurveyQuestionPoolGUI", "questions"));
00493 }
00494 if ($_GET["q_id"])
00495 {
00496 $ilTabs->addTarget("preview",
00497 $this->ctrl->getLinkTargetByClass("$guiclass", "preview"), "preview",
00498 "$guiclass");
00499 }
00500 if ($rbacsystem->checkAccess('edit', $_GET["ref_id"])) {
00501 $ilTabs->addTarget("edit_properties",
00502 $this->ctrl->getLinkTargetByClass("$guiclass", "editQuestion"),
00503 array("editQuestion", "cancelExplorer", "linkChilds", "addGIT", "addST",
00504 "addPG",
00505 "editQuestion", "addMaterial", "removeMaterial", "save", "cancel"
00506 ),
00507 "$guiclass");
00508 }
00509
00510 switch ($guiclass)
00511 {
00512 case "surveynominalquestiongui":
00513 case "surveyordinalquestiongui":
00514 if ($this->object->getId() > 0)
00515 {
00516 $ilTabs->addTarget("categories",
00517 $this->ctrl->getLinkTargetByClass("$guiclass", "categories"),
00518 array("categories", "addCategory", "insertBeforeCategory",
00519 "insertAfterCategory", "moveCategory", "deleteCategory",
00520 "saveCategories", "savePhrase", "addPhrase",
00521 "savePhrase", "addSelectedPhrase", "cancelViewPhrase", "confirmSavePhrase",
00522 "cancelSavePhrase",
00523 "confirmDeleteCategory", "cancelDeleteCategory"
00524 ),
00525 $guiclass
00526 );
00527 }
00528 break;
00529 }
00530
00531 if ($this->object->getId() > 0)
00532 {
00533 $title = $this->lng->txt("edit") . " "" . $this->object->getTitle() . """;
00534 }
00535 else
00536 {
00537 $title = $this->lng->txt("create_new") . " " . $this->lng->txt($this->getQuestionType());
00538 }
00539
00540 $this->tpl->setVariable("HEADER", $title);
00541 }
00542
00550 function addCategory()
00551 {
00552 $result = $this->writeCategoryData();
00553 if ($result == false)
00554 {
00555 sendInfo($this->lng->txt("fill_out_all_category_fields"));
00556 }
00557 $_SESSION["spl_modified"] = true;
00558 $this->categories($result);
00559 }
00560
00561
00571 function writeCategoryData($save = false)
00572 {
00573
00574 $this->object->categories->flushCategories();
00575 $complete = true;
00576 $array1 = array();
00577
00578 include_once "./classes/class.ilUtil.php";
00579 foreach ($_POST as $key => $value)
00580 {
00581 if (preg_match("/^category_(\d+)/", $key, $matches))
00582 {
00583 $array1[$matches[1]] = ilUtil::stripSlashes($value);
00584 if (strlen($array1[$matches[1]]) == 0) $complete = false;
00585 }
00586 }
00587 $this->object->categories->addCategoryArray($array1);
00588 if ($save)
00589 {
00590 $this->object->saveCategoriesToDb();
00591 }
00592 return $complete;
00593 }
00594
00602 function deleteCategory()
00603 {
00604 $this->writeCategoryData();
00605 $nothing_selected = true;
00606 if (array_key_exists("chb_category", $_POST))
00607 {
00608 if (count($_POST["chb_category"]))
00609 {
00610 $nothing_selected = false;
00611 $this->object->categories->removeCategories($_POST["chb_category"]);
00612 }
00613 }
00614 if ($nothing_selected) sendInfo($this->lng->txt("category_delete_select_none"));
00615 $_SESSION["spl_modified"] = true;
00616 $this->categories();
00617 }
00618
00626 function moveCategory()
00627 {
00628 $this->writeCategoryData();
00629 $nothing_selected = true;
00630 if (array_key_exists("chb_category", $_POST))
00631 {
00632 if (count($_POST["chb_category"]))
00633 {
00634 $nothing_selected = false;
00635 sendInfo($this->lng->txt("select_target_position_for_move"));
00636 $_SESSION["spl_move"] = $_POST["chb_category"];
00637 }
00638 }
00639 if ($nothing_selected) sendInfo($this->lng->txt("no_category_selected_for_move"));
00640 $this->categories();
00641 }
00642
00650 function insertBeforeCategory()
00651 {
00652 $result = $this->writeCategoryData();
00653 if (array_key_exists("chb_category", $_POST))
00654 {
00655 if (count($_POST["chb_category"]) == 1)
00656 {
00657
00658 $this->object->categories->removeCategories($_SESSION["spl_move"]);
00659 $newinsertindex = $this->object->categories->getCategoryIndex($_POST["category_".$_POST["chb_category"][0]]);
00660 if ($newinsertindex === false) $newinsertindex = 0;
00661 $move_categories = $_SESSION["spl_move"];
00662 natsort($move_categories);
00663 foreach (array_reverse($move_categories) as $index)
00664 {
00665 $this->object->categories->addCategoryAtPosition($_POST["category_$index"], $newinsertindex);
00666 }
00667 $_SESSION["spl_modified"] = true;
00668 unset($_SESSION["spl_move"]);
00669 }
00670 else
00671 {
00672 sendInfo("wrong_categories_selected_for_insert");
00673 }
00674 }
00675 $this->categories();
00676 }
00677
00685 function insertAfterCategory()
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+1);
00701 }
00702 $_SESSION["spl_modified"] = true;
00703 unset($_SESSION["spl_move"]);
00704 }
00705 else
00706 {
00707 sendInfo("wrong_categories_selected_for_insert");
00708 }
00709 }
00710 $this->categories();
00711 }
00712 }
00713 ?>