PluginProbe
Welcart e-Commerce / 2.12.4
Welcart e-Commerce v2.12.4
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.12.4, at classes/orderList.class.php

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