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-print-admin.php

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

195 lines 7.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 class WPCargo_Print_Admin{
6 public function __construct() {
7 add_action('admin_menu', array( $this, 'wpcargo_print_register_submenu_page' ) );
8 add_action('admin_print_header', array( $this, 'wpcargo_print_header_template' ) );
9 add_action('admin_print_shipper', array( $this, 'wpcargo_print_shipper_template' ), 10 );
10 add_action('admin_print_shipment', array( $this, 'wpcargo_print_shipment_template' ), 10 );
11 }
12 public function wpcargo_print_register_submenu_page() {
13 add_submenu_page(
14 '',
15 wpcargo_print_layout_label(),
16 wpcargo_print_layout_label(),
17 'edit_posts',
18 'wpcargo-print-layout',
19 array( $this, 'wpcargo_print_submenu_page_callback' )
20 );
21 add_submenu_page(
22 '',
23 wpcargo_shipment_label(),
24 wpcargo_shipment_label(),
25 'edit_posts',
26 'wpcargo-print-label',
27 array( $this, 'wpcargo_print_label_page_callback' )
28 );
29 }
30 public function wpcargo_print_submenu_page_callback( ) {
31 global $wpdb, $WPCCF_Fields, $wpcargo, $wpcargo_print_admin;
32 $shipment_id = isset($_GET['id']) ? (int)sanitize_text_field($_GET['id']) : '';
33 $mp_settings = get_option('wpc_mp_settings');
34 $setting_options = get_option('wpcargo_option_settings');
35 $packages = maybe_unserialize( get_post_meta( $shipment_id,'wpc-multiple-package', TRUE) );
36 $logo = '';
37 if( !empty( $setting_options['settings_shipment_ship_logo'] ) ){
38 $logo = '<img style="width: 180px;" id="logo" src="'. esc_url( $setting_options['settings_shipment_ship_logo'] ).'">';
39 }
40 if( get_option('wpcargo_label_header') ){
41 $siteInfo = get_option('wpcargo_label_header');
42 }else{
43 $siteInfo = $logo;
44 $siteInfo .= '<h2 style="margin:0;padding:0;">'.get_bloginfo('name').'</h2>';
45 $siteInfo .= '<p style="margin:0;padding:0;font-size: 14px;">'.get_bloginfo('description').'</p>';
46 $siteInfo .= '<p style="margin:0;padding:0;font-size: 8px;">'.get_bloginfo('wpurl').'</p>';
47 }
48 $shipmentDetails = array(
49 'shipmentID' => $shipment_id,
50 'barcode' => $wpcargo->barcode_url( $shipment_id ),
51 'packageSettings' => $mp_settings,
52 'cargoSettings' => $setting_options,
53 'packages' => $packages,
54 'logo' => $logo,
55 'siteInfo' => $siteInfo,
56 );
57 $custom_template_path = get_stylesheet_directory().'/wpcargo/invoice.tpl.php';
58 // do_action( 'wpcargo_before_search_result' );
59 do_action( 'wpcargo_print_btn' );
60 echo '<div id="wpcargo-result-print">';
61 if( file_exists( $custom_template_path ) ){
62 $label_template_url = $custom_template_path;
63 require_once( $label_template_url );
64 }else{
65 $label_template_url = WPCARGO_PLUGIN_PATH.'admin/templates/admin-print.tpl.php';
66 require_once( $label_template_url );
67 }
68 echo '</div>';
69 }
70 public function wpcargo_print_header_template($shipment_detail) {
71 global $wpdb, $wpcargo;
72 require_once(WPCARGO_PLUGIN_PATH.'admin/templates/print-details-header.tpl.php');
73 }
74 public function wpcargo_print_shipper_template($shipment_detail) {
75 global $wpdb;
76 require_once(WPCARGO_PLUGIN_PATH.'admin/templates/print-details-shipper.tpl.php');
77 }
78 public function wpcargo_print_shipment_template($shipment_detail) {
79 global $wpdb;
80 require_once(WPCARGO_PLUGIN_PATH.'admin/templates/print-details-shipment.tpl.php');
81 }
82 //** Print Label methods
83 public function wpcargo_print_label_page_callback(){
84 global $wpcargo;
85 if( isset( $_GET['id'] ) ){
86 $shipmentID = (int)sanitize_text_field($_GET['id']);
87 if( get_post_type( $shipmentID ) != 'wpcargo_shipment' && get_post_status( $shipmentID ) != 'publish' ){
88 return false;
89 }
90 $barcode = $wpcargo->barcode_url( $shipmentID );
91 $mp_settings = get_option('wpc_mp_settings');
92 $setting_options = get_option('wpcargo_option_settings');
93 $packages = maybe_unserialize( get_post_meta( $shipmentID,'wpc-multiple-package', TRUE) );
94 $print_fonts = wpcargo_print_fonts();
95 $ffamily = get_option('wpcargo_print_ffamily');
96 $fsize = get_option('wpcargo_print_fsize') ? get_option('wpcargo_print_fsize') : 12 ;
97 $logo = '';
98
99 if( !empty( $setting_options['settings_shipment_ship_logo'] ) ){
100 $logo = '<img style="width: 180px;" src="'. esc_url( $setting_options['settings_shipment_ship_logo'] ).'">';
101 }
102 if( get_option('wpcargo_label_header') ){
103 $siteInfo = get_option('wpcargo_label_header');
104 }else{
105 $siteInfo = $logo;
106 $siteInfo .= '<h2 style="margin:0;padding:0;">'.get_bloginfo('name').'</h2>';
107 $siteInfo .= '<p style="margin:0;padding:0;font-size: 14px;">'.get_bloginfo('description').'</p>';
108 $siteInfo .= '<p style="margin:0;padding:0;font-size: 10px;">'.get_bloginfo('wpurl').'</p>';
109 }
110 $shipmentDetails = array(
111 'shipmentID' => $shipmentID,
112 'barcode' => $barcode,
113 'packageSettings' => $mp_settings,
114 'cargoSettings' => $setting_options,
115 'packages' => $packages,
116 'logo' => $logo,
117 'siteInfo' => $siteInfo
118 );
119 $custom_template_path = get_stylesheet_directory().'/wpcargo/waybill.tpl.php';
120 if( file_exists( $custom_template_path ) ){
121 $label_template_url = $custom_template_path;
122 }else{
123 $label_template_url = apply_filters( 'label_template_url', $this->print_label_template_callback(), $shipmentDetails );
124 }
125 ?>
126 <div class="wrap">
127 <div class="postbox">
128 <div class="inside">
129 <script type="text/javascript">
130 function wpcargo_print(wpcargo_class) {
131 var printContents = document.getElementById(wpcargo_class).innerHTML;
132 var originalContents = document.body.innerHTML;
133 document.body.innerHTML = printContents;
134 window.print();
135 document.body.innerHTML = originalContents;
136 location.reload(true);
137 }
138 </script>
139 <div id="actions" style="margin-bottom: 12px; text-align: right;">
140 <a href="#" class="button button-secondary print" onclick="wpcargo_print('print-label')"><span class="dashicons dashicons-tag" style="vertical-align: sub;"></span> <?php esc_html_e('Print Waybill', 'wpcargo'); ?></a>
141 </div>
142 <div id="print-label">
143 <style type="text/css">
144 <?php if( $ffamily && array_key_exists( $ffamily, $print_fonts ) ): ?>
145 @import url('<?php echo esc_url( $print_fonts[$ffamily]['url'] ); ?>');
146 #print-label *{
147 font-family: <?php echo esc_html( $print_fonts[$ffamily]['fontfamily'] ); ?> !important;
148 font-size: <?php echo esc_html( $fsize ); ?>px;
149 }
150 <?php endif; ?>
151 div.copy-section {
152 border: 2px solid #000;
153 margin-bottom: 18px;
154 }
155 .copy-section table {
156 border-collapse: collapse;
157 }
158 .copy-section table td.align-center{
159 text-align: center;
160 }
161 .copy-section table td {
162 border: 1px solid #000;
163 }
164 table tr td{
165 padding:6px;
166 }
167 table tr td.center{
168 text-align:center;
169 }
170 table tr td.bold{
171 font-weight: bold;
172 }
173 @media print{
174 <?php if( $ffamily && array_key_exists( $ffamily, $print_fonts ) ): ?>
175 @import url('<?php echo esc_url( $print_fonts[$ffamily]['url'] ); ?>');
176 *{
177 font-family: <?php echo esc_html( $print_fonts[$ffamily]['fontfamily'] ); ?> !important;
178 font-size: <?php echo esc_html( $fsize ); ?>px;
179 }
180 <?php endif; ?>
181 }
182 <?php do_action( 'wpcargo_after_print_waybill_styles' ); ?>
183 </style>
184 <?php require_once( $label_template_url ); ?>
185 </div>
186 </div>
187 </div>
188 <?php
189 }
190 }
191 public function print_label_template_callback( ){
192 return WPCARGO_PLUGIN_PATH.'admin/templates/admin-print-label.tpl.php';
193 }
194 }
195 $wpcargo_print_admin = new WPCargo_Print_Admin;