19 declare(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"])) {
76 $lng = $DIC->language();
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") {
256 $ret = $item->getItemByPostVar($a_post_var);
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;
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;
371 if (!$ok && !is_null($filehash) && $filehash && count($_FILES)) {
374 foreach ($_FILES as $field =>
$data) {
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"]);
403 $http = $DIC->http();
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));
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.');
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);
483 $this->buttons = array();
496 $tpl->addJavaScript(
"assets/js/Basic.js");
497 $tpl->addJavaScript(
"assets/js/Form.js");
499 $this->tpl =
new ilTemplate(
"tpl.property_form.html",
true,
true,
"components/ILIAS/Form");
504 $fi = $this->items[0] ??
null;
505 if ($this->
getMode() ==
"std" &&
507 is_object($fi) && $fi->getType() ==
"section_header" 510 unset($this->items[0]);
516 $this->tpl->setCurrentBlock(
"title_icon");
517 $this->tpl->setVariable(
"IMG_ICON", $this->
getTitleIcon());
518 $this->tpl->parseCurrentBlock();
524 if (count($this->buttons) > 0 && $this->
getShowTopButtons() && (count($this->items) > 2 || $this->force_top_buttons)) {
526 foreach ($this->buttons as $button) {
527 $this->tpl->setCurrentBlock(
"cmd2");
528 $this->tpl->setVariable(
"CMD", $button[
"cmd"]);
529 $this->tpl->setVariable(
"CMD_TXT", $button[
"text"]);
530 if ($button[
"id"] !=
"") {
531 $this->tpl->setVariable(
"CMD2_ID",
" id='" . $button[
"id"] .
"_top'");
533 $this->tpl->parseCurrentBlock();
535 $this->tpl->setCurrentBlock(
"commands2");
536 $this->tpl->parseCurrentBlock();
540 $this->tpl->setCurrentBlock(
"header");
542 $this->tpl->setCurrentBlock(
"required_text_top");
543 $this->tpl->setVariable(
"TXT_REQUIRED_TOP", $lng->
txt(
"required_field"));
544 $this->tpl->parseCurrentBlock();
547 $this->tpl->setVariable(
"TXT_TITLE", $this->
getTitle());
549 $this->tpl->setVariable(
"TXT_DESCRIPTION", $this->
getDescription());
550 $this->tpl->parseCurrentBlock();
551 } elseif (!$this->required_text && $this->
getMode() ==
"std") {
552 $this->tpl->setCurrentBlock(
"header");
554 $this->tpl->setCurrentBlock(
"required_text_top");
555 $this->tpl->setVariable(
"TXT_REQUIRED_TOP", $lng->
txt(
"required_field"));
556 $this->tpl->parseCurrentBlock();
558 $this->tpl->touchBlock(
"item");
561 $this->required_text =
false;
562 foreach ($this->items as $item) {
563 if ($item->getType() !=
"hidden") {
569 if ($this->required_text && $this->
getMode() ==
"std") {
570 $this->tpl->setCurrentBlock(
"required_text");
571 $this->tpl->setVariable(
"TXT_REQUIRED", $lng->
txt(
"required_field"));
572 $this->tpl->parseCurrentBlock();
576 foreach ($this->buttons as $button) {
577 $this->tpl->setCurrentBlock(
"cmd");
578 $this->tpl->setVariable(
"CMD", $button[
"cmd"]);
579 $this->tpl->setVariable(
"CMD_TXT", $button[
"text"]);
581 if ($button[
"id"] !=
"") {
582 $this->tpl->setVariable(
"CMD_ID",
" id='" . $button[
"id"] .
"'");
585 $this->tpl->parseCurrentBlock();
589 if ($this->
getMode() !=
"subform") {
594 $hash = md5(uniqid((
string) mt_rand(),
true));
597 $fhash->setValue($hash);
603 $hidden_fields =
false;
604 foreach ($this->items as $item) {
605 if ($item->getType() ==
"hidden") {
606 $item->insert($this->tpl);
607 $hidden_fields =
true;
611 if ($this->required_text || count($this->buttons) > 0 || $hidden_fields) {
612 $this->tpl->setCurrentBlock(
"commands");
613 $this->tpl->parseCurrentBlock();
617 if ($this->
getMode() ==
"subform") {
618 $this->tpl->touchBlock(
"sub_table");
620 $this->tpl->touchBlock(
"std_table");
621 $this->tpl->setVariable(
'STD_TABLE_WIDTH', $this->
getTableWidth());
624 return $this->tpl->get();
630 return $a_type ==
"non_editable_value";
638 bool $a_sub_item =
false 649 $tpl->addJavascript(
"assets/js/ServiceFormMulti.js");
652 $this->tpl->setVariable(
"ID", $item->getFieldId());
653 $this->tpl->parseCurrentBlock();
655 $this->tpl->touchBlock(
"multi_out");
660 $multi_values = $item->getMultiValues();
661 if (is_array($multi_values) &&
sizeof($multi_values) > 1) {
662 $multi_value =
new ilHiddenInputGUI(
"ilMultiValues~" . $item->getPostVar());
663 $multi_value->
setValue(base64_encode(json_encode($multi_values)));
669 $item->insert($this->tpl);
671 if ($item->getType() ==
"file" || $item->getType() ==
"image_file") {
675 if ($item->getType() !=
"section_header") {
679 if ($item->getInfo() !=
"") {
680 $this->tpl->setCurrentBlock(
"description");
681 $this->tpl->setVariable(
682 "PROPERTY_DESCRIPTION",
685 $this->tpl->setVariable(
686 "DESCRIPTION_FOR_ID",
689 $this->tpl->parseCurrentBlock();
692 if ($this->
getMode() ==
"subform") {
695 if ($item->getRequired()) {
696 $this->tpl->touchBlock(
"sub_required");
697 $this->required_text =
true;
702 if ($item->getHiddenTitle() !=
"") {
703 $this->tpl->setCurrentBlock(
"sub_hid_title");
704 $this->tpl->setVariable(
706 $item->getHiddenTitle()
708 $this->tpl->parseCurrentBlock();
711 $this->tpl->setCurrentBlock(
"sub_prop_start");
712 $this->tpl->setVariable(
"PROPERTY_TITLE", $item->getTitle());
713 $this->tpl->setVariable(
"PROPERTY_CLASS",
"il_" . $item->getType());
714 if ($item->getType() !=
"non_editable_value" && $item->getFormLabelFor() !=
"") {
715 $this->tpl->setVariable(
"FOR_ID",
' for="' . $item->getFormLabelFor() .
'" ');
717 $this->tpl->setVariable(
"LAB_ID", $item->getFieldId());
721 if ($item->getRequired()) {
722 $this->tpl->touchBlock(
"required");
723 $this->required_text =
true;
728 if ($item->getHiddenTitle() !=
"") {
729 $this->tpl->setCurrentBlock(
"std_hid_title");
730 $this->tpl->setVariable(
732 $item->getHiddenTitle()
734 $this->tpl->parseCurrentBlock();
737 $this->tpl->setCurrentBlock(
"std_prop_start");
738 $this->tpl->setVariable(
"PROPERTY_TITLE", $item->getTitle());
739 if ($item->getType() !=
"non_editable_value" && $item->getFormLabelFor() !=
"") {
740 $this->tpl->setVariable(
"FOR_ID",
' for="' . $item->getFormLabelFor() .
'" ');
742 $this->tpl->setVariable(
"LAB_ID", $item->getFieldId());
744 $this->tpl->setVariable(
"HIDE_LABELS_STYLE",
" ilFormOptionHidden");
747 $this->tpl->parseCurrentBlock();
750 if ($item->getType() !=
"non_editable_value" && $item->getAlert() !=
"") {
751 $this->tpl->setCurrentBlock(
"alert");
752 $this->tpl->setVariable(
756 $this->tpl->setVariable(
760 $this->tpl->setVariable(
764 $this->tpl->setVariable(
768 $this->tpl->parseCurrentBlock();
773 if ($item->getType() !=
"non_editable_value" or 1) {
774 $sf = $item->getSubForm();
775 if ($item->hideSubForm() && is_object($sf)) {
776 if ($this->global_tpl) {
777 $dsfid = $item->getFieldId();
778 $this->global_tpl->addOnloadCode(
779 "il.Form.hideSubForm('subform_$dsfid');" 787 if (is_object($sf)) {
788 $sf_content = $sf->getContent();
789 if ($sf->getMultipart()) {
792 $this->tpl->setCurrentBlock(
"sub_form");
793 $this->tpl->setVariable(
"PROP_SUB_FORM", $sf_content);
794 $this->tpl->setVariable(
"SFID", $item->getFieldId());
795 $this->tpl->parseCurrentBlock();
798 $this->tpl->setCurrentBlock(
"prop");
802 $this->tpl->parseCurrentBlock();
806 $this->tpl->touchBlock(
"item");
811 $this->onload_code[] = $code;
816 $html = parent::getHTML();
819 foreach ($this->items as $item) {
821 if (method_exists($item,
"getContentOutsideFormTag")) {
822 $outside = $item->getContentOutsideFormTag();
828 if ($this->
ctrl->isAsynch()) {
837 if (!$this->
ctrl->isAsynch()) {
845 if (count($this->onload_code) > 0) {
847 foreach ($this->onload_code as $code) {
848 $html .= $code .
"\n";
850 $html .=
"</script>";
871 protected function keepFileUpload(
877 ?
string $a_index =
null,
878 ?
string $a_sub_index =
null 880 if (in_array($a_tmp_name, $this->kept_uploads)) {
884 if (trim($a_tmp_name) ==
"") {
890 $tmp_file_name = implode(
"~~", array(session_id(),
895 str_replace(
"/",
"~~", $a_type),
896 str_replace(
"~~",
"_", $a_name)));
900 if (!is_dir($temp_path)) {
908 $file_input->setPending($a_name);
909 $this->kept_uploads[] = $a_tmp_name;
922 ?
string $a_index =
null,
923 ?
string $a_sub_index =
null 927 if ($_FILES[$a_field][
"tmp_name"][$a_index][$a_sub_index] ??
false) {
929 "tmp_name" => $_FILES[$a_field][
"tmp_name"][$a_index][$a_sub_index],
930 "name" => $_FILES[$a_field][
"name"][$a_index][$a_sub_index],
931 "type" => $_FILES[$a_field][
"type"][$a_index][$a_sub_index],
932 "error" => $_FILES[$a_field][
"error"][$a_index][$a_sub_index],
933 "size" => $_FILES[$a_field][
"size"][$a_index][$a_sub_index],
934 "is_upload" => $_FILES[$a_field][
"is_upload"][$a_index][$a_sub_index] ??
true 937 } elseif ($a_sub_index) {
938 if ($_FILES[$a_field][
"tmp_name"][$a_index] ??
false) {
940 "tmp_name" => $_FILES[$a_field][
"tmp_name"][$a_index],
941 "name" => $_FILES[$a_field][
"name"][$a_index],
942 "type" => $_FILES[$a_field][
"type"][$a_index],
943 "error" => $_FILES[$a_field][
"error"][$a_index],
944 "size" => $_FILES[$a_field][
"size"][$a_index],
945 "is_upload" => $_FILES[$a_field][
"is_upload"][$a_index] ??
true 949 if ($_FILES[$a_field][
"tmp_name"] ??
false) {
951 "tmp_name" => $_FILES[$a_field][
"tmp_name"],
952 "name" => $_FILES[$a_field][
"name"],
953 "type" => $_FILES[$a_field][
"type"],
954 "error" => $_FILES[$a_field][
"error"],
955 "size" => $_FILES[$a_field][
"size"],
956 "is_upload" => $_FILES[$a_field][
"is_upload"] ??
true 965 ?
string $a_index =
null,
966 ?
string $a_sub_index =
null 969 return (
bool) (
$data[
"tmp_name"] ??
false);
984 string $a_target_directory,
986 ?
string $a_target_name =
null,
987 ?
string $a_index =
null,
988 ?
string $a_sub_index =
null 990 if (!is_dir($a_target_directory)) {
995 if (
$data[
"tmp_name"] && file_exists(
$data[
"tmp_name"])) {
996 if ($a_target_name) {
997 $data[
"name"] = $a_target_name;
1000 $target_file = $a_target_directory .
"/" .
$data[
"name"];
1001 $target_file = str_replace(
"//",
"/", $target_file);
1003 if (
$data[
"is_upload"]) {
1013 return $target_file;
1021 if ($file_hash !=
"") {
1023 if (is_dir($temp_path)) {
1024 $temp_files = glob($temp_path .
"/" . session_id() .
"~~" . $file_hash .
"~~*");
1025 if (is_array($temp_files)) {
1026 foreach ($temp_files as $full_file) {
1027 $file = explode(
"~~", basename($full_file));
1031 $type = $file[5] .
"/" . $file[6];
1035 if (!isset($_FILES[$field][
"tmp_name"][$idx][$idx2])) {
1036 $_FILES[$field][
"tmp_name"][$idx][$idx2] = $full_file;
1037 $_FILES[$field][
"name"][$idx][$idx2] =
$name;
1038 $_FILES[$field][
"type"][$idx][$idx2] = $type;
1039 $_FILES[$field][
"error"][$idx][$idx2] = 0;
1040 $_FILES[$field][
"size"][$idx][$idx2] = filesize($full_file);
1041 $_FILES[$field][
"is_upload"][$idx][$idx2] =
false;
1043 } elseif ($idx !=
"") {
1044 if (!isset($_FILES[$field][
"tmp_name"][$idx])) {
1045 $_FILES[$field][
"tmp_name"][$idx] = $full_file;
1046 $_FILES[$field][
"name"][$idx] =
$name;
1047 $_FILES[$field][
"type"][$idx] = $type;
1048 $_FILES[$field][
"error"][$idx] = 0;
1049 $_FILES[$field][
"size"][$idx] = filesize($full_file);
1050 $_FILES[$field][
"is_upload"][$idx] =
false;
1053 if (!isset($_FILES[$field][
"tmp_name"])) {
1054 $_FILES[$field][
"tmp_name"] = $full_file;
1055 $_FILES[$field][
"name"] =
$name;
1056 $_FILES[$field][
"type"] = $type;
1057 $_FILES[$field][
"error"] = 0;
1058 $_FILES[$field][
"size"] = filesize($full_file);
1059 $_FILES[$field][
"is_upload"] =
false;
1070 foreach ($this->items as $item) {
1073 } elseif ($item->getType() !=
"hidden") {
1074 if ($this->
getMode() ==
"subform") {
1076 if ($item->getRequired()) {
1081 if ($item->getRequired()) {
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
loadLanguageModule(string $a_module)
Load language module.
static getASCIIFilename(string $a_filename)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static initDom(?ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Dom.
getNextClass($a_gui_class=null)
static http()
Fetches the global http state from ILIAS.
static createDirectory(string $a_dir, int $a_mod=0755)
create directory
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template 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
static getDataDir()
get data directory (outside webspace)
Interface for multi values support.
static ofString(string $string)
Creates a new stream with an initial value.
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
static rename(string $a_source, string $a_target)
static initEvent(?ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Event.