| 1 |
<?php |
| 2 |
/** |
| 3 |
* Item data upload screen |
| 4 |
* |
| 5 |
* @package Welcart |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
check_admin_referer( 'wel_item' ); |
| 12 |
|
| 13 |
?> |
| 14 |
<style type="text/css"> |
| 15 |
.label { |
| 16 |
font-size: small; |
| 17 |
font-weight: bold; |
| 18 |
margin: 10px 10px 0 10px; |
| 19 |
} |
| 20 |
#fileinfo { |
| 21 |
border: solid; |
| 22 |
border-color: lightgray; |
| 23 |
border-width: 1px; |
| 24 |
border-radius: 10px 10px 10px 10px; |
| 25 |
background-color: white; |
| 26 |
padding: 10px; |
| 27 |
margin-bottom: 20px; |
| 28 |
} |
| 29 |
.above_p_bar { |
| 30 |
font-size: large; |
| 31 |
font-weight: bold; |
| 32 |
margin: 10px; |
| 33 |
} |
| 34 |
#p_bar { |
| 35 |
width: 0; |
| 36 |
padding: 0; |
| 37 |
margin: 0; |
| 38 |
border-spacing: 0; |
| 39 |
background-color: #0099CC; |
| 40 |
} |
| 41 |
#i_p_bar { |
| 42 |
color: #FFFFFF; |
| 43 |
text-align: right; |
| 44 |
font-weight: bold; |
| 45 |
height: 40px; |
| 46 |
font-size: 16px; |
| 47 |
padding-right: 10px; |
| 48 |
} |
| 49 |
#out_bar { |
| 50 |
width: 100%; |
| 51 |
border: 1px solid #CC9900; |
| 52 |
border-spacing: 0; |
| 53 |
background-color: #FFFFE8; |
| 54 |
padding: 0; |
| 55 |
margin: 10px 0; |
| 56 |
} |
| 57 |
.under_p_bar { |
| 58 |
color: #565656; |
| 59 |
font-size: larger; |
| 60 |
font-weight: bold; |
| 61 |
margin: 10px 10px 20px 10px; |
| 62 |
} |
| 63 |
#reg_work { |
| 64 |
border: solid; |
| 65 |
border-color: lightgray; |
| 66 |
border-width: 1px; |
| 67 |
background-color: ghostwhite; |
| 68 |
padding: 10px; |
| 69 |
margin: 0 0 10px 0; |
| 70 |
} |
| 71 |
#download_file { |
| 72 |
font-weight: normal; |
| 73 |
color: cornflowerblue; |
| 74 |
text-decoration-line: underline; |
| 75 |
cursor: pointer; |
| 76 |
margin: 0; |
| 77 |
} |
| 78 |
</style> |
| 79 |
<div class="wrap"> |
| 80 |
<div class="usces_admin"> |
| 81 |
<h1>Welcart Shop <?php esc_html_e( 'Item list', 'usces' ); ?></h1> |
| 82 |
<p class="version_info">Version <?php echo esc_html( USCES_VERSION ); ?></p> |
| 83 |
<?php usces_admin_action_status(); ?> |
| 84 |
|
| 85 |
<div class="label"><?php esc_html_e( 'File Information', 'usces' ); ?></div> |
| 86 |
<div id="fileinfo" class="information"> |
| 87 |
<p><?php esc_html_e( 'Filename: ', 'usces' ); ?><span id="filename"></span></p> |
| 88 |
<p><?php esc_html_e( 'Type: ', 'usces' ); ?><span id="mode"></span></p> |
| 89 |
<p><?php esc_html_e( 'Number of data: ', 'usces' ); ?><span id="rowcount"></span></p> |
| 90 |
<p><?php esc_html_e( 'Line 1: ', 'usces' ); ?><span id="header"></span></p> |
| 91 |
</div> |
| 92 |
|
| 93 |
<div id="status" class="above_p_bar"><?php esc_html_e( 'Now preparing...', 'usces' ); ?></div> |
| 94 |
|
| 95 |
<table id="out_bar"> |
| 96 |
<tbody><tr><td> |
| 97 |
|
| 98 |
<table id="p_bar"> |
| 99 |
<tbody><tr><td id="i_p_bar"> </td></tr> |
| 100 |
</tbody></table> |
| 101 |
|
| 102 |
</td></tr> |
| 103 |
</tbody></table> |
| 104 |
<div id="msg" class="under_p_bar"><?php esc_html_e( 'Now preparing...', 'usces' ); ?></div> |
| 105 |
<div id="rest" class="under_p_bar"></div> |
| 106 |
|
| 107 |
|
| 108 |
<div class="label"><?php esc_html_e( 'Log', 'usces' ); ?><span id="download_file"></span></div> |
| 109 |
<div id="reg_work"></div> |
| 110 |
</div><!--usces_admin--> |
| 111 |
</div><!--wrap--> |
| 112 |
|
| 113 |
<?php |
| 114 |
$progress_ajax_nonce = wp_create_nonce( 'wel_progress_check_ajax' ); |
| 115 |
$progressfile = 'progress.txt'; |
| 116 |
$logfile_txt = 'log.txt'; |
| 117 |
$logfile = WP_CONTENT_URL . USCES_UPLOAD_TEMP . '/log.txt'; |
| 118 |
$_REQUEST['action'] = 'itemcsv'; |
| 119 |
|
| 120 |
$tempfilename = usces_item_uploadcsv(); |
| 121 |
$upload_mode = isset( $_REQUEST['upload_mode'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['upload_mode'] ) ) : ''; |
| 122 |
$check_mode = isset( $_REQUEST['checkcsv'] ) ? 1 : 0; |
| 123 |
?> |
| 124 |
<script type='text/javascript'> |
| 125 |
(function($) { |
| 126 |
var progressfile = '<?php echo esc_js( $progressfile ); ?>'; |
| 127 |
var progress_ajax_nonce = '<?php echo esc_js( $progress_ajax_nonce ); ?>'; |
| 128 |
var tempfilename = '<?php echo esc_js( $tempfilename ); ?>'; |
| 129 |
var logfile = '<?php echo esc_js( $logfile ); ?>'; |
| 130 |
var check_mode = '<?php echo esc_js( $check_mode ); ?>'; |
| 131 |
var upload_mode = '<?php echo esc_js( $upload_mode ); ?>'; |
| 132 |
|
| 133 |
checkPRG = { |
| 134 |
settings: { |
| 135 |
url: uscesL10n.requestFile, |
| 136 |
type: 'POST', |
| 137 |
dataType: 'json', |
| 138 |
cache: false |
| 139 |
}, |
| 140 |
|
| 141 |
refreshProgress : function() { |
| 142 |
|
| 143 |
var s = checkPRG.settings; |
| 144 |
|
| 145 |
s.data = { |
| 146 |
'action': 'wel_item_progress_check_ajax', |
| 147 |
'progressfile': progressfile, |
| 148 |
'nonce': progress_ajax_nonce, |
| 149 |
'noheader': 'true' |
| 150 |
}; |
| 151 |
|
| 152 |
$.ajax( s ).done(function( data ){ |
| 153 |
|
| 154 |
if ( data.status ) { |
| 155 |
$("#status").html(data.status); |
| 156 |
} |
| 157 |
if ( data.progress ) { |
| 158 |
$("#msg").html(data.progress); |
| 159 |
} |
| 160 |
if ( typeof( data.info ) != 'undefined' ) { |
| 161 |
$("#filename").html(data.info.filename); |
| 162 |
$("#mode").html(data.info.mode); |
| 163 |
$("#rowcount").html(data.info.rowcount); |
| 164 |
$("#header").html(data.info.header); |
| 165 |
} |
| 166 |
|
| 167 |
if ( typeof( data.all ) != 'undefined' && typeof( data.i ) != 'undefined' ) { |
| 168 |
$("#p_bar").css( 'width', ( ( data.i / data.all ) * 100 ) + '%' ); |
| 169 |
$("#i_p_bar").html( Math.round( 100 * ( data.i / data.all ) ) + "%" ); |
| 170 |
} |
| 171 |
|
| 172 |
if ( typeof( data.flag ) != 'undefined' && 'complete' == data.flag ) { |
| 173 |
checkPRG.completed(); |
| 174 |
} else { |
| 175 |
setTimeout( checkPRG.refreshProgress(), 1000 ); |
| 176 |
} |
| 177 |
|
| 178 |
//console.log(data); |
| 179 |
|
| 180 |
}).fail(function( msg ){ |
| 181 |
$("#status").html('Error'); |
| 182 |
$("#msg").html(''); |
| 183 |
|
| 184 |
console.log(msg); |
| 185 |
}); |
| 186 |
return; |
| 187 |
}, |
| 188 |
|
| 189 |
completed : function() { |
| 190 |
$.ajax({ |
| 191 |
url: uscesL10n.requestFile, |
| 192 |
type: 'POST', |
| 193 |
cache: false, |
| 194 |
data: { |
| 195 |
'action': 'wel_item_progress_completed_ajax', |
| 196 |
'logfile': '<?php echo esc_js( $logfile_txt ); ?>', |
| 197 |
'nonce': progress_ajax_nonce, |
| 198 |
'noheader': 'true' |
| 199 |
} |
| 200 |
}).done(function( logdata ) { |
| 201 |
$("#reg_work").html( '<div>' + logdata.replace(/\n/g, '<br>') + '</div>' ); |
| 202 |
}); |
| 203 |
$('#download_file').html('<?php esc_html_e( '( Download )', 'usces' ); ?>'); |
| 204 |
}, |
| 205 |
}; |
| 206 |
|
| 207 |
itemCSV = { |
| 208 |
settings: { |
| 209 |
url: uscesL10n.requestFile, |
| 210 |
type: 'POST', |
| 211 |
dataType: 'json', |
| 212 |
cache: false |
| 213 |
}, |
| 214 |
|
| 215 |
registration : function( work_number, comp_num, err_num ) { |
| 216 |
|
| 217 |
var s = itemCSV.settings; |
| 218 |
|
| 219 |
if ( 1 == check_mode ) { |
| 220 |
s.data = { |
| 221 |
'action' : 'wel_item_upload_ajax', |
| 222 |
'regfile' : tempfilename, |
| 223 |
'mode' : upload_mode, |
| 224 |
'work_number' : work_number, |
| 225 |
'comp_num' : comp_num, |
| 226 |
'err_num' : err_num, |
| 227 |
'checkcsv' : 1, |
| 228 |
'noheader' : 'true', |
| 229 |
'_wpnonce' : '<?php echo esc_js( wp_create_nonce() ); ?>' |
| 230 |
}; |
| 231 |
} else { |
| 232 |
s.data = { |
| 233 |
'action' : 'wel_item_upload_ajax', |
| 234 |
'regfile' : tempfilename, |
| 235 |
'mode' : upload_mode, |
| 236 |
'work_number' : work_number, |
| 237 |
'comp_num' : comp_num, |
| 238 |
'err_num' : err_num, |
| 239 |
'noheader' : 'true', |
| 240 |
'_wpnonce' : '<?php echo esc_js( wp_create_nonce() ); ?>' |
| 241 |
}; |
| 242 |
} |
| 243 |
|
| 244 |
<?php do_action( 'usces_action_itemcsv_upload_after_setting_data' ); ?> |
| 245 |
|
| 246 |
$.ajax( s ).done(function( data ){ |
| 247 |
if ( typeof( data.flag ) != 'undefined' && 'continue' == data.flag ) { |
| 248 |
if ( typeof( data.work_number ) != 'undefined' ) { |
| 249 |
console.log( 'work_number : ' + data.work_number ); |
| 250 |
itemCSV.registration( data.work_number, data.comp_num, data.err_num ); |
| 251 |
} |
| 252 |
} |
| 253 |
//console.log('Regist OK'); |
| 254 |
//console.log(data); |
| 255 |
}).fail(function( msg ){ |
| 256 |
console.log('Regist NG'); |
| 257 |
console.log(msg); |
| 258 |
}); |
| 259 |
return; |
| 260 |
}, |
| 261 |
}; |
| 262 |
setTimeout( checkPRG.refreshProgress(), 1000 ); |
| 263 |
|
| 264 |
if ( tempfilename ) { |
| 265 |
itemCSV.registration( 0, 0, 0 ); |
| 266 |
} |
| 267 |
|
| 268 |
$("#download_file").on('click', function () { |
| 269 |
$.get( logfile ).done(function (data) { |
| 270 |
var blob= new Blob([data]); |
| 271 |
var link= document.createElement('a'); |
| 272 |
link.href= window.URL.createObjectURL(blob); |
| 273 |
link.download= "log.txt"; |
| 274 |
link.click(); |
| 275 |
}); |
| 276 |
}); |
| 277 |
})(jQuery); |
| 278 |
</script> |
| 279 |
|