PluginProbe
Welcart e-Commerce / 1.3.2
Welcart e-Commerce v1.3.2
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
usc-e-shop / functions / define_function.php

define_function.php in Welcart e-Commerce 1.3.2, at functions/define_function.php

1,317 lines 50.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 function usces_define_functions(){
3
4 //20101111ysk start
5 if( !function_exists('usces_item_uploadcsv') ):
6 function usces_item_uploadcsv(){
7 global $wpdb, $usces, $user_ID;
8
9 if( !current_user_can( 'import' ) ){
10 $res['status'] = 'error';
11 $res['message'] = __('You do not have permission to do that.');
12 $url = USCES_ADMIN_URL . '?page=usces_itemedit&usces_status=' . $res['status'] . '&usces_message=' . urlencode($res['message']);
13 wp_redirect($url);
14 exit;
15 }
16
17 //check dataSELECT id,title FROM table GROUP BY id HAVING COUNT(id) > 1;
18 $query = $wpdb->prepare("SELECT post_id, meta_value FROM {$wpdb->postmeta}
19 LEFT JOIN {$wpdb->posts} ON ID = post_id
20 WHERE meta_key = %s AND (post_status = 'pending' OR post_status = 'publish' OR post_status = 'draft' OR post_status = 'private' OR post_status = 'future')
21 GROUP BY meta_value HAVING COUNT(meta_value) > 1",
22 '_itemCode');
23 $db_check = $wpdb->get_results( $query, ARRAY_A );
24 if( $db_check ) {
25 $res['status'] = 'error';
26 $res['message'] .= __('The same product cord is registered.', 'usces');
27 foreach($db_check as $d_item){
28 $res['message'] .= ' , ' . $d_item['meta_value'];
29 }
30 $url = USCES_ADMIN_URL . '?page=usces_itemedit&usces_status=' . $res['status'] . '&usces_message=' . urlencode($res['message']);
31 wp_redirect($url);
32 exit;
33 }
34
35
36 $path = WP_CONTENT_DIR . '/uploads/';
37 /*********************************************************************/
38 // Upload
39 /**********************************************************************/
40 if( isset($_REQUEST['action']) && 'itemcsv' == $_REQUEST['action'] ){
41 $workfile = $_FILES["usces_upcsv"]["tmp_name"];
42
43 if ( !is_uploaded_file($workfile) ) {
44 $res['status'] = 'error';
45 $res['message'] = __('The file was not uploaded.', 'usces');
46 $url = USCES_ADMIN_URL . '?page=usces_itemedit&usces_status=' . $res['status'] . '&usces_message=' . urlencode($res['message']);
47 wp_redirect($url);
48 exit;
49 }
50
51 //check ext
52 list($fname, $fext) = explode('.', $_FILES["usces_upcsv"]["name"], 2);
53 if( $fext != 'csv' ) {
54 $res['status'] = 'error';
55 $res['message'] = __('The file is not supported.', 'usces').$fname.'.'.$fext;
56 $url = USCES_ADMIN_URL . '?page=usces_itemedit&usces_status=' . $res['status'] . '&usces_message=' . urlencode($res['message']);
57 wp_redirect($url);
58 exit;
59 }
60
61 $new_filename = base64_encode($fname . '_' . time() . '.' .$fext);
62 if ( ! move_uploaded_file($_FILES['usces_upcsv']['tmp_name'], $path.$new_filename) ) {
63 $res['status'] = 'error';
64 $res['message'] = __('The file was not stored.', 'usces').$fname.'.'.$fext;
65 $url = USCES_ADMIN_URL . '?page=usces_itemedit&usces_status=' . $res['status'] . '&usces_message=' . urlencode($res['message']);
66 wp_redirect($url);
67 exit;
68 }
69 return $new_filename;
70 }
71
72
73 $yn = "\r\n";
74 $br = "<br />";
75 /*********************************************************************/
76 // Register
77 /**********************************************************************/
78 if( isset($_REQUEST['regfile']) && !WCUtils::is_blank($_REQUEST['regfile']) && isset($_REQUEST['action']) && 'upload_register' == $_REQUEST['action'] ){
79 $file_name = $_REQUEST['regfile'];
80 $decode_filename = base64_decode($file_name);
81 if( ! file_exists($path.$file_name) ){
82 $res['status'] = 'error';
83 $res['message'] = __('CSV file does not exist.', 'usces').esc_html($decode_filename);
84 //echo $res['status'] . ' : ' . $res['message'];
85 //return;
86 return( $res );
87 }
88 }
89 /*////////////////////////////////////////*/
90 // ready
91 /*////////////////////////////////////////*/
92 $start = microtime(true);
93
94 //$wpdb->show_errors();
95 $wpdb->query( 'SET SQL_BIG_SELECTS=1' );
96 set_time_limit(3600);
97
98 define('USCES_COL_POST_ID', 0); //new
99 define('USCES_COL_POST_AUTHOR', 1); //new
100 define('USCES_COL_POST_CONTENT', 2); //15
101 define('USCES_COL_POST_TITLE', 3); //14
102 define('USCES_COL_POST_EXCERPT', 4); //16
103 define('USCES_COL_POST_STATUS', 5); //17
104 define('USCES_COL_POST_COMMENT_STATUS', 6); //new
105 define('USCES_COL_POST_PASSWORD', 7); //new
106 define('USCES_COL_POST_NAME', 8); //new
107 define('USCES_COL_POST_MODIFIED', 9); //18
108
109 define('USCES_COL_ITEM_CODE', 10); //0
110 define('USCES_COL_ITEM_NAME', 11); //1
111 define('USCES_COL_ITEM_RESTRICTION', 12); //2
112 define('USCES_COL_ITEM_POINTRATE', 13); //3
113 define('USCES_COL_ITEM_GPNUM1', 14); //4
114 define('USCES_COL_ITEM_GPDIS1', 15); //5
115 define('USCES_COL_ITEM_GPNUM2', 16); //6
116 define('USCES_COL_ITEM_GPDIS2', 17); //7
117 define('USCES_COL_ITEM_GPNUM3', 18); //8
118 define('USCES_COL_ITEM_GPDIS3', 19); //9
119 define('USCES_COL_ITEM_SHIPPING', 20); //10
120 define('USCES_COL_ITEM_DELIVERYMETHOD', 21); //11
121 define('USCES_COL_ITEM_SHIPPINGCHARGE', 22); //12
122 define('USCES_COL_ITEM_INDIVIDUALSCHARGE', 23); //13
123
124 define('USCES_COL_CATEGORY', 24); //19
125 define('USCES_COL_POST_TAG', 25); //20
126 define('USCES_COL_CUSTOM_FIELD', 26); //new
127
128 define('USCES_COL_SKU_CODE', 27); //21
129 define('USCES_COL_SKU_NAME', 28); //22
130 define('USCES_COL_SKU_CPRICE', 29); //23
131 define('USCES_COL_SKU_PRICE', 30); //24
132 define('USCES_COL_SKU_ZAIKONUM', 31); //25
133 define('USCES_COL_SKU_ZAIKO', 32); //26
134 define('USCES_COL_SKU_UNIT', 33); //27
135 define('USCES_COL_SKU_GPTEKIYO', 34); //28
136 // define('IDENTIFIER_OLE', pack("CCCCCCCC",0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1));
137
138
139 $lines = array();
140 $total_num = 0;
141 $comp_num = 0;
142 $err_num = 0;
143 $min_field_num = 35;//29
144 $log = '';
145 $pre_code = '';
146 $sku_index = 0;
147 $res = array();
148 $date_pattern = "/(\d{4})-(\d{2}|\d)-(\d{2}|\d) (\d{2}):(\d{2}|\d):(\d{2}|\d)/";
149 $linereadytime = 0;
150 $checktime = 0;
151 $insertposttime = 0;
152 $metadeletetime = 0;
153 $addmetatime = 0;
154 $AddOptiontime = 0;
155 $AddSKUtime = 0;
156 $onelinetime = 0;
157
158 //log
159 if ( ! ($fpi = fopen (USCES_PLUGIN_DIR.'/logs/itemcsv_log.txt', "w"))) {
160 $res['status'] = 'error';
161 $res['message'] = __('The log file was not prepared for.', 'usces').esc_html($decode_filename);
162 echo $res['status'] . ' : ' . $res['message'];
163 return;
164 }
165 //read data
166 if ( ! ($fpo = fopen ($path.$file_name, "r"))) {
167 $res['status'] = 'error';
168 $res['message'] = __('A file does not open.', 'usces').esc_html($decode_filename);
169 echo $res['status'] . ' : ' . $res['message'];
170 return;
171 }
172
173
174 $orglines = array();
175 $sp = ",";
176 $fname_parts = explode('.', $decode_filename);
177 if('csv' !== end($fname_parts)) {
178 $res['status'] = 'error';
179 $res['message'] = __('This file is not in the CSV file.', 'usces').esc_html($decode_filename);
180 echo $res['status'] . ' : ' . $res['message'];
181 return;
182
183 } else {
184 $buf = '';
185 while (! feof ($fpo)) {
186 $temp = fgets ($fpo, 10240);
187 if( 0 == strlen($temp) ) continue;
188
189 $num = substr_count($temp, '"');
190 if( 0 == $num % 2 && '' == $buf ){
191 $orglines[] = $temp;
192 }elseif( 1 == $num % 2 && '' == $buf ){
193 $buf .= $temp;
194 }elseif( 0 == $num % 2 && '' != $buf ){
195 $buf .= $temp;
196 }elseif( 1 == $num % 2 && '' != $buf ){
197 $buf .= $temp;
198 $orglines[] = $buf;
199 $buf = '';
200 }
201 }
202 }
203 fclose($fpo);
204
205 echo '<script type="text/javascript">changeMsg("' . __('Processing...', 'usces') . '");</script>'.$yn;
206 echo '<div class="error_log">'.$yn;
207 ob_flush();
208 flush();
209
210 foreach($orglines as $line){
211 $line = trim($line);
212 if( 0 !== strpos( $line, 'Post ID' ) && !empty($line) )
213 $lines[] = $line;
214 }
215 $total_num = count($lines);
216
217 $readytime = microtime(true);
218 //reg loop
219 foreach($lines as $rows_num => $line){
220
221
222 /*////////////////////////////////////////*/
223 // lineReady
224 /*////////////////////////////////////////*/
225 $linestart = microtime(true);
226 $datas = array();
227
228 $logtemp = '';
229 $mestemp = '';
230 $line = trim($line);
231 if( empty($line) ) continue;
232
233 $d = explode($sp, $line);
234 $buf = '';
235 foreach($d as $data) {
236 $num = substr_count($data, '"');
237 if( 0 == $num % 2 && '' == $buf ){
238 if( '"' == substr($data, 0, 1) )
239 $data = substr($data, 1);
240 if( '"' == substr($data, -1) )
241 $data = substr($data, 0, -1);
242 $data = str_replace(array('""'), '"', $data);
243 $datas[] = ( false !== $data ) ? $data : '';
244 }elseif( 1 == $num % 2 && '' == $buf ){
245 $buf .= $data;
246 }elseif( 0 == $num % 2 && '' != $buf ){
247 $buf .= $sp.$data;
248 }elseif( 1 == $num % 2 && '' != $buf ){
249 $buf .= $sp.$data;
250 if( '"' == substr($buf, 0, 1) )
251 $buf = substr($buf, 1);
252 if( '"' == substr($buf, -1) )
253 $buf = substr($buf, 0, -1);
254 $buf = str_replace(array('""'), '"', $buf);
255 $datas[] = ( false !== $buf ) ? $buf : '';
256 $buf = '';
257 }
258 }
259
260 if( 'Post ID' == $datas[USCES_COL_POST_ID] )
261 continue;
262
263
264 if( $min_field_num > count($datas) ){
265 $err_num++;
266 $mes = "No." . ($rows_num+1)." ".count($datas) . "\t".__('The number of the columns is abnormal.', 'usces');
267 $logtemp .= $mes.$yn;
268 $log .= $logtemp;
269 echo $mes.$br.$yn;
270 continue;
271 }
272
273 if( $pre_code == $datas[USCES_COL_ITEM_CODE] && WCUtils::is_blank($datas[USCES_COL_POST_ID]) ){
274 $mode = 'add';
275
276 }else{
277 $post_id = ( !WCUtils::is_blank($datas[USCES_COL_POST_ID]) ) ? (int)$datas[USCES_COL_POST_ID] : NULL;
278 if( $post_id ){
279 $db_res = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE ID = %d", $post_id) );
280 if( !$db_res ){
281 $err_num++;
282 $mes = "No." . ($rows_num+1) . "\t".__("Post-ID {$post_id} does not exist in the database.", 'usces');
283 $logtemp .= $mes.$yn;
284 $log .= $logtemp;
285 echo $mes.$br.$yn;
286 continue;
287 }
288 }
289 if( $post_id ){
290 $mode = 'upd';
291 }else{
292 $mode = 'add';
293 }
294 }
295
296 $lineready = microtime(true);
297 $linereadytime += $lineready-$linestart;
298 /*////////////////////////////////////////*/
299 // dataCheck
300 /*////////////////////////////////////////*/
301 //data check loop
302 foreach($datas as $key => $data){
303 $data = trim(mb_convert_encoding($data, 'UTF-8', 'SJIS'));
304 switch($key){
305 case USCES_COL_ITEM_CODE:
306 if( 0 == strlen($data) ){
307 $mes = "No." . ($rows_num+1) . "\t".__('An item cord is non-input.', 'usces');
308 $logtemp .= $mes.$yn;
309 $mestemp .= $mes.$br.$yn;
310 }else{
311 $query = $wpdb->prepare("SELECT meta_id, post_id FROM {$wpdb->postmeta}
312 LEFT JOIN {$wpdb->posts} ON ID = post_id
313 WHERE meta_key = %s AND meta_value = %s AND (post_status = 'pending' OR post_status = 'publish' OR post_status = 'draft' OR post_status = 'private' OR post_status = 'future')",
314 '_itemCode', $data);
315 $db_res1 = $wpdb->get_results( $query, ARRAY_A );
316 if( 'upd' == $mode ){
317 if( 1 < count($db_res1) ){
318 $mes = "No." . ($rows_num+1) . "\t".__('This Item-Code has been duplicated.', 'usces');
319 $logtemp .= $mes.$yn;
320 $mestemp .= $mes.$br.$yn;
321 $mes = '';
322 foreach($db_res1 as $res_val){
323 $mes .= "meta_id=" . $res_val['meta_id'] . ", post_id=" . $res_val['post_id'] . "<br />";
324 }
325 $logtemp .= $mes.$yn;
326 $mestemp .= $mes.$br.$yn;
327 }
328 $query = $wpdb->prepare("SELECT meta_id, post_id FROM {$wpdb->postmeta}
329 LEFT JOIN {$wpdb->posts} ON ID = post_id
330 WHERE post_id <> %d AND meta_key = %s AND meta_value = %s AND (post_status = 'pending' OR post_status = 'publish' OR post_status = 'draft' OR post_status = 'private' OR post_status = 'future')",
331 $post_id, '_itemCode', $data);
332 $db_res2 = $wpdb->get_results( $query, ARRAY_A );
333 if( 0 < count($db_res2) ){
334 $mes = "No." . ($rows_num+1) . "\t".__('This Item-Code has already been used.', 'usces');
335 $logtemp .= $mes.$yn;
336 $mestemp .= $mes.$br.$yn;
337 $mes = '';
338 foreach($db_res2 as $res_val){
339 $mes .= "meta_id=" . $res_val['meta_id'] . ", post_id=" . $res_val['post_id'] . "<br />";
340 }
341 $logtemp .= $mes.$yn;
342 $mestemp .= $mes.$br.$yn;
343 }
344 }else if( 'add' == $mode ){
345 if( $data != $pre_code ) {
346 if( 0 < count($db_res1) ){
347 $mes = "No." . ($rows_num+1) . "\t".__('This Item-Code has already been used.', 'usces');
348 $logtemp .= $mes.$yn;
349 $mestemp .= $mes.$br.$yn;
350 $mes = '';
351 foreach($db_res1 as $res_val){
352 $mes .= "meta_id=" . $res_val['meta_id'] . ", post_id=" . $res_val['post_id'] . "<br />";
353 }
354 $logtemp .= $mes.$yn;
355 $mestemp .= $mes.$br.$yn;
356 }
357 }
358 }
359 }
360 break;
361 case USCES_COL_ITEM_NAME:
362 if( 0 == strlen($data) ){
363 $mes = "No." . ($rows_num+1) . "\t".__('An item name is non-input.', 'usces');
364 $logtemp .= $mes.$yn;
365 $mestemp .= $mes.$br.$yn;
366 }
367 break;
368 case USCES_COL_ITEM_RESTRICTION:
369 if( !preg_match("/^[0-9]+$/", $data) && 0 != strlen($data) ){
370 $mes = "No." . ($rows_num+1) . "\t".__('A value of the purchase limit number is abnormal.', 'usces');
371 $logtemp .= $mes.$yn;
372 $mestemp .= $mes.$br.$yn;
373 }
374 break;
375 case USCES_COL_ITEM_POINTRATE:
376 if( !preg_match("/^[0-9]+$/", $data) ){
377 $mes = "No." . ($rows_num+1) . "\t".__('A value of the point rate is abnormal.', 'usces');
378 $logtemp .= $mes.$yn;
379 $mestemp .= $mes.$br.$yn;
380 }
381 break;
382 case USCES_COL_ITEM_GPNUM1:
383 if( !preg_match("/^[0-9]+$/", $data) ){
384 $mes = "No." . ($rows_num+1) . "\t".__('Business package discount', 'usces')."1-".__('umerical value is abnormality.', 'usces');
385 $logtemp .= $mes.$yn;
386 $mestemp .= $mes.$br.$yn;
387 }
388 break;
389 case USCES_COL_ITEM_GPDIS1:
390 if( !preg_match("/^[0-9]+$/", $data) || ( 0 < $datas[USCES_COL_ITEM_GPNUM1] && 1 > $data ) ){
391 $mes = "No." . ($rows_num+1) . "\t".__('Business package discount', 'usces')."1-".__('rate is abnormal.', 'usces');
392 $logtemp .= $mes.$yn;
393 $mestemp .= $mes.$br.$yn;
394 }
395 break;
396 case USCES_COL_ITEM_GPNUM2:
397 if( !preg_match("/^[0-9]+$/", $data) || ($datas[USCES_COL_ITEM_GPNUM1] >= $data && 0 != $data) ){
398 $mes = "No." . ($rows_num+1) . "\t".__('Business package discount', 'usces')."2-".__('umerical value is abnormality.', 'usces');
399 $logtemp .= $mes.$yn;
400 $mestemp .= $mes.$br.$yn;
401 }
402 break;
403 case USCES_COL_ITEM_GPDIS2:
404 if( !preg_match("/^[0-9]+$/", $data) || ( 0 < $datas[USCES_COL_ITEM_GPNUM2] && 1 > $data ) ){
405 $mes = "No." . ($rows_num+1) . "\t".__('Business package discount', 'usces')."2-".__('rate is abnormal.', 'usces');
406 $logtemp .= $mes.$yn;
407 $mestemp .= $mes.$br.$yn;
408 }
409 break;
410 case USCES_COL_ITEM_GPNUM3:
411 if( !preg_match("/^[0-9]+$/", $data) || ($datas[USCES_COL_ITEM_GPNUM2] >= $data && 0 != $data) ){
412 $mes = "No." . ($rows_num+1) . "\t".__('Business package discount', 'usces')."3-".__('umerical value is abnormality.', 'usces');
413 $logtemp .= $mes.$yn;
414 $mestemp .= $mes.$br.$yn;
415 }
416 break;
417 case USCES_COL_ITEM_GPDIS3:
418 if( !preg_match("/^[0-9]+$/", $data) || ( 0 < $datas[USCES_COL_ITEM_GPNUM3] && 1 > $data ) ){
419 $mes = "No." . ($rows_num+1) . "\t".__('Business package discount', 'usces')."3-".__('rate is abnormal.', 'usces');
420 $logtemp .= $mes.$yn;
421 $mestemp .= $mes.$br.$yn;
422 }
423 break;
424 case USCES_COL_ITEM_SHIPPING:
425 if( !preg_match("/^[0-9]+$/", $data) || 9 < $data ){
426 $mes = "No." . ($rows_num+1) . "\t".__('A value of the shipment day is abnormal.', 'usces');
427 $logtemp .= $mes.$yn;
428 $mestemp .= $mes.$br.$yn;
429 }
430 break;
431 case USCES_COL_ITEM_DELIVERYMETHOD:
432 if( 0 === strlen($data) || !preg_match("/^[0-9;]+$/", $data) ){
433 $mes = "No." . ($rows_num+1) . "\t".__('Invalid value of Delivery method.', 'usces');
434 $logtemp .= $mes.$yn;
435 $mestemp .= $mes.$br.$yn;
436 }
437 break;
438 case USCES_COL_ITEM_SHIPPINGCHARGE:
439 if( 0 === strlen($data) || !preg_match("/^[0-9]+$/", $data) ){
440 $mes = "No." . ($rows_num+1) . "\t".__('Invalid type of shipping charge.', 'usces');
441 $logtemp .= $mes.$yn;
442 $mestemp .= $mes.$br.$yn;
443 }
444 break;
445 case USCES_COL_ITEM_INDIVIDUALSCHARGE:
446 if( !preg_match("/^[0-9]+$/", $data) || 1 < $data ){
447 $mes = "No." . ($rows_num+1) . "\t".__('A value of the postage individual charging is abnormal.', 'usces');
448 $logtemp .= $mes.$yn;
449 $mestemp .= $mes.$br.$yn;
450 }
451 break;
452 case USCES_COL_POST_ID:
453 if( !preg_match("/^[0-9]+$/", $data) && 0 != strlen($data) ){
454 $mes = "No." . ($rows_num+1) . "\t".__('A value of the Post-ID is abnormal.', 'usces');
455 $logtemp .= $mes.$yn;
456 $mestemp .= $mes.$br.$yn;
457 }
458 break;
459 case USCES_COL_POST_AUTHOR:
460 case USCES_COL_POST_COMMENT_STATUS:
461 case USCES_COL_POST_PASSWORD:
462 case USCES_COL_POST_NAME:
463 case USCES_COL_POST_TITLE:
464 case USCES_COL_POST_CONTENT:
465 case USCES_COL_POST_EXCERPT:
466 break;
467 case USCES_COL_POST_STATUS:
468 $array17 = array('publish', 'future', 'draft', 'pending', 'private');
469 if( !in_array($data, $array17) || WCUtils::is_blank($data) ){
470 $mes = "No." . ($rows_num+1) . "\t".__('A value of the display status is abnormal.', 'usces');
471 $logtemp .= $mes.$yn;
472 $mestemp .= $mes.$br.$yn;
473 }
474 break;
475 case USCES_COL_POST_MODIFIED:
476 if( 'future' == $datas[USCES_COL_POST_STATUS] && (WCUtils::is_blank($data) || '0000-00-00 00:00:00' === $data) ){
477 if( preg_match($date_pattern, $data, $match) ){
478 if( checkdate($match[2], $match[3], $match[1]) &&
479 (0 < $match[4] && 24 > $match[4]) &&
480 (0 < $match[5] && 60 > $match[5]) &&
481 (0 < $match[6] && 60 > $match[6]) ){
482 $mes = "";
483 }else{
484 $mes = "No." . ($rows_num+1) . "\t".__('A value of the schedule is abnormal.', 'usces');
485 $logtemp .= $mes.$yn;
486 $mestemp .= $mes.$br.$yn;
487 }
488
489 }else{
490 $mes = "No." . ($rows_num+1) . "\t".__('A value of the schedule is abnormal.', 'usces');
491 $logtemp .= $mes.$yn;
492 $mestemp .= $mes.$br.$yn;
493 }
494 }else if( !WCUtils::is_blank($data) && '0000-00-00 00:00:00' !== $data ){
495 if(preg_match("/^[0-9]+$/", substr($data,0,4))) {//�
496 �頭4桁が数値のみ
497 if(strtotime($data) === false){
498 $mes = "No." . ($rows_num+1) . "\t".__('A value of the schedule is abnormal.', 'usces');
499 $logtemp .= $mes.$yn;
500 $mestemp .= $mes.$br.$yn;
501 }
502 } else {
503 $datetime = explode(' ', $data);
504 $date_str = usces_dates_interconv($datetime[0]).' '.$datetime[1];
505 if(strtotime($date_str) === false){
506 $mes = "No." . ($rows_num+1) . "\t".__('A value of the schedule is abnormal.', 'usces');
507 $logtemp .= $mes.$yn;
508 $mestemp .= $mes.$br.$yn;
509 }
510 }
511 }
512 break;
513 case USCES_COL_CATEGORY:
514 if( 0 == strlen($data) ){
515 $mes = "No." . ($rows_num+1) . "\t".__('A category is non-input.', 'usces');
516 $logtemp .= $mes.$yn;
517 $mestemp .= $mes.$br.$yn;
518 }
519 break;
520 case USCES_COL_POST_TAG:
521 break;
522 case USCES_COL_CUSTOM_FIELD:
523 break;
524 case USCES_COL_SKU_CODE:
525 if( 0 == strlen($data) ){
526 $mes = "No." . ($rows_num+1) . "\t".__('A SKU cord is non-input.', 'usces');
527 $logtemp .= $mes.$yn;
528 $mestemp .= $mes.$br.$yn;
529 }
530 break;
531 case USCES_COL_SKU_NAME:
532 break;
533 case USCES_COL_SKU_CPRICE:
534 if( 0 < strlen($data) and !preg_match("/^\d$|^\d+\.?\d+$/", $data) ){
535 $mes = "No." . ($rows_num+1) . "\t".__('A value of the price is abnormal.', 'usces');
536 $logtemp .= $mes.$yn;
537 $mestemp .= $mes.$br.$yn;
538 }
539 break;
540 case USCES_COL_SKU_PRICE:
541 if( !preg_match("/^\d$|^\d+\.?\d+$/", $data) || 0 == strlen($data) ){
542 $mes = "No." . ($rows_num+1) . "\t".__('A value of the normal price is abnormal.', 'usces');
543 $logtemp .= $mes.$yn;
544 $mestemp .= $mes.$br.$yn;
545 }
546 break;
547 case USCES_COL_SKU_ZAIKONUM:
548 if( 0 < strlen($data) and !preg_match("/^[0-9]+$/", $data) ){
549 $mes = "No." . ($rows_num+1) . "\t".__('A value of the stock amount is abnormal.', 'usces');
550 $logtemp .= $mes.$yn;
551 $mestemp .= $mes.$br.$yn;
552 }
553 break;
554 case USCES_COL_SKU_ZAIKO:
555 if( !preg_match("/^[0-9]+$/", $data) || 4 < $data ){
556 $mes = "No." . ($rows_num+1) . "\t".__('A value of the stock status is abnormal.', 'usces');
557 $logtemp .= $mes.$yn;
558 $mestemp .= $mes.$br.$yn;
559 }
560 break;
561 case USCES_COL_SKU_UNIT:
562 break;
563 case USCES_COL_SKU_GPTEKIYO:
564 if( !preg_match("/^[0-9]+$/", $data) || 1 < $data ){
565 $mes = "No." . ($rows_num+1) . "\t".__('The value of the duties pack application is abnormal.', 'usces');
566 $logtemp .= $mes.$yn;
567 $mestemp .= $mes.$br.$yn;
568 }
569 break;
570 }
571 }
572 $opnum = ceil((count($datas) - $min_field_num) / 4);
573 for($i=0; $i<$opnum; $i++){
574 $val = array();
575 $oplogtemp = '';
576 $opmestemp = '';
577 for($o=1; $o<=4; $o++){
578 $key = ($min_field_num-1)+$o+($i*4);
579 if( isset($datas[$key]) ){
580 $value = trim($datas[$key]);
581 }else{
582 $value = NULL;
583 }
584 switch($o){
585 case 1:
586 if( empty($value) ){
587 $oplogtemp .= "No." . ($rows_num+1) . "\t" . __(sprintf('Option name of No.%s option is non-input.', ($i+1)), 'usces').$yn;
588 $opmestemp .= "No." . ($rows_num+1) . "\t" . __(sprintf('Option name of No.%s option is non-input.', ($i+1)), 'usces').$br.$yn;
589 }
590 $val['name'] = $value;
591 break;
592 case 2:
593 if( $value != NULL && ((0 != (int)$value) and (1 != (int)$value) and (2 != (int)$value) and (5 != (int)$value)) ){
594 $oplogtemp .= "No." . ($rows_num+1) . "\t" . __(sprintf('Option-entry-field of No.%s option is abnormal.', ($i+1)), 'usces').$yn;
595 $opmestemp .= "No." . ($rows_num+1) . "\t" . __(sprintf('Option-entry-field of No.%s option is abnormal.', ($i+1)), 'usces').$br.$yn;
596 }
597 $val['mean'] = $value;
598 break;
599 case 3:
600 if( $value != NULL && (!preg_match("/^[0-9]+$/", $value) || 1 < (int)$value) ){
601 $oplogtemp .= "No." . ($rows_num+1) . "\t" . __(sprintf('Option-required-item of No.%s option is abnormal.', ($i+1)), 'usces').$yn;
602 $opmestemp .= "No." . ($rows_num+1) . "\t" . __(sprintf('Option-required-item of No.%s option is abnormal.', ($i+1)), 'usces').$br.$yn;
603 }
604 $val['essential'] = $value;
605 break;
606 case 4:
607 if( ($value != NULL && $value == '') && (2 > $datas[($key-2)] && 0 < strlen($datas[($key-2)])) ){
608 $oplogtemp .= "No." . ($rows_num+1) . "\t" . __(sprintf('Option-select of No.%s option is non-input.', ($i+1)), 'usces').$yn;
609 $opmestemp .= "No." . ($rows_num+1) . "\t" . __(sprintf('Option-select of No.%s option is non-input.', ($i+1)), 'usces').$br.$yn;
610 }
611 $val['value'] = $value;
612 break;
613 }
614 }
615 if( !WCUtils::is_blank($val['name']) || !WCUtils::is_blank($val['mean']) || !WCUtils::is_blank($val['essential']) || !WCUtils::is_blank($val['value']) ){
616 $logtemp .= $oplogtemp;
617 $mestemp .= $opmestemp;
618 }
619 }
620 if( 0 < strlen($logtemp) ){
621 $err_num++;
622 $log .= $logtemp;
623 echo $mestemp;
624 continue;
625 }
626
627
628
629 /******************/
630 $checkend = microtime(true);
631 $checktime += $checkend-$lineready;
632 /*////////////////////////////////////////*/
633 // insPost
634 /*////////////////////////////////////////*/
635 //wp_posts data reg;
636 $cdatas = array();
637 $post_fields = array();
638 $sku = array();
639 $opt = array();
640 $valstr = '';
641
642
643 if( $pre_code != $datas[USCES_COL_ITEM_CODE] ){
644 $sku_index = 0;
645
646 $cdatas['ID'] = $post_id;
647
648 $data = $datas[USCES_COL_POST_MODIFIED];
649 if( $data == '' || $data == '0000-00-00 00:00:00' ){
650 $cdatas['post_date'] = current_time( 'mysql' );
651 $cdatas['post_date_gmt'] = current_time( 'mysql', 1 );
652 $cdatas['post_modified'] = current_time( 'mysql' );
653 $cdatas['post_modified_gmt'] = current_time( 'mysql', 1 );
654 }else{
655 if(preg_match("/^[0-9]+$/", substr($data,0,4))) {//�
656 �頭4桁が数値のみ
657 $time_data =strtotime($data);
658 } else {
659 $datetime = explode(' ', $data);
660 $date_str = usces_dates_interconv( $datetime[0] ).' '.$datetime[1];
661 $time_data =strtotime($date_str);
662 }
663 $cdatas['post_date'] = date('Y-m-d H:i:s', $time_data);
664 $cdatas['post_date_gmt'] = gmdate('Y-m-d H:i:s', $time_data);
665 $cdatas['post_modified'] = date('Y-m-d H:i:s', $time_data);
666 $cdatas['post_modified_gmt'] = gmdate('Y-m-d H:i:s', $time_data);
667 }
668 //usces_log('mysql2date : '.mysql2date('U', $cdatas['post_modified'], false) . '/' . mysql2date('U', current_time( 'mysql' ), false), 'acting_transaction.log');
669 if ( 'publish' == $datas[USCES_COL_POST_STATUS] ) {
670 $now = current_time( 'mysql' );
671 if ( mysql2date('U', $cdatas['post_modified'], false) > mysql2date('U', $now, false) )
672 $datas[USCES_COL_POST_STATUS] = 'future';
673 } elseif( 'future' == $datas[USCES_COL_POST_STATUS] ) {
674 $now = current_time( 'mysql' );
675 if ( mysql2date('U', $cdatas['post_modified'], false) <= mysql2date('U', $now, false) )
676 $datas[USCES_COL_POST_STATUS] = 'publish';
677 }
678
679 $cdatas['ID'] = $post_id;
680 $cdatas['post_author'] = ( !WCUtils::is_blank($datas[USCES_COL_POST_AUTHOR]) ) ? $datas[USCES_COL_POST_AUTHOR] : 1;
681 $cdatas['post_content'] = trim(mb_convert_encoding($datas[USCES_COL_POST_CONTENT], 'UTF-8', 'SJIS'));
682 $cdatas['post_title'] = trim(mb_convert_encoding($datas[USCES_COL_POST_TITLE], 'UTF-8', 'SJIS'));
683 $cdatas['post_excerpt'] = trim(mb_convert_encoding($datas[USCES_COL_POST_EXCERPT], 'UTF-8', 'SJIS'));
684 $cdatas['post_status'] = $datas[USCES_COL_POST_STATUS];
685 $cdatas['comment_status'] = ( !WCUtils::is_blank($datas[USCES_COL_POST_COMMENT_STATUS]) ) ? $datas[USCES_COL_POST_COMMENT_STATUS] : 'close';
686 $cdatas['ping_status'] = 'close';
687 $cdatas['post_password'] = ( 'private' == $cdatas['post_status'] ) ? '' : $datas[USCES_COL_POST_PASSWORD];
688 $cdatas['post_type'] = 'post';
689 $cdatas['post_parent'] = 0;
690 $cdatas['post_name'] = urlencode(wp_unique_post_slug(trim(mb_convert_encoding($datas[USCES_COL_POST_NAME], 'UTF-8', 'SJIS')), $cdatas['ID'], $cdatas['post_status'], $cdatas['post_type'], $cdatas['post_parent']));
691 $cdatas['to_ping'] = '';
692 $cdatas['pinged'] = '';
693 $cdatas['menu_order'] = 0;
694 $cdatas['post_mime_type'] = 'item';
695 $cdatas['post_content_filtered'] = '';
696
697
698 if ( empty($cdatas['post_name']) && !in_array( $cdatas['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) {
699 $cdatas['post_name'] = sanitize_title($cdatas['post_title'], $post_id);
700 }
701
702 if($mode == 'add') {
703
704 $cdatas['guid'] = '';
705 if ( false === $wpdb->insert( $wpdb->posts, $cdatas ) ) {
706 $err_num++;
707 $mes = "No." . ($rows_num+1) . "\t".__('This data was not registered in the database.', 'usces');
708 $log .= $mes.$yn;
709 echo $mes.$br.$yn;
710 $pre_code = $datas[USCES_COL_ITEM_CODE];
711 continue;
712 }
713 $post_id = $wpdb->insert_id;
714 $where = array( 'ID' => $post_id );
715 $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post_id ) ), $where );
716
717 /******************/
718 $insert_post = microtime(true);
719 $insertposttime += $insert_post-$checkend;
720
721 }elseif($mode == 'upd') {
722
723 $where = array( 'ID' => $post_id );
724 if ( false === $wpdb->update( $wpdb->posts, $cdatas, $where ) ) {
725 $err_num++;
726 $mes = "No." . ($rows_num+1) . "\t".__('The data were not registered with a database.', 'usces');
727 $log .= $mes.$yn;
728 echo $mes.$br.$yn;
729 $pre_code = $datas[USCES_COL_ITEM_CODE];
730 continue;
731 }
732
733 /******************/
734 $insert_post = microtime(true);
735 $insertposttime += $insert_post-$checkend;
736 //end of wp_insert_post
737 /************************************************************************************************/
738 /*////////////////////////////////////////*/
739 // delMeta
740 /*////////////////////////////////////////*/
741
742 //delete all metas of Item
743 //$query = $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE ( meta_key = '_iopt_' OR meta_key = '_isku_' OR ( SUBSTRING(meta_key,1,5) = '_item' AND SUBSTRING(meta_key,1,6) <> '_item_') ) AND post_id = %d", $post_id);
744 $query = $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_key <> '_thumbnail_id' AND post_id = %d", $post_id);
745 $dbres = $wpdb->query( $query );
746 if( $dbres === false ) {
747 $err_num++;
748 $mes = "No." . ($rows_num+1) . "\t".__('Error : delete postmeta', 'usces');
749 $log .= $mes.$yn;
750 echo $mes.$br.$yn;
751 $pre_code = $datas[USCES_COL_ITEM_CODE];
752 continue;
753 }
754 // delete Item revisions
755 $query = $wpdb->prepare("DELETE FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $post_id, 'revision');
756 $dbres = $wpdb->query( $query );
757 if( $dbres === false ) {
758 $err_num++;
759 $mes = "No." . ($rows_num+1) . "\t".__('Error : delete revisions', 'usces');
760 $log .= $mes.$yn;
761 echo $mes.$br.$yn;
762 $pre_code = $datas[USCES_COL_ITEM_CODE];
763 continue;
764 }
765 // delete relationships of category
766 $query = $wpdb->prepare("DELETE FROM $wpdb->term_relationships WHERE object_id = %d", $post_id);
767 $dbres = $wpdb->query( $query );
768 if( $dbres === false ) {
769 $err_num++;
770 $mes = "No." . ($rows_num+1) . "\t".__('Error : delete term_relationships(category)', 'usces');
771 $log .= $mes.$yn;
772 echo $mes.$br.$yn;
773 $pre_code = $datas[USCES_COL_ITEM_CODE];
774 continue;
775 }
776 // delete relationships of tag
777 $query = "SELECT term_taxonomy_id, COUNT(*) AS ct FROM $wpdb->term_relationships GROUP BY term_taxonomy_id";
778 $relation_data = $wpdb->get_results( $query, ARRAY_A );
779 foreach((array)$relation_data as $relation_rows) {
780 $term_taxonomy_ids['term_taxonomy_id'] = $relation_rows['term_taxonomy_id'];
781 $term_taxonomy_updatas['count'] = $relation_rows['ct'];
782 $dbres = $wpdb->update( $wpdb->term_taxonomy, $term_taxonomy_updatas, $term_taxonomy_ids );
783 if( $dbres === false ) {
784 $err_num++;
785 $mes = "No." . ($rows_num+1) . "\t".__('Error : delete term_relationships(tag)', 'usces');
786 $log .= $mes.$yn;
787 echo $mes.$br.$yn;
788 $pre_code = $datas[USCES_COL_ITEM_CODE];
789 continue;
790 }
791 }
792 }
793
794 /******************/
795 $metadelete = microtime(true);
796 $metadeletetime += $metadelete-$insert_post;
797 /*////////////////////////////////////////*/
798 // addMeta
799 /*////////////////////////////////////////*/
800 //add postmeta
801 $itemDeliveryMethod = explode(';', $datas[USCES_COL_ITEM_DELIVERYMETHOD]);
802 $valstr .= '(' . $post_id . ", '_itemCode','" . mysql_real_escape_string(trim(mb_convert_encoding($datas[USCES_COL_ITEM_CODE], 'UTF-8', 'SJIS'))) . "'),";
803 $valstr .= '(' . $post_id . ", '_itemName','" . mysql_real_escape_string(trim(mb_convert_encoding($datas[USCES_COL_ITEM_NAME], 'UTF-8', 'SJIS'))) . "'),";
804 $valstr .= '(' . $post_id . ", '_itemRestriction','" . $datas[USCES_COL_ITEM_RESTRICTION] . "'),";
805 $valstr .= '(' . $post_id . ", '_itemPointrate','" . $datas[USCES_COL_ITEM_POINTRATE] . "'),";
806 $valstr .= '(' . $post_id . ", '_itemGpNum1','" . $datas[USCES_COL_ITEM_GPNUM1] . "'),";
807 $valstr .= '(' . $post_id . ", '_itemGpDis1','" . $datas[USCES_COL_ITEM_GPDIS1] . "'),";
808 $valstr .= '(' . $post_id . ", '_itemGpNum2','" . $datas[USCES_COL_ITEM_GPNUM2] . "'),";
809 $valstr .= '(' . $post_id . ", '_itemGpDis2','" . $datas[USCES_COL_ITEM_GPDIS2] . "'),";
810 $valstr .= '(' . $post_id . ", '_itemGpNum3','" . $datas[USCES_COL_ITEM_GPNUM3] . "'),";
811 $valstr .= '(' . $post_id . ", '_itemGpDis3','" . $datas[USCES_COL_ITEM_GPDIS3] . "'),";
812 $valstr .= '(' . $post_id . ", '_itemShipping','" . $datas[USCES_COL_ITEM_SHIPPING] . "'),";
813 $valstr .= '(' . $post_id . ", '_itemDeliveryMethod','" . mysql_real_escape_string(serialize($itemDeliveryMethod)) . "'),";
814 $valstr .= '(' . $post_id . ", '_itemShippingCharge','" . $datas[USCES_COL_ITEM_SHIPPINGCHARGE] . "'),";
815 $valstr .= '(' . $post_id . ", '_itemIndividualSCharge','" . $datas[USCES_COL_ITEM_INDIVIDUALSCHARGE] . "'),";
816
817 //$valstr .= '(' . $post_id . ", '".mysql_real_escape_string($meta_key)."', '" . mysql_real_escape_string(serialize($sku)) . "'),";
818
819 // print_r($valstr);
820 $valstr = rtrim($valstr, ',');
821 $dbres = $wpdb->query("INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES $valstr");
822 // $dbres = mysql_query($query) or die(mysql_error());
823
824 /*////////////////////////////////////////*/
825 // Set Taxonomy
826 /*////////////////////////////////////////*/
827 // $post_categories = explode(';', $datas[USCES_COL_CATEGORY]);
828 // if ( is_object_in_taxonomy($cdatas['post_type'], 'category') )
829 // wp_set_post_categories( $post_id, $post_category );
830 //
831 // $tags_input = explode(';', trim(mb_convert_encoding($datas[USCES_COL_POST_TAG], 'UTF-8', 'SJIS')));
832 // if ( isset( $tags_input ) && is_object_in_taxonomy($cdatas['post_type'], 'post_tag') )
833 // wp_set_post_tags( $post_id, $tags_input );
834 //
835 // // new-style support for all custom taxonomies
836 // if ( !empty($datas[USCES_COL_POST_TAX]) ) {
837 // foreach ( $datas[USCES_COL_POST_TAX] as $taxonomy => $tags ) {
838 // $taxonomy_obj = get_taxonomy($taxonomy);
839 // if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
840 // $tags = array_filter($tags);
841 // if ( current_user_can($taxonomy_obj->cap->assign_terms) )
842 // wp_set_post_terms( $post_id, $tags, $taxonomy );
843 // }
844 // }
845
846
847
848
849
850 //add term_relationships, edit term_taxonomy
851 //category
852 $categories = explode(';', $datas[USCES_COL_CATEGORY]);
853 foreach((array)$categories as $category){
854 $query = $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy
855 WHERE term_id = %d", $category);
856 $term_taxonomy_id = $wpdb->get_var( $query );
857 if($term_taxonomy_id == NULL) continue;
858
859 $query = $wpdb->prepare("INSERT INTO $wpdb->term_relationships
860 (object_id, term_taxonomy_id, term_order) VALUES
861 (%d, %d, 0)",
862 $post_id, $term_taxonomy_id
863 );
864 $dbres = $wpdb->query($query);
865 if( !$dbres ) continue;
866
867 $query = $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships
868 WHERE term_taxonomy_id = %d", $term_taxonomy_id);
869 $tct = $wpdb->get_var( $query );
870
871 $query = $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d
872 WHERE term_taxonomy_id = %d",
873 $tct, $term_taxonomy_id
874 );
875 $dbres = $wpdb->query($query);
876 }
877 //tag
878 $tags = explode(';', trim(mb_convert_encoding($datas[USCES_COL_POST_TAG], 'UTF-8', 'SJIS')));
879 // wp_set_object_terms($post_id, (array)$tags, 'post_tag');
880 foreach((array)$tags as $tag){
881 $tag = trim($tag, " \n\t\r\0\x0B,");
882 if( empty($tag) )
883 continue;
884 $query = $wpdb->prepare("SELECT term_id FROM $wpdb->terms WHERE name = %s", $tag);
885 $term_id = $wpdb->get_var( $query );
886 //new tag
887 if( empty($term_id) ){
888 $query = $wpdb->prepare("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES
889 (%s, %s, 0)", $tag, urlencode($tag));
890 $dbres = $wpdb->query( $query );
891 if( !$dbres )
892 continue;
893 $term_id = $wpdb->insert_id;
894 }
895 $query = $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy
896 WHERE term_id = %d", $term_id);
897 $term_taxonomy_id = $wpdb->get_var( $query );
898 if( !$term_taxonomy_id ){
899 $query = $wpdb->prepare("INSERT INTO $wpdb->term_taxonomy
900 (term_id, taxonomy, description, parent, count) VALUES
901 (%d, %s, %s, 0, 0)", $term_id, 'post_tag', '');
902 $dbres = $wpdb->query( $query );
903 if( !$dbres )
904 continue;
905 $term_taxonomy_id = $wpdb->insert_id;
906 }
907 $query = $wpdb->prepare("INSERT INTO $wpdb->term_relationships
908 (object_id, term_taxonomy_id, term_order) VALUES
909 (%d, %d, 0)",
910 $post_id, $term_taxonomy_id
911 );
912 $dbres = $wpdb->query($query);
913 if( !$dbres ) continue;
914
915 $query = $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships
916 WHERE term_taxonomy_id = %d", $term_taxonomy_id);
917 $tct = $wpdb->get_var( $query );
918
919 $query = $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d
920 WHERE term_taxonomy_id = %d",
921 $tct, $term_taxonomy_id
922 );
923 $dbres = $wpdb->query($query);
924 }
925
926
927
928
929
930 /*////////////////////////////////////////*/
931 // Add Custom Field
932 /*////////////////////////////////////////*/
933 $cfrows = explode(';', trim(mb_convert_encoding($datas[USCES_COL_CUSTOM_FIELD], 'UTF-8', 'SJIS')));
934 if( !(1 === count($cfrows) && '' == reset($cfrows)) ){
935 $valstr = '';
936 foreach( $cfrows as $row ){
937 list($meta_key, $meta_value) = explode( '=', $row, 2 );
938 if( !WCUtils::is_blank($meta_key) )
939 $valstr .= $wpdb->prepare("( %d, %s, %s),", $post_id, trim($meta_key), trim($meta_value));
940 }
941 if( !WCUtils::is_blank($valstr) ){
942 $valstr = rtrim($valstr, ',');
943 $dbres = $wpdb->query("INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES $valstr");
944 }
945 }
946
947 /******************/
948 $add_postmeta = microtime(true);
949 $addmetatime += $add_postmeta-$metadelete;
950 /*////////////////////////////////////////*/
951 // addOption
952 /*////////////////////////////////////////*/
953 // Add Item Option
954 for($i=0; $i<$opnum; $i++){
955 $opflg = true;
956 $optvalue = array();
957 for($o=1; $o<=4; $o++){
958 $key = ($min_field_num-1)+$o+($i*4);
959 // if( !isset($datas[$key]) ){
960 // break 2;
961 // }
962 if( $o === 1 && $datas[$key] == '' ){
963 $opflg = false;
964 break 1;
965 }
966 switch($o){
967 case 1:
968 $optvalue['name'] = trim(mb_convert_encoding($datas[$key], 'UTF-8', 'SJIS'));
969 break;
970 case 2:
971 $optvalue['means'] = (int)$datas[$key];
972 break;
973 case 3:
974 $optvalue['essential'] = (int)$datas[$key];
975 break;
976 case 4:
977 if( !empty($datas[$key]) ) {
978 $optvalue['value'] = str_replace(';', "\n", trim(mb_convert_encoding($datas[$key], 'UTF-8', 'SJIS')));
979 }else{
980 $optvalue['value'] = "";
981 }
982 break;
983 }
984 }
985
986 if( $opflg && !empty($optvalue) ){
987 $optvalue['sort'] = $i;
988 $resopt = usces_add_opt($post_id, $optvalue, false);
989 }
990 //$valstr .= '(' . $post_id . ", '".mysql_real_escape_string($ometa_key)."', '" . mysql_real_escape_string(maybe_serialize($opt)) . "'),";
991 }
992
993 }else{
994 $sku_index++;
995 }
996
997 /******************/
998 $optionmeta = microtime(true);
999 $AddOptiontime += $optionmeta-$add_postmeta;
1000 /*////////////////////////////////////////*/
1001 // addSku
1002 /*////////////////////////////////////////*/
1003 // Add Item SKU
1004 $sku_code = trim(mb_convert_encoding($datas[USCES_COL_SKU_CODE], 'UTF-8', 'SJIS'));
1005 $skuvalue['code'] = $sku_code;
1006 $skuvalue['name'] = trim(mb_convert_encoding($datas[USCES_COL_SKU_NAME], 'UTF-8', 'SJIS'));
1007 $skuvalue['cprice'] = $datas[USCES_COL_SKU_CPRICE];
1008 $skuvalue['price'] = $datas[USCES_COL_SKU_PRICE];
1009 $skuvalue['unit'] = trim(mb_convert_encoding($datas[USCES_COL_SKU_UNIT], 'UTF-8', 'SJIS'));
1010 $skuvalue['stocknum'] = $datas[USCES_COL_SKU_ZAIKONUM];
1011 $skuvalue['stock'] = $datas[USCES_COL_SKU_ZAIKO];
1012 $skuvalue['gp'] = $datas[USCES_COL_SKU_GPTEKIYO];
1013 $skuvalue['sort'] = $sku_index;
1014 usces_add_sku( $post_id, $skuvalue, false );
1015
1016 // usces_log('skuvalue : '.$post_id.print_r($skuvalue,true), 'acting_transaction.log');
1017 $comp_num++;
1018 $pre_code = $datas[USCES_COL_ITEM_CODE];
1019 clean_post_cache($post_id);
1020 wp_cache_delete($post_id, 'posts');
1021 wp_cache_delete($post_id, 'post_meta');
1022 clean_object_term_cache($post_id, 'post');
1023 /******************/
1024 $addsku = microtime(true);
1025 $AddSKUtime += $addsku-$optionmeta;
1026 $onelinetime += $addsku-$linestart;
1027
1028 if( 0 === (($rows_num+1) % 10) ){
1029 $av = $onelinetime/$rows_num;
1030 $nt = round($av*($total_num-$rows_num));
1031 if( 60 < $nt ){
1032 $mtime = ceil($nt/60) . __('min', 'usces') . ($nt%60) . __('sec', 'usces') . ' ';
1033 }else{
1034 $mtime = $nt . __('sec', 'usces') . ' ';
1035 }
1036 echo '<script type="text/javascript">changeMsg("' . __('Processing...', 'usces') . __('Remaining time:', 'usces').$mtime.'");</script>'.$yn;
1037 echo '<script type="text/javascript">setProgress(', ($rows_num+1) . ',' . $total_num, ');</script>'.$yn;
1038 ob_flush();
1039 flush();
1040 }
1041 }
1042
1043 flock($fpi, LOCK_EX);
1044 fputs($fpi, mb_convert_encoding($log, 'SJIS', 'UTF-8'));
1045 flock($fpi, LOCK_UN);
1046 fclose($fpi);
1047
1048 $res['status'] = 'success';
1049 $res['message'] = __(sprintf('%2$s of %1$s lines registration completion, error on %3$s lines.',$total_num,$comp_num,$err_num), 'usces');
1050 /******************/
1051 $finish = microtime(true);
1052 usces_log('ready : '.round($readytime-$start, 4), 'acting_transaction.log');
1053 usces_log('lineReady : '.round($linereadytime/$total_num, 4), 'acting_transaction.log');
1054 usces_log('dataCheck : '.round($checktime/$total_num, 4), 'acting_transaction.log');
1055 usces_log('insPost : '.round($insertposttime/$total_num, 4), 'acting_transaction.log');
1056 usces_log('delMeta : '.round($metadeletetime/$total_num, 4), 'acting_transaction.log');
1057 usces_log('addMeta : '.round($addmetatime/$total_num, 4), 'acting_transaction.log');
1058 usces_log('addOption : '.round($AddOptiontime/$total_num, 4), 'acting_transaction.log');
1059 usces_log('addSku : '.round($AddSKUtime/$total_num, 4), 'acting_transaction.log');
1060 usces_log('oneline : '.round($onelinetime/$total_num, 4), 'acting_transaction.log');
1061 usces_log('finish : '.round($finish-$start, 4), 'acting_transaction.log');
1062 usces_log('totalLines: '.$total_num, 'acting_transaction.log');
1063 usces_log('--------------------------------------------------------------', 'acting_transaction.log');
1064
1065 echo '<script type="text/javascript">changeMsg("', __(sprintf('Successful %1$s lines, Failed %2$s lines.',$comp_num,$err_num), 'usces'), ' ");setProgress(', ($rows_num+1) . ',' . $total_num, ');</script>'.$yn;
1066 if( $log ){
1067 //echo '<div class="error_log">' . $log . '</div>'.$yn;
1068 }else{
1069 echo __('Finished', 'usces').$yn;
1070 }
1071 echo '</div>'.$yn;
1072 unlink($path.$file_name);
1073 return $res;
1074 }
1075 endif;
1076
1077 // item list download
1078 if( !function_exists('usces_download_item_list') ):
1079 function usces_download_item_list() {
1080 require_once( USCES_PLUGIN_DIR . "/classes/itemList.class.php" );
1081 global $wpdb, $usces;
1082
1083 $ext = 'csv';
1084 if($ext == 'csv') {//CSV
1085 $table_h = "";
1086 $table_f = "";
1087 $tr_h = "";
1088 $tr_f = "";
1089 $th_h1 = '"';
1090 $th_h = ',"';
1091 $th_f = '"';
1092 $td_h1 = '"';
1093 $td_h = ',"';
1094 $td_f = '"';
1095 $sp = ";";
1096 $eq = "=";
1097 $lf = "\n";
1098 } else {
1099 exit();
1100 }
1101
1102 //==========================================================================
1103 $usces_opt_item = get_option('usces_opt_item');
1104 if(!is_array($usces_opt_item)){
1105 $usces_opt_item = array();
1106 }
1107 $usces_opt_item['chk_header'] = (isset($_REQUEST['chk_header'])) ? 1 : 0;
1108 $usces_opt_item['ftype_item'] = $ext;
1109 update_option('usces_opt_item', $usces_opt_item);
1110 //==========================================================================
1111
1112 $tableName = $wpdb->posts;
1113 if( USCES_MYSQL_VERSION >= 5 ) {
1114 $arr_column = array(
1115 __('item code', 'usces') => 'item_code',
1116 __('item name', 'usces') => 'item_name',
1117 __('SKU code', 'usces') => 'sku_key',
1118 __('selling price', 'usces') => 'price',
1119 __('stock', 'usces') => 'zaiko_num',
1120 __('stock status', 'usces') => 'zaiko',
1121 __('Categories', 'usces') => 'category',
1122 __('display status', 'usces') => 'display_status');
1123 } else {
1124 $arr_column = array(
1125 __('item code', 'usces') => 'item_code',
1126 __('page title', 'usces') => 'post_title',
1127 __('SKU code', 'usces') => 'sku_key',
1128 __('selling price', 'usces') => 'price',
1129 __('stock', 'usces') => 'zaiko_num',
1130 __('stock status', 'usces') => 'zaiko',
1131 __('Categories', 'usces') => 'category',
1132 __('display status', 'usces') => 'display_status');
1133 }
1134
1135 $_REQUEST['searchIn'] = "searchIn";
1136 $DT = new dataList($tableName, $arr_column);
1137 $DT->pageLimit = 'off';
1138 $DT->exportMode = true;
1139 $res = $DT->MakeTable();
1140 $rows = $DT->rows;
1141 //==========================================================================
1142 $line = $table_h;
1143 if($usces_opt_item['chk_header'] == 1) {
1144 $line .= $tr_h;
1145 $line .= $th_h1.'Post ID'.$th_f;
1146 $line .= $th_h.__('Post Author', 'usces').$th_f;
1147 $line .= $th_h.__('explanation', 'usces').$th_f;
1148 $line .= $th_h.__('Title', 'usces').$th_f;
1149 $line .= $th_h.__('excerpt', 'usces').$th_f;
1150 $line .= $th_h.__('display status', 'usces').$th_f;
1151 $line .= $th_h.__('Comment Status', 'usces').$th_f;
1152 $line .= $th_h.__('Post PAssword', 'usces').$th_f;
1153 $line .= $th_h.__('Post Name', 'usces').$th_f;
1154 $line .= $th_h.__('Publish on:').$th_f;
1155
1156 $line .= $th_h.__('item code', 'usces').$th_f;
1157 $line .= $th_h.__('item name', 'usces').$th_f;
1158 $line .= $th_h.__('Limited amount for purchase', 'usces').$th_f;
1159 $line .= $th_h.__('Percentage of points', 'usces').$th_f;
1160 $line .= $th_h.__('Business package discount', 'usces').'1-'.__('num', 'usces').$th_f.$th_h.__('Business package discount', 'usces').'1-'.__('rate', 'usces').$th_f;
1161 $line .= $th_h.__('Business package discount', 'usces').'2-'.__('num', 'usces').$th_f.$th_h.__('Business package discount', 'usces').'2-'.__('rate', 'usces').$th_f;
1162 $line .= $th_h.__('Business package discount', 'usces').'3-'.__('num', 'usces').$th_f.$th_h.__('Business package discount', 'usces').'3-'.__('rate', 'usces').$th_f;
1163 $line .= $th_h.__('estimated shipping date', 'usces').$th_f;
1164 $line .= $th_h.__('shipping option', 'usces').$th_f;
1165 $line .= $th_h.__('Shipping', 'usces').$th_f;
1166 $line .= $th_h.__('Postage individual charging', 'usces').$th_f;
1167
1168 $line .= $th_h.__('Categories', 'usces').$th_f;
1169 $line .= $th_h.__('tag', 'usces').$th_f;
1170 $line .= $th_h.__('Custom Field', 'usces').$th_f;
1171
1172 $line .= $th_h.__('SKU code', 'usces').$th_f;
1173 $line .= $th_h.__('SKU display name ', 'usces').$th_f;
1174 $line .= $th_h.__('normal price', 'usces').$th_f;
1175 $line .= $th_h.__('Sale price', 'usces').$th_f;
1176 $line .= $th_h.__('stock', 'usces').$th_f;
1177 $line .= $th_h.__('stock status', 'usces').$th_f;
1178 $line .= $th_h.__('unit', 'usces').$th_f;
1179 $line .= $th_h.__('Apply business package', 'usces').$th_f;
1180 $line .= $th_h.__('option name', 'usces').$th_f.$th_h.__('Field type', 'usces').$th_f.$th_h.__('Required', 'usces').$th_f.$th_h.__('selected amount', 'usces').$th_f;
1181 $line .= $tr_f.$lf;
1182 }
1183 //==========================================================================
1184 mb_http_output('pass');
1185 set_time_limit(3600);
1186 header("Content-Type: application/octet-stream");
1187 header("Content-Disposition: attachment; filename=usces_item_list.".$ext);
1188 ob_end_flush();
1189 flush();
1190
1191 foreach((array)$rows as $array) {
1192 $post_id = $array['ID'];
1193 $post = get_post($post_id);
1194
1195 //Post Data
1196 $line_item = $td_h1.$post->ID.$td_f;
1197 $line_item .= $td_h.$post->post_author.$td_f;
1198 $line_item .= $td_h.usces_entity_decode($post->post_content, $ext).$td_f;
1199 $line_item .= $td_h.usces_entity_decode($post->post_title, $ext).$td_f;
1200 $line_item .= $td_h.usces_entity_decode($post->post_excerpt, $ext).$td_f;
1201 $line_item .= $td_h.$post->post_status.$td_f;
1202 $line_item .= $td_h.$post->comment_status.$td_f;
1203 $line_item .= $td_h.$post->post_password.$td_f;
1204 $line_item .= $td_h.urldecode($post->post_name).$td_f;
1205 $line_item .= $td_h.$post->post_date.$td_f;
1206
1207 //Item Meta
1208 $line_item .= $td_h.$usces->getItemCode($post_id).$td_f;
1209 $line_item .= $td_h.usces_entity_decode($usces->getItemName($post_id), $ext).$td_f;
1210 $line_item .= $td_h.$usces->getItemRestriction($post_id).$td_f;
1211 $line_item .= $td_h.$usces->getItemPointrate($post_id).$td_f;
1212 $line_item .= $td_h.$usces->getItemGpNum1($post_id).$td_f.$td_h.$usces->getItemGpDis1($post_id).$td_f;
1213 $line_item .= $td_h.$usces->getItemGpNum2($post_id).$td_f.$td_h.$usces->getItemGpDis2($post_id).$td_f;
1214 $line_item .= $td_h.$usces->getItemGpNum3($post_id).$td_f.$td_h.$usces->getItemGpDis3($post_id).$td_f;
1215 $line_item .= $td_h.$usces->getItemShipping($post_id).$td_f;
1216 $delivery_method = '';
1217 $itemDeliveryMethod = $usces->getItemDeliveryMethod($post_id);
1218 foreach((array)$itemDeliveryMethod as $k => $v) {
1219 $delivery_method .= $v.$sp;
1220 }
1221 $delivery_method = rtrim($delivery_method, $sp);
1222 $line_item .= $td_h.$delivery_method.$td_f;
1223 $line_item .= $td_h.$usces->getItemShippingCharge($post_id).$td_f;
1224 $line_item .= $td_h.$usces->getItemIndividualSCharge($post_id).$td_f;
1225
1226 //Categories
1227 $category = '';
1228 $cat_ids = wp_get_post_categories($post_id);
1229 if(!empty($cat_ids)) {
1230 foreach($cat_ids as $id) {
1231 $category .= $id.$sp;
1232 }
1233 $category = rtrim($category, $sp);
1234 }
1235 $line_item .= $td_h.$category.$td_f;
1236
1237 //Tags
1238 $tag = '';
1239 $tags_ob = wp_get_object_terms($post_id, 'post_tag');
1240 foreach($tags_ob as $ob) {
1241 $tag .= $ob->name.$sp;
1242 }
1243 $tag = rtrim($tag, $sp);
1244 $line_item .= $td_h.$tag.$td_f;
1245
1246 //Custom Fields
1247 $cfield = '';
1248 $custom_fields = $usces->get_post_user_custom($post_id);
1249 if( is_array($custom_fields) && 0 < count($custom_fields) ){
1250 foreach($custom_fields as $cfkey => $cfvalues ) {
1251 if( is_array($cfvalues) )
1252 $cfield .= usces_entity_decode($cfkey, $ext) . $eq . usces_entity_decode($cfvalues[0], $ext) . $sp;
1253 else
1254 $cfield .= usces_entity_decode($cfkey, $ext) . $eq . usces_entity_decode($cfvalues, $ext) . $sp;
1255 }
1256 $cfield = rtrim($cfield, $sp);
1257 }
1258 $line_item .= $td_h.$cfield.$td_f;
1259
1260 //Item Options
1261 $line_options = '';
1262 $option_meta = usces_get_opts( $post_id, 'sort' );
1263 foreach($option_meta as $option_value) {
1264 $value = '';
1265 if(is_array($option_value['value'])) {
1266 foreach($option_value['value'] as $k => $v) {
1267 $values = explode("\n", $v);
1268 foreach($values as $val) {
1269 $value .= $val.$sp;
1270 }
1271 }
1272 $value = rtrim($value, $sp);
1273 } else {
1274 $value = trim($option_value['value']);
1275 $value = str_replace("\n", ';', $value);
1276 }
1277
1278 $line_options .= $td_h.usces_entity_decode($option_value['name'], $ext).$td_f;
1279 $line_options .= $td_h.$option_value['means'].$td_f;
1280 $line_options .= $td_h.$option_value['essential'].$td_f;
1281 $line_options .= $td_h.usces_entity_decode($value, $ext).$td_f;
1282
1283 }
1284
1285 //SKUs
1286 $sku_meta = $usces->get_skus( $post_id, 'sort' );
1287 foreach($sku_meta as $sku_value) {
1288
1289 $line_sku = $td_h.$sku_value['code'].$td_f;
1290 $line_sku .= $td_h.usces_entity_decode($sku_value['name'], $ext).$td_f;
1291 $line_sku .= $td_h.usces_crform($sku_value['cprice'], false, false, 'return', false).$td_f;
1292 $line_sku .= $td_h.usces_crform($sku_value['price'], false, false, 'return', false).$td_f;
1293 $line_sku .= $td_h.$sku_value['stocknum'].$td_f;
1294 $line_sku .= $td_h.$sku_value['stock'].$td_f;
1295 $line_sku .= $td_h.usces_entity_decode($sku_value['unit'], $ext).$td_f;
1296 $line_sku .= $td_h.$sku_value['gp'].$td_f;
1297
1298 $line .= $tr_h.$line_item.$line_sku.$line_options.$tr_f.$lf;
1299 }
1300 print(mb_convert_encoding($line, "SJIS-win", "UTF-8"));
1301 if(ob_get_contents ()){
1302 ob_flush();
1303 flush();
1304 }
1305 $line = '';
1306 wp_cache_flush();
1307 }
1308 $end = $table_f.$lf;
1309 //==========================================================================
1310 print(mb_convert_encoding($end, "SJIS-win", "UTF-8"));
1311 unset($rows, $DT, $line, $line_item, $line_options, $line_sku);
1312 exit();
1313 }
1314 endif;
1315
1316 }
1317 ?>