1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
iblockdocument.php
См. документацию.
1<?php
2
4
5if (!CModule::IncludeModule("bizproc"))
6 return;
7
9{
10 public static function getEntityName()
11 {
12 return GetMessage('IBD_DOCUMENT_ENTITY_NAME');
13 }
14
15 public static function GetFieldInputControl($documentType, $arFieldType, $arFieldName, $fieldValue, $bAllowSelection = false, $publicMode = false)
16 {
17 $iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
18 if ($iblockId <= 0)
19 throw new CBPArgumentOutOfRangeException("documentType", $documentType);
20
21 global $APPLICATION;
22 if(!$publicMode)
23 $APPLICATION->showAjaxHead();
24
25 static $arDocumentFieldTypes = array();
26 if (!array_key_exists($documentType, $arDocumentFieldTypes))
27 $arDocumentFieldTypes[$documentType] = self::GetDocumentFieldTypes($documentType);
28
29 $arFieldType["BaseType"] = "string";
30 $arFieldType["Complex"] = false;
31 if (array_key_exists($arFieldType["Type"], $arDocumentFieldTypes[$documentType]))
32 {
33 $arFieldType["BaseType"] = $arDocumentFieldTypes[$documentType][$arFieldType["Type"]]["BaseType"];
34 $arFieldType["Complex"] = $arDocumentFieldTypes[$documentType][$arFieldType["Type"]]["Complex"];
35 }
36
37 if (!is_array($fieldValue) || is_array($fieldValue) && CBPHelper::IsAssociativeArray($fieldValue))
38 $fieldValue = array($fieldValue);
39
40 $customMethodName = "";
41 $customMethodNameMulty = "";
42 if (mb_strpos($arFieldType["Type"], ":") !== false)
43 {
44 $ar = CIBlockProperty::GetUserType(mb_substr($arFieldType["Type"], 2));
45 if (array_key_exists("GetPublicEditHTML", $ar))
46 $customMethodName = $ar["GetPublicEditHTML"];
47 if (array_key_exists("GetPublicEditHTMLMulty", $ar))
48 $customMethodNameMulty = $ar["GetPublicEditHTMLMulty"];
49 }
50
51 ob_start();
52
53 if ($arFieldType["Type"] == "select")
54 {
55 $fieldValueTmp = $fieldValue;
56 ?>
57 <select id="id_<?= htmlspecialcharsbx($arFieldName["Field"]) ?>" name="<?= htmlspecialcharsbx($arFieldName["Field"]).($arFieldType["Multiple"] ? "[]" : "") ?>"<?= ($arFieldType["Multiple"] ? ' size="5" multiple' : '') ?>>
58 <?
59 if (!$arFieldType["Required"])
60 echo '<option value="">['.GetMessage("BPCGHLP_NOT_SET").']</option>';
61 if(!empty($arFieldType["Options"]))
62 {
63 foreach ($arFieldType["Options"] as $k => $v)
64 {
65 if (is_array($v) && count($v) == 2)
66 {
67 $v1 = array_values($v);
68 $k = $v1[0];
69 $v = $v1[1];
70 }
71
72 $ind = array_search($k, $fieldValueTmp);
73 echo '<option value="'.htmlspecialcharsbx($k).'"'.($ind !== false ? ' selected' : '').'>'.htmlspecialcharsbx($v).'</option>';
74 if ($ind !== false)
75 unset($fieldValueTmp[$ind]);
76 }
77 }
78 ?>
79 </select>
80 <?
81 if ($bAllowSelection)
82 {
83 ?>
84 <br /><input type="text" id="id_<?= htmlspecialcharsbx($arFieldName["Field"]) ?>_text" name="<?= htmlspecialcharsbx($arFieldName["Field"]) ?>_text" value="<?
85 if (count($fieldValueTmp) > 0)
86 {
87 $a = array_values($fieldValueTmp);
88 echo htmlspecialcharsbx($a[0]);
89 }
90 ?>">
91 <input type="button" value="..." onclick="BPAShowSelector('id_<?= htmlspecialcharsbx($arFieldName["Field"]) ?>_text', 'select');">
92 <?
93 }
94 }
95 elseif ($arFieldType["Type"] == "user")
96 {
97 $fieldValue = CBPHelper::UsersArrayToString($fieldValue, null, array("iblock", "CIBlockDocument", $documentType));
98 ?><input type="text" size="40" id="id_<?= htmlspecialcharsbx($arFieldName["Field"]) ?>" name="<?= htmlspecialcharsbx($arFieldName["Field"]) ?>" value="<?= htmlspecialcharsbx($fieldValue) ?>"><input type="button" value="..." onclick="BPAShowSelector('id_<?= htmlspecialcharsbx($arFieldName["Field"]) ?>', 'user');"><?
99 }
100 elseif ((mb_strpos($arFieldType["Type"], ":") !== false)
101 && $arFieldType["Multiple"]
102 && (
103 is_array($customMethodNameMulty) && count($customMethodNameMulty) > 0
104 || !is_array($customMethodNameMulty) && $customMethodNameMulty <> ''
105 )
106 )
107 {
108 if (!is_array($fieldValue))
109 $fieldValue = array();
110
111 if ($bAllowSelection)
112 {
113 $fieldValueTmp1 = array();
114 $fieldValueTmp2 = array();
115 foreach ($fieldValue as $v)
116 {
117 $vTrim = trim($v);
118 if (CBPDocument::IsExpression($vTrim))
119 $fieldValueTmp1[] = $vTrim;
120 else
121 $fieldValueTmp2[] = $v;
122 }
123 }
124 else
125 {
126 $fieldValueTmp1 = array();
127 $fieldValueTmp2 = $fieldValue;
128 }
129
130 if (($arFieldType["Type"] == "S:employee") && COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y")
131 $fieldValueTmp2 = CBPHelper::StripUserPrefix($fieldValueTmp2);
132
133 foreach ($fieldValueTmp2 as &$fld)
134 if (!isset($fld['VALUE']))
135 $fld = array("VALUE" => $fld);
136
137 if ($arFieldType["Type"] == "E:EList")
138 {
139 static $fl = true;
140 if ($fl)
141 {
142 if (!empty($_SERVER['HTTP_BX_AJAX']))
143 $GLOBALS["APPLICATION"]->ShowAjaxHead();
144 $GLOBALS["APPLICATION"]->AddHeadScript('/bitrix/js/iblock/iblock_edit.js');
145 }
146 $fl = false;
147 }
148 echo call_user_func_array(
149 $customMethodNameMulty,
150 array(
151 array("LINK_IBLOCK_ID" => $arFieldType["Options"]),
152 $fieldValueTmp2,
153 array(
154 "FORM_NAME" => $arFieldName["Form"],
155 "VALUE" => htmlspecialcharsbx($arFieldName["Field"])
156 ),
157 true
158 )
159 );
160
161 if ($bAllowSelection)
162 {
163 ?>
164 <br /><input type="text" id="id_<?= htmlspecialcharsbx($arFieldName["Field"]) ?>_text" name="<?= htmlspecialcharsbx($arFieldName["Field"]) ?>_text" value="<?
165 if (count($fieldValueTmp1) > 0)
166 {
167 $a = array_values($fieldValueTmp1);
168 echo htmlspecialcharsbx($a[0]);
169 }
170 ?>">
171 <input type="button" value="..." onclick="BPAShowSelector('id_<?= htmlspecialcharsbx($arFieldName["Field"]) ?>_text', 'user', '<?= $arFieldType["Type"] == 'S:employee'? 'employee' : '' ?>');">
172 <?
173 }
174 }
175 else
176 {
177 if (!array_key_exists("CBPVirtualDocumentCloneRowPrinted", $GLOBALS) && $arFieldType["Multiple"])
178 {
179 $GLOBALS["CBPVirtualDocumentCloneRowPrinted"] = 1;
180 ?>
181 <script>
182 function CBPVirtualDocumentCloneRow(tableID)
183 {
184 var tbl = document.getElementById(tableID);
185 var cnt = tbl.rows.length;
186 var oRow = tbl.insertRow(cnt);
187 var oCell = oRow.insertCell(0);
188 var sHTML = tbl.rows[cnt - 1].cells[0].innerHTML;
189 var p = 0;
190 while (true)
191 {
192 var s = sHTML.indexOf('[n', p);
193 if (s < 0)
194 break;
195 var e = sHTML.indexOf(']', s);
196 if (e < 0)
197 break;
198 var n = parseInt(sHTML.substr(s + 2, e - s));
199 sHTML = sHTML.substr(0, s) + '[n' + (++n) + ']' + sHTML.substr(e + 1);
200 p = s + 1;
201 }
202 var p = 0;
203 while (true)
204 {
205 var s = sHTML.indexOf('__n', p);
206 if (s < 0)
207 break;
208 var e = sHTML.indexOf('_', s + 2);
209 if (e < 0)
210 break;
211 var n = parseInt(sHTML.substr(s + 3, e - s));
212 sHTML = sHTML.substr(0, s) + '__n' + (++n) + '_' + sHTML.substr(e + 1);
213 p = e + 1;
214 }
215 oCell.innerHTML = sHTML;
216 var patt = new RegExp('<' + 'script' + '>[^\000]*?<' + '\/' + 'script' + '>', 'ig');
217 var code = sHTML.match(patt);
218 if (code)
219 {
220 for (var i = 0; i < code.length; i++)
221 {
222 if (code[i] != '')
223 {
224 var s = code[i].substring(8, code[i].length - 9);
225 jsUtils.EvalGlobal(s);
226 }
227 }
228 }
229 }
230 function createAdditionalHtmlEditor(tableId)
231 {
232 var tbl = document.getElementById(tableId);
233 var cnt = tbl.rows.length-1;
234 var name = tableId.replace(/(?:CBPVirtualDocument_)(.*)(?:_Table)/, '$1')
235 var idEditor = 'id_'+name+'__n'+cnt+'_';
236 var inputNameEditor = name+'[n'+cnt+']';
237 window.BXHtmlEditor.Show(
238 {
239 'id':idEditor,
240 'inputName':inputNameEditor,
241 'content':'',
242 'useFileDialogs':false,
243 'width':'100%',
244 'height':'200',
245 'allowPhp':false,
246 'limitPhpAccess':false,
247 'templates':[],
248 'templateId':'',
249 'templateParams':[],
250 'componentFilter':'',
251 'snippets':[],
252 'placeholder':'Text here...',
253 'actionUrl':'/bitrix/tools/html_editor_action.php',
254 'cssIframePath':'/bitrix/js/fileman/html_editor/iframe-style.css?1412693817',
255 'bodyClass':'',
256 'bodyId':'',
257 'spellcheck_path':'/bitrix/js/fileman/html_editor/html-spell.js?v=1412693817',
258 'usePspell':'N',
259 'useCustomSpell':'Y',
260 'bbCode':false,
261 'askBeforeUnloadPage':true,
262 'settingsKey':'user_settings_1',
263 'showComponents':true,
264 'showSnippets':true,
265 'view':'wysiwyg',
266 'splitVertical':false,
267 'splitRatio':'1',
268 'taskbarShown':false,
269 'taskbarWidth':'250',
270 'lastSpecialchars':false,
271 'cleanEmptySpans':true,
272 'lazyLoad':false,
273 'showTaskbars':false,
274 'showNodeNavi':false,
275 'controlsMap':[
276 {'id':'Bold','compact':true,'sort':'80'},
277 {'id':'Italic','compact':true,'sort':'90'},
278 {'id':'Underline','compact':true,'sort':'100'},
279 {'id':'Strikeout','compact':true,'sort':'110'},
280 {'id':'RemoveFormat','compact':true,'sort':'120'},
281 {'id':'Color','compact':true,'sort':'130'},
282 {'id':'FontSelector','compact':false,'sort':'135'},
283 {'id':'FontSize','compact':false,'sort':'140'},
284 {'separator':true,'compact':false,'sort':'145'},
285 {'id':'OrderedList','compact':true,'sort':'150'},
286 {'id':'UnorderedList','compact':true,'sort':'160'},
287 {'id':'AlignList','compact':false,'sort':'190'},
288 {'separator':true,'compact':false,'sort':'200'},
289 {'id':'InsertLink','compact':true,'sort':'210','wrap':'bx-b-link-'+idEditor},
290 {'id':'InsertImage','compact':false,'sort':'220'},
291 {'id':'InsertVideo','compact':true,'sort':'230','wrap':'bx-b-video-'+idEditor},
292 {'id':'InsertTable','compact':false,'sort':'250'},
293 {'id':'Code','compact':true,'sort':'260'},
294 {'id':'Quote','compact':true,'sort':'270','wrap':'bx-b-quote-'+idEditor},
295 {'id':'Smile','compact':false,'sort':'280'},
296 {'separator':true,'compact':false,'sort':'290'},
297 {'id':'Fullscreen','compact':false,'sort':'310'},
298 {'id':'BbCode','compact':true,'sort':'340'},
299 {'id':'More','compact':true,'sort':'400'}],
300 'autoResize':true,
301 'autoResizeOffset':'40',
302 'minBodyWidth':'350',
303 'normalBodyWidth':'555'
304 });
305 var htmlEditor = BX.findChildrenByClassName(BX(tableId), 'bx-html-editor');
306 for(var k in htmlEditor)
307 {
308 var editorId = htmlEditor[k].getAttribute('id');
309 var frameArray = BX.findChildrenByClassName(BX(editorId), 'bx-editor-iframe');
310 if(frameArray.length > 1)
311 {
312 for(var i = 0; i < frameArray.length - 1; i++)
313 {
314 frameArray[i].parentNode.removeChild(frameArray[i]);
315 }
316 }
317
318 }
319 }
320 </script>
321 <?
322 }
323
324 if ($arFieldType["Multiple"])
325 echo '<table width="100%" border="0" cellpadding="2" cellspacing="2" id="CBPVirtualDocument_'.htmlspecialcharsbx($arFieldName["Field"]).'_Table">';
326
327 $fieldValueTmp = $fieldValue;
328
329 if (sizeof($fieldValue) == 0)
330 $fieldValue[] = null;
331
332 $ind = -1;
333 foreach ($fieldValue as $key => $value)
334 {
335 $ind++;
336 $fieldNameId = 'id_'.htmlspecialcharsbx($arFieldName["Field"]).'__n'.$ind.'_';
337 $fieldNameName = htmlspecialcharsbx($arFieldName["Field"]).($arFieldType["Multiple"] ? "[n".$ind."]" : "");
338
339 if ($arFieldType["Multiple"])
340 echo '<tr><td>';
341
342 if (is_array($customMethodName) && count($customMethodName) > 0 || !is_array($customMethodName) && $customMethodName <> '')
343 {
344 if($arFieldType["Type"] == "S:HTML")
345 {
346 if (CModule::includeModule("fileman"))
347 {
348 $editor = new \CHTMLEditor;
349 $res = array_merge(
350 array(
351 'useFileDialogs' => false,
352 'height' => 200,
353 'useFileDialogs' => false,
354 'minBodyWidth' => 350,
355 'normalBodyWidth' => 555,
356 'bAllowPhp' => false,
357 'limitPhpAccess' => false,
358 'showTaskbars' => false,
359 'showNodeNavi' => false,
360 'askBeforeUnloadPage' => true,
361 'bbCode' => false,
362 'siteId' => SITE_ID,
363 'autoResize' => true,
364 'autoResizeOffset' => 40,
365 'saveOnBlur' => true,
366 'controlsMap' => array(
367 array('id' => 'Bold', 'compact' => true, 'sort' => 80),
368 array('id' => 'Italic', 'compact' => true, 'sort' => 90),
369 array('id' => 'Underline', 'compact' => true, 'sort' => 100),
370 array('id' => 'Strikeout', 'compact' => true, 'sort' => 110),
371 array('id' => 'RemoveFormat', 'compact' => true, 'sort' => 120),
372 array('id' => 'Color', 'compact' => true, 'sort' => 130),
373 array('id' => 'FontSelector', 'compact' => false, 'sort' => 135),
374 array('id' => 'FontSize', 'compact' => false, 'sort' => 140),
375 array('separator' => true, 'compact' => false, 'sort' => 145),
376 array('id' => 'OrderedList', 'compact' => true, 'sort' => 150),
377 array('id' => 'UnorderedList', 'compact' => true, 'sort' => 160),
378 array('id' => 'AlignList', 'compact' => false, 'sort' => 190),
379 array('separator' => true, 'compact' => false, 'sort' => 200),
380 array('id' => 'InsertLink', 'compact' => true, 'sort' => 210, 'wrap' => 'bx-b-link-'.$fieldNameId),
381 array('id' => 'InsertImage', 'compact' => false, 'sort' => 220),
382 array('id' => 'InsertVideo', 'compact' => true, 'sort' => 230, 'wrap' => 'bx-b-video-'.$fieldNameId),
383 array('id' => 'InsertTable', 'compact' => false, 'sort' => 250),
384 array('id' => 'Code', 'compact' => true, 'sort' => 260),
385 array('id' => 'Quote', 'compact' => true, 'sort' => 270, 'wrap' => 'bx-b-quote-'.$fieldNameId),
386 array('id' => 'Smile', 'compact' => false, 'sort' => 280),
387 array('separator' => true, 'compact' => false, 'sort' => 290),
388 array('id' => 'Fullscreen', 'compact' => false, 'sort' => 310),
389 array('id' => 'BbCode', 'compact' => true, 'sort' => 340),
390 array('id' => 'More', 'compact' => true, 'sort' => 400)
391 )
392 ),
393 array(
394 'name' => $fieldNameName,
395 'inputName' => $fieldNameName,
396 'id' => $fieldNameId,
397 'width' => '100%',
398 'content' => htmlspecialcharsBack($value),
399 )
400 );
401 $editor->show($res);
402 }
403 else
404 {
405 ?><textarea rows="5" cols="40" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>"><?= htmlspecialcharsbx($value) ?></textarea><?
406 }
407 }
408 else
409 {
410 $value1 = $value;
411 if ($bAllowSelection && CBPDocument::IsExpression(trim($value1)))
412 $value1 = null;
413 else
414 unset($fieldValueTmp[$key]);
415
416 if (($arFieldType["Type"] == "S:employee") && COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y")
417 $value1 = CBPHelper::StripUserPrefix($value1);
418
419 echo call_user_func_array(
420 $customMethodName,
421 array(
422 array("LINK_IBLOCK_ID" => $arFieldType["Options"]),
423 array("VALUE" => $value1),
424 array(
425 "FORM_NAME" => $arFieldName["Form"],
426 "VALUE" => $fieldNameName
427 ),
428 true
429 )
430 );
431 }
432 }
433 else
434 {
435 switch ($arFieldType["Type"])
436 {
437 case "int":
438 case "double":
439 unset($fieldValueTmp[$key]);
440 ?><input type="text" size="10" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>" value="<?= htmlspecialcharsbx($value) ?>"><?
441 break;
442 case "file":
443 if ($publicMode)
444 {
445 //unset($fieldValueTmp[$key]);
446 ?><input type="file" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>"><?
447 }
448 break;
449 case "bool":
450 if (in_array($value, array("Y", "N")))
451 unset($fieldValueTmp[$key]);
452 ?>
453 <select id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>">
454 <?
455 if (!$arFieldType["Required"])
456 echo '<option value="">['.GetMessage("BPCGHLP_NOT_SET").']</option>';
457 ?>
458 <option value="Y"<?= (in_array("Y", $fieldValue) ? ' selected' : '') ?>><?= GetMessage("BPCGHLP_YES") ?></option>
459 <option value="N"<?= (in_array("N", $fieldValue) ? ' selected' : '') ?>><?= GetMessage("BPCGHLP_NO") ?></option>
460 </select>
461 <?
462 break;
463 case "text":
464 unset($fieldValueTmp[$key]);
465 ?><textarea rows="5" cols="40" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>"><?= htmlspecialcharsbx($value) ?></textarea><?
466 break;
467 case "date":
468 case "datetime":
469
470 if (defined("ADMIN_SECTION") && ADMIN_SECTION)
471 {
472 $v = "";
473 if (!CBPDocument::IsExpression(trim($value)))
474 {
475 $v = $value;
476 unset($fieldValueTmp[$key]);
477 }
478 require_once($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/interface/init_admin.php");
479 echo CAdminCalendar::CalendarDate($fieldNameName, $v, 19, ($arFieldType["Type"] != "date"));
480 }
481 else
482 {
483 $value1 = $value;
484 if ($bAllowSelection && CBPDocument::IsExpression(trim($value1)))
485 $value1 = null;
486 else
487 unset($fieldValueTmp[$key]);
488
489 if($arFieldType["Type"] == "date")
490 $type = "Date";
491 else
492 $type = "DateTime";
493 $ar = CIBlockProperty::GetUserType($type);
494 echo call_user_func_array(
495 $ar["GetPublicEditHTML"],
496 array(
497 array("LINK_IBLOCK_ID" => $arFieldType["Options"]),
498 array("VALUE" => $value1),
499 array(
500 "FORM_NAME" => $arFieldName["Form"],
501 "VALUE" => $fieldNameName
502 ),
503 true
504 )
505 );
506 }
507
508 break;
509 default:
510 unset($fieldValueTmp[$key]);
511 ?><input type="text" size="40" id="<?= $fieldNameId ?>" name="<?= $fieldNameName ?>" value="<?= htmlspecialcharsbx($value) ?>"><?
512 }
513 }
514
515 if ($bAllowSelection)
516 {
517 if (!in_array($arFieldType["Type"], array("file", "bool", "date", "datetime")) && (is_array($customMethodName) && count($customMethodName) <= 0 || !is_array($customMethodName) && $customMethodName == ''))
518 {
519 ?><input type="button" value="..." onclick="BPAShowSelector('<?= $fieldNameId ?>', '<?= htmlspecialcharsbx($arFieldType["BaseType"]) ?>');"><?
520 }
521 }
522
523 if ($arFieldType["Multiple"])
524 echo '</td></tr>';
525 }
526
527 if ($arFieldType["Multiple"])
528 echo "</table>";
529
530 if ($arFieldType["Multiple"] && $arFieldType["Type"] != "S:HTML" && (($arFieldType["Type"] != "file") || $publicMode))
531 {
532 echo '<input type="button" value="'.GetMessage("BPCGHLP_ADD").'" onclick="CBPVirtualDocumentCloneRow(\'CBPVirtualDocument_'.$arFieldName["Field"].'_Table\')"/><br />';
533 }
534 elseif($arFieldType["Multiple"] && $arFieldType["Type"] == "S:HTML")
535 {
536 $functionOnclick = 'CBPVirtualDocumentCloneRow(\'CBPVirtualDocument_'.$arFieldName["Field"].'_Table\');createAdditionalHtmlEditor(\'CBPVirtualDocument_'.$arFieldName["Field"].'_Table\');';
537 echo '<input type="button" value="'.GetMessage("BPCGHLP_ADD").'" onclick="'.$functionOnclick.'"/><br />';
538 }
539
540 if ($bAllowSelection)
541 {
542 if (in_array($arFieldType["Type"], array("file", "bool", "date", "datetime")) || (is_array($customMethodName) && count($customMethodName) > 0 || !is_array($customMethodName) && $customMethodName <> ''))
543 {
544 ?>
545 <input type="text" id="id_<?= htmlspecialcharsbx($arFieldName["Field"]) ?>_text" name="<?= htmlspecialcharsbx($arFieldName["Field"]) ?>_text" value="<?
546 if (count($fieldValueTmp) > 0)
547 {
548 $a = array_values($fieldValueTmp);
549 echo htmlspecialcharsbx($a[0]);
550 }
551 ?>">
552 <input type="button" value="..." onclick="BPAShowSelector('id_<?= htmlspecialcharsbx($arFieldName["Field"]) ?>_text', '<?= htmlspecialcharsbx($arFieldType["BaseType"]) ?>', '<?= $arFieldType["Type"] == 'S:employee'? 'employee' : '' ?>');">
553 <?
554 }
555 }
556 }
557
558 $s = ob_get_contents();
559 ob_end_clean();
560
561 return $s;
562 }
563
564 public static function GetFieldInputValue($documentType, $arFieldType, $arFieldName, $arRequest, &$arErrors)
565 {
566
567 $iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
568 if ($iblockId <= 0)
569 throw new CBPArgumentOutOfRangeException("documentType", $documentType);
570
571 $result = array();
572
573 if ($arFieldType["Type"] == "user")
574 {
575 $value = $arRequest[$arFieldName["Field"]];
576 if ($value <> '')
577 {
578 $result = CBPHelper::UsersStringToArray($value, array("iblock", "CIBlockDocument", $documentType), $arErrors);
579 if (count($arErrors) > 0)
580 {
581 foreach ($arErrors as $e)
582 $arErrors[] = $e;
583 }
584 }
585 }
586 elseif (array_key_exists($arFieldName["Field"], $arRequest) || array_key_exists($arFieldName["Field"]."_text", $arRequest))
587 {
588 $arValue = array();
589 if (array_key_exists($arFieldName["Field"], $arRequest))
590 {
591 $arValue = $arRequest[$arFieldName["Field"]];
592 if (!is_array($arValue) || is_array($arValue) && CBPHelper::IsAssociativeArray($arValue))
593 $arValue = array($arValue);
594 }
595 if (array_key_exists($arFieldName["Field"]."_text", $arRequest))
596 $arValue[] = $arRequest[$arFieldName["Field"]."_text"];
597
598 foreach ($arValue as $value)
599 {
600 if (is_array($value) || !is_array($value) && !CBPDocument::IsExpression(trim($value)))
601 {
602 if ($arFieldType["Type"] == "int")
603 {
604 if ($value <> '')
605 {
606 $value = str_replace(" ", "", $value);
607 if ($value."|" == intval($value)."|")
608 {
609 $value = intval($value);
610 }
611 else
612 {
613 $value = null;
614 $arErrors[] = array(
615 "code" => "ErrorValue",
616 "message" => GetMessage("BPCGWTL_INVALID1"),
617 "parameter" => $arFieldName["Field"],
618 );
619 }
620 }
621 else
622 {
623 $value = null;
624 }
625 }
626 elseif ($arFieldType["Type"] == "double")
627 {
628 if ($value <> '')
629 {
630 $value = str_replace(" ", "", str_replace(",", ".", $value));
631 if (is_numeric($value))
632 {
633 $value = doubleval($value);
634 }
635 else
636 {
637 $value = null;
638 $arErrors[] = array(
639 "code" => "ErrorValue",
640 "message" => GetMessage("BPCGWTL_INVALID11"),
641 "parameter" => $arFieldName["Field"],
642 );
643 }
644 }
645 else
646 {
647 $value = null;
648 }
649 }
650 elseif ($arFieldType["Type"] == "select")
651 {
652 if (!is_array($arFieldType["Options"]) || count($arFieldType["Options"]) <= 0 || $value == '')
653 {
654 $value = null;
655 }
656 else
657 {
658 $ar = array_values($arFieldType["Options"]);
659 if (is_array($ar[0]))
660 {
661 $b = false;
662 foreach ($ar as $a)
663 {
664 if ($a[0] == $value)
665 {
666 $b = true;
667 break;
668 }
669 }
670 if (!$b)
671 {
672 $value = null;
673 $arErrors[] = array(
674 "code" => "ErrorValue",
675 "message" => GetMessage("BPCGWTL_INVALID35"),
676 "parameter" => $arFieldName["Field"],
677 );
678 }
679 }
680 else
681 {
682 if (!array_key_exists($value, $arFieldType["Options"]))
683 {
684 $value = null;
685 $arErrors[] = array(
686 "code" => "ErrorValue",
687 "message" => GetMessage("BPCGWTL_INVALID35"),
688 "parameter" => $arFieldName["Field"],
689 );
690 }
691 }
692 }
693 }
694 elseif ($arFieldType["Type"] == "bool")
695 {
696 if ($value !== "Y" && $value !== "N")
697 {
698 if ($value === true)
699 {
700 $value = "Y";
701 }
702 elseif ($value === false)
703 {
704 $value = "N";
705 }
706 elseif ($value <> '')
707 {
708 $value = mb_strtolower($value);
709 if (in_array($value, array("y", "yes", "true", "1")))
710 {
711 $value = "Y";
712 }
713 elseif (in_array($value, array("n", "no", "false", "0")))
714 {
715 $value = "N";
716 }
717 else
718 {
719 $value = null;
720 $arErrors[] = array(
721 "code" => "ErrorValue",
722 "message" => GetMessage("BPCGWTL_INVALID45"),
723 "parameter" => $arFieldName["Field"],
724 );
725 }
726 }
727 else
728 {
729 $value = null;
730 }
731 }
732 }
733 elseif ($arFieldType["Type"] == "file")
734 {
735 if (is_array($value) && array_key_exists("name", $value) && $value["name"] <> '')
736 {
737 if (!array_key_exists("MODULE_ID", $value) || $value["MODULE_ID"] == '')
738 $value["MODULE_ID"] = "bizproc";
739
740 $value = CFile::SaveFile($value, "bizproc_wf", true, true);
741 if (!$value)
742 {
743 $value = null;
744 $arErrors[] = array(
745 "code" => "ErrorValue",
746 "message" => GetMessage("BPCGWTL_INVALID915"),
747 "parameter" => $arFieldName["Field"],
748 );
749 }
750 }
751 else
752 {
753 $value = null;
754 }
755 }
756 elseif (mb_strpos($arFieldType["Type"], ":") !== false)
757 {
758 $arCustomType = CIBlockProperty::GetUserType(mb_substr($arFieldType["Type"], 2));
759 if (array_key_exists("GetLength", $arCustomType))
760 {
761 if (call_user_func_array(
762 $arCustomType["GetLength"],
763 array(
764 array("LINK_IBLOCK_ID" => $arFieldType["Options"]),
765 array("VALUE" => $value)
766 )
767 ) <= 0)
768 {
769 $value = null;
770 }
771 }
772
773 if (($value != null) && array_key_exists("CheckFields", $arCustomType))
774 {
775 $arErrorsTmp1 = call_user_func_array(
776 $arCustomType["CheckFields"],
777 array(
778 array("LINK_IBLOCK_ID" => $arFieldType["Options"]),
779 array("VALUE" => $value)
780 )
781 );
782 if (count($arErrorsTmp1) > 0)
783 {
784 $value = null;
785 foreach ($arErrorsTmp1 as $e)
786 $arErrors[] = array(
787 "code" => "ErrorValue",
788 "message" => $e,
789 "parameter" => $arFieldName["Field"],
790 );
791 }
792 }
793 elseif (!array_key_exists("GetLength", $arCustomType) && $value === '')
794 $value = null;
795
796 if (($value !== null)
797 && ($arFieldType["Type"] == "S:employee")
798 && COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y")
799 {
800 $value = "user_".$value;
801 }
802 }
803 else
804 {
805 if (!is_array($value) && $value == '')
806 $value = null;
807 }
808 }
809
810 if ($value !== null)
811 $result[] = $value;
812 }
813 }
814
815 if (!$arFieldType["Multiple"])
816 {
817 if (count($result) > 0)
818 $result = $result[0];
819 else
820 $result = null;
821 }
822
823 return $result;
824 }
825
826 public static function GetFieldInputValuePrintable($documentType, $arFieldType, $fieldValue)
827 {
828 $result = $fieldValue;
829
830 switch ($arFieldType['Type'])
831 {
832 case "user":
833 if (!is_array($fieldValue))
834 $fieldValue = array($fieldValue);
835
836 $result = CBPHelper::UsersArrayToString($fieldValue, null, array("iblock", "CIBlockDocument", $documentType));
837 break;
838
839 case "bool":
840 if (is_array($fieldValue))
841 {
842 $result = array();
843 foreach ($fieldValue as $r)
844 $result[] = ((mb_strtoupper($r) != "N" && !empty($r)) ? GetMessage("BPVDX_YES") : GetMessage("BPVDX_NO"));
845 }
846 else
847 {
848 $result = ((mb_strtoupper($fieldValue) != "N" && !empty($fieldValue)) ? GetMessage("BPVDX_YES") : GetMessage("BPVDX_NO"));
849 }
850 break;
851
852 case "file":
853 if (is_array($fieldValue))
854 {
855 $result = array();
856 foreach ($fieldValue as $r)
857 {
858 $r = intval($r);
859 $dbImg = CFile::GetByID($r);
860 if ($arImg = $dbImg->Fetch())
861 $result[] = "[url=/bitrix/tools/bizproc_show_file.php?f=".urlencode($arImg["FILE_NAME"])."&i=".$r."&h=".md5($arImg["SUBDIR"])."]".htmlspecialcharsbx($arImg["ORIGINAL_NAME"])."[/url]";
862 }
863 }
864 else
865 {
866 $fieldValue = intval($fieldValue);
867 $dbImg = CFile::GetByID($fieldValue);
868 if ($arImg = $dbImg->Fetch())
869 $result = "[url=/bitrix/tools/bizproc_show_file.php?f=".urlencode($arImg["FILE_NAME"])."&i=".$fieldValue."&h=".md5($arImg["SUBDIR"])."]".htmlspecialcharsbx($arImg["ORIGINAL_NAME"])."[/url]";
870 }
871 break;
872
873 case "select":
874 if (is_array($arFieldType["Options"]))
875 {
876 if (is_array($fieldValue))
877 {
878 $result = array();
879 foreach ($fieldValue as $r)
880 {
881 if (array_key_exists($r, $arFieldType["Options"]))
882 $result[] = $arFieldType["Options"][$r];
883 }
884 }
885 else
886 {
887 if (array_key_exists($fieldValue, $arFieldType["Options"]))
888 $result = $arFieldType["Options"][$fieldValue];
889 }
890 }
891 break;
892 }
893
894 if (mb_strpos($arFieldType['Type'], ":") !== false)
895 {
896 if ($arFieldType["Type"] == "S:employee")
897 $fieldValue = CBPHelper::StripUserPrefix($fieldValue);
898
899 $arCustomType = CIBlockProperty::GetUserType(mb_substr($arFieldType['Type'], 2));
900 if (array_key_exists("GetPublicViewHTML", $arCustomType))
901 {
902 if (is_array($fieldValue) && !CBPHelper::IsAssociativeArray($fieldValue))
903 {
904 $result = array();
905 foreach ($fieldValue as $value)
906 {
907 $r = call_user_func_array(
908 $arCustomType["GetPublicViewHTML"],
909 array(
910 array("LINK_IBLOCK_ID" => $arFieldType["Options"]),
911 array("VALUE" => $value),
912 ""
913 )
914 );
915
916 $result[] = HTMLToTxt($r);
917 }
918 }
919 else
920 {
921 $result = call_user_func_array(
922 $arCustomType["GetPublicViewHTML"],
923 array(
924 array("LINK_IBLOCK_ID" => $arFieldType["Options"]),
925 array("VALUE" => $fieldValue),
926 ""
927 )
928 );
929
931 }
932 }
933 }
934
935 return $result;
936 }
937
938 public static function GetFieldValuePrintable($documentId, $fieldName, $fieldType, $fieldValue, $arFieldType)
939 {
940 $documentType = null;
941
942 if ($fieldType == "user")
943 {
944 static $arCache = array();
945 if (!array_key_exists($documentId, $arCache))
946 {
947 if (mb_substr($documentId, 0, mb_strlen("iblock_")) == "iblock_")
948 $arCache[$documentId] = $documentId;
949 else
950 $arCache[$documentId] = self::GetDocumentType($documentId);
951 }
952 $documentType = $arCache[$documentId];
953 }
954
955 if (is_null($arFieldType) || !is_array($arFieldType) || count($arFieldType) <= 0)
956 $arFieldType = array();
957 $arFieldType["Type"] = $fieldType;
958
959 return self::GetFieldInputValuePrintable($documentType, $arFieldType, $fieldValue);
960 }
961
962 public static function GetVersion()
963 {
964 static $v = null;
965 if (is_null($v))
966 $v = intval(COption::GetOptionString("iblock", "~iblock_document_version", 2));
967 return $v;
968 }
969
974 public static function GetDocumentAdminPage($documentId)
975 {
976 $documentId = intval($documentId);
977 if ($documentId <= 0)
978 throw new CBPArgumentNullException("documentId");
979
980 $db = CIBlockElement::GetList(
981 array(),
982 array("ID" => $documentId, "SHOW_NEW"=>"Y", "SHOW_HISTORY" => "Y"),
983 false,
984 false,
985 array("ID", "IBLOCK_ID", "IBLOCK_TYPE_ID", "DETAIL_PAGE_URL")
986 );
987 if ($ar = $db->Fetch())
988 {
989 foreach(GetModuleEvents("iblock", "CIBlockDocument_OnGetDocumentAdminPage", true) as $arEvent)
990 {
991 $url = ExecuteModuleEventEx($arEvent, array($ar));
992 if($url)
993 return $url;
994 }
995 return "/bitrix/admin/iblock_element_edit.php?view=Y&ID=".$documentId."&IBLOCK_ID=".$ar["IBLOCK_ID"]."&type=".$ar["IBLOCK_TYPE_ID"];
996 }
997
998 return null;
999 }
1000
1006
1007 public static function getDocumentName($documentId)
1008 {
1009 $documentId = intval($documentId);
1010 if ($documentId <= 0)
1011 throw new CBPArgumentNullException("documentId");
1012
1013 $db = CIBlockElement::GetList(
1014 array(),
1015 array("ID" => $documentId, "SHOW_NEW"=>"Y", "SHOW_HISTORY" => "Y"),
1016 false,
1017 false,
1018 array("ID", "NAME")
1019 );
1020 if ($ar = $db->fetch())
1021 {
1022 return $ar["NAME"];
1023 }
1024
1025 return null;
1026 }
1027
1028 public static function getDocumentTypeName($documentType)
1029 {
1030 if (mb_strpos($documentType, 'iblock_') !== 0)
1031 {
1032 return $documentType;
1033 }
1034
1035 $id = (int)mb_substr($documentType, 7);
1036
1037 $iterator = CIBlock::GetList(false,array('ID' => $id));
1038 $result = $iterator->fetch();
1039 if (!$result)
1040 {
1041 return $documentType;
1042 }
1043
1044 return '['.$result['IBLOCK_TYPE_ID'].'] '.$result['NAME'];
1045 }
1046
1047 public static function getDocumentTypeCaption($documentType)
1048 {
1049 if (mb_strpos($documentType, 'iblock_') !== 0)
1050 {
1051 return $documentType;
1052 }
1053
1054 $id = (int)mb_substr($documentType, 7);
1055
1056 $result = (CIBlock::GetList(
1057 false,
1058 [
1059 'ID' => $id,
1060 'CHECK_PERMISSIONS' => 'N'
1061 ])
1062 )->fetch();
1063 if (!$result)
1064 {
1065 return $documentType;
1066 }
1067
1068 return $result['NAME'];
1069 }
1070
1075 public static function isDocumentExists($documentId): bool
1076 {
1077 $dbResult = CIBlockElement::GetList(
1078 [],
1079 ["ID" => $documentId, "SHOW_NEW" => "Y", "SHOW_HISTORY" => "Y"],
1080 false,
1081 false,
1082 ["ID", "IBLOCK_ID"],
1083 );
1084
1085 return (bool)$dbResult->Fetch();
1086 }
1087
1094 public static function GetDocument($documentId)
1095 {
1096 $args = func_get_args();
1097 $select = $args[2] ?? [];
1098 $documentId = (int)$documentId;
1099 if ($documentId <= 0)
1100 {
1101 throw new CBPArgumentNullException('documentId');
1102 }
1103
1104 $arResult = null;
1105 if (!empty($select))
1106 {
1107 $select = array_merge(['ID', 'IBLOCK_ID'], $select);
1108 }
1109
1110 $userNameFields = [
1111 'CREATED_BY_PRINTABLE' => 'CREATED_USER_NAME',
1112 'MODIFIED_BY_PRINTABLE' => 'USER_NAME',
1113 ];
1114
1115 $select = array_map(static fn($selectField) => $userNameFields[$selectField] ?? $selectField, $select);
1116
1117 $iterator = CIBlockElement::GetList(
1118 [],
1119 ['ID' => $documentId, 'SHOW_NEW' => 'Y', 'SHOW_HISTORY' => 'Y'],
1120 arSelectFields: $select
1121 );
1122 if ($objDocument = $iterator->GetNextElement(false, true))
1123 {
1124 $arDocumentFields = $objDocument->GetFields();
1125 $arDocumentProperties = $objDocument->GetProperties();
1126
1127 foreach ($arDocumentFields as $fieldKey => $fieldValue)
1128 {
1129 if (mb_substr($fieldKey, 0, 1) == "~")
1130 continue;
1131
1132 $arResult[$fieldKey] = $fieldValue;
1133 if (in_array($fieldKey, array("MODIFIED_BY", "CREATED_BY")))
1134 {
1135 $arResult[$fieldKey] = "user_".$fieldValue;
1136 $arResult[$fieldKey."_PRINTABLE"] = $arDocumentFields[($fieldKey == "MODIFIED_BY") ? "USER_NAME" : "CREATED_USER_NAME"];
1137 }
1138 elseif (in_array($fieldKey, array("PREVIEW_TEXT", "DETAIL_TEXT")))
1139 {
1140 if ($arDocumentFields[$fieldKey."_TYPE"] == "html")
1141 $arResult[$fieldKey] = HTMLToTxt($arDocumentFields["~".$fieldKey]);
1142 }
1143 }
1144
1145 foreach ($arDocumentProperties as $propertyKey => $propertyValue)
1146 {
1147 if ($propertyValue["USER_TYPE"] <> '')
1148 {
1149 if ($propertyValue["USER_TYPE"] == "UserID" || $propertyValue["USER_TYPE"] == "employee" &&
1150 (COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y"))
1151 {
1152 if(empty($propertyValue["VALUE"]))
1153 {
1154 continue;
1155 }
1156 if(!is_array($propertyValue["VALUE"]))
1157 {
1158 $propertyValue["VALUE"] = array($propertyValue["VALUE"]);
1159 }
1160 $listUsers = implode(' | ', $propertyValue["VALUE"]);
1161 $userQuery = CUser::getList('ID', 'ASC',
1162 array('ID' => $listUsers) ,
1163 array('FIELDS' => array('ID' ,'LOGIN', 'NAME', 'LAST_NAME')));
1164 while($user = $userQuery->fetch())
1165 {
1166 if($propertyValue["MULTIPLE"] == "Y")
1167 {
1168 $arResult["PROPERTY_".$propertyKey][] = "user_".intval($user['ID']);
1169 $arResult["PROPERTY_".$propertyKey."_PRINTABLE"][] = "(".$user["LOGIN"].")".
1170 (($user["NAME"] <> '' || $user["LAST_NAME"] <> '') ? " " : "").$user["NAME"].
1171 (($user["NAME"] <> '' && $user["LAST_NAME"] <> '') ? " " : "").$user["LAST_NAME"];
1172 }
1173 else
1174 {
1175 $arResult["PROPERTY_".$propertyKey] = "user_".intval($user['ID']);
1176 $arResult["PROPERTY_".$propertyKey."_PRINTABLE"] = "(".$user["LOGIN"].")".
1177 (($user["NAME"] <> '' || $user["LAST_NAME"] <> '') ? " " : "").$user["NAME"].
1178 (($user["NAME"] <> '' && $user["LAST_NAME"] <> '') ? " " : "").$user["LAST_NAME"];
1179 }
1180 }
1181 }
1182 elseif($propertyValue["USER_TYPE"] == "DiskFile")
1183 {
1184 if(is_array($propertyValue["VALUE"]))
1185 {
1186 if($propertyValue["MULTIPLE"] == "Y")
1187 {
1188 $propertyValue["VALUE"] = current($propertyValue["VALUE"]);
1189 }
1190
1191 if(!is_array($propertyValue["VALUE"]))
1192 {
1193 continue;
1194 }
1195
1196 foreach($propertyValue["VALUE"] as $attachedId)
1197 {
1198 $userType = \CIBlockProperty::getUserType($propertyValue['USER_TYPE']);
1199 $fileId = null;
1200 if (array_key_exists('GetObjectId', $userType))
1201 {
1202 $fileId = call_user_func_array($userType['GetObjectId'], array($attachedId));
1203 }
1204 if(!$fileId)
1205 {
1206 continue;
1207 }
1208 $printableUrl = '';
1209 if (array_key_exists('GetUrlAttachedFileElement', $userType))
1210 {
1211 $printableUrl = call_user_func_array($userType['GetUrlAttachedFileElement'], array($documentId, $fileId));
1212 }
1213
1214 $arResult["PROPERTY_".$propertyKey][$attachedId] = $fileId;
1215 $arResult["PROPERTY_".$propertyKey."_PRINTABLE"][$attachedId] = $printableUrl;
1216 }
1217 }
1218 else
1219 {
1220 continue;
1221 }
1222 }
1223 else
1224 {
1225 $arResult["PROPERTY_".$propertyKey] = $propertyValue["VALUE"];
1226 }
1227 }
1228 elseif ($propertyValue["PROPERTY_TYPE"] == "L")
1229 {
1230 $arPropertyValue = $propertyValue["VALUE"];
1231 $arPropertyKey = ((self::GetVersion() > 1) ? $propertyValue["VALUE_XML_ID"] : $propertyValue["VALUE_ENUM_ID"]);
1232 if (!is_array($arPropertyValue))
1233 {
1234 $arPropertyValue = array($arPropertyValue);
1235 $arPropertyKey = array($arPropertyKey);
1236 }
1237
1238 for ($i = 0, $cnt = count($arPropertyValue); $i < $cnt; $i++)
1239 $arResult["PROPERTY_".$propertyKey][$arPropertyKey[$i]] = $arPropertyValue[$i];
1240 }
1241 elseif ($propertyValue["PROPERTY_TYPE"] == "F")
1242 {
1243 $arPropertyValue = $propertyValue["VALUE"];
1244 if (!is_array($arPropertyValue))
1245 $arPropertyValue = array($arPropertyValue);
1246
1247 foreach ($arPropertyValue as $v)
1248 {
1249 $ar = CFile::GetFileArray($v);
1250 if ($ar)
1251 {
1252 $arResult["PROPERTY_".$propertyKey][intval($v)] = $ar["SRC"];
1253 $arResult["PROPERTY_".$propertyKey."_printable"][intval($v)] = "[url=/bitrix/tools/bizproc_show_file.php?f=".urlencode($ar["FILE_NAME"])."&i=".$v."&h=".md5($ar["SUBDIR"])."]".htmlspecialcharsbx($ar["ORIGINAL_NAME"])."[/url]";
1254 }
1255 }
1256 }
1257 else
1258 {
1259 $arResult["PROPERTY_".$propertyKey] = $propertyValue["VALUE"];
1260 }
1261 }
1262
1263 $documentFields = static::GetDocumentFields(static::GetDocumentType($documentId));
1264 foreach ($documentFields as $fieldKey => $field)
1265 {
1266 if (!array_key_exists($fieldKey, $arResult))
1267 $arResult[$fieldKey] = null;
1268 }
1269 }
1270
1271 return $arResult;
1272 }
1273
1274 public static function GetDocumentType($documentId)
1275 {
1276 if (mb_substr($documentId, 0, mb_strlen("iblock_")) == "iblock_")
1277 {
1278 return $documentId;
1279 }
1280
1281 $documentId = (int)$documentId;
1282 $iblockId = CIBlockElement::GetIBlockByID($documentId);
1283 if ($iblockId === false)
1284 {
1285 throw new CBPArgumentNullException("documentId");
1286 }
1287
1288 return "iblock_$iblockId";
1289 }
1290
1291 public static function GetDocumentFields($documentType)
1292 {
1293 $iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
1294 if ($iblockId <= 0)
1295 throw new CBPArgumentOutOfRangeException("documentType", $documentType);
1296
1297 $arDocumentFieldTypes = self::GetDocumentFieldTypes($documentType);
1298
1299 $arResult = array(
1300 "ID" => array(
1301 "Name" => GetMessage("IBD_FIELD_ID"),
1302 "Type" => "int",
1303 "Filterable" => true,
1304 "Editable" => false,
1305 "Required" => false,
1306 ),
1307 "TIMESTAMP_X" => array(
1308 "Name" => GetMessage("IBD_FIELD_TIMESTAMP_X"),
1309 "Type" => "datetime",
1310 "Filterable" => true,
1311 "Editable" => true,
1312 "Required" => false,
1313 ),
1314 "MODIFIED_BY" => array(
1315 "Name" => GetMessage("IBD_FIELD_MODYFIED"),
1316 "Type" => "user",
1317 "Filterable" => true,
1318 "Editable" => true,
1319 "Required" => false,
1320 ),
1321 "MODIFIED_BY_PRINTABLE" => array(
1322 "Name" => GetMessage("IBD_FIELD_MODIFIED_BY_USER_PRINTABLE"),
1323 "Type" => "string",
1324 "Filterable" => false,
1325 "Editable" => false,
1326 "Required" => false,
1327 ),
1328 "DATE_CREATE" => array(
1329 "Name" => GetMessage("IBD_FIELD_DATE_CREATE"),
1330 "Type" => "datetime",
1331 "Filterable" => true,
1332 "Editable" => true,
1333 "Required" => false,
1334 ),
1335 "CREATED_BY" => array(
1336 "Name" => GetMessage("IBD_FIELD_CREATED"),
1337 "Type" => "user",
1338 "Filterable" => true,
1339 "Editable" => false,
1340 "Required" => false,
1341 ),
1342 "CREATED_BY_PRINTABLE" => array(
1343 "Name" => GetMessage("IBD_FIELD_CREATED_BY_USER_PRINTABLE"),
1344 "Type" => "string",
1345 "Filterable" => false,
1346 "Editable" => false,
1347 "Required" => false,
1348 ),
1349 "IBLOCK_ID" => array(
1350 "Name" => GetMessage("IBD_FIELD_IBLOCK_ID"),
1351 "Type" => "int",
1352 "Filterable" => true,
1353 "Editable" => true,
1354 "Required" => true,
1355 ),
1356 "ACTIVE" => array(
1357 "Name" => GetMessage("IBD_FIELD_ACTIVE"),
1358 "Type" => "bool",
1359 "Filterable" => true,
1360 "Editable" => true,
1361 "Required" => false,
1362 ),
1363 "BP_PUBLISHED" => array(
1364 "Name" => GetMessage("IBD_FIELD_BP_PUBLISHED"),
1365 "Type" => "bool",
1366 "Filterable" => false,
1367 "Editable" => true,
1368 "Required" => false,
1369 ),
1370 "ACTIVE_FROM" => array(
1371 "Name" => GetMessage("IBD_FIELD_DATE_ACTIVE_FROM"),
1372 "Type" => "datetime",
1373 "Filterable" => true,
1374 "Editable" => true,
1375 "Required" => false,
1376 ),
1377 "ACTIVE_TO" => array(
1378 "Name" => GetMessage("IBD_FIELD_DATE_ACTIVE_TO"),
1379 "Type" => "datetime",
1380 "Filterable" => true,
1381 "Editable" => true,
1382 "Required" => false,
1383 ),
1384 "SORT" => array(
1385 "Name" => GetMessage("IBD_FIELD_SORT"),
1386 "Type" => "int",
1387 "Filterable" => true,
1388 "Editable" => true,
1389 "Required" => false,
1390 ),
1391 "NAME" => array(
1392 "Name" => GetMessage("IBD_FIELD_NAME"),
1393 "Type" => "string",
1394 "Filterable" => true,
1395 "Editable" => true,
1396 "Required" => true,
1397 ),
1398 "PREVIEW_PICTURE" => array(
1399 "Name" => GetMessage("IBD_FIELD_PREVIEW_PICTURE"),
1400 "Type" => "file",
1401 "Filterable" => false,
1402 "Editable" => true,
1403 "Required" => false,
1404 ),
1405 "PREVIEW_TEXT" => array(
1406 "Name" => GetMessage("IBD_FIELD_PREVIEW_TEXT"),
1407 "Type" => "text",
1408 "Filterable" => false,
1409 "Editable" => true,
1410 "Required" => false,
1411 ),
1412 "PREVIEW_TEXT_TYPE" => array(
1413 "Name" => GetMessage("IBD_FIELD_PREVIEW_TEXT_TYPE"),
1414 "Type" => "select",
1415 "Options" => array(
1416 "text" => GetMessage("IBD_DESC_TYPE_TEXT"),
1417 "html" => "Html",
1418 ),
1419 "Filterable" => false,
1420 "Editable" => true,
1421 "Required" => false,
1422 ),
1423 "DETAIL_PICTURE" => array(
1424 "Name" => GetMessage("IBD_FIELD_DETAIL_PICTURE"),
1425 "Type" => "file",
1426 "Filterable" => false,
1427 "Editable" => true,
1428 "Required" => false,
1429 ),
1430 "DETAIL_TEXT" => array(
1431 "Name" => GetMessage("IBD_FIELD_DETAIL_TEXT"),
1432 "Type" => "text",
1433 "Filterable" => false,
1434 "Editable" => true,
1435 "Required" => false,
1436 ),
1437 "DETAIL_TEXT_TYPE" => array(
1438 "Name" => GetMessage("IBD_FIELD_DETAIL_TEXT_TYPE"),
1439 "Type" => "select",
1440 "Options" => array(
1441 "text" => GetMessage("IBD_DESC_TYPE_TEXT"),
1442 "html" => "Html",
1443 ),
1444 "Filterable" => false,
1445 "Editable" => true,
1446 "Required" => false,
1447 ),
1448 "CODE" => array(
1449 "Name" => GetMessage("IBD_FIELD_CODE"),
1450 "Type" => "string",
1451 "Filterable" => true,
1452 "Editable" => true,
1453 "Required" => false,
1454 ),
1455 "XML_ID" => array(
1456 "Name" => GetMessage("IBD_FIELD_XML_ID"),
1457 "Type" => "string",
1458 "Filterable" => true,
1459 "Editable" => true,
1460 "Required" => false,
1461 ),
1462 );
1463
1464 $arKeys = array_keys($arResult);
1465 foreach ($arKeys as $key)
1466 $arResult[$key]["Multiple"] = false;
1467
1468 $dbProperties = CIBlockProperty::GetList(
1469 array("sort" => "asc", "name" => "asc"),
1470 array("IBLOCK_ID" => $iblockId, 'ACTIVE' => 'Y')
1471 );
1472 while ($arProperty = $dbProperties->Fetch())
1473 {
1474 if (trim($arProperty["CODE"]) <> '')
1475 $key = "PROPERTY_".$arProperty["CODE"];
1476 else
1477 $key = "PROPERTY_".$arProperty["ID"];
1478
1479 $arResult[$key] = array(
1480 "Name" => $arProperty["NAME"],
1481 "Filterable" => ($arProperty["FILTRABLE"] == "Y"),
1482 "Editable" => true,
1483 "Required" => ($arProperty["IS_REQUIRED"] == "Y"),
1484 "Multiple" => ($arProperty["MULTIPLE"] == "Y"),
1485 );
1486
1487 if(trim($arProperty["CODE"]) <> '')
1488 $arResult[$key]["Alias"] = "PROPERTY_".$arProperty["ID"];
1489
1490 if ($arProperty["USER_TYPE"] <> '')
1491 {
1492 if ($arProperty["USER_TYPE"] == "UserID"
1493 || $arProperty["USER_TYPE"] == "employee" && (COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y"))
1494 {
1495 $arResult[$key]["Type"] = "user";
1496 $arResult[$key."_PRINTABLE"] = array(
1497 "Name" => $arProperty["NAME"].GetMessage("IBD_FIELD_USERNAME_PROPERTY"),
1498 "Filterable" => false,
1499 "Editable" => false,
1500 "Required" => false,
1501 "Multiple" => ($arProperty["MULTIPLE"] == "Y"),
1502 "Type" => "string",
1503 );
1504 }
1505 elseif ($arProperty["USER_TYPE"] == "DateTime")
1506 {
1507 $arResult[$key]["Type"] = "datetime";
1508 }
1509 elseif ($arProperty["USER_TYPE"] == "Date")
1510 {
1511 $arResult[$key]["Type"] = "date";
1512 }
1513 elseif ($arProperty["USER_TYPE"] == "EList")
1514 {
1515 $arResult[$key]["Type"] = "E:EList";
1516 $arResult[$key]["Options"] = $arProperty["LINK_IBLOCK_ID"];
1517 }
1518 elseif($arProperty["USER_TYPE"] == "DiskFile")
1519 {
1520 $arResult[$key]["Type"] = "S:DiskFile";
1521 $arResult[$key."_PRINTABLE"] = array(
1522 "Name" => $arProperty["NAME"].GetMessage("IBD_FIELD_USERNAME_PROPERTY"),
1523 "Filterable" => false,
1524 "Editable" => false,
1525 "Required" => false,
1526 "Multiple" => ($arProperty["MULTIPLE"] == "Y"),
1527 "Type" => "int",
1528 );
1529 }
1530 elseif ($arProperty["USER_TYPE"] == "HTML")
1531 {
1532 $arResult[$key]["Type"] = "S:HTML";
1533 }
1534 else
1535 {
1536 $arResult[$key]["Type"] = "string";
1537 }
1538 }
1539 elseif ($arProperty["PROPERTY_TYPE"] == "L")
1540 {
1541 $arResult[$key]["Type"] = "select";
1542
1543 $arResult[$key]["Options"] = array();
1544 $dbPropertyEnums = CIBlockProperty::GetPropertyEnum($arProperty["ID"]);
1545 while ($arPropertyEnum = $dbPropertyEnums->GetNext())
1546 $arResult[$key]["Options"][(self::GetVersion() > 1) ? $arPropertyEnum["XML_ID"] : $arPropertyEnum["ID"]] = $arPropertyEnum["VALUE"];
1547 }
1548 elseif ($arProperty["PROPERTY_TYPE"] == "N")
1549 {
1550 $arResult[$key]["Type"] = "int";
1551 }
1552 elseif ($arProperty["PROPERTY_TYPE"] == "F")
1553 {
1554 $arResult[$key]["Type"] = "file";
1555 $arResult[$key."_printable"] = array(
1556 "Name" => $arProperty["NAME"].GetMessage("IBD_FIELD_USERNAME_PROPERTY"),
1557 "Filterable" => false,
1558 "Editable" => false,
1559 "Required" => false,
1560 "Multiple" => ($arProperty["MULTIPLE"] == "Y"),
1561 "Type" => "string",
1562 );
1563 }
1564 elseif ($arProperty["PROPERTY_TYPE"] == "S")
1565 {
1566 $arResult[$key]["Type"] = "string";
1567 }
1568 else
1569 {
1570 $arResult[$key]["Type"] = "string";
1571 }
1572 }
1573
1574 $arKeys = array_keys($arResult);
1575 foreach ($arKeys as $k)
1576 {
1577 $arResult[$k]["BaseType"] = $arDocumentFieldTypes[$arResult[$k]["Type"]]["BaseType"];
1578 $arResult[$k]["Complex"] = $arDocumentFieldTypes[$arResult[$k]["Type"]]["Complex"];
1579 }
1580
1581 return $arResult;
1582 }
1583
1584 public static function GetDocumentFieldTypes($documentType)
1585 {
1586 $iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
1587 if ($iblockId <= 0)
1588 throw new CBPArgumentOutOfRangeException("documentType", $documentType);
1589
1590 $arResult = array(
1591 "string" => array("Name" => GetMessage("BPCGHLP_PROP_STRING"), "BaseType" => "string"),
1592 "text" => array("Name" => GetMessage("BPCGHLP_PROP_TEXT"), "BaseType" => "text"),
1593 "int" => array("Name" => GetMessage("BPCGHLP_PROP_INT"), "BaseType" => "int"),
1594 "double" => array("Name" => GetMessage("BPCGHLP_PROP_DOUBLE"), "BaseType" => "double"),
1595 "select" => array("Name" => GetMessage("BPCGHLP_PROP_SELECT"), "BaseType" => "select", "Complex" => true),
1596 "bool" => array("Name" => GetMessage("BPCGHLP_PROP_BOOL"), "BaseType" => "bool"),
1597 "date" => array("Name" => GetMessage("BPCGHLP_PROP_DATA"), "BaseType" => "date"),
1598 "datetime" => array("Name" => GetMessage("BPCGHLP_PROP_DATETIME"), "BaseType" => "datetime"),
1599 "user" => array("Name" => GetMessage("BPCGHLP_PROP_USER"), "BaseType" => "user"),
1600 "file" => array("Name" => GetMessage("BPCGHLP_PROP_FILE"), "BaseType" => "file"),
1601 );
1602
1603 $ignoredTypes = array('map_yandex', 'directory', 'SectionAuto', 'SKU', 'EAutocomplete');
1604
1606 "Name" => GetMessage("BPCGHLP_PROP_SELECT_INTERNAL"),
1607 "BaseType" => "string",
1608 "Complex" => true,
1609 );
1610
1611 foreach (CIBlockProperty::GetUserType() as $ar)
1612 {
1613 if(in_array($ar["USER_TYPE"], $ignoredTypes))
1614 {
1615 continue;
1616 }
1617
1618 $t = $ar["PROPERTY_TYPE"].":".$ar["USER_TYPE"];
1619
1620 if($t == "S:ECrm")
1621 {
1622 $t = "E:ECrm";
1623 }
1624
1625 if (COption::GetOptionString("bizproc", "SkipNonPublicCustomTypes", "N") == "Y"
1626 && !array_key_exists("GetPublicEditHTML", $ar) || $t == "S:UserID" || $t == "S:DateTime" || $t == "S:Date")
1627 continue;
1628
1629 $arResult[$t] = array("Name" => $ar["DESCRIPTION"], "BaseType" => "string", 'typeClass' => '\Bitrix\Iblock\BizprocType\UserTypeProperty');
1630 if ($t == "S:employee")
1631 {
1632 $arResult[$t]['typeClass'] = '\Bitrix\Iblock\BizprocType\UserTypePropertyEmployee';
1633 if (COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y")
1634 {
1635 $arResult[$t]["BaseType"] = "user";
1636 $arResult[$t]['typeClass'] = \Bitrix\Bizproc\BaseType\User::class;
1637 }
1638 }
1639 elseif ($t == "E:EList")
1640 {
1641 $arResult[$t]["BaseType"] = "string";
1642 $arResult[$t]["Complex"] = true;
1643 $arResult[$t]['typeClass'] = '\Bitrix\Iblock\BizprocType\UserTypePropertyElist';
1644 }
1645 elseif ($t == 'S:HTML')
1646 {
1647 $arResult[$t]['typeClass'] = '\Bitrix\Iblock\BizprocType\UserTypePropertyHtml';
1648 }
1649 elseif($t == 'S:DiskFile')
1650 {
1651 $arResult[$t]["BaseType"] = "int";
1652 $arResult[$t]['typeClass'] = '\Bitrix\Iblock\BizprocType\UserTypePropertyDiskFile';
1653 }
1654 elseif($t == 'E:ECrm')
1655 {
1656 $arResult[$t]["BaseType"] = "string";
1657 $arResult[$t]["Complex"] = true;
1658 $arResult[$t]['typeClass'] = '\Bitrix\Iblock\BizprocType\ECrm';
1659 }
1660 elseif($t == 'S:Money')
1661 {
1662 $arResult[$t]["BaseType"] = "string";
1663 $arResult[$t]['typeClass'] = '\Bitrix\Iblock\BizprocType\Money';
1664 }
1665 elseif($t == 'N:Sequence')
1666 {
1667 $arResult[$t]["BaseType"] = "int";
1668 $arResult[$t]['typeClass'] = '\Bitrix\Iblock\BizprocType\Sequence';
1669 }
1670 }
1671
1672 return $arResult;
1673 }
1674
1675 public static function generateMnemonicCode($integerCode = 0)
1676 {
1677 if(!$integerCode)
1678 $integerCode = time();
1679
1680 $code = '';
1681 for ($i = 1; $integerCode >= 0 && $i < 10; $i++)
1682 {
1683 $code = chr(0x41 + ($integerCode % pow(26, $i) / pow(26, $i - 1))) . $code;
1684 $integerCode -= pow(26, $i);
1685 }
1686 return $code;
1687 }
1688
1689 public static function AddDocumentField($documentType, $arFields)
1690 {
1691 $iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
1692 if ($iblockId <= 0)
1693 throw new CBPArgumentOutOfRangeException("documentType", $documentType);
1694
1695 if (mb_substr($arFields["code"], 0, mb_strlen("PROPERTY_")) == "PROPERTY_")
1696 $arFields["code"] = mb_substr($arFields["code"], mb_strlen("PROPERTY_"));
1697
1698 $arFieldsTmp = array(
1699 "NAME" => $arFields["name"],
1700 "ACTIVE" => "Y",
1701 "SORT" => 150,
1702 "CODE" => $arFields["code"],
1703 'MULTIPLE' => $arFields['multiple'] == 'Y' || (string)$arFields['multiple'] === '1' ? 'Y' : 'N',
1704 'IS_REQUIRED' => $arFields['required'] == 'Y' || (string)$arFields['required'] === '1' ? 'Y' : 'N',
1705 "IBLOCK_ID" => $iblockId,
1706 "FILTRABLE" => "Y",
1707 );
1708
1709 if (mb_strpos("0123456789", mb_substr($arFieldsTmp["CODE"], 0, 1)) !== false)
1710 $arFieldsTmp["CODE"] = self::generateMnemonicCode($arFieldsTmp["CODE"]);
1711
1712 if (array_key_exists("additional_type_info", $arFields))
1713 $arFieldsTmp["LINK_IBLOCK_ID"] = intval($arFields["additional_type_info"]);
1714
1715 if (mb_strstr($arFields["type"], ":") !== false)
1716 {
1717 if($arFields["type"] == "S:DiskFile")
1718 {
1719 $arFieldsTmp["TYPE"] = $arFields["type"];
1720 }
1721 else
1722 {
1723 [$arFieldsTmp["PROPERTY_TYPE"], $arFieldsTmp["USER_TYPE"]] = explode(":", $arFields["type"], 2);
1724 if ($arFields["type"] == "E:EList")
1725 $arFieldsTmp["LINK_IBLOCK_ID"] = $arFields["options"];
1726 }
1727 }
1728 elseif ($arFields["type"] == "user")
1729 {
1730 $arFieldsTmp["PROPERTY_TYPE"] = "S";
1731 $arFieldsTmp["USER_TYPE"]= "UserID";
1732 }
1733 elseif ($arFields["type"] == "date")
1734 {
1735 $arFieldsTmp["PROPERTY_TYPE"] = "S";
1736 $arFieldsTmp["USER_TYPE"]= "Date";
1737 }
1738 elseif ($arFields["type"] == "datetime")
1739 {
1740 $arFieldsTmp["PROPERTY_TYPE"] = "S";
1741 $arFieldsTmp["USER_TYPE"]= "DateTime";
1742 }
1743 elseif ($arFields["type"] == "file")
1744 {
1745 $arFieldsTmp["PROPERTY_TYPE"] = "F";
1746 $arFieldsTmp["USER_TYPE"]= "";
1747 }
1748 elseif ($arFields["type"] == "select")
1749 {
1750 $arFieldsTmp["PROPERTY_TYPE"] = "L";
1751 $arFieldsTmp["USER_TYPE"]= false;
1752
1753 if (is_array($arFields["options"]))
1754 {
1755 $i = 10;
1756 foreach ($arFields["options"] as $k => $v)
1757 {
1758 $arFieldsTmp["VALUES"][] = array("XML_ID" => $k, "VALUE" => $v, "DEF" => "N", "SORT" => $i);
1759 $i = $i + 10;
1760 }
1761 }
1762 elseif (is_string($arFields["options"]) && ($arFields["options"] <> ''))
1763 {
1764 $a = explode("\n", $arFields["options"]);
1765 $i = 10;
1766 foreach ($a as $v)
1767 {
1768 $v = trim(trim($v), "\r\n");
1769 if (!$v)
1770 continue;
1771 $v1 = $v2 = $v;
1772 if (mb_substr($v, 0, 1) == "[" && mb_strpos($v, "]") !== false)
1773 {
1774 $v1 = mb_substr($v, 1, mb_strpos($v, "]") - 1);
1775 $v2 = trim(mb_substr($v, mb_strpos($v, "]") + 1));
1776 }
1777 $arFieldsTmp["VALUES"][] = array("XML_ID" => $v1, "VALUE" => $v2, "DEF" => "N", "SORT" => $i);
1778 $i = $i + 10;
1779 }
1780 }
1781 }
1782 elseif($arFields["type"] == "bool")
1783 {
1784 $arFieldsTmp["TYPE"] = "L";
1785 $arFieldsTmp["VALUES"][] = array(
1786 "XML_ID" => 'Y',
1787 "VALUE" => GetMessage("BPVDX_YES"),
1788 "DEF" => "N",
1789 "SORT" => 10
1790 );
1791 $arFieldsTmp["VALUES"][] = array(
1792 "XML_ID" => 'N',
1793 "VALUE" => GetMessage("BPVDX_NO"),
1794 "DEF" => "N",
1795 "SORT" => 20
1796 );
1797 }
1798 else
1799 {
1800 $arFieldsTmp["PROPERTY_TYPE"] = $arFields["type"];
1801 $arFieldsTmp["USER_TYPE"] = false;
1802 }
1803
1804 if ($arFieldsTmp["PROPERTY_TYPE"] == "T")
1805 {
1806 $arFieldsTmp["PROPERTY_TYPE"] = "S";
1807 $arFieldsTmp["ROW_COUNT"] = 5;
1808 }
1809
1810 $properties = CIBlockProperty::getList(
1811 array(),
1812 array("IBLOCK_ID" => $arFieldsTmp["IBLOCK_ID"], "CODE" => $arFieldsTmp["CODE"])
1813 );
1814 if(!$properties->fetch())
1815 {
1816 $ibp = new CIBlockProperty;
1817 $propId = $ibp->Add($arFieldsTmp);
1818 if (intval($propId) <= 0)
1819 throw new Exception($ibp->LAST_ERROR);
1820 }
1821
1822 return "PROPERTY_".$arFields["code"];
1823 }
1824
1825 public static function UpdateDocument($documentId, $arFields)
1826 {
1827 $documentId = intval($documentId);
1828 if ($documentId <= 0)
1829 throw new CBPArgumentNullException("documentId");
1830
1831 CIBlockElement::WF_CleanUpHistoryCopies($documentId, 0);
1832
1833 $arFieldsPropertyValues = array();
1834 $complexDocumentId = ['iblock', get_called_class(), $documentId];
1835
1836 $dbResult = CIBlockElement::GetList(
1837 array(),
1838 array("ID" => $documentId, "SHOW_NEW" => "Y", "SHOW_HISTORY" => "Y"),
1839 false, false,
1840 array("ID", "IBLOCK_ID")
1841 );
1842 $arResult = $dbResult->Fetch();
1843 if (!$arResult)
1844 throw new Exception("Element is not found");
1845
1846 $arDocumentFields = self::GetDocumentFields("iblock_".$arResult["IBLOCK_ID"]);
1847
1848 $arKeys = array_keys($arFields);
1849 foreach ($arKeys as $key)
1850 {
1851 if (!array_key_exists($key, $arDocumentFields))
1852 continue;
1853
1854 $arFields[$key] = (is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key])) ?
1856 $realKey = ((mb_substr($key, 0, mb_strlen("PROPERTY_")) == "PROPERTY_")?
1857 mb_substr($key, mb_strlen("PROPERTY_")) : $key);
1858
1859 if ($arDocumentFields[$key]["Type"] == "user")
1860 {
1861 $arFields[$key] = \CBPHelper::extractUsers($arFields[$key], $complexDocumentId);
1862 }
1863 elseif ($arDocumentFields[$key]["Type"] == "select")
1864 {
1865 $arV = array();
1866 $db = CIBlockProperty::GetPropertyEnum(
1867 $realKey,
1868 false,
1869 array("IBLOCK_ID" => $arResult["IBLOCK_ID"])
1870 );
1871 while ($ar = $db->GetNext())
1872 $arV[$ar["XML_ID"]] = $ar["ID"];
1873
1874 $listValue = array();
1875 foreach ($arFields[$key] as &$value)
1876 {
1877 if(is_array($value) && CBPHelper::isAssociativeArray($value))
1878 {
1879 $listXmlId = array_keys($value);
1880 foreach($listXmlId as $xmlId)
1881 {
1882 $listValue[] = $arV[$xmlId];
1883 }
1884 }
1885 else
1886 {
1887 if (array_key_exists($value, $arV))
1888 $value = $arV[$value];
1889 }
1890 }
1891 if(!empty($listValue))
1892 {
1893 $arFields[$key] = $listValue;
1894 }
1895 }
1896 elseif ($arDocumentFields[$key]["Type"] == "file")
1897 {
1898 $files = array();
1899 foreach ($arFields[$key] as $value)
1900 {
1901 if (is_array($value))
1902 {
1903 foreach($value as $file)
1904 {
1905 $makeFileArray = CFile::MakeFileArray($file);
1906 if($makeFileArray)
1907 $files[] = $makeFileArray;
1908 }
1909 }
1910 else
1911 {
1912 $makeFileArray = CFile::MakeFileArray($value);
1913 if($makeFileArray)
1914 $files[] = $makeFileArray;
1915 }
1916 }
1917 if($files)
1918 $arFields[$key] = $files;
1919 else
1920 $arFields[$key] = array(array('del' => 'Y'));
1921 }
1922 elseif($arDocumentFields[$key]["Type"] == "S:DiskFile")
1923 {
1924 foreach ($arFields[$key] as &$value)
1925 {
1926 if(!empty($value))
1927 {
1928 $value = "n".$value;
1929 }
1930 }
1931 $arFields[$key] = array("VALUE" => $arFields[$key], "DESCRIPTION" => "workflow");
1932 }
1933 elseif ($arDocumentFields[$key]["Type"] == "S:HTML")
1934 {
1935 foreach ($arFields[$key] as &$value)
1936 $value = array("VALUE" => $value);
1937 }
1938
1939 unset($value);
1940
1941 if (!$arDocumentFields[$key]["Multiple"] && is_array($arFields[$key]))
1942 {
1943 if (count($arFields[$key]) > 0)
1944 {
1945 $a = array_values($arFields[$key]);
1946 $arFields[$key] = $a[0];
1947 }
1948 else
1949 {
1950 $arFields[$key] = null;
1951 }
1952 }
1953
1954 if (mb_substr($key, 0, mb_strlen("PROPERTY_")) == "PROPERTY_")
1955 {
1956 $realKey = mb_substr($key, mb_strlen("PROPERTY_"));
1957 $arFieldsPropertyValues[$realKey] = (is_array($arFields[$key]) &&
1958 !CBPHelper::IsAssociativeArray($arFields[$key])) ? $arFields[$key] : array($arFields[$key]);
1959 if(empty($arFieldsPropertyValues[$realKey]))
1960 $arFieldsPropertyValues[$realKey] = array(null);
1961 unset($arFields[$key]);
1962 }
1963 }
1964
1965 $iblockElement = new CIBlockElement();
1966 if (!empty($arFieldsPropertyValues))
1967 {
1968 $iblockElement->SetPropertyValuesEx($documentId, $arResult["IBLOCK_ID"], $arFieldsPropertyValues);
1969 }
1970
1971 $res = $iblockElement->Update($documentId, $arFields, false, true, true);
1972 if (!$res)
1973 throw new Exception($iblockElement->LAST_ERROR);
1974 }
1975
1976 public static function LockDocument($documentId, $workflowId)
1977 {
1978 global $DB;
1979 $strSql = "
1980 SELECT * FROM b_iblock_element_lock
1981 WHERE IBLOCK_ELEMENT_ID = ".intval($documentId)."
1982 AND LOCKED_BY = '".$DB->ForSQL($workflowId, 32)."'
1983 ";
1984 $z = $DB->Query($strSql);
1985 if($z->Fetch())
1986 {
1987 //Success lock because documentId already locked by workflowId
1988 return true;
1989 }
1990 else
1991 {
1992 $strSql = "
1993 INSERT INTO b_iblock_element_lock (IBLOCK_ELEMENT_ID, DATE_LOCK, LOCKED_BY)
1994 SELECT E.ID, ".$DB->GetNowFunction().", '".$DB->ForSQL($workflowId, 32)."'
1995 FROM b_iblock_element E
1996 LEFT JOIN b_iblock_element_lock EL on EL.IBLOCK_ELEMENT_ID = E.ID
1997 WHERE ID = ".intval($documentId)."
1998 AND EL.IBLOCK_ELEMENT_ID IS NULL
1999 ";
2000 $z = $DB->Query($strSql);
2001 return $z->AffectedRowsCount() > 0;
2002 }
2003 }
2004
2005 public static function UnlockDocument($documentId, $workflowId)
2006 {
2007 global $DB;
2008
2009 $strSql = "
2010 SELECT * FROM b_iblock_element_lock
2011 WHERE IBLOCK_ELEMENT_ID = ".intval($documentId)."
2012 ";
2013 $z = $DB->Query($strSql);
2014 if($z->Fetch())
2015 {
2016 $strSql = "
2017 DELETE FROM b_iblock_element_lock
2018 WHERE IBLOCK_ELEMENT_ID = ".intval($documentId)."
2019 AND (LOCKED_BY = '".$DB->ForSQL($workflowId, 32)."' OR '".$DB->ForSQL($workflowId, 32)."' = '')
2020 ";
2021 $z = $DB->Query($strSql);
2022 $result = $z->AffectedRowsCount();
2023 }
2024 else
2025 {//Success unlock when there is no locks at all
2026 $result = 1;
2027 }
2028
2029 if ($result > 0)
2030 {
2031 foreach (GetModuleEvents("iblock", "CIBlockDocument_OnUnlockDocument", true) as $arEvent)
2032 {
2033 ExecuteModuleEventEx($arEvent, array(array("iblock", "CIBlockDocument", $documentId)));
2034 }
2035 }
2036
2037 return $result > 0;
2038 }
2039
2040 public static function IsDocumentLocked($documentId, $workflowId)
2041 {
2042 global $DB;
2043 $strSql = "
2044 SELECT * FROM b_iblock_element_lock
2045 WHERE IBLOCK_ELEMENT_ID = ".intval($documentId)."
2046 AND LOCKED_BY <> '".$DB->ForSQL($workflowId, 32)."'
2047 ";
2048 $z = $DB->Query($strSql);
2049 if($z->Fetch())
2050 return true;
2051 else
2052 return false;
2053 }
2054
2055 public static function CanUserOperateDocument($operation, $userId, $documentId, $arParameters = array())
2056 {
2057 $documentId = trim($documentId);
2058 if ($documentId == '')
2059 return false;
2060
2061 if (!array_key_exists("IBlockId", $arParameters)
2062 && (
2063 !array_key_exists("IBlockPermission", $arParameters)
2064 || !array_key_exists("DocumentStates", $arParameters)
2065 || !array_key_exists("IBlockRightsMode", $arParameters)
2066 || array_key_exists("IBlockRightsMode", $arParameters) && ($arParameters["IBlockRightsMode"] === "E")
2067 )
2068 || !array_key_exists("CreatedBy", $arParameters) && !array_key_exists("AllUserGroups", $arParameters))
2069 {
2070 $dbElementList = CIBlockElement::GetList(
2071 array(),
2072 array("ID" => $documentId, "SHOW_NEW" => "Y", "SHOW_HISTORY" => "Y"),
2073 false,
2074 false,
2075 array("ID", "IBLOCK_ID", "CREATED_BY")
2076 );
2077 $arElement = $dbElementList->Fetch();
2078
2079 if (!$arElement)
2080 return false;
2081
2082 $arParameters["IBlockId"] = $arElement["IBLOCK_ID"];
2083 $arParameters["CreatedBy"] = $arElement["CREATED_BY"];
2084 }
2085
2086 if (!array_key_exists("IBlockRightsMode", $arParameters))
2087 $arParameters["IBlockRightsMode"] = CIBlock::GetArrayByID($arParameters["IBlockId"], "RIGHTS_MODE");
2088
2089 if ($arParameters["IBlockRightsMode"] === "E")
2090 {
2092 return CIBlockElementRights::UserHasRightTo($arParameters["IBlockId"], $documentId, "element_read");
2094 return CIBlockElementRights::UserHasRightTo($arParameters["IBlockId"], $documentId, "element_edit");
2095 elseif (
2098 )
2099 {
2100 if (CIBlockElementRights::UserHasRightTo($arParameters["IBlockId"], $documentId, "element_edit"))
2101 return true;
2102
2103 if (!array_key_exists("WorkflowId", $arParameters))
2104 return false;
2105
2106 if (!CIBlockElementRights::UserHasRightTo($arParameters["IBlockId"], $documentId, "element_read"))
2107 return false;
2108
2109 $userId = intval($userId);
2110 if (!array_key_exists("AllUserGroups", $arParameters))
2111 {
2112 if (!array_key_exists("UserGroups", $arParameters))
2113 $arParameters["UserGroups"] = CUser::GetUserGroup($userId);
2114
2115 $arParameters["AllUserGroups"] = $arParameters["UserGroups"];
2116 if ($userId == $arParameters["CreatedBy"])
2117 $arParameters["AllUserGroups"][] = "Author";
2118 }
2119
2120 if (!array_key_exists("DocumentStates", $arParameters))
2121 {
2123 $arParameters["DocumentStates"] = CBPWorkflowTemplateLoader::GetDocumentTypeStates(array("iblock", "CIBlockDocument", "iblock_".$arParameters["IBlockId"]));
2124 else
2125 $arParameters["DocumentStates"] = CBPDocument::GetDocumentStates(
2126 array("iblock", "CIBlockDocument", "iblock_".$arParameters["IBlockId"]),
2127 array("iblock", "CIBlockDocument", $documentId)
2128 );
2129 }
2130
2131 if (array_key_exists($arParameters["WorkflowId"], $arParameters["DocumentStates"]))
2132 $arParameters["DocumentStates"] = array($arParameters["WorkflowId"] => $arParameters["DocumentStates"][$arParameters["WorkflowId"]]);
2133 else
2134 return false;
2135
2136 $arAllowableOperations = CBPDocument::GetAllowableOperations(
2137 $userId,
2138 $arParameters["AllUserGroups"],
2139 $arParameters["DocumentStates"],
2140 true
2141 );
2142
2143 if (!is_array($arAllowableOperations))
2144 return false;
2145
2146 if (($operation === CBPCanUserOperateOperation::ViewWorkflow) && in_array("read", $arAllowableOperations)
2147 || ($operation === CBPCanUserOperateOperation::StartWorkflow) && in_array("write", $arAllowableOperations))
2148 return true;
2149
2150 $chop = ($operation === CBPCanUserOperateOperation::ViewWorkflow) ? "element_read" : "element_edit";
2151
2152 foreach ($arAllowableOperations as $op)
2153 {
2154 $ar = CTask::GetOperations($op, true);
2155 if (in_array($chop, $ar))
2156 return true;
2157 }
2158 }
2159 elseif (
2161 )
2162 {
2163 return CBPDocument::CanUserOperateDocumentType(
2165 $userId,
2166 array("iblock", "CIBlockDocument", $documentId),
2167 $arParameters
2168 );
2169 }
2170
2171 return false;
2172 }
2173
2174 if (!array_key_exists("IBlockPermission", $arParameters))
2175 {
2176 if (CModule::IncludeModule('lists'))
2177 $arParameters["IBlockPermission"] = CLists::GetIBlockPermission($arParameters["IBlockId"], $userId);
2178 else
2179 $arParameters["IBlockPermission"] = CIBlock::GetPermission($arParameters["IBlockId"], $userId);
2180 }
2181
2182 if ($arParameters["IBlockPermission"] <= "R")
2183 return false;
2184 elseif ($arParameters["IBlockPermission"] >= "W")
2185 return true;
2186
2187 $userId = intval($userId);
2188 if (!array_key_exists("AllUserGroups", $arParameters))
2189 {
2190 if (!array_key_exists("UserGroups", $arParameters))
2191 $arParameters["UserGroups"] = CUser::GetUserGroup($userId);
2192
2193 $arParameters["AllUserGroups"] = $arParameters["UserGroups"];
2194 if ($userId == $arParameters["CreatedBy"])
2195 $arParameters["AllUserGroups"][] = "Author";
2196 }
2197
2198 if (!array_key_exists("DocumentStates", $arParameters))
2199 {
2200 $arParameters["DocumentStates"] = CBPDocument::GetDocumentStates(
2201 array("iblock", "CIBlockDocument", "iblock_".$arParameters["IBlockId"]),
2202 array("iblock", "CIBlockDocument", $documentId)
2203 );
2204 }
2205
2206 if (array_key_exists("WorkflowId", $arParameters))
2207 {
2208 if (array_key_exists($arParameters["WorkflowId"], $arParameters["DocumentStates"]))
2209 $arParameters["DocumentStates"] = array($arParameters["WorkflowId"] => $arParameters["DocumentStates"][$arParameters["WorkflowId"]]);
2210 else
2211 return false;
2212 }
2213
2214 $arAllowableOperations = CBPDocument::GetAllowableOperations(
2215 $userId,
2216 $arParameters["AllUserGroups"],
2217 $arParameters["DocumentStates"]
2218 );
2219
2220 if (!is_array($arAllowableOperations))
2221 return false;
2222
2223 $r = false;
2224 switch ($operation)
2225 {
2227 $r = in_array("read", $arAllowableOperations);
2228 break;
2230 $r = in_array("write", $arAllowableOperations);
2231 break;
2233 $r = false;
2234 break;
2236 $r = in_array("write", $arAllowableOperations);
2237 break;
2239 $r = in_array("read", $arAllowableOperations) || in_array("write", $arAllowableOperations);
2240 break;
2241 default:
2242 $r = false;
2243 }
2244
2245 return $r;
2246 }
2247
2248 public static function CanUserOperateDocumentType($operation, $userId, $documentType, $arParameters = array())
2249 {
2250 $documentType = trim($documentType);
2251 if ($documentType == '')
2252 return false;
2253
2254 $arParameters["IBlockId"] = intval(mb_substr($documentType, mb_strlen("iblock_")));
2255 $arParameters['sectionId'] = !empty($arParameters['sectionId']) ? (int)$arParameters['sectionId'] : 0;
2256
2257 if (!array_key_exists("IBlockRightsMode", $arParameters))
2258 $arParameters["IBlockRightsMode"] = CIBlock::GetArrayByID($arParameters["IBlockId"], "RIGHTS_MODE");
2259
2260 if ($arParameters["IBlockRightsMode"] === "E")
2261 {
2263 return CIBlockRights::UserHasRightTo($arParameters["IBlockId"], $arParameters["IBlockId"], "iblock_rights_edit");
2265 return CIBlockSectionRights::UserHasRightTo($arParameters["IBlockId"], $arParameters["sectionId"], "section_element_bind");
2268 {
2269 if (!array_key_exists("WorkflowId", $arParameters))
2270 return false;
2271
2273 return CIBlockRights::UserHasRightTo($arParameters["IBlockId"], 0, "element_read");
2274
2276 return CIBlockSectionRights::UserHasRightTo($arParameters["IBlockId"], $arParameters['sectionId'], "section_element_bind");
2277
2278 $userId = intval($userId);
2279 if (!array_key_exists("AllUserGroups", $arParameters))
2280 {
2281 if (!array_key_exists("UserGroups", $arParameters))
2282 $arParameters["UserGroups"] = CUser::GetUserGroup($userId);
2283
2284 $arParameters["AllUserGroups"] = $arParameters["UserGroups"];
2285 $arParameters["AllUserGroups"][] = "Author";
2286 }
2287
2288 if (!array_key_exists("DocumentStates", $arParameters))
2289 {
2291 $arParameters["DocumentStates"] = CBPWorkflowTemplateLoader::GetDocumentTypeStates(array("iblock", "CIBlockDocument", "iblock_".$arParameters["IBlockId"]));
2292 else
2293 $arParameters["DocumentStates"] = CBPDocument::GetDocumentStates(
2294 array("iblock", "CIBlockDocument", "iblock_".$arParameters["IBlockId"]),
2295 null
2296 );
2297 }
2298
2299 if (array_key_exists($arParameters["WorkflowId"], $arParameters["DocumentStates"]))
2300 $arParameters["DocumentStates"] = array($arParameters["WorkflowId"] => $arParameters["DocumentStates"][$arParameters["WorkflowId"]]);
2301 else
2302 return false;
2303
2304 $arAllowableOperations = CBPDocument::GetAllowableOperations(
2305 $userId,
2306 $arParameters["AllUserGroups"],
2307 $arParameters["DocumentStates"],
2308 true
2309 );
2310
2311 if (!is_array($arAllowableOperations))
2312 return false;
2313
2314 if (($operation === CBPCanUserOperateOperation::ViewWorkflow) && in_array("read", $arAllowableOperations)
2315 || ($operation === CBPCanUserOperateOperation::StartWorkflow) && in_array("write", $arAllowableOperations))
2316 return true;
2317
2318 $chop = ($operation === CBPCanUserOperateOperation::ViewWorkflow) ? "element_read" : "section_element_bind";
2319
2320 foreach ($arAllowableOperations as $op)
2321 {
2322 $ar = CTask::GetOperations($op, true);
2323 if (in_array($chop, $ar))
2324 return true;
2325 }
2326 }
2327
2328 return false;
2329 }
2330
2331 if (!array_key_exists("IBlockPermission", $arParameters))
2332 {
2333 if(CModule::IncludeModule('lists'))
2334 $arParameters["IBlockPermission"] = CLists::GetIBlockPermission($arParameters["IBlockId"], $userId);
2335 else
2336 $arParameters["IBlockPermission"] = CIBlock::GetPermission($arParameters["IBlockId"], $userId);
2337 }
2338
2339 if ($arParameters["IBlockPermission"] <= "R")
2340 return false;
2341 elseif ($arParameters["IBlockPermission"] >= "W")
2342 return true;
2343
2344 $userId = intval($userId);
2345 if (!array_key_exists("AllUserGroups", $arParameters))
2346 {
2347 if (!array_key_exists("UserGroups", $arParameters))
2348 $arParameters["UserGroups"] = CUser::GetUserGroup($userId);
2349
2350 $arParameters["AllUserGroups"] = $arParameters["UserGroups"];
2351 $arParameters["AllUserGroups"][] = "Author";
2352 }
2353
2354 if (!array_key_exists("DocumentStates", $arParameters))
2355 {
2356 $arParameters["DocumentStates"] = CBPDocument::GetDocumentStates(
2357 array("iblock", "CIBlockDocument", "iblock_".$arParameters["IBlockId"]),
2358 null
2359 );
2360 }
2361
2362 if (array_key_exists("WorkflowId", $arParameters))
2363 {
2364 if (array_key_exists($arParameters["WorkflowId"], $arParameters["DocumentStates"]))
2365 $arParameters["DocumentStates"] = array($arParameters["WorkflowId"] => $arParameters["DocumentStates"][$arParameters["WorkflowId"]]);
2366 else
2367 return false;
2368 }
2369
2370 $arAllowableOperations = CBPDocument::GetAllowableOperations(
2371 $userId,
2372 $arParameters["AllUserGroups"],
2373 $arParameters["DocumentStates"]
2374 );
2375
2376 if (!is_array($arAllowableOperations))
2377 return false;
2378
2379 $r = false;
2380 switch ($operation)
2381 {
2383 $r = in_array("read", $arAllowableOperations);
2384 break;
2386 $r = in_array("write", $arAllowableOperations);
2387 break;
2389 $r = in_array("write", $arAllowableOperations);
2390 break;
2392 $r = in_array("write", $arAllowableOperations);
2393 break;
2395 $r = false;
2396 break;
2397 default:
2398 $r = false;
2399 }
2400
2401 return $r;
2402 }
2403
2410 public static function CreateDocument($parentDocumentId, $arFields)
2411 {
2412 if (!array_key_exists("IBLOCK_ID", $arFields) || intval($arFields["IBLOCK_ID"]) <= 0)
2413 throw new Exception("IBlock ID is not found");
2414
2415 $arFieldsPropertyValues = array();
2416 $complexDocumentId = ['iblock', get_called_class(), $parentDocumentId];
2417
2418 $arDocumentFields = static::GetDocumentFields("iblock_".$arFields["IBLOCK_ID"]);
2419
2420 $arKeys = array_keys($arFields);
2421 foreach ($arKeys as $key)
2422 {
2423 if (!array_key_exists($key, $arDocumentFields))
2424 continue;
2425
2426 $arFields[$key] = (is_array($arFields[$key]) &&
2427 !CBPHelper::IsAssociativeArray($arFields[$key])) ? $arFields[$key] : array($arFields[$key]);
2428 $realKey = ((mb_substr($key, 0, mb_strlen("PROPERTY_")) == "PROPERTY_")? mb_substr($key, mb_strlen("PROPERTY_")) : $key);
2429
2430 if ($arDocumentFields[$key]["Type"] == "user")
2431 {
2432 $arFields[$key] = \CBPHelper::extractUsers($arFields[$key], $complexDocumentId);
2433 }
2434 elseif ($arDocumentFields[$key]["Type"] == "select")
2435 {
2436 $arV = array();
2437 $db = CIBlockProperty::GetPropertyEnum($realKey, false, array("IBLOCK_ID" => $arFields["IBLOCK_ID"]));
2438 while ($ar = $db->GetNext())
2439 $arV[$ar["XML_ID"]] = $ar["ID"];
2440
2441 $listValue = array();
2442 foreach ($arFields[$key] as &$value)
2443 {
2444 if(CBPHelper::isAssociativeArray($value))
2445 {
2446 $listXmlId = array_keys($value);
2447 foreach($listXmlId as $xmlId)
2448 {
2449 $listValue[] = $arV[$xmlId];
2450 }
2451 }
2452 else
2453 {
2454 if (array_key_exists($value, $arV))
2455 $value = $arV[$value];
2456 }
2457 }
2458 if(!empty($listValue))
2459 {
2460 $arFields[$key] = $listValue;
2461 }
2462 }
2463 elseif ($arDocumentFields[$key]["Type"] == "file")
2464 {
2465 $files = array();
2466 foreach ($arFields[$key] as $value)
2467 {
2468 if (is_array($value))
2469 {
2470 foreach($value as $file)
2471 {
2472 $files[] = CFile::MakeFileArray($file);
2473 }
2474 }
2475 else
2476 $files[] = CFile::MakeFileArray($value);
2477 }
2478 $arFields[$key] = $files;
2479 }
2480 elseif ($arDocumentFields[$key]["Type"] == "S:DiskFile")
2481 {
2482 foreach ($arFields[$key] as &$value)
2483 {
2484 if(!empty($value))
2485 {
2486 $value = "n".$value;
2487 }
2488 }
2489 $arFields[$key] = array("VALUE" => $arFields[$key], "DESCRIPTION" => "workflow");
2490 }
2491 elseif ($arDocumentFields[$key]["Type"] == "N:Sequence")
2492 {
2493 $queryObject = \CIBlockProperty::getByID($realKey, $arFields["IBLOCK_ID"]);
2494 if ($property = $queryObject->fetch())
2495 {
2496 $propertyId = $property["ID"];
2497 $sequence = new \CIBlockSequence($arFields["IBLOCK_ID"], $propertyId);
2498 foreach ($arFields[$key] as &$value)
2499 {
2500 $value = ["VALUE" => $value];
2501 }
2502 $value = ["VALUE" => $sequence->getNext()];
2503 }
2504 }
2505 elseif ($arDocumentFields[$key]["Type"] == "S:HTML")
2506 {
2507 foreach ($arFields[$key] as &$value)
2508 $value = array("VALUE" => $value);
2509 }
2510
2511 unset($value);
2512
2513 if (!$arDocumentFields[$key]["Multiple"] && is_array($arFields[$key]))
2514 {
2515 if (count($arFields[$key]) > 0)
2516 {
2517 $a = array_values($arFields[$key]);
2518 $arFields[$key] = $a[0];
2519 }
2520 else
2521 {
2522 $arFields[$key] = null;
2523 }
2524 }
2525
2526 if (mb_substr($key, 0, mb_strlen("PROPERTY_")) == "PROPERTY_")
2527 {
2528 $realKey = mb_substr($key, mb_strlen("PROPERTY_"));
2529 $arFieldsPropertyValues[$realKey] = (is_array($arFields[$key]) &&
2530 !CBPHelper::IsAssociativeArray($arFields[$key])) ? $arFields[$key] : array($arFields[$key]);
2531 unset($arFields[$key]);
2532 }
2533 }
2534
2535 if (count($arFieldsPropertyValues) > 0)
2536 $arFields["PROPERTY_VALUES"] = $arFieldsPropertyValues;
2537
2538 if (isset($arFields['SORT']))
2539 {
2540 $arFields['SORT'] = (int) $arFields['SORT'];
2541 }
2542
2543 $iblockElement = new CIBlockElement();
2544 $id = $iblockElement->Add($arFields, false, true, true);
2545 if (!$id || $id <= 0)
2546 throw new Exception($iblockElement->LAST_ERROR);
2547
2548 return $id;
2549 }
2550
2556 public static function DeleteDocument($documentId)
2557 {
2558 $documentId = intval($documentId);
2559 if ($documentId <= 0)
2560 throw new CBPArgumentNullException("documentId");
2561
2562 CIBlockElement::Delete($documentId);
2563 }
2564
2570 public static function PublishDocument($documentId)
2571 {
2572 global $DB;
2573 $ID = intval($documentId);
2574
2575 $db_element = CIBlockElement::GetList(array(), array("ID"=>$ID, "SHOW_HISTORY"=>"Y"), false, false,
2576 array(
2577 "ID",
2578 "TIMESTAMP_X",
2579 "MODIFIED_BY",
2580 "DATE_CREATE",
2581 "CREATED_BY",
2582 "IBLOCK_ID",
2583 "ACTIVE",
2584 "ACTIVE_FROM",
2585 "ACTIVE_TO",
2586 "SORT",
2587 "NAME",
2588 "PREVIEW_PICTURE",
2589 "PREVIEW_TEXT",
2590 "PREVIEW_TEXT_TYPE",
2591 "DETAIL_PICTURE",
2592 "DETAIL_TEXT",
2593 "DETAIL_TEXT_TYPE",
2594 "WF_STATUS_ID",
2595 "WF_PARENT_ELEMENT_ID",
2596 "WF_NEW",
2597 "WF_COMMENTS",
2598 "IN_SECTIONS",
2599 "CODE",
2600 "TAGS",
2601 "XML_ID",
2602 "TMP_ID",
2603 )
2604 );
2605 if($ar_element = $db_element->Fetch())
2606 {
2607 $PARENT_ID = intval($ar_element["WF_PARENT_ELEMENT_ID"]);
2608 if($PARENT_ID)
2609 {
2610 $obElement = new CIBlockElement;
2611 $ar_element["WF_PARENT_ELEMENT_ID"] = false;
2612
2613 if($ar_element["PREVIEW_PICTURE"])
2614 $ar_element["PREVIEW_PICTURE"] = CFile::MakeFileArray($ar_element["PREVIEW_PICTURE"]);
2615 else
2616 $ar_element["PREVIEW_PICTURE"] = array("tmp_name" => "", "del" => "Y");
2617
2618 if($ar_element["DETAIL_PICTURE"])
2619 $ar_element["DETAIL_PICTURE"] = CFile::MakeFileArray($ar_element["DETAIL_PICTURE"]);
2620 else
2621 $ar_element["DETAIL_PICTURE"] = array("tmp_name" => "", "del" => "Y");
2622
2623 $ar_element["IBLOCK_SECTION"] = array();
2624 if($ar_element["IN_SECTIONS"] == "Y")
2625 {
2626 $rsSections = CIBlockElement::GetElementGroups($ar_element["ID"], true, array('ID', 'IBLOCK_ELEMENT_ID'));
2627 while($arSection = $rsSections->Fetch())
2628 $ar_element["IBLOCK_SECTION"][] = $arSection["ID"];
2629 }
2630
2631 $ar_element["PROPERTY_VALUES"] = array();
2632 $arProps = &$ar_element["PROPERTY_VALUES"];
2633
2634 //Delete old files
2635 $rsProps = CIBlockElement::GetProperty($ar_element["IBLOCK_ID"], $PARENT_ID, array("value_id" => "asc"), array("PROPERTY_TYPE" => "F", "EMPTY" => "N"));
2636 while($arProp = $rsProps->Fetch())
2637 {
2638 if(!array_key_exists($arProp["ID"], $arProps))
2639 $arProps[$arProp["ID"]] = array();
2640 $arProps[$arProp["ID"]][$arProp["PROPERTY_VALUE_ID"]] = array(
2641 "VALUE" => array("tmp_name" => "", "del" => "Y"),
2642 "DESCRIPTION" => false,
2643 );
2644 }
2645
2646 //Add new proiperty values
2647 $rsProps = CIBlockElement::GetProperty($ar_element["IBLOCK_ID"], $ar_element["ID"], array("value_id" => "asc"));
2648 $i = 0;
2649 while($arProp = $rsProps->Fetch())
2650 {
2651 $i++;
2652 if(!array_key_exists($arProp["ID"], $arProps))
2653 $arProps[$arProp["ID"]] = array();
2654
2655 if($arProp["PROPERTY_VALUE_ID"])
2656 {
2657 if($arProp["PROPERTY_TYPE"] == "F")
2658 $arProps[$arProp["ID"]]["n".$i] = array(
2659 "VALUE" => CFile::MakeFileArray($arProp["VALUE"]),
2660 "DESCRIPTION" => $arProp["DESCRIPTION"],
2661 );
2662 else
2663 $arProps[$arProp["ID"]]["n".$i] = array(
2664 "VALUE" => $arProp["VALUE"],
2665 "DESCRIPTION" => $arProp["DESCRIPTION"],
2666 );
2667 }
2668 }
2669
2670 $obElement->Update($PARENT_ID, $ar_element);
2671
2672 CBPDocument::MergeDocuments(
2673 array("iblock", "CIBlockDocument", $PARENT_ID),
2674 array("iblock", "CIBlockDocument", $documentId)
2675 );
2676
2677 CIBlockElement::Delete($ID);
2678
2679 CIBlockElement::WF_CleanUpHistoryCopies($PARENT_ID, 0);
2680 $strSql = "update b_iblock_element set WF_STATUS_ID='1', WF_NEW=NULL WHERE ID=".$PARENT_ID." AND WF_PARENT_ELEMENT_ID IS NULL";
2681 $DB->Query($strSql);
2682 CIBlockElement::UpdateSearch($PARENT_ID);
2683 \Bitrix\Iblock\PropertyIndex\Manager::updateElementIndex($ar_element["IBLOCK_ID"], $PARENT_ID);
2684
2685 return $PARENT_ID;
2686 }
2687 else
2688 {
2689 CIBlockElement::WF_CleanUpHistoryCopies($ID, 0);
2690 $strSql = "update b_iblock_element set WF_STATUS_ID='1', WF_NEW=NULL WHERE ID=".$ID." AND WF_PARENT_ELEMENT_ID IS NULL";
2691 $DB->Query($strSql);
2692 CIBlockElement::UpdateSearch($ID);
2694
2695 return $ID;
2696 }
2697 }
2698 return false;
2699 }
2700
2701 public static function CloneElement($ID, $arFields = array())
2702 {
2703 global $DB;
2704 $ID = intval($ID);
2705
2706 $db_element = CIBlockElement::GetList(array(), array("ID"=>$ID, "SHOW_HISTORY"=>"Y"), false, false,
2707 array(
2708 "ID",
2709 "MODIFIED_BY",
2710 "DATE_CREATE",
2711 "CREATED_BY",
2712 "IBLOCK_ID",
2713 "ACTIVE",
2714 "ACTIVE_FROM",
2715 "ACTIVE_TO",
2716 "SORT",
2717 "NAME",
2718 "PREVIEW_PICTURE",
2719 "PREVIEW_TEXT",
2720 "PREVIEW_TEXT_TYPE",
2721 "DETAIL_PICTURE",
2722 "DETAIL_TEXT",
2723 "DETAIL_TEXT_TYPE",
2724 "WF_STATUS_ID",
2725 "WF_PARENT_ELEMENT_ID",
2726 "WF_COMMENTS",
2727 "IN_SECTIONS",
2728 "CODE",
2729 "TAGS",
2730 "XML_ID",
2731 "TMP_ID",
2732 )
2733 );
2734 if($ar_element = $db_element->Fetch())
2735 {
2736 $IBLOCK_ID = $ar_element["IBLOCK_ID"];
2737 if($ar_element["WF_PARENT_ELEMENT_ID"] > 0)
2738 {
2739 throw new Exception(GetMessage("IBD_ELEMENT_NOT_FOUND"));
2740 }
2741 else
2742 {
2743 if($ar_element["PREVIEW_PICTURE"])
2744 $ar_element["PREVIEW_PICTURE"] = CFile::MakeFileArray($ar_element["PREVIEW_PICTURE"]);
2745
2746 if($ar_element["DETAIL_PICTURE"])
2747 $ar_element["DETAIL_PICTURE"] = CFile::MakeFileArray($ar_element["DETAIL_PICTURE"]);
2748
2749 $ar_element["IBLOCK_SECTION"] = array();
2750 if($ar_element["IN_SECTIONS"] == "Y")
2751 {
2752 $rsSections = CIBlockElement::GetElementGroups($ar_element["ID"], true, array('ID', 'IBLOCK_ELEMENT_ID'));
2753 while($arSection = $rsSections->Fetch())
2754 $ar_element["IBLOCK_SECTION"][] = $arSection["ID"];
2755 }
2756
2757 $ar_element["PROPERTY_VALUES"] = array();
2758
2759 foreach($arFields as $field_id => $value)
2760 if(array_key_exists($field_id, $ar_element))
2761 $ar_element[$field_id] = $value;
2762
2763 $ar_element["WF_PARENT_ELEMENT_ID"] = $ID;
2764 $ar_element["IBLOCK_ID"] = $IBLOCK_ID;
2765
2766 $arProps = &$ar_element["PROPERTY_VALUES"];
2767
2768 //Add new proiperty values
2769 $rsProps = CIBlockElement::GetProperty($ar_element["IBLOCK_ID"], $ar_element["ID"], array("value_id" => "asc"));
2770 $i = 0;
2771 while($arProp = $rsProps->Fetch())
2772 {
2773 if(array_key_exists($arProp["CODE"], $ar_element["PROPERTY_VALUES"]))
2774 continue;
2775
2776 $i++;
2777 if(!array_key_exists($arProp["ID"], $arProps))
2778 $arProps[$arProp["ID"]] = array();
2779
2780 if($arProp["PROPERTY_VALUE_ID"])
2781 {
2782 if($arProp["PROPERTY_TYPE"] == "F")
2783 $arProps[$arProp["ID"]]["n".$i] = array(
2784 "VALUE" => CFile::MakeFileArray($arProp["VALUE"]),
2785 "DESCRIPTION" => $arProp["DESCRIPTION"],
2786 );
2787 else
2788 $arProps[$arProp["ID"]]["n".$i] = array(
2789 "VALUE" => $arProp["VALUE"],
2790 "DESCRIPTION" => $arProp["DESCRIPTION"],
2791 );
2792 }
2793 }
2794
2795 if (CIBlock::GetArrayByID($IBLOCK_ID, "RIGHTS_MODE") === "E")
2796 {
2797 $ibRights = new CIBlockElementRights(intval($IBLOCK_ID), $ID);
2798 $arRights = $ibRights->GetRights();
2799 $arNewRights = array();
2800 $rightIndex = 0;
2801 foreach($arRights as $rightID=>$right)
2802 {
2803 if ($right['IS_INHERITED'] !== 'Y')
2804 $arNewRights['n'.$rightIndex++] = $right;
2805 }
2806 $ar_element['RIGHTS'] = $arNewRights;
2807 }
2808
2809 $obElement = new CIBlockElement;
2810 $NEW_ID = $obElement->Add($ar_element);
2811 if(!$NEW_ID)
2812 throw new Exception($obElement->LAST_ERROR);
2813 else
2814 return $NEW_ID;
2815 }
2816 }
2817 else
2818 {
2819 throw new Exception(GetMessage("IBD_ELEMENT_NOT_FOUND"));
2820 }
2821 }
2822
2828 public static function UnpublishDocument($documentId)
2829 {
2830 global $DB;
2831 CIBlockElement::WF_CleanUpHistoryCopies($documentId, 0);
2832 $strSql = "update b_iblock_element set WF_STATUS_ID='2', WF_NEW='Y' WHERE ID=".intval($documentId)." AND WF_PARENT_ELEMENT_ID IS NULL";
2833 $z = $DB->Query($strSql);
2834 CIBlockElement::UpdateSearch($documentId);
2835 }
2836
2837 // array("read" => "it's reading", "write" => "it's writing")
2838 public static function GetAllowableOperations($documentType)
2839 {
2840 $iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
2841 if ($iblockId <= 0)
2842 throw new CBPArgumentOutOfRangeException("documentType", $documentType);
2843
2844 if (CIBlock::GetArrayByID($iblockId, "RIGHTS_MODE") === "E")
2845 {
2846 $ob = new CIBlockRights($iblockId);
2847 return $ob->GetRightsList();
2848 }
2849
2850 return array("read" => GetMessage("IBD_OPERATION_READ"), "write" => GetMessage("IBD_OPERATION_WRITE"));
2851 }
2852
2853 public static function GetJSFunctionsForFields($documentType, $objectName, $arDocumentFields = array(), $arDocumentFieldTypes = array())
2854 {
2855 return "";
2856 }
2857
2858 public static function GetFieldInputControlOptions($documentType, &$arFieldType, $jsFunctionName, &$value)
2859 {
2860 $result = "";
2861
2862 static $arDocumentFieldTypes = array();
2863 if (!array_key_exists($documentType, $arDocumentFieldTypes))
2864 $arDocumentFieldTypes[$documentType] = self::GetDocumentFieldTypes($documentType);
2865
2866 if (!array_key_exists($arFieldType["Type"], $arDocumentFieldTypes[$documentType])
2867 || !$arDocumentFieldTypes[$documentType][$arFieldType["Type"]]["Complex"])
2868 {
2869 return "";
2870 }
2871
2872 if ($arFieldType["Type"] == "E:EList")
2873 {
2874 if (is_array($value))
2875 {
2876 reset($value);
2877 $valueTmp = intval(current($value));
2878 }
2879 else
2880 {
2881 $valueTmp = intval($value);
2882 }
2883
2884 $iblockId = 0;
2885 if ($valueTmp > 0)
2886 {
2887 $dbResult = CIBlockElement::GetList(array(), array("ID" => $valueTmp), false, false, array("ID", "IBLOCK_ID"));
2888 if ($arResult = $dbResult->Fetch())
2889 $iblockId = $arResult["IBLOCK_ID"];
2890 }
2891 if ($iblockId <= 0 && intval($arFieldType["Options"]) > 0)
2892 $iblockId = intval($arFieldType["Options"]);
2893
2894 $defaultIBlockId = 0;
2895
2896 $result .= '<select id="WFSFormOptionsX" onchange="'.htmlspecialcharsbx($jsFunctionName).'(this.options[this.selectedIndex].value)">';
2897 $arIBlockType = CIBlockParameters::GetIBlockTypes();
2898 foreach ($arIBlockType as $iblockTypeId => $iblockTypeName)
2899 {
2900 $result .= '<optgroup label="'.$iblockTypeName.'">';
2901
2902 $dbIBlock = CIBlock::GetList(array("SORT" => "ASC"), array("TYPE" => $iblockTypeId, "ACTIVE" => "Y"));
2903 while ($arIBlock = $dbIBlock->GetNext())
2904 {
2905 $result .= '<option value="'.$arIBlock["ID"].'"'.(($arIBlock["ID"] == $iblockId) ? " selected" : "").'>'.$arIBlock["NAME"].'</option>';
2906 if (($defaultIBlockId <= 0) || ($arIBlock["ID"] == $iblockId))
2907 $defaultIBlockId = $arIBlock["ID"];
2908 }
2909
2910 $result .= '</optgroup>';
2911 }
2912 $result .= '</select><!--__defaultOptionsValue:'.$defaultIBlockId.'--><!--__modifyOptionsPromt:'.GetMessage("IBD_DOCUMENT_MOPROMT").'-->';
2913
2914 $arFieldType["Options"] = $defaultIBlockId;
2915 }
2916 elseif ($arFieldType["Type"] == "select")
2917 {
2918 $valueTmp = $arFieldType["Options"];
2919 if (!is_array($valueTmp))
2920 $valueTmp = array($valueTmp => $valueTmp);
2921
2922 $str = '';
2923 foreach ($valueTmp as $k => $v)
2924 {
2925 if (is_array($v) && count($v) == 2)
2926 {
2927 $v1 = array_values($v);
2928 $k = $v1[0];
2929 $v = $v1[1];
2930 }
2931
2932 if ($k != $v)
2933 $str .= '['.$k.']'.$v;
2934 else
2935 $str .= $v;
2936
2937 $str .= "\n";
2938 }
2939 $result .= '<textarea id="WFSFormOptionsX" rows="5" cols="30">'.htmlspecialcharsbx($str).'</textarea><br />';
2940 $result .= GetMessage("IBD_DOCUMENT_XFORMOPTIONS1").'<br />';
2941 $result .= GetMessage("IBD_DOCUMENT_XFORMOPTIONS2").'<br />';
2942 $result .= '<script>
2943 function WFSFormOptionsXFunction()
2944 {
2945 var result = {};
2946 var i, id, val, str = document.getElementById("WFSFormOptionsX").value;
2947
2948 var arr = str.split(/[\r\n]+/);
2949 var p, re = /\[([^\]]+)\].+/;
2950 for (i in arr)
2951 {
2952 str = arr[i].replace(/^\s+|\s+$/g, \'\');
2953 if (str.length > 0)
2954 {
2955 id = str.match(re);
2956 if (id)
2957 {
2958 p = str.indexOf(\']\');
2959 id = id[1];
2960 val = str.substr(p + 1);
2961 }
2962 else
2963 {
2964 val = str;
2965 id = val;
2966 }
2967 result[id] = val;
2968 }
2969 }
2970
2971 return result;
2972 }
2973 </script>';
2974 $result .= '<input type="button" onclick="'.htmlspecialcharsbx($jsFunctionName).'(WFSFormOptionsXFunction())" value="'.GetMessage("IBD_DOCUMENT_XFORMOPTIONS3").'">';
2975 }
2976
2977 return $result;
2978 }
2979
2980 public static function GetAllowableUserGroups($documentType, $withExtended = false)
2981 {
2982 $documentType = trim($documentType);
2983 if ($documentType == '')
2984 return false;
2985
2986 $iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
2987
2988 $result = array('Author' => GetMessage('IBD_DOCUMENT_AUTHOR'));
2989
2990 $groupsId = array(1);
2991 $extendedGroupsCode = array();
2992 if(CIBlock::GetArrayByID($iblockId, "RIGHTS_MODE") === "E")
2993 {
2994 $obRights = new CIBlockRights($iblockId);
2995 foreach($obRights->GetGroups(/*"element_bizproc_start"*/) as $GROUP_CODE)
2996 if(preg_match("/^G(\\d+)\$/", $GROUP_CODE, $match))
2997 $groupsId[] = $match[1];
2998 else
2999 $extendedGroupsCode[] = $GROUP_CODE;
3000 }
3001 else
3002 {
3003 foreach(CIBlock::GetGroupPermissions($iblockId) as $groupId => $perm)
3004 {
3005 if ($perm > "R")
3006 $groupsId[] = $groupId;
3007 }
3008 }
3009
3010 $dbGroupsList = CGroup::GetListEx(array("NAME" => "ASC"), array("ID" => $groupsId));
3011 while ($arGroup = $dbGroupsList->Fetch())
3012 $result[$arGroup["ID"]] = $arGroup["NAME"];
3013
3014 if ($withExtended && $extendedGroupsCode)
3015 {
3016 foreach ($extendedGroupsCode as $groupCode)
3017 {
3018 $result['group_'.$groupCode] = CBPHelper::getExtendedGroupName($groupCode);
3019 }
3020 }
3021
3022 return $result;
3023 }
3024
3025 public static function GetUsersFromUserGroup($group, $documentId)
3026 {
3027 $group = mb_strtolower($group);
3028 if ($group == 'author')
3029 {
3030 $documentId = (int)$documentId;
3031 if ($documentId <= 0)
3032 return array();
3033
3034 $db = CIBlockElement::GetList(array(), array("ID" => $documentId, "SHOW_NEW" => "Y", "SHOW_HISTORY" => "Y"), false, false, array("ID", "IBLOCK_ID", "CREATED_BY"));
3035 if ($ar = $db->Fetch())
3036 return array($ar["CREATED_BY"]);
3037 return array();
3038 }
3039
3040 if ((string)intval($group) !== (string)$group)
3041 return array();
3042
3043 $group = (int)$group;
3044 if ($group <= 0)
3045 return array();
3046
3047 $arResult = array();
3048
3049 $arFilter = ['ACTIVE' => 'Y', 'IS_REAL_USER' => true];
3050 if ($group != 2)
3051 {
3052 $arFilter["GROUPS_ID"] = $group;
3053 }
3054
3055 $dbUsersList = CUser::GetList("ID", "ASC", $arFilter, ['FIELDS' => ['ID']]);
3056 while ($arUser = $dbUsersList->Fetch())
3057 {
3058 $arResult[] = $arUser["ID"];
3059 }
3060
3061 return $arResult;
3062 }
3063
3064 public static function SetPermissions($documentId, $workflowId, $arPermissions, $bRewrite = true)
3065 {
3066 $documentId = intval($documentId);
3067 if ($documentId <= 0)
3068 throw new CBPArgumentNullException("documentId");
3069
3070 $documentType = self::GetDocumentType($documentId);
3071 $iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
3072 if ($iblockId <= 0)
3073 throw new CBPArgumentOutOfRangeException("documentType", $documentType);
3074
3075 if (CIBlock::GetArrayByID($iblockId, "RIGHTS_MODE") !== "E")
3076 return;
3077
3078 $ob = new CIBlockElementRights($iblockId, $documentId);
3079 $documentRights = $ob->GetRights();
3080
3081 $mode = 'Hold';
3082 $scope = 'ScopeWorkflow';
3083
3084 if (is_array($bRewrite) && class_exists('CBPSetPermissionsMode'))
3085 {
3086 if (isset($bRewrite['setMode']))
3087 $mode = CBPSetPermissionsMode::outMode($bRewrite['setMode']);
3088 if (isset($bRewrite['setScope']))
3089 $scope = CBPSetPermissionsMode::outScope($bRewrite['setScope']);
3090 }
3091 elseif ($bRewrite == true)
3092 {
3093 $mode = 'Clear';
3094 }
3095
3096 $overrideCodes = array();
3097 if ($mode == 'Clear' || $mode == 'Rewrite')
3098 {
3099 foreach ($documentRights as $i => $arRight)
3100 {
3101 if ($scope == 'ScopeDocument' || $scope == 'ScopeWorkflow' && $arRight["XML_ID"] == $workflowId)
3102 {
3103 if ($mode == 'Clear')
3104 unset($documentRights[$i]);
3105
3106 if ($mode == 'Rewrite')
3107 $overrideCodes[$arRight["GROUP_CODE"]] = $i;
3108 }
3109
3110 }
3111 }
3112
3113 $i = 0;
3114 $l = mb_strlen("user_");
3115 foreach ($arPermissions as $taskId => $arUsers)
3116 {
3117 foreach ($arUsers as $user)
3118 {
3119 if (!$user)
3120 continue;
3121 $gc = null;
3122 if ($user == 'author')
3123 {
3124 $u = self::GetUsersFromUserGroup('author', $documentId);
3125 foreach ($u as $u1)
3126 $gc = "U".$u1;
3127 }
3128 elseif (mb_strpos($user, 'group_') === 0)
3129 {
3130 $gc = mb_strtoupper(mb_substr($user, mb_strlen('group_')));
3131 }
3132 else
3133 {
3134 $gc = ((mb_substr($user, 0, $l) == "user_") ? "U".mb_substr($user, $l) : "G".$user);
3135 }
3136 if ($gc != null)
3137 {
3138 $documentRights["n".$i] = array("GROUP_CODE" => $gc, "TASK_ID" => $taskId, "XML_ID" => $workflowId);
3139 $i++;
3140
3141 if (isset($overrideCodes[$gc]))
3142 unset($documentRights[$overrideCodes[$gc]]);
3143 }
3144 }
3145 }
3146
3147 $ob->SetRights($documentRights);
3148 }
3149
3156 public static function GetDocumentForHistory($documentId, $historyIndex)
3157 {
3158 $documentId = intval($documentId);
3159 if ($documentId <= 0)
3160 throw new CBPArgumentNullException("documentId");
3161
3162 $arResult = null;
3163
3164 $dbDocumentList = CIBlockElement::GetList(
3165 array(),
3166 array("ID" => $documentId, "SHOW_NEW"=>"Y", "SHOW_HISTORY" => "Y")
3167 );
3168 if ($objDocument = $dbDocumentList->GetNextElement())
3169 {
3170 $arDocumentFields = $objDocument->GetFields();
3171 $arDocumentProperties = $objDocument->GetProperties();
3172
3173 $arResult["NAME"] = $arDocumentFields["~NAME"];
3174
3175 $arResult["FIELDS"] = array();
3176 foreach ($arDocumentFields as $fieldKey => $fieldValue)
3177 {
3178 if ($fieldKey == "~PREVIEW_PICTURE" || $fieldKey == "~DETAIL_PICTURE")
3179 {
3180 $arResult["FIELDS"][mb_substr($fieldKey, 1)] = CBPDocument::PrepareFileForHistory(
3181 array("iblock", "CIBlockDocument", $documentId),
3182 $fieldValue,
3183 $historyIndex
3184 );
3185 }
3186 elseif (mb_substr($fieldKey, 0, 1) == "~")
3187 {
3188 $arResult["FIELDS"][mb_substr($fieldKey, 1)] = $fieldValue;
3189 }
3190 }
3191
3192 $arResult["PROPERTIES"] = array();
3193 foreach ($arDocumentProperties as $propertyKey => $propertyValue)
3194 {
3195 if ($propertyValue["USER_TYPE"] <> '')
3196 {
3197 $arResult["PROPERTIES"][$propertyKey] = array(
3198 "VALUE" => $propertyValue["VALUE"],
3199 "DESCRIPTION" => $propertyValue["DESCRIPTION"]
3200 );
3201 }
3202 elseif ($propertyValue["PROPERTY_TYPE"] == "L")
3203 {
3204 $arResult["PROPERTIES"][$propertyKey] = array(
3205 "VALUE" => $propertyValue["VALUE_ENUM_ID"],
3206 "DESCRIPTION" => $propertyValue["DESCRIPTION"]
3207 );
3208 }
3209 elseif ($propertyValue["PROPERTY_TYPE"] == "F")
3210 {
3211 $arResult["PROPERTIES"][$propertyKey] = array(
3212 "VALUE" => CBPDocument::PrepareFileForHistory(
3213 array("iblock", "CIBlockDocument", $documentId),
3214 $propertyValue["VALUE"],
3215 $historyIndex
3216 ),
3217 "DESCRIPTION" => $propertyValue["DESCRIPTION"]
3218 );
3219 }
3220 else
3221 {
3222 $arResult["PROPERTIES"][$propertyKey] = array(
3223 "VALUE" => $propertyValue["VALUE"],
3224 "DESCRIPTION" => $propertyValue["DESCRIPTION"]
3225 );
3226 }
3227 }
3228 }
3229
3230 return $arResult;
3231 }
3232
3239 public static function RecoverDocumentFromHistory($documentId, $arDocument)
3240 {
3241 $documentId = intval($documentId);
3242 if ($documentId <= 0)
3243 throw new CBPArgumentNullException("documentId");
3244
3245 $arFields = $arDocument["FIELDS"];
3246 if ($arFields["PREVIEW_PICTURE"] <> '')
3247 $arFields["PREVIEW_PICTURE"] = CFile::MakeFileArray($arFields["PREVIEW_PICTURE"]);
3248 if ($arFields["DETAIL_PICTURE"] <> '')
3249 $arFields["DETAIL_PICTURE"] = CFile::MakeFileArray($arFields["DETAIL_PICTURE"]);
3250
3251 $arFields["PROPERTY_VALUES"] = array();
3252
3253 $dbProperties = CIBlockProperty::GetList(
3254 array("sort" => "asc", "name" => "asc"),
3255 array("IBLOCK_ID" => $arFields["IBLOCK_ID"])
3256 );
3257 while ($arProperty = $dbProperties->Fetch())
3258 {
3259 if (trim($arProperty["CODE"]) <> '')
3260 $key = $arProperty["CODE"];
3261 else
3262 $key = $arProperty["ID"];
3263
3264 if (!array_key_exists($key, $arDocument["PROPERTIES"]))
3265 continue;
3266
3267 $documentValue = $arDocument["PROPERTIES"][$key]["VALUE"];
3268
3269 if($arProperty["USER_TYPE"] == '' && $arProperty["PROPERTY_TYPE"] == "F")
3270 {
3271 $arFields["PROPERTY_VALUES"][$key] = array();
3272 //Mark files to be deleted
3273 $rsFiles = CIBlockElement::GetProperty($arFields["IBLOCK_ID"], $documentId, array("ID"=>$arProperty["ID"], "EMPTY"=>"N"));
3274 while($arFile = $rsFiles->Fetch())
3275 {
3276 if($arFile["PROPERTY_VALUE_ID"] > 0)
3277 $arFields["PROPERTY_VALUES"][$key][$arFile["PROPERTY_VALUE_ID"]] = array(
3278 "VALUE" => array("del"=>"Y"),
3279 "DESCRIPTION" => "",
3280 );
3281 }
3282 //Restore from history
3284 if(is_array($documentValue))
3285 {
3286 $n = 0;
3287 foreach ($documentValue as $i => $v)
3288 if($v <> '')
3289 {
3290 $arFields["PROPERTY_VALUES"][$key]["n".($n++)] = array(
3291 "VALUE" => CFile::MakeFileArray($io->GetPhysicalName($v)),
3292 "DESCRIPTION" => $arDocument["PROPERTIES"][$key]["DESCRIPTION"][$i]
3293 );
3294 }
3295 }
3296 else
3297 {
3298 if($documentValue <> '')
3299 {
3300 $arFields["PROPERTY_VALUES"][$key]["n0"] = array(
3301 "VALUE" => CFile::MakeFileArray($io->GetPhysicalName($documentValue)),
3302 "DESCRIPTION" => $arDocument["PROPERTIES"][$key]["DESCRIPTION"]
3303 );
3304 }
3305 }
3306 }
3307 else
3308 {
3309 if(is_array($documentValue))
3310 {
3311 $n = 0;
3312 foreach ($documentValue as $i => $v)
3313 if($v <> '')
3314 $arFields["PROPERTY_VALUES"][$key]["n".($n++)] = array(
3315 "VALUE" => $v,
3316 "DESCRIPTION" => $arDocument["PROPERTIES"][$key]["DESCRIPTION"][$i]
3317 );
3318 }
3319 else
3320 {
3321 if($documentValue <> '')
3322 $arFields["PROPERTY_VALUES"][$key]["n0"] = array(
3323 "VALUE" => $documentValue,
3324 "DESCRIPTION" => $arDocument["PROPERTIES"][$key]["DESCRIPTION"]
3325 );
3326 }
3327 }
3328 }
3329
3330 $iblockElement = new CIBlockElement();
3331 $res = $iblockElement->Update($documentId, $arFields);
3332 if (intval($arFields["WF_STATUS_ID"]) > 1 && intval($arFields["WF_PARENT_ELEMENT_ID"]) <= 0)
3333 self::UnpublishDocument($documentId);
3334 if (!$res)
3335 throw new Exception($iblockElement->LAST_ERROR);
3336
3337 return true;
3338 }
3339
3340 public static function isExtendedPermsSupported($documentType)
3341 {
3342 $iblockId = (int)mb_substr($documentType, mb_strlen("iblock_"));
3343 if ($iblockId <= 0)
3344 throw new CBPArgumentOutOfRangeException("documentType", $documentType);
3345
3346 return CIBlock::GetArrayByID($iblockId, "RIGHTS_MODE");
3347 }
3348
3349 public static function generatePropertyCode($name, $code, $iblockId, $propertyId = 0)
3350 {
3351 if(empty($code) || is_numeric($code))
3352 {
3353 $code = CUtil::translit($name, LANGUAGE_ID, array("change_case" => "U"));
3354 }
3355
3356 $object = CIBlockProperty::getList(array(), array("IBLOCK_ID" => $iblockId));
3357 while($property = $object->fetch())
3358 {
3359 if($property["CODE"] == $code && $property["ID"] != $propertyId)
3360 {
3362 break;
3363 }
3364 }
3365
3366 return $code;
3367 }
3368}
return select
Определения access_edit.php:440
$type
Определения options.php:106
const BX_ROOT
Определения bx_root.php:3
while($arIBType=$dbIBlockType->Fetch()) $dbIBlock
Определения options.php:178
global $APPLICATION
Определения include.php:80
$arResult
Определения generate_coupon.php:16
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
const INTERNALSELECT
Определения fieldtype.php:52
static updateElementIndex($iblockId, $elementId)
Определения manager.php:264
static CalendarDate($sFieldName, $sValue="", $size="10", $bTime=false)
Определения admin_calendar.php:78
static GetListEx($arOrder=["ID"=> "DESC"], $arFilter=[], $arGroupBy=false, $arNavStartParams=false, $arSelectFields=[])
Определения group.php:736
static GetOperations($ID, $return_names=false)
Определения task.php:230
const ViewWorkflow
Определения constants.php:211
const CreateWorkflow
Определения constants.php:213
const StartWorkflow
Определения constants.php:212
const ReadDocument
Определения constants.php:216
const WriteDocument
Определения constants.php:215
static outScope($v)
Определения constants.php:246
static outMode($v)
Определения constants.php:229
static GetInstance()
Определения virtual_io.php:60
static RecoverDocumentFromHistory($documentId, $arDocument)
Определения iblockdocument.php:3239
static generatePropertyCode($name, $code, $iblockId, $propertyId=0)
Определения iblockdocument.php:3349
static generateMnemonicCode($integerCode=0)
Определения iblockdocument.php:1675
static GetDocumentFieldTypes($documentType)
Определения iblockdocument.php:1584
static CreateDocument($parentDocumentId, $arFields)
Определения iblockdocument.php:2410
static GetFieldInputValuePrintable($documentType, $arFieldType, $fieldValue)
Определения iblockdocument.php:826
static GetDocumentType($documentId)
Определения iblockdocument.php:1274
static UpdateDocument($documentId, $arFields)
Определения iblockdocument.php:1825
static PublishDocument($documentId)
Определения iblockdocument.php:2570
static getDocumentTypeName($documentType)
Определения iblockdocument.php:1028
static SetPermissions($documentId, $workflowId, $arPermissions, $bRewrite=true)
Определения iblockdocument.php:3064
static CanUserOperateDocument($operation, $userId, $documentId, $arParameters=array())
Определения iblockdocument.php:2055
static AddDocumentField($documentType, $arFields)
Определения iblockdocument.php:1689
static getDocumentTypeCaption($documentType)
Определения iblockdocument.php:1047
static GetAllowableOperations($documentType)
Определения iblockdocument.php:2838
static IsDocumentLocked($documentId, $workflowId)
Определения iblockdocument.php:2040
static GetFieldInputValue($documentType, $arFieldType, $arFieldName, $arRequest, &$arErrors)
Определения iblockdocument.php:564
static GetDocumentFields($documentType)
Определения iblockdocument.php:1291
static GetFieldInputControl($documentType, $arFieldType, $arFieldName, $fieldValue, $bAllowSelection=false, $publicMode=false)
Определения iblockdocument.php:15
static LockDocument($documentId, $workflowId)
Определения iblockdocument.php:1976
static UnpublishDocument($documentId)
Определения iblockdocument.php:2828
static GetFieldValuePrintable($documentId, $fieldName, $fieldType, $fieldValue, $arFieldType)
Определения iblockdocument.php:938
static getDocumentName($documentId)
Определения iblockdocument.php:1007
static GetJSFunctionsForFields($documentType, $objectName, $arDocumentFields=array(), $arDocumentFieldTypes=array())
Определения iblockdocument.php:2853
static GetDocumentAdminPage($documentId)
Определения iblockdocument.php:974
static GetVersion()
Определения iblockdocument.php:962
static CloneElement($ID, $arFields=array())
Определения iblockdocument.php:2701
static GetDocumentForHistory($documentId, $historyIndex)
Определения iblockdocument.php:3156
static CanUserOperateDocumentType($operation, $userId, $documentType, $arParameters=array())
Определения iblockdocument.php:2248
static GetDocument($documentId)
Определения iblockdocument.php:1094
static UnlockDocument($documentId, $workflowId)
Определения iblockdocument.php:2005
static GetUsersFromUserGroup($group, $documentId)
Определения iblockdocument.php:3025
static GetAllowableUserGroups($documentType, $withExtended=false)
Определения iblockdocument.php:2980
static isDocumentExists($documentId)
Определения iblockdocument.php:1075
static DeleteDocument($documentId)
Определения iblockdocument.php:2556
static GetFieldInputControlOptions($documentType, &$arFieldType, $jsFunctionName, &$value)
Определения iblockdocument.php:2858
static getEntityName()
Определения iblockdocument.php:10
static isExtendedPermsSupported($documentType)
Определения iblockdocument.php:3340
static GetIBlockTypes($arTop=false)
Определения comp_parameters.php:932
$right
Определения options.php:8
$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
$res
Определения filter_act.php:7
$perm
Определения options.php:169
$result
Определения get_property_values.php:14
if($ajaxMode) $ID
Определения get_user.php:27
$iblockTypeId
Определения group_lists.php:25
$iblockId
Определения iblock_catalog_edit.php:30
$select
Определения iblock_catalog_list.php:194
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $DB
Определения cron_frame.php:29
$IBLOCK_ID
Определения csv_new_run.php:168
$io
Определения csv_new_run.php:98
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$l
Определения options.php:783
$z
Определения options.php:31
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
HTMLToTxt($str, $strSiteUrl="", $aDelete=[], $maxlen=70)
Определения tools.php:2587
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$name
Определения menu_edit.php:35
$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
const ADMIN_SECTION
Определения rss.php:2
$i
Определения factura.php:643
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
const SITE_ID
Определения sonet_set_content_view.php:12
$k
Определения template_pdf.php:567
$GLOBALS['_____370096793']
Определения update_client.php:1
$n
Определения update_log.php:107
$dbResult
Определения updtr957.php:3
$arFilter
Определения user_search.php:106
$url
Определения iframe.php:7
$arIBlock['PROPERTY']
Определения yandex_detail.php:172
$rsProps
Определения yandex_run.php:584
$iterator
Определения yandex_run.php:610