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/Survey/classes/inc.SurveyConstants.php";
00025
00036 class SurveyQuestionGUI
00037 {
00045 var $object;
00046 var $tpl;
00047 var $lng;
00048 var $errormessage;
00049
00057 var $cumulated;
00058
00070 function SurveyQuestionGUI()
00071
00072 {
00073 global $lng, $tpl, $ilCtrl;
00074
00075 $this->lng =& $lng;
00076 $this->tpl =& $tpl;
00077 $this->ctrl =& $ilCtrl;
00078 $this->ctrl->saveParameter($this, "q_id");
00079 $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
00080 $this->cumulated = array();
00081 }
00082
00086 function &executeCommand()
00087 {
00088 $cmd = $this->ctrl->getCmd();
00089 $next_class = $this->ctrl->getNextClass($this);
00090
00091 $cmd = $this->getCommand($cmd);
00092 switch($next_class)
00093 {
00094 default:
00095 $ret =& $this->$cmd();
00096 break;
00097 }
00098 return $ret;
00099 }
00100
00101 function getCommand($cmd)
00102 {
00103 return $cmd;
00104 }
00105
00117 function &_getQuestionGUI($questiontype, $question_id = -1)
00118 {
00119 if (!$questiontype)
00120 {
00121 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
00122 $questiontype = SurveyQuestion::_getQuestiontype($question_id);
00123 }
00124 $questiontypegui = $questiontype . "GUI";
00125 include_once "./Modules/SurveyQuestionPool/classes/class.$questiontypegui.php";
00126 $question = new $questiontypegui();
00127 if ($question_id > 0)
00128 {
00129 $question->object->loadFromDb($question_id);
00130 }
00131
00132 return $question;
00133 }
00134
00135 function _getGUIClassNameForId($a_q_id)
00136 {
00137 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
00138 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
00139 $q_type = SurveyQuestion::_getQuestiontype($a_q_id);
00140 $class_name = SurveyQuestionGUI::_getClassNameForQType($q_type);
00141 return $class_name;
00142 }
00143
00144 function _getClassNameForQType($q_type)
00145 {
00146 return $q_type;
00147 }
00148
00149 function originalSyncForm()
00150 {
00151 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_sync_original.html", "Modules/SurveyQuestionPool");
00152 $this->tpl->setCurrentBlock("adm_content");
00153 $this->tpl->setVariable("BUTTON_YES", $this->lng->txt("yes"));
00154 $this->tpl->setVariable("BUTTON_NO", $this->lng->txt("no"));
00155 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00156 $this->tpl->setVariable("TEXT_SYNC", $this->lng->txt("confirm_sync_questions"));
00157 $this->tpl->parseCurrentBlock();
00158 }
00159
00160 function sync()
00161 {
00162 $original_id = $this->object->original_id;
00163 if ($original_id)
00164 {
00165 $this->object->syncWithOriginal();
00166 }
00167 $this->ctrl->redirect($this, "editQuestion");
00168
00169
00170
00171
00172 }
00173
00174 function cancelSync()
00175 {
00176 $this->ctrl->redirect($this, "editQuestion");
00177
00178
00179
00180 }
00181
00185 function save()
00186 {
00187 global $ilUser;
00188
00189 $old_id = $_GET["q_id"];
00190 $this->errormessage = $this->lng->txt("fill_out_all_required_fields");
00191 $result = $this->writePostData();
00192 if ($result == 0)
00193 {
00194 $ilUser->setPref("svy_lastquestiontype", $this->object->getQuestionType());
00195 $ilUser->writePref("svy_lastquestiontype", $this->object->getQuestionType());
00196 $this->object->saveToDb();
00197 $originalexists = $this->object->_questionExists($this->object->original_id);
00198 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00199 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
00200 if ($_GET["calling_survey"] && $originalexists && SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
00201 {
00202 $this->originalSyncForm();
00203 return;
00204 }
00205 elseif ($_GET["calling_survey"])
00206 {
00207 $_GET["ref_id"] = $_GET["calling_survey"];
00208 include_once "./Services/Utilities/classes/class.ilUtil.php";
00209 ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&ref_id=" . $_GET["calling_survey"] . "&cmd=questions");
00210 return;
00211 }
00212 elseif ($_GET["new_for_survey"] > 0)
00213 {
00214 $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
00215 $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
00216 $this->ctrl->setParameterByClass($_GET["cmdClass"], "new_for_survey", $_GET["new_for_survey"]);
00217 $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
00218 return;
00219 }
00220 else
00221 {
00222 ilUtil::sendInfo($this->lng->txt("msg_obj_modified"), true);
00223 $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
00224 $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
00225 $this->ctrl->setParameterByClass($_GET["cmdClass"], "new_for_survey", $_GET["new_for_survey"]);
00226 $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
00227 }
00228 }
00229 else
00230 {
00231 ilUtil::sendInfo($this->errormessage);
00232 }
00233 $this->editQuestion();
00234 }
00235
00236 function cancel()
00237 {
00238 if ($_GET["calling_survey"])
00239 {
00240 $_GET["ref_id"] = $_GET["calling_survey"];
00241 include_once "./Services/Utilities/classes/class.ilUtil.php";
00242 ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&cmd=questions&ref_id=".$_GET["calling_survey"]);
00243 }
00244 elseif ($_GET["new_for_survey"])
00245 {
00246 $_GET["ref_id"] = $_GET["new_for_survey"];
00247 include_once "./Services/Utilities/classes/class.ilUtil.php";
00248 ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&cmd=questions&ref_id=".$_GET["new_for_survey"]);
00249 }
00250 else
00251 {
00252 $this->ctrl->redirectByClass("ilobjsurveyquestionpoolgui", "questions");
00253 }
00254 }
00255
00263 function cancelDeleteCategory()
00264 {
00265 $this->ctrl->redirect($this, "editQuestion");
00266 }
00267
00268 function addMaterial()
00269 {
00270 global $tree;
00271
00272 if ($_POST["cmd"]["addMaterial"])
00273 {
00274 if ($this->writePostData() == 1)
00275 {
00276 return $this->editQuestion();
00277 }
00278 else
00279 {
00280 $this->object->saveToDb();
00281 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00282 }
00283 }
00284 include_once("./Modules/SurveyQuestionPool/classes/class.ilMaterialExplorer.php");
00285 switch ($_POST["internalLinkType"])
00286 {
00287 case "lm":
00288 $_SESSION["link_new_type"] = "lm";
00289 $_SESSION["search_link_type"] = "lm";
00290 break;
00291 case "glo":
00292 $_SESSION["link_new_type"] = "glo";
00293 $_SESSION["search_link_type"] = "glo";
00294 break;
00295 case "st":
00296 $_SESSION["link_new_type"] = "lm";
00297 $_SESSION["search_link_type"] = "st";
00298 break;
00299 case "pg":
00300 $_SESSION["link_new_type"] = "lm";
00301 $_SESSION["search_link_type"] = "pg";
00302 break;
00303 default:
00304 if (!$_SESSION["link_new_type"])
00305 {
00306 $_SESSION["link_new_type"] = "lm";
00307 }
00308 break;
00309 }
00310
00311 ilUtil::sendInfo($this->lng->txt("select_object_to_link"));
00312
00313 $exp = new ilMaterialExplorer($this->ctrl->getLinkTarget($this,'addMaterial'), get_class($this));
00314
00315 $exp->setExpand($_GET["expand"] ? $_GET["expand"] : $tree->readRootId());
00316 $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'addMaterial'));
00317 $exp->setTargetGet("ref_id");
00318 $exp->setRefId($this->cur_ref_id);
00319 $exp->addFilter($_SESSION["link_new_type"]);
00320 $exp->setSelectableType($_SESSION["link_new_type"]);
00321
00322
00323 $exp->setOutput(0);
00324
00325 $this->tpl->addBlockFile("ADM_CONTENT", "explorer", "tpl.il_svy_qpl_explorer.html", "Modules/SurveyQuestionPool");
00326 $this->tpl->setVariable("EXPLORER_TREE",$exp->getOutput());
00327 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00328 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00329 $this->tpl->parseCurrentBlock();
00330 }
00331
00332 function removeMaterial()
00333 {
00334 $this->object->material = array();
00335 $this->object->saveToDb();
00336 $this->editQuestion();
00337 }
00338
00339 function cancelExplorer()
00340 {
00341 unset($_SESSION["link_new_type"]);
00342 $this->editQuestion();
00343 }
00344
00345 function addPG()
00346 {
00347 $this->object->setMaterial("il__pg_" . $_GET["pg"]);
00348 unset($_SESSION["link_new_type"]);
00349 unset($_SESSION["search_link_type"]);
00350 ilUtil::sendInfo($this->lng->txt("material_added_successfully"));
00351 $this->editQuestion();
00352 }
00353
00354 function addST()
00355 {
00356 $this->object->setMaterial("il__st_" . $_GET["st"]);
00357 unset($_SESSION["link_new_type"]);
00358 unset($_SESSION["search_link_type"]);
00359 ilUtil::sendInfo($this->lng->txt("material_added_successfully"));
00360 $this->editQuestion();
00361 }
00362
00363 function addGIT()
00364 {
00365 $this->object->setMaterial("il__git_" . $_GET["git"]);
00366 unset($_SESSION["link_new_type"]);
00367 unset($_SESSION["search_link_type"]);
00368 ilUtil::sendInfo($this->lng->txt("material_added_successfully"));
00369 $this->editQuestion();
00370 }
00371
00372 function linkChilds()
00373 {
00374 switch ($_SESSION["search_link_type"])
00375 {
00376 case "pg":
00377 include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
00378 include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
00379 $cont_obj_gui =& new ilObjContentObjectGUI("", $_GET["source_id"], true);
00380 $cont_obj = $cont_obj_gui->object;
00381 $pages = ilLMPageObject::getPageList($cont_obj->getId());
00382 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00383 $color_class = array("tblrow1", "tblrow2");
00384 $counter = 0;
00385 $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", "Modules/SurveyQuestionPool");
00386 foreach($pages as $page)
00387 {
00388 if($page["type"] == $_SESSION["search_link_type"])
00389 {
00390 $this->tpl->setCurrentBlock("linktable_row");
00391 $this->tpl->setVariable("TEXT_LINK", $page["title"]);
00392 $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
00393 $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($page["type"])) . "&" . $page["type"] . "=" . $page["obj_id"]);
00394 $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
00395 $this->tpl->parseCurrentBlock();
00396 $counter++;
00397 }
00398 }
00399 $this->tpl->setCurrentBlock("link_selection");
00400 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00401 $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_SESSION["search_link_type"]));
00402 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00403 $this->tpl->parseCurrentBlock();
00404 break;
00405 case "st":
00406 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00407 $color_class = array("tblrow1", "tblrow2");
00408 $counter = 0;
00409 include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
00410 $cont_obj_gui =& new ilObjContentObjectGUI("", $_GET["source_id"], true);
00411 $cont_obj = $cont_obj_gui->object;
00412
00413 $ctree =& $cont_obj->getLMTree();
00414 $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
00415 $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", "Modules/SurveyQuestionPool");
00416 foreach($nodes as $node)
00417 {
00418 if($node["type"] == $_SESSION["search_link_type"])
00419 {
00420 $this->tpl->setCurrentBlock("linktable_row");
00421 $this->tpl->setVariable("TEXT_LINK", $node["title"]);
00422 $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
00423 $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($node["type"])) . "&" . $node["type"] . "=" . $node["obj_id"]);
00424 $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
00425 $this->tpl->parseCurrentBlock();
00426 $counter++;
00427 }
00428 }
00429 $this->tpl->setCurrentBlock("link_selection");
00430 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00431 $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_SESSION["search_link_type"]));
00432 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00433 $this->tpl->parseCurrentBlock();
00434 break;
00435 case "glo":
00436 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00437 $color_class = array("tblrow1", "tblrow2");
00438 $counter = 0;
00439 $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", "Modules/SurveyQuestionPool");
00440 include_once "./Modules/Glossary/classes/class.ilObjGlossary.php";
00441 $glossary =& new ilObjGlossary($_GET["source_id"], true);
00442
00443 $terms = $glossary->getTermList();
00444 foreach($terms as $term)
00445 {
00446 $this->tpl->setCurrentBlock("linktable_row");
00447 $this->tpl->setVariable("TEXT_LINK", $term["term"]);
00448 $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
00449 $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "addGIT") . "&git=" . $term["id"]);
00450 $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
00451 $this->tpl->parseCurrentBlock();
00452 $counter++;
00453 }
00454 $this->tpl->setCurrentBlock("link_selection");
00455 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00456 $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("glossary_term"));
00457 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00458 $this->tpl->parseCurrentBlock();
00459 break;
00460 case "lm":
00461 $this->object->setMaterial("il__lm_" . $_GET["source_id"]);
00462 unset($_SESSION["link_new_type"]);
00463 unset($_SESSION["search_link_type"]);
00464 ilUtil::sendInfo($this->lng->txt("material_added_successfully"));
00465 $this->editQuestion();
00466 break;
00467 }
00468 }
00469
00470
00478 function getPrintView($question_title = 1, $show_questiontext = 1)
00479 {
00480 return "";
00481 }
00482
00483 function setQuestionTabsForClass($guiclass)
00484 {
00485 global $rbacsystem,$ilTabs;
00486 $this->ctrl->setParameterByClass("$guiclass", "sel_question_types", $this->getQuestionType());
00487 $this->ctrl->setParameterByClass("$guiclass", "q_id", $_GET["q_id"]);
00488
00489 if (($_GET["calling_survey"] > 0) || ($_GET["new_for_survey"] > 0))
00490 {
00491 $ref_id = $_GET["calling_survey"];
00492 if (!strlen($ref_id)) $ref_id = $_GET["new_for_survey"];
00493 $addurl = "";
00494 if (strlen($_GET["new_for_survey"]))
00495 {
00496 $addurl = "&new_id=" . $_GET["q_id"];
00497 }
00498 $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), "ilias.php?baseClass=ilObjSurveyGUI&ref_id=$ref_id&cmd=questions" . $addurl);
00499 }
00500 else
00501 {
00502 $ilTabs->setBackTarget($this->lng->txt("spl"), $this->ctrl->getLinkTargetByClass("ilObjSurveyQuestionPoolGUI", "questions"));
00503 }
00504 if ($_GET["q_id"])
00505 {
00506 $ilTabs->addTarget("preview",
00507 $this->ctrl->getLinkTargetByClass("$guiclass", "preview"), "preview",
00508 "$guiclass");
00509 }
00510 if ($rbacsystem->checkAccess('edit', $_GET["ref_id"])) {
00511 $ilTabs->addTarget("edit_properties",
00512 $this->ctrl->getLinkTargetByClass("$guiclass", "editQuestion"),
00513 array("editQuestion", "cancelExplorer", "linkChilds", "addGIT", "addST",
00514 "addPG",
00515 "editQuestion", "addMaterial", "removeMaterial", "save", "cancel"
00516 ),
00517 "$guiclass");
00518 }
00519
00520 switch ($guiclass)
00521 {
00522 case "surveynominalquestiongui":
00523 case "surveyordinalquestiongui":
00524 if ($this->object->getId() > 0)
00525 {
00526 $ilTabs->addTarget("categories",
00527 $this->ctrl->getLinkTargetByClass("$guiclass", "categories"),
00528 array("categories", "addCategory", "insertBeforeCategory",
00529 "insertAfterCategory", "moveCategory", "deleteCategory",
00530 "saveCategories", "savePhrase", "addPhrase",
00531 "savePhrase", "addSelectedPhrase", "cancelViewPhrase", "confirmSavePhrase",
00532 "cancelSavePhrase",
00533 "confirmDeleteCategory", "cancelDeleteCategory"
00534 ),
00535 $guiclass
00536 );
00537 }
00538 break;
00539 }
00540
00541 if ($this->object->getId() > 0)
00542 {
00543 $title = $this->lng->txt("edit") . " "" . $this->object->getTitle() . """;
00544 }
00545 else
00546 {
00547 $title = $this->lng->txt("create_new") . " " . $this->lng->txt($this->getQuestionType());
00548 }
00549
00550 $this->tpl->setVariable("HEADER", $title);
00551 }
00552
00561 function getQuestionType()
00562 {
00563 return $this->object->getQuestionType();
00564 }
00565
00574 function getCumulatedResultRow($counter, $css_class, $survey_id)
00575 {
00576
00577 return "";
00578 }
00579 }
00580 ?>