PluginProbe
WPCargo Track & Trace / trunk
WPCargo Track & Trace vtrunk
8.0.5 8.0.3 8.0.4 trunk 6.10.0 6.10.1 6.10.2 6.10.3 6.10.4 6.10.5 6.10.6 6.10.8 6.11.0 6.12.2 6.13.0 6.13.1 6.13.3 6.13.4 6.13.5 6.13.6 6.9.0 6.9.1 6.9.2 6.9.3 6.9.4 All 38 releases
wpcargo / admin / classes / class-wpc-export-extend.php

class-wpc-export-extend.php in WPCargo Track & Trace trunk, at admin/classes/class-wpc-export-extend.php

156 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) { exit; }
3 require_once( WPCARGO_PLUGIN_PATH.'admin/classes/class-wpc-export.php');
4 class WPC_Export_Admin extends WPC_Export{
5 protected $post_type = 'wpcargo_shipment';
6 protected $post_taxonomy = 'wpcargo_shipment_cat';
7 function __construct(){
8 add_action('admin_menu', array($this,'wpc_import_export_submenu_page') );
9 add_action( 'wp_ajax_update_import_option_ajax_request', array($this,'update_import_option_ajax_request') );
10 add_action( 'wp_ajax_search_shipper', array($this,'wpc_import_export_search_shipper') );
11 }
12 function wpc_import_export_submenu_page() {
13 //** Import Submenu
14 add_submenu_page(
15 'edit.php?post_type=wpcargo_shipment',
16 wpcargo_report_settings_label(),
17 wpcargo_report_settings_label(),
18 'manage_options',
19 'wpc-report-export',
20 array($this,'wpc_import_export_submenu_page_callback') );
21 //** Exmport Submenu
22 add_submenu_page(
23 'wpc-ie-import',
24 wpcargo_report_settings_label(),
25 wpcargo_report_settings_label(),
26 'manage_options',
27 'wpc-ie-import',
28 array($this,'wpc_import_export_submenu_page_callback') );
29 }
30 function wpc_import_export_submenu_page_callback() {
31 global $wpdb;
32 $table_name = $wpdb->prefix.'wpcargo_custom_fields';
33 $field_selection = $this->form_fields();
34 $page = sanitize_text_field( $_GET['page'] );
35 $tax_args = array(
36 'orderby' => 'name',
37 'order' => 'ASC',
38 'taxonomy' => $this->post_taxonomy,
39 'hide_empty' => 0
40 );
41 $cat_taxonomy = get_categories($tax_args);
42 ?>
43 <div class="wrap"><div id="icon-tools" class="icon32"></div>
44 <?php $this->wpc_ie_header_tab(); ?>
45 <div style="clear: both;"></div>
46 <div id="form-block">
47 <?php
48 if( $page == 'wpc-report-export' ){
49 $this->wpc_export_form( $field_selection, $cat_taxonomy, $page);
50 }
51 ?>
52 </div>
53 <div id="ads">
54 <a href="http://www.wpcargo.com/product/wpcargo-importexport-add-ons/" target="_blank" class="wpc-documentation">
55 <div class="wpc-img"> <img src="<?php echo esc_url(WPCARGO_PLUGIN_URL); ?>/admin/assets/images/documentation.png"> </div>
56 <div class="wpc-desc">
57 <h3><?php esc_html_e('Purchase', 'wpcargo'); ?> WPCargo Import Export Add-ons</h3>
58 <p><?php esc_html_e('If you want a more comprehensive and customizable report, purchase', 'wpcargo'); ?> WPCargo Import Export Add-ons.</p>
59 </div>
60 </a>
61 </div>
62 </div>
63 <?php
64 }
65 function update_import_option_ajax_request() {
66 // The $_REQUEST contains all the data sent via ajax
67 if ( isset($_POST) ) {
68 update_option('multiselect_settings', sanitize_text_field( $_POST['multiselect_settings'] ), true);
69 }
70 // Always die in functions echoing ajax content
71 die();
72 }
73 function wpc_export_form( $fields = array(), $taxonomy = array(), $page ='') {
74 add_action( 'wp_ajax_update_import_option_ajax_request', 'update_import_option_ajax_request' );
75 global $wpcargo;
76 $options = get_option( 'multiselect_settings' );
77 if( !empty( $options ) ){
78 if( array_key_exists( 0, $options ) ){
79 $options = array();
80 }
81 }
82 $user_args = array(
83 'meta_key' => 'first_name',
84 'orderby' => 'meta_value',
85 'role__in' => array( 'wpcargo_client' ),
86 );
87 $users = get_users( $user_args );
88 $registered_shipper = isset( $_POST['shipment_author'] ) ? (int)sanitize_text_field( $_POST['shipment_author'] ) : '';
89 include_once( wpcargo_include_template( 'report.tpl' ) );
90 ?>
91 <script type="text/javascript">
92 jQuery(document).ready(function($) {
93 $('#multi-select-export button.btn.btn-block').on('click', function(e){
94 e.preventDefault();
95 $("#multiselect_to, #multiselect").trigger('change');
96 });
97 $('#multiselect').multiselect({
98 sort: false,
99 autoSort: false,
100 autoSortAvailable: false,
101 });
102 $("#multiselect_to, #multiselect").on('change',function() {
103 setTimeout(function(){
104 var selectoptions= {};
105 $.each($("#multiselect option"), function( ) {
106 var metaKey = $(this).attr("value");
107 var metaValue = $(this).text();
108 selectoptions[metaKey] = metaValue;
109 });
110 $.each($("#multiselect_to option"), function( ) {
111 var metaKey = $(this).attr("value");
112 var metaValue = $(this).text();
113 selectoptions[metaKey] = metaValue;
114 });
115
116 jQuery.ajax({
117 url : 'admin-ajax.php',
118 type : 'post',
119 data : {
120 action : 'update_import_option_ajax_request',
121 multiselect_settings: selectoptions
122 },
123 success : function( response ) {
124 //alert(response)
125 }
126 });
127 }, 1000);
128 });
129 });
130 </script>
131 <?php
132 }
133 function wpc_import_export_search_shipper(){
134 global $wpdb, $post;
135 // Handle request then generate response using WP_Ajax_Response
136 $term = isset( $_GET['term'] ) ? sanitize_text_field( $_GET['term'] ) : '';
137 $metakey = apply_filters( 'wpc_report_search_shipper_name_metakey', 'wpcargo_shipper_name' );
138 $results = $wpdb->get_col( $wpdb->prepare( "SELECT tbl2.meta_value AS meta_value FROM `$wpdb->posts` AS tbl1 INNER JOIN `$wpdb->postmeta` AS tbl2 ON tbl1.ID = tbl2.post_id WHERE tbl1.post_type = 'wpcargo_shipment' AND tbl2.meta_key LIKE %s AND tbl2.meta_value LIKE %s GROUP BY meta_value", $metakey, '%'.$term.'%' ) );
139 wp_send_json( $results );
140 wp_die();
141 }
142 function wpc_ie_header_tab(){
143 $view = sanitize_text_field( $_GET['page'] );
144 ?>
145 <div class="wpc-ie-tab">
146 <h2 class="nav-tab-wrapper">
147 <a href="<?php echo esc_url(admin_url( 'edit.php?post_type=wpcargo_shipment&page=wpc-report-export' )); ?>" class="nav-tab<?php if($view == 'wpc-report-export') { ?> nav-tab-active<?php } ?>"><?php esc_html_e("Shipment Reports", 'wpcargo'); ?> </a>
148 </h2>
149 </div>
150 <?php
151 if( $view == 'wpc-report-export' ){
152 $this->wpc_export_request( );
153 }
154 }
155 }
156 $wpc_export_admin = new WPC_Export_Admin();