Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
bizprocdocument.php
1<?php
2
5
6Loc::loadMessages(__FILE__);
7
8if (!Loader::includeModule('bizproc') || !Loader::includeModule('iblock'))
9{
10 return;
11}
12
13class BizprocDocument extends CIBlockDocument
14{
15 const DOCUMENT_TYPE_PREFIX = 'iblock_';
16 private static $cachedTasks;
17 private static $elements = [];
18
19 public static function getEntityName()
20 {
21 return Loc::getMessage('LISTS_BIZPROC_ENTITY_NAME');
22 }
23
28 public static function generateDocumentType($iblockId)
29 {
30 $iblockId = (int)$iblockId;
31 return self::DOCUMENT_TYPE_PREFIX . $iblockId;
32 }
33
39 public static function generateDocumentComplexType($iblockType, $iblockId)
40 {
41 if($iblockType == COption::GetOptionString("lists", "livefeed_iblock_type_id"))
42 return array('lists', get_called_class(), self::generateDocumentType($iblockId));
43 else
44 return array('lists', 'Bitrix\Lists\BizprocDocumentLists', self::generateDocumentType($iblockId));
45 }
46
52 public static function getDocumentComplexId($iblockType, $documentId)
53 {
54 if($iblockType == COption::getOptionString("lists", "livefeed_iblock_type_id"))
55 return array('lists', get_called_class(), $documentId);
56 else
57 return array('lists', 'Bitrix\Lists\BizprocDocumentLists', $documentId);
58 }
59
63 public static function deleteDataIblock($iblockId)
64 {
65 $iblockId = intval($iblockId);
66 $documentType = array('lists', get_called_class(), self::generateDocumentType($iblockId));
67 $errors = array();
68 $templateObject = CBPWorkflowTemplateLoader::getList(
69 array('ID' => 'DESC'),
70 array('DOCUMENT_TYPE' => $documentType),
71 false,
72 false,
73 array('ID')
74 );
75 while($template = $templateObject->fetch())
76 {
77 CBPDocument::deleteWorkflowTemplate($template['ID'], $documentType, $errors);
78 }
79 }
80
87 public static function getDocumentIcon($documentId)
88 {
89 $documentId = intval($documentId);
90 if ($documentId <= 0)
91 throw new CBPArgumentNullException('documentId');
92
93 $db = CIBlockElement::getList(
94 array(),
95 array('ID' => $documentId, 'SHOW_NEW'=>'Y', 'SHOW_HISTORY' => 'Y'),
96 false,
97 false,
98 array('ID', 'IBLOCK_ID')
99 );
100 if ($element = $db->fetch())
101 {
102 $iblockPicture = CIBlock::getArrayByID($element['IBLOCK_ID'], 'PICTURE');
103 $imageFile = CFile::getFileArray($iblockPicture);
104 if(!empty($imageFile['SRC']))
105 return $imageFile['SRC'];
106 }
107
108 return null;
109 }
110
118 public static function getDocument($documentId)
119 {
120 $documentId = intval($documentId);
121 if ($documentId <= 0)
122 {
123 throw new CBPArgumentNullException('documentId');
124 }
125
126 $result = [];
127 $element = [];
128 $elementProperty = [];
129
130 $queryElement = CIBlockElement::getList(
131 [],
132 ['ID' => $documentId, 'SHOW_NEW' => 'Y', 'SHOW_HISTORY' => 'Y']
133 );
134 while ($queryResult = $queryElement->fetch())
135 {
136 $element = $queryResult;
137 $queryProperty = CIBlockElement::getProperty(
138 $queryResult['IBLOCK_ID'],
139 $queryResult['ID'],
140 ['sort' => 'asc', 'id' => 'asc', 'enum_sort' => 'asc', 'value_id' => 'asc'],
141 ['ACTIVE' => 'Y', 'EMPTY' => 'N']
142 );
143 while ($property = $queryProperty->fetch())
144 {
145 $propertyKey = 'PROPERTY_' . $property['ID'];
146 if ($property['MULTIPLE'] == 'Y')
147 {
148 if (!array_key_exists($propertyKey, $elementProperty))
149 {
150 $elementProperty[$propertyKey] = $property;
151 $elementProperty[$propertyKey]['VALUE'] = [];
152 }
153 $elementProperty[$propertyKey]['VALUE'][] = $property['VALUE'];
154 }
155 else
156 {
157 $elementProperty[$propertyKey] = $property;
158 }
159 }
160 }
161
162 foreach ($element as $fieldId => $fieldValue)
163 {
164 $result[$fieldId] = $fieldValue;
165 if (in_array($fieldId, ['MODIFIED_BY', 'CREATED_BY']))
166 {
167 $result[$fieldId] = 'user_' . $fieldValue;
168 $result[$fieldId . '_PRINTABLE'] =
169 $element[($fieldId == 'MODIFIED_BY')
170 ? 'USER_NAME'
171 : 'CREATED_USER_NAME']
172 ;
173 }
174 elseif (in_array($fieldId, ['PREVIEW_TEXT', 'DETAIL_TEXT']))
175 {
176 if ($element[$fieldId . '_TYPE'] == 'html')
177 {
178 $result[$fieldId] = HTMLToTxt($fieldValue);
179 }
180 }
181 }
182 foreach ($elementProperty as $propertyId => $property)
183 {
184 if (trim($property['CODE']) <> '')
185 {
186 $propertyId = $property['CODE'];
187 }
188 else
189 {
190 $propertyId = $property['ID'];
191 }
192
193 if (!empty($property['USER_TYPE']))
194 {
195 if (
196 $property['USER_TYPE'] == 'UserID'
197 || $property['USER_TYPE'] == 'employee'
198 && (COption::getOptionString('bizproc', 'employee_compatible_mode', 'N') != 'Y')
199 )
200 {
201 if (empty($property['VALUE']))
202 {
203 continue;
204 }
205 if (!is_array($property['VALUE']))
206 {
207 $property['VALUE'] = [$property['VALUE']];
208 }
209
210 $listUsers = implode(' | ', $property['VALUE']);
211 $userQuery = CUser::getList(
212 'ID',
213 'ASC',
214 ['ID' => $listUsers],
215 [
216 'FIELDS' => ['ID', 'LOGIN', 'NAME', 'LAST_NAME'],
217 ]
218 );
219 while ($user = $userQuery->fetch())
220 {
221 if ($property['MULTIPLE'] == 'Y')
222 {
223 $result = self::setArray($result, 'PROPERTY_' . $propertyId);
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'];
229 }
230 else
231 {
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'];
236 }
237 }
238 }
239 elseif ($property['USER_TYPE'] == 'DiskFile')
240 {
241 $diskValues = current($property['VALUE']);
242 $userType = \CIBlockProperty::getUserType($property['USER_TYPE']);
243 if (is_array($diskValues))
244 {
245 $result = self::setArray($result, 'PROPERTY_' . $propertyId);
246 $result = self::setArray($result, 'PROPERTY_' . $propertyId . '_PRINTABLE');
247 foreach ($diskValues as $attachedId)
248 {
249 $fileId = null;
250 if (array_key_exists('GetObjectId', $userType))
251 {
252 $fileId = call_user_func_array($userType['GetObjectId'], [$attachedId]);
253 }
254 if (!$fileId)
255 {
256 continue;
257 }
258 $printableUrl = '';
259 if (array_key_exists('GetUrlAttachedFileElement', $userType))
260 {
261 $printableUrl = call_user_func_array(
262 $userType['GetUrlAttachedFileElement'],
263 [$documentId, $fileId]
264 );
265 }
266
267 $result['PROPERTY_' . $propertyId][$attachedId] = $fileId;
268 $result['PROPERTY_' . $propertyId . '_PRINTABLE'][$attachedId] = $printableUrl;
269 }
270 }
271 else
272 {
273 continue;
274 }
275 }
276 elseif ($property['USER_TYPE'] == 'HTML')
277 {
278 if (\CBPHelper::isAssociativeArray($property['VALUE']))
279 {
280 if ($property['VALUE']['TYPE'] == 'HTML')
281 {
282 $result['PROPERTY_' . $propertyId] = HTMLToTxt($property['VALUE']['TEXT']);
283 }
284 else
285 {
286 $result['PROPERTY_' . $propertyId] = $property['VALUE']['TEXT'];
287 }
288 }
289 else
290 {
291 $result = self::setArray($result, 'PROPERTY_' . $propertyId);
292 foreach ($property['VALUE'] as $htmlValue)
293 {
294 if ($htmlValue['TYPE'] == 'HTML')
295 {
296 $result['PROPERTY_' . $propertyId][] = HTMLToTxt($htmlValue['TEXT']);
297 }
298 else
299 {
300 $result['PROPERTY_' . $propertyId][] = $htmlValue['TEXT'];
301 }
302 }
303 }
304 }
305 elseif ($property['USER_TYPE'] == 'Money')
306 {
307 $userType = \CIBlockProperty::getUserType($property['USER_TYPE']);
308 if (is_array($property['VALUE']))
309 {
310 $result = self::setArray($result, 'PROPERTY_' . $propertyId);
311 $result = self::setArray($result, 'PROPERTY_' . $propertyId . '_PRINTABLE');
312 foreach ($property['VALUE'] as $moneyValue)
313 {
314 $result['PROPERTY_' . $propertyId][] = $moneyValue;
315 if (array_key_exists('GetPublicViewHTML', $userType))
316 {
317 $result['PROPERTY_' . $propertyId . '_PRINTABLE'][] = call_user_func_array(
318 $userType['GetPublicViewHTML'],
319 [$property, ['VALUE' => $moneyValue], []]
320 );
321 }
322 }
323 }
324 else
325 {
326 $result['PROPERTY_' . $propertyId] = $property['VALUE'];
327 if (array_key_exists('GetPublicViewHTML', $userType))
328 {
329 $result['PROPERTY_' . $propertyId . '_PRINTABLE'] = call_user_func_array(
330 $userType['GetPublicViewHTML'],
331 [$property, ['VALUE' => $property['VALUE']], []]
332 );
333 }
334 }
335 }
336 else
337 {
338 $result['PROPERTY_' . $propertyId] = $property['VALUE'];
339 }
340 }
341 elseif ($property['PROPERTY_TYPE'] == 'L')
342 {
343 $result = self::setArray($result, 'PROPERTY_' . $propertyId);
344 //$result = self::setArray($result, 'PROPERTY_'.$propertyId.'_PRINTABLE');
345 $propertyArray = [];
346 $propertyKeyArray = [];
347 if (!is_array($property['VALUE']))
348 {
349 $property['VALUE'] = [$property['VALUE']];
350 }
351 foreach ($property['VALUE'] as $enumId)
352 {
353 $enumsObject = CIBlockProperty::getPropertyEnum(
354 $property['ID'],
355 ['SORT' => 'asc'],
356 ['ID' => $enumId]
357 );
358 while ($enums = $enumsObject->fetch())
359 {
360 $propertyArray[] = $enums['VALUE'];
361 $propertyKeyArray[] = $enums['XML_ID'];
362 }
363 }
364 for ($i = 0, $cnt = count($propertyArray); $i < $cnt; $i++)
365 {
366 $result['PROPERTY_' . $propertyId][$propertyKeyArray[$i]] = $propertyArray[$i];
367 }
368 }
369 elseif ($property['PROPERTY_TYPE'] == 'F')
370 {
371 $result = self::setArray($result, 'PROPERTY_' . $propertyId);
372 $result = self::setArray($result, 'PROPERTY_' . $propertyId . '_PRINTABLE');
373 $propertyArray = $property['VALUE'];
374 if (!is_array($propertyArray))
375 {
376 $propertyArray = [$propertyArray];
377 }
378
379 foreach ($propertyArray as $v)
380 {
381 $fileArray = \CFile::getFileArray($v);
382 if ($fileArray)
383 {
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]";
389 }
390 }
391 }
392 else
393 {
394 $result['PROPERTY_' . $propertyId] = $property['VALUE'];
395 }
396 }
397
398 if (!empty($result))
399 {
400 $documentFields = static::getDocumentFields(static::getDocumentType($documentId));
401 foreach ($documentFields as $fieldKey => $field)
402 {
403 if (!array_key_exists($fieldKey, $result))
404 {
405 $result[$fieldKey] = null;
406 }
407 }
408 }
409
410 return $result;
411 }
412
413 protected static function setArray(array $result, $value)
414 {
415 if (!isset($result[$value]) || !is_array($result[$value]))
416 {
417 $result[$value] = array();
418 }
419 return $result;
420 }
421
422 protected static function getSystemIblockFields()
423 {
424 $result = array(
425 "ID" => array(
426 "Name" => GetMessage("IBD_FIELD_ID"),
427 "Type" => "int",
428 "Filterable" => true,
429 "Editable" => false,
430 "Required" => false,
431 ),
432 "TIMESTAMP_X" => array(
433 "Name" => GetMessage("IBD_FIELD_TIMESTAMP_X"),
434 "Type" => "datetime",
435 "Filterable" => true,
436 "Editable" => true,
437 "Required" => false,
438 ),
439 "MODIFIED_BY" => array(
440 "Name" => GetMessage("IBD_FIELD_MODYFIED"),
441 "Type" => "user",
442 "Filterable" => true,
443 "Editable" => true,
444 "Required" => false,
445 ),
446 "MODIFIED_BY_PRINTABLE" => array(
447 "Name" => GetMessage("IBD_FIELD_MODIFIED_BY_USER_PRINTABLE"),
448 "Type" => "string",
449 "Filterable" => false,
450 "Editable" => false,
451 "Required" => false,
452 ),
453 "DATE_CREATE" => array(
454 "Name" => GetMessage("IBD_FIELD_DATE_CREATE"),
455 "Type" => "datetime",
456 "Filterable" => true,
457 "Editable" => true,
458 "Required" => false,
459 ),
460 "CREATED_BY" => array(
461 "Name" => GetMessage("IBD_FIELD_CREATED"),
462 "Type" => "user",
463 "Filterable" => true,
464 "Editable" => false,
465 "Required" => false,
466 ),
467 "CREATED_BY_PRINTABLE" => array(
468 "Name" => GetMessage("IBD_FIELD_CREATED_BY_USER_PRINTABLE"),
469 "Type" => "string",
470 "Filterable" => false,
471 "Editable" => false,
472 "Required" => false,
473 ),
474 "IBLOCK_ID" => array(
475 "Name" => GetMessage("IBD_FIELD_IBLOCK_ID"),
476 "Type" => "int",
477 "Filterable" => true,
478 "Editable" => true,
479 "Required" => true,
480 ),
481 "ACTIVE" => array(
482 "Name" => GetMessage("IBD_FIELD_ACTIVE"),
483 "Type" => "bool",
484 "Filterable" => true,
485 "Editable" => true,
486 "Required" => false,
487 ),
488 "BP_PUBLISHED" => array(
489 "Name" => GetMessage("IBD_FIELD_BP_PUBLISHED"),
490 "Type" => "bool",
491 "Filterable" => false,
492 "Editable" => true,
493 "Required" => false,
494 ),
495 "ACTIVE_FROM" => array(
496 "Name" => GetMessage("IBD_FIELD_DATE_ACTIVE_FROM"),
497 "Type" => "datetime",
498 "Filterable" => true,
499 "Editable" => true,
500 "Required" => false,
501 ),
502 "ACTIVE_TO" => array(
503 "Name" => GetMessage("IBD_FIELD_DATE_ACTIVE_TO"),
504 "Type" => "datetime",
505 "Filterable" => true,
506 "Editable" => true,
507 "Required" => false,
508 ),
509 "SORT" => array(
510 "Name" => GetMessage("IBD_FIELD_SORT"),
511 "Type" => "int",
512 "Filterable" => true,
513 "Editable" => true,
514 "Required" => false,
515 ),
516 "NAME" => array(
517 "Name" => GetMessage("IBD_FIELD_NAME"),
518 "Type" => "string",
519 "Filterable" => true,
520 "Editable" => true,
521 "Required" => true,
522 ),
523 "PREVIEW_PICTURE" => array(
524 "Name" => GetMessage("IBD_FIELD_PREVIEW_PICTURE"),
525 "Type" => "file",
526 "Filterable" => false,
527 "Editable" => true,
528 "Required" => false,
529 ),
530 "PREVIEW_TEXT" => array(
531 "Name" => GetMessage("IBD_FIELD_PREVIEW_TEXT"),
532 "Type" => "text",
533 "Filterable" => false,
534 "Editable" => true,
535 "Required" => false,
536 ),
537 "PREVIEW_TEXT_TYPE" => array(
538 "Name" => GetMessage("IBD_FIELD_PREVIEW_TEXT_TYPE"),
539 "Type" => "select",
540 "Options" => array(
541 "text" => GetMessage("IBD_DESC_TYPE_TEXT"),
542 "html" => "Html",
543 ),
544 "Filterable" => false,
545 "Editable" => true,
546 "Required" => false,
547 ),
548 "DETAIL_PICTURE" => array(
549 "Name" => GetMessage("IBD_FIELD_DETAIL_PICTURE"),
550 "Type" => "file",
551 "Filterable" => false,
552 "Editable" => true,
553 "Required" => false,
554 ),
555 "DETAIL_TEXT" => array(
556 "Name" => GetMessage("IBD_FIELD_DETAIL_TEXT"),
557 "Type" => "text",
558 "Filterable" => false,
559 "Editable" => true,
560 "Required" => false,
561 ),
562 "DETAIL_TEXT_TYPE" => array(
563 "Name" => GetMessage("IBD_FIELD_DETAIL_TEXT_TYPE"),
564 "Type" => "select",
565 "Options" => array(
566 "text" => GetMessage("IBD_DESC_TYPE_TEXT"),
567 "html" => "Html",
568 ),
569 "Filterable" => false,
570 "Editable" => true,
571 "Required" => false,
572 ),
573 "CODE" => array(
574 "Name" => GetMessage("IBD_FIELD_CODE"),
575 "Type" => "string",
576 "Filterable" => true,
577 "Editable" => true,
578 "Required" => false,
579 ),
580 "XML_ID" => array(
581 "Name" => GetMessage("IBD_FIELD_XML_ID"),
582 "Type" => "string",
583 "Filterable" => true,
584 "Editable" => true,
585 "Required" => false,
586 ),
587 );
588
589 $keys = array_keys($result);
590 foreach ($keys as $key)
591 {
592 $result[$key]["Multiple"] = false;
593 $result[$key]["active"] = false;
594 }
595
596 return $result;
597 }
598
604 public static function getDocumentFields($documentType)
605 {
606 $iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
607 if ($iblockId <= 0)
608 throw new CBPArgumentOutOfRangeException("documentType", $documentType);
609
610 $documentFieldTypes = self::getDocumentFieldTypes($documentType);
611
612 $result = self::getSystemIblockFields();
613
614 $dbProperties = CIBlockProperty::getList(
615 array("sort" => "asc", "name" => "asc"),
616 array("IBLOCK_ID" => $iblockId, 'ACTIVE' => 'Y')
617 );
618 $ignoreProperty = array();
619 while ($property = $dbProperties->fetch())
620 {
621 if (trim($property["CODE"]) <> '')
622 {
623 $key = "PROPERTY_".$property["CODE"];
624 $ignoreProperty["PROPERTY_".$property["ID"]] = "PROPERTY_".$property["CODE"];
625 }
626 else
627 {
628 $key = "PROPERTY_".$property["ID"];
629 $ignoreProperty["PROPERTY_".$property["ID"]] = 0;
630 }
631
632 $result[$key] = array(
633 "Name" => $property["NAME"],
634 "Filterable" => ($property["FILTRABLE"] == "Y"),
635 "Editable" => true,
636 "Required" => ($property["IS_REQUIRED"] == "Y"),
637 "Multiple" => ($property["MULTIPLE"] == "Y"),
638 "TypeReal" => $property["PROPERTY_TYPE"],
639 "UserTypeSettings" => $property["USER_TYPE_SETTINGS"]
640 );
641
642 if(trim($property["CODE"]) <> '')
643 $result[$key]["Alias"] = "PROPERTY_".$property["ID"];
644
645 if ($property["USER_TYPE"] <> '')
646 {
647 $result[$key]["TypeReal"] = $property["PROPERTY_TYPE"].":".$property["USER_TYPE"];
648
649 if ($property["USER_TYPE"] == "UserID"
650 || $property["USER_TYPE"] == "employee" && (COption::getOptionString("bizproc", "employee_compatible_mode", "N") != "Y"))
651 {
652 $result[$key]["Type"] = "user";
653 $result[$key."_PRINTABLE"] = array(
654 "Name" => $property["NAME"].GetMessage("IBD_FIELD_USERNAME_PROPERTY"),
655 "Filterable" => false,
656 "Editable" => false,
657 "Required" => false,
658 "Multiple" => ($property["MULTIPLE"] == "Y"),
659 "Type" => "string",
660 );
661 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
662 }
663 elseif ($property["USER_TYPE"] == "DateTime")
664 {
665 $result[$key]["Type"] = "datetime";
666 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
667 }
668 elseif ($property["USER_TYPE"] == "Date")
669 {
670 $result[$key]["Type"] = "date";
671 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
672 }
673 elseif ($property["USER_TYPE"] == "EList")
674 {
675 $result[$key]["Type"] = "E:EList";
676 $result[$key]["Options"] = $property["LINK_IBLOCK_ID"];
677 }
678 elseif ($property["USER_TYPE"] == "ECrm")
679 {
680 $result[$key]["Type"] = "E:ECrm";
681 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
682 $result[$key]["Options"] = $property["USER_TYPE_SETTINGS"];
683 }
684 elseif ($property["USER_TYPE"] == "Money")
685 {
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,
691 "Editable" => false,
692 "Required" => false,
693 "Multiple" => ($property["MULTIPLE"] == "Y"),
694 "Type" => "string",
695 );
696 }
697 elseif ($property["USER_TYPE"] == "Sequence")
698 {
699 $result[$key]["Type"] = "N:Sequence";
700 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
701 $result[$key]["Options"] = $property["USER_TYPE_SETTINGS"];
702 }
703 elseif ($property["USER_TYPE"] == "DiskFile")
704 {
705 $result[$key]["Type"] = "S:DiskFile";
706 $result[$key."_PRINTABLE"] = array(
707 "Name" => $property["NAME"].GetMessage("IBD_FIELD_USERNAME_PROPERTY"),
708 "Filterable" => false,
709 "Editable" => false,
710 "Required" => false,
711 "Multiple" => ($property["MULTIPLE"] == "Y"),
712 "Type" => "int",
713 );
714 }
715 elseif ($property["USER_TYPE"] == "HTML")
716 {
717 $result[$key]["Type"] = "S:HTML";
718 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
719 }
720 else
721 {
722 $result[$key]["Type"] = "string";
723 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
724 }
725 }
726 elseif ($property["PROPERTY_TYPE"] == "L")
727 {
728 $result[$key]["Type"] = "select";
729
730 $result[$key]["Options"] = array();
731 $dbPropertyEnums = CIBlockProperty::getPropertyEnum($property["ID"]);
732 while ($propertyEnum = $dbPropertyEnums->getNext())
733 {
734 $result[$key]["Options"][$propertyEnum["XML_ID"]] = $propertyEnum["~VALUE"];
735 if($propertyEnum["DEF"] == "Y")
736 $result[$key]["DefaultValue"] = $propertyEnum["~VALUE"];
737 }
738 }
739 elseif ($property["PROPERTY_TYPE"] == "N")
740 {
741 $result[$key]["Type"] = "double";
742 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
743 }
744 elseif ($property["PROPERTY_TYPE"] == "F")
745 {
746 $result[$key]["Type"] = "file";
747 $result[$key."_PRINTABLE"] = array(
748 "Name" => $property["NAME"].GetMessage("IBD_FIELD_USERNAME_PROPERTY"),
749 "Filterable" => false,
750 "Editable" => false,
751 "Required" => false,
752 "Multiple" => ($property["MULTIPLE"] == "Y"),
753 "Type" => "string",
754 );
755 }
756 elseif ($property["PROPERTY_TYPE"] == "S")
757 {
758 $result[$key]["Type"] = "string";
759 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
760 }
761 elseif ($property["PROPERTY_TYPE"] == "E")
762 {
763 $result[$key]["Type"] = "E:EList";
764 $result[$key]["Options"] = $property["LINK_IBLOCK_ID"];
765 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
766 }
767 else
768 {
769 $result[$key]["Type"] = "string";
770 $result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
771 }
772 }
773
774 $list = new CList($iblockId);
775 $fields = $list->getFields();
776 foreach($fields as $fieldId => $field)
777 {
778 if(empty($field["SETTINGS"]))
779 $field["SETTINGS"] = array("SHOW_ADD_FORM" => 'Y', "SHOW_EDIT_FORM"=>'Y');
780
781 if(array_key_exists($fieldId, $ignoreProperty))
782 {
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"])
789 {
790 $result[$key]["row_count"] = $field["ROW_COUNT"];
791 $result[$key]["col_count"] = $field["COL_COUNT"];
792 }
793 }
794 else
795 {
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"],
805 "active" => true,
806 "active_type" => $field['TYPE'],
807 "DefaultValue" => $field["DEFAULT_VALUE"],
808 );
809 if(isset($field['ROW_COUNT'], $field['COL_COUNT']) && $field["ROW_COUNT"] && $field["COL_COUNT"])
810 {
811 $result[$fieldId]["row_count"] = $field["ROW_COUNT"];
812 $result[$fieldId]["col_count"] = $field["COL_COUNT"];
813 }
814 }
815 }
816
817 $keys = array_keys($result);
818 foreach ($keys as $k)
819 {
820 $result[$k]["BaseType"] = $documentFieldTypes[$result[$k]["Type"]]["BaseType"];
821 $result[$k]["Complex"] = $documentFieldTypes[$result[$k]["Type"]]["Complex"] ?? null;
822 }
823
824 return $result;
825 }
826
831 public static function generateMnemonicCode($integerCode = 0)
832 {
833 $code = '';
834 for ($i = 1; $integerCode >= 0 && $i < 10; $i++)
835 {
836 $code = chr(0x41 + ($integerCode % pow(26, $i) / pow(26, $i - 1))) . $code;
837 $integerCode -= pow(26, $i);
838 }
839 return $code;
840 }
841
848 public static function addDocumentField($documentType, $fields)
849 {
850 $iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
851 if ($iblockId <= 0)
852 throw new CBPArgumentOutOfRangeException("documentType", $documentType);
853
854 if (mb_substr($fields["code"], 0, mb_strlen("PROPERTY_")) == "PROPERTY_")
855 $fields["code"] = mb_substr($fields["code"], mb_strlen("PROPERTY_"));
856
857 if(!empty($fields["active_type"]))
858 $fields["type"] = $fields["active_type"];
859
860 $fieldsTemporary = array(
861 "NAME" => $fields["name"],
862 "ACTIVE" => "Y",
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,
868 "FILTRABLE" => "Y",
869 "SETTINGS" => $fields["settings"] ? $fields["settings"] : array("SHOW_ADD_FORM" => 'Y', "SHOW_EDIT_FORM"=>'Y'),
870 "DEFAULT_VALUE" => $fields['DefaultValue']
871 );
872
873 if (mb_strpos("0123456789", mb_substr($fieldsTemporary["CODE"], 0, 1)) !== false)
874 $fieldsTemporary["CODE"] = self::generatePropertyCode($fields["name"], $fields["code"], $iblockId);
875
876 if (array_key_exists("additional_type_info", $fields))
877 $fieldsTemporary["LINK_IBLOCK_ID"] = intval($fields["additional_type_info"]);
878
879 if(!empty($fields["UserTypeSettings"]))
880 $fieldsTemporary["USER_TYPE_SETTINGS"] = $fields["UserTypeSettings"];
881
882 if(mb_strstr($fields["type"], ":") !== false)
883 {
884 list($fieldsTemporary["TYPE"], $fieldsTemporary["USER_TYPE"]) = explode(":", $fields["type"], 2);
885 if($fields["type"] == "E:EList")
886 {
887 $fieldsTemporary["LINK_IBLOCK_ID"] = $fields["options"] ?? null;
888 }
889 elseif($fields["type"] == "E:ECrm")
890 {
891 $fieldsTemporary["TYPE"] = "S:ECrm";
892 }
893 }
894 elseif ($fields["type"] == "user")
895 {
896 $fieldsTemporary["TYPE"] = "S:employee";
897 $fieldsTemporary["USER_TYPE"]= "UserID";
898 }
899 elseif ($fields["type"] == "date")
900 {
901 $fieldsTemporary["TYPE"] = "S:Date";
902 $fieldsTemporary["USER_TYPE"]= "Date";
903 }
904 elseif ($fields["type"] == "datetime")
905 {
906 $fieldsTemporary["TYPE"] = "S:DateTime";
907 $fieldsTemporary["USER_TYPE"]= "DateTime";
908 }
909 elseif ($fields["type"] == "file")
910 {
911 $fieldsTemporary["TYPE"] = "F";
912 $fieldsTemporary["USER_TYPE"]= "";
913 }
914 elseif ($fields["type"] == "select")
915 {
916 $fieldsTemporary["TYPE"] = "L";
917 $fieldsTemporary["USER_TYPE"]= false;
918
919 if (is_array($fields["options"]))
920 {
921 $i = 10;
922 foreach ($fields["options"] as $k => $v)
923 {
924 $def = "N";
925 if($fields['DefaultValue'] == $v)
926 $def = "Y";
927 $fieldsTemporary["VALUES"][] = array("XML_ID" => $k, "VALUE" => $v, "DEF" => $def, "SORT" => $i);
928 $i = $i + 10;
929 }
930 }
931 elseif (is_string($fields["options"]) && ($fields["options"] <> ''))
932 {
933 $a = explode("\n", $fields["options"]);
934 $i = 10;
935 foreach ($a as $v)
936 {
937 $v = trim(trim($v), "\r\n");
938 if (!$v)
939 continue;
940 $v1 = $v2 = $v;
941 if (mb_substr($v, 0, 1) == "[" && mb_strpos($v, "]") !== false)
942 {
943 $v1 = mb_substr($v, 1, mb_strpos($v, "]") - 1);
944 $v2 = trim(mb_substr($v, mb_strpos($v, "]") + 1));
945 }
946 $def = "N";
947 if($fields['DefaultValue'] == $v2)
948 $def = "Y";
949 $fieldsTemporary["VALUES"][] = array("XML_ID" => $v1, "VALUE" => $v2, "DEF" => $def, "SORT" => $i);
950 $i = $i + 10;
951 }
952 }
953 }
954 elseif($fields["type"] == "string")
955 {
956 $fieldsTemporary["TYPE"] = "S";
957
958 if($fields["row_count"] && $fields["col_count"])
959 {
960 $fieldsTemporary["ROW_COUNT"] = $fields["row_count"];
961 $fieldsTemporary["COL_COUNT"] = $fields["col_count"];
962 }
963 else
964 {
965 $fieldsTemporary["ROW_COUNT"] = 1;
966 $fieldsTemporary["COL_COUNT"] = 30;
967 }
968 }
969 elseif($fields["type"] == "text")
970 {
971 $fieldsTemporary["TYPE"] = "S";
972 if($fields["row_count"] && $fields["col_count"])
973 {
974 $fieldsTemporary["ROW_COUNT"] = $fields["row_count"];
975 $fieldsTemporary["COL_COUNT"] = $fields["col_count"];
976 }
977 else
978 {
979 $fieldsTemporary["ROW_COUNT"] = 4;
980 $fieldsTemporary["COL_COUNT"] = 30;
981 }
982 }
983 elseif($fields["type"] == "int" || $fields["type"] == "double")
984 {
985 $fieldsTemporary["TYPE"] = "N";
986 }
987 elseif($fields["type"] == "bool")
988 {
989 $fieldsTemporary["TYPE"] = "L";
990 $fieldsTemporary["VALUES"][] = array(
991 "XML_ID" => 'Y',
992 "VALUE" => GetMessage("BPVDX_YES"),
993 "DEF" => "N",
994 "SORT" => 10
995 );
996 $fieldsTemporary["VALUES"][] = array(
997 "XML_ID" => 'N',
998 "VALUE" => GetMessage("BPVDX_NO"),
999 "DEF" => "N",
1000 "SORT" => 20
1001 );
1002 }
1003 else
1004 {
1005 $fieldsTemporary["TYPE"] = $fields["type"];
1006 $fieldsTemporary["USER_TYPE"] = false;
1007 }
1008
1009 $idField = false;
1010 $properties = CIBlockProperty::getList(
1011 array(),
1012 array("IBLOCK_ID" => $fieldsTemporary["IBLOCK_ID"], "CODE" => $fieldsTemporary["CODE"])
1013 );
1014 if(!$properties->fetch())
1015 {
1016 $listObject = new CList($iblockId);
1017 $idField = $listObject->addField($fieldsTemporary);
1018 }
1019
1020 if($idField)
1021 {
1022 global $CACHE_MANAGER;
1023 $CACHE_MANAGER->clearByTag("lists_list_".$iblockId);
1024 if(!empty($fieldsTemporary["CODE"]))
1025 {
1026 $idField = mb_substr($idField, 0, mb_strlen("PROPERTY_")).$fieldsTemporary["CODE"];
1027 }
1028 return $idField;
1029 }
1030 return false;
1031 }
1032
1039 public static function updateDocumentField($documentType, $fields)
1040 {
1041 if(!isset($fields['settings'])) // check field on the activity
1042 return false;
1043
1044 if(!empty($fields["active_type"]))
1045 $fields["type"] = $fields["active_type"];
1046
1047 $iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
1048 if ($iblockId <= 0)
1049 throw new CBPArgumentOutOfRangeException("documentType", $documentType);
1050
1051 $fieldId = false;
1052 if (mb_substr($fields["code"], 0, mb_strlen("PROPERTY_")) == "PROPERTY_")
1053 {
1054 $fields["code"] = mb_substr($fields["code"], mb_strlen("PROPERTY_"));
1055 $propertyObject = CIBlockProperty::getList(
1056 array(),
1057 array("IBLOCK_ID" => $iblockId, "CODE" => $fields["code"])
1058 );
1059 if($property = $propertyObject->fetch())
1060 {
1061 $fieldId = "PROPERTY_".$property["ID"];
1062 }
1063 }
1064 else
1065 {
1066 if(empty($fields["code"]))
1067 {
1068 return false;
1069 }
1070
1071 $fieldId = $fields["code"];
1072 }
1073
1074 if($fieldId)
1075 {
1076 $fieldData = array(
1077 "NAME" => $fields["name"],
1078 "ACTIVE" => "Y",
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,
1084 "FILTRABLE" => "Y",
1085 "SETTINGS" => $fields["settings"] ? $fields["settings"] :
1086 array("SHOW_ADD_FORM" => 'Y', "SHOW_EDIT_FORM"=>'Y'),
1087 "DEFAULT_VALUE" => $fields['DefaultValue']
1088 );
1089
1090 if (array_key_exists("additional_type_info", $fields))
1091 $fieldData["LINK_IBLOCK_ID"] = intval($fields["additional_type_info"]);
1092
1093 if(!empty($fields["UserTypeSettings"]))
1094 $fieldData["USER_TYPE_SETTINGS"] = $fields["UserTypeSettings"];
1095
1096 if(mb_strstr($fields["type"], ":") !== false)
1097 {
1098 list($fieldData["TYPE"], $fieldData["USER_TYPE"]) = explode(":", $fields["type"], 2);
1099 if($fields["type"] == "E:EList")
1100 {
1101 $fieldData["LINK_IBLOCK_ID"] = $fields["options"] ?? null;
1102 }
1103 elseif($fields["type"] == "E:ECrm")
1104 {
1105 $fieldData["TYPE"] = "S:ECrm";
1106 }
1107 }
1108 elseif ($fields["type"] == "user")
1109 {
1110 $fieldData["TYPE"] = "S:employee";
1111 $fieldData["USER_TYPE"]= "UserID";
1112 }
1113 elseif ($fields["type"] == "date")
1114 {
1115 $fieldData["TYPE"] = "S:Date";
1116 $fieldData["USER_TYPE"]= "Date";
1117 }
1118 elseif ($fields["type"] == "datetime")
1119 {
1120 $fieldData["TYPE"] = "S:DateTime";
1121 $fieldData["USER_TYPE"]= "DateTime";
1122 }
1123 elseif ($fields["type"] == "file")
1124 {
1125 $fieldData["TYPE"] = "F";
1126 $fieldData["USER_TYPE"]= "";
1127 }
1128 elseif ($fields["type"] == "select")
1129 {
1130 $fieldData["TYPE"] = "L";
1131 $fieldData["USER_TYPE"]= false;
1132
1133 if (is_array($fields["options"]))
1134 {
1135 $i = 10;
1136 foreach ($fields["options"] as $k => $v)
1137 {
1138 $def = "N";
1139 if($fields['DefaultValue'] == $v)
1140 $def = "Y";
1141 $fieldData["VALUES"][] = array("XML_ID" => $k, "VALUE" => $v, "DEF" => $def, "SORT" => $i);
1142 $i = $i + 10;
1143 }
1144 }
1145 elseif (is_string($fields["options"]) && ($fields["options"] <> ''))
1146 {
1147 $a = explode("\n", $fields["options"]);
1148 $i = 10;
1149 foreach ($a as $v)
1150 {
1151 $v = trim(trim($v), "\r\n");
1152 if (!$v)
1153 continue;
1154 $v1 = $v2 = $v;
1155 if (mb_substr($v, 0, 1) == "[" && mb_strpos($v, "]") !== false)
1156 {
1157 $v1 = mb_substr($v, 1, mb_strpos($v, "]") - 1);
1158 $v2 = trim(mb_substr($v, mb_strpos($v, "]") + 1));
1159 }
1160 $def = "N";
1161 if($fields['DefaultValue'] == $v2)
1162 $def = "Y";
1163 $fieldData["VALUES"][] = array("XML_ID" => $v1, "VALUE" => $v2, "DEF" => $def, "SORT" => $i);
1164 $i = $i + 10;
1165 }
1166 }
1167 }
1168 elseif($fields["type"] == "string")
1169 {
1170 $fieldData["TYPE"] = "S";
1171
1172 if($fields["row_count"] && $fields["col_count"])
1173 {
1174 $fieldData["ROW_COUNT"] = $fields["row_count"];
1175 $fieldData["COL_COUNT"] = $fields["col_count"];
1176 }
1177 else
1178 {
1179 $fieldData["ROW_COUNT"] = 1;
1180 $fieldData["COL_COUNT"] = 30;
1181 }
1182 }
1183 elseif($fields["type"] == "text")
1184 {
1185 $fieldData["TYPE"] = "S";
1186 if($fields["row_count"] && $fields["col_count"])
1187 {
1188 $fieldData["ROW_COUNT"] = $fields["row_count"];
1189 $fieldData["COL_COUNT"] = $fields["col_count"];
1190 }
1191 else
1192 {
1193 $fieldData["ROW_COUNT"] = 4;
1194 $fieldData["COL_COUNT"] = 30;
1195 }
1196 }
1197 elseif($fields["type"] == "int" || $fields["type"] == "double")
1198 {
1199 $fieldData["TYPE"] = "N";
1200 }
1201 elseif($fields["type"] == "bool")
1202 {
1203 $fieldData["TYPE"] = "L";
1204 $fieldData["VALUES"][] = array(
1205 "XML_ID" => 'Y',
1206 "VALUE" => GetMessage("BPVDX_YES"),
1207 "DEF" => "N",
1208 "SORT" => 10
1209 );
1210 $fieldData["VALUES"][] = array(
1211 "XML_ID" => 'N',
1212 "VALUE" => GetMessage("BPVDX_NO"),
1213 "DEF" => "N",
1214 "SORT" => 20
1215 );
1216 }
1217 else
1218 {
1219 $fieldData["TYPE"] = $fields["type"];
1220 $fieldData["USER_TYPE"] = false;
1221 }
1222
1223 $list = new CList($iblockId);
1224 $oldFields = $list->getFields();
1225 if(array_key_exists($fieldId, $oldFields))
1226 {
1227 if($oldFields[$fieldId]["TYPE"] != $fieldData["TYPE"])
1228 $fieldData["TYPE"] = $oldFields[$fieldId]["TYPE"];
1229 $fieldId = $list->updateField($fieldId, $fieldData);
1230 }
1231 else
1232 {
1233 $fieldId = $list->addField($fieldData);
1234 }
1235
1236 if($fieldId)
1237 {
1238 global $CACHE_MANAGER;
1239 $CACHE_MANAGER->clearByTag("lists_list_".$iblockId);
1240 return $fieldId;
1241 }
1242 }
1243
1244 return false;
1245 }
1246
1247 public static function updateDocument($documentId, $arFields)
1248 {
1249 $documentId = intval($documentId);
1250 if ($documentId <= 0)
1251 {
1252 throw new CBPArgumentNullException('documentId');
1253 }
1254
1255 CIBlockElement::WF_CleanUpHistoryCopies($documentId, 0);
1256
1257 $arFieldsPropertyValues = [];
1258
1259 $dbResult = CIBlockElement::GetList(
1260 [],
1261 ['ID' => $documentId, 'SHOW_NEW' => 'Y', 'SHOW_HISTORY' => 'Y'],
1262 false, false,
1263 ['ID', 'IBLOCK_ID']
1264 );
1265 $arResult = $dbResult->Fetch();
1266 if (!$arResult)
1267 {
1268 throw new Exception('Element is not found');
1269 }
1270
1271 $complexDocumentId = ['lists', get_called_class(), $documentId];
1272 $arDocumentFields = self::GetDocumentFields('iblock_' . $arResult['IBLOCK_ID']);
1273
1274 $arKeys = array_keys($arFields);
1275 foreach ($arKeys as $key)
1276 {
1277 if (!array_key_exists($key, $arDocumentFields))
1278 {
1279 continue;
1280 }
1281
1282 $arFields[$key] =
1283 (is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key]))
1284 ? $arFields[$key]
1285 : [$arFields[$key]];
1286 $realKey = (
1287 (mb_substr($key, 0, mb_strlen('PROPERTY_')) == 'PROPERTY_')
1288 ? mb_substr($key, mb_strlen('PROPERTY_'))
1289 : $key
1290 );
1291
1292 if ($arDocumentFields[$key]['Type'] == 'user')
1293 {
1294 $arFields[$key] = \CBPHelper::extractUsers($arFields[$key], $complexDocumentId);
1295 }
1296 elseif ($arDocumentFields[$key]['Type'] == 'select')
1297 {
1298 $arV = [];
1299 $db = CIBlockProperty::GetPropertyEnum(
1300 $realKey,
1301 false,
1302 ['IBLOCK_ID' => $arResult['IBLOCK_ID']]
1303 );
1304 while ($ar = $db->GetNext())
1305 {
1306 $arV[$ar['XML_ID']] = $ar['ID'];
1307 }
1308
1309 $listValue = [];
1310 foreach ($arFields[$key] as &$value)
1311 {
1312 if (is_array($value) && CBPHelper::isAssociativeArray($value))
1313 {
1314 $listXmlId = array_keys($value);
1315 foreach ($listXmlId as $xmlId)
1316 {
1317 $listValue[] = $arV[$xmlId];
1318 }
1319 }
1320 else
1321 {
1322 if (array_key_exists($value, $arV))
1323 {
1324 $value = $arV[$value];
1325 }
1326 }
1327 }
1328 if (!empty($listValue))
1329 {
1330 $arFields[$key] = $listValue;
1331 }
1332 }
1333 elseif ($arDocumentFields[$key]['Type'] == 'file')
1334 {
1335 $files = [];
1336 foreach ($arFields[$key] as $value)
1337 {
1338 if (is_array($value))
1339 {
1340 foreach ($value as $file)
1341 {
1342 $makeFileArray = CFile::MakeFileArray($file);
1343 if ($makeFileArray)
1344 {
1345 $files[] = $makeFileArray;
1346 }
1347 }
1348 }
1349 else
1350 {
1351 $makeFileArray = CFile::MakeFileArray($value);
1352 if ($makeFileArray)
1353 {
1354 $files[] = $makeFileArray;
1355 }
1356 }
1357 }
1358 if ($files)
1359 {
1360 $arFields[$key] = $files;
1361 }
1362 else
1363 {
1364 $arFields[$key] = [['del' => 'Y']];
1365 }
1366 }
1367 elseif ($arDocumentFields[$key]['Type'] == 'S:DiskFile')
1368 {
1369 foreach ($arFields[$key] as &$value)
1370 {
1371 if (!empty($value))
1372 {
1373 $value = 'n' . $value;
1374 }
1375 }
1376 $arFields[$key] = ['VALUE' => $arFields[$key], 'DESCRIPTION' => 'workflow'];
1377 }
1378 elseif ($arDocumentFields[$key]['Type'] == 'S:HTML')
1379 {
1380 foreach ($arFields[$key] as &$value)
1381 {
1382 $value = ['VALUE' => $value];
1383 }
1384 }
1385
1386 unset($value);
1387
1388 if (!$arDocumentFields[$key]["Multiple"] && is_array($arFields[$key]))
1389 {
1390 if (count($arFields[$key]) > 0)
1391 {
1392 $a = array_values($arFields[$key]);
1393 $arFields[$key] = $a[0];
1394 }
1395 else
1396 {
1397 $arFields[$key] = null;
1398 }
1399 }
1400
1401 if (mb_substr($key, 0, mb_strlen("PROPERTY_")) == "PROPERTY_")
1402 {
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]);
1409 }
1410 }
1411
1412 if (count($arFieldsPropertyValues) > 0)
1413 {
1414 $arFields['PROPERTY_VALUES'] = $arFieldsPropertyValues;
1415 }
1416
1417 $iblockElement = new CIBlockElement();
1418 if (isset($arFields['PROPERTY_VALUES']) && count($arFields['PROPERTY_VALUES']) > 0)
1419 {
1420 $iblockElement->SetPropertyValuesEx($documentId, $arResult['IBLOCK_ID'], $arFields['PROPERTY_VALUES']);
1421 }
1422
1423 unset($arFields['PROPERTY_VALUES']);
1424 $res = $iblockElement->Update($documentId, $arFields, false, true, true);
1425 if (!$res)
1426 {
1427 throw new Exception($iblockElement->LAST_ERROR);
1428 }
1429
1430 if (isset($arFields['BP_PUBLISHED']) && $arFields['BP_PUBLISHED'] === 'Y')
1431 {
1432 self::publishDocument($documentId);
1433 }
1434 elseif (isset($arFields['BP_PUBLISHED']) &&$arFields['BP_PUBLISHED'] === 'N')
1435 {
1436 self::unpublishDocument($documentId);
1437 }
1438
1439 if (CModule::includeModule('lists'))
1440 {
1441 CLists::rebuildSeachableContentForElement($arResult['IBLOCK_ID'], $documentId);
1442 }
1443 }
1444
1445 public static function onTaskChange($documentId, $taskId, $taskData, $status)
1446 {
1447 CListsLiveFeed::setMessageLiveFeed($taskData['USERS'] ?? null, $documentId, $taskData['WORKFLOW_ID'], false);
1448 if ($status == CBPTaskChangedStatus::Delegate)
1449 {
1450 $runtime = CBPRuntime::getRuntime();
1454 $stateService = $runtime->getService('StateService');
1455 $stateService->setStatePermissions(
1456 $taskData['WORKFLOW_ID'],
1457 array('R' => array('user_'.$taskData['USERS'][0])),
1458 array('setMode' => CBPSetPermissionsMode::Hold, 'setScope' => CBPSetPermissionsMode::ScopeDocument)
1459 );
1460 }
1461 }
1462
1469 public static function onWorkflowStatusChange($documentId, $workflowId, $status, $rootActivity)
1470 {
1471 if ($status == CBPWorkflowStatus::Completed)
1472 {
1473 CListsLiveFeed::setMessageLiveFeed(array(), $documentId, $workflowId, true);
1474 }
1475
1476 if($status == CBPWorkflowStatus::Terminated)
1477 {
1478 CLists::deleteSocnetLog(array($workflowId));
1479 }
1480
1481 if (
1482 $rootActivity
1483 && $status === \CBPWorkflowStatus::Running
1484 && !$rootActivity->workflow->isNew()
1485 )
1486 {
1487 $iblockTypeId = 'lists';
1488
1489 $elementQuery = CIBlockElement::getList(
1490 [],
1491 ['ID' => $documentId],
1492 false,
1493 false,
1494 ['IBLOCK_TYPE_ID']
1495 );
1496 if ($element = $elementQuery->fetch())
1497 {
1498 $iblockTypeId = $element['IBLOCK_TYPE_ID'];
1499 }
1500
1501 if (!\CLists::isBpFeatureEnabled($iblockTypeId))
1502 {
1503 throw new \Exception(Loc::getMessage('LISTS_BIZPROC_RESUME_RESTRICTED'));
1504 }
1505 }
1506 }
1507
1513 public static function getDocumentAdminPage($documentId)
1514 {
1515 $documentId = intval($documentId);
1516 if ($documentId <= 0)
1517 throw new CBPArgumentNullException("documentId");
1518
1519 $elementQuery = CIBlockElement::getList(
1520 array(),
1521 array("ID" => $documentId, "SHOW_NEW"=>"Y", "SHOW_HISTORY" => "Y"),
1522 false,
1523 false,
1524 array("ID", "IBLOCK_ID", "IBLOCK_TYPE_ID", "DETAIL_PAGE_URL")
1525 );
1526 if ($element = $elementQuery->fetch())
1527 {
1528 return COption::getOptionString('lists', 'livefeed_url').'?livefeed=y&list_id='.$element["IBLOCK_ID"].'&element_id='.$documentId;
1529 }
1530
1531 return null;
1532 }
1533
1534 protected static function getRightsTasks()
1535 {
1536 if (self::$cachedTasks === null)
1537 {
1538 $iterator = CTask::getList(
1539 array("LETTER"=>"asc"),
1540 array(
1541 "MODULE_ID" => "iblock",
1542 "BINDING" => "iblock"
1543 )
1544 );
1545
1546 while($ar = $iterator->fetch())
1547 {
1548 if ($ar['LETTER'] === '')
1549 {
1550 $ar['LETTER'] = $ar['ID'];
1551 }
1552 self::$cachedTasks[$ar["LETTER"]] = $ar;
1553 }
1554 }
1555 return self::$cachedTasks;
1556 }
1557
1563 public static function getAllowableOperations($documentType)
1564 {
1565 $iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
1566 if ($iblockId <= 0)
1567 throw new CBPArgumentOutOfRangeException("documentType", $documentType);
1568
1569 if (CIBlock::getArrayByID($iblockId, "RIGHTS_MODE") === "E")
1570 {
1571 $operations = array();
1572 $tasks = self::getRightsTasks();
1573
1574 foreach($tasks as $ar)
1575 {
1576 $key = empty($ar['LETTER']) ? $ar['ID'] : $ar['LETTER'];
1577 $operations[$key] = $ar['TITLE'];
1578 }
1579
1580 return $operations;
1581 }
1582 return parent::getAllowableOperations($documentType);
1583 }
1584
1590 public static function toInternalOperations($documentType, $permissions)
1591 {
1592 $permissions = (array) $permissions;
1593 $tasks = self::getRightsTasks();
1594
1595 $normalized = array();
1596 foreach ($permissions as $key => $value)
1597 {
1598 if (isset($tasks[$key]))
1599 $key = $tasks[$key]['ID'];
1600 $normalized[$key] = $value;
1601 }
1602
1603 return $normalized;
1604 }
1605
1611 public static function toExternalOperations($documentType, $permissions)
1612 {
1613 $permissions = (array) $permissions;
1614 $tasks = self::getRightsTasks();
1615 $letters = array();
1616 foreach ($tasks as $k => $t)
1617 {
1618 $letters[$t['ID']] = $k;
1619 }
1620 unset($tasks);
1621
1622 $normalized = array();
1623 foreach ($permissions as $key => $value)
1624 {
1625 if (isset($letters[$key]))
1626 $key = $letters[$key];
1627 $normalized[$key] = $value;
1628 }
1629
1630 return $normalized;
1631 }
1632
1633 public static function CanUserOperateDocument($operation, $userId, $documentId, $parameters = array())
1634 {
1635 $documentId = trim($documentId);
1636 if ($documentId == '')
1637 return false;
1638
1639 if (self::isAdmin())
1640 {
1641 return true;
1642 }
1643
1644 if (!array_key_exists("IBlockId", $parameters)
1645 && (
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")
1650 )
1651 || !array_key_exists("CreatedBy", $parameters) && !array_key_exists("AllUserGroups", $parameters))
1652 {
1653 if (empty(self::$elements[$documentId]))
1654 {
1655 $elementListQuery = CIBlockElement::getList(
1656 array(),
1657 array("ID" => $documentId, "SHOW_NEW" => "Y", "SHOW_HISTORY" => "Y"),
1658 false,
1659 false,
1660 array("ID", "IBLOCK_ID", "CREATED_BY")
1661 );
1662 self::$elements[$documentId] = $elementListQuery->fetch();
1663 }
1664
1665 if (empty(self::$elements[$documentId]))
1666 return false;
1667
1668 $element = self::$elements[$documentId];
1669
1670 $parameters["IBlockId"] = $element["IBLOCK_ID"];
1671 $parameters["CreatedBy"] = $element["CREATED_BY"];
1672 }
1673
1674 if (!array_key_exists("IBlockRightsMode", $parameters))
1675 $parameters["IBlockRightsMode"] = CIBlock::getArrayByID($parameters["IBlockId"], "RIGHTS_MODE");
1676
1677 if ($parameters["IBlockRightsMode"] === "E")
1678 {
1679 if (
1680 $operation === CBPCanUserOperateOperation::ReadDocument ||
1681 $operation === CBPCanUserOperateOperation::ViewWorkflow
1682 )
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)
1687 {
1688 if (CIBlockElementRights::userHasRightTo($parameters["IBlockId"], $documentId, "element_edit"))
1689 return true;
1690
1691 if (!array_key_exists("WorkflowId", $parameters))
1692 return false;
1693
1694 if (!CIBlockElementRights::userHasRightTo($parameters["IBlockId"], $documentId, "element_read"))
1695 return false;
1696
1697 $userId = intval($userId);
1698 if (!array_key_exists("AllUserGroups", $parameters))
1699 {
1700 if (!array_key_exists("UserGroups", $parameters))
1701 $parameters["UserGroups"] = CUser::getUserGroup($userId);
1702
1703 $parameters["AllUserGroups"] = $parameters["UserGroups"];
1704 if ($userId == $parameters["CreatedBy"])
1705 $parameters["AllUserGroups"][] = "Author";
1706 }
1707
1708 if (!array_key_exists("DocumentStates", $parameters))
1709 {
1710 if ($operation === CBPCanUserOperateOperation::StartWorkflow)
1711 $parameters["DocumentStates"] = CBPWorkflowTemplateLoader::getDocumentTypeStates(array('lists', get_called_class(), self::generateDocumentType($parameters["IBlockId"])));
1712 else
1713 $parameters["DocumentStates"] = CBPDocument::getDocumentStates(
1714 array('lists', get_called_class(), self::generateDocumentType($parameters["IBlockId"])),
1715 array('lists', get_called_class(), $documentId)
1716 );
1717 }
1718
1719 if (array_key_exists($parameters["WorkflowId"], $parameters["DocumentStates"]))
1720 $parameters["DocumentStates"] = array($parameters["WorkflowId"] => $parameters["DocumentStates"][$parameters["WorkflowId"]]);
1721 else
1722 return false;
1723
1724 $allowableOperations = CBPDocument::getAllowableOperations(
1725 $userId,
1726 $parameters["AllUserGroups"],
1727 $parameters["DocumentStates"],
1728 true
1729 );
1730
1731 if (!is_array($allowableOperations))
1732 return false;
1733
1734 if (($operation === CBPCanUserOperateOperation::ViewWorkflow) && in_array("read", $allowableOperations)
1735 || ($operation === CBPCanUserOperateOperation::StartWorkflow) && in_array("write", $allowableOperations))
1736 return true;
1737
1738 $chop = ($operation === CBPCanUserOperateOperation::ViewWorkflow) ? "element_read" : "element_edit";
1739
1740 $tasks = self::getRightsTasks();
1741 foreach ($allowableOperations as $op)
1742 {
1743 if (isset($tasks[$op]))
1744 $op = $tasks[$op]['ID'];
1745 $ar = CTask::getOperations($op, true);
1746 if (in_array($chop, $ar))
1747 return true;
1748 }
1749 }
1750 elseif ($operation === CBPCanUserOperateOperation::CreateWorkflow)
1751 {
1752 return CBPDocument::canUserOperateDocumentType(
1753 CBPCanUserOperateOperation::CreateWorkflow,
1754 $userId,
1755 array('lists', get_called_class(), $parameters['IBlockId']),
1756 $parameters
1757 );
1758 }
1759
1760 return false;
1761 }
1762
1763 if (!array_key_exists("IBlockPermission", $parameters))
1764 {
1765 if (CModule::includeModule('lists'))
1766 $parameters["IBlockPermission"] = CLists::getIBlockPermission($parameters["IBlockId"], $userId);
1767 else
1768 $parameters["IBlockPermission"] = CIBlock::getPermission($parameters["IBlockId"], $userId);
1769 }
1770
1771 if ($parameters["IBlockPermission"] <= "R")
1772 return false;
1773 elseif ($parameters["IBlockPermission"] >= "W")
1774 return true;
1775
1776 $userId = intval($userId);
1777 if (!array_key_exists("AllUserGroups", $parameters))
1778 {
1779 if (!array_key_exists("UserGroups", $parameters))
1780 $parameters["UserGroups"] = CUser::getUserGroup($userId);
1781
1782 $parameters["AllUserGroups"] = $parameters["UserGroups"];
1783 if ($userId == $parameters["CreatedBy"])
1784 $parameters["AllUserGroups"][] = "Author";
1785 }
1786
1787 if (!array_key_exists("DocumentStates", $parameters))
1788 {
1789 $parameters["DocumentStates"] = CBPDocument::getDocumentStates(
1790 array("lists", get_called_class(), "iblock_".$parameters["IBlockId"]),
1791 array('lists', get_called_class(), $documentId)
1792 );
1793 }
1794
1795 if (array_key_exists("WorkflowId", $parameters))
1796 {
1797 if (array_key_exists($parameters["WorkflowId"], $parameters["DocumentStates"]))
1798 $parameters["DocumentStates"] = array($parameters["WorkflowId"] => $parameters["DocumentStates"][$parameters["WorkflowId"]]);
1799 else
1800 return false;
1801 }
1802
1803 $allowableOperations = CBPDocument::getAllowableOperations(
1804 $userId,
1805 $parameters["AllUserGroups"],
1806 $parameters["DocumentStates"]
1807 );
1808
1809 if (!is_array($allowableOperations))
1810 return false;
1811
1812 $r = false;
1813 switch ($operation)
1814 {
1815 case CBPCanUserOperateOperation::ViewWorkflow:
1816 $r = in_array("read", $allowableOperations);
1817 break;
1818 case CBPCanUserOperateOperation::StartWorkflow:
1819 $r = in_array("write", $allowableOperations);
1820 break;
1821 case CBPCanUserOperateOperation::CreateWorkflow:
1822 $r = false;
1823 break;
1824 case CBPCanUserOperateOperation::WriteDocument:
1825 $r = in_array("write", $allowableOperations);
1826 break;
1827 case CBPCanUserOperateOperation::ReadDocument:
1828 $r = in_array("read", $allowableOperations) || in_array("write", $allowableOperations);
1829 break;
1830 default:
1831 $r = false;
1832 }
1833
1834 return $r;
1835 }
1836
1837 public static function CanUserOperateDocumentType($operation, $userId, $documentType, $parameters = array())
1838 {
1839 $documentType = trim($documentType);
1840 if ($documentType == '')
1841 return false;
1842
1843 if (self::isAdmin())
1844 {
1845 return true;
1846 }
1847
1848 if(is_numeric($documentType))
1849 $parameters["IBlockId"] = intval($documentType);
1850 else
1851 $parameters["IBlockId"] = intval(mb_substr($documentType, mb_strlen("iblock_")));
1852 $parameters['sectionId'] = !empty($parameters['sectionId']) ? (int)$parameters['sectionId'] : 0;
1853
1854 if (!array_key_exists("IBlockRightsMode", $parameters))
1855 $parameters["IBlockRightsMode"] = CIBlock::getArrayByID($parameters["IBlockId"], "RIGHTS_MODE");
1856
1857 if ($parameters["IBlockRightsMode"] === "E")
1858 {
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)
1865 {
1866 if ($operation === CBPCanUserOperateOperation::ViewWorkflow)
1867 {
1868 return (
1869 CIBlockRights::userHasRightTo($parameters["IBlockId"], 0, "element_read")
1870 || CIBlockRights::userHasRightTo($parameters["IBlockId"], $parameters["IBlockId"], "iblock_rights_edit")
1871 );
1872 }
1873
1874 if ($operation === CBPCanUserOperateOperation::StartWorkflow)
1875 return CIBlockSectionRights::userHasRightTo($parameters["IBlockId"], $parameters['sectionId'], "section_element_bind");
1876
1877
1878 $userId = intval($userId);
1879 if (!array_key_exists("AllUserGroups", $parameters))
1880 {
1881 if (!array_key_exists("UserGroups", $parameters))
1882 $parameters["UserGroups"] = CUser::getUserGroup($userId);
1883
1884 $parameters["AllUserGroups"] = $parameters["UserGroups"];
1885 $parameters["AllUserGroups"][] = "Author";
1886 }
1887
1888 if (!array_key_exists("DocumentStates", $parameters))
1889 {
1890 if ($operation === CBPCanUserOperateOperation::StartWorkflow)
1891 $parameters["DocumentStates"] = CBPWorkflowTemplateLoader::getDocumentTypeStates(array("lists", get_called_class(), "iblock_".$parameters["IBlockId"]));
1892 else
1893 $parameters["DocumentStates"] = CBPDocument::getDocumentStates(
1894 array("lists", get_called_class(), "iblock_".$parameters["IBlockId"]),
1895 null
1896 );
1897 }
1898
1899 if (array_key_exists($parameters["WorkflowId"], $parameters["DocumentStates"]))
1900 $parameters["DocumentStates"] = array($parameters["WorkflowId"] => $parameters["DocumentStates"][$parameters["WorkflowId"]]);
1901 else
1902 return false;
1903
1904 $allowableOperations = CBPDocument::getAllowableOperations(
1905 $userId,
1906 $parameters["AllUserGroups"],
1907 $parameters["DocumentStates"],
1908 true
1909 );
1910
1911 if (!is_array($allowableOperations))
1912 return false;
1913
1914 if (($operation === CBPCanUserOperateOperation::ViewWorkflow) && in_array("read", $allowableOperations)
1915 || ($operation === CBPCanUserOperateOperation::StartWorkflow) && in_array("write", $allowableOperations))
1916 return true;
1917
1918 $chop = ($operation === CBPCanUserOperateOperation::ViewWorkflow) ? "element_read" : "section_element_bind";
1919
1920 $tasks = self::getRightsTasks();
1921 foreach ($allowableOperations as $op)
1922 {
1923 if (isset($tasks[$op]))
1924 $op = $tasks[$op]['ID'];
1925 $ar = CTask::getOperations($op, true);
1926 if (in_array($chop, $ar))
1927 return true;
1928 }
1929 }
1930
1931 return false;
1932 }
1933
1934 if (!array_key_exists("IBlockPermission", $parameters))
1935 {
1936 if(CModule::includeModule('lists'))
1937 $parameters["IBlockPermission"] = CLists::getIBlockPermission($parameters["IBlockId"], $userId);
1938 else
1939 $parameters["IBlockPermission"] = CIBlock::getPermission($parameters["IBlockId"], $userId);
1940 }
1941
1942 if ($parameters["IBlockPermission"] <= "R")
1943 return false;
1944 elseif ($parameters["IBlockPermission"] >= "W")
1945 return true;
1946
1947 $userId = intval($userId);
1948 if (!array_key_exists("AllUserGroups", $parameters))
1949 {
1950 if (!array_key_exists("UserGroups", $parameters))
1951 $parameters["UserGroups"] = CUser::getUserGroup($userId);
1952
1953 $parameters["AllUserGroups"] = $parameters["UserGroups"];
1954 $parameters["AllUserGroups"][] = "Author";
1955 }
1956
1957 if (!array_key_exists("DocumentStates", $parameters))
1958 {
1959 $parameters["DocumentStates"] = CBPDocument::getDocumentStates(
1960 array("lists", get_called_class(), "iblock_".$parameters["IBlockId"]),
1961 null
1962 );
1963 }
1964
1965 if (array_key_exists("WorkflowId", $parameters))
1966 {
1967 if (array_key_exists($parameters["WorkflowId"], $parameters["DocumentStates"]))
1968 $parameters["DocumentStates"] = array($parameters["WorkflowId"] => $parameters["DocumentStates"][$parameters["WorkflowId"]]);
1969 else
1970 return false;
1971 }
1972
1973 $allowableOperations = CBPDocument::getAllowableOperations(
1974 $userId,
1975 $parameters["AllUserGroups"],
1976 $parameters["DocumentStates"]
1977 );
1978
1979 if (!is_array($allowableOperations))
1980 return false;
1981
1982 $r = false;
1983 switch ($operation)
1984 {
1985 case CBPCanUserOperateOperation::ViewWorkflow:
1986 $r = in_array("read", $allowableOperations);
1987 break;
1988 case CBPCanUserOperateOperation::StartWorkflow:
1989 $r = in_array("write", $allowableOperations);
1990 break;
1991 case CBPCanUserOperateOperation::CreateWorkflow:
1992 $r = in_array("write", $allowableOperations);
1993 break;
1994 case CBPCanUserOperateOperation::WriteDocument:
1995 $r = in_array("write", $allowableOperations);
1996 break;
1997 case CBPCanUserOperateOperation::ReadDocument:
1998 $r = false;
1999 break;
2000 default:
2001 $r = false;
2002 }
2003
2004 return $r;
2005 }
2006
2007 protected static function isAdmin()
2008 {
2009 global $USER;
2010 if (is_object($USER) && $USER->IsAuthorized())
2011 {
2012 if ($USER->IsAdmin() || CModule::IncludeModule("bitrix24") && CBitrix24::IsPortalAdmin($USER->GetID()))
2013 {
2014 return true;
2015 }
2016 }
2017
2018 return false;
2019 }
2020
2026 public static function GetAllowableUserGroups($documentType, $withExtended = false)
2027 {
2028 $documentType = trim($documentType);
2029 if ($documentType == '')
2030 return false;
2031
2032 $iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
2033
2034 $result = array("Author" => GetMessage("IBD_DOCUMENT_AUTHOR"));
2035
2036 $groupsId = array(1);
2037 $extendedGroupsCode = array();
2038 if(CIBlock::getArrayByID($iblockId, "RIGHTS_MODE") === "E")
2039 {
2040 $rights = new CIBlockRights($iblockId);
2041 foreach($rights->getGroups(/*"element_bizproc_start"*/) as $iblockGroupCode)
2042 if(preg_match("/^G(\\d+)\$/", $iblockGroupCode, $match))
2043 $groupsId[] = $match[1];
2044 else
2045 $extendedGroupsCode[] = $iblockGroupCode;
2046 }
2047 else
2048 {
2049 foreach(CIBlock::getGroupPermissions($iblockId) as $groupId => $perm)
2050 {
2051 if ($perm > "R")
2052 $groupsId[] = $groupId;
2053 }
2054 }
2055
2056 $groupsIterator = CGroup::getListEx(array("NAME" => "ASC"), array("ID" => $groupsId));
2057 while ($group = $groupsIterator->fetch())
2058 $result[$group["ID"]] = $group["NAME"];
2059
2060 if ($withExtended && $extendedGroupsCode)
2061 {
2062 foreach ($extendedGroupsCode as $groupCode)
2063 {
2064 $result['group_'.$groupCode] = CBPHelper::getExtendedGroupName($groupCode);
2065 }
2066 }
2067
2068 return $result;
2069 }
2070
2071 public static function SetPermissions($documentId, $workflowId, $permissions, $rewrite = true)
2072 {
2073 $permissions = self::toInternalOperations(null, $permissions);
2074 parent::setPermissions($documentId, $workflowId, $permissions, $rewrite);
2075 }
2076
2077 public static function GetFieldInputControl($documentType, $fieldType, $fieldName, $fieldValue, $allowSelection = false, $publicMode = false)
2078 {
2079 $iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
2080 if ($iblockId <= 0)
2081 throw new CBPArgumentOutOfRangeException("documentType", $documentType);
2082
2083 static $documentFieldTypes = array();
2084 if (!array_key_exists($documentType, $documentFieldTypes))
2085 $documentFieldTypes[$documentType] = self::getDocumentFieldTypes($documentType);
2086
2087 $fieldType["BaseType"] = "string";
2088 $fieldType["Complex"] = false;
2089 if (array_key_exists($fieldType["Type"], $documentFieldTypes[$documentType]))
2090 {
2091 $fieldType["BaseType"] = $documentFieldTypes[$documentType][$fieldType["Type"]]["BaseType"];
2092 $fieldType["Complex"] = $documentFieldTypes[$documentType][$fieldType["Type"]]["Complex"];
2093 }
2094
2095 if (!is_array($fieldValue) || is_array($fieldValue) && CBPHelper::isAssociativeArray($fieldValue))
2096 $fieldValue = array($fieldValue);
2097
2098 $customMethodName = "";
2099 $customMethodNameMulty = "";
2100 if (mb_strpos($fieldType["Type"], ":") !== false)
2101 {
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"];
2107 }
2108
2109 ob_start();
2110
2111 if ($fieldType["Type"] == "select")
2112 {
2113 $fieldValueTmp = $fieldValue;
2114 ?>
2115 <select id="id_<?= htmlspecialcharsbx($fieldName["Field"]) ?>" name="<?= htmlspecialcharsbx($fieldName["Field"]).($fieldType["Multiple"] ? "[]" : "") ?>"<?= ($fieldType["Multiple"] ? ' size="5" multiple' : '') ?>>
2116 <?
2117 if (!$fieldType["Required"])
2118 echo '<option value="">['.GetMessage("BPCGHLP_NOT_SET").']</option>';
2119 foreach ($fieldType["Options"] as $k => $v)
2120 {
2121 if (is_array($v) && count($v) == 2)
2122 {
2123 $v1 = array_values($v);
2124 $k = $v1[0];
2125 $v = $v1[1];
2126 }
2127
2128 $ind = array_search($k, $fieldValueTmp);
2129 echo '<option value="'.htmlspecialcharsbx($k).'"'.($ind !== false ? ' selected' : '').'>'.htmlspecialcharsbx($v).'</option>';
2130 if ($ind !== false)
2131 unset($fieldValueTmp[$ind]);
2132 }
2133 ?>
2134 </select>
2135 <?
2136 if ($allowSelection)
2137 {
2138 ?>
2139 <br /><input type="text" id="id_<?= htmlspecialcharsbx($fieldName["Field"]) ?>_text" name="<?= htmlspecialcharsbx($fieldName["Field"]) ?>_text" value="<?
2140 if (count($fieldValueTmp) > 0)
2141 {
2142 $a = array_values($fieldValueTmp);
2143 echo htmlspecialcharsbx($a[0]);
2144 }
2145 ?>">
2146 <input type="button" value="..." onclick="BPAShowSelector('id_<?= htmlspecialcharsbx($fieldName["Field"]) ?>_text', 'select');">
2147 <?
2148 }
2149 }
2150 elseif ($fieldType["Type"] == "user")
2151 {
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');"><?
2154 }
2155 elseif ((mb_strpos($fieldType["Type"], ":") !== false)
2156 && $fieldType["Multiple"]
2157 && (
2158 is_array($customMethodNameMulty) && count($customMethodNameMulty) > 0
2159 || !is_array($customMethodNameMulty) && $customMethodNameMulty <> ''
2160 )
2161 )
2162 {
2163 if (!is_array($fieldValue))
2164 $fieldValue = array();
2165
2166 if ($allowSelection)
2167 {
2168 $fieldValueTmp1 = array();
2169 $fieldValueTmp2 = array();
2170 foreach ($fieldValue as $v)
2171 {
2172 $vTrim = trim($v);
2173 if (\CBPDocument::IsExpression($vTrim))
2174 $fieldValueTmp1[] = $vTrim;
2175 else
2176 $fieldValueTmp2[] = $v;
2177 }
2178 }
2179 else
2180 {
2181 $fieldValueTmp1 = array();
2182 $fieldValueTmp2 = $fieldValue;
2183 }
2184
2185 if (($fieldType["Type"] == "S:employee") && COption::getOptionString("bizproc", "employee_compatible_mode", "N") != "Y")
2186 $fieldValueTmp2 = CBPHelper::stripUserPrefix($fieldValueTmp2);
2187
2188 foreach ($fieldValueTmp2 as &$fld)
2189 if (!isset($fld['VALUE']))
2190 $fld = array("VALUE" => $fld);
2191
2192 if ($fieldType["Type"] == "E:EList")
2193 {
2194 static $fl = true;
2195 if ($fl)
2196 {
2197 if (!empty($_SERVER['HTTP_BX_AJAX']))
2198 $GLOBALS["APPLICATION"]->showAjaxHead();
2199 $GLOBALS["APPLICATION"]->addHeadScript('/bitrix/js/iblock/iblock_edit.js');
2200 }
2201 $fl = false;
2202 }
2203 echo call_user_func_array(
2204 $customMethodNameMulty,
2205 array(
2206 array("LINK_IBLOCK_ID" => $fieldType["Options"]),
2207 $fieldValueTmp2,
2208 array(
2209 "FORM_NAME" => $fieldName["Form"],
2210 "VALUE" => htmlspecialcharsbx($fieldName["Field"])
2211 ),
2212 true
2213 )
2214 );
2215
2216 if ($allowSelection)
2217 {
2218 ?>
2219 <br /><input type="text" id="id_<?= htmlspecialcharsbx($fieldName["Field"]) ?>_text" name="<?= htmlspecialcharsbx($fieldName["Field"]) ?>_text" value="<?
2220 if (count($fieldValueTmp1) > 0)
2221 {
2222 $a = array_values($fieldValueTmp1);
2223 echo htmlspecialcharsbx($a[0]);
2224 }
2225 ?>">
2226 <input type="button" value="..." onclick="BPAShowSelector('id_<?= htmlspecialcharsbx($fieldName["Field"]) ?>_text', 'user', '<?= $fieldType["Type"] == 'S:employee'? 'employee' : '' ?>');">
2227 <?
2228 }
2229 }
2230 else
2231 {
2232 if (!array_key_exists("CBPVirtualDocumentCloneRowPrinted", $GLOBALS) && $fieldType["Multiple"])
2233 {
2234 $GLOBALS["CBPVirtualDocumentCloneRowPrinted"] = 1;
2235 ?>
2236 <script language="JavaScript">
2237 function CBPVirtualDocumentCloneRow(tableID)
2238 {
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;
2244 var p = 0;
2245 while (true)
2246 {
2247 var s = sHTML.indexOf('[n', p);
2248 if (s < 0)
2249 break;
2250 var e = sHTML.indexOf(']', s);
2251 if (e < 0)
2252 break;
2253 var n = parseInt(sHTML.substr(s + 2, e - s));
2254 sHTML = sHTML.substr(0, s) + '[n' + (++n) + ']' + sHTML.substr(e + 1);
2255 p = s + 1;
2256 }
2257 var p = 0;
2258 while (true)
2259 {
2260 var s = sHTML.indexOf('__n', p);
2261 if (s < 0)
2262 break;
2263 var e = sHTML.indexOf('_', s + 2);
2264 if (e < 0)
2265 break;
2266 var n = parseInt(sHTML.substr(s + 3, e - s));
2267 sHTML = sHTML.substr(0, s) + '__n' + (++n) + '_' + sHTML.substr(e + 1);
2268 p = e + 1;
2269 }
2270 oCell.innerHTML = sHTML;
2271 var patt = new RegExp('<' + 'script' + '>[^\000]*?<' + '\/' + 'script' + '>', 'ig');
2272 var code = sHTML.match(patt);
2273 if (code)
2274 {
2275 for (var i = 0; i < code.length; i++)
2276 {
2277 if (code[i] != '')
2278 {
2279 var s = code[i].substring(8, code[i].length - 9);
2280 jsUtils.EvalGlobal(s);
2281 }
2282 }
2283 }
2284 }
2285 function createAdditionalHtmlEditor(tableId)
2286 {
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(
2293 {
2294 'id':idEditor,
2295 'inputName':inputNameEditor,
2296 'content':'',
2297 'useFileDialogs':false,
2298 'width':'100%',
2299 'height':'200',
2300 'allowPhp':false,
2301 'limitPhpAccess':false,
2302 'templates':[],
2303 'templateId':'',
2304 'templateParams':[],
2305 'componentFilter':'',
2306 'snippets':[],
2307 'placeholder':'Text here...',
2308 'actionUrl':'/bitrix/tools/html_editor_action.php',
2309 'cssIframePath':'/bitrix/js/fileman/html_editor/iframe-style.css?1412693817',
2310 'bodyClass':'',
2311 'bodyId':'',
2312 'spellcheck_path':'/bitrix/js/fileman/html_editor/html-spell.js?v=1412693817',
2313 'usePspell':'N',
2314 'useCustomSpell':'Y',
2315 'bbCode':false,
2316 'askBeforeUnloadPage':true,
2317 'settingsKey':'user_settings_1',
2318 'showComponents':true,
2319 'showSnippets':true,
2320 'view':'wysiwyg',
2321 'splitVertical':false,
2322 'splitRatio':'1',
2323 'taskbarShown':false,
2324 'taskbarWidth':'250',
2325 'lastSpecialchars':false,
2326 'cleanEmptySpans':true,
2327 'lazyLoad':false,
2328 'showTaskbars':false,
2329 'showNodeNavi':false,
2330 'controlsMap':[
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'}],
2352 'autoResize':true,
2353 'autoResizeOffset':'40',
2354 'minBodyWidth':'350',
2355 'normalBodyWidth':'555'
2356 });
2357 var htmlEditor = BX.findChildrenByClassName(BX(tableId), 'bx-html-editor');
2358 for(var k in htmlEditor)
2359 {
2360 var editorId = htmlEditor[k].getAttribute('id');
2361 var frameArray = BX.findChildrenByClassName(BX(editorId), 'bx-editor-iframe');
2362 if(frameArray.length > 1)
2363 {
2364 for(var i = 0; i < frameArray.length - 1; i++)
2365 {
2366 frameArray[i].parentNode.removeChild(frameArray[i]);
2367 }
2368 }
2369
2370 }
2371 }
2372 </script>
2373 <?
2374 }
2375
2376 if ($fieldType["Multiple"])
2377 echo '<table width="100%" border="0" cellpadding="2" cellspacing="2" id="CBPVirtualDocument_'.htmlspecialcharsbx($fieldName["Field"]).'_Table">';
2378
2379 $fieldValueTmp = $fieldValue;
2380
2381 if (sizeof($fieldValue) == 0)
2382 $fieldValue[] = null;
2383
2384 $ind = -1;
2385 foreach ($fieldValue as $key => $value)
2386 {
2387 $ind++;
2388 $fieldNameId = 'id_'.htmlspecialcharsbx($fieldName["Field"]).'__n'.$ind.'_';
2389 $fieldNameName = htmlspecialcharsbx($fieldName["Field"]).($fieldType["Multiple"] ? "[n".$ind."]" : "");
2390
2391 if ($fieldType["Multiple"])
2392 echo '<tr><td>';
2393
2394 if (is_array($customMethodName) && count($customMethodName) > 0 || !is_array($customMethodName) && $customMethodName <> '')
2395 {
2396 if($fieldType["Type"] == "S:HTML")
2397 {
2398 if (Loader::includeModule("fileman"))
2399 {
2400 $editor = new CHTMLEditor;
2401 $res = array_merge(
2402 array(
2403 'useFileDialogs' => false,
2404 'height' => 200,
2405 'useFileDialogs' => false,
2406 'minBodyWidth' => 350,
2407 'normalBodyWidth' => 555,
2408 'bAllowPhp' => false,
2409 'limitPhpAccess' => false,
2410 'showTaskbars' => false,
2411 'showNodeNavi' => false,
2412 'askBeforeUnloadPage' => true,
2413 'bbCode' => false,
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)
2444 )
2445 ),
2446 array(
2447 'name' => $fieldNameName,
2448 'inputName' => $fieldNameName,
2449 'id' => $fieldNameId,
2450 'width' => '100%',
2451 'content' => htmlspecialcharsBack($value),
2452 )
2453 );
2454 $editor->show($res);
2455 }
2456 else
2457 {
2458 ?><textarea rows="5" cols="40" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>"><?= htmlspecialcharsbx($value) ?></textarea><?
2459 }
2460 }
2461 else
2462 {
2463 $value1 = $value;
2464 if ($allowSelection && \CBPDocument::IsExpression(trim($value1)))
2465 $value1 = null;
2466 else
2467 unset($fieldValueTmp[$key]);
2468
2469 if (($fieldType["Type"] == "S:employee") && COption::getOptionString("bizproc", "employee_compatible_mode", "N") != "Y")
2470 $value1 = CBPHelper::stripUserPrefix($value1);
2471
2472 echo call_user_func_array(
2473 $customMethodName,
2474 array(
2475 array("LINK_IBLOCK_ID" => $fieldType["Options"]),
2476 array("VALUE" => $value1),
2477 array(
2478 "FORM_NAME" => $fieldName["Form"],
2479 "VALUE" => $fieldNameName
2480 ),
2481 true
2482 )
2483 );
2484 }
2485 }
2486 else
2487 {
2488 switch ($fieldType["Type"])
2489 {
2490 case "int":
2491 case "double":
2492 unset($fieldValueTmp[$key]);
2493 ?><input type="text" size="10" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>" value="<?= htmlspecialcharsbx($value) ?>"><?
2494 break;
2495 case "file":
2496 if ($publicMode)
2497 {
2498 //unset($fieldValueTmp[$key]);
2499 ?><input type="file" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>"><?
2500 }
2501 break;
2502 case "bool":
2503 if (in_array($value, array("Y", "N")))
2504 unset($fieldValueTmp[$key]);
2505 ?>
2506 <select id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>">
2507 <?
2508 if (!$fieldType["Required"])
2509 echo '<option value="">['.GetMessage("BPCGHLP_NOT_SET").']</option>';
2510 ?>
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>
2513 </select>
2514 <?
2515 break;
2516 case "text":
2517 unset($fieldValueTmp[$key]);
2518 ?><textarea rows="5" cols="40" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>"><?= htmlspecialcharsbx($value) ?></textarea><?
2519 break;
2520 case "date":
2521 case "datetime":
2522 if (defined("ADMIN_SECTION") && ADMIN_SECTION)
2523 {
2524 $v = "";
2525 if (!\CBPDocument::IsExpression(trim($value)))
2526 {
2527 $v = $value;
2528 unset($fieldValueTmp[$key]);
2529 }
2530 require_once($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/interface/init_admin.php");
2531 echo CAdminCalendar::calendarDate($fieldNameName, $v, 19, ($fieldType["Type"] != "date"));
2532 }
2533 else
2534 {
2535 $value1 = $value;
2536 if ($allowSelection && \CBPDocument::IsExpression(trim($value1)))
2537 $value1 = null;
2538 else
2539 unset($fieldValueTmp[$key]);
2540
2541 if($fieldType["Type"] == "date")
2542 $type = "Date";
2543 else
2544 $type = "DateTime";
2545 $ar = CIBlockProperty::getUserType($type);
2546 echo call_user_func_array(
2547 $ar["GetPublicEditHTML"],
2548 array(
2549 array("LINK_IBLOCK_ID" => $fieldType["Options"]),
2550 array("VALUE" => $value1),
2551 array(
2552 "FORM_NAME" => $fieldName["Form"],
2553 "VALUE" => $fieldNameName
2554 ),
2555 true
2556 )
2557 );
2558 }
2559
2560 break;
2561 default:
2562 unset($fieldValueTmp[$key]);
2563 ?><input type="text" size="40" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>" value="<?= htmlspecialcharsbx($value) ?>"><?
2564 }
2565 }
2566
2567 if ($allowSelection)
2568 {
2569 if (!in_array($fieldType["Type"], array("file", "bool", "date", "datetime")) && (is_array($customMethodName) && count($customMethodName) <= 0 || !is_array($customMethodName) && $customMethodName == ''))
2570 {
2571 ?><input type="button" value="..." onclick="BPAShowSelector('<?= $fieldNameId ?>', '<?= htmlspecialcharsbx($fieldType["BaseType"]) ?>');"><?
2572 }
2573 }
2574
2575 if ($fieldType["Multiple"])
2576 echo '</td></tr>';
2577 }
2578
2579 if ($fieldType["Multiple"])
2580 echo "</table>";
2581
2582 if ($fieldType["Multiple"] && $fieldType["Type"] != "S:HTML" && (($fieldType["Type"] != "file") || $publicMode))
2583 {
2584 echo '<input type="button" value="'.GetMessage("BPCGHLP_ADD").'" onclick="CBPVirtualDocumentCloneRow(\'CBPVirtualDocument_'.$fieldName["Field"].'_Table\')"/><br />';
2585 }
2586 elseif($fieldType["Multiple"] && $fieldType["Type"] == "S:HTML")
2587 {
2588 $functionOnclick = 'CBPVirtualDocumentCloneRow(\'CBPVirtualDocument_'.$fieldName["Field"].'_Table\');createAdditionalHtmlEditor(\'CBPVirtualDocument_'.$fieldName["Field"].'_Table\');';
2589 echo '<input type="button" value="'.GetMessage("BPCGHLP_ADD").'" onclick="'.$functionOnclick.'"/><br />';
2590 }
2591
2592 if ($allowSelection)
2593 {
2594 if (in_array($fieldType["Type"], array("file", "bool", "date", "datetime")) || (is_array($customMethodName) && count($customMethodName) > 0 || !is_array($customMethodName) && $customMethodName <> ''))
2595 {
2596 ?>
2597 <input type="text" id="id_<?= htmlspecialcharsbx($fieldName["Field"]) ?>_text" name="<?= htmlspecialcharsbx($fieldName["Field"]) ?>_text" value="<?
2598 if (count($fieldValueTmp) > 0)
2599 {
2600 $a = array_values($fieldValueTmp);
2601 echo htmlspecialcharsbx($a[0]);
2602 }
2603 ?>">
2604 <input type="button" value="..." onclick="BPAShowSelector('id_<?= htmlspecialcharsbx($fieldName["Field"]) ?>_text', '<?= htmlspecialcharsbx($fieldType["BaseType"]) ?>', '<?= $fieldType["Type"] == 'S:employee'? 'employee' : '' ?>');">
2605 <?
2606 }
2607 }
2608 }
2609
2610 $s = ob_get_contents();
2611 ob_end_clean();
2612
2613 return $s;
2614 }
2615
2616 public static function GetFieldInputValue($documentType, $fieldType, $fieldName, $request, &$errors)
2617 {
2618 $iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
2619 if ($iblockId <= 0)
2620 throw new CBPArgumentOutOfRangeException("documentType", $documentType);
2621
2622 $result = array();
2623
2624 if ($fieldType["Type"] == "user")
2625 {
2626 $value = $request[$fieldName["Field"]];
2627 if ($value <> '')
2628 {
2629 $result = CBPHelper::usersStringToArray($value, array("lists", get_called_class(), $documentType), $errors);
2630 if (count($errors) > 0)
2631 {
2632 foreach ($errors as $e)
2633 $errors[] = $e;
2634 }
2635 }
2636 else
2637 $result = null;
2638 }
2639 elseif (array_key_exists($fieldName["Field"], $request) || array_key_exists($fieldName["Field"]."_text", $request))
2640 {
2641 $valueArray = array();
2642 if (array_key_exists($fieldName["Field"], $request))
2643 {
2644 $valueArray = $request[$fieldName["Field"]];
2645 if (!is_array($valueArray) || is_array($valueArray) && CBPHelper::isAssociativeArray($valueArray))
2646 $valueArray = array($valueArray);
2647 }
2648 if (array_key_exists($fieldName["Field"]."_text", $request))
2649 $valueArray[] = $request[$fieldName["Field"]."_text"];
2650
2651 foreach ($valueArray as $value)
2652 {
2653 if (is_array($value) || !is_array($value) && !\CBPDocument::IsExpression(trim($value)))
2654 {
2655 if ($fieldType["Type"] == "int")
2656 {
2657 if ($value <> '')
2658 {
2659 $value = str_replace(" ", "", str_replace(",", ".", $value));
2660 if (is_numeric($value))
2661 {
2662 $value = doubleval($value);
2663 }
2664 else
2665 {
2666 $value = null;
2667 $errors[] = array(
2668 "code" => "ErrorValue",
2669 "message" => GetMessage("LISTS_BIZPROC_INVALID_INT"),
2670 "parameter" => $fieldName["Field"],
2671 );
2672 }
2673 }
2674 else
2675 {
2676 $value = null;
2677 }
2678 }
2679 elseif ($fieldType["Type"] == "double")
2680 {
2681 if ($value <> '')
2682 {
2683 $value = str_replace(" ", "", str_replace(",", ".", $value));
2684 if (is_numeric($value))
2685 {
2686 $value = doubleval($value);
2687 }
2688 else
2689 {
2690 $value = null;
2691 $errors[] = array(
2692 "code" => "ErrorValue",
2693 "message" => GetMessage("LISTS_BIZPROC_INVALID_INT"),
2694 "parameter" => $fieldName["Field"],
2695 );
2696 }
2697 }
2698 else
2699 {
2700 $value = null;
2701 }
2702 }
2703 elseif ($fieldType["Type"] == "select")
2704 {
2705 if (!is_array($fieldType["Options"]) || count($fieldType["Options"]) <= 0 || $value == '')
2706 {
2707 $value = null;
2708 }
2709 else
2710 {
2711 $ar = array_values($fieldType["Options"]);
2712 if (is_array($ar[0]))
2713 {
2714 $b = false;
2715 foreach ($ar as $a)
2716 {
2717 if ($a[0] == $value)
2718 {
2719 $b = true;
2720 break;
2721 }
2722 }
2723 if (!$b)
2724 {
2725 $value = null;
2726 $errors[] = array(
2727 "code" => "ErrorValue",
2728 "message" => GetMessage("LISTS_BIZPROC_INVALID_SELECT"),
2729 "parameter" => $fieldName["Field"],
2730 );
2731 }
2732 }
2733 else
2734 {
2735 if (!array_key_exists($value, $fieldType["Options"]))
2736 {
2737 $value = null;
2738 $errors[] = array(
2739 "code" => "ErrorValue",
2740 "message" => GetMessage("LISTS_BIZPROC_INVALID_SELECT"),
2741 "parameter" => $fieldName["Field"],
2742 );
2743 }
2744 }
2745 }
2746 }
2747 elseif ($fieldType["Type"] == "bool")
2748 {
2749 if ($value !== "Y" && $value !== "N")
2750 {
2751 if ($value === true)
2752 {
2753 $value = "Y";
2754 }
2755 elseif ($value === false)
2756 {
2757 $value = "N";
2758 }
2759 elseif ($value <> '')
2760 {
2761 $value = mb_strtolower($value);
2762 if (in_array($value, array("y", "yes", "true", "1")))
2763 {
2764 $value = "Y";
2765 }
2766 elseif (in_array($value, array("n", "no", "false", "0")))
2767 {
2768 $value = "N";
2769 }
2770 else
2771 {
2772 $value = null;
2773 $errors[] = array(
2774 "code" => "ErrorValue",
2775 "message" => GetMessage("BPCGWTL_INVALID45"),
2776 "parameter" => $fieldName["Field"],
2777 );
2778 }
2779 }
2780 else
2781 {
2782 $value = null;
2783 }
2784 }
2785 }
2786 elseif ($fieldType["Type"] == "file")
2787 {
2788 if (is_array($value) && array_key_exists("name", $value) && $value["name"] <> '')
2789 {
2790 if (!array_key_exists("MODULE_ID", $value) || $value["MODULE_ID"] == '')
2791 $value["MODULE_ID"] = "bizproc";
2792
2793 $value = CFile::saveFile($value, "bizproc_wf", true, true);
2794 if (!$value)
2795 {
2796 $value = null;
2797 $errors[] = array(
2798 "code" => "ErrorValue",
2799 "message" => GetMessage("BPCGWTL_INVALID915"),
2800 "parameter" => $fieldName["Field"],
2801 );
2802 }
2803 }
2804 else
2805 {
2806 $value = null;
2807 }
2808 }
2809 elseif ($fieldType["Type"] == "date")
2810 {
2811 if ($value <> '')
2812 {
2813 if(!CheckDateTime($value, FORMAT_DATE))
2814 {
2815 $value = null;
2816 $errors[] = array(
2817 "code" => "ErrorValue",
2818 "message" => GetMessage("LISTS_BIZPROC_INVALID_DATE"),
2819 "parameter" => $fieldName["Field"],
2820 );
2821 }
2822 }
2823 else
2824 {
2825 $value = null;
2826 }
2827
2828 }
2829 elseif ($fieldType["Type"] == "datetime")
2830 {
2831 if ($value <> '')
2832 {
2833 $valueTemporary = array();
2834 $valueTemporary["VALUE"] = $value;
2835 $result = CIBlockPropertyDateTime::checkFields('', $valueTemporary);
2836 if (!empty($result))
2837 {
2838 $message = '';
2839 foreach ($result as $error)
2840 $message .= $error;
2841
2842 $value = null;
2843 $errors[] = array(
2844 "code" => "ErrorValue",
2845 "message" => $message,
2846 "parameter" => $fieldName["Field"],
2847 );
2848 }
2849 }
2850 else
2851 {
2852 $value = null;
2853 }
2854 }
2855 elseif (mb_strpos($fieldType["Type"], ":") !== false && $fieldType["Type"] != "S:HTML")
2856 {
2857 $customType = CIBlockProperty::getUserType(mb_substr($fieldType["Type"], 2));
2858 if (array_key_exists("GetLength", $customType))
2859 {
2860 if (call_user_func_array(
2861 $customType["GetLength"],
2862 array(
2863 array("LINK_IBLOCK_ID" => $fieldType["Options"]),
2864 array("VALUE" => $value)
2865 )
2866 ) <= 0)
2867 {
2868 $value = null;
2869 }
2870 }
2871
2872 if (($value != null) && array_key_exists("CheckFields", $customType))
2873 {
2874 $errorsTemporary = call_user_func_array(
2875 $customType["CheckFields"],
2876 array(
2877 array("LINK_IBLOCK_ID" => $fieldType["Options"]),
2878 array("VALUE" => $value)
2879 )
2880 );
2881 if (count($errorsTemporary) > 0)
2882 {
2883 $value = null;
2884 foreach ($errorsTemporary as $e)
2885 $errors[] = array(
2886 "code" => "ErrorValue",
2887 "message" => $e,
2888 "parameter" => $fieldName["Field"],
2889 );
2890 }
2891 }
2892 elseif (!array_key_exists("GetLength", $customType) && $value === '')
2893 $value = null;
2894
2895 if (
2896 $value !== null &&
2897 $fieldType["Type"] == "S:employee" &&
2898 COption::getOptionString("bizproc", "employee_compatible_mode", "N") != "Y"
2899 )
2900 {
2901 $value = "user_".$value;
2902 }
2903 }
2904 else
2905 {
2906 if (!is_array($value) && $value == '')
2907 $value = null;
2908 }
2909 }
2910
2911 if ($value !== null)
2912 $result[] = $value;
2913 }
2914 }
2915
2916 if (!$fieldType["Multiple"])
2917 {
2918 if (is_array($result) && count($result) > 0)
2919 $result = $result[0];
2920 else
2921 $result = null;
2922 }
2923
2924 return $result;
2925 }
2926
2927 public static function GetFieldInputValuePrintable($documentType, $fieldType, $fieldValue)
2928 {
2929 $result = $fieldValue;
2930
2931 switch ($fieldType['Type'])
2932 {
2933 case "user":
2934 if (!is_array($fieldValue))
2935 $fieldValue = array($fieldValue);
2936
2937 $result = CBPHelper::usersArrayToString($fieldValue, null, array("lists", get_called_class(), $documentType));
2938 break;
2939
2940 case "bool":
2941 if (is_array($fieldValue))
2942 {
2943 $result = array();
2944 foreach ($fieldValue as $r)
2945 $result[] = ((mb_strtoupper($r) != "N" && !empty($r)) ? GetMessage("BPVDX_YES") : GetMessage("BPVDX_NO"));
2946 }
2947 else
2948 {
2949 $result = ((mb_strtoupper($fieldValue) != "N" && !empty($fieldValue)) ? GetMessage("BPVDX_YES") : GetMessage("BPVDX_NO"));
2950 }
2951 break;
2952
2953 case "file":
2954 if (is_array($fieldValue))
2955 {
2956 $result = array();
2957 foreach ($fieldValue as $r)
2958 {
2959 $r = intval($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]";
2963 }
2964 }
2965 else
2966 {
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]";
2971 }
2972 break;
2973
2974 case "select":
2975 if (is_array($fieldType["Options"]))
2976 {
2977 if (is_array($fieldValue))
2978 {
2979 $result = array();
2980 foreach ($fieldValue as $r)
2981 {
2982 if (array_key_exists($r, $fieldType["Options"]))
2983 $result[] = $fieldType["Options"][$r];
2984 }
2985 }
2986 else
2987 {
2988 if (array_key_exists($fieldValue, $fieldType["Options"]))
2989 $result = $fieldType["Options"][$fieldValue];
2990 }
2991 }
2992 break;
2993 }
2994
2995 if (mb_strpos($fieldType['Type'], ":") !== false)
2996 {
2997 if ($fieldType["Type"] == "S:employee")
2998 $fieldValue = CBPHelper::stripUserPrefix($fieldValue);
2999
3000 $customType = CIBlockProperty::getUserType(mb_substr($fieldType['Type'], 2));
3001 if (array_key_exists("GetPublicViewHTML", $customType))
3002 {
3003 if (is_array($fieldValue) && !CBPHelper::isAssociativeArray($fieldValue))
3004 {
3005 $result = array();
3006 foreach ($fieldValue as $value)
3007 {
3008 $r = call_user_func_array(
3009 $customType["GetPublicViewHTML"],
3010 array(
3011 array("LINK_IBLOCK_ID" => $fieldType["Options"]),
3012 array("VALUE" => $value),
3013 ""
3014 )
3015 );
3016
3017 $result[] = HTMLToTxt($r);
3018 }
3019 }
3020 else
3021 {
3022 $result = call_user_func_array(
3023 $customType["GetPublicViewHTML"],
3024 array(
3025 array("LINK_IBLOCK_ID" => $fieldType["Options"]),
3026 array("VALUE" => $fieldValue),
3027 ""
3028 )
3029 );
3030
3031 $result = HTMLToTxt($result);
3032 }
3033 }
3034 }
3035
3036 return $result;
3037 }
3038
3039 public static function UnlockDocument($documentId, $workflowId)
3040 {
3041 global $DB;
3042
3043 $strSql = "
3044 SELECT * FROM b_iblock_element_lock
3045 WHERE IBLOCK_ELEMENT_ID = ".intval($documentId)."
3046 ";
3047 $query = $DB->query($strSql, false, "FILE: ".__FILE__."<br>LINE: ".__LINE__);
3048 if($query->fetch())
3049 {
3050 $strSql = "
3051 DELETE FROM b_iblock_element_lock
3052 WHERE IBLOCK_ELEMENT_ID = ".intval($documentId)."
3053 AND (LOCKED_BY = '".$DB->forSQL($workflowId, 32)."' OR '".$DB->forSQL($workflowId, 32)."' = '')
3054 ";
3055 $query = $DB->query($strSql, false, "FILE: ".__FILE__."<br>LINE: ".__LINE__);
3056 $result = $query->affectedRowsCount();
3057 }
3058 else
3059 {//Success unlock when there is no locks at all
3060 $result = 1;
3061 }
3062
3063 if ($result > 0)
3064 {
3065 foreach (GetModuleEvents("iblock", "CIBlockDocument_OnUnlockDocument", true) as $event)
3066 {
3067 ExecuteModuleEventEx($event, array(array("lists", get_called_class(), $documentId)));
3068 }
3069 }
3070
3071 return $result > 0;
3072 }
3073
3079 public static function PublishDocument($documentId)
3080 {
3081 global $DB;
3082 $ID = intval($documentId);
3083
3084 $elementQuery = CIBlockElement::getList(array(), array("ID"=>$ID, "SHOW_HISTORY"=>"Y"), false, false,
3085 array(
3086 "ID",
3087 "TIMESTAMP_X",
3088 "MODIFIED_BY",
3089 "DATE_CREATE",
3090 "CREATED_BY",
3091 "IBLOCK_ID",
3092 "ACTIVE",
3093 "ACTIVE_FROM",
3094 "ACTIVE_TO",
3095 "SORT",
3096 "NAME",
3097 "PREVIEW_PICTURE",
3098 "PREVIEW_TEXT",
3099 "PREVIEW_TEXT_TYPE",
3100 "DETAIL_PICTURE",
3101 "DETAIL_TEXT",
3102 "DETAIL_TEXT_TYPE",
3103 "WF_STATUS_ID",
3104 "WF_PARENT_ELEMENT_ID",
3105 "WF_NEW",
3106 "WF_COMMENTS",
3107 "IN_SECTIONS",
3108 "CODE",
3109 "TAGS",
3110 "XML_ID",
3111 "TMP_ID",
3112 )
3113 );
3114 if($element = $elementQuery->fetch())
3115 {
3116 $parentId = intval($element["WF_PARENT_ELEMENT_ID"]);
3117 if($parentId)
3118 {
3119 $elementObject = new CIBlockElement;
3120 $element["WF_PARENT_ELEMENT_ID"] = false;
3121
3122 if($element["PREVIEW_PICTURE"])
3123 $element["PREVIEW_PICTURE"] = CFile::makeFileArray($element["PREVIEW_PICTURE"]);
3124 else
3125 $element["PREVIEW_PICTURE"] = array("tmp_name" => "", "del" => "Y");
3126
3127 if($element["DETAIL_PICTURE"])
3128 $element["DETAIL_PICTURE"] = CFile::makeFileArray($element["DETAIL_PICTURE"]);
3129 else
3130 $element["DETAIL_PICTURE"] = array("tmp_name" => "", "del" => "Y");
3131
3132 $element["IBLOCK_SECTION"] = array();
3133 if($element["IN_SECTIONS"] == "Y")
3134 {
3135 $sectionsQuery = CIBlockElement::getElementGroups($element["ID"], true, array('ID', 'IBLOCK_ELEMENT_ID'));
3136 while($section = $sectionsQuery->fetch())
3137 $element["IBLOCK_SECTION"][] = $section["ID"];
3138 }
3139
3140 $element["PROPERTY_VALUES"] = array();
3141 $props = &$element["PROPERTY_VALUES"];
3142
3143 //Delete old files
3144 $propsQuery = CIBlockElement::getProperty($element["IBLOCK_ID"], $parentId, array("value_id" => "asc"), array("PROPERTY_TYPE" => "F", "EMPTY" => "N"));
3145 while($prop = $propsQuery->fetch())
3146 {
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,
3152 );
3153 }
3154
3155 //Add new proiperty values
3156 $propsQuery = CIBlockElement::getProperty($element["IBLOCK_ID"], $element["ID"], array("value_id" => "asc"));
3157 $i = 0;
3158 while($prop = $propsQuery->fetch())
3159 {
3160 $i++;
3161 if(!array_key_exists($prop["ID"], $props))
3162 $props[$prop["ID"]] = array();
3163
3164 if($prop["PROPERTY_VALUE_ID"])
3165 {
3166 if($prop["PROPERTY_TYPE"] == "F")
3167 $props[$prop["ID"]]["n".$i] = array(
3168 "VALUE" => CFile::makeFileArray($prop["VALUE"]),
3169 "DESCRIPTION" => $prop["DESCRIPTION"],
3170 );
3171 else
3172 $props[$prop["ID"]]["n".$i] = array(
3173 "VALUE" => $prop["VALUE"],
3174 "DESCRIPTION" => $prop["DESCRIPTION"],
3175 );
3176 }
3177 }
3178
3179 $elementObject->update($parentId, $element);
3180 CBPDocument::mergeDocuments(
3181 array("lists", get_called_class(), $parentId),
3182 array("lists", get_called_class(), $documentId)
3183 );
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);
3189 return $parentId;
3190 }
3191 else
3192 {
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);
3197 return $ID;
3198 }
3199 }
3200 return false;
3201 }
3202
3210 public static function GetDocumentForHistory($documentId, $historyIndex)
3211 {
3212 $documentId = intval($documentId);
3213 if ($documentId <= 0)
3214 throw new CBPArgumentNullException("documentId");
3215
3216 $result = null;
3217
3218 $dbDocumentList = CIBlockElement::getList(
3219 array(),
3220 array("ID" => $documentId, "SHOW_NEW"=>"Y", "SHOW_HISTORY" => "Y")
3221 );
3222 if ($objDocument = $dbDocumentList->getNextElement())
3223 {
3224 $fields = $objDocument->getFields();
3225 $properties = $objDocument->getProperties();
3226
3227 $result["NAME"] = $fields["~NAME"];
3228
3229 $result["FIELDS"] = array();
3230 foreach ($fields as $fieldKey => $fieldValue)
3231 {
3232 if ($fieldKey == "~PREVIEW_PICTURE" || $fieldKey == "~DETAIL_PICTURE")
3233 {
3234 $result["FIELDS"][mb_substr($fieldKey, 1)] = CBPDocument::prepareFileForHistory(
3235 array("lists", get_called_class(), $documentId),
3236 $fieldValue,
3237 $historyIndex
3238 );
3239 }
3240 elseif (mb_substr($fieldKey, 0, 1) == "~")
3241 {
3242 $result["FIELDS"][mb_substr($fieldKey, 1)] = $fieldValue;
3243 }
3244 }
3245
3246 $result["PROPERTIES"] = array();
3247 foreach ($properties as $propertyKey => $propertyValue)
3248 {
3249 if ($propertyValue["USER_TYPE"] <> '')
3250 {
3251 $result["PROPERTIES"][$propertyKey] = array(
3252 "VALUE" => $propertyValue["VALUE"],
3253 "DESCRIPTION" => $propertyValue["DESCRIPTION"]
3254 );
3255 }
3256 elseif ($propertyValue["PROPERTY_TYPE"] == "L")
3257 {
3258 $result["PROPERTIES"][$propertyKey] = array(
3259 "VALUE" => $propertyValue["VALUE_ENUM_ID"],
3260 "DESCRIPTION" => $propertyValue["DESCRIPTION"]
3261 );
3262 }
3263 elseif ($propertyValue["PROPERTY_TYPE"] == "F")
3264 {
3265 $result["PROPERTIES"][$propertyKey] = array(
3266 "VALUE" => CBPDocument::prepareFileForHistory(
3267 array("lists", get_called_class(), $documentId),
3268 $propertyValue["VALUE"],
3269 $historyIndex
3270 ),
3271 "DESCRIPTION" => $propertyValue["DESCRIPTION"]
3272 );
3273 }
3274 else
3275 {
3276 $result["PROPERTIES"][$propertyKey] = array(
3277 "VALUE" => $propertyValue["VALUE"],
3278 "DESCRIPTION" => $propertyValue["DESCRIPTION"]
3279 );
3280 }
3281 }
3282 }
3283
3284 return $result;
3285 }
3286
3287 public static function isFeatureEnabled($documentType, $feature)
3288 {
3289 return in_array($feature, array(\CBPDocumentService::FEATURE_MARK_MODIFIED_FIELDS));
3290 }
3291}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getDocumentIcon($documentId)
static getDocument($documentId)
static generateMnemonicCode($integerCode=0)
static generateDocumentType($iblockId)
static getSystemIblockFields()
static updateDocumentField($documentType, $fields)
static PublishDocument($documentId)
static CanUserOperateDocumentType($operation, $userId, $documentType, $parameters=array())
static getDocumentComplexId($iblockType, $documentId)
static setArray(array $result, $value)
static generateDocumentComplexType($iblockType, $iblockId)
static CanUserOperateDocument($operation, $userId, $documentId, $parameters=array())
static GetFieldInputControl($documentType, $fieldType, $fieldName, $fieldValue, $allowSelection=false, $publicMode=false)
static GetFieldInputValuePrintable($documentType, $fieldType, $fieldValue)
static getDocumentFields($documentType)
static SetPermissions($documentId, $workflowId, $permissions, $rewrite=true)
static deleteDataIblock($iblockId)
static addDocumentField($documentType, $fields)
static isFeatureEnabled($documentType, $feature)
static getAllowableOperations($documentType)
static toExternalOperations($documentType, $permissions)
static onWorkflowStatusChange($documentId, $workflowId, $status, $rootActivity)
static GetDocumentForHistory($documentId, $historyIndex)
static UnlockDocument($documentId, $workflowId)
static updateDocument($documentId, $arFields)
static getDocumentAdminPage($documentId)
static toInternalOperations($documentType, $permissions)
static GetAllowableUserGroups($documentType, $withExtended=false)
static GetFieldInputValue($documentType, $fieldType, $fieldName, $request, &$errors)
static setMessageLiveFeed($users, $elementId, $workflowId, $flagCompleteProcess)
Definition livefeed.php:9