Advertisement
Trigub_Ilia

Импорт каталога из xml-файлов CML2.0 без прямого обмена с 1С

Jul 3rd, 2018
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.19 KB | None | 0 0
  1. <?
  2. /**
  3.  * Èìïîðò êàòàëîãà èç xml-ôàéëîâ CML2.0 áåç ïðÿìîãî îáìåíà ñ 1Ñ 8.1
  4.  * http://dev.1c-bitrix.ru/community/webdev/group/78/blog/1654/
  5.  */
  6. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
  7. header("Content-type:text/html; charset=windows-1251");
  8. $_SESSION["BX_CML2_IMPORT"]["NS"]["STEP"]=0;
  9. ?>
  10. <html>
  11. <a  href="javascript:start('import.xml')">èìïîðò import.xml</a>
  12. <a href="javascript:start('offers.xml')">èìïîðò offers.xml</a>
  13. <a href="javascript:start('company.xml')"> èìïîðò company.xml</a>
  14. <a style='color:red;' href="javascript:reset()">îáíóëèòü øàã</a>
  15. <a style='color:red;' href="javascript:status='stop'">îñòàíîâèòü èìïîðò</a><hr>
  16. <div id='main' style='display:none;width:400;font-size:12;border:1px solid #ADC3D5; padding:5'>
  17. <div id="log"></div>
  18. <div align=right id="load"></div>
  19. </div>
  20. <div id="timer"></div>
  21.  
  22. <script>
  23. var
  24. log=document.getElementById("log");
  25. timer=document.getElementById("timer");
  26. load=document.getElementById("load");
  27. var zup_import=false;
  28. //ïåðåìåííûå òàéìåðà
  29. m_second=0;
  30. seconds=0;
  31. minute=0;
  32. //ïåðåìåííûå èìïîðòà
  33. i=1;
  34. a='';
  35. proccess=true;
  36. status="continue";
  37. function createHttpRequest()
  38.    {
  39.    var httpRequest;
  40.       if (window.XMLHttpRequest)
  41.       httpRequest = new XMLHttpRequest();  
  42.       else if (window.ActiveXObject) {    
  43.       try {
  44.       httpRequest = new ActiveXObject('Msxml2.XMLHTTP');  
  45.       } catch (e){}                                  
  46.       try {                                          
  47.       httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
  48.       } catch (e){}
  49.       }
  50.    return httpRequest;
  51. }
  52. function start(file)
  53.       {
  54.       document.getElementById("main").style.display='block';
  55.       load.innerHTML="<b>Çàãðóçêà</b>...<img align='center'                 src='http://gifanimation.ru/images/ludi/17_3.gif' width='30'/>"
  56.              i=1;
  57.       a="";
  58.       m_second=0;
  59.         seconds=0;
  60.       proccess=true;
  61.       start_timer();
  62.       timer.innerHTML="";
  63.       if (file=="company.xml") {zup_import=true;}
  64.       log.innerHTML="<b>Èìïîðò "+file+"</b><hr>";
  65.       query_1c(file)
  66.       }
  67.      
  68.       function query_1c(file)
  69.       {
  70.       var import_1c=createHttpRequest();
  71.       if (zup_import==true)
  72.       {
  73.       r="/bitrix/admin/1c_intranet.php?type=catalog&mode=import&filename="+file;
  74.       } else{r="/bitrix/admin/1c_exchange.php?type=catalog&mode=import&filename="+file;}
  75.                      load.style.display="block";
  76.             import_1c.open("GET", r, true);
  77.       import_1c.onreadystatechange = function()
  78.             {
  79.             a=log.innerHTML;
  80.             if (import_1c.readyState == 4 && import_1c.status == 0)
  81.                   {
  82.                   error_text="<em>Îøèáêà â ïðîöåññå âûãðóçêè</em><div style='width:270;font-size:11;border:1px solid             black;background-color:#ADC3D5;padding:5'>Ñåðâåð óïàë è íå âåðíóë çàãîëîâêîâ.</div>"
  83.                      log.innerHTML=a+"Øàã "+i+": "+error_text;
  84.                      load.style.display="none";
  85.                      status="continue"
  86.                      alert("Import is crashed!");
  87.                   }
  88.              
  89.                   if (import_1c.readyState == 4 && import_1c.status == 200)  
  90.                      {
  91.                         if ((import_1c.responseText.substr(0,8 )!="progress")&&(import_1c.responseText.substr(0,7)!="success"))
  92.                         {
  93.                            error_text="<em>Îøèáêà â ïðîöåññå âûãðóçêè</em><div style='width:270;font-size:11;border:1px solid black;background-color:#ADC3D5;padding:5'>"+import_1c.responseText+"</div>"
  94.                            log.innerHTML=a+"Øàã "+i+": "+error_text;
  95.                            status="error";
  96.                         }
  97.                         else
  98.                         {
  99.                            n=import_1c.responseText.lastIndexOf('s')+1;
  100.                            l=import_1c.responseText.length;
  101.                            mess=import_1c.responseText.substr(n,l);
  102.                            log.innerHTML=a+"Øàã "+i+": "+mess+" ("+seconds+" ñåê.)"+"<br>";
  103.                            seconds=0;
  104.                            load.style.display="none";
  105.                            i++;
  106.                         }
  107.                         if ((import_1c.responseText.substr(0,7)=="success")||(status=="error")||(status=="stop"))
  108.                         {
  109.                            load.style.display="none";
  110.                            status="continue"
  111.                            proccess=false;
  112.                            timer.innerHTML="<hr>Âðåìÿ âûãðóçêè: <b>"+minute+" ìèí. "+m_second+" ñåê.</b>";
  113.                         }
  114.                         else
  115.                         {
  116.                            query_1c(file);
  117.                         }
  118.                      }
  119.                    
  120.                    
  121.             };
  122. import_1c.send(null);
  123.       }
  124.       function start_timer()
  125.       {
  126.          if (m_second==60)
  127.          {
  128.          m_second=0;
  129.          minute+=1;
  130.          }
  131.          if (proccess==true)
  132.          {
  133.          seconds+=1;
  134.          m_second+=1;
  135.          setTimeout("start_timer()",1000);
  136.       }
  137.       }
  138.        
  139. function reset()
  140.             {
  141.             var rest=createHttpRequest();
  142.                q="bx_1c_import_lite.php";
  143.                rest.open("GET", q, true);
  144.                rest.onreadystatechange=function()
  145.                         {
  146.                         if (rest.readyState == 4 && rest.status == 200)  
  147.                            alert("Øàã èìïîðòà îáíóë¸í!");
  148.                         }
  149.                
  150.                rest.send(null);
  151.                
  152.             }      
  153. </script>
  154.  
  155. <style>
  156. a {
  157.    text-decoration: none;
  158.    color:#36648B;
  159.    background:#FFEFD5; 
  160.    font-size:13;
  161.    padding:5;
  162.    font-family:Arial;
  163.    border:1px dashed #ADC3D5;
  164.    }
  165.    
  166. </style>
  167. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement