ILIAS  release_4-3 Revision
 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  $this->ctrl->saveParameter($this, "rtrn");
157 
158  ilUtil::sendQuestion($this->lng->txt("confirm_sync_questions"));
159  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_sync_original.html", "Modules/SurveyQuestionPool");
160  $this->tpl->setCurrentBlock("adm_content");
161  $this->tpl->setVariable("BUTTON_YES", $this->lng->txt("yes"));
162  $this->tpl->setVariable("BUTTON_NO", $this->lng->txt("no"));
163  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
164  $this->tpl->parseCurrentBlock();
165  }
166 
167  function sync()
168  {
169  $original_id = $this->object->original_id;
170  if ($original_id)
171  {
172  $this->object->syncWithOriginal();
173  }
174 
175  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
176  $this->redirectAfterSaving($_REQUEST["rtrn"]);
177  }
178 
179  function cancelSync()
180  {
181  ilUtil::sendInfo($this->lng->txt("question_changed_in_survey_only"), true);
182  $this->redirectAfterSaving($_REQUEST["rtrn"]);
183  }
184 
190  function redirectAfterSaving($a_return = false)
191  {
192  // return?
193  if($a_return)
194  {
195  // to calling survey
196  if($_GET["calling_survey"] || $_GET["new_for_survey"])
197  {
198  $addurl = "";
199  if ($_REQUEST["pgov"])
200  {
201  $addurl .= "&pgov=".$_REQUEST["pgov"];
202  $addurl .= "&pgov_pos=".$_REQUEST["pgov_pos"];
203  }
204 
205  // edit
206  if($_GET["calling_survey"])
207  {
208  $_GET["ref_id"] = $_GET["calling_survey"];
209  }
210  // create
211  else if($_GET["new_for_survey"])
212  {
213  $_GET["ref_id"] = $_GET["new_for_survey"];
214  $addurl .= "&new_id=".$this->object->getId();
215  }
216 
217  // we cannot use ilctrl here as pool has no "knowledge" of calling survey
218  include_once "./Services/Utilities/classes/class.ilUtil.php";
219  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&ref_id=" . $_GET["ref_id"] . "&cmd=questions".$addurl);
220  }
221  // to pool
222  else
223  {
224  $this->ctrl->setParameterByClass("ilObjSurveyQuestionPoolGUI", "q_id_table_nav", $_SESSION['q_id_table_nav']);
225  $this->ctrl->redirectByClass("ilObjSurveyQuestionPoolGUI", "questions");
226  }
227  }
228  // stay in form
229  else
230  {
231 
232  $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
233  $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
234  $this->ctrl->setParameterByClass($_GET["cmdClass"], "new_for_survey", $_GET["new_for_survey"]);
235  $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
236  }
237  }
238 
239  protected function addCommandButtons($a_form)
240  {
241  $a_form->addCommandButton("saveReturn", $this->lng->txt("save_return"));
242  $a_form->addCommandButton("save", $this->lng->txt("save"));
243 
244  // pool question?
245  if(ilObject::_lookupType($this->object->getObjId()) == "spl")
246  {
247  if($this->object->hasCopies())
248  {
249  $a_form->addCommandButton("saveSync", $this->lng->txt("svy_save_sync"));
250  }
251  }
252  }
253 
257  function saveSync()
258  {
259  $this->save($_REQUEST["rtrn"], true);
260  }
261 
265  function saveReturn()
266  {
267  $this->save(true);
268  }
269 
273  function save($a_return = false, $a_sync = false)
274  {
275  global $ilUser;
276 
277  $old_id = $_GET["q_id"];
278  $result = $this->writePostData();
279  if ($result == 0)
280  {
281  $ilUser->setPref("svy_lastquestiontype", $this->object->getQuestionType());
282  $ilUser->writePref("svy_lastquestiontype", $this->object->getQuestionType());
283  $this->object->saveToDb();
284  $originalexists = $this->object->_questionExists($this->object->original_id);
285  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
286  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
287 
288  // pool question?
289  if($a_sync)
290  {
291  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
292  $this->ctrl->redirect($this, 'copySyncForm');
293  }
294  else
295  {
296  // form: update original pool question, too?
297  if ($_GET["calling_survey"] && $originalexists &&
298  SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
299  {
300  if($a_return)
301  {
302  $this->ctrl->setParameter($this, 'rtrn', 1);
303  }
304  $this->ctrl->redirect($this, 'originalSyncForm');
305  }
306  }
307 
308  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
309  $this->redirectAfterSaving($a_return);
310  }
311  }
312 
313  function cancel()
314  {
315  if ($_GET["calling_survey"])
316  {
317  $_GET["ref_id"] = $_GET["calling_survey"];
318  include_once "./Services/Utilities/classes/class.ilUtil.php";
319  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&cmd=questions&ref_id=".$_GET["calling_survey"]);
320  }
321  elseif ($_GET["new_for_survey"])
322  {
323  $_GET["ref_id"] = $_GET["new_for_survey"];
324  include_once "./Services/Utilities/classes/class.ilUtil.php";
325  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&cmd=questions&ref_id=".$_GET["new_for_survey"]);
326  }
327  else
328  {
329  $this->ctrl->redirectByClass("ilobjsurveyquestionpoolgui", "questions");
330  }
331  }
332 
339  {
340  $this->ctrl->redirect($this, "editQuestion");
341  }
342 
346  protected function getMaterialOutput()
347  {
348  if (count($this->object->getMaterial()))
349  {
350  $template = new ilTemplate("tpl.il_svy_qpl_material.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
351  foreach ($this->object->getMaterial() as $material)
352  {
353  $template->setCurrentBlock('material');
354  switch ($material->type)
355  {
356  case 0:
357  $href = SurveyQuestion::_getInternalLinkHref($material->internal_link);
358  $template->setVariable('MATERIAL_TYPE', 'internallink');
359  $template->setVariable('MATERIAL_HREF', $href);
360  break;
361  }
362  $template->setVariable('MATERIAL_TITLE', (strlen($material->title)) ? ilUtil::prepareFormOutput($material->title) : $this->lng->txt('material'));
363  $template->setVariable('TEXT_AVAILABLE_MATERIALS', $this->lng->txt('material'));
364  $template->parseCurrentBlock();
365  }
366  return $template->get();
367  }
368  return "";
369  }
370 
371 
375  public function material($checkonly = FALSE)
376  {
377  global $rbacsystem;
378 
379  $add_html = '';
380  if ($rbacsystem->checkAccess('write', $_GET['ref_id']))
381  {
382  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
383  $form = new ilPropertyFormGUI();
384  $form->setFormAction($this->ctrl->getFormAction($this));
385  $form->setTitle($this->lng->txt('add_material'));
386  $form->setMultipart(FALSE);
387  $form->setTableWidth("100%");
388  $form->setId("material");
389 
390  // material
391  $material = new ilRadioGroupInputGUI($this->lng->txt("material"), "internalLinkType");
392  $material->setRequired(true);
393  $material->addOption(new ilRadioOption($this->lng->txt('obj_lm'), "lm"));
394  $material->addOption(new ilRadioOption($this->lng->txt('obj_st'), "st"));
395  $material->addOption(new ilRadioOption($this->lng->txt('obj_pg'), "pg"));
396  $material->addOption(new ilRadioOption($this->lng->txt('glossary_term'), "glo"));
397  $form->addItem($material);
398 
399  $form->addCommandButton("addMaterial", $this->lng->txt("add"));
400 
401  $errors = false;
402 
403  if ($checkonly)
404  {
405  $form->setValuesByPost();
406  $errors = !$form->checkInput();
407  if ($errors) $checkonly = false;
408  }
409  $add_html = $form->getHTML();
410  }
411 
412 
413  $mat_html = "";
414  if (count($this->object->getMaterial()))
415  {
416  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyMaterialsTableGUI.php";
417  $table_gui = new ilSurveyMaterialsTableGUI($this, 'material', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
418  $data = array();
419  foreach ($this->object->getMaterial() as $material)
420  {
421  switch ($material->type)
422  {
423  case 0:
424  $href = SurveyQuestion::_getInternalLinkHref($material->internal_link);
425  $type = $this->lng->txt('internal_link');
426  break;
427  }
428  $title = (strlen($material->title)) ? ilUtil::prepareFormOutput($material->title) : $this->lng->txt('material');
429  array_push($data, array('href' => $href, 'title' => $title, 'type' => $type));
430  }
431  $table_gui->setData($data);
432  $mat_html = $table_gui->getHTML();
433  }
434 
435  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $add_html . $mat_html);
436  return $errors;
437  }
438 
439  public function deleteMaterial()
440  {
441  if (is_array($_POST['idx']))
442  {
443  $this->object->deleteMaterials($_POST['idx']);
444  ilUtil::sendSuccess($this->lng->txt('materials_deleted'), true);
445  }
446  else
447  {
448  ilUtil::sendFailure($this->lng->txt('no_checkbox'), true);
449  }
450  $this->ctrl->redirect($this, 'material');
451  }
452 
456  public function addMaterial()
457  {
458  global $tree;
459 
460  if (strlen($_SESSION["link_new_type"]) || !$this->material(true))
461  {
462  include_once("./Modules/SurveyQuestionPool/classes/class.ilMaterialExplorer.php");
463  switch ($_POST["internalLinkType"])
464  {
465  case "lm":
466  $_SESSION["link_new_type"] = "lm";
467  $_SESSION["search_link_type"] = "lm";
468  break;
469  case "glo":
470  $_SESSION["link_new_type"] = "glo";
471  $_SESSION["search_link_type"] = "glo";
472  break;
473  case "st":
474  $_SESSION["link_new_type"] = "lm";
475  $_SESSION["search_link_type"] = "st";
476  break;
477  case "pg":
478  $_SESSION["link_new_type"] = "lm";
479  $_SESSION["search_link_type"] = "pg";
480  break;
481  }
482 
483  ilUtil::sendInfo($this->lng->txt("select_object_to_link"));
484 
485  $exp = new ilMaterialExplorer($this->ctrl->getLinkTarget($this, 'addMaterial'), get_class($this));
486 
487  // expand current path (if no specific node given)
488  if(!$_GET["expand"])
489  {
490  $path = $tree->getPathId($_GET["ref_id"]);
491  $exp->setForceOpenPath($path);
492  }
493  else
494  {
495  $exp->setExpand($_GET["expand"]);
496  }
497  $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'addMaterial'));
498  $exp->setTargetGet("ref_id");
499  $exp->setRefId($_GET["ref_id"]);
500  $exp->addFilter($_SESSION["link_new_type"]);
501  $exp->setSelectableType($_SESSION["link_new_type"]);
502 
503  // build html-output
504  $exp->setOutput(0);
505 
506  $this->tpl->addBlockFile("ADM_CONTENT", "explorer", "tpl.il_svy_qpl_explorer.html", "Modules/SurveyQuestionPool");
507  $this->tpl->setVariable("EXPLORER_TREE",$exp->getOutput());
508  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
509  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
510  }
511  }
512 
513  function removeMaterial()
514  {
515  $this->object->material = array();
516  $this->object->saveToDb();
517  $this->editQuestion();
518  }
519 
520  function cancelExplorer()
521  {
522  unset($_SESSION["link_new_type"]);
523  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
524  $this->ctrl->redirect($this, 'material');
525  }
526 
527  function addPG()
528  {
529  $this->object->addInternalLink("il__pg_" . $_GET["pg"]);
530  unset($_SESSION["link_new_type"]);
531  unset($_SESSION["search_link_type"]);
532  ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
533  $this->ctrl->redirect($this, "material");
534  }
535 
536  function addST()
537  {
538  $this->object->addInternalLink("il__st_" . $_GET["st"]);
539  unset($_SESSION["link_new_type"]);
540  unset($_SESSION["search_link_type"]);
541  ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
542  $this->ctrl->redirect($this, "material");
543  }
544 
545  function addGIT()
546  {
547  $this->object->addInternalLink("il__git_" . $_GET["git"]);
548  unset($_SESSION["link_new_type"]);
549  unset($_SESSION["search_link_type"]);
550  ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
551  $this->ctrl->redirect($this, "material");
552  }
553 
554  function linkChilds()
555  {
556  switch ($_SESSION["search_link_type"])
557  {
558  case "pg":
559  include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
560  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
561  $cont_obj_gui =& new ilObjContentObjectGUI("", $_GET["source_id"], true);
562  $cont_obj = $cont_obj_gui->object;
563  $pages = ilLMPageObject::getPageList($cont_obj->getId());
564  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
565  $color_class = array("tblrow1", "tblrow2");
566  $counter = 0;
567  $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", "Modules/SurveyQuestionPool");
568  foreach($pages as $page)
569  {
570  if($page["type"] == $_SESSION["search_link_type"])
571  {
572  $this->tpl->setCurrentBlock("linktable_row");
573  $this->tpl->setVariable("TEXT_LINK", $page["title"]);
574  $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
575  $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($page["type"])) . "&" . $page["type"] . "=" . $page["obj_id"]);
576  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
577  $this->tpl->parseCurrentBlock();
578  $counter++;
579  }
580  }
581  $this->tpl->setCurrentBlock("link_selection");
582  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
583  $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_SESSION["search_link_type"]));
584  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
585  $this->tpl->parseCurrentBlock();
586  break;
587  case "st":
588  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
589  $color_class = array("tblrow1", "tblrow2");
590  $counter = 0;
591  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
592  $cont_obj_gui =& new ilObjContentObjectGUI("", $_GET["source_id"], true);
593  $cont_obj = $cont_obj_gui->object;
594  // get all chapters
595  $ctree =& $cont_obj->getLMTree();
596  $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
597  $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", "Modules/SurveyQuestionPool");
598  foreach($nodes as $node)
599  {
600  if($node["type"] == $_SESSION["search_link_type"])
601  {
602  $this->tpl->setCurrentBlock("linktable_row");
603  $this->tpl->setVariable("TEXT_LINK", $node["title"]);
604  $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
605  $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($node["type"])) . "&" . $node["type"] . "=" . $node["obj_id"]);
606  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
607  $this->tpl->parseCurrentBlock();
608  $counter++;
609  }
610  }
611  $this->tpl->setCurrentBlock("link_selection");
612  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
613  $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_SESSION["search_link_type"]));
614  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
615  $this->tpl->parseCurrentBlock();
616  break;
617  case "glo":
618  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
619  $color_class = array("tblrow1", "tblrow2");
620  $counter = 0;
621  $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", "Modules/SurveyQuestionPool");
622  include_once "./Modules/Glossary/classes/class.ilObjGlossary.php";
623  $glossary =& new ilObjGlossary($_GET["source_id"], true);
624  // get all glossary items
625  $terms = $glossary->getTermList();
626  foreach($terms as $term)
627  {
628  $this->tpl->setCurrentBlock("linktable_row");
629  $this->tpl->setVariable("TEXT_LINK", $term["term"]);
630  $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
631  $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "addGIT") . "&git=" . $term["id"]);
632  $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
633  $this->tpl->parseCurrentBlock();
634  $counter++;
635  }
636  $this->tpl->setCurrentBlock("link_selection");
637  $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
638  $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("glossary_term"));
639  $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
640  $this->tpl->parseCurrentBlock();
641  break;
642  case "lm":
643  $this->object->addInternalLink("il__lm_" . $_GET["source_id"]);
644  unset($_SESSION["link_new_type"]);
645  unset($_SESSION["search_link_type"]);
646  ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
647  $this->ctrl->redirect($this, "material");
648  break;
649  }
650  }
651 
657  function getPrintView($question_title = 1, $show_questiontext = 1)
658  {
659  return "";
660  }
661 
662  function setQuestionTabsForClass($guiclass)
663  {
664  global $rbacsystem,$ilTabs;
665  $this->ctrl->setParameterByClass("$guiclass", "sel_question_types", $this->getQuestionType());
666  $this->ctrl->setParameterByClass("$guiclass", "q_id", $_GET["q_id"]);
667 
668  if (($_GET["calling_survey"] > 0) || ($_GET["new_for_survey"] > 0))
669  {
670  $ref_id = $_GET["calling_survey"];
671  if (!strlen($ref_id)) $ref_id = $_GET["new_for_survey"];
672  $addurl = "";
673  if (strlen($_GET["new_for_survey"]))
674  {
675  $addurl = "&new_id=" . $_GET["q_id"];
676  }
677  if ($_REQUEST["pgov"])
678  {
679  $addurl .= "&pgov=".$_REQUEST["pgov"];
680  $addurl .= "&pgov_pos=".$_REQUEST["pgov_pos"];
681  }
682  $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), "ilias.php?baseClass=ilObjSurveyGUI&ref_id=$ref_id&cmd=questions" . $addurl);
683  }
684  else
685  {
686  $this->ctrl->setParameterByClass("ilObjSurveyQuestionPoolGUI", "q_id_table_nav", $_SESSION['q_id_table_nav']);
687  $ilTabs->setBackTarget($this->lng->txt("spl"), $this->ctrl->getLinkTargetByClass("ilObjSurveyQuestionPoolGUI", "questions"));
688  }
689  if ($_GET["q_id"])
690  {
691  $ilTabs->addTarget("preview",
692  $this->ctrl->getLinkTargetByClass("$guiclass", "preview"), "preview",
693  "$guiclass");
694  }
695  if ($rbacsystem->checkAccess('edit', $_GET["ref_id"])) {
696  $ilTabs->addTarget("edit_properties",
697  $this->ctrl->getLinkTargetByClass("$guiclass", "editQuestion"),
698  array("editQuestion", "save", "cancel", "originalSyncForm"),
699  "$guiclass");
700  }
701  if ($_GET["q_id"])
702  {
703  $ilTabs->addTarget("material",
704  $this->ctrl->getLinkTargetByClass("$guiclass", "material"),
705  array("material", "cancelExplorer", "linkChilds", "addGIT", "addST",
706  "addPG", "addMaterial", "removeMaterial"),
707  "$guiclass");
708  }
709 
710  if ($this->object->getId() > 0)
711  {
712  $title = $this->lng->txt("edit") . " &quot;" . $this->object->getTitle() . "&quot";
713  }
714  else
715  {
716  $title = $this->lng->txt("create_new") . " " . $this->lng->txt($this->getQuestionType());
717  }
718 
719  $this->tpl->setVariable("HEADER", $title);
720  }
721 
728  function getQuestionType()
729  {
730  return $this->object->getQuestionType();
731  }
732 
739  function getCumulatedResultRow($counter, $css_class, $survey_id)
740  {
741  // overwrite in parent classes
742  return "";
743  }
744 
745  function editQuestion()
746  {
747  $this->outErrorMessages();
748  }
749 
750  protected function outQuestionText($template)
751  {
752  $questiontext = $this->object->getQuestiontext();
753  if (preg_match("/^<.[\\>]?>(.*?)<\\/.[\\>]*?>$/", $questiontext, $matches))
754  {
755  $questiontext = $matches[1];
756  }
757  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
758  if ($this->object->getObligatory($survey_id))
759  {
760  $template->setVariable("OBLIGATORY_TEXT", ' *');
761  }
762  }
763 
764  function isSaveCommand(array $a_cmds = array())
765  {
766  $a_cmds[] = "save";
767  $a_cmds[] = "saveReturn";
768  return in_array($this->ctrl->getCmd(), $a_cmds);
769  }
770 
776  function preview()
777  {
778  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", "Modules/SurveyQuestionPool");
779  $question_output = $this->getWorkingForm();
780 
781  if ($this->object->getObligatory())
782  {
783  $this->tpl->setCurrentBlock("required");
784  $this->tpl->setVariable("TEXT_REQUIRED", $this->lng->txt("required_field"));
785  $this->tpl->parseCurrentBlock();
786  }
787 
788  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
789  }
790 
791  protected function renderChart($a_id, $a_variables)
792  {
793  include_once "Services/Chart/classes/class.ilChart.php";
794  $chart = new ilChart($a_id, 700, 400);
795 
796  $legend = new ilChartLegend();
797  $chart->setLegend($legend);
798  $chart->setYAxisToInteger(true);
799 
800  $data = new ilChartData("bars");
801  $data->setLabel($this->lng->txt("users_answered"));
802  $data->setBarOptions(0.5, "center");
803 
804  $max = 5;
805 
806  if(sizeof($a_variables) <= $max)
807  {
808  if($a_variables)
809  {
810  $labels = array();
811  foreach($a_variables as $idx => $points)
812  {
813  $data->addPoint($idx, $points["selected"]);
814  $labels[$idx] = ($idx+1).". ".ilUtil::prepareFormOutput($points["title"]);
815  }
816  $chart->addData($data);
817 
818  $chart->setTicks($labels, false, true);
819  }
820 
821  return "<div style=\"margin:10px\">".$chart->getHTML()."</div>";
822  }
823  else
824  {
825  $chart_legend = array();
826  $labels = array();
827  foreach($a_variables as $idx => $points)
828  {
829  $data->addPoint($idx, $points["selected"]);
830  $labels[$idx] = ($idx+1).".";
831  $chart_legend[($idx+1)] = ilUtil::prepareFormOutput($points["title"]);
832  }
833  $chart->addData($data);
834 
835  $chart->setTicks($labels, false, true);
836 
837  $legend = "<table>";
838  foreach($chart_legend as $number => $caption)
839  {
840  $legend .= "<tr valign=\"top\"><td>".$number.".</td><td>".$caption."</td></tr>";
841  }
842  $legend .= "</table>";
843 
844  return "<div style=\"margin:10px\"><table><tr valign=\"bottom\"><td>".
845  $chart->getHTML()."</td><td class=\"small\" style=\"padding-left:15px\">".
846  $legend."</td></tr></table></div>";
847  }
848  }
849 
850  protected function copySyncForm()
851  {
852  include_once "Modules/SurveyQuestionPool/classes/class.ilSurveySyncTableGUI.php";
853  $tbl = new ilSurveySyncTableGUI($this, "copySyncForm", $this->object);
854 
855  $this->tpl->setContent($tbl->getHTML());
856  }
857 
858  protected function syncCopies()
859  {
860  global $lng, $ilAccess;
861 
862  if(!sizeof($_POST["qid"]))
863  {
864  ilUtil::sendFailure($lng->txt("select_one"));
865  return $this->copySyncForm();
866  }
867 
868  foreach($this->object->getCopyIds(true) as $survey_id => $questions)
869  {
870  // check permissions for "parent" survey
871  $can_write = false;
872  $ref_ids = ilObject::_getAllReferences($survey_id);
873  foreach($ref_ids as $ref_id)
874  {
875  if($ilAccess->checkAccess("edit", "", $ref_id))
876  {
877  $can_write = true;
878  break;
879  }
880  }
881 
882  if($can_write)
883  {
884  foreach($questions as $qid)
885  {
886  if(in_array($qid, $_POST["qid"]))
887  {
888  $id = $this->object->getId();
889 
890  $this->object->setId($qid);
891  $this->object->setOriginalId($id);
892  $this->object->saveToDb();
893 
894  $this->object->setId($id);
895  $this->object->setOriginalId(null);
896 
897  // see: SurveyQuestion::syncWithOriginal()
898  // what about material?
899  }
900  }
901  }
902  }
903 
904  ilUtil::sendSuccess($lng->txt("survey_sync_success"), true);
905  $this->redirectAfterSaving($_REQUEST["rtrn"]);
906  }
907 }
908 
909 ?>