1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
virtualdocument.php
См. документацию.
1<?php
2
5
6if (!CModule::IncludeModule("iblock") || !class_exists("CIBlockDocument"))
7 return;
8
10{
11 public static function getEntityName()
12 {
13 return GetMessage('BPVDX_ENTITY_NAME');
14 }
15
16 public static function getDocumentTypeName($documentType)
17 {
18 if (mb_strpos($documentType, 'type_') !== 0)
19 return $documentType;
20
21 $id = (int)mb_substr($documentType, 5);
22
23 $iterator = CIBlock::GetList(false,array('ID' => $id));
24 $result = $iterator->fetch();
25 if (!$result)
26 return $documentType;
27
28 return $result['NAME'];
29 }
30
31 public static function getFieldInputControlOptions($documentType, &$arFieldType, $jsFunctionName, &$value)
32 {
33 $result = "";
34
35 static $arDocumentFieldTypes = array();
36 if (!array_key_exists($documentType, $arDocumentFieldTypes))
37 {
38 $arDocumentFieldTypes[$documentType] = self::GetDocumentFieldTypes($documentType);
39 }
40
41 if (!array_key_exists($arFieldType["Type"], $arDocumentFieldTypes[$documentType])
42 || !$arDocumentFieldTypes[$documentType][$arFieldType["Type"]]["Complex"])
43 {
44 return "";
45 }
46
47 if ($arFieldType["Type"] == "E:EList")
48 {
49 if (is_array($value))
50 {
51 reset($value);
52 $valueTmp = intval(current($value));
53 }
54 else
55 {
56 $valueTmp = intval($value);
57 }
58
59 $iblockId = 0;
60 if ($valueTmp > 0)
61 {
62 $dbResult = CIBlockElement::GetList(array(), array("ID" => $valueTmp), false, false, array("ID", "IBLOCK_ID"));
63 if ($arResult = $dbResult->Fetch())
64 $iblockId = $arResult["IBLOCK_ID"];
65 }
66 if ($iblockId <= 0 && intval($arFieldType["Options"]) > 0)
67 $iblockId = intval($arFieldType["Options"]);
68
69 $defaultIBlockId = 0;
70
71 $result .= '<select onchange="'.htmlspecialcharsbx($jsFunctionName).'(this.options[this.selectedIndex].value)">';
72 $arIBlockType = CIBlockParameters::GetIBlockTypes();
73 foreach ($arIBlockType as $iblockTypeId => $iblockTypeName)
74 {
75 $result .= '<optgroup label="'.$iblockTypeName.'">';
76
77 $dbIBlock = CIBlock::GetList(array("SORT" => "ASC"), array("TYPE" => $iblockTypeId, "ACTIVE" => "Y"));
78 while ($arIBlock = $dbIBlock->GetNext())
79 {
80 $result .= '<option value="'.$arIBlock["ID"].'"'.(($arIBlock["ID"] == $iblockId) ? " selected" : "").'>'.$arIBlock["NAME"].'</option>';
81 if (($defaultIBlockId <= 0) || ($arIBlock["ID"] == $iblockId))
82 $defaultIBlockId = $arIBlock["ID"];
83 }
84
85 $result .= '</optgroup>';
86 }
87 $result .= '</select><!--__defaultOptionsValue:'.$defaultIBlockId.'--><!--__modifyOptionsPromt:'.GetMessage("IBD_DOCUMENT_MOPROMT").'-->';
88
89 $arFieldType["Options"] = $defaultIBlockId;
90 }
91 elseif ($arFieldType["Type"] == "L")
92 {
93 $valueTmp = $arFieldType["Options"];
94 if (!is_array($valueTmp))
95 $valueTmp = array($valueTmp => $valueTmp);
96
97 $str = '';
98 foreach ($valueTmp as $k => $v)
99 {
100 if (is_array($v) && count($v) == 2)
101 {
102 $v1 = array_values($v);
103 $k = $v1[0];
104 $v = $v1[1];
105 }
106
107 if ($k != $v)
108 $str .= '['.$k.']'.$v;
109 else
110 $str .= $v;
111
112 $str .= "\n";
113 }
114 $result .= '<textarea id="WFSFormOptionsX" rows="5" cols="30">'.htmlspecialcharsbx($str).'</textarea><br />';
115 $result .= GetMessage("IBD_DOCUMENT_XFORMOPTIONS1").'<br />';
116 $result .= GetMessage("IBD_DOCUMENT_XFORMOPTIONS2").'<br />';
117 $result .= '<script>
118 function WFSFormOptionsXFunction()
119 {
120 var result = {};
121 var i, id, val, str = document.getElementById("WFSFormOptionsX").value;
122
123 var arr = str.split(/[\r\n]+/);
124 var p, re = /\[([^\]]+)\].+/;
125 for (i in arr)
126 {
127 str = arr[i].replace(/^\s+|\s+$/g, \'\');
128 if (str.length > 0)
129 {
130 id = str.match(re);
131 if (id)
132 {
133 p = str.indexOf(\']\');
134 id = id[1];
135 val = str.substr(p + 1);
136 }
137 else
138 {
139 val = str;
140 id = val;
141 }
142 result[id] = val;
143 }
144 }
145
146 return result;
147 }
148 </script>';
149 $result .= '<input type="button" onclick="'.htmlspecialcharsbx($jsFunctionName).'(WFSFormOptionsXFunction())" value="'.GetMessage("IBD_DOCUMENT_XFORMOPTIONS3").'">';
150 }
151
152 return $result;
153 }
154
155 public static function getFieldInputControl($documentType, $arFieldType, $arFieldName, $fieldValue, $bAllowSelection = false, $publicMode = false)
156 {
157 $v = mb_substr($documentType, mb_strlen("type_"));
158 if (intval($v)."!" != $v."!")
159 return "";
160 $iblockId = intval($v);
161
162 static $arDocumentFieldTypes = array();
163 if (!array_key_exists($documentType, $arDocumentFieldTypes))
164 $arDocumentFieldTypes[$documentType] = self::GetDocumentFieldTypes($documentType);
165
166 $arFieldType["BaseType"] = "string";
167 $arFieldType["Complex"] = false;
168 if (array_key_exists($arFieldType["Type"], $arDocumentFieldTypes[$documentType]))
169 {
170 $arFieldType["BaseType"] = $arDocumentFieldTypes[$documentType][$arFieldType["Type"]]["BaseType"];
171 $arFieldType["Complex"] = $arDocumentFieldTypes[$documentType][$arFieldType["Type"]]["Complex"];
172 }
173
174 if (!is_array($fieldValue) || is_array($fieldValue) && CBPHelper::IsAssociativeArray($fieldValue))
175 $fieldValue = array($fieldValue);
176
177 $customMethodName = "";
178 $customMethodNameMulty = "";
179 if (mb_strpos($arFieldType["Type"], ":") !== false)
180 {
181 $ar = CIBlockProperty::GetUserType(mb_substr($arFieldType["Type"], 2));
182 if (array_key_exists("GetPublicEditHTML", $ar))
183 $customMethodName = $ar["GetPublicEditHTML"];
184 if (array_key_exists("GetPublicEditHTMLMulty", $ar))
185 $customMethodNameMulty = $ar["GetPublicEditHTMLMulty"];
186 }
187
188 ob_start();
189
190 if ($arFieldType["Type"] == "L")
191 {
192 $fieldValueTmp = $fieldValue;
193 ?>
194 <select id="id_<?= htmlspecialcharsbx($arFieldName["Field"]) ?>" name="<?= htmlspecialcharsbx($arFieldName["Field"]).($arFieldType["Multiple"] ? "[]" : "") ?>"<?= ($arFieldType["Multiple"] ? ' size="5" multiple' : '') ?>>
195 <?
196 if (!$arFieldType["Required"])
197 echo '<option value="">['.GetMessage("BPVDX_NOT_SET").']</option>';
198 foreach ($arFieldType["Options"] as $k => $v)
199 {
200 if (is_array($v) && count($v) == 2)
201 {
202 $v1 = array_values($v);
203 $k = $v1[0];
204 $v = $v1[1];
205 }
206
207 $ind = array_search($k, $fieldValueTmp);
208 echo '<option value="'.htmlspecialcharsbx($k).'"'.($ind !== false ? ' selected' : '').'>'.htmlspecialcharsbx($v).'</option>';
209 if ($ind !== false)
210 unset($fieldValueTmp[$ind]);
211 }
212 ?>
213 </select>
214 <?
215 if ($bAllowSelection)
216 {
217 ?>
218 <br /><input type="text" id="id_<?= htmlspecialcharsbx($arFieldName["Field"]) ?>_text" name="<?= htmlspecialcharsbx($arFieldName["Field"]) ?>_text" value="<?
219 if (count($fieldValueTmp) > 0)
220 {
221 $a = array_values($fieldValueTmp);
222 echo htmlspecialcharsbx($a[0]);
223 }
224 ?>"><?
225 echo CBPHelper::renderControlSelectorButton('id_'.$arFieldName["Field"].'_text', 'select');
226 }
227 }
228 elseif ($arFieldType["Type"] == "S:UserID")
229 {
230 $fieldValue = CBPHelper::UsersArrayToString($fieldValue, null, array("bizproc", "CBPVirtualDocument", $documentType));
231 ?><input type="text" size="40" style="max-width: 85%" id="id_<?= $arFieldName["Field"] ?>" name="<?= $arFieldName["Field"] ?>" value="<?= htmlspecialcharsbx($fieldValue) ?>">
232 <? echo CBPHelper::renderControlSelectorButton('id_'.$arFieldName["Field"], 'user');
233 }
234 elseif ((mb_strpos($arFieldType["Type"], ":") !== false)
235 && $arFieldType["Multiple"]
236 && (
237 is_array($customMethodNameMulty) && count($customMethodNameMulty) > 0
238 || !is_array($customMethodNameMulty) && $customMethodNameMulty <> ''
239 )
240 )
241 {
242 if (!is_array($fieldValue))
243 $fieldValue = array();
244
245 if ($bAllowSelection)
246 {
247 $fieldValueTmp1 = array();
248 $fieldValueTmp2 = array();
249 foreach ($fieldValue as $v)
250 {
251 $vTrim = trim($v);
252 if (CBPActivity::isExpression($vTrim))
253 $fieldValueTmp1[] = $vTrim;
254 else
255 $fieldValueTmp2[] = $v;
256 }
257 }
258 else
259 {
260 $fieldValueTmp1 = array();
261 $fieldValueTmp2 = $fieldValue;
262 }
263
264 if (($arFieldType["Type"] == "S:employee") && COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y")
265 $fieldValueTmp2 = CBPHelper::StripUserPrefix($fieldValueTmp2);
266 if ($arFieldType["Type"] == "E:EList")
267 {
268 static $fl = true;
269 if ($fl)
270 {
271 $GLOBALS["APPLICATION"]->AddHeadScript('/bitrix/js/iblock/iblock_edit.js');
272 }
273
274 $fl = false;
275 }
276
277 $fieldValueTmp21 = array();
278 foreach ($fieldValueTmp2 as $k => $fld)
279 {
280 if ($fld === null || $fld === "")
281 continue;
282 if (is_array($fld) && isset($fld["VALUE"]))
283 $fieldValueTmp21[$k] = $fld;
284 else
285 $fieldValueTmp21[$k] = array("VALUE" => $fld);
286 }
287 $fieldValueTmp2 = $fieldValueTmp21;
288
289 echo call_user_func_array(
290 $customMethodNameMulty,
291 array(
292 array("LINK_IBLOCK_ID" => $arFieldType["Options"]),
293 $fieldValueTmp2,
294 array(
295 "FORM_NAME" => $arFieldName["Form"],
296 "VALUE" => htmlspecialcharsbx($arFieldName["Field"])
297 ),
298 true
299 )
300 );
301
302 if ($bAllowSelection)
303 {
304 ?>
305 <br /><input type="text" id="id_<?= htmlspecialcharsbx($arFieldName["Field"]) ?>_text" name="<?= htmlspecialcharsbx($arFieldName["Field"]) ?>_text" value="<?
306 if (count($fieldValueTmp1) > 0)
307 {
308 $a = array_values($fieldValueTmp1);
309 echo htmlspecialcharsbx($a[0]);
310 }
311 ?>"><?
312 echo CBPHelper::renderControlSelectorButton(
313 'id_'.$arFieldName["Field"].'_text',
314 $arFieldType["BaseType"],
315 array('mode' => $arFieldType["Type"] == 'S:employee'? 'employee' : '')
316 );
317 }
318 }
319 else
320 {
321 if (!array_key_exists("CBPVirtualDocumentCloneRowPrinted_".$documentType, $GLOBALS) && $arFieldType["Multiple"])
322 {
323 $GLOBALS["CBPVirtualDocumentCloneRowPrinted_".$documentType] = 1;
324 ?>
325 <script>
326 <!--
327 function CBPVirtualDocumentCloneRow(tableID)
328 {
329 var tbl = document.getElementById(tableID);
330 var cnt = tbl.rows.length;
331 var oRow = tbl.insertRow(cnt);
332 var oCell = oRow.insertCell(0);
333 var sHTML = tbl.rows[cnt - 1].cells[0].innerHTML;
334 var p = 0;
335 while (true)
336 {
337 var s = sHTML.indexOf('[n', p);
338 if (s < 0)
339 break;
340 var e = sHTML.indexOf(']', s);
341 if (e < 0)
342 break;
343 var n = parseInt(sHTML.substr(s + 2, e - s));
344 sHTML = sHTML.substr(0, s) + '[n' + (++n) + ']' + sHTML.substr(e + 1);
345 p = s + 1;
346 }
347 var p = 0;
348 while (true)
349 {
350 var s = sHTML.indexOf('__n', p);
351 if (s < 0)
352 break;
353 var e = sHTML.indexOf('_', s + 2);
354 if (e < 0)
355 break;
356 var n = parseInt(sHTML.substr(s + 3, e - s));
357 sHTML = sHTML.substr(0, s) + '__n' + (++n) + '_' + sHTML.substr(e + 1);
358 p = e + 1;
359 }
360 oCell.innerHTML = sHTML;
361 var patt = new RegExp('<' + 'script' + '>[^\000]*?<' + '\/' + 'script' + '>', 'ig');
362 var code = sHTML.match(patt);
363 if (code)
364 {
365 for (var i = 0; i < code.length; i++)
366 {
367 if (code[i] != '')
368 {
369 var s = code[i].substring(8, code[i].length - 9);
370 jsUtils.EvalGlobal(s);
371 }
372 }
373 }
374 }
375 //-->
376 </script>
377 <?
378 }
379
380 if ($arFieldType["Multiple"])
381 echo '<table width="100%" border="0" cellpadding="2" cellspacing="2" id="CBPVirtualDocument_'.$arFieldName["Field"].'_Table">';
382
383 $fieldValueTmp = $fieldValue;
384
385 if (sizeof($fieldValue) == 0)
386 $fieldValue[] = null;
387
388 $ind = -1;
389 foreach ($fieldValue as $key => $value)
390 {
391 $ind++;
392 $fieldNameId = 'id_'.htmlspecialcharsbx($arFieldName["Field"]).'__n'.$ind.'_';
393 $fieldNameName = htmlspecialcharsbx($arFieldName["Field"]).($arFieldType["Multiple"] ? "[n".$ind."]" : "");
394
395 if ($arFieldType["Multiple"])
396 echo '<tr><td>';
397
398 if (is_array($customMethodName) && count($customMethodName) > 0 || !is_array($customMethodName) && $customMethodName <> '')
399 {
400 $value1 = $value;
401 if ($bAllowSelection && CBPActivity::isExpression($value1))
402 $value1 = null;
403 else
404 unset($fieldValueTmp[$key]);
405
406 if (($arFieldType["Type"] == "S:employee") && COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y")
407 $value1 = CBPHelper::StripUserPrefix($value1);
408
409 echo call_user_func_array(
410 $customMethodName,
411 array(
412 array("LINK_IBLOCK_ID" => $arFieldType["Options"]),
413 array("VALUE" => $value1),
414 array(
415 "FORM_NAME" => $arFieldName["Form"],
416 "VALUE" => $fieldNameName
417 ),
418 true
419 )
420 );
421 }
422 else
423 {
424 switch ($arFieldType["Type"])
425 {
426 case "N":
427 unset($fieldValueTmp[$key]);
428 ?><input type="text" size="10" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>" value="<?= htmlspecialcharsbx($value) ?>"><?
429 break;
430 case "F":
431 if ($publicMode)
432 {
433 //unset($fieldValueTmp[$key]);
434 ?><input type="file" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>"><?
435 }
436 break;
437 case "B":
438 if (in_array($value, array("Y", "N")))
439 unset($fieldValueTmp[$key]);
440 ?>
441 <select id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>">
442 <?
443 if (!$arFieldType["Required"])
444 echo '<option value="">['.GetMessage("BPVDX_NOT_SET").']</option>';
445 ?>
446 <option value="Y"<?= (in_array("Y", $fieldValue) ? ' selected' : '') ?>><?= GetMessage("BPVDX_YES") ?></option>
447 <option value="N"<?= (in_array("N", $fieldValue) ? ' selected' : '') ?>><?= GetMessage("BPVDX_NO") ?></option>
448 </select>
449 <?
450 break;
451 case "T":
452 unset($fieldValueTmp[$key]);
453 ?><textarea rows="5" cols="40" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>"><?= htmlspecialcharsbx($value) ?></textarea><?
454 break;
455 default:
456 unset($fieldValueTmp[$key]);
457 ?><input type="text" size="40" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>" value="<?= htmlspecialcharsbx($value) ?>"><?
458 }
459 }
460
461 if ($bAllowSelection)
462 {
463 if (!in_array($arFieldType["Type"], array("F", "B")) && (is_array($customMethodName) && count($customMethodName) <= 0 || !is_array($customMethodName) && $customMethodName == ''))
464 {
465 echo CBPHelper::renderControlSelectorButton($fieldNameId, $arFieldType["BaseType"]);
466 }
467 }
468
469 if ($arFieldType["Multiple"])
470 echo '</td></tr>';
471 }
472
473 if ($arFieldType["Multiple"])
474 echo "</table>";
475
476 if ($arFieldType["Multiple"] && (($arFieldType["Type"] != "F") || $publicMode))
477 echo '<input type="button" value="'.GetMessage("BPVDX_ADD").'" onclick="CBPVirtualDocumentCloneRow(\'CBPVirtualDocument_'.htmlspecialcharsbx($arFieldName["Field"]).'_Table\')"/><br />';
478
479 if ($bAllowSelection)
480 {
481 if (in_array($arFieldType["Type"], array("F", "B")) || (is_array($customMethodName) && count($customMethodName) > 0 || !is_array($customMethodName) && $customMethodName <> ''))
482 {
483 ?>
484 <input type="text" id="id_<?= htmlspecialcharsbx($arFieldName["Field"]) ?>_text" name="<?= htmlspecialcharsbx($arFieldName["Field"]) ?>_text" value="<?
485 if (count($fieldValueTmp) > 0)
486 {
487 $a = array_values($fieldValueTmp);
488 echo htmlspecialcharsbx($a[0]);
489 }
490 ?>"><?
491 echo CBPHelper::renderControlSelectorButton(
492 'id_'.$arFieldName["Field"].'_text',
493 $arFieldType["BaseType"],
494 array('mode' => $arFieldType["Type"] == 'S:employee'? 'employee' : '')
495 );
496 }
497 }
498 }
499
500 $s = ob_get_contents();
501 ob_end_clean();
502
503 return $s;
504 }
505
506 public static function getFieldInputValue($documentType, $arFieldType, $arFieldName, $arRequest, &$arErrors)
507 {
508 $v = mb_substr($documentType, mb_strlen("type_"));
509 if (intval($v)."!" != $v."!")
510 return null;
511 $iblockId = intval($v);
512
513 $result = array();
514
515 if ($arFieldType["Type"] == "S:UserID")
516 {
517 $value = $arRequest[$arFieldName["Field"]];
518 if ($value <> '')
519 {
520 $arErrorsTmp1 = array();
521 $result = CBPHelper::UsersStringToArray($value, array("bizproc", "CBPVirtualDocument", $documentType), $arErrorsTmp1);
522 if (count($arErrorsTmp1) > 0)
523 {
524 foreach ($arErrorsTmp1 as $e)
525 $arErrors[] = $e;
526 }
527 }
528 }
529 elseif (array_key_exists($arFieldName["Field"], $arRequest) || array_key_exists($arFieldName["Field"]."_text", $arRequest))
530 {
531 $arValue = array();
532 if (array_key_exists($arFieldName["Field"], $arRequest))
533 {
534 $arValue = $arRequest[$arFieldName["Field"]];
535 if (!is_array($arValue) || is_array($arValue) && CBPHelper::IsAssociativeArray($arValue))
536 $arValue = array($arValue);
537 }
538 if (array_key_exists($arFieldName["Field"]."_text", $arRequest))
539 $arValue[] = $arRequest[$arFieldName["Field"]."_text"];
540
541 foreach ($arValue as $value)
542 {
543 if (is_array($value)
544 || !is_array($value) && !CBPActivity::isExpression($value))
545 {
546 if ($arFieldType["Type"] == "N")
547 {
548 if ($value <> '')
549 {
550 $value = str_replace(" ", "", str_replace(",", ".", $value));
551 if (is_numeric($value))
552 {
553 $value = doubleval($value);
554 }
555 else
556 {
557 $value = null;
558 $arErrors[] = array(
559 "code" => "ErrorValue",
560 "message" => GetMessage("BPCGWTL_INVALID1N"),
561 "parameter" => $arFieldName["Field"],
562 );
563 }
564 }
565 else
566 {
567 $value = null;
568 }
569 }
570 elseif ($arFieldType["Type"] == "L")
571 {
572 if (!is_array($arFieldType["Options"]) || count($arFieldType["Options"]) <= 0 || $value == '')
573 {
574 $value = null;
575 }
576 else
577 {
578 $ar = array_values($arFieldType["Options"]);
579 if (is_array($ar[0]))
580 {
581 $b = false;
582 foreach ($ar as $a)
583 {
584 if ($a[0] == $value)
585 {
586 $b = true;
587 break;
588 }
589 }
590 if (!$b)
591 {
592 $value = null;
593 $arErrors[] = array(
594 "code" => "ErrorValue",
595 "message" => GetMessage("BPCGWTL_INVALID3N"),
596 "parameter" => $arFieldName["Field"],
597 );
598 }
599 }
600 else
601 {
602 if (!array_key_exists($value, $arFieldType["Options"]))
603 {
604 $value = null;
605 $arErrors[] = array(
606 "code" => "ErrorValue",
607 "message" => GetMessage("BPCGWTL_INVALID3N"),
608 "parameter" => $arFieldName["Field"],
609 );
610 }
611 }
612 }
613 }
614 elseif ($arFieldType["Type"] == "B")
615 {
616 if ($value !== "Y" && $value !== "N")
617 {
618 if ($value === true)
619 {
620 $value = "Y";
621 }
622 elseif ($value === false)
623 {
624 $value = "N";
625 }
626 elseif ($value <> '')
627 {
628 $value = mb_strtolower($value);
629 if (in_array($value, array("y", "yes", "true", "1")))
630 {
631 $value = "Y";
632 }
633 elseif (in_array($value, array("n", "no", "false", "0")))
634 {
635 $value = "N";
636 }
637 else
638 {
639 $value = null;
640 $arErrors[] = array(
641 "code" => "ErrorValue",
642 "message" => GetMessage("BPCGWTL_INVALID4N"),
643 "parameter" => $arFieldName["Field"],
644 );
645 }
646 }
647 else
648 {
649 $value = null;
650 }
651 }
652 }
653 elseif ($arFieldType["Type"] == "F")
654 {
655 if (array_key_exists("name", $value) && $value["name"] <> '')
656 {
657 if (!array_key_exists("MODULE_ID", $value))
658 $value["MODULE_ID"] = "bizproc";
659
660 $value = CFile::SaveFile($value, "bizproc_wf");
661 if (!$value)
662 {
663 $value = null;
664 $arErrors[] = array(
665 "code" => "ErrorValue",
666 "message" => GetMessage("BPCGWTL_INVALID9N"),
667 "parameter" => $arFieldName["Field"],
668 );
669 }
670 }
671 else
672 {
673 $value = null;
674 }
675 }
676 elseif (mb_strpos($arFieldType["Type"], ":") !== false)
677 {
678 $arCustomType = CIBlockProperty::GetUserType(mb_substr($arFieldType["Type"], 2));
679 if (array_key_exists("GetLength", $arCustomType))
680 {
681 if (call_user_func_array(
682 $arCustomType["GetLength"],
683 array(
684 array("LINK_IBLOCK_ID" => $arFieldType["Options"]),
685 array("VALUE" => $value)
686 )
687 ) <= 0)
688 {
689 $value = null;
690 }
691 }
692 else
693 {
694 if (!is_array($value) && ($value == '') || is_array($value) && (count($value) == 0 || count($value) == 1 && isset($value["VALUE"]) && !is_array($value["VALUE"]) && $value["VALUE"] == ''))
695 $value = null;
696 }
697
698 if (($value !== null) && array_key_exists("CheckFields", $arCustomType))
699 {
700 $arErrorsTmp1 = call_user_func_array(
701 $arCustomType["CheckFields"],
702 array(
703 array("LINK_IBLOCK_ID" => $arFieldType["Options"]),
704 array("VALUE" => $value)
705 )
706 );
707 if (count($arErrorsTmp1) > 0)
708 {
709 $value = null;
710 foreach ($arErrorsTmp1 as $e)
711 $arErrors[] = array(
712 "code" => "ErrorValue",
713 "message" => $e,
714 "parameter" => $arFieldName["Field"],
715 );
716 }
717 }
718
719 if (($value !== null)
720 && ($arFieldType["Type"] == "S:employee")
721 && COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y")
722 {
723 $value = "user_".$value;
724 }
725 }
726 else
727 {
728 if (!is_array($value) && $value == '')
729 $value = null;
730 }
731 }
732
733 if ($value !== null)
734 $result[] = $value;
735 }
736 }
737
738 if (!$arFieldType["Multiple"])
739 {
740 if (count($result) > 0)
741 $result = $result[0];
742 else
743 $result = null;
744 }
745
746 return $result;
747 }
748
749 public static function getFieldInputValuePrintable($documentType, $arFieldType, $fieldValue)
750 {
751 $result = $fieldValue;
752
753 switch ($arFieldType['Type'])
754 {
755 case "S:UserID":
756 if (!is_array($fieldValue))
757 $fieldValue = array($fieldValue);
758
759 $result = CBPHelper::UsersArrayToString($fieldValue, null, array("bizproc", "CBPVirtualDocument", $documentType));
760 break;
761
762 case "B":
763 if (is_array($fieldValue))
764 {
765 $result = array();
766 foreach ($fieldValue as $r)
767 $result[] = ((mb_strtoupper($r) != "N" && !empty($r)) ? GetMessage("BPVDX_YES") : GetMessage("BPVDX_NO"));
768 }
769 else
770 {
771 $result = ((mb_strtoupper($fieldValue) != "N" && !empty($fieldValue)) ? GetMessage("BPVDX_YES") : GetMessage("BPVDX_NO"));
772 }
773 break;
774
775 case "F":
776 if (is_array($fieldValue))
777 {
778 $result = array();
779 foreach ($fieldValue as $r)
780 {
781 $r = intval($r);
782 $dbImg = CFile::GetByID($r);
783 if ($arImg = $dbImg->Fetch())
784 $result[] = "[url=/bitrix/tools/bizproc_show_file.php?f=".urlencode($arImg["FILE_NAME"])."&i=".$r."]".htmlspecialcharsbx($arImg["ORIGINAL_NAME"])."[/url]";
785 }
786 }
787 else
788 {
789 $fieldValue = intval($fieldValue);
790 $dbImg = CFile::GetByID($fieldValue);
791 if ($arImg = $dbImg->Fetch())
792 $result = "[url=/bitrix/tools/bizproc_show_file.php?f=".urlencode($arImg["FILE_NAME"])."&i=".$fieldValue."]".htmlspecialcharsbx($arImg["ORIGINAL_NAME"])."[/url]";
793 }
794 break;
795 case "L":
796 if (is_array($arFieldType["Options"]))
797 {
798 if (is_array($fieldValue))
799 {
800 $result = array();
801 foreach ($fieldValue as $r)
802 {
803 if (array_key_exists($r, $arFieldType["Options"]))
804 $result[] = $arFieldType["Options"][$r];
805 }
806 }
807 else
808 {
809 if (array_key_exists($fieldValue, $arFieldType["Options"]))
810 $result = $arFieldType["Options"][$fieldValue];
811 }
812 }
813 break;
814 }
815
816 if (mb_strpos($arFieldType['Type'], ":") !== false)
817 {
818 if ($arFieldType["Type"] == "S:employee")
819 $fieldValue = CBPHelper::StripUserPrefix($fieldValue);
820
821 $arCustomType = CIBlockProperty::GetUserType(mb_substr($arFieldType['Type'], 2));
822 if (array_key_exists("GetPublicViewHTML", $arCustomType))
823 {
824 if (is_array($fieldValue) && !CBPHelper::IsAssociativeArray($fieldValue))
825 {
826 $checkValue = $arCustomType["GetPublicViewHTML"][0] == "CIBlockPropertyElementList";
827 $result = array();
828 foreach ($fieldValue as $value)
829 {
830 $v = $checkValue && isset($value['VALUE']) ? $value : array('VALUE' => $value);
831 $r = call_user_func_array(
832 $arCustomType["GetPublicViewHTML"],
833 array(
834 array("LINK_IBLOCK_ID" => $arFieldType["Options"]),
835 $v,
836 ""
837 )
838 );
839
840 $result[] = HTMLToTxt($r);
841 }
842 }
843 else
844 {
845 $result = call_user_func_array(
846 $arCustomType["GetPublicViewHTML"],
847 array(
848 array("LINK_IBLOCK_ID" => $arFieldType["Options"]),
849 array("VALUE" => $fieldValue),
850 ""
851 )
852 );
853
855 }
856 }
857 }
858
859 return $result;
860 }
861
862 public static function canUserOperateDocument($operation, $userId, $documentId, $arParameters = array())
863 {
864 $documentId = trim($documentId);
865 if ($documentId == '')
866 return false;
867
868 $userId = intval($userId);
869
870 if (array_key_exists("UserIsAdmin", $arParameters))
871 {
872 if ($arParameters["UserIsAdmin"] === true)
873 return true;
874 }
875 else
876 {
877 $arGroups = CUser::GetUserGroup($userId);
878 if (in_array(1, $arGroups))
879 return true;
880 }
881
882 if (!array_key_exists("TargetUser", $arParameters) || !array_key_exists("DocumentType", $arParameters))
883 {
884 $dbElementList = CIBlockElement::GetList(
885 array(),
886 array("ID" => $documentId, "SHOW_NEW" => "Y"),
887 false,
888 false,
889 array("ID", "IBLOCK_ID", "CREATED_BY")
890 );
891 $arElement = $dbElementList->Fetch();
892
893 if (!$arElement)
894 return false;
895
896 $arParameters["TargetUser"] = $arElement["CREATED_BY"];
897 $arParameters["DocumentType"] = "type_".$arElement["IBLOCK_ID"];
898 }
899
900 if (!array_key_exists("AllUserGroups", $arParameters))
901 {
902 if (!array_key_exists("UserGroups", $arParameters))
903 $arParameters["UserGroups"] = CUser::GetUserGroup($userId);
904
905 $arParameters["AllUserGroups"] = $arParameters["UserGroups"];
906 if ($userId == $arParameters["TargetUser"])
907 $arParameters["AllUserGroups"][] = "author";
908 }
909
910 if (!array_key_exists("DocumentStates", $arParameters))
911 {
912 $arParameters["DocumentStates"] = CBPDocument::GetDocumentStates(
913 array("bizproc", "CBPVirtualDocument", $arParameters["DocumentType"]),
914 array("bizproc", "CBPVirtualDocument", $documentId)
915 );
916 }
917
918 if (array_key_exists("WorkflowId", $arParameters))
919 {
920 if (array_key_exists($arParameters["WorkflowId"], $arParameters["DocumentStates"]))
921 $arParameters["DocumentStates"] = array($arParameters["WorkflowId"] => $arParameters["DocumentStates"][$arParameters["WorkflowId"]]);
922 else
923 return false;
924 }
925
926 $arAllowableOperations = CBPDocument::GetAllowableOperations(
927 $userId,
928 $arParameters["AllUserGroups"],
929 $arParameters["DocumentStates"]
930 );
931
932 // $arAllowableOperations == null - workflow is not a statemachine
933 // $arAllowableOperations == array() - no allowable operations
934 // $arAllowableOperations == array("read", ...) - allowable operations list
935 if (!is_array($arAllowableOperations))
936 return in_array("author", $arParameters["AllUserGroups"]);
937
938 $r = false;
939 switch ($operation)
940 {
941 case 0: // DOCUMENT_OPERATION_VIEW_WORKFLOW
942 $r = in_array("read", $arAllowableOperations);
943 break;
944 case 1: // DOCUMENT_OPERATION_START_WORKFLOW
945 $r = in_array("create", $arAllowableOperations);
946 break;
947 case 4: // DOCUMENT_OPERATION_CREATE_WORKFLOW
948 $r = false;
949 break;
950 case 2: // DOCUMENT_OPERATION_WRITE_DOCUMENT
951 $r = in_array("create", $arAllowableOperations);
952 break;
953 case 3: // DOCUMENT_OPERATION_READ_DOCUMENT
954 $r = in_array("read", $arAllowableOperations);
955 break;
956 default:
957 $r = false;
958 }
959
960 return $r;
961 }
962
963 public static function canUserOperateDocumentType($operation, $userId, $documentType, $arParameters = array())
964 {
965 $documentType = trim($documentType);
966 if ($documentType == '')
967 return false;
968
969 $userId = intval($userId);
970
971 if (array_key_exists("UserIsAdmin", $arParameters))
972 {
973 if ($arParameters["UserIsAdmin"] === true)
974 return true;
975 }
976 else
977 {
978 $arGroups = CUser::GetUserGroup($userId);
979 if (in_array(1, $arGroups))
980 return true;
981 }
982
983 if (!array_key_exists("AllUserGroups", $arParameters))
984 {
985 if (!array_key_exists("UserGroups", $arParameters))
986 $arParameters["UserGroups"] = CUser::GetUserGroup($userId);
987
988 $arParameters["AllUserGroups"] = $arParameters["UserGroups"];
989 $arParameters["AllUserGroups"][] = "author";
990 }
991
992 if (!array_key_exists("DocumentStates", $arParameters))
993 {
994 $arParameters["DocumentStates"] = CBPDocument::GetDocumentStates(
995 array("bizproc", "CBPVirtualDocument", $documentType),
996 null
997 );
998 }
999
1000 if (array_key_exists("WorkflowId", $arParameters))
1001 {
1002 if (array_key_exists($arParameters["WorkflowId"], $arParameters["DocumentStates"]))
1003 $arParameters["DocumentStates"] = array($arParameters["WorkflowId"] => $arParameters["DocumentStates"][$arParameters["WorkflowId"]]);
1004 else
1005 return false;
1006 }
1007
1008 $arAllowableOperations = CBPDocument::GetAllowableOperations(
1009 $userId,
1010 $arParameters["AllUserGroups"],
1011 $arParameters["DocumentStates"]
1012 );
1013
1014 // $arAllowableOperations == null - workflow is not a statemachine
1015 // $arAllowableOperations == array() - no allowable operations
1016 // $arAllowableOperations == array("read", ...) - allowable operations list
1017 if (!is_array($arAllowableOperations) && $operation != 4)
1018 return true;
1019
1020 if ($operation == 4)
1021 return true;
1022
1023 $r = false;
1024 switch ($operation)
1025 {
1026 case 0: // DOCUMENT_OPERATION_VIEW_WORKFLOW
1027 $r = false;
1028 break;
1029 case 1: // DOCUMENT_OPERATION_START_WORKFLOW
1030 $r = in_array("create", $arAllowableOperations);
1031 break;
1032 case 4: // DOCUMENT_OPERATION_CREATE_WORKFLOW
1033 $r = false;
1034 break;
1035 case 2: // DOCUMENT_OPERATION_WRITE_DOCUMENT
1036 $r = in_array("create", $arAllowableOperations);
1037 break;
1038 case 3: // DOCUMENT_OPERATION_READ_DOCUMENT
1039 $r = false;
1040 break;
1041 default:
1042 $r = false;
1043 }
1044
1045 return $r;
1046 }
1047
1048 public static function getList($arOrder = array("SORT" => "ASC"), $arFilter = array(), $arGroupBy = false, $arNavStartParams = false, $arSelectFields=array())
1049 {
1050 $arFilter["SHOW_NEW"] = "Y";
1051 $arFilter["ACTIVE"] = "Y";
1052
1053 if (count($arSelectFields) > 0)
1054 {
1055 if (!in_array("ID", $arSelectFields))
1056 $arSelectFields[] = "ID";
1057 if (!in_array("IBLOCK_ID", $arSelectFields))
1058 $arSelectFields[] = "IBLOCK_ID";
1059 if (!in_array("CREATED_BY", $arSelectFields))
1060 $arSelectFields[] = "CREATED_BY";
1061 }
1062
1063 $arResultList = array();
1064
1065 $arIDMap = array();
1066
1067 $dbTasksList = CIBlockElement::GetList(
1068 $arOrder,
1069 $arFilter,
1070 $arGroupBy,
1071 $arNavStartParams,
1072 $arSelectFields
1073 );
1074 while ($obTask = $dbTasksList->GetNextElement())
1075 {
1076 $arResult = array();
1077
1078 $arFields = $obTask->GetFields();
1079 foreach ($arFields as $fieldKey => $fieldValue)
1080 {
1081 if (mb_substr($fieldKey, 0, 1) != "~")
1082 continue;
1083 $fieldKey = mb_substr($fieldKey, 1);
1084
1085 $arResult[$fieldKey] = $fieldValue;
1086 $arResult[$fieldKey."_PRINTABLE"] = $fieldValue;
1087
1088 if (in_array($fieldKey, array("MODIFIED_BY", "CREATED_BY")))
1089 {
1090 $arResult[$fieldKey] = "user_".$fieldValue;
1091 $arResult[$fieldKey."_PRINTABLE"] = self::PrepareUserForPrint($fieldValue);
1092 }
1093 }
1094
1095 $arProperties = $obTask->GetProperties();
1096 foreach ($arProperties as $propertyKey => $propertyValue)
1097 {
1098 $arResult["PROPERTY_".$propertyKey] = $propertyValue["~VALUE"];
1099 $arResult["PROPERTY_".$propertyKey."_PRINTABLE"] = $propertyValue["~VALUE"];
1100
1101 if ($propertyValue["USER_TYPE"] <> '')
1102 {
1103 if ($propertyValue["USER_TYPE"] == "UserID")
1104 {
1105 if (is_array($propertyValue["VALUE"]))
1106 {
1107 $arResult["PROPERTY_".$propertyKey] = array();
1108 foreach ($propertyValue["VALUE"] as $v)
1109 {
1110 $v = intval($v);
1111 if ($v > 0)
1112 $arResult["PROPERTY_".$propertyKey][] = "user_".$v;
1113 }
1114 }
1115 else
1116 {
1117 $arResult["PROPERTY_".$propertyKey] = "";
1118 if (intval($propertyValue["VALUE"]) > 0)
1119 $arResult["PROPERTY_".$propertyKey] = "user_".intval($propertyValue["VALUE"]);
1120 }
1121 $arResult["PROPERTY_".$propertyKey."_PRINTABLE"] = self::PrepareUserForPrint($propertyValue["VALUE"]);
1122 }
1123 }
1124 elseif ($propertyValue["PROPERTY_TYPE"] == "G")
1125 {
1126 $arResult["PROPERTY_".$propertyKey."_PRINTABLE"] = array();
1127 $vx = self::PrepareSectionForPrint($propertyValue["VALUE"], $propertyValue["LINK_IBLOCK_ID"]);
1128 foreach ($vx as $vx1 => $vx2)
1129 $arResult["PROPERTY_".$propertyKey."_PRINTABLE"][$vx1] = $vx2["NAME"];
1130 }
1131 elseif ($propertyValue["PROPERTY_TYPE"] == "L")
1132 {
1133 $arResult["PROPERTY_".$propertyKey] = array();
1134
1135 $arPropertyValue = $propertyValue["VALUE"];
1136 $arPropertyKey = $propertyValue["VALUE_ENUM_ID"];
1137 if (!is_array($arPropertyValue))
1138 {
1139 $arPropertyValue = array($arPropertyValue);
1140 $arPropertyKey = array($arPropertyKey);
1141 }
1142
1143 for ($i = 0, $cnt = count($arPropertyValue); $i < $cnt; $i++)
1144 $arResult["PROPERTY_".$propertyKey][$arPropertyKey[$i]] = $arPropertyValue[$i];
1145
1146 $arResult["PROPERTY_".$propertyKey."_PRINTABLE"] = $arResult["PROPERTY_".$propertyKey];
1147 }
1148 }
1149
1150 if (array_key_exists($arFields["ID"], $arIDMap))
1151 {
1152 foreach ($arResultList[$arIDMap[$arFields["ID"]]] as $key => &$value)
1153 {
1154 if ($value != $arResult[$key])
1155 {
1156 if (!is_array($value))
1157 $value = array($value);
1158 $value[] = $arResult[$key];
1159 }
1160 }
1161 }
1162 else
1163 {
1164 $index = count($arResultList);
1165 $arResultList[$index] = $arResult;
1166 $arIDMap[$arFields["ID"]] = $index;
1167 }
1168 }
1169
1170 $dbTasksList1 = new CDBResult();
1171 $dbTasksList1->InitFromArray($arResultList);
1172
1173 return array($dbTasksList1, $dbTasksList);
1174 }
1175
1176 private static function prepareUserForPrint($value)
1177 {
1178 $arReturn = array();
1179
1180 $valueTmp = $value;
1181 if (!is_array($valueTmp))
1182 $valueTmp = array($valueTmp);
1183
1184 if (empty($nameTemplate))
1185 $nameTemplate = COption::GetOptionString("bizproc", "name_template", CSite::GetNameFormat(false), SITE_ID);
1186
1187 foreach ($valueTmp as $val)
1188 {
1189 $dbUser = CUser::GetByID($val);
1190 if ($arUser = $dbUser->fetch())
1191 {
1192 $formatName = CUser::FormatName($nameTemplate, $arUser, true, false);
1193 $arReturn[] = $formatName." <".$arUser["EMAIL"]."> [".$arUser["ID"]."]";
1194 }
1195 }
1196
1197 return (is_array($value) ? $arReturn : ((count($arReturn) > 0) ? $arReturn[0] : ""));
1198 }
1199
1200 private static function prepareSectionForPrint($value, $iblockId = 0)
1201 {
1202 if ($iblockId <= 0)
1203 {
1204 $iblockId = COption::GetOptionInt("intranet", "iblock_tasks", 0);
1205 }
1206 if ($iblockId <= 0)
1207 {
1208 return false;
1209 }
1210
1211 $arReturn = [];
1212 $valueTmp = $value;
1213 if (!is_array($valueTmp))
1214 {
1215 $valueTmp = [$valueTmp];
1216 }
1217
1218 foreach ($valueTmp as $val)
1219 {
1220 $ar = [];
1221 $dbSectionsList = CIBlockSection::GetNavChain(
1222 $iblockId,
1223 $val,
1224 ['ID', 'NAME', 'XML_ID'],
1225 );
1226
1227 while ($arSection = $dbSectionsList->fetch())
1228 {
1229 $ar[$arSection["ID"]] = ["NAME" => $arSection["NAME"], "XML_ID" => $arSection["XML_ID"]];
1230 }
1231
1232 $arReturn[] = $ar;
1233 }
1234
1235 return (is_array($value) ? $arReturn : ($arReturn[0] ?? []));
1236 }
1237
1242 public static function getDocumentAdminPage($documentId)
1243 {
1244 return null;
1245
1246 $documentId = intval($documentId);
1247 if ($documentId <= 0)
1248 throw new CBPArgumentNullException("documentId");
1249
1250 $db = CIBlockElement::GetList(
1251 array(),
1252 array("ID" => $documentId, "SHOW_NEW"=>"Y"),
1253 false,
1254 false,
1255 array("ID", "IBLOCK_ID", "IBLOCK_TYPE_ID")
1256 );
1257 if ($ar = $db->Fetch())
1258 return "/bitrix/admin/iblock_element_edit.php?view=Y&ID=".$documentId."&IBLOCK_ID=".$ar["IBLOCK_ID"]."&type=".$ar["IBLOCK_TYPE_ID"];
1259
1260 return null;
1261 }
1262
1263 public static function getDocument($documentId)
1264 {
1265 $args = func_get_args();
1266 $select = $args[2] ?? [];
1267 $documentId = (int)$documentId;
1268 if ($documentId <= 0)
1269 {
1270 throw new CBPArgumentNullException('documentId');
1271 }
1272
1273 $arResult = null;
1274 if (!empty($select))
1275 {
1276 $select = array_filter($select, fn($field) => !str_starts_with($field, 'PROPERTY_'));
1277 $select = array_merge(['ID', 'IBLOCK_ID'], $select);
1278
1279 if (in_array('CREATED_BY', $select) && !in_array('CREATED_USER_NAME', $select))
1280 {
1281 $select[] = 'CREATED_USER_NAME';
1282 }
1283 if (in_array('MODIFIED_BY', $select) && !in_array('USER_NAME', $select))
1284 {
1285 $select[] = 'USER_NAME';
1286 }
1287 }
1288
1289 $userNameFields = [
1290 'CREATED_BY_PRINTABLE' => 'CREATED_USER_NAME',
1291 'MODIFIED_BY_PRINTABLE' => 'USER_NAME',
1292 ];
1293
1294 $select = array_map(static fn($selectField) => $userNameFields[$selectField] ?? $selectField, $select);
1295
1296 $iterator = CIBlockElement::GetList(
1297 [],
1298 ['ID' => $documentId, 'SHOW_NEW' => 'Y'],
1299 arSelectFields: $select,
1300 );
1301 if ($objDocument = $iterator->GetNextElement(false, true))
1302 {
1303 $arDocumentFields = $objDocument->GetFields();
1304 $arDocumentProperties = $objDocument->GetProperties();
1305
1306 foreach ($arDocumentFields as $fieldKey => $fieldValue)
1307 {
1308 if (mb_substr($fieldKey, 0, 1) == "~")
1309 continue;
1310
1311 $arResult[$fieldKey] = $fieldValue;
1312 if (in_array($fieldKey, array("MODIFIED_BY", "CREATED_BY")))
1313 {
1314 $arResult[$fieldKey] = "user_".$fieldValue;
1315 $arResult[$fieldKey."_PRINTABLE"] = $arDocumentFields[($fieldKey == "MODIFIED_BY") ? "~USER_NAME" : "~CREATED_USER_NAME"];
1316 }
1317 elseif (in_array($fieldKey, array("PREVIEW_TEXT", "DETAIL_TEXT")))
1318 {
1319 if ($arDocumentFields[$fieldKey."_TYPE"] == "html")
1320 $arResult[$fieldKey] = HTMLToTxt($arDocumentFields["~".$fieldKey]);
1321 }
1322 }
1323
1324 foreach ($arDocumentProperties as $propertyKey => $propertyValue)
1325 {
1326 if ($propertyValue["USER_TYPE"] <> '')
1327 {
1328 if ($propertyValue["USER_TYPE"] == "UserID"
1329 || $propertyValue["USER_TYPE"] == "employee" && (COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y"))
1330 {
1331 if (!is_array($propertyValue["VALUE"]))
1332 {
1333 $db = CUser::GetByID($propertyValue["VALUE"]);
1334 if ($ar = $db->fetch())
1335 {
1336 $arResult["PROPERTY_".$propertyKey] = "user_".intval($propertyValue["VALUE"]);
1337 $arResult["PROPERTY_".$propertyKey."_PRINTABLE"] = "(".$ar["LOGIN"].")".(($ar["NAME"] <> '' || $ar["LAST_NAME"] <> '') ? " " : "").CUser::FormatName(COption::GetOptionString("bizproc", "name_template", CSite::GetNameFormat(false), SITE_ID), $ar, false, false);
1338 }
1339 }
1340 else
1341 {
1342 for ($i = 0, $cnt = count($propertyValue["VALUE"]); $i < $cnt; $i++)
1343 {
1344 $db = CUser::GetByID($propertyValue["VALUE"][$i]);
1345 if ($ar = $db->fetch())
1346 {
1347 $arResult["PROPERTY_".$propertyKey][] = "user_".intval($propertyValue["VALUE"][$i]);
1348 $arResult["PROPERTY_".$propertyKey."_PRINTABLE"][$propertyValue["VALUE"][$i]] = "(".$ar["LOGIN"].")".(($ar["NAME"] <> '' || $ar["LAST_NAME"] <> '') ? " " : "").CUser::FormatName(COption::GetOptionString("bizproc", "name_template", CSite::GetNameFormat(false), SITE_ID), $ar, false, false);
1349 }
1350 }
1351 }
1352 }
1353 else
1354 {
1355 $arResult["PROPERTY_".$propertyKey] = $propertyValue["VALUE"];
1356 }
1357 }
1358 elseif ($propertyValue["PROPERTY_TYPE"] == "L")
1359 {
1360 $arPropertyValue = $propertyValue["VALUE"];
1361 $arPropertyKey = $propertyValue["VALUE_XML_ID"];
1362 if (!is_array($arPropertyValue))
1363 {
1364 $arPropertyValue = array($arPropertyValue);
1365 $arPropertyKey = array($arPropertyKey);
1366 }
1367
1368 for ($i = 0, $cnt = count($arPropertyValue); $i < $cnt; $i++)
1369 $arResult["PROPERTY_".$propertyKey][$arPropertyKey[$i]] = $arPropertyValue[$i];
1370 }
1371 elseif ($propertyValue["PROPERTY_TYPE"] == "F")
1372 {
1373 if (!is_array($propertyValue["VALUE"]))
1374 {
1375 if ((intval($propertyValue["VALUE"]) > 0) && ($ar = CFile::GetFileArray($propertyValue["VALUE"])))
1376 {
1377 $arResult["PROPERTY_".$propertyKey] = $propertyValue["VALUE"];
1378 $arResult["PROPERTY_".$propertyKey."_PRINTABLE"] = $ar["SRC"];
1379 }
1380 }
1381 else
1382 {
1383 for ($i = 0, $cnt = count($propertyValue["VALUE"]); $i < $cnt; $i++)
1384 {
1385 if ((intval($propertyValue["VALUE"][$i]) > 0) && ($ar = CFile::GetFileArray($propertyValue["VALUE"][$i])))
1386 {
1387 $arResult["PROPERTY_".$propertyKey][] = $propertyValue["VALUE"][$i];
1388 $arResult["PROPERTY_".$propertyKey."_PRINTABLE"][$propertyValue["VALUE"][$i]] = $ar["SRC"];
1389 }
1390 }
1391 }
1392 }
1393 else
1394 {
1395 $arResult["PROPERTY_".$propertyKey] = $propertyValue["VALUE"];
1396 }
1397 }
1398 }
1399
1400 return $arResult;
1401 }
1402
1403 public static function getDocumentType($documentId)
1404 {
1405 if (mb_substr($documentId, 0, mb_strlen("type_")) == "type_")
1406 return $documentId;
1407
1408 $documentId = intval($documentId);
1409 if ($documentId <= 0)
1410 throw new CBPArgumentNullException("documentId");
1411
1412 $dbResult = CIBlockElement::GetList(array(), array("ID" => $documentId, "SHOW_NEW" => "Y"), false, false, array("ID", "IBLOCK_ID"));
1413 $arResult = $dbResult->Fetch();
1414 if (!$arResult)
1415 throw new Exception("Element is not found");
1416
1417 return "type_".$arResult["IBLOCK_ID"];
1418 }
1419
1420 public static function getDocumentFields($documentType)
1421 {
1422 $v = mb_substr($documentType, mb_strlen("type_"));
1423 if (intval($v)."!" != $v."!")
1424 throw new CBPArgumentOutOfRangeException("documentType", $documentType);
1425 $iblockId = intval($v);
1426
1427 $arDocumentFieldTypes = self::GetDocumentFieldTypes($documentType);
1428
1429 $arResult = array(
1430 "ID" => array(
1431 "Name" => GetMessage("BPVDX_FIELD_ID"),
1432 "Type" => "N",
1433 "Filterable" => true,
1434 "Editable" => false,
1435 "Required" => false,
1436 ),
1437 "TIMESTAMP_X" => array(
1438 "Name" => GetMessage("BPVDX_FIELD_TIMESTAMP_X"),
1439 "Type" => "S:DateTime",
1440 "Filterable" => true,
1441 "Editable" => true,
1442 "Required" => false,
1443 ),
1444 "MODIFIED_BY" => array(
1445 "Name" => GetMessage("BPVDX_FIELD_MODYFIED"),
1446 "Type" => "S:UserID",
1447 "Filterable" => true,
1448 "Editable" => true,
1449 "Required" => false,
1450 ),
1451 "MODIFIED_BY_PRINTABLE" => array(
1452 "Name" => GetMessage("BPVDX_FIELD_MODIFIED_BY_USER_PRINTABLE"),
1453 "Type" => "S",
1454 "Filterable" => false,
1455 "Editable" => false,
1456 "Required" => false,
1457 ),
1458 "DATE_CREATE" => array(
1459 "Name" => GetMessage("BPVDX_FIELD_DATE_CREATE"),
1460 "Type" => "S:DateTime",
1461 "Filterable" => true,
1462 "Editable" => true,
1463 "Required" => false,
1464 ),
1465 "CREATED_BY" => array(
1466 "Name" => GetMessage("BPVDX_FIELD_CREATED"),
1467 "Type" => "S:UserID",
1468 "Filterable" => true,
1469 "Editable" => false,
1470 "Required" => false,
1471 ),
1472 "CREATED_BY_PRINTABLE" => array(
1473 "Name" => GetMessage("BPVDX_FIELD_CREATED_BY_USER_PRINTABLE"),
1474 "Type" => "S",
1475 "Filterable" => false,
1476 "Editable" => false,
1477 "Required" => false,
1478 ),
1479 "IBLOCK_ID" => array(
1480 "Name" => GetMessage("BPVDX_FIELD_IBLOCK_ID"),
1481 "Type" => "N",
1482 "Filterable" => true,
1483 "Editable" => true,
1484 "Required" => false,
1485 ),
1486 "ACTIVE" => array(
1487 "Name" => GetMessage("BPVDX_FIELD_ACTIVE"),
1488 "Type" => "B",
1489 "Filterable" => true,
1490 "Editable" => true,
1491 "Required" => false,
1492 ),
1493 /*"BP_PUBLISHED" => array(
1494 "Name" => GetMessage("BPVDX_FIELD_BP_PUBLISHED"),
1495 "Type" => "B",
1496 "Filterable" => false,
1497 "Editable" => true,
1498 "Required" => false,
1499 ),*/
1500 "ACTIVE_FROM" => array(
1501 "Name" => GetMessage("BPVDX_FIELD_DATE_ACTIVE_FROM"),
1502 "Type" => "S:DateTime",
1503 "Filterable" => true,
1504 "Editable" => true,
1505 "Required" => false,
1506 ),
1507 "ACTIVE_TO" => array(
1508 "Name" => GetMessage("BPVDX_FIELD_DATE_ACTIVE_TO"),
1509 "Type" => "S:DateTime",
1510 "Filterable" => true,
1511 "Editable" => true,
1512 "Required" => false,
1513 ),
1514 "SORT" => array(
1515 "Name" => GetMessage("BPVDX_FIELD_SORT"),
1516 "Type" => "N",
1517 "Filterable" => true,
1518 "Editable" => true,
1519 "Required" => false,
1520 ),
1521 "NAME" => array(
1522 "Name" => GetMessage("BPVDX_FIELD_NAME"),
1523 "Type" => "S",
1524 "Filterable" => true,
1525 "Editable" => true,
1526 "Required" => true,
1527 ),
1528 "PREVIEW_PICTURE" => array(
1529 "Name" => GetMessage("BPVDX_FIELD_PREVIEW_PICTURE"),
1530 "Type" => "F",
1531 "Filterable" => false,
1532 "Editable" => true,
1533 "Required" => false,
1534 ),
1535 "PREVIEW_TEXT" => array(
1536 "Name" => GetMessage("BPVDX_FIELD_PREVIEW_TEXT"),
1537 "Type" => "T",
1538 "Filterable" => false,
1539 "Editable" => true,
1540 "Required" => false,
1541 ),
1542 "PREVIEW_TEXT_TYPE" => array(
1543 "Name" => GetMessage("BPVDX_FIELD_PREVIEW_TEXT_TYPE"),
1544 "Type" => "L",
1545 "Options" => array(
1546 "text" => GetMessage("BPVDX_DESC_TYPE_TEXT"),
1547 "html" => "Html",
1548 ),
1549 "Filterable" => false,
1550 "Editable" => true,
1551 "Required" => false,
1552 ),
1553 "DETAIL_PICTURE" => array(
1554 "Name" => GetMessage("BPVDX_FIELD_DETAIL_PICTURE"),
1555 "Type" => "F",
1556 "Filterable" => false,
1557 "Editable" => true,
1558 "Required" => false,
1559 ),
1560 "DETAIL_TEXT" => array(
1561 "Name" => GetMessage("BPVDX_FIELD_DETAIL_TEXT"),
1562 "Type" => "T",
1563 "Filterable" => false,
1564 "Editable" => true,
1565 "Required" => false,
1566 ),
1567 "DETAIL_TEXT_TYPE" => array(
1568 "Name" => GetMessage("BPVDX_FIELD_DETAIL_TEXT_TYPE"),
1569 "Type" => "L",
1570 "Options" => array(
1571 "text" => GetMessage("BPVDX_DESC_TYPE_TEXT"),
1572 "html" => "Html",
1573 ),
1574 "Filterable" => false,
1575 "Editable" => true,
1576 "Required" => false,
1577 ),
1578 "CODE" => array(
1579 "Name" => GetMessage("BPVDX_FIELD_CODE"),
1580 "Type" => "S",
1581 "Filterable" => true,
1582 "Editable" => true,
1583 "Required" => false,
1584 ),
1585 "XML_ID" => array(
1586 "Name" => GetMessage("BPVDX_FIELD_XML_ID"),
1587 "Type" => "S",
1588 "Filterable" => true,
1589 "Editable" => true,
1590 "Required" => false,
1591 ),
1592 );
1593
1594 $arKeys = array_keys($arResult);
1595 foreach ($arKeys as $key)
1596 $arResult[$key]["Multiple"] = false;
1597
1598 $dbProperties = CIBlockProperty::GetList(
1599 array("sort" => "asc", "name" => "asc"),
1600 array("IBLOCK_ID" => $iblockId)
1601 );
1602 while ($arProperty = $dbProperties->Fetch())
1603 {
1604 if (trim($arProperty["CODE"]) <> '')
1605 $key = "PROPERTY_".$arProperty["CODE"];
1606 else
1607 $key = "PROPERTY_".$arProperty["ID"];
1608
1609 $arResult[$key] = array(
1610 "Name" => $arProperty["NAME"],
1611 "Filterable" => ($arProperty["FILTRABLE"] == "Y"),
1612 "Editable" => true,
1613 "Required" => ($arProperty["IS_REQUIRED"] == "Y"),
1614 "Multiple" => ($arProperty["MULTIPLE"] == "Y"),
1615 "Type" => $arProperty["PROPERTY_TYPE"],
1616 );
1617
1618 if ($arProperty["USER_TYPE"] <> '')
1619 {
1620 $arResult[$key]["Type"] = "S:".$arProperty["USER_TYPE"];
1621
1622 if ($arProperty["USER_TYPE"] == "UserID"
1623 || $arProperty["USER_TYPE"] == "employee" && (COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y"))
1624 {
1625 $arResult[$key."_PRINTABLE"] = array(
1626 "Name" => $arProperty["NAME"].GetMessage("BPVDX_FIELD_USERNAME_PROPERTY"),
1627 "Filterable" => false,
1628 "Editable" => false,
1629 "Required" => false,
1630 "Multiple" => ($arProperty["MULTIPLE"] == "Y"),
1631 "Type" => "S",
1632 );
1633 }
1634 elseif ($arProperty["USER_TYPE"] == "EList")
1635 {
1636 $arResult[$key]["Type"] = "E:EList";
1637 $arResult[$key]["Options"] = $arProperty["LINK_IBLOCK_ID"];
1638 }
1639 }
1640 elseif ($arProperty["PROPERTY_TYPE"] == "L")
1641 {
1642 $arResult[$key]["Options"] = array();
1643 $dbPropertyEnums = CIBlockProperty::GetPropertyEnum($arProperty["ID"]);
1644 while ($arPropertyEnum = $dbPropertyEnums->GetNext())
1645 $arResult[$key]["Options"][$arPropertyEnum["XML_ID"]] = $arPropertyEnum["VALUE"];
1646 }
1647 elseif ($arProperty["PROPERTY_TYPE"] == "F")
1648 {
1649 $arResult[$key."_PRINTABLE"] = array(
1650 "Name" => $arProperty["NAME"].GetMessage("BPVDX_FIELD_USERNAME_PROPERTY"),
1651 "Filterable" => false,
1652 "Editable" => false,
1653 "Required" => false,
1654 "Multiple" => ($arProperty["MULTIPLE"] == "Y"),
1655 "Type" => "S",
1656 );
1657 }
1658 elseif ($arProperty["PROPERTY_TYPE"] == "S" && intval($arProperty["ROW_COUNT"]) > 1)
1659 $arResult[$key]["Type"] = "T";
1660 }
1661
1662 $arKeys = array_keys($arResult);
1663 foreach ($arKeys as $k)
1664 {
1665 $arResult[$k]["BaseType"] = $arDocumentFieldTypes[$arResult[$k]["Type"]]["BaseType"];
1666 $arResult[$k]["Complex"] = $arDocumentFieldTypes[$arResult[$k]["Type"]]["Complex"];
1667 }
1668
1669 return $arResult;
1670 }
1671
1672 public static function getDocumentFieldTypes($documentType)
1673 {
1674 $typesMap = FieldType::getBaseTypesMap();
1675
1676 $arResult = array(
1677 "S" => array("Name" => GetMessage("BPVDX_STRING"), "BaseType" => "string", 'typeClass' => $typesMap[FieldType::STRING]),
1678 "T" => array("Name" => GetMessage("BPVDX_TEXT"), "BaseType" => "text", 'typeClass' => $typesMap[FieldType::TEXT]),
1679 "N" => array("Name" => GetMessage("BPVDX_NUM"), "BaseType" => "double", 'typeClass' => $typesMap[FieldType::DOUBLE]),
1680 "L" => array("Name" => GetMessage("BPVDX_LIST"), "BaseType" => "select", "Complex" => true, 'typeClass' => $typesMap[FieldType::SELECT]),
1681 "F" => array("Name" => GetMessage("BPVDX_FILE"), "BaseType" => "file", 'typeClass' => $typesMap[FieldType::FILE]),
1682 "B" => array("Name" => GetMessage("BPVDX_YN"), "BaseType" => "bool", 'typeClass' => $typesMap[FieldType::BOOL]),
1683 );
1684
1685 foreach (CIBlockProperty::GetUserType() as $ar)
1686 {
1687 $t = $ar["PROPERTY_TYPE"].":".$ar["USER_TYPE"];
1688
1689 if($t == "S:ECrm")
1690 {
1691 $t = "E:ECrm";
1692 }
1693
1694 if (COption::GetOptionString("bizproc", "SkipNonPublicCustomTypes", "N") == "Y"
1695 && !array_key_exists("GetPublicEditHTML", $ar) && $t != "S:UserID" && $t != "S:DateTime")
1696 continue;
1697
1698 $arResult[$t] = array("Name" => $ar["DESCRIPTION"], "BaseType" => "string", 'typeClass' => BizprocType\UserTypeProperty::class);
1699 if ($t == "S:UserID")
1700 {
1701 $arResult[$t]["BaseType"] = "user";
1702 $arResult[$t]['typeClass'] = $typesMap[FieldType::USER];
1703 }
1704 elseif ($t == "S:employee" && COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y")
1705 {
1706 $arResult[$t]["BaseType"] = "user";
1707 $arResult[$t]['typeClass'] = BizprocType\UserTypePropertyEmployee::class;
1708 }
1709 elseif ($t == "S:DateTime")
1710 {
1711 $arResult[$t]["BaseType"] = "datetime";
1712 $arResult[$t]["typeClass"] = $typesMap[FieldType::DATETIME];
1713 }
1714 elseif ($t == "S:Date")
1715 {
1716 $arResult[$t]["BaseType"] = "date";
1717 $arResult[$t]["typeClass"] = $typesMap[FieldType::DATE];
1718 }
1719 elseif ($t == "E:EList")
1720 {
1721 $arResult[$t]["BaseType"] = "string";
1722 $arResult[$t]["Complex"] = true;
1723 $arResult[$t]['typeClass'] = BizprocType\UserTypePropertyElist::class;
1724 }
1725 elseif ($t == 'S:HTML')
1726 {
1727 $arResult[$t]['typeClass'] = BizprocType\UserTypePropertyHtml::class;
1728 }
1729 elseif($t == 'S:DiskFile')
1730 {
1731 $arResult[$t]["BaseType"] = "int";
1732 $arResult[$t]['typeClass'] = BizprocType\UserTypePropertyDiskFile::class;
1733 }
1734 elseif($t == 'E:ECrm')
1735 {
1736 $arResult[$t]["BaseType"] = "string";
1737 $arResult[$t]["Complex"] = true;
1738 $arResult[$t]['typeClass'] = BizprocType\ECrm::class;
1739 }
1740 }
1741
1742 return $arResult;
1743 }
1744
1745 public static function addDocumentField($documentType, $arFields)
1746 {
1747 $iblockId = intval(mb_substr($documentType, mb_strlen("type_")));
1748 if ($iblockId <= 0)
1749 throw new CBPArgumentOutOfRangeException("documentType", $documentType);
1750
1751 if (mb_substr($arFields["code"], 0, mb_strlen("PROPERTY_")) == "PROPERTY_")
1752 $arFields["code"] = mb_substr($arFields["code"], mb_strlen("PROPERTY_"));
1753
1754 $arFieldsTmp = array(
1755 "NAME" => $arFields["name"],
1756 "ACTIVE" => "Y",
1757 "SORT" => 150,
1758 "CODE" => $arFields["code"],
1759 "MULTIPLE" => $arFields["multiple"],
1760 "IS_REQUIRED" => $arFields["required"],
1761 "IBLOCK_ID" => $iblockId,
1762 "FILTRABLE" => "Y",
1763 );
1764
1765 if (mb_strpos("0123456789", mb_substr($arFieldsTmp["CODE"], 0, 1)) !== false)
1766 unset($arFieldsTmp["CODE"]);
1767
1768 if (array_key_exists("additional_type_info", $arFields))
1769 $arFieldsTmp["LINK_IBLOCK_ID"] = intval($arFields["additional_type_info"]);
1770
1771 if (mb_strstr($arFields["type"], ":") !== false)
1772 {
1773 [$arFieldsTmp["PROPERTY_TYPE"], $arFieldsTmp["USER_TYPE"]] = explode(":", $arFields["type"], 2);
1774 if ($arFields["type"] == "E:EList")
1775 $arFieldsTmp["LINK_IBLOCK_ID"] = $arFields["options"];
1776 }
1777 else
1778 {
1779 $arFieldsTmp["PROPERTY_TYPE"] = $arFields["type"];
1780 $arFieldsTmp["USER_TYPE"] = false;
1781 }
1782
1783 if ($arFieldsTmp["PROPERTY_TYPE"] == "T")
1784 {
1785 $arFieldsTmp["PROPERTY_TYPE"] = "S";
1786 $arFieldsTmp["ROW_COUNT"] = 5;
1787 }
1788
1789 if ($arFields["type"] == "L")
1790 {
1791 if (is_array($arFields["options"]))
1792 {
1793 $i = 10;
1794 foreach ($arFields["options"] as $k => $v)
1795 {
1796 $arFieldsTmp["VALUES"][] = array("XML_ID" => $k, "VALUE" => $v, "DEF" => "N", "SORT" => $i);
1797 $i = $i + 10;
1798 }
1799 }
1800 elseif (is_string($arFields["options"]) && ($arFields["options"] <> ''))
1801 {
1802 $a = explode("\n", $arFields["options"]);
1803 $i = 10;
1804 foreach ($a as $v)
1805 {
1806 $v = trim(trim($v), "\r\n");
1807 $v1 = $v2 = $v;
1808 if (mb_substr($v, 0, 1) == "[" && mb_strpos($v, "]") !== false)
1809 {
1810 $v1 = mb_substr($v, 1, mb_strpos($v, "]") - 1);
1811 $v2 = trim(mb_substr($v, mb_strpos($v, "]") + 1));
1812 }
1813 $arFieldsTmp["VALUES"][] = array("XML_ID" => $v1, "VALUE" => $v2, "DEF" => "N", "SORT" => $i);
1814 $i = $i + 10;
1815 }
1816 }
1817 }
1818
1819 $ibp = new CIBlockProperty;
1820 $propId = $ibp->Add($arFieldsTmp);
1821
1822 if (intval($propId) <= 0)
1823 throw new Exception($ibp->LAST_ERROR);
1824
1825 return "PROPERTY_".$arFields["code"];
1826 }
1827
1828 public static function updateDocument($documentId, $arFields)
1829 {
1830 $documentId = intval($documentId);
1831 if ($documentId <= 0)
1832 throw new CBPArgumentNullException("documentId");
1833
1834 CIBlockElement::WF_CleanUpHistoryCopies($documentId, 0);
1835
1836 $arFieldsPropertyValues = array();
1837
1838 $dbResult = CIBlockElement::GetList(array(), array("ID" => $documentId, "SHOW_NEW" => "Y"), false, false, array("ID", "IBLOCK_ID"));
1839 $arResult = $dbResult->Fetch();
1840 if (!$arResult)
1841 throw new Exception("Element is not found");
1842
1843 $arDocumentFields = self::GetDocumentFields("type_".$arResult["IBLOCK_ID"]);
1844
1845 $arKeys = array_keys($arFields);
1846 foreach ($arKeys as $key)
1847 {
1848 if (!array_key_exists($key, $arDocumentFields))
1849 continue;
1850
1851 if ($arDocumentFields[$key]["Multiple"] && is_string($arFields[$key]))
1852 {
1853 $arFieldsTmp = explode(",", $arFields[$key]);
1854 $arFields[$key] = array();
1855 foreach ($arFieldsTmp as $value)
1856 $arFields[$key][] = trim($value);
1857 }
1858
1859 $arFields[$key] = (is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key])) ? $arFields[$key] : array($arFields[$key]);
1860
1861 if ($arDocumentFields[$key]["Type"] == "S:UserID")
1862 {
1863 $ar = array();
1864 foreach ($arFields[$key] as $v1)
1865 {
1866 if (mb_substr($v1, 0, mb_strlen("user_")) == "user_")
1867 {
1868 $ar[] = mb_substr($v1, mb_strlen("user_"));
1869 }
1870 else
1871 {
1872 $a1 = self::GetUsersFromUserGroup($v1, $documentId);
1873 foreach ($a1 as $a11)
1874 $ar[] = $a11;
1875 }
1876 }
1877
1878 $arFields[$key] = $ar;
1879 }
1880 elseif ($arDocumentFields[$key]['Type'] == 'S:employee')
1881 {
1882 $arFields[$key] = CBPHelper::StripUserPrefix($arFields[$key]);
1883 }
1884 elseif ($arDocumentFields[$key]["Type"] == "L")
1885 {
1886 $realKey = ((mb_substr($key, 0, mb_strlen("PROPERTY_")) == "PROPERTY_")? mb_substr($key, mb_strlen("PROPERTY_")) : $key);
1887
1888 $arV = array();
1889 $db = CIBlockProperty::GetPropertyEnum($realKey, false, array("IBLOCK_ID" => $arResult["IBLOCK_ID"]));
1890 while ($ar = $db->GetNext())
1891 $arV[$ar["XML_ID"]] = $ar["ID"];
1892
1893 foreach ($arFields[$key] as &$value)
1894 {
1895 if (array_key_exists($value, $arV))
1896 $value = $arV[$value];
1897 }
1898 }
1899 elseif ($arDocumentFields[$key]["Type"] == "F")
1900 {
1901 foreach ($arFields[$key] as &$value)
1902 $value = CFile::MakeFileArray($value);
1903 }
1904 elseif ($arDocumentFields[$key]["Type"] == "S:HTML")
1905 {
1906 foreach ($arFields[$key] as &$value)
1907 $value = array("VALUE" => $value);
1908 }
1909
1910 if (!$arDocumentFields[$key]["Multiple"] && is_array($arFields[$key]))
1911 {
1912 if (count($arFields[$key]) > 0)
1913 {
1914 $a = array_values($arFields[$key]);
1915 $arFields[$key] = $a[0];
1916 }
1917 else
1918 {
1919 $arFields[$key] = null;
1920 }
1921 }
1922
1923 if (mb_substr($key, 0, mb_strlen("PROPERTY_")) == "PROPERTY_")
1924 {
1925 $realKey = mb_substr($key, mb_strlen("PROPERTY_"));
1926 $arFieldsPropertyValues[$realKey] = (is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key])) ? $arFields[$key] : array($arFields[$key]);
1927 unset($arFields[$key]);
1928 }
1929 }
1930
1931 $iblockElement = new CIBlockElement();
1932
1933 if (count($arFieldsPropertyValues) > 0)
1934 $iblockElement->SetPropertyValuesEx($documentId, $arResult["IBLOCK_ID"], $arFieldsPropertyValues);
1935
1936 if (count($arFields) > 0)
1937 {
1938 $res = $iblockElement->Update($documentId, $arFields, false, true, true);
1939 if (!$res)
1940 throw new Exception($iblockElement->LAST_ERROR);
1941 }
1942 }
1943
1944 public static function createDocument($parentDocumentId, $arFields)
1945 {
1946 if (!array_key_exists("IBLOCK_ID", $arFields) || intval($arFields["IBLOCK_ID"]) <= 0)
1947 throw new Exception("IBlock ID is not found");
1948
1949 $arDocumentFields = self::GetDocumentFields("type_".$arFields["IBLOCK_ID"]);
1950
1951 $arKeys = array_keys($arFields);
1952 $arFieldsPropertyValues = [];
1953 foreach ($arKeys as $key)
1954 {
1955 if (!array_key_exists($key, $arDocumentFields))
1956 continue;
1957
1958 if ($arDocumentFields[$key]["Multiple"] && is_string($arFields[$key]))
1959 {
1960 $arFieldsTmp = explode(",", $arFields[$key]);
1961 $arFields[$key] = array();
1962 foreach ($arFieldsTmp as $value)
1963 $arFields[$key][] = trim($value);
1964 }
1965
1966 $arFields[$key] = (is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key])) ? $arFields[$key] : array($arFields[$key]);
1967
1968 if ($arDocumentFields[$key]["Type"] == "S:UserID")
1969 {
1970 $ar = array();
1971 foreach ($arFields[$key] as $v1)
1972 {
1973 if (mb_substr($v1, 0, mb_strlen("user_")) == "user_")
1974 {
1975 $ar[] = mb_substr($v1, mb_strlen("user_"));
1976 }
1977 else
1978 {
1979 $a1 = self::GetUsersFromUserGroup($v1, $parentDocumentId);
1980 foreach ($a1 as $a11)
1981 $ar[] = $a11;
1982 }
1983 }
1984
1985 $arFields[$key] = $ar;
1986 }
1987 elseif ($arDocumentFields[$key]["Type"] == "L")
1988 {
1989 $realKey = ((mb_substr($key, 0, mb_strlen("PROPERTY_")) == "PROPERTY_")? mb_substr($key, mb_strlen("PROPERTY_")) : $key);
1990
1991 $arV = array();
1992 $db = CIBlockProperty::GetPropertyEnum($realKey, false, array("IBLOCK_ID" => $arFields["IBLOCK_ID"]));
1993 while ($ar = $db->GetNext())
1994 $arV[$ar["XML_ID"]] = $ar["ID"];
1995
1996 foreach ($arFields[$key] as &$value)
1997 {
1998 if (array_key_exists($value, $arV))
1999 $value = $arV[$value];
2000 }
2001 }
2002 elseif ($arDocumentFields[$key]["Type"] == "F")
2003 {
2004 foreach ($arFields[$key] as &$value)
2005 $value = CFile::MakeFileArray($value);
2006 }
2007 elseif ($arDocumentFields[$key]["Type"] == "S:HTML")
2008 {
2009 foreach ($arFields[$key] as &$value)
2010 $value = array("VALUE" => $value);
2011 }
2012
2013 if (!$arDocumentFields[$key]["Multiple"] && is_array($arFields[$key]))
2014 {
2015 if (count($arFields[$key]) > 0)
2016 {
2017 $a = array_values($arFields[$key]);
2018 $arFields[$key] = $a[0];
2019 }
2020 else
2021 {
2022 $arFields[$key] = null;
2023 }
2024 }
2025
2026 if (mb_substr($key, 0, mb_strlen("PROPERTY_")) == "PROPERTY_")
2027 {
2028 $realKey = mb_substr($key, mb_strlen("PROPERTY_"));
2029 $arFieldsPropertyValues[$realKey] = (is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key])) ? $arFields[$key] : array($arFields[$key]);
2030 unset($arFields[$key]);
2031 }
2032 }
2033
2034 if (count($arFieldsPropertyValues) > 0)
2035 $arFields["PROPERTY_VALUES"] = $arFieldsPropertyValues;
2036
2037 $iblockElement = new CIBlockElement();
2038 $id = $iblockElement->Add($arFields, false, true, true);
2039 if (!$id || $id <= 0)
2040 throw new Exception($iblockElement->LAST_ERROR);
2041 return $id;
2042 }
2043
2044 public static function getAllowableOperations($documentType)
2045 {
2046 return array("read" => GetMessage("BPVDX_OP_READ"), "create" => GetMessage("BPVDX_OP_CREATE")/*, "admin" => GetMessage("BPVDX_OP_ADMIN")*/);
2047 }
2048
2049 // array("1" => "Admins", 2 => "Guests", 3 => ..., "Author" => "Author")
2050 public static function getAllowableUserGroups($documentType, $withExtended = false)
2051 {
2052 $documentType = trim($documentType);
2053 if ($documentType == '')
2054 return false;
2055
2056 $iblockId = intval(mb_substr($documentType, mb_strlen("type_")));
2057
2058 $arResult = array("Author" => GetMessage("BPVDX_DOCUMENT_AUTHOR"));
2059
2060// $arRes = array(1);
2061// $arGroups = CIBlock::GetGroupPermissions($iblockId);
2062// foreach ($arGroups as $groupId => $perm)
2063// {
2064// if ($perm > "R")
2065// $arRes[] = $groupId;
2066// }
2067
2068 $dbGroupsList = CGroup::GetListEx(array("NAME" => "ASC"), array("ACTIVE" => "Y")); //array("ID" => $arRes)
2069 while ($arGroup = $dbGroupsList->Fetch())
2070 $arResult[$arGroup["ID"]] = $arGroup["NAME"];
2071
2072 return $arResult;
2073 }
2074
2075 public static function getUsersFromUserGroup($group, $documentId)
2076 {
2077 $group = mb_strtolower($group);
2078 if ($group == "author")
2079 {
2080 $documentId = intval($documentId);
2081 if ($documentId <= 0)
2082 return array();
2083
2084 $db = CIBlockElement::GetList(array(), array("ID" => $documentId, "SHOW_NEW"=>"Y"), false, false, array("ID", "IBLOCK_ID", "CREATED_BY"));
2085 if ($ar = $db->Fetch())
2086 return array($ar["CREATED_BY"]);
2087
2088 return array();
2089 }
2090
2091 if ((string)intval($group) !== (string)$group)
2092 return array();
2093
2094 $group = (int)$group;
2095 if ($group <= 0)
2096 return array();
2097
2098 $arResult = array();
2099
2100 $dbUsersList = CUser::GetList(
2101 "ID",
2102 "ASC",
2103 ['GROUPS_ID' => $group, 'ACTIVE' => 'Y', 'IS_REAL_USER' => true],
2104 ['FIELDS' => ['ID']]
2105 );
2106 while ($arUser = $dbUsersList->Fetch())
2107 {
2108 $arResult[] = $arUser["ID"];
2109 }
2110 return $arResult;
2111 }
2112
2113 public static function getJSFunctionsForFields($documentType, $objectName, $arDocumentFields = array(), $arDocumentFieldTypes = array())
2114 {
2115 $iblockId = intval(mb_substr($documentType, mb_strlen("type_")));
2116 if ($iblockId <= 0)
2117 return "";
2118
2119 ob_start();
2120
2122 ?>
2123 <script>
2124 <?= $objectName ?>.GetGUIFieldEdit = function(field, value, showAddButton, inputName)
2125 {
2126 alert("Deprecated method GetGUIFieldEdit used");
2127
2128 if (!this.arDocumentFields[field])
2129 return "";
2130
2131 if (typeof showAddButton == "undefined")
2132 showAddButton = false;
2133
2134 if (typeof inputName == "undefined")
2135 inputName = field;
2136
2137 var type = this.arDocumentFields[field]["Type"];
2138
2139 var bAddSelection = false;
2140 var bAddButton = true;
2141
2142 s = "";
2143 if (type == "N")
2144 {
2145 s += '<input type="text" size="10" id="id_' + field + '" name="' + inputName + '" value="' + this.HtmlSpecialChars(value) + '">';
2146 }
2147 else if (type == "L")
2148 {
2149 s += '<select name="' + inputName + '_1">';
2150 s += '<option value=""></option>';
2151 for (k in this.arDocumentFields[field]["Options"])
2152 {
2153 s += '<option value="' + this.arDocumentFields[field]["Options"][k][0] + '"' + (value == this.arDocumentFields[field]["Options"][k][0] ? " selected" : "") + '>' + this.arDocumentFields[field]["Options"][k][1] + '</option>';
2154 if (value == this.arDocumentFields[field]["Options"][k][0])
2155 value = "";
2156 }
2157 s += '</select>';
2158 bAddSelection = true;
2159 }
2160 else if (type == "F")
2161 {
2162 s += '<input type="file" id="id_' + field + '_1" name="' + inputName + '">';
2163 bAddSelection = true;
2164 bAddButton = true;
2165 }
2166 else if (type == "B")
2167 {
2168 s += '<select name="' + inputName + '_1" id="id_' + name + '">';
2169 s += '<option value=""></option>';
2170 s += '<option value="Y"' + (value == "Y" ? " selected" : "") + '><?= GetMessage("BPVDX_YES") ?></option>';
2171 s += '<option value="N"' + (value == "N" ? " selected" : "") + '><?= GetMessage("BPVDX_NO") ?></option>';
2172 s += '</select>';
2173 bAddSelection = true;
2174 if (value == "Y" || value == "N")
2175 value = "";
2176 }
2177 else if (type == "S:DateTime")
2178 {
2179 s += '<span style="white-space:nowrap;">';
2180 s += '<input type="text" name="' + inputName + '" id="id_' + field + '" size="10" value="' + this.HtmlSpecialChars(value) + '">';
2181 s += '<a href="javascript:void(0);" title="<?= GetMessage("BPVDX_CALENDAR") ?>">';
2182 s += '<img src="<?= ADMIN_THEMES_PATH ?>/<?= ADMIN_THEME_ID ?>/images/calendar/icon.gif" alt="<?= GetMessage("BPVDX_CALENDAR") ?>" class="calendar-icon" onclick="jsAdminCalendar.Show(this, \'' + inputName + '\', \'\', \'\', ' + ((type == "datetime") ? 'true' : 'false') + ', <?= time() + date("Z") + CTimeZone::GetOffset() ?>);" onmouseover="this.className+=\' calendar-icon-hover\';" onmouseout="this.className = this.className.replace(/\s*calendar-icon-hover/ig, \'\');">';
2183 s += '</a></span>';
2184 }
2185 //else if (type.substr(0, 2) == "S:" && this.arUserTypes[type.substr(2)])
2186 //{
2187 // s += eval(this.arUserTypes[type.substr(2)] + "(\"" + field + "\", \"" + value + "\")");
2188 //}
2189 else // type == "S"
2190 {
2191 s += '<input type="text" size="40" id="id_' + field + '" name="' + inputName + '" value="' + this.HtmlSpecialChars(value) + '">';
2192 }
2193
2194 if (bAddSelection)
2195 s += '<br /><input type="text" id="id_' + field + '" name="' + inputName + '" value="' + this.HtmlSpecialChars(value) + '">';
2196
2197 if (bAddButton && showAddButton)
2198 s += '<input type="button" value="..." onclick="BPAShowSelector(\'id_' + field + '\', \'' + type + '\');">';
2199
2200 return s;
2201 }
2202
2203 <?= $objectName ?>.SetGUIFieldEdit = function(field)
2204 {
2205 alert("Deprecated method SetGUIFieldEdit used");
2206 }
2207
2208 <?= $objectName ?>.GetGUIFieldEditSimple = function(type, value, name)
2209 {
2210 alert("Deprecated method GetGUIFieldEditSimple used");
2211
2212 if (typeof name == "undefined" || name.length <= 0)
2213 name = "BPVDDefaultValue";
2214
2215 if (typeof value == "undefined")
2216 {
2217 value = "";
2218
2219 var obj = document.getElementById('id_' + name);
2220 if (obj)
2221 {
2222 if (obj.type.substr(0, "select".length) == "select")
2223 value = obj.options[obj.selectedIndex].value;
2224 else
2225 value = obj.value;
2226 }
2227 }
2228
2229 s = "";
2230 if (type == "F")
2231 {
2232 s += '';
2233 }
2234 else if (type == "B")
2235 {
2236 s += '<select name="' + name + '" id="id_' + name + '">';
2237 s += '<option value=""></option>';
2238 s += '<option value="Y"' + (value == "Y" ? " selected" : "") + '><?= GetMessage("BPVDX_YES") ?></option>';
2239 s += '<option value="N"' + (value == "N" ? " selected" : "") + '><?= GetMessage("BPVDX_NO") ?></option>';
2240 s += '</select>';
2241 }
2242 else if (type == "S:UserID")
2243 {
2244 s += '<input type="text" size="10" id="id_' + name + '" name="' + name + '" value="' + this.HtmlSpecialChars(value) + '">';
2245 s += '<input type="button" value="..." onclick="BPAShowSelector(\'id_' + name + '\', \'user\')">';
2246 }
2247 else
2248 {
2249 s += '<input type="text" size="10" id="id_' + name + '" name="' + name + '" value="' + this.HtmlSpecialChars(value) + '">';
2250 }
2251
2252 return s;
2253 }
2254
2255 <?= $objectName ?>.SetGUIFieldEditSimple = function(type, name)
2256 {
2257 alert("Deprecated method SetGUIFieldEditSimple used");
2258
2259 if (typeof name == "undefined" || name.length <= 0)
2260 name = "BPVDDefaultValue";
2261
2262 s = "";
2263 if (type != "F")
2264 {
2265 var obj = document.getElementById('id_' + name);
2266 if (obj)
2267 {
2268 if (obj.type.substr(0, "select".length) == "select")
2269 s = obj.options[obj.selectedIndex].value;
2270 else
2271 s = obj.value;
2272 }
2273 }
2274
2275 return s;
2276 }
2277 </script>
2278 <?
2279
2280 $str = ob_get_contents();
2281 ob_end_clean();
2282
2283 return $str;
2284 }
2285
2286 public static function getGUIFieldEdit($documentType, $formName, $fieldName, $fieldValue, $arDocumentField = null, $bAllowSelection = false)
2287 {
2288 return self::GetFieldInputControl(
2289 $documentType,
2290 $arDocumentField,
2291 array("Form" => $formName, "Field" => $fieldName),
2292 $fieldValue,
2293 $bAllowSelection
2294 );
2295 }
2296
2297 public static function setGUIFieldEdit($documentType, $fieldName, $arRequest, &$arErrors, $arDocumentField = null)
2298 {
2299 return self::GetFieldInputValue($documentType, $arDocumentField, array("Field" => $fieldName), $arRequest, $arErrors);
2300 }
2301
2302 public static function getFieldValuePrintable($documentId, $fieldName, $fieldType, $fieldValue, $arFieldType)
2303 {
2304 $documentType = null;
2305
2306 if ($fieldType == "S:UserID")
2307 {
2308 static $arCache = array();
2309 if (!array_key_exists($documentId, $arCache))
2310 {
2311 if (mb_substr($documentId, 0, mb_strlen("type_")) == "type_")
2312 $arCache[$documentId] = $documentId;
2313 else
2314 $arCache[$documentId] = self::GetDocumentType($documentId);
2315 }
2316 $documentType = $arCache[$documentId];
2317 }
2318
2319 if (is_null($arFieldType) || !is_array($arFieldType) || count($arFieldType) <= 0)
2320 $arFieldType = array();
2321 $arFieldType["Type"] = $fieldType;
2322
2323 return self::GetFieldInputValuePrintable($documentType, $arFieldType, $fieldValue);
2324 }
2325
2326 public static function setPermissions($documentId, $workflowId, $arPermissions, $bRewrite = true)
2327 {
2328 $documentId = intval($documentId);
2329 if ($documentId <= 0)
2330 throw new CBPArgumentNullException("documentId");
2331 }
2332
2334 {
2335 CBPDocument::OnDocumentDelete(array("bizproc", "CBPVirtualDocument", $arFields["ID"]), $arErrorsTmp);
2336 }
2337
2338 public static function isExtendedPermsSupported($documentType)
2339 {
2340 return false;
2341 }
2342}
return select
Определения access_edit.php:440
$obTask
Определения access_edit.php:112
<?=$taskID?> selected
Определения access_edit.php:348
while($arIBType=$dbIBlockType->Fetch()) $dbIBlock
Определения options.php:178
$arResult
Определения generate_coupon.php:16
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
const USER
Определения fieldtype.php:67
const BOOL
Определения fieldtype.php:17
const DATE
Определения fieldtype.php:22
const SELECT
Определения fieldtype.php:47
const FILE
Определения fieldtype.php:37
const STRING
Определения fieldtype.php:57
static getBaseTypesMap()
Определения fieldtype.php:481
const TEXT
Определения fieldtype.php:62
const DATETIME
Определения fieldtype.php:27
const DOUBLE
Определения fieldtype.php:32
static ShowScript()
Определения admin_calendar.php:55
static GetListEx($arOrder=["ID"=> "DESC"], $arFilter=[], $arGroupBy=false, $arNavStartParams=false, $arSelectFields=[])
Определения group.php:736
Add($arFields)
Определения iblockproperty.php:240
static GetNavChain($IBLOCK_ID, $SECTION_ID, $arSelect=array(), $arrayResult=false)
Определения iblocksection.php:204
static GetOptionInt($module_id, $name, $def="", $site=false)
Определения option.php:49
static isExpression($text)
Определения activity.php:1718
static getDocumentFieldTypes($documentType)
Определения virtualdocument.php:1672
static addDocumentField($documentType, $arFields)
Определения virtualdocument.php:1745
static getDocument($documentId)
Определения virtualdocument.php:1263
static getAllowableUserGroups($documentType, $withExtended=false)
Определения virtualdocument.php:2050
static getFieldInputValue($documentType, $arFieldType, $arFieldName, $arRequest, &$arErrors)
Определения virtualdocument.php:506
static createDocument($parentDocumentId, $arFields)
Определения virtualdocument.php:1944
static setGUIFieldEdit($documentType, $fieldName, $arRequest, &$arErrors, $arDocumentField=null)
Определения virtualdocument.php:2297
static getDocumentTypeName($documentType)
Определения virtualdocument.php:16
static getUsersFromUserGroup($group, $documentId)
Определения virtualdocument.php:2075
static getGUIFieldEdit($documentType, $formName, $fieldName, $fieldValue, $arDocumentField=null, $bAllowSelection=false)
Определения virtualdocument.php:2286
static setPermissions($documentId, $workflowId, $arPermissions, $bRewrite=true)
Определения virtualdocument.php:2326
static getJSFunctionsForFields($documentType, $objectName, $arDocumentFields=array(), $arDocumentFieldTypes=array())
Определения virtualdocument.php:2113
static getDocumentFields($documentType)
Определения virtualdocument.php:1420
static getList($arOrder=array("SORT"=> "ASC"), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения virtualdocument.php:1048
static getFieldInputValuePrintable($documentType, $arFieldType, $fieldValue)
Определения virtualdocument.php:749
static getFieldInputControlOptions($documentType, &$arFieldType, $jsFunctionName, &$value)
Определения virtualdocument.php:31
static getFieldValuePrintable($documentId, $fieldName, $fieldType, $fieldValue, $arFieldType)
Определения virtualdocument.php:2302
static getAllowableOperations($documentType)
Определения virtualdocument.php:2044
static canUserOperateDocumentType($operation, $userId, $documentType, $arParameters=array())
Определения virtualdocument.php:963
static onAfterIBlockElementDelete($arFields)
Определения virtualdocument.php:2333
static updateDocument($documentId, $arFields)
Определения virtualdocument.php:1828
static getDocumentAdminPage($documentId)
Определения virtualdocument.php:1242
static getDocumentType($documentId)
Определения virtualdocument.php:1403
static getFieldInputControl($documentType, $arFieldType, $arFieldName, $fieldValue, $bAllowSelection=false, $publicMode=false)
Определения virtualdocument.php:155
static canUserOperateDocument($operation, $userId, $documentId, $arParameters=array())
Определения virtualdocument.php:862
static getEntityName()
Определения virtualdocument.php:11
static isExtendedPermsSupported($documentType)
Определения virtualdocument.php:2338
Определения dbresult.php:88
static GetDocumentFieldTypes($documentType)
Определения iblockdocument.php:1584
static GetDocumentFields($documentType)
Определения iblockdocument.php:1291
static GetUsersFromUserGroup($group, $documentId)
Определения iblockdocument.php:3025
Определения iblockelement.php:9
static GetIBlockTypes($arTop=false)
Определения comp_parameters.php:932
$str
Определения commerceml2.php:63
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr ><?endif?><? $propertyIndex=0;foreach( $arGlobalProperties as $propertyCode=> $propertyValue
Определения file_new.php:729
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$arGroups
Определения options.php:1766
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$iblockTypeId
Определения group_lists.php:25
$iblockId
Определения iblock_catalog_edit.php:30
$select
Определения iblock_catalog_list.php:194
HTMLToTxt($str, $strSiteUrl="", $aDelete=[], $maxlen=70)
Определения tools.php:2587
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$value
Определения Param.php:39
$GLOBALS['____1690880296']
Определения license.php:1
$publicMode
Определения product_settings.php:144
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
if(empty($signedUserToken)) $key
Определения quickway.php:257
$i
Определения factura.php:643
font style
Определения invoice.php:442
font size
Определения invoice.php:442
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
else $a
Определения template.php:137
$val
Определения options.php:1793
const SITE_ID
Определения sonet_set_content_view.php:12
$k
Определения template_pdf.php:567
$dbResult
Определения updtr957.php:3
$arFilter
Определения user_search.php:106
$arIBlock['PROPERTY']
Определения yandex_detail.php:172
$iterator
Определения yandex_run.php:610
if( $site[ 'SERVER_NAME']==='') if($site['SERVER_NAME']==='') $arProperties
Определения yandex_run.php:644