ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilEssayKeywordWizardInputGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2007 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.ilSingleChoiceWizardInputGUI.php";
25 
27 {
33  function setValue($a_value)
34  {
35  $this->values = array();
36  if (is_array( $a_value ))
37  {
38  if (is_array( $a_value['answer'] ))
39  {
40  foreach ($a_value['answer'] as $index => $value)
41  {
42  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
43  $answer = new ASS_AnswerMultipleResponseImage($value, $a_value['points'][$index], $index, $a_value['points_unchecked'][$index], $a_value['imagename'][$index]);
44  array_push( $this->values, $answer );
45  }
46  }
47  }
48  }
49 
55  function checkInput()
56  {
57  global $lng;
58 
59  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
60  if (is_array( $_POST[$this->getPostVar()] ))
61  {
62  $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive( $_POST[$this->getPostVar()], false,
64  )
65  );
66  }
67  $foundvalues = $_POST[$this->getPostVar()];
68  if (is_array( $foundvalues ))
69  {
70  // check answers
71  if (is_array( $foundvalues['answer'] ))
72  {
73  foreach ($foundvalues['answer'] as $aidx => $answervalue)
74  {
75  if (((strlen( $answervalue )) == 0) && (strlen( $foundvalues['imagename'][$aidx] ) == 0))
76  {
77  $this->setAlert( $lng->txt( "msg_input_is_required" ) );
78  return FALSE;
79  }
80  }
81  }
82  // check points
83  $max = 0;
84  if (is_array( $foundvalues['points'] ))
85  {
86  foreach ($foundvalues['points'] as $points)
87  {
88  if ($points > $max)
89  {
90  $max = $points;
91  }
92  if (((strlen( $points )) == 0) || (!is_numeric( $points )))
93  {
94  $this->setAlert( $lng->txt( "form_msg_numeric_value_required" ) );
95  return FALSE;
96  }
97  }
98  }
99  if ($max == 0)
100  {
101  $this->setAlert( $lng->txt( "enter_enough_positive_points" ) );
102  return false;
103  }
104 
105  if (is_array( $_FILES ) && count( $_FILES ) && $this->getSingleline())
106  {
107  if (!$this->hideImages)
108  {
109  if (is_array( $_FILES[$this->getPostVar()]['error']['image'] ))
110  {
111  foreach ($_FILES[$this->getPostVar()]['error']['image'] as $index => $error)
112  {
113  // error handling
114  if ($error > 0)
115  {
116  switch ($error)
117  {
118  case UPLOAD_ERR_INI_SIZE:
119  $this->setAlert( $lng->txt( "form_msg_file_size_exceeds" ) );
120  return false;
121  break;
122 
123  case UPLOAD_ERR_FORM_SIZE:
124  $this->setAlert( $lng->txt( "form_msg_file_size_exceeds" ) );
125  return false;
126  break;
127 
128  case UPLOAD_ERR_PARTIAL:
129  $this->setAlert( $lng->txt( "form_msg_file_partially_uploaded" ) );
130  return false;
131  break;
132 
133  case UPLOAD_ERR_NO_FILE:
134  if ($this->getRequired())
135  {
136  if ((!strlen( $foundvalues['imagename'][$index]
137  )) && (!strlen( $foundvalues['answer'][$index] ))
138  )
139  {
140  $this->setAlert( $lng->txt( "form_msg_file_no_upload" ) );
141  return false;
142  }
143  }
144  break;
145 
146  case UPLOAD_ERR_NO_TMP_DIR:
147  $this->setAlert( $lng->txt( "form_msg_file_missing_tmp_dir" ) );
148  return false;
149  break;
150 
151  case UPLOAD_ERR_CANT_WRITE:
152  $this->setAlert( $lng->txt( "form_msg_file_cannot_write_to_disk" ) );
153  return false;
154  break;
155 
156  case UPLOAD_ERR_EXTENSION:
157  $this->setAlert( $lng->txt( "form_msg_file_upload_stopped_ext" ) );
158  return false;
159  break;
160  }
161  }
162  }
163  }
164  else
165  {
166  if ($this->getRequired())
167  {
168  $this->setAlert( $lng->txt( "form_msg_file_no_upload" ) );
169  return false;
170  }
171  }
172 
173  if (is_array( $_FILES[$this->getPostVar()]['tmp_name']['image'] ))
174  {
175  foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname)
176  {
177  $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
178  $filename_arr = pathinfo( $filename );
179  $suffix = $filename_arr["extension"];
180  $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
181  $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
182  // check suffixes
183  if (strlen( $tmpname ) && is_array( $this->getSuffixes() ))
184  {
185  if (!in_array( strtolower( $suffix ), $this->getSuffixes() ))
186  {
187  $this->setAlert( $lng->txt( "form_msg_file_wrong_file_type" ) );
188  return false;
189  }
190  }
191  }
192  }
193 
194  if (is_array( $_FILES[$this->getPostVar()]['tmp_name']['image'] ))
195  {
196  foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname)
197  {
198  $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
199  $filename_arr = pathinfo( $filename );
200  $suffix = $filename_arr["extension"];
201  $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
202  $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
203  // virus handling
204  if (strlen( $tmpname ))
205  {
206  $vir = ilUtil::virusHandling( $tmpname, $filename );
207  if ($vir[0] == false)
208  {
209  $this->setAlert( $lng->txt( "form_msg_file_virus_found" ) . "<br />" . $vir[1] );
210  return false;
211  }
212  }
213  }
214  }
215  }
216  }
217  }
218  else
219  {
220  $this->setAlert( $lng->txt( "msg_input_is_required" ) );
221  return FALSE;
222  }
223 
224  return $this->checkSubItemsInput();
225  }
226 
232  function insert(&$a_tpl)
233  {
234  global $lng;
235 
236  $tpl = new ilTemplate("tpl.prop_essaykeywordswizardinput.html", true, true, "Modules/TestQuestionPool");
237  $i = 0;
238  foreach ($this->values as $value)
239  {
240  if ($this->getSingleline())
241  {
242  if (is_object( $value ))
243  {
244  $tpl->setCurrentBlock( "prop_text_propval" );
245  $tpl->setVariable( "PROPERTY_VALUE", ilUtil::prepareFormOutput( $value->getAnswertext() ) );
246  $tpl->parseCurrentBlock();
247  $tpl->setCurrentBlock( "prop_points_propval" );
248  $tpl->setVariable( "PROPERTY_VALUE", ilUtil::prepareFormOutput( $value->getPointsChecked() ) );
249  $tpl->parseCurrentBlock();
250  }
251  $tpl->setCurrentBlock( 'singleline' );
252  $tpl->setVariable( "SIZE", $this->getSize() );
253  $tpl->setVariable( "SINGLELINE_ID", $this->getPostVar() . "[answer][$i]" );
254  $tpl->setVariable( "SINGLELINE_ROW_NUMBER", $i );
255  $tpl->setVariable( "SINGLELINE_POST_VAR", $this->getPostVar() );
256  $tpl->setVariable( "MAXLENGTH", $this->getMaxLength() );
257  if ($this->getDisabled())
258  {
259  $tpl->setVariable( "DISABLED_SINGLELINE", " disabled=\"disabled\"" );
260  }
261  $tpl->parseCurrentBlock();
262  }
263  else {
264  if (!$this->getSingleline())
265  {
266  if (is_object( $value ))
267  {
268  $tpl->setCurrentBlock( "prop_points_propval" );
269  $tpl->setVariable( "PROPERTY_VALUE", ilUtil::prepareFormOutput( $value->getPoints() ) );
270  $tpl->parseCurrentBlock();
271  }
272  }
273  }
274 
275  $tpl->setCurrentBlock( "row" );
276  $class = ($i % 2 == 0) ? "even" : "odd";
277  if ($i == 0)
278  {
279  $class .= " first";
280  }
281  if ($i == count( $this->values ) - 1)
282  {
283  $class .= " last";
284  }
285  $tpl->setVariable( "ROW_CLASS", $class );
286  $tpl->setVariable( "POST_VAR", $this->getPostVar() );
287  $tpl->setVariable( "ROW_NUMBER", $i );
288  $tpl->setVariable( "ID", $this->getPostVar() . "[answer][$i]" );
289  $tpl->setVariable( "POINTS_ID", $this->getPostVar() . "[points][$i]" );
290  $tpl->setVariable( "CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]" );
291  $tpl->setVariable( "CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]" );
292  if ($this->getDisabled())
293  {
294  $tpl->setVariable( "DISABLED_POINTS", " disabled=\"disabled\"" );
295  }
296  $tpl->setVariable( "ADD_BUTTON", ilUtil::getImagePath( 'edit_add.png' ) );
297  $tpl->setVariable( "REMOVE_BUTTON", ilUtil::getImagePath( 'edit_remove.png' ) );
298  $tpl->parseCurrentBlock();
299  $i++;
300  }
301 
302  $tpl->setVariable( "ELEMENT_ID", $this->getPostVar() );
303  $tpl->setVariable( "TEXT_YES", $lng->txt( 'yes' ) );
304  $tpl->setVariable( "TEXT_NO", $lng->txt( 'no' ) );
305  $tpl->setVariable( "DELETE_IMAGE_HEADER", $lng->txt( 'delete_image_header' ) );
306  $tpl->setVariable( "DELETE_IMAGE_QUESTION", $lng->txt( 'delete_image_question' ) );
307  $tpl->setVariable( "ANSWER_TEXT", $lng->txt( 'answer_text' ) );
308  $tpl->setVariable( "POINTS_TEXT", $lng->txt( 'points' ) );
309  $tpl->setVariable( "COMMANDS_TEXT", $lng->txt( 'actions' ) );
310  $tpl->setVariable( "POINTS_CHECKED_TEXT", $lng->txt( 'checkbox_checked' ) );
311 
312  $a_tpl->setCurrentBlock( "prop_generic" );
313  $a_tpl->setVariable( "PROP_GENERIC", $tpl->get() );
314  $a_tpl->parseCurrentBlock();
315 
316  global $tpl;
317  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
319  $tpl->addJavascript( "./Modules/TestQuestionPool/templates/default/multiplechoicewizard.js" );
320  }
321 
322 }