-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.php
231 lines (212 loc) · 7.21 KB
/
export.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
/*
* Выгрузка bitrix
* Mikhail Novikov
* v.1.0 // 11.11.19
*/
?>
<!DOCTYPE html>
<html>
<head>
<?php header("Content-type:text/html; charset=utf-8");?>
<title>Импорт Базы</title>
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,600&display=swap" rel="stylesheet">
<style type="text/css">
.button{
padding: 10px 15px;
text-align: center;
text-decoration: none;
box-sizing: border-box;
line-height: 40px;
color: #fff;
border-radius: 3px;
margin: 0 10px;
font-size: 1rem;
font-weight: 300;
}
.button--green{
background: #8BC34A;
}
.button--red{
background: red;
}
.header{
text-align: center;
border-bottom: 1px solid #ccc;
box-shadow: 0 0 15px #ccc;
position: fixed;
width: 100%;
top: 0;
padding: 10px 0;
}
#main{
display: block;
border: 1px solid rgb(173, 195, 213);
max-width: 80%;
margin: 0 auto;
margin-top: 100px;
padding: 25px;
border-radius: 3px;
}
body{
padding: 0;
margin:0;
font-family: 'Montserrat', sans-serif;
}
.error{
background: red;
padding: 5px 10px;
color: #fff;
border-radius: 3px;
margin-top: 15px;
}
.time{
max-width: 80%;
margin: 0 auto;
margin-top: 25px;
text-align: right;
}
hr{
opacity: .3;
}
#log{
height: 70vh;
overflow-y: scroll;
}
</style>
</head>
<body>
<header class="header">
<a href="javascript:start('import.xml')" class="button button--green">импорт import.xml</a>
<a href="javascript:start('offers.xml')" class="button button--green">импорт offers.xml</a>
<a href="javascript:reset()" class="button button--red">обнулить шаг</a>
<a href="javascript:status='stop'" class="button button--red">остановить импорт</a>
</header>
<div id='main' style='display:none;'>
<div id="log"></div>
<div align=right id="load"></div>
</div>
<div id="timer"></div>
<script type="text/javascript">
var
log=document.getElementById("log");
timer=document.getElementById("timer");
load=document.getElementById("load");
var zup_import=false;
//переменные таймера
m_second=0;
seconds=0;
minute=0;
//переменные импорта
i=1;
a='';
proccess=true;
status="continue";
function createHttpRequest() {
var httpRequest;
if (window.XMLHttpRequest)
httpRequest = new XMLHttpRequest();
else if (window.ActiveXObject) {
try {
httpRequest = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e){}
try {
httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
} catch (e){}
}
return httpRequest;
}
function start(file) {
document.getElementById("main").style.display='block';
load.innerHTML="<b>Загрузка</b>..."
i=1;
a="";
m_second=0;
seconds=0;
proccess=true;
start_timer();
timer.innerHTML="";
if (file=="company.xml") {zup_import=true;}
log.innerHTML="<b>Импорт "+file+"</b><hr>";
query_1c(file)
}
function query_1c(file) {
var import_1c=createHttpRequest();
if (zup_import==true)
{
r="/fivecms/cml/1c_exchange.php?type=catalog&mode=import&filename="+file;
} else{r="/fivecms/cml/1c_exchange.php?type=catalog&mode=import&filename="+file;}
load.style.display="block";
import_1c.open("GET", r, true);
import_1c.onreadystatechange = function()
{
a=log.innerHTML;
if (import_1c.readyState == 4 && import_1c.status == 0)
{
error_text="<em>Ошибка в процессе выгрузки</em><div class='error'>Сервер упал и не вернул заголовков.</div>"
log.innerHTML=a+"Шаг "+i+": "+error_text;
load.style.display="none";
status="continue"
alert("Import is crashed!");
}
if (import_1c.readyState == 4 && import_1c.status == 200)
{
if ((import_1c.responseText.substr(0,8 )!="progress")&&(import_1c.responseText.substr(0,7)!="success"))
{
error_text="<em>Ошибка в процессе выгрузки</em><div class='error'>"+import_1c.responseText+"</div>"
log.innerHTML=a+"Шаг "+i+": "+error_text;
status="error";
}
else
{
n=import_1c.responseText.lastIndexOf('s')+1;
l=import_1c.responseText.length;
mess=import_1c.responseText.substr(n,l);
log.innerHTML=a+"Шаг "+i+": "+mess+" ("+seconds+" сек.)"+"<br>";
seconds=0;
load.style.display="none";
i++;
}
if ((import_1c.responseText.substr(0,7)=="success")||(status=="error")||(status=="stop"))
{
load.style.display="none";
status="continue"
proccess=false;
timer.innerHTML="<div class='time'>Время выгрузки: <b>"+minute+" мин. "+m_second+" сек.</b></div>";
}
else
{
query_1c(file);
}
}
};
import_1c.send(null);
}
function start_timer() {
if (m_second==60)
{
m_second=0;
minute+=1;
}
if (proccess==true)
{
seconds+=1;
m_second+=1;
setTimeout("start_timer()",1000);
}
}
function reset() {
var rest=createHttpRequest();
q="export.php";
rest.open("GET", q, true);
rest.onreadystatechange=function()
{
if (rest.readyState == 4 && rest.status == 200)
alert("Шаг импорта обнулён!");
}
rest.send(null);
}
</script>
</body>
</html>