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 / orderList.class.php

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

835 lines 34.7 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 * - Old type.
5 *
6 * @package Welcart
7 */
8 class dataList {
9 var $table; /* テーブル名 */
10 var $rows; /* データ */
11 var $action; /* アクション */
12 var $startRow; /* 表示開始行番号 */
13 var $maxRow; /* 最大表示行数 */
14 var $currentPage; /* 現在のページNo */
15 var $firstPage; /* 最初のページNo */
16 var $previousPage; /* 前のページNo */
17 var $nextPage; /* 次のページNo */
18 var $lastPage; /* 最終ページNo */
19 var $naviMaxButton; /* ページネーション・ナビのボタンの数 */
20 var $dataTableNavigation; /* ナヴィゲーションhtmlコード */
21 var $arr_period; /* 表示データ期間 */
22 var $arr_search; /* サーチ条件 */
23 var $searchSql; /* 簡易絞込みSQL */
24 var $searchSkuSql; /* SKU絞り込み */
25 var $searchSwitchStatus; /* サーチ表示スイッチ */
26 var $columns; /* データカラム */
27 var $sortColumn; /* 現在ソート中のフィールド */
28 var $sortOldColumn;
29 var $sortSwitchs; /* 各フィールド毎の昇順降順スイッチ */
30 var $userHeaderNames; /* ユーザー指定のヘッダ名 */
31 var $action_status, $action_message;
32 var $pageLimit; /* ページ制限 */
33 var $management_status; /* 処理ステータス */
34 var $selectSql;
35 var $joinTableSql;
36 var $period_initial_index;
37 var $period_specified_index;
38 var $placeholder_escape;
39 var $data_cookie;
40 var $startdate;
41 var $enddate;
42
43 public $listOption;
44 public $totalRow;
45 public $selectedRow;
46 public $headers;
47
48 /**
49 * Constructor.
50 *
51 * @param string $tableName Table name.
52 * @param array $arr_column Column.
53 */
54 public function __construct( $tableName, $arr_column ) {
55 $this->table = $tableName;
56 $this->columns = $arr_column;
57 $this->rows = array();
58
59 $this->maxRow = apply_filters( 'usces_filter_orderlist_maxrow', 30 );
60 $this->naviMaxButton = 11;
61 $this->firstPage = 1;
62 $this->action_status = 'none';
63 $this->action_message = '';
64 $this->pageLimit = 'on';
65 $this->selectSql = '';
66 $this->joinTableSql = '';
67
68 $this->period_initial_index = apply_filters( 'usces_filter_order_list_arr_period_initial_index', 3, $this );
69 $this->period_specified_index = apply_filters( 'usces_filter_order_list_arr_period_specified_index', 6, $this );
70
71 $this->getCookie();
72 $this->SetDefaultParam();
73 $this->SetParamByQuery();
74 $this->validationSearchParameters();
75
76 $arr_period = array(
77 __( 'This month', 'usces' ),
78 __( 'Last month', 'usces' ),
79 __( 'The past one week', 'usces' ),
80 __( 'Last 30 days', 'usces' ),
81 __( 'Last 90days', 'usces' ),
82 __( 'All', 'usces' ),
83 __( 'Period specified', 'usces' ),
84 );
85 $this->arr_period = apply_filters( 'usces_filter_order_list_arr_period', $arr_period, $this );
86
87 $management_status = array(
88 'duringorder' => __( 'temporaly out of stock', 'usces' ),
89 'cancel' => __( 'Cancel', 'usces' ),
90 'completion' => __( 'It has sent it out.', 'usces' ),
91 'estimate' => __( 'An estimate', 'usces' ),
92 'adminorder' => __( 'Management of Note', 'usces' ),
93 'continuation' => __( 'Continuation', 'usces' ),
94 'termination' => __( 'Termination', 'usces' ),
95 );
96 $this->management_status = apply_filters( 'usces_filter_management_status', $management_status, $this );
97
98 $this->SetSelects();
99 $this->SetJoinTables();
100 }
101
102 /**
103 * Set Selects.
104 */
105 public function SetSelects() {
106 global $wpdb;
107
108 $status_sql = '';
109 foreach ( $this->management_status as $status_key => $status_name ) {
110 $status_sql .= $wpdb->prepare( " WHEN LOCATE( %s, order_status ) > 0 THEN %s", $status_key, $status_name );
111 }
112
113 if ( defined( 'WCEX_AUTO_DELIVERY' ) && version_compare( WCEX_AUTO_DELIVERY_VERSION, '1.4.0', '>=' ) ) {
114 $select = array(
115 "ID",
116 "meta1.meta_value AS `deco_id`",
117 "IFNULL( reg_id, meta2.meta_value ) AS `reg_id`",
118 "DATE_FORMAT( order_date, '%Y-%m-%d %H:%i' ) AS `date`",
119 "mem_id",
120 "CONCAT( order_name1, ' ', order_name2 ) AS `name`",
121 "order_pref AS `pref`",
122 "order_delivery_method AS `delivery_method`",
123 "( order_item_total_price - order_usedpoint + order_discount + order_shipping_charge + order_cod_fee + order_tax ) AS `total_price`",
124 "order_payment_name AS `payment_name`",
125 "CASE WHEN LOCATE( 'noreceipt', order_status ) > 0 THEN '" . __( 'unpaid', 'usces' ) . "'
126 WHEN LOCATE( 'receipted', order_status ) > 0 THEN '" . __( 'payment confirmed', 'usces' ) . "'
127 WHEN LOCATE( 'pending', order_status ) > 0 THEN '" . __( 'Pending', 'usces' ) . "'
128 ELSE '&nbsp;'
129 END AS `receipt_status`",
130 "CASE {$status_sql}
131 ELSE '" . __( 'new order', 'usces' ) . "'
132 END AS `order_status`",
133 "order_modified",
134 "IFNULL( reg_id, '' ) AS `reg_parent_id`",
135 "IFNULL( meta3.meta_value, '' ) AS `acting_zeus_card`",
136 );
137 } else {
138 $select = array(
139 "ID",
140 "meta.meta_value AS `deco_id`",
141 "DATE_FORMAT( order_date, '%Y-%m-%d %H:%i' ) AS `date`",
142 "mem_id",
143 "CONCAT( order_name1, ' ', order_name2 ) AS `name`",
144 "order_pref AS `pref`",
145 "order_delivery_method AS `delivery_method`",
146 "( order_item_total_price - order_usedpoint + order_discount + order_shipping_charge + order_cod_fee + order_tax ) AS `total_price`",
147 "order_payment_name AS `payment_name`",
148 "CASE WHEN LOCATE( 'noreceipt', order_status) > 0 THEN '" . __( 'unpaid', 'usces' ) . "'
149 WHEN LOCATE( 'receipted', order_status) > 0 THEN '" . __( 'payment confirmed', 'usces' ) . "'
150 WHEN LOCATE( 'pending', order_status) > 0 THEN '" . __( 'Pending', 'usces' ) . "'
151 ELSE '&nbsp;'
152 END AS `receipt_status`",
153 "CASE {$status_sql}
154 ELSE '" . __( 'new order', 'usces' ) . "'
155 END AS `order_status`",
156 "order_modified",
157 );
158 }
159 $this->selectSql = apply_filters( 'usces_filter_order_list_sql_select', $select, $status_sql, $this );
160 }
161
162 /**
163 * Set Join Tables.
164 */
165 public function SetJoinTables() {
166 global $wpdb;
167 $meta_table = $wpdb->prefix . 'usces_order_meta';
168 $ordercart_table = $wpdb->prefix . 'usces_ordercart';
169 $ordercartmeta_table = $wpdb->prefix . 'usces_ordercart_meta';
170 if ( defined( 'WCEX_AUTO_DELIVERY' ) && version_compare( WCEX_AUTO_DELIVERY_VERSION, '1.4.0', '>=' ) ) {
171 $regular_table = $wpdb->prefix . 'usces_regular';
172 $join_table = array(
173 "LEFT JOIN {$meta_table} AS `meta1` ON ID = meta1.order_id AND meta1.meta_key = 'dec_order_id' ",
174 "LEFT JOIN {$meta_table} AS `meta2` ON ID = meta2.order_id AND meta2.meta_key = 'regular_id' ",
175 "LEFT JOIN {$meta_table} AS `meta3` ON ID = meta3.order_id AND meta3.meta_key = 'acting_zeus_card' ",
176 "LEFT JOIN {$ordercart_table} AS `cart` ON ID = cart.order_id ",
177 "LEFT JOIN {$regular_table} ON ID = reg_order_id ",
178 );
179 } else {
180 $join_table = array(
181 " LEFT JOIN {$meta_table} AS `meta` ON ID = meta.order_id AND meta.meta_key = 'dec_order_id'" . " \n",
182 " LEFT JOIN {$ordercart_table} AS `cart` ON ID = cart.order_id" . " \n",
183 );
184 }
185 $this->joinTableSql = apply_filters( 'usces_filter_order_list_sql_jointable', $join_table, $meta_table, $this );
186 }
187
188 /**
189 * Action.
190 *
191 * @return mixed
192 */
193 public function MakeTable() {
194 $this->SetParam();
195 switch ( $this->action ) {
196
197 case 'searchOut':
198 $this->SearchOut();
199 $res = $this->GetRows();
200 break;
201
202 case 'collective_order_reciept':
203 check_admin_referer( 'order_list', 'wc_nonce' );
204 usces_all_change_order_reciept( $this );
205 $res = $this->GetRows();
206 break;
207
208 case 'collective_order_status':
209 check_admin_referer( 'order_list', 'wc_nonce' );
210 usces_all_change_order_status( $this );
211 $res = $this->GetRows();
212 break;
213
214 case 'collective_delete':
215 check_admin_referer( 'order_list', 'wc_nonce' );
216 usces_all_delete_order_data( $this );
217 $this->SetTotalRow();
218 $res = $this->GetRows();
219 break;
220
221 case 'searchIn':
222 case 'refresh':
223 case 'returnList':
224 case 'changeSort':
225 case 'changePage':
226 default:
227 $this->SearchIn();
228 $res = $this->GetRows();
229 break;
230 }
231
232 $this->SetNavi();
233 $this->SetHeaders();
234
235 if ( $res ) {
236 return true;
237 } else {
238 return false;
239 }
240 }
241
242 /**
243 * Default Parameters.
244 */
245 public function SetDefaultParam() {
246 $this->startRow = isset( $this->data_cookie['startRow'] ) ? $this->data_cookie['startRow'] : 0;
247 $this->currentPage = isset( $this->data_cookie['currentPage'] ) ? $this->data_cookie['currentPage'] : 1;
248 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : 'ID';
249 $this->searchSwitchStatus = ( isset( $this->data_cookie['searchSwitchStatus'] ) ) ? $this->data_cookie['searchSwitchStatus'] : 'OFF';
250 $this->searchSql = ( isset( $this->data_cookie['searchSql'] ) ) ? $this->data_cookie['searchSql'] : '';
251 $this->searchSkuSql = ( isset( $this->data_cookie['searchSkuSql'] ) ) ? $this->data_cookie['searchSkuSql'] : '';
252 if ( isset( $this->data_cookie['arr_search'] ) ) {
253 $this->arr_search = $this->data_cookie['arr_search'];
254 } else {
255 $arr_search = array(
256 'period' => $this->period_initial_index,
257 'column' => '',
258 'word' => '',
259 'sku' => '',
260 'skuword' => '',
261 );
262 $this->arr_search = apply_filters( 'usces_filter_order_list_arr_search', $arr_search, $this );
263 }
264 if ( isset( $this->data_cookie['sortSwitchs'] ) ) {
265 $this->sortSwitchs = $this->data_cookie['sortSwitchs'];
266 } else {
267 foreach ( $this->columns as $key => $value ) {
268 $this->sortSwitchs[ $value ] = 'DESC';
269 }
270 }
271 $this->startdate = ( isset( $_REQUEST['startdate'] ) ) ? $_REQUEST['startdate'] : ( ( isset( $this->data_cookie['startdate'] ) ) ? $this->data_cookie['startdate'] : '' );
272 $this->enddate = ( isset( $_REQUEST['enddate'] ) ) ? $_REQUEST['enddate'] : ( ( isset( $this->data_cookie['enddate'] ) ) ? $this->data_cookie['enddate'] : '' );
273 $this->SetTotalRow();
274 }
275
276 /**
277 * Set Parameters.
278 */
279 public function SetParam() {
280 $this->startRow = ( $this->currentPage - 1 ) * $this->maxRow;
281 }
282
283 /**
284 * Set Parameters.
285 */
286 public function SetParamByQuery() {
287 global $wpdb;
288 if ( isset( $_REQUEST['changePage'] ) ) {
289
290 $this->action = 'changePage';
291 $this->currentPage = (int) $_REQUEST['changePage'];
292 $this->sortColumn = ( isset( $data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
293 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
294 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
295 $this->searchSwitchStatus = ( isset( $this->data_cookie['searchSwitchStatus'] ) ) ? $this->data_cookie['searchSwitchStatus'] : $this->searchSwitchStatus;
296 $this->searchSql = ( isset( $this->data_cookie['searchSql'] ) ) ? $this->data_cookie['searchSql'] : $this->searchSql;
297 $this->searchSkuSql = ( isset( $this->data_cookie['searchSkuSql'] ) ) ? $this->data_cookie['searchSkuSql'] : $this->searchSkuSql;
298 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
299 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
300 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
301 $this->placeholder_escape = ( isset( $this->data_cookie['placeholder_escape'] ) ) ? $this->data_cookie['placeholder_escape'] : $this->placeholder_escape;
302
303 } elseif ( isset( $_REQUEST['changeSort'] ) ) {
304
305 $this->action = 'changeSort';
306 $this->sortOldColumn = $this->sortColumn;
307 // Validate sortColumn.
308 if ( in_array( $_REQUEST['changeSort'], $this->columns ) ) {
309 $this->sortColumn = $_REQUEST['changeSort'];
310 } else {
311 $this->sortColumn = 'ID'; // default.
312 }
313 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
314 // Validate sortSwitchs.
315 if (isset($_REQUEST['switch']) && in_array($_REQUEST['switch'], array('ASC', 'DESC'))) {
316 $this->sortSwitchs[$this->sortColumn] = $_REQUEST['switch'];
317 } else {
318 $this->sortSwitchs[$this->sortColumn] = 'DESC'; // default.
319 }
320 $this->currentPage = ( isset( $this->data_cookie['currentPage'] ) ) ? $this->data_cookie['currentPage'] : $this->currentPage;
321 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
322 $this->searchSql = ( isset( $this->data_cookie['searchSql'] ) ) ? $this->data_cookie['searchSql'] : $this->searchSql;
323 $this->searchSkuSql = ( isset( $this->data_cookie['searchSkuSql'] ) ) ? $this->data_cookie['searchSkuSql'] : $this->searchSkuSql;
324 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
325 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
326 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
327 $this->placeholder_escape = ( isset( $this->data_cookie['placeholder_escape'] ) ) ? $this->data_cookie['placeholder_escape'] : $this->placeholder_escape;
328
329 } elseif ( isset( $_REQUEST['searchIn'] ) ) {
330
331 $this->action = 'searchIn';
332 $this->arr_search['column'] = isset( $_REQUEST['search']['column'] ) ? str_replace( '`', '', $_REQUEST['search']['column'] ) : '';
333 $this->arr_search['sku'] = isset( $_REQUEST['search']['sku'] ) ? $_REQUEST['search']['sku'] : '';
334 $this->arr_search['word'] = isset( $_REQUEST['search']['word'] ) ? $_REQUEST['search']['word'] : '';
335 $this->arr_search['skuword'] = isset( $_REQUEST['search']['skuword'] ) ? $_REQUEST['search']['skuword'] : '';
336 $this->arr_search['period'] = isset( $_REQUEST['search']['period'] ) ? (int) $_REQUEST['search']['period'] : $this->period_initial_index;
337 if ( $this->period_specified_index != $this->arr_search['period'] ) {
338 $this->startdate = '';
339 $this->enddate = '';
340 $this->data_cookie['startdate'] = '';
341 $this->data_cookie['enddate'] = '';
342 }
343 $this->searchSwitchStatus = isset( $_REQUEST['searchSwitchStatus'] ) ? $_REQUEST['searchSwitchStatus'] : '';
344 $this->currentPage = 1;
345 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
346 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
347 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
348 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
349 $this->placeholder_escape = $wpdb->placeholder_escape();
350
351 } elseif ( isset( $_REQUEST['searchOut'] ) ) {
352
353 $this->action = 'searchOut';
354 $this->arr_search['column'] = '';
355 $this->arr_search['word'] = '';
356 $this->arr_search['sku'] = '';
357 $this->arr_search['skuword'] = '';
358 $this->arr_search['period'] = ( isset( $this->data_cookie['arr_search']['period'] ) ) ? $this->data_cookie['arr_search']['period'] : $this->arr_search['period'];
359 $this->searchSwitchStatus = isset( $_REQUEST['searchSwitchStatus'] ) ? str_replace( ',', '', $_REQUEST['searchSwitchStatus'] ) : '';
360 $this->currentPage = 1;
361 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
362 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
363 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
364 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
365 $this->placeholder_escape = '';
366
367 } elseif ( isset( $_REQUEST['refresh'] ) ) {
368
369 $this->action = 'refresh';
370 $this->currentPage = ( isset( $this->data_cookie['currentPage'] ) ) ? $this->data_cookie['currentPage'] : $this->currentPage;
371 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
372 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
373 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
374 $this->searchSwitchStatus = ( isset( $this->data_cookie['searchSwitchStatus'] ) ) ? $this->data_cookie['searchSwitchStatus'] : $this->searchSwitchStatus;
375 $this->searchSql = ( isset( $this->data_cookie['searchSql'] ) ) ? $this->data_cookie['searchSql'] : $this->searchSql;
376 $this->searchSkuSql = ( isset( $this->data_cookie['searchSkuSql'] ) ) ? $this->data_cookie['searchSkuSql'] : $this->searchSkuSql;
377 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
378 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
379 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
380 $this->placeholder_escape = '';
381
382 } elseif ( isset( $_REQUEST['collective'] ) ) {
383
384 $this->action = 'collective_' . str_replace( ',', '', $_POST['allchange']['column'] );
385 $this->currentPage = ( isset( $this->data_cookie['currentPage'] ) ) ? $this->data_cookie['currentPage'] : $this->currentPage;
386 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
387 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
388 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
389 $this->searchSwitchStatus = ( isset( $this->data_cookie['searchSwitchStatus'] ) ) ? $this->data_cookie['searchSwitchStatus'] : $this->searchSwitchStatus;
390 $this->searchSql = ( isset( $this->data_cookie['searchSql'] ) ) ? $this->data_cookie['searchSql'] : $this->searchSql;
391 $this->searchSkuSql = ( isset( $this->data_cookie['searchSkuSql'] ) ) ? $this->data_cookie['searchSkuSql'] : $this->searchSkuSql;
392 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
393 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
394 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
395 $this->placeholder_escape = ( isset( $this->data_cookie['placeholder_escape'] ) ) ? $this->data_cookie['placeholder_escape'] : $this->placeholder_escape;
396
397 } else {
398
399 $this->action = 'default';
400 $this->placeholder_escape = '';
401 }
402 }
403
404 /**
405 * Validation Search Parameters.
406 */
407 public function validationSearchParameters() {
408 $default_sku_columns = [ 'item_code', 'item_name' ];
409 if ( 'none' != $this->arr_search['column'] && ! in_array( $this->arr_search['column'], $this->columns ) ) {
410 if ( is_array( $this->arr_search['word'] ) && count( $this->arr_search['word'] ) && in_array( $key = key( $this->arr_search['word'] ), $this->columns ) ) {
411 $this->arr_search['column'] = $key;
412 } else {
413 $this->arr_search['column'] = 'none';
414 }
415 }
416 if ( 'none' != $this->arr_search['sku'] && ! in_array( $this->arr_search['sku'], $default_sku_columns ) ) {
417 if ( is_array( $this->arr_search['skuword'] ) && count( $this->arr_search['skuword'] ) && in_array( $key = key( $this->arr_search['skuword'] ), $default_sku_columns ) ) {
418 $this->arr_search['sku'] = $key;
419 } else {
420 $this->arr_search['sku'] = 'none';
421 }
422 }
423 }
424
425 /**
426 * Get Rows.
427 *
428 * @return array
429 */
430 public function GetRows() {
431 global $wpdb;
432 $where = $this->GetWhere();
433
434 $init_column = 'ID';
435 $sort_column = in_array( $this->sortColumn, $this->columns, true ) ? $this->sortColumn : $init_column;
436 $init_switch = 'DESC';
437 $sort_switch = $this->sortSwitchs[ $sort_column ] ?? $init_switch;
438 $sort_switch = in_array( strtoupper( $sort_switch ), array( 'ASC', 'DESC' ), true ) ? $sort_switch : $init_switch;
439 $order = ' ORDER BY ' . esc_sql( $sort_column ) . ' ' . esc_sql( $sort_switch );
440 $order = apply_filters( 'usces_filter_order_list_get_orderby', $order, $this );
441
442 $select = '';
443 foreach ( $this->selectSql as $value ) {
444 $select .= $value . ', ';
445 }
446 $select = rtrim( $select, ', ' );
447 $select .= ', item_name, item_code';
448 $query = apply_filters( 'usces_filter_order_list_select', $select, $this );
449 $join_table = '';
450 foreach ( $this->joinTableSql as $value ) {
451 $join_table .= $value;
452 }
453 $query = 'SELECT ' . $select . " \n" . "FROM {$this->table} " . "\n" . $join_table . $where . "\n" . $order;
454 $query = apply_filters( 'usces_filter_order_list_get_rows', $query, $this );
455 $wpdb->show_errors();
456
457 if ( $this->placeholder_escape ) {
458 add_filter( 'query', array( $this, 'remove_ph' ) );
459 }
460
461 $rows = $wpdb->get_results( $query, ARRAY_A );
462 $this->selectedRow = ( $rows && is_array( $rows ) ) ? count( $rows ) : 0;
463 if ( 'on' == $this->pageLimit ) {
464 $this->rows = array_slice( (array) $rows, $this->startRow, $this->maxRow );
465 } else {
466 $this->rows = (array) $rows;
467 }
468
469 return $this->rows;
470 }
471
472 /**
473 * Placeholder clear.
474 *
475 * @param string $query Query.
476 * @return string
477 */
478 public function remove_ph( $query ) {
479 return str_replace( $this->placeholder_escape, '%', $query );
480 }
481
482 /**
483 * Set Total Rows.
484 */
485 public function SetTotalRow() {
486 global $wpdb;
487 $where = '';
488 if ( $this->period_specified_index == $this->arr_search['period'] ) {
489 if ( isset( $_REQUEST['startdate'] ) ) {
490 $startdate = $_REQUEST['startdate'];
491 } else {
492 $startdate = $this->data_cookie['startdate'];
493 }
494
495 if ( isset( $_REQUEST['enddate'] ) ) {
496 $enddate = $_REQUEST['enddate'];
497 } else {
498 $enddate = $this->data_cookie['enddate'];
499 }
500 if ( '' != $startdate || '' != $enddate ) {
501 if ( '' == $enddate ) {
502 $where = " WHERE order_date >= '{$startdate}'";
503 } elseif ( '' == $startdate ) {
504 $where = " WHERE order_date <= '{$enddate}'";
505 } elseif ( $startdate == $enddate ) {
506 $where = " WHERE order_date BETWEEN '{$startdate} 00:00:00' AND '{$startdate} 23:59:59'";
507 } else {
508 $where = " WHERE order_date >= '{$startdate}' AND order_date <= '{$enddate}'";
509 }
510 }
511 }
512 $query = "SELECT COUNT(ID) AS `ct` FROM {$this->table}" . apply_filters( 'usces_filter_order_list_sql_where', $where, $this );
513 $query = apply_filters( 'usces_filter_order_list_set_total_row', $query, $this );
514 $res = $wpdb->get_var( $query );
515 $this->totalRow = $res;
516 }
517
518 /**
519 * Where Condition.
520 *
521 * @return string
522 */
523 public function GetWhere() {
524 global $wpdb;
525 $str = '';
526 $where = '';
527 if ( $this->period_specified_index == $this->arr_search['period'] ) {
528 if ( isset( $_REQUEST['startdate'] ) ) {
529 $startdate = $_REQUEST['startdate'];
530 } else {
531 $startdate = $this->data_cookie['startdate'];
532 }
533
534 if ( isset( $_REQUEST['enddate'] ) ) {
535 $enddate = $_REQUEST['enddate'];
536 } else {
537 $enddate = $this->data_cookie['enddate'];
538 }
539 if ( '' != $startdate || '' != $enddate ) {
540 if ( '' == $enddate ) {
541 $where = " WHERE order_date >= '{$startdate}'";
542 } elseif ( '' == $startdate ) {
543 $where = " WHERE order_date <= '{$enddate}'";
544 } elseif ( $startdate == $enddate ) {
545 $where = " WHERE order_date BETWEEN '{$startdate} 00:00:00' AND '{$startdate} 23:59:59'";
546 } else {
547 $where = " WHERE order_date >= '{$startdate}' AND order_date <= '{$enddate}'";
548 }
549 }
550 } else {
551 $thismonth = date_i18n( 'Y-m-01 00:00:00' );
552 $lastmonth = date_i18n( 'Y-m-01 00:00:00', mktime( 0, 0, 0, date_i18n( 'm' ) - 1, 1, date_i18n( 'Y' ) ) );
553 $lastweek = date_i18n( 'Y-m-d 00:00:00', mktime( 0, 0, 0, date_i18n( 'm' ), date_i18n( 'd' ) - 7, date_i18n( 'Y' ) ) );
554 $last30 = date_i18n( 'Y-m-d 00:00:00', mktime( 0, 0, 0, date_i18n( 'm' ), date_i18n( 'd' ) - 30, date_i18n( 'Y' ) ) );
555 $last90 = date_i18n( 'Y-m-d 00:00:00', mktime( 0, 0, 0, date_i18n( 'm' ), date_i18n( 'd' ) - 90, date_i18n( 'Y' ) ) );
556 switch ( $this->arr_search['period'] ) {
557 case 0:
558 $where = $wpdb->prepare( " WHERE order_date >= %s ", $thismonth );
559 break;
560 case 1:
561 $where = $wpdb->prepare( " WHERE order_date >= %s AND order_date < %s ", $lastmonth, $thismonth );
562 break;
563 case 2:
564 $where = $wpdb->prepare( " WHERE order_date >= %s ", $lastweek );
565 break;
566 case 3:
567 $where = $wpdb->prepare( " WHERE order_date >= %s ", $last30 );
568 break;
569 case 4:
570 $where = $wpdb->prepare( " WHERE order_date >= %s ", $last90 );
571 break;
572 case 5:
573 $where = '';
574 break;
575 }
576 }
577 if ( ! WCUtils::is_blank( $where ) ) {
578 if ( ! WCUtils::is_blank( $this->searchSkuSql ) ) {
579 $where .= ' AND ' . $this->searchSkuSql;
580 }
581 } else {
582 if ( ! WCUtils::is_blank( $this->searchSkuSql ) ) {
583 $where = ' WHERE ' . $this->searchSkuSql;
584 }
585 }
586 $str = apply_filters( 'usces_filter_order_list_sql_where', $where, $this );
587
588 $str .= ' GROUP BY `ID` ';
589
590 $having = '';
591 if ( ! WCUtils::is_blank( $this->searchSql ) ) {
592 $having = ' HAVING ' . $this->searchSql;
593 }
594 $having = apply_filters( 'usces_filter_order_list_sql_having', $having, $this );
595
596 if ( ! WCUtils::is_blank( $having ) ) {
597 $str .= $having;
598 }
599
600 return apply_filters( 'usces_filter_order_list_get_where', $str, $this );
601 }
602
603 /**
604 * Search.
605 */
606 public function SearchIn() {
607 global $wpdb;
608 switch ( $this->arr_search['column'] ) {
609 case 'ID':
610 $column = 'ID';
611 $this->searchSql = $wpdb->prepare( '`' . $column . '` = %d', $this->arr_search['word']['ID'] );
612 break;
613 case 'deco_id':
614 $column = 'deco_id';
615 $this->searchSql = $wpdb->prepare( '`' . $column . '` LIKE %s', "%" . $this->arr_search['word']['deco_id'] . "%" );
616 break;
617 case 'date':
618 $column = 'date';
619 $this->searchSql = $wpdb->prepare( '`' . $column . '` LIKE %s', "%" . $this->arr_search['word']['date'] . "%" );
620 break;
621 case 'mem_id':
622 $column = 'mem_id';
623 $this->searchSql = $wpdb->prepare( '`' . $column . '` = %d', $this->arr_search['word']['mem_id'] );
624 break;
625 case 'name':
626 $column = 'name';
627 $this->searchSql = $wpdb->prepare( '`' . $column . '` LIKE %s', "%" . $this->arr_search['word']['name'] . "%" );
628 break;
629 case 'order_modified':
630 $column = 'order_modified';
631 $this->searchSql = $wpdb->prepare( '`' . $column . '` LIKE %s', "%" . $this->arr_search['word']['order_modified'] . "%" );
632 break;
633 case 'pref':
634 $column = 'pref';
635 $this->searchSql = $wpdb->prepare( '`' . $column . "` = %s", $this->arr_search['word']['pref'] );
636 break;
637 case 'delivery_method':
638 $column = 'delivery_method';
639 $this->searchSql = $wpdb->prepare( '`' . $column . "` = %s", $this->arr_search['word']['delivery_method'] );
640 break;
641 case 'payment_name':
642 $column = 'payment_name';
643 $this->searchSql = $wpdb->prepare( '`' . $column . "` = %s", $this->arr_search['word']['payment_name'] );
644 break;
645 case 'receipt_status':
646 $column = 'receipt_status';
647 $this->searchSql = $wpdb->prepare( '`' . $column . "` = %s", $this->arr_search['word']['receipt_status'] );
648 break;
649 case 'order_status':
650 $column = 'order_status';
651 $this->searchSql = $wpdb->prepare( '`' . $column . "` = %s", $this->arr_search['word']['order_status'] );
652 break;
653 }
654 switch ( $this->arr_search['sku'] ) {
655 case 'item_code':
656 $column = 'item_code';
657 $this->searchSkuSql = $wpdb->prepare( '`' . $column . '` LIKE %s', "%" . $this->arr_search['skuword']['item_code'] . "%" );
658 break;
659 case 'item_name':
660 $column = 'item_name';
661 $this->searchSkuSql = $wpdb->prepare( '`' . $column . '` LIKE %s', "%" . $this->arr_search['skuword']['item_name'] . "%" );
662 break;
663 }
664 }
665
666 /**
667 * Search clear.
668 */
669 public function SearchOut() {
670 $this->searchSql = '';
671 $this->searchSkuSql = '';
672 }
673
674 /**
675 * Set Navigation.
676 */
677 public function SetNavi() {
678 $this->lastPage = ceil( $this->selectedRow / $this->maxRow );
679 $this->previousPage = ( $this->currentPage - 1 == 0 ) ? 1 : $this->currentPage - 1;
680 $this->nextPage = ( $this->currentPage + 1 > $this->lastPage ) ? $this->lastPage : $this->currentPage + 1;
681 $box = array();
682
683 for ( $i = 0; $i < $this->naviMaxButton; $i++ ) {
684 if ( $i > $this->lastPage - 1 ) {
685 break;
686 }
687 if ( $this->lastPage <= $this->naviMaxButton ) {
688 $box[] = $i + 1;
689 } else {
690 if ( $this->currentPage <= 6 ) {
691 $label = $i + 1;
692 $box[] = $label;
693 } else {
694 $label = $i + 1 + $this->currentPage - 6;
695 $box[] = $label;
696 if ( $label == $this->lastPage ) {
697 break;
698 }
699 }
700 }
701 }
702
703 $html = '';
704 $html .= '<ul class="clearfix">';
705 $html .= '<li class="rowsnum">' . $this->selectedRow . ' / ' . $this->totalRow . ' ' . __( 'cases', 'usces' ) . '</li>';
706 if ( ( 1 == $this->currentPage ) || ( 0 == $this->selectedRow ) ) {
707 $html .= '<li class="navigationStr">first&lt;&lt;</li>';
708 $html .= '<li class="navigationStr">prev&lt;</li>';
709 } else {
710 $html .= '<li class="navigationStr"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_orderlist&changePage=1">first&lt;&lt;</a></li>';
711 $html .= '<li class="navigationStr"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_orderlist&changePage=' . $this->previousPage . '">prev&lt;</a></li>';
712 }
713 if ( $this->selectedRow > 0 ) {
714 $box_count = count( $box );
715 for ( $i = 0; $i < $box_count; $i++ ) {
716 if ( $box[ $i ] == $this->currentPage ) {
717 $html .= '<li class="navigationButtonSelected">' . $box[ $i ] . '</li>';
718 } else {
719 $html .= '<li class="navigationButton"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_orderlist&changePage=' . $box[ $i ] . '">' . $box[ $i ] . '</a></li>';
720 }
721 }
722 }
723 if ( ( $this->currentPage == $this->lastPage ) || ( 0 == $this->selectedRow ) ) {
724 $html .= '<li class="navigationStr">&gt;next</li>';
725 $html .= '<li class="navigationStr">&gt;&gt;last</li>';
726 } else {
727 $html .= '<li class="navigationStr"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_orderlist&changePage=' . $this->nextPage . '">&gt;next</a></li>';
728 $html .= '<li class="navigationStr"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_orderlist&changePage=' . $this->lastPage . '">&gt;&gt;last</a></li>';
729 }
730 if ( 'OFF ' == $this->searchSwitchStatus ) {
731 $html .= '<li class="rowsnum"><a style="cursor:pointer;" id="searchVisiLink">' . __( 'Hide the Operation field', 'usces' ) . '<span class="dashicons dashicons-arrow-up"></a>';
732 } else {
733 $html .= '<li class="rowsnum"><a style="cursor:pointer;" id="searchVisiLink">' . __( 'Show the Operation field', 'usces' ) . '<span class="dashicons dashicons-arrow-down"></a>';
734 }
735
736 $html .= '<li class="refresh"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_orderlist&refresh">' . __( 'updates it to latest information', 'usces' ) . '</a></li>';
737 $html .= '</ul>';
738
739 $this->dataTableNavigation = $html;
740 }
741
742 /**
743 * Get Cookie.
744 */
745 public function getCookie() {
746 $this->data_cookie = ( isset( $_COOKIE[ $this->table ] ) ) ? json_decode( str_replace( "\'", "'", str_replace( '\"', '"', $_COOKIE[ $this->table ] ) ), true ) : array();
747 }
748
749 /**
750 * Set Headers.
751 */
752 public function SetHeaders() {
753 foreach ( $this->columns as $key => $value ) {
754 if ( $value == $this->sortColumn ) {
755 if ( 'ASC' == $this->sortSwitchs[ $value ] ) {
756 $str = __( '[ASC]', 'usces' );
757 $switch = 'DESC';
758 } else {
759 $str = __( '[DESC]', 'usces' );
760 $switch = 'ASC';
761 }
762 $this->headers[ $value ] = '<a href="' . site_url() . '/wp-admin/admin.php?page=usces_orderlist&changeSort=' . $value . '&switch=' . $switch . '"><span class="sortcolumn">' . $key . ' ' . $str . '</span></a>';
763 } else {
764 $switch = $this->sortSwitchs[ $value ];
765 $this->headers[ $value ] = '<a href="' . site_url() . '/wp-admin/admin.php?page=usces_orderlist&changeSort=' . $value . '&switch=' . $switch . '"><span>' . $key . '</span></a>';
766 }
767 }
768 }
769
770 /**
771 * Get Search.
772 *
773 * @return string
774 */
775 public function GetSearchs() {
776 return $this->arr_search;
777 }
778
779 /**
780 * Get Headers.
781 *
782 * @return string
783 */
784 public function GetListheaders() {
785 return $this->headers;
786 }
787
788 /**
789 * Get Navigation.
790 *
791 * @return string
792 */
793 public function GetDataTableNavigation() {
794 return $this->dataTableNavigation;
795 }
796
797 /**
798 * Set Action Status and Action Message.
799 *
800 * @param string $status Action status.
801 * @param string $message Action message.
802 */
803 public function set_action_status( $status, $message ) {
804 $this->action_status = $status;
805 $this->action_message = $message;
806 }
807
808 /**
809 * Get Action Status.
810 *
811 * @return string
812 */
813 public function get_action_status() {
814 return $this->action_status;
815 }
816
817 /**
818 * Get Action Message.
819 *
820 * @return string
821 */
822 public function get_action_message() {
823 return $this->action_message;
824 }
825
826 /**
827 * Get Period Specified.
828 *
829 * @return int
830 */
831 public function get_period_specified_index() {
832 return $this->period_specified_index;
833 }
834 }
835