PageRenderTime 29ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/bitrix/modules/sale/admin/order_export.php

https://gitlab.com/Rad1calDreamer/honey
PHP | 180 lines | 153 code | 26 blank | 1 comment | 56 complexity | 90d75c5ba52e091f9c2fe909b4aaf0c6 MD5 | raw file
  1. <?
  2. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
  3. $saleModulePermissions = $APPLICATION->GetGroupRight("sale");
  4. if ($saleModulePermissions == "D")
  5. $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
  6. IncludeModuleLangFile(__FILE__);
  7. $arAvailableExports = array(
  8. // "excel" => "excel.php",
  9. "csv" => "csv.php",
  10. "commerceml" => "commerceml.php",
  11. "commerceml2" => "commerceml2.php",
  12. );
  13. $strPath2Export = BX_PERSONAL_ROOT."/php_interface/include/sale_export/";
  14. $strPath2Export1 = "/bitrix/modules/sale/export/";
  15. CheckDirPath($_SERVER["DOCUMENT_ROOT"].$strPath2Export);
  16. if ($handle = opendir($_SERVER["DOCUMENT_ROOT"].$strPath2Export))
  17. {
  18. while (($file = readdir($handle)) !== false)
  19. {
  20. if ($file == "." || $file == "..")
  21. continue;
  22. if (is_file($_SERVER["DOCUMENT_ROOT"].$strPath2Export.$file) && substr($file, strlen($file)-4)==".php")
  23. {
  24. $export_name = substr($file, 0, strlen($file) - 4);
  25. $arAvailableExports[$export_name] = $file;
  26. }
  27. }
  28. }
  29. closedir($handle);
  30. $errorMessage = "";
  31. if (CModule::IncludeModule("sale"))
  32. {
  33. $EXPORT_FORMAT = Trim($EXPORT_FORMAT);
  34. if (strlen($EXPORT_FORMAT) > 0)
  35. {
  36. if (array_key_exists($EXPORT_FORMAT, $arAvailableExports))
  37. {
  38. $exportFilePath = "";
  39. if (file_exists($_SERVER["DOCUMENT_ROOT"].$strPath2Export.$arAvailableExports[$EXPORT_FORMAT])
  40. && is_file($_SERVER["DOCUMENT_ROOT"].$strPath2Export.$arAvailableExports[$EXPORT_FORMAT]))
  41. $exportFilePath = $_SERVER["DOCUMENT_ROOT"].$strPath2Export.$arAvailableExports[$EXPORT_FORMAT];
  42. elseif (file_exists($_SERVER["DOCUMENT_ROOT"].$strPath2Export1.$arAvailableExports[$EXPORT_FORMAT])
  43. && is_file($_SERVER["DOCUMENT_ROOT"].$strPath2Export1.$arAvailableExports[$EXPORT_FORMAT]))
  44. $exportFilePath = $_SERVER["DOCUMENT_ROOT"].$strPath2Export1.$arAvailableExports[$EXPORT_FORMAT];
  45. if (StrLen($exportFilePath) > 0)
  46. {
  47. @set_time_limit(50000);
  48. $arAccessibleSites = array();
  49. $dbAccessibleSites = CSaleGroupAccessToSite::GetList(
  50. array(),
  51. array("GROUP_ID" => $GLOBALS["USER"]->GetUserGroupArray()),
  52. false,
  53. false,
  54. array("SITE_ID")
  55. );
  56. while ($arAccessibleSite = $dbAccessibleSites->Fetch())
  57. {
  58. if (!in_array($arAccessibleSite["SITE_ID"], $arAccessibleSites))
  59. $arAccessibleSites[] = $arAccessibleSite["SITE_ID"];
  60. }
  61. $filter_lang = Trim($filter_lang);
  62. if (strlen($filter_lang) > 0)
  63. {
  64. if (!in_array($filter_lang, $arAccessibleSites) && $saleModulePermissions < "W")
  65. $filter_lang = "";
  66. }
  67. $arFilter = array();
  68. if (isset($OID) && is_array($OID) && count($OID) > 0)
  69. $arFilter["ID"] = $OID;
  70. elseif (isset($OID) && IntVal($OID) > 0)
  71. $arFilter["ID"] = IntVal($OID);
  72. if (IntVal($filter_id_from)>0) $arFilter[">=ID"] = IntVal($filter_id_from);
  73. if (IntVal($filter_id_to)>0) $arFilter["<=ID"] = IntVal($filter_id_to);
  74. if (strlen($filter_date_from)>0) $arFilter["DATE_FROM"] = Trim($filter_date_from);
  75. if (strlen($filter_date_to)>0) $arFilter["DATE_TO"] = Trim($filter_date_to);
  76. if (strlen($filter_lang)>0 && $filter_lang!="NOT_REF") $arFilter["LID"] = Trim($filter_lang);
  77. if (strlen($filter_currency)>0) $arFilter["CURRENCY"] = Trim($filter_currency);
  78. if (isset($filter_status) && !is_array($filter_status) && strlen($filter_status) > 0)
  79. $filter_status = array($filter_status);
  80. if (isset($filter_status) && is_array($filter_status) && count($filter_status) > 0)
  81. {
  82. for ($i = 0; $i < count($filter_status); $i++)
  83. {
  84. $filter_status[$i] = Trim($filter_status[$i]);
  85. if (strlen($filter_status[$i]) > 0)
  86. $arFilter["STATUS_ID"][] = $filter_status[$i];
  87. }
  88. }
  89. if (strlen($filter_date_status_from)>0) $arFilter["DATE_STATUS_FROM"] = Trim($filter_date_status_from);
  90. if (strlen($filter_date_status_to)>0) $arFilter["DATE_STATUS_TO"] = Trim($filter_date_status_to);
  91. if (strlen($filter_payed)>0) $arFilter["PAYED"] = Trim($filter_payed);
  92. if (strlen($filter_allow_delivery)>0) $arFilter["ALLOW_DELIVERY"] = Trim($filter_allow_delivery);
  93. if (strlen($filter_ps_status)>0) $arFilter["PS_STATUS"] = Trim($filter_ps_status);
  94. if (IntVal($filter_pay_system)>0) $arFilter["PAY_SYSTEM_ID"] = IntVal($filter_pay_system);
  95. if (strlen($filter_canceled)>0) $arFilter["CANCELED"] = Trim($filter_canceled);
  96. if (strlen($filter_buyer)>0) $arFilter["%BUYER"] = Trim($filter_buyer);
  97. if ($saleModulePermissions < "W")
  98. {
  99. if (strlen($filter_lang) <= 0)
  100. $arFilter["LID"] = $arAccessibleSites;
  101. }
  102. $shownFieldsList = COption::GetOptionString("sale", "order_list_fields", "ID,USER,PAY_SYSTEM,PRICE,STATUS,PAYED,PS_STATUS,CANCELED,BASKET");
  103. $arShownFieldsList = explode(",", $shownFieldsList);
  104. $arShownFieldsParams = array();
  105. $arSelectFields = array("PAYED");
  106. $ind = -1;
  107. foreach ($GLOBALS["AVAILABLE_ORDER_FIELDS"] as $key => $value)
  108. {
  109. if (in_array($key, $arShownFieldsList))
  110. {
  111. $ind++;
  112. $arShownFieldsParams[$ind] = $value;
  113. $arShownFieldsParams[$ind]["KEY"] = $key;
  114. $arFields_tmp = array();
  115. if (strlen($value["SELECT"]) > 0)
  116. $arFields_tmp = explode(",", $value["SELECT"]);
  117. $arShownFieldsParams[$ind]["SHOW"] = $arFields_tmp;
  118. for ($i = 0; $i < count($arFields_tmp); $i++)
  119. {
  120. if (!in_array($arFields_tmp[$i], $arSelectFields))
  121. $arSelectFields[] = $arFields_tmp[$i];
  122. }
  123. }
  124. }
  125. include($exportFilePath);
  126. }
  127. else
  128. {
  129. $errorMessage .= str_replace("#FILE#", $exportFilePath, GetMessage("SOE_NO_SCRIPT")).". ";
  130. }
  131. }
  132. else
  133. {
  134. $errorMessage .= str_replace("#EXPORT_FORMAT#", $EXPORT_FORMAT, GetMessage("SOE_WRONG_FORMAT")).". ";
  135. }
  136. }
  137. else
  138. {
  139. $errorMessage .= GetMessage("SOE_NO_FORMAT").". ";
  140. }
  141. }
  142. else
  143. {
  144. $errorMessage .= GetMessage("SOE_NO_SALE").". ";
  145. }
  146. if (strlen($errorMessage) > 0)
  147. {
  148. $APPLICATION->SetTitle(GetMessage("SOE_EXPORT_ERROR"));
  149. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
  150. CAdminMessage::ShowMessage($errorMessage);
  151. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin_before.php");
  152. }
  153. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin_after.php");
  154. ?>