Example #1
0
 public function GetDocumentFields($documentType)
 {
     $iblockId = intval(substr($documentType, strlen("iblock_")));
     if ($iblockId <= 0) {
         throw new CBPArgumentOutOfRangeException("documentType", $documentType);
     }
     $documentFieldTypes = self::getDocumentFieldTypes($documentType);
     $result = array("ID" => array("Name" => GetMessage("IBD_FIELD_ID"), "Type" => "int", "Filterable" => true, "Editable" => false, "Required" => false), "TIMESTAMP_X" => array("Name" => GetMessage("IBD_FIELD_TIMESTAMP_X"), "Type" => "datetime", "Filterable" => true, "Editable" => true, "Required" => false), "MODIFIED_BY" => array("Name" => GetMessage("IBD_FIELD_MODYFIED"), "Type" => "user", "Filterable" => true, "Editable" => true, "Required" => false), "MODIFIED_BY_PRINTABLE" => array("Name" => GetMessage("IBD_FIELD_MODIFIED_BY_USER_PRINTABLE"), "Type" => "string", "Filterable" => false, "Editable" => false, "Required" => false), "DATE_CREATE" => array("Name" => GetMessage("IBD_FIELD_DATE_CREATE"), "Type" => "datetime", "Filterable" => true, "Editable" => true, "Required" => false), "CREATED_BY" => array("Name" => GetMessage("IBD_FIELD_CREATED"), "Type" => "user", "Filterable" => true, "Editable" => false, "Required" => false), "CREATED_BY_PRINTABLE" => array("Name" => GetMessage("IBD_FIELD_CREATED_BY_USER_PRINTABLE"), "Type" => "string", "Filterable" => false, "Editable" => false, "Required" => false), "IBLOCK_ID" => array("Name" => GetMessage("IBD_FIELD_IBLOCK_ID"), "Type" => "int", "Filterable" => true, "Editable" => true, "Required" => false), "ACTIVE" => array("Name" => GetMessage("IBD_FIELD_ACTIVE"), "Type" => "bool", "Filterable" => true, "Editable" => true, "Required" => false), "BP_PUBLISHED" => array("Name" => GetMessage("IBD_FIELD_BP_PUBLISHED"), "Type" => "bool", "Filterable" => false, "Editable" => true, "Required" => false), "CODE" => array("Name" => GetMessage("IBD_FIELD_CODE"), "Type" => "string", "Filterable" => true, "Editable" => true, "Required" => false), "XML_ID" => array("Name" => GetMessage("IBD_FIELD_XML_ID"), "Type" => "string", "Filterable" => true, "Editable" => true, "Required" => false));
     $keys = array_keys($result);
     foreach ($keys as $key) {
         $result[$key]["Multiple"] = false;
     }
     $dbProperties = CIBlockProperty::getList(array("sort" => "asc", "name" => "asc"), array("IBLOCK_ID" => $iblockId, 'ACTIVE' => 'Y'));
     $ignoreProperty = array();
     while ($property = $dbProperties->fetch()) {
         if (strlen(trim($property["CODE"])) > 0) {
             $key = "PROPERTY_" . $property["CODE"];
             $ignoreProperty["PROPERTY_" . $property["ID"]] = "PROPERTY_" . $property["CODE"];
         } else {
             $key = "PROPERTY_" . $property["ID"];
             $ignoreProperty["PROPERTY_" . $property["ID"]] = 0;
         }
         $result[$key] = array("Name" => $property["NAME"], "Filterable" => $property["FILTRABLE"] == "Y", "Editable" => true, "Required" => $property["IS_REQUIRED"] == "Y", "Multiple" => $property["MULTIPLE"] == "Y", "TypeReal" => $property["PROPERTY_TYPE"]);
         if (strlen($property["USER_TYPE"]) > 0) {
             $result[$key]["TypeReal"] = $property["PROPERTY_TYPE"] . ":" . $property["USER_TYPE"];
             if ($property["USER_TYPE"] == "UserID" || $property["USER_TYPE"] == "employee" && COption::getOptionString("bizproc", "employee_compatible_mode", "N") != "Y") {
                 $result[$key]["Type"] = "user";
                 $result[$key . "_PRINTABLE"] = array("Name" => $property["NAME"] . GetMessage("IBD_FIELD_USERNAME_PROPERTY"), "Filterable" => false, "Editable" => false, "Required" => false, "Multiple" => $property["MULTIPLE"] == "Y", "Type" => "string");
                 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
             } elseif ($property["USER_TYPE"] == "DateTime") {
                 $result[$key]["Type"] = "datetime";
                 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
             } elseif ($property["USER_TYPE"] == "Date") {
                 $result[$key]["Type"] = "date";
                 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
             } elseif ($property["USER_TYPE"] == "EList") {
                 $result[$key]["Type"] = "E:EList";
                 $result[$key]["Options"] = $property["LINK_IBLOCK_ID"];
             } elseif ($property["USER_TYPE"] == "HTML") {
                 $result[$key]["Type"] = "S:HTML";
                 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
             } else {
                 $result[$key]["Type"] = "string";
                 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
             }
         } elseif ($property["PROPERTY_TYPE"] == "L") {
             $result[$key]["Type"] = "select";
             $result[$key]["Options"] = array();
             $dbPropertyEnums = CIBlockProperty::getPropertyEnum($property["ID"]);
             while ($propertyEnum = $dbPropertyEnums->getNext()) {
                 $result[$key]["Options"][$propertyEnum["XML_ID"]] = $propertyEnum["VALUE"];
                 if ($propertyEnum["DEF"] == "Y") {
                     $result[$key]["DefaultValue"] = $propertyEnum["VALUE"];
                 }
             }
         } elseif ($property["PROPERTY_TYPE"] == "N") {
             $result[$key]["Type"] = "int";
             $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
         } elseif ($property["PROPERTY_TYPE"] == "F") {
             $result[$key]["Type"] = "file";
             $result[$key . "_printable"] = array("Name" => $property["NAME"] . GetMessage("IBD_FIELD_USERNAME_PROPERTY"), "Filterable" => false, "Editable" => false, "Required" => false, "Multiple" => $property["MULTIPLE"] == "Y", "Type" => "string");
         } elseif ($property["PROPERTY_TYPE"] == "S") {
             $result[$key]["Type"] = "string";
             $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
         } else {
             $result[$key]["Type"] = "string";
             $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
         }
     }
     $keys = array_keys($result);
     foreach ($keys as $k) {
         $result[$k]["BaseType"] = $documentFieldTypes[$result[$k]["Type"]]["BaseType"];
         $result[$k]["Complex"] = $documentFieldTypes[$result[$k]["Type"]]["Complex"];
     }
     $list = new CList($iblockId);
     $fields = $list->getFields();
     foreach ($fields as $fieldId => $field) {
         if (empty($field["SETTINGS"])) {
             $field["SETTINGS"] = array("SHOW_ADD_FORM" => 'Y', "SHOW_EDIT_FORM" => 'Y');
         }
         if (array_key_exists($fieldId, $ignoreProperty)) {
             $ignoreProperty[$fieldId] ? $key = $ignoreProperty[$fieldId] : ($key = $fieldId);
             $result[$key]["sort"] = $field["SORT"];
             $result[$key]["settings"] = $field["SETTINGS"];
             if ($field["ROW_COUNT"] && $field["COL_COUNT"]) {
                 $result[$key]["row_count"] = $field["ROW_COUNT"];
                 $result[$key]["col_count"] = $field["COL_COUNT"];
             }
         } else {
             if (!isset($result[$fieldId])) {
                 $result[$fieldId] = array('Name' => $field['NAME'], 'Filterable' => false, 'Editable' => true, 'Required' => $field['IS_REQUIRED'], 'Multiple' => $field['MULTIPLE'], 'Type' => $field['TYPE']);
             }
             $result[$fieldId]["sort"] = $field["SORT"];
             $result[$fieldId]["settings"] = $field["SETTINGS"];
             if ($field["ROW_COUNT"] && $field["COL_COUNT"]) {
                 $result[$fieldId]["row_count"] = $field["ROW_COUNT"];
                 $result[$fieldId]["col_count"] = $field["COL_COUNT"];
             }
         }
     }
     return $result;
 }
