PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/catalog/admin/cat_discount_convert.php

https://gitlab.com/alexprowars/bitrix
PHP | 216 lines | 201 code | 15 blank | 0 comment | 24 complexity | 4b939e5ceb4b522db396e62399ff1250 MD5 | raw file
  1. <?
  2. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
  3. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/catalog/prolog.php");
  4. global $USER;
  5. if (!$USER->CanDoOperation('catalog_discount'))
  6. $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
  7. CModule::IncludeModule("catalog");
  8. IncludeModuleLangFile(__FILE__);
  9. if ('POST' == $_SERVER['REQUEST_METHOD'] && (isset($_REQUEST["Convert"]) && 'Y' == $_REQUEST["Convert"]) && check_bitrix_sessid())
  10. {
  11. CUtil::JSPostUnescape();
  12. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_js.php");
  13. $max_execution_time = 10;
  14. if (isset($_REQUEST['max_execution_time']) && 0 < intval($_REQUEST['max_execution_time']))
  15. {
  16. $max_execution_time = intval($_REQUEST['max_execution_time']);
  17. }
  18. COption::SetOptionString("catalog", "max_execution_time", $max_execution_time);
  19. $converted = isset($_REQUEST['converted'])? intval($_REQUEST['converted']): 0;
  20. $maxMessage = isset($_REQUEST['maxMessage'])? intval($_REQUEST['maxMessage']): 0;
  21. $maxMessagePerStep = isset($_REQUEST['maxMessagePerStep'])? intval($_REQUEST['maxMessagePerStep']): 100;
  22. if ($converted == 0 && $maxMessage == 0)
  23. $maxMessage = CCatalogDiscountConvert::GetCountOld();
  24. $strSessID = isset($_REQUEST['DC']) ? $_REQUEST['DC'] : '';
  25. CCatalogDiscountConvert::$intConvertPerStep = 0;
  26. CCatalogDiscountConvert::$intConverted = $converted;
  27. CCatalogDiscountConvert::$strSessID = $strSessID;
  28. CCatalogDiscountConvert::ConvertDiscount($maxMessagePerStep, $max_execution_time);
  29. if (CCatalogDiscountConvert::$intConvertPerStep > 0)
  30. {
  31. $aboutMinute = ($maxMessage-CCatalogDiscountConvert::$intConverted)/CCatalogDiscountConvert::$intConvertPerStep*$max_execution_time/60;
  32. $strAbout = ($aboutMinute >= 1 ? str_replace('#MIN#', ceil($aboutMinute), GetMessage('CAT_DISC_CONVERT_TOTAL_MIN')) : str_replace('#SEC#', ceil($aboutMinute*60), GetMessage('CAT_DISC_CONVERT_TOTAL_SEC')));
  33. CAdminMessage::ShowMessage(array(
  34. "MESSAGE"=>GetMessage("CAT_DISC_CONVERT_IN_PROGRESS"),
  35. "DETAILS" => str_replace(array('#COUNT#', '#PERCENT#', '#TIME#'), array($converted, ceil(CCatalogDiscountConvert::$intConverted/$maxMessage*100), $strAbout), GetMessage('CAT_DISC_CONVERT_TOTAL')),
  36. "HTML"=>true,
  37. "TYPE"=>"OK",
  38. ));
  39. ?><script type="text/javascript">
  40. BX.closeWait();
  41. DoNext(<?=CCatalogDiscountConvert::$intConverted; ?>, <?=$maxMessage?>, <?=CCatalogDiscountConvert::$intNextConvertPerStep; ?>, '<?=CUtil::JSEscape(CCatalogDiscountConvert::$strSessID); ?>');
  42. </script><?
  43. }
  44. else
  45. {
  46. $strDetail = '';
  47. $arErrors = CCatalogDiscountConvert::GetErrors();
  48. if (!empty($arErrors) && is_array($arErrors))
  49. {
  50. $strDetail = str_replace('#COUNT#', $converted, GetMessage("CAT_DISC_CONVERT_RESULT")).'<br><br>';
  51. $strDetail .= GetMessage('CAT_DISC_CONVERT_ERR').'<br>';
  52. $strDetail .= '<ul>';
  53. foreach ($arErrors as &$arOneError)
  54. {
  55. $strDetail .= '<li>'.str_replace(
  56. array('#LINK#', '#NAME#', '#MESS#'),
  57. array(
  58. '/bitrix/admin/cat_discount_edit.php?lang='.LANGUAGE_ID.'&ID='.$arOneError['ID'],
  59. htmlspecialcharsbx($arOneError['NAME']),
  60. htmlspecialcharsbx($arOneError['ERROR']),
  61. ),
  62. GetMessage('CAT_DISC_CONVERT_ONE_ERROR')
  63. ).'</li>';
  64. }
  65. if (isset($arOneError))
  66. unset($arOneError);
  67. $strDetail .= '</ul>';
  68. $strDetail .= GetMessage('CAT_DISC_CONVERT_ERROR_RESUME');
  69. $strDetail .= '<div id="cat_disc_convert_finish"></div>';
  70. }
  71. else
  72. {
  73. $strDetail = str_replace('#COUNT#', $converted, GetMessage("CAT_DISC_CONVERT_RESULT")).'<div id="cat_disc_convert_finish"></div>';
  74. }
  75. CAdminMessage::ShowMessage(array(
  76. "MESSAGE" => GetMessage("CAT_DISC_CONVERT_COMPLETE"),
  77. "DETAILS" => $strDetail,
  78. "HTML" => true,
  79. "TYPE" => "OK",
  80. ));
  81. CAdminNotify::DeleteByTag("CATALOG_DISC_CONVERT");
  82. ?><script type="text/javascript">
  83. BX.closeWait();
  84. EndConvert();
  85. </script><?
  86. }
  87. require($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/include/epilog_admin_js.php");
  88. }
  89. else
  90. {
  91. $APPLICATION->SetTitle(GetMessage("CAT_DISC_CONVERT_TITLE"));
  92. $aTabs = array(
  93. array("DIV" => "edit1", "TAB" => GetMessage("CAT_DISC_CONVERT_TAB"), "ICON"=>"catalog", "TITLE"=>GetMessage("CAT_DISC_CONVERT_TAB_TITLE")),
  94. );
  95. $tabControl = new CAdminTabControl("tabControl", $aTabs, true, true);
  96. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
  97. ?><script type="text/javascript">
  98. var stop;
  99. var interval = 0;
  100. function StartConvert(maxMessage)
  101. {
  102. stop=false;
  103. BX('convert_result_div').innerHTML='';
  104. BX('stop_button').disabled=false;
  105. BX('start_button').disabled=true;
  106. DoNext(0, maxMessage, 100, '');
  107. }
  108. function StopConvert()
  109. {
  110. stop=true;
  111. BX('stop_button').disabled=true;
  112. BX('start_button').disabled=false;
  113. }
  114. function EndConvert()
  115. {
  116. stop=true;
  117. BX('stop_button').disabled=true;
  118. BX('start_button').disabled=false;
  119. }
  120. function DoNext(converted, maxMessage, maxMessagePerStep, sess)
  121. {
  122. var arParams = {
  123. 'Convert': 'Y',
  124. 'lang': '<? echo CUtil::JSEscape(LANGUAGE_ID); ?>',
  125. 'converted': parseInt(converted),
  126. 'maxMessage': parseInt(maxMessage),
  127. 'maxMessagePerStep': parseInt(maxMessagePerStep),
  128. 'max_execution_time': BX('max_execution_time').value,
  129. 'DC': sess,
  130. 'sessid': BX.bitrix_sessid()
  131. };
  132. if(!stop)
  133. {
  134. BX.showWait();
  135. BX.ajax.post(
  136. 'cat_discount_convert.php',
  137. arParams,
  138. function(result){
  139. BX('convert_result_div').innerHTML = result;
  140. if(BX('cat_disc_convert_finish') != null)
  141. {
  142. BX.closeWait();
  143. StopConvert();
  144. }
  145. }
  146. );
  147. }
  148. return false;
  149. }
  150. </script><?
  151. $intCountOld = CCatalogDiscountConvert::GetCountOld();
  152. if ($intCountOld <= 0)
  153. {
  154. CAdminMessage::ShowMessage(array(
  155. "MESSAGE"=>GetMessage("CAT_DISC_CONVERT_COMPLETE"),
  156. "DETAILS"=>GetMessage("ICAT_DISC_CONVERT_COMPLETE_ALL_OK"),
  157. "HTML"=>true,
  158. "TYPE"=>"OK",
  159. ));
  160. CAdminNotify::DeleteByTag("CATALOG_DISC_CONVERT");
  161. }
  162. ?><div id="convert_result_div" style="margin:0;"></div>
  163. <form method="POST" action="<?echo $APPLICATION->GetCurPage(); ?>" name="fs1"><?
  164. $tabControl->Begin();
  165. $tabControl->BeginNextTab();
  166. $max_execution_time = intval(COption::GetOptionString("catalog", "max_execution_time", 10));
  167. if($max_execution_time <= 0)
  168. $max_execution_time = '';
  169. ?>
  170. <tr>
  171. <td width="40%"><?echo GetMessage("CAT_DISC_CONVERT_STEP")?></td>
  172. <td><input type="text" name="max_execution_time" id="max_execution_time" size="3" value="<?echo htmlspecialcharsbx($max_execution_time);?>"> <?echo GetMessage("CAT_DISC_CONVERT_STEP_SEC")?></td>
  173. </tr>
  174. <?
  175. $tabControl->Buttons();
  176. ?>
  177. <input type="button" id="start_button" value="<?echo GetMessage("CAT_DISC_CONVERT_BUTTON")?>" <? (0 < $intCountOld ? "" : "disabled"); ?>>
  178. <input type="button" id="stop_button" value="<?=GetMessage("CAT_DISC_CONVERT_STOP")?>" disabled>
  179. <?
  180. $tabControl->End();
  181. ?></form>
  182. <script type="text/javascript">
  183. BX.ready(function(){
  184. var obStartButton = BX('start_button');
  185. if (!!obStartButton)
  186. {
  187. BX.bind(obStartButton, 'click', function(){
  188. StartConvert(<? echo $intCountOld; ?>);
  189. });
  190. }
  191. var obStopButton = BX('stop_button');
  192. if (!!obStopButton)
  193. {
  194. BX.bind(obStopButton, 'click', StopConvert);
  195. }
  196. });
  197. </script>
  198. <?
  199. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");
  200. }
  201. ?>