-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfieldsSP.php
More file actions
117 lines (102 loc) · 4.98 KB
/
Copy pathfieldsSP.php
File metadata and controls
117 lines (102 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
// fieldsSP.php — тянет поля CRM и строит таблицу соответствий поле - колонка файла
require_once(__DIR__ . '/crestcurrent.php');
require_once(__DIR__ . '/crest.php');
//Забираем ID сделки
$placementRaw = $_POST['PLACEMENT_OPTIONS'] ?? '';
$placement = $placementRaw ? json_decode($placementRaw, true) : [];
$dealId = 0;
// пытаемся надёжно вытащить ID сделки из разных возможных ключей
foreach (['DEAL_ID', 'dealId', 'ENTITY_ID', 'ID'] as $k) {
if (isset($placement[$k]) && (int)$placement[$k] > 0) {
$dealId = (int)$placement[$k];
break;
}
}
// иногда бывает вложенность
if (!$dealId && isset($placement['options']['ID'])) $dealId = (int)$placement['options']['ID'];
if (!$dealId && isset($placement['value']['ID'])) $dealId = (int)$placement['value']['ID'];
// Заберём данные из pars.php
$eTypeId = isset($_POST['entityTypeId']) ? (int)$_POST['entityTypeId'] : 0;
$headers = isset($_POST['headers']) && is_array($_POST['headers']) ? $_POST['headers'] : [];
$fileToken = $_POST['file_token'] ?? '';
if ($eTypeId <= 0) exit('<div>ENTITY_TYPE_ID не указан</div>');
if (empty($headers)) exit('<div>Нет заголовков файла. Сначала загрузите XLSX.</div>');
if ($fileToken === '') exit('<div>Нет токена файла</div>');
// Тянем поля смарт-процесса
$resp = CRest::call('crm.item.fields', [
'entityTypeId' => $eTypeId,
'useOriginalUfNames' => 'N',
]);
if (!$resp || empty($resp['result']['fields'])) {
exit('<div>Не удалось получить поля для entityTypeId ' . $eTypeId . '</div>');
}
$fields = $resp['result']['fields'];
// рисуем таблицу соответствий: поле CRM select(headers)
?>
<h3>Текущий пользователь Bitrix24</h3>
<div id="name">
<?php
require_once(__DIR__ . '/crestcurrent.php');
// берём результат из CRestCurrent, если есть
$r1 = CRest::call('user.current');
$r2 = CRestCurrent::call('user.current');
$u = $r2['result'] ?? $r1['result'] ?? null;
echo $u ? htmlspecialchars(($u['NAME'] ?? '') . ' ' . ($u['LAST_NAME'] ?? '')) : '<span class="muted">Пользователь не получен</span>';
?>
</div>
<form id="mapping-form"
hx-post="runImport.php"
hx-target="#step"
hx-swap="innerHTML">
<!-- протащим обратно entityTypeId file_token -->
<input type="hidden" name="entityTypeId" value="<?= htmlspecialchars($eTypeId) ?>">
<input type="hidden" name="file_token" value="<?= htmlspecialchars($fileToken) ?>">
<input type="hidden" name="PLACEMENT_OPTIONS"
value="<?= htmlspecialchars($_POST['PLACEMENT_OPTIONS'] ?? '', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') ?>">
<?php if ($dealId > 0): ?>
<!-- parentId2 связь со сделкой -->
<input type="hidden" name="defaults[parentId2]" value="<?= $dealId ?>">
<!-- crm_entity UF_CRM_* строка формата -->
<input type="hidden" name="defaults[crm_entity]" value="<?= 'D_'.$dealId ?>">
<div style="margin:8px 0;color:#555">
По-умолчанию будет установлена связь со сделкой с ID: "<strong><?= (int)$dealId ?></strong>"
<code>crm_entity</code> = <?= (int)$dealId; ?>.
</div>
<?php endif; ?>
<h3>Соответствие полей</h3>
<table border="1" cellpadding="6" cellspacing="0" style="border-collapse:collapse;">
<tr>
<th>Поле CRM</th>
<th>Колонка XLSX</th>
<th>Тип</th>
</tr>
<?php foreach ($fields as $code => $meta): ?>
<?php
// отфильтруем поля только для ввода (readOnly пропускаем)
if (!empty($meta['isReadOnly'])) continue;
$title = $meta['title'] ?? $code;
$type = $meta['type'] ?? 'string';
?>
<tr>
<td>
<strong><?= htmlspecialchars($title) ?></strong><br>
<small><?= htmlspecialchars($code) ?></small>
</td>
<td>
<label>
<select name="map[<?= htmlspecialchars($code) ?>]">
<option value="">— пропустить —</option>
<?php foreach ($headers as $h): ?>
<option value="<?= htmlspecialchars($h) ?>"><?= htmlspecialchars($h) ?></option>
<?php endforeach; ?>
</select>
</label>
</td>
<td><?= htmlspecialchars($type) ?></td>
</tr>
<?php endforeach; ?>
</table>
<br>
<button type="submit">Запустить импорт</button>
</form>