ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilEssayKeywordWizardInputGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "./Modules/TestQuestionPool/classes/class.ilSingleChoiceWizardInputGUI.php";
5 
7 {
13  function setValue($a_value)
14  {
15  $this->values = array();
16  if (is_array( $a_value ))
17  {
18  if (is_array( $a_value['answer'] ))
19  {
20  foreach ($a_value['answer'] as $index => $value)
21  {
22  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
23  $answer = new ASS_AnswerMultipleResponseImage($value, $a_value['points'][$index], $index, $a_value['points_unchecked'][$index], $a_value['imagename'][$index]);
24  array_push( $this->values, $answer );
25  }
26  }
27  }
28  }
29 
35  function checkInput()
36  {
37  global $lng;
38 
39  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
40  if (is_array( $_POST[$this->getPostVar()] ))
41  {
42  $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive( $_POST[$this->getPostVar()], false,
44  )
45  );
46  }
47  $foundvalues = $_POST[$this->getPostVar()];
48  if (is_array( $foundvalues ))
49  {
50  // check answers
51  if (is_array( $foundvalues['answer'] ))
52  {
53  foreach ($foundvalues['answer'] as $aidx => $answervalue)
54  {
55  if (((strlen( $answervalue )) == 0) && (strlen( $foundvalues['imagename'][$aidx] ) == 0))
56  {
57  $this->setAlert( $lng->txt( "msg_input_is_required" ) );
58  return FALSE;
59  }
60  }
61  }
62  // check points
63  $max = 0;
64  if (is_array( $foundvalues['points'] ))
65  {
66  foreach ($foundvalues['points'] as $points)
67  {
68  if ($points > $max)
69  {
70  $max = $points;
71  }
72  if (((strlen( $points )) == 0) || (!is_numeric( $points )))
73  {
74  $this->setAlert( $lng->txt( "form_msg_numeric_value_required" ) );
75  return FALSE;
76  }
77  }
78  }
79  if ($max == 0)
80  {
81  $this->setAlert( $lng->txt( "enter_enough_positive_points" ) );
82  return false;
83  }
84 
85  if (is_array( $_FILES ) && count( $_FILES ) && $this->getSingleline())
86  {
87  if (!$this->hideImages)
88  {
89  if (is_array( $_FILES[$this->getPostVar()]['error']['image'] ))
90  {
91  foreach ($_FILES[$this->getPostVar()]['error']['image'] as $index => $error)
92  {
93  // error handling
94  if ($error > 0)
95  {
96  switch ($error)
97  {
98  case UPLOAD_ERR_INI_SIZE:
99  $this->setAlert( $lng->txt( "form_msg_file_size_exceeds" ) );
100  return false;
101  break;
102 
103  case UPLOAD_ERR_FORM_SIZE:
104  $this->setAlert( $lng->txt( "form_msg_file_size_exceeds" ) );
105  return false;
106  break;
107 
108  case UPLOAD_ERR_PARTIAL:
109  $this->setAlert( $lng->txt( "form_msg_file_partially_uploaded" ) );
110  return false;
111  break;
112 
113  case UPLOAD_ERR_NO_FILE:
114  if ($this->getRequired())
115  {
116  if ((!strlen( $foundvalues['imagename'][$index]
117  )) && (!strlen( $foundvalues['answer'][$index] ))
118  )
119  {
120  $this->setAlert( $lng->txt( "form_msg_file_no_upload" ) );
121  return false;
122  }
123  }
124  break;
125 
126  case UPLOAD_ERR_NO_TMP_DIR:
127  $this->setAlert( $lng->txt( "form_msg_file_missing_tmp_dir" ) );
128  return false;
129  break;
130 
131  case UPLOAD_ERR_CANT_WRITE:
132  $this->setAlert( $lng->txt( "form_msg_file_cannot_write_to_disk" ) );
133  return false;
134  break;
135 
136  case UPLOAD_ERR_EXTENSION:
137  $this->setAlert( $lng->txt( "form_msg_file_upload_stopped_ext" ) );
138  return false;
139  break;
140  }
141  }
142  }
143  }
144  else
145  {
146  if ($this->getRequired())
147  {
148  $this->setAlert( $lng->txt( "form_msg_file_no_upload" ) );
149  return false;
150  }
151  }
152 
153  if (is_array( $_FILES[$this->getPostVar()]['tmp_name']['image'] ))
154  {
155  foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname)
156  {
157  $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
158  $filename_arr = pathinfo( $filename );
159  $suffix = $filename_arr["extension"];
160  $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
161  $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
162  // check suffixes
163  if (strlen( $tmpname ) && is_array( $this->getSuffixes() ))
164  {
165  if (!in_array( strtolower( $suffix ), $this->getSuffixes() ))
166  {
167  $this->setAlert( $lng->txt( "form_msg_file_wrong_file_type" ) );
168  return false;
169  }
170  }
171  }
172  }
173 
174  if (is_array( $_FILES[$this->getPostVar()]['tmp_name']['image'] ))
175  {
176  foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname)
177  {
178  $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
179  $filename_arr = pathinfo( $filename );
180  $suffix = $filename_arr["extension"];
181  $mimetype = $_FILES[$this->getPostVar()]['type']['image'][$index];
182  $size_bytes = $_FILES[$this->getPostVar()]['size']['image'][$index];
183  // virus handling
184  if (strlen( $tmpname ))
185  {
186  $vir = ilUtil::virusHandling( $tmpname, $filename );
187  if ($vir[0] == false)
188  {
189  $this->setAlert( $lng->txt( "form_msg_file_virus_found" ) . "<br />" . $vir[1] );
190  return false;
191  }
192  }
193  }
194  }
195  }
196  }
197  }
198  else
199  {
200  $this->setAlert( $lng->txt( "msg_input_is_required" ) );
201  return FALSE;
202  }
203 
204  return $this->checkSubItemsInput();
205  }
206 
212  function insert(&$a_tpl)
213  {
214  global $lng;
215 
216  $tpl = new ilTemplate("tpl.prop_essaykeywordswizardinput.html", true, true, "Modules/TestQuestionPool");
217  $i = 0;
218  foreach ($this->values as $value)
219  {
220  if ($this->getSingleline())
221  {
222  if (is_object( $value ))
223  {
224  $tpl->setCurrentBlock( "prop_text_propval" );
225  $tpl->setVariable( "PROPERTY_VALUE", ilUtil::prepareFormOutput( $value->getAnswertext() ) );
226  $tpl->parseCurrentBlock();
227  $tpl->setCurrentBlock( "prop_points_propval" );
228  $tpl->setVariable( "PROPERTY_VALUE", ilUtil::prepareFormOutput( $value->getPointsChecked() ) );
229  $tpl->parseCurrentBlock();
230  }
231  $tpl->setCurrentBlock( 'singleline' );
232  $tpl->setVariable( "SIZE", $this->getSize() );
233  $tpl->setVariable( "SINGLELINE_ID", $this->getPostVar() . "[answer][$i]" );
234  $tpl->setVariable( "SINGLELINE_ROW_NUMBER", $i );
235  $tpl->setVariable( "SINGLELINE_POST_VAR", $this->getPostVar() );
236  $tpl->setVariable( "MAXLENGTH", $this->getMaxLength() );
237  if ($this->getDisabled())
238  {
239  $tpl->setVariable( "DISABLED_SINGLELINE", " disabled=\"disabled\"" );
240  }
241  $tpl->parseCurrentBlock();
242  }
243  else {
244  if (!$this->getSingleline())
245  {
246  if (is_object( $value ))
247  {
248  $tpl->setCurrentBlock( "prop_points_propval" );
249  $tpl->setVariable( "PROPERTY_VALUE", ilUtil::prepareFormOutput( $value->getPoints() ) );
250  $tpl->parseCurrentBlock();
251  }
252  }
253  }
254 
255  $tpl->setCurrentBlock( "row" );
256  $class = ($i % 2 == 0) ? "even" : "odd";
257  if ($i == 0)
258  {
259  $class .= " first";
260  }
261  if ($i == count( $this->values ) - 1)
262  {
263  $class .= " last";
264  }
265  $tpl->setVariable( "ROW_CLASS", $class );
266  $tpl->setVariable( "POST_VAR", $this->getPostVar() );
267  $tpl->setVariable( "ROW_NUMBER", $i );
268  $tpl->setVariable( "ID", $this->getPostVar() . "[answer][$i]" );
269  $tpl->setVariable( "POINTS_ID", $this->getPostVar() . "[points][$i]" );
270  $tpl->setVariable( "CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]" );
271  $tpl->setVariable( "CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]" );
272  if ($this->getDisabled())
273  {
274  $tpl->setVariable( "DISABLED_POINTS", " disabled=\"disabled\"" );
275  }
276  $tpl->setVariable( "ADD_BUTTON", ilUtil::getImagePath( 'edit_add.png' ) );
277  $tpl->setVariable( "REMOVE_BUTTON", ilUtil::getImagePath( 'edit_remove.png' ) );
278  $tpl->parseCurrentBlock();
279  $i++;
280  }
281 
282  $tpl->setVariable( "ELEMENT_ID", $this->getPostVar() );
283  $tpl->setVariable( "TEXT_YES", $lng->txt( 'yes' ) );
284  $tpl->setVariable( "TEXT_NO", $lng->txt( 'no' ) );
285  $tpl->setVariable( "DELETE_IMAGE_HEADER", $lng->txt( 'delete_image_header' ) );
286  $tpl->setVariable( "DELETE_IMAGE_QUESTION", $lng->txt( 'delete_image_question' ) );
287  $tpl->setVariable( "ANSWER_TEXT", $lng->txt( 'answer_text' ) );
288  $tpl->setVariable( "POINTS_TEXT", $lng->txt( 'points' ) );
289  $tpl->setVariable( "COMMANDS_TEXT", $lng->txt( 'actions' ) );
290  $tpl->setVariable( "POINTS_CHECKED_TEXT", $lng->txt( 'checkbox_checked' ) );
291 
292  $a_tpl->setCurrentBlock( "prop_generic" );
293  $a_tpl->setVariable( "PROP_GENERIC", $tpl->get() );
294  $a_tpl->parseCurrentBlock();
295 
296  global $tpl;
297  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
299  $tpl->addJavascript( "./Modules/TestQuestionPool/templates/default/multiplechoicewizard.js" );
300  }
301 
302 }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getMaxLength()
Get Max Length.
$_POST['username']
Definition: cron.php:12
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
& _getUsedHTMLTagsAsString($a_module="")
Returns a string of all allowed HTML tags for text editing.
getPostVar()
Get Post Variable.
ASS_AnswerBinaryStateImage is a class for answers with a binary state indicator (checked/unchecked, set/unset) and an image file.
checkInput()
Check input, strip slashes etc.
setAlert($a_alert)
Set Alert Text.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
static initDomEvent()
Init YUI DomEvent.
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$filename
Definition: buildRTE.php:89
This class represents a single choice wizard property in a property form.
global $lng
Definition: privfeed.php:40