PluginProbe
Welcart e-Commerce / 2.11.34
Welcart e-Commerce v2.11.34
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 / memberList.class.php

memberList.class.php in Welcart e-Commerce 2.11.34, at classes/memberList.class.php

926 lines 37.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Member List Class.
4 *
5 * @package Welcart
6 */
7 class WlcMemberList {
8 public $table; /* テーブル名 */
9 public $rows; /* データ */
10 public $action; /* アクション */
11 public $startRow; /* 表示開始行番号 */
12 public $maxRow; /* 最大表示行数 */
13 public $currentPage; /* 現在のページNo */
14 public $firstPage; /* 最初のページNo */
15 public $previousPage; /* 前のページNo */
16 public $nextPage; /* 次のページNo */
17 public $lastPage; /* 最終ページNo */
18 public $naviMaxButton; /* ページネーション・ナビのボタンの数 */
19 public $dataTableNavigation; /* ナヴィゲーションhtmlコード */
20 public $arr_period; /* 表示データ期間 */
21 public $arr_search; /* サーチ条件 */
22 public $searchWhere; /* オーダーカラム */
23 public $searchHaving; /* メンバーカラム */
24 public $columns; /* データカラム */
25 public $sortColumn; /* 現在ソート中のフィールド */
26 public $sortOldColumn;
27 public $sortSwitchs; /* 各フィールド毎の昇順降順スイッチ */
28 public $userHeaderNames; /* ユーザー指定のヘッダ名 */
29 public $pageLimit; /* ページ制限 */
30 public $listOption;
31 public $csmb_meta;
32 public $admb_meta;
33 public $csod_meta;
34 public $action_status;
35 public $action_message;
36 public $currentPageIds;
37 public $placeholder_escape;
38 public $data_cookie;
39
40 public $totalRow;
41 public $selectedRow;
42 public $headers;
43
44 /**
45 * Constructor.
46 */
47 public function __construct() {
48 global $wpdb;
49 $this->csmb_meta = usces_has_custom_field_meta( 'member' );
50 $this->admb_meta = usces_has_custom_field_meta( 'admin_member' );
51 $this->csod_meta = usces_has_custom_field_meta( 'order' );
52
53 $this->listOption = get_option( 'usces_memberlist_option', array() );
54
55 $this->table = usces_get_tablename( 'usces_member' );
56 $this->set_column();
57 $this->rows = array();
58
59 $this->maxRow = $this->listOption['max_row'] ?? 50;
60 $this->naviMaxButton = 11;
61 $this->firstPage = 1;
62 $this->pageLimit = 'on';
63 $this->action_status = 'none';
64 $this->action_message = '';
65
66 $this->getCookie();
67 $this->SetDefaultParam();
68 $this->SetParamByQuery();
69 $this->validationSearchParameters();
70 $this->arr_period = array(
71 __( 'This month', 'usces' ),
72 __( 'Last month', 'usces' ),
73 __( 'The past one week', 'usces' ),
74 __( 'Last 30 days', 'usces' ),
75 __( 'Last 90days', 'usces' ),
76 __( 'All', 'usces' ),
77 );
78
79 $wpdb->query( 'SET SQL_BIG_SELECTS=1' );
80 }
81
82 /**
83 * Set Column.
84 */
85 public function set_column() {
86 $arr_column = array();
87 $arr_column['ID'] = __( 'membership number', 'usces' );
88 $arr_column['name1'] = __( 'Last Name', 'usces' );
89 $arr_column['name2'] = __( 'First Name', 'usces' );
90 $arr_column['name3'] = __( 'Last Furigana', 'usces' );
91 $arr_column['name4'] = __( 'First Furigana', 'usces' );
92 $arr_column['zipcode'] = __( 'Zip', 'usces' );
93 $arr_column['country'] = __( 'Country', 'usces' );
94 $arr_column['pref'] = __( 'Province', 'usces' );
95 $arr_column['address1'] = __( 'city', 'usces' );
96 $arr_column['address2'] = __( 'numbers', 'usces' );
97 $arr_column['address3'] = __( 'building name', 'usces' );
98 $arr_column['tel'] = __( 'Phone number', 'usces' );
99 $arr_column['fax'] = __( 'FAX number', 'usces' );
100 $arr_column['email'] = __( 'e-mail', 'usces' );
101 $arr_column['entrydate'] = __( 'Entry date', 'usces' );
102 $arr_column['rank'] = __( 'Rank', 'usces' );
103 $arr_column['point'] = __( 'current point', 'usces' );
104
105 foreach ( (array) $this->csmb_meta as $key => $value ) {
106 $csmb_key = 'csmb_' . $key;
107 $csmb_name = $value['name'];
108 $arr_column[ $csmb_key ] = $csmb_name;
109 }
110
111 foreach ( (array) $this->admb_meta as $key => $value ) {
112 $admb_key = 'admb_' . $key;
113 $admb_name = $value['name'];
114 $arr_column[ $admb_key ] = $admb_name;
115 }
116
117 foreach ( (array) $this->csod_meta as $key => $value ) {
118 $csod_key = 'csod_' . $key;
119 $csod_name = $value['name'];
120 $arr_column[ $csod_key ] = $csod_name;
121 }
122
123 $arr_column = apply_filters( 'usces_filter_memberlist_column', $arr_column, $this );
124 $this->columns = $arr_column;
125 }
126
127 /**
128 * Get Column.
129 */
130 public function get_column() {
131 return $this->columns;
132 }
133
134 /**
135 * Action.
136 *
137 * @return mixed
138 */
139 public function MakeTable() {
140
141 $this->SetParam();
142
143 switch ( $this->action ) {
144
145 case 'searchOut':
146 check_admin_referer( 'member_list', 'wc_nonce' );
147 $this->SearchOut();
148 $res = $this->GetRows();
149 break;
150
151 case 'collective_rank':
152 check_admin_referer( 'member_list', 'wc_nonce' );
153 usces_all_change_member_rank( $this );
154 $this->SearchIn();
155 $res = $this->GetRows();
156 break;
157
158 case 'collective_point':
159 check_admin_referer( 'member_list', 'wc_nonce' );
160 usces_all_change_member_point( $this );
161 $this->SearchIn();
162 $res = $this->GetRows();
163 break;
164
165 case 'collective_delete':
166 check_admin_referer( 'member_list', 'wc_nonce' );
167 usces_all_delete_member_data( $this );
168 $this->SearchIn();
169 $res = $this->GetRows();
170 break;
171
172 case 'searchIn':
173 case 'returnList':
174 case 'changeSort':
175 case 'changePage':
176 case 'refresh':
177 check_admin_referer( 'member_list', 'wc_nonce' );
178 default:
179 $this->SearchIn();
180 $res = $this->GetRows();
181 break;
182 }
183
184 $this->SetNavi();
185 $this->SetHeaders();
186
187 if ( $res ) {
188 return true;
189 } else {
190 return false;
191 }
192 }
193
194 /**
195 * Default Parameters.
196 */
197 public function SetDefaultParam() {
198 $this->startRow = isset( $this->data_cookie['startRow'] ) ? $this->data_cookie['startRow'] : 0;
199 $this->currentPage = isset( $this->data_cookie['currentPage'] ) ? $this->data_cookie['currentPage'] : 1;
200 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : 'ID';
201 $this->searchWhere = ( isset( $this->data_cookie['searchWhere'] ) ) ? $this->data_cookie['searchWhere'] : '';
202 $this->searchHaving = ( isset( $this->data_cookie['searchHaving'] ) ) ? $this->data_cookie['searchHaving'] : '';
203 if ( isset( $this->data_cookie['arr_search'] ) ) {
204 $this->arr_search = $this->data_cookie['arr_search'];
205 } else {
206 $this->arr_search = array(
207 'period' => '3',
208 'member_column' => array( '', '' ),
209 'member_word' => array( '', '' ),
210 'member_word_term' => array( 'contain', 'contain' ),
211 'member_term' => 'AND',
212 'order_column' => array( '', '' ),
213 'order_word' => array( '', '' ),
214 'order_word_term' => array( 'contain', 'contain' ),
215 'order_term' => 'AND',
216 );
217 }
218 if ( isset( $this->data_cookie['sortSwitchs'] ) ) {
219 $this->sortSwitchs = $this->data_cookie['sortSwitchs'];
220 foreach ( $this->csmb_meta as $key => $value ) {
221 $csmb_key = 'csmb_' . $key;
222 if ( ! isset( $this->sortSwitchs[ $csmb_key ] ) ) {
223 $this->sortSwitchs[ $csmb_key ] = 'DESC';
224 }
225 }
226 foreach ( $this->admb_meta as $key => $value ) {
227 $admb_key = 'admb_' . $key;
228 if ( ! isset( $this->sortSwitchs[ $admb_key ] ) ) {
229 $this->sortSwitchs[ $admb_key ] = 'DESC';
230 }
231 }
232 } else {
233 $this->sortSwitchs[ $this->sortColumn ] = 'DESC';
234 }
235
236 $this->SetTotalRow();
237 }
238
239 /**
240 * Set Parameters.
241 */
242 public function SetParam() {
243 $this->startRow = ( $this->currentPage - 1 ) * $this->maxRow;
244 }
245
246 /**
247 * Set Parameters.
248 */
249 public function SetParamByQuery() {
250 global $wpdb;
251 if ( isset( $_REQUEST['changePage'] ) ) {
252
253 $this->action = 'changePage';
254 $this->currentPage = (int) $_REQUEST['changePage'];
255 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
256 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
257 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
258 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
259 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
260 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
261 $this->placeholder_escape = ( isset( $this->data_cookie['placeholder_escape'] ) ) ? $this->data_cookie['placeholder_escape'] : $this->placeholder_escape;
262
263 } elseif ( isset( $_REQUEST['returnList'] ) ) {
264
265 $this->action = 'returnList';
266 $this->currentPage = ( isset( $this->data_cookie['currentPage'] ) ) ? $this->data_cookie['currentPage'] : $this->currentPage;
267 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
268 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
269 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
270 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
271 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
272 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
273 $this->placeholder_escape = ( isset( $this->data_cookie['placeholder_escape'] ) ) ? $this->data_cookie['placeholder_escape'] : $this->placeholder_escape;
274
275 } elseif ( isset( $_REQUEST['changeSort'] ) ) {
276
277 $this->action = 'changeSort';
278 $this->sortOldColumn = $this->sortColumn;
279 // Validate sortColumn.
280 if ( in_array( $_REQUEST['changeSort'], array_keys( $this->columns ) ) ) {
281 $this->sortColumn = $_REQUEST['changeSort'];
282 } else {
283 $this->sortColumn = 'ID'; // default.
284 }
285 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
286 // Validate sortSwitchs.
287 if ( isset( $_REQUEST['switch'] ) && in_array( $_REQUEST['switch'], array( 'ASC', 'DESC' ) ) ) {
288 $this->sortSwitchs[ $this->sortColumn ] = $_REQUEST['switch'];
289 } else {
290 $this->sortSwitchs[ $this->sortColumn ] = 'DESC'; // default.
291 }
292 $this->currentPage = ( isset( $this->data_cookie['currentPage'] ) ) ? $this->data_cookie['currentPage'] : $this->currentPage;
293 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
294 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
295 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
296 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
297 $this->placeholder_escape = ( isset( $this->data_cookie['placeholder_escape'] ) ) ? $this->data_cookie['placeholder_escape'] : $this->placeholder_escape;
298
299 } elseif ( isset( $_REQUEST['searchIn'] ) ) {
300
301 $this->action = 'searchIn';
302 $this->arr_search['member_column'][0] = ! WCUtils::is_blank( $_REQUEST['search']['member_column'][0] ) ? str_replace( '`', '', $_REQUEST['search']['member_column'][0] ) : '';
303 $this->arr_search['member_column'][1] = ! WCUtils::is_blank( $_REQUEST['search']['member_column'][1] ) ? str_replace( '`', '', $_REQUEST['search']['member_column'][1] ) : '';
304 $this->arr_search['member_word'][0] = ! WCUtils::is_blank( $_REQUEST['search']['member_word'][0] ) ? trim( $_REQUEST['search']['member_word'][0] ) : '';
305 $this->arr_search['member_word'][1] = ! WCUtils::is_blank( $_REQUEST['search']['member_word'][1] ) ? trim( $_REQUEST['search']['member_word'][1] ) : '';
306 $this->arr_search['member_word_term'][0] = isset( $_REQUEST['search']['member_word_term'][0] ) ? $_REQUEST['search']['member_word_term'][0] : 'contain';
307 $this->arr_search['member_word_term'][1] = isset( $_REQUEST['search']['member_word_term'][1] ) ? $_REQUEST['search']['member_word_term'][1] : 'contain';
308 if ( WCUtils::is_blank( $_REQUEST['search']['member_column'][0] ) ) {
309 $this->arr_search['member_column'][1] = '';
310 $this->arr_search['member_word'][0] = '';
311 $this->arr_search['member_word'][1] = '';
312 $this->arr_search['member_word_term'][0] = 'contain';
313 $this->arr_search['member_word_term'][1] = 'contain';
314 }
315 $this->arr_search['member_term'] = $_REQUEST['search']['member_term'];
316 $this->arr_search['order_column'][0] = ! WCUtils::is_blank( $_REQUEST['search']['order_column'][0] ) ? str_replace( '`', '', $_REQUEST['search']['order_column'][0] ) : '';
317 $this->arr_search['order_column'][1] = ! WCUtils::is_blank( $_REQUEST['search']['order_column'][1] ) ? str_replace( '`', '', $_REQUEST['search']['order_column'][1] ) : '';
318 $this->arr_search['order_word'][0] = ! WCUtils::is_blank( $_REQUEST['search']['order_word'][0] ) ? trim( $_REQUEST['search']['order_word'][0] ) : '';
319 $this->arr_search['order_word'][1] = ! WCUtils::is_blank( $_REQUEST['search']['order_word'][1] ) ? trim( $_REQUEST['search']['order_word'][1] ) : '';
320 $this->arr_search['order_word_term'][0] = isset( $_REQUEST['search']['order_word_term'][0] ) ? $_REQUEST['search']['order_word_term'][0] : 'contain';
321 $this->arr_search['order_word_term'][1] = isset( $_REQUEST['search']['order_word_term'][1] ) ? $_REQUEST['search']['order_word_term'][1] : 'contain';
322 if ( WCUtils::is_blank( $_REQUEST['search']['order_column'][0] ) ) {
323 $this->arr_search['order_column'][1] = '';
324 $this->arr_search['order_word'][0] = '';
325 $this->arr_search['order_word'][1] = '';
326 $this->arr_search['order_word_term'][0] = 'contain';
327 $this->arr_search['order_word_term'][1] = 'contain';
328 }
329 $this->arr_search['order_term'] = $_REQUEST['search']['order_term'];
330 $this->currentPage = 1;
331 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
332 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
333 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
334 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
335 $this->placeholder_escape = $wpdb->placeholder_escape();
336
337 } elseif ( isset( $_REQUEST['searchOut'] ) ) {
338
339 $this->action = 'searchOut';
340 $this->arr_search['column'] = '';
341 $this->arr_search['word'] = '';
342 $this->arr_search['member_column'][0] = '';
343 $this->arr_search['member_column'][1] = '';
344 $this->arr_search['member_word'][0] = '';
345 $this->arr_search['member_word'][1] = '';
346 $this->arr_search['member_word_term'][0] = 'contain';
347 $this->arr_search['member_word_term'][1] = 'contain';
348 $this->arr_search['member_term'] = 'AND';
349 $this->arr_search['order_column'][0] = '';
350 $this->arr_search['order_column'][1] = '';
351 $this->arr_search['order_word'][0] = '';
352 $this->arr_search['order_word'][1] = '';
353 $this->arr_search['order_word_term'][0] = 'contain';
354 $this->arr_search['order_word_term'][1] = 'contain';
355 $this->arr_search['order_term'] = 'AND';
356 $this->currentPage = 1;
357 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
358 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
359 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
360 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
361 $this->placeholder_escape = '';
362
363 } elseif ( isset( $_REQUEST['collective'] ) ) {
364
365 $this->action = 'collective_' . str_replace( ',', '', $_POST['allchange']['column'] );
366 $this->currentPage = ( isset( $this->data_cookie['currentPage'] ) ) ? $this->data_cookie['currentPage'] : $this->currentPage;
367 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
368 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
369 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
370 $this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search;
371 $this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow;
372 $this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow;
373 $this->selectedRow = ( isset( $this->data_cookie['placeholder_escape'] ) ) ? $this->data_cookie['placeholder_escape'] : $this->placeholder_escape;
374
375 } elseif ( isset( $_REQUEST['refresh'] ) ) {
376
377 $this->action = 'refresh';
378 $this->currentPage = ( isset( $this->data_cookie['currentPage'] ) ) ? $this->data_cookie['currentPage'] : $this->currentPage;
379 $this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn;
380 $this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs;
381 $this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames;
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 } else {
388
389 $this->action = 'default';
390 $this->placeholder_escape = '';
391 }
392 }
393
394 /**
395 * Validation Search Parameters.
396 */
397 public function validationSearchParameters() {
398 $default_member_word_term = [ 'contain', 'notcontain', 'equal', 'morethan', 'lessthan' ];
399 $default_order_word_term = [ 'contain', 'notcontain', 'equal', 'morethan', 'lessthan' ];
400 $default_order_term = [ 'AND', 'OR' ];
401 $default_member_term = [ 'AND', 'OR' ];
402 $default_order_columns = [ 'item_code', 'item_name', 'sku_code', 'sku_name', 'item_option' ];
403 if ( ! empty( $this->arr_search['member_column'][0] ) && ! array_key_exists( $this->arr_search['member_column'][0], $this->columns ) ) {
404 $this->arr_search['member_column'][0] = key( $this->columns );
405 }
406 if ( ! empty( $this->arr_search['member_column'][1] ) && ! array_key_exists( $this->arr_search['member_column'][1], $this->columns ) ) {
407 $this->arr_search['member_column'][1] = key( $this->columns );
408 }
409
410 if ( ! empty( $this->arr_search['member_word_term'][0] ) && ! in_array( $this->arr_search['member_word_term'][0], $default_member_word_term ) ) {
411 $this->arr_search['member_word_term'][0] = $default_order_word_term[0];
412 }
413 if ( ! empty( $this->arr_search['member_word_term'][1] ) && ! in_array( $this->arr_search['member_word_term'][1], $default_order_word_term ) ) {
414 $this->arr_search['member_word_term'][1] = $default_order_word_term[0];
415 }
416 if ( ! in_array( $this->arr_search['member_term'], $default_member_term ) ) {
417 $this->arr_search['member_term'] = $default_member_term[0];
418 }
419
420 if ( ! empty( $this->arr_search['order_column'][0] ) && ! in_array( $this->arr_search['order_column'][0], $default_order_columns ) ) {
421 $this->arr_search['order_column'][0] = $default_order_columns[0];
422 }
423 if ( ! empty( $this->arr_search['order_column'][1] ) && ! in_array( $this->arr_search['order_column'][1], $default_order_columns ) ) {
424 $this->arr_search['order_column'][1] = $default_order_columns[0];
425 }
426
427 if ( ! empty( $this->arr_search['order_word_term'][0] ) && ! in_array( $this->arr_search['order_word_term'][0], $default_order_word_term ) ) {
428 $this->arr_search['order_word_term'][0] = $default_order_word_term[0];
429 }
430 if ( ! empty( $this->arr_search['order_word_term'][1] ) && ! in_array( $this->arr_search['order_word_term'][1], $default_order_word_term ) ) {
431 $this->arr_search['order_word_term'][1] = $default_order_word_term[0];
432 }
433 if ( ! in_array( $this->arr_search['order_term'], $default_order_term ) ) {
434 $this->arr_search['order_term'] = $default_order_term[0];
435 }
436 }
437
438 /**
439 * Get Rows.
440 *
441 * @return array
442 */
443 public function GetRows() {
444 global $wpdb;
445
446 $member_meta_table = usces_get_tablename( 'usces_member_meta' );
447 $order_table = $wpdb->prefix . 'usces_order';
448 $order_meta_table = $wpdb->prefix . 'usces_order_meta';
449 $ordercart_table = $wpdb->prefix . 'usces_ordercart';
450 $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
451
452 $where = $this->GetWhere();
453 $having = $this->GetHaving();
454
455 $join = '';
456 $csmb = '';
457 $admb = '';
458 $csod = '';
459 foreach ( $this->columns as $key => $value ) {
460 if ( 'csmb_' === substr( $key, 0, 5 ) ) {
461 $join .= $wpdb->prepare( " LEFT JOIN {$member_meta_table} AS `p{$key}` ON mem.ID = `p{$key}`.member_id AND `p{$key}`.meta_key = %s ", $key ) . "\n";
462 $csmb .= ', `p' . $key . '`.meta_value AS `' . $key . "`\n";
463 }
464 if ( 'admb_' === substr( $key, 0, 5 ) ) {
465 $join .= $wpdb->prepare( " LEFT JOIN {$member_meta_table} AS `p{$key}` ON mem.ID = `p{$key}`.member_id AND `p{$key}`.meta_key = %s ", $key ) . "\n";
466 $admb .= ', `p' . $key . '`.meta_value AS `' . $key . "`\n";
467 }
468 }
469
470 if ( $where ) {
471 $join .= " LEFT JOIN {$order_table} AS `ord` ON mem.ID = ord.mem_id " . "\n";
472
473 foreach ( $this->columns as $key => $value ) {
474 if ( 'csod_' === substr( $key, 0, 5 ) ) {
475 $join .= $wpdb->prepare(" LEFT JOIN {$order_meta_table} AS `p{$key}` ON ord.ID = `p{$key}`.order_id AND `p{$key}`.meta_key = %s ", $key ) . "\n";
476 $csod .= ', `p' . $key . '`.meta_value ' . "\n";
477 }
478 }
479
480 $join .= " LEFT JOIN {$ordercart_table} AS `cart` ON ord.ID = cart.order_id " . "\n";
481 $csod .= ', cart.item_code , cart.item_name , cart.sku_code , cart.sku_name ' . "\n";
482 }
483 $join = apply_filters( 'usces_filter_memberlist_sql_jointable', $join, $this );
484
485 $group = ' GROUP BY `ID` ';
486
487 $init_column = 'ID';
488 $sort_column = in_array( $this->sortColumn, array_keys( $this->columns ), true ) ? $this->sortColumn : $init_column;
489 $init_switch = 'DESC';
490 $sort_switch = $this->sortSwitchs[ $sort_column ] ?? $init_switch;
491 $sort_switch = in_array( strtoupper( $sort_switch ), array( 'ASC', 'DESC' ), true ) ? $sort_switch : $init_switch;
492 $order = ' ORDER BY ' . esc_sql( $sort_column ) . ' ' . esc_sql( $sort_switch );
493 $order = apply_filters( 'usces_filter_memberlist_sql_order', $order, $sort_column, $sort_switch, $this );
494
495 $query = $wpdb->prepare(
496 "SELECT
497 mem.ID AS `ID`,
498 mem.mem_name1 AS `name1`,
499 mem.mem_name2 AS `name2`,
500 mem.mem_name3 AS `name3`,
501 mem.mem_name4 AS `name4`,
502 mem.mem_zip AS `zipcode`,
503 country.meta_value AS `country`,
504 mem.mem_pref AS `pref`,
505 mem.mem_address1 AS `address1`,
506 mem.mem_address2 AS `address2`,
507 mem.mem_address3 AS `address3`,
508 mem.mem_tel AS `tel`,
509 mem.mem_fax AS `fax`,
510 mem.mem_email AS `email`,
511 DATE_FORMAT(mem.mem_registered, %s) AS `entrydate`,
512 mem.mem_status AS `rank`,
513 mem.mem_point AS `point`
514 {$csmb}
515 {$admb}
516 {$csod}
517 FROM {$this->table} AS `mem`
518 LEFT JOIN {$member_meta_table} AS `country` ON mem.ID = country.member_id AND country.meta_key = %s ",
519 '%Y-%m-%d %H:%i', 'customer_country'
520 );
521 $query = apply_filters( 'usces_filter_memberlist_sql_select', $query, $csmb, $csod, $this );
522
523 $query .= $join . $where . $group . $having . $order;
524
525 if ( $this->placeholder_escape ) {
526 add_filter( 'query', array( $this, 'remove_ph' ) );
527 }
528
529 $rows = $wpdb->get_results( $query, ARRAY_A );
530
531 $this->selectedRow = ( $rows && is_array( $rows ) ) ? count( $rows ) : 0;
532 if ( 'on' == $this->pageLimit ) {
533 $this->rows = array_slice( $rows, $this->startRow, $this->maxRow );
534 $this->currentPageIds = array();
535 foreach ( $this->rows as $row ) {
536 $this->currentPageIds[] = $row['ID'];
537 }
538 } else {
539 $this->rows = $rows;
540 }
541 return $this->rows;
542 }
543
544 /**
545 * Placeholder clear.
546 *
547 * @param string $query Query.
548 * @return string
549 */
550 public function remove_ph( $query ) {
551 return str_replace( $this->placeholder_escape, '%', $query );
552 }
553
554 /**
555 * Set Total Rows.
556 */
557 public function SetTotalRow() {
558 global $wpdb;
559 $query = "SELECT COUNT(ID) AS `ct` FROM {$this->table}";
560 $res = $wpdb->get_var( $query );
561 $this->totalRow = $res;
562 }
563
564 /**
565 * Having Condition.
566 *
567 * @return string
568 */
569 public function GetHaving() {
570 global $wpdb;
571
572 $str = '';
573 if ( ! WCUtils::is_blank( $this->searchHaving ) ) {
574 $str .= ' HAVING ' . $this->searchHaving;
575 }
576 $str = apply_filters( 'usces_filter_memberlist_sql_having', $str, $this->searchHaving, $this );
577 return $str;
578 }
579
580 /**
581 * Where Condition.
582 *
583 * @return string
584 */
585 public function GetWhere() {
586 $str = '';
587 if ( ! WCUtils::is_blank( $this->searchWhere ) ) {
588 $str .= ' WHERE ' . $this->searchWhere;
589 }
590 $str = apply_filters( 'usces_filter_memberlist_sql_where', $str, $this->searchWhere, $this );
591 return $str;
592 }
593
594 /**
595 * Search.
596 */
597 public function SearchIn() {
598 global $wpdb;
599
600 $this->searchWhere = '';
601 $this->searchHaving = '';
602
603 if ( ! empty( $this->arr_search['order_column'][0] ) && ! WCUtils::is_blank( $this->arr_search['order_word'][0] ) ) {
604 switch ( $this->arr_search['order_word_term'][0] ) {
605 case 'notcontain':
606 $wordterm0 = ' NOT LIKE %s';
607 $word0 = '%' . $this->arr_search['order_word'][0] . '%';
608 break;
609 case 'equal':
610 $wordterm0 = ' = %s';
611 $word0 = $this->arr_search['order_word'][0];
612 break;
613 case 'morethan':
614 $wordterm0 = ' > %d';
615 $word0 = $this->arr_search['order_word'][0];
616 break;
617 case 'lessthan':
618 $wordterm0 = ' < %d';
619 $word0 = $this->arr_search['order_word'][0];
620 break;
621 case 'contain':
622 default:
623 $wordterm0 = ' LIKE %s';
624 $word0 = '%' . $this->arr_search['order_word'][0] . '%';
625 break;
626 }
627
628 switch ( $this->arr_search['order_word_term'][1] ) {
629 case 'notcontain':
630 $wordterm1 = ' NOT LIKE %s';
631 $word1 = '%' . $this->arr_search['order_word'][1] . '%';
632 break;
633 case 'equal':
634 $wordterm1 = ' = %s';
635 $word1 = $this->arr_search['order_word'][1];
636 break;
637 case 'morethan':
638 $wordterm1 = ' > %d';
639 $word1 = $this->arr_search['order_word'][1];
640 break;
641 case 'lessthan':
642 $wordterm1 = ' < %d';
643 $word1 = $this->arr_search['order_word'][1];
644 break;
645 case 'contain':
646 default:
647 $wordterm1 = ' LIKE %s';
648 $word1 = '%' . $this->arr_search['order_word'][1] . '%';
649 break;
650 }
651
652 $this->searchWhere .= ' ( ';
653
654 if ( 'csod_' == substr( $this->arr_search['order_column'][0], 0, 5) ) {
655 $this->searchWhere .= $wpdb->prepare( '`p' . esc_sql( $this->arr_search['order_column'][0] ) . '`.meta_value LIKE %s', '%' . $this->arr_search['order_word'][0] . '%' );
656 } else {
657 $this->searchWhere .= '`' . $wpdb->prepare( esc_sql( $this->arr_search['order_column'][0] ) . '`' . $wordterm0, $word0 );
658 }
659 if ( ! empty( $this->arr_search['order_column'][1] ) && ! WCUtils::is_blank( $this->arr_search['order_word'][1] ) ) {
660 $this->searchWhere .= ' ' . $this->arr_search['order_term'] . ' ';
661 if ( 'csod_' == substr( $this->arr_search['order_column'][1], 0, 5 ) ) {
662 $this->searchWhere .= $wpdb->prepare( '`p' . esc_sql( $this->arr_search['order_column'][1] ) . '`.meta_value LIKE %s', '%' . $this->arr_search['order_word'][1] . '%' );
663 } else {
664 $this->searchWhere .= '`' . $wpdb->prepare( esc_sql( $this->arr_search['order_column'][1] ) . '`' . $wordterm1, $word1 );
665 }
666 }
667
668 $this->searchWhere .= ' ) ';
669 }
670
671 if ( ! empty( $this->arr_search['member_column'][0] ) && ! WCUtils::is_blank( $this->arr_search['member_word'][0] ) ) {
672
673 switch ( $this->arr_search['member_word_term'][0] ) {
674 case 'notcontain':
675 if ( 'rank' === $this->arr_search['member_column'][0] ) {
676 $wordterm0 = ' != %d';
677 $word0 = (int) $this->arr_search['member_word'][0];
678 } else {
679 $wordterm0 = ' NOT LIKE %s';
680 $word0 = '%' . $this->arr_search['member_word'][0] . '%';
681 }
682 break;
683 case 'equal':
684 $wordterm0 = ' = %s';
685 $word0 = $this->arr_search['member_word'][0];
686 break;
687 case 'morethan':
688 $wordterm0 = ' > %d';
689 $word0 = $this->arr_search['member_word'][0];
690 break;
691 case 'lessthan':
692 $wordterm0 = ' < %d';
693 $word0 = $this->arr_search['member_word'][0];
694 break;
695 case 'contain':
696 default:
697 if ( 'rank' === $this->arr_search['member_column'][0] ) {
698 $wordterm0 = ' = %d';
699 $word0 = (int) $this->arr_search['member_word'][0];
700 } else {
701 $wordterm0 = ' LIKE %s';
702 $word0 = '%' . $this->arr_search['member_word'][0] . '%';
703 }
704 break;
705 }
706
707 switch ( $this->arr_search['member_word_term'][1] ) {
708 case 'notcontain':
709 if ( 'rank' === $this->arr_search['member_column'][1] ) {
710 $wordterm1 = ' != %d';
711 $word1 = (int) $this->arr_search['member_word'][1];
712 } else {
713 $wordterm1 = ' NOT LIKE %s';
714 $word1 = '%' . $this->arr_search['member_word'][1] . '%';
715 }
716 break;
717 case 'equal':
718 $wordterm1 = ' = %s';
719 $word1 = $this->arr_search['member_word'][1];
720 break;
721 case 'morethan':
722 $wordterm1 = ' > %d';
723 $word1 = $this->arr_search['member_word'][1];
724 break;
725 case 'lessthan':
726 $wordterm1 = ' < %d';
727 $word1 = $this->arr_search['member_word'][1];
728 break;
729 case 'contain':
730 default:
731 if ( 'rank' === $this->arr_search['member_column'][1] ) {
732 $wordterm1 = ' = %d';
733 $word1 = (int) $this->arr_search['member_word'][1];
734 } else {
735 $wordterm1 = ' LIKE %s';
736 $word1 = '%' . $this->arr_search['member_word'][1] . '%';
737 }
738 break;
739 }
740
741 $this->searchHaving .= ' ( ';
742 $this->searchHaving .= '`' . $wpdb->prepare( esc_sql( $this->arr_search['member_column'][0] ) . '`' . $wordterm0, $word0 );
743
744 if ( ! empty( $this->arr_search['member_column'][1] ) && ! WCUtils::is_blank( $this->arr_search['member_word'][1] ) ) {
745 $this->searchHaving .= ' ' . $this->arr_search['member_term'] . ' ';
746 $this->searchHaving .= '`' . $wpdb->prepare( esc_sql( $this->arr_search['member_column'][1] ) . '`' . $wordterm1, $word1 );
747 }
748 $this->searchHaving .= ' ) ';
749 }
750 }
751
752 /**
753 * Search clear.
754 */
755 public function SearchOut() {
756 $this->searchWhere = '';
757 $this->searchHaving = '';
758 }
759
760 /**
761 * Set Navigation.
762 */
763 public function SetNavi() {
764
765 $this->lastPage = ceil( $this->selectedRow / $this->maxRow );
766 $this->previousPage = ( $this->currentPage - 1 == 0 ) ? 1 : $this->currentPage - 1;
767 $this->nextPage = ( $this->currentPage + 1 > $this->lastPage ) ? $this->lastPage : $this->currentPage + 1;
768 $box = array();
769
770 for ( $i = 0; $i < $this->naviMaxButton; $i++ ) {
771 if ( $i > $this->lastPage - 1 ) {
772 break;
773 }
774 if ( $this->lastPage <= $this->naviMaxButton ) {
775 $box[] = $i + 1;
776 } else {
777 if ( $this->currentPage <= 6 ) {
778 $label = $i + 1;
779 $box[] = $label;
780 } else {
781 $label = $i + 1 + $this->currentPage - 6;
782 $box[] = $label;
783 if ( $label == $this->lastPage ) {
784 break;
785 }
786 }
787 }
788 }
789
790 $html = '';
791 $html .= '<ul class="clearfix">';
792 $html .= '<li class="rowsnum">' . $this->selectedRow . ' / ' . $this->totalRow . ' ' . __( 'cases', 'usces' ) . '</li>';
793 if ( ( 1 === $this->currentPage ) || ( 0 === $this->selectedRow ) ) {
794 $html .= '<li class="navigationStr">first&lt;&lt;</li>';
795 $html .= '<li class="navigationStr">prev&lt;</li>';
796 } else {
797 $url = admin_url( 'admin.php?page=usces_memberlist&changePage=1' );
798 $nonce_url = wp_nonce_url( $url, 'member_list', 'wc_nonce' );
799 $html .= '<li class="navigationStr"><a href="' . esc_url( $nonce_url ) . '">first&lt;&lt;</a></li>';
800
801 $url = admin_url( 'admin.php?page=usces_memberlist&changePage=' . $this->previousPage );
802 $nonce_url = wp_nonce_url( $url, 'member_list', 'wc_nonce' );
803 $html .= '<li class="navigationStr"><a href="' . esc_url( $nonce_url ) . '">prev&lt;</a></li>';
804 }
805 if ( $this->selectedRow > 0 ) {
806 $box_count = count( $box );
807 for ( $i = 0; $i < $box_count; $i ++ ) {
808 if ( $box[ $i ] == $this->currentPage ) {
809 $html .= '<li class="navigationButtonSelected"><span>' . $box[ $i ] . '</span></li>';
810 } else {
811 $url = admin_url( 'admin.php?page=usces_memberlist&changePage=' . $box[ $i ] );
812 $nonce_url = wp_nonce_url( $url, 'member_list', 'wc_nonce' );
813 $html .= '<li class="navigationButton"><a href="' . esc_url( $nonce_url ) . '">' . $box[ $i ] . '</a></li>';
814 }
815 }
816 }
817 if ( ( $this->currentPage == $this->lastPage ) || ( 0 === $this->selectedRow ) ) {
818 $html .= '<li class="navigationStr">&gt;next</li>';
819 $html .= '<li class="navigationStr">&gt;&gt;last</li>';
820 } else {
821 $url = admin_url( 'admin.php?page=usces_memberlist&changePage=' . $this->nextPage );
822 $nonce_url = wp_nonce_url( $url, 'member_list', 'wc_nonce' );
823 $html .= '<li class="navigationStr"><a href="' . esc_url( $nonce_url ) . '">&gt;next</a></li>';
824
825 $url = admin_url( 'admin.php?page=usces_memberlist&changePage=' . $this->lastPage );
826 $nonce_url = wp_nonce_url( $url, 'member_list', 'wc_nonce' );
827 $html .= '<li class="navigationStr"><a href="' . esc_url( $nonce_url ) . '">&gt;&gt;last</a></li>';
828 }
829
830 $html .= '</ul>';
831
832 $this->dataTableNavigation = $html;
833 }
834
835 /**
836 * Get Cookie.
837 */
838 public function getCookie() {
839 $this->data_cookie = ( isset( $_COOKIE[ $this->table ] ) ) ? json_decode( str_replace( "\'", "'", str_replace( '\"','"', $_COOKIE[ $this->table ] ) ), true ) : array();
840 }
841
842 /**
843 * Set Headers.
844 */
845 public function SetHeaders() {
846 foreach ( $this->columns as $key => $value ) {
847 if ( 'csod_' == substr( $key, 0, 5 ) ) {
848 continue;
849 }
850 if ( $key == $this->sortColumn ) {
851 if ( isset( $this->sortSwitchs[ $key ] ) && 'ASC' == $this->sortSwitchs[ $key ] ) {
852 $str = __( '[ASC]', 'usces' );
853 $switch = 'DESC';
854 } else {
855 $str = __( '[DESC]', 'usces' );
856 $switch = 'ASC';
857 }
858 $url = admin_url( 'admin.php?page=usces_memberlist&changeSort=' . $key . '&switch=' . $switch );
859 $nonce_url = wp_nonce_url( $url, 'member_list', 'wc_nonce' );
860 $this->headers[ $key ] = '<a href="' . esc_url( $nonce_url ) . '"><span class="sortcolumn">' . $value . ' ' . $str . '</span></a>';
861 } else {
862 $switch = isset( $this->sortSwitchs[ $key ] ) ? $this->sortSwitchs[ $key ] : 'DESC';
863 $url = admin_url( 'admin.php?page=usces_memberlist&changeSort=' . $key . '&switch=' . $switch );
864 $nonce_url = wp_nonce_url( $url, 'member_list', 'wc_nonce' );
865 $this->headers[ $key ] = '<a href="' . esc_url( $nonce_url ) . '"><span>' . $value . '</span></a>';
866 }
867 }
868 }
869
870 /**
871 * Get Search.
872 *
873 * @return string
874 */
875 public function GetSearchs() {
876 return $this->arr_search;
877 }
878
879 /**
880 * Get Headers.
881 *
882 * @return string
883 */
884 public function GetListheaders() {
885 return $this->headers;
886 }
887
888 /**
889 * Get Navigation.
890 *
891 * @return string
892 */
893 public function GetDataTableNavigation() {
894 return $this->dataTableNavigation;
895 }
896
897 /**
898 * Set Action Status and Action Message.
899 *
900 * @param string $status Action status.
901 * @param string $message Action message.
902 */
903 public function set_action_status( $status, $message ) {
904 $this->action_status = $status;
905 $this->action_message = $message;
906 }
907
908 /**
909 * Get Action Status.
910 *
911 * @return string
912 */
913 public function get_action_status() {
914 return $this->action_status;
915 }
916
917 /**
918 * Get Action Message.
919 *
920 * @return string
921 */
922 public function get_action_message() {
923 return $this->action_message;
924 }
925 }
926