1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
catalog_cond.php
См. документацию.
1<?php
2
8
9const BT_COND_LOGIC_EQ = 0; // = (equal)
10const BT_COND_LOGIC_NOT_EQ = 1; // != (not equal)
11const BT_COND_LOGIC_GR = 2; // > (great)
12const BT_COND_LOGIC_LS = 3; // < (less)
13const BT_COND_LOGIC_EGR = 4; // => (great or equal)
14const BT_COND_LOGIC_ELS = 5; // =< (less or equal)
15const BT_COND_LOGIC_CONT = 6; // contain
16const BT_COND_LOGIC_NOT_CONT = 7; // not contain
17
18const BT_COND_MODE_DEFAULT = 0; // full mode
19const BT_COND_MODE_PARSE = 1; // parsing mode
20const BT_COND_MODE_GENERATE = 2; // generate mode
21const BT_COND_MODE_SQL = 3; // generate getlist mode
22const BT_COND_MODE_SEARCH = 4; // info mode
23
24const BT_COND_BUILD_CATALOG = 0; // catalog conditions
25const BT_COND_BUILD_SALE = 1; // sale conditions
26const BT_COND_BUILD_SALE_ACTIONS = 2; // sale actions conditions
27
29{
30 public static $arInitParams = false;
31 public static $boolInit = false;
32
33 public static function GetClassName()
34 {
35 return get_called_class();
36 }
37
38 public static function GetControlDescr()
39 {
40 $strClassName = get_called_class();
41 return array(
42 'ID' => static::GetControlID(),
43 'GetControlShow' => array($strClassName, 'GetControlShow'),
44 'GetConditionShow' => array($strClassName, 'GetConditionShow'),
45 'IsGroup' => array($strClassName, 'IsGroup'),
46 'Parse' => array($strClassName, 'Parse'),
47 'Generate' => array($strClassName, 'Generate'),
48 'ApplyValues' => array($strClassName, 'ApplyValues'),
49 'InitParams' => array($strClassName, 'InitParams')
50 );
51 }
52
53 public static function GetControlShow($arParams)
54 {
55 return array();
56 }
57
58 public static function GetConditionShow($arParams)
59 {
60 return '';
61 }
62
63 public static function IsGroup($strControlID = false)
64 {
65 return 'N';
66 }
67
68 public static function Parse($arOneCondition)
69 {
70 return '';
71 }
72
73 public static function Generate($arOneCondition, $arParams, $arControl, $arSubs = false)
74 {
75 return '';
76 }
77
78 public static function ApplyValues($arOneCondition, $arControl)
79 {
80 return array();
81 }
82
83 public static function InitParams($arParams)
84 {
85 if (!empty($arParams) && is_array($arParams))
86 {
87 static::$arInitParams = $arParams;
88 static::$boolInit = true;
89 }
90 }
91
95 public static function GetControlID()
96 {
97 return '';
98 }
99
100 public static function GetShowIn($arControls)
101 {
102 if (!is_array($arControls))
103 $arControls = array($arControls);
104 return array_values(array_unique($arControls));
105 }
106
111 public static function GetControls($strControlID = false)
112 {
113 return false;
114 }
115
116 public static function GetAtoms()
117 {
118 return array();
119 }
120
121 public static function GetAtomsEx($strControlID = false, $boolEx = false)
122 {
123 return array();
124 }
125
126 public static function GetJSControl($arControl, $arParams = array())
127 {
128 return array();
129 }
130
131 public static function OnBuildConditionAtomList()
132 {
133
134 }
135
140 public static function GetLogic($arOperators = false)
141 {
142 $arOperatorsList = array(
144 'ID' => BT_COND_LOGIC_EQ,
145 'OP' => array(
146 'Y' => 'in_array(#VALUE#, #FIELD#)',
147 'N' => '#FIELD# == #VALUE#'
148 ),
149 'PARENT' => ' || ',
150 'MULTI_SEP' => ' || ',
151 'VALUE' => 'Equal',
152 'LABEL' => Loc::getMessage('BT_COND_LOGIC_EQ_LABEL')
153 ),
155 'ID' => BT_COND_LOGIC_NOT_EQ,
156 'OP' => array(
157 'Y' => '!in_array(#VALUE#, #FIELD#)',
158 'N' => '#FIELD# != #VALUE#'
159 ),
160 'PARENT' => ' && ',
161 'MULTI_SEP' => ' && ',
162 'VALUE' => 'Not',
163 'LABEL' => Loc::getMessage('BT_COND_LOGIC_NOT_EQ_LABEL')
164 ),
166 'ID' => BT_COND_LOGIC_GR,
167 'OP' => array(
168 'N' => '#FIELD# > #VALUE#',
169 'Y' => 'CGlobalCondCtrl::LogicGreat(#FIELD#, #VALUE#)'
170 ),
171 'VALUE' => 'Great',
172 'LABEL' => Loc::getMessage('BT_COND_LOGIC_GR_LABEL')
173 ),
175 'ID' => BT_COND_LOGIC_LS,
176 'OP' => array(
177 'N' => '#FIELD# < #VALUE#',
178 'Y' => 'CGlobalCondCtrl::LogicLess(#FIELD#, #VALUE#)'
179 ),
180 'VALUE' => 'Less',
181 'LABEL' => Loc::getMessage('BT_COND_LOGIC_LS_LABEL')
182 ),
184 'ID' => BT_COND_LOGIC_EGR,
185 'OP' => array(
186 'N' => '#FIELD# >= #VALUE#',
187 'Y' => 'CGlobalCondCtrl::LogicEqualGreat(#FIELD#, #VALUE#)'
188 ),
189 'VALUE' => 'EqGr',
190 'LABEL' => Loc::getMessage('BT_COND_LOGIC_EGR_LABEL')
191 ),
193 'ID' => BT_COND_LOGIC_ELS,
194 'OP' => array(
195 'N' => '#FIELD# <= #VALUE#',
196 'Y' => 'CGlobalCondCtrl::LogicEqualLess(#FIELD#, #VALUE#)'
197 ),
198 'VALUE' => 'EqLs',
199 'LABEL' => Loc::getMessage('BT_COND_LOGIC_ELS_LABEL')
200 ),
202 'ID' => BT_COND_LOGIC_CONT,
203 'OP' => array(
204 'N' => 'false !== mb_strpos(#FIELD#, #VALUE#)',
205 'Y' => 'CGlobalCondCtrl::LogicContain(#FIELD#, #VALUE#)'
206 ),
207 'PARENT' => ' || ',
208 'MULTI_SEP' => ' || ',
209 'VALUE' => 'Contain',
210 'LABEL' => Loc::getMessage('BT_COND_LOGIC_CONT_LABEL')
211 ),
214 'OP' => array(
215 'N' => 'false === mb_strpos(#FIELD#, #VALUE#)',
216 'Y' => 'CGlobalCondCtrl::LogicNotContain(#FIELD#, #VALUE#)'
217 ),
218 'PARENT' => ' && ',
219 'MULTI_SEP' => ' && ',
220 'VALUE' => 'NotCont',
221 'LABEL' => Loc::getMessage('BT_COND_LOGIC_NOT_CONT_LABEL')
222 )
223 );
224
225 $boolSearch = false;
226 $arSearch = array();
227 if (!empty($arOperators) && is_array($arOperators))
228 {
229 foreach ($arOperators as &$intOneOp)
230 {
231 if (isset($arOperatorsList[$intOneOp]))
232 {
233 $boolSearch = true;
234 $arSearch[$intOneOp] = $arOperatorsList[$intOneOp];
235 }
236 }
237 unset($intOneOp);
238 }
239 return ($boolSearch ? $arSearch : $arOperatorsList);
240 }
241
247 public static function GetLogicEx($arOperators = false, $arLabels = false)
248 {
249 $arOperatorsList = static::GetLogic($arOperators);
250 if (!empty($arLabels) && is_array($arLabels))
251 {
252 foreach ($arOperatorsList as &$arOneOperator)
253 {
254 if (isset($arLabels[$arOneOperator['ID']]))
255 $arOneOperator['LABEL'] = $arLabels[$arOneOperator['ID']];
256 }
257 if (isset($arOneOperator))
258 unset($arOneOperator);
259 }
260 return $arOperatorsList;
261 }
262
263 public static function GetLogicAtom($arLogic)
264 {
265 if (!empty($arLogic) && is_array($arLogic))
266 {
267 $arValues = array();
268 foreach ($arLogic as &$arOneLogic)
269 {
270 $arValues[$arOneLogic['VALUE']] = $arOneLogic['LABEL'];
271 }
272 if (isset($arOneLogic))
273 unset($arOneLogic);
275 'id' => 'logic',
276 'name' => 'logic',
277 'type' => 'select',
278 'values' => $arValues,
279 'defaultText' => current($arValues),
280 'defaultValue' => key($arValues)
281 );
282 return $arResult;
283 }
284 return false;
285 }
286
287 public static function GetValueAtom($arValue)
288 {
289 if (empty($arValue) || !isset($arValue['type']))
290 {
292 'type' => 'input'
293 );
294 }
295 else
296 {
297 $arResult = $arValue;
298 }
299 $arResult['id'] = 'value';
300 $arResult['name'] = 'value';
301
302 return $arResult;
303 }
304
305 public static function CheckLogic($strValue, $arLogic, $boolShow = false)
306 {
307 $boolShow = (true === $boolShow);
308 if (empty($arLogic) || !is_array($arLogic))
309 return false;
310 $strResult = '';
311 foreach ($arLogic as &$arOneLogic)
312 {
313 if ($strValue == $arOneLogic['VALUE'])
314 {
315 $strResult = $arOneLogic['VALUE'];
316 break;
317 }
318 }
319 if (isset($arOneLogic))
320 unset($arOneLogic);
321 if ($strResult == '')
322 {
323 if ($boolShow)
324 {
325 $arOneLogic = current($arLogic);
326 $strResult = $arOneLogic['VALUE'];
327 }
328 }
329 return ($strResult == '' ? false : $strResult);
330 }
331
332 public static function SearchLogic($strValue, $arLogic)
333 {
334 $mxResult = false;
335 if (empty($arLogic) || !is_array($arLogic))
336 return $mxResult;
337 foreach ($arLogic as &$arOneLogic)
338 {
339 if ($strValue == $arOneLogic['VALUE'])
340 {
341 $mxResult = $arOneLogic;
342 break;
343 }
344 }
345 if (isset($arOneLogic))
346 unset($arOneLogic);
347 return $mxResult;
348 }
349
350 public static function Check($arOneCondition, $arParams, $arControl, $boolShow)
351 {
352 $boolShow = ($boolShow === true);
353 $boolError = false;
354 $boolFatalError = false;
355 $arMsg = array();
356
358 'logic' => '',
359 'value' => ''
360 );
361 $arLabels = array();
362
363 static $intTimeOffset = false;
364 if ($intTimeOffset === false)
365 $intTimeOffset = CTimeZone::GetOffset();
366
367 if ($boolShow)
368 {
369 if (!isset($arOneCondition['logic']))
370 {
371 $arOneCondition['logic'] = '';
372 $boolError = true;
373 }
374 if (!isset($arOneCondition['value']))
375 {
376 $arOneCondition['value'] = '';
377 $boolError = true;
378 }
379 $strLogic = static::CheckLogic($arOneCondition['logic'], $arControl['LOGIC'], $boolShow);
380 if ($strLogic === false)
381 {
382 $boolError = true;
383 $boolFatalError = true;
384 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_LOGIC_ABSENT');
385 }
386 else
387 {
388 $arValues['logic'] = $strLogic;
389 }
390
391 $boolValueError = static::ClearValue($arOneCondition['value']);
392 if (!$boolValueError)
393 {
394 $boolMulti = is_array($arOneCondition['value']);
395 switch ($arControl['FIELD_TYPE'])
396 {
397 case 'int':
398 if ($boolMulti)
399 {
400 foreach ($arOneCondition['value'] as &$intOneValue)
401 {
402 $intOneValue = (int)$intOneValue;
403 }
404 unset($intOneValue);
405 }
406 else
407 {
408 $arOneCondition['value'] = (int)$arOneCondition['value'];
409 }
410 break;
411 case 'double':
412 if ($boolMulti)
413 {
414 foreach ($arOneCondition['value'] as &$dblOneValue)
415 {
416 $dblOneValue = (float)$dblOneValue;
417 }
418 unset($dblOneValue);
419 }
420 else
421 {
422 $arOneCondition['value'] = (float)$arOneCondition['value'];
423 }
424 break;
425 case 'char':
426 if ($boolMulti)
427 {
428 foreach ($arOneCondition['value'] as &$strOneValue)
429 {
430 $strOneValue = mb_substr($strOneValue, 0, 1);
431 }
432 unset($strOneValue);
433 }
434 else
435 {
436 $arOneCondition['value'] = mb_substr($arOneCondition['value'], 0, 1);
437 }
438 break;
439 case 'string':
440 $intMaxLen = (int)(isset($arControl['FIELD_LENGTH']) ? $arControl['FIELD_LENGTH'] : 255);
441 if ($intMaxLen <= 0)
442 $intMaxLen = 255;
443 if ($boolMulti)
444 {
445 foreach ($arOneCondition['value'] as &$strOneValue)
446 {
447 $strOneValue = mb_substr($strOneValue, 0, $intMaxLen);
448 }
449 unset($strOneValue);
450 }
451 else
452 {
453 $arOneCondition['value'] = mb_substr($arOneCondition['value'], 0, $intMaxLen);
454 }
455 break;
456 case 'text':
457 break;
458 case 'date':
459 case 'datetime':
460 if ($arControl['FIELD_TYPE'] == 'date')
461 {
462 $strFormat = 'SHORT';
463 $intOffset = 0;
464 }
465 else
466 {
467 $strFormat = 'FULL';
468 $intOffset = $intTimeOffset;
469 }
470 $boolValueError = static::ConvertInt2DateTime($arOneCondition['value'], $strFormat, $intOffset);
471 break;
472 default:
473 $boolValueError = true;
474 break;
475 }
476 if (!$boolValueError)
477 {
478 if ($boolMulti)
479 $arOneCondition['value'] = array_values(array_unique($arOneCondition['value']));
480 }
481 }
482
483 if (!$boolValueError)
484 {
485 if (isset($arControl['PHP_VALUE']) && !empty($arControl['PHP_VALUE']['VALIDATE']))
486 {
487 $arValidate = static::Validate($arOneCondition, $arParams, $arControl, $boolShow);
488 if ($arValidate === false)
489 {
490 $boolValueError = true;
491 }
492 else
493 {
494 if (isset($arValidate['err_cond']) && $arValidate['err_cond'] == 'Y')
495 {
496 $boolValueError = true;
497 if (isset($arValidate['err_cond_mess']) && !empty($arValidate['err_cond_mess']))
498 $arMsg = array_merge($arMsg, $arValidate['err_cond_mess']);
499 }
500 else
501 {
502 $arValues['value'] = $arValidate['values'];
503 if (isset($arValidate['labels']))
504 $arLabels['value'] = $arValidate['labels'];
505 }
506 }
507 }
508 else
509 {
510 $arValues['value'] = $arOneCondition['value'];
511 }
512 }
513
514 if ($boolValueError)
515 $boolError = $boolValueError;
516 }
517 else
518 {
519 if (!isset($arOneCondition['logic']) || !isset($arOneCondition['value']))
520 {
521 $boolError = true;
522 }
523 else
524 {
525 $strLogic = static::CheckLogic($arOneCondition['logic'], $arControl['LOGIC'], $boolShow);
526 if (!$strLogic)
527 {
528 $boolError = true;
529 }
530 else
531 {
532 $arValues['logic'] = $arOneCondition['logic'];
533 }
534 }
535
536 if (!$boolError)
537 {
538 $boolError = static::ClearValue($arOneCondition['value']);
539 }
540
541 if (!$boolError)
542 {
543 $boolMulti = is_array($arOneCondition['value']);
544 switch ($arControl['FIELD_TYPE'])
545 {
546 case 'int':
547 if ($boolMulti)
548 {
549 foreach ($arOneCondition['value'] as &$intOneValue)
550 {
551 $intOneValue = (int)$intOneValue;
552 }
553 unset($intOneValue);
554 }
555 else
556 {
557 $arOneCondition['value'] = (int)$arOneCondition['value'];
558 }
559 break;
560 case 'double':
561 if ($boolMulti)
562 {
563 foreach ($arOneCondition['value'] as &$dblOneValue)
564 {
565 $dblOneValue = (float)$dblOneValue;
566 }
567 unset($dblOneValue);
568 }
569 else
570 {
571 $arOneCondition['value'] = (float)$arOneCondition['value'];
572 }
573 break;
574 case 'char':
575 if ($boolMulti)
576 {
577 foreach ($arOneCondition['value'] as &$strOneValue)
578 {
579 $strOneValue = mb_substr($strOneValue, 0, 1);
580 }
581 unset($strOneValue);
582 }
583 else
584 {
585 $arOneCondition['value'] = mb_substr($arOneCondition['value'], 0, 1);
586 }
587 break;
588 case 'string':
589 $intMaxLen = (int)(isset($arControl['FIELD_LENGTH']) ? $arControl['FIELD_LENGTH'] : 255);
590 if ($intMaxLen <= 0)
591 $intMaxLen = 255;
592 if ($boolMulti)
593 {
594 foreach ($arOneCondition['value'] as &$strOneValue)
595 {
596 $strOneValue = mb_substr($strOneValue, 0, $intMaxLen);
597 }
598 unset($strOneValue);
599 }
600 else
601 {
602 $arOneCondition['value'] = mb_substr($arOneCondition['value'], 0, $intMaxLen);
603 }
604 break;
605 case 'text':
606 break;
607 case 'date':
608 case 'datetime':
609 if ($arControl['FIELD_TYPE'] == 'date')
610 {
611 $strFormat = 'SHORT';
612 $intOffset = 0;
613 }
614 else
615 {
616 $strFormat = 'FULL';
617 $intOffset = $intTimeOffset;
618 }
619 $boolError = static::ConvertDateTime2Int($arOneCondition['value'], $strFormat, $intOffset);
620 break;
621 default:
622 $boolError = true;
623 break;
624 }
625 if ($boolMulti)
626 {
627 if (!$boolError)
628 $arOneCondition['value'] = array_values(array_unique($arOneCondition['value']));
629 }
630 }
631
632 if (!$boolError)
633 {
634 if (isset($arControl['PHP_VALUE']) && !empty($arControl['PHP_VALUE']['VALIDATE']))
635 {
636 $arValidate = static::Validate($arOneCondition, $arParams, $arControl, $boolShow);
637 if ($arValidate === false)
638 {
639 $boolError = true;
640 }
641 else
642 {
643 $arValues['value'] = $arValidate['values'];
644 if (isset($arValidate['labels']))
645 $arLabels['value'] = $arValidate['labels'];
646 }
647 }
648 else
649 {
650 $arValues['value'] = $arOneCondition['value'];
651 }
652 }
653 }
654
655 if ($boolShow)
656 {
658 'id' => $arParams['COND_NUM'],
659 'controlId' => $arControl['ID'],
660 'values' => $arValues,
661 );
662 if (!empty($arLabels))
663 $arResult['labels'] = $arLabels;
664 if ($boolError)
665 {
666 $arResult['err_cond'] = 'Y';
667 if ($boolFatalError)
668 $arResult['fatal_err_cond'] = 'Y';
669 if (!empty($arMsg))
670 $arResult['err_cond_mess'] = implode('. ', $arMsg);
671 }
672
673 return $arResult;
674 }
675 else
676 {
678 return (!$boolError ? $arResult : false);
679 }
680 }
681
682 public static function Validate($arOneCondition, $arParams, $arControl, $boolShow)
683 {
684 static $userNameFormat = null;
685
686 $boolShow = ($boolShow === true);
687 $boolError = false;
688 $arMsg = array();
689
691 'values' => '',
692 );
693
694 if (!(isset($arControl['PHP_VALUE']) && isset($arControl['PHP_VALUE']['VALIDATE']) && !empty($arControl['PHP_VALUE']['VALIDATE'])))
695 {
696 $boolError = true;
697 }
698
699 if (!$boolError)
700 {
701 if ($boolShow)
702 {
703 // validate for show
704 $boolMulti = is_array($arOneCondition['value']);
705 switch($arControl['PHP_VALUE']['VALIDATE'])
706 {
707 case 'element':
708 $rsItems = CIBlockElement::GetList(
709 array(),
710 array('ID' => $arOneCondition['value']),
711 false,
712 false,
713 array('ID', 'NAME')
714 );
715 if ($boolMulti)
716 {
717 $arCheckResult = array();
718 while ($arItem = $rsItems->Fetch())
719 {
720 $arCheckResult[(int)$arItem['ID']] = $arItem['NAME'];
721 }
722 if (!empty($arCheckResult))
723 {
724 $arResult['values'] = array_keys($arCheckResult);
725 $arResult['labels'] = array_values($arCheckResult);
726 }
727 else
728 {
729 $boolError = true;
730 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_ELEMENT_ABSENT_MULTI');
731 }
732 }
733 else
734 {
735 if ($arItem = $rsItems->Fetch())
736 {
737 $arResult['values'] = (int)$arItem['ID'];
738 $arResult['labels'] = $arItem['NAME'];
739 }
740 else
741 {
742 $boolError = true;
743 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_ELEMENT_ABSENT');
744 }
745 }
746 break;
747 case 'section':
748 $rsSections = CIBlockSection::GetList(
749 array(),
750 array('ID' => $arOneCondition['value']),
751 false,
752 array('ID', 'NAME')
753 );
754 if ($boolMulti)
755 {
756 $arCheckResult = array();
757 while ($arSection = $rsSections->Fetch())
758 {
759 $arCheckResult[(int)$arSection['ID']] = $arSection['NAME'];
760 }
761 if (!empty($arCheckResult))
762 {
763 $arResult['values'] = array_keys($arCheckResult);
764 $arResult['labels'] = array_values($arCheckResult);
765 }
766 else
767 {
768 $boolError = true;
769 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_SECTION_ABSENT_MULTI');
770 }
771 }
772 else
773 {
774 if ($arSection = $rsSections->Fetch())
775 {
776 $arResult['values'] = (int)$arSection['ID'];
777 $arResult['labels'] = $arSection['NAME'];
778 }
779 else
780 {
781 $boolError = true;
782 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_SECTION_ABSENT');
783 }
784 }
785 break;
786 case 'iblock':
787 if ($boolMulti)
788 {
789 $arCheckResult = array();
790 foreach ($arOneCondition['value'] as &$intIBlockID)
791 {
792 $strName = CIBlock::GetArrayByID($intIBlockID, 'NAME');
793 if ($strName !== false && $strName !== null)
794 {
795 $arCheckResult[$intIBlockID] = $strName;
796 }
797 }
798 if (isset($intIBlockID))
799 unset($intIBlockID);
800 if (!empty($arCheckResult))
801 {
802 $arResult['values'] = array_keys($arCheckResult);
803 $arResult['labels'] = array_values($arCheckResult);
804 }
805 else
806 {
807 $boolError = true;
808 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_IBLOCK_ABSENT_MULTI');
809 }
810 }
811 else
812 {
813 $strName = CIBlock::GetArrayByID($arOneCondition['value'], 'NAME');
814 if ($strName !== false && $strName !== null)
815 {
816 $arResult['values'] = $arOneCondition['value'];
817 $arResult['labels'] = $strName;
818 }
819 else
820 {
821 $boolError = true;
822 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_IBLOCK_ABSENT');
823 }
824 }
825 break;
826 case 'enumValue':
827 $iterator = Iblock\PropertyEnumerationTable::getList(array(
828 'select' => array('ID', 'VALUE'),
829 'filter' => array('@ID' => $arOneCondition['value'])
830 ));
831 if ($boolMulti)
832 {
833 $checkResult = array();
834 while ($row = $iterator->fetch())
835 $checkResult[$row['ID']] = $row['VALUE'];
836 unset($row);
837 if (!empty($checkResult))
838 {
839 $arResult['values'] = array_keys($checkResult);
840 $arResult['labels'] = array_values($checkResult);
841 }
842 else
843 {
844 $boolError = true;
845 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_ENUM_VALUE_ABSENT_MULTI');
846 }
847 unset($checkResult);
848 }
849 else
850 {
851 $row = $iterator->fetch();
852 if (!empty($row))
853 {
854 $arResult['values'] = $row['ID'];
855 $arResult['labels'] = $row['VALUE'];
856 }
857 else
858 {
859 $boolError = true;
860 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_ENUM_VALUE_ABSENT');
861 }
862 }
863 unset($iterator);
864 break;
865 case 'user':
866 if ($userNameFormat === null)
867 $userNameFormat = CSite::GetNameFormat(true);
868 if ($boolMulti)
869 {
870 $arCheckResult = array();
871 $userIterator = UserTable::getList(array(
872 'select' => array('ID', 'LOGIN', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'EMAIL'),
873 'filter' => array('ID' => $arOneCondition['value'])
874 ));
875 while ($user = $userIterator->fetch())
876 {
877 $user['ID'] = (int)$user['ID'];
878 $arCheckResult[$user['ID']] = CUser::FormatName($userNameFormat, $user);
879 }
880 if (!empty($arCheckResult))
881 {
882 $arResult['values'] = array_keys($arCheckResult);
883 $arResult['labels'] = array_values($arCheckResult);
884 }
885 else
886 {
887 $boolError = true;
888 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_USER_ABSENT_MULTI');
889 }
890 }
891 else
892 {
893 $userIterator = UserTable::getList(array(
894 'select' => array('ID', 'LOGIN', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'EMAIL'),
895 'filter' => array('ID' => $arOneCondition['value'])
896 ));
897 if ($user = $userIterator->fetch())
898 {
899 $arResult['values'] = (int)$user['ID'];
900 $arResult['labels'] = CUser::FormatName($userNameFormat, $user);
901 }
902 else
903 {
904 $boolError = true;
905 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_USER_ABSENT');
906 }
907 }
908 break;
909 case 'list':
910 if (isset($arControl['JS_VALUE']) && isset($arControl['JS_VALUE']['values']) && !empty($arControl['JS_VALUE']['values']))
911 {
912 if ($boolMulti)
913 {
914 $arCheckResult = array();
915 foreach ($arOneCondition['value'] as &$strValue)
916 {
917 if (isset($arControl['JS_VALUE']['values'][$strValue]))
918 $arCheckResult[] = $strValue;
919 }
920 if (isset($strValue))
921 unset($strValue);
922 if (!empty($arCheckResult))
923 {
924 $arResult['values'] = $arCheckResult;
925 }
926 else
927 {
928 $boolError = true;
929 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_LIST_ABSENT_MULTI');
930 }
931 }
932 else
933 {
934 if (isset($arControl['JS_VALUE']['values'][$arOneCondition['value']]))
935 {
936 $arResult['values'] = $arOneCondition['value'];
937 }
938 else
939 {
940 $boolError = true;
941 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_LIST_ABSENT');
942 }
943 }
944 }
945 else
946 {
947 $boolError = true;
948 }
949 break;
950 }
951 }
952 else
953 {
954 // validate for save
955 $boolMulti = is_array($arOneCondition['value']);
956 switch($arControl['PHP_VALUE']['VALIDATE'])
957 {
958 case 'element':
959 $rsItems = CIBlockElement::GetList(array(), array('ID' => $arOneCondition['value']), false, false, array('ID'));
960 if ($boolMulti)
961 {
962 $arCheckResult = array();
963 while ($arItem = $rsItems->Fetch())
964 {
965 $arCheckResult[] = (int)$arItem['ID'];
966 }
967 if (!empty($arCheckResult))
968 {
969 $arResult['values'] = $arCheckResult;
970 }
971 else
972 {
973 $boolError = true;
974 }
975 }
976 else
977 {
978 if ($arItem = $rsItems->Fetch())
979 {
980 $arResult['values'] = (int)$arItem['ID'];
981 }
982 else
983 {
984 $boolError = true;
985 }
986 }
987 break;
988 case 'section':
989 $rsSections = CIBlockSection::GetList(array(), array('ID' => $arOneCondition['value']), false, array('ID'));
990 if ($boolMulti)
991 {
992 $arCheckResult = array();
993 while ($arSection = $rsSections->Fetch())
994 {
995 $arCheckResult[] = (int)$arSection['ID'];
996 }
997 if (!empty($arCheckResult))
998 {
999 $arResult['values'] = $arCheckResult;
1000 }
1001 else
1002 {
1003 $boolError = true;
1004 }
1005 }
1006 else
1007 {
1008 if ($arSection = $rsSections->Fetch())
1009 {
1010 $arResult['values'] = (int)$arSection['ID'];
1011 }
1012 else
1013 {
1014 $boolError = true;
1015 }
1016 }
1017 break;
1018 case 'iblock':
1019 if ($boolMulti)
1020 {
1021 $arCheckResult = array();
1022 foreach ($arOneCondition['value'] as &$intIBlockID)
1023 {
1024 $strName = CIBlock::GetArrayByID($intIBlockID, 'NAME');
1025 if ($strName !== false && $strName !== null)
1026 {
1027 $arCheckResult[] = $intIBlockID;
1028 }
1029 }
1030 if (isset($intIBlockID))
1031 unset($intIBlockID);
1032 if (!empty($arCheckResult))
1033 {
1034 $arResult['values'] = $arCheckResult;
1035 }
1036 else
1037 {
1038 $boolError = true;
1039 }
1040 }
1041 else
1042 {
1043 $strName = CIBlock::GetArrayByID($arOneCondition['value'], 'NAME');
1044 if ($strName !== false && $strName !== null)
1045 {
1046 $arResult['values'] = $arOneCondition['value'];
1047 }
1048 else
1049 {
1050 $boolError = true;
1051 }
1052 }
1053 break;
1054 case 'enumValue':
1055 $iterator = Iblock\PropertyEnumerationTable::getList(array(
1056 'select' => array('ID'),
1057 'filter' => array('@ID' => $arOneCondition['value'])
1058 ));
1059 if ($boolMulti)
1060 {
1061 $checkResult = array();
1062 while ($row = $iterator->fetch())
1063 $checkResult[] = (int)$row['ID'];
1064 unset($row);
1065 if (!empty($checkResult))
1066 $arResult['values'] = $checkResult;
1067 else
1068 $boolError = true;
1069 unset($checkResult);
1070 }
1071 else
1072 {
1073 $row = $iterator->fetch();
1074 if (!empty($row))
1075 $arResult['values'] = (int)$row['ID'];
1076 else
1077 $boolError = true;
1078 unset($row);
1079 }
1080 unset($iterator);
1081 break;
1082 case 'user':
1083 if ($boolMulti)
1084 {
1085 $arCheckResult = array();
1086 $userIterator = UserTable::getList(array(
1087 'select' => array('ID'),
1088 'filter' => array('ID' => $arOneCondition['value'])
1089 ));
1090 while ($user = $userIterator->fetch())
1091 {
1092 $arCheckResult[] = (int)$user['ID'];
1093 }
1094 if (!empty($arCheckResult))
1095 {
1096 $arResult['values'] = $arCheckResult;
1097 }
1098 else
1099 {
1100 $boolError = true;
1101 }
1102 }
1103 else
1104 {
1105 $userIterator = UserTable::getList(array(
1106 'select' => array('ID'),
1107 'filter' => array('ID' => $arOneCondition['value'])
1108 ));
1109 if ($user = $userIterator->fetch())
1110 {
1111 $arResult['values'] = (int)$user['ID'];
1112 }
1113 else
1114 {
1115 $boolError = true;
1116 }
1117 }
1118 break;
1119 case 'list':
1120 if (isset($arControl['JS_VALUE']) && isset($arControl['JS_VALUE']['values']) && !empty($arControl['JS_VALUE']['values']))
1121 {
1122 if ($boolMulti)
1123 {
1124 $arCheckResult = array();
1125 foreach ($arOneCondition['value'] as &$strValue)
1126 {
1127 if (isset($arControl['JS_VALUE']['values'][$strValue]))
1128 $arCheckResult[] = $strValue;
1129 }
1130 if (isset($strValue))
1131 unset($strValue);
1132 if (!empty($arCheckResult))
1133 {
1134 $arResult['values'] = $arCheckResult;
1135 }
1136 else
1137 {
1138 $boolError = true;
1139 }
1140 }
1141 else
1142 {
1143 if (isset($arControl['JS_VALUE']['values'][$arOneCondition['value']]))
1144 {
1145 $arResult['values'] = $arOneCondition['value'];
1146 }
1147 else
1148 {
1149 $boolError = true;
1150 }
1151 }
1152 }
1153 else
1154 {
1155 $boolError = true;
1156 }
1157 break;
1158 }
1159 }
1160 }
1161
1162 if ($boolShow)
1163 {
1164 if ($boolError)
1165 {
1166 $arResult['err_cond'] = 'Y';
1167 $arResult['err_cond_mess'] = $arMsg;
1168 }
1169 return $arResult;
1170 }
1171 else
1172 {
1173 return (!$boolError ? $arResult : false);
1174 }
1175 }
1176
1177 public static function CheckAtoms($arOneCondition, $arParams, $arControl, $boolShow)
1178 {
1179 $boolShow = (true === $boolShow);
1180 $boolError = false;
1181 $boolFatalError = false;
1182 $arMsg = array();
1183
1184 $arValues = array();
1185 $arLabels = array();
1186
1187 static $intTimeOffset = false;
1188 if ($intTimeOffset === false)
1189 $intTimeOffset = CTimeZone::GetOffset();
1190
1191 if (!isset($arControl['ATOMS']) || empty($arControl['ATOMS']) || !is_array($arControl['ATOMS']))
1192 {
1193 $boolFatalError = true;
1194 $boolError = true;
1195 $arMsg[] = Loc::getMessage('BT_GLOBAL_COND_ERR_ATOMS_ABSENT');
1196 }
1197 if (!$boolError)
1198 {
1199 $boolValidate = false;
1200 if ($boolShow)
1201 {
1202 foreach ($arControl['ATOMS'] as &$arOneAtom)
1203 {
1204 $boolAtomError = false;
1205 $strID = $arOneAtom['ATOM']['ID'];
1206 $boolMulti = false;
1207 if (!isset($arOneCondition[$strID]))
1208 {
1209 $boolAtomError = true;
1210 }
1211 else
1212 {
1213 $boolMulti = is_array($arOneCondition[$strID]);
1214 switch ($arOneAtom['ATOM']['FIELD_TYPE'])
1215 {
1216 case 'int':
1217 if ($boolMulti)
1218 {
1219 foreach ($arOneCondition[$strID] as &$intOneValue)
1220 {
1221 $intOneValue = (int)$intOneValue;
1222 }
1223 if (isset($intOneValue))
1224 unset($intOneValue);
1225 }
1226 else
1227 {
1228 $arOneCondition[$strID] = (int)$arOneCondition[$strID];
1229 }
1230 break;
1231 case 'double':
1232 if ($boolMulti)
1233 {
1234 foreach ($arOneCondition[$strID] as &$dblOneValue)
1235 {
1236 $dblOneValue = (float)$dblOneValue;
1237 }
1238 if (isset($dblOneValue))
1239 unset($dblOneValue);
1240 }
1241 else
1242 {
1243 $arOneCondition[$strID] = doubleval($arOneCondition[$strID]);
1244 }
1245 break;
1246 case 'strdouble':
1247 if ($boolMulti)
1248 {
1249 foreach ($arOneCondition[$strID] as &$dblOneValue)
1250 {
1251 if ($dblOneValue !== '')
1252 $dblOneValue = (float)$dblOneValue;
1253 }
1254 if (isset($dblOneValue))
1255 unset($dblOneValue);
1256 }
1257 else
1258 {
1259 if ($arOneCondition[$strID] !== '')
1260 $arOneCondition[$strID] = (float)$arOneCondition[$strID];
1261 }
1262 break;
1263 case 'char':
1264 if ($boolMulti)
1265 {
1266 foreach ($arOneCondition[$strID] as &$strOneValue)
1267 {
1268 $strOneValue = mb_substr($strOneValue, 0, 1);
1269 }
1270 if (isset($strOneValue))
1271 unset($strOneValue);
1272 }
1273 else
1274 {
1275 $arOneCondition[$strID] = mb_substr($arOneCondition[$strID], 0, 1);
1276 }
1277 break;
1278 case 'string':
1279 $intMaxLen = (int)(isset($arOneAtom['ATOM']['FIELD_LENGTH']) ? $arOneAtom['ATOM']['FIELD_LENGTH'] : 255);
1280 if ($intMaxLen <= 0)
1281 $intMaxLen = 255;
1282 if ($boolMulti)
1283 {
1284 foreach ($arOneCondition[$strID] as &$strOneValue)
1285 {
1286 $strOneValue = mb_substr($strOneValue, 0, $intMaxLen);
1287 }
1288 if (isset($strOneValue))
1289 unset($strOneValue);
1290 }
1291 else
1292 {
1293 $arOneCondition[$strID] = mb_substr($arOneCondition[$strID], 0, $intMaxLen);
1294 }
1295 break;
1296 case 'text':
1297 break;
1298 case 'date':
1299 case 'datetime':
1300 if ($arOneAtom['ATOM']['FIELD_TYPE'] == 'date')
1301 {
1302 $strFormat = 'SHORT';
1303 $intOffset = 0;
1304 }
1305 else
1306 {
1307 $strFormat = 'FULL';
1308 $intOffset = $intTimeOffset;
1309 }
1310 $boolAtomError = static::ConvertInt2DateTime($arOneCondition[$strID], $strFormat, $intOffset);
1311 break;
1312 default:
1313 $boolAtomError = true;
1314 }
1315 }
1316 if (!$boolAtomError)
1317 {
1318 if ($boolMulti)
1319 $arOneCondition[$strID] = array_values(array_unique($arOneCondition[$strID]));
1320 $arValues[$strID] = $arOneCondition[$strID];
1321 if (isset($arOneAtom['ATOM']['VALIDATE']) && !empty($arOneAtom['ATOM']['VALIDATE']))
1322 $boolValidate = true;
1323 }
1324 else
1325 {
1326 $arValues[$strID] = '';
1327 }
1328 if ($boolAtomError)
1329 $boolError = true;
1330 }
1331 if (isset($arOneAtom))
1332 unset($arOneAtom);
1333
1334 if (!$boolError)
1335 {
1336 if ($boolValidate)
1337 {
1338 $arValidate = static::ValidateAtoms($arValues, $arParams, $arControl, $boolShow);
1339 if ($arValidate === false)
1340 {
1341 $boolError = true;
1342 }
1343 else
1344 {
1345 if (isset($arValidate['err_cond']) && $arValidate['err_cond'] == 'Y')
1346 {
1347 $boolError = true;
1348 if (isset($arValidate['err_cond_mess']) && !empty($arValidate['err_cond_mess']))
1349 $arMsg = array_merge($arMsg, $arValidate['err_cond_mess']);
1350 }
1351 else
1352 {
1353 $arValues = $arValidate['values'];
1354 if (isset($arValidate['labels']))
1355 $arLabels = $arValidate['labels'];
1356 }
1357 }
1358 }
1359 }
1360 }
1361 else
1362 {
1363 foreach ($arControl['ATOMS'] as &$arOneAtom)
1364 {
1365 $boolAtomError = false;
1366 $strID = $arOneAtom['ATOM']['ID'];
1367 $strName = $arOneAtom['JS']['name'];
1368 $boolMulti = false;
1369 if (!isset($arOneCondition[$strName]))
1370 {
1371 $boolAtomError = true;
1372 }
1373 else
1374 {
1375 $boolMulti = is_array($arOneCondition[$strName]);
1376 }
1377 if (!$boolAtomError)
1378 {
1379 switch ($arOneAtom['ATOM']['FIELD_TYPE'])
1380 {
1381 case 'int':
1382 if ($boolMulti)
1383 {
1384 foreach ($arOneCondition[$strName] as &$intOneValue)
1385 {
1386 $intOneValue = (int)$intOneValue;
1387 }
1388 if (isset($intOneValue))
1389 unset($intOneValue);
1390 }
1391 else
1392 {
1393 $arOneCondition[$strName] = (int)$arOneCondition[$strName];
1394 }
1395 break;
1396 case 'double':
1397 if ($boolMulti)
1398 {
1399 foreach ($arOneCondition[$strName] as &$dblOneValue)
1400 {
1401 $dblOneValue = (float)$dblOneValue;
1402 }
1403 if (isset($dblOneValue))
1404 unset($dblOneValue);
1405 }
1406 else
1407 {
1408 $arOneCondition[$strName] = (float)$arOneCondition[$strName];
1409 }
1410 break;
1411 case 'strdouble':
1412 if ($boolMulti)
1413 {
1414 foreach ($arOneCondition[$strName] as &$dblOneValue)
1415 {
1416 if ($dblOneValue !== '')
1417 $dblOneValue = (float)$dblOneValue;
1418 }
1419 if (isset($dblOneValue))
1420 unset($dblOneValue);
1421 }
1422 else
1423 {
1424 if ($arOneCondition[$strName] !== '')
1425 {
1426 $arOneCondition[$strName] = (float)$arOneCondition[$strName];
1427 }
1428 }
1429 break;
1430 case 'char':
1431 if ($boolMulti)
1432 {
1433 foreach ($arOneCondition[$strName] as &$strOneValue)
1434 {
1435 $strOneValue = mb_substr($strOneValue, 0, 1);
1436 }
1437 if (isset($strOneValue))
1438 unset($strOneValue);
1439 }
1440 else
1441 {
1442 $arOneCondition[$strName] = mb_substr($arOneCondition[$strName], 0, 1);
1443 }
1444 break;
1445 case 'string':
1446 $intMaxLen = (int)(isset($arOneAtom['ATOM']['FIELD_LENGTH']) ? $arOneAtom['ATOM']['FIELD_LENGTH'] : 255);
1447 if ($intMaxLen <= 0)
1448 $intMaxLen = 255;
1449 if ($boolMulti)
1450 {
1451 foreach ($arOneCondition[$strName] as &$strOneValue)
1452 {
1453 $strOneValue = mb_substr($strOneValue, 0, $intMaxLen);
1454 }
1455 if (isset($strOneValue))
1456 unset($strOneValue);
1457 }
1458 else
1459 {
1460 $arOneCondition[$strName] = mb_substr($arOneCondition[$strName], 0, $intMaxLen);
1461 }
1462 break;
1463 case 'text':
1464 break;
1465 case 'date':
1466 case 'datetime':
1467 if ($arOneAtom['ATOM']['FIELD_TYPE'] == 'date')
1468 {
1469 $strFormat = 'SHORT';
1470 $intOffset = 0;
1471 }
1472 else
1473 {
1474 $strFormat = 'FULL';
1475 $intOffset = $intTimeOffset;
1476 }
1477 $boolAtomError = static::ConvertDateTime2Int($arOneCondition[$strName], $strFormat, $intOffset);
1478 break;
1479 default:
1480 $boolAtomError = true;
1481 }
1482 if (!$boolAtomError)
1483 {
1484 if ($boolMulti)
1485 $arOneCondition[$strName] = array_values(array_unique($arOneCondition[$strName]));
1486 $arValues[$strID] = $arOneCondition[$strName];
1487 if (isset($arOneAtom['ATOM']['VALIDATE']) && !empty($arOneAtom['ATOM']['VALIDATE']))
1488 $boolValidate = true;
1489 }
1490 else
1491 {
1492 $arValues[$strID] = '';
1493 }
1494 }
1495 if ($boolAtomError)
1496 $boolError = true;
1497 }
1498 if (isset($arOneAtom))
1499 unset($arOneAtom);
1500
1501 if (!$boolError)
1502 {
1503 if ($boolValidate)
1504 {
1505 $arValidate = static::ValidateAtoms($arValues, $arParams, $arControl, $boolShow);
1506 if ($arValidate === false)
1507 {
1508 $boolError = true;
1509 }
1510 else
1511 {
1512 $arValues = $arValidate['values'];
1513 if (isset($arValidate['labels']))
1514 $arLabels = $arValidate['labels'];
1515 }
1516 }
1517 }
1518 }
1519 }
1520
1521 if ($boolShow)
1522 {
1523 $arResult = array(
1524 'id' => $arParams['COND_NUM'],
1525 'controlId' => $arControl['ID'],
1526 'values' => $arValues
1527 );
1528 if (!empty($arLabels))
1529 $arResult['labels'] = $arLabels;
1530 if ($boolError)
1531 {
1532 $arResult['err_cond'] = 'Y';
1533 if ($boolFatalError)
1534 $arResult['fatal_err_cond'] = 'Y';
1535 if (!empty($arMsg))
1536 $arResult['err_cond_mess'] = implode('. ', $arMsg);
1537 }
1538 return $arResult;
1539 }
1540 else
1541 {
1542 return (!$boolError ? $arValues : false);
1543 }
1544 }
1545
1546 public static function ValidateAtoms($arValues, $arParams, $arControl, $boolShow)
1547 {
1548 static $userNameFormat = null;
1549
1550 $boolShow = ($boolShow === true);
1551 $boolError = false;
1552 $arMsg = array();
1553
1554 $arResult = array(
1555 'values' => array(),
1556 'labels' => array(),
1557 'titles' => array()
1558 );
1559
1560 if (!isset($arControl['ATOMS']) || empty($arControl['ATOMS']) || !is_array($arControl['ATOMS']))
1561 {
1562 $boolError = true;
1563 $arMsg[] = Loc::getMessage('BT_GLOBAL_COND_ERR_ATOMS_ABSENT');
1564 }
1565 if (!$boolError)
1566 {
1567 if ($boolShow)
1568 {
1569 foreach ($arControl['ATOMS'] as &$arOneAtom)
1570 {
1571 $strID = $arOneAtom['ATOM']['ID'];
1572 if (!isset($arOneAtom['ATOM']['VALIDATE']) || empty($arOneAtom['ATOM']['VALIDATE']))
1573 {
1574 $arResult['values'][$strID] = $arValues[$strID];
1575 continue;
1576 }
1577 switch ($arOneAtom['ATOM']['VALIDATE'])
1578 {
1579 case 'list':
1580 if (isset($arOneAtom['JS']) && isset($arOneAtom['JS']['values']) && !empty($arOneAtom['JS']['values']))
1581 {
1582 if (is_array($arValues[$strID]))
1583 {
1584 $arCheckResult = array();
1585 foreach ($arValues[$strID] as &$strValue)
1586 {
1587 if (isset($arOneAtom['JS']['values'][$strValue]))
1588 $arCheckResult[] = $strValue;
1589 }
1590 if (isset($strValue))
1591 unset($strValue);
1592 if (!empty($arCheckResult))
1593 {
1594 $arResult['values'][$strID] = $arCheckResult;
1595 }
1596 else
1597 {
1598 $boolError = true;
1599 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_LIST_ABSENT_MULTI');
1600 }
1601 }
1602 else
1603 {
1604 if (isset($arOneAtom['JS']['values'][$arValues[$strID]]))
1605 {
1606 $arResult['values'][$strID] = $arValues[$strID];
1607 }
1608 else
1609 {
1610 $boolError = true;
1611 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_LIST_ABSENT');
1612 }
1613 }
1614 }
1615 else
1616 {
1617 $boolError = true;
1618 }
1619 break;
1620 case 'element':
1621 $rsItems = CIBlockElement::GetList(array(), array('ID' => $arValues[$strID]), false, false, array('ID', 'NAME'));
1622 if (is_array($arValues[$strID]))
1623 {
1624 $arCheckResult = array();
1625 while ($arItem = $rsItems->Fetch())
1626 {
1627 $arCheckResult[(int)$arItem['ID']] = $arItem['NAME'];
1628 }
1629 if (!empty($arCheckResult))
1630 {
1631 $arResult['values'][$strID] = array_keys($arCheckResult);
1632 $arResult['labels'][$strID] = array_values($arCheckResult);
1633 }
1634 else
1635 {
1636 $boolError = true;
1637 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_ELEMENT_ABSENT_MULTI');
1638 }
1639 }
1640 else
1641 {
1642 if ($arItem = $rsItems->Fetch())
1643 {
1644 $arResult['values'][$strID] = (int)$arItem['ID'];
1645 $arResult['labels'][$strID] = $arItem['NAME'];
1646 }
1647 else
1648 {
1649 $boolError = true;
1650 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_ELEMENT_ABSENT');
1651 }
1652 }
1653 break;
1654 case 'section':
1655 $rsSections = CIBlockSection::GetList(array(), array('ID' => $arValues[$strID]), false, array('ID', 'NAME'));
1656 if (is_array($arValues[$strID]))
1657 {
1658 $arCheckResult = array();
1659 while ($arSection = $rsSections->Fetch())
1660 {
1661 $arCheckResult[(int)$arSection['ID']] = $arSection['NAME'];
1662 }
1663 if (!empty($arCheckResult))
1664 {
1665 $arResult['values'][$strID] = array_keys($arCheckResult);
1666 $arResult['labels'][$strID] = array_values($arCheckResult);
1667 }
1668 else
1669 {
1670 $boolError = true;
1671 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_SECTION_ABSENT_MULTI');
1672 }
1673 }
1674 else
1675 {
1676 if ($arSection = $rsSections->Fetch())
1677 {
1678 $arResult['values'][$strID] = (int)$arSection['ID'];
1679 $arResult['labels'][$strID] = $arSection['NAME'];
1680 }
1681 else
1682 {
1683 $boolError = true;
1684 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_SECTION_ABSENT');
1685 }
1686 }
1687 break;
1688 case 'iblock':
1689 if (is_array($arValues[$strID]))
1690 {
1691 $arCheckResult = array();
1692 foreach ($arValues[$strID] as &$intIBlockID)
1693 {
1694 $strName = CIBlock::GetArrayByID($intIBlockID, 'NAME');
1695 if ($strName !== false && $strName !== null)
1696 {
1697 $arCheckResult[$intIBlockID] = $strName;
1698 }
1699 }
1700 if (isset($intIBlockID))
1701 unset($intIBlockID);
1702 if (!empty($arCheckResult))
1703 {
1704 $arResult['values'][$strID] = array_keys($arCheckResult);
1705 $arResult['labels'][$strID] = array_values($arCheckResult);
1706 }
1707 else
1708 {
1709 $boolError = true;
1710 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_IBLOCK_ABSENT_MULTI');
1711 }
1712 }
1713 else
1714 {
1715 $strName = CIBlock::GetArrayByID($arValues[$strID], 'NAME');
1716 if ($strName !== false && $strName !== null)
1717 {
1718 $arResult['values'][$strID] = $arValues[$strID];
1719 $arResult['labels'][$strID] = $strName;
1720 }
1721 else
1722 {
1723 $boolError = true;
1724 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_IBLOCK_ABSENT');
1725 }
1726 }
1727 break;
1728 case 'user':
1729 if ($userNameFormat === null)
1730 $userNameFormat = CSite::GetNameFormat(true);
1731 if (is_array($arValues[$strID]))
1732 {
1733 $arCheckResult = array();
1734 $userIterator = UserTable::getList(array(
1735 'select' => array('ID', 'LOGIN', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'EMAIL'),
1736 'filter' => array('ID' => $arValues[$strID])
1737 ));
1738 while ($user = $userIterator->fetch())
1739 {
1740 $user['ID'] = (int)$user['ID'];
1741 $arCheckResult[$user['ID']] = CUser::FormatName($userNameFormat, $user);
1742 }
1743 if (!empty($arCheckResult))
1744 {
1745 $arResult['values'][$strID] = array_keys($arCheckResult);
1746 $arResult['labels'][$strID] = array_values($arCheckResult);
1747 }
1748 else
1749 {
1750 $boolError = true;
1751 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_USER_ABSENT_MULTI');
1752 }
1753 }
1754 else
1755 {
1756 $userIterator = UserTable::getList(array(
1757 'select' => array('ID', 'LOGIN', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'EMAIL'),
1758 'filter' => array('ID' => $arValues[$strID])
1759 ));
1760 if ($user = $userIterator->fetch())
1761 {
1762 $arResult['values'] = (int)$user['ID'];
1763 $arResult['labels'] = CUser::FormatName($userNameFormat, $user);
1764 }
1765 else
1766 {
1767 $boolError = true;
1768 $arMsg[] = Loc::getMessage('BT_MOD_COND_ERR_CHECK_DATA_USER_ABSENT');
1769 }
1770 }
1771 break;
1772 }
1773 }
1774 if (isset($arOneAtom))
1775 unset($arOneAtom);
1776 }
1777 else
1778 {
1779 foreach ($arControl['ATOMS'] as &$arOneAtom)
1780 {
1781 $strID = $arOneAtom['ATOM']['ID'];
1782 if (!isset($arOneAtom['ATOM']['VALIDATE']) || empty($arOneAtom['ATOM']['VALIDATE']))
1783 {
1784 $arResult['values'][$strID] = $arValues[$strID];
1785 continue;
1786 }
1787 switch ($arOneAtom['ATOM']['VALIDATE'])
1788 {
1789 case 'list':
1790 if (isset($arOneAtom['JS']) && isset($arOneAtom['JS']['values']) && !empty($arOneAtom['JS']['values']))
1791 {
1792 if (is_array($arValues[$strID]))
1793 {
1794 $arCheckResult = array();
1795 foreach ($arValues[$strID] as &$strValue)
1796 {
1797 if (isset($arOneAtom['JS']['values'][$strValue]))
1798 $arCheckResult[] = $strValue;
1799 }
1800 if (isset($strValue))
1801 unset($strValue);
1802 if (!empty($arCheckResult))
1803 {
1804 $arResult['values'][$strID] = $arCheckResult;
1805 }
1806 else
1807 {
1808 $boolError = true;
1809 }
1810 }
1811 else
1812 {
1813 if (isset($arOneAtom['JS']['values'][$arValues[$strID]]))
1814 {
1815 $arResult['values'][$strID] = $arValues[$strID];
1816 }
1817 else
1818 {
1819 $boolError = true;
1820 }
1821 }
1822 }
1823 else
1824 {
1825 $boolError = true;
1826 }
1827 break;
1828 case 'element':
1829 $rsItems = CIBlockElement::GetList(array(), array('ID' => $arValues[$strID]), false, false, array('ID'));
1830 if (is_array($arValues[$strID]))
1831 {
1832 $arCheckResult = array();
1833 while ($arItem = $rsItems->Fetch())
1834 {
1835 $arCheckResult[] = (int)$arItem['ID'];
1836 }
1837 if (!empty($arCheckResult))
1838 {
1839 $arResult['values'][$strID] = $arCheckResult;
1840 }
1841 else
1842 {
1843 $boolError = true;
1844 }
1845 }
1846 else
1847 {
1848 if ($arItem = $rsItems->Fetch())
1849 {
1850 $arResult['values'][$strID] = (int)$arItem['ID'];
1851 }
1852 else
1853 {
1854 $boolError = true;
1855 }
1856 }
1857 break;
1858 case 'section':
1859 $rsSections = CIBlockSection::GetList(array(), array('ID' => $arValues[$strID]), false, array('ID'));
1860 if (is_array($arValues[$strID]))
1861 {
1862 $arCheckResult = array();
1863 while ($arSection = $rsSections->Fetch())
1864 {
1865 $arCheckResult[] = (int)$arSection['ID'];
1866 }
1867 if (!empty($arCheckResult))
1868 {
1869 $arResult['values'][$strID] = $arCheckResult;
1870 }
1871 else
1872 {
1873 $boolError = true;
1874 }
1875 }
1876 else
1877 {
1878 if ($arSection = $rsSections->Fetch())
1879 {
1880 $arResult['values'][$strID] = (int)$arSection['ID'];
1881 }
1882 else
1883 {
1884 $boolError = true;
1885 }
1886 }
1887 break;
1888 case 'iblock':
1889 if (is_array($arValues[$strID]))
1890 {
1891 $arCheckResult = array();
1892 foreach ($arValues[$strID] as &$intIBlockID)
1893 {
1894 $strName = CIBlock::GetArrayByID($intIBlockID, 'NAME');
1895 if ($strName !== false && $strName !== null)
1896 {
1897 $arCheckResult[] = $intIBlockID;
1898 }
1899 }
1900 if (isset($intIBlockID))
1901 unset($intIBlockID);
1902 if (!empty($arCheckResult))
1903 {
1904 $arResult['values'][$strID] = $arCheckResult;
1905 }
1906 else
1907 {
1908 $boolError = true;
1909 }
1910 }
1911 else
1912 {
1913 $strName = CIBlock::GetArrayByID($arValues[$strID], 'NAME');
1914 if ($strName !== false && $strName !== null)
1915 {
1916 $arResult['values'][$strID] = $arValues[$strID];
1917 }
1918 else
1919 {
1920 $boolError = true;
1921 }
1922 }
1923 break;
1924 case 'user':
1925 if (is_array($arValues[$strID]))
1926 {
1927 $arCheckResult = array();
1928 $userIterator = UserTable::getList(array(
1929 'select' => array('ID'),
1930 'filter' => array('ID' => $arValues[$strID])
1931 ));
1932 while ($user = $userIterator->fetch())
1933 {
1934 $arCheckResult[] = (int)$user['ID'];
1935 }
1936 if (!empty($arCheckResult))
1937 {
1938 $arResult['values'][$strID] = $arCheckResult;
1939 }
1940 else
1941 {
1942 $boolError = true;
1943 }
1944 }
1945 else
1946 {
1947 $userIterator = UserTable::getList(array(
1948 'select' => array('ID'),
1949 'filter' => array('ID' => $arValues[$strID])
1950 ));
1951 if ($user = $userIterator->fetch())
1952 {
1953 $arCheckResult[] = (int)$user['ID'];
1954 }
1955 else
1956 {
1957 $boolError = true;
1958 }
1959 }
1960 break;
1961 }
1962 }
1963 if (isset($arOneAtom))
1964 unset($arOneAtom);
1965 }
1966 }
1967
1968 if ($boolShow)
1969 {
1970 if ($boolError)
1971 {
1972 $arResult['err_cond'] = 'Y';
1973 $arResult['err_cond_mess'] = $arMsg;
1974 }
1975 return $arResult;
1976 }
1977 else
1978 {
1979 return (!$boolError ? $arResult : false);
1980 }
1981 }
1982
1983 public static function LogicGreat($arField, $mxValue)
1984 {
1985 $boolResult = false;
1986 if (!is_array($arField))
1987 $arField = array($arField);
1988 if (!empty($arField))
1989 {
1990 foreach ($arField as &$mxOneValue)
1991 {
1992 if ($mxOneValue === null || $mxOneValue === false || $mxOneValue === '')
1993 continue;
1994 if ($mxOneValue > $mxValue)
1995 {
1996 $boolResult = true;
1997 break;
1998 }
1999 }
2000 if (isset($mxOneValue))
2001 unset($mxOneValue);
2002 }
2003 return $boolResult;
2004 }
2005
2006 public static function LogicLess($arField, $mxValue)
2007 {
2008 $boolResult = false;
2009 if (!is_array($arField))
2010 $arField = array($arField);
2011 if (!empty($arField))
2012 {
2013 foreach ($arField as &$mxOneValue)
2014 {
2015 if ($mxOneValue === null || $mxOneValue === false || $mxOneValue === '')
2016 continue;
2017 if ($mxOneValue < $mxValue)
2018 {
2019 $boolResult = true;
2020 break;
2021 }
2022 }
2023 if (isset($mxOneValue))
2024 unset($mxOneValue);
2025 }
2026 return $boolResult;
2027 }
2028
2029 public static function LogicEqualGreat($arField, $mxValue)
2030 {
2031 $boolResult = false;
2032 if (!is_array($arField))
2033 $arField = array($arField);
2034 if (!empty($arField))
2035 {
2036 foreach ($arField as &$mxOneValue)
2037 {
2038 if ($mxOneValue === null || $mxOneValue === false || $mxOneValue === '')
2039 continue;
2040 if ($mxOneValue >= $mxValue)
2041 {
2042 $boolResult = true;
2043 break;
2044 }
2045 }
2046 if (isset($mxOneValue))
2047 unset($mxOneValue);
2048 }
2049 return $boolResult;
2050 }
2051
2052 public static function LogicEqualLess($arField, $mxValue)
2053 {
2054 $boolResult = false;
2055 if (!is_array($arField))
2056 $arField = array($arField);
2057 if (!empty($arField))
2058 {
2059 foreach ($arField as &$mxOneValue)
2060 {
2061 if ($mxOneValue === null || $mxOneValue === false || $mxOneValue === '')
2062 continue;
2063 if ($mxOneValue <= $mxValue)
2064 {
2065 $boolResult = true;
2066 break;
2067 }
2068 }
2069 if (isset($mxOneValue))
2070 unset($mxOneValue);
2071 }
2072 return $boolResult;
2073 }
2074
2075 public static function LogicContain($arField, $mxValue)
2076 {
2077 $boolResult = false;
2078 if (!is_array($arField))
2079 $arField = array($arField);
2080 if (!empty($arField))
2081 {
2082 foreach ($arField as &$mxOneValue)
2083 {
2084 if (mb_strpos($mxOneValue, $mxValue) !== false)
2085 {
2086 $boolResult = true;
2087 break;
2088 }
2089 }
2090 if (isset($mxOneValue))
2091 unset($mxOneValue);
2092 }
2093 return $boolResult;
2094 }
2095
2096 public static function LogicNotContain($arField, $mxValue)
2097 {
2098 $boolResult = true;
2099 if (!is_array($arField))
2100 $arField = array($arField);
2101 if (!empty($arField))
2102 {
2103 foreach ($arField as &$mxOneValue)
2104 {
2105 if (mb_strpos($mxOneValue, $mxValue) !== false)
2106 {
2107 $boolResult = false;
2108 break;
2109 }
2110 }
2111 if (isset($mxOneValue))
2112 unset($mxOneValue);
2113 }
2114 return $boolResult;
2115 }
2116
2117 public static function ClearValue(&$mxValues)
2118 {
2119 $boolLocalError = false;
2120 if (is_array($mxValues))
2121 {
2122 if (!empty($mxValues))
2123 {
2124 $arResult = array();
2125 foreach ($mxValues as &$strOneValue)
2126 {
2127 $strOneValue = trim((string)$strOneValue);
2128 if ($strOneValue !== '')
2129 $arResult[] = $strOneValue;
2130 }
2131 if (isset($strOneValue))
2132 unset($strOneValue);
2133 $mxValues = $arResult;
2134 if (empty($mxValues))
2135 $boolLocalError = true;
2136 }
2137 else
2138 {
2139 $boolLocalError = true;
2140 }
2141 }
2142 else
2143 {
2144 $mxValues = trim((string)$mxValues);
2145 if ($mxValues === '')
2146 {
2147 $boolLocalError = true;
2148 }
2149 }
2150 return $boolLocalError;
2151 }
2152
2153 public static function ConvertInt2DateTime(&$mxValues, $strFormat, $intOffset)
2154 {
2155 global $DB;
2156
2157 $boolValueError = false;
2158 if (is_array($mxValues))
2159 {
2160 foreach ($mxValues as &$strValue)
2161 {
2162 if ($strValue.'!' == (int)$strValue.'!')
2163 {
2164 $strValue = ConvertTimeStamp($strValue + $intOffset, $strFormat);
2165 }
2166 if (!$DB->IsDate($strValue, false, false, $strFormat))
2167 {
2168 $boolValueError = true;
2169 }
2170 }
2171 if (isset($strValue))
2172 unset($strValue);
2173 }
2174 else
2175 {
2176 if ($mxValues.'!' == (int)$mxValues.'!')
2177 {
2178 $mxValues = ConvertTimeStamp($mxValues + $intOffset, $strFormat);
2179 }
2180 $boolValueError = !$DB->IsDate($mxValues, false, false, $strFormat);
2181 }
2182 return $boolValueError;
2183 }
2184
2185 public static function ConvertDateTime2Int(&$mxValues, $strFormat, $intOffset)
2186 {
2187 global $DB;
2188
2189 $boolError = false;
2190 if (is_array($mxValues))
2191 {
2192 $boolLocalErr = false;
2193 $arLocal = array();
2194 foreach ($mxValues as &$strValue)
2195 {
2196 if ($strValue.'!' != (int)$strValue.'!')
2197 {
2198 if (!$DB->IsDate($strValue, false, false, $strFormat))
2199 {
2200 $boolError = true;
2201 $boolLocalErr = true;
2202 break;
2203 }
2204 $arLocal[] = MakeTimeStamp($strValue) - $intOffset;
2205 }
2206 else
2207 {
2208 $arLocal[] = $strValue;
2209 }
2210 }
2211 if (isset($strValue))
2212 unset($strValue);
2213 if (!$boolLocalErr)
2214 $mxValues = $arLocal;
2215 }
2216 else
2217 {
2218 if ($mxValues.'!' != (int)$mxValues.'!')
2219 {
2220 if (!$DB->IsDate($mxValues, false, false, $strFormat))
2221 {
2222 $boolError = true;
2223 }
2224 else
2225 {
2226 $mxValues = MakeTimeStamp($mxValues) - $intOffset;
2227 }
2228 }
2229 }
2230 return $boolError;
2231 }
2232
2239 protected static function searchControlAtoms(array $atoms, $controlId, $extendedMode)
2240 {
2241 if (empty($atoms))
2242 return false;
2243
2244 $extendedMode = ($extendedMode === true);
2245 if (!$extendedMode)
2246 {
2247 foreach (array_keys($atoms) as $index)
2248 {
2249 foreach (array_keys($atoms[$index]) as $atomId)
2250 {
2251 $atoms[$index][$atomId] = $atoms[$index][$atomId]['JS'];
2252 }
2253 }
2254 unset($atomId, $index);
2255 }
2256
2257 if ($controlId === false)
2258 return $atoms;
2259
2260 $controlId = (string)$controlId;
2261 return (isset($atoms[$controlId]) ? $atoms[$controlId] : false);
2262 }
2263
2264 protected static function searchControl(array $controls, $controlId)
2265 {
2266 if (empty($controls))
2267 return false;
2268
2269 if ($controlId === false)
2270 return $controls;
2271
2272 $controlId = (string)$controlId;
2273 return (isset($controls[$controlId]) ? $controls[$controlId] : false);
2274 }
2275}
2276
2278{
2279 public static function GetControlDescr()
2280 {
2281 $strClassName = get_called_class();
2282 return array(
2283 'COMPLEX' => 'Y',
2284 'GetControlShow' => array($strClassName, 'GetControlShow'),
2285 'GetConditionShow' => array($strClassName, 'GetConditionShow'),
2286 'IsGroup' => array($strClassName, 'IsGroup'),
2287 'Parse' => array($strClassName, 'Parse'),
2288 'Generate' => array($strClassName, 'Generate'),
2289 'ApplyValues' => array($strClassName, 'ApplyValues'),
2290 'InitParams' => array($strClassName, 'InitParams'),
2291 'CONTROLS' => static::GetControls()
2292 );
2293 }
2294
2295 public static function GetConditionShow($arParams)
2296 {
2297 if (!isset($arParams['ID']))
2298 return false;
2299 $arControl = static::GetControls($arParams['ID']);
2300 if ($arControl === false)
2301 return false;
2302 if (!isset($arParams['DATA']))
2303 return false;
2304 return static::Check($arParams['DATA'], $arParams, $arControl, true);
2305 }
2306
2307 public static function Parse($arOneCondition)
2308 {
2309 if (!isset($arOneCondition['controlId']))
2310 return false;
2311 $arControl = static::GetControls($arOneCondition['controlId']);
2312 if ($arControl === false)
2313 return false;
2314 return static::Check($arOneCondition, $arOneCondition, $arControl, false);
2315 }
2316
2317 public static function Generate($arOneCondition, $arParams, $arControl, $arSubs = false)
2318 {
2319 $strResult = '';
2320 $resultValues = array();
2321 $arValues = false;
2322
2323 if (is_string($arControl))
2324 {
2325 $arControl = static::GetControls($arControl);
2326 }
2327 $boolError = !is_array($arControl);
2328
2329 if (!$boolError)
2330 {
2331 $arValues = static::Check($arOneCondition, $arOneCondition, $arControl, false);
2332 $boolError = ($arValues === false);
2333 }
2334 if (!$boolError)
2335 {
2336 $boolError = !isset($arControl['MULTIPLE']);
2337 }
2338
2339 if (!$boolError)
2340 {
2341 $arLogic = static::SearchLogic($arValues['logic'], $arControl['LOGIC']);
2342 if (!isset($arLogic['OP'][$arControl['MULTIPLE']]) || empty($arLogic['OP'][$arControl['MULTIPLE']]))
2343 {
2344 $boolError = true;
2345 }
2346 else
2347 {
2348 $strField = $arParams['FIELD'].'[\''.$arControl['FIELD'].'\']';
2349 switch ($arControl['FIELD_TYPE'])
2350 {
2351 case 'int':
2352 case 'double':
2353 if (is_array($arValues['value']))
2354 {
2355 if (!isset($arLogic['MULTI_SEP']))
2356 {
2357 $boolError = true;
2358 }
2359 else
2360 {
2361 foreach ($arValues['value'] as &$value)
2362 {
2363 $resultValues[] = str_replace(
2364 array('#FIELD#', '#VALUE#'),
2365 array($strField, $value),
2366 $arLogic['OP'][$arControl['MULTIPLE']]
2367 );
2368 }
2369 unset($value);
2370 $strResult = '('.implode($arLogic['MULTI_SEP'], $resultValues).')';
2371 unset($resultValues);
2372 }
2373 }
2374 else
2375 {
2376 $strResult = str_replace(
2377 array('#FIELD#', '#VALUE#'),
2378 array($strField, $arValues['value']),
2379 $arLogic['OP'][$arControl['MULTIPLE']]
2380 );
2381 }
2382 break;
2383 case 'char':
2384 case 'string':
2385 case 'text':
2386 if (is_array($arValues['value']))
2387 {
2388 $boolError = true;
2389 }
2390 else
2391 {
2392 $strResult = str_replace(
2393 array('#FIELD#', '#VALUE#'),
2394 array($strField, '"'.EscapePHPString($arValues['value']).'"'),
2395 $arLogic['OP'][$arControl['MULTIPLE']]
2396 );
2397 }
2398 break;
2399 case 'date':
2400 case 'datetime':
2401 if (is_array($arValues['value']))
2402 {
2403 $boolError = true;
2404 }
2405 else
2406 {
2407 $strResult = str_replace(
2408 array('#FIELD#', '#VALUE#'),
2409 array($strField, $arValues['value']),
2410 $arLogic['OP'][$arControl['MULTIPLE']]
2411 );
2412 }
2413 break;
2414 }
2415 }
2416 }
2417
2418 return (!$boolError ? $strResult : false);
2419 }
2420
2425 public static function GetControls($strControlID = false)
2426 {
2427 return false;
2428 }
2429}
2430
2431class CGlobalCondCtrlAtoms extends CGlobalCondCtrl
2432{
2436 public static function GetControlDescr()
2437 {
2438 $className = get_called_class();
2439 $controls = static::GetControls();
2440 if (empty($controls) || !is_array($controls))
2441 return false;
2442 $result = array();
2443 foreach ($controls as &$oneControl)
2444 {
2445 unset($oneControl['ATOMS']);
2446 $row = $oneControl;
2447 $row['GetControlShow'] = array($className, 'GetControlShow');
2448 $row['GetConditionShow'] = array($className, 'GetConditionShow');
2449 $row['IsGroup'] = array($className, 'IsGroup');
2450 $row['Parse'] = array($className, 'Parse');
2451 $row['Generate'] = array($className, 'Generate');
2452 $row['ApplyValues'] = array($className, 'ApplyValues');
2453 $row['InitParams'] = array($className, 'InitParams');
2454
2455 $result[] = $row;
2456 unset($row);
2457 }
2458 unset($oneControl, $controls, $className);
2459 return $result;
2460 }
2461
2462 public static function GetConditionShow($params)
2463 {
2464 if (!isset($params['ID']))
2465 return false;
2466 $atoms = static::GetAtomsEx($params['ID'], true);
2467 if (empty($atoms))
2468 return false;
2469 $control = array(
2470 'ID' => $params['ID'],
2471 'ATOMS' => $atoms
2472 );
2473 unset($atoms);
2474 return static::CheckAtoms($params['DATA'], $params, $control, true);
2475 }
2476
2477 public static function Parse($condition)
2478 {
2479 if (!isset($condition['controlId']))
2480 return false;
2481 $atoms = static::GetAtomsEx($condition['controlId'], true);
2482 if (empty($atoms))
2483 return false;
2484 $control = array(
2485 'ID' => $condition['controlId'],
2486 'ATOMS' => $atoms
2487 );
2488 unset($atoms);
2489 return static::CheckAtoms($condition, $condition, $control, false);
2490 }
2491
2492 public static function Generate($condition, $params, $control, $childrens = false)
2493 {
2494 return '';
2495 }
2496
2497 public static function GetAtomsEx($controlId = false, $extendedMode = false)
2498 {
2499 return array();
2500 }
2501
2502 public static function GetAtoms()
2503 {
2504 return static::GetAtomsEx(false, false);
2505 }
2506
2510 public static function GetControlID()
2511 {
2512 $atoms = static::GetAtomsEx(false, true);
2513 return (empty($atoms) ? array() : array_keys($atoms));
2514 }
2515
2520 public static function GetControls($strControlID = false)
2521 {
2522 return array();
2523 }
2524
2525 public static function GetControlShow($params)
2526 {
2527 $controls = static::GetControls();
2528 if (empty($controls) || !is_array($controls))
2529 return array();
2530 $result = array();
2531 foreach ($controls as $controlId => $data)
2532 {
2533 $row = array(
2534 'controlId' => $data['ID'],
2535 'group' => false,
2536 'label' => $data['LABEL'],
2537 'showIn' => static::GetShowIn($params['SHOW_IN_GROUPS']),
2538 'control' => array()
2539 );
2540 if (isset($data['PREFIX']))
2541 $row['control'][] = $data['PREFIX'];
2542 if (empty($row['control']))
2543 {
2544 $row['control'] = array_values($data['ATOMS']);
2545 }
2546 else
2547 {
2548 foreach ($data['ATOMS'] as &$atom)
2549 $row['control'][] = $atom;
2550 unset($atom);
2551 }
2552
2553 $result[] = $row;
2554 }
2555 unset($controlId, $data, $controls);
2556 return $result;
2557 }
2558}
2559
2560class CGlobalCondCtrlGroup extends CGlobalCondCtrl
2561{
2562 public static function GetControlDescr()
2563 {
2564 $className = get_called_class();
2565 return array(
2566 'ID' => static::GetControlID(),
2567 'GROUP' => 'Y',
2568 'GetControlShow' => array($className, 'GetControlShow'),
2569 'GetConditionShow' => array($className, 'GetConditionShow'),
2570 'IsGroup' => array($className, 'IsGroup'),
2571 'Parse' => array($className, 'Parse'),
2572 'Generate' => array($className, 'Generate'),
2573 'ApplyValues' => array($className, 'ApplyValues')
2574 );
2575 }
2576
2577 public static function GetControlShow($arParams)
2578 {
2579 return array(
2580 'controlId' => static::GetControlID(),
2581 'group' => true,
2582 'label' => Loc::getMessage('BT_CLOBAL_COND_GROUP_LABEL'),
2583 'defaultText' => Loc::getMessage('BT_CLOBAL_COND_GROUP_DEF_TEXT'),
2584 'showIn' => static::GetShowIn($arParams['SHOW_IN_GROUPS']),
2585 'visual' => static::GetVisual(),
2586 'control' => array_values(static::GetAtoms())
2587 );
2588 }
2589
2590 public static function GetConditionShow($arParams)
2591 {
2592 $error = false;
2593 $values = array();
2594 foreach (static::GetAtoms() as $atom)
2595 {
2596 if (
2597 !isset($arParams['DATA'][$atom['id']])
2598 || !is_string($arParams['DATA'][$atom['id']])
2599 || !isset($atom['values'][$arParams['DATA'][$atom['id']]])
2600 )
2601 $error = true;
2602
2603 $values[$atom['id']] = ($error ? '' : $arParams['DATA'][$atom['id']]);
2604 }
2605 unset($atom);
2606
2607 $result = array(
2608 'id' => $arParams['COND_NUM'],
2609 'controlId' => static::GetControlID(),
2610 'values' => $values
2611 );
2612 if ($error)
2613 $result['err_cond'] = 'Y';
2614 unset($values);
2615
2616 return $result;
2617 }
2618
2622 public static function GetControlID()
2623 {
2624 return 'CondGroup';
2625 }
2626
2627 public static function GetAtoms()
2628 {
2629 return array(
2630 'All' => array(
2631 'id' => 'All',
2632 'name' => 'aggregator',
2633 'type' => 'select',
2634 'values' => array(
2635 'AND' => Loc::getMessage('BT_CLOBAL_COND_GROUP_SELECT_ALL'),
2636 'OR' => Loc::getMessage('BT_CLOBAL_COND_GROUP_SELECT_ANY')
2637 ),
2638 'defaultText' => Loc::getMessage('BT_CLOBAL_COND_GROUP_SELECT_DEF'),
2639 'defaultValue' => 'AND',
2640 'first_option' => '...'
2641 ),
2642 'True' => array(
2643 'id' => 'True',
2644 'name' => 'value',
2645 'type' => 'select',
2646 'values' => array(
2647 'True' => Loc::getMessage('BT_CLOBAL_COND_GROUP_SELECT_TRUE'),
2648 'False' => Loc::getMessage('BT_CLOBAL_COND_GROUP_SELECT_FALSE')
2649 ),
2650 'defaultText' => Loc::getMessage('BT_CLOBAL_COND_GROUP_SELECT_DEF'),
2651 'defaultValue' => 'True',
2652 'first_option' => '...'
2653 )
2654 );
2655 }
2656
2657 public static function GetVisual()
2658 {
2659 return array(
2660 'controls' => array(
2661 'All',
2662 'True'
2663 ),
2664 'values' => array(
2665 array(
2666 'All' => 'AND',
2667 'True' => 'True'
2668 ),
2669 array(
2670 'All' => 'AND',
2671 'True' => 'False'
2672 ),
2673 array(
2674 'All' => 'OR',
2675 'True' => 'True'
2676 ),
2677 array(
2678 'All' => 'OR',
2679 'True' => 'False'
2680 )
2681 ),
2682 'logic' => array(
2683 array(
2684 'style' => 'condition-logic-and',
2685 'message' => Loc::getMessage('BT_CLOBAL_COND_GROUP_LOGIC_AND')
2686 ),
2687 array(
2688 'style' => 'condition-logic-and',
2689 'message' => Loc::getMessage('BT_CLOBAL_COND_GROUP_LOGIC_NOT_AND')
2690 ),
2691 array(
2692 'style' => 'condition-logic-or',
2693 'message' => Loc::getMessage('BT_CLOBAL_COND_GROUP_LOGIC_OR')
2694 ),
2695 array(
2696 'style' => 'condition-logic-or',
2697 'message' => Loc::getMessage('BT_CLOBAL_COND_GROUP_LOGIC_NOT_OR')
2698 )
2699 )
2700 );
2701 }
2702
2703 public static function IsGroup($strControlID = false)
2704 {
2705 return 'Y';
2706 }
2707
2708 public static function Parse($arOneCondition)
2709 {
2710 $error = false;
2711 $result = array();
2712 foreach (static::GetAtoms() as $atom)
2713 {
2714 if (
2715 !isset($arOneCondition[$atom['name']])
2716 || !is_string($arOneCondition[$atom['name']])
2717 || !isset($atom['values'][$arOneCondition[$atom['name']]])
2718 )
2719 {
2720 $error = true;
2721 break;
2722 }
2723 $result[$atom['id']] = $arOneCondition[$atom['name']];
2724 }
2725 unset($atom);
2726
2727 return (!$error ? $result : false);
2728 }
2729
2730 public static function Generate($arOneCondition, $arParams, $arControl, $arSubs = false)
2731 {
2732 $result = '';
2733 $error = false;
2734
2735 foreach (static::GetAtoms() as $atom)
2736 {
2737 if (
2738 !isset($arOneCondition[$atom['id']])
2739 || !is_string($arOneCondition[$atom['id']])
2740 || !isset($atom['values'][$arOneCondition[$atom['id']]])
2741 )
2742 $error = true;
2743 }
2744 unset($atom);
2745
2746 if (!isset($arSubs) || !is_array($arSubs))
2747 {
2748 $error = true;
2749 }
2750 elseif (empty($arSubs))
2751 {
2752 return '(1 == 1)';
2753 }
2754
2755 if (!$error)
2756 {
2757 if ('AND' == $arOneCondition['All'])
2758 {
2759 $prefix = '';
2760 $logic = ' && ';
2761 $itemPrefix = ($arOneCondition['True'] == 'True' ? '' : '!');
2762 }
2763 else
2764 {
2765 $itemPrefix = '';
2766 if ($arOneCondition['True'] == 'True')
2767 {
2768 $prefix = '';
2769 $logic = ' || ';
2770 }
2771 else
2772 {
2773 $prefix = '!';
2774 $logic = ' && ';
2775 }
2776 }
2777
2778 $commandLine = $itemPrefix.implode($logic.$itemPrefix, $arSubs);
2779 if ($prefix != '')
2780 $commandLine = $prefix.'('.$commandLine.')';
2781 if ($commandLine != '')
2782 $commandLine = '('.$commandLine.')';
2783 $result = $commandLine;
2784 unset($commandLine);
2785 }
2786
2787 return $result;
2788 }
2789
2790 public static function ApplyValues($arOneCondition, $arControl)
2791 {
2792 return (isset($arOneCondition['True']) && $arOneCondition['True'] == 'True');
2793 }
2794}
2795
2796class CCatalogCondCtrl extends CGlobalCondCtrl
2797{
2798}
2799
2800class CCatalogCondCtrlComplex extends CGlobalCondCtrlComplex
2801{
2802}
2803
2804class CCatalogCondCtrlGroup extends CGlobalCondCtrlGroup
2805{
2806 public static function GetControlDescr()
2807 {
2808 $description = parent::GetControlDescr();
2809 $description['SORT'] = 100;
2810 return $description;
2811 }
2812}
2813
2814class CCatalogCondCtrlIBlockFields extends CCatalogCondCtrlComplex
2815{
2816 public static function GetControlDescr()
2817 {
2818 $description = parent::GetControlDescr();
2819 $description['SORT'] = 200;
2820 return $description;
2821 }
2822
2826 public static function GetControlID()
2827 {
2828 return array(
2829 'CondIBElement',
2830 'CondIBIBlock',
2831 'CondIBSection',
2832 'CondIBCode',
2833 'CondIBXmlID',
2834 'CondIBName',
2835 'CondIBDateActiveFrom',
2836 'CondIBDateActiveTo',
2837 'CondIBSort',
2838 'CondIBPreviewText',
2839 'CondIBDetailText',
2840 'CondIBDateCreate',
2841 'CondIBCreatedBy',
2842 'CondIBTimestampX',
2843 'CondIBModifiedBy',
2844 'CondIBTags',
2845 'CondCatQuantity',
2846 'CondCatWeight',
2847 'CondCatVatID',
2848 'CondCatVatIncluded',
2849 );
2850 }
2851
2852 public static function GetControlShow($arParams)
2853 {
2854 $arControls = static::GetControls();
2855 $arResult = array(
2856 'controlgroup' => true,
2857 'group' => false,
2858 'label' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_CONTROLGROUP_LABEL'),
2859 'showIn' => static::GetShowIn($arParams['SHOW_IN_GROUPS']),
2860 'children' => array()
2861 );
2862 foreach ($arControls as $arOneControl)
2863 {
2864 $arResult['children'][] = array(
2865 'controlId' => $arOneControl['ID'],
2866 'group' => false,
2867 'label' => $arOneControl['LABEL'],
2868 'showIn' => static::GetShowIn($arParams['SHOW_IN_GROUPS']),
2869 'control' => array(
2870 array(
2871 'id' => 'prefix',
2872 'type' => 'prefix',
2873 'text' => $arOneControl['PREFIX']
2874 ),
2875 static::GetLogicAtom($arOneControl['LOGIC']),
2876 static::GetValueAtom($arOneControl['JS_VALUE'])
2877 )
2878 );
2879 }
2880 unset($arOneControl);
2881
2882 return $arResult;
2883 }
2884
2889 public static function GetControls($strControlID = false)
2890 {
2891 $vatList = array();
2892 $vatIterator = Catalog\VatTable::getList(array(
2893 'select' => array('ID', 'NAME', 'SORT'),
2894 'order' => array('SORT' => 'ASC')
2895 ));
2896 while ($vat = $vatIterator->fetch())
2897 {
2898 $vat['ID'] = (int)$vat['ID'];
2899 $vatList[$vat['ID']] = $vat['NAME'];
2900 }
2901 unset($vat, $vatIterator);
2902
2903 $arControlList = array(
2904 'CondIBElement' => array(
2905 'ID' => 'CondIBElement',
2906 'FIELD' => 'ID',
2907 'FIELD_TYPE' => 'int',
2908 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_ELEMENT_ID_LABEL'),
2909 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_ELEMENT_ID_PREFIX'),
2910 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ)),
2911 'JS_VALUE' => array(
2912 'type' => 'multiDialog',
2913 'popup_url' => self::getAdminSection().'cat_product_search_dialog.php',
2914 'popup_params' => array(
2915 'lang' => LANGUAGE_ID,
2916 'caller' => 'discount_rules',
2917 'allow_select_parent' => 'Y'
2918 ),
2919 'param_id' => 'n',
2920 'show_value' => 'Y'
2921 ),
2922 'PHP_VALUE' => array(
2923 'VALIDATE' => 'element'
2924 )
2925 ),
2926 'CondIBIBlock' => array(
2927 'ID' => 'CondIBIBlock',
2928 'FIELD' => 'IBLOCK_ID',
2929 'FIELD_TYPE' => 'int',
2930 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_IBLOCK_ID_LABEL'),
2931 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_IBLOCK_ID_PREFIX'),
2932 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ)),
2933 'JS_VALUE' => array(
2934 'type' => 'popup',
2935 'popup_url' => self::getAdminSection().'cat_iblock_search.php',
2936 'popup_params' => array(
2937 'lang' => LANGUAGE_ID,
2938 'discount' => 'Y'
2939 ),
2940 'param_id' => 'n',
2941 'show_value' => 'Y'
2942 ),
2943 'PHP_VALUE' => array(
2944 'VALIDATE' => 'iblock'
2945 )
2946 ),
2947 'CondIBSection' => array(
2948 'ID' => 'CondIBSection',
2949 'PARENT' => false,
2950 'FIELD' => 'SECTION_ID',
2951 'FIELD_TYPE' => 'int',
2952 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_SECTION_ID_LABEL'),
2953 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_SECTION_ID_PREFIX'),
2954 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ)),
2955 'JS_VALUE' => array(
2956 'type' => 'popup',
2957 'popup_url' => self::getAdminSection().'iblock_section_search.php',
2958 'popup_params' => array(
2959 'lang' => LANGUAGE_ID,
2960 'discount' => 'Y',
2961 'simplename' => 'Y'
2962 ),
2963 'param_id' => 'n',
2964 'show_value' => 'Y'
2965 ),
2966 'PHP_VALUE' => array(
2967 'VALIDATE' => 'section'
2968 )
2969 ),
2970 'CondIBCode' => array(
2971 'ID' => 'CondIBCode',
2972 'FIELD' => 'CODE',
2973 'FIELD_TYPE' => 'string',
2974 'FIELD_LENGTH' => 255,
2975 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_CODE_LABEL'),
2976 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_CODE_PREFIX'),
2977 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_CONT, BT_COND_LOGIC_NOT_CONT)),
2978 'JS_VALUE' => array(
2979 'type' => 'input'
2980 ),
2981 'PHP_VALUE' => ''
2982 ),
2983 'CondIBXmlID' => array(
2984 'ID' => 'CondIBXmlID',
2985 'FIELD' => 'XML_ID',
2986 'FIELD_TYPE' => 'string',
2987 'FIELD_LENGTH' => 255,
2988 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_XML_ID_LABEL'),
2989 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_XML_ID_PREFIX'),
2990 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_CONT, BT_COND_LOGIC_NOT_CONT)),
2991 'JS_VALUE' => array(
2992 'type' => 'input'
2993 ),
2994 'PHP_VALUE' => ''
2995 ),
2996 'CondIBName' => array(
2997 'ID' => 'CondIBName',
2998 'FIELD' => 'NAME',
2999 'FIELD_TYPE' => 'string',
3000 'FIELD_LENGTH' => 255,
3001 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_NAME_LABEL'),
3002 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_NAME_PREFIX'),
3003 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_CONT, BT_COND_LOGIC_NOT_CONT)),
3004 'JS_VALUE' => array(
3005 'type' => 'input'
3006 ),
3007 'PHP_VALUE' => ''
3008 ),
3009 'CondIBDateActiveFrom' => array(
3010 'ID' => 'CondIBDateActiveFrom',
3011 'FIELD' => 'DATE_ACTIVE_FROM',
3012 'FIELD_TYPE' => 'datetime',
3013 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_DATE_ACTIVE_FROM_LABEL'),
3014 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_DATE_ACTIVE_FROM_PREFIX'),
3015 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_GR, BT_COND_LOGIC_LS, BT_COND_LOGIC_EGR, BT_COND_LOGIC_ELS)),
3016 'JS_VALUE' => array(
3017 'type' => 'datetime',
3018 'format' => 'datetime'
3019 ),
3020 'PHP_VALUE' => ''
3021 ),
3022 'CondIBDateActiveTo' => array(
3023 'ID' => 'CondIBDateActiveTo',
3024 'FIELD' => 'DATE_ACTIVE_TO',
3025 'FIELD_TYPE' => 'datetime',
3026 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_DATE_ACTIVE_TO_LABEL'),
3027 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_DATE_ACTIVE_TO_PREFIX'),
3028 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_GR, BT_COND_LOGIC_LS, BT_COND_LOGIC_EGR, BT_COND_LOGIC_ELS)),
3029 'JS_VALUE' => array(
3030 'type' => 'datetime',
3031 'format' => 'datetime'
3032 ),
3033 'PHP_VALUE' => ''
3034 ),
3035 'CondIBSort' => array(
3036 'ID' => 'CondIBSort',
3037 'FIELD' => 'SORT',
3038 'FIELD_TYPE' => 'int',
3039 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_SORT_LABEL'),
3040 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_SORT_PREFIX'),
3041 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_GR, BT_COND_LOGIC_LS, BT_COND_LOGIC_EGR, BT_COND_LOGIC_ELS)),
3042 'JS_VALUE' => array(
3043 'type' => 'input'
3044 ),
3045 'PHP_VALUE' => ''
3046 ),
3047 'CondIBPreviewText' => array(
3048 'ID' => 'CondIBPreviewText',
3049 'FIELD' => 'PREVIEW_TEXT',
3050 'FIELD_TYPE' => 'text',
3051 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_PREVIEW_TEXT_LABEL'),
3052 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_PREVIEW_TEXT_PREFIX'),
3053 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_CONT, BT_COND_LOGIC_NOT_CONT)),
3054 'JS_VALUE' => array(
3055 'type' => 'input'
3056 ),
3057 'PHP_VALUE' => ''
3058 ),
3059 'CondIBDetailText' => array(
3060 'ID' => 'CondIBDetailText',
3061 'FIELD' => 'DETAIL_TEXT',
3062 'FIELD_TYPE' => 'text',
3063 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_DETAIL_TEXT_LABEL'),
3064 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_DETAIL_TEXT_PREFIX'),
3065 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_CONT, BT_COND_LOGIC_NOT_CONT)),
3066 'JS_VALUE' => array(
3067 'type' => 'input'
3068 ),
3069 'PHP_VALUE' => ''
3070 ),
3071 'CondIBDateCreate' => array(
3072 'ID' => 'CondIBDateCreate',
3073 'FIELD' => 'DATE_CREATE',
3074 'FIELD_TYPE' => 'datetime',
3075 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_DATE_CREATE_LABEL'),
3076 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_DATE_CREATE_PREFIX'),
3077 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_GR, BT_COND_LOGIC_LS, BT_COND_LOGIC_EGR, BT_COND_LOGIC_ELS)),
3078 'JS_VALUE' => array(
3079 'type' => 'datetime',
3080 'format' => 'datetime'
3081 ),
3082 'PHP_VALUE' => ''
3083 ),
3084 'CondIBCreatedBy' => array(
3085 'ID' => 'CondIBCreatedBy',
3086 'FIELD' => 'CREATED_BY',
3087 'FIELD_TYPE' => 'int',
3088 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_CREATED_BY_LABEL'),
3089 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_CREATED_BY_PREFIX'),
3090 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ)),
3091 'JS_VALUE' => array(
3092 'type' => 'input'
3093 ),
3094 'PHP_VALUE' => array(
3095 'VALIDATE' => 'user'
3096 )
3097 ),
3098 'CondIBTimestampX' => array(
3099 'ID' => 'CondIBTimestampX',
3100 'FIELD' => 'TIMESTAMP_X',
3101 'FIELD_TYPE' => 'datetime',
3102 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_TIMESTAMP_X_LABEL'),
3103 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_TIMESTAMP_X_PREFIX'),
3104 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_GR, BT_COND_LOGIC_LS, BT_COND_LOGIC_EGR, BT_COND_LOGIC_ELS)),
3105 'JS_VALUE' => array(
3106 'type' => 'datetime',
3107 'format' => 'datetime'
3108 ),
3109 'PHP_VALUE' => ''
3110 ),
3111 'CondIBModifiedBy' => array(
3112 'ID' => 'CondIBModifiedBy',
3113 'FIELD' => 'MODIFIED_BY',
3114 'FIELD_TYPE' => 'int',
3115 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_MODIFIED_BY_LABEL'),
3116 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_MODIFIED_BY_PREFIX'),
3117 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ)),
3118 'JS_VALUE' => array(
3119 'type' => 'input'
3120 ),
3121 'PHP_VALUE' => array(
3122 'VALIDATE' => 'user'
3123 )
3124 ),
3125 'CondIBTags' => array(
3126 'ID' => 'CondIBTags',
3127 'FIELD' => 'TAGS',
3128 'FIELD_TYPE' => 'string',
3129 'FIELD_LENGTH' => 255,
3130 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_TAGS_LABEL'),
3131 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_TAGS_PREFIX'),
3132 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_CONT, BT_COND_LOGIC_NOT_CONT)),
3133 'JS_VALUE' => array(
3134 'type' => 'input'
3135 ),
3136 'PHP_VALUE' => ''
3137 ),
3138 'CondCatQuantity' => array(
3139 'ID' => 'CondCatQuantity',
3140 'PARENT' => false,
3141 'MODULE_ENTITY' => 'catalog',
3142 'ENTITY' => 'PRODUCT',
3143 'FIELD' => 'CATALOG_QUANTITY',
3144 'FIELD_TABLE' => 'QUANTITY',
3145 'FIELD_TYPE' => 'double',
3146 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_CATALOG_QUANTITY_LABEL'),
3147 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_CATALOG_QUANTITY_PREFIX'),
3148 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_GR, BT_COND_LOGIC_LS, BT_COND_LOGIC_EGR, BT_COND_LOGIC_ELS)),
3149 'JS_VALUE' => array(
3150 'type' => 'input'
3151 )
3152 ),
3153 'CondCatWeight' => array(
3154 'ID' => 'CondCatWeight',
3155 'PARENT' => false,
3156 'MODULE_ENTITY' => 'catalog',
3157 'ENTITY' => 'PRODUCT',
3158 'FIELD' => 'CATALOG_WEIGHT',
3159 'FIELD_TABLE' => 'WEIGHT',
3160 'FIELD_TYPE' => 'double',
3161 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_CATALOG_WEIGHT_LABEL'),
3162 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_CATALOG_WEIGHT_PREFIX'),
3163 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_GR, BT_COND_LOGIC_LS, BT_COND_LOGIC_EGR, BT_COND_LOGIC_ELS)),
3164 'JS_VALUE' => array(
3165 'type' => 'input'
3166 ),
3167 'PHP_VALUE' => ''
3168 ),
3169 'CondCatVatID' => array(
3170 'ID' => 'CondCatVatID',
3171 'PARENT' => false,
3172 'MODULE_ENTITY' => 'catalog',
3173 'ENTITY' => 'PRODUCT',
3174 'FIELD' => 'CATALOG_VAT_ID',
3175 'FIELD_TABLE' => 'VAT_ID',
3176 'FIELD_TYPE' => 'int',
3177 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_CATALOG_VAT_ID_LABEL'),
3178 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_CATALOG_VAT_ID_PREFIX'),
3179 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ)),
3180 'JS_VALUE' => array(
3181 'type' => 'select',
3182 'values' => $vatList
3183 ),
3184 'PHP_VALUE' => array(
3185 'VALIDATE' => 'list'
3186 )
3187 ),
3188 'CondCatVatIncluded' => array(
3189 'ID' => 'CondCatVatIncluded',
3190 'PARENT' => false,
3191 'MODULE_ENTITY' => 'catalog',
3192 'ENTITY' => 'PRODUCT',
3193 'FIELD' => 'CATALOG_VAT_INCLUDED',
3194 'FIELD_TABLE' => 'VAT_INCLUDED',
3195 'FIELD_TYPE' => 'char',
3196 'LABEL' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_CATALOG_VAT_INCLUDED_LABEL'),
3197 'PREFIX' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_CATALOG_VAT_INCLUDED_PREFIX'),
3198 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ)),
3199 'JS_VALUE' => array(
3200 'type' => 'select',
3201 'values' => array(
3202 'Y' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_CATALOG_VAT_INCLUDED_VALUE_YES'),
3203 'N' => Loc::getMessage('BT_MOD_CATALOG_COND_CMP_CATALOG_VAT_INCLUDED_VALUE_NO')
3204 )
3205 ),
3206 'PHP_VALUE' => array(
3207 'VALIDATE' => 'list'
3208 )
3209 )
3210 );
3211 if (empty($vatList))
3212 {
3213 unset($arControlList['CondCatVatID']);
3214 unset($arControlList['CondCatVatIncluded']);
3215 }
3216 foreach ($arControlList as &$control)
3217 {
3218 if (!isset($control['PARENT']))
3219 $control['PARENT'] = true;
3220 $control['EXIST_HANDLER'] = 'Y';
3221 $control['MODULE_ID'] = 'catalog';
3222 if (!isset($control['MODULE_ENTITY']))
3223 $control['MODULE_ENTITY'] = 'iblock';
3224 if (!isset($control['ENTITY']))
3225 $control['ENTITY'] = 'ELEMENT';
3226 if (!isset($control['FIELD_TABLE']))
3227 $control['FIELD_TABLE'] = false;
3228 $control['MULTIPLE'] = 'N';
3229 $control['GROUP'] = 'N';
3230 $control['ENTITY_ID'] = -1;
3231 }
3232 unset($control);
3233 $arControlList['CondIBSection']['MULTIPLE'] = 'Y';
3234
3235 return static::searchControl($arControlList, $strControlID);
3236 }
3237
3238 public static function Generate($arOneCondition, $arParams, $arControl, $arSubs = false)
3239 {
3240 $strParentResult = '';
3241 $strResult = '';
3242 $parentResultValues = array();
3243 $resultValues = array();
3244
3245 if (is_string($arControl))
3246 {
3247 $arControl = static::GetControls($arControl);
3248 }
3249 $boolError = !is_array($arControl);
3250
3251 if (!$boolError)
3252 {
3253 $arValues = static::Check($arOneCondition, $arOneCondition, $arControl, false);
3254 $boolError = ($arValues === false);
3255 }
3256
3257 if (!$boolError)
3258 {
3259 $boolError = !isset($arControl['MULTIPLE']);
3260 }
3261
3262 if (!$boolError)
3263 {
3264 $arLogic = static::SearchLogic($arValues['logic'], $arControl['LOGIC']);
3265 if (!isset($arLogic['OP'][$arControl['MULTIPLE']]) || empty($arLogic['OP'][$arControl['MULTIPLE']]))
3266 {
3267 $boolError = true;
3268 }
3269 else
3270 {
3271 $useParent = ($arControl['PARENT'] && isset($arLogic['PARENT']));
3272 $strParent = $arParams['FIELD'].'[\'PARENT_'.$arControl['FIELD'].'\']';
3273 $strField = $arParams['FIELD'].'[\''.$arControl['FIELD'].'\']';
3274 switch ($arControl['FIELD_TYPE'])
3275 {
3276 case 'int':
3277 case 'double':
3278 if (is_array($arValues['value']))
3279 {
3280 if (!isset($arLogic['MULTI_SEP']))
3281 {
3282 $boolError = true;
3283 }
3284 else
3285 {
3286 foreach ($arValues['value'] as $value)
3287 {
3288 if ($useParent)
3289 $parentResultValues[] = str_replace(
3290 array('#FIELD#', '#VALUE#'),
3291 array($strParent, $value),
3292 $arLogic['OP'][$arControl['MULTIPLE']]
3293 );
3294 $resultValues[] = str_replace(
3295 array('#FIELD#', '#VALUE#'),
3296 array($strField, $value),
3297 $arLogic['OP'][$arControl['MULTIPLE']]
3298 );
3299 }
3300 unset($value);
3301 if ($useParent)
3302 $strParentResult = '('.implode($arLogic['MULTI_SEP'], $parentResultValues).')';
3303 $strResult = '('.implode($arLogic['MULTI_SEP'], $resultValues).')';
3304 unset($resultValues, $parentResultValues);
3305 }
3306 }
3307 else
3308 {
3309 if ($useParent)
3310 $strParentResult = str_replace(
3311 array('#FIELD#', '#VALUE#'),
3312 array($strParent, $arValues['value']),
3313 $arLogic['OP'][$arControl['MULTIPLE']]
3314 );
3315 $strResult = str_replace(
3316 array('#FIELD#', '#VALUE#'),
3317 array($strField, $arValues['value']),
3318 $arLogic['OP'][$arControl['MULTIPLE']]
3319 );
3320 }
3321 break;
3322 case 'char':
3323 case 'string':
3324 case 'text':
3325 if (is_array($arValues['value']))
3326 {
3327 $boolError = true;
3328 }
3329 else
3330 {
3331 if ($useParent)
3332 $strParentResult = str_replace(
3333 array('#FIELD#', '#VALUE#'),
3334 array($strParent, '"'.EscapePHPString($arValues['value']).'"'),
3335 $arLogic['OP'][$arControl['MULTIPLE']]
3336 );
3337 $strResult = str_replace(
3338 array('#FIELD#', '#VALUE#'),
3339 array($strField, '"'.EscapePHPString($arValues['value']).'"'),
3340 $arLogic['OP'][$arControl['MULTIPLE']]
3341 );
3342 }
3343 break;
3344 case 'date':
3345 case 'datetime':
3346 if (is_array($arValues['value']))
3347 {
3348 $boolError = true;
3349 }
3350 else
3351 {
3352 if ($useParent)
3353 $strParentResult = str_replace(array('#FIELD#', '#VALUE#'), array($strParent, $arValues['value']), $arLogic['OP'][$arControl['MULTIPLE']]);
3354 $strResult = str_replace(array('#FIELD#', '#VALUE#'), array($strField, $arValues['value']), $arLogic['OP'][$arControl['MULTIPLE']]);
3355 if (!(BT_COND_LOGIC_EQ == $arLogic['ID'] || BT_COND_LOGIC_NOT_EQ == $arLogic['ID']))
3356 {
3357 if ($useParent)
3358 $strParentResult = 'null !== '.$strParent.' && \'\' !== '.$strParent.' && '.$strResult;
3359 $strResult = 'null !== '.$strField.' && \'\' !== '.$strField.' && '.$strResult;
3360 }
3361 }
3362 break;
3363 }
3364 $strResult = 'isset('.$strField.') && ('.$strResult.')';
3365 if ($useParent)
3366 {
3367 $strResult = '(isset('.$strParent.') ? (('.$strResult.')'.$arLogic['PARENT'].$strParentResult.') : ('.$strResult.'))';
3368 }
3369 }
3370 }
3371
3372 return (!$boolError ? $strResult : false);
3373 }
3374
3375 public static function ApplyValues($arOneCondition, $arControl)
3376 {
3377 $arResult = array();
3378
3379 $arLogicID = array(
3380 BT_COND_LOGIC_EQ,
3381 BT_COND_LOGIC_EGR,
3382 BT_COND_LOGIC_ELS,
3383 );
3384
3385 if (is_string($arControl))
3386 {
3387 $arControl = static::GetControls($arControl);
3388 }
3389 $boolError = !is_array($arControl);
3390
3391 if (!$boolError)
3392 {
3393 $arValues = static::Check($arOneCondition, $arOneCondition, $arControl, false);
3394 if (false === $arValues)
3395 {
3396 $boolError = true;
3397 }
3398 }
3399
3400 if (!$boolError)
3401 {
3402 $arLogic = static::SearchLogic($arValues['logic'], $arControl['LOGIC']);
3403 if (in_array($arLogic['ID'], $arLogicID))
3404 {
3405 $arResult = array(
3406 'ID' => $arControl['ID'],
3407 'FIELD' => $arControl['FIELD'],
3408 'FIELD_TYPE' => $arControl['FIELD_TYPE'],
3409 'VALUES' => (is_array($arValues['value']) ? $arValues['value'] : array($arValues['value']))
3410 );
3411 }
3412 }
3413
3414 return (!$boolError ? $arResult : false);
3415 }
3416
3420 private static function getAdminSection()
3421 {
3422 //TODO: need use \CAdminPage::getSelfFolderUrl, but in general it is impossible now
3423 return (defined('SELF_FOLDER_URL') ? SELF_FOLDER_URL : '/bitrix/admin/');
3424 }
3425}
3426
3427class CCatalogCondCtrlIBlockProps extends CCatalogCondCtrlComplex
3428{
3429 public static function GetControlDescr()
3430 {
3431 $description = parent::GetControlDescr();
3432 $description['SORT'] = 300;
3433 return $description;
3434 }
3435
3440 public static function GetControls($strControlID = false)
3441 {
3442 $arControlList = array();
3443 $arIBlockList = array();
3444 $iterator = Catalog\CatalogIblockTable::getList(array(
3445 'select' => array('IBLOCK_ID', 'PRODUCT_IBLOCK_ID')
3446 ));
3447 while ($arIBlock = $iterator->fetch())
3448 {
3449 $arIBlock['IBLOCK_ID'] = (int)$arIBlock['IBLOCK_ID'];
3450 $arIBlock['PRODUCT_IBLOCK_ID'] = (int)$arIBlock['PRODUCT_IBLOCK_ID'];
3451 if ($arIBlock['IBLOCK_ID'] > 0)
3452 $arIBlockList[$arIBlock['IBLOCK_ID']] = true;
3453 if ($arIBlock['PRODUCT_IBLOCK_ID'] > 0)
3454 $arIBlockList[$arIBlock['PRODUCT_IBLOCK_ID']] = true;
3455 }
3456 unset($arIBlock, $iterator);
3457 if (!empty($arIBlockList))
3458 {
3459 $arIBlockList = array_keys($arIBlockList);
3460 sort($arIBlockList);
3461 foreach ($arIBlockList as $intIBlockID)
3462 {
3463 $strName = CIBlock::GetArrayByID($intIBlockID, 'NAME');
3464 if (false !== $strName)
3465 {
3466 $boolSep = true;
3467 $rsProps = CIBlockProperty::GetList(array('SORT' => 'ASC', 'NAME' => 'ASC'), array('IBLOCK_ID' => $intIBlockID));
3468 while ($arProp = $rsProps->Fetch())
3469 {
3470 if ('CML2_LINK' == $arProp['XML_ID'] || 'F' == $arProp['PROPERTY_TYPE'])
3471 continue;
3472 if ('L' == $arProp['PROPERTY_TYPE'])
3473 $arProp['VALUES'] = array();
3474
3475 $strFieldType = '';
3476 $arLogic = array();
3477 $arValue = array();
3478 $arPhpValue = '';
3479
3480 $boolUserType = false;
3481 if (isset($arProp['USER_TYPE']) && !empty($arProp['USER_TYPE']))
3482 {
3483 switch ($arProp['USER_TYPE'])
3484 {
3485 case 'DateTime':
3486 $strFieldType = 'datetime';
3487 $arLogic = static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_GR, BT_COND_LOGIC_LS, BT_COND_LOGIC_EGR, BT_COND_LOGIC_ELS));
3488 $arValue = array(
3489 'type' => 'datetime',
3490 'format' => 'datetime'
3491 );
3492 $boolUserType = true;
3493 break;
3494 case 'Date':
3495 $strFieldType = 'date';
3496 $arLogic = static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_GR, BT_COND_LOGIC_LS, BT_COND_LOGIC_EGR, BT_COND_LOGIC_ELS));
3497 $arValue = array(
3498 'type' => 'datetime',
3499 'format' => 'date'
3500 );
3501 $boolUserType = true;
3502 break;
3503 case 'directory':
3504 $strFieldType = 'text';
3505 $arLogic = static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ));
3506 $arValue = array(
3507 'type' => 'lazySelect',
3508 'load_url' => '/bitrix/tools/catalog/get_property_values.php',
3509 'load_params' => array(
3510 'lang' => LANGUAGE_ID,
3511 'propertyId' => $arProp['ID']
3512 )
3513 );
3514 $boolUserType = true;
3515 break;
3516 default:
3517 $boolUserType = false;
3518 break;
3519 }
3520 }
3521
3522 if (!$boolUserType)
3523 {
3524 switch ($arProp['PROPERTY_TYPE'])
3525 {
3526 case 'N':
3527 $strFieldType = 'double';
3528 $arLogic = static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_GR, BT_COND_LOGIC_LS, BT_COND_LOGIC_EGR, BT_COND_LOGIC_ELS));
3529 $arValue = array('type' => 'input');
3530 break;
3531 case 'S':
3532 $strFieldType = 'text';
3533 $arLogic = static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_CONT, BT_COND_LOGIC_NOT_CONT));
3534 $arValue = array('type' => 'input');
3535 break;
3536 case 'L':
3537 $strFieldType = 'int';
3538 $arLogic = static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ));
3539 $arValue = array(
3540 'type' => 'lazySelect',
3541 'load_url' => '/bitrix/tools/catalog/get_property_values.php',
3542 'load_params' => array(
3543 'lang' => LANGUAGE_ID,
3544 'propertyId' => $arProp['ID']
3545 )
3546 );
3547 $arPhpValue = array('VALIDATE' => 'enumValue');
3548 break;
3549 case 'E':
3550 $strFieldType = 'int';
3551 $arLogic = static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ));
3552 $arValue = array(
3553 'type' => 'popup',
3554 'popup_url' => self::getAdminSection().'iblock_element_search.php',
3555 'popup_params' => array(
3556 'lang' => LANGUAGE_ID,
3557 'IBLOCK_ID' => $arProp['LINK_IBLOCK_ID'],
3558 'discount' => 'Y'
3559 ),
3560 'param_id' => 'n'
3561 );
3562 $arPhpValue = array('VALIDATE' => 'element');
3563 break;
3564 case 'G':
3565 $popupParams = array(
3566 'lang' => LANGUAGE_ID,
3567 'IBLOCK_ID' => $arProp['LINK_IBLOCK_ID'],
3568 'discount' => 'Y',
3569 'simplename' => 'Y',
3570 );
3571 if ($arProp['LINK_IBLOCK_ID'] > 0)
3572 $popupParams['iblockfix'] = 'y';
3573 $strFieldType = 'int';
3574 $arLogic = static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ));
3575 $arValue = array(
3576 'type' => 'popup',
3577 'popup_url' => self::getAdminSection().'iblock_section_search.php',
3578 'popup_params' => $popupParams,
3579 'param_id' => 'n'
3580 );
3581 unset($popupParams);
3582 $arPhpValue = array('VALIDATE' => 'section');
3583 break;
3584 }
3585 }
3586 $arControlList['CondIBProp:'.$intIBlockID.':'.$arProp['ID']] = array(
3587 'ID' => 'CondIBProp:'.$intIBlockID.':'.$arProp['ID'],
3588 'PARENT' => false,
3589 'EXIST_HANDLER' => 'Y',
3590 'MODULE_ID' => 'catalog',
3591 'MODULE_ENTITY' => 'iblock',
3592 'ENTITY' => 'ELEMENT_PROPERTY',
3593 'ENTITY_ID' => $intIBlockID,
3594 'IBLOCK_ID' => $intIBlockID, // deprecated
3595 'PROPERTY_ID' => $arProp['ID'],
3596 'FIELD' => 'PROPERTY_'.$arProp['ID'].'_VALUE',
3597 'FIELD_TABLE' => $intIBlockID.':'.$arProp['ID'],
3598 'FIELD_TYPE' => $strFieldType,
3599 'MULTIPLE' => 'Y',
3600 'GROUP' => 'N',
3601 'SEP' => ($boolSep ? 'Y' : 'N'),
3602 'SEP_LABEL' => ($boolSep
3603 ? str_replace(
3604 array('#ID#', '#NAME#'),
3605 array($intIBlockID, $strName),
3606 Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_PROP_LABEL')
3607 )
3608 : ''
3609 ),
3610 'LABEL' => $arProp['NAME'],
3611 'PREFIX' => str_replace(
3612 array('#NAME#', '#IBLOCK_ID#', '#IBLOCK_NAME#'),
3613 array($arProp['NAME'], $intIBlockID, $strName),
3614 Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_ONE_PROP_PREFIX')
3615 ),
3616 'LOGIC' => $arLogic,
3617 'JS_VALUE' => $arValue,
3618 'PHP_VALUE' => $arPhpValue
3619 );
3620
3621 $boolSep = false;
3622 }
3623 }
3624 }
3625 unset($intIBlockID);
3626 }
3627 unset($arIBlockList);
3628
3629 return static::searchControl($arControlList, $strControlID);
3630 }
3631
3632 public static function GetControlShow($arParams)
3633 {
3634 $arControls = static::GetControls();
3635 $arResult = array();
3636 $intCount = -1;
3637 foreach ($arControls as &$arOneControl)
3638 {
3639 if (isset($arOneControl['SEP']) && 'Y' == $arOneControl['SEP'])
3640 {
3641 $intCount++;
3642 $arResult[$intCount] = array(
3643 'controlgroup' => true,
3644 'group' => false,
3645 'label' => $arOneControl['SEP_LABEL'],
3646 'showIn' => static::GetShowIn($arParams['SHOW_IN_GROUPS']),
3647 'children' => array()
3648 );
3649 }
3650 $arLogic = static::GetLogicAtom($arOneControl['LOGIC']);
3651 $arValue = static::GetValueAtom($arOneControl['JS_VALUE']);
3652
3653 $arResult[$intCount]['children'][] = array(
3654 'controlId' => $arOneControl['ID'],
3655 'group' => false,
3656 'label' => $arOneControl['LABEL'],
3657 'showIn' => static::GetShowIn($arParams['SHOW_IN_GROUPS']),
3658 'control' => array(
3659 array(
3660 'id' => 'prefix',
3661 'type' => 'prefix',
3662 'text' => $arOneControl['PREFIX']
3663 ),
3664 $arLogic,
3665 $arValue
3666 )
3667 );
3668 }
3669 if (isset($arOneControl))
3670 unset($arOneControl);
3671
3672 return $arResult;
3673 }
3674
3675 public static function Generate($arOneCondition, $arParams, $arControl, $arSubs = false)
3676 {
3677 $strResult = '';
3678
3679 if (is_string($arControl))
3680 {
3681 $arControl = static::GetControls($arControl);
3682 }
3683 $boolError = !is_array($arControl);
3684
3685 if (!$boolError)
3686 {
3687 $strResult = parent::Generate($arOneCondition, $arParams, $arControl, $arSubs);
3688 if (false === $strResult || '' == $strResult)
3689 {
3690 $boolError = true;
3691 }
3692 else
3693 {
3694 $strField = 'isset('.$arParams['FIELD'].'[\''.$arControl['FIELD'].'\'])';
3695 $strResult = $strField.' && '.$strResult;
3696 }
3697 }
3698
3699 return (!$boolError ? $strResult : false);
3700 }
3701
3702 public static function ApplyValues($arOneCondition, $arControl)
3703 {
3704 $arResult = array();
3705 $arValues = false;
3706
3707 $arLogicID = array(
3708 BT_COND_LOGIC_EQ,
3709 BT_COND_LOGIC_EGR,
3710 BT_COND_LOGIC_ELS,
3711 );
3712
3713 if (is_string($arControl))
3714 {
3715 $arControl = static::GetControls($arControl);
3716 }
3717 $boolError = !is_array($arControl);
3718
3719 if (!$boolError)
3720 {
3721 $arValues = static::Check($arOneCondition, $arOneCondition, $arControl, false);
3722 if ($arValues === false)
3723 {
3724 $boolError = true;
3725 }
3726 }
3727
3728 if (!$boolError)
3729 {
3730 $arLogic = static::SearchLogic($arValues['logic'], $arControl['LOGIC']);
3731 if (in_array($arLogic['ID'], $arLogicID))
3732 {
3733 $arResult = array(
3734 'ID' => $arControl['ID'],
3735 'FIELD' => $arControl['FIELD'],
3736 'FIELD_TYPE' => $arControl['FIELD_TYPE'],
3737 'VALUES' => (is_array($arValues['value']) ? $arValues['value'] : array($arValues['value']))
3738 );
3739 }
3740 }
3741 return (!$boolError ? $arResult : false);
3742 }
3743
3744 public static function Check($arOneCondition, $arParams, $arControl, $boolShow)
3745 {
3746 $result = parent::Check($arOneCondition, $arParams, $arControl, $boolShow);
3747 if (self::checkActiveProperty($arControl))
3748 return $result;
3749 $boolShow = ($boolShow === true);
3750 if ($boolShow)
3751 {
3752 $result['err_cond'] = 'Y';
3753 if (isset($result['err_cond_mess']))
3754 $result['err_cond_mess'] .= '. '.Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_PROPERTY_NOT_ACTIVE');
3755 else
3756 $result['err_cond_mess'] = Loc::getMessage('BT_MOD_CATALOG_COND_CMP_IBLOCK_PROPERTY_NOT_ACTIVE');
3757 }
3758 else
3759 {
3760 $result = false;
3761 }
3762 return $result;
3763 }
3764
3768 private static function getAdminSection()
3769 {
3770 //TODO: need use \CAdminPage::getSelfFolderUrl, but in general it is impossible now
3771 return (defined('SELF_FOLDER_URL') ? SELF_FOLDER_URL : '/bitrix/admin/');
3772 }
3773
3778 private static function checkActiveProperty(array $control)
3779 {
3780 $iterator = Iblock\PropertyTable::getList([
3781 'select' => ['ID', 'IBLOCK_ID'],
3782 'filter' => [
3783 '=IBLOCK_ID' => $control['IBLOCK_ID'],
3784 '=ID' => $control['PROPERTY_ID'],
3785 '=ACTIVE' => 'Y'
3786 ]
3787 ]);
3788 $row = $iterator->fetch();
3789 $result = !empty($row);
3790 unset($row, $iterator);
3791 return $result;
3792 }
3793}
3794
3795class CGlobalCondTree
3796{
3797 protected const PARAM_TITLE_MASK = '/^[A-Za-z_][A-Za-z01-9_]*$/';
3798
3799 protected $intMode = BT_COND_MODE_DEFAULT; // work mode
3800 protected $arEvents = array(); // events ID
3801 protected $arInitParams = array(); // start params
3802 protected $boolError = false; // error flag
3803 protected $arMsg = array(); // messages (errors)
3804
3805 protected $strFormName = ''; // form name
3806 protected $strFormID = ''; // form id
3807 protected $strContID = ''; // container id
3808 protected $strJSName = ''; // js object var name
3809 protected $boolCreateForm = false; // need create form
3810 protected $boolCreateCont = false; // need create container
3811 protected $strPrefix = 'rule'; // prefix for input
3812 protected $strSepID = '__'; // separator for id
3813
3814 protected $arSystemMess = array(); // system messages
3815
3816 protected $arAtomList = null; // atom list cache
3817 protected $arAtomJSPath = null; // atom js files
3818 protected $arControlList = null; // control list cache
3819 protected $arShowControlList = null; // control show method list
3820 protected $arShowInGroups = null; // showin group list
3821 protected $forcedShowInGroup = null; // forced showin list
3822 protected $arInitControlList = null; // control init list
3823
3824 protected $arDefaultControl = array(
3825 'Parse',
3827 'Generate',
3828 'ApplyValues'
3829 ); // required control fields
3830
3831 protected $usedModules = array(); // modules for real conditions
3832 protected $usedExtFiles = array(); // files from AddEventHandler
3833 protected $usedEntity = array(); // entity list in conditions
3834
3835 protected $arConditions = null; // conditions array
3836
3837 public function __construct()
3838 {
3839 CJSCore::Init(array("core_condtree"));
3840 }
3841
3842 public function __destruct()
3843 {
3844
3845 }
3846
3847 public function OnConditionAtomBuildList()
3848 {
3849 if ($this->boolError || isset($this->arAtomList))
3850 return;
3851
3852 $this->arAtomList = array();
3853 $this->arAtomJSPath = array();
3854
3855 $result = array();
3856 if (isset($this->arEvents['INTERFACE_ATOMS']))
3857 {
3858 $event = new Main\Event(
3859 $this->arEvents['INTERFACE_ATOMS']['MODULE_ID'],
3860 $this->arEvents['INTERFACE_ATOMS']['EVENT_ID']
3861 );
3862 $event->send();
3863 $resultList = $event->getResults();
3864 if (!empty($resultList))
3865 {
3866 foreach ($resultList as $eventResult)
3867 {
3868 if ($eventResult->getType() != Main\EventResult::SUCCESS)
3869 continue;
3870 $module = $eventResult->getModuleId();
3871 if (empty($module))
3872 continue;
3873 $result[] = $eventResult->getParameters();
3874 }
3875 unset($eventResult);
3876 }
3877 unset($resultList, $event);
3878 }
3879 if (isset($this->arEvents['ATOMS']))
3880 {
3881 foreach (GetModuleEvents($this->arEvents['ATOMS']['MODULE_ID'], $this->arEvents['ATOMS']['EVENT_ID'], true) as $arEvent)
3882 {
3883 $result[] = ExecuteModuleEventEx($arEvent);
3884 }
3885 }
3886
3887 if (!empty($result))
3888 {
3889 foreach ($result as $row)
3890 {
3891 if (empty($row) || !is_array($row))
3892 continue;
3893 if (empty($row['ID']) || isset($this->arAtomList[$row['ID']]))
3894 continue;
3895 $this->arAtomList[$row['ID']] = $row;
3896 if (
3897 !empty($row['JS_SRC'])
3898 && is_string($row['JS_SRC'])
3899 && !in_array($row['JS_SRC'], $this->arAtomJSPath)
3900 )
3901 {
3902 $this->arAtomJSPath[] = $row['JS_SRC'];
3903 }
3904 }
3905 unset($row);
3906 }
3907 unset($result);
3908 }
3909
3910 public function OnConditionControlBuildList()
3911 {
3912 if ($this->boolError || isset($this->arControlList))
3913 return;
3914
3915 $this->arControlList = array();
3916 $this->arShowInGroups = array();
3917 $this->forcedShowInGroup = array();
3918 $this->arShowControlList = array();
3919 $this->arInitControlList = array();
3920
3921 $result = array();
3922
3923 if (isset($this->arEvents['CONTROLS']))
3924 {
3925 foreach (GetModuleEvents($this->arEvents['CONTROLS']['MODULE_ID'], $this->arEvents['CONTROLS']['EVENT_ID'], true) as $arEvent)
3926 {
3927 $result[] = ExecuteModuleEventEx($arEvent);
3928 }
3929 }
3930 if (isset($this->arEvents['INTERFACE_CONTROLS']))
3931 {
3932 $event = new Main\Event(
3933 $this->arEvents['INTERFACE_CONTROLS']['MODULE_ID'],
3934 $this->arEvents['INTERFACE_CONTROLS']['EVENT_ID']
3935 );
3936 $event->send();
3937 $resultList = $event->getResults();
3938 if (!empty($resultList))
3939 {
3940 foreach ($resultList as $eventResult)
3941 {
3942 if ($eventResult->getType() != Main\EventResult::SUCCESS)
3943 continue;
3944 $module = $eventResult->getModuleId();
3945 if (empty($module))
3946 continue;
3947 $result[] = $eventResult->getParameters();
3948 }
3949 unset($eventResult);
3950 }
3951 unset($resultList, $event);
3952 }
3953
3954 if (!empty($result))
3955 {
3956 $rawControls = array();
3957 $controlIndex = 0;
3958 foreach ($result as $arRes)
3959 {
3960 if (empty($arRes) || !is_array($arRes))
3961 continue;
3962 if (isset($arRes['ID']))
3963 {
3964 if (isset($arRes['EXIST_HANDLER']) && $arRes['EXIST_HANDLER'] === 'Y')
3965 {
3966 if (!isset($arRes['MODULE_ID']) && !isset($arRes['EXT_FILE']))
3967 continue;
3968 }
3969 else
3970 {
3971 $arRes['MODULE_ID'] = '';
3972 $arRes['EXT_FILE'] = '';
3973 }
3974 if (array_key_exists('EXIST_HANDLER', $arRes))
3975 unset($arRes['EXIST_HANDLER']);
3976 $arRes['GROUP'] = (isset($arRes['GROUP']) && $arRes['GROUP'] == 'Y' ? 'Y' : 'N');
3977 if (isset($this->arControlList[$arRes['ID']]))
3978 {
3979 $this->arMsg[] = array('id' => 'CONTROLS', 'text' => str_replace('#CONTROL#', $arRes['ID'], Loc::getMessage('BT_MOD_COND_ERR_CONTROL_DOUBLE')));
3980 $this->boolError = true;
3981 }
3982 else
3983 {
3984 if (!$this->CheckControl($arRes))
3985 continue;
3986 $this->arControlList[$arRes["ID"]] = $arRes;
3987 if ($arRes['GROUP'] == 'Y')
3988 {
3989 if (empty($arRes['FORCED_SHOW_LIST']))
3990 {
3991 $this->arShowInGroups[] = $arRes['ID'];
3992 }
3993 else
3994 {
3995 $forcedList = $arRes['FORCED_SHOW_LIST'];
3996 if (!is_array($forcedList))
3997 $forcedList = array($forcedList);
3998 foreach ($forcedList as $forcedId)
3999 {
4000 if (is_array($forcedId))
4001 continue;
4002 $forcedId = trim($forcedId);
4003 if ($forcedId == '')
4004 continue;
4005 if (!isset($this->forcedShowInGroup[$forcedId]))
4006 $this->forcedShowInGroup[$forcedId] = array();
4007 $this->forcedShowInGroup[$forcedId][] = $arRes['ID'];
4008 }
4009 unset($forcedId, $forcedList);
4010 }
4011 }
4012 if (isset($arRes['GetControlShow']) && !empty($arRes['GetControlShow']))
4013 {
4014 if (!in_array($arRes['GetControlShow'], $this->arShowControlList))
4015 {
4016 $this->arShowControlList[] = $arRes['GetControlShow'];
4017 $showDescription = array(
4018 'CONTROL' => $arRes['GetControlShow'],
4019 );
4020 if (isset($arRes['SORT']) && (int)$arRes['SORT'] > 0)
4021 {
4022 $showDescription['SORT'] = (int)$arRes['SORT'];
4023 $showDescription['INDEX'] = 1;
4024 }
4025 else
4026 {
4027 $showDescription['SORT'] = INF;
4028 $showDescription['INDEX'] = $controlIndex;
4029 $controlIndex++;
4030 }
4031 $rawControls[] = $showDescription;
4032 unset($showDescription);
4033 }
4034 }
4035 if (isset($arRes['InitParams']) && !empty($arRes['InitParams']))
4036 {
4037 if (!in_array($arRes['InitParams'], $this->arInitControlList))
4038 $this->arInitControlList[] = $arRes['InitParams'];
4039 }
4040 }
4041 }
4042 elseif (isset($arRes['COMPLEX']) && 'Y' == $arRes['COMPLEX'])
4043 {
4044 $complexModuleID = '';
4045 $complexExtFiles = '';
4046 if (isset($arRes['EXIST_HANDLER']) && $arRes['EXIST_HANDLER'] === 'Y')
4047 {
4048 if (isset($arRes['MODULE_ID']))
4049 $complexModuleID = $arRes['MODULE_ID'];
4050 if (isset($arRes['EXT_FILE']))
4051 $complexExtFiles = $arRes['EXT_FILE'];
4052 }
4053 if (isset($arRes['CONTROLS']) && !empty($arRes['CONTROLS']) && is_array($arRes['CONTROLS']))
4054 {
4055 if (array_key_exists('EXIST_HANDLER', $arRes))
4056 unset($arRes['EXIST_HANDLER']);
4057 $arInfo = $arRes;
4058 unset($arInfo['COMPLEX'], $arInfo['CONTROLS']);
4059 foreach ($arRes['CONTROLS'] as &$arOneControl)
4060 {
4061 if (isset($arOneControl['ID']))
4062 {
4063 if (isset($arOneControl['EXIST_HANDLER']) && $arOneControl['EXIST_HANDLER'] === 'Y')
4064 {
4065 if (!isset($arOneControl['MODULE_ID']) && !isset($arOneControl['EXT_FILE']))
4066 continue;
4067 }
4068 $arInfo['GROUP'] = 'N';
4069 $arInfo['MODULE_ID'] = isset($arOneControl['MODULE_ID']) ? $arOneControl['MODULE_ID'] : $complexModuleID;
4070 $arInfo['EXT_FILE'] = isset($arOneControl['EXT_FILE']) ? $arOneControl['EXT_FILE'] : $complexExtFiles;
4071 $control = array_merge($arOneControl, $arInfo);
4072 if (isset($this->arControlList[$control['ID']]))
4073 {
4074 $this->arMsg[] = array('id' => 'CONTROLS', 'text' => str_replace('#CONTROL#', $control['ID'], Loc::getMessage('BT_MOD_COND_ERR_CONTROL_DOUBLE')));
4075 $this->boolError = true;
4076 }
4077 else
4078 {
4079 if (!$this->CheckControl($control))
4080 continue;
4081 $this->arControlList[$control['ID']] = $control;
4082 }
4083 unset($control);
4084 }
4085 }
4086 if (isset($arOneControl))
4087 unset($arOneControl);
4088 if (isset($arRes['GetControlShow']) && !empty($arRes['GetControlShow']))
4089 {
4090 if (!in_array($arRes['GetControlShow'], $this->arShowControlList))
4091 {
4092 $this->arShowControlList[] = $arRes['GetControlShow'];
4093 $showDescription = array(
4094 'CONTROL' => $arRes['GetControlShow'],
4095 );
4096 if (isset($arRes['SORT']) && (int)$arRes['SORT'] > 0)
4097 {
4098 $showDescription['SORT'] = (int)$arRes['SORT'];
4099 $showDescription['INDEX'] = 1;
4100 }
4101 else
4102 {
4103 $showDescription['SORT'] = INF;
4104 $showDescription['INDEX'] = $controlIndex;
4105 $controlIndex++;
4106 }
4107 $rawControls[] = $showDescription;
4108 unset($showDescription);
4109 }
4110 }
4111 if (isset($arRes['InitParams']) && !empty($arRes['InitParams']))
4112 {
4113 if (!in_array($arRes['InitParams'], $this->arInitControlList))
4114 $this->arInitControlList[] = $arRes['InitParams'];
4115 }
4116 }
4117 }
4118 else
4119 {
4120 foreach ($arRes as &$arOneRes)
4121 {
4122 if (is_array($arOneRes) && isset($arOneRes['ID']))
4123 {
4124 if (isset($arOneRes['EXIST_HANDLER']) && $arOneRes['EXIST_HANDLER'] === 'Y')
4125 {
4126 if (!isset($arOneRes['MODULE_ID']) && !isset($arOneRes['EXT_FILE']))
4127 continue;
4128 }
4129 else
4130 {
4131 $arOneRes['MODULE_ID'] = '';
4132 $arOneRes['EXT_FILE'] = '';
4133 }
4134 if (array_key_exists('EXIST_HANDLER', $arOneRes))
4135 unset($arOneRes['EXIST_HANDLER']);
4136 $arOneRes['GROUP'] = (isset($arOneRes['GROUP']) && $arOneRes['GROUP'] == 'Y' ? 'Y' : 'N');
4137 if (isset($this->arControlList[$arOneRes['ID']]))
4138 {
4139 $this->arMsg[] = array('id' => 'CONTROLS', 'text' => str_replace('#CONTROL#', $arOneRes['ID'], Loc::getMessage('BT_MOD_COND_ERR_CONTROL_DOUBLE')));
4140 $this->boolError = true;
4141 }
4142 else
4143 {
4144 if (!$this->CheckControl($arOneRes))
4145 continue;
4146 $this->arControlList[$arOneRes['ID']] = $arOneRes;
4147 if ($arOneRes['GROUP'] == 'Y')
4148 {
4149 if (empty($arOneRes['FORCED_SHOW_LIST']))
4150 {
4151 $this->arShowInGroups[] = $arOneRes['ID'];
4152 }
4153 else
4154 {
4155 $forcedList = (!is_array($arOneRes['FORCED_SHOW_LIST']) ? array($arOneRes['FORCED_SHOW_LIST']) : $arOneRes['FORCED_SHOW_LIST']);
4156 foreach ($forcedList as &$forcedId)
4157 {
4158 if (is_array($forcedId))
4159 continue;
4160 $forcedId = trim($forcedId);
4161 if ($forcedId == '')
4162 continue;
4163 if (!isset($this->forcedShowInGroup[$forcedId]))
4164 $this->forcedShowInGroup[$forcedId] = array();
4165 $this->forcedShowInGroup[$forcedId][] = $arOneRes['ID'];
4166 }
4167 unset($forcedId);
4168 }
4169 }
4170 if (isset($arOneRes['GetControlShow']) && !empty($arOneRes['GetControlShow']))
4171 {
4172 if (!in_array($arOneRes['GetControlShow'], $this->arShowControlList))
4173 {
4174 $this->arShowControlList[] = $arOneRes['GetControlShow'];
4175 $showDescription = array(
4176 'CONTROL' => $arOneRes['GetControlShow'],
4177 );
4178 if (isset($arOneRes['SORT']) && (int)$arOneRes['SORT'] > 0)
4179 {
4180 $showDescription['SORT'] = (int)$arOneRes['SORT'];
4181 $showDescription['INDEX'] = 1;
4182 }
4183 else
4184 {
4185 $showDescription['SORT'] = INF;
4186 $showDescription['INDEX'] = $controlIndex;
4187 $controlIndex++;
4188 }
4189 $rawControls[] = $showDescription;
4190 unset($showDescription);
4191 }
4192 }
4193 if (isset($arOneRes['InitParams']) && !empty($arOneRes['InitParams']))
4194 {
4195 if (!in_array($arOneRes['InitParams'], $this->arInitControlList))
4196 $this->arInitControlList[] = $arOneRes['InitParams'];
4197 }
4198 }
4199 }
4200 }
4201 unset($arOneRes);
4202 }
4203 }
4204 unset($arRes);
4205
4206 if (!empty($rawControls))
4207 {
4208 $this->arShowControlList = array();
4209 Main\Type\Collection::sortByColumn($rawControls, array('SORT' => SORT_ASC, 'INDEX' => SORT_ASC));
4210 foreach ($rawControls as $row)
4211 $this->arShowControlList[] = $row['CONTROL'];
4212 unset($row);
4213 }
4214 unset($controlIndex, $rawControls);
4215 }
4216 if (empty($this->arControlList))
4217 {
4218 $this->arMsg[] = array('id' => 'CONTROLS', 'text' => Loc::getMessage('BT_MOD_COND_ERR_CONTROLS_EMPTY'));
4219 $this->boolError = true;
4220 }
4221 }
4222
4223 protected function CheckControl($arControl)
4224 {
4225 $boolResult = true;
4226 foreach ($this->arDefaultControl as &$strKey)
4227 {
4228 if (!isset($arControl[$strKey]) || empty($arControl[$strKey]))
4229 {
4230 $boolResult = false;
4231 break;
4232 }
4233 }
4234 unset($strKey);
4235 return $boolResult;
4236 }
4237
4238 protected function GetModeList()
4239 {
4240 return array(
4241 BT_COND_MODE_DEFAULT,
4242 BT_COND_MODE_PARSE,
4243 BT_COND_MODE_GENERATE,
4244 BT_COND_MODE_SQL,
4245 BT_COND_MODE_SEARCH
4246 );
4247 }
4248
4249 protected function GetEventList($intEventID)
4250 {
4251 $arEventList = array(
4252 BT_COND_BUILD_CATALOG => array(
4253 'INTERFACE_ATOMS' => array(
4254 'MODULE_ID' => 'catalog',
4255 'EVENT_ID' => 'onBuildDiscountInterfaceAtoms'
4256 ),
4257 'INTERFACE_CONTROLS' => array(
4258 'MODULE_ID' => 'catalog',
4259 'EVENT_ID' => 'onBuildDiscountInterfaceControls'
4260 ),
4261 'ATOMS' => array(
4262 'MODULE_ID' => 'catalog',
4263 'EVENT_ID' => 'OnCondCatAtomBuildList'
4264 ),
4265 'CONTROLS' => array(
4266 'MODULE_ID' => 'catalog',
4267 'EVENT_ID' => 'OnCondCatControlBuildList'
4268 )
4269 ),
4270 BT_COND_BUILD_SALE => array(
4271 'INTERFACE_ATOMS' => array(
4272 'MODULE_ID' => 'sale',
4273 'EVENT_ID' => 'onBuildDiscountConditionInterfaceAtoms'
4274 ),
4275 'INTERFACE_CONTROLS' => array(
4276 'MODULE_ID' => 'sale',
4277 'EVENT_ID' => 'onBuildDiscountConditionInterfaceControls'
4278 ),
4279 'ATOMS' => array(
4280 'MODULE_ID' => 'sale',
4281 'EVENT_ID' => 'OnCondSaleAtomBuildList'
4282 ),
4283 'CONTROLS' => array(
4284 'MODULE_ID' => 'sale',
4285 'EVENT_ID' => 'OnCondSaleControlBuildList'
4286 )
4287 ),
4288 BT_COND_BUILD_SALE_ACTIONS => array(
4289 'INTERFACE_ATOMS' => array(
4290 'MODULE_ID' => 'sale',
4291 'EVENT_ID' => 'onBuildDiscountActionInterfaceAtoms'
4292 ),
4293 'INTERFACE_CONTROLS' => array(
4294 'MODULE_ID' => 'sale',
4295 'EVENT_ID' => 'onBuildDiscountActionInterfaceControls'
4296 ),
4297 'ATOMS' => array(
4298 'MODULE_ID' => 'sale',
4299 'EVENT_ID' => 'OnCondSaleActionsAtomBuildList'
4300 ),
4301 'CONTROLS' => array(
4302 'MODULE_ID' => 'sale',
4303 'EVENT_ID' => 'OnCondSaleActionsControlBuildList'
4304 )
4305 )
4306 );
4307 return (isset($arEventList[$intEventID]) ? $arEventList[$intEventID] : false);
4308 }
4309
4310 protected function CheckEvent($arEvent)
4311 {
4312 if (!is_array($arEvent))
4313 return false;
4314 if (!isset($arEvent['MODULE_ID']) || empty($arEvent['MODULE_ID']) || !is_string($arEvent['MODULE_ID']))
4315 return false;
4316 if (!isset($arEvent['EVENT_ID']) || empty($arEvent['EVENT_ID']) || !is_string($arEvent['EVENT_ID']))
4317 return false;
4318 return true;
4319 }
4320
4321 public function Init($intMode, $mxEvent, $arParams = array())
4322 {
4323 global $APPLICATION;
4324 $this->arMsg = array();
4325
4326 $intMode = (int)$intMode;
4327 if (!in_array($intMode, $this->GetModeList()))
4328 $intMode = BT_COND_MODE_DEFAULT;
4329 $this->intMode = $intMode;
4330
4331 $arEvent = false;
4332 if (is_array($mxEvent))
4333 {
4334 $fields = array(
4335 'INTERFACE_ATOMS', 'INTERFACE_CONTROLS',
4336 'ATOMS', 'CONTROLS'
4337 );
4338 foreach ($fields as $fieldName)
4339 {
4340 if (!isset($mxEvent[$fieldName]) || !$this->CheckEvent($mxEvent[$fieldName]))
4341 continue;
4342 $arEvent[$fieldName] = $mxEvent[$fieldName];
4343 }
4344 unset($fieldName);
4345 if (!isset($arEvent['INTERFACE_CONTROLS']) && !isset($arEvent['CONTROLS']))
4346 $arEvent = false;
4347 }
4348 else
4349 {
4350 $mxEvent = (int)$mxEvent;
4351 if ($mxEvent >= 0)
4352 $arEvent = $this->GetEventList($mxEvent);
4353 }
4354
4355 if ($arEvent === false)
4356 {
4357 $this->boolError = true;
4358 $this->arMsg[] = array('id' => 'EVENT','text' => Loc::getMessage('BT_MOD_COND_ERR_EVENT_BAD'));
4359 }
4360 else
4361 {
4362 $this->arEvents = $arEvent;
4363 }
4364
4365 $this->arInitParams = $arParams;
4366
4367 if (!is_array($arParams))
4368 $arParams = array();
4369
4370 $parsedValues = [];
4371 if (BT_COND_MODE_DEFAULT == $this->intMode)
4372 {
4373 if (!empty($arParams) && is_array($arParams))
4374 {
4375 if (
4376 isset($arParams['FORM_NAME'])
4377 && is_string($arParams['FORM_NAME'])
4378 && preg_match(self::PARAM_TITLE_MASK, $arParams['FORM_NAME'], $parsedValues)
4379 )
4380 {
4381 $this->strFormName = $arParams['FORM_NAME'];
4382 }
4383 if (
4384 isset($arParams['FORM_ID'])
4385 && is_string($arParams['FORM_ID'])
4386 && preg_match(self::PARAM_TITLE_MASK, $arParams['FORM_ID'], $parsedValues)
4387 )
4388 {
4389 $this->strFormID = $arParams['FORM_ID'];
4390 }
4391 if (
4392 isset($arParams['CONT_ID'])
4393 && is_string($arParams['CONT_ID'])
4394 && preg_match(self::PARAM_TITLE_MASK, $arParams['CONT_ID'], $parsedValues)
4395 )
4396 {
4397 $this->strContID = $arParams['CONT_ID'];
4398 }
4399 if (
4400 isset($arParams['JS_NAME'])
4401 && is_string($arParams['JS_NAME'])
4402 && preg_match(self::PARAM_TITLE_MASK, $arParams['JS_NAME'], $parsedValues)
4403 )
4404 {
4405 $this->strJSName = $arParams['JS_NAME'];
4406 }
4407
4408 $this->boolCreateForm = (isset($arParams['CREATE_FORM']) && 'Y' == $arParams['CREATE_FORM']);
4409 $this->boolCreateCont = (isset($arParams['CREATE_CONT']) && 'Y' == $arParams['CREATE_CONT']);
4410 }
4411
4412 if (empty($this->strJSName))
4413 {
4414 if (empty($this->strContID))
4415 {
4416 $this->boolError = true;
4417 $this->arMsg[] = array('id' => 'JS_NAME','text' => Loc::getMessage('BT_MOD_COND_ERR_JS_NAME_BAD'));
4418 }
4419 else
4420 {
4421 $this->strJSName = md5($this->strContID);
4422 }
4423 }
4424 }
4425 if (BT_COND_MODE_DEFAULT == $this->intMode || BT_COND_MODE_PARSE == $this->intMode)
4426 {
4427 if (!empty($arParams) && is_array($arParams))
4428 {
4429 if (
4430 isset($arParams['PREFIX'])
4431 && is_string($arParams['PREFIX'])
4432 && preg_match(self::PARAM_TITLE_MASK, $arParams['PREFIX'], $parsedValues)
4433 )
4434 {
4435 $this->strPrefix = $arParams['PREFIX'];
4436 }
4437 if (
4438 isset($arParams['SEP_ID'])
4439 && is_string($arParams['SEP_ID'])
4440 && preg_match(self::PARAM_TITLE_MASK, $arParams['SEP_ID'], $parsedValues)
4441 )
4442 {
4443 $this->strSepID = $arParams['SEP_ID'];
4444 }
4445 }
4446 }
4447
4448 $this->OnConditionAtomBuildList();
4449 $this->OnConditionControlBuildList();
4450
4451 if (!$this->boolError)
4452 {
4453 if (!empty($this->arInitControlList) && is_array($this->arInitControlList))
4454 {
4455 if (!empty($arParams) && is_array($arParams))
4456 {
4457 if (isset($arParams['INIT_CONTROLS']) && !empty($arParams['INIT_CONTROLS']) && is_array($arParams['INIT_CONTROLS']))
4458 {
4459 foreach ($this->arInitControlList as &$arOneControl)
4460 {
4461 call_user_func_array($arOneControl,
4462 array(
4463 $arParams['INIT_CONTROLS']
4464 )
4465 );
4466 }
4467 if (isset($arOneControl))
4468 unset($arOneControl);
4469 }
4470 }
4471 }
4472 }
4473
4474 if (isset($arParams['SYSTEM_MESSAGES']) && !empty($arParams['SYSTEM_MESSAGES']) && is_array($arParams['SYSTEM_MESSAGES']))
4475 {
4476 $this->arSystemMess = $arParams['SYSTEM_MESSAGES'];
4477 }
4478
4479 if ($this->boolError)
4480 {
4481 $obError = new CAdminException($this->arMsg);
4482 $APPLICATION->ThrowException($obError);
4483 }
4484 return !$this->boolError;
4485 }
4486
4487 public function Show($arConditions)
4488 {
4489 $this->arMsg = array();
4490
4491 if (!$this->boolError)
4492 {
4493 if (!empty($arConditions))
4494 {
4495 if (!is_array($arConditions))
4496 {
4497 if (!CheckSerializedData($arConditions))
4498 {
4499 $this->boolError = true;
4500 $this->arMsg[] = array('id' => 'CONDITIONS', 'text' => Loc::getMessage('BT_MOD_COND_ERR_SHOW_DATA_UNSERIALIZE'));
4501 }
4502 else
4503 {
4504 $arConditions = unserialize($arConditions, ['allowed_classes' => false]);
4505 if (!is_array($arConditions))
4506 {
4507 $this->boolError = true;
4508 $this->arMsg[] = array('id' => 'CONDITIONS', 'text' => Loc::getMessage('BT_MOD_COND_ERR_SHOW_DATA_UNSERIALIZE'));
4509 }
4510 }
4511 }
4512 }
4513 }
4514
4515 if (!$this->boolError)
4516 {
4517 $this->arConditions = (!empty($arConditions) ? $arConditions : $this->GetDefaultConditions());
4518
4519 $strResult = '';
4520
4521 $this->ShowScripts();
4522
4523 if ($this->boolCreateForm)
4524 {
4525
4526 }
4527 if ($this->boolCreateCont)
4528 {
4529
4530 }
4531
4532 $strResult .= '<script>'."\n";
4533 $strResult .= 'var '.$this->strJSName.' = new BX.TreeConditions('."\n";
4534 $strResult .= $this->ShowParams().",\n";
4535 $strResult .= $this->ShowConditions().",\n";
4536 $strResult .= $this->ShowControls()."\n";
4537
4538 $strResult .= ');'."\n";
4539 $strResult .= '</script>'."\n";
4540
4541 if ($this->boolCreateCont)
4542 {
4543
4544 }
4545 if ($this->boolCreateForm)
4546 {
4547
4548 }
4549
4550 echo $strResult;
4551 }
4552 }
4553
4554 public function GetDefaultConditions()
4555 {
4556 return array(
4557 'CLASS_ID' => 'CondGroup',
4558 'DATA' => array('All' => 'AND', 'True' => 'True'),
4559 'CHILDREN' => array()
4560 );
4561 }
4562
4563 public function Parse($arData = '', $arParams = false)
4564 {
4565 global $APPLICATION;
4566 $this->arMsg = array();
4567
4568 $this->usedModules = array();
4569 $this->usedExtFiles = array();
4570
4571 $arResult = array();
4572 if (!$this->boolError)
4573 {
4574 if (empty($arData) || !is_array($arData))
4575 {
4576 if (isset($_POST[$this->strPrefix]) && !empty($_POST[$this->strPrefix]) && is_array($_POST[$this->strPrefix]))
4577 {
4578 $arData = $_POST[$this->strPrefix];
4579 }
4580 else
4581 {
4582 $this->boolError = true;
4583 $this->arMsg[] = array('id' => 'CONDITIONS', 'text' => Loc::getMessage('BT_MOD_COND_ERR_PARSE_DATA_EMPTY'));
4584 }
4585 }
4586 }
4587
4588 if (!$this->boolError)
4589 {
4590 foreach ($arData as $strKey => $value)
4591 {
4592 $arKeys = $this->__ConvertKey($strKey);
4593 if (empty($arKeys))
4594 {
4595 $this->boolError = true;
4596 $this->arMsg[] = array('id' => 'CONDITIONS', 'text' => Loc::getMessage('BT_MOD_COND_ERR_PARSE_DATA_BAD_KEY'));
4597 break;
4598 }
4599
4600 if (!isset($value['controlId']) || empty($value['controlId']))
4601 {
4602 $this->boolError = true;
4603 $this->arMsg[] = array('id' => 'CONDITIONS', 'text' => Loc::getMessage('BT_MOD_COND_ERR_PARSE_DATA_EMPTY_CONTROLID'));
4604 break;
4605 }
4606
4607 if (!isset($this->arControlList[$value['controlId']]))
4608 {
4609 $this->boolError = true;
4610 $this->arMsg[] = array('id' => 'CONDITIONS', 'text' => Loc::getMessage('BT_MOD_COND_ERR_PARSE_DATA_BAD_CONTROLID'));
4611 break;
4612 }
4613
4614 $arOneCondition = call_user_func_array($this->arControlList[$value['controlId']]['Parse'],
4615 array(
4616 $value
4617 )
4618 );
4619 if (false === $arOneCondition)
4620 {
4621 $this->boolError = true;
4622 $this->arMsg[] = array('id' => 'CONDITIONS', 'text' => Loc::getMessage('BT_MOD_COND_ERR_PARSE_DATA_CONTROL_BAD_VALUE'));
4623 break;
4624 }
4625
4626 $arItem = array(
4627 'CLASS_ID' => $value['controlId'],
4628 'DATA' => $arOneCondition
4629 );
4630 if ('Y' == $this->arControlList[$value['controlId']]['GROUP'])
4631 {
4632 $arItem['CHILDREN'] = array();
4633 }
4634 if (!$this->__SetCondition($arResult, $arKeys, 0, $arItem))
4635 {
4636 $this->boolError = true;
4637 $this->arMsg[] = array('id' => 'CONDITIONS', 'text' => Loc::getMessage('BT_MOD_COND_ERR_PARSE_DATA_DOUBLE_KEY'));
4638 break;
4639 }
4640 }
4641 }
4642
4643 if ($this->boolError)
4644 {
4645 $obError = new CAdminException($this->arMsg);
4646 $APPLICATION->ThrowException($obError);
4647 }
4648 return (!$this->boolError ? $arResult : '');
4649 }
4650
4651 public function ShowScripts()
4652 {
4653 if (!$this->boolError)
4654 {
4655 $this->ShowAtoms();
4656 }
4657 }
4658
4659 public function ShowAtoms()
4660 {
4661 if (!$this->boolError)
4662 {
4663 if (!isset($this->arAtomList))
4664 {
4665 $this->OnConditionAtomBuildList();
4666 }
4667 if (!empty($this->arAtomJSPath) && is_array($this->arAtomJSPath))
4668 {
4669 $asset = Main\Page\Asset::getInstance();
4670 foreach ($this->arAtomJSPath as $jsPath)
4671 $asset->addJs($jsPath);
4672 unset($jsPath);
4673 unset($asset);
4674 }
4675 }
4676 }
4677
4678 public function ShowParams()
4679 {
4680 if (!$this->boolError)
4681 {
4682 $arParams = array(
4683 'parentContainer' => $this->strContID,
4684 'form' => $this->strFormID,
4685 'formName' => $this->strFormName,
4686 'sepID' => $this->strSepID,
4687 'prefix' => $this->strPrefix,
4688 );
4689
4690 if (!empty($this->arSystemMess))
4691 $arParams['messTree'] = $this->arSystemMess;
4692
4693 return CUtil::PhpToJSObject($arParams);
4694 }
4695 else
4696 {
4697 return '';
4698 }
4699 }
4700
4701 public function ShowControls()
4702 {
4703 if ($this->boolError)
4704 return '';
4705
4706 $result = array();
4707 if (!empty($this->arShowControlList))
4708 {
4709 foreach ($this->arShowControlList as &$arOneControl)
4710 {
4711 $arShowControl = call_user_func_array($arOneControl, array(
4712 array('SHOW_IN_GROUPS' => $this->arShowInGroups)
4713 ));
4714 if (!empty($arShowControl) && is_array($arShowControl))
4715 {
4716 $this->fillForcedShow($arShowControl);
4717 if (isset($arShowControl['controlId']) || isset($arShowControl['controlgroup']))
4718 {
4719 $result[] = $arShowControl;
4720 }
4721 else
4722 {
4723 foreach ($arShowControl as &$oneControl)
4724 $result[] = $oneControl;
4725 unset($oneControl);
4726 }
4727 }
4728 }
4729 unset($arOneControl);
4730 }
4731
4732 return CUtil::PhpToJSObject($result);
4733 }
4734
4735 public function ShowLevel(&$arLevel, $boolFirst = false)
4736 {
4737 $boolFirst = ($boolFirst === true);
4738 $arResult = array();
4739 if (empty($arLevel) || !is_array($arLevel))
4740 return $arResult;
4741 $intCount = 0;
4742 if ($boolFirst)
4743 {
4744 if (isset($arLevel['CLASS_ID']) && !empty($arLevel['CLASS_ID']))
4745 {
4746 if (isset($this->arControlList[$arLevel['CLASS_ID']]))
4747 {
4748 $arOneControl = $this->arControlList[$arLevel['CLASS_ID']];
4749 $arParams = array(
4750 'COND_NUM' => $intCount,
4751 'DATA' => $arLevel['DATA'],
4752 'ID' => $arOneControl['ID'],
4753 );
4754 $arOneResult = call_user_func_array($arOneControl["GetConditionShow"],
4755 array(
4756 $arParams,
4757 )
4758 );
4759 if ('Y' == $arOneControl['GROUP'])
4760 {
4761 $arOneResult['children'] = array();
4762 if (isset($arLevel['CHILDREN']))
4763 $arOneResult['children'] = $this->ShowLevel($arLevel['CHILDREN'], false);
4764 }
4765 $arResult[] = $arOneResult;
4766 }
4767 }
4768 }
4769 else
4770 {
4771 foreach ($arLevel as &$arOneCondition)
4772 {
4773 if (isset($arOneCondition['CLASS_ID']) && !empty($arOneCondition['CLASS_ID']))
4774 {
4775 if (isset($this->arControlList[$arOneCondition['CLASS_ID']]))
4776 {
4777 $arOneControl = $this->arControlList[$arOneCondition['CLASS_ID']];
4778 $arParams = array(
4779 'COND_NUM' => $intCount,
4780 'DATA' => $arOneCondition['DATA'],
4781 'ID' => $arOneControl['ID'],
4782 );
4783 $arOneResult = call_user_func_array($arOneControl["GetConditionShow"],
4784 array(
4785 $arParams,
4786 )
4787 );
4788
4789 if ('Y' == $arOneControl['GROUP'] && isset($arOneCondition['CHILDREN']))
4790 {
4791 $arOneResult['children'] = $this->ShowLevel($arOneCondition['CHILDREN'], false);
4792 }
4793 $arResult[] = $arOneResult;
4794 $intCount++;
4795 }
4796 }
4797 }
4798 if (isset($arOneCondition))
4799 unset($arOneCondition);
4800 }
4801 return $arResult;
4802 }
4803
4804 public function ShowConditions()
4805 {
4806 if (!$this->boolError)
4807 {
4808 if (empty($this->arConditions))
4809 $this->arConditions = $this->GetDefaultConditions();
4810
4811 $arResult = $this->ShowLevel($this->arConditions, true);
4812
4813 return CUtil::PhpToJSObject(current($arResult));
4814 }
4815 else
4816 {
4817 return '';
4818 }
4819 }
4820
4821 public function Generate($arConditions, $arParams)
4822 {
4823 $this->usedModules = array();
4824 $this->usedExtFiles = array();
4825 $this->usedEntity = array();
4826
4827 $strResult = '';
4828 if (!$this->boolError)
4829 {
4830 if (!empty($arConditions) && is_array($arConditions))
4831 {
4832 $arResult = $this->GenerateLevel($arConditions, $arParams, true);
4833 if (empty($arResult))
4834 {
4835 $strResult = '';
4836 $this->boolError = true;
4837 }
4838 else
4839 {
4840 $strResult = current($arResult);
4841 }
4842 }
4843 else
4844 {
4845 $this->boolError = true;
4846 }
4847 }
4848 return $strResult;
4849 }
4850
4851 public function GenerateLevel(&$arLevel, $arParams, $boolFirst = false)
4852 {
4853 $arResult = array();
4854 $boolFirst = ($boolFirst === true);
4855 if (empty($arLevel) || !is_array($arLevel))
4856 {
4857 return $arResult;
4858 }
4859 if ($boolFirst)
4860 {
4861 if (isset($arLevel['CLASS_ID']) && !empty($arLevel['CLASS_ID']))
4862 {
4863 if (isset($this->arControlList[$arLevel['CLASS_ID']]))
4864 {
4865 $arOneControl = $this->arControlList[$arLevel['CLASS_ID']];
4866 if ('Y' == $arOneControl['GROUP'])
4867 {
4868 $arSubEval = $this->GenerateLevel($arLevel['CHILDREN'], $arParams);
4869 if (false === $arSubEval || !is_array($arSubEval))
4870 return false;
4871 $strEval = call_user_func_array($arOneControl['Generate'],
4872 array($arLevel['DATA'], $arParams, $arLevel['CLASS_ID'], $arSubEval)
4873 );
4874 }
4875 else
4876 {
4877 $strEval = call_user_func_array($arOneControl['Generate'],
4878 array($arLevel['DATA'], $arParams, $arLevel['CLASS_ID'])
4879 );
4880 }
4881 if (false === $strEval || !is_string($strEval) || 'false' === $strEval)
4882 {
4883 return false;
4884 }
4885 $arResult[] = '('.$strEval.')';
4886 $this->fillUsedData($arOneControl);
4887 }
4888 }
4889 }
4890 else
4891 {
4892 foreach ($arLevel as &$arOneCondition)
4893 {
4894 if (isset($arOneCondition['CLASS_ID']) && !empty($arOneCondition['CLASS_ID']))
4895 {
4896 if (isset($this->arControlList[$arOneCondition['CLASS_ID']]))
4897 {
4898 $arOneControl = $this->arControlList[$arOneCondition['CLASS_ID']];
4899 if ('Y' == $arOneControl['GROUP'])
4900 {
4901 $arSubEval = $this->GenerateLevel($arOneCondition['CHILDREN'], $arParams);
4902 if (false === $arSubEval || !is_array($arSubEval))
4903 return false;
4904 $strEval = call_user_func_array($arOneControl['Generate'],
4905 array($arOneCondition['DATA'], $arParams, $arOneCondition['CLASS_ID'], $arSubEval)
4906 );
4907 }
4908 else
4909 {
4910 $strEval = call_user_func_array($arOneControl['Generate'],
4911 array($arOneCondition['DATA'], $arParams, $arOneCondition['CLASS_ID'])
4912 );
4913 }
4914
4915 if (false === $strEval || !is_string($strEval) || 'false' === $strEval)
4916 {
4917 return false;
4918 }
4919 $arResult[] = '('.$strEval.')';
4920 $this->fillUsedData($arOneControl);
4921 }
4922 }
4923 }
4924 if (isset($arOneCondition))
4925 unset($arOneCondition);
4926 }
4927
4928 if (!empty($arResult))
4929 {
4930 foreach ($arResult as $key => $value)
4931 {
4932 if ('' == $value || '()' == $value)
4933 unset($arResult[$key]);
4934 }
4935 }
4936 if (!empty($arResult))
4937 $arResult = array_values($arResult);
4938
4939 return $arResult;
4940 }
4941
4942 public function GetConditionValues($arConditions)
4943 {
4944 $arResult = false;
4945 if (!$this->boolError)
4946 {
4947 if (!empty($arConditions) && is_array($arConditions))
4948 {
4949 $arValues = array();
4950 $this->GetConditionValuesLevel($arConditions, $arValues, true);
4951 $arResult = $arValues;
4952 }
4953 }
4954 return $arResult;
4955 }
4956
4957 public function GetConditionValuesLevel(&$arLevel, &$arResult, $boolFirst = false)
4958 {
4959 $boolFirst = ($boolFirst === true);
4960 if (is_array($arLevel) && !empty($arLevel))
4961 {
4962 if ($boolFirst)
4963 {
4964 if (isset($arLevel['CLASS_ID']) && !empty($arLevel['CLASS_ID']))
4965 {
4966 if (isset($this->arControlList[$arLevel['CLASS_ID']]))
4967 {
4968 $arOneControl = $this->arControlList[$arLevel['CLASS_ID']];
4969 if ('Y' == $arOneControl['GROUP'])
4970 {
4971 if (call_user_func_array($arOneControl['ApplyValues'],
4972 array($arLevel['DATA'], $arLevel['CLASS_ID'])))
4973 {
4974 $this->GetConditionValuesLevel($arLevel['CHILDREN'], $arResult, false);
4975 }
4976 }
4977 else
4978 {
4979 $arCondInfo = call_user_func_array($arOneControl['ApplyValues'],
4980 array($arLevel['DATA'], $arLevel['CLASS_ID'])
4981 );
4982 if (!empty($arCondInfo) && is_array($arCondInfo))
4983 {
4984 if (!isset($arResult[$arLevel['CLASS_ID']]) || empty($arResult[$arLevel['CLASS_ID']]) || !is_array($arResult[$arLevel['CLASS_ID']]))
4985 {
4986 $arResult[$arLevel['CLASS_ID']] = $arCondInfo;
4987 }
4988 else
4989 {
4990 $arResult[$arLevel['CLASS_ID']]['VALUES'] = array_merge($arResult[$arLevel['CLASS_ID']]['VALUES'], $arCondInfo['VALUES']);
4991 }
4992 }
4993 }
4994 }
4995 }
4996 }
4997 else
4998 {
4999 foreach ($arLevel as &$arOneCondition)
5000 {
5001 if (isset($arOneCondition['CLASS_ID']) && !empty($arOneCondition['CLASS_ID']))
5002 {
5003 if (isset($this->arControlList[$arOneCondition['CLASS_ID']]))
5004 {
5005 $arOneControl = $this->arControlList[$arOneCondition['CLASS_ID']];
5006 if ('Y' == $arOneControl['GROUP'])
5007 {
5008 if (call_user_func_array($arOneControl['ApplyValues'],
5009 array($arOneCondition['DATA'], $arOneCondition['CLASS_ID'])))
5010 {
5011 $this->GetConditionValuesLevel($arOneCondition['CHILDREN'], $arResult, false);
5012 }
5013 }
5014 else
5015 {
5016 $arCondInfo = call_user_func_array($arOneControl['ApplyValues'],
5017 array($arOneCondition['DATA'], $arOneCondition['CLASS_ID'])
5018 );
5019 if (!empty($arCondInfo) && is_array($arCondInfo))
5020 {
5021 if (!isset($arResult[$arOneCondition['CLASS_ID']]) || empty($arResult[$arOneCondition['CLASS_ID']]) || !is_array($arResult[$arOneCondition['CLASS_ID']]))
5022 {
5023 $arResult[$arOneCondition['CLASS_ID']] = $arCondInfo;
5024 }
5025 else
5026 {
5027 $arResult[$arOneCondition['CLASS_ID']]['VALUES'] = array_merge($arResult[$arOneCondition['CLASS_ID']]['VALUES'], $arCondInfo['VALUES']);
5028 }
5029 }
5030 }
5031 }
5032 }
5033 }
5034 if (isset($arOneCondition))
5035 unset($arOneCondition);
5036 }
5037 }
5038 }
5039
5040 public function GetConditionHandlers()
5041 {
5042 return array(
5043 'MODULES' => (!empty($this->usedModules) ? array_keys($this->usedModules) : array()),
5044 'EXT_FILES' => (!empty($this->usedExtFiles) ? array_keys($this->usedExtFiles) : array())
5045 );
5046 }
5047
5048 public function GetUsedEntityList()
5049 {
5050 return $this->usedEntity;
5051 }
5052
5053 protected function __ConvertKey($strKey)
5054 {
5055 if ('' !== $strKey)
5056 {
5057 $arKeys = explode($this->strSepID, $strKey);
5058 if (is_array($arKeys))
5059 {
5060 foreach ($arKeys as &$intOneKey)
5061 {
5062 $intOneKey = (int)$intOneKey;
5063 }
5064 }
5065 return $arKeys;
5066 }
5067 else
5068 {
5069 return false;
5070 }
5071 }
5072
5073 protected function __SetCondition(&$arResult, $arKeys, $intIndex, $arOneCondition)
5074 {
5075 if (0 == $intIndex)
5076 {
5077 if (1 == sizeof($arKeys))
5078 {
5079 $arResult = $arOneCondition;
5080 return true;
5081 }
5082 else
5083 {
5084 return $this->__SetCondition($arResult, $arKeys, $intIndex + 1, $arOneCondition);
5085 }
5086 }
5087 else
5088 {
5089 if (!isset($arResult['CHILDREN']))
5090 {
5091 $arResult['CHILDREN'] = array();
5092 }
5093 if (!isset($arResult['CHILDREN'][$arKeys[$intIndex]]))
5094 {
5095 $arResult['CHILDREN'][$arKeys[$intIndex]] = array();
5096 }
5097 if (($intIndex + 1) < sizeof($arKeys))
5098 {
5099 return $this->__SetCondition($arResult['CHILDREN'][$arKeys[$intIndex]], $arKeys, $intIndex + 1, $arOneCondition);
5100 }
5101 else
5102 {
5103 if (!empty($arResult['CHILDREN'][$arKeys[$intIndex]]))
5104 {
5105 return false;
5106 }
5107 else
5108 {
5109 $arResult['CHILDREN'][$arKeys[$intIndex]] = $arOneCondition;
5110 return true;
5111 }
5112 }
5113 }
5114 }
5115
5116 protected function fillUsedData(&$control)
5117 {
5118 if (!empty($control['MODULE_ID']))
5119 {
5120 if (is_array($control['MODULE_ID']))
5121 {
5122 foreach ($control['MODULE_ID'] as &$oneModuleID)
5123 {
5124 if ($oneModuleID != $this->arEvents['CONTROLS']['MODULE_ID'])
5125 $this->usedModules[$oneModuleID] = true;
5126 }
5127 unset($oneModuleID);
5128 }
5129 else
5130 {
5131 if ($control['MODULE_ID'] != $this->arEvents['CONTROLS']['MODULE_ID'])
5132 $this->usedModules[$control['MODULE_ID']] = true;
5133 }
5134 }
5135 if (!empty($control['EXT_FILE']))
5136 {
5137 if (is_array($control['EXT_FILE']))
5138 {
5139 foreach ($control['EXT_FILE'] as &$oneExtFile)
5140 $this->usedExtFiles[$oneExtFile] = true;
5141 unset($oneExtFile);
5142 }
5143 else
5144 {
5145 $this->usedExtFiles[$control['EXT_FILE']] = true;
5146 }
5147 }
5148
5149 if (!empty($control['ENTITY']))
5150 {
5151 $entityID = $control['ENTITY'].'|';
5152 $entityID .= (is_array($control['FIELD']) ? implode('-', $control['FIELD']) : $control['FIELD']);
5153 if (!isset($this->usedEntity[$entityID]))
5154 {
5155 $row = [
5156 'MODULE' => (!empty($control['MODULE_ID']) ? $control['MODULE_ID'] : $control['MODULE_ENTITY']),
5157 'ENTITY' => $control['ENTITY'],
5158 'FIELD_ENTITY' => $control['FIELD'],
5159 'FIELD_TABLE' => (!empty($control['FIELD_TABLE']) ? $control['FIELD_TABLE'] : $control['FIELD'])
5160 ];
5161 if (isset($control['ENTITY_ID']))
5162 {
5163 $row['ENTITY_ID'] = $control['ENTITY_ID'];
5164 }
5165 if (isset($control['ENTITY_VALUE']) || isset($control['ENTITY_ID']))
5166 {
5167 $row['ENTITY_VALUE'] = (isset($control['ENTITY_VALUE'])
5168 ? $control['ENTITY_VALUE']
5169 : $control['ENTITY_ID']
5170 );
5171 }
5172 $this->usedEntity[$entityID] = $row;
5173 unset($row);
5174 }
5175 unset($entityID);
5176 }
5177 }
5178
5179 protected function fillForcedShow(&$showControl)
5180 {
5181 if (empty($this->forcedShowInGroup))
5182 return;
5183 if (isset($showControl['controlId']) || isset($showControl['controlgroup']))
5184 {
5185 if (!isset($showControl['controlgroup']))
5186 {
5187 if (isset($this->forcedShowInGroup[$showControl['controlId']]))
5188 $showControl['showIn'] = array_values(array_unique(array_merge(
5189 $showControl['showIn'], $this->forcedShowInGroup[$showControl['controlId']]
5190 )));
5191 }
5192 else
5193 {
5194 $forcedGroup = array();
5195 foreach ($showControl['children'] as &$oneControl)
5196 {
5197 if (isset($oneControl['controlId']))
5198 {
5199 if (isset($this->forcedShowInGroup[$oneControl['controlId']]))
5200 {
5201 $oneControl['showIn'] = array_values(array_unique(array_merge(
5202 $oneControl['showIn'], $this->forcedShowInGroup[$oneControl['controlId']]
5203 )));
5204 $forcedGroup = array_merge($forcedGroup, $this->forcedShowInGroup[$oneControl['controlId']]);
5205 }
5206 }
5207 }
5208 unset($oneControl);
5209 if (!empty($forcedGroup))
5210 {
5211 $forcedGroup = array_values(array_unique($forcedGroup));
5212 $showControl['showIn'] = array_values(array_unique(array_merge($showControl['showIn'], $forcedGroup)));
5213 }
5214 unset($forcedGroup);
5215
5216 }
5217 }
5218 else
5219 {
5220 foreach ($showControl as &$oneControl)
5221 {
5222 if (isset($oneControl['controlId']))
5223 {
5224 if (isset($this->forcedShowInGroup[$oneControl['controlId']]))
5225 $oneControl['showIn'] = array_values(array_unique(array_merge(
5226 $oneControl['showIn'], $this->forcedShowInGroup[$oneControl['controlId']]
5227 )));
5228 }
5229 }
5230 unset($oneControl);
5231 }
5232 }
5233}
5234
5235class CCatalogCondTree extends CGlobalCondTree
5236{
5237 public function __construct()
5238 {
5239 parent::__construct();
5240 }
5241
5242 public function __destruct()
5243 {
5244 parent::__destruct();
5245 }
5246}
$arParams
Определения access_dialog.php:21
return select
Определения access_edit.php:440
$arResult
Определения generate_coupon.php:16
const BT_COND_LOGIC_CONT
Определения catalog_cond.php:15
const BT_COND_MODE_SQL
Определения catalog_cond.php:21
const BT_COND_MODE_DEFAULT
Определения catalog_cond.php:18
const BT_COND_BUILD_SALE_ACTIONS
Определения catalog_cond.php:26
const BT_COND_LOGIC_ELS
Определения catalog_cond.php:14
const BT_COND_LOGIC_EGR
Определения catalog_cond.php:13
const BT_COND_MODE_GENERATE
Определения catalog_cond.php:20
const BT_COND_LOGIC_LS
Определения catalog_cond.php:12
const BT_COND_LOGIC_NOT_CONT
Определения catalog_cond.php:16
const BT_COND_LOGIC_NOT_EQ
Определения catalog_cond.php:10
const BT_COND_MODE_PARSE
Определения catalog_cond.php:19
const BT_COND_LOGIC_EQ
Определения catalog_cond.php:9
const BT_COND_LOGIC_GR
Определения catalog_cond.php:11
const BT_COND_MODE_SEARCH
Определения catalog_cond.php:22
const BT_COND_BUILD_CATALOG
Определения catalog_cond.php:24
const BT_COND_BUILD_SALE
Определения catalog_cond.php:25
static getMessage($code, $replace=null, $language=null)
Определения loc.php:30
static getList(array $parameters=array())
Определения datamanager.php:431
Определения date.php:9
Определения user.php:48
static Parse($condition)
Определения catalog_cond.php:2477
static GetConditionShow($params)
Определения catalog_cond.php:2462
static Generate($condition, $params, $control, $childrens=false)
Определения catalog_cond.php:2492
static GetControlShow($params)
Определения catalog_cond.php:2525
static GetControlDescr()
Определения catalog_cond.php:2279
static GetConditionShow($arParams)
Определения catalog_cond.php:2295
static Generate($arOneCondition, $arParams, $arControl, $arSubs=false)
Определения catalog_cond.php:2317
static Parse($arOneCondition)
Определения catalog_cond.php:2307
static ApplyValues($arOneCondition, $arControl)
Определения catalog_cond.php:2790
static GetConditionShow($arParams)
Определения catalog_cond.php:2590
static Generate($arOneCondition, $arParams, $arControl, $arSubs=false)
Определения catalog_cond.php:2730
static IsGroup($strControlID=false)
Определения catalog_cond.php:2703
static Parse($arOneCondition)
Определения catalog_cond.php:2708
static GetControlShow($arParams)
Определения catalog_cond.php:2577
Определения catalog_cond.php:29
static ApplyValues($arOneCondition, $arControl)
Определения catalog_cond.php:78
static LogicEqualGreat($arField, $mxValue)
Определения catalog_cond.php:2029
static CheckLogic($strValue, $arLogic, $boolShow=false)
Определения catalog_cond.php:305
static GetControlDescr()
Определения catalog_cond.php:38
static LogicGreat($arField, $mxValue)
Определения catalog_cond.php:1983
static ClearValue(&$mxValues)
Определения catalog_cond.php:2117
static ConvertDateTime2Int(&$mxValues, $strFormat, $intOffset)
Определения catalog_cond.php:2185
static Validate($arOneCondition, $arParams, $arControl, $boolShow)
Определения catalog_cond.php:682
static GetClassName()
Определения catalog_cond.php:33
static $boolInit
Определения catalog_cond.php:31
static InitParams($arParams)
Определения catalog_cond.php:83
static searchControlAtoms(array $atoms, $controlId, $extendedMode)
Определения catalog_cond.php:2239
static LogicContain($arField, $mxValue)
Определения catalog_cond.php:2075
static GetLogicAtom($arLogic)
Определения catalog_cond.php:263
static GetConditionShow($arParams)
Определения catalog_cond.php:58
static Generate($arOneCondition, $arParams, $arControl, $arSubs=false)
Определения catalog_cond.php:73
static CheckAtoms($arOneCondition, $arParams, $arControl, $boolShow)
Определения catalog_cond.php:1177
static GetControlID()
Определения catalog_cond.php:95
static LogicNotContain($arField, $mxValue)
Определения catalog_cond.php:2096
static GetLogicEx($arOperators=false, $arLabels=false)
Определения catalog_cond.php:247
static GetLogic($arOperators=false)
Определения catalog_cond.php:140
static GetShowIn($arControls)
Определения catalog_cond.php:100
static GetValueAtom($arValue)
Определения catalog_cond.php:287
static IsGroup($strControlID=false)
Определения catalog_cond.php:63
static Parse($arOneCondition)
Определения catalog_cond.php:68
static LogicLess($arField, $mxValue)
Определения catalog_cond.php:2006
static GetJSControl($arControl, $arParams=array())
Определения catalog_cond.php:126
static $arInitParams
Определения catalog_cond.php:30
static searchControl(array $controls, $controlId)
Определения catalog_cond.php:2264
static Check($arOneCondition, $arParams, $arControl, $boolShow)
Определения catalog_cond.php:350
static ValidateAtoms($arValues, $arParams, $arControl, $boolShow)
Определения catalog_cond.php:1546
static GetControls($strControlID=false)
Определения catalog_cond.php:111
static LogicEqualLess($arField, $mxValue)
Определения catalog_cond.php:2052
static OnBuildConditionAtomList()
Определения catalog_cond.php:131
static GetAtomsEx($strControlID=false, $boolEx=false)
Определения catalog_cond.php:121
static SearchLogic($strValue, $arLogic)
Определения catalog_cond.php:332
static GetControlShow($arParams)
Определения catalog_cond.php:53
static ConvertInt2DateTime(&$mxValues, $strFormat, $intOffset)
Определения catalog_cond.php:2153
static GetAtoms()
Определения catalog_cond.php:116
Generate($arConditions, $arParams)
Определения catalog_cond.php:4821
Parse($arData='', $arParams=false)
Определения catalog_cond.php:4563
$arValues
Определения component_props.php:25
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
global $DB
Определения cron_frame.php:29
MakeTimeStamp($datetime, $format=false)
Определения tools.php:538
$user
Определения mysql_to_pgsql.php:33
lang
Определения options.php:182
font style
Определения invoice.php:442
if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_CATALOG_EXPORT_EDIT)) if((!isset($_REQUEST['IBLOCK_ID']))||($_REQUEST['IBLOCK_ID']=='')) $intIBlockID
Определения yandex_detail.php:44
$iterator
Определения yandex_run.php:610