ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilPropertyFormGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/Form/classes/class.ilFormGUI.php");
5
6// please do not add any more includes here if things are not really
7// highly re-used
8include_once("./Services/Form/classes/class.ilFormPropertyGUI.php");
9include_once("./Services/Form/classes/class.ilSubEnabledFormPropertyGUI.php");
10include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
11include_once("./Services/Form/classes/class.ilCustomInputGUI.php");
12include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
13include_once("./Services/Form/classes/class.ilFileInputGUI.php");
14include_once("./Services/Form/classes/class.ilImageFileInputGUI.php");
15include_once('./Services/Form/classes/class.ilFlashFileInputGUI.php');
16include_once("./Services/Form/classes/class.ilLocationInputGUI.php");
17include_once("./Services/Form/classes/class.ilRadioGroupInputGUI.php");
18include_once("./Services/Form/classes/class.ilCheckboxGroupInputGUI.php");
19include_once("./Services/Form/classes/class.ilFormSectionHeaderGUI.php");
20include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
21include_once("./Services/Form/classes/class.ilTextAreaInputGUI.php");
22include_once("./Services/Form/classes/class.ilTextInputGUI.php");
23include_once("./Services/Form/classes/class.ilDurationInputGUI.php");
24include_once("./Services/Form/classes/class.ilFeedUrlInputGUI.php");
25include_once("./Services/Form/classes/class.ilNonEditableValueGUI.php");
26include_once("./Services/Form/classes/class.ilRegExpInputGUI.php");
27include_once('./Services/Form/classes/class.ilColorPickerInputGUI.php');
28include_once('./Services/Form/classes/class.ilPasswordInputGUI.php');
29include_once('./Services/Form/classes/class.ilUserLoginInputGUI.php');
30include_once('./Services/Form/classes/class.ilEMailInputGUI.php');
31include_once('./Services/Form/classes/class.ilHiddenInputGUI.php');
32include_once('./Services/Form/classes/class.ilNumberInputGUI.php');
33include_once('./Services/Form/classes/class.ilCSSRectInputGUI.php');
34include_once('./Services/Form/classes/class.ilTextWizardInputGUI.php');
35include_once './Services/Form/classes/class.ilFileWizardInputGUI.php';
36include_once './Services/Form/classes/class.ilFormulaInputGUI.php';
37include_once './Services/Form/classes/class.ilBirthdayInputGUI.php';
38
48{
49 private $buttons = array();
50 private $items = array();
51 protected $mode = "std";
52 protected $check_input_called = false;
53 protected $disable_standard_message = false;
54 protected $top_anchor = "il_form_top";
55 protected $titleicon = false;
56 protected $description = "";
57 protected $tbl_width = false;
58 protected $show_top_buttons = true;
59 protected $reloaded_files;
60 protected $hide_labels = false;
61
68 {
69 global $lng;
70
71 $lng->loadLanguageModule("form");
72 parent::ilFormGUI();
73
74 // avoid double submission
75 $this->setPreventDoubleSubmission(true);
76
77 // do it as early as possible
78 $this->rebuildUploadedFiles();
79 }
80
84 function &executeCommand()
85 {
86 global $ilCtrl;
87
88 $next_class = $ilCtrl->getNextClass($this);
89 $cmd = $ilCtrl->getCmd();
90
91 switch($next_class)
92 {
93 case 'ilformpropertydispatchgui':
94 $ilCtrl->saveParameter($this, 'postvar');
95 include_once './Services/Form/classes/class.ilFormPropertyDispatchGUI.php';
96 $form_prop_dispatch = new ilFormPropertyDispatchGUI();
97 $item = $this->getItemByPostVar($_REQUEST["postvar"]);
98 $form_prop_dispatch->setItem($item);
99 return $ilCtrl->forwardCommand($form_prop_dispatch);
100 break;
101
102 }
103 return false;
104 }
105
113 final public function setTableWidth($a_width)
114 {
115 $this->tbl_width = $a_width;
116 }
117
124 final public function getTableWidth()
125 {
126 return $this->tbl_width;
127 }
128
134 function setMode($a_mode)
135 {
136 $this->mode = $a_mode;
137 }
138
144 function getMode()
145 {
146 return $this->mode;
147 }
148
154 function setTitle($a_title)
155 {
156 $this->title = $a_title;
157 }
158
164 function getTitle()
165 {
166 return $this->title;
167 }
168
174 function setTitleIcon($a_titleicon)
175 {
176 $this->titleicon = $a_titleicon;
177 }
178
184 function getTitleIcon()
185 {
186 return $this->titleicon;
187 }
188
194 function setDescription($a_val)
195 {
196 $this->description = $a_val;
197 }
198
204 function getDescription()
205 {
206 return $this->description;
207 }
208
214 function setTopAnchor($a_val)
215 {
216 $this->top_anchor = $a_val;
217 }
218
224 function getTopAnchor()
225 {
226 return $this->top_anchor;
227 }
228
232 public function setShowTopButtons($a_val)
233 {
234 $this->show_top_buttons = $a_val;
235 }
236
240 public function getShowTopButtons()
241 {
243 }
244
250 function addItem($a_item)
251 {
252 $a_item->setParentForm($this);
253 return $this->items[] = $a_item;
254 }
255
261 function removeItemByPostVar($a_post_var)
262 {
263 foreach ($this->items as $key => $item)
264 {
265 if (method_exists($item, "getPostVar") && $item->getPostVar() == $a_post_var)
266 {
267 unset($this->items[$key]);
268 }
269 }
270 }
271
277 function getItemByPostVar($a_post_var)
278 {
279 foreach ($this->items as $key => $item)
280 {
281 if ($item->getType() != "section_header")
282 {
283 //if ($item->getPostVar() == $a_post_var)
284 $ret = $item->getItemByPostVar($a_post_var);
285 if (is_object($ret))
286 {
287 return $ret;
288 }
289 }
290 }
291
292 return false;
293 }
294
300 function setItems($a_items)
301 {
302 $this->items = $a_items;
303 }
304
310 function getItems()
311 {
312 return $this->items;
313 }
314
321 public function getInputItemsRecursive()
322 {
323 $inputItems = array();
324
325 foreach($this->items as $item)
326 {
327 if( $item->getType() == 'section_header' )
328 {
329 continue;
330 }
331
332 $inputItems[] = $item;
333
334 if( $item instanceof ilSubEnabledFormPropertyGUI )
335 {
336 $inputItems = array_merge( $inputItems, $item->getSubInputItemsRecursive() );
337 }
338 }
339
340 return $inputItems;
341 }
342
349 {
350 $this->disable_standard_message = $a_val;
351 }
352
359 {
361 }
362
368 function getHideLabels()
369 {
370 return $this->hide_labels;
371 }
372
378 function setHideLabels($a_value = true)
379 {
380 $this->hide_labels = $a_value;
381 }
382
388 function setValuesByArray($a_values, $a_restrict_to_value_keys = false)
389 {
390 foreach($this->items as $item)
391 {
392 if(!($a_restrict_to_value_keys) ||
393 in_array($item->getPostVar(), array_keys($a_values)))
394 {
395 $item->setValueByArray($a_values);
396 }
397 }
398 }
399
405 {
406 foreach($this->items as $item)
407 {
408 $item->setValueByArray($_POST);
409 }
410 }
411
418 function checkInput()
419 {
420 global $lng;
421
422 if ($this->check_input_called)
423 {
424 die ("Error: ilPropertyFormGUI->checkInput() called twice.");
425 }
426
427 $ok = true;
428 foreach($this->items as $item)
429 {
430 $item_ok = $item->checkInput();
431 if(!$item_ok)
432 {
433 $ok = false;
434 }
435 }
436
437 // check if POST is missint completely (if post_max_size exceeded)
438 if (count($this->items) > 0 && !is_array($_POST))
439 {
440 $ok = false;
441 }
442
443 $this->check_input_called = true;
444
445
446
447 // try to keep uploads for another try
448 if(!$ok && $_POST["ilfilehash"] && sizeof($_FILES))
449 {
450 $hash = $_POST["ilfilehash"];
451
452 foreach($_FILES as $field => $data)
453 {
454 // we support up to 2 nesting levels (see test/assesment)
455 if(is_array($data["tmp_name"]))
456 {
457 foreach($data["tmp_name"] as $idx => $upload)
458 {
459 if(is_array($upload))
460 {
461 foreach($upload as $idx2 => $file)
462 {
463 if($file && is_uploaded_file($file))
464 {
465 $file_name = $data["name"][$idx][$idx2];
466 $file_type = $data["type"][$idx][$idx2];
467 $this->keepFileUpload($hash, $field, $file, $file_name, $file_type, $idx, $idx2);
468 }
469 }
470 }
471 else if($upload && is_uploaded_file($upload))
472 {
473 $file_name = $data["name"][$idx];
474 $file_type = $data["type"][$idx];
475 $this->keepFileUpload($hash, $field, $upload, $file_name, $file_type, $idx);
476 }
477 }
478 }
479 else
480 {
481 $this->keepFileUpload($hash, $field, $data["tmp_name"], $data["name"], $data["type"]);
482 }
483 }
484 }
485
486
487 if (!$ok && !$this->getDisableStandardMessage())
488 {
489 ilUtil::sendFailure($lng->txt("form_input_not_valid"));
490 }
491 return $ok;
492 }
493
504 public function getInput($a_post_var, $ensureValidation = true)
505 {
506 // this check ensures, that checkInput has been called (incl. stripSlashes())
507 if (!$this->check_input_called && $ensureValidation)
508 {
509 die ("Error: ilPropertyFormGUI->getInput() called without calling checkInput() first.");
510 }
511
512 return $_POST[$a_post_var];
513 }
514
524 function addCustomProperty($a_title, $a_html, $a_info = "",
525 $a_alert = "", $a_required = false)
526 {
527 $this->properties[] = array ("type" => "custom",
528 "title" => $a_title,
529 "html" => $a_html,
530 "info" => $a_info);
531 }
532
539 function addCommandButton($a_cmd, $a_text)
540 {
541 $this->buttons[] = array("cmd" => $a_cmd, "text" => $a_text);
542 }
543
544
550 public function getCommandButtons() {
551 return $this->buttons;
552 }
553
558 {
559 $this->buttons = array();
560 }
561
565 function getContent()
566 {
567 global $lng, $tpl, $ilUser, $ilSetting;
568
569 include_once("./Services/YUI/classes/class.ilYuiUtil.php");
573
574 $tpl->addJavaScript("./Services/JavaScript/js/Basic.js");
575 $tpl->addJavaScript("Services/Form/js/Form.js");
576
577 $this->tpl = new ilTemplate("tpl.property_form.html", true, true, "Services/Form");
578
579 // check if form has not title and first item is a section header
580 // -> use section header for title and remove section header
581 // -> command buttons are presented on top
582 $fi = $this->items[0];
583 if ($this->getMode() == "std" &&
584 $this->getTitle() == "" &&
585 is_object($fi) && $fi->getType() == "section_header"
586 )
587 {
588 $this->setTitle($fi->getTitle());
589 unset($this->items[0]);
590 }
591
592
593 // title icon
594 if ($this->getTitleIcon() != "" && @is_file($this->getTitleIcon()))
595 {
596 $this->tpl->setCurrentBlock("title_icon");
597 $this->tpl->setVariable("IMG_ICON", $this->getTitleIcon());
598 $this->tpl->parseCurrentBlock();
599 }
600
601 // title
602 if ($this->getTitle() != "")
603 {
604 // commands on top
605 if (count($this->buttons) > 0 && $this->getShowTopButtons() && count($this->items) > 2)
606 {
607 // command buttons
608 foreach($this->buttons as $button)
609 {
610 $this->tpl->setCurrentBlock("cmd2");
611 $this->tpl->setVariable("CMD", $button["cmd"]);
612 $this->tpl->setVariable("CMD_TXT", $button["text"]);
613 $this->tpl->parseCurrentBlock();
614 }
615 $this->tpl->setCurrentBlock("commands2");
616 $this->tpl->parseCurrentBlock();
617 }
618
619 if (is_object($ilSetting))
620 {
621 if ($ilSetting->get('char_selector_availability') > 0)
622 {
623 require_once 'Services/UIComponent/CharSelector/classes/class.ilCharSelectorGUI.php';
625 {
626 $char_selector = ilCharSelectorGUI::_getCurrentGUI();
627 if ($char_selector->getConfig()->getAvailability() == ilCharSelectorConfig::ENABLED)
628 {
629 $char_selector->addToPage();
630 $this->tpl->TouchBlock('char_selector');
631 }
632 }
633 }
634 }
635
636 $this->tpl->setCurrentBlock("header");
637 $this->tpl->setVariable("TXT_TITLE", $this->getTitle());
638 $this->tpl->setVariable("LABEL", $this->getTopAnchor());
639 $this->tpl->setVariable("TXT_DESCRIPTION", $this->getDescription());
640 $this->tpl->parseCurrentBlock();
641 }
642 $this->tpl->touchBlock("item");
643
644 // properties
645 $this->required_text = false;
646 foreach($this->items as $item)
647 {
648 if ($item->getType() != "hidden")
649 {
650 $this->insertItem($item);
651 }
652 }
653
654 // required
655 if ($this->required_text && $this->getMode() == "std")
656 {
657 $this->tpl->setCurrentBlock("required_text");
658 $this->tpl->setVariable("TXT_REQUIRED", $lng->txt("required_field"));
659 $this->tpl->parseCurrentBlock();
660 }
661
662 // command buttons
663 foreach($this->buttons as $button)
664 {
665 $this->tpl->setCurrentBlock("cmd");
666 $this->tpl->setVariable("CMD", $button["cmd"]);
667 $this->tpl->setVariable("CMD_TXT", $button["text"]);
668 $this->tpl->parseCurrentBlock();
669 }
670
671 // #18808
672 if ($this->getMode() != "subform")
673 {
674 // try to keep uploads even if checking input fails
675 if($this->getMultipart())
676 {
677 $hash = $_POST["ilfilehash"];
678 if(!$hash)
679 {
680 $hash = md5(uniqid(mt_rand(), true));
681 }
682 $fhash = new ilHiddenInputGUI("ilfilehash");
683 $fhash->setValue($hash);
684 $this->addItem($fhash);
685 }
686 }
687
688 // hidden properties
689 $hidden_fields = false;
690 foreach($this->items as $item)
691 {
692 if ($item->getType() == "hidden")
693 {
694 $item->insert($this->tpl);
695 $hidden_fields = true;
696 }
697 }
698
699 if ($this->required_text || count($this->buttons) > 0 || $hidden_fields)
700 {
701 $this->tpl->setCurrentBlock("commands");
702 $this->tpl->parseCurrentBlock();
703 }
704
705
706 if ($this->getMode() == "subform")
707 {
708 $this->tpl->touchBlock("sub_table");
709 }
710 else
711 {
712 $this->tpl->touchBlock("std_table");
713 $this->tpl->setVariable('STD_TABLE_WIDTH',$this->getTableWidth());
714 }
715
716 return $this->tpl->get();
717 }
718
719 protected function hideRequired($a_type)
720 {
721 // #15818
722 return in_array($a_type, array("non_editable_value"));
723 }
724
725 function insertItem($item, $a_sub_item = false)
726 {
727 global $tpl, $lng;
728
729
730 $cfg = array();
731
732 //if(method_exists($item, "getMulti") && $item->getMulti())
733 if ($item instanceof ilMultiValuesItem && $item->getMulti())
734 {
735 $tpl->addJavascript("./Services/Form/js/ServiceFormMulti.js");
736
737 $this->tpl->setCurrentBlock("multi_in");
738 $this->tpl->setVariable("ID", $item->getFieldId());
739 $this->tpl->parseCurrentBlock();
740
741 $this->tpl->touchBlock("multi_out");
742
743
744 // add hidden item to enable preset multi items
745 // not used yet, should replace hidden field stuff
746 $multi_values = $item->getMultiValues();
747 if(is_array($multi_values) && sizeof($multi_values) > 1)
748 {
749 $multi_value = new ilHiddenInputGUI("ilMultiValues~".$item->getPostVar());
750 $multi_value->setValue(implode("~", $multi_values));
751 $this->addItem($multi_value);
752 }
753 $cfg["multi_values"] = $multi_values;
754 }
755
756 $item->insert($this->tpl);
757
758 if ($item->getType() == "file" || $item->getType() == "image_file")
759 {
760 $this->setMultipart(true);
761 }
762
763 if ($item->getType() != "section_header")
764 {
765 $cfg["id"] = $item->getFieldId();
766
767 // info text
768 if ($item->getInfo() != "")
769 {
770 $this->tpl->setCurrentBlock("description");
771 $this->tpl->setVariable("PROPERTY_DESCRIPTION",
772 $item->getInfo());
773 $this->tpl->parseCurrentBlock();
774 }
775
776 if ($this->getMode() == "subform")
777 {
778 // required
779 if (!$this->hideRequired($item->getType()))
780 {
781 if ($item->getRequired())
782 {
783 $this->tpl->touchBlock("sub_required");
784 $this->required_text = true;
785 }
786 }
787
788 // hidden title (for accessibility, e.g. file upload)
789 if ($item->getHiddenTitle() != "")
790 {
791 $this->tpl->setCurrentBlock("sub_hid_title");
792 $this->tpl->setVariable("SPHID_TITLE",
793 $item->getHiddenTitle());
794 $this->tpl->parseCurrentBlock();
795 }
796
797 $this->tpl->setCurrentBlock("sub_prop_start");
798 $this->tpl->setVariable("PROPERTY_TITLE", $item->getTitle());
799 $this->tpl->setVariable("PROPERTY_CLASS", "il_".$item->getType());
800 if ($item->getType() != "non_editable_value")
801 {
802 $this->tpl->setVariable("LAB_ID", $item->getFieldId());
803 }
804 $this->tpl->parseCurrentBlock();
805 }
806 else
807 {
808 // required
809 if (!$this->hideRequired($item->getType()))
810 {
811 if ($item->getRequired())
812 {
813 $this->tpl->touchBlock("required");
814 $this->required_text = true;
815 }
816 }
817
818 // hidden title (for accessibility, e.g. file upload)
819 if ($item->getHiddenTitle() != "")
820 {
821 $this->tpl->setCurrentBlock("std_hid_title");
822 $this->tpl->setVariable("PHID_TITLE",
823 $item->getHiddenTitle());
824 $this->tpl->parseCurrentBlock();
825 }
826
827 $this->tpl->setCurrentBlock("std_prop_start");
828 $this->tpl->setVariable("PROPERTY_TITLE", $item->getTitle());
829 if ($item->getType() != "non_editable_value")
830 {
831 $this->tpl->setVariable("LAB_ID", $item->getFieldId());
832 }
833 if ($this->getHideLabels())
834 {
835 $this->tpl->setVariable("HIDE_LABELS_STYLE", " ilFormOptionHidden");
836 }
837 $this->tpl->parseCurrentBlock();
838 }
839
840 // alert
841 if ($item->getType() != "non_editable_value" && $item->getAlert() != "")
842 {
843 $this->tpl->setCurrentBlock("alert");
844 $this->tpl->setVariable("IMG_ALERT",
845 ilUtil::getImagePath("icon_alert.svg"));
846 $this->tpl->setVariable("ALT_ALERT",
847 $lng->txt("alert"));
848 $this->tpl->setVariable("TXT_ALERT",
849 $item->getAlert());
850 $this->tpl->parseCurrentBlock();
851 }
852
853 // subitems
854 $sf = null;
855 if ($item->getType() != "non_editable_value" or 1)
856 {
857 $sf = $item->getSubForm();
858 if ($item->hideSubForm() && is_object($sf))
859 {
860 $this->tpl->setCurrentBlock("sub_form_hide");
861 $this->tpl->setVariable("DSFID", $item->getFieldId());
862 $this->tpl->parseCurrentBlock();
863 }
864 }
865
866
867 $sf_content = "";
868 if (is_object($sf))
869 {
870 $sf_content = $sf->getContent();
871 if ($sf->getMultipart())
872 {
873 $this->setMultipart(true);
874 }
875 $this->tpl->setCurrentBlock("sub_form");
876 $this->tpl->setVariable("PROP_SUB_FORM", $sf_content);
877 $this->tpl->setVariable("SFID", $item->getFieldId());
878 $this->tpl->parseCurrentBlock();
879 }
880
881 $this->tpl->setCurrentBlock("prop");
882 /* not used yet
883 include_once("./Services/JSON/classes/class.ilJsonUtil.php");
884 $this->tpl->setVariable("ID", $item->getFieldId());
885 $this->tpl->setVariable("CFG", ilJsonUtil::encode($cfg));*/
886 $this->tpl->parseCurrentBlock();
887 }
888
889
890 $this->tpl->touchBlock("item");
891 }
892
893 public function getHTML()
894 {
895 $html = parent::getHTML();
896
897 // #13531 - get content that has to reside outside of the parent form tag, e.g. panels/layers
898 foreach($this->items as $item)
899 {
900 // #13536 - ilFormSectionHeaderGUI does NOT extend ilFormPropertyGUI ?!
901 if(method_exists($item, "getContentOutsideFormTag"))
902 {
903 $outside = $item->getContentOutsideFormTag();
904 if($outside)
905 {
906 $html .= $outside;
907 }
908 }
909 }
910
911 return $html;
912 }
913
914
915 //
916 // UPLOAD HANDLING
917 //
918
931 protected function keepFileUpload($a_hash, $a_field, $a_tmp_name, $a_name, $a_type, $a_index = null, $a_sub_index = null)
932 {
933 global $ilUser;
934
935 if (trim($a_tmp_name) == "")
936 {
937 return;
938 }
939
940 $user_id = $ilUser->getId();
941 if(!$user_id || $user_id == ANONYMOUS_USER_ID)
942 {
943 return;
944 }
945
946 $a_name = ilUtil::getAsciiFileName($a_name);
947
948 $tmp_file_name = implode("~~", array($user_id,
949 $a_hash,
950 $a_field,
951 $a_index,
952 $a_sub_index,
953 str_replace("/", "~~", $a_type),
954 str_replace("~~", "_", $a_name)));
955
956 // make sure temp directory exists
957 $temp_path = ilUtil::getDataDir() . "/temp";
958 if (!is_dir($temp_path))
959 {
960 ilUtil::createDirectory($temp_path);
961 }
962
963 ilUtil::moveUploadedFile($a_tmp_name, $tmp_file_name, $temp_path."/".$tmp_file_name);
964 }
965
974 function getFileUpload($a_field, $a_index = null, $a_sub_index = null)
975 {
976 $res = array();
977 if($a_index)
978 {
979 if($_FILES[$a_field]["tmp_name"][$a_index][$a_sub_index])
980 {
981 $res = array(
982 "tmp_name" => $_FILES[$a_field]["tmp_name"][$a_index][$a_sub_index],
983 "name" => $_FILES[$a_field]["name"][$a_index][$a_sub_index],
984 "type" => $_FILES[$a_field]["type"][$a_index][$a_sub_index],
985 "error" => $_FILES[$a_field]["error"][$a_index][$a_sub_index],
986 "size" => $_FILES[$a_field]["size"][$a_index][$a_sub_index],
987 "is_upload" => true
988 );
989 }
990 else if($this->reloaded_files[$a_field]["tmp_name"][$a_index][$a_sub_index])
991 {
992 $res = array(
993 "tmp_name" => $this->reloaded_files["tmp_name"][$a_index][$a_sub_index],
994 "name" => $this->reloaded_files["name"][$a_index][$a_sub_index],
995 "type" => $this->reloaded_files["type"][$a_index][$a_sub_index],
996 "error" => $this->reloaded_files["error"][$a_index][$a_sub_index],
997 "size" => $this->reloaded_files["size"][$a_index][$a_sub_index],
998 "is_upload" => false
999 );
1000 }
1001 }
1002 else if($a_sub_index)
1003 {
1004 if($_FILES[$a_field]["tmp_name"][$a_index])
1005 {
1006 $res = array(
1007 "tmp_name" => $_FILES[$a_field]["tmp_name"][$a_index],
1008 "name" => $_FILES[$a_field]["name"][$a_index],
1009 "type" => $_FILES[$a_field]["type"][$a_index],
1010 "error" => $_FILES[$a_field]["error"][$a_index],
1011 "size" => $_FILES[$a_field]["size"][$a_index],
1012 "is_upload" => true
1013 );
1014 }
1015 else if($this->reloaded_files[$a_field]["tmp_name"][$a_index])
1016 {
1017 $res = array(
1018 "tmp_name" => $this->reloaded_files[$a_field]["tmp_name"][$a_index],
1019 "name" => $this->reloaded_files[$a_field]["name"][$a_index],
1020 "type" => $this->reloaded_files[$a_field]["type"][$a_index],
1021 "error" => $this->reloaded_files[$a_field]["error"][$a_index],
1022 "size" => $this->reloaded_files[$a_field]["size"][$a_index],
1023 "is_upload" => false
1024 );
1025 }
1026 }
1027 else
1028 {
1029 if($_FILES[$a_field]["tmp_name"])
1030 {
1031 $res = array(
1032 "tmp_name" => $_FILES[$a_field]["tmp_name"],
1033 "name" => $_FILES[$a_field]["name"],
1034 "type" => $_FILES[$a_field]["type"],
1035 "error" => $_FILES[$a_field]["error"],
1036 "size" => $_FILES[$a_field]["size"],
1037 "is_upload" => true
1038 );
1039 }
1040 else if($this->reloaded_files[$a_field]["tmp_name"])
1041 {
1042 $res = array(
1043 "tmp_name" => $this->reloaded_files[$a_field]["tmp_name"],
1044 "name" => $this->reloaded_files[$a_field]["name"],
1045 "type" => $this->reloaded_files[$a_field]["type"],
1046 "error" => $this->reloaded_files[$a_field]["error"],
1047 "size" => $this->reloaded_files[$a_field]["size"],
1048 "is_upload" => false
1049 );
1050 }
1051 }
1052 return $res;
1053 }
1054
1063 function hasFileUpload($a_field, $a_index = null, $a_sub_index = null)
1064 {
1065 $data = $this->getFileUpload($a_field, $a_index, $a_sub_index);
1066 return (bool)$data["tmp_name"];
1067 }
1068
1079 function moveFileUpload($a_target_directory, $a_field, $a_target_name = null, $a_index = null, $a_sub_index = null)
1080 {
1081 if(!is_dir($a_target_directory))
1082 {
1083 return;
1084 }
1085
1086 $data = $this->getFileUpload($a_field, $a_index, $a_sub_index);
1087 if($data["tmp_name"] && file_exists($data["tmp_name"]))
1088 {
1089 if($a_target_name)
1090 {
1091 $data["name"] = $a_target_name;
1092 }
1093
1094 $target_file = $a_target_directory."/".$data["name"];
1095 $target_file = str_replace("//", "/", $target_file);
1096
1097 if($data["is_upload"])
1098 {
1099 if (!ilUtil::moveUploadedFile($data["tmp_name"], $data["name"], $target_file))
1100 {
1101 return;
1102 }
1103 }
1104 else
1105 {
1106 if (!rename($data["tmp_name"], $target_file))
1107 {
1108 return;
1109 }
1110 }
1111
1112 return $target_file;
1113 }
1114 }
1115
1119 protected function rebuildUploadedFiles()
1120 {
1121 global $ilUser;
1122
1123 if($_POST["ilfilehash"])
1124 {
1125 $user_id = $ilUser->getId();
1126 $temp_path = ilUtil::getDataDir() . "/temp";
1127 if(is_dir($temp_path) && $user_id && $user_id != ANONYMOUS_USER_ID)
1128 {
1129 $reload = array();
1130
1131 $temp_files = glob($temp_path."/".$ilUser->getId()."~~".$_POST["ilfilehash"]."~~*");
1132 if(is_array($temp_files))
1133 {
1134 foreach($temp_files as $full_file)
1135 {
1136 $file = explode("~~", basename($full_file));
1137 $field = $file[2];
1138 $idx = $file[3];
1139 $idx2 = $file[4];
1140 $type = $file[5]."/".$file[6];
1141 $name = $file[7];
1142
1143 if($idx2 != "")
1144 {
1145 if(!$_FILES[$field]["tmp_name"][$idx][$idx2])
1146 {
1147 $reload[$field]["tmp_name"][$idx][$idx2] = $full_file;
1148 $reload[$field]["name"][$idx][$idx2] = $name;
1149 $reload[$field]["type"][$idx][$idx2] = $type;
1150 $reload[$field]["error"][$idx][$idx2] = 0;
1151 $reload[$field]["size"][$idx][$idx2] = filesize($full_file);
1152 }
1153 }
1154 else if($idx != "")
1155 {
1156 if(!$_FILES[$field]["tmp_name"][$idx])
1157 {
1158 $reload[$field]["tmp_name"][$idx] = $full_file;
1159 $reload[$field]["name"][$idx] = $name;
1160 $reload[$field]["type"][$idx] = $type;
1161 $reload[$field]["error"][$idx] = 0;
1162 $reload[$field]["size"][$idx] = filesize($full_file);
1163 }
1164 }
1165 else
1166 {
1167 if(!$_FILES[$field]["tmp_name"])
1168 {
1169 $reload[$field]["tmp_name"] = $full_file;
1170 $reload[$field]["name"] = $name;
1171 $reload[$field]["type"] = $type;
1172 $reload[$field]["error"] = 0;
1173 $reload[$field]["size"] = filesize($full_file);
1174 }
1175 }
1176 }
1177 }
1178
1179 $this->reloaded_files = $reload;
1180 }
1181 }
1182 }
1183}
1184
1185?>
print $file
global $tpl
Definition: ilias.php:8
static _isAllowed()
Check if the CharSelector is allowed for the current GUI.
static _getCurrentGUI(ilObjTest $a_test_obj=null)
Get the GUI that is used for the currently available selector (other GUI instances may exist for conf...
This class represents a form user interface.
getMultipart()
Get Enctype Multipart/Formdata true/false.
setPreventDoubleSubmission($a_val)
Set prevent double submission.
setMultipart($a_multipart)
Set Enctype Multipart/Formdata true/false.
This class represents a hidden form property in a property form.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
setValuesByArray($a_values, $a_restrict_to_value_keys=false)
Set form values from an array.
setTableWidth($a_width)
Set table width.
moveFileUpload($a_target_directory, $a_field, $a_target_name=null, $a_index=null, $a_sub_index=null)
Move upload to target directory.
setDescription($a_val)
Set description.
getTableWidth()
get table width
getDisableStandardMessage()
Get disable standard message.
rebuildUploadedFiles()
try to rebuild files
& executeCommand()
Execute command.
getDescription()
Get description.
removeItemByPostVar($a_post_var)
Remove Item.
setTitleIcon($a_titleicon)
Set TitleIcon.
getTopAnchor()
Get top anchor.
clearCommandButtons()
Remove all command buttons.
getCommandButtons()
Return all Command buttons.
setShowTopButtons($a_val)
Get show top buttons.
insertItem($item, $a_sub_item=false)
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
setMode($a_mode)
Set Mode ('std', 'subform').
checkInput()
Check Post Input.
getHideLabels()
Get a value indicating whether the labels should be hidden or not.
getFileUpload($a_field, $a_index=null, $a_sub_index=null)
Get file upload data.
getInputItemsRecursive()
returns a flat array of all input items including the possibly existing subitems recursively
hasFileUpload($a_field, $a_index=null, $a_sub_index=null)
Was any file uploaded?
setValuesByPost()
Set form values from POST values.
addCustomProperty($a_title, $a_html, $a_info="", $a_alert="", $a_required=false)
Add a custom property.
getMode()
Get Mode ('std', 'subform').
getItemByPostVar($a_post_var)
Get Item by POST variable.
keepFileUpload($a_hash, $a_field, $a_tmp_name, $a_name, $a_type, $a_index=null, $a_sub_index=null)
Import upload into temp directory.
setDisableStandardMessage($a_val)
Set disable standard message.
addCommandButton($a_cmd, $a_text)
Add Command button.
setItems($a_items)
Set Items.
setTopAnchor($a_val)
Set top anchor.
getShowTopButtons()
Set show top buttons.
setTitle($a_title)
Set Title.
setHideLabels($a_value=true)
Set a value indicating whether the labels should be hidden or not.
This class represents a property that may include a sub form.
special template class to simplify handling of ITX/PEAR
static getDataDir()
get data directory (outside webspace)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static createDirectory($a_dir, $a_mod=0755)
create directory
static initDom()
Init YUI Dom.
static initEvent()
Init YUI Event.
static initAnimation()
Init YUI Animation.
$_POST['username']
Definition: cron.php:12
$html
Definition: example_001.php:87
$data
global $ilCtrl
Definition: ilias.php:18
Interface for multi values support.
global $lng
Definition: privfeed.php:40
global $ilSetting
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
global $ilUser
Definition: imgupload.php:15