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