ILIAS  Release_3_10_x_branch Revision 61812
 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 
90  function editQuestion()
91  {
92  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_matrix.html", "Modules/SurveyQuestionPool");
93  $this->tpl->addBlockFile("OTHER_QUESTION_DATA", "other_question_data", "tpl.il_svy_qpl_other_question_data.html", "Modules/SurveyQuestionPool");
94 
95  $subtypes = array(
96  "0" => "matrix_subtype_sr",
97  "1" => "matrix_subtype_mr",
98  //"2" => "matrix_subtype_text",
99  //"3" => "matrix_subtype_integer",
100  //"4" => "matrix_subtype_double",
101  //"5" => "matrix_subtype_date",
102  //"6" => "matrix_subtype_time"
103  );
104 
105  foreach ($subtypes as $value => $text)
106  {
107  $this->tpl->setCurrentBlock("subtype_row");
108  $this->tpl->setVariable("VALUE_SUBTYPE", $value);
109  $this->tpl->setVariable("TEXT_SUBTYPE", $this->lng->txt($text));
110  if ($value == $this->object->getSubtype())
111  {
112  $this->tpl->setVariable("CHECKED_SUBTYPE", " checked=\"checked\"");
113  }
114  $this->tpl->parseCurrentBlock();
115  }
116 
117  $internallinks = array(
118  "lm" => $this->lng->txt("obj_lm"),
119  "st" => $this->lng->txt("obj_st"),
120  "pg" => $this->lng->txt("obj_pg"),
121  "glo" => $this->lng->txt("glossary_term")
122  );
123  foreach ($internallinks as $key => $value)
124  {
125  $this->tpl->setCurrentBlock("internallink");
126  $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
127  $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
128  $this->tpl->parseCurrentBlock();
129  }
130 
131  $this->tpl->setCurrentBlock("adm_content");
132  $this->tpl->setVariable("TEXT_MATERIAL", $this->lng->txt("material"));
133  if (count($this->object->material))
134  {
135  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
136  $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
137  $this->tpl->setVariable("TEXT_VALUE_MATERIAL", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("material"). "</a> ");
138  $this->tpl->setVariable("BUTTON_REMOVE_MATERIAL", $this->lng->txt("remove"));
139  $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("change"));
140  $this->tpl->setVariable("VALUE_MATERIAL", $this->object->material["internal_link"]);
141  $this->tpl->setVariable("VALUE_MATERIAL_TITLE", $this->object->material["title"]);
142  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
143  }
144  else
145  {
146  $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("add"));
147  }
148  $this->tpl->setVariable("TEXT_ORIENTATION", $this->lng->txt("orientation"));
149  $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
150  $this->tpl->setVariable("VALUE_TITLE", $this->object->getTitle());
151  $this->tpl->setVariable("VALUE_DESCRIPTION", $this->object->getDescription());
152  $this->tpl->setVariable("VALUE_AUTHOR", $this->object->getAuthor());
153  $questiontext = $this->object->getQuestiontext();
154  $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
155  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
156  $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
157  $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
158  $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
159  $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("questiontype"));
160  $this->tpl->setVariable("TEXT_OBLIGATORY", $this->lng->txt("obligatory"));
161  if ($this->object->getObligatory())
162  {
163  $this->tpl->setVariable("CHECKED_OBLIGATORY", " checked=\"checked\"");
164  }
165 
166  $this->tpl->setVariable("TEXT_APPEARANCE", $this->lng->txt("matrix_appearance"));
167  $this->tpl->setVariable("TEXT_COLUMN_SEPARATORS", $this->lng->txt("matrix_column_separators"));
168  $this->tpl->setVariable("TEXT_ROW_SEPARATORS", $this->lng->txt("matrix_row_separators"));
169  $this->tpl->setVariable("TEXT_NEUTRAL_COLUMN_SEPARATOR", $this->lng->txt("matrix_neutral_column_separator"));
170  $this->tpl->setVariable("DESCRIPTION_NEUTRAL_COLUMN_SEPARATOR", $this->lng->txt("matrix_neutral_column_separator_description"));
171  $this->tpl->setVariable("DESCRIPTION_ROW_SEPARATORS", $this->lng->txt("matrix_row_separators_description"));
172  $this->tpl->setVariable("DESCRIPTION_COLUMN_SEPARATORS", $this->lng->txt("matrix_column_separators_description"));
173  if ($this->object->getRowSeparators())
174  {
175  $this->tpl->setVariable("CHECKED_ROW_SEPARATORS", " checked=\"checked\"");
176  }
177  if ($this->object->getColumnSeparators())
178  {
179  $this->tpl->setVariable("CHECKED_COLUMN_SEPARATORS", " checked=\"checked\"");
180  }
181  if ($this->object->getNeutralColumnSeparator())
182  {
183  $this->tpl->setVariable("CHECKED_NEUTRAL_COLUMN_SEPARATOR", " checked=\"checked\"");
184  }
185 
186  $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
187  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
188  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "editQuestion"));
189  $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt($this->getQuestionType()));
190  $this->tpl->setVariable("TEXT_SUBTYPE", $this->lng->txt("subtype"));
191  $this->tpl->setVariable("DESCRIPTION_SUBTYPE", $this->lng->txt("matrix_subtype_description"));
192  $this->tpl->parseCurrentBlock();
193 
194  include_once "./Services/RTE/classes/class.ilRTE.php";
195  $rtestring = ilRTE::_getRTEClassname();
196  include_once "./Services/RTE/classes/class.$rtestring.php";
197  $rte = new $rtestring();
198  $rte->addPlugin("latex");
199  $rte->addButton("latex"); $rte->addButton("pastelatex");
200  $rte->removePlugin("ibrowser");
201  include_once "./classes/class.ilObject.php";
202  $obj_id = $_GET["q_id"];
203  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
204  $rte->addRTESupport($obj_id, $obj_type, "survey");
205 
207  }
208 
216  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "")
217  {
218  $layout = $this->object->getLayout();
219  $neutralstyle = "3px solid #808080";
220  $bordercolor = "#808080";
221  $template = new ilTemplate("tpl.il_svy_out_matrix.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
222  if (count($this->object->material))
223  {
224  $template->setCurrentBlock("material_matrix");
225  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
226  $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
227  $template->setVariable("TEXT_MATERIAL", $this->lng->txt("material") . ": <a href=\"$href\" target=\"content\">" . $this->object->material["title"]. "</a> ");
228  $template->parseCurrentBlock();
229  }
230 
231  if ($this->show_layout_row)
232  {
233  $layout_row = $this->getLayoutRow();
234  $template->setCurrentBlock("matrix_row");
235  $template->setVariable("ROW", $layout_row);
236  $template->parseCurrentBlock();
237  }
238 
239  $tplheaders = new ilTemplate("tpl.il_svy_out_matrix_columnheaders.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
240  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
241  {
242  $tplheaders->setCurrentBlock("bipolar_start");
243  $style = array();
244  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective1"], "%"));
245  if (count($style) > 0)
246  {
247  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
248  }
249  $tplheaders->parseCurrentBlock();
250  }
251  // column headers
252  for ($i = 0; $i < $this->object->getColumnCount(); $i++)
253  {
254  $style = array();
255  if ($this->object->getColumnSeparators() == 1)
256  {
257  if (($i < $this->object->getColumnCount() - 1))
258  {
259  array_push($style, "border-right: 1px solid $bordercolor!important");
260  }
261  }
262  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_columns"] / $this->object->getColumnCount(), "%"));
263  $tplheaders->setCurrentBlock("column_header");
264  $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($this->object->getColumn($i)));
265  $tplheaders->setVariable("CLASS", "center");
266  if (count($style) > 0)
267  {
268  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
269  }
270  $tplheaders->parseCurrentBlock();
271  }
272  if (strlen($this->object->getNeutralColumn()))
273  {
274  $tplheaders->setCurrentBlock("neutral_column_header");
275  $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($this->object->getNeutralColumn()));
276  $tplheaders->setVariable("CLASS", "rsep");
277  $style = array();
278  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_neutral"], "%"));
279  if ($this->object->getNeutralColumnSeparator())
280  {
281  array_push($style, "border-left: $neutralstyle!important;");
282  }
283  if (count($style) > 0)
284  {
285  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
286  }
287  $tplheaders->parseCurrentBlock();
288  }
289  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
290  {
291  $tplheaders->setCurrentBlock("bipolar_end");
292  $style = array();
293  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective2"], "%"));
294  if (count($style) > 0)
295  {
296  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
297  }
298  $tplheaders->parseCurrentBlock();
299  }
300 
301  $style = array();
302  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_row"], "%"));
303  if (count($style) > 0)
304  {
305  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
306  }
307 
308  $template->setCurrentBlock("matrix_row");
309  $template->setVariable("ROW", $tplheaders->get());
310  $template->parseCurrentBlock();
311 
312  $rowclass = array("tblrow1", "tblrow2");
313  for ($i = 0; $i < $this->object->getRowCount(); $i++)
314  {
315  $tplrow = new ilTemplate("tpl.il_svy_out_matrix_row.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
316  for ($j = 0; $j < $this->object->getColumnCount(); $j++)
317  {
318  if (($i == 0) && ($j == 0))
319  {
320  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
321  {
322  $tplrow->setCurrentBlock("bipolar_start");
323  $tplrow->setVariable("TEXT_BIPOLAR_START", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(0)));
324  $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
325  $tplrow->parseCurrentBlock();
326  }
327  }
328  if (($i == 0) && ($j == $this->object->getColumnCount()-1))
329  {
330  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
331  {
332  $tplrow->setCurrentBlock("bipolar_end");
333  $tplrow->setVariable("TEXT_BIPOLAR_END", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(1)));
334  $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
335  $tplrow->parseCurrentBlock();
336  }
337  }
338  switch ($this->object->getSubtype())
339  {
340  case 0:
341  $tplrow->setCurrentBlock("radiobutton");
342  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
343  $tplrow->setVariable("ROW", $i);
344  $tplrow->setVariable("VALUE", $j);
345  if (is_array($working_data))
346  {
347  foreach ($working_data as $data)
348  {
349  if (($data["value"] == $j) && ($data["row"] == $i))
350  {
351  $tplrow->setVariable("CHECKED_RADIOBUTTON", " checked=\"checked\"");
352  }
353  }
354  }
355  $tplrow->parseCurrentBlock();
356  break;
357  case 1:
358  $tplrow->setCurrentBlock("checkbox");
359  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
360  $tplrow->setVariable("ROW", $i);
361  $tplrow->setVariable("VALUE", $j);
362  if (is_array($working_data))
363  {
364  foreach ($working_data as $data)
365  {
366  if (($data["value"] == $j) && ($data["row"] == $i))
367  {
368  $tplrow->setVariable("CHECKED_CHECKBOX", " checked=\"checked\"");
369  }
370  }
371  }
372  $tplrow->parseCurrentBlock();
373  break;
374  }
375  $tplrow->setCurrentBlock("answer");
376  $style = array();
377 
378  if ($this->object->getColumnSeparators() == 1)
379  {
380  if ($j < $this->object->getColumnCount() - 1)
381  {
382  array_push($style, "border-right: 1px solid $bordercolor!important");
383  }
384  }
385 
386  if ($this->object->getRowSeparators() == 1)
387  {
388  if ($i < $this->object->getRowCount() - 1)
389  {
390  array_push($style, "border-bottom: 1px solid $bordercolor!important");
391  }
392  }
393  if (count($style))
394  {
395  $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
396  }
397  $tplrow->parseCurrentBlock();
398 
399  }
400 
401  if (strlen($this->object->getNeutralColumn()))
402  {
403  $j = $this->object->getNeutralColumnIndex();
404  switch ($this->object->getSubtype())
405  {
406  case 0:
407  $tplrow->setCurrentBlock("neutral_radiobutton");
408  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
409  $tplrow->setVariable("ROW", $i);
410  $tplrow->setVariable("VALUE", $j);
411  if (is_array($working_data))
412  {
413  foreach ($working_data as $data)
414  {
415  if (($data["value"] == $j) && ($data["row"] == $i))
416  {
417  $tplrow->setVariable("CHECKED_RADIOBUTTON", " checked=\"checked\"");
418  }
419  }
420  }
421  $tplrow->parseCurrentBlock();
422  break;
423  case 1:
424  $tplrow->setCurrentBlock("neutral_checkbox");
425  $tplrow->setVariable("QUESTION_ID", $this->object->getId());
426  $tplrow->setVariable("ROW", $i);
427  $tplrow->setVariable("VALUE", $j);
428  if (is_array($working_data))
429  {
430  foreach ($working_data as $data)
431  {
432  if (($data["value"] == $j) && ($data["row"] == $i))
433  {
434  $tplrow->setVariable("CHECKED_CHECKBOX", " checked=\"checked\"");
435  }
436  }
437  }
438  $tplrow->parseCurrentBlock();
439  break;
440  }
441  $tplrow->setCurrentBlock("neutral_answer");
442  $style = array();
443  if ($this->object->getNeutralColumnSeparator())
444  {
445  array_push($style, "border-left: $neutralstyle!important");
446  }
447  if ($this->object->getColumnSeparators() == 1)
448  {
449  if ($j < $this->object->getColumnCount() - 1)
450  {
451  array_push($style, "border-right: 1px solid $bordercolor!important");
452  }
453  }
454 
455  if ($this->object->getRowSeparators() == 1)
456  {
457  if ($i < $this->object->getRowCount() - 1)
458  {
459  array_push($style, "border-bottom: 1px solid $bordercolor!important");
460  }
461  }
462  if (count($style))
463  {
464  $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
465  }
466  $tplrow->parseCurrentBlock();
467  }
468 
469  $tplrow->setVariable("TEXT_ROW", ilUtil::prepareFormOutput($this->object->getRow($i)));
470  $tplrow->setVariable("ROWCLASS", $rowclass[$i % 2]);
471  if ($this->object->getRowSeparators() == 1)
472  {
473  if ($i < $this->object->getRowCount() - 1)
474  {
475  $tplrow->setVariable("STYLE", " style=\"border-bottom: 1px solid $bordercolor!important\"");
476  }
477  }
478  $template->setCurrentBlock("matrix_row");
479  $template->setVariable("ROW", $tplrow->get());
480  $template->parseCurrentBlock();
481  }
482 
483  if ($question_title)
484  {
485  $template->setVariable("QUESTION_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
486  }
487  $template->setCurrentBlock("question_data_matrix");
488  if (strcmp($error_message, "") != 0)
489  {
490  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
491  }
492  if ($show_questiontext)
493  {
494  $questiontext = $this->object->getQuestiontext();
495  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
496  }
497  if (! $this->object->getObligatory())
498  {
499  $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
500  }
501  $template->parseCurrentBlock();
502  return $template->get();
503  }
504 
512  function getPrintView($question_title = 1, $show_questiontext = 1)
513  {
514  $layout = $this->object->getLayout();
515  $neutralstyle = "3px solid #808080";
516  $bordercolor = "#808080";
517  $template = new ilTemplate("tpl.il_svy_qpl_matrix_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
518 
519  if ($this->show_layout_row)
520  {
521  $layout_row = $this->getLayoutRow();
522  $template->setCurrentBlock("matrix_row");
523  $template->setVariable("ROW", $layout_row);
524  $template->parseCurrentBlock();
525  }
526 
527  $tplheaders = new ilTemplate("tpl.il_svy_out_matrix_columnheaders.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
528  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
529  {
530  $tplheaders->setCurrentBlock("bipolar_start");
531  $style = array();
532  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective1"], "%"));
533  if (count($style) > 0)
534  {
535  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
536  }
537  $tplheaders->parseCurrentBlock();
538  }
539  // column headers
540  for ($i = 0; $i < $this->object->getColumnCount(); $i++)
541  {
542  $style = array();
543  if ($this->object->getColumnSeparators() == 1)
544  {
545  if (($i < $this->object->getColumnCount() - 1))
546  {
547  array_push($style, "border-right: 1px solid $bordercolor!important");
548  }
549  }
550  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_columns"] / $this->object->getColumnCount(), "%"));
551  $tplheaders->setCurrentBlock("column_header");
552  $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($this->object->getColumn($i)));
553  $tplheaders->setVariable("CLASS", "center");
554  if (count($style) > 0)
555  {
556  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
557  }
558  $tplheaders->parseCurrentBlock();
559  }
560  if (strlen($this->object->getNeutralColumn()))
561  {
562  $tplheaders->setCurrentBlock("neutral_column_header");
563  $tplheaders->setVariable("TEXT", ilUtil::prepareFormOutput($this->object->getNeutralColumn()));
564  $tplheaders->setVariable("CLASS", "rsep");
565  $style = array();
566  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_neutral"], "%"));
567  if ($this->object->getNeutralColumnSeparator())
568  {
569  array_push($style, "border-left: $neutralstyle!important;");
570  }
571  if (count($style) > 0)
572  {
573  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
574  }
575  $tplheaders->parseCurrentBlock();
576  }
577  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
578  {
579  $tplheaders->setCurrentBlock("bipolar_end");
580  $style = array();
581  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_bipolar_adjective2"], "%"));
582  if (count($style) > 0)
583  {
584  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
585  }
586  $tplheaders->parseCurrentBlock();
587  }
588 
589  $style = array();
590  array_push($style, sprintf("width: %.2f%s!important", $layout["percent_row"], "%"));
591  if (count($style) > 0)
592  {
593  $tplheaders->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
594  }
595 
596  $template->setCurrentBlock("matrix_row");
597  $template->setVariable("ROW", $tplheaders->get());
598  $template->parseCurrentBlock();
599 
600  $rowclass = array("tblrow1", "tblrow2");
601 
602  for ($i = 0; $i < $this->object->getRowCount(); $i++)
603  {
604  $tplrow = new ilTemplate("tpl.il_svy_qpl_matrix_printview_row.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
605  for ($j = 0; $j < $this->object->getColumnCount(); $j++)
606  {
607  if (($i == 0) && ($j == 0))
608  {
609  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
610  {
611  $tplrow->setCurrentBlock("bipolar_start");
612  $tplrow->setVariable("TEXT_BIPOLAR_START", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(0)));
613  $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
614  $tplrow->parseCurrentBlock();
615  }
616  }
617  if (($i == 0) && ($j == $this->object->getColumnCount()-1))
618  {
619  if ((strlen($this->object->getBipolarAdjective(0))) && (strlen($this->object->getBipolarAdjective(1))))
620  {
621  $tplrow->setCurrentBlock("bipolar_end");
622  $tplrow->setVariable("TEXT_BIPOLAR_END", ilUtil::prepareFormOutput($this->object->getBipolarAdjective(1)));
623  $tplrow->setVariable("ROWSPAN", $this->object->getRowCount());
624  $tplrow->parseCurrentBlock();
625  }
626  }
627  switch ($this->object->getSubtype())
628  {
629  case 0:
630  $tplrow->setCurrentBlock("radiobutton");
631  $tplrow->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
632  $tplrow->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
633  $tplrow->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
634  $tplrow->parseCurrentBlock();
635  break;
636  case 1:
637  $tplrow->setCurrentBlock("checkbox");
638  $tplrow->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.gif")));
639  $tplrow->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
640  $tplrow->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
641  $tplrow->parseCurrentBlock();
642  break;
643  }
644  $tplrow->setCurrentBlock("answer");
645  $style = array();
646 
647  if ($this->object->getColumnSeparators() == 1)
648  {
649  if ($j < $this->object->getColumnCount() - 1)
650  {
651  array_push($style, "border-right: 1px solid $bordercolor!important");
652  }
653  }
654 
655  if ($this->object->getRowSeparators() == 1)
656  {
657  if ($i < $this->object->getRowCount() - 1)
658  {
659  array_push($style, "border-bottom: 1px solid $bordercolor!important");
660  }
661  }
662  if (count($style))
663  {
664  $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
665  }
666  $tplrow->parseCurrentBlock();
667  }
668 
669  if (strlen($this->object->getNeutralColumn()))
670  {
671  $j = $this->object->getRowCount();
672  switch ($this->object->getSubtype())
673  {
674  case 0:
675  $tplrow->setCurrentBlock("neutral_radiobutton");
676  $tplrow->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
677  $tplrow->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
678  $tplrow->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
679  $tplrow->parseCurrentBlock();
680  break;
681  case 1:
682  $tplrow->setCurrentBlock("neutral_checkbox");
683  $tplrow->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.gif")));
684  $tplrow->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
685  $tplrow->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
686  $tplrow->parseCurrentBlock();
687  break;
688  }
689  $tplrow->setCurrentBlock("neutral_answer");
690  $style = array();
691  if ($this->object->getNeutralColumnSeparator())
692  {
693  array_push($style, "border-left: $neutralstyle!important");
694  }
695  if ($this->object->getColumnSeparators() == 1)
696  {
697  if ($j < $this->object->getColumnCount() - 1)
698  {
699  array_push($style, "border-right: 1px solid $bordercolor!important");
700  }
701  }
702 
703  if ($this->object->getRowSeparators() == 1)
704  {
705  if ($i < $this->object->getRowCount() - 1)
706  {
707  array_push($style, "border-bottom: 1px solid $bordercolor!important");
708  }
709  }
710  if (count($style))
711  {
712  $tplrow->setVariable("STYLE", " style=\"" . implode(";", $style) . "\"");
713  }
714  $tplrow->parseCurrentBlock();
715  }
716 
717  $tplrow->setVariable("TEXT_ROW", ilUtil::prepareFormOutput($this->object->getRow($i)));
718  $tplrow->setVariable("ROWCLASS", $rowclass[$i % 2]);
719  if ($this->object->getRowSeparators() == 1)
720  {
721  if ($i < $this->object->getRowCount() - 1)
722  {
723  $tplrow->setVariable("STYLE", " style=\"border-bottom: 1px solid $bordercolor!important\"");
724  }
725  }
726  $template->setCurrentBlock("matrix_row");
727  $template->setVariable("ROW", $tplrow->get());
728  $template->parseCurrentBlock();
729  }
730 
731  if ($question_title)
732  {
733  $template->setVariable("QUESTION_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
734  }
735  $template->setCurrentBlock();
736  if ($show_questiontext)
737  {
738  $questiontext = $this->object->getQuestiontext();
739  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
740  }
741  if (! $this->object->getObligatory())
742  {
743  $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
744  }
745  $template->parseCurrentBlock();
746  return $template->get();
747  }
748 
756  function preview()
757  {
758  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", "Modules/SurveyQuestionPool");
759  $question_output = $this->getWorkingForm();
760  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
761  }
762 
770  function layout()
771  {
772  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_layout.html", "Modules/SurveyQuestionPool");
773  $this->show_layout_row = TRUE;
774  $question_output = $this->getWorkingForm();
775  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
776  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "saveLayout"));
777  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
778  }
779 
787  function saveLayout()
788  {
789  $this->object->saveLayout($_POST["percent_row"], $_POST['percent_columns'], $_POST['percent_bipolar_adjective1'], $_POST['percent_bipolar_adjective2'], $_POST["percent_neutral"]);
790  $percent_values = array(
791  "percent_row" => $_POST["percent_row"],
792  "percent_columns" => $_POST["percent_columns"],
793  "percent_bipolar_adjective1" => $_POST['percent_bipolar_adjective1'],
794  "percent_bipolar_adjective2" => $_POST['percent_bipolar_adjective2'],
795  "percent_neutral" => $_POST["percent_neutral"]
796  );
797  $this->object->setLayout($percent_values);
798  $this->layout();
799  }
800 
808  function getLayoutRow()
809  {
810  $percent_values = $this->object->getLayout();
811  $template = new ilTemplate("tpl.il_svy_out_matrix_layout.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
812  if (strlen($this->object->getBipolarAdjective(0)) && strlen($this->object->getBipolarAdjective(1)))
813  {
814  $template->setCurrentBlock("bipolar_start");
815  $template->setVariable("VALUE_PERCENT_BIPOLAR_ADJECTIVE1", " value=\"" . $percent_values["percent_bipolar_adjective1"] . "\"");
816  $template->setVariable("STYLE", " style=\"width:" . $percent_values["percent_bipolar_adjective1"] . "%\"");
817  $template->parseCurrentBlock();
818  $template->setCurrentBlock("bipolar_end");
819  $template->setVariable("VALUE_PERCENT_BIPOLAR_ADJECTIVE2", " value=\"" . $percent_values["percent_bipolar_adjective2"] . "\"");
820  $template->setVariable("STYLE", " style=\"width:" . $percent_values["percent_bipolar_adjective2"] . "%\"");
821  $template->parseCurrentBlock();
822  }
823  if (strlen($this->object->getNeutralColumn()))
824  {
825  $template->setCurrentBlock("bipolar_end");
826  $template->setVariable("VALUE_PERCENT_NEUTRAL", " value=\"" . $percent_values["percent_neutral"] . "\"");
827  $template->setVariable("STYLE_NEUTRAL", " style=\"width:" . $percent_values["percent_neutral"] . "%\"");
828  $template->parseCurrentBlock();
829  }
830  $template->setVariable("VALUE_PERCENT_ROW", " value=\"" . $percent_values["percent_row"] . "\"");
831  $template->setVariable("STYLE_ROW", " style=\"width:" . $percent_values["percent_row"] . "%\"");
832  $counter = $this->object->getColumnCount();
833  $template->setVariable("COLSPAN_COLUMNS", $counter);
834  $template->setVariable("VALUE_PERCENT_COLUMNS", " value=\"" . $percent_values["percent_columns"] . "\"");
835  $template->setVariable("STYLE_COLUMNS", " style=\"width:" . $percent_values["percent_columns"] . "%\"");
836  return $template->get();
837  }
838 
847  function writePostData()
848  {
849  $result = 0;
850  if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"])) $result = 1;
851  if ($result == 1) $this->addErrorMessage($this->lng->txt("fill_out_all_required_fields"));
852  // Set the question id from a hidden form parameter
853  if ($_POST["id"] > 0) $this->object->setId($_POST["id"]);
854  include_once "./Services/Utilities/classes/class.ilUtil.php";
855  $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
856  $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
857  $this->object->setDescription(ilUtil::stripSlashes($_POST["description"]));
858  $this->object->setOrientation($_POST["orientation"]);
859  if (strlen($_POST["material"]))
860  {
861  $this->object->setMaterial($_POST["material"], 0, ilUtil::stripSlashes($_POST["material_title"]));
862  }
863  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
864  $questiontext = ilUtil::stripSlashes($_POST["question"], true, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("survey"));
865  $this->object->setQuestiontext($questiontext);
866  if ($_POST["obligatory"])
867  {
868  $this->object->setObligatory(1);
869  }
870  else
871  {
872  $this->object->setObligatory(0);
873  }
874  $this->object->setSubtype($_POST["subtype"]);
875  $this->object->setRowSeparators(($_POST["row_separators"]) ? 1 : 0);
876  $this->object->setColumnSeparators(($_POST["column_separators"]) ? 1 : 0);
877  $this->object->setNeutralColumnSeparator(($_POST["neutral_column_separator"]) ? 1 : 0);
878 
879  if ($saved)
880  {
881  // If the question was saved automatically before an upload, we have to make
882  // sure, that the state after the upload is saved. Otherwise the user could be
883  // irritated, if he presses cancel, because he only has the question state before
884  // the upload process.
885  $this->object->saveToDb();
886  }
887  return $result;
888  }
889 
897  function moveColumnUp($column)
898  {
899  $complete = $this->writeRowColData();
900  $columntext = $this->object->getColumn($column);
901  $this->object->removeColumn($column);
902  $this->object->addColumnAtPosition($columntext, $column - 1);
903  $_SESSION["spl_modified"] = TRUE;
904  }
905 
913  function moveColumnDown($column)
914  {
915  $complete = $this->writeRowColData();
916  $columntext = $this->object->getColumn($column);
917  $this->object->removeColumn($column);
918  $this->object->addColumnAtPosition($columntext, $column + 1);
919  $_SESSION["spl_modified"] = TRUE;
920  }
921 
929  function categories()
930  {
931  if (count($_POST) == 0) $_SESSION["spl_modified"] = FALSE;
932  if (is_array($_POST))
933  {
934  foreach ($_POST as $key => $value)
935  {
936  if (preg_match("/moveUp_(\d+)_x/", $key, $matches))
937  {
938  $this->moveColumnUp($matches[1]);
939  }
940  if (preg_match("/moveDown_(\d+)_x/", $key, $matches))
941  {
942  $this->moveColumnDown($matches[1]);
943  }
944  }
945  }
946  if ($this->object->getId() < 1)
947  {
948  ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_category"), true);
949  $this->ctrl->redirect($this, "editQuestion");
950  }
951  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_matrix_answers.html", "Modules/SurveyQuestionPool");
952 
953  // check for ordinal columns
954  if ($this->object->getSubtype() == 0)
955  {
956  $this->tpl->setCurrentBlock("ordinal");
957  $this->tpl->setVariable("TEXT_COLUMN_SETTINGS", $this->lng->txt("matrix_column_settings"));
958  $this->tpl->setVariable("TEXT_BIPOLAR_ADJECTIVES", $this->lng->txt("matrix_bipolar_adjectives"));
959  $this->tpl->setVariable("TEXT_BIPOLAR_ADJECTIVES_DESCRIPTION", $this->lng->txt("matrix_bipolar_adjectives_description"));
960  $this->tpl->setVariable("TEXT_ADJECTIVE_1", $this->lng->txt("matrix_adjective") . " 1");
961  $this->tpl->setVariable("TEXT_ADJECTIVE_2", $this->lng->txt("matrix_adjective") . " 2");
962  $this->tpl->setVariable("VALUE_BIPOLAR1", " value=\"" . ilUtil::prepareFormOutput($this->object->getBipolarAdjective(0)) . "\"");
963  $this->tpl->setVariable("VALUE_BIPOLAR2", " value=\"" . ilUtil::prepareFormOutput($this->object->getBipolarAdjective(1)) . "\"");
964  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
965  $this->tpl->parseCurrentBlock();
966  }
967 
968  // create an empty column if nothing is defined
969  if ($this->object->getColumnCount() == 0)
970  {
971  $this->object->addColumn("");
972  }
973  if (strcmp($this->ctrl->getCmd(), "addColumn") == 0)
974  {
975  $nrOfCategories = $_POST["nrOfCategories"];
976  if ($nrOfCategories < 1) $nrOfCategories = 1;
977  // Create template for a new column
978  for ($i = 1; $i <= $nrOfCategories; $i++)
979  {
980  $this->object->addColumn("");
981  }
982  }
983  // output of existing single response answers
984  $hasneutralcolumn = FALSE;
985  for ($i = 0; $i < $this->object->getColumnCount(); $i++)
986  {
987  $column = $this->object->getColumn($i);
988  if ($this->object->getColumnCount() > 1)
989  {
990  if ($i == 0)
991  {
992  $this->tpl->setCurrentBlock("move_down");
993  $this->tpl->setVariable("IMAGE_DOWN", ilUtil::getImagePath("a_down.gif"));
994  $this->tpl->setVariable("ALT_DOWN", $this->lng->txt("move_down"));
995  $this->tpl->setVariable("TITLE_DOWN", $this->lng->txt("move_down"));
996  $this->tpl->setVariable("COLUMN", $i);
997  $this->tpl->parseCurrentBlock();
998  }
999  else if ($i == $this->object->getColumnCount() - 1)
1000  {
1001  $this->tpl->setCurrentBlock("move_up");
1002  $this->tpl->setVariable("IMAGE_UP", ilUtil::getImagePath("a_up.gif"));
1003  $this->tpl->setVariable("ALT_UP", $this->lng->txt("move_up"));
1004  $this->tpl->setVariable("TITLE_UP", $this->lng->txt("move_up"));
1005  $this->tpl->setVariable("COLUMN", $i);
1006  $this->tpl->parseCurrentBlock();
1007  }
1008  else
1009  {
1010  $this->tpl->setCurrentBlock("move_down");
1011  $this->tpl->setVariable("IMAGE_DOWN", ilUtil::getImagePath("a_down.gif"));
1012  $this->tpl->setVariable("ALT_DOWN", $this->lng->txt("move_down"));
1013  $this->tpl->setVariable("TITLE_DOWN", $this->lng->txt("move_down"));
1014  $this->tpl->setVariable("COLUMN", $i);
1015  $this->tpl->parseCurrentBlock();
1016  $this->tpl->setCurrentBlock("move_up");
1017  $this->tpl->setVariable("IMAGE_UP", ilUtil::getImagePath("a_up.gif"));
1018  $this->tpl->setVariable("ALT_UP", $this->lng->txt("move_up"));
1019  $this->tpl->setVariable("TITLE_UP", $this->lng->txt("move_up"));
1020  $this->tpl->setVariable("COLUMN", $i);
1021  $this->tpl->parseCurrentBlock();
1022  }
1023  }
1024  $this->tpl->setCurrentBlock("categories");
1025  $this->tpl->setVariable("CATEGORY_ORDER", $i);
1026  $this->tpl->setVariable("CATEGORY_ORDER", $i);
1027  $this->tpl->setVariable("CATEGORY_NUMBER", $i+1);
1028  $this->tpl->setVariable("VALUE_CATEGORY", $column);
1029  $this->tpl->setVariable("TEXT_CATEGORY", $this->lng->txt("category"));
1030  $this->tpl->parseCurrentBlock();
1031  }
1032 
1033  if (strlen($this->object->getNeutralColumn()))
1034  {
1035  $this->tpl->setVariable("VALUE_NEUTRAL", " value=\"" . ilUtil::prepareFormOutput($this->object->getNeutralColumn()) . "\"");
1036  }
1037  $this->tpl->setVariable("CATEGORY_NEUTRAL", $this->object->getColumnCount() + 1);
1038 
1039  if ($this->object->getRowCount() == 0)
1040  {
1041  $this->object->addRow("");
1042  }
1043  if (strcmp($this->ctrl->getCmd(), "addRow") == 0)
1044  {
1045  $nrOfRows = $_POST["nrOfRows"];
1046  if ($nrOfRows < 1) $nrOfRows = 1;
1047  // Create template for a new column
1048  for ($i = 1; $i <= $nrOfRows; $i++)
1049  {
1050  $this->object->addRow("");
1051  }
1052  }
1053  // output of existing rows
1054  for ($i = 0; $i < $this->object->getRowCount(); $i++)
1055  {
1056  $this->tpl->setCurrentBlock("rows");
1057  $this->tpl->setVariable("ROW_ORDER", $i);
1058  $row = $this->object->getRow($i);
1059  $this->tpl->setVariable("ROW_ORDER", $i);
1060  $this->tpl->setVariable("ROW_NUMBER", $i+1);
1061  $this->tpl->setVariable("VALUE_ROW", $row);
1062  $this->tpl->setVariable("TEXT_ROW", $this->lng->txt("row"));
1063  $this->tpl->parseCurrentBlock();
1064  }
1065 
1066  include_once "./Services/Utilities/classes/class.ilUtil.php";
1067  if ($this->object->getColumnCount() > 0)
1068  {
1069  $this->tpl->setCurrentBlock("selectall");
1070  $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
1071  $this->tpl->parseCurrentBlock();
1072  $this->tpl->setCurrentBlock("existingcategories");
1073  $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
1074  $this->tpl->setVariable("VALUE_SAVE_PHRASE", $this->lng->txt("save_phrase"));
1075  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
1076  $this->tpl->parseCurrentBlock();
1077  }
1078 
1079  if ($this->object->getRowCount() > 0)
1080  {
1081  $this->tpl->setCurrentBlock("selectall_rows");
1082  $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
1083  $this->tpl->parseCurrentBlock();
1084  }
1085 
1086  for ($i = 1; $i < 10; $i++)
1087  {
1088  $this->tpl->setCurrentBlock("numbers");
1089  $this->tpl->setVariable("VALUE_NUMBER", $i);
1090  if ($i == 1)
1091  {
1092  $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("category"));
1093  }
1094  else
1095  {
1096  $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("categories"));
1097  }
1098  $this->tpl->parseCurrentBlock();
1099  $this->tpl->setCurrentBlock("rownumbers");
1100  $this->tpl->setVariable("VALUE_NUMBER", $i);
1101  if ($i == 1)
1102  {
1103  $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("row"));
1104  }
1105  else
1106  {
1107  $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("rows"));
1108  }
1109  $this->tpl->parseCurrentBlock();
1110  }
1111 
1112  $this->tpl->setCurrentBlock("adm_content");
1113  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "categories"));
1114  $this->tpl->setVariable("TEXT_ANSWERS", $this->lng->txt("matrix_columns"));
1115  $this->tpl->setVariable("VALUE_ADD_CATEGORY", $this->lng->txt("add"));
1116  $this->tpl->setVariable("VALUE_ADD_PHRASE", $this->lng->txt("add_phrase"));
1117  $this->tpl->setVariable("TEXT_STANDARD_ANSWERS", $this->lng->txt("matrix_standard_answers"));
1118  $this->tpl->setVariable("TEXT_NEUTRAL_ANSWER", $this->lng->txt("matrix_neutral_answer"));
1119  if (!$hasneutralcolumn)
1120  {
1121  $this->tpl->setVariable("CATEGORY_NEUTRAL", $this->object->getColumnCount()+1);
1122  }
1123  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
1124 
1125  $this->tpl->setVariable("TEXT_ROWS", $this->lng->txt("matrix_rows"));
1126  $this->tpl->setVariable("SAVEROWS", $this->lng->txt("save"));
1127  $this->tpl->setVariable("VALUE_ADD_ROW", $this->lng->txt("add"));
1128  $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
1129  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
1130 
1131  if ($_SESSION["spl_modified"])
1132  {
1133  $this->tpl->setVariable("FORM_DATA_MODIFIED_PRESS_SAVE", $this->lng->txt("form_data_modified_press_save"));
1134  }
1135  $questiontext = $this->object->getQuestiontext();
1136  $this->tpl->setVariable("QUESTION_TEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
1137  $this->tpl->parseCurrentBlock();
1138  }
1139 
1140  function setQuestionTabs()
1141  {
1142  global $rbacsystem,$ilTabs;
1143  $this->ctrl->setParameterByClass("$guiclass", "sel_question_types", $this->getQuestionType());
1144  $this->ctrl->setParameterByClass("$guiclass", "q_id", $_GET["q_id"]);
1145 
1146  if (($_GET["calling_survey"] > 0) || ($_GET["new_for_survey"] > 0))
1147  {
1148  $ref_id = $_GET["calling_survey"];
1149  if (!strlen($ref_id)) $ref_id = $_GET["new_for_survey"];
1150  $addurl = "";
1151  if (strlen($_GET["new_for_survey"]))
1152  {
1153  $addurl = "&new_id=" . $_GET["q_id"];
1154  }
1155  $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), "ilias.php?baseClass=ilObjSurveyGUI&ref_id=$ref_id&cmd=questions" . $addurl);
1156  }
1157  else
1158  {
1159  $ilTabs->setBackTarget($this->lng->txt("spl"), $this->ctrl->getLinkTargetByClass("ilObjSurveyQuestionPoolGUI", "questions"));
1160  }
1161  if ($_GET["q_id"])
1162  {
1163  $ilTabs->addTarget("preview",
1164  $this->ctrl->getLinkTarget($this, "preview"),
1165  array("preview"),
1166  "",
1167  "");
1168 
1169  $ilTabs->addTarget("layout",
1170  $this->ctrl->getLinkTarget($this, "layout"),
1171  array("layout", "saveLayout"),
1172  "",
1173  "");
1174  }
1175  if ($rbacsystem->checkAccess('edit', $_GET["ref_id"]))
1176  {
1177  $ilTabs->addTarget("edit_properties",
1178  $this->ctrl->getLinkTarget($this, "editQuestion"),
1179  array("editQuestion", "cancelExplorer", "linkChilds", "addGIT", "addST",
1180  "addPG", "editQuestion", "addMaterial", "removeMaterial",
1181  "save", "cancel"),
1182  "",
1183  "");
1184  }
1185 
1186  if ($this->object->getId() > 0)
1187  {
1188  $ilTabs->addTarget("matrix_columns_rows",
1189  $this->ctrl->getLinkTarget($this, "categories"),
1190  array("categories", "addColumn", "addRow", "deleteRow", "moveColumn",
1191  "deleteColumn", "saveRowColEditor", "savePhrase", "addPhrase",
1192  "savePhrase", "addSelectedPhrase", "cancelViewPhrase", "confirmSavePhrase",
1193  "cancelSavePhrase", "confirmdeleteColumn", "canceldeleteColumn"),
1194  "",
1195  ""
1196  );
1197  }
1198 
1199  if ($this->object->getId() > 0)
1200  {
1201  $title = $this->lng->txt("edit") . " &quot;" . $this->object->getTitle() . "&quot";
1202  }
1203  else
1204  {
1205  $title = $this->lng->txt("create_new") . " " . $this->lng->txt($this->getQuestionType());
1206  }
1207 
1208  $this->tpl->setVariable("HEADER", $title);
1209  }
1210 
1218  function addPhrase()
1219  {
1220  $complete = $this->writeRowColData(true);
1221  $this->ctrl->setParameterByClass(get_class($this), "q_id", $this->object->getId());
1222  $this->ctrl->setParameterByClass("ilobjsurveyquestionpoolgui", "q_id", $this->object->getId());
1223 
1224  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase.html", "Modules/SurveyQuestionPool");
1225 
1226  // set the id to return to the selected question
1227  $this->tpl->setCurrentBlock("hidden");
1228  $this->tpl->setVariable("HIDDEN_NAME", "id");
1229  $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
1230  $this->tpl->parseCurrentBlock();
1231 
1232  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyPhrases.php";
1234  $colors = array("tblrow1", "tblrow2");
1235  $counter = 0;
1236  foreach ($phrases as $phrase_id => $phrase_array)
1237  {
1238  $this->tpl->setCurrentBlock("phraserow");
1239  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter++ % 2]);
1240  $this->tpl->setVariable("PHRASE_VALUE", $phrase_id);
1241  $this->tpl->setVariable("PHRASE_NAME", $phrase_array["title"]);
1243  $this->tpl->setVariable("PHRASE_CONTENT", join($columns, ","));
1244  $this->tpl->parseCurrentBlock();
1245  }
1246 
1247  $this->tpl->setCurrentBlock("adm_content");
1248  $this->tpl->setVariable("TEXT_CANCEL", $this->lng->txt("cancel"));
1249  $this->tpl->setVariable("TEXT_PHRASE", $this->lng->txt("phrase"));
1250  $this->tpl->setVariable("TEXT_CONTENT", $this->lng->txt("categories"));
1251  $this->tpl->setVariable("TEXT_ADD_PHRASE", $this->lng->txt("add_phrase"));
1252  $this->tpl->setVariable("TEXT_INTRODUCTION",$this->lng->txt("add_phrase_introduction"));
1253  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "addPhrase"));
1254  $this->tpl->parseCurrentBlock();
1255  }
1256 
1264  function cancelViewPhrase()
1265  {
1266  $this->ctrl->redirect($this, "categories");
1267  }
1268 
1276  function addSelectedPhrase()
1277  {
1278  if (strcmp($_POST["phrases"], "") == 0)
1279  {
1280  ilUtil::sendInfo($this->lng->txt("select_phrase_to_add"));
1281  $this->addPhrase();
1282  }
1283  else
1284  {
1285  if (strcmp($this->object->getPhrase($_POST["phrases"]), "dp_standard_numbers") != 0)
1286  {
1287  $this->object->addPhrase($_POST["phrases"]);
1288  $this->object->saveColumnsToDb();
1289  }
1290  else
1291  {
1292  $this->addStandardNumbers();
1293  return;
1294  }
1295  $this->ctrl->redirect($this, "categories");
1296  }
1297  }
1298 
1307  {
1308  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase_standard_numbers.html", "Modules/SurveyQuestionPool");
1309 
1310  // set the id to return to the selected question
1311  $this->tpl->setCurrentBlock("hidden");
1312  $this->tpl->setVariable("HIDDEN_NAME", "id");
1313  $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
1314  $this->tpl->parseCurrentBlock();
1315 
1316  $this->tpl->setCurrentBlock("adm_content");
1317  $this->tpl->setVariable("ADD_STANDARD_NUMBERS", $this->lng->txt("add_standard_numbers"));
1318  $this->tpl->setVariable("TEXT_ADD_LIMITS", $this->lng->txt("add_limits_for_standard_numbers"));
1319  $this->tpl->setVariable("TEXT_LOWER_LIMIT",$this->lng->txt("lower_limit"));
1320  $this->tpl->setVariable("TEXT_UPPER_LIMIT",$this->lng->txt("upper_limit"));
1321  $this->tpl->setVariable("VALUE_LOWER_LIMIT", $_POST["lower_limit"]);
1322  $this->tpl->setVariable("VALUE_UPPER_LIMIT", $_POST["upper_limit"]);
1323  $this->tpl->setVariable("BTN_ADD",$this->lng->txt("add_phrase"));
1324  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
1325  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "addStandardNumbers"));
1326  $this->tpl->parseCurrentBlock();
1327  }
1328 
1337  {
1338  $this->ctrl->redirect($this, "categories");
1339  }
1340 
1349  {
1350  if ((strcmp($_POST["lower_limit"], "") == 0) or (strcmp($_POST["upper_limit"], "") == 0))
1351  {
1352  ilUtil::sendInfo($this->lng->txt("missing_upper_or_lower_limit"));
1353  $this->addStandardNumbers();
1354  }
1355  else if ((int)$_POST["upper_limit"] <= (int)$_POST["lower_limit"])
1356  {
1357  ilUtil::sendInfo($this->lng->txt("upper_limit_must_be_greater"));
1358  $this->addStandardNumbers();
1359  }
1360  else
1361  {
1362  $this->object->addStandardNumbers($_POST["lower_limit"], $_POST["upper_limit"]);
1363  $this->object->saveColumnsToDb();
1364  $this->ctrl->redirect($this, "categories");
1365  }
1366  }
1367 
1375  function savePhrase()
1376  {
1377  $complete = $this->writeRowColData(true);
1378  if (!$complete)
1379  {
1380  $_SESSION["spl_modified"] = TRUE;
1381  ilUtil::sendInfo($this->errormessage);
1382  return $this->categories();
1383  }
1384  $nothing_selected = true;
1385  if (array_key_exists("chb_category", $_POST))
1386  {
1387  if (count($_POST["chb_category"]))
1388  {
1389  $nothing_selected = false;
1390  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_savephrase.html", "Modules/SurveyQuestionPool");
1391  $rowclass = array("tblrow1", "tblrow2");
1392  $counter = 0;
1393  foreach ($_POST["chb_category"] as $column)
1394  {
1395  $this->tpl->setCurrentBlock("row");
1396  $this->tpl->setVariable("TXT_TITLE", $this->object->getColumn($column));
1397  $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
1398  $this->tpl->parseCurrentBlock();
1399  $this->tpl->setCurrentBlock("hidden");
1400  $this->tpl->setVariable("HIDDEN_NAME", "chb_category[]");
1401  $this->tpl->setVariable("HIDDEN_VALUE", $column["title"]);
1402  $this->tpl->parseCurrentBlock();
1403  }
1404 
1405  $this->tpl->setCurrentBlock("adm_content");
1406  $this->tpl->setVariable("SAVE_PHRASE_INTRODUCTION", $this->lng->txt("save_phrase_introduction"));
1407  $this->tpl->setVariable("TEXT_PHRASE_TITLE", $this->lng->txt("enter_phrase_title"));
1408  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("category"));
1409  $this->tpl->setVariable("VALUE_PHRASE_TITLE", $_POST["phrase_title"]);
1410  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
1411  $this->tpl->setVariable("BTN_CONFIRM",$this->lng->txt("confirm"));
1412  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "savePhrase"));
1413  $this->tpl->parseCurrentBlock();
1414  }
1415  }
1416  if ($nothing_selected)
1417  {
1418  ilUtil::sendInfo($this->lng->txt("check_category_to_save_phrase"), true);
1419  $this->ctrl->redirect($this, "categories");
1420  }
1421  }
1422 
1430  function cancelSavePhrase()
1431  {
1432  $this->ctrl->redirect($this, "categories");
1433  }
1434 
1442  function confirmSavePhrase()
1443  {
1444  if (!$_POST["phrase_title"])
1445  {
1446  ilUtil::sendInfo($this->lng->txt("qpl_savephrase_empty"));
1447  $this->savePhrase();
1448  return;
1449  }
1450 
1451  if ($this->object->phraseExists($_POST["phrase_title"]))
1452  {
1453  ilUtil::sendInfo($this->lng->txt("qpl_savephrase_exists"));
1454  $this->savePhrase();
1455  return;
1456  }
1457 
1458  $this->object->savePhrase($_POST["chb_category"], $_POST["phrase_title"]);
1459  ilUtil::sendInfo($this->lng->txt("phrase_saved"), true);
1460  $this->ctrl->redirect($this, "categories");
1461  }
1462 
1470  function addColumn()
1471  {
1472  $result = $this->writeRowColData();
1473  $_SESSION["spl_modified"] = true;
1474  $this->categories();
1475  }
1476 
1477 
1485  function addRow()
1486  {
1487  $this->addColumn();
1488  }
1489 
1498  function writeRowColData($save = FALSE)
1499  {
1500  // Delete all existing columns and create new columns from the form data
1501  $this->object->flushColumns();
1502  $this->object->flushRows();
1503  $columnscomplete = TRUE;
1504  $rowscomplete = TRUE;
1505  // Add standard columns and rows
1506  include_once "./Services/Utilities/classes/class.ilUtil.php";
1507  $cats = "";
1508  $rows = "";
1509  foreach ($_POST as $key => $value)
1510  {
1511  if (preg_match("/^category_(\d+)/", $key, $matches))
1512  {
1513  $this->object->addColumn(ilUtil::stripSlashes($value));
1514  $cats .= $value;
1515  }
1516  if (preg_match("/^row_(\d+)/", $key, $matches))
1517  {
1518  $this->object->addRow(ilUtil::stripSlashes($value));
1519  $rows .= $value;
1520  }
1521  }
1522 
1523  if (strlen($cats) == 0)
1524  {
1525  $columnscomplete = FALSE;
1526  $this->addErrorMessage($this->lng->txt("matrix_error_no_columns"));
1527  }
1528  if (strlen($rows) == 0)
1529  {
1530  $rowscomplete = FALSE;
1531  $this->addErrorMessage($this->lng->txt("matrix_error_no_rows"));
1532  }
1533 
1534  // Set neutral column
1535  $this->object->setNeutralColumn(ilUtil::stripSlashes($_POST["neutral"]));
1536 
1537  // Set bipolar adjectives
1538  $this->object->setBipolarAdjective(0, ilUtil::stripSlashes($_POST["bipolar1"]));
1539  $this->object->setBipolarAdjective(1, ilUtil::stripSlashes($_POST["bipolar2"]));
1540 
1541  if ($save)
1542  {
1543  $this->object->saveColumnsToDb();
1544  $this->object->saveRowsToDb();
1545  if (array_key_exists("bipolar1", $_POST))
1546  {
1547  $this->object->saveBipolarAdjectives(ilUtil::stripSlashes($_POST["bipolar1"]), ilUtil::stripSlashes($_POST["bipolar2"]));
1548  }
1549  }
1550 
1551  return $columnscomplete && $rowscomplete;
1552  }
1553 
1561  function saveRowColEditor()
1562  {
1563  global $ilUser;
1564 
1565  $complete = $this->writeRowColData(true);
1566  if (!$complete)
1567  {
1568  $_SESSION["spl_modified"] = TRUE;
1569  $this->categories();
1570  }
1571  else
1572  {
1573  $_SESSION["spl_modified"] = FALSE;
1574  ilUtil::sendInfo($this->lng->txt("saved_successfully"), true);
1575  $originalexists = $this->object->_questionExists($this->object->original_id);
1576  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
1577  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1578  if ($_GET["calling_survey"] && $originalexists && SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
1579  {
1580  $this->originalSyncForm();
1581  return;
1582  }
1583  else
1584  {
1585  $this->ctrl->redirect($this, "categories");
1586  }
1587  }
1588  }
1589 
1597  function deleteColumn()
1598  {
1599  $this->writeRowColData();
1600  $nothing_selected = true;
1601  if (array_key_exists("chb_category", $_POST))
1602  {
1603  if (count($_POST["chb_category"]))
1604  {
1605  $nothing_selected = false;
1606  $this->object->removeColumns($_POST["chb_category"]);
1607  }
1608  }
1609  if ($nothing_selected)
1610  {
1611  ilUtil::sendInfo($this->lng->txt("matrix_column_delete_select_none"));
1612  }
1613  else
1614  {
1615  $_SESSION["spl_modified"] = true;
1616  }
1617  $this->categories();
1618  }
1619 
1627  function deleteRow()
1628  {
1629  $this->writeRowColData();
1630  $nothing_selected = true;
1631  if (array_key_exists("chb_row", $_POST))
1632  {
1633  if (count($_POST["chb_row"]))
1634  {
1635  $nothing_selected = false;
1636  $this->object->removeRows($_POST["chb_row"]);
1637  }
1638  }
1639  if ($nothing_selected)
1640  {
1641  ilUtil::sendInfo($this->lng->txt("matrix_row_delete_select_none"));
1642  }
1643  else
1644  {
1645  $_SESSION["spl_modified"] = true;
1646  }
1647  $this->categories();
1648  }
1649 
1658  function getCumulatedResultRow($counter, $css_class, $survey_id)
1659  {
1660  $output = "";
1661  include_once "./classes/class.ilTemplate.php";
1662  if (count($this->cumulated) == 0)
1663  {
1664  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
1665  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
1666  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
1667  }
1668  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_row.html", TRUE, TRUE, "Modules/Survey");
1669  $template->setVariable("QUESTION_TITLE", ($counter+1) . ". ".$this->object->getTitle());
1670  $maxlen = 37;
1671  $questiontext = preg_replace("/<[^>]+?>/ims", "", $this->object->getQuestiontext());
1672  if (strlen($questiontext) > $maxlen + 3)
1673  {
1674  $questiontext = substr($questiontext, 0, $maxlen) . "...";
1675  }
1676  $template->setVariable("QUESTION_TEXT", $questiontext);
1677  $template->setVariable("USERS_ANSWERED", $this->cumulated["TOTAL"]["USERS_ANSWERED"]);
1678  $template->setVariable("USERS_SKIPPED", $this->cumulated["TOTAL"]["USERS_SKIPPED"]);
1679  $template->setVariable("QUESTION_TYPE", $this->lng->txt($this->cumulated["TOTAL"]["QUESTION_TYPE"]));
1680  $template->setVariable("MODE", $this->cumulated["TOTAL"]["MODE"]);
1681  $template->setVariable("MODE_NR_OF_SELECTIONS", $this->cumulated["TOTAL"]["MODE_NR_OF_SELECTIONS"]);
1682  $template->setVariable("MEDIAN", $this->cumulated["TOTAL"]["MEDIAN"]);
1683  $template->setVariable("ARITHMETIC_MEAN", $this->cumulated["TOTAL"]["ARITHMETIC_MEAN"]);
1684  $template->setVariable("COLOR_CLASS", $css_class);
1685  $output = $template->get();
1686  foreach ($this->cumulated as $key => $value)
1687  {
1688  if (is_numeric($key))
1689  {
1690  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_row_matrix.html", TRUE, TRUE, "Modules/Survey");
1691  $template->setVariable("QUESTION_TITLE", "");
1692  $template->setVariable("ROW", ($key+1) . ". " . $value["ROW"]);
1693  $template->setVariable("USERS_ANSWERED", $value["USERS_ANSWERED"]);
1694  $template->setVariable("USERS_SKIPPED", $value["USERS_SKIPPED"]);
1695  $template->setVariable("MODE", $value["MODE"]);
1696  $template->setVariable("MODE_NR_OF_SELECTIONS", $value["MODE_NR_OF_SELECTIONS"]);
1697  $template->setVariable("MEDIAN", $value["MEDIAN"]);
1698  $template->setVariable("ARITHMETIC_MEAN", $value["ARITHMETIC_MEAN"]);
1699  $template->setVariable("COLOR_CLASS", $css_class);
1700  $output .= $template->get();
1701  }
1702  }
1703  return $output;
1704  }
1705 
1716  function getCumulatedResultsDetails($survey_id, $counter)
1717  {
1718  if (count($this->cumulated) == 0)
1719  {
1720  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
1721  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
1722  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
1723  }
1724 
1725  $output = "";
1726  include_once "./classes/class.ilTemplate.php";
1727  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
1728 
1729  $template->setCurrentBlock("detail_row");
1730  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
1731  $questiontext = $this->object->getQuestiontext();
1732  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
1733  $template->parseCurrentBlock();
1734  $template->setCurrentBlock("detail_row");
1735  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
1736  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
1737  $template->parseCurrentBlock();
1738  $template->setCurrentBlock("detail_row");
1739  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
1740  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["USERS_ANSWERED"]);
1741  $template->parseCurrentBlock();
1742  $template->setCurrentBlock("detail_row");
1743  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
1744  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["USERS_SKIPPED"]);
1745  $template->parseCurrentBlock();
1746 
1747  $template->setCurrentBlock("detail_row");
1748  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
1749  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["MODE"]);
1750  $template->parseCurrentBlock();
1751  $template->setCurrentBlock("detail_row");
1752  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
1753  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["MODE_NR_OF_SELECTIONS"]);
1754  $template->parseCurrentBlock();
1755  $template->setCurrentBlock("detail_row");
1756  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
1757  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["TOTAL"]["MEDIAN"]);
1758  $template->parseCurrentBlock();
1759 
1760  $template->setCurrentBlock("detail_row");
1761  $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
1762  $columns = "";
1763  foreach ($this->cumulated["TOTAL"]["variables"] as $key => $value)
1764  {
1765  $columns .= "<li>" . $this->lng->txt("title") . ":" . "<span class=\"bold\">" . $value["title"] . "</span><br />" .
1766  $this->lng->txt("category_nr_selected") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
1767  $this->lng->txt("percentage_of_selections") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
1768  }
1769  $columns = "<ol>$columns</ol>";
1770  $template->setVariable("TEXT_OPTION_VALUE", $columns);
1771  $template->parseCurrentBlock();
1772 
1773  foreach ($this->cumulated as $key => $value)
1774  {
1775  if (is_numeric($key))
1776  {
1777  $template->setCurrentBlock("detail_row");
1778  $template->setVariable("TEXT_OPTION", $this->lng->txt("row"));
1779  $questiontext = $value["ROW"];
1780  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
1781  $template->parseCurrentBlock();
1782  $template->setCurrentBlock("detail_row");
1783  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
1784  $template->setVariable("TEXT_OPTION_VALUE", $value["USERS_ANSWERED"]);
1785  $template->parseCurrentBlock();
1786  $template->setCurrentBlock("detail_row");
1787  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
1788  $template->setVariable("TEXT_OPTION_VALUE", $value["USERS_SKIPPED"]);
1789  $template->parseCurrentBlock();
1790 
1791  $template->setCurrentBlock("detail_row");
1792  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
1793  $template->setVariable("TEXT_OPTION_VALUE", $value["MODE"]);
1794  $template->parseCurrentBlock();
1795  $template->setCurrentBlock("detail_row");
1796  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
1797  $template->setVariable("TEXT_OPTION_VALUE", $value["MODE_NR_OF_SELECTIONS"]);
1798  $template->parseCurrentBlock();
1799  $template->setCurrentBlock("detail_row");
1800  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
1801  $template->setVariable("TEXT_OPTION_VALUE", $value["MEDIAN"]);
1802  $template->parseCurrentBlock();
1803 
1804  $template->setCurrentBlock("detail_row");
1805  $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
1806  $columns = "";
1807  foreach ($value["variables"] as $key => $value)
1808  {
1809  $columns .= "<li>" . $this->lng->txt("title") . ":" . "<span class=\"bold\">" . $value["title"] . "</span><br />" .
1810  $this->lng->txt("category_nr_selected") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
1811  $this->lng->txt("percentage_of_selections") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
1812  }
1813  $columns = "<ol>$columns</ol>";
1814  $template->setVariable("TEXT_OPTION_VALUE", $columns);
1815  $template->parseCurrentBlock();
1816  }
1817  }
1818 
1819  // display chart for matrix question for array $eval["variables"]
1820  foreach ($this->cumulated as $key => $value)
1821  {
1822  if (is_numeric($key))
1823  {
1824  $template->setCurrentBlock("chartimage");
1825 
1826  $charturl = "";
1827  include_once "./Services/Administration/classes/class.ilSetting.php";
1828  $surveySetting = new ilSetting("survey");
1829  if ($surveySetting->get("googlechart") == 1)
1830  {
1831  $chartcolors = array("2A4BD7", "9DAFFF", "1D6914", "81C57A", "814A19", "E9DEBB", "8126C0", "AD2323", "29D0D0", "FFEE33", "FF9233", "FFCDF3", "A0A0A0", "575757", "000000");
1832  $selections = array();
1833  $values = array();
1834  $maxselection = 0;
1835  foreach ($value["variables"] as $val)
1836  {
1837  if ($val["selected"] > $maxselection) $maxselection = $val["selected"];
1838  array_push($selections, $val["selected"]);
1839  array_push($values, str_replace(" ", "+", $val["title"]));
1840  }
1841  $chartwidth = 800;
1842  $selectionlabels = "";
1843  if ($maxselection % 2 == 0)
1844  {
1845  $selectionlabels = "0|" . ($maxselection / 2) . "|$maxselection";
1846  }
1847  else
1848  {
1849  $selectionlabels = "0|$maxselection";
1850  }
1851  $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)+1.5)) . "&chdl=" . implode("|", $values) . "&chdlp=b";
1852  }
1853  else
1854  {
1855  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "type", $key);
1856  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "survey", $survey_id);
1857  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "question", $this->object->getId());
1858  $charturl = $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "outChart");
1859  }
1860  $template->setVariable("CHART", $charturl);
1861  $template->setVariable("ALT_CHART", $this->lng->txt("chart"));
1862  $template->parseCurrentBlock();
1863  }
1864  }
1865  $template->setCurrentBlock("chart");
1866  $template->setVariable("TEXT_CHART", $this->lng->txt("chart"));
1867  $template->parseCurrentBlock();
1868 
1869  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
1870  $output = $template->get();
1871  return $output;
1872  }
1873 
1874 }
1875 ?>