4 require_once
'Modules/TestQuestionPool/classes/class.ilSingleChoiceWizardInputGUI.php';
5 require_once
'Modules/TestQuestionPool/classes/class.ilAssKprimChoiceAnswer.php';
6 require_once
'Services/MediaObjects/classes/class.ilObjMediaObject.php';
38 parent::__construct($a_title, $a_postvar);
47 $this->
files = array();
49 $this->ignoreMissingUploadsEnabled =
false;
74 $this->values = array();
76 if (is_array($a_value) && is_array($a_value[
'answer'])) {
80 $answer->setPosition(
$index);
81 $answer->setAnswertext(
$value);
82 $answer->setImageFile($a_value[
'imagename'][
$index]);
84 if (strlen($a_value[
'correctness'][$index])) {
85 $answer->setCorrectness((
bool) $a_value[
'correctness'][$index]);
88 $answer->setThumbPrefix($this->qstObject->getThumbPrefix());
89 $answer->setImageFsDir($this->qstObject->getImagePath());
90 $answer->setImageWebDir($this->qstObject->getImagePathWeb());
92 $this->values[] = $answer;
104 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
117 if (is_array($foundvalues)) {
119 if (is_array($foundvalues[
'answer'])) {
120 foreach ($foundvalues[
'answer'] as $aidx => $answervalue) {
121 if (((strlen($answervalue)) == 0) && (strlen($foundvalues[
'imagename'][$aidx]) == 0)) {
129 if (!isset($foundvalues[
'correctness']) || count($foundvalues[
'correctness']) < count($foundvalues[
'answer'])) {
148 public function insert($a_tpl)
150 $tpl =
new ilTemplate(
"tpl.prop_kprimchoicewizardinput.html",
true,
true,
"Modules/TestQuestionPool");
152 foreach ($this->values as
$value) {
158 if (!$this->hideImages) {
159 if (strlen($value->getImageFile())) {
160 $imagename = $value->getImageWebPath();
162 if (($this->
getSingleline()) && ($this->qstObject->getThumbSize())) {
163 if (@file_exists($value->getThumbFsPath())) {
164 $imagename = $value->getThumbWebPath();
168 $tpl->setCurrentBlock(
'image');
169 $tpl->setVariable(
'SRC_IMAGE', $imagename);
170 $tpl->setVariable(
'IMAGE_NAME', $value->getImageFile());
172 $tpl->setVariable(
"TXT_DELETE_EXISTING", $this->lng->txt(
"delete_existing_file"));
173 $tpl->setVariable(
"IMAGE_ROW_NUMBER", $value->getPosition());
175 $tpl->parseCurrentBlock();
177 $tpl->setCurrentBlock(
'addimage');
178 $tpl->setVariable(
"IMAGE_BROWSE", $this->lng->txt(
'select_file'));
179 $tpl->setVariable(
"IMAGE_ID", $this->
getPostVar() .
"[image][{$value->getPosition()}]");
180 $tpl->setVariable(
"IMAGE_SUBMIT", $this->lng->txt(
"upload"));
181 $tpl->setVariable(
"IMAGE_ROW_NUMBER", $value->getPosition());
183 $tpl->parseCurrentBlock();
186 $tpl->setCurrentBlock(
"prop_text_propval");
188 $tpl->parseCurrentBlock();
190 $tpl->setCurrentBlock(
'singleline');
192 $tpl->setVariable(
"SINGLELINE_ID", $this->
getPostVar() .
"[answer][{$value->getPosition()}]");
193 $tpl->setVariable(
"SINGLELINE_ROW_NUMBER", $value->getPosition());
197 $tpl->setVariable(
"DISABLED_SINGLELINE",
" disabled=\"disabled\"");
199 $tpl->parseCurrentBlock();
201 $tpl->setCurrentBlock(
'multiline');
203 $tpl->setVariable(
"MULTILINE_ID", $this->
getPostVar() .
"[answer][{$value->getPosition()}]");
204 $tpl->setVariable(
"MULTILINE_ROW_NUMBER", $value->getPosition());
207 $tpl->setVariable(
"DISABLED_MULTILINE",
" disabled=\"disabled\"");
209 $tpl->parseCurrentBlock();
212 $tpl->setCurrentBlock(
"move");
213 $tpl->setVariable(
"CMD_UP",
"cmd[up" . $this->
getFieldId() .
"][{$value->getPosition()}]");
214 $tpl->setVariable(
"CMD_DOWN",
"cmd[down" . $this->
getFieldId() .
"][{$value->getPosition()}]");
215 $tpl->setVariable(
"UP_ID",
"up_{$this->getPostVar()}[{$value->getPosition()}]");
216 $tpl->setVariable(
"DOWN_ID",
"down_{$this->getPostVar()}[{$value->getPosition()}]");
219 $tpl->parseCurrentBlock();
222 $tpl->setCurrentBlock(
"row");
225 $tpl->setVariable(
"ROW_NUMBER", $value->getPosition());
226 $tpl->setVariable(
"ID", $this->
getPostVar() .
"[answer][{$value->getPosition()}]");
229 "CORRECTNESS_TRUE_ID",
230 $this->
getPostVar() .
"[correctness][{$value->getPosition()}][true]" 233 "CORRECTNESS_FALSE_ID",
234 $this->
getPostVar() .
"[correctness][{$value->getPosition()}][false]" 236 $tpl->setVariable(
"CORRECTNESS_TRUE_VALUE", 1);
237 $tpl->setVariable(
"CORRECTNESS_FALSE_VALUE", 0);
239 if ($value->getCorrectness() !== null) {
240 if ($value->getCorrectness()) {
241 $tpl->setVariable(
'CORRECTNESS_TRUE_SELECTED',
' checked="checked"');
243 $tpl->setVariable(
'CORRECTNESS_FALSE_SELECTED',
' checked="checked"');
248 $tpl->setVariable(
"DISABLED_CORRECTNESS",
" disabled=\"disabled\"");
251 $tpl->parseCurrentBlock();
255 if (!$this->hideImages) {
257 $suff_str = $delim =
"";
259 $suff_str .= $delim .
"." .
$suffix;
262 $tpl->setCurrentBlock(
'allowed_image_suffixes');
263 $tpl->setVariable(
"TXT_ALLOWED_SUFFIXES", $this->lng->txt(
"file_allowed_suffixes") .
" " . $suff_str);
264 $tpl->parseCurrentBlock();
267 $tpl->setCurrentBlock(
"image_heading");
268 $tpl->setVariable(
"ANSWER_IMAGE", $this->lng->txt(
'answer_image'));
270 $tpl->parseCurrentBlock();
274 foreach ($this->qstObject->getValidOptionLabels() as $optionLabel) {
275 if ($this->qstObject->isCustomOptionLabel($optionLabel)) {
279 $tpl->setCurrentBlock(
'option_label_translations');
280 $tpl->setVariable(
'OPTION_LABEL', $optionLabel);
281 $tpl->setVariable(
'TRANSLATION_TRUE', $this->qstObject->getTrueOptionLabelTranslation($this->lng, $optionLabel));
282 $tpl->setVariable(
'TRANSLATION_FALSE', $this->qstObject->getFalseOptionLabelTranslation($this->lng, $optionLabel));
283 $tpl->parseCurrentBlock();
287 $tpl->setVariable(
"DELETE_IMAGE_HEADER", $this->lng->txt(
'delete_image_header'));
288 $tpl->setVariable(
"DELETE_IMAGE_QUESTION", $this->lng->txt(
'delete_image_question'));
289 $tpl->setVariable(
"ANSWER_TEXT", $this->lng->txt(
'answer_text'));
291 $tpl->setVariable(
"OPTIONS_TEXT", $this->lng->txt(
'options'));
297 $a_tpl->setCurrentBlock(
"prop_generic");
298 $a_tpl->setVariable(
"PROP_GENERIC",
$tpl->get());
299 $a_tpl->parseCurrentBlock();
301 include_once
"./Services/YUI/classes/class.ilYuiUtil.php";
302 $this->tpl->addJavascript(
"./Services/Form/js/ServiceFormWizardInput.js");
303 $this->tpl->addJavascript(
"./Modules/TestQuestionPool/templates/default/kprimchoicewizard.js");
304 $this->tpl->addJavascript(
'Modules/TestQuestionPool/js/ilAssKprimChoice.js');
309 if (is_array($_FILES) && count($_FILES) && $this->
getSingleline()) {
310 if (!$this->hideImages) {
311 if (is_array($_FILES[$this->
getPostVar()][
'error'][
'image'])) {
312 foreach ($_FILES[$this->
getPostVar()][
'error'][
'image'] as
$index => $error) {
316 case UPLOAD_ERR_INI_SIZE:
317 $this->
setAlert($this->lng->txt(
"form_msg_file_size_exceeds"));
321 case UPLOAD_ERR_FORM_SIZE:
322 $this->
setAlert($this->lng->txt(
"form_msg_file_size_exceeds"));
326 case UPLOAD_ERR_PARTIAL:
327 $this->
setAlert($this->lng->txt(
"form_msg_file_partially_uploaded"));
331 case UPLOAD_ERR_NO_FILE:
333 if ((!strlen($foundvalues[
'imagename'][
$index])) && (!strlen($foundvalues[
'answer'][$index]))) {
334 $this->
setAlert($this->lng->txt(
"form_msg_file_no_upload"));
340 case UPLOAD_ERR_NO_TMP_DIR:
341 $this->
setAlert($this->lng->txt(
"form_msg_file_missing_tmp_dir"));
345 case UPLOAD_ERR_CANT_WRITE:
346 $this->
setAlert($this->lng->txt(
"form_msg_file_cannot_write_to_disk"));
350 case UPLOAD_ERR_EXTENSION:
351 $this->
setAlert($this->lng->txt(
"form_msg_file_upload_stopped_ext"));
359 $this->
setAlert($this->lng->txt(
"form_msg_file_no_upload"));
364 if (is_array($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'])) {
365 foreach ($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'] as
$index => $tmpname) {
368 $suffix = $filename_arr[
"extension"];
372 if (strlen($tmpname) && is_array($this->
getSuffixes())) {
374 $this->
setAlert($this->lng->txt(
"form_msg_file_wrong_file_type"));
381 if (is_array($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'])) {
382 foreach ($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'] as
$index => $tmpname) {
389 if (!preg_match(
"/^image/", $mimetype)) {
390 $_FILES[$this->
getPostVar()][
'error'][
'image'][
$index] = self::CUSTOM_UPLOAD_ERR;
391 $this->
setAlert($this->lng->txt(
"form_msg_file_wrong_mime_type"));
398 if (is_array($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'])) {
399 foreach ($_FILES[$this->
getPostVar()][
'tmp_name'][
'image'] as
$index => $tmpname) {
402 $suffix = $filename_arr[
"extension"];
406 if (strlen($tmpname)) {
408 if ($vir[0] ==
false) {
409 $_FILES[$this->
getPostVar()][
'error'][
'image'][
$index] = self::CUSTOM_UPLOAD_ERR;
410 $this->
setAlert($this->lng->txt(
"form_msg_file_virus_found") .
"<br />" . $vir[1]);
424 foreach ($_FILES[$this->
getPostVar()][
'error'][
'image'] as
$index => $err) {
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getMaxLength()
Get Max Length.
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
static _getUsedHTMLTagsAsString($a_module="")
Returns a string of all allowed HTML tags for text editing.
static get($a_glyph, $a_text="")
Get glyph html.
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.