PluginProbe
Welcart e-Commerce / 2.12.3
Welcart e-Commerce v2.12.3
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 1.4.13 All 291 releases
usc-e-shop / classes / orderList.class.php

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

840 lines 35.1 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 foreach ( $this->columns as $key => $value ) {
267 if ( ! isset( $this->sortSwitchs[ $value ] ) ) {
268 $this->sortSwitchs[ $value ] = 'DESC';
269 }
270 }
271 } else {
272 foreach ( $this->columns as $key => $value ) {
273 $this->sortSwitchs[ $value ] = 'DESC';
274 }
275 }
276 $this->startdate = ( isset( $_REQUEST['startdate'] ) ) ? $_REQUEST['startdate'] : ( ( isset( $this->data_cookie['startdate'] ) ) ? $this->data_cookie['startdate'] : '' );
277 $this->enddate = ( isset( $_REQUEST['enddate'] ) ) ? $_REQUEST['enddate'] : ( ( isset( $this->data_cookie['enddate'] ) ) ? $this->data_cookie['enddate'] : '' );
278 $this->SetTotalRow();
279 }
280
281 /**
282 * Set Parameters.
283 */
284 public function SetParam() {
285 $this->startRow = ( $this->currentPage - 1 ) * $this->maxRow;
286 }
287
288 /**
289 * Set Parameters.
290 */
291 public function SetParamByQuery() {
292 global $wpdb;
293 if ( isset( $_REQUEST['changePage'] ) ) {
294
295 $this->action = 'changePage';
296 $this->currentPage = (int) $_REQUEST['changePage'];
297 $this->sortColumn = ( isset( $data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
298 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
299 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
300 $this->searchSwitchStatus = ( isset( $this->data_cookie['searchSwitchStatus'] ) ) ? $this->data_cookie['searchSwitchStatus'] : $this->searchSwitchStatus;
301 $this->searchSql = ( isset( $this->data_cookie['searchSql'] ) ) ? $this->data_cookie['searchSql'] : $this->searchSql;
302 $this->searchSkuSql = ( isset( $this->data_cookie['searchSkuSql'] ) ) ? $this->data_cookie['searchSkuSql'] : $this->searchSkuSql;
303 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
304 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
305 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
306 $this->placeholder_escape = ( isset( $this->data_cookie['placeholder_escape'] ) ) ? $this->data_cookie['placeholder_escape'] : $this->placeholder_escape;
307
308 } elseif ( isset( $_REQUEST['changeSort'] ) ) {
309
310 $this->action = 'changeSort';
311 $this->sortOldColumn = $this->sortColumn;
312 // Validate sortColumn.
313 if ( in_array( $_REQUEST['changeSort'], $this->columns ) ) {
314 $this->sortColumn = $_REQUEST['changeSort'];
315 } else {
316 $this->sortColumn = 'ID'; // default.
317 }
318 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
319 // Validate sortSwitchs.
320 if (isset($_REQUEST['switch']) && in_array($_REQUEST['switch'], array('ASC', 'DESC'))) {
321 $this->sortSwitchs[$this->sortColumn] = $_REQUEST['switch'];
322 } else {
323 $this->sortSwitchs[$this->sortColumn] = 'DESC'; // default.
324 }
325 $this->currentPage = ( isset( $this->data_cookie['currentPage'] ) ) ? $this->data_cookie['currentPage'] : $this->currentPage;
326 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
327 $this->searchSql = ( isset( $this->data_cookie['searchSql'] ) ) ? $this->data_cookie['searchSql'] : $this->searchSql;
328 $this->searchSkuSql = ( isset( $this->data_cookie['searchSkuSql'] ) ) ? $this->data_cookie['searchSkuSql'] : $this->searchSkuSql;
329 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
330 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
331 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
332 $this->placeholder_escape = ( isset( $this->data_cookie['placeholder_escape'] ) ) ? $this->data_cookie['placeholder_escape'] : $this->placeholder_escape;
333
334 } elseif ( isset( $_REQUEST['searchIn'] ) ) {
335
336 $this->action = 'searchIn';
337 $this->arr_search['column'] = isset( $_REQUEST['search']['column'] ) ? str_replace( '`', '', $_REQUEST['search']['column'] ) : '';
338 $this->arr_search['sku'] = isset( $_REQUEST['search']['sku'] ) ? $_REQUEST['search']['sku'] : '';
339 $this->arr_search['word'] = isset( $_REQUEST['search']['word'] ) ? $_REQUEST['search']['word'] : '';
340 $this->arr_search['skuword'] = isset( $_REQUEST['search']['skuword'] ) ? $_REQUEST['search']['skuword'] : '';
341 $this->arr_search['period'] = isset( $_REQUEST['search']['period'] ) ? (int) $_REQUEST['search']['period'] : $this->period_initial_index;
342 if ( $this->period_specified_index != $this->arr_search['period'] ) {
343 $this->startdate = '';
344 $this->enddate = '';
345 $this->data_cookie['startdate'] = '';
346 $this->data_cookie['enddate'] = '';
347 }
348 $this->searchSwitchStatus = isset( $_REQUEST['searchSwitchStatus'] ) ? $_REQUEST['searchSwitchStatus'] : '';
349 $this->currentPage = 1;
350 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
351 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
352 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
353 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
354 $this->placeholder_escape = $wpdb->placeholder_escape();
355
356 } elseif ( isset( $_REQUEST['searchOut'] ) ) {
357
358 $this->action = 'searchOut';
359 $this->arr_search['column'] = '';
360 $this->arr_search['word'] = '';
361 $this->arr_search['sku'] = '';
362 $this->arr_search['skuword'] = '';
363 $this->arr_search['period'] = ( isset( $this->data_cookie['arr_search']['period'] ) ) ? $this->data_cookie['arr_search']['period'] : $this->arr_search['period'];
364 $this->searchSwitchStatus = isset( $_REQUEST['searchSwitchStatus'] ) ? str_replace( ',', '', $_REQUEST['searchSwitchStatus'] ) : '';
365 $this->currentPage = 1;
366 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
367 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
368 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
369 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
370 $this->placeholder_escape = '';
371
372 } elseif ( isset( $_REQUEST['refresh'] ) ) {
373
374 $this->action = 'refresh';
375 $this->currentPage = ( isset( $this->data_cookie['currentPage'] ) ) ? $this->data_cookie['currentPage'] : $this->currentPage;
376 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
377 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
378 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
379 $this->searchSwitchStatus = ( isset( $this->data_cookie['searchSwitchStatus'] ) ) ? $this->data_cookie['searchSwitchStatus'] : $this->searchSwitchStatus;
380 $this->searchSql = ( isset( $this->data_cookie['searchSql'] ) ) ? $this->data_cookie['searchSql'] : $this->searchSql;
381 $this->searchSkuSql = ( isset( $this->data_cookie['searchSkuSql'] ) ) ? $this->data_cookie['searchSkuSql'] : $this->searchSkuSql;
382 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
383 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
384 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
385 $this->placeholder_escape = '';
386
387 } elseif ( isset( $_REQUEST['collective'] ) ) {
388
389 $this->action = 'collective_' . str_replace( ',', '', $_POST['allchange']['column'] );
390 $this->currentPage = ( isset( $this->data_cookie['currentPage'] ) ) ? $this->data_cookie['currentPage'] : $this->currentPage;
391 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
392 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
393 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
394 $this->searchSwitchStatus = ( isset( $this->data_cookie['searchSwitchStatus'] ) ) ? $this->data_cookie['searchSwitchStatus'] : $this->searchSwitchStatus;
395 $this->searchSql = ( isset( $this->data_cookie['searchSql'] ) ) ? $this->data_cookie['searchSql'] : $this->searchSql;
396 $this->searchSkuSql = ( isset( $this->data_cookie['searchSkuSql'] ) ) ? $this->data_cookie['searchSkuSql'] : $this->searchSkuSql;
397 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
398 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
399 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
400 $this->placeholder_escape = ( isset( $this->data_cookie['placeholder_escape'] ) ) ? $this->data_cookie['placeholder_escape'] : $this->placeholder_escape;
401
402 } else {
403
404 $this->action = 'default';
405 $this->placeholder_escape = '';
406 }
407 }
408
409 /**
410 * Validation Search Parameters.
411 */
412 public function validationSearchParameters() {
413 $default_sku_columns = [ 'item_code', 'item_name' ];
414 if ( ! empty( $this->arr_search['column'] ) && 'none' != $this->arr_search['column'] && ! in_array( $this->arr_search['column'], $this->columns ) ) {
415 if ( ! empty( $this->arr_search['word'] ) && is_array( $this->arr_search['word'] ) && count( $this->arr_search['word'] ) && in_array( $key = key( $this->arr_search['word'] ), $this->columns ) ) {
416 $this->arr_search['column'] = $key;
417 } else {
418 $this->arr_search['column'] = 'none';
419 }
420 }
421 if ( ! empty( $this->arr_search['sku'] ) && 'none' != $this->arr_search['sku'] && ! in_array( $this->arr_search['sku'], $default_sku_columns ) ) {
422 if ( ! empty( $this->arr_search['skuword'] ) && is_array( $this->arr_search['skuword'] ) && count( $this->arr_search['skuword'] ) && in_array( $key = key( $this->arr_search['skuword'] ), $default_sku_columns ) ) {
423 $this->arr_search['sku'] = $key;
424 } else {
425 $this->arr_search['sku'] = 'none';
426 }
427 }
428 }
429
430 /**
431 * Get Rows.
432 *
433 * @return array
434 */
435 public function GetRows() {
436 global $wpdb;
437 $where = $this->GetWhere();
438
439 $init_column = 'ID';
440 $sort_column = in_array( $this->sortColumn, $this->columns, true ) ? $this->sortColumn : $init_column;
441 $init_switch = 'DESC';
442 $sort_switch = $this->sortSwitchs[ $sort_column ] ?? $init_switch;
443 $sort_switch = in_array( strtoupper( $sort_switch ), array( 'ASC', 'DESC' ), true ) ? $sort_switch : $init_switch;
444 $order = ' ORDER BY ' . esc_sql( $sort_column ) . ' ' . esc_sql( $sort_switch );
445 $order = apply_filters( 'usces_filter_order_list_get_orderby', $order, $this );
446
447 $select = '';
448 foreach ( $this->selectSql as $value ) {
449 $select .= $value . ', ';
450 }
451 $select = rtrim( $select, ', ' );
452 $select .= ', item_name, item_code';
453 $query = apply_filters( 'usces_filter_order_list_select', $select, $this );
454 $join_table = '';
455 foreach ( $this->joinTableSql as $value ) {
456 $join_table .= $value;
457 }
458 $query = 'SELECT ' . $select . " \n" . "FROM {$this->table} " . "\n" . $join_table . $where . "\n" . $order;
459 $query = apply_filters( 'usces_filter_order_list_get_rows', $query, $this );
460 $wpdb->show_errors();
461
462 if ( $this->placeholder_escape ) {
463 add_filter( 'query', array( $this, 'remove_ph' ) );
464 }
465
466 $rows = $wpdb->get_results( $query, ARRAY_A );
467 $this->selectedRow = ( $rows && is_array( $rows ) ) ? count( $rows ) : 0;
468 if ( 'on' == $this->pageLimit ) {
469 $this->rows = array_slice( (array) $rows, $this->startRow, $this->maxRow );
470 } else {
471 $this->rows = (array) $rows;
472 }
473
474 return $this->rows;
475 }
476
477 /**
478 * Placeholder clear.
479 *
480 * @param string $query Query.
481 * @return string
482 */
483 public function remove_ph( $query ) {
484 return str_replace( $this->placeholder_escape, '%', $query );
485 }
486
487 /**
488 * Set Total Rows.
489 */
490 public function SetTotalRow() {
491 global $wpdb;
492 $where = '';
493 if ( $this->period_specified_index == $this->arr_search['period'] ) {
494 if ( isset( $_REQUEST['startdate'] ) ) {
495 $startdate = $_REQUEST['startdate'];
496 } else {
497 $startdate = $this->data_cookie['startdate'];
498 }
499
500 if ( isset( $_REQUEST['enddate'] ) ) {
501 $enddate = $_REQUEST['enddate'];
502 } else {
503 $enddate = $this->data_cookie['enddate'];
504 }
505 if ( '' != $startdate || '' != $enddate ) {
506 if ( '' == $enddate ) {
507 $where = " WHERE order_date >= '{$startdate}'";
508 } elseif ( '' == $startdate ) {
509 $where = " WHERE order_date <= '{$enddate}'";
510 } elseif ( $startdate == $enddate ) {
511 $where = " WHERE order_date BETWEEN '{$startdate} 00:00:00' AND '{$startdate} 23:59:59'";
512 } else {
513 $where = " WHERE order_date >= '{$startdate}' AND order_date <= '{$enddate}'";
514 }
515 }
516 }
517 $query = "SELECT COUNT(ID) AS `ct` FROM {$this->table}" . apply_filters( 'usces_filter_order_list_sql_where', $where, $this );
518 $query = apply_filters( 'usces_filter_order_list_set_total_row', $query, $this );
519 $res = $wpdb->get_var( $query );
520 $this->totalRow = $res;
521 }
522
523 /**
524 * Where Condition.
525 *
526 * @return string
527 */
528 public function GetWhere() {
529 global $wpdb;
530 $str = '';
531 $where = '';
532 if ( $this->period_specified_index == $this->arr_search['period'] ) {
533 if ( isset( $_REQUEST['startdate'] ) ) {
534 $startdate = $_REQUEST['startdate'];
535 } else {
536 $startdate = $this->data_cookie['startdate'];
537 }
538
539 if ( isset( $_REQUEST['enddate'] ) ) {
540 $enddate = $_REQUEST['enddate'];
541 } else {
542 $enddate = $this->data_cookie['enddate'];
543 }
544 if ( '' != $startdate || '' != $enddate ) {
545 if ( '' == $enddate ) {
546 $where = " WHERE order_date >= '{$startdate}'";
547 } elseif ( '' == $startdate ) {
548 $where = " WHERE order_date <= '{$enddate}'";
549 } elseif ( $startdate == $enddate ) {
550 $where = " WHERE order_date BETWEEN '{$startdate} 00:00:00' AND '{$startdate} 23:59:59'";
551 } else {
552 $where = " WHERE order_date >= '{$startdate}' AND order_date <= '{$enddate}'";
553 }
554 }
555 } else {
556 $thismonth = date_i18n( 'Y-m-01 00:00:00' );
557 $lastmonth = date_i18n( 'Y-m-01 00:00:00', mktime( 0, 0, 0, date_i18n( 'm' ) - 1, 1, date_i18n( 'Y' ) ) );
558 $lastweek = date_i18n( 'Y-m-d 00:00:00', mktime( 0, 0, 0, date_i18n( 'm' ), date_i18n( 'd' ) - 7, date_i18n( 'Y' ) ) );
559 $last30 = date_i18n( 'Y-m-d 00:00:00', mktime( 0, 0, 0, date_i18n( 'm' ), date_i18n( 'd' ) - 30, date_i18n( 'Y' ) ) );
560 $last90 = date_i18n( 'Y-m-d 00:00:00', mktime( 0, 0, 0, date_i18n( 'm' ), date_i18n( 'd' ) - 90, date_i18n( 'Y' ) ) );
561 switch ( $this->arr_search['period'] ) {
562 case 0:
563 $where = $wpdb->prepare( " WHERE order_date >= %s ", $thismonth );
564 break;
565 case 1:
566 $where = $wpdb->prepare( " WHERE order_date >= %s AND order_date < %s ", $lastmonth, $thismonth );
567 break;
568 case 2:
569 $where = $wpdb->prepare( " WHERE order_date >= %s ", $lastweek );
570 break;
571 case 3:
572 $where = $wpdb->prepare( " WHERE order_date >= %s ", $last30 );
573 break;
574 case 4:
575 $where = $wpdb->prepare( " WHERE order_date >= %s ", $last90 );
576 break;
577 case 5:
578 $where = '';
579 break;
580 }
581 }
582 if ( ! WCUtils::is_blank( $where ) ) {
583 if ( ! WCUtils::is_blank( $this->searchSkuSql ) ) {
584 $where .= ' AND ' . $this->searchSkuSql;
585 }
586 } else {
587 if ( ! WCUtils::is_blank( $this->searchSkuSql ) ) {
588 $where = ' WHERE ' . $this->searchSkuSql;
589 }
590 }
591 $str = apply_filters( 'usces_filter_order_list_sql_where', $where, $this );
592
593 $str .= ' GROUP BY `ID` ';
594
595 $having = '';
596 if ( ! WCUtils::is_blank( $this->searchSql ) ) {
597 $having = ' HAVING ' . $this->searchSql;
598 }
599 $having = apply_filters( 'usces_filter_order_list_sql_having', $having, $this );
600
601 if ( ! WCUtils::is_blank( $having ) ) {
602 $str .= $having;
603 }
604
605 return apply_filters( 'usces_filter_order_list_get_where', $str, $this );
606 }
607
608 /**
609 * Search.
610 */
611 public function SearchIn() {
612 global $wpdb;
613 switch ( $this->arr_search['column'] ) {
614 case 'ID':
615 $column = 'ID';
616 $this->searchSql = $wpdb->prepare( '`' . $column . '` = %d', $this->arr_search['word']['ID'] );
617 break;
618 case 'deco_id':
619 $column = 'deco_id';
620 $this->searchSql = $wpdb->prepare( '`' . $column . '` LIKE %s', "%" . $this->arr_search['word']['deco_id'] . "%" );
621 break;
622 case 'date':
623 $column = 'date';
624 $this->searchSql = $wpdb->prepare( '`' . $column . '` LIKE %s', "%" . $this->arr_search['word']['date'] . "%" );
625 break;
626 case 'mem_id':
627 $column = 'mem_id';
628 $this->searchSql = $wpdb->prepare( '`' . $column . '` = %d', $this->arr_search['word']['mem_id'] );
629 break;
630 case 'name':
631 $column = 'name';
632 $this->searchSql = $wpdb->prepare( '`' . $column . '` LIKE %s', "%" . $this->arr_search['word']['name'] . "%" );
633 break;
634 case 'order_modified':
635 $column = 'order_modified';
636 $this->searchSql = $wpdb->prepare( '`' . $column . '` LIKE %s', "%" . $this->arr_search['word']['order_modified'] . "%" );
637 break;
638 case 'pref':
639 $column = 'pref';
640 $this->searchSql = $wpdb->prepare( '`' . $column . "` = %s", $this->arr_search['word']['pref'] );
641 break;
642 case 'delivery_method':
643 $column = 'delivery_method';
644 $this->searchSql = $wpdb->prepare( '`' . $column . "` = %s", $this->arr_search['word']['delivery_method'] );
645 break;
646 case 'payment_name':
647 $column = 'payment_name';
648 $this->searchSql = $wpdb->prepare( '`' . $column . "` = %s", $this->arr_search['word']['payment_name'] );
649 break;
650 case 'receipt_status':
651 $column = 'receipt_status';
652 $this->searchSql = $wpdb->prepare( '`' . $column . "` = %s", $this->arr_search['word']['receipt_status'] );
653 break;
654 case 'order_status':
655 $column = 'order_status';
656 $this->searchSql = $wpdb->prepare( '`' . $column . "` = %s", $this->arr_search['word']['order_status'] );
657 break;
658 }
659 switch ( $this->arr_search['sku'] ) {
660 case 'item_code':
661 $column = 'item_code';
662 $this->searchSkuSql = $wpdb->prepare( '`' . $column . '` LIKE %s', "%" . $this->arr_search['skuword']['item_code'] . "%" );
663 break;
664 case 'item_name':
665 $column = 'item_name';
666 $this->searchSkuSql = $wpdb->prepare( '`' . $column . '` LIKE %s', "%" . $this->arr_search['skuword']['item_name'] . "%" );
667 break;
668 }
669 }
670
671 /**
672 * Search clear.
673 */
674 public function SearchOut() {
675 $this->searchSql = '';
676 $this->searchSkuSql = '';
677 }
678
679 /**
680 * Set Navigation.
681 */
682 public function SetNavi() {
683 $this->lastPage = ceil( $this->selectedRow / $this->maxRow );
684 $this->previousPage = ( $this->currentPage - 1 == 0 ) ? 1 : $this->currentPage - 1;
685 $this->nextPage = ( $this->currentPage + 1 > $this->lastPage ) ? $this->lastPage : $this->currentPage + 1;
686 $box = array();
687
688 for ( $i = 0; $i < $this->naviMaxButton; $i++ ) {
689 if ( $i > $this->lastPage - 1 ) {
690 break;
691 }
692 if ( $this->lastPage <= $this->naviMaxButton ) {
693 $box[] = $i + 1;
694 } else {
695 if ( $this->currentPage <= 6 ) {
696 $label = $i + 1;
697 $box[] = $label;
698 } else {
699 $label = $i + 1 + $this->currentPage - 6;
700 $box[] = $label;
701 if ( $label == $this->lastPage ) {
702 break;
703 }
704 }
705 }
706 }
707
708 $html = '';
709 $html .= '<ul class="clearfix">';
710 $html .= '<li class="rowsnum">' . $this->selectedRow . ' / ' . $this->totalRow . ' ' . __( 'cases', 'usces' ) . '</li>';
711 if ( ( 1 == $this->currentPage ) || ( 0 == $this->selectedRow ) ) {
712 $html .= '<li class="navigationStr">first&lt;&lt;</li>';
713 $html .= '<li class="navigationStr">prev&lt;</li>';
714 } else {
715 $html .= '<li class="navigationStr"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_orderlist&changePage=1">first&lt;&lt;</a></li>';
716 $html .= '<li class="navigationStr"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_orderlist&changePage=' . $this->previousPage . '">prev&lt;</a></li>';
717 }
718 if ( $this->selectedRow > 0 ) {
719 $box_count = count( $box );
720 for ( $i = 0; $i < $box_count; $i++ ) {
721 if ( $box[ $i ] == $this->currentPage ) {
722 $html .= '<li class="navigationButtonSelected">' . $box[ $i ] . '</li>';
723 } else {
724 $html .= '<li class="navigationButton"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_orderlist&changePage=' . $box[ $i ] . '">' . $box[ $i ] . '</a></li>';
725 }
726 }
727 }
728 if ( ( $this->currentPage == $this->lastPage ) || ( 0 == $this->selectedRow ) ) {
729 $html .= '<li class="navigationStr">&gt;next</li>';
730 $html .= '<li class="navigationStr">&gt;&gt;last</li>';
731 } else {
732 $html .= '<li class="navigationStr"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_orderlist&changePage=' . $this->nextPage . '">&gt;next</a></li>';
733 $html .= '<li class="navigationStr"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_orderlist&changePage=' . $this->lastPage . '">&gt;&gt;last</a></li>';
734 }
735 if ( 'OFF ' == $this->searchSwitchStatus ) {
736 $html .= '<li class="rowsnum"><a style="cursor:pointer;" id="searchVisiLink">' . __( 'Hide the Operation field', 'usces' ) . '<span class="dashicons dashicons-arrow-up"></a>';
737 } else {
738 $html .= '<li class="rowsnum"><a style="cursor:pointer;" id="searchVisiLink">' . __( 'Show the Operation field', 'usces' ) . '<span class="dashicons dashicons-arrow-down"></a>';
739 }
740
741 $html .= '<li class="refresh"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_orderlist&refresh">' . __( 'updates it to latest information', 'usces' ) . '</a></li>';
742 $html .= '</ul>';
743
744 $this->dataTableNavigation = $html;
745 }
746
747 /**
748 * Get Cookie.
749 */
750 public function getCookie() {
751 $this->data_cookie = ( isset( $_COOKIE[ $this->table ] ) ) ? json_decode( str_replace( "\'", "'", str_replace( '\"', '"', $_COOKIE[ $this->table ] ) ), true ) : array();
752 }
753
754 /**
755 * Set Headers.
756 */
757 public function SetHeaders() {
758 foreach ( $this->columns as $key => $value ) {
759 if ( $value == $this->sortColumn ) {
760 if ( 'ASC' == $this->sortSwitchs[ $value ] ) {
761 $str = __( '[ASC]', 'usces' );
762 $switch = 'DESC';
763 } else {
764 $str = __( '[DESC]', 'usces' );
765 $switch = 'ASC';
766 }
767 $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>';
768 } else {
769 $switch = $this->sortSwitchs[ $value ];
770 $this->headers[ $value ] = '<a href="' . site_url() . '/wp-admin/admin.php?page=usces_orderlist&changeSort=' . $value . '&switch=' . $switch . '"><span>' . $key . '</span></a>';
771 }
772 }
773 }
774
775 /**
776 * Get Search.
777 *
778 * @return string
779 */
780 public function GetSearchs() {
781 return $this->arr_search;
782 }
783
784 /**
785 * Get Headers.
786 *
787 * @return string
788 */
789 public function GetListheaders() {
790 return $this->headers;
791 }
792
793 /**
794 * Get Navigation.
795 *
796 * @return string
797 */
798 public function GetDataTableNavigation() {
799 return $this->dataTableNavigation;
800 }
801
802 /**
803 * Set Action Status and Action Message.
804 *
805 * @param string $status Action status.
806 * @param string $message Action message.
807 */
808 public function set_action_status( $status, $message ) {
809 $this->action_status = $status;
810 $this->action_message = $message;
811 }
812
813 /**
814 * Get Action Status.
815 *
816 * @return string
817 */
818 public function get_action_status() {
819 return $this->action_status;
820 }
821
822 /**
823 * Get Action Message.
824 *
825 * @return string
826 */
827 public function get_action_message() {
828 return $this->action_message;
829 }
830
831 /**
832 * Get Period Specified.
833 *
834 * @return int
835 */
836 public function get_period_specified_index() {
837 return $this->period_specified_index;
838 }
839 }
840