ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyTextQuestionGUI.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.SurveyTextQuestion.php";
56  $this->object = new SurveyTextQuestion();
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_text.html", "Modules/SurveyQuestionPool");
73  $this->tpl->addBlockFile("OTHER_QUESTION_DATA", "other_question_data", "tpl.il_svy_qpl_other_question_data.html", "Modules/SurveyQuestionPool");
74 
75  $internallinks = array(
76  "lm" => $this->lng->txt("obj_lm"),
77  "st" => $this->lng->txt("obj_st"),
78  "pg" => $this->lng->txt("obj_pg"),
79  "glo" => $this->lng->txt("glossary_term")
80  );
81  foreach ($internallinks as $key => $value)
82  {
83  $this->tpl->setCurrentBlock("internallink");
84  $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
85  $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
86  $this->tpl->parseCurrentBlock();
87  }
88 
89  $this->tpl->setCurrentBlock("adm_content");
90  $this->tpl->setVariable("TEXT_MATERIAL", $this->lng->txt("material"));
91  if (count($this->object->material))
92  {
93  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
94  $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
95  $this->tpl->setVariable("TEXT_VALUE_MATERIAL", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("material"). "</a> ");
96  $this->tpl->setVariable("BUTTON_REMOVE_MATERIAL", $this->lng->txt("remove"));
97  $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("change"));
98  $this->tpl->setVariable("VALUE_MATERIAL", $this->object->material["internal_link"]);
99  $this->tpl->setVariable("VALUE_MATERIAL_TITLE", $this->object->material["title"]);
100  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
101  }
102  else
103  {
104  $this->tpl->setVariable("BUTTON_ADD_MATERIAL", $this->lng->txt("add"));
105  }
106  $this->tpl->setVariable("QUESTION_ID", $this->object->getId());
107  $this->tpl->setVariable("VALUE_TITLE", $this->object->getTitle());
108  $this->tpl->setVariable("VALUE_DESCRIPTION", $this->object->getDescription());
109  $this->tpl->setVariable("VALUE_AUTHOR", $this->object->getAuthor());
110  if ($this->object->getMaxChars() > 0)
111  {
112  $this->tpl->setVariable("VALUE_MAXCHARS", $this->object->getMaxChars());
113  }
114  $questiontext = $this->object->getQuestiontext();
115  $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
116  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
117  $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
118  $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
119  $this->tpl->setVariable("TEXT_MAXCHARS", $this->lng->txt("maxchars"));
120  $this->tpl->setVariable("TEXT_WIDTH", $this->lng->txt("width"));
121  $this->tpl->setVariable("TEXT_HEIGHT", $this->lng->txt("height"));
122  $this->tpl->setVariable("DESCRIPTION_TEXTWIDTH", $this->lng->txt("survey_text_textwidth_desc"));
123  $this->tpl->setVariable("DESCRIPTION_TEXTHEIGHT", $this->lng->txt("survey_text_textheight_desc"));
124  if ($this->object->getTextWidth())
125  {
126  $this->tpl->setVariable("VALUE_TEXTWIDTH", " value=\"" . $this->object->getTextWidth() . "\"");
127  }
128  if ($this->object->getTextHeight())
129  {
130  $this->tpl->setVariable("VALUE_TEXTHEIGHT", " value=\"" . $this->object->getTextHeight() . "\"");
131  }
132  $this->tpl->setVariable("DESCRIPTION_MAXCHARS", $this->lng->txt("description_maxchars"));
133  $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
134  $this->tpl->setVariable("TEXT_OBLIGATORY", $this->lng->txt("obligatory"));
135  if ($this->object->getObligatory())
136  {
137  $this->tpl->setVariable("CHECKED_OBLIGATORY", " checked=\"checked\"");
138  }
139  $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
140  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
141  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
142  $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt($this->getQuestionType()));
143  $this->tpl->parseCurrentBlock();
144  include_once "./Services/RTE/classes/class.ilRTE.php";
145  $rtestring = ilRTE::_getRTEClassname();
146  include_once "./Services/RTE/classes/class.$rtestring.php";
147  $rte = new $rtestring();
148  $rte->addPlugin("latex");
149  $rte->addButton("latex"); $rte->addButton("pastelatex");
150  $rte->removePlugin("ibrowser");
151  include_once "./classes/class.ilObject.php";
152  $obj_id = $_GET["q_id"];
153  $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
154  $rte->addRTESupport($obj_id, $obj_type, "survey");
155 
157  }
158 
166  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
167  {
168  $template = new ilTemplate("tpl.il_svy_out_text.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
169  if (count($this->object->material))
170  {
171  $template->setCurrentBlock("material_text");
172  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
173  $href = SurveyQuestion::_getInternalLinkHref($this->object->material["internal_link"]);
174  $template->setVariable("TEXT_MATERIAL", $this->lng->txt("material") . ": <a href=\"$href\" target=\"content\">" . $this->object->material["title"]. "</a> ");
175  $template->parseCurrentBlock();
176  }
177 
178  if ($this->object->getTextHeight() == 1)
179  {
180  $template->setCurrentBlock("textinput");
181  if (is_array($working_data))
182  {
183  if (strlen($working_data[0]["textanswer"]))
184  {
185  $template->setVariable("VALUE_ANSWER", " value=\"" . ilUtil::prepareFormOutput($working_data[0]["textanswer"]) . "\"");
186  }
187  }
188  $template->setVariable("QUESTION_ID", $this->object->getId());
189  $template->setVariable("WIDTH", $this->object->getTextWidth());
190  if ($this->object->getMaxChars())
191  {
192  $template->setVariable("MAXLENGTH", " maxlength=\"" . $this->object->getMaxChars() . "\"");
193  }
194  $template->parseCurrentBlock();
195  }
196  else
197  {
198  $template->setCurrentBlock("textarea");
199  if (is_array($working_data))
200  {
201  $template->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($working_data[0]["textanswer"]));
202  }
203  $template->setVariable("QUESTION_ID", $this->object->getId());
204  $template->setVariable("WIDTH", $this->object->getTextWidth());
205  $template->setVariable("HEIGHT", $this->object->getTextHeight());
206  $template->parseCurrentBlock();
207  }
208  $template->setCurrentBlock("question_data_text");
209  if ($show_questiontext)
210  {
211  $questiontext = $this->object->getQuestiontext();
212  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
213  }
214  if (! $this->object->getObligatory($survey_id))
215  {
216  $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
217  }
218  if ($question_title)
219  {
220  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
221  }
222  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
223  $template->setVariable("LABEL_QUESTION_ID", $this->object->getId());
224  if (strcmp($error_message, "") != 0)
225  {
226  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
227  }
228  if ($this->object->getMaxChars())
229  {
230  $template->setVariable("TEXT_MAXCHARS", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxChars()));
231  }
232  $template->parseCurrentBlock();
233  return $template->get();
234  }
235 
243  function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
244  {
245  $template = new ilTemplate("tpl.il_svy_qpl_text_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
246  if ($show_questiontext)
247  {
248  $questiontext = $this->object->getQuestiontext();
249  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
250  }
251  if (! $this->object->getObligatory($survey_id))
252  {
253  $template->setVariable("OBLIGATORY_TEXT", $this->lng->txt("survey_question_optional"));
254  }
255  if ($question_title)
256  {
257  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
258  }
259  $template->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
260  $template->setVariable("TEXTBOX_IMAGE", ilUtil::getHtmlPath(ilUtil::getImagePath("textbox.png")));
261  $template->setVariable("TEXTBOX", $this->lng->txt("textbox"));
262  $template->setVariable("TEXTBOX_WIDTH", $this->object->getTextWidth()*16);
263  $template->setVariable("TEXTBOX_HEIGHT", $this->object->getTextHeight()*16);
264  $template->setVariable("QUESTION_ID", $this->object->getId());
265  if ($this->object->getMaxChars())
266  {
267  $template->setVariable("TEXT_MAXCHARS", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxChars()));
268  }
269  return $template->get();
270  }
271 
279  function preview()
280  {
281  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", "Modules/SurveyQuestionPool");
282  $question_output = $this->getWorkingForm();
283  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
284  }
285 
294  function writePostData()
295  {
296  $result = 0;
297  if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"])) $result = 1;
298  if ($result == 1) $this->addErrorMessage($this->lng->txt("fill_out_all_required_fields"));
299 
300  // Set the question id from a hidden form parameter
301  if ($_POST["id"] > 0) $this->object->setId($_POST["id"]);
302  include_once "./Services/Utilities/classes/class.ilUtil.php";
303  $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
304  $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
305  $this->object->setDescription(ilUtil::stripSlashes($_POST["description"]));
306  $this->object->setMaxChars(ilUtil::stripSlashes($_POST["maxchars"]));
307  $this->object->setTextWidth(ilUtil::stripSlashes($_POST["textwidth"]));
308  $this->object->setTextHeight(ilUtil::stripSlashes($_POST["textheight"]));
309  if (strlen($_POST["material"]))
310  {
311  $this->object->setMaterial($_POST["material"], 0, ilUtil::stripSlashes($_POST["material_title"]));
312  }
313  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
314  $questiontext = ilUtil::stripSlashes($_POST["question"], true, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("survey"));
315  $this->object->setQuestiontext($questiontext);
316  if ($_POST["obligatory"])
317  {
318  $this->object->setObligatory(1);
319  }
320  else
321  {
322  $this->object->setObligatory(0);
323  }
324 
325  if ($saved)
326  {
327  // If the question was saved automatically before an upload, we have to make
328  // sure, that the state after the upload is saved. Otherwise the user could be
329  // irritated, if he presses cancel, because he only has the question state before
330  // the upload process.
331  $this->object->saveToDb();
332  }
333  return $result;
334  }
335 
336  function setQuestionTabs()
337  {
338  $this->setQuestionTabsForClass("surveytextquestiongui");
339  }
340 
349  function getCumulatedResultRow($counter, $css_class, $survey_id)
350  {
351  include_once "./classes/class.ilTemplate.php";
352  if (count($this->cumulated) == 0)
353  {
354  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
355  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
356  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
357  }
358  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_row.html", TRUE, TRUE, "Modules/Survey");
359  $template->setVariable("QUESTION_TITLE", ($counter+1) . ". ".$this->object->getTitle());
360  $maxlen = 37;
361  $questiontext = preg_replace("/<[^>]+?>/ims", "", $this->object->getQuestiontext());
362  if (strlen($questiontext) > $maxlen + 3)
363  {
364  $questiontext = substr($questiontext, 0, $maxlen) . "...";
365  }
366  $template->setVariable("QUESTION_TEXT", $questiontext);
367  $template->setVariable("USERS_ANSWERED", $this->cumulated["USERS_ANSWERED"]);
368  $template->setVariable("USERS_SKIPPED", $this->cumulated["USERS_SKIPPED"]);
369  $template->setVariable("QUESTION_TYPE", $this->lng->txt($this->cumulated["QUESTION_TYPE"]));
370  $template->setVariable("MODE", $this->cumulated["MODE"]);
371  $template->setVariable("MODE_NR_OF_SELECTIONS", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
372  $template->setVariable("MEDIAN", $this->cumulated["MEDIAN"]);
373  $template->setVariable("ARITHMETIC_MEAN", $this->cumulated["ARITHMETIC_MEAN"]);
374  $template->setVariable("COLOR_CLASS", $css_class);
375  return $template->get();
376  }
377 
388  function getCumulatedResultsDetails($survey_id, $counter)
389  {
390  if (count($this->cumulated) == 0)
391  {
392  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
393  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
394  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
395  }
396 
397  $output = "";
398  include_once "./classes/class.ilTemplate.php";
399  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
400 
401  $template->setCurrentBlock("detail_row");
402  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
403  $questiontext = $this->object->getQuestiontext();
404  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
405  $template->parseCurrentBlock();
406  $template->setCurrentBlock("detail_row");
407  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
408  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
409  $template->parseCurrentBlock();
410  $template->setCurrentBlock("detail_row");
411  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
412  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
413  $template->parseCurrentBlock();
414  $template->setCurrentBlock("detail_row");
415  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
416  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
417  $template->parseCurrentBlock();
418 
419  $template->setCurrentBlock("detail_row");
420  $template->setVariable("TEXT_OPTION", $this->lng->txt("given_answers"));
421  $textvalues = "";
422  if (is_array($this->cumulated["textvalues"]))
423  {
424  foreach ($this->cumulated["textvalues"] as $textvalue)
425  {
426  $textvalues .= "<li>" . preg_replace("/\n/", "<br>", $textvalue) . "</li>";
427  }
428  }
429  $textvalues = "<ul>$textvalues</ul>";
430  $template->setVariable("TEXT_OPTION_VALUE", $textvalues);
431  $template->parseCurrentBlock();
432 
433  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
434  return $template->get();
435  }
436 }
437 ?>