ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyMatrixQuestionGUI.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 {
41 
51  $id = -1
52  )
53 
54  {
55  $this->SurveyQuestionGUI();
56  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyMatrixQuestion.php";
57  $this->object = new SurveyMatrixQuestion();
58  $this->show_layout_row = FALSE;
59  if ($id >= 0)
60  {
61  $this->object->loadFromDb($id);
62  }
63  }
64 
68  function &executeCommand()
69  {
70  $cmd = $this->ctrl->getCmd();
71  $next_class = $this->ctrl->getNextClass($this);
72 
73  $cmd = $this->getCommand($cmd);
74  switch($next_class)
75  {
76  default:
77  $ret =& $this->$cmd();
78  break;
79  }
80  return $ret;
81  }
82 
89  function writePostData($always = false)
90  {
91  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
92  if (!$hasErrors)
93  {
94  $this->object->setTitle($_POST["title"]);
95  $this->object->setAuthor($_POST["author"]);
96  $this->object->setDescription($_POST["description"]);
97  $questiontext = $_POST["question"];
98  $this->object->setQuestiontext($questiontext);
99  $this->object->setObligatory(($_POST["obligatory"]) ? 1 : 0);
100  $this->object->setSubtype($_POST["type"]);
101  $this->object->setRowSeparators(($_POST["row_separators"]) ? 1 : 0);
102  $this->object->setColumnSeparators(($_POST["column_separators"]) ? 1 : 0);
103  $this->object->setNeutralColumnSeparator(($_POST["neutral_column_separator"]) ? 1 : 0);
104  // Set bipolar adjectives
105  $this->object->setBipolarAdjective(0, $_POST["bipolar1"]);
106  $this->object->setBipolarAdjective(1, $_POST["bipolar2"]);
107  // set columns
108  $this->object->flushColumns();
109  foreach ($_POST['columns']['answer'] as $key => $value)
110  {
111  if (strlen($value)) $this->object->addColumn($value);
112  }
113  // Set neutral column
114  $this->object->setNeutralColumn($_POST["columns"]["neutral"]);
115  // set rows
116  $this->object->flushRows();
117  foreach ($_POST['rows'] as $key => $value)
118  {
119  $this->object->addRow($value);
120  }
121  return 0;
122  }
123  else
124  {
125  return 1;
126  }
127  }
128 
134  public function editQuestion($checkonly = FALSE)
135  {
136  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) ||
137  (strcmp($this->ctrl->getCmd(), "wizardcolumns") == 0) ||
138  (strcmp($this->ctrl->getCmd(), "savePhrasecolumns") == 0)
139  ) ? TRUE : FALSE;
140 
141  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
142  $form = new ilPropertyFormGUI();
143  $form->setFormAction($this->ctrl->getFormAction($this));
144  $form->setTitle($this->lng->txt($this->getQuestionType()));
145  $form->setMultipart(FALSE);
146  $form->setTableWidth("100%");
147  $form->setId("multiplechoice");
148 
149  // title
150  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
151  $title->setValue($this->object->getTitle());
152  $title->setRequired(TRUE);
153  $form->addItem($title);
154 
155  // author
156  $author = new ilTextInputGUI($this->lng->txt("author"), "author");
157  $author->setValue($this->object->getAuthor());
158  $author->setRequired(TRUE);
159  $form->addItem($author);
160 
161  // description
162  $description = new ilTextInputGUI($this->lng->txt("description"), "description");
163  $description->setValue($this->object->getDescription());
164  $description->setRequired(FALSE);
165  $form->addItem($description);
166 
167  // questiontext
168  $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
169  $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestiontext()));
170  $question->setRequired(TRUE);
171  $question->setRows(10);
172  $question->setCols(80);
173  $question->setUseRte(TRUE);
174  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
175  $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
176  $question->addPlugin("latex");
177  $question->addButton("latex");
178  $question->addButton("pastelatex");
179  $question->removePlugin("ibrowser");
180  $question->setRTESupport($this->object->getId(), "spl", "survey");
181  $form->addItem($question);
182 
183  // subtype
184  $subtype = new ilRadioGroupInputGUI($this->lng->txt("subtype"), "type");
185  $subtype->setRequired(false);
186  $subtype->setValue($this->object->getSubtype());
187  $subtypes = array(
188  "0" => "matrix_subtype_sr",
189  "1" => "matrix_subtype_mr",
190  //"2" => "matrix_subtype_text",
191  //"3" => "matrix_subtype_integer",
192  //"4" => "matrix_subtype_double",
193  //"5" => "matrix_subtype_date",
194  //"6" => "matrix_subtype_time"
195  );
196  foreach ($subtypes as $idx => $st)
197  {
198  $subtype->addOption(new ilRadioOption($this->lng->txt($st), $idx));
199  }
200  $form->addItem($subtype);
201 
202  // obligatory
203  $shuffle = new ilCheckboxInputGUI($this->lng->txt("obligatory"), "obligatory");
204  $shuffle->setValue(1);
205  $shuffle->setChecked($this->object->getObligatory());
206  $shuffle->setRequired(FALSE);
207  $form->addItem($shuffle);
208 
209  $header = new ilFormSectionHeaderGUI();
210  $header->setTitle($this->lng->txt("matrix_appearance"));
211  $form->addItem($header);
212 
213  // column separators
214  $column_separators = new ilCheckboxInputGUI($this->lng->txt("matrix_column_separators"), "column_separators");
215  $column_separators->setValue(1);
216  $column_separators->setInfo($this->lng->txt("matrix_column_separators_description"));
217  $column_separators->setChecked($this->object->getColumnSeparators());
218  $column_separators->setRequired(false);
219  $form->addItem($column_separators);
220 
221  // row separators
222  $row_separators = new ilCheckboxInputGUI($this->lng->txt("matrix_row_separators"), "row_separators");
223  $row_separators->setValue(1);
224  $row_separators->setInfo($this->lng->txt("matrix_row_separators_description"));
225  $row_separators->setChecked($this->object->getRowSeparators());
226  $row_separators->setRequired(false);
227  $form->addItem($row_separators);
228 
229  // neutral column separators
230  $neutral_column_separator = new ilCheckboxInputGUI($this->lng->txt("matrix_neutral_column_separator"), "neutral_column_separator");
231  $neutral_column_separator->setValue(1);
232  $neutral_column_separator->setInfo($this->lng->txt("matrix_neutral_column_separator_description"));
233  $neutral_column_separator->setChecked($this->object->getNeutralColumnSeparator());
234  $neutral_column_separator->setRequired(false);
235  $form->addItem($neutral_column_separator);
236 
237  $header = new ilFormSectionHeaderGUI();
238  $header->setTitle($this->lng->txt("matrix_columns"));
239  $form->addItem($header);
240 
241  // Answers
242  include_once "./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
243  $columns = new ilCategoryWizardInputGUI("", "columns");
244  $columns->setRequired(false);
245  $columns->setAllowMove(true);
246  $columns->setShowWizard(true);
247  $columns->setShowNeutralCategory(true);
248  $columns->setNeutralCategory($this->object->getNeutralColumn());
249  $columns->setNeutralCategoryTitle($this->lng->txt('matrix_neutral_answer'));
250  $columns->setCategoryText($this->lng->txt('matrix_standard_answers'));
251  $columns->setShowSavePhrase(true);
252  if (!$this->object->getColumnCount())
253  {
254  $this->object->addColumn("");
255  }
256  $columns->setValues($this->object->getColumns());
257  $form->addItem($columns);
258 
259  $header = new ilFormSectionHeaderGUI();
260  $header->setTitle($this->lng->txt("matrix_column_settings"));
261  $form->addItem($header);
262 
263  // bipolar adjectives
264  $bipolar = new ilCustomInputGUI($this->lng->txt("matrix_bipolar_adjectives"));
265  $bipolar->setInfo($this->lng->txt("matrix_bipolar_adjectives_description"));
266 
267  // left pole
268  $bipolar1 = new ilTextInputGUI($this->lng->txt("matrix_left_pole"), "bipolar1");
269  $bipolar1->setValue($this->object->getBipolarAdjective(0));
270  $bipolar1->setRequired(false);
271  $bipolar->addSubItem($bipolar1);
272 
273  // right pole
274  $bipolar2 = new ilTextInputGUI($this->lng->txt("matrix_right_pole"), "bipolar2");
275  $bipolar2->setValue($this->object->getBipolarAdjective(1));
276  $bipolar2->setRequired(false);
277  $bipolar->addSubItem($bipolar2);
278 
279  $form->addItem($bipolar);
280 
281  $header = new ilFormSectionHeaderGUI();
282  $header->setTitle($this->lng->txt("matrix_rows"));
283  $form->addItem($header);
284 
285  // matrix rows
286  $rows = new ilTextWizardInputGUI($this->lng->txt('row_text'), "rows");
287  $rows->setRequired(true);
288  $rows->setAllowMove(true);
289  if (count($this->object->getRows()) == 0)
290  {
291  $this->object->addRow("");
292  }
293  $rows->setValues($this->object->getRows());
294  $form->addItem($rows);
295 
296  $form->addCommandButton("save", $this->lng->txt("save"));
297 
298  $errors = false;
299 
300  if ($save)
301  {
302  $form->setValuesByPost();
303  $errors = !$form->checkInput();
304  $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
305  if ($errors) $checkonly = false;
306  }
307 
308  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
309  return $errors;
310  }
311 
315  public function addrows()
316  {
317  $this->writePostData(true);
318  $position = key($_POST['cmd']['addrows']);
319  $this->object->addRowAtPosition("", $position+1);
320  $this->editQuestion();
321  }
322 
326  public function removerows()
327  {
328  $this->writePostData(true);
329  $position = key($_POST['cmd']['removerows']);
330  $this->object->removeRow($position);
331  $this->editQuestion();
332  }
333 
337  public function uprows()
338  {
339  $this->writePostData(true);
340  $position = key($_POST['cmd']['uprows']);
341  $this->object->moveRowUp($position);
342  $this->editQuestion();
343  }
344 
348  public function downrows()
349  {
350  $this->writePostData(true);
351  $position = key($_POST['cmd']['downrows']);
352  $this->object->moveRowDown($position);
353  $this->editQuestion();
354  }
355 
359  public function addcolumns()
360  {
361  $this->writePostData(true);
362  $position = key($_POST['cmd']['addcolumns']);
363  $this->object->getColumns()->addCategoryAtPosition("", $position+1);
364  $this->editQuestion();
365  }
366 
370  public function removecolumns()
371  {
372  $this->writePostData(true);
373  $position = key($_POST['cmd']['removecolumns']);
374  $this->object->getColumns()->removeCategory($position);
375  $this->editQuestion();
376  }
377 
381  public function upcolumns()
382  {
383  $this->writePostData(true);
384  $position = key($_POST['cmd']['upcolumns']);
385  $this->object->getColumns()->moveCategoryUp($position);
386  $this->editQuestion();
387  }
388 
392  public function downcolumns()
393  {
394  $this->writePostData(true);
395  $position = key($_POST['cmd']['downcolumns']);
396  $this->object->getColumns()->moveCategoryDown($position);
397  $this->editQuestion();
398  }
399 
405  function savePhrasecolumns($haserror = false)
406  {
407  if (!$haserror) $result = $this->writePostData();
408  if ($result == 0 || $haserror)
409  {
410  if (!$haserror) $this->object->saveToDb();
411  $nothing_selected = true;
412  $nothing_selected = false;
413  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_savephrase.html", "Modules/SurveyQuestionPool");
414  $rowclass = array("tblrow1", "tblrow2");
415  $counter = 0;
416  foreach ($_POST['columns']['answer'] as $key => $value)
417  {
418  if (strlen($value))
419  {
420  $this->tpl->setCurrentBlock("row");
421  $this->tpl->setVariable("TXT_TITLE", ilUtil::stripSlashes($value));
422  $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
423  $this->tpl->parseCurrentBlock();
424  $this->tpl->setCurrentBlock("hidden");
425  $this->tpl->setVariable("HIDDEN_NAME", "columns[answer][]");
426  $this->tpl->setVariable("HIDDEN_VALUE", ilUtil::stripSlashes($value));
427  $this->tpl->parseCurrentBlock();
428  $counter++;
429  }
430  }
431  if ($counter == 0)
432  {
433  ilUtil::sendFailure($this->lng->txt("check_category_to_save_phrase"), true);
434  $this->ctrl->redirect($this, "editQuestion");
435  }
436  $this->tpl->setCurrentBlock("adm_content");
437  $this->tpl->setVariable("SAVE_PHRASE_INTRODUCTION", $this->lng->txt("save_phrase_introduction"));
438  $this->tpl->setVariable("TEXT_PHRASE_TITLE", $this->lng->txt("enter_phrase_title"));
439  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("category"));
440  $this->tpl->setVariable("VALUE_PHRASE_TITLE", $_POST["phrase_title"]);
441  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
442  $this->tpl->setVariable("BTN_CONFIRM",$this->lng->txt("confirm"));
443  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
444  $this->tpl->parseCurrentBlock();
445  }
446  }
447 
453  function cancelSavePhrase()
454  {
455  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
456  $this->ctrl->redirect($this, "editQuestion");
457  }
458 
464  function confirmSavePhrase()
465  {
466  if (!$_POST["phrase_title"])
467  {
468  ilUtil::sendInfo($this->lng->txt("qpl_savephrase_empty"));
469  $this->savePhrasecolumns(true);
470  return;
471  }
472 
473  if ($this->object->phraseExists($_POST["phrase_title"]))
474  {
475  ilUtil::sendInfo($this->lng->txt("qpl_savephrase_exists"));
476  $this->savePhrasecolumns(true);
477  return;
478  }
479 
480  $this->object->savePhrase($_POST['columns']['answer'], $_POST["phrase_title"]);
481  ilUtil::sendSuccess($this->lng->txt("phrase_saved"), true);
482  $this->ctrl->redirect($this, "editQuestion");
483  }
484 
490  function wizardcolumns($save_post_data = true)
491  {
492  if ($save_post_data) $result = $this->writePostData();
493  if ($result == 0)
494  {
495  if ($save_post_data) $this->object->saveToDb();
496  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase.html", "Modules/SurveyQuestionPool");
497 
498  // set the id to return to the selected question
499  $this->tpl->setCurrentBlock("hidden");
500  $this->tpl->setVariable("HIDDEN_NAME", "id");
501  $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
502  $this->tpl->parseCurrentBlock();
503 
504  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyPhrases.php";
506  $colors = array("tblrow1", "tblrow2");
507  $counter = 0;
508  foreach ($phrases as $phrase_id => $phrase_array)
509  {
510  $this->tpl->setCurrentBlock("phraserow");
511  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter++ % 2]);
512  $this->tpl->setVariable("PHRASE_VALUE", $phrase_id);
513  $this->tpl->setVariable("PHRASE_NAME", $phrase_array["title"]);
514  $categories =& ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
515  $this->tpl->setVariable("PHRASE_CONTENT", join($categories, ","));
516  $this->tpl->parseCurrentBlock();
517  }
518 
519  $this->tpl->setCurrentBlock("adm_content");
520  $this->tpl->setVariable("TEXT_CANCEL", $this->lng->txt("cancel"));
521  $this->tpl->setVariable("TEXT_PHRASE", $this->lng->txt("phrase"));
522  $this->tpl->setVariable("TEXT_CONTENT", $this->lng->txt("categories"));
523  $this->tpl->setVariable("TEXT_ADD_PHRASE", $this->lng->txt("add_phrase"));
524  $this->tpl->setVariable("TEXT_INTRODUCTION",$this->lng->txt("add_phrase_introduction"));
525  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
526  $this->tpl->parseCurrentBlock();
527  }
528  }
529 
535  function cancelViewPhrase()
536  {
537  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
538  $this->ctrl->redirect($this, 'editQuestion');
539  }
540 
546  function addSelectedPhrase()
547  {
548  if (strcmp($_POST["phrases"], "") == 0)
549  {
550  ilUtil::sendInfo($this->lng->txt("select_phrase_to_add"));
551  $this->wizardcolumns(false);
552  }
553  else
554  {
555  if (strcmp($this->object->getPhrase($_POST["phrases"]), "dp_standard_numbers") != 0)
556  {
557  $this->object->addPhrase($_POST["phrases"]);
558  $this->object->saveToDb();
559  }
560  else
561  {
562  $this->addStandardNumbers();
563  return;
564  }
565  ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
566  $this->ctrl->redirect($this, 'editQuestion');
567  }
568  }
569 
575  function addStandardNumbers()
576  {
577  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase_standard_numbers.html", "Modules/SurveyQuestionPool");
578 
579  // set the id to return to the selected question
580  $this->tpl->setCurrentBlock("hidden");
581  $this->tpl->setVariable("HIDDEN_NAME", "id");
582  $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
583  $this->tpl->parseCurrentBlock();
584 
585  $this->tpl->setCurrentBlock("adm_content");
586  $this->tpl->setVariable("ADD_STANDARD_NUMBERS", $this->lng->txt("add_standard_numbers"));
587  $this->tpl->setVariable("TEXT_ADD_LIMITS", $this->lng->txt("add_limits_for_standard_numbers"));
588  $this->tpl->setVariable("TEXT_LOWER_LIMIT",$this->lng->txt("lower_limit"));
589  $this->tpl->setVariable("TEXT_UPPER_LIMIT",$this->lng->txt("upper_limit"));
590  $this->tpl->setVariable("VALUE_LOWER_LIMIT", $_POST["lower_limit"]);
591  $this->tpl->setVariable("VALUE_UPPER_LIMIT", $_POST["upper_limit"]);
592  $this->tpl->setVariable("BTN_ADD",$this->lng->txt("add_phrase"));
593  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
594  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
595  $this->tpl->parseCurrentBlock();
596  }
597 
604  {
605  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
606  $this->ctrl->redirect($this, "editQuestion");
607  }
608 
615  {
616  if ((strcmp($_POST["lower_limit"], "") == 0) or (strcmp($_POST["upper_limit"], "") == 0))
617  {
618  ilUtil::sendInfo($this->lng->txt("missing_upper_or_lower_limit"));
619  $this->addStandardNumbers();
620  }
621  else if ((int)$_POST["upper_limit"] <= (int)$_POST["lower_limit"])
622  {
623  ilUtil::sendInfo($this->lng->txt("upper_limit_must_be_greater"));
624  $this->addStandardNumbers();
625  }
626  else
627  {
628  $this->object->addStandardNumbers($_POST["lower_limit"], $_POST["upper_limit"]);
629  $this->object->saveToDb();
630  ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
631  $this->ctrl->redirect($this, "editQuestion");
632  }
633  }
634 
640  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "")
641  {
642  $layout = $this->object->getLayout();
643  $neutralstyle = "3px solid #808080";
644  $bordercolor = "#808080";
645  $template = new ilTemplate("tpl.il_svy_out_matrix.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
646  $template->setCurrentBlock("material_matrix");
647  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
648  $template->parseCurrentBlock();
649 
650  if ($this->show_layout_row)
651  {
652  $layout_row = $this->getLayoutRow();
653  $template->setCurrentBlock("matrix_row");
654  $template->setVariable("ROW", $layout_row);
655  $template->parseCurrentBlock();
656  }
657 
658  $tplheaders = new ilTemplate("tpl.il_svy_out_matrix_columnheaders.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
659  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
660  {
661  $tplheaders->setCurrentBlock("bipolar_start");
662  $style = array();
663  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective1"], "%"));
664  if (count($style) > 0)
665  {
666  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
667  }
668  $tplheaders->parseCurrentBlock();
669  }
670  // column headers
671  for ($i = 0; $i < $this->object->getColumnCount(); $i++)
672  {
673  $style = array();
674  if ($this->object->getColumnSeparators() == 1)
675  {
676  if (($i < $this->object->getColumnCount() - 1))
677  {
678  array_push($style, "border-right: 1px solid $bordercolor!important");
679  }
680  }
681  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_columns"] / $this->object->getColumnCount(), "%"));
682  $tplheaders->setCurrentBlock("column_header");
683  $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($this->object->getColumn($i)));
684  $tplheaders->setVariable("CLASS", "center");
685  if (count($style) > 0)
686  {
687  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
688  }
689  $tplheaders->parseCurrentBlock();
690  }
691  if (strlen($this->object->getNeutralColumn()))
692  {
693  $tplheaders->setCurrentBlock("neutral_column_header");
694  $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($this->object->getNeutralColumn()));
695  $tplheaders->setVariable("CLASS", "rsep");
696  $style = array();
697  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_neutral"], "%"));
698  if ($this->object->getNeutralColumnSeparator())
699  {
700  array_push($style, "border-left: $neutralstyle!important;");
701  }
702  if (count($style) > 0)
703  {
704  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
705  }
706  $tplheaders->parseCurrentBlock();
707  }
708  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
709  {
710  $tplheaders->setCurrentBlock("bipolar_end");
711  $style = array();
712  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective2"], "%"));
713  if (count($style) > 0)
714  {
715  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
716  }
717  $tplheaders->parseCurrentBlock();
718  }
719 
720  $style = array();
721  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_row"], "%"));
722  if (count($style) > 0)
723  {
724  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
725  }
726 
727  $template->setCurrentBlock("matrix_row");
728  $template->setVariable("ROW", $tplheaders->get());
729  $template->parseCurrentBlock();
730 
731  $rowclass = array("tblrow1", "tblrow2");
732  for ($i = 0; $i < $this->object->getRowCount(); $i++)
733  {
734  $tplrow = new ilTemplate("tpl.il_svy_out_matrix_row.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
735  for ($j = 0; $j < $this->object->getColumnCount(); $j++)
736  {
737  if (($i == 0) && ($j == 0))
738  {
739  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
740  {
741  $tplrow->setCurrentBlock("bipolar_start");
742  $tplrow->setVariable("TEXT_BIPOLAR_START", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(0)));
743  $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
744  $tplrow->parseCurrentBlock();
745  }
746  }
747  if (($i == 0) && ($j == $this->object->getColumnCount()-1))
748  {
749  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
750  {
751  $tplrow->setCurrentBlock("bipolar_end");
752  $tplrow->setVariable("TEXT_BIPOLAR_END", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(1)));
753  $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
754  $tplrow->parseCurrentBlock();
755  }
756  }
757  switch ($this->object->getSubtype())
758  {
759  case 0:
760  $tplrow->setCurrentBlock("radiobutton");
761  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
762  $tplrow->setVariable("ROW", $i);
763  $tplrow->setVariable("VALUE", $j);
764  if (is_array($working_data))
765  {
766  foreach ($working_data as $data)
767  {
768  if (($data["value"] == $j) && ($data["rowvalue"] == $i))
769  {
770  $tplrow->setVariable("CHECKED_RADIOBUTTON", " checked=\"checked\"");
771  }
772  }
773  }
774  $tplrow->parseCurrentBlock();
775  break;
776  case 1:
777  $tplrow->setCurrentBlock("checkbox");
778  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
779  $tplrow->setVariable("ROW", $i);
780  $tplrow->setVariable("VALUE", $j);
781  if (is_array($working_data))
782  {
783  foreach ($working_data as $data)
784  {
785  if (($data["value"] == $j) && ($data["rowvalue"] == $i))
786  {
787  $tplrow->setVariable("CHECKED_CHECKBOX", " checked=\"checked\"");
788  }
789  }
790  }
791  $tplrow->parseCurrentBlock();
792  break;
793  }
794  $tplrow->setCurrentBlock("answer");
795  $style = array();
796 
797  if ($this->object->getColumnSeparators() == 1)
798  {
799  if ($j < $this->object->getColumnCount() - 1)
800  {
801  array_push($style, "border-right: 1px solid $bordercolor!important");
802  }
803  }
804 
805  if ($this->object->getRowSeparators() == 1)
806  {
807  if ($i < $this->object->getRowCount() - 1)
808  {
809  array_push($style, "border-bottom: 1px solid $bordercolor!important");
810  }
811  }
812  if (count($style))
813  {
814  $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
815  }
816  $tplrow->parseCurrentBlock();
817 
818  }
819 
820  if (strlen($this->object->getNeutralColumn()))
821  {
822  $j = $this->object->getNeutralColumnIndex();
823  switch ($this->object->getSubtype())
824  {
825  case 0:
826  $tplrow->setCurrentBlock("neutral_radiobutton");
827  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
828  $tplrow->setVariable("ROW", $i);
829  $tplrow->setVariable("VALUE", $j);
830  if (is_array($working_data))
831  {
832  foreach ($working_data as $data)
833  {
834  if (($data["value"] == $j) && ($data["rowvalue"] == $i))
835  {
836  $tplrow->setVariable("CHECKED_RADIOBUTTON", " checked=\"checked\"");
837  }
838  }
839  }
840  $tplrow->parseCurrentBlock();
841  break;
842  case 1:
843  $tplrow->setCurrentBlock("neutral_checkbox");
844  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
845  $tplrow->setVariable("ROW", $i);
846  $tplrow->setVariable("VALUE", $j);
847  if (is_array($working_data))
848  {
849  foreach ($working_data as $data)
850  {
851  if (($data["value"] == $j) && ($data["rowvalue"] == $i))
852  {
853  $tplrow->setVariable("CHECKED_CHECKBOX", " checked=\"checked\"");
854  }
855  }
856  }
857  $tplrow->parseCurrentBlock();
858  break;
859  }
860  $tplrow->setCurrentBlock("neutral_answer");
861  $style = array();
862  if ($this->object->getNeutralColumnSeparator())
863  {
864  array_push($style, "border-left: $neutralstyle!important");
865  }
866  if ($this->object->getColumnSeparators() == 1)
867  {
868  if ($j < $this->object->getColumnCount() - 1)
869  {
870  array_push($style, "border-right: 1px solid $bordercolor!important");
871  }
872  }
873 
874  if ($this->object->getRowSeparators() == 1)
875  {
876  if ($i < $this->object->getRowCount() - 1)
877  {
878  array_push($style, "border-bottom: 1px solid $bordercolor!important");
879  }
880  }
881  if (count($style))
882  {
883  $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
884  }
885  $tplrow->parseCurrentBlock();
886  }
887 
888  $tplrow->setVariable("TEXT_ROW", ilUtil::prepareFormOutput($this->object->getRow($i)));
889  $tplrow->setVariable("ROWCLASS", $rowclass[$i % 2]);
890  if ($this->object->getRowSeparators() == 1)
891  {
892  if ($i < $this->object->getRowCount() - 1)
893  {
894  $tplrow->setVariable("STYLE", " style=\"border-bottom: 1px solid $bordercolor!important\"");
895  }
896  }
897  $template->setCurrentBlock("matrix_row");
898  $template->setVariable("ROW", $tplrow->get());
899  $template->parseCurrentBlock();
900  }
901 
902  if ($question_title)
903  {
904  $template->setVariable("QUESTION_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
905  }
906  $template->setCurrentBlock("question_data_matrix");
907  if (strcmp($error_message, "") != 0)
908  {
909  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
910  }
911  if ($show_questiontext)
912  {
913  $questiontext = $this->object->getQuestiontext();
914  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
915  }
916  if (! $this->object->getObligatory())
917  {
918  $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
919  }
920  $template->parseCurrentBlock();
921  return $template->get();
922  }
923 
931  function getPrintView($question_title = 1, $show_questiontext = 1)
932  {
933  $layout = $this->object->getLayout();
934  $neutralstyle = "3px solid #808080";
935  $bordercolor = "#808080";
936  $template = new ilTemplate("tpl.il_svy_qpl_matrix_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
937 
938  if ($this->show_layout_row)
939  {
940  $layout_row = $this->getLayoutRow();
941  $template->setCurrentBlock("matrix_row");
942  $template->setVariable("ROW", $layout_row);
943  $template->parseCurrentBlock();
944  }
945 
946  $tplheaders = new ilTemplate("tpl.il_svy_out_matrix_columnheaders.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
947  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
948  {
949  $tplheaders->setCurrentBlock("bipolar_start");
950  $style = array();
951  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective1"], "%"));
952  if (count($style) > 0)
953  {
954  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
955  }
956  $tplheaders->parseCurrentBlock();
957  }
958  // column headers
959  for ($i = 0; $i < $this->object->getColumnCount(); $i++)
960  {
961  $style = array();
962  if ($this->object->getColumnSeparators() == 1)
963  {
964  if (($i < $this->object->getColumnCount() - 1))
965  {
966  array_push($style, "border-right: 1px solid $bordercolor!important");
967  }
968  }
969  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_columns"] / $this->object->getColumnCount(), "%"));
970  $tplheaders->setCurrentBlock("column_header");
971  $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($this->object->getColumn($i)));
972  $tplheaders->setVariable("CLASS", "center");
973  if (count($style) > 0)
974  {
975  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
976  }
977  $tplheaders->parseCurrentBlock();
978  }
979  if (strlen($this->object->getNeutralColumn()))
980  {
981  $tplheaders->setCurrentBlock("neutral_column_header");
982  $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($this->object->getNeutralColumn()));
983  $tplheaders->setVariable("CLASS", "rsep");
984  $style = array();
985  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_neutral"], "%"));
986  if ($this->object->getNeutralColumnSeparator())
987  {
988  array_push($style, "border-left: $neutralstyle!important;");
989  }
990  if (count($style) > 0)
991  {
992  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
993  }
994  $tplheaders->parseCurrentBlock();
995  }
996  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
997  {
998  $tplheaders->setCurrentBlock("bipolar_end");
999  $style = array();
1000  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective2"], "%"));
1001  if (count($style) > 0)
1002  {
1003  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
1004  }
1005  $tplheaders->parseCurrentBlock();
1006  }
1007 
1008  $style = array();
1009  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_row"], "%"));
1010  if (count($style) > 0)
1011  {
1012  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
1013  }
1014 
1015  $template->setCurrentBlock("matrix_row");
1016  $template->setVariable("ROW", $tplheaders->get());
1017  $template->parseCurrentBlock();
1018 
1019  $rowclass = array("tblrow1", "tblrow2");
1020 
1021  for ($i = 0; $i < $this->object->getRowCount(); $i++)
1022  {
1023  $tplrow = new ilTemplate("tpl.il_svy_qpl_matrix_printview_row.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
1024  for ($j = 0; $j < $this->object->getColumnCount(); $j++)
1025  {
1026  if (($i == 0) && ($j == 0))
1027  {
1028  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
1029  {
1030  $tplrow->setCurrentBlock("bipolar_start");
1031  $tplrow->setVariable("TEXT_BIPOLAR_START", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(0)));
1032  $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
1033  $tplrow->parseCurrentBlock();
1034  }
1035  }
1036  if (($i == 0) && ($j == $this->object->getColumnCount()-1))
1037  {
1038  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
1039  {
1040  $tplrow->setCurrentBlock("bipolar_end");
1041  $tplrow->setVariable("TEXT_BIPOLAR_END", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(1)));
1042  $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
1043  $tplrow->parseCurrentBlock();
1044  }
1045  }
1046  switch ($this->object->getSubtype())
1047  {
1048  case 0:
1049  $tplrow->setCurrentBlock("radiobutton");
1050  $tplrow->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
1051  $tplrow->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
1052  $tplrow->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
1053  $tplrow->parseCurrentBlock();
1054  break;
1055  case 1:
1056  $tplrow->setCurrentBlock("checkbox");
1057  $tplrow->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.gif")));
1058  $tplrow->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
1059  $tplrow->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
1060  $tplrow->parseCurrentBlock();
1061  break;
1062  }
1063  $tplrow->setCurrentBlock("answer");
1064  $style = array();
1065 
1066  if ($this->object->getColumnSeparators() == 1)
1067  {
1068  if ($j < $this->object->getColumnCount() - 1)
1069  {
1070  array_push($style, "border-right: 1px solid $bordercolor!important");
1071  }
1072  }
1073 
1074  if ($this->object->getRowSeparators() == 1)
1075  {
1076  if ($i < $this->object->getRowCount() - 1)
1077  {
1078  array_push($style, "border-bottom: 1px solid $bordercolor!important");
1079  }
1080  }
1081  if (count($style))
1082  {
1083  $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
1084  }
1085  $tplrow->parseCurrentBlock();
1086  }
1087 
1088  if (strlen($this->object->getNeutralColumn()))
1089  {
1090  $j = $this->object->getRowCount();
1091  switch ($this->object->getSubtype())
1092  {
1093  case 0:
1094  $tplrow->setCurrentBlock("neutral_radiobutton");
1095  $tplrow->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
1096  $tplrow->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
1097  $tplrow->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
1098  $tplrow->parseCurrentBlock();
1099  break;
1100  case 1:
1101  $tplrow->setCurrentBlock("neutral_checkbox");
1102  $tplrow->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.gif")));
1103  $tplrow->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
1104  $tplrow->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
1105  $tplrow->parseCurrentBlock();
1106  break;
1107  }
1108  $tplrow->setCurrentBlock("neutral_answer");
1109  $style = array();
1110  if ($this->object->getNeutralColumnSeparator())
1111  {
1112  array_push($style, "border-left: $neutralstyle!important");
1113  }
1114  if ($this->object->getColumnSeparators() == 1)
1115  {
1116  if ($j < $this->object->getColumnCount() - 1)
1117  {
1118  array_push($style, "border-right: 1px solid $bordercolor!important");
1119  }
1120  }
1121 
1122  if ($this->object->getRowSeparators() == 1)
1123  {
1124  if ($i < $this->object->getRowCount() - 1)
1125  {
1126  array_push($style, "border-bottom: 1px solid $bordercolor!important");
1127  }
1128  }
1129  if (count($style))
1130  {
1131  $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
1132  }
1133  $tplrow->parseCurrentBlock();
1134  }
1135 
1136  $tplrow->setVariable("TEXT_ROW", ilUtil::prepareFormOutput($this->object->getRow($i)));
1137  $tplrow->setVariable("ROWCLASS", $rowclass[$i % 2]);
1138  if ($this->object->getRowSeparators() == 1)
1139  {
1140  if ($i < $this->object->getRowCount() - 1)
1141  {
1142  $tplrow->setVariable("STYLE", " style=\"border-bottom: 1px solid $bordercolor!important\"");
1143  }
1144  }
1145  $template->setCurrentBlock("matrix_row");
1146  $template->setVariable("ROW", $tplrow->get());
1147  $template->parseCurrentBlock();
1148  }
1149 
1150  if ($question_title)
1151  {
1152  $template->setVariable("QUESTION_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
1153  }
1154  $template->setCurrentBlock();
1155  if ($show_questiontext)
1156  {
1157  $questiontext = $this->object->getQuestiontext();
1158  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
1159  }
1160  if (! $this->object->getObligatory())
1161  {
1162  $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
1163  }
1164  $template->parseCurrentBlock();
1165  return $template->get();
1166  }
1167 
1173  function preview()
1174  {
1175  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", "Modules/SurveyQuestionPool");
1176  $question_output = $this->getWorkingForm();
1177  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
1178  }
1179 
1185  function layout()
1186  {
1187  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_layout.html", "Modules/SurveyQuestionPool");
1188  $this->show_layout_row = TRUE;
1189  $question_output = $this->getWorkingForm();
1190  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
1191  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "saveLayout"));
1192  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
1193  }
1194 
1200  function saveLayout()
1201  {
1202  $this->object->saveLayout($_POST["percent_row"], $_POST['percent_columns'], $_POST['percent_bipolar_adjective1'], $_POST['percent_bipolar_adjective2'], $_POST["percent_neutral"]);
1203  $percent_values = array(
1204  "percent_row" => $_POST["percent_row"],
1205  "percent_columns" => $_POST["percent_columns"],
1206  "percent_bipolar_adjective1" => $_POST['percent_bipolar_adjective1'],
1207  "percent_bipolar_adjective2" => $_POST['percent_bipolar_adjective2'],
1208  "percent_neutral" => $_POST["percent_neutral"]
1209  );
1210  $this->object->setLayout($percent_values);
1211  $this->layout();
1212  }
1213 
1219  function getLayoutRow()
1220  {
1221  $percent_values = $this->object->getLayout();
1222  $template = new ilTemplate("tpl.il_svy_out_matrix_layout.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
1223  if (strlen($this->object->getBipolarAdjective(0)) && strlen($this->object->getBipolarAdjective(1)))
1224  {
1225  $template->setCurrentBlock("bipolar_start");
1226  $template->setVariable("VALUE_PERCENT_BIPOLAR_ADJECTIVE1", " value=\"" . $percent_values["percent_bipolar_adjective1"] . "\"");
1227  $template->setVariable("STYLE", " style=\"width:" . $percent_values["percent_bipolar_adjective1"] . "%\"");
1228  $template->parseCurrentBlock();
1229  $template->setCurrentBlock("bipolar_end");
1230  $template->setVariable("VALUE_PERCENT_BIPOLAR_ADJECTIVE2", " value=\"" . $percent_values["percent_bipolar_adjective2"] . "\"");
1231  $template->setVariable("STYLE", " style=\"width:" . $percent_values["percent_bipolar_adjective2"] . "%\"");
1232  $template->parseCurrentBlock();
1233  }
1234  if (strlen($this->object->getNeutralColumn()))
1235  {
1236  $template->setCurrentBlock("bipolar_end");
1237  $template->setVariable("VALUE_PERCENT_NEUTRAL", " value=\"" . $percent_values["percent_neutral"] . "\"");
1238  $template->setVariable("STYLE_NEUTRAL", " style=\"width:" . $percent_values["percent_neutral"] . "%\"");
1239  $template->parseCurrentBlock();
1240  }
1241  $template->setVariable("VALUE_PERCENT_ROW", " value=\"" . $percent_values["percent_row"] . "\"");
1242  $template->setVariable("STYLE_ROW", " style=\"width:" . $percent_values["percent_row"] . "%\"");
1243  $counter = $this->object->getColumnCount();
1244  $template->setVariable("COLSPAN_COLUMNS", $counter);
1245  $template->setVariable("VALUE_PERCENT_COLUMNS", " value=\"" . $percent_values["percent_columns"] . "\"");
1246  $template->setVariable("STYLE_COLUMNS", " style=\"width:" . $percent_values["percent_columns"] . "%\"");
1247  return $template->get();
1248  }
1249 
1258  function getCumulatedResultsDetails($survey_id, $counter)
1259  {
1260  if (count($this->cumulated) == 0)
1261  {
1262  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
1263  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
1264  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
1265  }
1266 
1267  $output = "";
1268  include_once "./classes/class.ilTemplate.php";
1269  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
1270 
1271  $template->setCurrentBlock("detail_row");
1272  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
1273  $questiontext = $this->object->getQuestiontext();
1274  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
1275  $template->parseCurrentBlock();
1276  $template->setCurrentBlock("detail_row");
1277  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
1278  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
1279  $template->parseCurrentBlock();
1280  $template->setCurrentBlock("detail_row");
1281  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
1282  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["USERS_ANSWERED"]);
1283  $template->parseCurrentBlock();
1284  $template->setCurrentBlock("detail_row");
1285  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
1286  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["USERS_SKIPPED"]);
1287  $template->parseCurrentBlock();
1288 
1289  $template->setCurrentBlock("detail_row");
1290  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
1291  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["MODE"]);
1292  $template->parseCurrentBlock();
1293  $template->setCurrentBlock("detail_row");
1294  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
1295  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["MODE_NR_OF_SELECTIONS"]);
1296  $template->parseCurrentBlock();
1297  $template->setCurrentBlock("detail_row");
1298  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
1299  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["MEDIAN"]);
1300  $template->parseCurrentBlock();
1301 
1302  $template->setCurrentBlock("detail_row");
1303  $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
1304  $columns = "";
1305  foreach ($this->cumulated["TOTAL"]["variables"] as $key => $value)
1306  {
1307  $columns .= "<li>" . $this->lng->txt("title") . ":" . "<span class=\"bold\">" . $value["title"] . "</span><br />" .
1308  $this->lng->txt("category_nr_selected") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
1309  $this->lng->txt("percentage_of_selections") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
1310  }
1311  $columns = "<ol>$columns</ol>";
1312  $template->setVariable("TEXT_OPTION_VALUE", $columns);
1313  $template->parseCurrentBlock();
1314 
1315  foreach ($this->cumulated as $key => $value)
1316  {
1317  if (is_numeric($key))
1318  {
1319  $template->setCurrentBlock("detail_row");
1320  $template->setVariable("TEXT_OPTION", $this->lng->txt("row"));
1321  $questiontext = $value["ROW"];
1322  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
1323  $template->parseCurrentBlock();
1324  $template->setCurrentBlock("detail_row");
1325  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
1326  $template->setVariable("TEXT_OPTION_VALUE", $value["USERS_ANSWERED"]);
1327  $template->parseCurrentBlock();
1328  $template->setCurrentBlock("detail_row");
1329  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
1330  $template->setVariable("TEXT_OPTION_VALUE", $value["USERS_SKIPPED"]);
1331  $template->parseCurrentBlock();
1332 
1333  $template->setCurrentBlock("detail_row");
1334  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
1335  $template->setVariable("TEXT_OPTION_VALUE", $value["MODE"]);
1336  $template->parseCurrentBlock();
1337  $template->setCurrentBlock("detail_row");
1338  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
1339  $template->setVariable("TEXT_OPTION_VALUE", $value["MODE_NR_OF_SELECTIONS"]);
1340  $template->parseCurrentBlock();
1341  $template->setCurrentBlock("detail_row");
1342  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
1343  $template->setVariable("TEXT_OPTION_VALUE", $value["MEDIAN"]);
1344  $template->parseCurrentBlock();
1345 
1346  $template->setCurrentBlock("detail_row");
1347  $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
1348  $columns = "";
1349  foreach ($value["variables"] as $key => $value)
1350  {
1351  $columns .= "<li>" . $this->lng->txt("title") . ":" . "<span class=\"bold\">" . $value["title"] . "</span><br />" .
1352  $this->lng->txt("category_nr_selected") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
1353  $this->lng->txt("percentage_of_selections") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
1354  }
1355  $columns = "<ol>$columns</ol>";
1356  $template->setVariable("TEXT_OPTION_VALUE", $columns);
1357  $template->parseCurrentBlock();
1358  }
1359  }
1360 
1361  // display chart for matrix question for array $eval["variables"]
1362  foreach ($this->cumulated as $key => $value)
1363  {
1364  if (is_numeric($key))
1365  {
1366  $template->setCurrentBlock("chartimage");
1367 
1368  $charturl = "";
1369  include_once "./Services/Administration/classes/class.ilSetting.php";
1370  $surveySetting = new ilSetting("survey");
1371  if ($surveySetting->get("googlechart") == 1)
1372  {
1373  $chartcolors = array("2A4BD7", "9DAFFF", "1D6914", "81C57A", "814A19", "E9DEBB", "8126C0", "AD2323", "29D0D0", "FFEE33", "FF9233", "FFCDF3", "A0A0A0", "575757", "000000");
1374  $selections = array();
1375  $values = array();
1376  $maxselection = 0;
1377  foreach ($value["variables"] as $val)
1378  {
1379  if ($val["selected"] > $maxselection) $maxselection = $val["selected"];
1380  array_push($selections, $val["selected"]);
1381  array_push($values, str_replace(" ", "+", $val["title"]));
1382  }
1383  $chartwidth = 800;
1384  $selectionlabels = "";
1385  if ($maxselection % 2 == 0)
1386  {
1387  $selectionlabels = "0|" . ($maxselection / 2) . "|$maxselection";
1388  }
1389  else
1390  {
1391  $selectionlabels = "0|$maxselection";
1392  }
1393  $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(" ", "+", $value["ROW"]) . "&chbh=20," . (round($chartwidth/count($values))-25) . "&chdl=" . implode("|", $values) . "&chdlp=b";
1394  }
1395  else
1396  {
1397  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "type", $key);
1398  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "survey", $survey_id);
1399  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "question", $this->object->getId());
1400  $charturl = $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "outChart");
1401  }
1402  $template->setVariable("CHART", $charturl);
1403  $template->setVariable("ALT_CHART", $this->lng->txt("chart"));
1404  $template->parseCurrentBlock();
1405  }
1406  }
1407  $template->setCurrentBlock("chart");
1408  $template->setVariable("TEXT_CHART", $this->lng->txt("chart"));
1409  $template->parseCurrentBlock();
1410 
1411  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
1412  $output = $template->get();
1413  return $output;
1414  }
1415 
1416  function setQuestionTabs()
1417  {
1418  global $rbacsystem,$ilTabs;
1419  $this->ctrl->setParameterByClass("$guiclass", "sel_question_types", $this->getQuestionType());
1420  $this->ctrl->setParameterByClass("$guiclass", "q_id", $_GET["q_id"]);
1421 
1422  if (($_GET["calling_survey"] > 0) || ($_GET["new_for_survey"] > 0))
1423  {
1424  $ref_id = $_GET["calling_survey"];
1425  if (!strlen($ref_id)) $ref_id = $_GET["new_for_survey"];
1426  $addurl = "";
1427  if (strlen($_GET["new_for_survey"]))
1428  {
1429  $addurl = "&new_id=" . $_GET["q_id"];
1430  }
1431  $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), "ilias.php?baseClass=ilObjSurveyGUI&ref_id=$ref_id&cmd=questions" . $addurl);
1432  }
1433  else
1434  {
1435  $this->ctrl->setParameterByClass("ilObjSurveyQuestionPoolGUI", "q_id_table_nav", $_SESSION['q_id_table_nav']);
1436  $ilTabs->setBackTarget($this->lng->txt("spl"), $this->ctrl->getLinkTargetByClass("ilObjSurveyQuestionPoolGUI", "questions"));
1437  }
1438  if ($_GET["q_id"])
1439  {
1440  $ilTabs->addTarget("preview",
1441  $this->ctrl->getLinkTarget($this, "preview"),
1442  array("preview"),
1443  "",
1444  "");
1445 
1446  $ilTabs->addTarget("layout",
1447  $this->ctrl->getLinkTarget($this, "layout"),
1448  array("layout", "saveLayout"),
1449  "",
1450  "");
1451  }
1452  if ($rbacsystem->checkAccess('edit', $_GET["ref_id"]))
1453  {
1454  $ilTabs->addTarget("edit_properties",
1455  $this->ctrl->getLinkTarget($this, "editQuestion"),
1456  array("editQuestion", "cancelExplorer", "linkChilds", "addGIT", "addST",
1457  "addPG", "editQuestion", "addMaterial", "removeMaterial",
1458  "save", "cancel", "savePhrasecolumns", "confirmSavePhrase",
1459  "downcolumns", "upcolumns", "addcolumns", "removecolumns",
1460  "downrows", "uprows", "addrows", "removerows", "wizardcolumns",
1461  "addSelectedPhrase", "insertStandardNumbers"),
1462  "",
1463  "");
1464  }
1465 
1466  if ($this->object->getId() > 0)
1467  {
1468  $ilTabs->addTarget("material",
1469  $this->ctrl->getLinkTarget($this, "material"),
1470  array("material", "cancelExplorer", "linkChilds", "addGIT", "addST",
1471  "addPG", "addMaterial", "removeMaterial"),
1472  "$guiclass");
1473  }
1474 
1475  if ($this->object->getId() > 0)
1476  {
1477  $title = $this->lng->txt("edit") . " &quot;" . $this->object->getTitle() . "&quot";
1478  }
1479  else
1480  {
1481  $title = $this->lng->txt("create_new") . " " . $this->lng->txt($this->getQuestionType());
1482  }
1483 
1484  $this->tpl->setVariable("HEADER", $title);
1485  }
1486 
1487 }
1488 ?>