PluginProbe
Welcart e-Commerce / 2.12.4
Welcart e-Commerce v2.12.4
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 / admin_page.php

admin_page.php in Welcart e-Commerce 2.12.4, at functions/admin_page.php

641 lines 18.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Page Scripts.
4 *
5 * @package Welcart
6 */
7
8 /**
9 * Admin scripts.
10 * admin_footer-welcart-shop_page_usces_itemnew
11 * admin_footer-welcart-shop_page_usces_itemedit
12 * admin_footer-welcart-shop_page_usces_initial
13 * admin_footer-welcart-shop_page_usces_cart
14 */
15 function admin_prodauct_footer() {
16 $admin_page = ( isset( $_GET['page'] ) ) ? wp_unslash( $_GET['page'] ) : '';
17 switch ( $admin_page ) {
18 case 'usces_itemedit':
19 if ( ! isset( $_GET['action'] ) || ( isset( $_REQUEST['action'] ) && 'upload_register' == $_REQUEST['action'] ) ) {
20 break;
21 }
22 case 'usces_itemnew':
23 ?>
24 <script type="text/javascript">
25 (function($) {
26
27 itemEdit = {
28 settings: {
29 url: uscesL10n.requestFile,
30 type: 'POST',
31 dataType: 'json',
32 cache: false
33 },
34 checkItemCode : function( item_code ) {
35 var s = itemOpt.settings;
36 var post_id = $('#post_ID').val();
37 s.data = {
38 action : 'wel_item_code_exists_ajax',
39 item_code : item_code,
40 wc_nonce : '<?php echo wp_create_nonce( 'check_item_code' ); ?>',
41 noheader : true
42 }
43 $.ajax( s ).done(function( data ){
44 if ( false != data.result && post_id != data.result ) {
45 alert( data.message );
46 $('#itemCode').val('');
47 }
48 // console.log(data);
49 }).fail(function( msg ){
50 console.log(msg);
51 });
52 return;
53 }
54 }
55
56 $('#itemCode').change( function(e){
57
58 itemEdit.checkItemCode( $('#itemCode').val() );
59
60 });
61
62 $('#itemCode').focusin( function(e){
63
64 $('#save-post').attr('disabled', true);
65 $('#post-preview').attr('disabled', true);
66 $('#publish').attr('disabled', true);
67
68 }).focusout( function(e){
69
70 $('#save-post').attr('disabled', false);
71 $('#post-preview').attr('disabled', false);
72 $('#publish').attr('disabled', false);
73
74 });
75
76 var submit_event = true;
77 $('#post-preview, #save-post').click(function(){
78 if(!$("#auto_draft").val())
79 submit_event = false;
80 return true;
81 });
82 $('#post').submit(function(e){
83 $('form#post').attr('action', '');
84 var mes = '';
85 var itemCode = $("#itemCode").val();
86 var itemName = $("#itemName").val();
87 var itemsku = $("input[name^='itemsku\[']");
88 var DeliveryMethod = $("input[name^='itemDeliveryMethod\[']");
89 var itemDivision = $("input[name='item_division']:checked").val();
90 if ( !itemDivision || 'shipped' == itemDivision ) {
91 if ( 0 == DeliveryMethod.length ) {
92 mes += "<?php esc_html_e( "You can not choose the delivery method. Please complete the registration of shipping method than 'delivery setting' before product registration.", 'usces' ); ?><br />";
93 }
94 if ( ! $("input[name^='itemDeliveryMethod\[']:checked").length ) {
95 mes += '<?php esc_html_e( 'Delivery method has not been entered.', 'usces' ); ?><br />';
96 var eleLabelDeliveryMethod = $("label[for^='itemDeliveryMethod\[']");
97 eleLabelDeliveryMethod.css({'background-color': '#FFA'}).click(function(){
98 eleLabelDeliveryMethod.css({'background-color': '#FFF'});
99 });
100 }
101 }
102 if ( "" == itemCode ) {
103 mes += '<?php esc_html_e( 'Product code has not been entered.', 'usces' ); ?><br />';
104 $("#itemCode").css({'background-color': '#FFA'}).click(function(){
105 $(this).css({'background-color': '#FFF'});
106 });
107 }
108
109 if ( "" == itemName ) {
110 mes += '<?php esc_html_e( 'Brand name has not been entered.', 'usces' ); ?><br />';
111 $("#itemName").css({'background-color': '#FFA'}).click(function(){
112 $(this).css({'background-color': '#FFF'});
113 });
114 }
115 <?php if ( defined( 'WCEX_SKU_SELECT' ) ) : ?>
116 if ( 0 == itemsku.length && ! $("#select_sku_switch").prop('checked') ) {
117 <?php else : ?>
118 if ( 0 == itemsku.length ) {
119 <?php endif; ?>
120 mes += '<?php esc_html_e( 'SKU is not registered.', 'usces' ); ?><br />';
121 $("#newskuname").css({'background-color': '#FFA'}).click(function(){
122 $(this).css({'background-color': '#FFF'});
123 });
124 $("#newskuprice").css({'background-color': '#FFA'}).click(function(){
125 $(this).css({'background-color': '#FFF'});
126 });
127 }
128 if ( '' != mes ) {
129 $("#major-publishing-actions").append('<div id="usces_mess"></div>');
130 $('#ajax-loading').css({'visibility': 'hidden'});
131 $('#draft-ajax-loading').css({'visibility': 'hidden'});
132 $('#publish').removeClass('button-primary-disabled');
133 $('#save-post').removeClass('button-disabled');
134 $("#usces_mess").html(mes);
135 return false;
136 } else {
137 $('#usces_mess').fadeOut();
138 return true;
139 }
140 });
141
142 $('#itemName').blur(
143 function() {
144 if ( $("#itemName").val().length == 0 ) return;
145 uscesItem.newdraft($('#itemName').val());
146 });
147
148 $( "#item-sku-list" ).sortable({
149 handle : 'th',
150 axis : 'y',
151 cursor : "move",
152 tolerance : "pointer",
153 forceHelperSize : true,
154 forcePlaceholderSize : true,
155 revert : 300,
156 opacity: 0.6,
157 cancel: ":input,button",
158 update : function(){
159 var data=[];
160 $("table, #item-sku-list").each(function(i,v){
161 data.push($(this).attr('id'));
162 });
163 if( 1 < data.length ){
164 itemSku.dosort(data);
165 }
166 }
167 });
168 $( "#item-opt-list" ).sortable({
169 handle : 'th',
170 axis : 'y',
171 cursor : "move",
172 tolerance : "pointer",
173 forceHelperSize : true,
174 forcePlaceholderSize : true,
175 revert : 300,
176 opacity: 0.6,
177 cancel: ":input,button",
178 update : function(){
179 var data=[];
180 $("table","#item-opt-list").each(function(i,v){
181 data.push($(this).attr('id'));
182 });
183 if( 1 < data.length ){
184 itemOpt.dosort(data.toString());
185 }
186 }
187 });
188 })(jQuery);
189 </script>
190 <?php
191 break;
192 case 'usces_initial':
193 ?>
194 <script type="text/javascript">
195 (function($) {
196 $('#option_form').submit(function(e) {
197 var error = 0;
198
199 if( "" == $("*[name='order_mail']").val() ) {
200 error++;
201 $("*[name='order_mail']").css({'background-color': '#FFA'}).click(function() {
202 $(this).css({'background-color': '#FFF'});
203 });
204 }
205 /*if( "" == $("*[name='inquiry_mail']").val() ) {
206 error++;
207 $("*[name='inquiry_mail']").css({'background-color': '#FFA'}).click(function() {
208 $(this).css({'background-color': '#FFF'});
209 });
210 }*/
211 if( "" == $("*[name='sender_mail']").val() ) {
212 error++;
213 $("*[name='sender_mail']").css({'background-color': '#FFA'}).click(function() {
214 $(this).css({'background-color': '#FFF'});
215 });
216 }
217 if( "" == $("*[name='error_mail']").val() ) {
218 error++;
219 $("*[name='error_mail']").css({'background-color': '#FFA'}).click(function() {
220 $(this).css({'background-color': '#FFF'});
221 });
222 }
223 if( !checkNum( $("*[name='point_num']").val() ) ) {
224 error++;
225 $("*[name='point_num']").css({'background-color': '#FFA'}).click(function() {
226 $(this).css({'background-color': '#FFF'});
227 });
228 }
229 if( !checkNum( $("*[name='discount_num']").val() ) ) {
230 error++;
231 $("*[name='discount_num']").css({'background-color': '#FFA'}).click(function() {
232 $(this).css({'background-color': '#FFF'});
233 });
234 }
235 if( !checkNum( $("*[name='postage_privilege']").val() ) ) {
236 error++;
237 $("*[name='postage_privilege']").css({'background-color': '#FFA'}).click(function() {
238 $(this).css({'background-color': '#FFF'});
239 });
240 }
241 if( !checkNum( $("*[name='purchase_limit']").val() ) ) {
242 error++;
243 $("*[name='purchase_limit']").css({'background-color': '#FFA'}).click(function() {
244 $(this).css({'background-color': '#FFF'});
245 });
246 }
247 if( !checkNum( $("*[name='tax_rate']").val() ) ) {
248 error++;
249 $("*[name='tax_rate']").css({'background-color': '#FFA'}).click(function() {
250 $(this).css({'background-color': '#FFF'});
251 });
252 }
253 if( !checkNum( $("*[name='point_rate']").val() ) ) {
254 error++;
255 $("*[name='point_rate']").css({'background-color': '#FFA'}).click(function() {
256 $(this).css({'background-color': '#FFF'});
257 });
258 }
259 if( !checkNum( $("*[name='start_point']").val() ) ) {
260 error++;
261 $("*[name='start_point']").css({'background-color': '#FFA'}).click(function() {
262 $(this).css({'background-color': '#FFF'});
263 });
264 }
265
266 if( 0 < error ) {
267 $("#aniboxStatus").removeClass("none");
268 $("#aniboxStatus").addClass("error");
269 $("#info_image").attr("src", "<?php echo esc_url( USCES_PLUGIN_URL ); ?>/images/list_message_error.gif");
270 $("#info_massage").html("<?php _e( 'Data have deficiency.', 'usces' ); ?>");
271 $("#anibox").animate({ backgroundColor: "#FFE6E6" }, 2000);
272 return false;
273 } else {
274 return true;
275 }
276 });
277
278 $( "#item-opt-list" ).sortable({
279 handle : 'th',
280 axis : 'y',
281 cursor : "move",
282 tolerance : "pointer",
283 forceHelperSize : true,
284 forcePlaceholderSize : true,
285 revert : 300,
286 opacity: 0.6,
287 cancel: ":input,button",
288 update : function(){
289 var data=[];
290 $("table","#item-opt-list").each(function(i,v){
291 data.push($(this).attr('id'));
292 });
293 if( 1 < data.length ){
294 itemOpt.dosort(data.toString());
295 }
296 }
297 });
298
299 $( "#payment-list" ).sortable({
300 handle : 'th',
301 axis : 'y',
302 cursor : "move",
303 tolerance : "pointer",
304 forceHelperSize : true,
305 forcePlaceholderSize : true,
306 revert : 300,
307 opacity: 0.6,
308 cancel: ":input,button",
309 update : function(){
310 var data=[];
311 $("table","#payment-list").each(function(i,v){
312 data.push($(this).attr('id'));
313 });
314 if( 1 < data.length ){
315 payment.dosort(data.toString());
316 }
317 }
318 });
319
320 $( document ).on( "change", "input[name='applicable_taxrate']", function() {
321 if( 'reduced' == $( "input[name='applicable_taxrate']:checked" ).val() ) {
322 $( "#tax_rate_reduced" ).css( "display", "" );
323 $( "#point_coverage0" ).prop( "checked", true );
324 } else {
325 $( "#tax_rate_reduced" ).css( "display", "none" );
326 }
327 });
328 $( "input[name='applicable_taxrate']" ).trigger( "change" );
329
330 $( document ).on( "change", "input[name='point_coverage']", function() {
331 if( '1' == $( this ).val() ) {
332 if( 'reduced' == $( "input[name='applicable_taxrate']:checked" ).val() ) {
333 $( "input[value='0']" ).prop( "checked", true );
334 }
335 }
336 });
337
338 })(jQuery);
339 </script>
340 <?php
341 break;
342 case 'usces_cart':
343 ?>
344 <script type="text/javascript">
345 (function($) {
346 $('#option_form').submit(function(e) {
347 var error = 0;
348
349 if( !$("#indi_item_name").prop("checked") &&
350 !$("#indi_item_code").prop("checked") &&
351 !$("#indi_sku_name").prop("checked") &&
352 !$("#indi_sku_code").prop("checked") ) {
353 error++;
354 $("#indi_item_name").parent().css({'background-color': '#FFA'}).click(function() {
355 $("#indi_item_name").parent().css({'background-color': '#FFF'});
356 $("#indi_item_code").parent().css({'background-color': '#FFF'});
357 $("#indi_sku_name").parent().css({'background-color': '#FFF'});
358 $("#indi_sku_code").parent().css({'background-color': '#FFF'});
359 });
360 $("#indi_item_code").parent().css({'background-color': '#FFA'}).click(function() {
361 $("#indi_item_name").parent().css({'background-color': '#FFF'});
362 $("#indi_item_code").parent().css({'background-color': '#FFF'});
363 $("#indi_sku_name").parent().css({'background-color': '#FFF'});
364 $("#indi_sku_code").parent().css({'background-color': '#FFF'});
365 });
366 $("#indi_sku_name").parent().css({'background-color': '#FFA'}).click(function() {
367 $("#indi_item_name").parent().css({'background-color': '#FFF'});
368 $("#indi_item_code").parent().css({'background-color': '#FFF'});
369 $("#indi_sku_name").parent().css({'background-color': '#FFF'});
370 $("#indi_sku_code").parent().css({'background-color': '#FFF'});
371 });
372 $("#indi_sku_code").parent().css({'background-color': '#FFA'}).click(function() {
373 $("#indi_item_name").parent().css({'background-color': '#FFF'});
374 $("#indi_item_code").parent().css({'background-color': '#FFF'});
375 $("#indi_sku_name").parent().css({'background-color': '#FFF'});
376 $("#indi_sku_code").parent().css({'background-color': '#FFF'});
377 });
378 }
379 if( !checkNum( $("#pos_item_name").val() ) ) {
380 error++;
381 $("#pos_item_name").css({'background-color': '#FFA'}).click(function() {
382 $(this).css({'background-color': '#FFF'});
383 });
384 }
385 if( !checkNum( $("#pos_item_code").val() ) ) {
386 error++;
387 $("#pos_item_code").css({'background-color': '#FFA'}).click(function() {
388 $(this).css({'background-color': '#FFF'});
389 });
390 }
391 if( !checkNum( $("#pos_sku_name").val() ) ) {
392 error++;
393 $("#pos_sku_name").css({'background-color': '#FFA'}).click(function() {
394 $(this).css({'background-color': '#FFF'});
395 });
396 }
397 if( !checkNum( $("#pos_sku_code").val() ) ) {
398 error++;
399 $("#pos_sku_code").css({'background-color': '#FFA'}).click(function() {
400 $(this).css({'background-color': '#FFF'});
401 });
402 }
403
404 if( 0 < error ) {
405 $("#aniboxStatus").removeClass("none");
406 $("#aniboxStatus").addClass("error");
407 $("#info_image").attr("src", "<?php echo esc_url( USCES_PLUGIN_URL ); ?>/images/list_message_error.gif");
408 $("#info_massage").html("<?php esc_html_e( 'Data have deficiency.', 'usces' ); ?>");
409 $("#anibox").animate({ backgroundColor: "#FFE6E6" }, 2000);
410 if( $.fn.jquery < "1.10" ) {
411 $('#uscestabs_cart').tabs("select", 0);
412 } else {
413 $('#uscestabs_cart').tabs("option", "active", 0);
414 }
415 return false;
416 } else {
417 return true;
418 }
419 });
420 })(jQuery);
421 </script>
422 <?php
423 break;
424 }
425 }
426
427 /**
428 * Admin scripts.
429 * admin_footer-post.php
430 * admin_footer-post-new.php
431 */
432 function admin_post_footer() {
433 switch ( $GLOBALS['hook_suffix'] ) {
434 case 'post.php':
435 case 'post-new.php':
436 $categories = get_categories( array( 'child_of' => USCES_ITEM_CAT_PARENT_ID ) );
437 ?>
438 <script type="text/javascript">
439 (function($) {
440 $("#category-<?php echo esc_attr( USCES_ITEM_CAT_PARENT_ID ); ?>").remove();
441 $("#popular-category-<?php echo esc_attr( USCES_ITEM_CAT_PARENT_ID ); ?>").remove();
442 <?php foreach ( $categories as $category ) : ?>
443 $("#popular-category-<?php echo esc_attr( $category->term_id ); ?>").remove();
444 <?php endforeach; ?>
445 })(jQuery);
446 </script>
447 <?php
448 break;
449 }
450 }
451
452 /**
453 * Item data duplication.
454 *
455 * @param int $post_id Post ID.
456 * @return int Post ID after duplication.
457 */
458 function usces_item_duplicate( $post_id ) {
459 global $wpdb;
460
461 $nonce_action = 'duplicate_post_' . $post_id ;
462 if ( ! check_admin_referer( $nonce_action, '_wpnonce' ) ) {
463 wp_die( __( 'Sorry, you do not have the right to access this site.' ) );
464 }
465 if ( ! current_user_can( 'edit_post', $post_id ) ) {
466 wp_die( __( 'Sorry, you do not have the right to access this site.' ) );
467 }
468 if ( empty( $post_id ) ) {
469 wp_die( __( 'Data does not exist.', 'usces' ) );
470 }
471
472 $product = wel_get_product( $post_id );
473 if ( false === $product ) {
474 wp_die( __( 'Data does not exist.', 'usces' ) );
475 }
476 $post = $product['_pst'];
477
478 $datas = array();
479 foreach ( $post as $key => $value ) {
480 switch ( $key ) {
481 case 'ID':
482 break;
483 case 'post_date':
484 case 'post_modified':
485 break;
486 case 'post_date_gmt':
487 case 'post_modified_gmt':
488 break;
489 case 'post_status':
490 $datas[ $key ] = 'draft';
491 break;
492 case 'post_name':
493 case 'guid':
494 break;
495 case 'menu_order':
496 case 'post_parent':
497 case 'comment_count':
498 $datas[ $key ] = 0;
499 break;
500 default:
501 $datas[ $key ] = $value;
502 }
503 }
504
505 $datas['post_category'] = wp_get_post_categories( $post_id );
506 $data_tag = wp_get_object_terms( $post_id, 'post_tag', array( 'fields' => 'slugs' ) );
507 if ( $data_tag ) {
508 $datas['tags_input'] = $data_tag;
509 }
510
511 $newpost_id = wp_insert_post( $datas );
512
513 $item = wel_get_item( $post_id, false );
514 $item['itemCode'] .= '(copy)';
515 $item['itemName'] .= '(copy)';
516 wel_update_item_data( $item, $newpost_id );
517
518 $skus = wel_get_skus( $post_id, 'sort', false );
519 foreach ( $skus as $sku ) {
520 unset( $sku['meta_id'] );
521 wel_add_sku_data( $newpost_id, $sku );
522 }
523
524 $opts = wel_get_opts( $post_id, 'name', false );
525 foreach ( $opts as $opt ) {
526 unset( $opt['meta_id'] );
527 wel_add_opt_data( $newpost_id, $opt );
528 }
529
530 $query = $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post_id );
531 $meta_data = $wpdb->get_results( $query );
532
533 if ( $meta_data ) {
534
535 $valstr = '';
536 foreach ( $meta_data as $data ) {
537 $valstr .= $wpdb->prepare( "(%d, %s, %s),", $newpost_id, $data->meta_key, $data->meta_value ) . "\n";
538 }
539 $valstr = rtrim( $valstr, ",\n" );
540
541 $query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES $valstr";
542 $res = $wpdb->query( $query );
543 }
544
545 do_action( 'usces_action_item_dupricate', $post_id, $newpost_id );
546
547 return $newpost_id;
548 }
549
550 /**
551 * Item data duplication.
552 * alias usces_item_duplicate()
553 *
554 * @param int $post_id Post ID.
555 * @return int Post ID after duplication.
556 */
557 function usces_item_dupricate( $post_id ) {
558 return usces_item_duplicate( $post_id );
559 }
560
561 /**
562 * Bulk delete items.
563 *
564 * @param object $obj Item list object.
565 */
566 function usces_all_delete_itemdata( &$obj ) {
567
568 if ( ! current_user_can( 'edit_posts' ) ) {
569 wp_die( __( 'Sorry, you do not have the right to access this site.' ) );
570 }
571
572 $ids = filter_input( INPUT_POST, 'listcheck', FILTER_VALIDATE_INT, FILTER_REQUIRE_ARRAY );
573 if ( null === $ids ) {
574 return;
575 }
576 $status = true;
577 foreach ( (array) $ids as $post_id ) {
578 if ( ! wp_delete_post( $post_id, true ) ) {
579 $status = false;
580 } else {
581 wel_delete_all_sku_data( $post_id );
582 wel_delete_all_opt_data( $post_id );
583 wel_delete_item_data( $post_id );
584 }
585 }
586 if ( true === $status ) {
587 $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
588 } elseif ( false === $status ) {
589 $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
590 } else {
591 $obj->set_action_status( 'none', '' );
592 }
593 }
594
595 /**
596 * Typenow.
597 */
598 function usces_typenow() {
599 global $typenow;
600 if ( isset( $_GET['page'] ) && ( 'usces_itemedit' == $_GET['page'] || 'usces_itemnew' == $_GET['page'] ) ) {
601 $typenow = '';
602 }
603 }
604
605 /**
606 * Admin notices.
607 * unused
608 */
609 function usces_admin_notices() {
610
611 }
612
613 /**
614 * Field of Member admin page for release the card information update lock.
615 *
616 * @since 2.5.8
617 *
618 * @param array $data Member data.
619 * @param array $member_metas Member metadata.
620 * @param array $usces_member_history Member history.
621 */
622 function wel_release_card_update_lock_field( $data, $member_metas, $usces_member_history ) {
623
624 $lock_date = null;
625 foreach ( $member_metas as $meta ) {
626 if ( isset( $meta['meta_key'] ) && 'settlement_action_lock' === $meta['meta_key'] ) {
627 $lock_date = $meta['meta_value'];
628 break;
629 }
630 }
631
632 if ( null !== $lock_date ) {
633 ?>
634 <tr>
635 <td class="label"><input type="checkbox" name="release_card_update_lock" id="release_card_update_lock" value="release"></td>
636 <td><label for="release_card_update_lock"><?php echo esc_html( sprintf( __( 'Unlock the card information update (Lock date and time: %s)', 'usces' ), $lock_date ) ); ?></label></td>
637 </tr>
638 <?php
639 }
640 }
641