ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assFileUploadGUI.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/TestQuestionPool/classes/class.assQuestionGUI.php";
25 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
26 
37 {
46  function __construct($id = -1)
47  {
49  include_once "./Modules/TestQuestionPool/classes/class.assFileUpload.php";
50  $this->object = new assFileUpload();
51  $this->setErrorMessage($this->lng->txt("msg_form_save_error"));
52  if ($id >= 0)
53  {
54  $this->object->loadFromDb($id);
55  }
56  }
57 
58  function getCommand($cmd)
59  {
60  return $cmd;
61  }
62 
69  function writePostData($always = false)
70  {
71  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
72  if (!$hasErrors)
73  {
74  $this->object->setTitle($_POST["title"]);
75  $this->object->setAuthor($_POST["author"]);
76  $this->object->setComment($_POST["comment"]);
77  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
78  $questiontext = $_POST["question"];
79  $this->object->setQuestion($questiontext);
80  $this->object->setPoints($_POST["points"]);
81  // adding estimated working time
82  $this->object->setEstimatedWorkingTime(
83  $_POST["Estimated"]["hh"],
84  $_POST["Estimated"]["mm"],
85  $_POST["Estimated"]["ss"]
86  );
87  $this->object->setMaxSize($_POST["maxsize"]);
88  $this->object->setAllowedExtensions($_POST["allowedextensions"]);
89  return 0;
90  }
91  else
92  {
93  return 1;
94  }
95  }
96 
102  public function editQuestion($checkonly = FALSE)
103  {
104  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
105  $this->getQuestionTemplate();
106 
107  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
108  $form = new ilPropertyFormGUI();
109  $form->setFormAction($this->ctrl->getFormAction($this));
110  $form->setTitle($this->outQuestionType());
111  $form->setMultipart(false);
112  $form->setTableWidth("100%");
113  $form->setId("assfileupload");
114 
115  $this->addBasicQuestionFormProperties($form);
116 
117  // maxsize
118  $maxsize = new ilNumberInputGUI($this->lng->txt("maxsize"), "maxsize");
119  $maxsize->setValue($this->object->getMaxSize());
120  $maxsize->setInfo($this->lng->txt("maxsize_info"));
121  $maxsize->setSize(10);
122  $maxsize->setMinValue(0);
123 
124  //mbecker: Quick fix for mantis bug 8595: Change size file
125  $umf = get_cfg_var("upload_max_filesize");
126  // get the value for the maximal post data from the php.ini (if available)
127  $pms = get_cfg_var("post_max_size");
128 
129  //convert from short-string representation to "real" bytes
130  $multiplier_a=array("K"=>1024, "M"=>1024*1024, "G"=>1024*1024*1024);
131 
132  $umf_parts=preg_split("/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
133  $pms_parts=preg_split("/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
134 
135  if (count($umf_parts) == 2) { $umf = $umf_parts[0]*$multiplier_a[$umf_parts[1]]; }
136  if (count($pms_parts) == 2) { $pms = $pms_parts[0]*$multiplier_a[$pms_parts[1]]; }
137 
138  // use the smaller one as limit
139  $max_filesize = min($umf, $pms);
140 
141  if (!$max_filesize) $max_filesize=max($umf, $pms);
142 
143  $maxsize->setMaxValue($max_filesize);
144  // end quick fix
145 
146  $maxsize->setRequired(FALSE);
147  $form->addItem($maxsize);
148  // allowedextensions
149  $allowedextensions = new ilTextInputGUI($this->lng->txt("allowedextensions"), "allowedextensions");
150  $allowedextensions->setInfo($this->lng->txt("allowedextensions_info"));
151  $allowedextensions->setValue($this->object->getAllowedExtensions());
152  $allowedextensions->setRequired(FALSE);
153  $form->addItem($allowedextensions);
154  // points
155  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
156  $points->setValue($this->object->getPoints() > 0 ? $this->object->getPoints() : '');
157  $points->setRequired(TRUE);
158  $points->setSize(3);
159  $points->setMinValue(0.0);
160  $points->setMinvalueShouldBeGreater(true);
161  $form->addItem($points);
162 
163  $this->addQuestionFormCommandButtons($form);
164 
165  $errors = false;
166 
167  if ($save)
168  {
169  $form->setValuesByPost();
170  $errors = !$form->checkInput();
171  $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and we need this if we don't want to have duplication of backslashes
172  if ($errors) $checkonly = false;
173  }
174 
175  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
176  return $errors;
177  }
178 
179  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
180  {
181  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions, $show_feedback);
182  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
183  $this->tpl->setVariable("FORMACTION", $formaction);
184  $this->tpl->setVariable("ENCTYPE", 'enctype="multipart/form-data"');
185  }
186 
201  $active_id,
202  $pass = NULL,
203  $graphicalOutput = FALSE,
204  $result_output = FALSE,
205  $show_question_only = TRUE,
206  $show_feedback = FALSE,
207  $show_correct_solution = FALSE,
208  $show_manual_scoring = FALSE
209  )
210  {
211  // get the solution of the user for the active pass or from the last pass if allowed
212  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
213 
214  $solutionvalue = "";
215  if (($active_id > 0) && (!$show_correct_solution))
216  {
217  $solutions =& $this->object->getSolutionValues($active_id, $pass);
218  include_once "./Modules/Test/classes/class.ilObjTest.php";
219  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
220  {
221  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
222  }
223  $solutions =& $this->object->getSolutionValues($active_id, $pass);
224 
225  $files = ($show_manual_scoring) ? $this->object->getUploadedFilesForWeb($active_id, $pass) : $this->object->getUploadedFiles($active_id, $pass);
226  if (count($files))
227  {
228  include_once "./Modules/TestQuestionPool/classes/tables/class.assFileUploadFileTableGUI.php";
229  $table_gui = new assFileUploadFileTableGUI("iltestoutputgui", 'gotoquestion');
230  $table_gui->setTitle($this->lng->txt('already_delivered_files'), 'icon_file.gif', $this->lng->txt('already_delivered_files'));
231  $table_gui->setData($files);
232  $table_gui->setRowTemplate("tpl.il_as_qpl_fileupload_file_view_row.html", "Modules/TestQuestionPool");
233  $table_gui->setSelectAllCheckbox("");
234  $table_gui->clearCommandButtons();
235  $table_gui->disable('select_all');
236  $table_gui->disable('numinfo');
237  $template->setCurrentBlock("files");
238  $template->setVariable('FILES', $table_gui->getHTML());
239  $template->parseCurrentBlock();
240  }
241  }
242 
243  if (($active_id > 0) && (!$show_correct_solution))
244  {
245  $reached_points = $this->object->getReachedPoints($active_id, $pass);
246  if ($graphicalOutput)
247  {
248  // output of ok/not ok icons for user entered solutions
249  if ($reached_points == $this->object->getMaximumPoints())
250  {
251  $template->setCurrentBlock("icon_ok");
252  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
253  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
254  $template->parseCurrentBlock();
255  }
256  else
257  {
258  $template->setCurrentBlock("icon_ok");
259  if ($reached_points > 0)
260  {
261  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
262  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
263  }
264  else
265  {
266  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
267  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
268  }
269  $template->parseCurrentBlock();
270  }
271  }
272  }
273  else
274  {
275  $reached_points = $this->object->getPoints();
276  }
277 
278  if ($result_output)
279  {
280  $resulttext = ($reached_points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
281  $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $reached_points));
282  }
283  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->getQuestion(), TRUE));
284 
285  $questionoutput = $template->get();
286  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
287  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
288  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
289  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
290  $solutionoutput = $solutiontemplate->get();
291  if (!$show_question_only)
292  {
293  // get page object output
294  $solutionoutput = $this->getILIASPage($solutionoutput);
295  }
296  return $solutionoutput;
297  }
298 
299  function getPreview($show_question_only = FALSE)
300  {
301  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
302  if (strlen($this->object->getAllowedExtensions()))
303  {
304  $template->setCurrentBlock("allowed_extensions");
305  $template->setVariable("TXT_ALLOWED_EXTENSIONS", $this->object->prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
306  $template->parseCurrentBlock();
307  }
308  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->question, TRUE));
309  $template->setVariable("TEXT_UPLOAD", $this->object->prepareTextareaOutput($this->lng->txt('upload')));
310  $template->setVariable("TXT_UPLOAD_FILE", $this->object->prepareTextareaOutput($this->lng->txt('file_add')));
311  $template->setVariable("TXT_MAX_SIZE", $this->object->prepareTextareaOutput($this->lng->txt('file_notice') . ": " . $this->object->getMaxFilesizeAsString()));
312 
313  $questionoutput = $template->get();
314  if (!$show_question_only)
315  {
316  // get page object output
317  $questionoutput = $this->getILIASPage($questionoutput);
318  }
319  return $questionoutput;
320  }
321 
322  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
323  {
324  // generate the question output
325  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
326 
327  if ($active_id)
328  {
329  $solutions = NULL;
330  include_once "./Modules/Test/classes/class.ilObjTest.php";
331  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
332  {
333  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
334  }
335  $solutions =& $this->object->getSolutionValues($active_id, $pass);
336 
337  $files = $this->object->getUploadedFiles($active_id, $pass);
338  if (count($files))
339  {
340  include_once "./Modules/TestQuestionPool/classes/tables/class.assFileUploadFileTableGUI.php";
341  $table_gui = new assFileUploadFileTableGUI("iltestoutputgui", 'gotoquestion');
342  $table_gui->setTitle($this->lng->txt('already_delivered_files'), 'icon_file.gif', $this->lng->txt('already_delivered_files'));
343  $table_gui->setData($files);
344  $template->setCurrentBlock("files");
345  $template->setVariable('FILES', $table_gui->getHTML());
346  $template->parseCurrentBlock();
347  }
348  }
349 
350  if (strlen($this->object->getAllowedExtensions()))
351  {
352  $template->setCurrentBlock("allowed_extensions");
353  $template->setVariable("TXT_ALLOWED_EXTENSIONS", $this->object->prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
354  $template->parseCurrentBlock();
355  }
356  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($this->object->question, TRUE));
357  $template->setVariable("TEXT_UPLOAD", $this->object->prepareTextareaOutput($this->lng->txt('upload')));
358  $template->setVariable("TXT_UPLOAD_FILE", $this->object->prepareTextareaOutput($this->lng->txt('file_add')));
359  $template->setVariable("TXT_MAX_SIZE", $this->object->prepareTextareaOutput($this->lng->txt('file_notice') . ": " . $this->object->getMaxFilesizeAsString()));
360 
361  $questionoutput = $template->get();
362  if (!$show_question_only)
363  {
364  // get page object output
365  $questionoutput = $this->getILIASPage($questionoutput);
366  }
367  $questionoutput = $template->get();
368  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
369  return $pageoutput;
370  }
371 
377  function saveFeedback()
378  {
379  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
380  $errors = $this->feedback(true);
381  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
382  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
383  $this->object->cleanupMediaObjectUsage();
385  }
386 
392  function setQuestionTabs()
393  {
394  global $rbacsystem, $ilTabs;
395 
396  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
397  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
398  $q_type = $this->object->getQuestionType();
399 
400  if (strlen($q_type))
401  {
402  $classname = $q_type . "GUI";
403  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
404  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
405  }
406 
407  if ($_GET["q_id"])
408  {
409  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
410  {
411  // edit page
412  $ilTabs->addTarget("edit_content",
413  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
414  array("edit", "insert", "exec_pg"),
415  "", "", $force_active);
416  }
417 
418  // edit page
419  $ilTabs->addTarget("preview",
420  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
421  array("preview"),
422  "ilPageObjectGUI", "", $force_active);
423  }
424 
425  $force_active = false;
426  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
427  {
428  $url = "";
429  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
430  // edit question properties
431  $ilTabs->addTarget("edit_properties",
432  $url,
433  array("editQuestion", "save", "cancel", "saveEdit"),
434  $classname, "");
435  }
436 
437  if ($_GET["q_id"])
438  {
439  $ilTabs->addTarget("feedback",
440  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
441  array("feedback", "saveFeedback"),
442  $classname, "");
443  }
444 
445  if ($_GET["q_id"])
446  {
447  $ilTabs->addTarget("solution_hint",
448  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
449  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
450  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
451  ),
452  $classname,
453  ""
454  );
455  }
456 
457  // Assessment of questions sub menu entry
458  if ($_GET["q_id"])
459  {
460  $ilTabs->addTarget("statistics",
461  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
462  array("assessment"),
463  $classname, "");
464  }
465 
466  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
467  {
468  $ref_id = $_GET["calling_test"];
469  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
470  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
471  }
472  else
473  {
474  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
475  }
476  }
477 }
478 ?>