PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/components/bitrix/lists/component.php

https://gitlab.com/alexprowars/bitrix
PHP | 353 lines | 311 code | 28 blank | 14 comment | 46 complexity | f8001160dad50ed13888f6f2fd700c60 MD5 | raw file
  1. <?php
  2. if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true)
  3. {
  4. die();
  5. }
  6. /** @global CMain $APPLICATION */
  7. /** @global CUser $USER */
  8. /** @global CDatabase $DB */
  9. /** @var CBitrixComponent $this */
  10. /** @var array $arParams */
  11. /** @var array $arResult */
  12. /** @var string $componentName */
  13. /** @var string $componentPath */
  14. /** @var string $componentTemplate */
  15. /** @var string $parentComponentName */
  16. /** @var string $parentComponentPath */
  17. /** @var string $parentComponentTemplate */
  18. $this->setFrameMode(false);
  19. if (!CModule::IncludeModule('lists'))
  20. {
  21. ShowError(GetMessage("CC_BLL_MODULE_NOT_INSTALLED"));
  22. return;
  23. }
  24. $arDefaultUrlTemplates404 = array(
  25. "lists" => "",
  26. "list" =>"#list_id#/view/#section_id#/",
  27. "list_edit" => "#list_id#/edit/",
  28. "list_fields" => "#list_id#/fields/",
  29. "list_field_edit" => "#list_id#/field/#field_id#/",
  30. "list_element_edit" => "#list_id#/element/#section_id#/#element_id#/",
  31. "list_file" => "#list_id#/file/#section_id#/#element_id#/#field_id#/#file_id#/",
  32. "bizproc_log" => "#list_id#/bp_log/#document_state_id#/",
  33. "bizproc_workflow_start" => "#list_id#/bp_start/#element_id#/",
  34. "bizproc_task" => "#list_id#/bp_task/#section_id#/#element_id#/#task_id#/",
  35. "bizproc_workflow_admin" => "#list_id#/bp_list/",
  36. "bizproc_workflow_edit" => "#list_id#/bp_edit/#ID#/",
  37. "bizproc_workflow_vars" => "#list_id#/bp_vars/#ID#/",
  38. "bizproc_workflow_constants" => "#list_id#/bp_constants/#ID#/",
  39. "list_export_excel" => "#list_id#/excel/",
  40. );
  41. $processes = CLists::isListProcesses($arParams["IBLOCK_TYPE_ID"]);
  42. $arDefaultUrlTemplates404["catalog_processes"] = "catalog_processes/";
  43. $featureName = ($processes ? "lists_processes" : "lists");
  44. if (CModule::IncludeModule("lists") && !CLists::isFeatureEnabled($featureName))
  45. {
  46. ShowError(GetMessage("CC_BLL_ACCESS_DENIDED"));
  47. return;
  48. }
  49. $arDefaultVariableAliases404 = array();
  50. $arDefaultVariableAliases = array();
  51. $arComponentVariables = array(
  52. "list_id",
  53. "field_id",
  54. "section_id",
  55. "element_id",
  56. "file_id",
  57. "mode",
  58. "document_state_id",
  59. "task_id",
  60. "ID",
  61. );
  62. /* We set the option on the component, as well as accounting for multiple sites */
  63. if($arParams["IBLOCK_TYPE_ID"] == COption::GetOptionString("lists", "livefeed_iblock_type_id"))
  64. {
  65. if($arParams["SEF_FOLDER"] != COption::GetOptionString('lists', 'livefeed_url'))
  66. {
  67. $sitDirTrim = trim(SITE_DIR, '/');
  68. if(!empty($sitDirTrim))
  69. {
  70. $setOptions = str_replace(SITE_DIR, '/', $arParams["SEF_FOLDER"]);
  71. COption::SetOptionString("lists", "livefeed_url", $setOptions);
  72. }
  73. else
  74. {
  75. COption::SetOptionString("lists", "livefeed_url", $arParams["SEF_FOLDER"]);
  76. }
  77. }
  78. }
  79. if($arParams["SEF_MODE"] == "Y")
  80. {
  81. $arVariables = array();
  82. $arUrlTemplates = CComponentEngine::MakeComponentUrlTemplates($arDefaultUrlTemplates404, $arParams["SEF_URL_TEMPLATES"]);
  83. $arVariableAliases = CComponentEngine::MakeComponentVariableAliases($arDefaultVariableAliases404, $arParams["VARIABLE_ALIASES"]);
  84. if($_GET['livefeed'] == 'y')
  85. {
  86. $componentPage = 'list_element_edit';
  87. $arVariables = array('list_id' => $_GET['list_id'], 'element_id' => $_GET['element_id'], 'section_id' => 0);
  88. }
  89. elseif($_GET['bp_constants'] == 'y')
  90. {
  91. $componentPage = "bizproc_workflow_constants";
  92. $arVariables = array('list_id' => $_GET['list_id'], 'ID' => $_GET['id']);
  93. }
  94. elseif($processes && $_GET["bp_catalog"] == "y")
  95. {
  96. $componentPage = "catalog_processes";
  97. }
  98. else
  99. {
  100. $componentPage = CComponentEngine::ParseComponentPath(
  101. $arParams["SEF_FOLDER"],
  102. $arUrlTemplates,
  103. $arVariables
  104. );
  105. }
  106. if(!$componentPage)
  107. $componentPage = "lists";
  108. CComponentEngine::InitComponentVariables($componentPage, $arComponentVariables, $arVariableAliases, $arVariables);
  109. $arResult = array(
  110. "FOLDER" => $arParams["SEF_FOLDER"],
  111. "URL_TEMPLATES" => $arUrlTemplates,
  112. "VARIABLES" => $arVariables,
  113. "ALIASES" => $arVariableAliases
  114. );
  115. // Registering routes for building preview by url
  116. Bitrix\Main\UrlPreview\Router::setRouteHandler(
  117. $arParams["SEF_FOLDER"].$arUrlTemplates['list_element_edit'],
  118. 'lists',
  119. '\Bitrix\Lists\Preview\Element',
  120. array(
  121. 'listId' => '$list_id',
  122. 'sectionId' => '$section_id',
  123. 'elementId' => '$element_id',
  124. 'IBLOCK_TYPE_ID' => $arParams['IBLOCK_TYPE_ID']
  125. )
  126. );
  127. }
  128. else
  129. {
  130. $arVariables = array();
  131. if(!isset($arParams["VARIABLE_ALIASES"]["ID"]))
  132. $arParams["VARIABLE_ALIASES"]["ID"] = "ID";
  133. $arVariableAliases = CComponentEngine::MakeComponentVariableAliases($arDefaultVariableAliases, $arParams["VARIABLE_ALIASES"]);
  134. if(!isset($arVariableAliases["file_id"]))
  135. $arVariableAliases["file_id"] = "file_id";
  136. if($_GET['livefeed'] == 'y')
  137. {
  138. $componentPage = 'list_element_edit';
  139. $arVariables = array('list_id' => $_GET['list_id'], 'element_id' => $_GET['element_id'], 'section_id' => 0);
  140. }
  141. elseif($_GET['bp_constants'] == 'y')
  142. {
  143. $componentPage = "bizproc_workflow_constants";
  144. $arVariables = array('list_id' => $_GET['list_id'], 'ID' => $_GET['id']);
  145. }
  146. elseif($processes && $_GET["bp_catalog"] == "y")
  147. {
  148. $componentPage = "catalog_processes";
  149. }
  150. else
  151. {
  152. CComponentEngine::InitComponentVariables(false, $arComponentVariables, $arVariableAliases, $arVariables);
  153. $componentPage = "lists"; //default page
  154. }
  155. if(isset($arVariables["list_id"]) && isset($arVariables["mode"]))
  156. {
  157. switch($arVariables["mode"])
  158. {
  159. case "field":
  160. if(isset($arVariables["field_id"]))
  161. $componentPage = "list_field_edit";
  162. break;
  163. case "fields":
  164. $componentPage = "list_fields";
  165. break;
  166. case "edit":
  167. if(isset($arVariables["element_id"]))
  168. $componentPage = "list_element_edit";
  169. elseif(isset($arVariables["section_id"]))
  170. $componentPage = "list_sections";
  171. else
  172. $componentPage = "list_edit";
  173. break;
  174. case "bp":
  175. if(isset($arVariables["document_state_id"]))
  176. $componentPage = "bizproc_log";
  177. elseif(isset($arVariables["task_id"]))
  178. $componentPage = "bizproc_task";
  179. elseif(isset($arVariables["element_id"]) && isset($_GET["action"]) && $_GET["action"] === "del_bizproc")
  180. $componentPage = "bizproc_workflow_delete";
  181. elseif(isset($arVariables["section_id"]) && isset($arVariables["element_id"]))
  182. $componentPage = "bizproc_workflow_start";
  183. elseif(isset($arVariables["ID"]) && !isset($_GET["action"]))
  184. $componentPage = "bizproc_workflow_edit";
  185. else
  186. $componentPage = "bizproc_workflow_admin";
  187. break;
  188. case "bp_vars":
  189. $componentPage = "bizproc_workflow_vars";
  190. break;
  191. case "bp_constants":
  192. $componentPage = "bizproc_workflow_constants";
  193. break;
  194. case "view":
  195. if(isset($arVariables["file_id"]))
  196. $componentPage = "list_file";
  197. else
  198. $componentPage = "list";
  199. break;
  200. case "excel":
  201. $componentPage = "list_export_excel";
  202. break;
  203. }
  204. }
  205. if($processes)
  206. {
  207. if(isset($arVariables["mode"]))
  208. {
  209. switch($arVariables["mode"])
  210. {
  211. case "catalog":
  212. if($processes)
  213. $componentPage = "catalog_processes";
  214. break;
  215. }
  216. }
  217. }
  218. $arResult = array(
  219. "FOLDER" => "",
  220. "URL_TEMPLATES" => Array(
  221. "list_field_edit" => $APPLICATION->GetCurPage()
  222. ."?mode=field"
  223. ."&".$arVariableAliases["list_id"]."=#list_id#"
  224. ."&".$arVariableAliases["field_id"]."=#field_id#"
  225. ,
  226. "list_fields" => $APPLICATION->GetCurPage()
  227. ."?mode=fields"
  228. ."&".$arVariableAliases["list_id"]."=#list_id#"
  229. ,
  230. "list_edit" => $APPLICATION->GetCurPage()
  231. ."?mode=edit"
  232. ."&".$arVariableAliases["list_id"]."=#list_id#"
  233. ,
  234. "list_element_edit" => $APPLICATION->GetCurPage()
  235. ."?mode=edit"
  236. ."&".$arVariableAliases["list_id"]."=#list_id#"
  237. ."&".$arVariableAliases["section_id"]."=#section_id#"
  238. ."&".$arVariableAliases["element_id"]."=#element_id#"
  239. ,
  240. "list_sections" => $APPLICATION->GetCurPage()
  241. ."?mode=edit"
  242. ."&".$arVariableAliases["list_id"]."=#list_id#"
  243. ."&".$arVariableAliases["section_id"]."=#section_id#"
  244. ,
  245. "bizproc_log" => $APPLICATION->GetCurPage()
  246. ."?mode=bp"
  247. ."&".$arVariableAliases["list_id"]."=#list_id#"
  248. ."&".$arVariableAliases["document_state_id"]."=#document_state_id#"
  249. ,
  250. "bizproc_task" => $APPLICATION->GetCurPage()
  251. ."?mode=bp&".$arVariableAliases["list_id"]."=#list_id#"
  252. ."&".$arVariableAliases["task_id"]."=#task_id#"
  253. ,
  254. "bizproc_workflow_start" => $APPLICATION->GetCurPage()
  255. ."?mode=bp"
  256. ."&".$arVariableAliases["list_id"]."=#list_id#"
  257. ."&".$arVariableAliases["section_id"]."=#section_id#"
  258. ."&".$arVariableAliases["element_id"]."=#element_id#"
  259. ,
  260. "bizproc_workflow_delete" => $APPLICATION->GetCurPage()
  261. ."?mode=bp"
  262. ."&".$arVariableAliases["list_id"]."=#list_id#"
  263. ."&".$arVariableAliases["section_id"]."=#section_id#"
  264. ."&".$arVariableAliases["element_id"]."=#element_id#"
  265. ,
  266. "bizproc_workflow_admin" => $APPLICATION->GetCurPage()
  267. ."?mode=bp"
  268. ."&".$arVariableAliases["list_id"]."=#list_id#"
  269. ,
  270. "bizproc_workflow_edit" => $APPLICATION->GetCurPage()
  271. ."?mode=bp"
  272. ."&".$arVariableAliases["list_id"]."=#list_id#"
  273. ."&".$arVariableAliases["ID"]."=#ID#"
  274. ,
  275. "bizproc_workflow_vars" => $APPLICATION->GetCurPage()
  276. ."?mode=bp_vars"
  277. ."&".$arVariableAliases["list_id"]."=#list_id#"
  278. ."&".$arVariableAliases["ID"]."=#ID#"
  279. ,
  280. "bizproc_workflow_constants" => $APPLICATION->GetCurPage()
  281. ."?mode=bp_constants"
  282. ."&".$arVariableAliases["list_id"]."=#list_id#"
  283. ."&".$arVariableAliases["ID"]."=#ID#"
  284. ,
  285. "list_file" => $APPLICATION->GetCurPage()
  286. ."?mode=view"
  287. ."&".$arVariableAliases["list_id"]."=#list_id#"
  288. ."&".$arVariableAliases["section_id"]."=#section_id#"
  289. ."&".$arVariableAliases["element_id"]."=#element_id#"
  290. ."&".$arVariableAliases["field_id"]."=#field_id#"
  291. ."&".$arVariableAliases["file_id"]."=#file_id#"
  292. ,
  293. "list" => $APPLICATION->GetCurPage()
  294. ."?mode=view"
  295. ."&".$arVariableAliases["list_id"]."=#list_id#"
  296. ."&".$arVariableAliases["section_id"]."=#section_id#"
  297. ,
  298. "lists" => $APPLICATION->GetCurPage(),
  299. "list_export_excel" => $APPLICATION->GetCurPage()."?mode=excel"
  300. ."&".$arVariableAliases["list_id"]."=#list_id#",
  301. ),
  302. "VARIABLES" => $arVariables,
  303. "ALIASES" => $arVariableAliases
  304. );
  305. if($processes)
  306. $arResult["URL_TEMPLATES"]["catalog_processes"] = $APPLICATION->GetCurPage()."?mode=catalog";
  307. }
  308. $p = mb_strpos($arResult["URL_TEMPLATES"]["bizproc_workflow_delete"], "?");
  309. if($p === false)
  310. $ch = "?";
  311. else
  312. $ch = "&";
  313. $arResult["URL_TEMPLATES"]["bizproc_workflow_delete"] .= $ch."action=del_bizproc";
  314. if(
  315. isset($arVariables["document_state_id"])
  316. && !isset($arVariables["element_id"])
  317. && CModule::IncludeModule("bizproc")
  318. && CLists::isBpFeatureEnabled($arParams["IBLOCK_TYPE_ID"])
  319. )
  320. {
  321. $arWorkflowState = CBPStateService::GetWorkflowState($arVariables["document_state_id"]);
  322. if(is_array($arWorkflowState) && is_array($arWorkflowState["DOCUMENT_ID"]))
  323. list(, , $arResult["VARIABLES"]["element_id"]) = CBPHelper::ParseDocumentId($arWorkflowState["DOCUMENT_ID"]);
  324. }
  325. $this->IncludeComponentTemplate($componentPage);