PluginProbe
Welcart e-Commerce / 2.11.30
Welcart e-Commerce v2.11.30
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 / classes / orderList2.class.php

orderList2.class.php in Welcart e-Commerce 2.11.30, at classes/orderList2.class.php

1,364 lines 58.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Order List Class.
4 * - New type.
5 *
6 * @package Welcart
7 */
8 class WlcOrderList {
9 public $table; /* テーブル名 */
10 public $rows; /* データ */
11 public $action; /* アクション */
12 public $startRow; /* 表示開始行番号 */
13 public $maxRow; /* 最大表示行数 */
14 public $currentPage; /* 現在のページNo */
15 public $firstPage; /* 最初のページNo */
16 public $previousPage; /* 前のページNo */
17 public $nextPage; /* 次のページNo */
18 public $lastPage; /* 最終ページNo */
19 public $naviMaxButton; /* ページネーション・ナビのボタンの数 */
20 public $dataTableNavigation; /* ナヴィゲーションhtmlコード */
21 public $arr_period; /* 表示データ期間 */
22 public $arr_search; /* サーチ条件 */
23 public $searchSql; /* 簡易絞込みSQL */
24 public $searchSkuSql; /* SKU絞り込み */
25 public $searchSwitchStatus; /* サーチ表示スイッチ */
26 public $columns; /* データカラム */
27 public $all_columns; /* �
28 �てのカラム */
29 public $sortColumn; /* 現在ソート中のフィールド */
30 public $sortOldColumn;
31 public $sortSwitchs; /* 各フィールド毎の昇順降順スイッチ */
32 public $userHeaderNames; /* ユーザー指定のヘッダ名 */
33 public $action_status, $action_message;
34 public $pageLimit; /* ページ制限 */
35 public $management_status; /* 処理ステータス */
36 public $selectSql;
37 public $joinTableSql;
38 public $cscs_meta;
39 public $csod_meta;
40 public $currentPageIds;
41 public $period;
42 public $placeholder_escape;
43 public $view_column;
44 public $all_column;
45 public $data_cookie;
46 public $searchWhere;
47 public $searchHaving;
48
49 public $listOption;
50 public $totalRow;
51 public $selectedRow;
52 public $headers;
53
54 /**
55 * Constructor.
56 *
57 * @param bool $all_column Column.
58 */
59 public function __construct( $all_column = false ) {
60 global $wpdb;
61 $this->all_column = $all_column;
62 $this->cscs_meta = usces_has_custom_field_meta( 'customer' );
63 $this->csod_meta = usces_has_custom_field_meta( 'order' );
64
65 $this->listOption = get_option( 'usces_orderlist_option', array() );
66 $this->view_column = $this->listOption['view_column'] ?? array();
67 if ( $this->all_column ) {
68 foreach ( $this->view_column as $key => $value ) {
69 $this->view_column[ $key ] = 1;
70 }
71 }
72
73 $this->table = $wpdb->prefix . 'usces_order';
74 $this->set_all_column();
75 $this->set_column();
76 $this->rows = array();
77
78 $this->maxRow = $this->listOption['max_row'] ?? 50;
79 $this->naviMaxButton = 11;
80 $this->firstPage = 1;
81 $this->pageLimit = 'on';
82 $this->action_status = 'none';
83 $this->action_message = '';
84 $orderPeriod = isset( $_COOKIE['orderPeriod'] ) ? $_COOKIE['orderPeriod'] : '';
85 if ( empty( $orderPeriod ) ) {
86 $this->period = array(
87 'period' => 0,
88 'start' => '',
89 'end' => '',
90 );
91 } else {
92 parse_str( $orderPeriod, $this->period );
93 }
94 $this->getCookie();
95 $this->SetDefaultParam();
96 $this->SetParamByQuery();
97 $this->validationSearchParameters();
98 $arr_period = array(
99 __( 'This month', 'usces' ),
100 __( 'Last month', 'usces' ),
101 __( 'The past one week', 'usces' ),
102 __( 'Last 30 days', 'usces' ),
103 __( 'Last 90days', 'usces' ),
104 __( 'All', 'usces' ),
105 );
106 $this->arr_period = apply_filters( 'usces_filter_order_list_arr_period', $arr_period, $this );
107
108 $management_status = array(
109 'duringorder' => __( 'temporaly out of stock', 'usces' ),
110 'cancel' => __( 'Cancel', 'usces' ),
111 'completion' => __( 'It has sent it out.', 'usces' ),
112 'estimate' => __( 'An estimate', 'usces' ),
113 'adminorder' => __( 'Management of Note', 'usces' ),
114 'continuation' => __( 'Continuation', 'usces' ),
115 'termination' => __( 'Termination', 'usces' ),
116 );
117 $this->management_status = apply_filters( 'usces_filter_management_status', $management_status, $this );
118
119 $wpdb->query( 'SET SQL_BIG_SELECTS=1' );
120 }
121
122 /**
123 * Set Column.
124 */
125 public function set_column() {
126
127 $arr_column = array();
128
129 if ( isset( $this->view_column['admin_memo'] ) ) {
130 $arr_column['admin_memo'] = __( 'Administrator Note', 'usces' );
131 }
132
133 $arr_column['ID'] = __( 'ID', 'usces' );
134
135 if ( isset( $this->view_column['deco_id'] ) ) {
136 $arr_column['deco_id'] = __( 'Order number', 'usces' );
137 }
138
139 if ( defined( 'WCEX_AUTO_DELIVERY' ) && version_compare( WCEX_AUTO_DELIVERY_VERSION, '1.4.0', '>=' ) ) {
140 $arr_column['reg_id'] = __( 'Regular ID', 'autodelivery' );
141 }
142
143 $arr_column['order_date'] = __( 'Order date', 'usces' );
144 $arr_column['order_modified'] = apply_filters( 'usces_filter_admin_modified_label', __( 'shpping date', 'usces' ) );
145 $arr_column['estimate_status'] = __( 'Order type', 'usces' );
146 $arr_column['process_status'] = __( 'Processing status', 'usces' );
147
148 if ( isset( $this->view_column['tracking_number'] ) ) {
149 $arr_column['tracking_number'] = __( 'Tracking number', 'usces' );
150 }
151
152 $arr_column['payment_name'] = __( 'payment method', 'usces' );
153
154 if ( isset( $this->view_column['wc_trans_id'] ) ) {
155 $arr_column['wc_trans_id'] = __( 'Transaction ID', 'usces' );
156 }
157
158 $arr_column['receipt_status'] = __( 'transfer statement', 'usces' );
159 $arr_column['item_total_price'] = __( 'total items', 'usces' ) . '( ' . __( usces_crcode( 'return' ), 'usces' ) . ')';
160 $arr_column['getpoint'] = __( 'granted points', 'usces' );
161 $arr_column['usedpoint'] = __( 'Used points', 'usces' );
162 $arr_column['discount'] = __( 'Discount', 'usces' ) . '( ' . __( usces_crcode( 'return' ), 'usces' ) . ')';
163 $arr_column['shipping_charge'] = __( 'Shipping', 'usces' ) . '( ' . __( usces_crcode( 'return' ), 'usces' ) . ')';
164 $arr_column['cod_fee'] = __( 'Fee', 'usces' ) . '( ' . __( usces_crcode( 'return' ), 'usces' ) . ')';
165 $arr_column['tax'] = __( 'Tax', 'usces' ) . '( ' . __( usces_crcode( 'return' ), 'usces' ) . ')';
166 $arr_column['total_price'] = __( 'Total Amount', 'usces' ) . '( ' . __( usces_crcode( 'return' ), 'usces' ) . ')';
167 $arr_column['deli_method'] = __( 'shipping option', 'usces' );
168 $arr_column['deli_name'] = __( 'Destination name', 'usces' );
169 $arr_column['deli_time'] = __( 'delivery time', 'usces' );
170 $arr_column['deli_date'] = __( 'Delivery date', 'usces' );
171 $arr_column['delidue_date'] = __( 'Shipping date', 'usces' );
172
173 $arr_column['mem_id'] = __( 'membership number', 'usces' );
174 $arr_column['name1'] = __( 'Last Name', 'usces' );
175 $arr_column['name2'] = __( 'First Name', 'usces' );
176 $arr_column['name3'] = __( 'Last Furigana', 'usces' );
177 $arr_column['name4'] = __( 'First Furigana', 'usces' );
178 $arr_column['zipcode'] = __( 'Zip', 'usces' );
179
180 if ( isset( $this->view_column['country'] ) ) {
181 $arr_column['country'] = __( 'Country', 'usces' );
182 }
183
184 $arr_column['pref'] = __( 'Province', 'usces' );
185 $arr_column['address1'] = __( 'city', 'usces' );
186 $arr_column['address2'] = __( 'numbers', 'usces' );
187 $arr_column['address3'] = __( 'building name', 'usces' );
188 $arr_column['tel'] = __( 'Phone number', 'usces' );
189 $arr_column['fax'] = __( 'FAX number', 'usces' );
190 $arr_column['email'] = __( 'e-mail', 'usces' );
191 $arr_column['note'] = __( 'Notes', 'usces' );
192
193 foreach ( (array) $this->cscs_meta as $key => $value ) {
194 $cscs_key = 'cscs_' . $key;
195
196 if ( isset( $this->view_column[ $cscs_key ] ) && $this->view_column[ $cscs_key ] ) {
197 $cscs_name = $value['name'];
198 $arr_column[ $cscs_key ] = $cscs_name;
199 }
200 }
201
202 foreach ( (array) $this->csod_meta as $key => $value ) {
203 $csod_key = 'csod_' . $key;
204
205 if ( isset( $this->view_column[ $csod_key ] ) && $this->view_column[ $csod_key ] ) {
206 $csod_name = $value['name'];
207 $arr_column[ $csod_key ] = $csod_name;
208 }
209 }
210
211 $arr_mail_print_fields = get_option( 'usces_order_mail_print_fields', array() );
212 foreach ( $arr_mail_print_fields as $key => $value ) {
213 if ( isset( $this->view_column[ $key ] ) ) {
214 $arr_column[ $key ] = $value['label'];
215 }
216 }
217
218 $arr_column = apply_filters( 'usces_filter_orderlist_column', $arr_column, $this );
219 $this->columns = $arr_column;
220 }
221
222 /**
223 * Set All Columns.
224 */
225 public function set_all_column() {
226
227 $arr_column = array();
228
229 $arr_column['admin_memo'] = __( 'Administrator Note', 'usces' );
230 $arr_column['ID'] = __( 'ID', 'usces' );
231 $arr_column['deco_id'] = __( 'Order number', 'usces' );
232 if ( defined( 'WCEX_AUTO_DELIVERY' ) && version_compare( WCEX_AUTO_DELIVERY_VERSION, '1.4.0', '>=' ) ) {
233 $arr_column['reg_id'] = __( 'Regular ID', 'autodelivery' );
234 }
235 $arr_column['order_date'] = __( 'Order date', 'usces' );
236
237 $arr_column['order_modified'] = apply_filters( 'usces_filter_admin_modified_label', __( 'shpping date', 'usces' ) );
238 $arr_column['estimate_status'] = __( 'Order type', 'usces' );
239 $arr_column['process_status'] = __( 'Processing status', 'usces' );
240 $arr_column['tracking_number'] = __( 'Tracking number', 'usces' );
241 $arr_column['payment_name'] = __( 'payment method', 'usces' );
242 $arr_column['wc_trans_id'] = __( 'Transaction ID', 'usces' );
243 $arr_column['receipt_status'] = __( 'transfer statement', 'usces' );
244 $arr_column['item_total_price'] = __( 'total items', 'usces' ) . '( ' . __( usces_crcode( 'return' ), 'usces' ) . ')';
245 $arr_column['getpoint'] = __( 'granted points', 'usces' );
246 $arr_column['usedpoint'] = __( 'Used points', 'usces' );
247 $arr_column['discount'] = __( 'Discount', 'usces' ) . '( ' . __( usces_crcode( 'return' ), 'usces' ) . ')';
248 $arr_column['shipping_charge'] = __( 'Shipping', 'usces' ) . '( ' . __( usces_crcode( 'return' ), 'usces' ) . ')';
249 $arr_column['cod_fee'] = __( 'Fee', 'usces' ) . '( ' . __( usces_crcode( 'return' ), 'usces' ) . ')';
250 $arr_column['tax'] = __( 'Tax', 'usces' ) . '( ' . __( usces_crcode( 'return' ), 'usces' ) . ')';
251 $arr_column['total_price'] = __( 'Total Amount', 'usces' ) . '( ' . __( usces_crcode( 'return' ), 'usces' ) . ')';
252 $arr_column['deli_method'] = __( 'shipping option', 'usces' );
253 $arr_column['deli_name'] = __( 'Destination name', 'usces' );
254 $arr_column['deli_time'] = __( 'delivery time', 'usces' );
255 $arr_column['deli_date'] = __( 'Delivery date', 'usces' );
256 $arr_column['delidue_date'] = __( 'Shipping date', 'usces' );
257
258 $arr_column['mem_id'] = __( 'membership number', 'usces' );
259 $arr_column['name1'] = __( 'Last Name', 'usces' );
260 $arr_column['name2'] = __( 'First Name', 'usces' );
261 $arr_column['name3'] = __( 'Last Furigana', 'usces' );
262 $arr_column['name4'] = __( 'First Furigana', 'usces' );
263 $arr_column['zipcode'] = __( 'Zip', 'usces' );
264 $arr_column['country'] = __( 'Country', 'usces' );
265 $arr_column['pref'] = __( 'Province', 'usces' );
266 $arr_column['address1'] = __( 'city', 'usces' );
267 $arr_column['address2'] = __( 'numbers', 'usces' );
268 $arr_column['address3'] = __( 'building name', 'usces' );
269 $arr_column['tel'] = __( 'Phone number', 'usces' );
270 $arr_column['fax'] = __( 'FAX number', 'usces' );
271 $arr_column['email'] = __( 'e-mail', 'usces' );
272 $arr_column['note'] = __( 'Notes', 'usces' );
273
274 foreach ( (array) $this->cscs_meta as $key => $value ) {
275 $cscs_key = 'cscs_' . $key;
276 $cscs_name = $value['name'];
277 $arr_column[ $cscs_key ] = $cscs_name;
278 }
279
280 foreach ( (array) $this->csod_meta as $key => $value ) {
281 $csod_key = 'csod_' . $key;
282 $csod_name = $value['name'];
283 $arr_column[ $csod_key ] = $csod_name;
284 }
285
286 $arr_mail_print_fields = get_option( 'usces_order_mail_print_fields', array() );
287 foreach ( $arr_mail_print_fields as $key => $value ) {
288 $arr_column[ $key ] = $value['label'];
289 }
290
291 $arr_column = apply_filters( 'usces_filter_orderlist_all_column', $arr_column, $this );
292 $this->all_columns = $arr_column;
293 }
294
295 /**
296 * Get Column.
297 */
298 public function get_column() {
299 return $this->columns;
300 }
301
302 /**
303 * Get All Columns.
304 */
305 public function get_all_column() {
306 return $this->all_columns;
307 }
308
309 /**
310 * Action.
311 *
312 * @return mixed
313 */
314 public function MakeTable() {
315 $this->SetParam();
316 switch ( $this->action ) {
317 case 'searchOut':
318 $this->SearchOut();
319 $res = $this->GetRows();
320 break;
321
322 case 'collective_receipt_status':
323 if ( ! current_user_can( 'wel_manage_order' ) ) {
324 wp_die( __( 'You do not have sufficient privileges to perform this operation.', 'usces' ) );
325 }
326 check_admin_referer( 'order_list', 'wc_nonce' );
327 usces_all_change_order_reciept( $this );
328 $this->SearchIn();
329 $res = $this->GetRows();
330 break;
331
332 case 'collective_estimate_status':
333 case 'collective_process_status':
334 if ( ! current_user_can( 'wel_manage_order' ) ) {
335 wp_die( __( 'You do not have sufficient privileges to perform this operation.', 'usces' ) );
336 }
337 check_admin_referer( 'order_list', 'wc_nonce' );
338 usces_all_change_order_status( $this );
339 $this->SearchIn();
340 $res = $this->GetRows();
341 break;
342
343 case 'collective_delete':
344 if ( ! current_user_can( 'wel_manage_order' ) ) {
345 wp_die( __( 'You do not have sufficient privileges to perform this operation.', 'usces' ) );
346 }
347 check_admin_referer( 'order_list', 'wc_nonce' );
348 usces_all_delete_order_data( $this );
349 $this->SetTotalRow();
350 $this->SearchIn();
351 $res = $this->GetRows();
352 break;
353
354 case 'searchIn':
355 case 'refresh':
356 case 'returnList':
357 case 'changeSort':
358 case 'changePage':
359 check_admin_referer( 'order_list', 'wc_nonce' );
360 default:
361 $this->SearchIn();
362 $res = $this->GetRows();
363 break;
364 }
365
366 $this->SetNavi();
367 $this->SetHeaders();
368
369 if ( $res ) {
370 return true;
371 } else {
372 return false;
373 }
374 }
375
376 /**
377 * Default Parameters.
378 */
379 public function SetDefaultParam() {
380 $this->startRow = isset( $this->data_cookie['startRow'] ) ? $this->data_cookie['startRow'] : 0;
381 $this->currentPage = isset( $this->data_cookie['currentPage'] ) ? $this->data_cookie['currentPage'] : 1;
382 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : 'ID';
383 $this->searchWhere = '';
384 $this->searchHaving = '';
385 $this->searchSwitchStatus = ( isset( $this->data_cookie['searchSwitchStatus'] ) ) ? $this->data_cookie['searchSwitchStatus'] : 'OFF';
386 if ( isset( $this->data_cookie['arr_search'] ) ) {
387 $this->arr_search = $this->data_cookie['arr_search'];
388 } else {
389 $arr_search = array(
390 'period' => array( '', '' ),
391 'order_column' => array( '', '' ),
392 'order_word' => array( '', '' ),
393 'order_word_term' => array( 'contain', 'contain' ),
394 'order_term' => 'AND',
395 'product_column' => array( '', '' ),
396 'product_word' => array( '', '' ),
397 'product_word_term' => array( 'contain', 'contain' ),
398 'option_word' => array( '', '' ),
399 'product_term' => 'AND',
400 );
401 $this->arr_search = apply_filters( 'usces_filter_order_list_arr_search', $arr_search, $this );
402 }
403 if ( isset( $this->data_cookie['sortSwitchs'] ) ) {
404 $this->sortSwitchs = $this->data_cookie['sortSwitchs'];
405 } else {
406 $this->sortSwitchs[ $this->sortColumn ] = 'DESC';
407 }
408 $this->SetTotalRow();
409 }
410
411 /**
412 * Set Parameters.
413 */
414 public function SetParam() {
415 $this->startRow = ( $this->currentPage - 1 ) * $this->maxRow;
416 }
417
418 /**
419 * Set Parameters.
420 */
421 public function SetParamByQuery() {
422 global $wpdb;
423 if ( isset( $_REQUEST['changePage'] ) ) {
424
425 $this->action = 'changePage';
426 $this->currentPage = (int) $_REQUEST['changePage'];
427 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
428 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
429 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
430 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
431 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
432 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
433 $this->placeholder_escape = ( isset( $this->data_cookie['placeholder_escape'] ) ) ? $this->data_cookie['placeholder_escape'] : $this->placeholder_escape;
434
435 } elseif ( isset( $_REQUEST['returnList'] ) ) {
436
437 $this->action = 'returnList';
438 $this->currentPage = ( isset( $this->data_cookie['currentPage'] ) ) ? $this->data_cookie['currentPage'] : $this->currentPage;
439 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
440 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
441 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
442 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
443 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
444 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
445 $this->placeholder_escape = ( isset( $this->data_cookie['placeholder_escape'] ) ) ? $this->data_cookie['placeholder_escape'] : $this->placeholder_escape;
446
447 } elseif ( isset( $_REQUEST['changeSort'] ) ) {
448
449 $this->action = 'changeSort';
450 $this->sortOldColumn = $this->sortColumn;
451 // Validate sortColumn.
452 if ( in_array( $_REQUEST['changeSort'], array_keys( $this->columns ) ) ) {
453 $this->sortColumn = $_REQUEST['changeSort'];
454 } else {
455 $this->sortColumn = 'ID'; // default.
456 }
457 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
458 // Validate sortSwitchs.
459 if ( isset( $_REQUEST['switch'] ) && in_array( $_REQUEST['switch'], array( 'ASC', 'DESC' ) ) ) {
460 $this->sortSwitchs[ $this->sortColumn ] = $_REQUEST['switch'];
461 } else {
462 $this->sortSwitchs[ $this->sortColumn ] = 'DESC'; // default.
463 }
464 $this->currentPage = ( isset( $this->data_cookie['currentPage'] ) ) ? $this->data_cookie['currentPage'] : $this->currentPage;
465 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
466 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
467 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
468 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
469 $this->placeholder_escape = ( isset( $this->data_cookie['placeholder_escape'] ) ) ? $this->data_cookie['placeholder_escape'] : $this->placeholder_escape;
470
471 } elseif ( isset( $_REQUEST['searchIn'] ) ) {
472
473 $this->action = 'searchIn';
474 $this->arr_search['order_column'][0] = ! WCUtils::is_blank( $_REQUEST['search']['order_column'][0] ) ? str_replace( '`', '', $_REQUEST['search']['order_column'][0] ) : '';
475 $this->arr_search['order_column'][1] = ! WCUtils::is_blank( $_REQUEST['search']['order_column'][1] ) ? str_replace( '`', '', $_REQUEST['search']['order_column'][1] ) : '';
476 $this->arr_search['order_word'][0] = ! WCUtils::is_blank( $_REQUEST['search']['order_word'][0] ) ? trim( $_REQUEST['search']['order_word'][0] ) : '';
477 $this->arr_search['order_word'][1] = ! WCUtils::is_blank( $_REQUEST['search']['order_word'][1] ) ? trim( $_REQUEST['search']['order_word'][1] ) : '';
478 $this->arr_search['order_word_term'][0] = isset( $_REQUEST['search']['order_word_term'][0] ) ? $_REQUEST['search']['order_word_term'][0] : 'contain';
479 $this->arr_search['order_word_term'][1] = isset( $_REQUEST['search']['order_word_term'][1] ) ? $_REQUEST['search']['order_word_term'][1] : 'contain';
480 if ( WCUtils::is_blank( $_REQUEST['search']['order_column'][0] ) ) {
481 $this->arr_search['order_column'][1] = '';
482 $this->arr_search['order_word'][0] = '';
483 $this->arr_search['order_word'][1] = '';
484 $this->arr_search['order_word_term'][0] = 'contain';
485 $this->arr_search['order_word_term'][1] = 'contain';
486 }
487 $this->arr_search['order_term'] = $_REQUEST['search']['order_term'];
488 $this->arr_search['product_column'][0] = ! WCUtils::is_blank( $_REQUEST['search']['product_column'][0] ) ? str_replace( '`', '', $_REQUEST['search']['product_column'][0] ) : '';
489 $this->arr_search['product_column'][1] = ! WCUtils::is_blank( $_REQUEST['search']['product_column'][1] ) ? str_replace( '`', '', $_REQUEST['search']['product_column'][1] ) : '';
490 $this->arr_search['product_word'][0] = ! WCUtils::is_blank( $_REQUEST['search']['product_word'][0] ) ? trim( $_REQUEST['search']['product_word'][0] ) : '';
491 $this->arr_search['product_word'][1] = ! WCUtils::is_blank( $_REQUEST['search']['product_word'][1] ) ? trim( $_REQUEST['search']['product_word'][1] ) : '';
492 $this->arr_search['product_word_term'][0] = isset( $_REQUEST['search']['product_word_term'][0] ) ? $_REQUEST['search']['product_word_term'][0] : 'contain';
493 $this->arr_search['product_word_term'][1] = isset( $_REQUEST['search']['product_word_term'][1] ) ? $_REQUEST['search']['product_word_term'][1] : 'contain';
494 $this->arr_search['option_word'][0] = ( isset( $_REQUEST['search']['option_word'][0] ) && ! WCUtils::is_blank( $_REQUEST['search']['option_word'][0] ) ) ? trim( $_REQUEST['search']['option_word'][0] ) : '';
495 $this->arr_search['option_word'][1] = ( isset( $_REQUEST['search']['option_word'][1] ) && ! WCUtils::is_blank( $_REQUEST['search']['option_word'][1] ) ) ? trim( $_REQUEST['search']['option_word'][1] ) : '';
496 if ( WCUtils::is_blank( $_REQUEST['search']['product_column'][0] ) ) {
497 $this->arr_search['product_column'][1] = '';
498 $this->arr_search['product_word'][0] = '';
499 $this->arr_search['product_word'][1] = '';
500 $this->arr_search['product_word_term'][0] = 'contain';
501 $this->arr_search['product_word_term'][1] = 'contain';
502 $this->arr_search['option_word'][0] = '';
503 $this->arr_search['option_word'][1] = '';
504 }
505 $this->arr_search['product_term'] = $_REQUEST['search']['product_term'];
506 $this->currentPage = 1;
507 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
508 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
509 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
510 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
511 $this->placeholder_escape = $wpdb->placeholder_escape();
512
513 } elseif ( isset( $_REQUEST['searchOut'] ) ) {
514
515 $this->action = 'searchOut';
516 $this->arr_search['column'] = '';
517 $this->arr_search['word'] = '';
518 $this->arr_search['order_column'][0] = '';
519 $this->arr_search['order_column'][1] = '';
520 $this->arr_search['order_word'][0] = '';
521 $this->arr_search['order_word'][1] = '';
522 $this->arr_search['order_word_term'][0] = 'contain';
523 $this->arr_search['order_word_term'][1] = 'contain';
524 $this->arr_search['order_term'] = 'AND';
525 $this->arr_search['product_column'][0] = '';
526 $this->arr_search['product_column'][1] = '';
527 $this->arr_search['product_word'][0] = '';
528 $this->arr_search['product_word'][1] = '';
529 $this->arr_search['product_word_term'][0] = 'contain';
530 $this->arr_search['product_word_term'][1] = 'contain';
531 $this->arr_search['option_word'][0] = '';
532 $this->arr_search['option_word'][1] = '';
533 $this->arr_search['product_term'] = 'AND';
534
535 $this->currentPage = 1;
536 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
537 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
538 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
539 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
540 $this->placeholder_escape = '';
541
542 } elseif ( isset( $_REQUEST['refresh'] ) ) {
543
544 $this->action = 'refresh';
545 $this->currentPage = ( isset( $this->data_cookie['currentPage'] ) ) ? $this->data_cookie['currentPage'] : $this->currentPage;
546 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
547 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
548 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
549 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
550 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
551 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
552 $this->placeholder_escape = '';
553
554 } elseif ( isset( $_REQUEST['collective'] ) ) {
555
556 $this->action = 'collective_' . str_replace( ',', '', $_POST['allchange']['column'] );
557 $this->currentPage = ( isset( $this->data_cookie['currentPage'] ) ) ? $this->data_cookie['currentPage'] : $this->currentPage;
558 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
559 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
560 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
561 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
562 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
563 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
564 $this->placeholder_escape = ( isset( $this->data_cookie['placeholder_escape'] ) ) ? $this->data_cookie['placeholder_escape'] : $this->placeholder_escape;
565
566 } else {
567
568 $this->action = 'default';
569 $this->placeholder_escape = '';
570 }
571 }
572
573 /**
574 * Validation Search Parameters.
575 */
576 public function validationSearchParameters() {
577 $default_order_word_term = [ 'contain', 'notcontain', 'equal', 'morethan', 'lessthan' ];
578 $default_product_word_term = [ 'contain', 'notcontain', 'equal', 'morethan', 'lessthan' ];
579 $default_order_term = [ 'AND', 'OR' ];
580 $default_product_term = [ 'AND', 'OR' ];
581 $default_product_columns = [ 'item_code', 'item_name', 'sku_code', 'sku_name', 'item_option' ];
582 if ( ! empty( $this->arr_search['order_column'][0] ) && ! array_key_exists( $this->arr_search['order_column'][0], $this->columns ) ) {
583 $this->arr_search['order_column'][0] = key( $this->columns );
584 }
585 if ( ! empty( $this->arr_search['order_column'][1] ) && ! array_key_exists( $this->arr_search['order_column'][1], $this->columns ) ) {
586 $this->arr_search['order_column'][1] = key( $this->columns );
587 }
588
589 if ( ! empty( $this->arr_search['order_word_term'][0] ) && ! in_array( $this->arr_search['order_word_term'][0], $default_order_word_term ) ) {
590 $this->arr_search['order_word_term'][0] = $default_order_word_term[0];
591 }
592 if ( ! empty( $this->arr_search['order_word_term'][1] ) && ! in_array( $this->arr_search['order_word_term'][1], $default_order_word_term ) ) {
593 $this->arr_search['order_word_term'][1] = $default_order_word_term[0];
594 }
595 if ( isset( $this->arr_search['order_term'] ) && ! in_array( $this->arr_search['order_term'], $default_order_term ) ) {
596 $this->arr_search['order_term'] = $default_order_term[0];
597 }
598
599 if ( ! empty( $this->arr_search['product_column'][0] ) && ! in_array( $this->arr_search['product_column'][0], $default_product_columns ) ) {
600 $this->arr_search['product_column'][0] = $default_product_columns[0];
601 }
602 if ( ! empty( $this->arr_search['product_column'][1] ) && ! in_array( $this->arr_search['product_column'][1], $default_product_columns ) ) {
603 $this->arr_search['product_column'][1] = $default_product_columns[0];
604 }
605
606 if ( ! empty( $this->arr_search['product_word_term'][0] ) && ! in_array( $this->arr_search['product_word_term'][0], $default_product_word_term ) ) {
607 $this->arr_search['product_word_term'][0] = $default_product_word_term[0];
608 }
609 if ( ! empty( $this->arr_search['product_word_term'][1] ) && ! in_array( $this->arr_search['product_word_term'][1], $default_product_word_term ) ) {
610 $this->arr_search['product_word_term'][1] = $default_product_word_term[0];
611 }
612 if ( isset( $this->arr_search['product_term'] ) && ! in_array( $this->arr_search['product_term'], $default_product_term ) ) {
613 $this->arr_search['product_term'] = $default_product_term[0];
614 }
615 }
616
617 /**
618 * Get Rows.
619 *
620 * @return array
621 */
622 public function GetRows() {
623 global $wpdb;
624
625 $order_table = $wpdb->prefix . 'usces_order';
626 $order_meta_table = $wpdb->prefix . 'usces_order_meta';
627 $ordercart_table = $wpdb->prefix . 'usces_ordercart';
628 $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
629 $regular_table = $wpdb->prefix . 'usces_regular';
630
631 $where = $this->GetWhere();
632 $having = $this->GetHaving();
633
634 $join = '';
635 $cscs = '';
636 $csod = '';
637
638 $tracking_key = apply_filters( 'usces_filter_tracking_meta_key', 'tracking_number' );
639
640 if ( $this->view_column['deco_id'] ) {
641 $join .= "LEFT JOIN {$order_meta_table} AS deco ON ord.ID = deco.order_id AND deco.meta_key = 'dec_order_id' ";
642 }
643 if ( $this->view_column['wc_trans_id'] ) {
644 $join .= "LEFT JOIN {$order_meta_table} AS trans ON ord.ID = trans.order_id AND trans.meta_key = 'wc_trans_id' ";
645 }
646 if ( $this->view_column['country'] ) {
647 $join .= "LEFT JOIN {$order_meta_table} AS country ON ord.ID = country.order_id AND country.meta_key = 'customer_country' ";
648 }
649 if ( $this->view_column['admin_memo'] ) {
650 $join .= "LEFT JOIN {$order_meta_table} AS memo ON ord.ID = memo.order_id AND memo.meta_key = 'order_memo' ";
651 }
652 if ( $this->view_column['tracking_number'] ) {
653 $join .= $wpdb->prepare( "LEFT JOIN {$order_meta_table} AS trac ON ord.ID = trac.order_id AND trac.meta_key = %s ", $tracking_key );
654 }
655 foreach ( $this->columns as $key => $value ) {
656 if ( 'cscs_' === substr( $key, 0, 5 ) && $this->view_column[ $key ] ) {
657 $join .= $wpdb->prepare( " LEFT JOIN {$order_meta_table} AS `p{$key}` ON ord.ID = `p{$key}`.order_id AND `p{$key}`.meta_key = %s ", $key );
658 $cscs .= ', `p' . $key . '`.meta_value AS `' . $key . "`\n";
659 }
660 }
661
662 foreach ( $this->columns as $key => $value ) {
663 if ( 'csod_' === substr( $key, 0, 5 ) && $this->view_column[ $key ] ) {
664 $join .= $wpdb->prepare( " LEFT JOIN {$order_meta_table} AS `p{$key}` ON ord.ID = `p{$key}`.order_id AND `p{$key}`.meta_key = %s ", $key );
665 $csod .= ', `p' . $key . '`.meta_value AS `' . $key . "`\n";
666 }
667 }
668
669 $arr_mail_print_fields = get_option( 'usces_order_mail_print_fields', array() );
670 foreach ( $arr_mail_print_fields as $key => $value ) {
671 if ( $this->view_column[ $key ] ) {
672 $csod .= ", ord.order_check \n";
673 break;
674 }
675 }
676
677 if ( $where ) {
678 $join .= " LEFT JOIN {$ordercart_table} AS `cart` ON ord.ID = cart.order_id ";
679 $csod .= ', cart.item_code , cart.item_name , cart.sku_code , cart.sku_name ';
680
681 $join .= " LEFT JOIN {$ordercart_meta_table} AS `itemopt` ON cart.cart_id = itemopt.cart_id AND itemopt.meta_type = 'option' ";
682 $csod .= ', itemopt.meta_key, itemopt.meta_value ';
683 }
684 if ( defined( 'WCEX_AUTO_DELIVERY' ) && version_compare( WCEX_AUTO_DELIVERY_VERSION, '1.4.0', '>=' ) ) {
685 $join .= "LEFT JOIN {$order_meta_table} AS `rmeta1` ON ord.ID = rmeta1.order_id AND rmeta1.meta_key = 'regular_id' ";
686 $join .= "LEFT JOIN {$order_meta_table} AS `rmeta2` ON ord.ID = rmeta2.order_id AND rmeta2.meta_key = 'acting_zeus_card' ";
687 $join .= "LEFT JOIN {$regular_table} ON ord.ID = reg_order_id ";
688 }
689 $join = apply_filters( 'usces_filter_orderlist_sql_jointable', $join, $tracking_key, $this );
690
691 $group = ' GROUP BY `ID` ';
692
693 $init_column = 'ID';
694 $sort_column = in_array( $this->sortColumn, array_keys( $this->columns ), true ) ? $this->sortColumn : $init_column;
695 $init_switch = 'DESC';
696 $sort_switch = $this->sortSwitchs[ $sort_column ] ?? $init_switch;
697 $sort_switch = in_array( strtoupper( $sort_switch ), array( 'ASC', 'DESC' ), true ) ? $sort_switch : $init_switch;
698 $order = ' ORDER BY ' . esc_sql( $sort_column ) . ' ' . esc_sql( $sort_switch );
699 $order = apply_filters( 'usces_filter_orderlist_sql_order', $order, $sort_column, $sort_switch, $this );
700
701 $qstr = "SELECT \n";
702
703 if ( $this->view_column['admin_memo'] ) {
704 $qstr .= "memo.meta_value AS admin_memo, \n";
705 }
706 $qstr .= "ord.ID AS ID, \n";
707
708 if ( $this->view_column['deco_id'] ) {
709 $qstr .= "deco.meta_value AS deco_id, \n";
710 }
711
712 if ( defined( 'WCEX_AUTO_DELIVERY' ) && version_compare( WCEX_AUTO_DELIVERY_VERSION, '1.4.0', '>=' ) ) {
713 $qstr .= "IFNULL( reg_id, rmeta1.meta_value ) AS `reg_id`, \n";
714 }
715
716 $qstr .= "DATE_FORMAT( ord.order_date, %s ) AS order_date, \n";
717 $qstr .= "ord.order_modified AS order_modified, \n";
718 $qstr .= "ord.order_status AS estimate_status, \n";
719 $qstr .= "ord.order_status AS process_status, \n";
720
721 if ( $this->view_column['tracking_number'] ) {
722 $qstr .= "trac.meta_value AS tracking_number, \n";
723 }
724 $qstr .= "ord.order_payment_name AS payment_name, \n";
725
726 if ( $this->view_column['wc_trans_id'] ) {
727 $qstr .= "trans.meta_value AS wc_trans_id, \n";
728 }
729 $qstr .= "ord.order_status AS receipt_status, \n";
730 $qstr .= "ord.order_item_total_price AS item_total_price, \n";
731 $qstr .= "ord.order_getpoint AS getpoint \n,";
732 $qstr .= "ord.order_usedpoint AS usedpoint, \n";
733 $qstr .= "ord.order_discount AS discount, \n";
734 $qstr .= "ord.order_shipping_charge AS shipping_charge, \n";
735 $qstr .= "ord.order_cod_fee AS cod_fee, \n";
736 $qstr .= "ord.order_tax AS tax, \n";
737 $qstr .= "( ord.order_item_total_price - ord.order_usedpoint + ord.order_discount + ord.order_shipping_charge + ord.order_cod_fee + ord.order_tax ) AS total_price, \n";
738 $qstr .= "ord.order_delivery_method AS deli_method, \n";
739 $qstr .= "ord.order_delivery AS deli_name, \n";
740 $qstr .= "ord.order_delivery_time AS deli_time, \n";
741 $qstr .= "ord.order_delivery_date AS deli_date, \n";
742 $qstr .= "ord.order_delidue_date AS delidue_date, \n";
743 $qstr .= "ord.mem_id AS mem_id, \n";
744 $qstr .= "ord.order_name1 AS name1, \n";
745 $qstr .= "ord.order_name2 AS name2, \n";
746 $qstr .= "ord.order_name3 AS name3, \n";
747 $qstr .= "ord.order_name4 AS name4, \n";
748 $qstr .= "ord.order_zip AS zipcode, \n";
749
750 if ( $this->view_column['country'] ) {
751 $qstr .= "country.meta_value AS country, \n";
752 }
753 $qstr .= "ord.order_pref AS pref, \n";
754 $qstr .= "ord.order_address1 AS address1, \n";
755 $qstr .= "ord.order_address2 AS address2, \n";
756 $qstr .= "ord.order_address3 AS address3, \n";
757 $qstr .= "ord.order_tel AS tel, \n";
758 $qstr .= "ord.order_fax AS fax, \n";
759 $qstr .= "ord.order_email AS email, \n";
760 $qstr .= "ord.order_note AS note \n";
761 $qstr .= "{$cscs}";
762 $qstr .= "{$csod}";
763 $qstr = apply_filters( 'usces_filter_orderlist_sql_after_note', $qstr, $this );
764
765 if ( defined( 'WCEX_AUTO_DELIVERY' ) && version_compare( WCEX_AUTO_DELIVERY_VERSION, '1.4.0', '>=' ) ) {
766 $qstr .= ", IFNULL( reg_id, '' ) AS `reg_parent_id` \n";
767 // $qstr .= "IFNULL( rmeta2.meta_value, '' ) AS `acting_zeus_card` \n";
768 }
769
770 $qstr .= "FROM {$this->table} AS ord \n";
771
772 $query = $wpdb->prepare( $qstr, '%Y-%m-%d %H:%i:%s' );
773 $query = apply_filters( 'usces_filter_orderlist_sql_select', $query, $cscs, $csod, $this );
774
775 $aq = $query . $join . $where . $group . $having;
776 $cquery = "SELECT COUNT(*) AS ct FROM (" . $aq . ") AS temp";
777
778 if ( 'on' == $this->pageLimit ) {
779 $query .= $join . $where . $group . $having . $order . " LIMIT " . $this->startRow . ", " . $this->maxRow;
780 } else {
781 $query .= $join . $where . $group . $having . $order;
782 }
783
784 if ( $this->placeholder_escape ) {
785 add_filter( 'query', array( $this, 'remove_ph' ) );
786 }
787
788 $ct = $wpdb->get_var( $cquery );
789 $this->selectedRow = $ct;
790
791 $rows = $wpdb->get_results( $query, ARRAY_A );
792 $this->rows = $rows;
793
794 if ( 'on' == $this->pageLimit ) {
795 $this->currentPageIds = array();
796 foreach ( $this->rows as $row ) {
797 $this->currentPageIds[] = $row['ID'];
798 }
799 }
800
801 return $this->rows;
802 }
803
804 /**
805 * Placeholder clear.
806 *
807 * @param string $query Query.
808 * @return string
809 */
810 public function remove_ph( $query ) {
811 return str_replace( $this->placeholder_escape, '%', $query );
812 }
813
814 /**
815 * Set Total Rows.
816 */
817 public function SetTotalRow() {
818 global $wpdb;
819 $query = "SELECT COUNT(ID) AS `ct` FROM {$this->table}" . apply_filters( 'usces_filter_orderlist_sql_where', '', $this );
820 $query = apply_filters( 'usces_filter_orderlist_set_total_row', $query, $this );
821 $res = $wpdb->get_var( $query );
822 $this->totalRow = $res;
823 }
824
825 /**
826 * Having Condition.
827 *
828 * @return string
829 */
830 public function GetHaving() {
831 global $wpdb;
832
833 $lastmonth_s = date_i18n( 'Y-m-d H:i:s', mktime( 0, 0, 0, ( current_time( 'n' ) - 1 ), 1, current_time( 'Y' ) ) );
834 $lastmonth_e = date_i18n( 'Y-m-d H:i:s', mktime( 23, 59, 59, current_time( 'n' ), 0, current_time( 'Y' ) ) );
835 $thismonth = date_i18n( 'Y-m-d H:i:s', mktime( 0, 0, 0, current_time( 'n' ), 1, current_time( 'Y' ) ) );
836
837 $query = '';
838 if ( 1 == $this->period['period'] ) {
839
840 $query = $wpdb->prepare( " order_date >= %s ", $thismonth );
841
842 } elseif ( 2 == $this->period['period'] ) {
843
844 $query = $wpdb->prepare( " order_date >= %s AND order_date <= %s ", $lastmonth_s, $lastmonth_e );
845
846 } elseif ( 3 == $this->period['period'] ) {
847
848 $start = $this->period['start'] . ' 00:00:00';
849 $end = $this->period['end'] . ' 23:59:59';
850 if ( ! empty( $this->period['start'] ) && ! empty( $this->period['end'] ) ) {
851
852 $query = $wpdb->prepare( " order_date >= %s AND order_date <= %s ", $start, $end );
853
854 } elseif ( empty( $this->period['start'] ) && ! empty( $this->period['end'] ) ) {
855
856 $query = $wpdb->prepare( " order_date <= %s ", $end );
857
858 } elseif ( ! empty( $this->period['start'] ) && empty( $this->period['end'] ) ) {
859
860 $query = $wpdb->prepare( " order_date >= %s ", $start );
861
862 }
863 }
864
865 $str = '';
866
867 if ( ! WCUtils::is_blank( $this->searchHaving ) ) {
868 if ( ! WCUtils::is_blank( $query ) ) {
869 $str .= ' HAVING ' . $this->searchHaving . ' AND ' . $query;
870 } else {
871 $str .= ' HAVING ' . $this->searchHaving;
872 }
873 } else {
874 if ( ! WCUtils::is_blank( $query ) ) {
875 $str .= ' HAVING ' . $query;
876 }
877 }
878 $str = apply_filters( 'usces_filter_orderlist_sql_having', $str, $query, $this->searchHaving, $this->period, $this );
879 return $str;
880 }
881
882 /**
883 * Where Condition.
884 *
885 * @return string
886 */
887 public function GetWhere() {
888 $str = '';
889 if ( ! WCUtils::is_blank( $this->searchWhere ) ) {
890 $str .= ' WHERE ' . $this->searchWhere;
891 }
892 $str = apply_filters( 'usces_filter_orderlist_sql_where', $str, $this );
893 return $str;
894 }
895
896 /**
897 * Search.
898 */
899 public function SearchIn() {
900 global $wpdb;
901
902 $arr_mail_print_fields = get_option( 'usces_order_mail_print_fields', array() );
903 $print_mail_column = 'order_check';
904 $this->searchWhere = '';
905 $this->searchHaving = '';
906
907 if ( ! empty( $this->arr_search['order_column'][0] ) && ! WCUtils::is_blank( $this->arr_search['order_word'][0] ) ) {
908 $result_order_term_0 = $this->build_condition_order_word_term( $this->arr_search['order_word_term'][0], $this->arr_search['order_word'][0], $this->arr_search['order_column'][0] );
909 $wordterm0 = $result_order_term_0['term'];
910 $word0 = $result_order_term_0['word'];
911
912 $this->searchHaving .= ' ( ';
913
914 if ( 'estimate_status' == $this->arr_search['order_column'][0] && 'frontorder' == $this->arr_search['order_word'][0] ) {
915 $search_estimate_status = apply_filters( 'usces_filter_orderlist_search_estimate_status', array( "%adminorder%", "%estimate%" ) );
916 $and = '';
917 $this->searchHaving .= '( ';
918 foreach ( $search_estimate_status as $status ) {
919 $this->searchHaving .= $and . esc_sql( $this->arr_search['order_column'][0] ) . " NOT LIKE '" . $status . "'";
920 $and = ' AND ';
921 }
922 $this->searchHaving .= ' ) ';
923
924 } elseif ( 'process_status' == $this->arr_search['order_column'][0] && 'neworder' == $this->arr_search['order_word'][0] ) {
925 $search_process_status = apply_filters( 'usces_filter_orderlist_search_process_status', array( "%duringorder%", "%cancel%", "%completion%" ) );
926 $and = '';
927 $this->searchHaving .= '( ';
928 foreach ( $search_process_status as $status ) {
929 $this->searchHaving .= $and . esc_sql( $this->arr_search['order_column'][0] ) . " NOT LIKE '" . $status . "'";
930 $and = ' AND ';
931 }
932 $this->searchHaving .= ' ) ';
933
934 } elseif ( 'cscs_' == substr( $this->arr_search['order_column'][0], 0, 5 ) || 'csod_' == substr( $this->arr_search['order_column'][0], 0, 5) ) {
935 $this->searchHaving .= $wpdb->prepare( '`p' . esc_sql( $this->arr_search['order_column'][0] ) . '`.meta_value' . $wordterm0, $word0 );
936
937 } elseif ( array_key_exists( $this->arr_search['order_column'][0], $arr_mail_print_fields ) ) {
938 if ( empty( $this->arr_search['order_word'][0] ) ) {
939 $cond_oc_0 = $print_mail_column . ' NOT LIKE %s OR ' . $print_mail_column . ' IS NULL ';
940 } else {
941 $cond_oc_0 = $print_mail_column . ' LIKE %s ';
942 }
943 $word_oc_0 = '%' . esc_sql( $this->arr_search['order_column'][0] ) . '%';
944 $this->searchHaving .= '( ' . $wpdb->prepare( $cond_oc_0, $word_oc_0 ) . ' ) ';
945 } else {
946 $is_date_column = $this->is_date_column( $this->arr_search['order_column'][0] );
947 if ( $is_date_column ) {
948 $order_column = esc_sql( $this->arr_search['order_column'][0] );
949 $date_condition = '(STR_TO_DATE(' . $order_column . ', %s) IS NOT NULL AND ';
950 $date_condition .= $order_column . ' != "" AND ';
951 $date_condition .= 'SUBSTRING(' . $order_column . ', 1, 10)' . $wordterm0 . ')';
952 $this->searchHaving .= $wpdb->prepare( $date_condition, '%Y-%m-%d', $word0 );
953 } else {
954 $this->searchHaving .= $wpdb->prepare( esc_sql( $this->arr_search['order_column'][0] ) . $wordterm0, $word0 );
955 }
956 }
957
958 if ( ! empty( $this->arr_search['order_column'][1] ) && ! WCUtils::is_blank( $this->arr_search['order_word'][1] ) ) {
959 $result_order_term_1 = $this->build_condition_order_word_term( $this->arr_search['order_word_term'][1], $this->arr_search['order_word'][1], $this->arr_search['order_column'][1] );
960 $wordterm1 = $result_order_term_1['term'];
961 $word1 = $result_order_term_1['word'];
962
963 $this->searchHaving .= ' ' . $this->arr_search['order_term'] . ' ';
964 if ( 'estimate_status' == $this->arr_search['order_column'][1] && 'frontorder' == $this->arr_search['order_word'][1] ) {
965 $search_estimate_status = apply_filters( 'usces_filter_orderlist_search_estimate_status', array( "%adminorder%", "%estimate%" ) );
966 $and = '';
967 $this->searchHaving .= '( ';
968 foreach ( $search_estimate_status as $status ) {
969 $this->searchHaving .= $and . esc_sql( $this->arr_search['order_column'][1] ) . " NOT LIKE '" . $status . "'";
970 $and = ' AND ';
971 }
972 $this->searchHaving .= ' ) ';
973
974 } elseif ( 'process_status' == $this->arr_search['order_column'][1] && 'neworder' == $this->arr_search['order_word'][1] ) {
975 $search_process_status = apply_filters( 'usces_filter_orderlist_search_process_status', array( "%duringorder%", "%cancel%", "%completion%" ) );
976 $and = '';
977 $this->searchHaving .= '( ';
978 foreach ( $search_process_status as $status ) {
979 $this->searchHaving .= $and . esc_sql( $this->arr_search['order_column'][1] ) . " NOT LIKE '" . $status . "'";
980 $and = ' AND ';
981 }
982 $this->searchHaving .= ' ) ';
983
984 } elseif ( 'cscs_' == substr( $this->arr_search['order_column'][1], 0, 5 ) || 'csod_' == substr( $this->arr_search['order_column'][1], 0, 5 ) ) {
985 $this->searchHaving .= $wpdb->prepare( '`p' . esc_sql( $this->arr_search['order_column'][1] ) . '`.meta_value' . $wordterm1, $word1 );
986
987 } elseif ( array_key_exists( $this->arr_search['order_column'][1], $arr_mail_print_fields ) ) {
988 if ( empty( $this->arr_search['order_word'][1] ) ) {
989 $cond_oc_1 = $print_mail_column . ' NOT LIKE %s OR ' . $print_mail_column . ' IS NULL ';
990 } else {
991 $cond_oc_1 = $print_mail_column . ' LIKE %s ';
992 }
993 $word_oc_1 = '%' . esc_sql( $this->arr_search['order_column'][1] ) . '%';
994 $this->searchHaving .= '( ' . $wpdb->prepare( $cond_oc_1, $word_oc_1 ) . ' ) ';
995 } else {
996 $is_date_column = $this->is_date_column( $this->arr_search['order_column'][1] );
997 if ( $is_date_column ) {
998 $order_column = esc_sql( $this->arr_search['order_column'][1] );
999 $date_condition = '(STR_TO_DATE(' . $order_column . ', %s) IS NOT NULL AND ';
1000 $date_condition .= $order_column . ' != "" AND ';
1001 $date_condition .= 'SUBSTRING(' . $order_column . ', 1, 10)' . $wordterm1 . ')';
1002 $this->searchHaving .= $wpdb->prepare( $date_condition, '%Y-%m-%d', $word1 );
1003 } else {
1004 $this->searchHaving .= $wpdb->prepare( esc_sql( $this->arr_search['order_column'][1] ) . $wordterm1, $word1 );
1005 }
1006 }
1007 }
1008
1009 $this->searchHaving .= ' ) ';
1010 }
1011
1012 if ( ! empty( $this->arr_search['product_column'][0] ) && ! WCUtils::is_blank( $this->arr_search['product_word'][0] ) ) {
1013
1014 switch ( $this->arr_search['product_word_term'][0] ) {
1015 case 'notcontain':
1016 $prowordterm0 = ' NOT LIKE %s';
1017 $proword0 = '%' . $this->arr_search['product_word'][0] . '%';
1018 break;
1019 case 'equal':
1020 $prowordterm0 = ' = %s';
1021 $proword0 = $this->arr_search['product_word'][0];
1022 break;
1023 case 'morethan':
1024 $prowordterm0 = ' > %d';
1025 $proword0 = $this->arr_search['product_word'][0];
1026 break;
1027 case 'lessthan':
1028 $prowordterm0 = ' < %d';
1029 $proword0 = $this->arr_search['product_word'][0];
1030 break;
1031 case 'contain':
1032 default:
1033 $prowordterm0 = ' LIKE %s';
1034 $proword0 = '%' . $this->arr_search['product_word'][0] . '%';
1035 break;
1036 }
1037
1038 switch ( $this->arr_search['product_word_term'][1] ) {
1039 case 'notcontain':
1040 $prowordterm1 = ' NOT LIKE %s';
1041 $proword1 = '%' . $this->arr_search['product_word'][1] . '%';
1042 break;
1043 case 'equal':
1044 $prowordterm1 = ' = %s';
1045 $proword1 = $this->arr_search['product_word'][1];
1046 break;
1047 case 'morethan':
1048 $prowordterm1 = ' > %d';
1049 $proword1 = $this->arr_search['product_word'][1];
1050 break;
1051 case 'lessthan':
1052 $prowordterm1 = ' < %d';
1053 $proword1 = $this->arr_search['product_word'][1];
1054 break;
1055 case 'contain':
1056 default:
1057 $prowordterm1 = ' LIKE %s';
1058 $proword1 = '%' . $this->arr_search['product_word'][1] . '%';
1059 break;
1060 }
1061
1062 $this->searchWhere .= ' ( ';
1063
1064 if ( 'item_option' == $this->arr_search['product_column'][0] ) {
1065 $this->searchWhere .= $wpdb->prepare( '( itemopt.meta_key LIKE %s AND itemopt.meta_value LIKE %s )' , '%' . $this->arr_search['product_word'][0] . '%' , '%' . $this->arr_search['option_word'][0] . '%' );
1066 } else {
1067 $this->searchWhere .= $wpdb->prepare( esc_sql( $this->arr_search['product_column'][0] ) . $prowordterm0, $proword0 );
1068 }
1069
1070 if ( ! empty( $this->arr_search['product_column'][1] ) && ! WCUtils::is_blank( $this->arr_search['product_word'][1] ) ) {
1071 $this->searchWhere .= ' ' . $this->arr_search['product_term'] . ' ';
1072 if ( 'item_option' == $this->arr_search['product_column'][1] ) {
1073 $this->searchWhere .= $wpdb->prepare( '( itemopt.meta_key LIKE %s AND itemopt.meta_value LIKE %s )' , '%' . $this->arr_search['product_word'][1] . '%' , '%' . $this->arr_search['option_word'][1] . '%' );
1074 } else {
1075 $this->searchWhere .= $wpdb->prepare( esc_sql( $this->arr_search['product_column'][1] ) . $prowordterm1, $proword1 );
1076 }
1077 }
1078
1079 $this->searchWhere .= ' ) ';
1080 }
1081 }
1082
1083 /**
1084 * Check if the column is date type or not.
1085 *
1086 * @param string $column_name the column name of order.
1087 *
1088 * @return bool true/false
1089 */
1090 public function is_date_column( $column_name ) {
1091 return in_array( $column_name, array( 'order_date', 'order_modified', 'deli_date', 'delidue_date' ), true );
1092 }
1093
1094 /**
1095 * Check if the column is order status or not.
1096 *
1097 * @param string $column_name the column name of order.
1098 * @return bool true/false
1099 */
1100 public function is_status_column( $column_name ) {
1101 return in_array( $column_name, array( 'estimate_status', 'process_status', 'receipt_status' ), true );
1102 }
1103
1104 /**
1105 * Build condition from order word term.
1106 *
1107 * @param string $order_word_term type order word term.
1108 * @param string $order_word value order word.
1109 * @param string $order_column value order column.
1110 *
1111 * @return array
1112 */
1113 public function build_condition_order_word_term( $order_word_term, $order_word, $order_column ) {
1114 $is_date_column = $this->is_date_column( $order_column );
1115
1116 switch ( $order_word_term ) {
1117 case 'notcontain':
1118 if ( 'deli_method' == $order_column ) {
1119 $term = ' NOT IN (%d)';
1120 $word = $order_word;
1121 } elseif ( $is_date_column ) {
1122 $term = ' != %s';
1123 $word = $order_word;
1124 } else {
1125 $term = ' NOT LIKE %s';
1126 $word = '%' . $order_word . '%';
1127 }
1128 break;
1129 case 'equal':
1130 $is_status_column = $this->is_status_column( $order_column );
1131 if ( 'deli_method' == $order_column ) {
1132 $term = ' = %d ';
1133 $word = $order_word;
1134 } elseif ( $is_date_column ) {
1135 $term = ' = %s';
1136 $word = $order_word;
1137 } elseif ( $is_status_column ) {
1138 $term = ' LIKE %s';
1139 $word = '%' . $order_word . '%';
1140 } else {
1141 $term = ' = %s';
1142 $word = $order_word;
1143 }
1144 break;
1145 case 'morethan':
1146 if ( 'deli_method' == $order_column ) {
1147 $term = ' = %d ';
1148 $word = $order_word;
1149 } elseif ( $is_date_column ) {
1150 $term = ' > %s';
1151 $word = $order_word;
1152 } else {
1153 $term = ' > %d';
1154 $word = $order_word;
1155 }
1156 break;
1157 case 'lessthan':
1158 if ( 'deli_method' == $order_column ) {
1159 $term = ' = %d ';
1160 $word = $order_word;
1161 } elseif ( $is_date_column ) {
1162 $term = ' < %s';
1163 $word = $order_word;
1164 } else {
1165 $term = ' < %d';
1166 $word = $order_word;
1167 }
1168 break;
1169 case 'contain':
1170 default:
1171 if ( 'deli_method' == $order_column ) {
1172 $term = ' IN (%d)';
1173 $word = $order_word;
1174 } else {
1175 $term = ' LIKE %s';
1176 $word = '%' . $order_word . '%';
1177 }
1178 break;
1179 }
1180
1181 return array(
1182 'term' => $term,
1183 'word' => $word,
1184 );
1185 }
1186
1187 /**
1188 * Search clear.
1189 */
1190 public function SearchOut() {
1191 $this->searchWhere = '';
1192 $this->searchHaving = '';
1193 }
1194
1195 /**
1196 * Set Navigation.
1197 */
1198 public function SetNavi() {
1199 $this->lastPage = ceil( $this->selectedRow / $this->maxRow );
1200 $this->previousPage = ( $this->currentPage - 1 == 0 ) ? 1 : $this->currentPage - 1;
1201 $this->nextPage = ( $this->currentPage + 1 > $this->lastPage ) ? $this->lastPage : $this->currentPage + 1;
1202 $box = array();
1203
1204 for ( $i = 0; $i < $this->naviMaxButton; $i++ ) {
1205 if ( $i > $this->lastPage - 1 ) {
1206 break;
1207 }
1208 if ( $this->lastPage <= $this->naviMaxButton ) {
1209 $box[] = $i + 1;
1210 } else {
1211 if ( $this->currentPage <= 6) {
1212 $label = $i + 1;
1213 $box[] = $label;
1214 } else {
1215 $label = $i + 1 + $this->currentPage - 6;
1216 $box[] = $label;
1217 if ( $label == $this->lastPage ) {
1218 break;
1219 }
1220 }
1221 }
1222 }
1223
1224 $html = '';
1225 $html .= '<ul class="clearfix">';
1226 $html .= '<li class="rowsnum">' . $this->selectedRow . ' / ' . $this->totalRow . ' ' . __( 'cases', 'usces' ) . '</li>';
1227 if ( ( 1 == $this->currentPage ) || ( 0 == $this->selectedRow ) ) {
1228 $html .= '<li class="navigationStr">first&lt;&lt;</li>';
1229 $html .= '<li class="navigationStr">prev&lt;</li>';
1230 } else {
1231 $url = admin_url( 'admin.php?page=usces_orderlist&changePage=1' );
1232 $nonce_url = wp_nonce_url( $url, 'order_list', 'wc_nonce' );
1233 $html .= '<li class="navigationStr"><a href="' . $nonce_url . '">first&lt;&lt;</a></li>';
1234
1235 $url = admin_url( 'admin.php?page=usces_orderlist&changePage=' . $this->previousPage );
1236 $nonce_url = wp_nonce_url( $url, 'order_list', 'wc_nonce' );
1237 $html .= '<li class="navigationStr"><a href="' . $nonce_url . '">prev&lt;</a></li>';
1238 }
1239 if ( $this->selectedRow > 0 ) {
1240 $box_count = count( $box );
1241 for ( $i = 0; $i < $box_count; $i++ ) {
1242 if ( $box[ $i ] == $this->currentPage ) {
1243 $html .= '<li class="navigationButtonSelected"><span>' . $box[ $i ] . '</span></li>';
1244 } else {
1245 $url = admin_url( 'admin.php?page=usces_orderlist&changePage=' . $box[ $i ] );
1246 $nonce_url = wp_nonce_url( $url, 'order_list', 'wc_nonce' );
1247 $html .= '<li class="navigationButton"><a href="' . $nonce_url . '">' . $box[ $i ] . '</a></li>';
1248 }
1249 }
1250 }
1251
1252 if ( ( $this->currentPage == $this->lastPage ) || ( 0 == $this->selectedRow ) ) {
1253 $html .= '<li class="navigationStr">&gt;next</li>';
1254 $html .= '<li class="navigationStr">&gt;&gt;last</li>';
1255 } else {
1256 $url = admin_url( 'admin.php?page=usces_orderlist&changePage=' . $this->nextPage );
1257 $nonce_url = wp_nonce_url( $url, 'order_list', 'wc_nonce' );
1258 $html .= '<li class="navigationStr"><a href="' . $nonce_url . '">&gt;next</a></li>';
1259
1260 $url = admin_url( 'admin.php?page=usces_orderlist&changePage=' . $this->lastPage );
1261 $nonce_url = wp_nonce_url( $url, 'order_list', 'wc_nonce' );
1262 $html .= '<li class="navigationStr"><a href="' . $nonce_url . '">&gt;&gt;last</a></li>';
1263 }
1264 $html .= '</ul>';
1265
1266 $this->dataTableNavigation = $html;
1267 }
1268
1269 /**
1270 * Get Cookie.
1271 */
1272 public function getCookie() {
1273 $this->data_cookie = ( isset( $_COOKIE[ $this->table ] ) ) ? json_decode( str_replace( "\'", "'", str_replace( '\"', '"', $_COOKIE[ $this->table ] ) ), true ) : array();
1274 }
1275
1276 /**
1277 * Set Headers.
1278 */
1279 public function SetHeaders() {
1280 $arr_mail_print_fields = get_option( 'usces_order_mail_print_fields', array() );
1281 foreach ( $this->columns as $key => $value ) {
1282 if ( 'admin_memo' == $key ) {
1283 continue;
1284 }
1285 if ( array_key_exists( $key, $arr_mail_print_fields ) ) {
1286 $value = $arr_mail_print_fields[ $key ]['alias'];
1287 }
1288 if ( $key == $this->sortColumn ) {
1289 if ( isset( $this->sortSwitchs[ $key ] ) && 'ASC' == $this->sortSwitchs[ $key ] ) {
1290 $str = __( '[ASC]', 'usces' );
1291 $switch = 'DESC';
1292 } else {
1293 $str = __( '[DESC]', 'usces' );
1294 $switch = 'ASC';
1295 }
1296 $url = admin_url( 'admin.php?page=usces_orderlist&changeSort=' . $key . '&switch=' . $switch );
1297 $nonce_url = wp_nonce_url( $url, 'order_list', 'wc_nonce' );
1298 $this->headers[ $key ] = '<a href="' . $nonce_url . '"><span class="sortcolumn">' . $value . ' ' . $str . '</span></a>';
1299 } else {
1300 $switch = isset( $this->sortSwitchs[ $key ] ) ? $this->sortSwitchs[ $key ] : 'DESC';
1301 $url = admin_url( 'admin.php?page=usces_orderlist&changeSort=' . $key . '&switch=' . $switch );
1302 $nonce_url = wp_nonce_url( $url, 'order_list', 'wc_nonce' );
1303 $this->headers[ $key ] = '<a href="' . $nonce_url . '"><span>' . $value . '</span></a>';
1304 }
1305 }
1306 }
1307
1308 /**
1309 * Get Search.
1310 *
1311 * @return string
1312 */
1313 public function GetSearchs() {
1314 return $this->arr_search;
1315 }
1316
1317 /**
1318 * Get Headers.
1319 *
1320 * @return string
1321 */
1322 public function GetListheaders() {
1323 return $this->headers;
1324 }
1325
1326 /**
1327 * Get Navigation.
1328 *
1329 * @return string
1330 */
1331 public function GetDataTableNavigation() {
1332 return $this->dataTableNavigation;
1333 }
1334
1335 /**
1336 * Set Action Status and Action Message.
1337 *
1338 * @param string $status Action status.
1339 * @param string $message Action message.
1340 */
1341 public function set_action_status( $status, $message ) {
1342 $this->action_status = $status;
1343 $this->action_message = $message;
1344 }
1345
1346 /**
1347 * Get Action Status.
1348 *
1349 * @return string
1350 */
1351 public function get_action_status() {
1352 return $this->action_status;
1353 }
1354
1355 /**
1356 * Get Action Message.
1357 *
1358 * @return string
1359 */
1360 public function get_action_message() {
1361 return $this->action_message;
1362 }
1363 }
1364