ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyQuestionGUI.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
25 
37 {
45  var $object;
46  var $tpl;
47  var $lng;
48  private $errormessages;
49 
58 
70  function SurveyQuestionGUI()
71  {
72  global $lng, $tpl, $ilCtrl;
73 
74  $this->lng =& $lng;
75  $this->tpl =& $tpl;
76  $this->ctrl =& $ilCtrl;
77  $this->ctrl->saveParameter($this, "q_id");
78  $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
79  $this->cumulated = array();
80  $this->errormessages = array();
81  }
82 
83  function addErrorMessage($errormessage)
84  {
85  if (strlen($errormessage)) array_push($this->errormessages, $errormessage);
86  }
87 
88  function outErrorMessages()
89  {
90  if (count($this->errormessages))
91  {
92  $out = implode("<br />", $this->errormessages);
94  }
95  }
96 
100  function &executeCommand()
101  {
102  $cmd = $this->ctrl->getCmd();
103  $next_class = $this->ctrl->getNextClass($this);
104 
105  $cmd = $this->getCommand($cmd);
106  switch($next_class)
107  {
108  default:
109  $ret =& $this->$cmd();
110  break;
111  }
112  return $ret;
113  }
114 
115  function getCommand($cmd)
116  {
117  return $cmd;
118  }
119 
131  static function &_getQuestionGUI($questiontype, $question_id = -1)
132  {
133  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
134  if ((!$questiontype) and ($question_id > 0))
135  {
136  $questiontype = SurveyQuestion::_getQuestiontype($question_id);
137  }
138  SurveyQuestion::_includeClass($questiontype, 1);
139  $question_type_gui = $questiontype . "GUI";
140  $question = new $question_type_gui($question_id);
141  return $question;
142  }
143 
144  function _getGUIClassNameForId($a_q_id)
145  {
146  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
147  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
148  $q_type = SurveyQuestion::_getQuestiontype($a_q_id);
149  $class_name = SurveyQuestionGUI::_getClassNameForQType($q_type);
150  return $class_name;
151  }
152 
153  function _getClassNameForQType($q_type)
154  {
155  return $q_type;
156  }
157 
158  function originalSyncForm()
159  {
160  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_sync_original.html", "Modules/SurveyQuestionPool");
161  $this->tpl->setCurrentBlock("adm_content");
162  $this->tpl->setVariable("BUTTON_YES", $this->lng->txt("yes"));
163  $this->tpl->setVariable("BUTTON_NO", $this->lng->txt("no"));
164  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
165  $this->tpl->setVariable("TEXT_SYNC", $this->lng->txt("confirm_sync_questions"));
166  $this->tpl->parseCurrentBlock();
167  }
168 
169  function sync()
170  {
171  $original_id = $this->object->original_id;
172  if ($original_id)
173  {
174  $this->object->syncWithOriginal();
175  }
176  $this->ctrl->redirect($this, "editQuestion");
177 
178  /*$_GET["ref_id"] = $_GET["calling_survey"];
179  include_once "./Services/Utilities/classes/class.ilUtil.php";
180  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&ref_id=" . $_GET["calling_survey"] . "&cmd=questions");*/
181  }
182 
183  function cancelSync()
184  {
185  $this->ctrl->redirect($this, "editQuestion");
186  /*$_GET["ref_id"] = $_GET["calling_survey"];
187  include_once "./Services/Utilities/classes/class.ilUtil.php";
188  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&ref_id=" . $_GET["calling_survey"] . "&cmd=questions");*/
189  }
190 
194  function save()
195  {
196  global $ilUser;
197 
198  $old_id = $_GET["q_id"];
199  $result = $this->writePostData();
200  if ($result == 0)
201  {
202  $ilUser->setPref("svy_lastquestiontype", $this->object->getQuestionType());
203  $ilUser->writePref("svy_lastquestiontype", $this->object->getQuestionType());
204  $this->object->saveToDb();
205  $originalexists = $this->object->_questionExists($this->object->original_id);
206  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
207  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
208  if ($_GET["calling_survey"] && $originalexists && SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
209  {
210  $this->originalSyncForm();
211  return;
212  }
213  elseif ($_GET["calling_survey"])
214  {
215  $_GET["ref_id"] = $_GET["calling_survey"];
216  include_once "./Services/Utilities/classes/class.ilUtil.php";
217  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&ref_id=" . $_GET["calling_survey"] . "&cmd=questions");
218  return;
219  }
220  elseif ($_GET["new_for_survey"] > 0)
221  {
222  $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
223  $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
224  $this->ctrl->setParameterByClass($_GET["cmdClass"], "new_for_survey", $_GET["new_for_survey"]);
225  $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
226  return;
227  }
228  else
229  {
230  ilUtil::sendInfo($this->lng->txt("msg_obj_modified"), true);
231  $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
232  $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
233  $this->ctrl->setParameterByClass($_GET["cmdClass"], "new_for_survey", $_GET["new_for_survey"]);
234  $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
235  }
236  }
237  $this->editQuestion();
238  }
239 
240  function cancel()
241  {
242  if ($_GET["calling_survey"])
243  {
244  $_GET["ref_id"] = $_GET["calling_survey"];
245  include_once "./Services/Utilities/classes/class.ilUtil.php";
246  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&cmd=questions&ref_id=".$_GET["calling_survey"]);
247  }
248  elseif ($_GET["new_for_survey"])
249  {
250  $_GET["ref_id"] = $_GET["new_for_survey"];
251  include_once "./Services/Utilities/classes/class.ilUtil.php";
252  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&cmd=questions&ref_id=".$_GET["new_for_survey"]);
253  }
254  else
255  {
256  $this->ctrl->redirectByClass("ilobjsurveyquestionpoolgui", "questions");
257  }
258  }
259 
268  {
269  $this->ctrl->redirect($this, "editQuestion");
270  }
271 
272  function addMaterial()
273  {
274  global $tree;
275 
276  if ($_POST["cmd"]["addMaterial"])
277  {
278  if ($this->writePostData() == 1)
279  {
280  return $this->editQuestion();
281  }
282  else
283  {
284  $this->object->saveToDb();
285  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
286  }
287  }
288  include_once("./Modules/SurveyQuestionPool/classes/class.ilMaterialExplorer.php");
289  switch ($_POST["internalLinkType"])
290  {
291  case "lm":
292  $_SESSION["link_new_type"] = "lm";
293  $_SESSION["search_link_type"] = "lm";
294  break;
295  case "glo":
296  $_SESSION["link_new_type"] = "glo";
297  $_SESSION["search_link_type"] = "glo";
298  break;
299  case "st":
300  $_SESSION["link_new_type"] = "lm";
301  $_SESSION["search_link_type"] = "st";
302  break;
303  case "pg":
304  $_SESSION["link_new_type"] = "lm";
305  $_SESSION["search_link_type"] = "pg";
306  break;
307  default:
308  if (!$_SESSION["link_new_type"])
309  {
310  $_SESSION["link_new_type"] = "lm";
311  }
312  break;
313  }
314 
315  ilUtil::sendInfo($this->lng->txt("select_object_to_link"));
316 
317  $exp = new ilMaterialExplorer($this->ctrl->getLinkTarget($this,'addMaterial'), get_class($this));
318 
319  $exp->setExpand($_GET["expand"] ? $_GET["expand"] : $tree->readRootId());
320  $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'addMaterial'));
321  $exp->setTargetGet("ref_id");
322  $exp->setRefId($this->cur_ref_id);
323  $exp->addFilter($_SESSION["link_new_type"]);
324  $exp->setSelectableType($_SESSION["link_new_type"]);
325 
326  // build html-output
327  $exp->setOutput(0);
328 
329  $this->tpl->addBlockFile("ADM_CONTENT", "explorer", "tpl.il_svy_qpl_explorer.html", "Modules/SurveyQuestionPool");
330  $this->tpl->setVariable("EXPLORER_TREE",$exp->getOutput());
331  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
332  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
333  $this->tpl->parseCurrentBlock();
334  }
335 
336  function removeMaterial()
337  {
338  $this->object->material = array();
339  $this->object->saveToDb();
340  $this->editQuestion();
341  }
342 
343  function cancelExplorer()
344  {
345  unset($_SESSION["link_new_type"]);
346  $this->editQuestion();
347  }
348 
349  function addPG()
350  {
351  $this->object->setMaterial("il__pg_" . $_GET["pg"]);
352  unset($_SESSION["link_new_type"]);
353  unset($_SESSION["search_link_type"]);
354  ilUtil::sendInfo($this->lng->txt("material_added_successfully"));
355  $this->editQuestion();
356  }
357 
358  function addST()
359  {
360  $this->object->setMaterial("il__st_" . $_GET["st"]);
361  unset($_SESSION["link_new_type"]);
362  unset($_SESSION["search_link_type"]);
363  ilUtil::sendInfo($this->lng->txt("material_added_successfully"));
364  $this->editQuestion();
365  }
366 
367  function addGIT()
368  {
369  $this->object->setMaterial("il__git_" . $_GET["git"]);
370  unset($_SESSION["link_new_type"]);
371  unset($_SESSION["search_link_type"]);
372  ilUtil::sendInfo($this->lng->txt("material_added_successfully"));
373  $this->editQuestion();
374  }
375 
376  function linkChilds()
377  {
378  switch ($_SESSION["search_link_type"])
379  {
380  case "pg":
381  include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
382  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
383  $cont_obj_gui =& new ilObjContentObjectGUI("", $_GET["source_id"], true);
384  $cont_obj = $cont_obj_gui->object;
385  $pages = ilLMPageObject::getPageList($cont_obj->getId());
386  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
387  $color_class = array("tblrow1", "tblrow2");
388  $counter = 0;
389  $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", "Modules/SurveyQuestionPool");
390  foreach($pages as $page)
391  {
392  if($page["type"] == $_SESSION["search_link_type"])
393  {
394  $this->tpl->setCurrentBlock("linktable_row");
395  $this->tpl->setVariable("TEXT_LINK", $page["title"]);
396  $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
397  $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($page["type"])) . "&" . $page["type"] . "=" . $page["obj_id"]);
398  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
399  $this->tpl->parseCurrentBlock();
400  $counter++;
401  }
402  }
403  $this->tpl->setCurrentBlock("link_selection");
404  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
405  $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_SESSION["search_link_type"]));
406  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
407  $this->tpl->parseCurrentBlock();
408  break;
409  case "st":
410  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
411  $color_class = array("tblrow1", "tblrow2");
412  $counter = 0;
413  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
414  $cont_obj_gui =& new ilObjContentObjectGUI("", $_GET["source_id"], true);
415  $cont_obj = $cont_obj_gui->object;
416  // get all chapters
417  $ctree =& $cont_obj->getLMTree();
418  $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
419  $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", "Modules/SurveyQuestionPool");
420  foreach($nodes as $node)
421  {
422  if($node["type"] == $_SESSION["search_link_type"])
423  {
424  $this->tpl->setCurrentBlock("linktable_row");
425  $this->tpl->setVariable("TEXT_LINK", $node["title"]);
426  $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
427  $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($node["type"])) . "&" . $node["type"] . "=" . $node["obj_id"]);
428  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
429  $this->tpl->parseCurrentBlock();
430  $counter++;
431  }
432  }
433  $this->tpl->setCurrentBlock("link_selection");
434  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
435  $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_SESSION["search_link_type"]));
436  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
437  $this->tpl->parseCurrentBlock();
438  break;
439  case "glo":
440  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
441  $color_class = array("tblrow1", "tblrow2");
442  $counter = 0;
443  $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", "Modules/SurveyQuestionPool");
444  include_once "./Modules/Glossary/classes/class.ilObjGlossary.php";
445  $glossary =& new ilObjGlossary($_GET["source_id"], true);
446  // get all glossary items
447  $terms = $glossary->getTermList();
448  foreach($terms as $term)
449  {
450  $this->tpl->setCurrentBlock("linktable_row");
451  $this->tpl->setVariable("TEXT_LINK", $term["term"]);
452  $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
453  $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "addGIT") . "&git=" . $term["id"]);
454  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
455  $this->tpl->parseCurrentBlock();
456  $counter++;
457  }
458  $this->tpl->setCurrentBlock("link_selection");
459  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
460  $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("glossary_term"));
461  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
462  $this->tpl->parseCurrentBlock();
463  break;
464  case "lm":
465  $this->object->setMaterial("il__lm_" . $_GET["source_id"]);
466  unset($_SESSION["link_new_type"]);
467  unset($_SESSION["search_link_type"]);
468  ilUtil::sendInfo($this->lng->txt("material_added_successfully"));
469  $this->editQuestion();
470  break;
471  }
472  }
473 
474 
482  function getPrintView($question_title = 1, $show_questiontext = 1)
483  {
484  return "";
485  }
486 
487  function setQuestionTabsForClass($guiclass)
488  {
489  global $rbacsystem,$ilTabs;
490  $this->ctrl->setParameterByClass("$guiclass", "sel_question_types", $this->getQuestionType());
491  $this->ctrl->setParameterByClass("$guiclass", "q_id", $_GET["q_id"]);
492 
493  if (($_GET["calling_survey"] > 0) || ($_GET["new_for_survey"] > 0))
494  {
495  $ref_id = $_GET["calling_survey"];
496  if (!strlen($ref_id)) $ref_id = $_GET["new_for_survey"];
497  $addurl = "";
498  if (strlen($_GET["new_for_survey"]))
499  {
500  $addurl = "&new_id=" . $_GET["q_id"];
501  }
502  $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), "ilias.php?baseClass=ilObjSurveyGUI&ref_id=$ref_id&cmd=questions" . $addurl);
503  }
504  else
505  {
506  $ilTabs->setBackTarget($this->lng->txt("spl"), $this->ctrl->getLinkTargetByClass("ilObjSurveyQuestionPoolGUI", "questions"));
507  }
508  if ($_GET["q_id"])
509  {
510  $ilTabs->addTarget("preview",
511  $this->ctrl->getLinkTargetByClass("$guiclass", "preview"), "preview",
512  "$guiclass");
513  }
514  if ($rbacsystem->checkAccess('edit', $_GET["ref_id"])) {
515  $ilTabs->addTarget("edit_properties",
516  $this->ctrl->getLinkTargetByClass("$guiclass", "editQuestion"),
517  array("editQuestion", "cancelExplorer", "linkChilds", "addGIT", "addST",
518  "addPG",
519  "editQuestion", "addMaterial", "removeMaterial", "save", "cancel"
520  ),
521  "$guiclass");
522  }
523 
524  switch ($guiclass)
525  {
526  case "surveynominalquestiongui":
527  case "surveyordinalquestiongui":
528  if ($this->object->getId() > 0)
529  {
530  $ilTabs->addTarget("categories",
531  $this->ctrl->getLinkTargetByClass("$guiclass", "categories"),
532  array("categories", "addCategory", "insertBeforeCategory",
533  "insertAfterCategory", "moveCategory", "deleteCategory",
534  "saveCategories", "savePhrase", "addPhrase",
535  "savePhrase", "addSelectedPhrase", "cancelViewPhrase", "confirmSavePhrase",
536  "cancelSavePhrase",
537  "confirmDeleteCategory", "cancelDeleteCategory"
538  ),
539  $guiclass
540  );
541  }
542  break;
543  }
544 
545  if ($this->object->getId() > 0)
546  {
547  $title = $this->lng->txt("edit") . " &quot;" . $this->object->getTitle() . "&quot";
548  }
549  else
550  {
551  $title = $this->lng->txt("create_new") . " " . $this->lng->txt($this->getQuestionType());
552  }
553 
554  $this->tpl->setVariable("HEADER", $title);
555  }
556 
565  function getQuestionType()
566  {
567  return $this->object->getQuestionType();
568  }
569 
578  function getCumulatedResultRow($counter, $css_class, $survey_id)
579  {
580  // overwrite in parent classes
581  return "";
582  }
583 
584  function editQuestion()
585  {
586  $this->outErrorMessages();
587  }
588 }
589 ?>