Example #2
0
    protected function createPreparedFields()
    {
        $this->lists['PREPARED_FIELDS'] = array();
        $this->lists['ELEMENT_ID'] = 0;
        $this->createFormData();
        $this->getElementFields();
        foreach ($this->lists['FIELDS'] as $fieldId => $field) {
            if ($fieldId == 'ACTIVE_FROM' || $fieldId == 'ACTIVE_TO') {
                $this->lists['PREPARED_FIELDS'][$fieldId] = array('id' => $fieldId . '[' . $this->iblockId . ']', 'name' => $field['NAME'], 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false, 'type' => 'date', 'value' => $this->lists['FORM_DATA'][$fieldId]);
            } elseif ($fieldId == 'PREVIEW_PICTURE' || $fieldId == 'DETAIL_PICTURE') {
                $this->lists['PREPARED_FIELDS'][$fieldId] = array('id' => $fieldId, 'name' => $field['NAME'], 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false, 'type' => 'file');
            } elseif ($fieldId == 'PREVIEW_TEXT' || $fieldId == 'DETAIL_TEXT') {
                if ($field['SETTINGS']['USE_EDITOR'] == 'Y') {
                    $params = array('width' => '100%', 'height' => '200px', 'iblockId' => $this->iblockId);
                    $match = array();
                    if (preg_match('/\\s*(\\d+)\\s*(px|%|)/', $field['SETTINGS']['WIDTH'], $match) && $match[1] > 0) {
                        $params['width'] = $match[1] . $match[2];
                    }
                    if (preg_match('/\\s*(\\d+)\\s*(px|%|)/', $field['SETTINGS']['HEIGHT'], $match) && $match[1] > 0) {
                        $params['height'] = $match[1] . $match[2];
                    }
                    $html = $this->connectionHtmlEditor($fieldId, $fieldId, $params, $this->lists['FORM_DATA'][$fieldId]);
                    $this->lists['PREPARED_FIELDS'][$fieldId] = array('id' => $fieldId, 'name' => $field['NAME'], 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false, 'type' => 'custom', 'value' => $html);
                } else {
                    $params = array('style' => '');
                    if (preg_match('/\\s*(\\d+)\\s*(px|%|)/', $field['SETTINGS']['WIDTH'], $match) && $match[1] > 0) {
                        if ($match[2] == '') {
                            $params['cols'] = $match[1];
                        } else {
                            $params['style'] .= 'width:' . $match[1] . $match[2] . ';';
                        }
                    }
                    if (preg_match('/\\s*(\\d+)\\s*(px|%|)/', $field['SETTINGS']['HEIGHT'], $match) && $match[1] > 0) {
                        if ($match[2] == "") {
                            $params['rows'] = $match[1];
                        } else {
                            $params['style'] .= 'height:' . $match[1] . $match[2] . ';';
                        }
                    }
                    $this->lists['PREPARED_FIELDS'][$fieldId] = array('id' => $fieldId, 'name' => $field['NAME'], 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false, 'type' => 'textarea', 'params' => $params);
                }
            } elseif ($fieldId == "DATE_CREATE" || $fieldId == "TIMESTAMP_X") {
                if ($this->lists['ELEMENT_FIELDS'][$fieldId]) {
                    $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId, "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => "custom", "value" => $this->lists['ELEMENT_FIELDS'][$fieldId]);
                }
            } elseif ($fieldId == "CREATED_BY") {
                if ($this->lists['ELEMENT_FIELDS']["CREATED_BY"]) {
                    $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId, "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => "custom", "value" => "[" . $this->lists['ELEMENT_FIELDS']["CREATED_BY"] . "] " . $this->lists['ELEMENT_FIELDS']["CREATED_USER_NAME"]);
                }
            } elseif ($fieldId == "MODIFIED_BY") {
                if ($this->lists['ELEMENT_FIELDS']["MODIFIED_BY"]) {
                    $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId, "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => "custom", "value" => "[" . $this->lists['ELEMENT_FIELDS']["MODIFIED_BY"] . "] " . $this->lists['ELEMENT_FIELDS']["USER_NAME"]);
                }
            } elseif (is_array($field["PROPERTY_USER_TYPE"]) && array_key_exists("GetPublicEditHTMLMulty", $field["PROPERTY_USER_TYPE"]) && $field["MULTIPLE"] == "Y" && $field["PROPERTY_TYPE"] != "E") {
                $html = call_user_func_array($field["PROPERTY_USER_TYPE"]["GetPublicEditHTMLMulty"], array($field, $this->lists['FORM_DATA'][$fieldId], array("VALUE" => $fieldId, "DESCRIPTION" => '', "FORM_NAME" => $this->formId, "MODE" => "FORM_FILL")));
                $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId, "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => "custom", "value" => $html);
            } elseif (is_array($field["PROPERTY_USER_TYPE"]) && array_key_exists("GetPublicEditHTML", $field["PROPERTY_USER_TYPE"])) {
                $params = array('width' => '100%', 'height' => '200px', 'iblockId' => '');
                if ($field["MULTIPLE"] == "Y") {
                    $checkHtml = false;
                    $html = '<table id="tbl' . $fieldId . '">';
                    foreach ($this->lists['FORM_DATA'][$fieldId] as $key => $value) {
                        if ($field["TYPE"] == "S:HTML") {
                            $checkHtml = true;
                            $fieldIdForHtml = 'id_' . $fieldId . '__' . $key . '_';
                            $fieldNameForHtml = $fieldId . "[" . $key . "][VALUE]";
                            $html .= '<tr><td>' . $this->connectionHtmlEditor($fieldIdForHtml, $fieldNameForHtml, $params, is_array($value['VALUE']) ? $value['VALUE']['TEXT'] : '') . '</td></tr>';
                        } elseif ($field['TYPE'] == 'S:DateTime') {
                            $html .= '<tr><td>
								<input class="bx-lists-input-calendar" type="text" name="' . $fieldId . '[' . $key . '][VALUE]" onclick="BX.calendar({node: this.parentNode, field: this, bTime: true, bHideTime: false});" value="' . $value['VALUE'] . '">
								<span class="bx-lists-calendar-icon" onclick="BX.calendar({node:this, field:\'' . $fieldId . '[' . $key . '][VALUE]\', form: \'\', bTime: true, bHideTime: false});"
									  onmouseover="BX.addClass(this, \'calendar-icon-hover\');" onmouseout="BX.removeClass(this, \'calendar-icon-hover\');" border="0"></span>
							</td></tr>';
                        } elseif ($field['TYPE'] == 'S:Date') {
                            $html .= '<tr><td>
								<input class="bx-lists-input-calendar" type="text" name="' . $fieldId . '[' . $key . '][VALUE]" onclick="BX.calendar({node: this.parentNode, field: this, bTime: false, bHideTime: false});" value="' . $value['VALUE'] . '">
								<span class="bx-lists-calendar-icon" onclick="BX.calendar({node:this, field:\'' . $fieldId . '[' . $key . '][VALUE]\', form: \'\', bTime: false, bHideTime: false});"
									  onmouseover="BX.addClass(this, \'calendar-icon-hover\');" onmouseout="BX.removeClass(this, \'calendar-icon-hover\');" border="0"></span>
							</td></tr>';
                        } else {
                            $html .= '<tr><td>' . call_user_func_array($field["PROPERTY_USER_TYPE"]["GetPublicEditHTML"], array($field, $value, array("VALUE" => $fieldId . "[" . $key . "][VALUE]", "DESCRIPTION" => '', "FORM_NAME" => $this->formId, "MODE" => "FORM_FILL", "COPY" => false))) . '</td></tr>';
                        }
                    }
                    $html .= '</table>';
                    if ($checkHtml) {
                        $html .= '<span class="bx-lists-input-add-button"><input type="button" onclick="javascript:BX[\'LiveFeedClass_' . $this->randomString . '\'].createAdditionalHtmlEditor(\'tbl' . $fieldId . '\', \'' . $fieldId . '\', \'' . $this->formId . '\');" value="' . Loc::getMessage("LISTS_SEAC_ADD_BUTTON") . '"></span>';
                    } else {
                        $html .= '<span class="bx-lists-input-add-button"><input type="button" onclick="javascript:BX[\'LiveFeedClass_' . $this->randomString . '\'].addNewTableRow(\'tbl' . $fieldId . '\', 1, /' . $fieldId . '\\[(n)([0-9]*)\\]/g, 2)" value="' . Loc::getMessage("LISTS_SEAC_ADD_BUTTON") . '"></span>';
                    }
                    $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId, "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => "custom", "value" => $html);
                } else {
                    $html = '';
                    foreach ($this->lists['FORM_DATA'][$fieldId] as $key => $value) {
                        if ($field["TYPE"] == "S:HTML") {
                            $html = $this->connectionHtmlEditor($fieldId, $fieldId, $params, is_array($value['VALUE']) ? $value['VALUE']['TEXT'] : '');
                        } elseif ($field['TYPE'] == 'S:DateTime') {
                            $html = '
								<input class="bx-lists-input-calendar" type="text" name="' . $fieldId . '[n0][VALUE]" onclick="BX.calendar({node: this.parentNode, field: this, bTime: true, bHideTime: false});" value="' . $value['VALUE'] . '">
								<span class="bx-lists-calendar-icon" onclick="BX.calendar({node:this, field:\'' . $fieldId . '[n0][VALUE]\', form: \'\', bTime: true, bHideTime: false});"
									  onmouseover="BX.addClass(this, \'calendar-icon-hover\');" onmouseout="BX.removeClass(this, \'calendar-icon-hover\');" border="0"></span>
							';
                        } elseif ($field['TYPE'] == 'S:Date') {
                            $html = '
								<input class="bx-lists-input-calendar" type="text" name="' . $fieldId . '[n0][VALUE]" onclick="BX.calendar({node: this.parentNode, field: this, bTime: false, bHideTime: false});" value="' . $value['VALUE'] . '">
								<span class="bx-lists-calendar-icon" onclick="BX.calendar({node:this, field:\'' . $fieldId . '[n0][VALUE]\', form: \'\', bTime: false, bHideTime: false});"
									  onmouseover="BX.addClass(this, \'calendar-icon-hover\');" onmouseout="BX.removeClass(this, \'calendar-icon-hover\');" border="0"></span>
							';
                        } else {
                            $html = call_user_func_array($field['PROPERTY_USER_TYPE']['GetPublicEditHTML'], array($field, $value, array('VALUE' => $fieldId . '[' . $key . '][VALUE]', 'DESCRIPTION' => '', 'FORM_NAME' => $this->formId, 'MODE' => 'FORM_FILL', 'COPY' => false)));
                        }
                        break;
                    }
                    $this->lists['PREPARED_FIELDS'][$fieldId] = array('id' => $fieldId, 'name' => $field['NAME'], 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false, 'type' => 'custom', 'value' => $html);
                }
            } elseif ($field["PROPERTY_TYPE"] == "N") {
                $html = '';
                if ($field["MULTIPLE"] == "Y") {
                    $html = '<table id="tbl' . $fieldId . '">';
                    foreach ($this->lists['FORM_DATA'][$fieldId] as $key => $value) {
                        $html .= '<tr><td><input type="text" name="' . $fieldId . '[' . $key . '][VALUE]" value="' . $value["VALUE"] . '"></td></tr>';
                    }
                    $html .= '</table>';
                    $html .= '<span class="bx-lists-input-add-button"><input type="button" onclick="javascript:BX[\'LiveFeedClass_' . $this->randomString . '\'].addNewTableRow(\'tbl' . $fieldId . '\', 1, /' . $fieldId . '\\[(n)([0-9]*)\\]/g, 2)" value="' . Loc::getMessage("LISTS_SEAC_ADD_BUTTON") . '"></span>';
                } else {
                    foreach ($this->lists['FORM_DATA'][$fieldId] as $key => $value) {
                        $html = '<input type="text" name="' . $fieldId . '[' . $key . '][VALUE]" value="' . $value["VALUE"] . '">';
                    }
                }
                $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId, "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => "custom", "value" => $html);
            } elseif ($field["PROPERTY_TYPE"] == "S") {
                $html = '';
                if ($field["MULTIPLE"] == "Y") {
                    $html = '<table id="tbl' . $fieldId . '">';
                    if ($field["ROW_COUNT"] > 1) {
                        foreach ($this->lists['FORM_DATA'][$fieldId] as $key => $value) {
                            $html .= '<tr><td><textarea name="' . $fieldId . '[' . $key . '][VALUE]" rows="' . intval($field["ROW_COUNT"]) . '" cols="' . intval($field["COL_COUNT"]) . '">' . $value["VALUE"] . '</textarea></td></tr>';
                        }
                    } else {
                        foreach ($this->lists['FORM_DATA'][$fieldId] as $key => $value) {
                            $html .= '<tr><td><input type="text" name="' . $fieldId . '[' . $key . '][VALUE]" value="' . $value["VALUE"] . '"></td></tr>';
                        }
                    }
                    $html .= '</table>';
                    $html .= '<span class="bx-lists-input-add-button"><input type="button" onclick="javascript:BX[\'LiveFeedClass_' . $this->randomString . '\'].addNewTableRow(\'tbl' . $fieldId . '\', 1, /' . $fieldId . '\\[(n)([0-9]*)\\]/g, 2)" value="' . Loc::getMessage("LISTS_SEAC_ADD_BUTTON") . '"></span>';
                } else {
                    if ($field["ROW_COUNT"] > 1) {
                        foreach ($this->lists['FORM_DATA'][$fieldId] as $key => $value) {
                            $html = '<textarea name="' . $fieldId . '[' . $key . '][VALUE]" rows="' . intval($field["ROW_COUNT"]) . '" cols="' . intval($field["COL_COUNT"]) . '">' . $value["VALUE"] . '</textarea>';
                        }
                    } else {
                        foreach ($this->lists['FORM_DATA'][$fieldId] as $key => $value) {
                            $html = '<input type="text" name="' . $fieldId . '[' . $key . '][VALUE]" value="' . $value["VALUE"] . '" size="' . intval($field["COL_COUNT"]) . '">';
                        }
                    }
                }
                $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId, "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => "custom", "value" => $html);
            } elseif ($field["PROPERTY_TYPE"] == "L") {
                $items = array("" => Loc::getMessage("LISTS_SEAC_NO_VALUE"));
                $propEnums = CIBlockProperty::getPropertyEnum($field["ID"]);
                while ($enum = $propEnums->fetch()) {
                    $items[$enum["ID"]] = $enum["VALUE"];
                }
                if ($field["MULTIPLE"] == "Y") {
                    $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId . '[]', "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => 'list', "items" => $items, "value" => $this->lists['FORM_DATA'][$fieldId], "params" => array("size" => 5, "multiple" => "multiple"));
                } else {
                    $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId, "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => 'list', "items" => $items, "value" => $this->lists['FORM_DATA'][$fieldId]);
                }
            } elseif ($field['PROPERTY_TYPE'] == 'F') {
                $html = '
					<script>
						var wrappers = document.getElementsByClassName("bx-lists-input-file");
						for (var i = 0; i < wrappers.length; i++)
						{
							var inputs = wrappers[i].getElementsByTagName("input");
							for (var j = 0; j < inputs.length; j++)
							{
								inputs[j].onchange = getName;
							}
						}
						function getName ()
						{
							var str = this.value, i;
							if (str.lastIndexOf("\\\\"))
							{
								i = str.lastIndexOf("\\\\")+1;
							}
							else
							{
								i = str.lastIndexOf("\\\\")+1;
							}
							str = str.slice(i);
							var uploaded = this.parentNode.parentNode.getElementsByClassName("fileformlabel")[0];
							uploaded.innerHTML = str;
						}
					</script>
				';
                if ($field['MULTIPLE'] == 'Y') {
                    $html .= '<table id="tbl' . $fieldId . '">';
                    foreach ($this->lists['FORM_DATA'][$fieldId] as $key => $value) {
                        $html .= '<tr><td><span class="file-wrapper"><span class="bx-lists-input-file">
								<span class="webform-small-button bx-lists-small-button">' . Loc::getMessage('LISTS_SEAC_FILE_ADD') . '</span>';
                        $html .= $this->connectionFile($fieldId, $key, $value, $field['PROPERTY_TYPE']);
                        $html .= '</span><span class="fileformlabel bx-lists-input-file-name"></span></span></td></tr>';
                    }
                    $html .= '</table>';
                    $html .= '
						<span class="bx-lists-input-add-button">
							<input type="button" onclick="javascript:BX[\'LiveFeedClass_' . $this->randomString . '\'].addNewTableRow(\'tbl' . $fieldId . '\', 1, /' . $fieldId . '\\[(n)([0-9]*)\\]/g, 2);
							BX[\'LiveFeedClass_' . $this->randomString . '\'].getNameInputFile();" value="' . Loc::getMessage("LISTS_SEAC_ADD_BUTTON") . '">
						</span>';
                    $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId, "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => "custom", "value" => $html);
                } else {
                    foreach ($this->lists['FORM_DATA'][$fieldId] as $key => $value) {
                        $html .= '<span class="file-wrapper"><span class="bx-lists-input-file">
								<span class="webform-small-button bx-lists-small-button">' . Loc::getMessage('LISTS_SEAC_FILE_ADD') . '</span>';
                        $html .= $this->connectionFile($fieldId, $key, $value, $field['PROPERTY_TYPE']);
                        $html .= '</span><span class="fileformlabel bx-lists-input-file-name"></span></span>';
                        $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId . '[' . $key . '][VALUE]', "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => "file", "value" => $html);
                    }
                }
            } elseif ($field["PROPERTY_TYPE"] == "G") {
                if ($field["IS_REQUIRED"] == "Y") {
                    $items = array();
                } else {
                    $items = array("" => Loc::getMessage("LISTS_SEAC_NO_VALUE"));
                }
                $rsSections = CIBlockSection::GetTreeList(array("IBLOCK_ID" => $field["LINK_IBLOCK_ID"]));
                while ($res = $rsSections->GetNext()) {
                    $items[$res["ID"]] = str_repeat(" . ", $res["DEPTH_LEVEL"]) . $res["NAME"];
                }
                if ($field["MULTIPLE"] == "Y") {
                    $params = array("size" => 4, "multiple" => "multiple");
                } else {
                    $params = array();
                }
                $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId . '[]', "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => 'list', "items" => $items, "value" => $this->lists['FORM_DATA'][$fieldId], "params" => $params);
            } elseif ($field["PROPERTY_TYPE"] == "E") {
                if ($field["IS_REQUIRED"] == "Y") {
                    $items = array();
                } else {
                    $items = array("" => Loc::getMessage("LISTS_SEAC_NO_VALUE"));
                }
                $elements = CIBlockElement::getList(array("NAME" => "ASC"), array("IBLOCK_ID" => $field["LINK_IBLOCK_ID"]), false, false, array("ID", "NAME"));
                while ($res = $elements->fetch()) {
                    $items[$res["ID"]] = $res["NAME"];
                }
                if ($field["MULTIPLE"] == "Y") {
                    $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId . '[]', "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => 'list', "items" => $items, "value" => $this->lists['FORM_DATA'][$fieldId], "params" => array("size" => 5, "multiple" => "multiple"));
                } else {
                    $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId, "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => 'list', "items" => $items, "value" => $this->lists['FORM_DATA'][$fieldId]);
                }
            } elseif ($field["MULTIPLE"] == "Y") {
                $html = '<table id="tbl' . $fieldId . '"><tr><td>';
                foreach ($this->lists['FORM_DATA'][$fieldId] as $key => $value) {
                    $html .= '<tr><td><input type="text" name="' . $fieldId . '[' . $key . '][VALUE]" value="' . $value["VALUE"] . '"></td></tr>';
                }
                $html .= '</td></tr></table>';
                $html .= '
				<span class="bx-lists-input-add-button">
					<input type="button" onclick="javascript:BX[\'LiveFeedClass_' . $this->randomString . '\'].addNewTableRow(\'tbl' . $fieldId . '\', 1, /' . $fieldId . '\\[(n)([0-9]*)\\]/g, 2)" value="' . Loc::getMessage("LISTS_SEAC_ADD_BUTTON") . '">
				</span>';
                $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId, "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => "custom", "value" => $html);
            } elseif (is_array($this->lists['FORM_DATA'][$fieldId]) && array_key_exists("VALUE", $this->lists['FORM_DATA'][$fieldId])) {
                $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId . '[VALUE]', "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => "text", "value" => $this->lists['FORM_DATA'][$fieldId]["VALUE"]);
            } else {
                $this->lists['PREPARED_FIELDS'][$fieldId] = array("id" => $fieldId, "name" => $field["NAME"], "required" => $field["IS_REQUIRED"] == "Y" ? true : false, "type" => "text");
            }
            if (!($fieldId == 'DATE_CREATE' || $fieldId == 'TIMESTAMP_X' || $fieldId == 'CREATED_BY' || $fieldId == 'MODIFIED_BY')) {
                if (isset($field['SETTINGS']['SHOW_ADD_FORM'])) {
                    $this->lists['PREPARED_FIELDS'][$fieldId]['show'] = $field['SETTINGS']['SHOW_ADD_FORM'] == 'Y' ? 'Y' : 'N';
                } else {
                    $this->lists['PREPARED_FIELDS'][$fieldId]['show'] = 'Y';
                }
            }
        }
    }
Example #3
0
 protected static function getPropsParams($iblockId)
 {
     $arRes = array();
     $bUseHLIblock = \Bitrix\Main\Loader::includeModule('highloadblock');
     $rsProps = \CIBlockProperty::getList(array('SORT' => 'ASC', 'ID' => 'ASC'), array('IBLOCK_ID' => $iblockId, 'ACTIVE' => 'Y'));
     while ($arProp = $rsProps->fetch()) {
         if ($arProp['PROPERTY_TYPE'] == 'L' || $arProp['PROPERTY_TYPE'] == 'E' || $arProp['PROPERTY_TYPE'] == 'S' && $arProp['USER_TYPE'] == 'directory') {
             if ($arProp['XML_ID'] == 'CML2_LINK') {
                 continue;
             }
             $arValues = array();
             if ($arProp['PROPERTY_TYPE'] == 'L') {
                 $arValues = array();
                 $rsPropEnums = \CIBlockProperty::getPropertyEnum($arProp['ID']);
                 while ($arEnum = $rsPropEnums->fetch()) {
                     $arValues[$arEnum['VALUE']] = array('ID' => $arEnum['ID'], 'NAME' => $arEnum['VALUE'], 'PICT' => false);
                 }
             } elseif ($arProp['PROPERTY_TYPE'] == 'E') {
                 $rsPropEnums = \CIBlockElement::getList(array('SORT' => 'ASC'), array('IBLOCK_ID' => $arProp['LINK_IBLOCK_ID'], 'ACTIVE' => 'Y'), false, false, array('ID', 'NAME', 'PREVIEW_PICTURE'));
                 while ($arEnum = $rsPropEnums->Fetch()) {
                     $arEnum['PREVIEW_PICTURE'] = \CFile::getFileArray($arEnum['PREVIEW_PICTURE']);
                     if (!is_array($arEnum['PREVIEW_PICTURE'])) {
                         $arEnum['PREVIEW_PICTURE'] = false;
                     }
                     if ($arEnum['PREVIEW_PICTURE'] !== false) {
                         $productImg = \CFile::resizeImageGet($arEnum['PREVIEW_PICTURE'], array('width' => 80, 'height' => 80), BX_RESIZE_IMAGE_PROPORTIONAL, false, false);
                         $arEnum['PREVIEW_PICTURE']['SRC'] = $productImg['src'];
                     }
                     $arValues[$arEnum['NAME']] = array('ID' => $arEnum['ID'], 'NAME' => $arEnum['NAME'], 'SORT' => $arEnum['SORT'], 'PICT' => $arEnum['PREVIEW_PICTURE']);
                 }
             } elseif ($arProp['PROPERTY_TYPE'] == 'S' && $arProp['USER_TYPE'] == 'directory') {
                 if ($bUseHLIblock) {
                     $hlblock = HL\HighloadBlockTable::getList(array("filter" => array("TABLE_NAME" => $arProp["USER_TYPE_SETTINGS"]["TABLE_NAME"])))->fetch();
                     if ($hlblock) {
                         $entity = HL\HighloadBlockTable::compileEntity($hlblock);
                         $entity_data_class = $entity->getDataClass();
                         $rsData = $entity_data_class::getList();
                         while ($arData = $rsData->fetch()) {
                             $arValues[$arData['UF_XML_ID']] = array('ID' => $arData['ID'], 'NAME' => $arData['UF_NAME'], 'SORT' => $arData['UF_SORT'], 'FILE' => $arData['UF_FILE'], 'PICT' => '', 'XML_ID' => $arData['UF_XML_ID']);
                         }
                     }
                 }
             }
             if (!empty($arValues) && is_array($arValues)) {
                 $arRes[$arProp['ID']] = array('ID' => $arProp['ID'], 'CODE' => $arProp['CODE'], 'NAME' => $arProp['NAME'], 'TYPE' => $arProp['PROPERTY_TYPE'], 'ORDER' => array_keys($arValues), 'VALUES' => $arValues, 'SORT' => $arProp['SORT']);
             }
         }
         if ($arProp['PROPERTY_TYPE'] == "S" && is_array($arRes[$arProp['ID']]['VALUES'])) {
             foreach ($arRes[$arProp['ID']]['VALUES'] as $id => $value) {
                 $arTmpFile = \CFile::getFileArray($value["FILE"]);
                 $tmpImg = \CFile::resizeImageGet($arTmpFile, array('width' => 20, 'height' => 20), BX_RESIZE_IMAGE_PROPORTIONAL, false, false);
                 $arRes[$arProp['ID']]['VALUES'][$id]['PICT'] = $tmpImg['src'];
             }
         }
     }
     return $arRes;
 }