1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
field.php
См. документацию.
1<?php
2
3namespace Bitrix\Lists;
4
5use Bitrix\Crm\UserField\Types\ElementType;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Main\Config\Option;
8use Bitrix\Main\Loader;
9use Bitrix\Main\Text\HtmlFilter;
10use Bitrix\Main\Type\RandomSequence;
11
12Loc::loadMessages(__FILE__);
13
20class Field
21{
22 protected static $cache = array();
23 protected static $separator = '<br>';
24 protected static $renderForForm = false;
25
32 public static function renderField(array $field)
33 {
34 $result = '';
35 $controlSettings = !empty($field['CONTROL_SETTINGS']) ? $field['CONTROL_SETTINGS'] : array();
36
37 if(!empty($field['DEFAULT']))
38 {
39 $field['VALUE'] = $field['DEFAULT_VALUE'];
40 if(in_array($field['TYPE'], array('S:DiskFile')))
41 {
42 $renderMethod = 'renderCustomDefaultValue'.$field['PROPERTY_USER_TYPE']['USER_TYPE'];
43 return self::$renderMethod($field);
44 }
45 }
46
47 if(!empty($field['SEPARATOR']))
48 {
49 self::$separator = $field['SEPARATOR'];
50 }
51
52 if(self::$renderForForm && isset($field['CURRENT_VALUE']))
53 {
54 $field['VALUE'] = $field['CURRENT_VALUE'];
55 }
56
57 if(isset($field['PROPERTY_USER_TYPE']['USER_TYPE'])
58 && method_exists(__CLASS__, 'renderFieldByUserType'.$field['PROPERTY_USER_TYPE']['USER_TYPE']))
59 {
60 $renderMethod = 'renderFieldByUserType'.$field['PROPERTY_USER_TYPE']['USER_TYPE'];
61 $result = self::$renderMethod($field);
62 }
63 elseif(isset($field['PROPERTY_USER_TYPE']['GetPublicViewHTMLMulty']))
64 {
65 $result = call_user_func_array(
66 $field['PROPERTY_USER_TYPE']['GetPublicViewHTMLMulty'], array($field, $field, $controlSettings));
67 }
68 elseif(isset($field['PROPERTY_USER_TYPE']['GetPublicViewHTML']))
69 {
70 if($field['MULTIPLE'] === 'Y' && is_array($field['VALUE']))
71 {
72 $results = array();
73 if(\CLists::isAssociativeArray($field['VALUE']))
74 {
75 $result = call_user_func_array(
76 $field['PROPERTY_USER_TYPE']['GetPublicViewHTML'], array($field, $field, $controlSettings));
77 }
78 else
79 {
80 foreach($field['VALUE'] as $value)
81 {
82 $fieldParam = array('VALUE' => $value);
83 $results[] = call_user_func_array($field['PROPERTY_USER_TYPE']['GetPublicViewHTML'],
84 array($field, $fieldParam, $controlSettings));
85 }
86 $result = implode(self::$separator, $results);
87 }
88 }
89 else
90 {
91 $result = call_user_func_array(
92 $field['PROPERTY_USER_TYPE']['GetPublicViewHTML'], array($field, $field, $controlSettings));
93 }
94
95 if ($field['TYPE'] == 'S:DiskFile' && ($field['READ'] ?? '') == 'Y')
96 {
97 $field['VALUE'] = array_filter((is_array($field['VALUE']) ? $field['VALUE'] : array($field['VALUE'])));
98 foreach ($field['VALUE'] as $key => $value)
99 {
100 $result .= '<input type="hidden" name="'.$field['FIELD_ID'].'[n'.$key.'][VALUE][]" value="'.HtmlFilter::encode($value).'">';
101 }
102 }
103 }
104 elseif($field['PROPERTY_TYPE'] != '')
105 {
106 $renderMethod = 'renderFieldByType'.$field['PROPERTY_TYPE'];
107 if(method_exists(__CLASS__, $renderMethod))
108 {
109 $result = self::$renderMethod($field);
110 }
111 }
112 elseif($field['TYPE'] != '')
113 {
114 $renderMethod = 'renderFieldByField'.str_replace('_', '', $field['TYPE']);
115 if(method_exists(__CLASS__, $renderMethod))
116 {
117 $result = self::$renderMethod($field);
118 }
119 else
120 {
121 $result = self::renderDefaultField($field);
122 }
123 }
124
125 return $result;
126 }
127
128 public static function prepareFieldDataForEditForm(array $field)
129 {
130 $result = ['customHtml' => ''];
131
132 self::$renderForForm = true;
133
134 $field['SHOW'] = 'Y';
135 if (!empty($field['ELEMENT_ID']) && !empty($field['SETTINGS']['SHOW_EDIT_FORM']))
136 {
137 $field['SHOW'] = $field['SETTINGS']['SHOW_EDIT_FORM'];
138 }
139 if (empty($field['ELEMENT_ID']) && !empty($field['SETTINGS']['SHOW_ADD_FORM']))
140 {
141 $field['SHOW'] = $field['SETTINGS']['SHOW_ADD_FORM'];
142 }
143
144 $field['READ'] = 'N';
145 if (!empty($field['ELEMENT_ID']) && !empty($field['SETTINGS']['EDIT_READ_ONLY_FIELD']))
146 {
147 $field['READ'] = $field['SETTINGS']['EDIT_READ_ONLY_FIELD'];
148 }
149 if (empty($field['ELEMENT_ID']) && !empty($field['SETTINGS']['ADD_READ_ONLY_FIELD']))
150 {
151 $field['READ'] = $field['SETTINGS']['ADD_READ_ONLY_FIELD'];
152 }
153
154 if ($field['TYPE'] === 'S:employee')
155 {
156 $field['SETTINGS']['USE_ENTITY_SELECTOR'] = 'Y';
157 }
158
159 if(isset($field['PROPERTY_USER_TYPE']['USER_TYPE']) && method_exists(
160 __CLASS__, 'prepareEditFieldByUserType'.$field['PROPERTY_USER_TYPE']['USER_TYPE']))
161 {
162 $prepareEditMethod = 'prepareEditFieldByUserType'.$field['PROPERTY_USER_TYPE']['USER_TYPE'];
163 $result = self::$prepareEditMethod($field);
164 }
165 elseif(isset($field['PROPERTY_USER_TYPE']['GetPublicEditHTMLMulty']) && $field['MULTIPLE'] == 'Y')
166 {
167 if(!is_array($field['VALUE']))
168 $field['VALUE'] = array($field['VALUE']);
169 $html = '';
170 $isEmptyValue = true;
171 foreach($field['VALUE'] as $key => $value)
172 {
173 if($field['READ'] == 'Y')
174 {
175 if(empty($value['VALUE']))
176 {
177 continue;
178 }
179 else
180 {
181 $isEmptyValue = false;
182 $field['CURRENT_VALUE'] = $value['VALUE'];
183 $html .= ' '.self::renderField($field);
184 }
185 $value['VALUE'] = (!is_array($value['VALUE']) ? [$value['VALUE']] : $value['VALUE']);
186 foreach ($value['VALUE'] as $innerKey => $innerValue)
187 {
188 $result['customHtml'] .= '<input type="hidden" name="'.
189 $field['FIELD_ID'].'[n'.$innerKey.'][VALUE]" value="'.HtmlFilter::encode($innerValue).'">';
190 }
191 }
192 }
193 if($field['READ'] == 'N')
194 {
195 $html .= call_user_func_array(
196 $field['PROPERTY_USER_TYPE']['GetPublicEditHTMLMulty'],
197 [
198 $field,
199 $field['VALUE'],
200 [
201 'VALUE' => $field['FIELD_ID'],
202 'DESCRIPTION' => '',
203 'FORM_NAME' => 'form_' . ($field['FORM_ID'] ?? ''),
204 'MODE' => 'FORM_FILL',
205 ],
206 ]
207 );
208 }
209 else
210 {
211 if($isEmptyValue)
212 $html .= Loc::getMessage('LISTS_FIELD_NOT_DATA');
213 }
214 $result['id'] = $field['FIELD_ID'];
215 $result['name'] = $field['NAME'];
216 $result['required'] = $field['IS_REQUIRED'] == 'Y' ? true : false;
217 $result['type'] = 'custom';
218 $result['value'] = $html;
219 $result['show'] = $field['SHOW'];
220 }
221 elseif(isset($field['PROPERTY_USER_TYPE']['GetPublicEditHTML']))
222 {
223 $listTypeNotMultiple = array('S:DiskFile', 'S:ECrm');
224 if (!isset($field['VALUE']) || !is_array($field['VALUE']))
225 {
226 $field['VALUE'] = [$field['VALUE'] ?? null];
227 }
228
229 if($field['MULTIPLE'] == 'Y' && !in_array($field['TYPE'], $listTypeNotMultiple))
230 {
231 $html = '<table id="tbl'.$field['FIELD_ID'].'">';
232 $isEmptyValue = true;
233 foreach($field['VALUE'] as $key => $value)
234 {
235 if($field['READ'] == 'Y')
236 {
237 if(empty($value['VALUE']))
238 {
239 continue;
240 }
241 else
242 {
243 $isEmptyValue = false;
244 $field['CURRENT_VALUE'] = $value['VALUE'];
245 $html .= '<tr><td>' . self::renderField($field).'</td></tr>';
246 }
247 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].
248 '['.$key.'][VALUE]" value="'.HtmlFilter::encode($value['VALUE']).'">';
249 }
250 else
251 {
252 $html .= '<tr><td>'.call_user_func_array($field['PROPERTY_USER_TYPE']['GetPublicEditHTML'],
253 array(
254 $field,
255 $value,
256 array(
257 'VALUE' => $field['FIELD_ID']."[".$key."][VALUE]",
258 'DESCRIPTION' => '',
259 'FORM_NAME' => 'form_' . ($field['FORM_ID'] ?? ''),
260 'MODE' => "FORM_FILL",
261 'COPY' => $field['COPY_ID'] > 0,
262 )
263 )).'</td></tr>';
264 }
265 }
266 if($field['READ'] == 'Y')
267 {
268 if($isEmptyValue)
269 $html .= Loc::getMessage('LISTS_FIELD_NOT_DATA');
270 }
271 $html .= '</table>';
272 if($field['READ'] == 'N')
273 {
274 $regExp = '/'.$field['FIELD_ID'].'\[(n)([0-9]*)\]/g';
275 $html .= '<input type="button" value="'.Loc::getMessage("LISTS_FIELD_ADD_BUTTON").'"
276 onclick="BX.Lists.addNewTableRow(\'tbl'.$field['FIELD_ID'].
277 '\', 1, '.HtmlFilter::encode($regExp).', 2)">';
278 }
279 }
280 else
281 {
282 $html = '';
283 $isEmptyValue = true;
284 foreach($field['VALUE'] as $key => $value)
285 {
286 if($field['READ'] == 'Y')
287 {
288 if(empty($value['VALUE']))
289 {
290 continue;
291 }
292 else
293 {
294 $isEmptyValue = false;
295 $field['CURRENT_VALUE'] = $value['VALUE'];
296 $html .= ' '.self::renderField($field);
297 }
298 if(!is_array($value['VALUE']))
299 {
300 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].
301 '['.$key.'][VALUE]" value="'.HtmlFilter::encode($value['VALUE']).'">';
302 }
303 }
304 else
305 {
306 if ($field['TYPE'] == 'S:DiskFile')
307 {
308 $html .= call_user_func_array($field['PROPERTY_USER_TYPE']['GetPublicViewHTML'],
309 array($field, $value, array()));
310 }
311 $html .= call_user_func_array($field['PROPERTY_USER_TYPE']['GetPublicEditHTML'],
312 array(
313 $field,
314 $value,
315 array(
316 'VALUE' => $field['FIELD_ID']."[".$key."][VALUE]",
317 'DESCRIPTION' => '',
318 'FORM_NAME' => 'form_' . ($field['FORM_ID'] ?? ''),
319 'MODE' => 'FORM_FILL',
320 'COPY' => $field['COPY_ID'] > 0,
321 ),
322 ));
323 }
324 break;
325 }
326 if($field['READ'] == 'Y')
327 {
328 if($isEmptyValue)
329 $html .= Loc::getMessage('LISTS_FIELD_NOT_DATA');
330 }
331 }
332 $result['id'] = $field['FIELD_ID'];
333 $result['name'] = $field['NAME'];
334 $result['required'] = $field['IS_REQUIRED'] == 'Y' ? true: false;
335 $result['type'] = 'custom';
336 $result['value'] = $html;
337 $result['show'] = $field['SHOW'];
338 }
339 elseif($field['PROPERTY_TYPE'] != '')
340 {
341 $prepareEditMethod = 'prepareEditFieldByType'.$field['PROPERTY_TYPE'];
342 if(method_exists(__CLASS__, $prepareEditMethod))
343 {
344 $result = self::$prepareEditMethod($field);
345 }
346 }
347 elseif($field['TYPE'] != '')
348 {
349 $prepareEditMethod = 'prepareEditFieldByField'.str_replace('_', '', $field['TYPE']);
350 if(method_exists(__CLASS__, $prepareEditMethod))
351 {
352 $result = self::$prepareEditMethod($field);
353 }
354 else
355 {
356 $result = self::prepareEditDefaultField($field);
357 }
358 }
359
360 return $result;
361 }
362
369 public static function prepareFieldDataForFilter(array $field)
370 {
371 $customEntityType = array('employee');
372 if($field['TYPE'] == 'SORT' || $field['TYPE'] == 'N')
373 {
374 $result = array(
375 'id' => $field['FIELD_ID'],
376 'name' => $field['NAME'],
377 'type' => 'number',
378 'filterable' => ''
379 );
380 }
381 elseif($field['TYPE'] == 'ACTIVE_FROM' || $field['TYPE'] == 'ACTIVE_TO')
382 {
383 $result = array(
384 'id' => 'DATE_'.$field['FIELD_ID'],
385 'name' => $field['NAME'],
386 'type' => 'date',
387 'filterable' => '',
388 'dateFilter' => true
389 );
390 }
391 elseif($field['TYPE'] == 'DATE_CREATE' || $field['TYPE'] == 'TIMESTAMP_X')
392 {
393 $result = array(
394 'id' => $field['FIELD_ID'],
395 'name' => $field['NAME'],
396 'type' => 'date',
397 'filterable' => '',
398 'dateFilter' => true
399 );
400 }
401 elseif($field['TYPE'] == 'CREATED_BY' || $field['TYPE'] == 'MODIFIED_BY')
402 {
403 $result = array(
404 'id' => $field['FIELD_ID'],
405 'name' => $field['NAME'],
406 'type' => 'custom_entity',
407 'filterable' => '',
408 );
409 }
410 elseif($field['TYPE'] == 'L')
411 {
412 $items = array();
413 $queryObject = \CIBlockProperty::getPropertyEnum($field['ID'], array('SORT' => 'ASC', 'NAME' => 'ASC'));
414 while($queryResult = $queryObject->fetch())
415 $items[$queryResult['ID']] = $queryResult['VALUE'];
416
417 $result = array(
418 'id' => $field['FIELD_ID'],
419 'name' => $field['NAME'],
420 'type' => 'list',
421 'items' => $items,
422 'params' => array('multiple' => 'Y'),
423 'filterable' => ''
424 );
425 }
426 elseif($field['TYPE'] == 'E')
427 {
428 $result = array(
429 'id' => $field['FIELD_ID'],
430 'name' => $field['NAME'],
431 'type' => 'custom_entity',
432 'filterable' => '',
433 'customFilter' => array('Bitrix\Iblock\Helpers\Filter\Property', 'addFilter')
434 );
435 }
436 elseif($field['TYPE'] == 'E:EList')
437 {
438 $items = [];
439 if (!empty($field['LINK_IBLOCK_ID']))
440 {
441 $queryObject = \CIBlockElement::getList(
442 array('SORT' => 'ASC'),
443 array('IBLOCK_ID' => $field['LINK_IBLOCK_ID']),
444 false,
445 false,
446 array('ID', 'NAME', 'SORT')
447 );
448 while ($queryResult = $queryObject->fetch())
449 {
450 $items[$queryResult['ID']] = $queryResult['NAME'];
451 }
452 }
453
454 $result = array(
455 'id' => $field['FIELD_ID'],
456 'name' => $field['NAME'],
457 'type' => 'list',
458 'items' => $items,
459 'params' => array('multiple' => 'Y'),
460 'filterable' => ''
461 );
462 }
463 elseif($field['TYPE'] == 'G')
464 {
465 $items = [];
466 if (!empty($field['LINK_IBLOCK_ID']))
467 {
468 $queryObject = \CIBlockSection::getList(
469 array('LEFT_MARGIN' => 'ASC'),
470 array('IBLOCK_ID' => $field['LINK_IBLOCK_ID']),
471 false,
472 array('ID', 'IBLOCK_ID', 'NAME', 'DEPTH_LEVEL', 'LEFT_MARGIN')
473 );
474 while ($queryResult = $queryObject->fetch())
475 {
476 $items[$queryResult['ID']] = str_repeat('. ', $queryResult['DEPTH_LEVEL'] - 1) . $queryResult['NAME'];
477 }
478 }
479
480 $result = array(
481 'id' => $field['FIELD_ID'],
482 'name' => $field['NAME'],
483 'type' => 'list',
484 'items' => $items,
485 'params' => array('multiple' => 'Y'),
486 'filterable' => ''
487 );
488 }
489 elseif(is_array($field['PROPERTY_USER_TYPE']) && !empty($field['PROPERTY_USER_TYPE']['USER_TYPE']))
490 {
491 $type = $field['PROPERTY_USER_TYPE']['USER_TYPE'];
492 if($type == 'Date')
493 {
494 $result = array(
495 'id' => $field['FIELD_ID'],
496 'name' => $field['NAME'],
497 'type' => 'date',
498 'filterable' => '',
499 'dateFilter' => true
500 );
501 }
502 elseif($type == 'DateTime')
503 {
504 $result = array(
505 'id' => $field['FIELD_ID'],
506 'name' => $field['NAME'],
507 'type' => 'date',
508 'time' => true,
509 'filterable' => '',
510 'dateFilter' => true
511 );
512 }
513 elseif($type == 'Sequence')
514 {
515 $result = array(
516 'id' => $field['FIELD_ID'],
517 'name' => $field['NAME'],
518 'type' => 'number',
519 'filterable' => ''
520 );
521 }
522 elseif($type === 'ECrm')
523 {
524 $result = [
525 'id' => $field['FIELD_ID'],
526 'name' => $field['NAME'],
527 'type' => 'dest_selector',
528 'params' => ElementType::getDestSelectorParametersForFilter(
529 $field['USER_TYPE_SETTINGS'],
530 $isMultiple = (isset($field['MULTIPLE']) && $field['MULTIPLE'] === 'Y')
531 ),
532 'filterable' => '',
533 ];
534 }
535 elseif(in_array($type, $customEntityType))
536 {
537 $result = array(
538 'id' => $field['FIELD_ID'],
539 'name' => $field['NAME'],
540 'type' => 'custom_entity',
541 'filterable' => '',
542 );
543 }
544 else
545 {
546 if(array_key_exists('GetPublicFilterHTML', $field['PROPERTY_USER_TYPE']))
547 {
548 $result = array(
549 'id' => $field['FIELD_ID'],
550 'name' => $field['NAME'],
551 'type' => 'custom',
552 'enable_settings' => false,
553 'value' => call_user_func_array(
554 $field['PROPERTY_USER_TYPE']['GetPublicFilterHTML'],
555 array(
556 $field,
557 array(
558 'VALUE' => $field['FIELD_ID'],
559 'FORM_NAME'=>'filter_'.$field['GRID_ID'],
560 'GRID_ID' => $field['GRID_ID']
561 )
562 )
563 ),
564 'filterable' => ''
565 );
566 }
567 else
568 {
569 $listLikeProperty = array('S:HTML');
570 $result = array(
571 'id' => $field['FIELD_ID'],
572 'name' => $field['NAME'],
573 'filterable' => in_array($field['TYPE'], $listLikeProperty) ? '?' : ''
574 );
575 }
576 }
577 if(array_key_exists('AddFilterFields', $field['PROPERTY_USER_TYPE']))
578 $result['customFilter'] = $field['PROPERTY_USER_TYPE']['AddFilterFields'];
579 }
580 else
581 {
582 $listLikeField = array('NAME', 'DETAIL_TEXT', 'PREVIEW_TEXT', 'S');
583 $result = array(
584 'id' => $field['FIELD_ID'],
585 'name' => $field['NAME'],
586 'filterable' => in_array($field['TYPE'], $listLikeField) ? '?' : ''
587 );
588 if($field['FIELD_ID'] == 'NAME')
589 {
590 $result['default'] = true;
591 }
592 }
593
594 return $result;
595 }
596
597 protected static function renderFieldByTypeS(array $field)
598 {
599 if($field['MULTIPLE'] == 'Y' && is_array($field['VALUE']))
600 {
601 $results = array();
602 foreach($field['VALUE'] as $value)
603 {
604 $results[] = nl2br(HtmlFilter::encode($value));
605 }
606 $result = implode(self::$separator, $results);
607 }
608 else
609 {
610 $result = nl2br(HtmlFilter::encode($field['VALUE']));
611 }
612 return $result;
613 }
614
615 protected static function renderFieldByTypeN(array $field)
616 {
617 if(empty($field['VALUE']))
618 return '';
619
620 if($field['MULTIPLE'] == 'Y' && is_array($field['VALUE']))
621 {
622 $results = array();
623 foreach($field['VALUE'] as $value)
624 {
625 $results[] = (float)$value;
626 }
627 $result = implode(self::$separator, $results);
628 }
629 else
630 {
631 $result = (float)$field['VALUE'];
632 }
633 return $result;
634 }
635
636 protected static function renderFieldByTypeL(array $field)
637 {
638 if(!empty(self::$cache[$field['ID']]))
639 {
640 $items = self::$cache[$field['ID']];
641 }
642 else
643 {
644 $items = array();
645 if(empty($field['DEFAULT']))
646 $items[] = Loc::getMessage('LISTS_FIELD_NO_VALUE');
647 $listElements = \CIBlockProperty::getPropertyEnum($field['ID']);
648 while($listElement = $listElements->fetch())
649 {
650 if(!empty($field['DEFAULT']))
651 {
652 if($listElement['DEF'] == 'Y')
653 {
654 $items[$listElement['ID']] = HtmlFilter::encode($listElement['VALUE']);
655 }
656 }
657 else
658 {
659 $items[$listElement['ID']] = HtmlFilter::encode($listElement['VALUE']);
660 }
661 if ($listElement['DEF'] == 'Y')
662 {
663 $field['DEFAULT_VALUE'] = HtmlFilter::encode($listElement['VALUE']);
664 }
665 }
666
667 self::$cache[$field['ID']] = $items;
668 }
669
670 if (is_array($field['VALUE']) && empty($field['VALUE']))
671 {
672 $result = $items[0] ?? null;
673 }
674 elseif (is_array($field['VALUE']))
675 {
676 foreach ($items as $itemKey => $itemValue)
677 {
678 if (!in_array($itemKey, $field['VALUE']))
679 {
680 unset($items[$itemKey]);
681 }
682 }
683 $result = implode(self::$separator, $items);
684 }
685 else
686 {
687 $result = $items[$field['VALUE']] ?? null;
688 }
689
690 return ($result ?: $field['DEFAULT_VALUE']);
691 }
692
693 protected static function renderFieldByTypeF(array $field)
694 {
695 if((empty($field['VALUE']) || !empty($field['DEFAULT'])) && !self::$renderForForm)
696 return '';
697
698 $iblockId = !empty($field['IBLOCK_ID']) ? intval($field['IBLOCK_ID']) : 0;
699 $sectionId = !empty($field['SECTION_ID']) ? intval($field['SECTION_ID']) : 0;
700 $elementId = !empty($field['ELEMENT_ID']) ? intval($field['ELEMENT_ID']) : 0;
701 $fieldId = !empty($field['FIELD_ID']) ? $field['FIELD_ID'] : '';
702 $socnetGroupId = !empty($field['SOCNET_GROUP_ID']) ? intval($field['SOCNET_GROUP_ID']) : 0;
703 $urlTemplate = !empty($field['LIST_FILE_URL']) ? $field['LIST_FILE_URL'] : '';
704 $downloadUrl = !empty($field['DOWNLOAD_FILE_URL']) ? $field['DOWNLOAD_FILE_URL'] : '';
705
706 $params = array(
707 'max_size' => 2024000,
708 'max_width' => 100,
709 'max_height' => 100,
710 'url_template' => $urlTemplate,
711 'download_url' => $downloadUrl,
712 'download_text' => Loc::getMessage('LISTS_FIELD_FILE_DOWNLOAD'),
713 'show_input' => false
714 );
715 if(!empty($field['READ']) && $field['READ'] == 'N')
716 $params['show_input'] = true;
717
718 if($field['MULTIPLE'] == 'Y' && is_array($field['VALUE']))
719 {
720 $results = array();
721 foreach($field['VALUE'] as $key => $value)
722 {
723 $file = new \CListFile($iblockId, $sectionId, $elementId, $fieldId,
724 is_array($value) && isset($value['VALUE']) ? $value['VALUE'] : $value);
725 $file->setSocnetGroup($socnetGroupId);
726 $fieldControlId = $field['TYPE'] == 'F' && self::$renderForForm ?
727 $fieldId.'['.$key.'][VALUE]' : $fieldId;
728 $fileControl = new \CListFileControl($file, $fieldControlId);
729 $results[] = $fileControl->getHTML($params);
730 }
731 $result = implode(self::$separator, $results);
732 }
733 else
734 {
735 if(is_array($field['VALUE']))
736 {
737 $results = array();
738 foreach($field['VALUE'] as $key => $value)
739 {
740 $file = new \CListFile($iblockId, $sectionId, $elementId, $fieldId,
741 is_array($value) && isset($value['VALUE']) ? $value['VALUE'] : $value);
742 $file->setSocnetGroup($socnetGroupId);
743 $fieldControlId = $field['TYPE'] == 'F' && self::$renderForForm ?
744 $fieldId.'['.$key.'][VALUE]' : $fieldId;
745 $fileControl = new \CListFileControl($file, $fieldControlId);
746 $results[] = $fileControl->getHTML($params);
747 }
748 $result = implode(self::$separator, $results);
749 }
750 else
751 {
752 $file = new \CListFile($iblockId, $sectionId, $elementId, $fieldId, $field['VALUE']);
753 $file->setSocnetGroup($socnetGroupId);
754 $fileControl = new \CListFileControl($file, $fieldId);
755 $result = $fileControl->getHTML($params);
756 }
757 }
758
759 return $result;
760 }
761
762 protected static function renderFieldByTypeE(array $field)
763 {
764 return self::getLinkToElement($field);
765 }
766
767 protected static function renderFieldByTypeG(array $field)
768 {
769 if(empty($field['VALUE']))
770 return Loc::getMessage('LISTS_FIELD_NOT_DATA');
771
772 if(!is_array($field['VALUE']))
773 $field['VALUE'] = array($field['VALUE']);
774
775 $urlTemplate = !empty($field['LIST_URL']) ? $field['LIST_URL'] : '';
776 $socnetGroupId = !empty($field['SOCNET_GROUP_ID']) ? intval($field['SOCNET_GROUP_ID']) : 0;
777
778 $result = array();
779 $filter = array();
780 foreach($field['VALUE'] as $value)
781 {
782 if(!empty(self::$cache[$field['TYPE']][$value]))
783 $result[] = self::$cache[$field['TYPE']][$value];
784
785 $filter['ID'][] = $value;
786 }
787
788 if(!empty($result) && (count($result) == count($field['VALUE'])))
789 return implode(self::$separator, $result);
790 else
791 $result = array();
792
793 $queryObject = \CIBlockSection::getList(array(),
794 array('=ID' => $field['VALUE']), false, array('ID', 'IBLOCK_ID', 'NAME'));
795 while($section = $queryObject->getNext())
796 {
797 if($urlTemplate)
798 {
799 $sectionUrl = \CHTTP::URN2URI(\CHTTP::urlAddParams(
800 str_replace(array("#list_id#", "#section_id#", "#group_id#"),
801 array($section['IBLOCK_ID'], 0, $socnetGroupId),
802 $urlTemplate), array('list_section_id' => $section['ID'])));
803
804 $html = '<a href="'.HtmlFilter::encode($sectionUrl).'" target="_blank">'.
805 HtmlFilter::encode($section['~NAME']).'</a>';
806 }
807 else
808 {
809 $html = HtmlFilter::encode($section['~NAME']);
810 }
811
812 $result[] = $html;
813 self::$cache[$field['TYPE']][$section['ID']] = $html;
814 }
815
816 return implode(self::$separator, $result);
817 }
818
819 protected static function renderFieldByUserTypeElist(array $field)
820 {
821 return self::getLinkToElement($field);
822 }
823
824 protected static function renderFieldByFieldPreviewPicture(array $field)
825 {
826 return self::renderFieldByTypeF($field);
827 }
828
829 protected static function renderFieldByFieldDetailPicture(array $field)
830 {
831 return self::renderFieldByTypeF($field);
832 }
833
834 protected static function renderFieldByFieldActiveFrom(array $field)
835 {
836 return self::renderDateField($field);
837 }
838
839 protected static function renderFieldByFieldActiveTo(array $field)
840 {
841 return self::renderDateField($field);
842 }
843
844 protected static function renderFieldByFieldDateCreate(array $field)
845 {
846 return self::renderDateField($field);
847 }
848
849 protected static function renderFieldByFieldTimestampX(array $field)
850 {
851 return self::renderDateField($field);
852 }
853
854 protected static function renderFieldByFieldCreatedBy(array $field)
855 {
856 $userId = (int)$field['VALUE'];
857
858 if(!empty(self::$cache[$field['TYPE']][$userId]))
859 return self::$cache[$field['TYPE']][$userId];
860
861 $user = new \CUser();
862 $userDetails = $user->getByID($userId)->fetch();
863 $result = null;
864
865 if(is_array($userDetails))
866 {
867 $siteNameFormat = \CSite::getNameFormat(false);
868 $formattedUsersName = \CUser::formatName($siteNameFormat, $userDetails, true, true);
869
870 $pathToUser = str_replace(array('#user_id#'), $userId,
871 Option::get('main', 'TOOLTIP_PATH_TO_USER', false, SITE_ID));
872
873 $result = '<a href="'.$pathToUser.'" target="_blank" bx-tooltip-user-id="'.$userId.'">'.$formattedUsersName.'</a>';
874
875 self::$cache[$field['TYPE']][$userId] = $result;
876 }
877
878 return $result;
879 }
880
881 protected static function renderFieldByFieldModifiedBy(array $field)
882 {
883 return self::renderFieldByFieldCreatedBy($field);
884 }
885
886 protected static function renderFieldByFieldDetailText(array $field)
887 {
888 if(isset($field["SETTINGS"]["USE_EDITOR"]) && $field["SETTINGS"]["USE_EDITOR"] == "Y")
889 return nl2br($field['VALUE']);
890 else
891 return nl2br(HtmlFilter::encode($field['VALUE']));
892 }
893
894 protected static function renderFieldByFieldPreviewText(array $field)
895 {
896 if(isset($field["SETTINGS"]["USE_EDITOR"]) && $field["SETTINGS"]["USE_EDITOR"] == "Y")
897 return nl2br($field['VALUE']);
898 else
899 return nl2br(HtmlFilter::encode($field['VALUE']));
900 }
901
902 protected static function renderDateField(array $field)
903 {
904 if(empty($field['VALUE']))
905 return '';
906
907 if($field['VALUE'] === '=now')
908 return ConvertTimeStamp(time()+\CTimeZone::getOffset(), 'FULL');
909 elseif($field['VALUE'] === '=today')
910 return ConvertTimeStamp(time()+\CTimeZone::getOffset(), 'SHORT');
911
912 if($field['MULTIPLE'] == 'Y' && is_array($field['VALUE']))
913 {
914 $results = array();
915 foreach($field['VALUE'] as $value)
916 {
917 $results[] = FormatDateFromDB($value, 'FULL');
918 }
919 $result = implode(self::$separator, $results);
920 }
921 else
922 {
923 $result = FormatDateFromDB($field['VALUE'], 'FULL');
924 }
925 return $result;
926 }
927
928 protected static function renderFieldByFieldName(array $field)
929 {
930 if(empty($field['LIST_ELEMENT_URL']))
931 return self::renderDefaultField($field);
932
933 $iblockId = !empty($field['IBLOCK_ID']) ? intval($field['IBLOCK_ID']) : 0;
934 $sectionId = !empty($field['SECTION_ID']) ? intval($field['SECTION_ID']) : 0;
935 $elementId = !empty($field['ELEMENT_ID']) ? intval($field['ELEMENT_ID']) : 0;
936 $socnetGroupId = !empty($field['SOCNET_GROUP_ID']) ? intval($field['SOCNET_GROUP_ID']) : 0;
937 $urlTemplate = $field['LIST_ELEMENT_URL'];
938
939 $url = str_replace(
940 ['#list_id#', '#section_id#', '#element_id#', '#group_id#'],
941 [$iblockId, $sectionId, $elementId, $socnetGroupId],
942 $urlTemplate
943 );
944 $url = \CHTTP::urlAddParams($url, ['list_section_id' => ($sectionId ? $sectionId : '')]);
945
946 $result = '<a href="'.\CHTTP::URN2URI(HtmlFilter::encode($url)).'">'.HtmlFilter::encode($field['VALUE']).'</a>';
947 return $result;
948 }
949
950 protected static function renderDefaultField(array $field)
951 {
952 if($field['MULTIPLE'] == 'Y' && is_array($field['VALUE']))
953 {
954 $results = array();
955 foreach($field['VALUE'] as $value)
956 {
957 $results[] = $value;
958 }
959 $result = implode(self::$separator, $results);
960 }
961 else
962 {
963 $result = $field['VALUE'];
964 }
965 return HtmlFilter::encode($result);
966 }
967
968 protected static function getLinkToElement(array $field)
969 {
970 if(empty($field['VALUE']))
971 return Loc::getMessage('LISTS_FIELD_NOT_DATA');
972
973 if(!is_array($field['VALUE']))
974 $field['VALUE'] = array($field['VALUE']);
975
976 $result = array();
977 $filter = array();
978 foreach($field['VALUE'] as $value)
979 {
980 if(!empty(self::$cache[$field['TYPE']][$value]))
981 $result[] = self::$cache[$field['TYPE']][$value];
982
983 $filter['ID'][] = $value;
984 }
985
986 if(!empty($result) && (count($result) == count($field['VALUE'])))
987 return implode(self::$separator, $result);
988 else
989 $result = array();
990
991 $urlTemplate = \CList::getUrlByIblockId($field['LINK_IBLOCK_ID']);
992 if(!$urlTemplate && !empty($field["LIST_ELEMENT_URL"]))
993 $urlTemplate = $field["LIST_ELEMENT_URL"];
994 $filter['CHECK_PERMISSIONS'] = 'Y';
995 if ($field['LINK_IBLOCK_ID'] > 0)
996 $filter['IBLOCK_ID'] = $field['LINK_IBLOCK_ID'];
997
998 $queryObject = \CIBlockElement::getList(array(), $filter, false, false, array('*'));
999 while($element = $queryObject->getNext())
1000 {
1001 $elementUrl = str_replace(
1002 array('#list_id#', '#section_id#', '#element_id#'),
1003 array($element['IBLOCK_ID'], '0', $element['ID']),
1004 $urlTemplate
1005 );
1006 $elementUrl = \CHTTP::urlAddParams($elementUrl, array("list_section_id" => ""));
1007 $result[] = '<a href="'.HtmlFilter::encode($elementUrl).'" target="_blank">'.HtmlFilter::encode(
1008 $element['~NAME']).'</a>';
1009
1010 self::$cache[$field['TYPE']][$element['ID']] =
1011 '<a href="'.HtmlFilter::encode($elementUrl).'" target="_blank">'.HtmlFilter::encode(
1012 $element['~NAME']).'</a>';
1013 }
1014
1015 return implode(self::$separator, $result);
1016 }
1017
1018 protected static function renderCustomDefaultValueDiskFile(array $field)
1019 {
1020 if(!Loader::includeModule('disk'))
1021 return '';
1022
1023 if(is_array($field['VALUE']))
1024 $field['VALUE'] = array_diff($field['VALUE'], array(''));
1025 else
1026 $field['VALUE'] = explode(',', $field['VALUE']);
1027
1028 $listValue = array();
1029 foreach($field['VALUE'] as $value)
1030 {
1031 [$type, $realId] = \Bitrix\Disk\Uf\FileUserType::detectType($value);
1032 if($type == \Bitrix\Disk\Uf\FileUserType::TYPE_NEW_OBJECT)
1033 {
1034 $fileModel = \Bitrix\Disk\File::loadById($realId, array('STORAGE'));
1035 if(!$fileModel)
1036 {
1037 return '';
1038 }
1039
1040 $listValue[] = $fileModel->getName();
1041 }
1042 else
1043 {
1044 $listValue[] = $realId;
1045 }
1046 }
1047
1048 return implode(',', $listValue);
1049 }
1050
1051 protected static function prepareEditFieldByTypeL(array $field)
1052 {
1053 $items = array('' => Loc::getMessage('LISTS_FIELD_NO_VALUE'));
1054 $queryObject = \CIBlockProperty::getPropertyEnum($field['ID']);
1055 while($enum = $queryObject->fetch())
1056 {
1057 if ($enum['DEF'] == 'Y')
1058 {
1059 $field['DEFAULT_VALUE'] = $enum['ID'];
1060 }
1061 $items[$enum['ID']] = $enum['VALUE'];
1062 }
1063
1064 $inputName = $field['FIELD_ID'];
1065 if($field['MULTIPLE'] == 'Y')
1066 {
1067 $inputName .= '[]';
1068 $params = array('size' => 5, 'multiple' => 'multiple');
1069 }
1070 else
1071 {
1072 $params = array();
1073 }
1074
1075 if (!is_array($field['VALUE']))
1076 {
1077 $field['VALUE'] = ($field['VALUE'] ? array($field['VALUE']) : array());
1078 }
1079
1080 if (empty($field['VALUE']))
1081 {
1082 $field['VALUE'][] = $field['DEFAULT_VALUE'];
1083 }
1084
1085 $result = array(
1086 'id' => $inputName,
1087 'name' => $field['NAME'],
1088 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1089 "type"=>'list',
1090 "items"=>$items,
1091 'show' => $field['SHOW'],
1092 'value' => $field['VALUE'],
1093 'customHtml' => '',
1094 );
1095 if($field['READ'] == 'Y')
1096 {
1097 $params['disabled'] = 'disabled';
1098
1099 foreach($field['VALUE'] as $value)
1100 {
1101 $result['customHtml'] .= '<input type="hidden" name="'.$inputName.
1102 '" value="'.HtmlFilter::encode($value).'">';
1103 }
1104 }
1105 $result['params'] = $params;
1106
1107 return $result;
1108 }
1109
1110 protected static function prepareEditFieldByTypeS(array $field)
1111 {
1112 $html = '';
1113 $disabled = $field['READ'] == 'Y' ? 'disabled' : '';
1114 if(!is_array($field['VALUE']))
1115 $field['VALUE'] = array($field['VALUE']);
1116
1117 if($field['MULTIPLE'] == 'Y')
1118 {
1119 $html .= '<table id="tbl'.$field['FIELD_ID'].'">';
1120 if ($field["ROW_COUNT"] > 1)
1121 {
1122 foreach($field['VALUE'] as $key => $value)
1123 {
1124 if($field['READ'] == 'Y')
1125 {
1126 if(empty($value['VALUE'])) continue;
1127 $html .= '<input type="hidden" name="'.$field['FIELD_ID'].'['.$key.'][VALUE]" value="'.
1128 HtmlFilter::encode($value["VALUE"]).'">';
1129 }
1130 $html.='<tr><td><textarea '.$disabled.' style="width:auto;height:auto;" name="'.$field['FIELD_ID'].
1131 '['.$key.'][VALUE]" rows="'.intval($field["ROW_COUNT"]).'" cols="'.
1132 intval($field["COL_COUNT"]).'">'.HtmlFilter::encode($value["VALUE"]).'</textarea></td></tr>';
1133 }
1134 }
1135 else
1136 {
1137 foreach($field['VALUE'] as $key => $value)
1138 {
1139 if($field['READ'] == 'Y')
1140 {
1141 if(empty($value['VALUE'])) continue;
1142 $html .= '<input type="hidden" name="'.$field['FIELD_ID'].'['.$key.'][VALUE]" value="'.
1143 HtmlFilter::encode($value["VALUE"]).'">';
1144 }
1145 $html .= '<tr><td class="bx-field-value"><input '.$disabled.' type="text" name="'.$field['FIELD_ID'].
1146 '['.$key.'][VALUE]" value="'.HtmlFilter::encode($value['VALUE']).'" size="'.
1147 intval($field["COL_COUNT"]).'"></td></tr>';
1148 }
1149 }
1150 $html .= '</table>';
1151 if($field['READ'] == 'N')
1152 {
1153 $html .= '<input type="button" value="'.Loc::getMessage('LISTS_FIELD_ADD_BUTTON').'"
1154 onclick="BX.Lists.addNewTableRow(\'tbl'.$field['FIELD_ID'].'\', 1, /'.
1155 $field['FIELD_ID'].'\[(n)([0-9]*)\]/g, 2)">';
1156 }
1157 }
1158 else
1159 {
1160 if ($field["ROW_COUNT"] > 1)
1161 {
1162 foreach($field['VALUE'] as $key => $value)
1163 {
1164 $html .= '<textarea '.$disabled.' style="width:auto;height:auto;" name="'.$field['FIELD_ID'].
1165 '['.$key.'][VALUE]" rows="'.intval($field["ROW_COUNT"]).'" cols="'.intval($field["COL_COUNT"]).'">'.HtmlFilter::encode($value["VALUE"]).'</textarea>';
1166 if($field['READ'] == 'Y')
1167 {
1168 if(empty($value['VALUE'])) continue;
1169 $html .= '<input type="hidden" name="'.$field['FIELD_ID'].'['.$key.'][VALUE]" value="'.
1170 HtmlFilter::encode($value["VALUE"]).'">';
1171 }
1172 }
1173 }
1174 else
1175 {
1176 foreach($field['VALUE'] as $key => $value)
1177 {
1178 $html .= '<input '.$disabled.' type="text" name="'.$field['FIELD_ID'].'['.$key.'][VALUE]" value="'.
1179 HtmlFilter::encode($value["VALUE"]).'" size="'.intval($field["COL_COUNT"]).'">';
1180 if($field['READ'] == 'Y')
1181 {
1182 if(empty($value['VALUE'])) continue;
1183 $html .= '<input type="hidden" name="'.$field['FIELD_ID'].'['.$key.'][VALUE]" value="'.
1184 HtmlFilter::encode($value["VALUE"]).'">';
1185 }
1186 }
1187 }
1188 }
1189
1190 $result = array(
1191 'id' => $field['FIELD_ID'],
1192 'name' => $field['NAME'],
1193 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1194 'type' => 'custom',
1195 'show' => $field['SHOW'],
1196 'value' => $html
1197 );
1198
1199 return $result;
1200 }
1201
1202 protected static function prepareEditFieldByTypeN(array $field)
1203 {
1204 $result = array(
1205 'id' => $field['FIELD_ID'],
1206 'name' => $field['NAME'],
1207 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1208 'type' => 'custom',
1209 'show' => $field['SHOW'],
1210 'customHtml' => '',
1211 );
1212 $html = '';
1213 $disabled = $field['READ'] == 'Y' ? 'disabled' : '';
1214 if(!is_array($field['VALUE']))
1215 $field['VALUE'] = array($field['VALUE']);
1216
1217 if($field['MULTIPLE'] == 'Y')
1218 {
1219 $html .= '<table id="tbl'.$field['FIELD_ID'].'">';
1220 foreach($field['VALUE'] as $key => $value)
1221 {
1222 if($field['READ'] == 'Y')
1223 {
1224 if(empty($value['VALUE'])) continue;
1225 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].
1226 '['.$key.'][VALUE]" value="'.$value['VALUE'].'">';
1227 }
1228 $html .= '<tr><td class="bx-field-value"><input '.$disabled.' type="text" name="'.$field['FIELD_ID'].
1229 '['.$key.'][VALUE]" value="'.HtmlFilter::encode($value["VALUE"]).'"></td></tr>';
1230 }
1231 $html .= '</table>';
1232 if($field['READ'] == 'N')
1233 {
1234 $html .= '<input type="button" value="'.Loc::getMessage('LISTS_FIELD_ADD_BUTTON').'"
1235 onclick="BX.Lists.addNewTableRow(\'tbl'.$field['FIELD_ID'].'\', 1, /'.
1236 $field['FIELD_ID'].'\[(n)([0-9]*)\]/g, 2)">';
1237 }
1238 }
1239 else
1240 {
1241 foreach($field['VALUE'] as $key => $value)
1242 {
1243 $html .= '<input '.$disabled.' type="text" name="'.$field['FIELD_ID'].
1244 '['.$key.'][VALUE]" value="'.HtmlFilter::encode($value["VALUE"]).'">';
1245 if($field['READ'] == 'Y')
1246 {
1247 if(empty($value['VALUE'])) continue;
1248 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].
1249 '['.$key.'][VALUE]" value="'.$value["VALUE"].'">';
1250 }
1251 }
1252 }
1253 $result['value'] = $html;
1254
1255 return $result;
1256 }
1257
1258 protected static function prepareEditFieldByUserTypeHTML(array $field)
1259 {
1260 $result = [
1261 'id' => $field['FIELD_ID'] . '[]',
1262 'name' => $field['NAME'],
1263 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1264 'type' => 'custom',
1265 'show' => $field['SHOW'],
1266 'customHtml' => '',
1267 ];
1268 $html = '';
1269 if (!isset($field['VALUE']) || !is_array($field['VALUE']))
1270 {
1271 $field['VALUE'] = [$field['VALUE'] ?? null];
1272 }
1273
1274 $isEmptyValue = true;
1275 foreach($field['VALUE'] as $value)
1276 {
1277 if(!empty($value['VALUE']))
1278 $isEmptyValue = false;
1279 }
1280 if($isEmptyValue && $field['READ'] == 'Y')
1281 {
1282 $result['value'] = Loc::getMessage('LISTS_FIELD_NOT_DATA');
1283 return $result;
1284 }
1285
1286 if($field['MULTIPLE'] == 'Y')
1287 {
1288 $params = array('width' => '100%','height' => '200px');
1289 $html .= '<table id="tbl'.$field['FIELD_ID'].'">';
1290 foreach($field['VALUE'] as $key => $value)
1291 {
1292 if($field['READ'] == 'Y')
1293 {
1294 $html .= call_user_func_array($field['PROPERTY_USER_TYPE']['GetPublicViewHTML'],
1295 array(
1296 $field,
1297 $value,
1298 array(
1299 'VALUE' => $field['FIELD_ID']."[".$key."][VALUE]",
1300 'DESCRIPTION' => '',
1301 'FORM_NAME' => 'form_'.$field['FORM_ID'],
1302 'MODE' => 'FORM_FILL',
1303 'COPY' => $field['COPY_ID'] > 0,
1304 ),
1305 ));
1306 if(is_array($value['VALUE']))
1307 {
1308 $value['VALUE']['TEXT'] ? $htmlContent = $value['VALUE']['TEXT'] : $htmlContent = '';
1309 }
1310 else
1311 {
1312 $value['VALUE'] ? $htmlContent = $value['VALUE'] : $htmlContent = '';
1313 }
1314 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].
1315 '['.$key.'][VALUE][TYPE]" value="html">';
1316 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].
1317 '['.$key.'][VALUE][TEXT]" value="'.HtmlFilter::encode($htmlContent).'">';
1318 }
1319 else
1320 {
1321 if(is_array($value['VALUE']))
1322 $htmlContent = $value['VALUE']['TEXT'] ? $value['VALUE']['TEXT'] : '';
1323 else
1324 $htmlContent = $value['VALUE'] ? $value['VALUE'] : '';
1325 $fieldIdForHtml = 'id_'.$field['FIELD_ID'].'__'.$key.'_';
1326 $fieldNameForHtml = $field['FIELD_ID']."[".$key."][VALUE][TEXT]";
1327 $html .= '<tr><td><input type="hidden" name="'.$field['FIELD_ID'].
1328 '['.$key.'][VALUE][TYPE]" value="html">'.self::renderHtmlEditor(
1329 $fieldIdForHtml, $fieldNameForHtml, $params, $htmlContent).'</td></tr>';
1330 }
1331 }
1332 $html .= '</table>';
1333 if($field['READ'] == 'N')
1334 {
1335 $html .= '<input type="button" value="'.Loc::getMessage("LISTS_FIELD_ADD_BUTTON").'"
1336 onclick="BX.Lists.createAdditionalHtmlEditor(\'tbl'.$field['FIELD_ID'].'\',
1337 \''.$field['FIELD_ID'].'\', \''.$field['FIELD_ID'].'\');">';
1338 }
1339
1340 }
1341 else
1342 {
1343 foreach($field['VALUE'] as $key => $value)
1344 {
1345 if($field['READ'] == 'Y')
1346 {
1347 $html .= call_user_func_array($field['PROPERTY_USER_TYPE']['GetPublicViewHTML'],
1348 array(
1349 $field,
1350 $value,
1351 array(
1352 'VALUE' => $field['FIELD_ID']."[".$key."][VALUE]",
1353 'DESCRIPTION' => '',
1354 'FORM_NAME' => 'form_' . ($field['FORM_ID'] ?? ''),
1355 'MODE' => 'FORM_FILL',
1356 'COPY' => isset($field['COPY_ID']) && $field['COPY_ID'] > 0,
1357 ),
1358 ));
1359 if(is_array($value['VALUE']))
1360 $value['VALUE']['TEXT'] ? $htmlContent = $value['VALUE']['TEXT'] : $htmlContent = '';
1361 else
1362 $value['VALUE'] ? $htmlContent = $value['VALUE'] : $htmlContent = '';
1363 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].
1364 '['.$key.'][VALUE][TYPE]" value="html">';
1365 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].
1366 '['.$key.'][VALUE][TEXT]" value="'.HtmlFilter::encode($htmlContent).'">';
1367 }
1368 else
1369 {
1370 $html .= call_user_func_array($field['PROPERTY_USER_TYPE']['GetPublicEditHTML'],
1371 array(
1372 $field,
1373 $value,
1374 array(
1375 'VALUE' => $field['FIELD_ID']."[".$key."][VALUE]",
1376 'DESCRIPTION' => '',
1377 'FORM_NAME' => 'form_' . ($field['FORM_ID'] ?? ''),
1378 'MODE' => 'FORM_FILL',
1379 'COPY' => $field['COPY_ID'] > 0,
1380 ),
1381 ));
1382 }
1383 }
1384 }
1385
1386 $result['value'] = $html;
1387
1388 return $result;
1389 }
1390
1391 protected static function prepareEditFieldByFieldCreatedBy(array $field)
1392 {
1393 $result = array();
1394 if($field['ELEMENT_ID'])
1395 {
1396 $result = array(
1397 'id' => $field['FIELD_ID'],
1398 'name' => $field['NAME'],
1399 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1400 'type' => 'custom',
1401 'show' => $field['SHOW'],
1402 'value' => self::renderFieldByFieldCreatedBy($field)
1403 );
1404 }
1405 return $result;
1406 }
1407
1408 protected static function prepareEditFieldByFieldModifiedBy(array $field)
1409 {
1410 return self::prepareEditFieldByFieldCreatedBy($field);
1411 }
1412
1413 protected static function prepareEditFieldByFieldDateCreate(array $field)
1414 {
1415 $result = array();
1416 if($field['ELEMENT_ID'])
1417 {
1418 $result = array(
1419 'id' => $field['FIELD_ID'],
1420 'name' => $field['NAME'],
1421 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1422 'type' => 'custom',
1423 'show' => $field['SHOW'],
1424 'value' => $field['VALUE']
1425 );
1426 }
1427 return $result;
1428 }
1429
1430 protected static function prepareEditFieldByFieldTimestampX(array $field)
1431 {
1432 return self::prepareEditFieldByFieldDateCreate($field);
1433 }
1434
1435 protected static function prepareEditFieldByFieldDetailText(array $field)
1436 {
1437 return self::prepareEditFieldByText($field);
1438 }
1439
1440 protected static function prepareEditFieldByFieldPreviewText(array $field)
1441 {
1442 return self::prepareEditFieldByText($field);
1443 }
1444
1445 protected static function prepareEditFieldByFieldPreviewPicture(array $field)
1446 {
1447 $result = array(
1448 'id' => $field['FIELD_ID'],
1449 'name' => $field['NAME'],
1450 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1451 'type' => 'custom',
1452 'show' => $field['SHOW'],
1453 'value' => ($field['ELEMENT_ID'] > 0 && empty($field['VALUE']) && $field['READ'] == 'Y') ?
1454 Loc::getMessage('LISTS_FIELD_NOT_DATA') : self::renderFieldByTypeF($field)
1455 );
1456 return $result;
1457 }
1458
1459 protected static function prepareEditFieldByFieldDetailPicture(array $field)
1460 {
1461 $result = array(
1462 'id' => $field['FIELD_ID'],
1463 'name' => $field['NAME'],
1464 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1465 'type' => 'custom',
1466 'show' => $field['SHOW'],
1467 'value' => ($field['ELEMENT_ID'] > 0 && empty($field['VALUE']) && $field['READ'] == 'Y') ?
1468 Loc::getMessage('LISTS_FIELD_NOT_DATA') : self::renderFieldByTypeF($field)
1469 );
1470 return $result;
1471 }
1472
1473 protected static function prepareEditFieldByFieldActiveFrom(array $field)
1474 {
1475 return self::prepareDateEditField($field);
1476 }
1477
1478 protected static function prepareEditFieldByFieldActiveTo(array $field)
1479 {
1480 return self::prepareDateEditField($field);
1481 }
1482
1483 protected static function prepareEditFieldByText($field)
1484 {
1485 if($field['READ'] == 'Y')
1486 {
1487 $result = array(
1488 'id' => $field['FIELD_ID'],
1489 'name' => $field['NAME'],
1490 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1491 'type' => 'custom',
1492 'value' => '<textarea disabled>'.HtmlFilter::encode($field['VALUE'] ?? '').'</textarea>
1493 <input type="hidden" name="'.$field['FIELD_ID'].'" value="'.HtmlFilter::encode($field['VALUE'] ?? '').'">',
1494 'show' => $field['SHOW']
1495 );
1496 }
1497 else
1498 {
1499 $result = [
1500 'id' => $field['FIELD_ID'],
1501 'name' => $field['NAME'],
1502 'required' => $field['IS_REQUIRED'] === 'Y',
1503 'type' => 'textarea',
1504 'show' => $field['SHOW'],
1505 ];
1506 if(($field['SETTINGS']['USE_EDITOR'] ?? 'N') === 'Y')
1507 {
1508 $params = ['width' => '100%', 'height' => '200px'];
1509 $match = [];
1510 if(
1511 preg_match('/\s*(\d+)\s*(px|%|)/', $field['SETTINGS']['WIDTH'] ?? '', $match)
1512 && ($match[1] > 0)
1513 )
1514 {
1515 $params['width'] = $match[1] . $match[2];
1516 }
1517 if(
1518 preg_match('/\s*(\d+)\s*(px|%|)/', $field['SETTINGS']['HEIGHT'] ?? '', $match)
1519 && ($match[1] > 0)
1520 )
1521 {
1522 $params['height'] = $match[1] . $match[2];
1523 }
1524 $result['type'] = 'custom';
1525 $result['params'] = $params;
1526 $result['value'] = self::renderHtmlEditor(
1527 $field['FIELD_ID'], $field['FIELD_ID'], $params, $field['VALUE']
1528 );
1529 }
1530 else
1531 {
1532 $params = ['style' => ''];
1533 if(preg_match('/\s*(\d+)\s*(px|%|)/', $field['SETTINGS']['WIDTH'] ?? '', $match) && ($match[1] > 0))
1534 {
1535 $params['style'] .= 'width:' . $match[1] . 'px;';
1536 }
1537 if(preg_match('/\s*(\d+)\s*(px|%|)/', $field['SETTINGS']['HEIGHT'] ?? '', $match) && ($match[1] > 0))
1538 {
1539 $params['style'] .= 'height:' . $match[1] . 'px;';
1540 }
1541 $result['params'] = $params;
1542 }
1543 }
1544
1545 return $result;
1546 }
1547
1548 protected static function prepareEditFieldByTypeE(array $field)
1549 {
1550 if($field['READ'] == 'Y' && empty($field['VALUE']))
1551 {
1552 return array(
1553 'id' => $field['FIELD_ID'],
1554 'name' => $field['NAME'],
1555 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1556 'type' => 'custom',
1557 'show' => $field['SHOW'],
1558 'value' => Loc::getMessage('LISTS_FIELD_NOT_DATA')
1559 );
1560 }
1561
1562 if(!is_array($field['VALUE']))
1563 $field['VALUE'] = array($field['VALUE']);
1564
1565 $currentElements = array();
1566 foreach($field['VALUE'] as $value)
1567 {
1568 if($value)
1569 {
1570 $currentElements[] = $value;
1571 }
1572 }
1573
1574 $randomGenerator = new RandomSequence($field['FIELD_ID']);
1575 $randString = mb_strtolower($randomGenerator->randString(6));
1576
1577 $html = '';
1578 global $APPLICATION;
1579 ob_start();
1580 $APPLICATION->includeComponent('bitrix:iblock.element.selector', '',
1581 array(
1582 'SELECTOR_ID' => $randString,
1583 'INPUT_NAME' => $field['FIELD_ID'],
1584 'IBLOCK_ID' => $field['LINK_IBLOCK_ID'],
1585 'MULTIPLE' => $field['MULTIPLE'],
1586 'CURRENT_ELEMENTS_ID' => $currentElements,
1587 'POPUP' => 'Y',
1588 'ONLY_READ' => $field['READ'],
1589 'PANEL_SELECTED_VALUES' => 'Y',
1590 'TEMPLATE_URL' => $field['LIST_ELEMENT_URL']
1591 ),
1592 null, array('HIDE_ICONS' => 'Y')
1593 );
1594 $html .= ob_get_contents();
1595 ob_end_clean();
1596
1597 $result = array(
1598 'id' => $field['FIELD_ID'],
1599 'name' => $field['NAME'],
1600 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1601 'type' => 'custom',
1602 'show' => $field['SHOW'],
1603 'value' => $html
1604 );
1605
1606 return $result;
1607 }
1608
1609 protected static function prepareEditFieldByTypeG(array $field)
1610 {
1611 if($field['IS_REQUIRED'] == 'Y')
1612 $items = array();
1613 else
1614 $items = array('' => Loc::getMessage('LISTS_FIELD_NO_VALUE'));
1615
1616 $queryObject = \CIBlockSection::getTreeList(array('IBLOCK_ID' => $field['LINK_IBLOCK_ID']));
1617 while($section = $queryObject->getNext())
1618 $items[$section['ID']] = str_repeat(' . ', $section['DEPTH_LEVEL']).$section['~NAME'];
1619
1620 $inputName = $field['FIELD_ID'];
1621 if($field['MULTIPLE'] == 'Y')
1622 {
1623 $inputName .= '[]';
1624 $params = array('size' => 5, 'multiple' => 'multiple');
1625 }
1626 else
1627 {
1628 $params = array();
1629 }
1630 if($field['READ'] == 'Y')
1631 $params["disabled"] = 'disabled';
1632
1633 if(!is_array($field['VALUE']))
1634 $field['VALUE'] = array($field['VALUE']);
1635
1636 $result = array(
1637 'id' => $inputName,
1638 'name' => $field['NAME'],
1639 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1640 'type' => 'list',
1641 'show' => $field['SHOW'],
1642 'value' => $field['VALUE'],
1643 'items' => $items,
1644 'params' => $params
1645 );
1646
1647 if($field['READ'] == 'Y')
1648 {
1649 if (!array_key_exists('customHtml', $result))
1650 {
1651 $result['customHtml'] = '';
1652 }
1653
1654 foreach($field['VALUE'] as $value)
1655 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].'[]" value="'.
1656 HtmlFilter::encode($value).'">';
1657 }
1658
1659 return $result;
1660 }
1661
1662 protected static function prepareEditFieldByTypeF(array $field)
1663 {
1664 $html = '';
1665 if(!is_array($field['VALUE']))
1666 $field['VALUE'] = array($field['VALUE']);
1667
1668 $isEmptyValue = true;
1669 foreach($field['VALUE'] as $value)
1670 {
1671 if(!empty($value['VALUE']))
1672 $isEmptyValue = false;
1673 }
1674
1675 if($field['MULTIPLE'] == 'Y')
1676 {
1677 $html .= '<table id="tbl'.$field['FIELD_ID'].'">';
1678 if($field['ELEMENT_ID'] > 0 && $isEmptyValue && $field['READ'] == 'Y')
1679 {
1680 $html .= '<tr><td>';
1681 $html .= Loc::getMessage('LISTS_FIELD_NOT_DATA');
1682 $html .= '</td></tr>';
1683 }
1684 else
1685 {
1686 $iblockId = !empty($field['IBLOCK_ID']) ? intval($field['IBLOCK_ID']) : 0;
1687 $sectionId = !empty($field['SECTION_ID']) ? intval($field['SECTION_ID']) : 0;
1688 $elementId = !empty($field['ELEMENT_ID']) ? intval($field['ELEMENT_ID']) : 0;
1689 $fieldId = !empty($field['FIELD_ID']) ? $field['FIELD_ID'] : '';
1690 $socnetGroupId = !empty($field['SOCNET_GROUP_ID']) ? intval($field['SOCNET_GROUP_ID']) : 0;
1691 $urlTemplate = !empty($field['LIST_FILE_URL']) ? $field['LIST_FILE_URL'] : '';
1692 $downloadUrl = !empty($field['DOWNLOAD_FILE_URL']) ? $field['DOWNLOAD_FILE_URL'] : '';
1693 $params = array(
1694 'max_size' => 2024000,
1695 'max_width' => 100,
1696 'max_height' => 100,
1697 'url_template' => $urlTemplate,
1698 'download_url' => $downloadUrl,
1699 'download_text' => Loc::getMessage('LISTS_FIELD_FILE_DOWNLOAD'),
1700 'show_input' => $field['READ'] == 'N'
1701 );
1702 foreach($field['VALUE'] as $key => $value)
1703 {
1704 $html .= '<tr><td>';
1705 $file = new \CListFile($iblockId, $sectionId, $elementId, $fieldId,
1706 is_array($value) && isset($value['VALUE']) ? $value['VALUE'] : $value);
1707 $file->setSocnetGroup($socnetGroupId);
1708 $fieldControlId = $field['TYPE'] == 'F' && self::$renderForForm ?
1709 $fieldId.'['.$key.'][VALUE]' : $fieldId;
1710 $fileControl = new \CListFileControl($file, $fieldControlId);
1711 $html .= $fileControl->getHTML($params);
1712 $html .= '</td></tr>';
1713 }
1714 }
1715 $html .= '</table>';
1716 if($field['READ'] == 'N')
1717 {
1718 $html .= '<input type="button" value="'.Loc::getMessage("LISTS_FIELD_ADD_BUTTON").'"
1719 onclick="BX.Lists.addNewTableRow(\'tbl'.$field['FIELD_ID'].'\', 1, /'.
1720 $field['FIELD_ID'].'\[(n)([0-9]*)\]/g, 2)">';
1721 }
1722 }
1723 else
1724 {
1725 $html .= ($field['ELEMENT_ID'] > 0 && $isEmptyValue && $field['READ'] == 'Y') ?
1726 Loc::getMessage('LISTS_FIELD_NOT_DATA') : self::renderFieldByTypeF($field);
1727 }
1728
1729 $result = array(
1730 'id' => $field['FIELD_ID'],
1731 'name' => $field['NAME'],
1732 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1733 'type' => 'custom',
1734 'show' => $field['SHOW'],
1735 'value' => $html
1736 );
1737 return $result;
1738 }
1739
1740 protected static function prepareDateEditField(array $field)
1741 {
1742 $result = array(
1743 'id' => $field['FIELD_ID'],
1744 'name' => $field['NAME'],
1745 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1746 'type' => 'date',
1747 'show' => $field['SHOW']
1748 );
1749
1750 if($field['READ'] == 'Y')
1751 {
1752 $result['type'] = 'custom';
1753 if(($field['ELEMENT_ID'] ?? 0) > 0 && empty($field['VALUE']))
1754 {
1755 $result['value'] = Loc::getMessage('LISTS_FIELD_NOT_DATA');
1756 }
1757 else
1758 {
1759 $result['value'] = '<input disabled type="text" value="'.HtmlFilter::encode($field['VALUE']).
1760 '"><input type="hidden" name="'.$field['FIELD_ID'].'" value="'.
1761 HtmlFilter::encode($field['VALUE']).'">';
1762 }
1763 }
1764 return $result;
1765 }
1766
1767 protected static function prepareEditDefaultField(array $field)
1768 {
1769 $result = array(
1770 'id' => $field['FIELD_ID'],
1771 'name' => $field['NAME'],
1772 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1773 'type' => 'text',
1774 'show' => $field['SHOW']
1775 );
1776 if($field['READ'] == 'Y')
1777 {
1778 $result['type'] = 'custom';
1779 $result['value'] = '<input disabled type="text" value="'.HtmlFilter::encode($field['VALUE']).
1780 '"><input type="hidden" name="'.$field["FIELD_ID"].'" value="'.HtmlFilter::encode($field['VALUE']).'">';
1781 }
1782 return $result;
1783 }
1784
1785 protected static function renderHtmlEditor($fieldId, $fieldNameForHtml, $params, $content)
1786 {
1787 $html = '';
1788 if (Loader::includeModule('fileman'))
1789 {
1790 ob_start();
1791 $editor = new \CHTMLEditor;
1792 $res = array(
1793 'name' => $fieldNameForHtml,
1794 'inputName' => $fieldNameForHtml,
1795 'id' => $fieldId,
1796 'width' => $params['width'],
1797 'height' => $params['height'],
1798 'content' => $content,
1799 'useFileDialogs' => false,
1800 'minBodyWidth' => 350,
1801 'normalBodyWidth' => 555,
1802 'bAllowPhp' => false,
1803 'limitPhpAccess' => false,
1804 'showTaskbars' => false,
1805 'showNodeNavi' => false,
1806 'beforeUnloadHandlerAllowed' => true,
1807 'askBeforeUnloadPage' => false,
1808 'bbCode' => false,
1809 'siteId' => SITE_ID,
1810 'autoResize' => true,
1811 'autoResizeOffset' => 40,
1812 'saveOnBlur' => true,
1813 'actionUrl' => '/bitrix/tools/html_editor_action.php',
1814 'setFocusAfterShow' => false,
1815 'controlsMap' => array(
1816 array('id' => 'Bold', 'compact' => true, 'sort' => 80),
1817 array('id' => 'Italic', 'compact' => true, 'sort' => 90),
1818 array('id' => 'Underline', 'compact' => true, 'sort' => 100),
1819 array('id' => 'Strikeout', 'compact' => true, 'sort' => 110),
1820 array('id' => 'RemoveFormat', 'compact' => true, 'sort' => 120),
1821 array('id' => 'Color', 'compact' => true, 'sort' => 130),
1822 array('id' => 'FontSelector', 'compact' => false, 'sort' => 135),
1823 array('id' => 'FontSize', 'compact' => false, 'sort' => 140),
1824 array('separator' => true, 'compact' => false, 'sort' => 145),
1825 array('id' => 'OrderedList', 'compact' => true, 'sort' => 150),
1826 array('id' => 'UnorderedList', 'compact' => true, 'sort' => 160),
1827 array('id' => 'AlignList', 'compact' => false, 'sort' => 190),
1828 array('separator' => true, 'compact' => false, 'sort' => 200),
1829 array('id' => 'InsertLink', 'compact' => true, 'sort' => 210),
1830 array('id' => 'InsertImage', 'compact' => false, 'sort' => 220),
1831 array('id' => 'InsertVideo', 'compact' => true, 'sort' => 230),
1832 array('id' => 'InsertTable', 'compact' => false, 'sort' => 250),
1833 array('separator' => true, 'compact' => false, 'sort' => 290),
1834 array('id' => 'Fullscreen', 'compact' => false, 'sort' => 310),
1835 array('id' => 'More', 'compact' => true, 'sort' => 400)
1836 ),
1837 );
1838 $editor->show($res);
1839 $html = ob_get_contents();
1840 ob_end_clean();
1841 }
1842 return $html;
1843 }
1844}
static prepareFieldDataForEditForm(array $field)
Определения field.php:128
static $cache
Определения field.php:22
static $separator
Определения field.php:23
static $renderForForm
Определения field.php:24
static renderField(array $field)
Определения field.php:32
hidden PROPERTY[<?=$propertyIndex?>][CODE]<?=htmlspecialcharsEx( $propertyCode)?> height
Определения file_new.php:759
bx popup label bx width30 PAGE_NEW_MENU_NAME text width
Определения file_new.php:677
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
Form FILTER_ACTION disabled
Определения options.php:358
$result
Определения get_property_values.php:14
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257