PageRenderTime 24ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/highloadblock/admin/highloadblock_directory_ajax.php

https://gitlab.com/alexprowars/bitrix
PHP | 461 lines | 414 code | 45 blank | 2 comment | 67 complexity | 18072152eed318c4ebb8caccab74f8f5 MD5 | raw file
  1. <?
  2. /** @global CUser $USER */
  3. /** @global CMain $APPLICATION */
  4. define('STOP_STATISTICS', true);
  5. define('DisableEventsCheck', true);
  6. define('BX_SECURITY_SHOW_MESSAGE', true);
  7. define("PUBLIC_AJAX_MODE", true);
  8. define("NOT_CHECK_PERMISSIONS", true);
  9. use Bitrix\Main\Loader,
  10. Bitrix\Main\Localization\Loc;
  11. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
  12. Loc::loadMessages(__FILE__);
  13. header('Content-Type: application/x-javascript; charset='.LANG_CHARSET);
  14. $defaultValues = array(
  15. 'UF_XML_ID' => '',
  16. 'ID' => 0,
  17. 'UF_NAME' => '',
  18. 'UF_LINK' => '',
  19. 'UF_SORT' => 100,
  20. 'UF_FILE' => 0,
  21. 'MULTIPLE' => 'N',
  22. 'UF_DEF' => 'N',
  23. 'UF_DESCRIPTION' => '',
  24. 'UF_FULL_DESCRIPTION' => ''
  25. );
  26. if ($USER->IsAuthorized() && check_bitrix_sessid() && isset($_REQUEST['IBLOCK_ID']))
  27. {
  28. if (!Loader::includeModule('highloadblock') || !Loader::includeModule('iblock'))
  29. {
  30. echo Bitrix\Main\Web\Json::encode(array('ERROR' => 'SS_MODULE_NOT_INSTALLED'));
  31. require($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/epilog_admin_after.php');
  32. die();
  33. }
  34. $iblockID = (int)$_REQUEST['IBLOCK_ID'];
  35. if ($iblockID < 0)
  36. {
  37. echo Bitrix\Main\Web\Json::encode(array('ERROR' => 'SS_IBLOCK_ID_ABSENT'));
  38. require($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/epilog_admin_after.php');
  39. die();
  40. }
  41. elseif ($iblockID === 0)
  42. {
  43. if (!$USER->IsAdmin())
  44. {
  45. echo Bitrix\Main\Web\Json::encode(array('ERROR' => 'SS_NO_ADMIN'));
  46. require($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/epilog_admin_after.php');
  47. die();
  48. }
  49. }
  50. else
  51. {
  52. $rsIBlocks = CIBlock::GetList(
  53. array(),
  54. array(
  55. 'ID' => $iblockID,
  56. 'CHECK_PERMISSIONS' => 'N'
  57. )
  58. );
  59. $arIBlock = $rsIBlocks->Fetch();
  60. if ($arIBlock)
  61. {
  62. if (!CIBlockRights::UserHasRightTo($iblockID, $iblockID, "iblock_edit"))
  63. {
  64. echo Bitrix\Main\Web\Json::encode(array('ERROR' => 'SS_ACCESS_DENIED'));
  65. require($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/epilog_admin_after.php');
  66. die();
  67. }
  68. }
  69. else
  70. {
  71. echo Bitrix\Main\Web\Json::encode(array('ERROR' => 'SS_IBLOCK_ABSENT'));
  72. require($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/epilog_admin_after.php');
  73. die();
  74. }
  75. }
  76. CUtil::JSPostUnescape();
  77. $multiple = 'N';
  78. if (isset($_REQUEST['multiple']) && $_REQUEST['multiple'] === 'Y')
  79. $multiple = 'Y';
  80. $defaultValues['MULTIPLE'] = $multiple;
  81. function addTableXmlIDCell($intPropID, $arPropInfo)
  82. {
  83. return '<input type="text" onchange="getDirectoryTableHead(this);" name="PROPERTY_DIRECTORY_VALUES['.$intPropID.'][UF_XML_ID]" id="PROPERTY_VALUES_XML_'.$intPropID.'" value="'.htmlspecialcharsbx($arPropInfo['UF_XML_ID']).'" size="20" style="width:90%">';
  84. }
  85. function addTableIdCell($intPropID, $arPropInfo)
  86. {
  87. return '<input type="hidden" name="PROPERTY_DIRECTORY_VALUES['.$intPropID.'][ID]" id="PROPERTY_VALUES_ID_'.$intPropID.'" value="'.htmlspecialcharsbx($arPropInfo['ID']).'">';
  88. }
  89. function addTableNameCell($intPropID, $arPropInfo)
  90. {
  91. return '<input type="text" name="PROPERTY_DIRECTORY_VALUES['.$intPropID.'][UF_NAME]" id="PROPERTY_VALUES_NAME_'.$intPropID.'" value="'.htmlspecialcharsbx($arPropInfo['UF_NAME']).'" size="20" style="width:90%">';
  92. }
  93. function addTableLinkCell($intPropID, $arPropInfo)
  94. {
  95. return '<input type="text" name="PROPERTY_DIRECTORY_VALUES['.$intPropID.'][UF_LINK]" id="PROPERTY_VALUES_LINK_'.$intPropID.'" value="'.htmlspecialcharsbx($arPropInfo['UF_LINK']).'" size="35" style="width:90%">';
  96. }
  97. function addTableSortCell($intPropID, $arPropInfo)
  98. {
  99. $sort = (isset($arPropInfo['UF_SORT']) && intval($arPropInfo['UF_SORT']) > 0) ? intval($arPropInfo['UF_SORT']) : 100;
  100. return '<input type="text" name="PROPERTY_DIRECTORY_VALUES['.$intPropID.'][UF_SORT]" id="PROPERTY_VALUES_SORT_'.$intPropID.'" value="'.$sort.'" size="5" maxlength="11">';
  101. }
  102. function addTableFileCell($intPropID, $arPropInfo)
  103. {
  104. static $maxImageSize = null;
  105. static $filemanIncluded = null;
  106. if (null === $maxImageSize)
  107. {
  108. $maxImageSize = array(
  109. "W" => COption::GetOptionString("iblock", "list_image_size"),
  110. "H" => COption::GetOptionString("iblock", "list_image_size"),
  111. );
  112. }
  113. $arPropInfo["UF_FILE"] = intval($arPropInfo["UF_FILE"]);
  114. if ($filemanIncluded === null)
  115. {
  116. $filemanIncluded = Loader::includeModule('fileman');
  117. }
  118. if (!$filemanIncluded)
  119. return '';
  120. $strShowFile = '';
  121. if (0 < $arPropInfo["UF_FILE"])
  122. {
  123. $strShowFile = CFile::ShowFile(
  124. $arPropInfo["UF_FILE"],
  125. 0,
  126. $maxImageSize['W'],
  127. $maxImageSize['H'],
  128. false
  129. );
  130. if ('' !== $strShowFile)
  131. $strShowFile .= '<br>';
  132. }
  133. return $strShowFile.CFile::InputFile(
  134. "PROPERTY_DIRECTORY_VALUES[$intPropID][FILE]",
  135. 20,
  136. $arPropInfo["UF_FILE"],
  137. false, 0, "IMAGE", "", 0, "class=typeinput", "", true, false);
  138. }
  139. function addTableDefCell($intPropID, $arPropInfo)
  140. {
  141. return '<input type="'.('Y' == $arPropInfo['MULTIPLE'] ? 'checkbox' : 'radio').'" name="PROPERTY_VALUES_DEF'.('Y' == $arPropInfo['MULTIPLE'] ? '[]' : '').'" id="PROPERTY_VALUES_DEF_'.$intPropID.'" value="'.$intPropID.'" '.('1' == $arPropInfo['UF_DEF'] ? 'checked="checked"' : '').'>';
  142. }
  143. function addTableDescriptionCell($intPropID, $arPropInfo)
  144. {
  145. return '<input type="text" name="PROPERTY_DIRECTORY_VALUES['.$intPropID.'][UF_DESCRIPTION]" id="PROPERTY_VALUES_DESCRIPTION_'.$intPropID.'" value="'.(is_string($arPropInfo['UF_DESCRIPTION']) ? htmlspecialcharsbx($arPropInfo['UF_DESCRIPTION']) : '').'" style="width:90%">';
  146. }
  147. function addTableFullDescriptionCell($intPropID, $arPropInfo)
  148. {
  149. return '<input type="text" name="PROPERTY_DIRECTORY_VALUES['.$intPropID.'][UF_FULL_DESCRIPTION]" id="PROPERTY_VALUES_FULL_DESCRIPTION_'.$intPropID.'" value="'.(is_string($arPropInfo['UF_FULL_DESCRIPTION']) ? htmlspecialcharsbx($arPropInfo['UF_FULL_DESCRIPTION']) : '').'" style="width:90%">';
  150. }
  151. function addTableDelField($intPropID)
  152. {
  153. return '<div style="background: url(/bitrix/panel/main/images/bx-admin-sprite-small-1.png) no-repeat 6px -2446px; display: inline-block; cursor: pointer; height: 23px; margin:0; opacity: 0.7; vertical-align: middle; width: 23px;" onclick="this.parentNode.parentNode.style.display = \'none\'; BX(\'PROPERTY_VALUES_DELETE_'.$intPropID.'\').value = \'Y\'"></div>
  154. <input type="hidden" name="PROPERTY_DIRECTORY_VALUES['.$intPropID.'][UF_DELETE]" id="PROPERTY_VALUES_DELETE_'.$intPropID.'" value="N">';
  155. }
  156. function addTableRow($intPropID, $arPropInfo, $fields, $json = false)
  157. {
  158. if (empty($fields))
  159. return '';
  160. if ($json)
  161. {
  162. $result = array();
  163. $result[] = array(
  164. 'style' => array(
  165. 'verticalAlign' => 'top'
  166. ),
  167. 'html' => addTableDelField($intPropID).addTableIdCell($intPropID, $arPropInfo)
  168. );
  169. if (isset($fields['UF_NAME']))
  170. {
  171. $result[] = array(
  172. 'style' => array(
  173. 'verticalAlign' => 'top'
  174. ),
  175. 'html' => addTableNameCell($intPropID, $arPropInfo)
  176. );
  177. }
  178. if (isset($fields['UF_SORT']))
  179. {
  180. $result[] = array(
  181. 'style' => array(
  182. 'verticalAlign' => 'top'
  183. ),
  184. 'html' => addTableSortCell($intPropID, $arPropInfo)
  185. );
  186. }
  187. if (isset($fields['UF_XML_ID']))
  188. {
  189. $result[] = array(
  190. 'style' => array(
  191. 'verticalAlign' => 'top'
  192. ),
  193. 'html' => addTableXmlIDCell($intPropID, $arPropInfo)
  194. );
  195. }
  196. if (isset($fields['UF_FILE']))
  197. {
  198. $result[] = array(
  199. 'style' => array(
  200. 'verticalAlign' => 'top'
  201. ),
  202. 'html' => addTableFileCell($intPropID, $arPropInfo)
  203. );
  204. }
  205. if (isset($fields['UF_LINK']))
  206. {
  207. $result[] = array(
  208. 'style' => array(
  209. 'verticalAlign' => 'top'
  210. ),
  211. 'html' => addTableLinkCell($intPropID, $arPropInfo)
  212. );
  213. }
  214. if (isset($fields['UF_DEF']))
  215. {
  216. $result[] = array(
  217. 'style' => array(
  218. 'verticalAlign' => 'top',
  219. 'textAlign' => 'center'
  220. ),
  221. 'html' => addTableDefCell($intPropID, $arPropInfo)
  222. );
  223. }
  224. if (isset($fields['UF_DESCRIPTION']))
  225. {
  226. $result[] = array(
  227. 'style' => array(
  228. 'verticalAlign' => 'top'
  229. ),
  230. 'html' => addTableDescriptionCell($intPropID, $arPropInfo)
  231. );
  232. }
  233. if (isset($fields['UF_FULL_DESCRIPTION']))
  234. {
  235. $result[] = array(
  236. 'style' => array(
  237. 'verticalAlign' => 'top'
  238. ),
  239. 'html' => addTableFullDescriptionCell($intPropID, $arPropInfo)
  240. );
  241. }
  242. }
  243. else
  244. {
  245. $result = '<tr id="hlbl_property_tr_'.$intPropID.'">';
  246. $result .= '<td style="vertical-align: top;">'.addTableDelField($intPropID).addTableIdCell($intPropID, $arPropInfo).'</td>';
  247. if (isset($fields['UF_NAME']))
  248. {
  249. $result .= '<td style="vertical-align: top;">'.addTableNameCell($intPropID, $arPropInfo).'</td>';
  250. }
  251. if (isset($fields['UF_SORT']))
  252. {
  253. $result .= '<td style="vertical-align: top;">'.addTableSortCell($intPropID, $arPropInfo).'</td>';
  254. }
  255. if (isset($fields['UF_XML_ID']))
  256. {
  257. $result .= '<td style="vertical-align: top;">'.addTableXmlIDCell($intPropID, $arPropInfo).'</td>';
  258. }
  259. if (isset($fields['UF_FILE']))
  260. {
  261. $result .= '<td style="vertical-align: top;">'.addTableFileCell($intPropID, $arPropInfo).'</td>';
  262. }
  263. if (isset($fields['UF_LINK']))
  264. {
  265. $result .= '<td style="vertical-align: top;">'.addTableLinkCell($intPropID, $arPropInfo).'</td>';
  266. }
  267. if (isset($fields['UF_DEF']))
  268. {
  269. $result .= '<td style="vertical-align: top; text-align:center;">'.addTableDefCell($intPropID, $arPropInfo).'</td>';
  270. }
  271. if (isset($fields['UF_DESCRIPTION']))
  272. {
  273. $result .= '<td style="vertical-align: top;">'.addTableDescriptionCell($intPropID, $arPropInfo).'</td>';
  274. }
  275. if (isset($fields['UF_FULL_DESCRIPTION']))
  276. {
  277. $result .= '<td style="vertical-align: top;">'.addTableFullDescriptionCell($intPropID, $arPropInfo).'</td>';
  278. }
  279. $result .= '</tr>';
  280. }
  281. return $result;
  282. }
  283. function addHeadRow($fields, &$colCount)
  284. {
  285. $result = '<tr class="heading"><td></td>';
  286. if (isset($fields['UF_NAME']))
  287. {
  288. $result .= '<td>'.Loc::getMessage('HIBLOCK_PROP_DIRECTORY_NAME').'</td>';
  289. $colCount++;
  290. }
  291. if (isset($fields['UF_SORT']))
  292. {
  293. $result .= '<td>'.Loc::getMessage('HIBLOCK_PROP_DIRECTORY_SORT').'</td>';
  294. $colCount++;
  295. }
  296. if (isset($fields['UF_XML_ID']))
  297. {
  298. $result .= '<td>'.Loc::getMessage('HIBLOCK_PROP_DIRECTORY_XML_ID').'</td>';
  299. $colCount++;
  300. }
  301. if (isset($fields['UF_FILE']))
  302. {
  303. $result .= '<td>'.Loc::getMessage('HIBLOCK_PROP_DIRECTORY_FILE').'</td>';
  304. $colCount++;
  305. }
  306. if (isset($fields['UF_LINK']))
  307. {
  308. $result .= '<td>'.Loc::getMessage('HIBLOCK_PROP_DIRECTORY_LINK').'</td>';
  309. $colCount++;
  310. }
  311. if (isset($fields['UF_DEF']))
  312. {
  313. $result .= '<td>'.Loc::getMessage('HIBLOCK_PROP_DIRECTORY_DEF').'</td>';
  314. $colCount++;
  315. }
  316. if (isset($fields['UF_DESCRIPTION']))
  317. {
  318. $result .= '<td>'.Loc::getMessage('HIBLOCK_PROP_DIRECTORY_DECSRIPTION').'</td>';
  319. $colCount++;
  320. }
  321. if (isset($fields['UF_FULL_DESCRIPTION']))
  322. {
  323. $result .= '<td>'.Loc::getMessage('HIBLOCK_PROP_DIRECTORY_FULL_DESCRIPTION').'</td>';
  324. $colCount++;
  325. }
  326. $result .= '</tr>';
  327. return $result;
  328. }
  329. function addEmptyDefaultRow($property, $fields)
  330. {
  331. if (empty($fields) || !isset($fields['UF_DEF']))
  332. return '';
  333. if ($property['MULTIPLE'] != 'N')
  334. return '';
  335. $result = '<tr id="hlbl_property_tr_empty">';
  336. $leftSide = [
  337. 'UF_NAME' => true,
  338. 'UF_SORT' => true,
  339. 'UF_XML_ID' => true,
  340. 'UF_FILE' => true,
  341. 'UF_LINK' => true
  342. ];
  343. $rightSide = [
  344. 'UF_DESCRIPTION' => true,
  345. 'UF_FULL_DESCRIPTION' => true
  346. ];
  347. $countLeft = count(array_intersect_key($fields, $leftSide)) + 1;
  348. $result .= '<td colspan="'.$countLeft.'" style="text-align: center;">'.Loc::getMessage('HIBLOCK_PROP_DIRECTORY_EMPTY_DEFAULT_VALUE').'</td>';
  349. $result .= '<td style="text-align:center;">'.
  350. '<input type="radio" name="PROPERTY_VALUES_DEF" id="PROPERTY_VALUES_DEF_EMPTY" value="-1" '.($property['UF_DEF'] == '1' ? 'checked="checked"' : '').'>'.
  351. '</td>';
  352. $countRight = count(array_intersect_key($fields, $rightSide));
  353. if ($countRight > 0)
  354. $result .= '<td colspan="'.$countRight.'">&nbsp;</td>';
  355. $result .= '</tr>';
  356. return $result;
  357. }
  358. $rowNumber = (int)(isset($_REQUEST['rowNumber']) ? $_REQUEST['rowNumber'] : 0);
  359. $currentRowNumber = 0;
  360. $colCount = 1;
  361. $hlBlockID = (string)(isset($_REQUEST['hlBlock']) ? $_REQUEST['hlBlock'] : '');
  362. $result = '';
  363. $entityDataClass = null;
  364. $hlblockFields = $defaultValues;
  365. $orderFields = array();
  366. if ($hlBlockID !== '' && $hlBlockID !== '-1')
  367. {
  368. $hlblock = Bitrix\Highloadblock\HighloadBlockTable::getList(array("filter" => array("=TABLE_NAME" => $hlBlockID)))->fetch();
  369. $entity = Bitrix\Highloadblock\HighloadBlockTable::compileEntity($hlblock);
  370. $entityDataClass = $entity->getDataClass();
  371. $hlblockFields = $entityDataClass::getEntity()->getFields();
  372. if (isset($hlblockFields['UF_SORT']))
  373. $orderFields['UF_SORT'] = 'ASC';
  374. if (isset($hlblockFields['UF_NAME']))
  375. $orderFields['UF_NAME'] = 'ASC';
  376. }
  377. if (isset($_REQUEST['addEmptyRow']) && $_REQUEST['addEmptyRow'] === 'Y')
  378. {
  379. $APPLICATION->RestartBuffer();
  380. echo Bitrix\Main\Web\Json::encode(addTableRow('n'.$rowNumber, $defaultValues, $hlblockFields, true));
  381. }
  382. else
  383. {
  384. if ($hlBlockID !== '')
  385. {
  386. if (isset($_REQUEST['getTitle']) && $_REQUEST['getTitle'] === 'Y')
  387. {
  388. $result .= addHeadRow($hlblockFields, $colCount);
  389. }
  390. $existDefault = false;
  391. $rowsList = '';
  392. $rsData = $entityDataClass::getList(array(
  393. 'order' => $orderFields
  394. ));
  395. while ($arData = $rsData->fetch())
  396. {
  397. if (isset($hlblockFields['UF_DEF']) && $arData['UF_DEF'] == '1')
  398. $existDefault = true;
  399. $arData['MULTIPLE'] = $multiple;
  400. $rowsList .= addTableRow($arData['ID'], $arData, $hlblockFields, false);
  401. }
  402. unset($arData, $rsData);
  403. $result .= addEmptyDefaultRow(
  404. ['MULTIPLE' => $multiple, 'UF_DEF' => ($existDefault ? '0' : '1')],
  405. $hlblockFields
  406. );
  407. $result .= $rowsList;
  408. if ($rowsList == '')
  409. $result .= addTableRow('n'.$rowNumber, $defaultValues, $hlblockFields, false);
  410. unset($rowsList);
  411. }
  412. $result .= '<tr style="display: none;"><td colspan="'.$colCount.'"><input type="hidden" id="IB_MAX_ROWS_COUNT" value="'.$rowNumber.'"></td></tr>';
  413. echo $result;
  414. }
  415. }
  416. require($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/epilog_admin_after.php');