19declare(strict_types=1);
63 $this->
lng = $DIC->language();
64 $this->
ctrl = $DIC->ctrl();
67 if (isset(
$DIC[
"ilUser"])) {
68 $this->
user = $DIC[
"ilUser"];
72 if (isset(
$DIC[
"ilSetting"])) {
84 if (isset(
$DIC[
"http"])) {
85 $this->
http = $DIC->http();
87 if (isset(
$DIC[
"refinery"])) {
91 if (isset(
$DIC[
"tpl"])) {
92 $this->global_tpl =
$DIC[
'tpl'];
106 switch ($next_class) {
107 case 'ilformpropertydispatchgui':
108 $ilCtrl->saveParameter($this,
'postvar');
111 $form_prop_dispatch->setItem($item);
112 return $ilCtrl->forwardCommand($form_prop_dispatch);
119 $t = $this->
refinery->kindlyTo()->string();
120 $w = $this->
http->wrapper();
121 if ($w->post()->has(
"postvar")) {
122 return $w->post()->retrieve(
"postvar", $t);
124 if ($w->query()->has(
"postvar")) {
125 return $w->query()->retrieve(
"postvar", $t);
132 $this->tbl_width = $a_width;
143 $this->mode = $a_mode;
153 $this->title = $a_title;
163 $this->titleicon = $a_titleicon;
173 $this->description = $a_val;
183 $this->top_anchor = $a_val;
193 $this->show_top_buttons = $a_val;
203 $this->force_top_buttons = $a_val;
216 $a_item->setParentForm($this);
217 $this->items[] = $a_item;
222 bool $a_remove_unused_headers =
false
224 foreach ($this->items as $key => $item) {
225 if (method_exists($item,
"getPostVar") && $item->getPostVar() == $a_post_var) {
226 unset($this->items[$key]);
231 if ($a_remove_unused_headers) {
232 $unset_keys = array();
235 foreach ($this->items as $key => $item) {
237 $unset_keys[] = $last_key;
243 $unset_keys[] = $last_key;
245 foreach ($unset_keys as $key) {
246 unset($this->items[$key]);
253 foreach ($this->items as $item) {
254 if ($item->getType() !=
"section_header") {
257 if (is_object($ret)) {
268 $this->items = $a_items;
282 $inputItems = array();
284 foreach ($this->items as $item) {
285 if ($item->getType() ==
'section_header') {
289 $inputItems[] = $item;
292 $inputItems = array_merge($inputItems, $item->getSubInputItemsRecursive());
301 $this->disable_standard_message = $a_val;
306 return $this->disable_standard_message;
312 return $this->hide_labels;
317 $this->hide_labels = $a_value;
322 bool $a_restrict_to_value_keys =
false
324 foreach ($this->items as $item) {
325 if (!($a_restrict_to_value_keys) ||
326 in_array($item->getPostVar(), array_keys($a_values))) {
327 $item->setValueByArray($a_values);
336 if (!isset(
$DIC[
"http"])) {
340 foreach ($this->items as $item) {
341 $item->setValueByArray(
$DIC->http()->request()->getParsedBody());
349 if ($this->check_input_called) {
350 die(
"Error: ilPropertyFormGUI->checkInput() called twice.");
354 foreach ($this->items as $item) {
355 $item_ok = $item->checkInput();
362 $post = $this->
http->request()->getParsedBody();
363 if (count($this->items) > 0 && count(
$post) === 0) {
367 $this->check_input_called =
true;
370 $filehash = $this->getFileHash();
371 if (!$ok && !is_null($filehash) && $filehash && count($_FILES)) {
374 foreach ($_FILES as $field =>
$data) {
377 $item = $this->getItemByPostVar($field);
378 if (is_null($item) || !$item->checkInput()) {
382 if (is_array(
$data[
"tmp_name"])) {
383 foreach (
$data[
"tmp_name"] as $idx => $upload) {
384 if (is_array($upload)) {
385 foreach ($upload as $idx2 => $file) {
386 if ($file && is_uploaded_file($file)) {
387 $file_name =
$data[
"name"][$idx][$idx2];
388 $file_type =
$data[
"type"][$idx][$idx2];
389 $this->keepFileUpload($hash, $field, $file, $file_name, $file_type, (
string) $idx, (
string) $idx2);
392 } elseif ($upload && is_uploaded_file($upload)) {
393 $file_name =
$data[
"name"][$idx];
394 $file_type =
$data[
"type"][$idx];
395 $this->keepFileUpload($hash, $field, $upload, $file_name, $file_type, (
string) $idx);
399 $this->keepFileUpload($hash, $field,
$data[
"tmp_name"],
$data[
"name"],
$data[
"type"]);
404 $txt =
$DIC->language()->txt(
"form_input_not_valid");
405 switch (
$http->request()->getHeaderLine(
'Accept')) {
407 case 'application/json':
412 $http->saveResponse(
$http->response()->withBody($stream));
419 if (!$ok && !$this->getDisableStandardMessage()) {
420 $this->global_tpl->setOnScreenMessage(
'failure', $txt);
433 $t = $this->
refinery->kindlyTo()->string();
434 $w = $this->
http->wrapper();
436 if ($w->post()->has(
"ilfilehash")) {
437 $filehash = $w->post()->retrieve(
"ilfilehash", $t);
451 bool $ensureValidation =
true
454 if (!$this->check_input_called && $ensureValidation) {
455 throw new LogicException(
'Error: ilPropertyFormGUI->getInput() called without calling checkInput() first.');
458 $item = $this->getItemByPostVar($a_post_var);
459 if (is_object($item) && method_exists($item,
"getInput")) {
460 return $item->getInput();
463 $post = $this->
http->request()->getParsedBody();
464 return $post[$a_post_var] ??
'';
472 $this->buttons[] = array(
"cmd" => $a_cmd,
"text" => $a_text,
"id" => $a_id);
478 return $this->buttons;
483 $this->buttons = array();
493 $tpl->addJavaScript(
"assets/js/Basic.js");
494 $tpl->addJavaScript(
"assets/js/Form.js");
496 $this->tpl =
new ilTemplate(
"tpl.property_form.html",
true,
true,
"components/ILIAS/Form");
501 $fi = $this->items[0] ??
null;
502 if ($this->getMode() ==
"std" &&
504 is_object($fi) && $fi->getType() ==
"section_header"
506 $this->setTitle($fi->getTitle());
507 unset($this->items[0]);
512 if ($this->getTitleIcon() !=
"" && is_file($this->getTitleIcon())) {
513 $this->tpl->setCurrentBlock(
"title_icon");
514 $this->tpl->setVariable(
"IMG_ICON", $this->getTitleIcon());
515 $this->tpl->parseCurrentBlock();
521 if (count($this->buttons) > 0 && $this->getShowTopButtons() && (count($this->items) > 2 || $this->force_top_buttons)) {
523 foreach ($this->buttons as $button) {
524 $this->tpl->setCurrentBlock(
"cmd2");
525 $this->tpl->setVariable(
"CMD", $button[
"cmd"]);
526 $this->tpl->setVariable(
"CMD_TXT", $button[
"text"]);
527 if ($button[
"id"] !=
"") {
528 $this->tpl->setVariable(
"CMD2_ID",
" id='" . $button[
"id"] .
"_top'");
530 $this->tpl->parseCurrentBlock();
532 $this->tpl->setCurrentBlock(
"commands2");
533 $this->tpl->parseCurrentBlock();
537 $this->tpl->setCurrentBlock(
"header");
538 if ($this->checkForRequiredField()) {
539 $this->tpl->setCurrentBlock(
"required_text_top");
540 $this->tpl->setVariable(
"TXT_REQUIRED_TOP",
$lng->txt(
"required_field"));
541 $this->tpl->parseCurrentBlock();
544 $this->tpl->setVariable(
"TXT_TITLE", $this->
getTitle());
546 $this->tpl->setVariable(
"TXT_DESCRIPTION", $this->getDescription());
547 $this->tpl->parseCurrentBlock();
548 } elseif (!$this->required_text && $this->getMode() ==
"std") {
549 $this->tpl->setCurrentBlock(
"header");
551 $this->tpl->setCurrentBlock(
"required_text_top");
552 $this->tpl->setVariable(
"TXT_REQUIRED_TOP",
$lng->txt(
"required_field"));
553 $this->tpl->parseCurrentBlock();
555 $this->tpl->touchBlock(
"item");
558 $this->required_text =
false;
559 foreach ($this->items as $item) {
560 if ($item->getType() !=
"hidden") {
561 $this->insertItem($item);
566 if ($this->required_text && $this->getMode() ==
"std") {
567 $this->tpl->setCurrentBlock(
"required_text");
568 $this->tpl->setVariable(
"TXT_REQUIRED",
$lng->txt(
"required_field"));
569 $this->tpl->parseCurrentBlock();
573 foreach ($this->buttons as $button) {
574 $this->tpl->setCurrentBlock(
"cmd");
575 $this->tpl->setVariable(
"CMD", $button[
"cmd"]);
576 $this->tpl->setVariable(
"CMD_TXT", $button[
"text"]);
578 if ($button[
"id"] !=
"") {
579 $this->tpl->setVariable(
"CMD_ID",
" id='" . $button[
"id"] .
"'");
582 $this->tpl->parseCurrentBlock();
586 if ($this->getMode() !=
"subform") {
588 if ($this->getMultipart()) {
589 $hash = $this->getFileHash() ??
null;
591 $hash = md5(uniqid((
string) mt_rand(),
true));
594 $fhash->setValue($hash);
595 $this->addItem($fhash);
600 $hidden_fields =
false;
601 foreach ($this->items as $item) {
602 if ($item->getType() ==
"hidden") {
603 $item->insert($this->tpl);
604 $hidden_fields =
true;
608 if ($this->required_text || count($this->buttons) > 0 || $hidden_fields) {
609 $this->tpl->setCurrentBlock(
"commands");
610 $this->tpl->parseCurrentBlock();
614 if ($this->getMode() ==
"subform") {
615 $this->tpl->touchBlock(
"sub_table");
617 $this->tpl->touchBlock(
"std_table");
618 $this->tpl->setVariable(
'STD_TABLE_WIDTH', $this->getTableWidth());
621 return $this->tpl->get();
627 return $a_type ==
"non_editable_value";
635 bool $a_sub_item =
false
646 $tpl->addJavascript(
"assets/js/ServiceFormMulti.js");
649 $this->tpl->setVariable(
"ID", $item->getFieldId());
650 $this->tpl->parseCurrentBlock();
652 $this->tpl->touchBlock(
"multi_out");
657 $multi_values = $item->getMultiValues();
658 if (is_array($multi_values) &&
sizeof($multi_values) > 1) {
659 $multi_value =
new ilHiddenInputGUI(
"ilMultiValues~" . $item->getPostVar());
660 $multi_value->setValue(base64_encode(json_encode($multi_values)));
661 $this->addItem($multi_value);
666 $item->insert($this->tpl);
668 if ($item->getType() ==
"file" || $item->getType() ==
"image_file") {
669 $this->setMultipart(
true);
672 if ($item->getType() !=
"section_header") {
676 if ($item->getInfo() !=
"") {
677 $this->tpl->setCurrentBlock(
"description");
678 $this->tpl->setVariable(
679 "PROPERTY_DESCRIPTION",
682 $this->tpl->setVariable(
683 "DESCRIPTION_FOR_ID",
686 $this->tpl->parseCurrentBlock();
689 if ($this->getMode() ==
"subform") {
691 if (!$this->hideRequired($item->getType())) {
692 if ($item->getRequired()) {
693 $this->tpl->touchBlock(
"sub_required");
694 $this->required_text =
true;
699 if ($item->getHiddenTitle() !=
"") {
700 $this->tpl->setCurrentBlock(
"sub_hid_title");
701 $this->tpl->setVariable(
703 $item->getHiddenTitle()
705 $this->tpl->parseCurrentBlock();
708 $this->tpl->setCurrentBlock(
"sub_prop_start");
709 $this->tpl->setVariable(
"PROPERTY_TITLE", $item->getTitle());
710 $this->tpl->setVariable(
"PROPERTY_CLASS",
"il_" . $item->getType());
711 if ($item->getType() !=
"non_editable_value" && $item->getFormLabelFor() !=
"") {
712 $this->tpl->setVariable(
"FOR_ID",
' for="' . $item->getFormLabelFor() .
'" ');
714 $this->tpl->setVariable(
"LAB_ID", $item->getFieldId());
717 if (!$this->hideRequired($item->getType())) {
718 if ($item->getRequired()) {
719 $this->tpl->touchBlock(
"required");
720 $this->required_text =
true;
725 if ($item->getHiddenTitle() !=
"") {
726 $this->tpl->setCurrentBlock(
"std_hid_title");
727 $this->tpl->setVariable(
729 $item->getHiddenTitle()
731 $this->tpl->parseCurrentBlock();
734 $this->tpl->setCurrentBlock(
"std_prop_start");
735 $this->tpl->setVariable(
"PROPERTY_TITLE", $item->getTitle());
736 if ($item->getType() !=
"non_editable_value" && $item->getFormLabelFor() !=
"") {
737 $this->tpl->setVariable(
"FOR_ID",
' for="' . $item->getFormLabelFor() .
'" ');
739 $this->tpl->setVariable(
"LAB_ID", $item->getFieldId());
740 if ($this->getHideLabels()) {
741 $this->tpl->setVariable(
"HIDE_LABELS_STYLE",
" ilFormOptionHidden");
744 $this->tpl->parseCurrentBlock();
747 if ($item->getType() !=
"non_editable_value" && $item->getAlert() !=
"") {
748 $this->tpl->setCurrentBlock(
"alert");
749 $this->tpl->setVariable(
753 $this->tpl->setVariable(
757 $this->tpl->setVariable(
761 $this->tpl->setVariable(
765 $this->tpl->parseCurrentBlock();
770 if ($item->getType() !=
"non_editable_value" or 1) {
771 $sf = $item->getSubForm();
772 if ($item->hideSubForm() && is_object($sf)) {
773 if ($this->global_tpl) {
774 $dsfid = $item->getFieldId();
775 $this->global_tpl->addOnloadCode(
776 "il.Form.hideSubForm('subform_$dsfid');"
779 $this->addAsyncOnloadCode(
"il.Form.hideSubForm('subform_$dsfid');");
784 if (is_object($sf)) {
785 $sf_content = $sf->getContent();
786 if ($sf->getMultipart()) {
787 $this->setMultipart(
true);
789 $this->tpl->setCurrentBlock(
"sub_form");
790 $this->tpl->setVariable(
"PROP_SUB_FORM", $sf_content);
791 $this->tpl->setVariable(
"SFID", $item->getFieldId());
792 $this->tpl->parseCurrentBlock();
795 $this->tpl->setCurrentBlock(
"prop");
799 $this->tpl->parseCurrentBlock();
803 $this->tpl->touchBlock(
"item");
808 $this->onload_code[] = $code;
813 $html = parent::getHTML();
816 foreach ($this->items as $item) {
818 if (method_exists($item,
"getContentOutsideFormTag")) {
819 $outside = $item->getContentOutsideFormTag();
825 if ($this->
ctrl->isAsynch()) {
826 $html = $this->appendOnloadCode($html);
833 $html = $this->getHTML();
834 if (!$this->
ctrl->isAsynch()) {
835 $html = $this->appendOnloadCode($html);
842 if (count($this->onload_code) > 0) {
844 foreach ($this->onload_code as $code) {
845 $html .= $code .
"\n";
847 $html .=
"</script>";
868 protected function keepFileUpload(
874 ?
string $a_index =
null,
875 ?
string $a_sub_index =
null
877 if (in_array($a_tmp_name, $this->kept_uploads)) {
881 if (trim($a_tmp_name) ==
"") {
887 $tmp_file_name = implode(
"~~", array(session_id(),
892 str_replace(
"/",
"~~", $a_type),
893 str_replace(
"~~",
"_", $a_name)));
897 if (!is_dir($temp_path)) {
904 $file_input = $this->getItemByPostVar($a_field);
905 $file_input->setPending($a_name);
906 $this->kept_uploads[] = $a_tmp_name;
919 ?
string $a_index =
null,
920 ?
string $a_sub_index =
null
924 if ($_FILES[$a_field][
"tmp_name"][$a_index][$a_sub_index] ??
false) {
926 "tmp_name" => $_FILES[$a_field][
"tmp_name"][$a_index][$a_sub_index],
927 "name" => $_FILES[$a_field][
"name"][$a_index][$a_sub_index],
928 "type" => $_FILES[$a_field][
"type"][$a_index][$a_sub_index],
929 "error" => $_FILES[$a_field][
"error"][$a_index][$a_sub_index],
930 "size" => $_FILES[$a_field][
"size"][$a_index][$a_sub_index],
931 "is_upload" => $_FILES[$a_field][
"is_upload"][$a_index][$a_sub_index] ??
true
934 } elseif ($a_sub_index) {
935 if ($_FILES[$a_field][
"tmp_name"][$a_index] ??
false) {
937 "tmp_name" => $_FILES[$a_field][
"tmp_name"][$a_index],
938 "name" => $_FILES[$a_field][
"name"][$a_index],
939 "type" => $_FILES[$a_field][
"type"][$a_index],
940 "error" => $_FILES[$a_field][
"error"][$a_index],
941 "size" => $_FILES[$a_field][
"size"][$a_index],
942 "is_upload" => $_FILES[$a_field][
"is_upload"][$a_index] ??
true
946 if ($_FILES[$a_field][
"tmp_name"] ??
false) {
948 "tmp_name" => $_FILES[$a_field][
"tmp_name"],
949 "name" => $_FILES[$a_field][
"name"],
950 "type" => $_FILES[$a_field][
"type"],
951 "error" => $_FILES[$a_field][
"error"],
952 "size" => $_FILES[$a_field][
"size"],
953 "is_upload" => $_FILES[$a_field][
"is_upload"] ??
true
962 ?
string $a_index =
null,
963 ?
string $a_sub_index =
null
965 $data = $this->getFileUpload($a_field, $a_index, $a_sub_index);
966 return (
bool) (
$data[
"tmp_name"] ??
false);
981 string $a_target_directory,
983 ?
string $a_target_name =
null,
984 ?
string $a_index =
null,
985 ?
string $a_sub_index =
null
987 if (!is_dir($a_target_directory)) {
991 $data = $this->getFileUpload($a_field, $a_index, $a_sub_index);
992 if (
$data[
"tmp_name"] && file_exists(
$data[
"tmp_name"])) {
993 if ($a_target_name) {
994 $data[
"name"] = $a_target_name;
997 $target_file = $a_target_directory .
"/" .
$data[
"name"];
998 $target_file = str_replace(
"//",
"/", $target_file);
1000 if (
$data[
"is_upload"]) {
1010 return $target_file;
1017 $file_hash = (string) $this->getFileHash();
1018 if ($file_hash !=
"") {
1020 if (is_dir($temp_path)) {
1021 $temp_files = glob($temp_path .
"/" . session_id() .
"~~" . $file_hash .
"~~*");
1022 if (is_array($temp_files)) {
1023 foreach ($temp_files as $full_file) {
1024 $file = explode(
"~~", basename($full_file));
1028 $type = $file[5] .
"/" . $file[6];
1032 if (!isset($_FILES[$field][
"tmp_name"][$idx][$idx2])) {
1033 $_FILES[$field][
"tmp_name"][$idx][$idx2] = $full_file;
1034 $_FILES[$field][
"name"][$idx][$idx2] = $name;
1035 $_FILES[$field][
"type"][$idx][$idx2] = $type;
1036 $_FILES[$field][
"error"][$idx][$idx2] = 0;
1037 $_FILES[$field][
"size"][$idx][$idx2] = filesize($full_file);
1038 $_FILES[$field][
"is_upload"][$idx][$idx2] =
false;
1040 } elseif ($idx !=
"") {
1041 if (!isset($_FILES[$field][
"tmp_name"][$idx])) {
1042 $_FILES[$field][
"tmp_name"][$idx] = $full_file;
1043 $_FILES[$field][
"name"][$idx] = $name;
1044 $_FILES[$field][
"type"][$idx] = $type;
1045 $_FILES[$field][
"error"][$idx] = 0;
1046 $_FILES[$field][
"size"][$idx] = filesize($full_file);
1047 $_FILES[$field][
"is_upload"][$idx] =
false;
1050 if (!isset($_FILES[$field][
"tmp_name"])) {
1051 $_FILES[$field][
"tmp_name"] = $full_file;
1052 $_FILES[$field][
"name"] = $name;
1053 $_FILES[$field][
"type"] = $type;
1054 $_FILES[$field][
"error"] = 0;
1055 $_FILES[$field][
"size"] = filesize($full_file);
1056 $_FILES[$field][
"is_upload"] =
false;
1067 foreach ($this->items as $item) {
1070 } elseif ($item->getType() !=
"hidden") {
1071 if ($this->getMode() ==
"subform") {
1072 if (!$this->hideRequired($item->getType())) {
1073 if ($item->getRequired()) {
1077 } elseif (!$this->hideRequired($item->getType())) {
1078 if ($item->getRequired()) {
static ofString(string $string)
Creates a new stream with an initial value.
Class ilCtrl provides processing control methods.
getNextClass($a_gui_class=null)
@inheritDoc
static getASCIIFilename(string $a_filename)
static rename(string $a_source, string $a_target)
static getDataDir()
get data directory (outside webspace)
static createDirectory(string $a_dir, int $a_mod=0755)
create directory
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
loadLanguageModule(string $a_module)
Load language module.
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
Interface for multi values support.
static http()
Fetches the global http state from ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))