ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyOrdinalQuestionGUI.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.SurveyOrdinalQuestion.php";
56  $this->object = new SurveyOrdinalQuestion();
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_ordinal.html", "Modules/SurveyQuestionPool");
73  $this->tpl->addBlockFile("OTHER_QUESTION_DATA", "other_question_data", "tpl.il_svy_qpl_other_question_data.html", "Modules/SurveyQuestionPool");
74  $internallinks = array(
75  "lm" => $this->lng->txt("obj_lm"),
76  "st" => $this->lng->txt("obj_st"),
77  "pg" => $this->lng->txt("obj_pg"),
78  "glo" => $this->lng->txt("glossary_term")
79  );
80  foreach ($internallinks as $key => $value)
81  {
82  $this->tpl->setCurrentBlock("internallink");
83  $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
84  $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
85  $this->tpl->parseCurrentBlock();
86  }
87 
88  $this->tpl->setCurrentBlock("adm_content");
89  $this->tpl->setVariable("TEXT_MATERIAL", $this->lng->txt("material"));
90  if (count($this->object->material))
91  {
92  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
93  $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
94  $this->tpl->setVariable("TEXT_VALUE_MATERIAL", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("material"). "</a> ");
95  $this->tpl->setVariable("BUTTON_REMOVE_MATERIAL", $this->lng->txt("remove"));
96  $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("change"));
97  $this->tpl->setVariable("VALUE_MATERIAL", $this->object->material["internal_link"]);
98  $this->tpl->setVariable("VALUE_MATERIAL_TITLE", $this->object->material["title"]);
99  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
100  }
101  else
102  {
103  $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("add"));
104  }
105  $this->tpl->setVariable("TEXT_ORIENTATION", $this->lng->txt("orientation"));
106  switch ($this->object->getOrientation())
107  {
108  case 0:
109  $this->tpl->setVariable("CHECKED_VERTICAL", " checked=\"checked\"");
110  break;
111  case 1:
112  $this->tpl->setVariable("CHECKED_HORIZONTAL", " checked=\"checked\"");
113  break;
114  case 2:
115  $this->tpl->setVariable("CHECKED_COMBOBOX", " checked=\"checked\"");
116  break;
117  }
118  $this->tpl->setVariable("TXT_VERTICAL", $this->lng->txt("vertical"));
119  $this->tpl->setVariable("TXT_HORIZONTAL", $this->lng->txt("horizontal"));
120  $this->tpl->setVariable("TXT_COMBOBOX", $this->lng->txt("combobox"));
121  $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
122  $this->tpl->setVariable("VALUE_TITLE", $this->object->getTitle());
123  $this->tpl->setVariable("VALUE_DESCRIPTION", $this->object->getDescription());
124  $this->tpl->setVariable("VALUE_AUTHOR", $this->object->getAuthor());
125  $questiontext = $this->object->getQuestiontext();
126  $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
127  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
128  $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
129  $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
130  $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
131  $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("questiontype"));
132  $this->tpl->setVariable("TEXT_OBLIGATORY", $this->lng->txt("obligatory"));
133  if ($this->object->getObligatory())
134  {
135  $this->tpl->setVariable("CHECKED_OBLIGATORY", " checked=\"checked\"");
136  }
137  $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
138  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
139  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
140  $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt($this->getQuestionType()));
141  $this->tpl->parseCurrentBlock();
142  include_once "./Services/RTE/classes/class.ilRTE.php";
143  $rtestring = ilRTE::_getRTEClassname();
144  include_once "./Services/RTE/classes/class.$rtestring.php";
145  $rte = new $rtestring();
146  $rte->addPlugin("latex");
147  $rte->addButton("latex"); $rte->addButton("pastelatex");
148  $rte->removePlugin("ibrowser");
149  include_once "./classes/class.ilObject.php";
150  $obj_id = $_GET["q_id"];
151  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
152  $rte->addRTESupport($obj_id, $obj_type, "survey");
153 
155  }
156 
164  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
165  {
166  $template = new ilTemplate("tpl.il_svy_out_ordinal.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
167  if (count($this->object->material))
168  {
169  $template->setCurrentBlock("material_ordinal");
170  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
171  $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
172  $template->setVariable("TEXT_MATERIAL", $this->lng->txt("material") . ": <a href=\"$href\" target=\"content\">" . $this->object->material["title"]. "</a> ");
173  $template->parseCurrentBlock();
174  }
175  switch ($this->object->orientation)
176  {
177  case 0:
178  // vertical orientation
179  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
180  {
181  $category = $this->object->categories->getCategory($i);
182  $template->setCurrentBlock("ordinal_row");
183  $template->setVariable("TEXT_ORDINAL", ilUtil::prepareFormOutput($category));
184  $template->setVariable("VALUE_ORDINAL", $i);
185  $template->setVariable("QUESTION_ID", $this->object->getId());
186  if (is_array($working_data))
187  {
188  if (strcmp($working_data[0]["value"], "") != 0)
189  {
190  if ($working_data[0]["value"] == $i)
191  {
192  $template->setVariable("CHECKED_ORDINAL", " checked=\"checked\"");
193  }
194  }
195  }
196  $template->parseCurrentBlock();
197  }
198  break;
199  case 1:
200  // horizontal orientation
201  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
202  {
203  $category = $this->object->categories->getCategory($i);
204  $template->setCurrentBlock("radio_col_ordinal");
205  $template->setVariable("VALUE_ORDINAL", $i);
206  $template->setVariable("QUESTION_ID", $this->object->getId());
207  if (is_array($working_data))
208  {
209  if (strcmp($working_data[0]["value"], "") != 0)
210  {
211  if ($working_data[0]["value"] == $i)
212  {
213  $template->setVariable("CHECKED_ORDINAL", " checked=\"checked\"");
214  }
215  }
216  }
217  $template->parseCurrentBlock();
218  }
219  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
220  {
221  $category = $this->object->categories->getCategory($i);
222  $template->setCurrentBlock("text_col_ordinal");
223  $template->setVariable("VALUE_ORDINAL", $i);
224  $template->setVariable("TEXT_ORDINAL", ilUtil::prepareFormOutput($category));
225  $template->setVariable("QUESTION_ID", $this->object->getId());
226  $template->parseCurrentBlock();
227  }
228  break;
229  case 2:
230  // combobox output
231  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
232  {
233  $category = $this->object->categories->getCategory($i);
234  $template->setCurrentBlock("comborow");
235  $template->setVariable("TEXT_ORDINAL", $category);
236  $template->setVariable("VALUE_ORDINAL", $i);
237  if (is_array($working_data))
238  {
239  if (strcmp($working_data[0]["value"], "") != 0)
240  {
241  if ($working_data[0]["value"] == $i)
242  {
243  $template->setVariable("SELECTED_ORDINAL", " selected=\"selected\"");
244  }
245  }
246  }
247  $template->parseCurrentBlock();
248  }
249  $template->setCurrentBlock("combooutput");
250  $template->setVariable("QUESTION_ID", $this->object->getId());
251  $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
252  $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
253  $template->parseCurrentBlock();
254  break;
255  }
256  if ($question_title)
257  {
258  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
259  }
260  $template->setCurrentBlock("question_data_ordinal");
261  if (strcmp($error_message, "") != 0)
262  {
263  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
264  }
265  if ($show_questiontext)
266  {
267  $questiontext = $this->object->getQuestiontext();
268  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
269  }
270  if (! $this->object->getObligatory($survey_id))
271  {
272  $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
273  }
274  $template->parseCurrentBlock();
275  return $template->get();
276  }
277 
285  function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
286  {
287  $template = new ilTemplate("tpl.il_svy_qpl_ordinal_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
288  switch ($this->object->orientation)
289  {
290  case 0:
291  // vertical orientation
292  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
293  {
294  $category = $this->object->categories->getCategory($i);
295  $template->setCurrentBlock("ordinal_row");
296  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
297  $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
298  $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
299  $template->setVariable("TEXT_ORDINAL", ilUtil::prepareFormOutput($category));
300  $template->parseCurrentBlock();
301  }
302  break;
303  case 1:
304  // horizontal orientation
305  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
306  {
307  $category = $this->object->categories->getCategory($i);
308  $template->setCurrentBlock("radio_col_ordinal");
309  $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_unchecked.gif")));
310  $template->setVariable("ALT_RADIO", $this->lng->txt("unchecked"));
311  $template->setVariable("TITLE_RADIO", $this->lng->txt("unchecked"));
312  $template->parseCurrentBlock();
313  }
314  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
315  {
316  $category = $this->object->categories->getCategory($i);
317  $template->setCurrentBlock("text_col_ordinal");
318  $template->setVariable("TEXT_ORDINAL", $category);
319  $template->parseCurrentBlock();
320  }
321  break;
322  case 2:
323  // combobox output
324  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
325  {
326  $category = $this->object->categories->getCategory($i);
327  $template->setCurrentBlock("comborow");
328  $template->setVariable("TEXT_ORDINAL", ilUtil::prepareFormOutput($category));
329  $template->setVariable("VALUE_ORDINAL", $i);
330  if (is_array($working_data))
331  {
332  if (strcmp($working_data[0]["value"], "") != 0)
333  {
334  if ($working_data[0]["value"] == $i)
335  {
336  $template->setVariable("SELECTED_ORDINAL", " selected=\"selected\"");
337  }
338  }
339  }
340  $template->parseCurrentBlock();
341  }
342  $template->setCurrentBlock("combooutput");
343  $template->setVariable("QUESTION_ID", $this->object->getId());
344  $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
345  $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
346  $template->parseCurrentBlock();
347  break;
348  }
349  if ($question_title)
350  {
351  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
352  }
353  if ($show_questiontext)
354  {
355  $questiontext = $this->object->getQuestiontext();
356  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
357  }
358  if (! $this->object->getObligatory($survey_id))
359  {
360  $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
361  }
362  $template->parseCurrentBlock();
363  return $template->get();
364  }
365 
373  function preview()
374  {
375  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", "Modules/SurveyQuestionPool");
376  $question_output = $this->getWorkingForm();
377  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
378  }
379 
388  function writePostData()
389  {
390  $result = 0;
391  if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"])) $result = 1;
392  if ($result == 1) $this->addErrorMessage($this->lng->txt("fill_out_all_required_fields"));
393  // Set the question id from a hidden form parameter
394  if ($_POST["id"] > 0) $this->object->setId($_POST["id"]);
395  include_once "./Services/Utilities/classes/class.ilUtil.php";
396  $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
397  $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
398  $this->object->setDescription(ilUtil::stripSlashes($_POST["description"]));
399  $this->object->setOrientation($_POST["orientation"]);
400  if (strlen($_POST["material"]))
401  {
402  $this->object->setMaterial($_POST["material"], 0, ilUtil::stripSlashes($_POST["material_title"]));
403  }
404  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
405  $questiontext = ilUtil::stripSlashes($_POST["question"], true, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("survey"));
406  $this->object->setQuestiontext($questiontext);
407  if ($_POST["obligatory"])
408  {
409  $this->object->setObligatory(1);
410  }
411  else
412  {
413  $this->object->setObligatory(0);
414  }
415 
416  if ($saved) {
417  // If the question was saved automatically before an upload, we have to make
418  // sure, that the state after the upload is saved. Otherwise the user could be
419  // irritated, if he presses cancel, because he only has the question state before
420  // the upload process.
421  $this->object->saveToDb();
422  }
423  return $result;
424  }
425 
433  function categories($add = false)
434  {
435  if ($this->object->getId() < 1)
436  {
437  ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_category"), true);
438  $this->ctrl->redirect($this, "editQuestion");
439  }
440  if (strcmp($this->ctrl->getCmd(), "categories") == 0) $_SESSION["spl_modified"] = false;
441  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_ordinal_answers.html", "Modules/SurveyQuestionPool");
442  // output of existing single response answers
443  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
444  {
445  $this->tpl->setCurrentBlock("cat_selector");
446  $this->tpl->setVariable("CATEGORY_ORDER", $i);
447  $this->tpl->parseCurrentBlock();
448  $this->tpl->setCurrentBlock("categories");
449  $category = $this->object->categories->getCategory($i);
450  $this->tpl->setVariable("CATEGORY_ORDER", $i);
451  $this->tpl->setVariable("CATEGORY_NUMBER", $i+1);
452  $this->tpl->setVariable("VALUE_CATEGORY", ilUtil::prepareFormOutput($category));
453  $this->tpl->setVariable("TEXT_CATEGORY", $this->lng->txt("category"));
454  $this->tpl->parseCurrentBlock();
455  }
456 
457  if ($add)
458  {
459  $nrOfCategories = $_POST["nrOfCategories"];
460  if ($nrOfCategories < 1) $nrOfCategories = 1;
461  // Create template for a new category
462  for ($i = 1; $i <= $nrOfCategories; $i++)
463  {
464  $this->tpl->setCurrentBlock("categories");
465  $this->tpl->setVariable("CATEGORY_ORDER", $this->object->categories->getCategoryCount() + $i - 1);
466  $this->tpl->setVariable("TEXT_CATEGORY", $this->lng->txt("category"));
467  $this->tpl->parseCurrentBlock();
468  }
469  }
470 
471  if (is_array($_SESSION["spl_move"]))
472  {
473  if (count($_SESSION["spl_move"]))
474  {
475  $this->tpl->setCurrentBlock("move_buttons");
476  $this->tpl->setVariable("INSERT_BEFORE", $this->lng->txt("insert_before"));
477  $this->tpl->setVariable("INSERT_AFTER", $this->lng->txt("insert_after"));
478  $this->tpl->parseCurrentBlock();
479  }
480  }
481 
482  include_once "./Services/Utilities/classes/class.ilUtil.php";
483  if ($this->object->categories->getCategoryCount() == 0)
484  {
485  if (!$add)
486  {
487  $this->tpl->setCurrentBlock("nocategories");
488  $this->tpl->setVariable("NO_CATEGORIES", $this->lng->txt("question_contains_no_categories"));
489  $this->tpl->parseCurrentBlock();
490  }
491  }
492  else
493  {
494  $this->tpl->setCurrentBlock("selectall");
495  $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
496  $this->tpl->parseCurrentBlock();
497  $this->tpl->setCurrentBlock("existingcategories");
498  $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
499  $this->tpl->setVariable("MOVE", $this->lng->txt("move"));
500  $this->tpl->setVariable("VALUE_SAVE_PHRASE", $this->lng->txt("save_phrase"));
501  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
502  $this->tpl->parseCurrentBlock();
503  }
504 
505  for ($i = 1; $i < 10; $i++)
506  {
507  $this->tpl->setCurrentBlock("numbers");
508  $this->tpl->setVariable("VALUE_NUMBER", $i);
509  if ($i == 1)
510  {
511  $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("category"));
512  }
513  else
514  {
515  $this->tpl->setVariable("TEXT_NUMBER", $i . " " . $this->lng->txt("categories"));
516  }
517  $this->tpl->parseCurrentBlock();
518  }
519 
520  $this->tpl->setCurrentBlock("adm_content");
521  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
522  $this->tpl->setVariable("VALUE_ADD_CATEGORY", $this->lng->txt("add"));
523  $this->tpl->setVariable("VALUE_ADD_PHRASE", $this->lng->txt("add_phrase"));
524  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
525  if ($_SESSION["spl_modified"])
526  {
527  $this->tpl->setVariable("FORM_DATA_MODIFIED_PRESS_SAVE", $this->lng->txt("form_data_modified_press_save"));
528  }
529  $questiontext = $this->object->getQuestiontext();
530  $this->tpl->setVariable("QUESTION_TEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
531  $this->tpl->parseCurrentBlock();
532  }
533 
534  function setQuestionTabs()
535  {
536  $this->setQuestionTabsForClass("surveyordinalquestiongui");
537  }
538 
546  function addPhrase()
547  {
548  $this->writeCategoryData(true);
549  $this->ctrl->setParameterByClass(get_class($this), "q_id", $this->object->getId());
550  $this->ctrl->setParameterByClass("ilobjsurveyquestionpoolgui", "q_id", $this->object->getId());
551 
552  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase.html", "Modules/SurveyQuestionPool");
553 
554  // set the id to return to the selected question
555  $this->tpl->setCurrentBlock("hidden");
556  $this->tpl->setVariable("HIDDEN_NAME", "id");
557  $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
558  $this->tpl->parseCurrentBlock();
559 
560  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyPhrases.php";
562  $colors = array("tblrow1", "tblrow2");
563  $counter = 0;
564  foreach ($phrases as $phrase_id => $phrase_array)
565  {
566  $this->tpl->setCurrentBlock("phraserow");
567  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter++ % 2]);
568  $this->tpl->setVariable("PHRASE_VALUE", $phrase_id);
569  $this->tpl->setVariable("PHRASE_NAME", $phrase_array["title"]);
570  $categories =& ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
571  $this->tpl->setVariable("PHRASE_CONTENT", join($categories, ","));
572  $this->tpl->parseCurrentBlock();
573  }
574 
575  $this->tpl->setCurrentBlock("adm_content");
576  $this->tpl->setVariable("TEXT_CANCEL", $this->lng->txt("cancel"));
577  $this->tpl->setVariable("TEXT_PHRASE", $this->lng->txt("phrase"));
578  $this->tpl->setVariable("TEXT_CONTENT", $this->lng->txt("categories"));
579  $this->tpl->setVariable("TEXT_ADD_PHRASE", $this->lng->txt("add_phrase"));
580  $this->tpl->setVariable("TEXT_INTRODUCTION",$this->lng->txt("add_phrase_introduction"));
581  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
582  $this->tpl->parseCurrentBlock();
583  }
584 
592  function cancelViewPhrase()
593  {
594  $this->ctrl->redirect($this, "categories");
595  }
596 
604  function addSelectedPhrase()
605  {
606  if (strcmp($_POST["phrases"], "") == 0)
607  {
608  ilUtil::sendInfo($this->lng->txt("select_phrase_to_add"));
609  $this->addPhrase();
610  }
611  else
612  {
613  if (strcmp($this->object->getPhrase($_POST["phrases"]), "dp_standard_numbers") != 0)
614  {
615  $this->object->addPhrase($_POST["phrases"]);
616  $this->object->saveCategoriesToDb();
617  }
618  else
619  {
620  $this->addStandardNumbers();
621  return;
622  }
623  $this->ctrl->redirect($this, "categories");
624  }
625  }
626 
634  function addStandardNumbers()
635  {
636  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase_standard_numbers.html", "Modules/SurveyQuestionPool");
637 
638  // set the id to return to the selected question
639  $this->tpl->setCurrentBlock("hidden");
640  $this->tpl->setVariable("HIDDEN_NAME", "id");
641  $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
642  $this->tpl->parseCurrentBlock();
643 
644  $this->tpl->setCurrentBlock("adm_content");
645  $this->tpl->setVariable("ADD_STANDARD_NUMBERS", $this->lng->txt("add_standard_numbers"));
646  $this->tpl->setVariable("TEXT_ADD_LIMITS", $this->lng->txt("add_limits_for_standard_numbers"));
647  $this->tpl->setVariable("TEXT_LOWER_LIMIT",$this->lng->txt("lower_limit"));
648  $this->tpl->setVariable("TEXT_UPPER_LIMIT",$this->lng->txt("upper_limit"));
649  $this->tpl->setVariable("VALUE_LOWER_LIMIT", $_POST["lower_limit"]);
650  $this->tpl->setVariable("VALUE_UPPER_LIMIT", $_POST["upper_limit"]);
651  $this->tpl->setVariable("BTN_ADD",$this->lng->txt("add_phrase"));
652  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
653  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
654  $this->tpl->parseCurrentBlock();
655  }
656 
665  {
666  $this->ctrl->redirect($this, "categories");
667  }
668 
677  {
678  if ((strcmp($_POST["lower_limit"], "") == 0) or (strcmp($_POST["upper_limit"], "") == 0))
679  {
680  ilUtil::sendInfo($this->lng->txt("missing_upper_or_lower_limit"));
681  $this->addStandardNumbers();
682  }
683  else if ((int)$_POST["upper_limit"] <= (int)$_POST["lower_limit"])
684  {
685  ilUtil::sendInfo($this->lng->txt("upper_limit_must_be_greater"));
686  $this->addStandardNumbers();
687  }
688  else
689  {
690  $this->object->addStandardNumbers($_POST["lower_limit"], $_POST["upper_limit"]);
691  $this->object->saveCategoriesToDb();
692  $this->ctrl->redirect($this, "categories");
693  }
694  }
695 
703  function savePhrase()
704  {
705  $this->writeCategoryData(true);
706  $nothing_selected = true;
707  if (array_key_exists("chb_category", $_POST))
708  {
709  if (count($_POST["chb_category"]))
710  {
711  $nothing_selected = false;
712  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_savephrase.html", "Modules/SurveyQuestionPool");
713  $rowclass = array("tblrow1", "tblrow2");
714  $counter = 0;
715  foreach ($_POST["chb_category"] as $category)
716  {
717  $this->tpl->setCurrentBlock("row");
718  $this->tpl->setVariable("TXT_TITLE", $this->object->categories->getCategory($category));
719  $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
720  $this->tpl->parseCurrentBlock();
721  $this->tpl->setCurrentBlock("hidden");
722  $this->tpl->setVariable("HIDDEN_NAME", "chb_category[]");
723  $this->tpl->setVariable("HIDDEN_VALUE", $category);
724  $this->tpl->parseCurrentBlock();
725  }
726 
727  $this->tpl->setCurrentBlock("adm_content");
728  $this->tpl->setVariable("SAVE_PHRASE_INTRODUCTION", $this->lng->txt("save_phrase_introduction"));
729  $this->tpl->setVariable("TEXT_PHRASE_TITLE", $this->lng->txt("enter_phrase_title"));
730  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("category"));
731  $this->tpl->setVariable("VALUE_PHRASE_TITLE", $_POST["phrase_title"]);
732  $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
733  $this->tpl->setVariable("BTN_CONFIRM",$this->lng->txt("confirm"));
734  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
735  $this->tpl->parseCurrentBlock();
736  }
737  }
738  if ($nothing_selected)
739  {
740  ilUtil::sendInfo($this->lng->txt("check_category_to_save_phrase"), true);
741  $this->ctrl->redirect($this, "categories");
742  }
743  }
744 
752  function cancelSavePhrase()
753  {
754  $this->ctrl->redirect($this, "categories");
755  }
756 
764  function confirmSavePhrase()
765  {
766  if (!$_POST["phrase_title"])
767  {
768  ilUtil::sendInfo($this->lng->txt("qpl_savephrase_empty"));
769  $this->savePhrase();
770  return;
771  }
772 
773  if ($this->object->phraseExists($_POST["phrase_title"]))
774  {
775  ilUtil::sendInfo($this->lng->txt("qpl_savephrase_exists"));
776  $this->savePhrase();
777  return;
778  }
779 
780  $this->object->savePhrase($_POST["chb_category"], $_POST["phrase_title"]);
781  ilUtil::sendInfo($this->lng->txt("phrase_saved"), true);
782  $this->ctrl->redirect($this, "categories");
783  }
784 
792  function saveCategories()
793  {
794  global $ilUser;
795 
796  $this->writeCategoryData(true);
797  $_SESSION["spl_modified"] = false;
798  ilUtil::sendInfo($this->lng->txt("saved_successfully"), true);
799  $originalexists = $this->object->_questionExists($this->object->original_id);
800  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
801  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
802  if ($_GET["calling_survey"] && $originalexists && SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
803  {
804  $this->originalSyncForm();
805  return;
806  }
807  else
808  {
809  $this->ctrl->redirect($this, "categories");
810  }
811  }
812 
820  function addCategory()
821  {
822  $result = $this->writeCategoryData();
823  if ($result == false)
824  {
825  ilUtil::sendInfo($this->lng->txt("fill_out_all_category_fields"));
826  }
827  $_SESSION["spl_modified"] = true;
828  $this->categories($result);
829  }
830 
840  function writeCategoryData($save = false)
841  {
842  // Delete all existing categories and create new categories from the form data
843  $this->object->categories->flushCategories();
844  $complete = true;
845  $array1 = array();
846  // Add all categories from the form into the object
847  include_once "./Services/Utilities/classes/class.ilUtil.php";
848  foreach ($_POST as $key => $value)
849  {
850  if (preg_match("/^category_(\d+)/", $key, $matches))
851  {
852  $array1[$matches[1]] = ilUtil::stripSlashes($value);
853  if (strlen($array1[$matches[1]]) == 0) $complete = false;
854  }
855  }
856  $this->object->categories->addCategoryArray($array1);
857  if ($save)
858  {
859  $this->object->saveCategoriesToDb();
860  }
861  return $complete;
862  }
863 
871  function deleteCategory()
872  {
873  $this->writeCategoryData();
874  $nothing_selected = true;
875  if (array_key_exists("chb_category", $_POST))
876  {
877  if (count($_POST["chb_category"]))
878  {
879  $nothing_selected = false;
880  $this->object->categories->removeCategories($_POST["chb_category"]);
881  }
882  }
883  if ($nothing_selected) ilUtil::sendInfo($this->lng->txt("category_delete_select_none"));
884  $_SESSION["spl_modified"] = true;
885  $this->categories();
886  }
887 
895  function moveCategory()
896  {
897  $this->writeCategoryData();
898  $nothing_selected = true;
899  if (array_key_exists("chb_category", $_POST))
900  {
901  if (count($_POST["chb_category"]))
902  {
903  $nothing_selected = false;
904  ilUtil::sendInfo($this->lng->txt("select_target_position_for_move"));
905  $_SESSION["spl_move"] = $_POST["chb_category"];
906  }
907  }
908  if ($nothing_selected) ilUtil::sendInfo($this->lng->txt("no_category_selected_for_move"));
909  $this->categories();
910  }
911 
920  {
921  $result = $this->writeCategoryData();
922  if (array_key_exists("chb_category", $_POST))
923  {
924  if (count($_POST["chb_category"]) == 1)
925  {
926  // one entry is selected, moving is allowed
927  $this->object->categories->removeCategories($_SESSION["spl_move"]);
928  $newinsertindex = $this->object->categories->getCategoryIndex($_POST["category_".$_POST["chb_category"][0]]);
929  if ($newinsertindex === false) $newinsertindex = 0;
930  $move_categories = $_SESSION["spl_move"];
931  natsort($move_categories);
932  foreach (array_reverse($move_categories) as $index)
933  {
934  $this->object->categories->addCategoryAtPosition($_POST["category_$index"], $newinsertindex);
935  }
936  $_SESSION["spl_modified"] = true;
937  unset($_SESSION["spl_move"]);
938  }
939  else
940  {
941  ilUtil::sendInfo("wrong_categories_selected_for_insert");
942  }
943  }
944  $this->categories();
945  }
946 
955  {
956  $result = $this->writeCategoryData();
957  if (array_key_exists("chb_category", $_POST))
958  {
959  if (count($_POST["chb_category"]) == 1)
960  {
961  // one entry is selected, moving is allowed
962  $this->object->categories->removeCategories($_SESSION["spl_move"]);
963  $newinsertindex = $this->object->categories->getCategoryIndex($_POST["category_".$_POST["chb_category"][0]]);
964  if ($newinsertindex === false) $newinsertindex = 0;
965  $move_categories = $_SESSION["spl_move"];
966  natsort($move_categories);
967  foreach (array_reverse($move_categories) as $index)
968  {
969  $this->object->categories->addCategoryAtPosition($_POST["category_$index"], $newinsertindex+1);
970  }
971  $_SESSION["spl_modified"] = true;
972  unset($_SESSION["spl_move"]);
973  }
974  else
975  {
976  ilUtil::sendInfo("wrong_categories_selected_for_insert");
977  }
978  }
979  $this->categories();
980  }
981 
990  function getCumulatedResultRow($counter, $css_class, $survey_id)
991  {
992  include_once "./classes/class.ilTemplate.php";
993  if (count($this->cumulated) == 0)
994  {
995  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
996  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
997  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
998  }
999  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_row.html", TRUE, TRUE, "Modules/Survey");
1000  $template->setVariable("QUESTION_TITLE", ($counter+1) . ". ".$this->object->getTitle());
1001  $maxlen = 37;
1002  $questiontext = preg_replace("/<[^>]+?>/ims", "", $this->object->getQuestiontext());
1003  if (strlen($questiontext) > $maxlen + 3)
1004  {
1005  $questiontext = substr($questiontext, 0, $maxlen) . "...";
1006  }
1007  $template->setVariable("QUESTION_TEXT", $questiontext);
1008  $template->setVariable("USERS_ANSWERED", $this->cumulated["USERS_ANSWERED"]);
1009  $template->setVariable("USERS_SKIPPED", $this->cumulated["USERS_SKIPPED"]);
1010  $template->setVariable("QUESTION_TYPE", $this->lng->txt($this->cumulated["QUESTION_TYPE"]));
1011  $template->setVariable("MODE", $this->cumulated["MODE"]);
1012  $template->setVariable("MODE_NR_OF_SELECTIONS", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
1013  $template->setVariable("MEDIAN", $this->cumulated["MEDIAN"]);
1014  $template->setVariable("ARITHMETIC_MEAN", $this->cumulated["ARITHMETIC_MEAN"]);
1015  $template->setVariable("COLOR_CLASS", $css_class);
1016  return $template->get();
1017  }
1018 
1029  function getCumulatedResultsDetails($survey_id, $counter)
1030  {
1031  if (count($this->cumulated) == 0)
1032  {
1033  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
1034  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
1035  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
1036  }
1037 
1038  $output = "";
1039  include_once "./classes/class.ilTemplate.php";
1040  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
1041 
1042  $template->setCurrentBlock("detail_row");
1043  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
1044  $questiontext = $this->object->getQuestiontext();
1045  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
1046  $template->parseCurrentBlock();
1047  $template->setCurrentBlock("detail_row");
1048  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
1049  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
1050  $template->parseCurrentBlock();
1051  $template->setCurrentBlock("detail_row");
1052  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
1053  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
1054  $template->parseCurrentBlock();
1055  $template->setCurrentBlock("detail_row");
1056  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
1057  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
1058  $template->parseCurrentBlock();
1059 
1060  $template->setCurrentBlock("detail_row");
1061  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
1062  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE"]);
1063  $template->parseCurrentBlock();
1064  $template->setCurrentBlock("detail_row");
1065  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
1066  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
1067  $template->parseCurrentBlock();
1068  $template->setCurrentBlock("detail_row");
1069  $template->setVariable("TEXT_OPTION", $this->lng->txt("median"));
1070  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MEDIAN"]);
1071  $template->parseCurrentBlock();
1072 
1073  $template->setCurrentBlock("detail_row");
1074  $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
1075  $categories = "";
1076  foreach ($this->cumulated["variables"] as $key => $value)
1077  {
1078  $categories .= "<li>" . $this->lng->txt("title") . ":" . "<span class=\"bold\">" . $value["title"] . "</span><br />" .
1079  $this->lng->txt("category_nr_selected") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
1080  $this->lng->txt("percentage_of_selections") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
1081  }
1082  $categories = "<ol>$categories</ol>";
1083  $template->setVariable("TEXT_OPTION_VALUE", $categories);
1084  $template->parseCurrentBlock();
1085 
1086  // display chart for ordinal question for array $eval["variables"]
1087  $template->setCurrentBlock("chart");
1088  $template->setVariable("TEXT_CHART", $this->lng->txt("chart"));
1089  $template->setVariable("ALT_CHART", $data["title"] . "( " . $this->lng->txt("chart") . ")");
1090  $charturl = "";
1091  include_once "./Services/Administration/classes/class.ilSetting.php";
1092  $surveySetting = new ilSetting("survey");
1093  if ($surveySetting->get("googlechart") == 1)
1094  {
1095  $chartcolors = array("2A4BD7", "9DAFFF", "1D6914", "81C57A", "814A19", "E9DEBB", "8126C0", "AD2323", "29D0D0", "FFEE33", "FF9233", "FFCDF3", "A0A0A0", "575757", "000000");
1096  $selections = array();
1097  $values = array();
1098  $maxselection = 0;
1099  $char = 65;
1100  foreach ($this->cumulated["variables"] as $val)
1101  {
1102  if ($val["selected"] > $maxselection) $maxselection = $val["selected"];
1103  array_push($selections, $val["selected"]);
1104  array_push($values, str_replace(" ", "+", $val["title"]));
1105  }
1106  $chartwidth = 800;
1107  if ($maxselection % 2 == 0)
1108  {
1109  $selectionlabels = "0|" . ($maxselection / 2) . "|$maxselection";
1110  }
1111  else
1112  {
1113  $selectionlabels = "0|$maxselection";
1114  }
1115  $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";
1116  }
1117  else
1118  {
1119  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "survey", $survey_id);
1120  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "question", $this->object->getId());
1121  $charturl = $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "outChart");
1122  }
1123  $template->setVariable("CHART", $charturl);
1124  $template->parseCurrentBlock();
1125 
1126  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
1127  return $template->get();
1128  }
1129 }
1130 ?>