ILIAS  Release_4_0_x_branch Revision 61816
 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 
54 
66  function SurveyQuestionGUI()
67  {
68  global $lng, $tpl, $ilCtrl;
69 
70  $this->lng =& $lng;
71  $this->tpl =& $tpl;
72  $this->ctrl =& $ilCtrl;
73  $this->ctrl->saveParameter($this, "q_id");
74  $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
75  $this->cumulated = array();
76  $this->errormessages = array();
77  }
78 
79  function addErrorMessage($errormessage)
80  {
81  if (strlen($errormessage)) array_push($this->errormessages, $errormessage);
82  }
83 
84  function outErrorMessages()
85  {
86  if (count($this->errormessages))
87  {
88  $out = implode("<br />", $this->errormessages);
90  }
91  }
92 
96  function &executeCommand()
97  {
98  $cmd = $this->ctrl->getCmd();
99  $next_class = $this->ctrl->getNextClass($this);
100 
101  $cmd = $this->getCommand($cmd);
102  switch($next_class)
103  {
104  default:
105  $ret =& $this->$cmd();
106  break;
107  }
108  return $ret;
109  }
110 
111  function getCommand($cmd)
112  {
113  return $cmd;
114  }
115 
127  static function &_getQuestionGUI($questiontype, $question_id = -1)
128  {
129  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
130  if ((!$questiontype) and ($question_id > 0))
131  {
132  $questiontype = SurveyQuestion::_getQuestiontype($question_id);
133  }
134  SurveyQuestion::_includeClass($questiontype, 1);
135  $question_type_gui = $questiontype . "GUI";
136  $question = new $question_type_gui($question_id);
137  return $question;
138  }
139 
140  function _getGUIClassNameForId($a_q_id)
141  {
142  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
143  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
144  $q_type = SurveyQuestion::_getQuestiontype($a_q_id);
145  $class_name = SurveyQuestionGUI::_getClassNameForQType($q_type);
146  return $class_name;
147  }
148 
149  function _getClassNameForQType($q_type)
150  {
151  return $q_type;
152  }
153 
154  function originalSyncForm()
155  {
156  ilUtil::sendQuestion($this->lng->txt("confirm_sync_questions"));
157  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_sync_original.html", "Modules/SurveyQuestionPool");
158  $this->tpl->setCurrentBlock("adm_content");
159  $this->tpl->setVariable("BUTTON_YES", $this->lng->txt("yes"));
160  $this->tpl->setVariable("BUTTON_NO", $this->lng->txt("no"));
161  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
162  $this->tpl->parseCurrentBlock();
163  }
164 
165  function sync()
166  {
167  $original_id = $this->object->original_id;
168  if ($original_id)
169  {
170  $this->object->syncWithOriginal();
171  }
172  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
173  $this->ctrl->redirect($this, "editQuestion");
174  }
175 
176  function cancelSync()
177  {
178  ilUtil::sendInfo($this->lng->txt("question_changed_in_survey_only"), true);
179  $this->ctrl->redirect($this, "editQuestion");
180  }
181 
185  function save()
186  {
187  global $ilUser;
188 
189  $old_id = $_GET["q_id"];
190  $result = $this->writePostData();
191  if ($result == 0)
192  {
193  $ilUser->setPref("svy_lastquestiontype", $this->object->getQuestionType());
194  $ilUser->writePref("svy_lastquestiontype", $this->object->getQuestionType());
195  $this->object->saveToDb();
196  $originalexists = $this->object->_questionExists($this->object->original_id);
197  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
198  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
199  if ($_GET["calling_survey"] && $originalexists && SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
200  {
201  $this->ctrl->redirect($this, 'originalSyncForm');
202  }
203  elseif ($_GET["calling_survey"])
204  {
205  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
206  $_GET["ref_id"] = $_GET["calling_survey"];
207  include_once "./Services/Utilities/classes/class.ilUtil.php";
208  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&ref_id=" . $_GET["calling_survey"] . "&cmd=questions");
209  return;
210  }
211  elseif ($_GET["new_for_survey"] > 0)
212  {
213  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
214  $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
215  $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
216  $this->ctrl->setParameterByClass($_GET["cmdClass"], "new_for_survey", $_GET["new_for_survey"]);
217  $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
218  return;
219  }
220  else
221  {
222  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
223  $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
224  $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
225  $this->ctrl->setParameterByClass($_GET["cmdClass"], "new_for_survey", $_GET["new_for_survey"]);
226  $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
227  }
228  }
229  }
230 
231  function cancel()
232  {
233  if ($_GET["calling_survey"])
234  {
235  $_GET["ref_id"] = $_GET["calling_survey"];
236  include_once "./Services/Utilities/classes/class.ilUtil.php";
237  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&cmd=questions&ref_id=".$_GET["calling_survey"]);
238  }
239  elseif ($_GET["new_for_survey"])
240  {
241  $_GET["ref_id"] = $_GET["new_for_survey"];
242  include_once "./Services/Utilities/classes/class.ilUtil.php";
243  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&cmd=questions&ref_id=".$_GET["new_for_survey"]);
244  }
245  else
246  {
247  $this->ctrl->redirectByClass("ilobjsurveyquestionpoolgui", "questions");
248  }
249  }
250 
257  {
258  $this->ctrl->redirect($this, "editQuestion");
259  }
260 
264  protected function getMaterialOutput()
265  {
266  if (count($this->object->getMaterial()))
267  {
268  $template = new ilTemplate("tpl.il_svy_qpl_material.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
269  foreach ($this->object->getMaterial() as $material)
270  {
271  $template->setCurrentBlock('material');
272  switch ($material->type)
273  {
274  case 0:
275  $href = SurveyQuestion::_getInternalLinkHref($material->internal_link);
276  $template->setVariable('MATERIAL_TYPE', 'internallink');
277  $template->setVariable('MATERIAL_HREF', $href);
278  break;
279  }
280  $template->setVariable('MATERIAL_TITLE', (strlen($material->title)) ? ilUtil::prepareFormOutput($material->title) : $this->lng->txt('material'));
281  $template->setVariable('TEXT_AVAILABLE_MATERIALS', $this->lng->txt('material'));
282  $template->parseCurrentBlock();
283  }
284  return $template->get();
285  }
286  return "";
287  }
288 
289 
293  public function material($checkonly = FALSE)
294  {
295  global $rbacsystem;
296 
297  $add_html = '';
298  if ($rbacsystem->checkAccess('write', $_GET['ref_id']))
299  {
300  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
301  $form = new ilPropertyFormGUI();
302  $form->setFormAction($this->ctrl->getFormAction($this));
303  $form->setTitle($this->lng->txt('add_material'));
304  $form->setMultipart(FALSE);
305  $form->setTableWidth("100%");
306  $form->setId("material");
307 
308  // material
309  $material = new ilRadioGroupInputGUI($this->lng->txt("material"), "internalLinkType");
310  $material->setRequired(true);
311  $material->addOption(new ilRadioOption($this->lng->txt('obj_lm'), "lm"));
312  $material->addOption(new ilRadioOption($this->lng->txt('obj_st'), "st"));
313  $material->addOption(new ilRadioOption($this->lng->txt('obj_pg'), "pg"));
314  $material->addOption(new ilRadioOption($this->lng->txt('glossary_term'), "glo"));
315  $form->addItem($material);
316 
317  $form->addCommandButton("addMaterial", $this->lng->txt("add"));
318 
319  $errors = false;
320 
321  if ($checkonly)
322  {
323  $form->setValuesByPost();
324  $errors = !$form->checkInput();
325  if ($errors) $checkonly = false;
326  }
327  $add_html = $form->getHTML();
328  }
329 
330 
331  $mat_html = "";
332  if (count($this->object->getMaterial()))
333  {
334  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyMaterialsTableGUI.php";
335  $table_gui = new ilSurveyMaterialsTableGUI($this, 'material', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
336  $data = array();
337  foreach ($this->object->getMaterial() as $material)
338  {
339  switch ($material->type)
340  {
341  case 0:
342  $href = SurveyQuestion::_getInternalLinkHref($material->internal_link);
343  $type = $this->lng->txt('internal_link');
344  break;
345  }
346  $title = (strlen($material->title)) ? ilUtil::prepareFormOutput($material->title) : $this->lng->txt('material');
347  array_push($data, array('href' => $href, 'title' => $title, 'type' => $type));
348  }
349  $table_gui->setData($data);
350  $mat_html = $table_gui->getHTML();
351  }
352 
353  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $add_html . $mat_html);
354  return $errors;
355  }
356 
357  public function deleteMaterial()
358  {
359  if (is_array($_POST['idx']))
360  {
361  $this->object->deleteMaterials($_POST['idx']);
362  ilUtil::sendSuccess($this->lng->txt('materials_deleted'), true);
363  }
364  else
365  {
366  ilUtil::sendFailure($this->lng->txt('no_checkbox'), true);
367  }
368  $this->ctrl->redirect($this, 'material');
369  }
370 
374  public function addMaterial()
375  {
376  global $tree;
377 
378  if (strlen($_SESSION["link_new_type"]) || !$this->material(true))
379  {
380  include_once("./Modules/SurveyQuestionPool/classes/class.ilMaterialExplorer.php");
381  switch ($_POST["internalLinkType"])
382  {
383  case "lm":
384  $_SESSION["link_new_type"] = "lm";
385  $_SESSION["search_link_type"] = "lm";
386  break;
387  case "glo":
388  $_SESSION["link_new_type"] = "glo";
389  $_SESSION["search_link_type"] = "glo";
390  break;
391  case "st":
392  $_SESSION["link_new_type"] = "lm";
393  $_SESSION["search_link_type"] = "st";
394  break;
395  case "pg":
396  $_SESSION["link_new_type"] = "lm";
397  $_SESSION["search_link_type"] = "pg";
398  break;
399  }
400 
401  ilUtil::sendInfo($this->lng->txt("select_object_to_link"));
402 
403  $exp = new ilMaterialExplorer($this->ctrl->getLinkTarget($this, 'addMaterial'), get_class($this));
404 
405  $exp->setExpand($_GET["expand"] ? $_GET["expand"] : $tree->getParentId($_GET["ref_id"]));
406  $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'addMaterial'));
407  $exp->setTargetGet("ref_id");
408  $exp->setRefId($_GET["ref_id"]);
409  $exp->addFilter($_SESSION["link_new_type"]);
410  $exp->setSelectableType($_SESSION["link_new_type"]);
411 
412  // build html-output
413  $exp->setOutput(0);
414 
415  $this->tpl->addBlockFile("ADM_CONTENT", "explorer", "tpl.il_svy_qpl_explorer.html", "Modules/SurveyQuestionPool");
416  $this->tpl->setVariable("EXPLORER_TREE",$exp->getOutput());
417  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
418  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
419  }
420  }
421 
422  function removeMaterial()
423  {
424  $this->object->material = array();
425  $this->object->saveToDb();
426  $this->editQuestion();
427  }
428 
429  function cancelExplorer()
430  {
431  unset($_SESSION["link_new_type"]);
432  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
433  $this->ctrl->redirect($this, 'material');
434  }
435 
436  function addPG()
437  {
438  $this->object->addInternalLink("il__pg_" . $_GET["pg"]);
439  unset($_SESSION["link_new_type"]);
440  unset($_SESSION["search_link_type"]);
441  ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
442  $this->ctrl->redirect($this, "material");
443  }
444 
445  function addST()
446  {
447  $this->object->addInternalLink("il__st_" . $_GET["st"]);
448  unset($_SESSION["link_new_type"]);
449  unset($_SESSION["search_link_type"]);
450  ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
451  $this->ctrl->redirect($this, "material");
452  }
453 
454  function addGIT()
455  {
456  $this->object->addInternalLink("il__git_" . $_GET["git"]);
457  unset($_SESSION["link_new_type"]);
458  unset($_SESSION["search_link_type"]);
459  ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
460  $this->ctrl->redirect($this, "material");
461  }
462 
463  function linkChilds()
464  {
465  switch ($_SESSION["search_link_type"])
466  {
467  case "pg":
468  include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
469  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
470  $cont_obj_gui =& new ilObjContentObjectGUI("", $_GET["source_id"], true);
471  $cont_obj = $cont_obj_gui->object;
472  $pages = ilLMPageObject::getPageList($cont_obj->getId());
473  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
474  $color_class = array("tblrow1", "tblrow2");
475  $counter = 0;
476  $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", "Modules/SurveyQuestionPool");
477  foreach($pages as $page)
478  {
479  if($page["type"] == $_SESSION["search_link_type"])
480  {
481  $this->tpl->setCurrentBlock("linktable_row");
482  $this->tpl->setVariable("TEXT_LINK", $page["title"]);
483  $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
484  $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($page["type"])) . "&" . $page["type"] . "=" . $page["obj_id"]);
485  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
486  $this->tpl->parseCurrentBlock();
487  $counter++;
488  }
489  }
490  $this->tpl->setCurrentBlock("link_selection");
491  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
492  $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_SESSION["search_link_type"]));
493  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
494  $this->tpl->parseCurrentBlock();
495  break;
496  case "st":
497  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
498  $color_class = array("tblrow1", "tblrow2");
499  $counter = 0;
500  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
501  $cont_obj_gui =& new ilObjContentObjectGUI("", $_GET["source_id"], true);
502  $cont_obj = $cont_obj_gui->object;
503  // get all chapters
504  $ctree =& $cont_obj->getLMTree();
505  $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
506  $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", "Modules/SurveyQuestionPool");
507  foreach($nodes as $node)
508  {
509  if($node["type"] == $_SESSION["search_link_type"])
510  {
511  $this->tpl->setCurrentBlock("linktable_row");
512  $this->tpl->setVariable("TEXT_LINK", $node["title"]);
513  $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
514  $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($node["type"])) . "&" . $node["type"] . "=" . $node["obj_id"]);
515  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
516  $this->tpl->parseCurrentBlock();
517  $counter++;
518  }
519  }
520  $this->tpl->setCurrentBlock("link_selection");
521  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
522  $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_SESSION["search_link_type"]));
523  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
524  $this->tpl->parseCurrentBlock();
525  break;
526  case "glo":
527  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
528  $color_class = array("tblrow1", "tblrow2");
529  $counter = 0;
530  $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", "Modules/SurveyQuestionPool");
531  include_once "./Modules/Glossary/classes/class.ilObjGlossary.php";
532  $glossary =& new ilObjGlossary($_GET["source_id"], true);
533  // get all glossary items
534  $terms = $glossary->getTermList();
535  foreach($terms as $term)
536  {
537  $this->tpl->setCurrentBlock("linktable_row");
538  $this->tpl->setVariable("TEXT_LINK", $term["term"]);
539  $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
540  $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "addGIT") . "&git=" . $term["id"]);
541  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
542  $this->tpl->parseCurrentBlock();
543  $counter++;
544  }
545  $this->tpl->setCurrentBlock("link_selection");
546  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
547  $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("glossary_term"));
548  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
549  $this->tpl->parseCurrentBlock();
550  break;
551  case "lm":
552  $this->object->addInternalLink("il__lm_" . $_GET["source_id"]);
553  unset($_SESSION["link_new_type"]);
554  unset($_SESSION["search_link_type"]);
555  ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
556  $this->ctrl->redirect($this, "material");
557  break;
558  }
559  }
560 
566  function getPrintView($question_title = 1, $show_questiontext = 1)
567  {
568  return "";
569  }
570 
571  function setQuestionTabsForClass($guiclass)
572  {
573  global $rbacsystem,$ilTabs;
574  $this->ctrl->setParameterByClass("$guiclass", "sel_question_types", $this->getQuestionType());
575  $this->ctrl->setParameterByClass("$guiclass", "q_id", $_GET["q_id"]);
576 
577  if (($_GET["calling_survey"] > 0) || ($_GET["new_for_survey"] > 0))
578  {
579  $ref_id = $_GET["calling_survey"];
580  if (!strlen($ref_id)) $ref_id = $_GET["new_for_survey"];
581  $addurl = "";
582  if (strlen($_GET["new_for_survey"]))
583  {
584  $addurl = "&new_id=" . $_GET["q_id"];
585  }
586  $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), "ilias.php?baseClass=ilObjSurveyGUI&ref_id=$ref_id&cmd=questions" . $addurl);
587  }
588  else
589  {
590  $this->ctrl->setParameterByClass("ilObjSurveyQuestionPoolGUI", "q_id_table_nav", $_SESSION['q_id_table_nav']);
591  $ilTabs->setBackTarget($this->lng->txt("spl"), $this->ctrl->getLinkTargetByClass("ilObjSurveyQuestionPoolGUI", "questions"));
592  }
593  if ($_GET["q_id"])
594  {
595  $ilTabs->addTarget("preview",
596  $this->ctrl->getLinkTargetByClass("$guiclass", "preview"), "preview",
597  "$guiclass");
598  }
599  if ($rbacsystem->checkAccess('edit', $_GET["ref_id"])) {
600  $ilTabs->addTarget("edit_properties",
601  $this->ctrl->getLinkTargetByClass("$guiclass", "editQuestion"),
602  array("editQuestion", "save", "cancel", "originalSyncForm"),
603  "$guiclass");
604  }
605  if ($_GET["q_id"])
606  {
607  $ilTabs->addTarget("material",
608  $this->ctrl->getLinkTargetByClass("$guiclass", "material"),
609  array("material", "cancelExplorer", "linkChilds", "addGIT", "addST",
610  "addPG", "addMaterial", "removeMaterial"),
611  "$guiclass");
612  }
613 
614  if ($this->object->getId() > 0)
615  {
616  $title = $this->lng->txt("edit") . " &quot;" . $this->object->getTitle() . "&quot";
617  }
618  else
619  {
620  $title = $this->lng->txt("create_new") . " " . $this->lng->txt($this->getQuestionType());
621  }
622 
623  $this->tpl->setVariable("HEADER", $title);
624  }
625 
632  function getQuestionType()
633  {
634  return $this->object->getQuestionType();
635  }
636 
643  function getCumulatedResultRow($counter, $css_class, $survey_id)
644  {
645  // overwrite in parent classes
646  return "";
647  }
648 
649  function editQuestion()
650  {
651  $this->outErrorMessages();
652  }
653 }
654 ?>