120 $documentId = intval($documentId);
121 if ($documentId <= 0)
123 throw new CBPArgumentNullException(
'documentId');
128 $elementProperty = [];
130 $queryElement = CIBlockElement::getList(
132 [
'ID' => $documentId,
'SHOW_NEW' =>
'Y',
'SHOW_HISTORY' =>
'Y']
134 while ($queryResult = $queryElement->fetch())
136 $element = $queryResult;
137 $queryProperty = CIBlockElement::getProperty(
138 $queryResult[
'IBLOCK_ID'],
140 [
'sort' =>
'asc',
'id' =>
'asc',
'enum_sort' =>
'asc',
'value_id' =>
'asc'],
141 [
'ACTIVE' =>
'Y',
'EMPTY' =>
'N']
143 while ($property = $queryProperty->fetch())
145 $propertyKey =
'PROPERTY_' . $property[
'ID'];
146 if ($property[
'MULTIPLE'] ==
'Y')
148 if (!array_key_exists($propertyKey, $elementProperty))
150 $elementProperty[$propertyKey] = $property;
151 $elementProperty[$propertyKey][
'VALUE'] = [];
153 $elementProperty[$propertyKey][
'VALUE'][] = $property[
'VALUE'];
157 $elementProperty[$propertyKey] = $property;
162 foreach ($element as $fieldId => $fieldValue)
164 $result[$fieldId] = $fieldValue;
165 if (in_array($fieldId, [
'MODIFIED_BY',
'CREATED_BY']))
167 $result[$fieldId] =
'user_' . $fieldValue;
168 $result[$fieldId .
'_PRINTABLE'] =
169 $element[($fieldId ==
'MODIFIED_BY')
171 :
'CREATED_USER_NAME']
174 elseif (in_array($fieldId, [
'PREVIEW_TEXT',
'DETAIL_TEXT']))
176 if ($element[$fieldId .
'_TYPE'] ==
'html')
178 $result[$fieldId] = HTMLToTxt($fieldValue);
182 foreach ($elementProperty as $propertyId => $property)
184 if (trim($property[
'CODE']) <>
'')
186 $propertyId = $property[
'CODE'];
190 $propertyId = $property[
'ID'];
193 if (!empty($property[
'USER_TYPE']))
196 $property[
'USER_TYPE'] ==
'UserID'
197 || $property[
'USER_TYPE'] ==
'employee'
198 && (COption::getOptionString(
'bizproc',
'employee_compatible_mode',
'N') !=
'Y')
201 if (empty($property[
'VALUE']))
205 if (!is_array($property[
'VALUE']))
207 $property[
'VALUE'] = [$property[
'VALUE']];
210 $listUsers = implode(
' | ', $property[
'VALUE']);
211 $userQuery = CUser::getList(
214 [
'ID' => $listUsers],
216 'FIELDS' => [
'ID',
'LOGIN',
'NAME',
'LAST_NAME'],
219 while ($user = $userQuery->fetch())
221 if ($property[
'MULTIPLE'] ==
'Y')
224 $result =
self::setArray($result,
'PROPERTY_' . $propertyId .
'_PRINTABLE');
225 $result[
'PROPERTY_' . $propertyId][] =
'user_' . intval($user[
'ID']);
226 $result[
'PROPERTY_' . $propertyId .
'_PRINTABLE'][] =
'(' . $user[
'LOGIN'] .
')' .
227 (($user[
'NAME'] <>
'' || $user[
'LAST_NAME'] <>
'') ?
' ' :
'') . $user[
'NAME'] .
228 (($user[
'NAME'] <>
'' && $user[
'LAST_NAME'] <>
'') ?
' ' :
'') . $user[
'LAST_NAME'];
232 $result[
'PROPERTY_' . $propertyId] =
'user_' . intval($user[
'ID']);
233 $result[
'PROPERTY_' . $propertyId .
'_PRINTABLE'] =
'(' . $user[
'LOGIN'] .
')' .
234 (($user[
'NAME'] <>
'' || $user[
'LAST_NAME'] <>
'') ?
' ' :
'') . $user[
'NAME'] .
235 (($user[
'NAME'] <>
'' && $user[
'LAST_NAME'] <>
'') ?
' ' :
'') . $user[
'LAST_NAME'];
239 elseif ($property[
'USER_TYPE'] ==
'DiskFile')
241 $diskValues = current($property[
'VALUE']);
242 $userType = \CIBlockProperty::getUserType($property[
'USER_TYPE']);
243 if (is_array($diskValues))
246 $result =
self::setArray($result,
'PROPERTY_' . $propertyId .
'_PRINTABLE');
247 foreach ($diskValues as $attachedId)
250 if (array_key_exists(
'GetObjectId', $userType))
252 $fileId = call_user_func_array($userType[
'GetObjectId'], [$attachedId]);
259 if (array_key_exists(
'GetUrlAttachedFileElement', $userType))
261 $printableUrl = call_user_func_array(
262 $userType[
'GetUrlAttachedFileElement'],
263 [$documentId, $fileId]
267 $result[
'PROPERTY_' . $propertyId][$attachedId] = $fileId;
268 $result[
'PROPERTY_' . $propertyId .
'_PRINTABLE'][$attachedId] = $printableUrl;
276 elseif ($property[
'USER_TYPE'] ==
'HTML')
278 if (\CBPHelper::isAssociativeArray($property[
'VALUE']))
280 if ($property[
'VALUE'][
'TYPE'] ==
'HTML')
282 $result[
'PROPERTY_' . $propertyId] = HTMLToTxt($property[
'VALUE'][
'TEXT']);
286 $result[
'PROPERTY_' . $propertyId] = $property[
'VALUE'][
'TEXT'];
292 foreach ($property[
'VALUE'] as $htmlValue)
294 if ($htmlValue[
'TYPE'] ==
'HTML')
296 $result[
'PROPERTY_' . $propertyId][] = HTMLToTxt($htmlValue[
'TEXT']);
300 $result[
'PROPERTY_' . $propertyId][] = $htmlValue[
'TEXT'];
305 elseif ($property[
'USER_TYPE'] ==
'Money')
307 $userType = \CIBlockProperty::getUserType($property[
'USER_TYPE']);
308 if (is_array($property[
'VALUE']))
311 $result =
self::setArray($result,
'PROPERTY_' . $propertyId .
'_PRINTABLE');
312 foreach ($property[
'VALUE'] as $moneyValue)
314 $result[
'PROPERTY_' . $propertyId][] = $moneyValue;
315 if (array_key_exists(
'GetPublicViewHTML', $userType))
317 $result[
'PROPERTY_' . $propertyId .
'_PRINTABLE'][] = call_user_func_array(
318 $userType[
'GetPublicViewHTML'],
319 [$property, [
'VALUE' => $moneyValue], []]
326 $result[
'PROPERTY_' . $propertyId] = $property[
'VALUE'];
327 if (array_key_exists(
'GetPublicViewHTML', $userType))
329 $result[
'PROPERTY_' . $propertyId .
'_PRINTABLE'] = call_user_func_array(
330 $userType[
'GetPublicViewHTML'],
331 [$property, [
'VALUE' => $property[
'VALUE']], []]
338 $result[
'PROPERTY_' . $propertyId] = $property[
'VALUE'];
341 elseif ($property[
'PROPERTY_TYPE'] ==
'L')
346 $propertyKeyArray = [];
347 if (!is_array($property[
'VALUE']))
349 $property[
'VALUE'] = [$property[
'VALUE']];
351 foreach ($property[
'VALUE'] as $enumId)
353 $enumsObject = CIBlockProperty::getPropertyEnum(
358 while ($enums = $enumsObject->fetch())
360 $propertyArray[] = $enums[
'VALUE'];
361 $propertyKeyArray[] = $enums[
'XML_ID'];
364 for ($i = 0, $cnt = count($propertyArray); $i < $cnt; $i++)
366 $result[
'PROPERTY_' . $propertyId][$propertyKeyArray[$i]] = $propertyArray[$i];
369 elseif ($property[
'PROPERTY_TYPE'] ==
'F')
372 $result =
self::setArray($result,
'PROPERTY_' . $propertyId .
'_PRINTABLE');
373 $propertyArray = $property[
'VALUE'];
374 if (!is_array($propertyArray))
376 $propertyArray = [$propertyArray];
379 foreach ($propertyArray as $v)
381 $fileArray = \CFile::getFileArray($v);
384 $result[
'PROPERTY_' . $propertyId][] = intval($v);
385 $result[
'PROPERTY_' . $propertyId .
'_PRINTABLE'][] =
386 "[url=/bitrix/tools/bizproc_show_file.php?f=" .
387 urlencode($fileArray[
"FILE_NAME"]) .
"&i=" . $v .
"&h=" . md5($fileArray[
"SUBDIR"]) .
"]" .
388 htmlspecialcharsbx($fileArray[
"ORIGINAL_NAME"]) .
"[/url]";
394 $result[
'PROPERTY_' . $propertyId] = $property[
'VALUE'];
400 $documentFields = static::getDocumentFields(static::getDocumentType($documentId));
401 foreach ($documentFields as $fieldKey => $field)
403 if (!array_key_exists($fieldKey, $result))
405 $result[$fieldKey] =
null;
606 $iblockId = intval(mb_substr($documentType, mb_strlen(
"iblock_")));
608 throw new CBPArgumentOutOfRangeException(
"documentType", $documentType);
610 $documentFieldTypes = self::getDocumentFieldTypes($documentType);
614 $dbProperties = CIBlockProperty::getList(
615 array(
"sort" =>
"asc",
"name" =>
"asc"),
616 array(
"IBLOCK_ID" => $iblockId,
'ACTIVE' =>
'Y')
618 $ignoreProperty = array();
619 while ($property = $dbProperties->fetch())
621 if (trim($property[
"CODE"]) <>
'')
623 $key =
"PROPERTY_".$property[
"CODE"];
624 $ignoreProperty[
"PROPERTY_".$property[
"ID"]] =
"PROPERTY_".$property[
"CODE"];
628 $key =
"PROPERTY_".$property[
"ID"];
629 $ignoreProperty[
"PROPERTY_".$property[
"ID"]] = 0;
632 $result[$key] = array(
633 "Name" => $property[
"NAME"],
634 "Filterable" => ($property[
"FILTRABLE"] ==
"Y"),
636 "Required" => ($property[
"IS_REQUIRED"] ==
"Y"),
637 "Multiple" => ($property[
"MULTIPLE"] ==
"Y"),
638 "TypeReal" => $property[
"PROPERTY_TYPE"],
639 "UserTypeSettings" => $property[
"USER_TYPE_SETTINGS"]
642 if(trim($property[
"CODE"]) <>
'')
643 $result[$key][
"Alias"] =
"PROPERTY_".$property[
"ID"];
645 if ($property[
"USER_TYPE"] <>
'')
647 $result[$key][
"TypeReal"] = $property[
"PROPERTY_TYPE"].
":".$property[
"USER_TYPE"];
649 if ($property[
"USER_TYPE"] ==
"UserID"
650 || $property[
"USER_TYPE"] ==
"employee" && (COption::getOptionString(
"bizproc",
"employee_compatible_mode",
"N") !=
"Y"))
652 $result[$key][
"Type"] =
"user";
653 $result[$key.
"_PRINTABLE"] = array(
654 "Name" => $property[
"NAME"].GetMessage(
"IBD_FIELD_USERNAME_PROPERTY"),
655 "Filterable" =>
false,
658 "Multiple" => ($property[
"MULTIPLE"] ==
"Y"),
661 $result[$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
663 elseif ($property[
"USER_TYPE"] ==
"DateTime")
665 $result[$key][
"Type"] =
"datetime";
666 $result[$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
668 elseif ($property[
"USER_TYPE"] ==
"Date")
670 $result[$key][
"Type"] =
"date";
671 $result[$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
673 elseif ($property[
"USER_TYPE"] ==
"EList")
675 $result[$key][
"Type"] =
"E:EList";
676 $result[$key][
"Options"] = $property[
"LINK_IBLOCK_ID"];
678 elseif ($property[
"USER_TYPE"] ==
"ECrm")
680 $result[$key][
"Type"] =
"E:ECrm";
681 $result[$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
682 $result[$key][
"Options"] = $property[
"USER_TYPE_SETTINGS"];
684 elseif ($property[
"USER_TYPE"] ==
"Money")
686 $result[$key][
"Type"] =
"S:Money";
687 $result[$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
688 $result[$key.
"_PRINTABLE"] = array(
689 "Name" => $property[
"NAME"].GetMessage(
"IBD_FIELD_USERNAME_PROPERTY"),
690 "Filterable" =>
false,
693 "Multiple" => ($property[
"MULTIPLE"] ==
"Y"),
697 elseif ($property[
"USER_TYPE"] ==
"Sequence")
699 $result[$key][
"Type"] =
"N:Sequence";
700 $result[$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
701 $result[$key][
"Options"] = $property[
"USER_TYPE_SETTINGS"];
703 elseif ($property[
"USER_TYPE"] ==
"DiskFile")
705 $result[$key][
"Type"] =
"S:DiskFile";
706 $result[$key.
"_PRINTABLE"] = array(
707 "Name" => $property[
"NAME"].GetMessage(
"IBD_FIELD_USERNAME_PROPERTY"),
708 "Filterable" =>
false,
711 "Multiple" => ($property[
"MULTIPLE"] ==
"Y"),
715 elseif ($property[
"USER_TYPE"] ==
"HTML")
717 $result[$key][
"Type"] =
"S:HTML";
718 $result[$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
722 $result[$key][
"Type"] =
"string";
723 $result[$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
726 elseif ($property[
"PROPERTY_TYPE"] ==
"L")
728 $result[$key][
"Type"] =
"select";
730 $result[$key][
"Options"] = array();
731 $dbPropertyEnums = CIBlockProperty::getPropertyEnum($property[
"ID"]);
732 while ($propertyEnum = $dbPropertyEnums->getNext())
734 $result[$key][
"Options"][$propertyEnum[
"XML_ID"]] = $propertyEnum[
"~VALUE"];
735 if($propertyEnum[
"DEF"] ==
"Y")
736 $result[$key][
"DefaultValue"] = $propertyEnum[
"~VALUE"];
739 elseif ($property[
"PROPERTY_TYPE"] ==
"N")
741 $result[$key][
"Type"] =
"double";
742 $result[$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
744 elseif ($property[
"PROPERTY_TYPE"] ==
"F")
746 $result[$key][
"Type"] =
"file";
747 $result[$key.
"_PRINTABLE"] = array(
748 "Name" => $property[
"NAME"].GetMessage(
"IBD_FIELD_USERNAME_PROPERTY"),
749 "Filterable" =>
false,
752 "Multiple" => ($property[
"MULTIPLE"] ==
"Y"),
756 elseif ($property[
"PROPERTY_TYPE"] ==
"S")
758 $result[$key][
"Type"] =
"string";
759 $result[$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
761 elseif ($property[
"PROPERTY_TYPE"] ==
"E")
763 $result[$key][
"Type"] =
"E:EList";
764 $result[$key][
"Options"] = $property[
"LINK_IBLOCK_ID"];
765 $result[$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
769 $result[$key][
"Type"] =
"string";
770 $result[$key][
"DefaultValue"] = $property[
"DEFAULT_VALUE"];
774 $list =
new CList($iblockId);
775 $fields = $list->getFields();
776 foreach($fields as $fieldId => $field)
778 if(empty($field[
"SETTINGS"]))
779 $field[
"SETTINGS"] = array(
"SHOW_ADD_FORM" =>
'Y',
"SHOW_EDIT_FORM"=>
'Y');
781 if(array_key_exists($fieldId, $ignoreProperty))
783 $ignoreProperty[$fieldId] ? $key = $ignoreProperty[$fieldId] : $key = $fieldId;
784 $result[$key][
"sort"] = $field[
"SORT"];
785 $result[$key][
"settings"] = $field[
"SETTINGS"];
786 $result[$key][
"active"] =
true;
787 $result[$key][
"DefaultValue"] = $field[
"DEFAULT_VALUE"];
788 if($field[
"ROW_COUNT"] && $field[
"COL_COUNT"])
790 $result[$key][
"row_count"] = $field[
"ROW_COUNT"];
791 $result[$key][
"col_count"] = $field[
"COL_COUNT"];
796 $result[$fieldId] = array(
797 "Name" => $field[
'NAME'],
798 "Filterable" => !empty($result[$fieldId][
'Filterable']) ? $result[$fieldId][
'Filterable'] :
false,
799 "Editable" => !empty($result[$fieldId][
'Editable']) ? $result[$fieldId][
'Editable'] :
true,
800 "Required" => ($field[
'IS_REQUIRED'] ==
'Y'),
801 "Multiple" => ($field[
'MULTIPLE'] ==
'Y'),
802 "Type" => !empty($result[$fieldId][
'Type']) ? $result[$fieldId][
'Type'] : $field[
'TYPE'],
803 "sort" => $field[
"SORT"],
804 "settings" => $field[
"SETTINGS"],
806 "active_type" => $field[
'TYPE'],
807 "DefaultValue" => $field[
"DEFAULT_VALUE"],
809 if(isset($field[
'ROW_COUNT'], $field[
'COL_COUNT']) && $field[
"ROW_COUNT"] && $field[
"COL_COUNT"])
811 $result[$fieldId][
"row_count"] = $field[
"ROW_COUNT"];
812 $result[$fieldId][
"col_count"] = $field[
"COL_COUNT"];
817 $keys = array_keys($result);
818 foreach ($keys as $k)
820 $result[$k][
"BaseType"] = $documentFieldTypes[$result[$k][
"Type"]][
"BaseType"];
821 $result[$k][
"Complex"] = $documentFieldTypes[$result[$k][
"Type"]][
"Complex"] ??
null;
850 $iblockId = intval(mb_substr($documentType, mb_strlen(
"iblock_")));
852 throw new CBPArgumentOutOfRangeException(
"documentType", $documentType);
854 if (mb_substr($fields[
"code"], 0, mb_strlen(
"PROPERTY_")) ==
"PROPERTY_")
855 $fields[
"code"] = mb_substr($fields[
"code"], mb_strlen(
"PROPERTY_"));
857 if(!empty($fields[
"active_type"]))
858 $fields[
"type"] = $fields[
"active_type"];
860 $fieldsTemporary = array(
861 "NAME" => $fields[
"name"],
863 "SORT" => $fields[
"sort"] ? $fields[
"sort"] : 900,
864 "CODE" => $fields[
"code"],
865 'MULTIPLE' => $fields[
'multiple'] ==
'Y' || (string)$fields[
'multiple'] ===
'1' ?
'Y' :
'N',
866 'IS_REQUIRED' => $fields[
'required'] ==
'Y' || (string)$fields[
'required'] ===
'1' ?
'Y' :
'N',
867 "IBLOCK_ID" => $iblockId,
869 "SETTINGS" => $fields[
"settings"] ? $fields[
"settings"] : array(
"SHOW_ADD_FORM" =>
'Y',
"SHOW_EDIT_FORM"=>
'Y'),
870 "DEFAULT_VALUE" => $fields[
'DefaultValue']
873 if (mb_strpos(
"0123456789", mb_substr($fieldsTemporary[
"CODE"], 0, 1)) !==
false)
874 $fieldsTemporary[
"CODE"] = self::generatePropertyCode($fields[
"name"], $fields[
"code"], $iblockId);
876 if (array_key_exists(
"additional_type_info", $fields))
877 $fieldsTemporary[
"LINK_IBLOCK_ID"] = intval($fields[
"additional_type_info"]);
879 if(!empty($fields[
"UserTypeSettings"]))
880 $fieldsTemporary[
"USER_TYPE_SETTINGS"] = $fields[
"UserTypeSettings"];
882 if(mb_strstr($fields[
"type"],
":") !==
false)
884 list($fieldsTemporary[
"TYPE"], $fieldsTemporary[
"USER_TYPE"]) = explode(
":", $fields[
"type"], 2);
885 if($fields[
"type"] ==
"E:EList")
887 $fieldsTemporary[
"LINK_IBLOCK_ID"] = $fields[
"options"] ??
null;
889 elseif($fields[
"type"] ==
"E:ECrm")
891 $fieldsTemporary[
"TYPE"] =
"S:ECrm";
894 elseif ($fields[
"type"] ==
"user")
896 $fieldsTemporary[
"TYPE"] =
"S:employee";
897 $fieldsTemporary[
"USER_TYPE"]=
"UserID";
899 elseif ($fields[
"type"] ==
"date")
901 $fieldsTemporary[
"TYPE"] =
"S:Date";
902 $fieldsTemporary[
"USER_TYPE"]=
"Date";
904 elseif ($fields[
"type"] ==
"datetime")
906 $fieldsTemporary[
"TYPE"] =
"S:DateTime";
907 $fieldsTemporary[
"USER_TYPE"]=
"DateTime";
909 elseif ($fields[
"type"] ==
"file")
911 $fieldsTemporary[
"TYPE"] =
"F";
912 $fieldsTemporary[
"USER_TYPE"]=
"";
914 elseif ($fields[
"type"] ==
"select")
916 $fieldsTemporary[
"TYPE"] =
"L";
917 $fieldsTemporary[
"USER_TYPE"]=
false;
919 if (is_array($fields[
"options"]))
922 foreach ($fields[
"options"] as $k => $v)
925 if($fields[
'DefaultValue'] == $v)
927 $fieldsTemporary[
"VALUES"][] = array(
"XML_ID" => $k,
"VALUE" => $v,
"DEF" => $def,
"SORT" => $i);
931 elseif (is_string($fields[
"options"]) && ($fields[
"options"] <>
''))
933 $a = explode(
"\n", $fields[
"options"]);
937 $v = trim(trim($v),
"\r\n");
941 if (mb_substr($v, 0, 1) ==
"[" && mb_strpos($v,
"]") !==
false)
943 $v1 = mb_substr($v, 1, mb_strpos($v,
"]") - 1);
944 $v2 = trim(mb_substr($v, mb_strpos($v,
"]") + 1));
947 if($fields[
'DefaultValue'] == $v2)
949 $fieldsTemporary[
"VALUES"][] = array(
"XML_ID" => $v1,
"VALUE" => $v2,
"DEF" => $def,
"SORT" => $i);
954 elseif($fields[
"type"] ==
"string")
956 $fieldsTemporary[
"TYPE"] =
"S";
958 if($fields[
"row_count"] && $fields[
"col_count"])
960 $fieldsTemporary[
"ROW_COUNT"] = $fields[
"row_count"];
961 $fieldsTemporary[
"COL_COUNT"] = $fields[
"col_count"];
965 $fieldsTemporary[
"ROW_COUNT"] = 1;
966 $fieldsTemporary[
"COL_COUNT"] = 30;
969 elseif($fields[
"type"] ==
"text")
971 $fieldsTemporary[
"TYPE"] =
"S";
972 if($fields[
"row_count"] && $fields[
"col_count"])
974 $fieldsTemporary[
"ROW_COUNT"] = $fields[
"row_count"];
975 $fieldsTemporary[
"COL_COUNT"] = $fields[
"col_count"];
979 $fieldsTemporary[
"ROW_COUNT"] = 4;
980 $fieldsTemporary[
"COL_COUNT"] = 30;
983 elseif($fields[
"type"] ==
"int" || $fields[
"type"] ==
"double")
985 $fieldsTemporary[
"TYPE"] =
"N";
987 elseif($fields[
"type"] ==
"bool")
989 $fieldsTemporary[
"TYPE"] =
"L";
990 $fieldsTemporary[
"VALUES"][] = array(
992 "VALUE" => GetMessage(
"BPVDX_YES"),
996 $fieldsTemporary[
"VALUES"][] = array(
998 "VALUE" => GetMessage(
"BPVDX_NO"),
1005 $fieldsTemporary[
"TYPE"] = $fields[
"type"];
1006 $fieldsTemporary[
"USER_TYPE"] =
false;
1010 $properties = CIBlockProperty::getList(
1012 array(
"IBLOCK_ID" => $fieldsTemporary[
"IBLOCK_ID"],
"CODE" => $fieldsTemporary[
"CODE"])
1014 if(!$properties->fetch())
1016 $listObject =
new CList($iblockId);
1017 $idField = $listObject->addField($fieldsTemporary);
1022 global $CACHE_MANAGER;
1023 $CACHE_MANAGER->clearByTag(
"lists_list_".$iblockId);
1024 if(!empty($fieldsTemporary[
"CODE"]))
1026 $idField = mb_substr($idField, 0, mb_strlen(
"PROPERTY_")).$fieldsTemporary[
"CODE"];
1041 if(!isset($fields[
'settings']))
1044 if(!empty($fields[
"active_type"]))
1045 $fields[
"type"] = $fields[
"active_type"];
1047 $iblockId = intval(mb_substr($documentType, mb_strlen(
"iblock_")));
1049 throw new CBPArgumentOutOfRangeException(
"documentType", $documentType);
1052 if (mb_substr($fields[
"code"], 0, mb_strlen(
"PROPERTY_")) ==
"PROPERTY_")
1054 $fields[
"code"] = mb_substr($fields[
"code"], mb_strlen(
"PROPERTY_"));
1055 $propertyObject = CIBlockProperty::getList(
1057 array(
"IBLOCK_ID" => $iblockId,
"CODE" => $fields[
"code"])
1059 if($property = $propertyObject->fetch())
1061 $fieldId =
"PROPERTY_".$property[
"ID"];
1066 if(empty($fields[
"code"]))
1071 $fieldId = $fields[
"code"];
1077 "NAME" => $fields[
"name"],
1079 "SORT" => $fields[
"sort"] ? $fields[
"sort"] : 900,
1080 "CODE" => $fields[
"code"],
1081 'MULTIPLE' => $fields[
'multiple'] ==
'Y' || (string)$fields[
'multiple'] ===
'1' ?
'Y' :
'N',
1082 'IS_REQUIRED' => $fields[
'required'] ==
'Y' || (string)$fields[
'required'] ===
'1' ?
'Y' :
'N',
1083 "IBLOCK_ID" => $iblockId,
1085 "SETTINGS" => $fields[
"settings"] ? $fields[
"settings"] :
1086 array(
"SHOW_ADD_FORM" =>
'Y',
"SHOW_EDIT_FORM"=>
'Y'),
1087 "DEFAULT_VALUE" => $fields[
'DefaultValue']
1090 if (array_key_exists(
"additional_type_info", $fields))
1091 $fieldData[
"LINK_IBLOCK_ID"] = intval($fields[
"additional_type_info"]);
1093 if(!empty($fields[
"UserTypeSettings"]))
1094 $fieldData[
"USER_TYPE_SETTINGS"] = $fields[
"UserTypeSettings"];
1096 if(mb_strstr($fields[
"type"],
":") !==
false)
1098 list($fieldData[
"TYPE"], $fieldData[
"USER_TYPE"]) = explode(
":", $fields[
"type"], 2);
1099 if($fields[
"type"] ==
"E:EList")
1101 $fieldData[
"LINK_IBLOCK_ID"] = $fields[
"options"] ??
null;
1103 elseif($fields[
"type"] ==
"E:ECrm")
1105 $fieldData[
"TYPE"] =
"S:ECrm";
1108 elseif ($fields[
"type"] ==
"user")
1110 $fieldData[
"TYPE"] =
"S:employee";
1111 $fieldData[
"USER_TYPE"]=
"UserID";
1113 elseif ($fields[
"type"] ==
"date")
1115 $fieldData[
"TYPE"] =
"S:Date";
1116 $fieldData[
"USER_TYPE"]=
"Date";
1118 elseif ($fields[
"type"] ==
"datetime")
1120 $fieldData[
"TYPE"] =
"S:DateTime";
1121 $fieldData[
"USER_TYPE"]=
"DateTime";
1123 elseif ($fields[
"type"] ==
"file")
1125 $fieldData[
"TYPE"] =
"F";
1126 $fieldData[
"USER_TYPE"]=
"";
1128 elseif ($fields[
"type"] ==
"select")
1130 $fieldData[
"TYPE"] =
"L";
1131 $fieldData[
"USER_TYPE"]=
false;
1133 if (is_array($fields[
"options"]))
1136 foreach ($fields[
"options"] as $k => $v)
1139 if($fields[
'DefaultValue'] == $v)
1141 $fieldData[
"VALUES"][] = array(
"XML_ID" => $k,
"VALUE" => $v,
"DEF" => $def,
"SORT" => $i);
1145 elseif (is_string($fields[
"options"]) && ($fields[
"options"] <>
''))
1147 $a = explode(
"\n", $fields[
"options"]);
1151 $v = trim(trim($v),
"\r\n");
1155 if (mb_substr($v, 0, 1) ==
"[" && mb_strpos($v,
"]") !==
false)
1157 $v1 = mb_substr($v, 1, mb_strpos($v,
"]") - 1);
1158 $v2 = trim(mb_substr($v, mb_strpos($v,
"]") + 1));
1161 if($fields[
'DefaultValue'] == $v2)
1163 $fieldData[
"VALUES"][] = array(
"XML_ID" => $v1,
"VALUE" => $v2,
"DEF" => $def,
"SORT" => $i);
1168 elseif($fields[
"type"] ==
"string")
1170 $fieldData[
"TYPE"] =
"S";
1172 if($fields[
"row_count"] && $fields[
"col_count"])
1174 $fieldData[
"ROW_COUNT"] = $fields[
"row_count"];
1175 $fieldData[
"COL_COUNT"] = $fields[
"col_count"];
1179 $fieldData[
"ROW_COUNT"] = 1;
1180 $fieldData[
"COL_COUNT"] = 30;
1183 elseif($fields[
"type"] ==
"text")
1185 $fieldData[
"TYPE"] =
"S";
1186 if($fields[
"row_count"] && $fields[
"col_count"])
1188 $fieldData[
"ROW_COUNT"] = $fields[
"row_count"];
1189 $fieldData[
"COL_COUNT"] = $fields[
"col_count"];
1193 $fieldData[
"ROW_COUNT"] = 4;
1194 $fieldData[
"COL_COUNT"] = 30;
1197 elseif($fields[
"type"] ==
"int" || $fields[
"type"] ==
"double")
1199 $fieldData[
"TYPE"] =
"N";
1201 elseif($fields[
"type"] ==
"bool")
1203 $fieldData[
"TYPE"] =
"L";
1204 $fieldData[
"VALUES"][] = array(
1206 "VALUE" => GetMessage(
"BPVDX_YES"),
1210 $fieldData[
"VALUES"][] = array(
1212 "VALUE" => GetMessage(
"BPVDX_NO"),
1219 $fieldData[
"TYPE"] = $fields[
"type"];
1220 $fieldData[
"USER_TYPE"] =
false;
1223 $list =
new CList($iblockId);
1224 $oldFields = $list->getFields();
1225 if(array_key_exists($fieldId, $oldFields))
1227 if($oldFields[$fieldId][
"TYPE"] != $fieldData[
"TYPE"])
1228 $fieldData[
"TYPE"] = $oldFields[$fieldId][
"TYPE"];
1229 $fieldId = $list->updateField($fieldId, $fieldData);
1233 $fieldId = $list->addField($fieldData);
1238 global $CACHE_MANAGER;
1239 $CACHE_MANAGER->clearByTag(
"lists_list_".$iblockId);
1249 $documentId = intval($documentId);
1250 if ($documentId <= 0)
1252 throw new CBPArgumentNullException(
'documentId');
1255 CIBlockElement::WF_CleanUpHistoryCopies($documentId, 0);
1257 $arFieldsPropertyValues = [];
1259 $dbResult = CIBlockElement::GetList(
1261 [
'ID' => $documentId,
'SHOW_NEW' =>
'Y',
'SHOW_HISTORY' =>
'Y'],
1265 $arResult = $dbResult->Fetch();
1268 throw new Exception(
'Element is not found');
1271 $complexDocumentId = [
'lists', get_called_class(), $documentId];
1272 $arDocumentFields = self::GetDocumentFields(
'iblock_' . $arResult[
'IBLOCK_ID']);
1274 $arKeys = array_keys($arFields);
1275 foreach ($arKeys as $key)
1277 if (!array_key_exists($key, $arDocumentFields))
1283 (is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key]))
1285 : [$arFields[$key]];
1287 (mb_substr($key, 0, mb_strlen(
'PROPERTY_')) ==
'PROPERTY_')
1288 ? mb_substr($key, mb_strlen(
'PROPERTY_'))
1292 if ($arDocumentFields[$key][
'Type'] ==
'user')
1294 $arFields[$key] = \CBPHelper::extractUsers($arFields[$key], $complexDocumentId);
1296 elseif ($arDocumentFields[$key][
'Type'] ==
'select')
1299 $db = CIBlockProperty::GetPropertyEnum(
1302 [
'IBLOCK_ID' => $arResult[
'IBLOCK_ID']]
1304 while ($ar = $db->GetNext())
1306 $arV[$ar[
'XML_ID']] = $ar[
'ID'];
1310 foreach ($arFields[$key] as &$value)
1312 if (is_array($value) && CBPHelper::isAssociativeArray($value))
1314 $listXmlId = array_keys($value);
1315 foreach ($listXmlId as $xmlId)
1317 $listValue[] = $arV[$xmlId];
1322 if (array_key_exists($value, $arV))
1324 $value = $arV[$value];
1328 if (!empty($listValue))
1330 $arFields[$key] = $listValue;
1333 elseif ($arDocumentFields[$key][
'Type'] ==
'file')
1336 foreach ($arFields[$key] as $value)
1338 if (is_array($value))
1340 foreach ($value as $file)
1342 $makeFileArray = CFile::MakeFileArray($file);
1345 $files[] = $makeFileArray;
1351 $makeFileArray = CFile::MakeFileArray($value);
1354 $files[] = $makeFileArray;
1360 $arFields[$key] = $files;
1364 $arFields[$key] = [[
'del' =>
'Y']];
1367 elseif ($arDocumentFields[$key][
'Type'] ==
'S:DiskFile')
1369 foreach ($arFields[$key] as &$value)
1373 $value =
'n' . $value;
1376 $arFields[$key] = [
'VALUE' => $arFields[$key],
'DESCRIPTION' =>
'workflow'];
1378 elseif ($arDocumentFields[$key][
'Type'] ==
'S:HTML')
1380 foreach ($arFields[$key] as &$value)
1382 $value = [
'VALUE' => $value];
1388 if (!$arDocumentFields[$key][
"Multiple"] && is_array($arFields[$key]))
1390 if (count($arFields[$key]) > 0)
1392 $a = array_values($arFields[$key]);
1393 $arFields[$key] = $a[0];
1397 $arFields[$key] =
null;
1401 if (mb_substr($key, 0, mb_strlen(
"PROPERTY_")) ==
"PROPERTY_")
1403 $realKey = mb_substr($key, mb_strlen(
"PROPERTY_"));
1404 $arFieldsPropertyValues[$realKey] = (is_array($arFields[$key])
1405 && !CBPHelper::IsAssociativeArray($arFields[$key])) ? $arFields[$key] : [$arFields[$key]];
1406 if (empty($arFieldsPropertyValues[$realKey]))
1407 $arFieldsPropertyValues[$realKey] = [
null];
1408 unset($arFields[$key]);
1412 if (count($arFieldsPropertyValues) > 0)
1414 $arFields[
'PROPERTY_VALUES'] = $arFieldsPropertyValues;
1417 $iblockElement =
new CIBlockElement();
1418 if (isset($arFields[
'PROPERTY_VALUES']) && count($arFields[
'PROPERTY_VALUES']) > 0)
1420 $iblockElement->SetPropertyValuesEx($documentId, $arResult[
'IBLOCK_ID'], $arFields[
'PROPERTY_VALUES']);
1423 unset($arFields[
'PROPERTY_VALUES']);
1424 $res = $iblockElement->Update($documentId, $arFields,
false,
true,
true);
1427 throw new Exception($iblockElement->LAST_ERROR);
1430 if (isset($arFields[
'BP_PUBLISHED']) && $arFields[
'BP_PUBLISHED'] ===
'Y')
1432 self::publishDocument($documentId);
1434 elseif (isset($arFields[
'BP_PUBLISHED']) &&$arFields[
'BP_PUBLISHED'] ===
'N')
1436 self::unpublishDocument($documentId);
1439 if (CModule::includeModule(
'lists'))
1441 CLists::rebuildSeachableContentForElement($arResult[
'IBLOCK_ID'], $documentId);
1635 $documentId = trim($documentId);
1636 if ($documentId ==
'')
1639 if (self::isAdmin())
1644 if (!array_key_exists(
"IBlockId", $parameters)
1646 !array_key_exists(
"IBlockPermission", $parameters)
1647 || !array_key_exists(
"DocumentStates", $parameters)
1648 || !array_key_exists(
"IBlockRightsMode", $parameters)
1649 || array_key_exists(
"IBlockRightsMode", $parameters) && ($parameters[
"IBlockRightsMode"] ===
"E")
1651 || !array_key_exists(
"CreatedBy", $parameters) && !array_key_exists(
"AllUserGroups", $parameters))
1653 if (empty(self::$elements[$documentId]))
1655 $elementListQuery = CIBlockElement::getList(
1657 array(
"ID" => $documentId,
"SHOW_NEW" =>
"Y",
"SHOW_HISTORY" =>
"Y"),
1660 array(
"ID",
"IBLOCK_ID",
"CREATED_BY")
1662 self::$elements[$documentId] = $elementListQuery->fetch();
1665 if (empty(self::$elements[$documentId]))
1668 $element = self::$elements[$documentId];
1670 $parameters[
"IBlockId"] = $element[
"IBLOCK_ID"];
1671 $parameters[
"CreatedBy"] = $element[
"CREATED_BY"];
1674 if (!array_key_exists(
"IBlockRightsMode", $parameters))
1675 $parameters[
"IBlockRightsMode"] = CIBlock::getArrayByID($parameters[
"IBlockId"],
"RIGHTS_MODE");
1677 if ($parameters[
"IBlockRightsMode"] ===
"E")
1680 $operation === CBPCanUserOperateOperation::ReadDocument ||
1681 $operation === CBPCanUserOperateOperation::ViewWorkflow
1683 return CIBlockElementRights::userHasRightTo($parameters[
"IBlockId"], $documentId,
"element_read");
1684 elseif ($operation === CBPCanUserOperateOperation::WriteDocument)
1685 return CIBlockElementRights::userHasRightTo($parameters[
"IBlockId"], $documentId,
"element_edit");
1686 elseif ($operation === CBPCanUserOperateOperation::StartWorkflow)
1688 if (CIBlockElementRights::userHasRightTo($parameters[
"IBlockId"], $documentId,
"element_edit"))
1691 if (!array_key_exists(
"WorkflowId", $parameters))
1694 if (!CIBlockElementRights::userHasRightTo($parameters[
"IBlockId"], $documentId,
"element_read"))
1697 $userId = intval($userId);
1698 if (!array_key_exists(
"AllUserGroups", $parameters))
1700 if (!array_key_exists(
"UserGroups", $parameters))
1701 $parameters[
"UserGroups"] = CUser::getUserGroup($userId);
1703 $parameters[
"AllUserGroups"] = $parameters[
"UserGroups"];
1704 if ($userId == $parameters[
"CreatedBy"])
1705 $parameters[
"AllUserGroups"][] =
"Author";
1708 if (!array_key_exists(
"DocumentStates", $parameters))
1710 if ($operation === CBPCanUserOperateOperation::StartWorkflow)
1711 $parameters[
"DocumentStates"] = CBPWorkflowTemplateLoader::getDocumentTypeStates(array(
'lists', get_called_class(), self::generateDocumentType($parameters[
"IBlockId"])));
1713 $parameters[
"DocumentStates"] = CBPDocument::getDocumentStates(
1714 array(
'lists', get_called_class(), self::generateDocumentType($parameters[
"IBlockId"])),
1715 array(
'lists', get_called_class(), $documentId)
1719 if (array_key_exists($parameters[
"WorkflowId"], $parameters[
"DocumentStates"]))
1720 $parameters[
"DocumentStates"] = array($parameters[
"WorkflowId"] => $parameters[
"DocumentStates"][$parameters[
"WorkflowId"]]);
1724 $allowableOperations = CBPDocument::getAllowableOperations(
1726 $parameters[
"AllUserGroups"],
1727 $parameters[
"DocumentStates"],
1731 if (!is_array($allowableOperations))
1734 if (($operation === CBPCanUserOperateOperation::ViewWorkflow) && in_array(
"read", $allowableOperations)
1735 || ($operation === CBPCanUserOperateOperation::StartWorkflow) && in_array(
"write", $allowableOperations))
1738 $chop = ($operation === CBPCanUserOperateOperation::ViewWorkflow) ?
"element_read" :
"element_edit";
1741 foreach ($allowableOperations as $op)
1743 if (isset($tasks[$op]))
1744 $op = $tasks[$op][
'ID'];
1745 $ar = CTask::getOperations($op,
true);
1746 if (in_array($chop, $ar))
1750 elseif ($operation === CBPCanUserOperateOperation::CreateWorkflow)
1752 return CBPDocument::canUserOperateDocumentType(
1753 CBPCanUserOperateOperation::CreateWorkflow,
1755 array(
'lists', get_called_class(), $parameters[
'IBlockId']),
1763 if (!array_key_exists(
"IBlockPermission", $parameters))
1765 if (CModule::includeModule(
'lists'))
1766 $parameters[
"IBlockPermission"] = CLists::getIBlockPermission($parameters[
"IBlockId"], $userId);
1768 $parameters[
"IBlockPermission"] = CIBlock::getPermission($parameters[
"IBlockId"], $userId);
1771 if ($parameters[
"IBlockPermission"] <=
"R")
1773 elseif ($parameters[
"IBlockPermission"] >=
"W")
1776 $userId = intval($userId);
1777 if (!array_key_exists(
"AllUserGroups", $parameters))
1779 if (!array_key_exists(
"UserGroups", $parameters))
1780 $parameters[
"UserGroups"] = CUser::getUserGroup($userId);
1782 $parameters[
"AllUserGroups"] = $parameters[
"UserGroups"];
1783 if ($userId == $parameters[
"CreatedBy"])
1784 $parameters[
"AllUserGroups"][] =
"Author";
1787 if (!array_key_exists(
"DocumentStates", $parameters))
1789 $parameters[
"DocumentStates"] = CBPDocument::getDocumentStates(
1790 array(
"lists", get_called_class(),
"iblock_".$parameters[
"IBlockId"]),
1791 array(
'lists', get_called_class(), $documentId)
1795 if (array_key_exists(
"WorkflowId", $parameters))
1797 if (array_key_exists($parameters[
"WorkflowId"], $parameters[
"DocumentStates"]))
1798 $parameters[
"DocumentStates"] = array($parameters[
"WorkflowId"] => $parameters[
"DocumentStates"][$parameters[
"WorkflowId"]]);
1803 $allowableOperations = CBPDocument::getAllowableOperations(
1805 $parameters[
"AllUserGroups"],
1806 $parameters[
"DocumentStates"]
1809 if (!is_array($allowableOperations))
1815 case CBPCanUserOperateOperation::ViewWorkflow:
1816 $r = in_array(
"read", $allowableOperations);
1818 case CBPCanUserOperateOperation::StartWorkflow:
1819 $r = in_array(
"write", $allowableOperations);
1821 case CBPCanUserOperateOperation::CreateWorkflow:
1824 case CBPCanUserOperateOperation::WriteDocument:
1825 $r = in_array(
"write", $allowableOperations);
1827 case CBPCanUserOperateOperation::ReadDocument:
1828 $r = in_array(
"read", $allowableOperations) || in_array(
"write", $allowableOperations);
1839 $documentType = trim($documentType);
1840 if ($documentType ==
'')
1843 if (self::isAdmin())
1848 if(is_numeric($documentType))
1849 $parameters[
"IBlockId"] = intval($documentType);
1851 $parameters[
"IBlockId"] = intval(mb_substr($documentType, mb_strlen(
"iblock_")));
1852 $parameters[
'sectionId'] = !empty($parameters[
'sectionId']) ? (int)$parameters[
'sectionId'] : 0;
1854 if (!array_key_exists(
"IBlockRightsMode", $parameters))
1855 $parameters[
"IBlockRightsMode"] = CIBlock::getArrayByID($parameters[
"IBlockId"],
"RIGHTS_MODE");
1857 if ($parameters[
"IBlockRightsMode"] ===
"E")
1859 if ($operation === CBPCanUserOperateOperation::CreateWorkflow)
1860 return CIBlockRights::userHasRightTo($parameters[
"IBlockId"], $parameters[
"IBlockId"],
"iblock_rights_edit");
1861 elseif ($operation === CBPCanUserOperateOperation::WriteDocument)
1862 return CIBlockSectionRights::userHasRightTo($parameters[
"IBlockId"], $parameters[
"sectionId"],
"section_element_bind");
1863 elseif ($operation === CBPCanUserOperateOperation::ViewWorkflow
1864 || $operation === CBPCanUserOperateOperation::StartWorkflow)
1866 if ($operation === CBPCanUserOperateOperation::ViewWorkflow)
1869 CIBlockRights::userHasRightTo($parameters[
"IBlockId"], 0,
"element_read")
1870 || CIBlockRights::userHasRightTo($parameters[
"IBlockId"], $parameters[
"IBlockId"],
"iblock_rights_edit")
1874 if ($operation === CBPCanUserOperateOperation::StartWorkflow)
1875 return CIBlockSectionRights::userHasRightTo($parameters[
"IBlockId"], $parameters[
'sectionId'],
"section_element_bind");
1878 $userId = intval($userId);
1879 if (!array_key_exists(
"AllUserGroups", $parameters))
1881 if (!array_key_exists(
"UserGroups", $parameters))
1882 $parameters[
"UserGroups"] = CUser::getUserGroup($userId);
1884 $parameters[
"AllUserGroups"] = $parameters[
"UserGroups"];
1885 $parameters[
"AllUserGroups"][] =
"Author";
1888 if (!array_key_exists(
"DocumentStates", $parameters))
1890 if ($operation === CBPCanUserOperateOperation::StartWorkflow)
1891 $parameters[
"DocumentStates"] = CBPWorkflowTemplateLoader::getDocumentTypeStates(array(
"lists", get_called_class(),
"iblock_".$parameters[
"IBlockId"]));
1893 $parameters[
"DocumentStates"] = CBPDocument::getDocumentStates(
1894 array(
"lists", get_called_class(),
"iblock_".$parameters[
"IBlockId"]),
1899 if (array_key_exists($parameters[
"WorkflowId"], $parameters[
"DocumentStates"]))
1900 $parameters[
"DocumentStates"] = array($parameters[
"WorkflowId"] => $parameters[
"DocumentStates"][$parameters[
"WorkflowId"]]);
1904 $allowableOperations = CBPDocument::getAllowableOperations(
1906 $parameters[
"AllUserGroups"],
1907 $parameters[
"DocumentStates"],
1911 if (!is_array($allowableOperations))
1914 if (($operation === CBPCanUserOperateOperation::ViewWorkflow) && in_array(
"read", $allowableOperations)
1915 || ($operation === CBPCanUserOperateOperation::StartWorkflow) && in_array(
"write", $allowableOperations))
1918 $chop = ($operation === CBPCanUserOperateOperation::ViewWorkflow) ?
"element_read" :
"section_element_bind";
1921 foreach ($allowableOperations as $op)
1923 if (isset($tasks[$op]))
1924 $op = $tasks[$op][
'ID'];
1925 $ar = CTask::getOperations($op,
true);
1926 if (in_array($chop, $ar))
1934 if (!array_key_exists(
"IBlockPermission", $parameters))
1936 if(CModule::includeModule(
'lists'))
1937 $parameters[
"IBlockPermission"] = CLists::getIBlockPermission($parameters[
"IBlockId"], $userId);
1939 $parameters[
"IBlockPermission"] = CIBlock::getPermission($parameters[
"IBlockId"], $userId);
1942 if ($parameters[
"IBlockPermission"] <=
"R")
1944 elseif ($parameters[
"IBlockPermission"] >=
"W")
1947 $userId = intval($userId);
1948 if (!array_key_exists(
"AllUserGroups", $parameters))
1950 if (!array_key_exists(
"UserGroups", $parameters))
1951 $parameters[
"UserGroups"] = CUser::getUserGroup($userId);
1953 $parameters[
"AllUserGroups"] = $parameters[
"UserGroups"];
1954 $parameters[
"AllUserGroups"][] =
"Author";
1957 if (!array_key_exists(
"DocumentStates", $parameters))
1959 $parameters[
"DocumentStates"] = CBPDocument::getDocumentStates(
1960 array(
"lists", get_called_class(),
"iblock_".$parameters[
"IBlockId"]),
1965 if (array_key_exists(
"WorkflowId", $parameters))
1967 if (array_key_exists($parameters[
"WorkflowId"], $parameters[
"DocumentStates"]))
1968 $parameters[
"DocumentStates"] = array($parameters[
"WorkflowId"] => $parameters[
"DocumentStates"][$parameters[
"WorkflowId"]]);
1973 $allowableOperations = CBPDocument::getAllowableOperations(
1975 $parameters[
"AllUserGroups"],
1976 $parameters[
"DocumentStates"]
1979 if (!is_array($allowableOperations))
1985 case CBPCanUserOperateOperation::ViewWorkflow:
1986 $r = in_array(
"read", $allowableOperations);
1988 case CBPCanUserOperateOperation::StartWorkflow:
1989 $r = in_array(
"write", $allowableOperations);
1991 case CBPCanUserOperateOperation::CreateWorkflow:
1992 $r = in_array(
"write", $allowableOperations);
1994 case CBPCanUserOperateOperation::WriteDocument:
1995 $r = in_array(
"write", $allowableOperations);
1997 case CBPCanUserOperateOperation::ReadDocument:
2028 $documentType = trim($documentType);
2029 if ($documentType ==
'')
2032 $iblockId = intval(mb_substr($documentType, mb_strlen(
"iblock_")));
2034 $result = array(
"Author" => GetMessage(
"IBD_DOCUMENT_AUTHOR"));
2036 $groupsId = array(1);
2037 $extendedGroupsCode = array();
2038 if(CIBlock::getArrayByID($iblockId,
"RIGHTS_MODE") ===
"E")
2040 $rights =
new CIBlockRights($iblockId);
2041 foreach($rights->getGroups() as $iblockGroupCode)
2042 if(preg_match(
"/^G(\\d+)\$/", $iblockGroupCode, $match))
2043 $groupsId[] = $match[1];
2045 $extendedGroupsCode[] = $iblockGroupCode;
2049 foreach(CIBlock::getGroupPermissions($iblockId) as $groupId => $perm)
2052 $groupsId[] = $groupId;
2056 $groupsIterator = CGroup::getListEx(array(
"NAME" =>
"ASC"), array(
"ID" => $groupsId));
2057 while ($group = $groupsIterator->fetch())
2058 $result[$group[
"ID"]] = $group[
"NAME"];
2060 if ($withExtended && $extendedGroupsCode)
2062 foreach ($extendedGroupsCode as $groupCode)
2064 $result[
'group_'.$groupCode] = CBPHelper::getExtendedGroupName($groupCode);
2077 public static function GetFieldInputControl($documentType, $fieldType, $fieldName, $fieldValue, $allowSelection =
false, $publicMode =
false)
2079 $iblockId = intval(mb_substr($documentType, mb_strlen(
"iblock_")));
2081 throw new CBPArgumentOutOfRangeException(
"documentType", $documentType);
2083 static $documentFieldTypes = array();
2084 if (!array_key_exists($documentType, $documentFieldTypes))
2085 $documentFieldTypes[$documentType] = self::getDocumentFieldTypes($documentType);
2087 $fieldType[
"BaseType"] =
"string";
2088 $fieldType[
"Complex"] =
false;
2089 if (array_key_exists($fieldType[
"Type"], $documentFieldTypes[$documentType]))
2091 $fieldType[
"BaseType"] = $documentFieldTypes[$documentType][$fieldType[
"Type"]][
"BaseType"];
2092 $fieldType[
"Complex"] = $documentFieldTypes[$documentType][$fieldType[
"Type"]][
"Complex"];
2095 if (!is_array($fieldValue) || is_array($fieldValue) && CBPHelper::isAssociativeArray($fieldValue))
2096 $fieldValue = array($fieldValue);
2098 $customMethodName =
"";
2099 $customMethodNameMulty =
"";
2100 if (mb_strpos($fieldType[
"Type"],
":") !==
false)
2102 $ar = CIBlockProperty::getUserType(mb_substr($fieldType[
"Type"], 2));
2103 if (array_key_exists(
"GetPublicEditHTML", $ar))
2104 $customMethodName = $ar[
"GetPublicEditHTML"];
2105 if (array_key_exists(
"GetPublicEditHTMLMulty", $ar))
2106 $customMethodNameMulty = $ar[
"GetPublicEditHTMLMulty"];
2111 if ($fieldType[
"Type"] ==
"select")
2113 $fieldValueTmp = $fieldValue;
2115 <select
id=
"id_<?= htmlspecialcharsbx($fieldName["Field
"]) ?>" name=
"<?= htmlspecialcharsbx($fieldName["Field
"]).($fieldType["Multiple
"] ? "[]
" : "") ?>"<?= ($fieldType[
"Multiple"] ?
' size="5" multiple' :
'') ?>>
2117 if (!$fieldType[
"Required"])
2118 echo
'<option value="">['.GetMessage(
"BPCGHLP_NOT_SET").
']</option>';
2119 foreach ($fieldType[
"Options"] as $k => $v)
2121 if (is_array($v) && count($v) == 2)
2123 $v1 = array_values($v);
2128 $ind = array_search($k, $fieldValueTmp);
2129 echo
'<option value="'.htmlspecialcharsbx($k).
'"'.($ind !==
false ?
' selected' :
'').
'>'.htmlspecialcharsbx($v).
'</option>';
2131 unset($fieldValueTmp[$ind]);
2136 if ($allowSelection)
2139 <br /><input type=
"text" id=
"id_<?= htmlspecialcharsbx($fieldName["Field
"]) ?>_text" name=
"<?= htmlspecialcharsbx($fieldName["Field
"]) ?>_text" value=
"<?
2140 if (count($fieldValueTmp) > 0)
2142 $a = array_values($fieldValueTmp);
2143 echo htmlspecialcharsbx($a[0]);
2146 <input type=
"button" value=
"..." onclick=
"BPAShowSelector('id_<?= htmlspecialcharsbx($fieldName["Field
"]) ?>_text', 'select');">
2150 elseif ($fieldType[
"Type"] ==
"user")
2152 $fieldValue = CBPHelper::usersArrayToString($fieldValue,
null, array(
"lists", get_called_class(), $documentType));
2153 ?><input type=
"text" size=
"40" id=
"id_<?= htmlspecialcharsbx($fieldName["Field
"]) ?>" name=
"<?= htmlspecialcharsbx($fieldName["Field
"]) ?>" value=
"<?= htmlspecialcharsbx($fieldValue) ?>"><input type=
"button" value=
"..." onclick=
"BPAShowSelector('id_<?= htmlspecialcharsbx($fieldName["Field
"]) ?>', 'user');"><?
2155 elseif ((mb_strpos($fieldType[
"Type"],
":") !==
false)
2156 && $fieldType[
"Multiple"]
2158 is_array($customMethodNameMulty) && count($customMethodNameMulty) > 0
2159 || !is_array($customMethodNameMulty) && $customMethodNameMulty <>
''
2163 if (!is_array($fieldValue))
2164 $fieldValue = array();
2166 if ($allowSelection)
2168 $fieldValueTmp1 = array();
2169 $fieldValueTmp2 = array();
2170 foreach ($fieldValue as $v)
2173 if (\CBPDocument::IsExpression($vTrim))
2174 $fieldValueTmp1[] = $vTrim;
2176 $fieldValueTmp2[] = $v;
2181 $fieldValueTmp1 = array();
2182 $fieldValueTmp2 = $fieldValue;
2185 if (($fieldType[
"Type"] ==
"S:employee") && COption::getOptionString(
"bizproc",
"employee_compatible_mode",
"N") !=
"Y")
2186 $fieldValueTmp2 = CBPHelper::stripUserPrefix($fieldValueTmp2);
2188 foreach ($fieldValueTmp2 as &$fld)
2189 if (!isset($fld[
'VALUE']))
2190 $fld = array(
"VALUE" => $fld);
2192 if ($fieldType[
"Type"] ==
"E:EList")
2197 if (!empty($_SERVER[
'HTTP_BX_AJAX']))
2198 $GLOBALS[
"APPLICATION"]->showAjaxHead();
2199 $GLOBALS[
"APPLICATION"]->addHeadScript(
'/bitrix/js/iblock/iblock_edit.js');
2203 echo call_user_func_array(
2204 $customMethodNameMulty,
2206 array(
"LINK_IBLOCK_ID" => $fieldType[
"Options"]),
2209 "FORM_NAME" => $fieldName[
"Form"],
2210 "VALUE" => htmlspecialcharsbx($fieldName[
"Field"])
2216 if ($allowSelection)
2219 <br /><input type=
"text" id=
"id_<?= htmlspecialcharsbx($fieldName["Field
"]) ?>_text" name=
"<?= htmlspecialcharsbx($fieldName["Field
"]) ?>_text" value=
"<?
2220 if (count($fieldValueTmp1) > 0)
2222 $a = array_values($fieldValueTmp1);
2223 echo htmlspecialcharsbx($a[0]);
2226 <input type=
"button" value=
"..." onclick=
"BPAShowSelector('id_<?= htmlspecialcharsbx($fieldName["Field
"]) ?>_text', 'user', '<?= $fieldType["Type"] == 'S:employee'? 'employee' : '' ?>');">
2232 if (!array_key_exists(
"CBPVirtualDocumentCloneRowPrinted", $GLOBALS) && $fieldType[
"Multiple"])
2234 $GLOBALS[
"CBPVirtualDocumentCloneRowPrinted"] = 1;
2236 <script language=
"JavaScript">
2237 function CBPVirtualDocumentCloneRow(tableID)
2239 var tbl = document.getElementById(tableID);
2240 var cnt = tbl.rows.length;
2241 var oRow = tbl.insertRow(cnt);
2242 var oCell = oRow.insertCell(0);
2243 var sHTML = tbl.rows[cnt - 1].cells[0].innerHTML;
2247 var s = sHTML.indexOf(
'[n', p);
2250 var e = sHTML.indexOf(
']', s);
2253 var n = parseInt(sHTML.substr(s + 2, e - s));
2254 sHTML = sHTML.substr(0, s) +
'[n' + (++n) +
']' + sHTML.substr(e + 1);
2260 var s = sHTML.indexOf(
'__n', p);
2263 var e = sHTML.indexOf(
'_', s + 2);
2266 var n = parseInt(sHTML.substr(s + 3, e - s));
2267 sHTML = sHTML.substr(0, s) +
'__n' + (++n) +
'_' + sHTML.substr(e + 1);
2270 oCell.innerHTML = sHTML;
2271 var patt =
new RegExp(
'<' +
'script' +
'>[^\000]*?<' +
'\/' +
'script' +
'>',
'ig');
2272 var code = sHTML.match(patt);
2275 for (var i = 0; i < code.length; i++)
2279 var s = code[i].substring(8, code[i].length - 9);
2280 jsUtils.EvalGlobal(s);
2285 function createAdditionalHtmlEditor(tableId)
2287 var tbl = document.getElementById(tableId);
2288 var cnt = tbl.rows.length-1;
2289 var name = tableId.replace(/(?:CBPVirtualDocument_)(.*)(?:_Table)/,
'$1')
2290 var idEditor =
'id_'+name+
'__n'+cnt+
'_';
2291 var inputNameEditor = name+
'[n'+cnt+
']';
2292 window.BXHtmlEditor.Show(
2295 'inputName':inputNameEditor,
2297 'useFileDialogs':
false,
2301 'limitPhpAccess':
false,
2304 'templateParams':[],
2305 'componentFilter':
'',
2307 'placeholder':
'Text here...',
2308 'actionUrl':
'/bitrix/tools/html_editor_action.php',
2309 'cssIframePath':
'/bitrix/js/fileman/html_editor/iframe-style.css?1412693817',
2312 'spellcheck_path':
'/bitrix/js/fileman/html_editor/html-spell.js?v=1412693817',
2314 'useCustomSpell':
'Y',
2316 'askBeforeUnloadPage':
true,
2317 'settingsKey':
'user_settings_1',
2318 'showComponents':
true,
2319 'showSnippets':
true,
2321 'splitVertical':
false,
2323 'taskbarShown':
false,
2324 'taskbarWidth':
'250',
2325 'lastSpecialchars':
false,
2326 'cleanEmptySpans':
true,
2328 'showTaskbars':
false,
2329 'showNodeNavi':
false,
2331 {
'id':
'Bold',
'compact':
true,
'sort':
'80'},
2332 {
'id':
'Italic',
'compact':
true,
'sort':
'90'},
2333 {
'id':
'Underline',
'compact':
true,
'sort':
'100'},
2334 {
'id':
'Strikeout',
'compact':
true,
'sort':
'110'},
2335 {
'id':
'RemoveFormat',
'compact':
true,
'sort':
'120'},
2336 {
'id':
'Color',
'compact':
true,
'sort':
'130'},
2337 {
'id':
'FontSelector',
'compact':
false,
'sort':
'135'},
2338 {
'id':
'FontSize',
'compact':
false,
'sort':
'140'},
2339 {
'separator':
true,
'compact':
false,
'sort':
'145'},
2340 {
'id':
'OrderedList',
'compact':
true,
'sort':
'150'},
2341 {
'id':
'UnorderedList',
'compact':
true,
'sort':
'160'},
2342 {
'id':
'AlignList',
'compact':
false,
'sort':
'190'},
2343 {
'separator':
true,
'compact':
false,
'sort':
'200'},
2344 {
'id':
'InsertLink',
'compact':
true,
'sort':
'210'},
2345 {
'id':
'InsertImage',
'compact':
false,
'sort':
'220'},
2346 {
'id':
'InsertVideo',
'compact':
true,
'sort':
'230'},
2347 {
'id':
'InsertTable',
'compact':
false,
'sort':
'250'},
2348 {
'id':
'Smile',
'compact':
false,
'sort':
'280'},
2349 {
'separator':
true,
'compact':
false,
'sort':
'290'},
2350 {
'id':
'Fullscreen',
'compact':
false,
'sort':
'310'},
2351 {
'id':
'More',
'compact':
true,
'sort':
'400'}],
2353 'autoResizeOffset':
'40',
2354 'minBodyWidth':
'350',
2355 'normalBodyWidth':
'555'
2357 var htmlEditor =
BX.findChildrenByClassName(
BX(tableId),
'bx-html-editor');
2358 for(var k in htmlEditor)
2360 var editorId = htmlEditor[k].getAttribute(
'id');
2361 var frameArray =
BX.findChildrenByClassName(
BX(editorId),
'bx-editor-iframe');
2362 if(frameArray.length > 1)
2364 for(var i = 0; i < frameArray.length - 1; i++)
2366 frameArray[i].parentNode.removeChild(frameArray[i]);
2376 if ($fieldType[
"Multiple"])
2377 echo
'<table width="100%" border="0" cellpadding="2" cellspacing="2" id="CBPVirtualDocument_'.htmlspecialcharsbx($fieldName[
"Field"]).
'_Table">';
2379 $fieldValueTmp = $fieldValue;
2381 if (
sizeof($fieldValue) == 0)
2382 $fieldValue[] =
null;
2385 foreach ($fieldValue as $key => $value)
2388 $fieldNameId =
'id_'.htmlspecialcharsbx($fieldName[
"Field"]).
'__n'.$ind.
'_';
2389 $fieldNameName = htmlspecialcharsbx($fieldName[
"Field"]).($fieldType[
"Multiple"] ?
"[n".$ind.
"]" :
"");
2391 if ($fieldType[
"Multiple"])
2394 if (is_array($customMethodName) && count($customMethodName) > 0 || !is_array($customMethodName) && $customMethodName <>
'')
2396 if($fieldType[
"Type"] ==
"S:HTML")
2398 if (Loader::includeModule(
"fileman"))
2400 $editor =
new CHTMLEditor;
2403 'useFileDialogs' =>
false,
2405 'useFileDialogs' =>
false,
2406 'minBodyWidth' => 350,
2407 'normalBodyWidth' => 555,
2408 'bAllowPhp' =>
false,
2409 'limitPhpAccess' =>
false,
2410 'showTaskbars' =>
false,
2411 'showNodeNavi' =>
false,
2412 'askBeforeUnloadPage' =>
true,
2414 'siteId' => SITE_ID,
2415 'autoResize' =>
true,
2416 'autoResizeOffset' => 40,
2417 'saveOnBlur' =>
true,
2418 'actionUrl' =>
'/bitrix/tools/html_editor_action.php',
2419 'controlsMap' => array(
2420 array(
'id' =>
'Bold',
'compact' =>
true,
'sort' => 80),
2421 array(
'id' =>
'Italic',
'compact' =>
true,
'sort' => 90),
2422 array(
'id' =>
'Underline',
'compact' =>
true,
'sort' => 100),
2423 array(
'id' =>
'Strikeout',
'compact' =>
true,
'sort' => 110),
2424 array(
'id' =>
'RemoveFormat',
'compact' =>
true,
'sort' => 120),
2425 array(
'id' =>
'Color',
'compact' =>
true,
'sort' => 130),
2426 array(
'id' =>
'FontSelector',
'compact' =>
false,
'sort' => 135),
2427 array(
'id' =>
'FontSize',
'compact' =>
false,
'sort' => 140),
2428 array(
'separator' =>
true,
'compact' =>
false,
'sort' => 145),
2429 array(
'id' =>
'OrderedList',
'compact' =>
true,
'sort' => 150),
2430 array(
'id' =>
'UnorderedList',
'compact' =>
true,
'sort' => 160),
2431 array(
'id' =>
'AlignList',
'compact' =>
false,
'sort' => 190),
2432 array(
'separator' =>
true,
'compact' =>
false,
'sort' => 200),
2433 array(
'id' =>
'InsertLink',
'compact' =>
true,
'sort' => 210,
'wrap' =>
'bx-b-link-'.$fieldNameId),
2434 array(
'id' =>
'InsertImage',
'compact' =>
false,
'sort' => 220),
2435 array(
'id' =>
'InsertVideo',
'compact' =>
true,
'sort' => 230,
'wrap' =>
'bx-b-video-'.$fieldNameId),
2436 array(
'id' =>
'InsertTable',
'compact' =>
false,
'sort' => 250),
2437 array(
'id' =>
'Code',
'compact' =>
true,
'sort' => 260),
2438 array(
'id' =>
'Quote',
'compact' =>
true,
'sort' => 270,
'wrap' =>
'bx-b-quote-'.$fieldNameId),
2439 array(
'id' =>
'Smile',
'compact' =>
false,
'sort' => 280),
2440 array(
'separator' =>
true,
'compact' =>
false,
'sort' => 290),
2441 array(
'id' =>
'Fullscreen',
'compact' =>
false,
'sort' => 310),
2442 array(
'id' =>
'BbCode',
'compact' =>
true,
'sort' => 340),
2443 array(
'id' =>
'More',
'compact' =>
true,
'sort' => 400)
2447 'name' => $fieldNameName,
2448 'inputName' => $fieldNameName,
2449 'id' => $fieldNameId,
2451 'content' => htmlspecialcharsBack($value),
2454 $editor->show($res);
2458 ?><textarea rows=
"5" cols=
"40" id=
"<?= $fieldNameId ?>" name=
"<?= $fieldNameName ?>"><?= htmlspecialcharsbx($value) ?></textarea><?
2464 if ($allowSelection && \CBPDocument::IsExpression(trim($value1)))
2467 unset($fieldValueTmp[$key]);
2469 if (($fieldType[
"Type"] ==
"S:employee") && COption::getOptionString(
"bizproc",
"employee_compatible_mode",
"N") !=
"Y")
2470 $value1 = CBPHelper::stripUserPrefix($value1);
2472 echo call_user_func_array(
2475 array(
"LINK_IBLOCK_ID" => $fieldType[
"Options"]),
2476 array(
"VALUE" => $value1),
2478 "FORM_NAME" => $fieldName[
"Form"],
2479 "VALUE" => $fieldNameName
2488 switch ($fieldType[
"Type"])
2492 unset($fieldValueTmp[$key]);
2493 ?><input type=
"text" size=
"10" id=
"<?= $fieldNameId ?>" name=
"<?= $fieldNameName ?>" value=
"<?= htmlspecialcharsbx($value) ?>"><?
2499 ?><input type=
"file" id=
"<?= $fieldNameId ?>" name=
"<?= $fieldNameName ?>"><?
2503 if (in_array($value, array(
"Y",
"N")))
2504 unset($fieldValueTmp[$key]);
2506 <select
id=
"<?= $fieldNameId ?>" name=
"<?= $fieldNameName ?>">
2508 if (!$fieldType[
"Required"])
2509 echo
'<option value="">['.GetMessage(
"BPCGHLP_NOT_SET").
']</option>';
2511 <option value=
"Y"<?= (in_array(
"Y", $fieldValue) ?
' selected' :
'') ?>><?= GetMessage(
"BPCGHLP_YES") ?></option>
2512 <option value=
"N"<?= (in_array(
"N", $fieldValue) ?
' selected' :
'') ?>><?= GetMessage(
"BPCGHLP_NO") ?></option>
2517 unset($fieldValueTmp[$key]);
2518 ?><textarea rows=
"5" cols=
"40" id=
"<?= $fieldNameId ?>" name=
"<?= $fieldNameName ?>"><?= htmlspecialcharsbx($value) ?></textarea><?
2522 if (defined(
"ADMIN_SECTION") && ADMIN_SECTION)
2525 if (!\CBPDocument::IsExpression(trim($value)))
2528 unset($fieldValueTmp[$key]);
2530 require_once($_SERVER[
"DOCUMENT_ROOT"].BX_ROOT.
"/modules/main/interface/init_admin.php");
2531 echo CAdminCalendar::calendarDate($fieldNameName, $v, 19, ($fieldType[
"Type"] !=
"date"));
2536 if ($allowSelection && \CBPDocument::IsExpression(trim($value1)))
2539 unset($fieldValueTmp[$key]);
2541 if($fieldType[
"Type"] ==
"date")
2545 $ar = CIBlockProperty::getUserType($type);
2546 echo call_user_func_array(
2547 $ar[
"GetPublicEditHTML"],
2549 array(
"LINK_IBLOCK_ID" => $fieldType[
"Options"]),
2550 array(
"VALUE" => $value1),
2552 "FORM_NAME" => $fieldName[
"Form"],
2553 "VALUE" => $fieldNameName
2562 unset($fieldValueTmp[$key]);
2563 ?><input type=
"text" size=
"40" id=
"<?= $fieldNameId ?>" name=
"<?= $fieldNameName ?>" value=
"<?= htmlspecialcharsbx($value) ?>"><?
2567 if ($allowSelection)
2569 if (!in_array($fieldType[
"Type"], array(
"file",
"bool",
"date",
"datetime")) && (is_array($customMethodName) && count($customMethodName) <= 0 || !is_array($customMethodName) && $customMethodName ==
''))
2571 ?><input type=
"button" value=
"..." onclick=
"BPAShowSelector('<?= $fieldNameId ?>', '<?= htmlspecialcharsbx($fieldType["BaseType
"]) ?>');"><?
2575 if ($fieldType[
"Multiple"])
2579 if ($fieldType[
"Multiple"])
2582 if ($fieldType[
"Multiple"] && $fieldType[
"Type"] !=
"S:HTML" && (($fieldType[
"Type"] !=
"file") || $publicMode))
2584 echo
'<input type="button" value="'.GetMessage(
"BPCGHLP_ADD").
'" onclick="CBPVirtualDocumentCloneRow(\'CBPVirtualDocument_'.$fieldName[
"Field"].
'_Table\')"/><br />';
2586 elseif($fieldType[
"Multiple"] && $fieldType[
"Type"] ==
"S:HTML")
2588 $functionOnclick =
'CBPVirtualDocumentCloneRow(\'CBPVirtualDocument_'.$fieldName[
"Field"].
'_Table\');createAdditionalHtmlEditor(\'CBPVirtualDocument_'.$fieldName[
"Field"].
'_Table\');';
2589 echo
'<input type="button" value="'.GetMessage(
"BPCGHLP_ADD").
'" onclick="'.$functionOnclick.
'"/><br />';
2592 if ($allowSelection)
2594 if (in_array($fieldType[
"Type"], array(
"file",
"bool",
"date",
"datetime")) || (is_array($customMethodName) && count($customMethodName) > 0 || !is_array($customMethodName) && $customMethodName <>
''))
2597 <input type=
"text" id=
"id_<?= htmlspecialcharsbx($fieldName["Field
"]) ?>_text" name=
"<?= htmlspecialcharsbx($fieldName["Field
"]) ?>_text" value=
"<?
2598 if (count($fieldValueTmp) > 0)
2600 $a = array_values($fieldValueTmp);
2601 echo htmlspecialcharsbx($a[0]);
2604 <input type=
"button" value=
"..." onclick=
"BPAShowSelector('id_<?= htmlspecialcharsbx($fieldName["Field
"]) ?>_text', '<?= htmlspecialcharsbx($fieldType["BaseType
"]) ?>', '<?= $fieldType["Type"] == 'S:employee'? 'employee' : '' ?>');">
2610 $s = ob_get_contents();
2618 $iblockId = intval(mb_substr($documentType, mb_strlen(
"iblock_")));
2620 throw new CBPArgumentOutOfRangeException(
"documentType", $documentType);
2624 if ($fieldType[
"Type"] ==
"user")
2626 $value = $request[$fieldName[
"Field"]];
2629 $result = CBPHelper::usersStringToArray($value, array(
"lists", get_called_class(), $documentType), $errors);
2630 if (count($errors) > 0)
2632 foreach ($errors as $e)
2639 elseif (array_key_exists($fieldName[
"Field"], $request) || array_key_exists($fieldName[
"Field"].
"_text", $request))
2641 $valueArray = array();
2642 if (array_key_exists($fieldName[
"Field"], $request))
2644 $valueArray = $request[$fieldName[
"Field"]];
2645 if (!is_array($valueArray) || is_array($valueArray) && CBPHelper::isAssociativeArray($valueArray))
2646 $valueArray = array($valueArray);
2648 if (array_key_exists($fieldName[
"Field"].
"_text", $request))
2649 $valueArray[] = $request[$fieldName[
"Field"].
"_text"];
2651 foreach ($valueArray as $value)
2653 if (is_array($value) || !is_array($value) && !\CBPDocument::IsExpression(trim($value)))
2655 if ($fieldType[
"Type"] ==
"int")
2659 $value = str_replace(
" ",
"", str_replace(
",",
".", $value));
2660 if (is_numeric($value))
2662 $value = doubleval($value);
2668 "code" =>
"ErrorValue",
2669 "message" => GetMessage(
"LISTS_BIZPROC_INVALID_INT"),
2670 "parameter" => $fieldName[
"Field"],
2679 elseif ($fieldType[
"Type"] ==
"double")
2683 $value = str_replace(
" ",
"", str_replace(
",",
".", $value));
2684 if (is_numeric($value))
2686 $value = doubleval($value);
2692 "code" =>
"ErrorValue",
2693 "message" => GetMessage(
"LISTS_BIZPROC_INVALID_INT"),
2694 "parameter" => $fieldName[
"Field"],
2703 elseif ($fieldType[
"Type"] ==
"select")
2705 if (!is_array($fieldType[
"Options"]) || count($fieldType[
"Options"]) <= 0 || $value ==
'')
2711 $ar = array_values($fieldType[
"Options"]);
2712 if (is_array($ar[0]))
2717 if ($a[0] == $value)
2727 "code" =>
"ErrorValue",
2728 "message" => GetMessage(
"LISTS_BIZPROC_INVALID_SELECT"),
2729 "parameter" => $fieldName[
"Field"],
2735 if (!array_key_exists($value, $fieldType[
"Options"]))
2739 "code" =>
"ErrorValue",
2740 "message" => GetMessage(
"LISTS_BIZPROC_INVALID_SELECT"),
2741 "parameter" => $fieldName[
"Field"],
2747 elseif ($fieldType[
"Type"] ==
"bool")
2749 if ($value !==
"Y" && $value !==
"N")
2751 if ($value ===
true)
2755 elseif ($value ===
false)
2759 elseif ($value <>
'')
2761 $value = mb_strtolower($value);
2762 if (in_array($value, array(
"y",
"yes",
"true",
"1")))
2766 elseif (in_array($value, array(
"n",
"no",
"false",
"0")))
2774 "code" =>
"ErrorValue",
2775 "message" => GetMessage(
"BPCGWTL_INVALID45"),
2776 "parameter" => $fieldName[
"Field"],
2786 elseif ($fieldType[
"Type"] ==
"file")
2788 if (is_array($value) && array_key_exists(
"name", $value) && $value[
"name"] <>
'')
2790 if (!array_key_exists(
"MODULE_ID", $value) || $value[
"MODULE_ID"] ==
'')
2791 $value[
"MODULE_ID"] =
"bizproc";
2793 $value = CFile::saveFile($value,
"bizproc_wf",
true,
true);
2798 "code" =>
"ErrorValue",
2799 "message" => GetMessage(
"BPCGWTL_INVALID915"),
2800 "parameter" => $fieldName[
"Field"],
2809 elseif ($fieldType[
"Type"] ==
"date")
2813 if(!CheckDateTime($value, FORMAT_DATE))
2817 "code" =>
"ErrorValue",
2818 "message" => GetMessage(
"LISTS_BIZPROC_INVALID_DATE"),
2819 "parameter" => $fieldName[
"Field"],
2829 elseif ($fieldType[
"Type"] ==
"datetime")
2833 $valueTemporary = array();
2834 $valueTemporary[
"VALUE"] = $value;
2835 $result = CIBlockPropertyDateTime::checkFields(
'', $valueTemporary);
2836 if (!empty($result))
2839 foreach ($result as $error)
2844 "code" =>
"ErrorValue",
2845 "message" => $message,
2846 "parameter" => $fieldName[
"Field"],
2855 elseif (mb_strpos($fieldType[
"Type"],
":") !==
false && $fieldType[
"Type"] !=
"S:HTML")
2857 $customType = CIBlockProperty::getUserType(mb_substr($fieldType[
"Type"], 2));
2858 if (array_key_exists(
"GetLength", $customType))
2860 if (call_user_func_array(
2861 $customType[
"GetLength"],
2863 array(
"LINK_IBLOCK_ID" => $fieldType[
"Options"]),
2864 array(
"VALUE" => $value)
2872 if (($value !=
null) && array_key_exists(
"CheckFields", $customType))
2874 $errorsTemporary = call_user_func_array(
2875 $customType[
"CheckFields"],
2877 array(
"LINK_IBLOCK_ID" => $fieldType[
"Options"]),
2878 array(
"VALUE" => $value)
2881 if (count($errorsTemporary) > 0)
2884 foreach ($errorsTemporary as $e)
2886 "code" =>
"ErrorValue",
2888 "parameter" => $fieldName[
"Field"],
2892 elseif (!array_key_exists(
"GetLength", $customType) && $value ===
'')
2897 $fieldType[
"Type"] ==
"S:employee" &&
2898 COption::getOptionString(
"bizproc",
"employee_compatible_mode",
"N") !=
"Y"
2901 $value =
"user_".$value;
2906 if (!is_array($value) && $value ==
'')
2911 if ($value !==
null)
2916 if (!$fieldType[
"Multiple"])
2918 if (is_array($result) && count($result) > 0)
2919 $result = $result[0];
2929 $result = $fieldValue;
2931 switch ($fieldType[
'Type'])
2934 if (!is_array($fieldValue))
2935 $fieldValue = array($fieldValue);
2937 $result = CBPHelper::usersArrayToString($fieldValue,
null, array(
"lists", get_called_class(), $documentType));
2941 if (is_array($fieldValue))
2944 foreach ($fieldValue as $r)
2945 $result[] = ((mb_strtoupper($r) !=
"N" && !empty($r)) ? GetMessage(
"BPVDX_YES") : GetMessage(
"BPVDX_NO"));
2949 $result = ((mb_strtoupper($fieldValue) !=
"N" && !empty($fieldValue)) ? GetMessage(
"BPVDX_YES") : GetMessage(
"BPVDX_NO"));
2954 if (is_array($fieldValue))
2957 foreach ($fieldValue as $r)
2960 $imgQuery = CFile::getByID($r);
2961 if ($img = $imgQuery->fetch())
2962 $result[] =
"[url=/bitrix/tools/bizproc_show_file.php?f=".urlencode($img[
"FILE_NAME"]).
"&i=".$r.
"&h=".md5($img[
"SUBDIR"]).
"]".htmlspecialcharsbx($img[
"ORIGINAL_NAME"]).
"[/url]";
2967 $fieldValue = intval($fieldValue);
2968 $imgQuery = CFile::getByID($fieldValue);
2969 if ($img = $imgQuery->fetch())
2970 $result =
"[url=/bitrix/tools/bizproc_show_file.php?f=".urlencode($img[
"FILE_NAME"]).
"&i=".$fieldValue.
"&h=".md5($img[
"SUBDIR"]).
"]".htmlspecialcharsbx($img[
"ORIGINAL_NAME"]).
"[/url]";
2975 if (is_array($fieldType[
"Options"]))
2977 if (is_array($fieldValue))
2980 foreach ($fieldValue as $r)
2982 if (array_key_exists($r, $fieldType[
"Options"]))
2983 $result[] = $fieldType[
"Options"][$r];
2988 if (array_key_exists($fieldValue, $fieldType[
"Options"]))
2989 $result = $fieldType[
"Options"][$fieldValue];
2995 if (mb_strpos($fieldType[
'Type'],
":") !==
false)
2997 if ($fieldType[
"Type"] ==
"S:employee")
2998 $fieldValue = CBPHelper::stripUserPrefix($fieldValue);
3000 $customType = CIBlockProperty::getUserType(mb_substr($fieldType[
'Type'], 2));
3001 if (array_key_exists(
"GetPublicViewHTML", $customType))
3003 if (is_array($fieldValue) && !CBPHelper::isAssociativeArray($fieldValue))
3006 foreach ($fieldValue as $value)
3008 $r = call_user_func_array(
3009 $customType[
"GetPublicViewHTML"],
3011 array(
"LINK_IBLOCK_ID" => $fieldType[
"Options"]),
3012 array(
"VALUE" => $value),
3017 $result[] = HTMLToTxt($r);
3022 $result = call_user_func_array(
3023 $customType[
"GetPublicViewHTML"],
3025 array(
"LINK_IBLOCK_ID" => $fieldType[
"Options"]),
3026 array(
"VALUE" => $fieldValue),
3031 $result = HTMLToTxt($result);
3082 $ID = intval($documentId);
3084 $elementQuery = CIBlockElement::getList(array(), array(
"ID"=>$ID,
"SHOW_HISTORY"=>
"Y"),
false,
false,
3099 "PREVIEW_TEXT_TYPE",
3104 "WF_PARENT_ELEMENT_ID",
3114 if($element = $elementQuery->fetch())
3116 $parentId = intval($element[
"WF_PARENT_ELEMENT_ID"]);
3119 $elementObject =
new CIBlockElement;
3120 $element[
"WF_PARENT_ELEMENT_ID"] =
false;
3122 if($element[
"PREVIEW_PICTURE"])
3123 $element[
"PREVIEW_PICTURE"] = CFile::makeFileArray($element[
"PREVIEW_PICTURE"]);
3125 $element[
"PREVIEW_PICTURE"] = array(
"tmp_name" =>
"",
"del" =>
"Y");
3127 if($element[
"DETAIL_PICTURE"])
3128 $element[
"DETAIL_PICTURE"] = CFile::makeFileArray($element[
"DETAIL_PICTURE"]);
3130 $element[
"DETAIL_PICTURE"] = array(
"tmp_name" =>
"",
"del" =>
"Y");
3132 $element[
"IBLOCK_SECTION"] = array();
3133 if($element[
"IN_SECTIONS"] ==
"Y")
3135 $sectionsQuery = CIBlockElement::getElementGroups($element[
"ID"],
true, array(
'ID',
'IBLOCK_ELEMENT_ID'));
3136 while($section = $sectionsQuery->fetch())
3137 $element[
"IBLOCK_SECTION"][] = $section[
"ID"];
3140 $element[
"PROPERTY_VALUES"] = array();
3141 $props = &$element[
"PROPERTY_VALUES"];
3144 $propsQuery = CIBlockElement::getProperty($element[
"IBLOCK_ID"], $parentId, array(
"value_id" =>
"asc"), array(
"PROPERTY_TYPE" =>
"F",
"EMPTY" =>
"N"));
3145 while($prop = $propsQuery->fetch())
3147 if(!array_key_exists($prop[
"ID"], $props))
3148 $props[$prop[
"ID"]] = array();
3149 $props[$prop[
"ID"]][$prop[
"PROPERTY_VALUE_ID"]] = array(
3150 "VALUE" => array(
"tmp_name" =>
"",
"del" =>
"Y"),
3151 "DESCRIPTION" =>
false,
3156 $propsQuery = CIBlockElement::getProperty($element[
"IBLOCK_ID"], $element[
"ID"], array(
"value_id" =>
"asc"));
3158 while($prop = $propsQuery->fetch())
3161 if(!array_key_exists($prop[
"ID"], $props))
3162 $props[$prop[
"ID"]] = array();
3164 if($prop[
"PROPERTY_VALUE_ID"])
3166 if($prop[
"PROPERTY_TYPE"] ==
"F")
3167 $props[$prop[
"ID"]][
"n".$i] = array(
3168 "VALUE" => CFile::makeFileArray($prop[
"VALUE"]),
3169 "DESCRIPTION" => $prop[
"DESCRIPTION"],
3172 $props[$prop[
"ID"]][
"n".$i] = array(
3173 "VALUE" => $prop[
"VALUE"],
3174 "DESCRIPTION" => $prop[
"DESCRIPTION"],
3179 $elementObject->update($parentId, $element);
3180 CBPDocument::mergeDocuments(
3181 array(
"lists", get_called_class(), $parentId),
3182 array(
"lists", get_called_class(), $documentId)
3184 CIBlockElement::delete($ID);
3185 CIBlockElement::wF_CleanUpHistoryCopies($parentId, 0);
3186 $strSql =
"update b_iblock_element set WF_STATUS_ID='1', WF_NEW=NULL WHERE ID=".$parentId.
" AND WF_PARENT_ELEMENT_ID IS NULL";
3187 $DB->Query($strSql,
false,
"FILE: ".__FILE__.
"<br>LINE: ".__LINE__);
3188 CIBlockElement::updateSearch($parentId);
3193 CIBlockElement::wF_CleanUpHistoryCopies($ID, 0);
3194 $strSql =
"update b_iblock_element set WF_STATUS_ID='1', WF_NEW=NULL WHERE ID=".$ID.
" AND WF_PARENT_ELEMENT_ID IS NULL";
3195 $DB->Query($strSql,
false,
"FILE: ".__FILE__.
"<br>LINE: ".__LINE__);
3196 CIBlockElement::updateSearch($ID);
3212 $documentId = intval($documentId);
3213 if ($documentId <= 0)
3214 throw new CBPArgumentNullException(
"documentId");
3218 $dbDocumentList = CIBlockElement::getList(
3220 array(
"ID" => $documentId,
"SHOW_NEW"=>
"Y",
"SHOW_HISTORY" =>
"Y")
3222 if ($objDocument = $dbDocumentList->getNextElement())
3224 $fields = $objDocument->getFields();
3225 $properties = $objDocument->getProperties();
3227 $result[
"NAME"] = $fields[
"~NAME"];
3229 $result[
"FIELDS"] = array();
3230 foreach ($fields as $fieldKey => $fieldValue)
3232 if ($fieldKey ==
"~PREVIEW_PICTURE" || $fieldKey ==
"~DETAIL_PICTURE")
3234 $result[
"FIELDS"][mb_substr($fieldKey, 1)] = CBPDocument::prepareFileForHistory(
3235 array(
"lists", get_called_class(), $documentId),
3240 elseif (mb_substr($fieldKey, 0, 1) ==
"~")
3242 $result[
"FIELDS"][mb_substr($fieldKey, 1)] = $fieldValue;
3246 $result[
"PROPERTIES"] = array();
3247 foreach ($properties as $propertyKey => $propertyValue)
3249 if ($propertyValue[
"USER_TYPE"] <>
'')
3251 $result[
"PROPERTIES"][$propertyKey] = array(
3252 "VALUE" => $propertyValue[
"VALUE"],
3253 "DESCRIPTION" => $propertyValue[
"DESCRIPTION"]
3256 elseif ($propertyValue[
"PROPERTY_TYPE"] ==
"L")
3258 $result[
"PROPERTIES"][$propertyKey] = array(
3259 "VALUE" => $propertyValue[
"VALUE_ENUM_ID"],
3260 "DESCRIPTION" => $propertyValue[
"DESCRIPTION"]
3263 elseif ($propertyValue[
"PROPERTY_TYPE"] ==
"F")
3265 $result[
"PROPERTIES"][$propertyKey] = array(
3266 "VALUE" => CBPDocument::prepareFileForHistory(
3267 array(
"lists", get_called_class(), $documentId),
3268 $propertyValue[
"VALUE"],
3271 "DESCRIPTION" => $propertyValue[
"DESCRIPTION"]
3276 $result[
"PROPERTIES"][$propertyKey] = array(
3277 "VALUE" => $propertyValue[
"VALUE"],
3278 "DESCRIPTION" => $propertyValue[
"DESCRIPTION"]