PageRenderTime 28ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/bitrix/modules/catalog/admin/cat_discount_format.php

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