Advertisement
Guest User

btrxwrap

a guest
Dec 18th, 2012
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.46 KB | None | 0 0
  1. <?
  2. if (isset($_REQUEST['work_start']))
  3. {
  4.     define("NO_AGENT_STATISTIC", true);
  5.     define("NO_KEEP_STATISTIC", true);
  6. }
  7. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
  8. CModule::IncludeModule("iblock");
  9. CModule::IncludeModule("catalog");
  10.  
  11. IncludeModuleLangFile(__FILE__);
  12.  
  13. $POST_RIGHT = $APPLICATION->GetGroupRight("main");
  14. if ($POST_RIGHT == "D")
  15.     $APPLICATION->AuthForm("Доступ запрещен");
  16.  
  17. $BID = 17;
  18. $limit = 100;
  19.  
  20. if($_REQUEST['work_start'] && check_bitrix_sessid())
  21. {
  22.     $rsEl = CIBlockElement::GetList(array("ID" => "ASC"), array("IBLOCK_ID" => $BID, ">ID" => $_REQUEST["lastid"]), false, array("nTopCount" => $limit));
  23.     while ($arEl = $rsEl->Fetch())
  24.     {
  25.         if($arEl["IBLOCK_SECTION_ID"] == 169 || $arEl["IBLOCK_SECTION_ID"] == 170){
  26.             $ar_res = CPrice::GetBasePrice($arEl["EXTERNAL_ID"]);
  27.             $newprice = $ar_res["PRICE"] + $ar_res["PRICE"]*50/100;
  28.             $newprice = number_format($newprice, 2, '.', '');
  29.             #printr($ar_res);
  30.             CPrice::SetBasePrice($ar_res["ID"], $newprice, "RUB");
  31.             $lastID = intval($arEl["ID"]);
  32.         }else{
  33.             $ar_res = CPrice::GetBasePrice($arEl["EXTERNAL_ID"]);
  34.             $newprice = $ar_res["PRICE"] + $ar_res["PRICE"]*30/100;
  35.             $newprice = number_format($newprice, 2, '.', '');
  36.             #printr($ar_res);
  37.             CPrice::SetBasePrice($ar_res["ID"], $newprice, "RUB");
  38.             $lastID = intval($arEl["ID"]);
  39.         }
  40.     }
  41.  
  42.     $rsLeftBorder = CIBlockElement::GetList(array("ID" => "ASC"), array("IBLOCK_ID" => $BID, "<=ID" => $lastID));
  43.     $leftBorderCnt = $rsLeftBorder->SelectedRowsCount();
  44.  
  45.     $rsAll = CIBlockElement::GetList(array("ID" => "ASC"), array("IBLOCK_ID" => $BID));
  46.     $allCnt = $rsAll->SelectedRowsCount();
  47.  
  48.     $p = round(100*$leftBorderCnt/$allCnt, 2);
  49.  
  50.     echo 'CurrentStatus = Array('.$p.',"'.($p < 100 ? '&lastid='.$lastID : '').'","Обрабатываю запись с ID #'.$lastID.'");';
  51.  
  52.     die();
  53. }
  54.  
  55. $clean_test_table = '<table id="result_table" cellpadding="0" cellspacing="0" border="0" width="100%" class="internal">'.
  56.                         '<tr class="heading">'.
  57.                             '<td>Текущее действие</td>'.
  58.                             '<td width="1%">&nbsp;</td>'.
  59.                         '</tr>'.
  60.                     '</table>';
  61.  
  62. $aTabs = array(array("DIV" => "edit1", "TAB" => "Обработка"));
  63. $tabControl = new CAdminTabControl("tabControl", $aTabs);
  64.  
  65. $APPLICATION->SetTitle("Обработка элементов инфоблока");
  66.  
  67. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
  68.  
  69. ?>
  70. <script type="text/javascript">
  71.  
  72.     var bWorkFinished = false;
  73.     var bSubmit;
  74.  
  75.     function set_start(val)
  76.     {
  77.         document.getElementById('work_start').disabled = val ? 'disabled' : '';
  78.         document.getElementById('work_stop').disabled = val ? '' : 'disabled';
  79.         document.getElementById('progress').style.display = val ? 'block' : 'none';
  80.  
  81.         if (val)
  82.         {
  83.             ShowWaitWindow();
  84.             document.getElementById('result').innerHTML = '<?=$clean_test_table?>';
  85.             document.getElementById('status').innerHTML = 'Работаю...';
  86.  
  87.             document.getElementById('percent').innerHTML = '0%';
  88.             document.getElementById('indicator').style.width = '0%';
  89.  
  90.             CHttpRequest.Action = work_onload;
  91.             CHttpRequest.Send('<?= $_SERVER["PHP_SELF"]?>?work_start=Y&lang=<?=LANGUAGE_ID?>&<?=bitrix_sessid_get()?>');
  92.         }
  93.         else
  94.             CloseWaitWindow();
  95.     }
  96.  
  97.     function work_onload(result)
  98.     {
  99.         try
  100.         {
  101.             eval(result);
  102.  
  103.             iPercent = CurrentStatus[0];
  104.             strNextRequest = CurrentStatus[1];
  105.             strCurrentAction = CurrentStatus[2];
  106.  
  107.             document.getElementById('percent').innerHTML = iPercent + '%';
  108.             document.getElementById('indicator').style.width = iPercent + '%';
  109.  
  110.             document.getElementById('status').innerHTML = 'Работаю...';
  111.  
  112.             if (strCurrentAction != 'null')
  113.             {
  114.                 oTable = document.getElementById('result_table');
  115.                 oRow = oTable.insertRow(-1);
  116.                 oCell = oRow.insertCell(-1);
  117.                 oCell.innerHTML = strCurrentAction;
  118.                 oCell = oRow.insertCell(-1);
  119.                 oCell.innerHTML = '';
  120.             }
  121.  
  122.             if (strNextRequest && document.getElementById('work_start').disabled)
  123.                 CHttpRequest.Send('<?= $_SERVER["PHP_SELF"]?>?work_start=Y&lang=<?=LANGUAGE_ID?>&<?=bitrix_sessid_get()?>' + strNextRequest);
  124.             else
  125.             {
  126.                 set_start(0);
  127.                 bWorkFinished = true;
  128.             }
  129.  
  130.         }
  131.         catch(e)
  132.         {
  133.             CloseWaitWindow();
  134.             document.getElementById('work_start').disabled = '';
  135.             alert('Сбой в получении данных');
  136.         }
  137.     }
  138.  
  139. </script>
  140.  
  141. <form method="post" action="<?echo $APPLICATION->GetCurPage()?>" enctype="multipart/form-data" name="post_form" id="post_form">
  142. <?
  143. echo bitrix_sessid_post();
  144.  
  145. $tabControl->Begin();
  146. $tabControl->BeginNextTab();
  147. ?>
  148.     <tr>
  149.         <td colspan="2">
  150.  
  151.             <input type=button value="Старт" id="work_start" onclick="set_start(1)" />
  152.             <input type=button value="Стоп" disabled id="work_stop" onclick="bSubmit=false;set_start(0)" />
  153.             <div id="progress" style="display:none;" width="100%">
  154.             <br />
  155.                 <div id="status"></div>
  156.                 <table border="0" cellspacing="0" cellpadding="2" width="100%">
  157.                     <tr>
  158.                         <td height="10">
  159.                             <div style="border:1px solid #B9CBDF">
  160.                                 <div id="indicator" style="height:10px; width:0%; background-color:#B9CBDF"></div>
  161.                             </div>
  162.                         </td>
  163.                         <td width=30>&nbsp;<span id="percent">0%</span></td>
  164.                     </tr>
  165.                 </table>
  166.             </div>
  167.             <div id="result" style="padding-top:10px"></div>
  168.  
  169.         </td>
  170.     </tr>
  171. <?
  172. $tabControl->End();
  173. ?>
  174. </form>
  175. <?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement