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