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