ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyNominalQuestionGUI.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
25 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
26 
39 {
40 
50  $id = -1
51  )
52 
53  {
54  $this->SurveyQuestionGUI();
55  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyNominalQuestion.php";
56  $this->object = new SurveyNominalQuestion();
57  if ($id >= 0)
58  {
59  $this->object->loadFromDb($id);
60  }
61  }
62 
70  function editQuestion()
71  {
72  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_nominal.html", "Modules/SurveyQuestionPool");
73  $this->tpl->addBlockFile("OTHER_QUESTION_DATA", "other_question_data", "tpl.il_svy_qpl_other_question_data.html", "Modules/SurveyQuestionPool");
74  $this->tpl->setVariable("TEXT_ORIENTATION", $this->lng->txt("orientation"));
75  switch ($this->object->getOrientation())
76  {
77  case 0:
78  $this->tpl->setVariable("CHECKED_VERTICAL", " checked=\"checked\"");
79  break;
80  case 1:
81  $this->tpl->setVariable("CHECKED_HORIZONTAL", " checked=\"checked\"");
82  break;
83  case 2:
84  $this->tpl->setVariable("CHECKED_COMBOBOX", " checked=\"checked\"");
85  break;
86  }
87  $this->tpl->setVariable("TXT_VERTICAL", $this->lng->txt("vertical"));
88  $this->tpl->setVariable("TXT_HORIZONTAL", $this->lng->txt("horizontal"));
89  if ($this->object->getSubtype() == SUBTYPE_MCSR)
90  {
91  $this->tpl->setVariable("TXT_COMBOBOX", $this->lng->txt("combobox"));
92  }
93 
94  $internallinks = array(
95  "lm" => $this->lng->txt("obj_lm"),
96  "st" => $this->lng->txt("obj_st"),
97  "pg" => $this->lng->txt("obj_pg"),
98  "glo" => $this->lng->txt("glossary_term")
99  );
100  foreach ($internallinks as $key => $value)
101  {
102  $this->tpl->setCurrentBlock("internallink");
103  $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
104  $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
105  $this->tpl->parseCurrentBlock();
106  }
107 
108  $this->tpl->setCurrentBlock("adm_content");
109  $this->tpl->setVariable("TEXT_MATERIAL", $this->lng->txt("material"));
110  if (count($this->object->material))
111  {
112  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
113  $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
114  $this->tpl->setVariable("TEXT_VALUE_MATERIAL", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("material"). "</a> ");
115  $this->tpl->setVariable("BUTTON_REMOVE_MATERIAL", $this->lng->txt("remove"));
116  $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("change"));
117  $this->tpl->setVariable("VALUE_MATERIAL", $this->object->material["internal_link"]);
118  $this->tpl->setVariable("VALUE_MATERIAL_TITLE", $this->object->material["title"]);
119  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
120  }
121  else
122  {
123  $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("add"));
124  }
125  $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
126  $this->tpl->setVariable("VALUE_TITLE", $this->object->getTitle());
127  $this->tpl->setVariable("VALUE_DESCRIPTION", $this->object->getDescription());
128  $this->tpl->setVariable("VALUE_AUTHOR", $this->object->getAuthor());
129  $questiontext = $this->object->getQuestiontext();
130  $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
131  $this->tpl->setVariable("TXT_SR", $this->lng->txt("multiple_choice_single_response"));
132  $this->tpl->setVariable("TXT_MR", $this->lng->txt("multiple_choice_multiple_response"));
133  $this->tpl->setVariable("TEXT_SUBTYPE", $this->lng->txt("subtype"));
134  $this->tpl->setVariable("DESCRIPTION_QUESTION_TYPE", $this->lng->txt("multiple_choice_subtype_description"));
135  if ($this->object->getSubtype() == SUBTYPE_MCSR)
136  {
137  $this->tpl->setVariable("CHECKED_SR", " checked=\"checked\"");
138  }
139  else
140  {
141  $this->tpl->setVariable("CHECKED_MR", " checked=\"checked\"");
142  }
143  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
144  $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
145  $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
146  $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
147  $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("questiontype"));
148  $this->tpl->setVariable("TEXT_OBLIGATORY", $this->lng->txt("obligatory"));
149  if ($this->object->getObligatory())
150  {
151  $this->tpl->setVariable("CHECKED_OBLIGATORY", " checked=\"checked\"");
152  }
153  $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
154  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
155  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
156  $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt($this->getQuestionType()));
157  $this->tpl->parseCurrentBlock();
158  include_once "./Services/RTE/classes/class.ilRTE.php";
159  $rtestring = ilRTE::_getRTEClassname();
160  include_once "./Services/RTE/classes/class.$rtestring.php";
161  $rte = new $rtestring();
162  $rte->addPlugin("latex");
163  $rte->addButton("latex"); $rte->addButton("pastelatex");
164  $rte->removePlugin("ibrowser");
165  include_once "./classes/class.ilObject.php";
166  $obj_id = $_GET["q_id"];
167  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
168  $rte->addRTESupport($obj_id, $obj_type, "survey");
169 
171  }
172 
180  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
181  {
182  $template = new ilTemplate("tpl.il_svy_out_nominal.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
183  if (count($this->object->material))
184  {
185  $template->setCurrentBlock("material_nominal");
186  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
187  $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
188  $template->setVariable("TEXT_MATERIAL", $this->lng->txt("material") . ": <a href=\"$href\" target=\"content\">" . $this->object->material["title"]. "</a> ");
189  $template->parseCurrentBlock();
190  }
191  switch ($this->object->getOrientation())
192  {
193  case 0:
194  // vertical orientation
195  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++) {
196  $category = $this->object->categories->getCategory($i);
197  if ($this->object->getSubtype() == SUBTYPE_MCSR)
198  {
199  $template->setCurrentBlock("nominal_row_sr");
200  $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
201  $template->setVariable("VALUE_NOMINAL", $i);
202  $template->setVariable("QUESTION_ID", $this->object->getId());
203  if (is_array($working_data))
204  {
205  foreach ($working_data as $value)
206  {
207  if (strlen($value["value"]))
208  {
209  if ($value["value"] == $i)
210  {
211  $template->setVariable("CHECKED_NOMINAL", " checked=\"checked\"");
212  }
213  }
214  }
215  }
216  $template->parseCurrentBlock();
217  }
218  else
219  {
220  $template->setCurrentBlock("nominal_row_mr");
221  $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
222  $template->setVariable("VALUE_NOMINAL", $i);
223  $template->setVariable("QUESTION_ID", $this->object->getId());
224  if (is_array($working_data))
225  {
226  foreach ($working_data as $value)
227  {
228  if (strlen($value["value"]))
229  {
230  if ($value["value"] == $i)
231  {
232  $template->setVariable("CHECKED_NOMINAL", " checked=\"checked\"");
233  }
234  }
235  }
236  }
237  $template->parseCurrentBlock();
238  }
239  }
240  break;
241  case 1:
242  // horizontal orientation
243  if ($this->object->getSubtype() == SUBTYPE_MCSR)
244  {
245  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
246  {
247  $category = $this->object->categories->getCategory($i);
248  $template->setCurrentBlock("radio_col_nominal");
249  $template->setVariable("VALUE_NOMINAL", $i);
250  $template->setVariable("QUESTION_ID", $this->object->getId());
251  if (is_array($working_data))
252  {
253  foreach ($working_data as $value)
254  {
255  if (strlen($value["value"]))
256  {
257  if ($value["value"] == $i)
258  {
259  $template->setVariable("CHECKED_NOMINAL", " checked=\"checked\"");
260  }
261  }
262  }
263  }
264  $template->parseCurrentBlock();
265  }
266  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
267  {
268  $category = $this->object->categories->getCategory($i);
269  $template->setCurrentBlock("text_col_nominal");
270  $template->setVariable("VALUE_NOMINAL", $i);
271  $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
272  $template->setVariable("QUESTION_ID", $this->object->getId());
273  $template->parseCurrentBlock();
274  }
275  }
276  else
277  {
278  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
279  {
280  $category = $this->object->categories->getCategory($i);
281  $template->setCurrentBlock("checkbox_col_nominal");
282  $template->setVariable("VALUE_NOMINAL", $i);
283  $template->setVariable("QUESTION_ID", $this->object->getId());
284  if (is_array($working_data))
285  {
286  foreach ($working_data as $value)
287  {
288  if (strlen($value["value"]))
289  {
290  if ($value["value"] == $i)
291  {
292  $template->setVariable("CHECKED_NOMINAL", " checked=\"checked\"");
293  }
294  }
295  }
296  }
297  $template->parseCurrentBlock();
298  }
299  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
300  {
301  $category = $this->object->categories->getCategory($i);
302  $template->setCurrentBlock("text_col_nominal_mr");
303  $template->setVariable("VALUE_NOMINAL", $i);
304  $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
305  $template->setVariable("QUESTION_ID", $this->object->getId());
306  $template->parseCurrentBlock();
307  }
308  }
309  break;
310  case 2:
311  // combobox output
312  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
313  {
314  $category = $this->object->categories->getCategory($i);
315  $template->setCurrentBlock("comborow_nominal");
316  $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
317  $template->setVariable("VALUE_NOMINAL", $i);
318  if (is_array($working_data))
319  {
320  foreach ($working_data as $value)
321  {
322  if (strlen($value["value"]))
323  {
324  if ($value["value"] == $i)
325  {
326  $template->setVariable("SELECTED_NOMINAL", " selected=\"selected\"");
327  }
328  }
329  }
330  }
331  $template->parseCurrentBlock();
332  }
333  $template->setCurrentBlock("combooutput_nominal");
334  $template->setVariable("QUESTION_ID", $this->object->getId());
335  $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
336  $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
337  $template->parseCurrentBlock();
338  break;
339  }
340 
341  $template->setCurrentBlock("question_data_nominal");
342  if (strcmp($error_message, "") != 0)
343  {
344  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
345  }
346  if ($show_questiontext)
347  {
348  $questiontext = $this->object->getQuestiontext();
349  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
350  }
351  if (!$this->object->getObligatory($survey_id))
352  {
353  $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
354  }
355  if ($question_title)
356  {
357  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
358  }
359  $template->parseCurrentBlock();
360  return $template->get();
361  }
362 
370  function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
371  {
372  $template = new ilTemplate("tpl.il_svy_qpl_nominal_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
373  switch ($this->object->getOrientation())
374  {
375  case 0:
376  // vertical orientation
377  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++) {
378  $category = $this->object->categories->getCategory($i);
379  if ($this->object->getSubtype() == SUBTYPE_MCSR)
380  {
381  $template->setCurrentBlock("nominal_row_sr");
382  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
383  $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
384  $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
385  $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
386  $template->parseCurrentBlock();
387  }
388  else
389  {
390  $template->setCurrentBlock("nominal_row_mr");
391  $template->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.gif")));
392  $template->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
393  $template->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
394  $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
395  $template->parseCurrentBlock();
396  }
397  }
398  break;
399  case 1:
400  // horizontal orientation
401  if ($this->object->getSubtype() == SUBTYPE_MCSR)
402  {
403  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
404  {
405  $category = $this->object->categories->getCategory($i);
406  $template->setCurrentBlock("radio_col_nominal");
407  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
408  $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
409  $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
410  $template->parseCurrentBlock();
411  }
412  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
413  {
414  $category = $this->object->categories->getCategory($i);
415  $template->setCurrentBlock("text_col_nominal");
416  $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
417  $template->parseCurrentBlock();
418  }
419  }
420  else
421  {
422  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
423  {
424  $category = $this->object->categories->getCategory($i);
425  $template->setCurrentBlock("checkbox_col_nominal");
426  $template->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.gif")));
427  $template->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
428  $template->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
429  $template->parseCurrentBlock();
430  }
431  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
432  {
433  $category = $this->object->categories->getCategory($i);
434  $template->setCurrentBlock("text_col_nominal_mr");
435  $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
436  $template->parseCurrentBlock();
437  }
438  }
439  break;
440  case 2:
441  // combobox output
442  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
443  {
444  $category = $this->object->categories->getCategory($i);
445  $template->setCurrentBlock("comborow_nominal");
446  $template->setVariable("TEXT_NOMINAL", ilUtil::prepareFormOutput($category));
447  $template->setVariable("VALUE_NOMINAL", $i);
448  $template->parseCurrentBlock();
449  }
450  $template->setCurrentBlock("combooutput_nominal");
451  $template->setVariable("QUESTION_ID", $this->object->getId());
452  $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
453  $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
454  $template->parseCurrentBlock();
455  break;
456  }
457 
458  if ($show_questiontext)
459  {
460  $questiontext = $this->object->getQuestiontext();
461  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
462  }
463  if (! $this->object->getObligatory($survey_id))
464  {
465  $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
466  }
467  if ($question_title)
468  {
469  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
470  }
471  $template->parseCurrentBlock();
472  return $template->get();
473  }
474 
482  function preview()
483  {
484  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", "Modules/SurveyQuestionPool");
485  $question_output = $this->getWorkingForm();
486  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
487  }
488 
497  function writePostData()
498  {
499  $result = 0;
500  if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"])) $result = 1;
501  if ($result == 1) $this->addErrorMessage($this->lng->txt("fill_out_all_required_fields"));
502  // Set the question id from a hidden form parameter
503  if ($_POST["id"] > 0) $this->object->setId($_POST["id"]);
504  include_once "./Services/Utilities/classes/class.ilUtil.php";
505  $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
506  $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
507  $this->object->setDescription(ilUtil::stripSlashes($_POST["description"]));
508  if (strlen($_POST["material"]))
509  {
510  $this->object->setMaterial($_POST["material"], 0, ilUtil::stripSlashes($_POST["material_title"]));
511  }
512  $this->object->setSubtype($_POST["type"]);
513  $this->object->setOrientation($_POST["orientation"]);
514  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
515  $questiontext = ilUtil::stripSlashes($_POST["question"], true, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("survey"));
516  $this->object->setQuestiontext($questiontext);
517  if ($_POST["obligatory"])
518  {
519  $this->object->setObligatory(1);
520  }
521  else
522  {
523  $this->object->setObligatory(0);
524  }
525 
526  if ($saved)
527  {
528  // If the question was saved automatically before an upload, we have to make
529  // sure, that the state after the upload is saved. Otherwise the user could be
530  // irritated, if he presses cancel, because he only has the question state before
531  // the upload process.
532  $this->object->saveToDb("", false);
533  }
534  return $result;
535  }
536 
544  function categories($add = false)
545  {
546  if ($this->object->getId() < 1)
547  {
548  ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_category"), true);
549  $this->ctrl->redirect($this, "editQuestion");
550  }
551  if (strcmp($this->ctrl->getCmd(), "categories") == 0) $_SESSION["spl_modified"] = false;
552  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_nominal_answers.html", "Modules/SurveyQuestionPool");
553  // output of existing single response answers
554  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
555  {
556  $this->tpl->setCurrentBlock("cat_selector");
557  $this->tpl->setVariable("CATEGORY_ORDER", $i);
558  $this->tpl->parseCurrentBlock();
559  $this->tpl->setCurrentBlock("categories");
560  $category = $this->object->categories->getCategory($i);
561  $this->tpl->setVariable("CATEGORY_ORDER", $i);
562  $this->tpl->setVariable("CATEGORY_NUMBER", $i+1);
563  $this->tpl->setVariable("VALUE_CATEGORY", $category);
564  $this->tpl->setVariable("TEXT_CATEGORY", $this->lng->txt("category"));
565  $this->tpl->parseCurrentBlock();
566  }
567 
568  if ($add)
569  {
570  $nrOfCategories = $_POST["nrOfCategories"];
571  if ($nrOfCategories < 1) $nrOfCategories = 1;
572  // Create template for a new category
573  for ($i = 1; $i <= $nrOfCategories; $i++)
574  {
575  $this->tpl->setCurrentBlock("categories");
576  $this->tpl->setVariable("CATEGORY_ORDER", $this->object->categories->getCategoryCount() + $i - 1);
577  $this->tpl->setVariable("TEXT_CATEGORY", $this->lng->txt("category"));
578  $this->tpl->parseCurrentBlock();
579  }
580  }
581 
582  if (is_array($_SESSION["spl_move"]))
583  {
584  if (count($_SESSION["spl_move"]))
585  {
586  $this->tpl->setCurrentBlock("move_buttons");
587  $this->tpl->setVariable("INSERT_BEFORE", $this->lng->txt("insert_before"));
588  $this->tpl->setVariable("INSERT_AFTER", $this->lng->txt("insert_after"));
589  $this->tpl->parseCurrentBlock();
590  }
591  }
592 
593  include_once "./Services/Utilities/classes/class.ilUtil.php";
594  if ($this->object->categories->getCategoryCount() == 0)
595  {
596  if (!$add)
597  {
598  $this->tpl->setCurrentBlock("nocategories");
599  $this->tpl->setVariable("NO_CATEGORIES", $this->lng->txt("question_contains_no_categories"));
600  $this->tpl->parseCurrentBlock();
601  }
602  }
603  else
604  {
605  $this->tpl->setCurrentBlock("selectall");
606  $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
607  $this->tpl->parseCurrentBlock();
608  $this->tpl->setCurrentBlock("existingcategories");
609  $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
610  $this->tpl->setVariable("MOVE", $this->lng->txt("move"));
611  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
612  $this->tpl->parseCurrentBlock();
613  }
614 
615  for ($i = 1; $i < 10; $i++)
616  {
617  $this->tpl->setCurrentBlock("numbers");
618  $this->tpl->setVariable("VALUE_NUMBER", $i);
619  if ($i == 1)
620  {
621  $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("category"));
622  }
623  else
624  {
625  $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("categories"));
626  }
627  $this->tpl->parseCurrentBlock();
628  }
629 
630  $this->tpl->setCurrentBlock("adm_content");
631  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
632  $this->tpl->setVariable("VALUE_ADD_CATEGORY", $this->lng->txt("add"));
633  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
634  if ($_SESSION["spl_modified"])
635  {
636  $this->tpl->setVariable("FORM_DATA_MODIFIED_PRESS_SAVE", $this->lng->txt("form_data_modified_press_save"));
637  }
638  $questiontext = $this->object->getQuestiontext();
639  $this->tpl->setVariable("QUESTION_TEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
640  $this->tpl->parseCurrentBlock();
641  }
642 
643  function setQuestionTabs()
644  {
645  $this->setQuestionTabsForClass("surveynominalquestiongui");
646  }
647 
655  function saveCategories()
656  {
657  global $ilUser;
658 
659  $this->writeCategoryData(true);
660  $_SESSION["spl_modified"] = false;
661  ilUtil::sendInfo($this->lng->txt("saved_successfully"), true);
662  $originalexists = $this->object->_questionExists($this->object->original_id);
663  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
664  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
665  if ($_GET["calling_survey"] && $originalexists && SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
666  {
667  $this->originalSyncForm();
668  return;
669  }
670  else
671  {
672  $this->ctrl->redirect($this, "categories");
673  }
674  }
675 
683  function addCategory()
684  {
685  $result = $this->writeCategoryData();
686  if ($result == false)
687  {
688  ilUtil::sendInfo($this->lng->txt("fill_out_all_category_fields"));
689  }
690  $_SESSION["spl_modified"] = true;
691  $this->categories($result);
692  }
693 
703  function writeCategoryData($save = false)
704  {
705  // Delete all existing categories and create new categories from the form data
706  $this->object->categories->flushCategories();
707  $complete = true;
708  $array1 = array();
709  // Add all categories from the form into the object
710  include_once "./Services/Utilities/classes/class.ilUtil.php";
711  foreach ($_POST as $key => $value)
712  {
713  if (preg_match("/^category_(\d+)/", $key, $matches))
714  {
715  $array1[$matches[1]] = ilUtil::stripSlashes($value);
716  if (strlen($array1[$matches[1]]) == 0) $complete = false;
717  }
718  }
719  $this->object->categories->addCategoryArray($array1);
720  if ($save)
721  {
722  $this->object->saveCategoriesToDb();
723  }
724  return $complete;
725  }
726 
734  function deleteCategory()
735  {
736  $this->writeCategoryData();
737  $nothing_selected = true;
738  if (array_key_exists("chb_category", $_POST))
739  {
740  if (count($_POST["chb_category"]))
741  {
742  $nothing_selected = false;
743  $this->object->categories->removeCategories($_POST["chb_category"]);
744  }
745  }
746  if ($nothing_selected) ilUtil::sendInfo($this->lng->txt("category_delete_select_none"));
747  $_SESSION["spl_modified"] = true;
748  $this->categories();
749  }
750 
758  function moveCategory()
759  {
760  $this->writeCategoryData();
761  $nothing_selected = true;
762  if (array_key_exists("chb_category", $_POST))
763  {
764  if (count($_POST["chb_category"]))
765  {
766  $nothing_selected = false;
767  ilUtil::sendInfo($this->lng->txt("select_target_position_for_move"));
768  $_SESSION["spl_move"] = $_POST["chb_category"];
769  }
770  }
771  if ($nothing_selected) ilUtil::sendInfo($this->lng->txt("no_category_selected_for_move"));
772  $this->categories();
773  }
774 
783  {
784  $result = $this->writeCategoryData();
785  if (array_key_exists("chb_category", $_POST))
786  {
787  if (count($_POST["chb_category"]) == 1)
788  {
789  // one entry is selected, moving is allowed
790  $this->object->categories->removeCategories($_SESSION["spl_move"]);
791  $newinsertindex = $this->object->categories->getCategoryIndex($_POST["category_".$_POST["chb_category"][0]]);
792  if ($newinsertindex === false) $newinsertindex = 0;
793  $move_categories = $_SESSION["spl_move"];
794  natsort($move_categories);
795  foreach (array_reverse($move_categories) as $index)
796  {
797  $this->object->categories->addCategoryAtPosition($_POST["category_$index"], $newinsertindex);
798  }
799  $_SESSION["spl_modified"] = true;
800  unset($_SESSION["spl_move"]);
801  }
802  else
803  {
804  ilUtil::sendInfo("wrong_categories_selected_for_insert");
805  }
806  }
807  $this->categories();
808  }
809 
818  {
819  $result = $this->writeCategoryData();
820  if (array_key_exists("chb_category", $_POST))
821  {
822  if (count($_POST["chb_category"]) == 1)
823  {
824  // one entry is selected, moving is allowed
825  $this->object->categories->removeCategories($_SESSION["spl_move"]);
826  $newinsertindex = $this->object->categories->getCategoryIndex($_POST["category_".$_POST["chb_category"][0]]);
827  if ($newinsertindex === false) $newinsertindex = 0;
828  $move_categories = $_SESSION["spl_move"];
829  natsort($move_categories);
830  foreach (array_reverse($move_categories) as $index)
831  {
832  $this->object->categories->addCategoryAtPosition($_POST["category_$index"], $newinsertindex+1);
833  }
834  $_SESSION["spl_modified"] = true;
835  unset($_SESSION["spl_move"]);
836  }
837  else
838  {
839  ilUtil::sendInfo("wrong_categories_selected_for_insert");
840  }
841  }
842  $this->categories();
843  }
844 
853  function getCumulatedResultRow($counter, $css_class, $survey_id)
854  {
855  include_once "./classes/class.ilTemplate.php";
856  if (count($this->cumulated) == 0)
857  {
858  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
859  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
860  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
861  }
862  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_row.html", TRUE, TRUE, "Modules/Survey");
863  $template->setVariable("QUESTION_TITLE", ($counter+1) . ". ".$this->object->getTitle());
864  $maxlen = 37;
865  $questiontext = preg_replace("/<[^>]+?>/ims", "", $this->object->getQuestiontext());
866  if (strlen($questiontext) > $maxlen + 3)
867  {
868  $questiontext = substr($questiontext, 0, $maxlen) . "...";
869  }
870  $template->setVariable("QUESTION_TEXT", $questiontext);
871  $template->setVariable("USERS_ANSWERED", $this->cumulated["USERS_ANSWERED"]);
872  $template->setVariable("USERS_SKIPPED", $this->cumulated["USERS_SKIPPED"]);
873  $template->setVariable("QUESTION_TYPE", $this->lng->txt($this->cumulated["QUESTION_TYPE"]));
874  $template->setVariable("MODE", $this->cumulated["MODE"]);
875  $template->setVariable("MODE_NR_OF_SELECTIONS", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
876  $template->setVariable("MEDIAN", $this->cumulated["MEDIAN"]);
877  $template->setVariable("ARITHMETIC_MEAN", $this->cumulated["ARITHMETIC_MEAN"]);
878  $template->setVariable("COLOR_CLASS", $css_class);
879  return $template->get();
880  }
881 
892  function getCumulatedResultsDetails($survey_id, $counter)
893  {
894  if (count($this->cumulated) == 0)
895  {
896  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
897  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
898  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
899  }
900 
901  $output = "";
902  include_once "./classes/class.ilTemplate.php";
903  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
904 
905  $template->setCurrentBlock("detail_row");
906  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
907  $questiontext = $this->object->getQuestiontext();
908  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
909  $template->parseCurrentBlock();
910  $template->setCurrentBlock("detail_row");
911  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
912  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
913  $template->parseCurrentBlock();
914  $template->setCurrentBlock("detail_row");
915  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
916  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
917  $template->parseCurrentBlock();
918  $template->setCurrentBlock("detail_row");
919  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
920  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
921  $template->parseCurrentBlock();
922 
923  $template->setCurrentBlock("detail_row");
924  $template->setVariable("TEXT_OPTION", $this->lng->txt("subtype"));
925  switch ($this->object->getSubType())
926  {
927  case SUBTYPE_MCSR:
928  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("multiple_choice_single_response"));
929  break;
930  case SUBTYPE_MCMR:
931  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt("multiple_choice_multiple_response"));
932  break;
933  }
934  $template->parseCurrentBlock();
935 
936  $template->setCurrentBlock("detail_row");
937  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
938  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE"]);
939  $template->parseCurrentBlock();
940  $template->setCurrentBlock("detail_row");
941  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
942  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
943  $template->parseCurrentBlock();
944 
945  $template->setCurrentBlock("detail_row");
946  $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
947  $categories = "";
948  if (is_array($this->cumulated["variables"]))
949  {
950  foreach ($this->cumulated["variables"] as $key => $value)
951  {
952  $categories .= "<li>" . $this->lng->txt("title") . ":" . "<span class=\"bold\">" . $value["title"] . "</span><br />" .
953  $this->lng->txt("category_nr_selected") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
954  $this->lng->txt("percentage_of_selections") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
955  }
956  }
957  $categories = "<ol>$categories</ol>";
958  $template->setVariable("TEXT_OPTION_VALUE", $categories);
959  $template->parseCurrentBlock();
960 
961  // display chart for nominal question for array $eval["variables"]
962  $template->setCurrentBlock("chart");
963  $template->setVariable("TEXT_CHART", $this->lng->txt("chart"));
964  $template->setVariable("ALT_CHART", $data["title"] . "( " . $this->lng->txt("chart") . ")");
965 
966  $charturl = "";
967  include_once "./Services/Administration/classes/class.ilSetting.php";
968  $surveySetting = new ilSetting("survey");
969  if ($surveySetting->get("googlechart") == 1)
970  {
971  $chartcolors = array("2A4BD7", "9DAFFF", "1D6914", "81C57A", "814A19", "E9DEBB", "8126C0", "AD2323", "29D0D0", "FFEE33", "FF9233", "FFCDF3", "A0A0A0", "575757", "000000");
972  $selections = array();
973  $values = array();
974  $maxselection = 0;
975  foreach ($this->cumulated["variables"] as $val)
976  {
977  if ($val["selected"] > $maxselection) $maxselection = $val["selected"];
978  array_push($selections, $val["selected"]);
979  array_push($values, str_replace(" ", "+", $val["title"]));
980  }
981  $chartwidth = 800;
982  if ($maxselection % 2 == 0)
983  {
984  $selectionlabels = "0|" . ($maxselection / 2) . "|$maxselection";
985  }
986  else
987  {
988  $selectionlabels = "0|$maxselection";
989  }
990  $charturl = "http://chart.apis.google.com/chart?chco=" . implode("|", array_slice($chartcolors, 0, count($values))). "&cht=bvs&chs=" . $chartwidth . "x250&chd=t:" . implode(",", $selections) . "&chds=0,$maxselection&chxt=y,y&chxl=0:|".$selectionlabels."|1:||".str_replace(" ", "+", $this->lng->txt("mode_nr_of_selections"))."|" . "&chxr=1,0,$maxselection&chtt=" . str_replace(" ", "+", $this->object->getTitle()) . "&chbh=20," . round($chartwidth/(count($values)+1.5)) . "&chdl=" . implode("|", $values) . "&chdlp=b";
991  }
992  else
993  {
994  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "survey", $survey_id);
995  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "question", $this->object->getId());
996  $charturl = $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "outChart");
997  }
998  $template->setVariable("CHART", $charturl);
999  $template->parseCurrentBlock();
1000 
1001  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
1002  return $template->get();
1003  }
1004 
1005 
1006 }
1007 ?>