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-custom-table.php

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

256 lines 11.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) {
3 exit; // Exit if accessed directly
4 }
5 add_filter('manage_wpcargo_shipment_posts_columns' , 'set_default_wpcargo_columns');
6 function set_default_wpcargo_columns($columns) {
7 $get_the_wpcargo_tbl = array(
8 'cb' => '<input type="checkbox" />',
9 'title' => apply_filters( 'wpc_admin_tbl_list_tracking_number', __('Tracking Number', 'wpcargo') ),
10 'wpcargo_category' => apply_filters( 'wpc_admin_tbl_list_category', __('Category', 'wpcargo') ),
11 'registered_shipper' => apply_filters( 'wpc_admin_tbl_registered_shipper', __('Shipment Owner', 'wpcargo') ),
12 'agent_fields' => apply_filters( 'wpc_admin_tbl_list_agent', __('Agent', 'wpcargo') ),
13 wpcargo_shipper_meta_filter() => wpcargo_shipper_label_filter(),
14 wpcargo_receiver_meta_filter() => wpcargo_receiver_label_filter(),
15 'wpcargo_date' => apply_filters( 'wpc_admin_tbl_list_date', __('Date', 'wpcargo') ),
16 'wpcargo_status' => apply_filters( 'wpc_admin_tbl_list_status', __('Status', 'wpcargo') ),
17 'wpcargo_actions' => apply_filters( 'wpc_admin_tbl_list_action', __('Actions', 'wpcargo') ),
18 );
19 $get_the_wpcargo_tbl = apply_filters('default_wpcargo_columns', $get_the_wpcargo_tbl );
20 return $get_the_wpcargo_tbl;
21 }
22 add_action( 'manage_wpcargo_shipment_posts_custom_column', 'manage_default_wpcargo_columns', 10, 2 );
23 function manage_default_wpcargo_columns( $column, $post_id ) {
24 global $post, $wpcargo;
25 switch( $column ) {
26 case 'agent_fields' :
27 $agent_fields = get_post_meta( $post_id, 'agent_fields', true);
28 if( is_numeric( $agent_fields ) ){
29 $last_name = get_the_author_meta( 'last_name', $agent_fields );
30 $first_name = get_the_author_meta( 'first_name', $agent_fields );
31 if( !empty( $last_name ) && !empty( $first_name ) ){
32 echo esc_html( $first_name ).' '. esc_html($last_name);
33 }else{
34 echo esc_html( get_the_author_meta( 'display_name', $agent_fields ) );
35 }
36 }else{
37 echo esc_html( $agent_fields );
38 }
39 break;
40 case 'wpcargo_category' :
41 $post_term = wp_get_post_terms( $post_id, 'wpcargo_shipment_cat', array( 'fields' => 'names' ) );
42 echo esc_html( implode(',', $post_term ) );
43 break;
44 case 'registered_shipper' :
45 $registered_shipper = (int)get_post_meta( $post_id, 'registered_shipper', true);
46 echo ( $registered_shipper ) ? esc_html( $wpcargo->user_fullname( $registered_shipper ) ) : '';
47 break;
48 case wpcargo_shipper_meta_filter() :
49 $shipper_name = wpcargo_shipper_meta_filter();
50 $wpcargo_shipper_name = get_post_meta( $post_id, $shipper_name, true);
51 echo esc_html( $wpcargo_shipper_name );
52 break;
53 case wpcargo_receiver_meta_filter() :
54 $receiver_name = wpcargo_receiver_meta_filter();
55 $wpcargo_receiver_name = get_post_meta($post_id, $receiver_name, true);
56 echo esc_html( $wpcargo_receiver_name );
57 break;
58 case 'wpcargo_date':
59 $wpcargo_date_publish = get_the_date( $wpcargo->date_format, $post_id );
60 echo esc_html( $wpcargo_date_publish );
61 break;
62 case 'wpcargo_status' :
63 $wpcargo_status = get_post_meta( $post_id, 'wpcargo_status', true );
64 echo esc_html( $wpcargo_status );
65 break;
66 case 'wpcargo_shipment_cat' :
67 $terms = get_the_terms( $post_id, 'wpcargo_shipment_cat' );
68 if ( !empty( $terms ) ) {
69 $out = array();
70 foreach ( $terms as $term ) {
71 $out[] = sprintf( '<a href="%s">%s</a>',
72 esc_url( add_query_arg( array( 'post_type' => 'wpcargo_shipment', 'wpcargo_shipment_cat' => $term->slug ), 'edit.php' ) ),
73 esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'wpcargo_shipment', 'display' ) )
74 );
75 }
76 echo esc_html( join( ', ', $out ) );
77 }
78 else {
79 esc_html_e( 'No Category', 'wpcargo' );
80 }
81 break;
82 case 'wpcargo_actions' :
83 do_action( 'wpcargo_before_admin_action_column', get_the_ID() );
84 echo '<a href="edit.php?post_type=wpcargo_shipment&page=wpcargo-print-layout&id='.esc_html( get_the_ID() ).'" class="button button-secondary" style="margin-bottom: 8px;"><span class="dashicons dashicons-media-document" style="vertical-align: sub;"></span> '.esc_html__('Invoice', 'wpcargo') .'</a><br/>';
85 echo '<a href="edit.php?post_type=wpcargo_shipment&page=wpcargo-print-label&id='.esc_html( get_the_ID() ).'" class="button button-secondary"><span class="dashicons dashicons-tag" style="vertical-align: sub;"></span> '.esc_html__('Waybill', 'wpcargo') .'</a>';
86 do_action( 'wpcargo_after_admin_action_column', get_the_ID() );
87 break;
88 default :
89 break;
90 }
91 }
92 add_filter( 'manage_edit-wpcargo_shipment_sortable_columns', 'set_custom_wpcargo_sortable_columns' );
93 function set_custom_wpcargo_sortable_columns( $columns ) {
94 $columns['wpcargo_date'] = 'wpcargo_date';
95 $columns['agent_fields'] = 'agent_fields';
96 $columns['registered_shipper'] = 'registered_shipper';
97 $columns[wpcargo_shipper_meta_filter()] = wpcargo_shipper_meta_filter();
98 $columns[wpcargo_receiver_meta_filter()] = wpcargo_receiver_meta_filter();
99 return $columns;
100 }
101 add_action( 'pre_get_posts', 'wpcargo_custom_orderby' );
102 function wpcargo_custom_orderby( $query ) {
103 if ( ! is_admin() )
104 return;
105 if(isset($_GET['post_type']) && $_GET['post_type'] == 'wpcargo_shipment') {
106 $orderby = $query->get( 'orderby');
107 if(!isset($_GET['orderby'])){
108 $query->set( 'orderby', 'wpcargo_date' );
109 $query->set( 'order', 'DESC' );
110 }
111 if ( 'agent_fields' == $orderby ) {
112 $query->set( 'meta_key', 'agent_fields' );
113 $query->set( 'orderby', 'meta_value' );
114 }
115 if ( wpcargo_shipper_meta_filter() == $orderby ) {
116 $query->set( 'meta_key', wpcargo_shipper_meta_filter() );
117 $query->set( 'orderby', 'meta_value' );
118 }
119 if ( wpcargo_receiver_meta_filter() == $orderby ) {
120 $query->set( 'meta_key', wpcargo_receiver_meta_filter() );
121 $query->set( 'orderby', 'meta_value' );
122 }
123 }
124 }
125 /*
126 ** Bulk and Quick Edit function
127 */
128 add_action( 'quick_edit_custom_box', 'wpcargo_bulk_update_status', 10, 2 );
129 add_action( 'bulk_edit_custom_box', 'wpcargo_bulk_update_status', 10, 2 );
130 function wpcargo_bulk_update_status( $column_name, $screen_post_type ){
131 global $wpcargo;
132 $shmap_active = get_option('shmap_active');
133 if( $screen_post_type == 'wpcargo_shipment' ){
134 wp_nonce_field( 'wpcargo_bulk_update_action', 'wpcargo_bulk_update_nonce' );
135 if( $column_name == 'wpcargo_status' ){
136 ?>
137 <fieldset id="shipment-bulk-update" class="inline-edit-col-left" style="border: 1px solid #ddd; margin-top: 6px; padding:8px;">
138 <div class="inline-edit-col wpc-status-section">
139 <div class="inline-edit-group wp-clearfix">
140 <legend class="inline-edit-legend"><?php esc_html_e( 'Update Shipment Status', 'wpcargo' ) ?></legend>
141 <p><input style="width:100%;" class="bulkdate" type="date" name="status_date" placeholder="<?php echo esc_html($wpcargo->date_format); ?>" autocomplete="off" /></p>
142 <p><input style="width:100%;" class="bulktime" type="time" name="status_time" autocomplete="off" /></p>
143 <p><input style="width:100%;" class="status_location" type="text" name="status_location" placeholder="<?php esc_html_e( 'Current City', 'wpcargo' ); ?>" autocomplete="off" /></p>
144 <?php if( !empty( $wpcargo->status ) ): ?>
145 <select style="width:100%;" class="wpcargo_status" name="wpcargo_status" >
146 <option value=""><?php esc_html_e( '--Select Status--', 'wpcargo' ) ?></option>
147 <?php
148 foreach( $wpcargo->status as $value ){
149 ?><option value="<?php echo esc_html($value); ?>"><?php echo esc_html($value); ?></option><?php
150 }
151 ?>
152 </select>
153 <?php else: ?>
154 <p class="description"><?php esc_html_e( 'No Shipment Status Found.', 'wpcargo' ) ?> <a href="<?php echo esc_url(admin_url('admin.php?page=wpcargo-settings')); ?>"><?php esc_html_e( 'Add Shipment Status', 'wpcargo' ) ?></a></p>
155 <?php endif; ?>
156 <p> <textarea style="width:100%;" class="remarks" name="status_remarks" placeholder="<?php esc_html_e( 'Remarks', 'wpcargo' ); ?>" ></textarea>
157 </div>
158 </div>
159 </fieldset>
160 <fieldset class="inline-edit-col-right">
161 <div class="inline-edit-col">
162 <div class="inline-edit-group wp-clearfix">
163 <label class="inline-edit-status alignleft">
164 <span class="title"><?php esc_html_e( 'Select Agent', 'wpcargo' ); ?></span>
165 <select name="wpcargo_agent">
166 <option value=""><?php esc_html_e( '— No Change —', 'wpcargo' ); ?></option>
167 <?php
168 if( !empty( $wpcargo->agents ) ){
169 foreach ( $wpcargo->agents as $agentid => $agent_name ) {
170 ?><option value="<?php echo (int)esc_html($agentid); ?>"><?php echo esc_html($agent_name); ?></option><?php
171 }
172 }
173 ?>
174 </select>
175 </label>
176 </div>
177 </div>
178 </fieldset>
179 <?php
180 }
181 }
182 }
183 /*
184 ** Bulk and Quick Save function
185 */
186 add_action( 'save_post', 'wpcargo_shipment_bulk_save' );
187 function wpcargo_shipment_bulk_save( $post_id ) {
188 global $wpcargo;
189 if ( !current_user_can( 'edit_post', $post_id ) ) {
190 return;
191 }
192 if( !isset( $_REQUEST["wpcargo_bulk_update_nonce"] ) ){
193 return;
194 }
195 if ( !wp_verify_nonce( $_REQUEST["wpcargo_bulk_update_nonce"], 'wpcargo_bulk_update_action' ) ){
196 return;
197 }
198 $current_user = wp_get_current_user();
199 if ( isset( $_REQUEST['wpcargo_status'] ) && $_REQUEST['wpcargo_status'] != '' ) {
200 $wpcargo_status = trim( sanitize_text_field( $_REQUEST['wpcargo_status'] ) );
201 $status_location = trim( sanitize_text_field( $_REQUEST['status_location'] ) );
202 $status_time = trim( sanitize_text_field( $_REQUEST['status_time'] ) );
203 $status_remarks = trim( sanitize_text_field( $_REQUEST['status_remarks'] ) );
204 $status_date = trim( sanitize_text_field( $_REQUEST['status_date'] ) );
205 $apply_to_shipment = ( isset($_REQUEST['apply_status']) ) ? true : false ;
206 $wpcargo_shipments_update = maybe_unserialize( get_post_meta( $post_id, 'wpcargo_shipments_update', true ) );
207 // Get Shipment OLD status before the update
208 $old_status = get_post_meta( $post_id, 'wpcargo_status', true );
209 // Make sure that it is set.
210 $new_history = array(
211 'date' => $status_date,
212 'time' => $status_time,
213 'location' => $status_location,
214 'updated-name' => $current_user->display_name,
215 'updated-by' => $current_user->ID,
216 'remarks' => $status_remarks,
217 'status' => $wpcargo_status
218 );
219 if( $wpcargo_status ){
220 update_post_meta($post_id, 'wpcargo_status', $wpcargo_status );
221 }
222 if( $status_location ){
223 update_post_meta( $post_id, 'location', $status_location );
224 }
225 if( $status_remarks ){
226 update_post_meta( $post_id, 'remarks', $status_remarks );
227 }
228 if( !empty( $wpcargo_shipments_update ) ){
229 if( $wpcargo_status ){
230 array_push($wpcargo_shipments_update, $new_history);
231 }
232 update_post_meta($post_id, 'wpcargo_shipments_update', $wpcargo_shipments_update );
233 }else{
234 if( !wp_is_post_revision( $post_id ) ){
235 if( $wpcargo_status ){
236 update_post_meta($post_id, 'wpcargo_shipments_update', array( $new_history ) );
237 }
238 }
239 }
240 // Dashboard Record and Notification
241 if( $wpcargo_status != $old_status ){
242 if( function_exists('wpcfe_save_report') ){
243 wpcfe_save_report( $post_id, $old_status, $wpcargo_status );
244 }
245 wpcargo_send_email_notificatio( $post_id, $wpcargo_status );
246 do_action( 'wpcargo_extra_send_email_notification', $post_id, $wpcargo_status );
247 do_action( 'wpc_add_sms_shipment_history', $post_id );
248 }
249 }
250 if ( isset( $_REQUEST['wpcargo_agent'] ) && $_REQUEST['wpcargo_agent'] != '' ) {
251 $wpcargo_agent = sanitize_text_field( $_REQUEST['wpcargo_agent'] );
252 update_post_meta( $post_id, 'agent_fields', $wpcargo_agent );
253 }
254
255 do_action( 'wpcargo_after_bulk_save', $post_id, $_REQUEST );
256 }