ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveySingleChoiceQuestionGUI.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/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
25 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
26 
39 {
40 
50  $id = -1
51  )
52 
53  {
54  $this->SurveyQuestionGUI();
55  include_once "./Modules/SurveyQuestionPool/classes/class.SurveySingleChoiceQuestion.php";
56  $this->object = new SurveySingleChoiceQuestion();
57  if ($id >= 0)
58  {
59  $this->object->loadFromDb($id);
60  }
61  }
62 
69  function writePostData($always = false)
70  {
71  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
72  if (!$hasErrors)
73  {
74  $this->object->setTitle($_POST["title"]);
75  $this->object->setAuthor($_POST["author"]);
76  $this->object->setDescription($_POST["description"]);
77  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
78  $questiontext = $_POST["question"];
79  $this->object->setQuestiontext($questiontext);
80  $this->object->setObligatory(($_POST["obligatory"]) ? 1 : 0);
81  $this->object->setOrientation($_POST["orientation"]);
82  $this->object->label = $_POST['label'];
83 
84  $this->object->categories->flushCategories();
85 
86  foreach ($_POST['answers']['answer'] as $key => $value)
87  {
88  if (strlen($value)) $this->object->getCategories()->addCategory($value, $_POST['answers']['other'][$key], 0, null, $_POST['answers']['scale'][$key]);
89  }
90  if (strlen($_POST['answers']['neutral']))
91  {
92  $this->object->getCategories()->addCategory($_POST['answers']['neutral'], 0, 1, null, $_POST['answers_neutral_scale']);
93  }
94  return 0;
95  }
96  else
97  {
98  return 1;
99  }
100  }
101 
107  public function editQuestion($checkonly = FALSE)
108  {
109  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
110  $form = new ilPropertyFormGUI();
111  $form->setFormAction($this->ctrl->getFormAction($this));
112  $form->setTitle($this->lng->txt($this->getQuestionType()));
113  $form->setMultipart(FALSE);
114  $form->setTableWidth("100%");
115  $form->setId("singlechoice");
116 
117  // title
118  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
119  $title->setValue($this->object->getTitle());
120  $title->setRequired(TRUE);
121  $form->addItem($title);
122 
123  // label
124  $label = new ilTextInputGUI($this->lng->txt("label"), "label");
125  $label->setValue($this->object->label);
126  $label->setInfo($this->lng->txt("label_info"));
127  $label->setRequired(false);
128  $form->addItem($label);
129 
130  // author
131  $author = new ilTextInputGUI($this->lng->txt("author"), "author");
132  $author->setValue($this->object->getAuthor());
133  $author->setRequired(TRUE);
134  $form->addItem($author);
135 
136  // description
137  $description = new ilTextInputGUI($this->lng->txt("description"), "description");
138  $description->setValue($this->object->getDescription());
139  $description->setRequired(FALSE);
140  $form->addItem($description);
141 
142  // questiontext
143  $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
144  $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestiontext()));
145  $question->setRequired(TRUE);
146  $question->setRows(10);
147  $question->setCols(80);
148  $question->setUseRte(TRUE);
149  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
150  $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
151  $question->addPlugin("latex");
152  $question->addButton("latex");
153  $question->addButton("pastelatex");
154  $question->setRTESupport($this->object->getId(), "spl", "survey", null, false, "3.4.7");
155  $form->addItem($question);
156 
157  // obligatory
158  $shuffle = new ilCheckboxInputGUI($this->lng->txt("obligatory"), "obligatory");
159  $shuffle->setValue(1);
160  $shuffle->setChecked($this->object->getObligatory());
161  $shuffle->setRequired(FALSE);
162  $form->addItem($shuffle);
163 
164  // orientation
165  $orientation = new ilRadioGroupInputGUI($this->lng->txt("orientation"), "orientation");
166  $orientation->setRequired(false);
167  $orientation->setValue($this->object->getOrientation());
168  $orientation->addOption(new ilRadioOption($this->lng->txt('vertical'), 0));
169  $orientation->addOption(new ilRadioOption($this->lng->txt('horizontal'), 1));
170  $orientation->addOption(new ilRadioOption($this->lng->txt('combobox'), 2));
171  $form->addItem($orientation);
172 
173  // Answers
174  include_once "./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
175  $answers = new ilCategoryWizardInputGUI($this->lng->txt("answers"), "answers");
176  $answers->setRequired(false);
177  $answers->setAllowMove(true);
178  $answers->setShowWizard(true);
179  $answers->setShowSavePhrase(true);
180  $answers->setUseOtherAnswer(true);
181  $answers->setShowNeutralCategory(true);
182  $answers->setNeutralCategoryTitle($this->lng->txt('svy_neutral_answer'));
183  if (!$this->object->getCategories()->getCategoryCount())
184  {
185  $this->object->getCategories()->addCategory("");
186  }
187  $answers->setValues($this->object->getCategories());
188  $answers->setDisabledScale(false);
189  $form->addItem($answers);
190 
191  $this->addCommandButtons($form);
192 
193  $errors = false;
194 
195  if ($this->isSaveCommand(array("wizardanswers", "savePhraseanswers")))
196  {
197  $form->setValuesByPost();
198  $errors = !$form->checkInput();
199  $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and we need this if we don't want to have duplication of backslashes
200  if ($errors) $checkonly = false;
201  }
202 
203  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
204  return $errors;
205  }
206 
210  public function addanswers()
211  {
212  $this->writePostData(true);
213  $position = key($_POST['cmd']['addanswers']);
214  $this->object->getCategories()->addCategoryAtPosition("", $position+1);
215  $this->editQuestion();
216  }
217 
221  public function removeanswers()
222  {
223  $this->writePostData(true);
224  $position = key($_POST['cmd']['removeanswers']);
225  $this->object->getCategories()->removeCategory($position);
226  $this->editQuestion();
227  }
228 
232  public function upanswers()
233  {
234  $this->writePostData(true);
235  $position = key($_POST['cmd']['upanswers']);
236  $this->object->getCategories()->moveCategoryUp($position);
237  $this->editQuestion();
238  }
239 
243  public function downanswers()
244  {
245  $this->writePostData(true);
246  $position = key($_POST['cmd']['downanswers']);
247  $this->object->getCategories()->moveCategoryDown($position);
248  $this->editQuestion();
249  }
250 
256  function wizardanswers($save_post_data = true)
257  {
258  if ($save_post_data) $result = $this->writePostData();
259  if ($result == 0 || !$save_post_data)
260  {
261  if ($save_post_data) $this->object->saveToDb();
262  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase.html", "Modules/SurveyQuestionPool");
263 
264  // set the id to return to the selected question
265  $this->tpl->setCurrentBlock("hidden");
266  $this->tpl->setVariable("HIDDEN_NAME", "id");
267  $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
268  $this->tpl->parseCurrentBlock();
269 
270  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyPhrases.php";
272  $colors = array("tblrow1", "tblrow2");
273  $counter = 0;
274  foreach ($phrases as $phrase_id => $phrase_array)
275  {
276  $this->tpl->setCurrentBlock("phraserow");
277  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter++ % 2]);
278  $this->tpl->setVariable("PHRASE_VALUE", $phrase_id);
279  $this->tpl->setVariable("PHRASE_NAME", $phrase_array["title"]);
280  $categories =& ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
281  $this->tpl->setVariable("PHRASE_CONTENT", join($categories, ","));
282  $this->tpl->parseCurrentBlock();
283  }
284 
285  $this->tpl->setCurrentBlock("adm_content");
286  $this->tpl->setVariable("TEXT_CANCEL", $this->lng->txt("cancel"));
287  $this->tpl->setVariable("TEXT_PHRASE", $this->lng->txt("phrase"));
288  $this->tpl->setVariable("TEXT_CONTENT", $this->lng->txt("categories"));
289  $this->tpl->setVariable("TEXT_ADD_PHRASE", $this->lng->txt("add_phrase"));
290  $this->tpl->setVariable("TEXT_INTRODUCTION",$this->lng->txt("add_phrase_introduction"));
291  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
292  $this->tpl->parseCurrentBlock();
293  }
294  }
295 
301  function cancelViewPhrase()
302  {
303  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
304  $this->ctrl->redirect($this, 'editQuestion');
305  }
306 
312  function addSelectedPhrase()
313  {
314  if (strcmp($_POST["phrases"], "") == 0)
315  {
316  ilUtil::sendInfo($this->lng->txt("select_phrase_to_add"));
317  $this->wizardanswers(false);
318  }
319  else
320  {
321  if (strcmp($this->object->getPhrase($_POST["phrases"]), "dp_standard_numbers") != 0)
322  {
323  $this->object->addPhrase($_POST["phrases"]);
324  $this->object->saveToDb();
325  }
326  else
327  {
328  $this->addStandardNumbers();
329  return;
330  }
331  ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
332  $this->ctrl->redirect($this, 'editQuestion');
333  }
334  }
335 
341  function addStandardNumbers()
342  {
343  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase_standard_numbers.html", "Modules/SurveyQuestionPool");
344 
345  // set the id to return to the selected question
346  $this->tpl->setCurrentBlock("hidden");
347  $this->tpl->setVariable("HIDDEN_NAME", "id");
348  $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
349  $this->tpl->parseCurrentBlock();
350 
351  $this->tpl->setCurrentBlock("adm_content");
352  $this->tpl->setVariable("ADD_STANDARD_NUMBERS", $this->lng->txt("add_standard_numbers"));
353  $this->tpl->setVariable("TEXT_ADD_LIMITS", $this->lng->txt("add_limits_for_standard_numbers"));
354  $this->tpl->setVariable("TEXT_LOWER_LIMIT",$this->lng->txt("lower_limit"));
355  $this->tpl->setVariable("TEXT_UPPER_LIMIT",$this->lng->txt("upper_limit"));
356  $this->tpl->setVariable("VALUE_LOWER_LIMIT", $_POST["lower_limit"]);
357  $this->tpl->setVariable("VALUE_UPPER_LIMIT", $_POST["upper_limit"]);
358  $this->tpl->setVariable("BTN_ADD",$this->lng->txt("add_phrase"));
359  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
360  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
361  $this->tpl->parseCurrentBlock();
362  }
363 
370  {
371  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
372  $this->ctrl->redirect($this, "editQuestion");
373  }
374 
381  {
382  if ((strcmp($_POST["lower_limit"], "") == 0) or (strcmp($_POST["upper_limit"], "") == 0))
383  {
384  ilUtil::sendInfo($this->lng->txt("missing_upper_or_lower_limit"));
385  $this->addStandardNumbers();
386  }
387  else if ((int)$_POST["upper_limit"] <= (int)$_POST["lower_limit"])
388  {
389  ilUtil::sendInfo($this->lng->txt("upper_limit_must_be_greater"));
390  $this->addStandardNumbers();
391  }
392  else
393  {
394  $this->object->addStandardNumbers($_POST["lower_limit"], $_POST["upper_limit"]);
395  $this->object->saveToDb();
396  ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
397  $this->ctrl->redirect($this, "editQuestion");
398  }
399  }
400 
406  function savePhraseanswers($haserror = false)
407  {
408  if (!$haserror) $result = $this->writePostData();
409  if ($result == 0 || $haserror)
410  {
411  if (!$haserror) $this->object->saveToDb();
412 
413  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_savephrase.html", "Modules/SurveyQuestionPool");
414  $this->tpl->setCurrentBlock("adm_content");
415  $this->tpl->setVariable("SAVE_PHRASE_INTRODUCTION", $this->lng->txt("save_phrase_introduction"));
416  $this->tpl->setVariable("TEXT_PHRASE_TITLE", $this->lng->txt("enter_phrase_title"));
417  $this->tpl->setVariable("VALUE_PHRASE_TITLE", $_POST["phrase_title"]);
418  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
419  $this->tpl->setVariable("BTN_CONFIRM",$this->lng->txt("confirm"));
420  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
421 
422  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveySavePhraseTableGUI.php";
423  $table_gui = new ilSurveySavePhraseTableGUI($this, 'editQuestion');
424 
425  $data = array();
426  if (!$haserror)
427  {
428  foreach ($_POST['answers']['answer'] as $key => $value)
429  {
430  array_push($data, array('answer' => $value, 'other' => (($_POST['answers']['other'][$key]) ? true : false), 'scale' => $_POST['answers']['scale'][$key], 'neutral' => false));
431  }
432  if (strlen($_POST['answers']['neutral']))
433  {
434  array_push($data, array('answer' => $_POST['answers']['neutral'], 'other' => false, 'scale' => $_POST['answers_neutral_scale'], 'neutral' => true));
435  }
436  }
437  else
438  {
439  $data = $_SESSION['save_phrase_data'];
440  }
441  $table_gui->setData($data);
442  $_SESSION['save_phrase_data'] = $data;
443  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
444  $this->tpl->parseCurrentBlock();
445  }
446  }
447 
453  function cancelSavePhrase()
454  {
455  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
456  $this->ctrl->redirect($this, "editQuestion");
457  }
458 
464  function confirmSavePhrase()
465  {
466  if (!$_POST["phrase_title"])
467  {
468  ilUtil::sendInfo($this->lng->txt("qpl_savephrase_empty"));
469  $this->savePhraseanswers(true);
470  return;
471  }
472 
473  if ($this->object->phraseExists($_POST["phrase_title"]))
474  {
475  ilUtil::sendInfo($this->lng->txt("qpl_savephrase_exists"));
476  $this->savePhraseanswers(true);
477  return;
478  }
479 
480  $this->object->savePhrase($_POST["phrase_title"]);
481  ilUtil::sendSuccess($this->lng->txt("phrase_saved"), true);
482  $this->ctrl->redirect($this, "editQuestion");
483  }
484 
485 
491  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
492  {
493  $template = new ilTemplate("tpl.il_svy_out_sc.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
494  $template->setCurrentBlock("material");
495  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
496  $template->parseCurrentBlock();
497  switch ($this->object->orientation)
498  {
499  case 0:
500  // vertical orientation
501  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
502  {
503  $cat = $this->object->categories->getCategory($i);
504  if ($cat->other)
505  {
506  $template->setCurrentBlock("other_row");
507  if (strlen($cat->title))
508  {
509  $template->setVariable("OTHER_LABEL", $cat->title);
510  }
511  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
512  $template->setVariable("QUESTION_ID", $this->object->getId());
513  if (is_array($working_data))
514  {
515  foreach ($working_data as $value)
516  {
517  if (strlen($value["value"]))
518  {
519  if ($value["value"] == $cat->scale-1)
520  {
521  if (strlen($value['textanswer'])) $template->setVariable("OTHER_VALUE", ' value="' . ilUtil::prepareFormOutput($value['textanswer']) . '"');
522  if (!$value['uncheck'])
523  {
524  $template->setVariable("CHECKED_SC", " checked=\"checked\"");
525  }
526  }
527  }
528  }
529  }
530  $template->parseCurrentBlock();
531  }
532  else
533  {
534  $template->setCurrentBlock("row");
535  if ($cat->neutral) $template->setVariable('ROWCLASS', ' class="neutral"');
536  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
537  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
538  $template->setVariable("QUESTION_ID", $this->object->getId());
539  if (is_array($working_data))
540  {
541  foreach ($working_data as $value)
542  {
543  if (strcmp($value["value"], "") != 0)
544  {
545  if ($value["value"] == $cat->scale-1)
546  {
547  if (!$value['uncheck'])
548  {
549  $template->setVariable("CHECKED_SC", " checked=\"checked\"");
550  }
551  }
552  }
553  }
554  }
555  $template->parseCurrentBlock();
556  }
557  $template->touchBlock('outer_row');
558  }
559  break;
560  case 1:
561  // horizontal orientation
562  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
563  {
564  $cat = $this->object->categories->getCategory($i);
565  $template->setCurrentBlock("radio_col");
566  if ($cat->neutral) $template->setVariable('COLCLASS', ' neutral');
567  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
568  $template->setVariable("QUESTION_ID", $this->object->getId());
569  if (is_array($working_data))
570  {
571  foreach ($working_data as $value)
572  {
573  if (strcmp($value["value"], "") != 0)
574  {
575  if ($value["value"] == $cat->scale-1)
576  {
577  if (!$value['uncheck'])
578  {
579  $template->setVariable("CHECKED_SC", " checked=\"checked\"");
580  }
581  }
582  }
583  }
584  }
585  $template->parseCurrentBlock();
586  }
587  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
588  {
589  $cat = $this->object->categories->getCategory($i);
590  if ($cat->other)
591  {
592  $template->setCurrentBlock("text_other_col");
593  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
594  $template->setVariable("QUESTION_ID", $this->object->getId());
595  if (strlen($cat->title))
596  {
597  $template->setVariable("OTHER_LABEL", $cat->title);
598  }
599  if (is_array($working_data))
600  {
601  foreach ($working_data as $value)
602  {
603  if (strlen($value["value"]))
604  {
605  if ($value["value"] == $cat->scale-1 && strlen($value['textanswer']))
606  {
607  $template->setVariable("OTHER_VALUE", ' value="' . ilUtil::prepareFormOutput($value['textanswer']) . '"');
608  }
609  }
610  }
611  }
612  $template->parseCurrentBlock();
613  }
614  else
615  {
616  $template->setCurrentBlock("text_col");
617  if ($cat->neutral) $template->setVariable('COLCLASS', ' neutral');
618  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
619  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
620  $template->setVariable("QUESTION_ID", $this->object->getId());
621  $template->parseCurrentBlock();
622  }
623  $template->touchBlock('text_outer_col');
624  }
625  break;
626  case 2:
627  // combobox output
628  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
629  {
630  $cat = $this->object->categories->getCategory($i);
631  $template->setCurrentBlock("comborow");
632  $template->setVariable("TEXT_SC", $cat->title);
633  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
634  if (is_array($working_data))
635  {
636  if (strcmp($working_data[0]["value"], "") != 0)
637  {
638  if ($working_data[0]["value"] == $cat->scale-1)
639  {
640  $template->setVariable("SELECTED_SC", " selected=\"selected\"");
641  }
642  }
643  }
644  $template->parseCurrentBlock();
645  }
646  $template->setCurrentBlock("combooutput");
647  $template->setVariable("QUESTION_ID", $this->object->getId());
648  $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
649  $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
650  $template->parseCurrentBlock();
651  break;
652  }
653  if ($question_title)
654  {
655  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
656  }
657  $template->setCurrentBlock("question_data");
658  if (strcmp($error_message, "") != 0)
659  {
660  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
661  }
662  if ($show_questiontext)
663  {
664  $this->outQuestionText($template);
665  }
666  $template->parseCurrentBlock();
667  return $template->get();
668  }
669 
675  function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
676  {
677  $template = new ilTemplate("tpl.il_svy_qpl_sc_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
678  switch ($this->object->orientation)
679  {
680  case 0:
681  // vertical orientation
682  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
683  {
684  $cat = $this->object->categories->getCategory($i);
685  if ($cat->other)
686  {
687  $template->setCurrentBlock("other_row");
688  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
689  $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
690  $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
691  $template->setVariable("OTHER_LABEL", ilUtil::prepareFormOutput($cat->title));
692  $template->setVariable("OTHER_ANSWER", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
693  $template->parseCurrentBlock();
694  }
695  else
696  {
697  $template->setCurrentBlock("row");
698  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
699  $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
700  $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
701  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
702  $template->parseCurrentBlock();
703  }
704  }
705  break;
706  case 1:
707  // horizontal orientation
708  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
709  {
710  $template->setCurrentBlock("radio_col");
711  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.png")));
712  $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
713  $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
714  $template->parseCurrentBlock();
715  }
716  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
717  {
718  $cat = $this->object->categories->getCategory($i);
719  if ($cat->other)
720  {
721  $template->setCurrentBlock("other_text_col");
722  $template->setVariable("OTHER_LABEL", ilUtil::prepareFormOutput($cat->title));
723  $template->setVariable("OTHER_ANSWER", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
724  $template->parseCurrentBlock();
725  }
726  else
727  {
728  $template->setCurrentBlock("text_col");
729  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
730  $template->parseCurrentBlock();
731  }
732  }
733  break;
734  case 2:
735  // combobox output
736  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
737  {
738  $cat = $this->object->categories->getCategory($i);
739  $template->setCurrentBlock("comborow");
740  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
741  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
742  if (is_array($working_data))
743  {
744  if (strcmp($working_data[0]["value"], "") != 0)
745  {
746  if ($working_data[0]["value"] == $i)
747  {
748  $template->setVariable("SELECTED_SC", " selected=\"selected\"");
749  }
750  }
751  }
752  $template->parseCurrentBlock();
753  }
754  $template->setCurrentBlock("combooutput");
755  $template->setVariable("QUESTION_ID", $this->object->getId());
756  $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
757  $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
758  $template->parseCurrentBlock();
759  break;
760  }
761  if ($question_title)
762  {
763  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
764  }
765  if ($show_questiontext)
766  {
767  $this->outQuestionText($template);
768  }
769  $template->parseCurrentBlock();
770  return $template->get();
771  }
772 
773  function setQuestionTabs()
774  {
775  global $rbacsystem,$ilTabs;
776  $this->ctrl->setParameter($this, "sel_question_types", $this->getQuestionType());
777  $this->ctrl->setParameter($this, "q_id", $_GET["q_id"]);
778 
779  if (($_GET["calling_survey"] > 0) || ($_GET["new_for_survey"] > 0))
780  {
781  $ref_id = $_GET["calling_survey"];
782  if (!strlen($ref_id)) $ref_id = $_GET["new_for_survey"];
783  $addurl = "";
784  if (strlen($_GET["new_for_survey"]))
785  {
786  $addurl = "&new_id=" . $_GET["q_id"];
787  }
788  if ($_REQUEST["pgov"])
789  {
790  $addurl .= "&pgov=".$_REQUEST["pgov"];
791  $addurl .= "&pgov_pos=".$_REQUEST["pgov_pos"];
792  }
793  $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), "ilias.php?baseClass=ilObjSurveyGUI&ref_id=$ref_id&cmd=questions" . $addurl);
794  }
795  else
796  {
797  $this->ctrl->setParameterByClass("ilObjSurveyQuestionPoolGUI", "q_id_table_nav", $_SESSION['q_id_table_nav']);
798  $ilTabs->setBackTarget($this->lng->txt("spl"), $this->ctrl->getLinkTargetByClass("ilObjSurveyQuestionPoolGUI", "questions"));
799  }
800  if ($_GET["q_id"])
801  {
802  $ilTabs->addTarget("preview",
803  $this->ctrl->getLinkTarget($this, "preview"),
804  "preview",
805  "",
806  ""
807  );
808  }
809  if ($rbacsystem->checkAccess('edit', $_GET["ref_id"])) {
810  $ilTabs->addTarget("edit_properties",
811  $this->ctrl->getLinkTarget($this, "editQuestion"),
812  array("editQuestion", "save", "cancel", "wizardanswers", "addSelectedPhrase",
813  "insertStandardNumbers", "savePhraseanswers", "confirmSavePhrase"),
814  "",
815  ""
816  );
817  }
818  if ($_GET["q_id"])
819  {
820  $ilTabs->addTarget("material",
821  $this->ctrl->getLinkTarget($this, "material"),
822  array("material", "cancelExplorer", "linkChilds", "addGIT", "addST",
823  "addPG", "addMaterial", "removeMaterial"),
824  "",
825  ""
826  );
827  }
828 
829  if ($this->object->getId() > 0)
830  {
831  $title = $this->lng->txt("edit") . " &quot;" . $this->object->getTitle() . "&quot";
832  }
833  else
834  {
835  $title = $this->lng->txt("create_new") . " " . $this->lng->txt($this->getQuestionType());
836  }
837 
838  $this->tpl->setVariable("HEADER", $title);
839  }
840 
849  function getCumulatedResultsDetails($survey_id, $counter)
850  {
851  if (count($this->cumulated) == 0)
852  {
853  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
854  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
855  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
856  }
857  $output = "";
858  include_once "./Services/UICore/classes/class.ilTemplate.php";
859  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
860 
861  $template->setCurrentBlock("detail_row");
862  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
863  $questiontext = $this->object->getQuestiontext();
864  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
865  $template->parseCurrentBlock();
866  $template->setCurrentBlock("detail_row");
867  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
868  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
869  $template->parseCurrentBlock();
870  $template->setCurrentBlock("detail_row");
871  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
872  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
873  $template->parseCurrentBlock();
874  $template->setCurrentBlock("detail_row");
875  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
876  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
877  $template->parseCurrentBlock();
878  /*
879  $template->setCurrentBlock("detail_row");
880  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
881  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE"]);
882  $template->parseCurrentBlock();
883  $template->setCurrentBlock("detail_row");
884  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
885  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
886  $template->parseCurrentBlock();
887  */
888  $template->setCurrentBlock("detail_row");
889  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
890  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MEDIAN"]);
891  $template->parseCurrentBlock();
892 
893  $template->setCurrentBlock("detail_row");
894  $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
895  $categories = "";
896  foreach ($this->cumulated["variables"] as $key => $value)
897  {
898  $categories .= "<li>" . $value["title"] . ": n=" . $value["selected"] .
899  " (" . sprintf("%.2f", 100*$value["percentage"]) . "%)</li>";
900  }
901  $categories = "<ol>$categories</ol>";
902  $template->setVariable("TEXT_OPTION_VALUE", $categories);
903  $template->parseCurrentBlock();
904 
905  // add text answers to detailed results
906  if (is_array($this->cumulated["textanswers"]))
907  {
908  $template->setCurrentBlock("detail_row");
909  $template->setVariable("TEXT_OPTION", $this->lng->txt("freetext_answers"));
910  $html = "";
911  foreach ($this->cumulated["textanswers"] as $key => $answers)
912  {
913  $html .= $this->cumulated["variables"][$key]["title"] ."\n";
914  $html .= "<ul>\n";
915  foreach ($answers as $answer)
916  {
917  $html .= "<li>" . preg_replace("/\n/", "<br>\n", $answer) . "</li>\n";
918  }
919  $html .= "</ul>\n";
920  }
921  $template->setVariable("TEXT_OPTION_VALUE", $html);
922  $template->parseCurrentBlock();
923  }
924 
925  // chart
926  $template->setCurrentBlock("detail_row");
927  $template->setVariable("TEXT_OPTION", $this->lng->txt("chart"));
928  $template->setVariable("TEXT_OPTION_VALUE", $this->renderChart("svy_ch_".$this->object->getId(), $this->cumulated["variables"]));
929  $template->parseCurrentBlock();
930 
931  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
932  return $template->get();
933  }
934 }
935 ?>