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