ILIAS  eassessment Revision 61809
 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  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) ||
110  (strcmp($this->ctrl->getCmd(), "wizardanswers") == 0) ||
111  (strcmp($this->ctrl->getCmd(), "savePhraseanswers") == 0)
112  ) ? TRUE : FALSE;
113 
114  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
115  $form = new ilPropertyFormGUI();
116  $form->setFormAction($this->ctrl->getFormAction($this));
117  $form->setTitle($this->lng->txt($this->getQuestionType()));
118  $form->setMultipart(FALSE);
119  $form->setTableWidth("100%");
120  $form->setId("singlechoice");
121 
122  // title
123  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
124  $title->setValue($this->object->getTitle());
125  $title->setRequired(TRUE);
126  $form->addItem($title);
127 
128  // label
129  $label = new ilTextInputGUI($this->lng->txt("label"), "label");
130  $label->setValue($this->object->label);
131  $label->setInfo($this->lng->txt("label_info"));
132  $label->setRequired(false);
133  $form->addItem($label);
134 
135  // author
136  $author = new ilTextInputGUI($this->lng->txt("author"), "author");
137  $author->setValue($this->object->getAuthor());
138  $author->setRequired(TRUE);
139  $form->addItem($author);
140 
141  // description
142  $description = new ilTextInputGUI($this->lng->txt("description"), "description");
143  $description->setValue($this->object->getDescription());
144  $description->setRequired(FALSE);
145  $form->addItem($description);
146 
147  // questiontext
148  $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
149  $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestiontext()));
150  $question->setRequired(TRUE);
151  $question->setRows(10);
152  $question->setCols(80);
153  $question->setUseRte(TRUE);
154  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
155  $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
156  $question->addPlugin("latex");
157  $question->addButton("latex");
158  $question->addButton("pastelatex");
159  $question->removePlugin("ibrowser");
160  $question->setRTESupport($this->object->getId(), "spl", "survey");
161  $form->addItem($question);
162 
163  // obligatory
164  $shuffle = new ilCheckboxInputGUI($this->lng->txt("obligatory"), "obligatory");
165  $shuffle->setValue(1);
166  $shuffle->setChecked($this->object->getObligatory());
167  $shuffle->setRequired(FALSE);
168  $form->addItem($shuffle);
169 
170  // orientation
171  $orientation = new ilRadioGroupInputGUI($this->lng->txt("orientation"), "orientation");
172  $orientation->setRequired(false);
173  $orientation->setValue($this->object->getOrientation());
174  $orientation->addOption(new ilRadioOption($this->lng->txt('vertical'), 0));
175  $orientation->addOption(new ilRadioOption($this->lng->txt('horizontal'), 1));
176  $orientation->addOption(new ilRadioOption($this->lng->txt('combobox'), 2));
177  $form->addItem($orientation);
178 
179  // Answers
180  include_once "./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
181  $answers = new ilCategoryWizardInputGUI($this->lng->txt("answers"), "answers");
182  $answers->setRequired(false);
183  $answers->setAllowMove(true);
184  $answers->setShowWizard(true);
185  $answers->setShowSavePhrase(true);
186  $answers->setUseOtherAnswer(true);
187  $answers->setShowNeutralCategory(true);
188  $answers->setNeutralCategoryTitle($this->lng->txt('matrix_neutral_answer'));
189  if (!$this->object->getCategories()->getCategoryCount())
190  {
191  $this->object->getCategories()->addCategory("");
192  }
193  $answers->setValues($this->object->getCategories());
194  $answers->setDisabledScale(false);
195  $form->addItem($answers);
196 
197  $form->addCommandButton("save", $this->lng->txt("save"));
198 
199  $errors = false;
200 
201  if ($save)
202  {
203  $form->setValuesByPost();
204  $errors = !$form->checkInput();
205  $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
206  if ($errors) $checkonly = false;
207  }
208 
209  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
210  return $errors;
211  }
212 
216  public function addanswers()
217  {
218  $this->writePostData(true);
219  $position = key($_POST['cmd']['addanswers']);
220  $this->object->getCategories()->addCategoryAtPosition("", $position+1);
221  $this->editQuestion();
222  }
223 
227  public function removeanswers()
228  {
229  $this->writePostData(true);
230  $position = key($_POST['cmd']['removeanswers']);
231  $this->object->getCategories()->removeCategory($position);
232  $this->editQuestion();
233  }
234 
238  public function upanswers()
239  {
240  $this->writePostData(true);
241  $position = key($_POST['cmd']['upanswers']);
242  $this->object->getCategories()->moveCategoryUp($position);
243  $this->editQuestion();
244  }
245 
249  public function downanswers()
250  {
251  $this->writePostData(true);
252  $position = key($_POST['cmd']['downanswers']);
253  $this->object->getCategories()->moveCategoryDown($position);
254  $this->editQuestion();
255  }
256 
262  function wizardanswers($save_post_data = true)
263  {
264  if ($save_post_data) $result = $this->writePostData();
265  if ($result == 0 || !$save_post_data)
266  {
267  if ($save_post_data) $this->object->saveToDb();
268  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase.html", "Modules/SurveyQuestionPool");
269 
270  // set the id to return to the selected question
271  $this->tpl->setCurrentBlock("hidden");
272  $this->tpl->setVariable("HIDDEN_NAME", "id");
273  $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
274  $this->tpl->parseCurrentBlock();
275 
276  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyPhrases.php";
278  $colors = array("tblrow1", "tblrow2");
279  $counter = 0;
280  foreach ($phrases as $phrase_id => $phrase_array)
281  {
282  $this->tpl->setCurrentBlock("phraserow");
283  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter++ % 2]);
284  $this->tpl->setVariable("PHRASE_VALUE", $phrase_id);
285  $this->tpl->setVariable("PHRASE_NAME", $phrase_array["title"]);
286  $categories =& ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
287  $this->tpl->setVariable("PHRASE_CONTENT", join($categories, ","));
288  $this->tpl->parseCurrentBlock();
289  }
290 
291  $this->tpl->setCurrentBlock("adm_content");
292  $this->tpl->setVariable("TEXT_CANCEL", $this->lng->txt("cancel"));
293  $this->tpl->setVariable("TEXT_PHRASE", $this->lng->txt("phrase"));
294  $this->tpl->setVariable("TEXT_CONTENT", $this->lng->txt("categories"));
295  $this->tpl->setVariable("TEXT_ADD_PHRASE", $this->lng->txt("add_phrase"));
296  $this->tpl->setVariable("TEXT_INTRODUCTION",$this->lng->txt("add_phrase_introduction"));
297  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
298  $this->tpl->parseCurrentBlock();
299  }
300  }
301 
307  function cancelViewPhrase()
308  {
309  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
310  $this->ctrl->redirect($this, 'editQuestion');
311  }
312 
318  function addSelectedPhrase()
319  {
320  if (strcmp($_POST["phrases"], "") == 0)
321  {
322  ilUtil::sendInfo($this->lng->txt("select_phrase_to_add"));
323  $this->wizardanswers(false);
324  }
325  else
326  {
327  if (strcmp($this->object->getPhrase($_POST["phrases"]), "dp_standard_numbers") != 0)
328  {
329  $this->object->addPhrase($_POST["phrases"]);
330  $this->object->saveToDb();
331  }
332  else
333  {
334  $this->addStandardNumbers();
335  return;
336  }
337  ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
338  $this->ctrl->redirect($this, 'editQuestion');
339  }
340  }
341 
347  function addStandardNumbers()
348  {
349  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase_standard_numbers.html", "Modules/SurveyQuestionPool");
350 
351  // set the id to return to the selected question
352  $this->tpl->setCurrentBlock("hidden");
353  $this->tpl->setVariable("HIDDEN_NAME", "id");
354  $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
355  $this->tpl->parseCurrentBlock();
356 
357  $this->tpl->setCurrentBlock("adm_content");
358  $this->tpl->setVariable("ADD_STANDARD_NUMBERS", $this->lng->txt("add_standard_numbers"));
359  $this->tpl->setVariable("TEXT_ADD_LIMITS", $this->lng->txt("add_limits_for_standard_numbers"));
360  $this->tpl->setVariable("TEXT_LOWER_LIMIT",$this->lng->txt("lower_limit"));
361  $this->tpl->setVariable("TEXT_UPPER_LIMIT",$this->lng->txt("upper_limit"));
362  $this->tpl->setVariable("VALUE_LOWER_LIMIT", $_POST["lower_limit"]);
363  $this->tpl->setVariable("VALUE_UPPER_LIMIT", $_POST["upper_limit"]);
364  $this->tpl->setVariable("BTN_ADD",$this->lng->txt("add_phrase"));
365  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
366  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
367  $this->tpl->parseCurrentBlock();
368  }
369 
376  {
377  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
378  $this->ctrl->redirect($this, "editQuestion");
379  }
380 
387  {
388  if ((strcmp($_POST["lower_limit"], "") == 0) or (strcmp($_POST["upper_limit"], "") == 0))
389  {
390  ilUtil::sendInfo($this->lng->txt("missing_upper_or_lower_limit"));
391  $this->addStandardNumbers();
392  }
393  else if ((int)$_POST["upper_limit"] <= (int)$_POST["lower_limit"])
394  {
395  ilUtil::sendInfo($this->lng->txt("upper_limit_must_be_greater"));
396  $this->addStandardNumbers();
397  }
398  else
399  {
400  $this->object->addStandardNumbers($_POST["lower_limit"], $_POST["upper_limit"]);
401  $this->object->saveToDb();
402  ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
403  $this->ctrl->redirect($this, "editQuestion");
404  }
405  }
406 
412  function savePhraseanswers($haserror = false)
413  {
414  if (!$haserror) $result = $this->writePostData();
415  if ($result == 0 || $haserror)
416  {
417  if (!$haserror) $this->object->saveToDb();
418 
419  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_savephrase.html", "Modules/SurveyQuestionPool");
420  $this->tpl->setCurrentBlock("adm_content");
421  $this->tpl->setVariable("SAVE_PHRASE_INTRODUCTION", $this->lng->txt("save_phrase_introduction"));
422  $this->tpl->setVariable("TEXT_PHRASE_TITLE", $this->lng->txt("enter_phrase_title"));
423  $this->tpl->setVariable("VALUE_PHRASE_TITLE", $_POST["phrase_title"]);
424  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
425  $this->tpl->setVariable("BTN_CONFIRM",$this->lng->txt("confirm"));
426  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
427 
428  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveySavePhraseTableGUI.php";
429  $table_gui = new ilSurveySavePhraseTableGUI($this, 'editQuestion');
430 
431  $data = array();
432  if (!$haserror)
433  {
434  foreach ($_POST['answers']['answer'] as $key => $value)
435  {
436  array_push($data, array('answer' => $value, 'other' => (($_POST['answers']['other'][$key]) ? true : false), 'scale' => $_POST['answers']['scale'][$key]));
437  }
438  if (strlen($_POST['answers']['neutral']))
439  {
440  array_push($data, array('answer' => $_POST['answers']['neutral'], 'other' => false, 'scale' => $_POST['answers_neutral_scale']));
441  }
442  }
443  else
444  {
445  $data = $_SESSION['save_phrase_data'];
446  }
447  $table_gui->setData($data);
448  $_SESSION['save_phrase_data'] = $data;
449  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
450  $this->tpl->parseCurrentBlock();
451  }
452  }
453 
459  function cancelSavePhrase()
460  {
461  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
462  $this->ctrl->redirect($this, "editQuestion");
463  }
464 
470  function confirmSavePhrase()
471  {
472  if (!$_POST["phrase_title"])
473  {
474  ilUtil::sendInfo($this->lng->txt("qpl_savephrase_empty"));
475  $this->savePhraseanswers(true);
476  return;
477  }
478 
479  if ($this->object->phraseExists($_POST["phrase_title"]))
480  {
481  ilUtil::sendInfo($this->lng->txt("qpl_savephrase_exists"));
482  $this->savePhraseanswers(true);
483  return;
484  }
485 
486  $this->object->savePhrase($_POST["phrase_title"]);
487  ilUtil::sendSuccess($this->lng->txt("phrase_saved"), true);
488  $this->ctrl->redirect($this, "editQuestion");
489  }
490 
491 
497  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
498  {
499  $template = new ilTemplate("tpl.il_svy_out_sc.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
500  $template->setCurrentBlock("material");
501  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
502  $template->parseCurrentBlock();
503  switch ($this->object->orientation)
504  {
505  case 0:
506  // vertical orientation
507  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
508  {
509  $cat = $this->object->categories->getCategory($i);
510  if ($cat->other)
511  {
512  $template->setCurrentBlock("other_row");
513  if (strlen($cat->title))
514  {
515  $template->setVariable("OTHER_LABEL", $cat->title);
516  }
517  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
518  $template->setVariable("QUESTION_ID", $this->object->getId());
519  if (is_array($working_data))
520  {
521  foreach ($working_data as $value)
522  {
523  if (strlen($value["value"]))
524  {
525  if ($value["value"] == $cat->scale-1)
526  {
527  if (strlen($value['textanswer'])) $template->setVariable("OTHER_VALUE", ' value="' . ilUtil::prepareFormOutput($value['textanswer']) . '"');
528  if (!$value['uncheck'])
529  {
530  $template->setVariable("CHECKED_SC", " checked=\"checked\"");
531  }
532  }
533  }
534  }
535  }
536  $template->parseCurrentBlock();
537  }
538  else
539  {
540  $template->setCurrentBlock("row");
541  if ($cat->neutral) $template->setVariable('ROWCLASS', ' class="neutral"');
542  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
543  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
544  $template->setVariable("QUESTION_ID", $this->object->getId());
545  if (is_array($working_data))
546  {
547  foreach ($working_data as $value)
548  {
549  if (strcmp($value["value"], "") != 0)
550  {
551  if ($value["value"] == $cat->scale-1)
552  {
553  if (!$value['uncheck'])
554  {
555  $template->setVariable("CHECKED_SC", " checked=\"checked\"");
556  }
557  }
558  }
559  }
560  }
561  $template->parseCurrentBlock();
562  }
563  $template->touchBlock('outer_row');
564  }
565  break;
566  case 1:
567  // horizontal orientation
568  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
569  {
570  $cat = $this->object->categories->getCategory($i);
571  $template->setCurrentBlock("radio_col");
572  if ($cat->neutral) $template->setVariable('COLCLASS', ' neutral');
573  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
574  $template->setVariable("QUESTION_ID", $this->object->getId());
575  if (is_array($working_data))
576  {
577  foreach ($working_data as $value)
578  {
579  if (strcmp($value["value"], "") != 0)
580  {
581  if ($value["value"] == $cat->scale-1)
582  {
583  if (!$value['uncheck'])
584  {
585  $template->setVariable("CHECKED_SC", " checked=\"checked\"");
586  }
587  }
588  }
589  }
590  }
591  $template->parseCurrentBlock();
592  }
593  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
594  {
595  $cat = $this->object->categories->getCategory($i);
596  if ($cat->other)
597  {
598  $template->setCurrentBlock("text_other_col");
599  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
600  $template->setVariable("QUESTION_ID", $this->object->getId());
601  if (strlen($cat->title))
602  {
603  $template->setVariable("OTHER_LABEL", $cat->title);
604  }
605  if (is_array($working_data))
606  {
607  foreach ($working_data as $value)
608  {
609  if (strlen($value["value"]))
610  {
611  if ($value["value"] == $cat->scale-1 && strlen($value['textanswer']))
612  {
613  $template->setVariable("OTHER_VALUE", ' value="' . ilUtil::prepareFormOutput($value['textanswer']) . '"');
614  }
615  }
616  }
617  }
618  $template->parseCurrentBlock();
619  }
620  else
621  {
622  $template->setCurrentBlock("text_col");
623  if ($cat->neutral) $template->setVariable('COLCLASS', ' neutral');
624  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
625  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
626  $template->setVariable("QUESTION_ID", $this->object->getId());
627  $template->parseCurrentBlock();
628  }
629  $template->touchBlock('text_outer_col');
630  }
631  break;
632  case 2:
633  // combobox output
634  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
635  {
636  $cat = $this->object->categories->getCategory($i);
637  $template->setCurrentBlock("comborow");
638  $template->setVariable("TEXT_SC", $cat->title);
639  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
640  if (is_array($working_data))
641  {
642  if (strcmp($working_data[0]["value"], "") != 0)
643  {
644  if ($working_data[0]["value"] == $cat->scale-1)
645  {
646  $template->setVariable("SELECTED_SC", " selected=\"selected\"");
647  }
648  }
649  }
650  $template->parseCurrentBlock();
651  }
652  $template->setCurrentBlock("combooutput");
653  $template->setVariable("QUESTION_ID", $this->object->getId());
654  $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
655  $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
656  $template->parseCurrentBlock();
657  break;
658  }
659  if ($question_title)
660  {
661  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
662  }
663  $template->setCurrentBlock("question_data");
664  if (strcmp($error_message, "") != 0)
665  {
666  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
667  }
668  if ($show_questiontext)
669  {
670  $this->outQuestionText($template);
671  }
672  $template->parseCurrentBlock();
673  return $template->get();
674  }
675 
681  function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
682  {
683  $template = new ilTemplate("tpl.il_svy_qpl_sc_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
684  switch ($this->object->orientation)
685  {
686  case 0:
687  // vertical orientation
688  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
689  {
690  $cat = $this->object->categories->getCategory($i);
691  if ($cat->other)
692  {
693  $template->setCurrentBlock("other_row");
694  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
695  $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
696  $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
697  $template->setVariable("OTHER_LABEL", ilUtil::prepareFormOutput($cat->title));
698  $template->setVariable("OTHER_ANSWER", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
699  $template->parseCurrentBlock();
700  }
701  else
702  {
703  $template->setCurrentBlock("row");
704  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
705  $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
706  $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
707  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
708  $template->parseCurrentBlock();
709  }
710  }
711  break;
712  case 1:
713  // horizontal orientation
714  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
715  {
716  $template->setCurrentBlock("radio_col");
717  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
718  $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
719  $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
720  $template->parseCurrentBlock();
721  }
722  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
723  {
724  $cat = $this->object->categories->getCategory($i);
725  if ($cat->other)
726  {
727  $template->setCurrentBlock("other_text_col");
728  $template->setVariable("OTHER_LABEL", ilUtil::prepareFormOutput($cat->title));
729  $template->setVariable("OTHER_ANSWER", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
730  $template->parseCurrentBlock();
731  }
732  else
733  {
734  $template->setCurrentBlock("text_col");
735  $template->setVariable("TEXT_SC", $cat->title);
736  $template->parseCurrentBlock();
737  }
738  }
739  break;
740  case 2:
741  // combobox output
742  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
743  {
744  $cat = $this->object->categories->getCategory($i);
745  $template->setCurrentBlock("comborow");
746  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
747  $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
748  if (is_array($working_data))
749  {
750  if (strcmp($working_data[0]["value"], "") != 0)
751  {
752  if ($working_data[0]["value"] == $i)
753  {
754  $template->setVariable("SELECTED_SC", " selected=\"selected\"");
755  }
756  }
757  }
758  $template->parseCurrentBlock();
759  }
760  $template->setCurrentBlock("combooutput");
761  $template->setVariable("QUESTION_ID", $this->object->getId());
762  $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
763  $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
764  $template->parseCurrentBlock();
765  break;
766  }
767  if ($question_title)
768  {
769  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
770  }
771  if ($show_questiontext)
772  {
773  $this->outQuestionText($template);
774  }
775  $template->parseCurrentBlock();
776  return $template->get();
777  }
778 
784  function preview()
785  {
786  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", "Modules/SurveyQuestionPool");
787  $question_output = $this->getWorkingForm();
788  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
789  }
790 
791  function setQuestionTabs()
792  {
793  global $rbacsystem,$ilTabs;
794  $this->ctrl->setParameter($this, "sel_question_types", $this->getQuestionType());
795  $this->ctrl->setParameter($this, "q_id", $_GET["q_id"]);
796 
797  if (($_GET["calling_survey"] > 0) || ($_GET["new_for_survey"] > 0))
798  {
799  $ref_id = $_GET["calling_survey"];
800  if (!strlen($ref_id)) $ref_id = $_GET["new_for_survey"];
801  $addurl = "";
802  if (strlen($_GET["new_for_survey"]))
803  {
804  $addurl = "&new_id=" . $_GET["q_id"];
805  }
806  $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), "ilias.php?baseClass=ilObjSurveyGUI&ref_id=$ref_id&cmd=questions" . $addurl);
807  }
808  else
809  {
810  $this->ctrl->setParameterByClass("ilObjSurveyQuestionPoolGUI", "q_id_table_nav", $_SESSION['q_id_table_nav']);
811  $ilTabs->setBackTarget($this->lng->txt("spl"), $this->ctrl->getLinkTargetByClass("ilObjSurveyQuestionPoolGUI", "questions"));
812  }
813  if ($_GET["q_id"])
814  {
815  $ilTabs->addTarget("preview",
816  $this->ctrl->getLinkTarget($this, "preview"),
817  "preview",
818  "",
819  ""
820  );
821  }
822  if ($rbacsystem->checkAccess('edit', $_GET["ref_id"])) {
823  $ilTabs->addTarget("edit_properties",
824  $this->ctrl->getLinkTarget($this, "editQuestion"),
825  array("editQuestion", "save", "cancel", "wizardanswers", "addSelectedPhrase",
826  "insertStandardNumbers", "savePhraseanswers", "confirmSavePhrase"),
827  "",
828  ""
829  );
830  }
831  if ($_GET["q_id"])
832  {
833  $ilTabs->addTarget("material",
834  $this->ctrl->getLinkTarget($this, "material"),
835  array("material", "cancelExplorer", "linkChilds", "addGIT", "addST",
836  "addPG", "addMaterial", "removeMaterial"),
837  "",
838  ""
839  );
840  }
841 
842  if ($this->object->getId() > 0)
843  {
844  $title = $this->lng->txt("edit") . " &quot;" . $this->object->getTitle() . "&quot";
845  }
846  else
847  {
848  $title = $this->lng->txt("create_new") . " " . $this->lng->txt($this->getQuestionType());
849  }
850 
851  $this->tpl->setVariable("HEADER", $title);
852  }
853 
862  function getCumulatedResultsDetails($survey_id, $counter)
863  {
864  if (count($this->cumulated) == 0)
865  {
866  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
867  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
868  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
869  }
870  $output = "";
871  include_once "./classes/class.ilTemplate.php";
872  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
873 
874  $template->setCurrentBlock("detail_row");
875  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
876  $questiontext = $this->object->getQuestiontext();
877  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
878  $template->parseCurrentBlock();
879  $template->setCurrentBlock("detail_row");
880  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
881  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
882  $template->parseCurrentBlock();
883  $template->setCurrentBlock("detail_row");
884  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
885  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
886  $template->parseCurrentBlock();
887  $template->setCurrentBlock("detail_row");
888  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
889  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
890  $template->parseCurrentBlock();
891 
892  $template->setCurrentBlock("detail_row");
893  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
894  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE"]);
895  $template->parseCurrentBlock();
896  $template->setCurrentBlock("detail_row");
897  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
898  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
899  $template->parseCurrentBlock();
900  $template->setCurrentBlock("detail_row");
901  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
902  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MEDIAN"]);
903  $template->parseCurrentBlock();
904 
905  $template->setCurrentBlock("detail_row");
906  $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
907  $categories = "";
908  foreach ($this->cumulated["variables"] as $key => $value)
909  {
910  $categories .= "<li>" . $this->lng->txt("title") . ":" . "<span class=\"bold\">" . $value["title"] . "</span><br />" .
911  $this->lng->txt("category_nr_selected") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
912  $this->lng->txt("percentage_of_selections") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
913  }
914  $categories = "<ol>$categories</ol>";
915  $template->setVariable("TEXT_OPTION_VALUE", $categories);
916  $template->parseCurrentBlock();
917 
918  // add text answers to detailed results
919  if (is_array($this->cumulated["textanswers"]))
920  {
921  $template->setCurrentBlock("detail_row");
922  $template->setVariable("TEXT_OPTION", $this->lng->txt("freetext_answers"));
923  $html = "";
924  foreach ($this->cumulated["textanswers"] as $key => $answers)
925  {
926  $html .= $this->cumulated["variables"][$key]["title"] ."\n";
927  $html .= "<ul>\n";
928  foreach ($answers as $answer)
929  {
930  $html .= "<li>" . preg_replace("/\n/", "<br>\n", $answer) . "</li>\n";
931  }
932  $html .= "</ul>\n";
933  }
934  $template->setVariable("TEXT_OPTION_VALUE", $html);
935  $template->parseCurrentBlock();
936  }
937 
938  // display chart for single choice question for array $eval["variables"]
939  $template->setCurrentBlock("chart");
940  $template->setVariable("TEXT_CHART", $this->lng->txt("chart"));
941  $template->setVariable("ALT_CHART", $data["title"] . "( " . $this->lng->txt("chart") . ")");
942  $charturl = "";
943  include_once "./Services/Administration/classes/class.ilSetting.php";
944  $surveySetting = new ilSetting("survey");
945  if ($surveySetting->get("googlechart") == 1)
946  {
947  $chartcolors = array("2A4BD7", "9DAFFF", "1D6914", "81C57A", "814A19", "E9DEBB", "8126C0", "AD2323", "29D0D0", "FFEE33", "FF9233", "FFCDF3", "A0A0A0", "575757", "000000");
948  $selections = array();
949  $values = array();
950  $maxselection = 0;
951  $char = 65;
952  foreach ($this->cumulated["variables"] as $val)
953  {
954  if ($val["selected"] > $maxselection) $maxselection = $val["selected"];
955  array_push($selections, $val["selected"]);
956  array_push($values, str_replace(" ", "+", $val["title"]));
957  }
958  $chartwidth = 800;
959  if ($maxselection % 2 == 0)
960  {
961  $selectionlabels = "0|" . ($maxselection / 2) . "|$maxselection";
962  }
963  else
964  {
965  $selectionlabels = "0|$maxselection";
966  }
967  $charturl = "http://chart.apis.google.com/chart?chco=" . implode("|", array_slice($chartcolors, 0, count($values))). "&cht=bvs&chs=" . $chartwidth . "x250&chd=t:" . implode(",", $selections) . "&chds=0,$maxselection&chxt=y,y&chxl=0:|".$selectionlabels."|1:||".str_replace(" ", "+", $this->lng->txt("mode_nr_of_selections"))."|" . "&chxr=1,0,$maxselection&chtt=" . str_replace(" ", "+", $this->object->getTitle()) . "&chbh=20," . (round($chartwidth/count($values))-25) . "&chdl=" . implode("|", $values) . "&chdlp=b";
968  }
969  else
970  {
971  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "survey", $survey_id);
972  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "question", $this->object->getId());
973  $charturl = $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "outChart");
974  }
975  $template->setVariable("CHART", $charturl);
976  $template->parseCurrentBlock();
977 
978  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
979  return $template->get();
980  }
981 }
982 ?>