ILIAS  Release_4_0_x_branch Revision 61816
 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 
83  $this->object->categories->flushCategories();
84 
85  foreach ($_POST['answers']['answer'] as $key => $value)
86  {
87  if (strlen($value)) $this->object->getCategories()->addCategory($value);
88  }
89  return 0;
90  }
91  else
92  {
93  return 1;
94  }
95  }
96 
102  public function editQuestion($checkonly = FALSE)
103  {
104  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) ||
105  (strcmp($this->ctrl->getCmd(), "wizardanswers") == 0) ||
106  (strcmp($this->ctrl->getCmd(), "savePhraseanswers") == 0)
107  ) ? TRUE : 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  // author
124  $author = new ilTextInputGUI($this->lng->txt("author"), "author");
125  $author->setValue($this->object->getAuthor());
126  $author->setRequired(TRUE);
127  $form->addItem($author);
128 
129  // description
130  $description = new ilTextInputGUI($this->lng->txt("description"), "description");
131  $description->setValue($this->object->getDescription());
132  $description->setRequired(FALSE);
133  $form->addItem($description);
134 
135  // questiontext
136  $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
137  $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestiontext()));
138  $question->setRequired(TRUE);
139  $question->setRows(10);
140  $question->setCols(80);
141  $question->setUseRte(TRUE);
142  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
143  $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
144  $question->addPlugin("latex");
145  $question->addButton("latex");
146  $question->addButton("pastelatex");
147  $question->removePlugin("ibrowser");
148  $question->setRTESupport($this->object->getId(), "spl", "survey");
149  $form->addItem($question);
150 
151  // obligatory
152  $shuffle = new ilCheckboxInputGUI($this->lng->txt("obligatory"), "obligatory");
153  $shuffle->setValue(1);
154  $shuffle->setChecked($this->object->getObligatory());
155  $shuffle->setRequired(FALSE);
156  $form->addItem($shuffle);
157 
158  // orientation
159  $orientation = new ilRadioGroupInputGUI($this->lng->txt("orientation"), "orientation");
160  $orientation->setRequired(false);
161  $orientation->setValue($this->object->getOrientation());
162  $orientation->addOption(new ilRadioOption($this->lng->txt('vertical'), 0));
163  $orientation->addOption(new ilRadioOption($this->lng->txt('horizontal'), 1));
164  $orientation->addOption(new ilRadioOption($this->lng->txt('combobox'), 2));
165  $form->addItem($orientation);
166 
167  // Answers
168  include_once "./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
169  $answers = new ilCategoryWizardInputGUI($this->lng->txt("answers"), "answers");
170  $answers->setRequired(false);
171  $answers->setAllowMove(true);
172  $answers->setShowWizard(true);
173  $answers->setShowSavePhrase(true);
174  if (!$this->object->getCategories()->getCategoryCount())
175  {
176  $this->object->getCategories()->addCategory("");
177  }
178  $answers->setValues($this->object->getCategories());
179  $form->addItem($answers);
180 
181  $form->addCommandButton("save", $this->lng->txt("save"));
182 
183  $errors = false;
184 
185  if ($save)
186  {
187  $form->setValuesByPost();
188  $errors = !$form->checkInput();
189  $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
190  if ($errors) $checkonly = false;
191  }
192 
193  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
194  return $errors;
195  }
196 
200  public function addanswers()
201  {
202  $this->writePostData(true);
203  $position = key($_POST['cmd']['addanswers']);
204  $this->object->getCategories()->addCategoryAtPosition("", $position+1);
205  $this->editQuestion();
206  }
207 
211  public function removeanswers()
212  {
213  $this->writePostData(true);
214  $position = key($_POST['cmd']['removeanswers']);
215  $this->object->getCategories()->removeCategory($position);
216  $this->editQuestion();
217  }
218 
222  public function upanswers()
223  {
224  $this->writePostData(true);
225  $position = key($_POST['cmd']['upanswers']);
226  $this->object->getCategories()->moveCategoryUp($position);
227  $this->editQuestion();
228  }
229 
233  public function downanswers()
234  {
235  $this->writePostData(true);
236  $position = key($_POST['cmd']['downanswers']);
237  $this->object->getCategories()->moveCategoryDown($position);
238  $this->editQuestion();
239  }
240 
246  function wizardanswers($save_post_data = true)
247  {
248  if ($save_post_data) $result = $this->writePostData();
249  if ($result == 0 || !$save_post_data)
250  {
251  if ($save_post_data) $this->object->saveToDb();
252  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase.html", "Modules/SurveyQuestionPool");
253 
254  // set the id to return to the selected question
255  $this->tpl->setCurrentBlock("hidden");
256  $this->tpl->setVariable("HIDDEN_NAME", "id");
257  $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
258  $this->tpl->parseCurrentBlock();
259 
260  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyPhrases.php";
262  $colors = array("tblrow1", "tblrow2");
263  $counter = 0;
264  foreach ($phrases as $phrase_id => $phrase_array)
265  {
266  $this->tpl->setCurrentBlock("phraserow");
267  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter++ % 2]);
268  $this->tpl->setVariable("PHRASE_VALUE", $phrase_id);
269  $this->tpl->setVariable("PHRASE_NAME", $phrase_array["title"]);
270  $categories =& ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
271  $this->tpl->setVariable("PHRASE_CONTENT", join($categories, ","));
272  $this->tpl->parseCurrentBlock();
273  }
274 
275  $this->tpl->setCurrentBlock("adm_content");
276  $this->tpl->setVariable("TEXT_CANCEL", $this->lng->txt("cancel"));
277  $this->tpl->setVariable("TEXT_PHRASE", $this->lng->txt("phrase"));
278  $this->tpl->setVariable("TEXT_CONTENT", $this->lng->txt("categories"));
279  $this->tpl->setVariable("TEXT_ADD_PHRASE", $this->lng->txt("add_phrase"));
280  $this->tpl->setVariable("TEXT_INTRODUCTION",$this->lng->txt("add_phrase_introduction"));
281  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
282  $this->tpl->parseCurrentBlock();
283  }
284  }
285 
291  function cancelViewPhrase()
292  {
293  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
294  $this->ctrl->redirect($this, 'editQuestion');
295  }
296 
302  function addSelectedPhrase()
303  {
304  if (strcmp($_POST["phrases"], "") == 0)
305  {
306  ilUtil::sendInfo($this->lng->txt("select_phrase_to_add"));
307  $this->wizardanswers(false);
308  }
309  else
310  {
311  if (strcmp($this->object->getPhrase($_POST["phrases"]), "dp_standard_numbers") != 0)
312  {
313  $this->object->addPhrase($_POST["phrases"]);
314  $this->object->saveToDb();
315  }
316  else
317  {
318  $this->addStandardNumbers();
319  return;
320  }
321  ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
322  $this->ctrl->redirect($this, 'editQuestion');
323  }
324  }
325 
331  function addStandardNumbers()
332  {
333  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase_standard_numbers.html", "Modules/SurveyQuestionPool");
334 
335  // set the id to return to the selected question
336  $this->tpl->setCurrentBlock("hidden");
337  $this->tpl->setVariable("HIDDEN_NAME", "id");
338  $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
339  $this->tpl->parseCurrentBlock();
340 
341  $this->tpl->setCurrentBlock("adm_content");
342  $this->tpl->setVariable("ADD_STANDARD_NUMBERS", $this->lng->txt("add_standard_numbers"));
343  $this->tpl->setVariable("TEXT_ADD_LIMITS", $this->lng->txt("add_limits_for_standard_numbers"));
344  $this->tpl->setVariable("TEXT_LOWER_LIMIT",$this->lng->txt("lower_limit"));
345  $this->tpl->setVariable("TEXT_UPPER_LIMIT",$this->lng->txt("upper_limit"));
346  $this->tpl->setVariable("VALUE_LOWER_LIMIT", $_POST["lower_limit"]);
347  $this->tpl->setVariable("VALUE_UPPER_LIMIT", $_POST["upper_limit"]);
348  $this->tpl->setVariable("BTN_ADD",$this->lng->txt("add_phrase"));
349  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
350  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
351  $this->tpl->parseCurrentBlock();
352  }
353 
360  {
361  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
362  $this->ctrl->redirect($this, "editQuestion");
363  }
364 
371  {
372  if ((strcmp($_POST["lower_limit"], "") == 0) or (strcmp($_POST["upper_limit"], "") == 0))
373  {
374  ilUtil::sendInfo($this->lng->txt("missing_upper_or_lower_limit"));
375  $this->addStandardNumbers();
376  }
377  else if ((int)$_POST["upper_limit"] <= (int)$_POST["lower_limit"])
378  {
379  ilUtil::sendInfo($this->lng->txt("upper_limit_must_be_greater"));
380  $this->addStandardNumbers();
381  }
382  else
383  {
384  $this->object->addStandardNumbers($_POST["lower_limit"], $_POST["upper_limit"]);
385  $this->object->saveToDb();
386  ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
387  $this->ctrl->redirect($this, "editQuestion");
388  }
389  }
390 
396  function savePhraseanswers($haserror = false)
397  {
398  if (!$haserror) $result = $this->writePostData();
399  if ($result == 0 || $haserror)
400  {
401  if (!$haserror) $this->object->saveToDb();
402  $nothing_selected = true;
403  $nothing_selected = false;
404  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_savephrase.html", "Modules/SurveyQuestionPool");
405  $rowclass = array("tblrow1", "tblrow2");
406  $counter = 0;
407  foreach ($_POST['answers']['answer'] as $key => $value)
408  {
409  if (strlen($value))
410  {
411  $this->tpl->setCurrentBlock("row");
412  $this->tpl->setVariable("TXT_TITLE", ilUtil::stripSlashes($value));
413  $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
414  $this->tpl->parseCurrentBlock();
415  $this->tpl->setCurrentBlock("hidden");
416  $this->tpl->setVariable("HIDDEN_NAME", "answers[answer][]");
417  $this->tpl->setVariable("HIDDEN_VALUE", ilUtil::stripSlashes($value));
418  $this->tpl->parseCurrentBlock();
419  $counter++;
420  }
421  }
422  if ($counter == 0)
423  {
424  ilUtil::sendFailure($this->lng->txt("check_category_to_save_phrase"), true);
425  $this->ctrl->redirect($this, "editQuestion");
426  }
427  $this->tpl->setCurrentBlock("adm_content");
428  $this->tpl->setVariable("SAVE_PHRASE_INTRODUCTION", $this->lng->txt("save_phrase_introduction"));
429  $this->tpl->setVariable("TEXT_PHRASE_TITLE", $this->lng->txt("enter_phrase_title"));
430  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("category"));
431  $this->tpl->setVariable("VALUE_PHRASE_TITLE", $_POST["phrase_title"]);
432  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
433  $this->tpl->setVariable("BTN_CONFIRM",$this->lng->txt("confirm"));
434  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
435  $this->tpl->parseCurrentBlock();
436  }
437  }
438 
444  function cancelSavePhrase()
445  {
446  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
447  $this->ctrl->redirect($this, "editQuestion");
448  }
449 
455  function confirmSavePhrase()
456  {
457  if (!$_POST["phrase_title"])
458  {
459  ilUtil::sendInfo($this->lng->txt("qpl_savephrase_empty"));
460  $this->savePhraseanswers(true);
461  return;
462  }
463 
464  if ($this->object->phraseExists($_POST["phrase_title"]))
465  {
466  ilUtil::sendInfo($this->lng->txt("qpl_savephrase_exists"));
467  $this->savePhraseanswers(true);
468  return;
469  }
470 
471  $this->object->savePhrase($_POST['answers']['answer'], $_POST["phrase_title"]);
472  ilUtil::sendSuccess($this->lng->txt("phrase_saved"), true);
473  $this->ctrl->redirect($this, "editQuestion");
474  }
475 
476 
482  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
483  {
484  $template = new ilTemplate("tpl.il_svy_out_sc.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
485  $template->setCurrentBlock("material");
486  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
487  $template->parseCurrentBlock();
488  switch ($this->object->orientation)
489  {
490  case 0:
491  // vertical orientation
492  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
493  {
494  $category = $this->object->categories->getCategory($i);
495  $template->setCurrentBlock("row");
496  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($category));
497  $template->setVariable("VALUE_SC", $i);
498  $template->setVariable("QUESTION_ID", $this->object->getId());
499  if (is_array($working_data))
500  {
501  if (strcmp($working_data[0]["value"], "") != 0)
502  {
503  if ($working_data[0]["value"] == $i)
504  {
505  $template->setVariable("CHECKED_SC", " checked=\"checked\"");
506  }
507  }
508  }
509  $template->parseCurrentBlock();
510  }
511  break;
512  case 1:
513  // horizontal orientation
514  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
515  {
516  $category = $this->object->categories->getCategory($i);
517  $template->setCurrentBlock("radio_col");
518  $template->setVariable("VALUE_SC", $i);
519  $template->setVariable("QUESTION_ID", $this->object->getId());
520  if (is_array($working_data))
521  {
522  if (strcmp($working_data[0]["value"], "") != 0)
523  {
524  if ($working_data[0]["value"] == $i)
525  {
526  $template->setVariable("CHECKED_SC", " checked=\"checked\"");
527  }
528  }
529  }
530  $template->parseCurrentBlock();
531  }
532  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
533  {
534  $category = $this->object->categories->getCategory($i);
535  $template->setCurrentBlock("text_col");
536  $template->setVariable("VALUE_SC", $i);
537  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($category));
538  $template->setVariable("QUESTION_ID", $this->object->getId());
539  $template->parseCurrentBlock();
540  }
541  break;
542  case 2:
543  // combobox output
544  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
545  {
546  $category = $this->object->categories->getCategory($i);
547  $template->setCurrentBlock("comborow");
548  $template->setVariable("TEXT_SC", $category);
549  $template->setVariable("VALUE_SC", $i);
550  if (is_array($working_data))
551  {
552  if (strcmp($working_data[0]["value"], "") != 0)
553  {
554  if ($working_data[0]["value"] == $i)
555  {
556  $template->setVariable("SELECTED_SC", " selected=\"selected\"");
557  }
558  }
559  }
560  $template->parseCurrentBlock();
561  }
562  $template->setCurrentBlock("combooutput");
563  $template->setVariable("QUESTION_ID", $this->object->getId());
564  $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
565  $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
566  $template->parseCurrentBlock();
567  break;
568  }
569  if ($question_title)
570  {
571  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
572  }
573  $template->setCurrentBlock("question_data");
574  if (strcmp($error_message, "") != 0)
575  {
576  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
577  }
578  if ($show_questiontext)
579  {
580  $questiontext = $this->object->getQuestiontext();
581  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
582  }
583  if (! $this->object->getObligatory($survey_id))
584  {
585  $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
586  }
587  $template->parseCurrentBlock();
588  return $template->get();
589  }
590 
596  function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
597  {
598  $template = new ilTemplate("tpl.il_svy_qpl_sc_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
599  switch ($this->object->orientation)
600  {
601  case 0:
602  // vertical orientation
603  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
604  {
605  $category = $this->object->categories->getCategory($i);
606  $template->setCurrentBlock("row");
607  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
608  $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
609  $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
610  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($category));
611  $template->parseCurrentBlock();
612  }
613  break;
614  case 1:
615  // horizontal orientation
616  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
617  {
618  $category = $this->object->categories->getCategory($i);
619  $template->setCurrentBlock("radio_col");
620  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
621  $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
622  $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
623  $template->parseCurrentBlock();
624  }
625  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
626  {
627  $category = $this->object->categories->getCategory($i);
628  $template->setCurrentBlock("text_col");
629  $template->setVariable("TEXT_SC", $category);
630  $template->parseCurrentBlock();
631  }
632  break;
633  case 2:
634  // combobox output
635  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
636  {
637  $category = $this->object->categories->getCategory($i);
638  $template->setCurrentBlock("comborow");
639  $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($category));
640  $template->setVariable("VALUE_SC", $i);
641  if (is_array($working_data))
642  {
643  if (strcmp($working_data[0]["value"], "") != 0)
644  {
645  if ($working_data[0]["value"] == $i)
646  {
647  $template->setVariable("SELECTED_SC", " selected=\"selected\"");
648  }
649  }
650  }
651  $template->parseCurrentBlock();
652  }
653  $template->setCurrentBlock("combooutput");
654  $template->setVariable("QUESTION_ID", $this->object->getId());
655  $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
656  $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
657  $template->parseCurrentBlock();
658  break;
659  }
660  if ($question_title)
661  {
662  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
663  }
664  if ($show_questiontext)
665  {
666  $questiontext = $this->object->getQuestiontext();
667  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
668  }
669  if (! $this->object->getObligatory($survey_id))
670  {
671  $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
672  }
673  $template->parseCurrentBlock();
674  return $template->get();
675  }
676 
682  function preview()
683  {
684  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", "Modules/SurveyQuestionPool");
685  $question_output = $this->getWorkingForm();
686  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
687  }
688 
689  function setQuestionTabs()
690  {
691  global $rbacsystem,$ilTabs;
692  $this->ctrl->setParameter($this, "sel_question_types", $this->getQuestionType());
693  $this->ctrl->setParameter($this, "q_id", $_GET["q_id"]);
694 
695  if (($_GET["calling_survey"] > 0) || ($_GET["new_for_survey"] > 0))
696  {
697  $ref_id = $_GET["calling_survey"];
698  if (!strlen($ref_id)) $ref_id = $_GET["new_for_survey"];
699  $addurl = "";
700  if (strlen($_GET["new_for_survey"]))
701  {
702  $addurl = "&new_id=" . $_GET["q_id"];
703  }
704  $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), "ilias.php?baseClass=ilObjSurveyGUI&ref_id=$ref_id&cmd=questions" . $addurl);
705  }
706  else
707  {
708  $this->ctrl->setParameterByClass("ilObjSurveyQuestionPoolGUI", "q_id_table_nav", $_SESSION['q_id_table_nav']);
709  $ilTabs->setBackTarget($this->lng->txt("spl"), $this->ctrl->getLinkTargetByClass("ilObjSurveyQuestionPoolGUI", "questions"));
710  }
711  if ($_GET["q_id"])
712  {
713  $ilTabs->addTarget("preview",
714  $this->ctrl->getLinkTarget($this, "preview"),
715  "preview",
716  "",
717  ""
718  );
719  }
720  if ($rbacsystem->checkAccess('edit', $_GET["ref_id"])) {
721  $ilTabs->addTarget("edit_properties",
722  $this->ctrl->getLinkTarget($this, "editQuestion"),
723  array("editQuestion", "save", "cancel", "wizardanswers", "addSelectedPhrase",
724  "insertStandardNumbers", "savePhraseanswers", "confirmSavePhrase"),
725  "",
726  ""
727  );
728  }
729  if ($_GET["q_id"])
730  {
731  $ilTabs->addTarget("material",
732  $this->ctrl->getLinkTarget($this, "material"),
733  array("material", "cancelExplorer", "linkChilds", "addGIT", "addST",
734  "addPG", "addMaterial", "removeMaterial"),
735  "",
736  ""
737  );
738  }
739 
740  if ($this->object->getId() > 0)
741  {
742  $title = $this->lng->txt("edit") . " &quot;" . $this->object->getTitle() . "&quot";
743  }
744  else
745  {
746  $title = $this->lng->txt("create_new") . " " . $this->lng->txt($this->getQuestionType());
747  }
748 
749  $this->tpl->setVariable("HEADER", $title);
750  }
751 
760  function getCumulatedResultsDetails($survey_id, $counter)
761  {
762  if (count($this->cumulated) == 0)
763  {
764  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
765  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
766  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
767  }
768  $output = "";
769  include_once "./classes/class.ilTemplate.php";
770  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
771 
772  $template->setCurrentBlock("detail_row");
773  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
774  $questiontext = $this->object->getQuestiontext();
775  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
776  $template->parseCurrentBlock();
777  $template->setCurrentBlock("detail_row");
778  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
779  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
780  $template->parseCurrentBlock();
781  $template->setCurrentBlock("detail_row");
782  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
783  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
784  $template->parseCurrentBlock();
785  $template->setCurrentBlock("detail_row");
786  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
787  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
788  $template->parseCurrentBlock();
789 
790  $template->setCurrentBlock("detail_row");
791  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
792  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE"]);
793  $template->parseCurrentBlock();
794  $template->setCurrentBlock("detail_row");
795  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
796  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
797  $template->parseCurrentBlock();
798  $template->setCurrentBlock("detail_row");
799  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
800  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MEDIAN"]);
801  $template->parseCurrentBlock();
802 
803  $template->setCurrentBlock("detail_row");
804  $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
805  $categories = "";
806  foreach ($this->cumulated["variables"] as $key => $value)
807  {
808  $categories .= "<li>" . $this->lng->txt("title") . ":" . "<span class=\"bold\">" . $value["title"] . "</span><br />" .
809  $this->lng->txt("category_nr_selected") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
810  $this->lng->txt("percentage_of_selections") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
811  }
812  $categories = "<ol>$categories</ol>";
813  $template->setVariable("TEXT_OPTION_VALUE", $categories);
814  $template->parseCurrentBlock();
815 
816  // display chart for single choice question for array $eval["variables"]
817  $template->setCurrentBlock("chart");
818  $template->setVariable("TEXT_CHART", $this->lng->txt("chart"));
819  $template->setVariable("ALT_CHART", $data["title"] . "( " . $this->lng->txt("chart") . ")");
820  $charturl = "";
821  include_once "./Services/Administration/classes/class.ilSetting.php";
822  $surveySetting = new ilSetting("survey");
823  if ($surveySetting->get("googlechart") == 1)
824  {
825  $chartcolors = array("2A4BD7", "9DAFFF", "1D6914", "81C57A", "814A19", "E9DEBB", "8126C0", "AD2323", "29D0D0", "FFEE33", "FF9233", "FFCDF3", "A0A0A0", "575757", "000000");
826  $selections = array();
827  $values = array();
828  $maxselection = 0;
829  $char = 65;
830  foreach ($this->cumulated["variables"] as $val)
831  {
832  if ($val["selected"] > $maxselection) $maxselection = $val["selected"];
833  array_push($selections, $val["selected"]);
834  array_push($values, str_replace(" ", "+", $val["title"]));
835  }
836  $chartwidth = 800;
837  if ($maxselection % 2 == 0)
838  {
839  $selectionlabels = "0|" . ($maxselection / 2) . "|$maxselection";
840  }
841  else
842  {
843  $selectionlabels = "0|$maxselection";
844  }
845  $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";
846  }
847  else
848  {
849  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "survey", $survey_id);
850  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "question", $this->object->getId());
851  $charturl = $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "outChart");
852  }
853  $template->setVariable("CHART", $charturl);
854  $template->parseCurrentBlock();
855 
856  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
857  return $template->get();
858  }
859 }
860 ?>