| 1 |
<?php |
| 2 |
/** |
| 3 |
* Item List Class. |
| 4 |
* |
| 5 |
* @package Welcart |
| 6 |
*/ |
| 7 |
class dataList { |
| 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 $dataTableNavigationBottom; |
| 21 |
public $arr_period; /* 表示データ期間 */ |
| 22 |
public $arr_search; /* サーチ条件 */ |
| 23 |
public $searchSql; /* 簡易絞込みSQL */ |
| 24 |
public $searchSwitchStatus; /* サーチ表示スイッチ */ |
| 25 |
public $columns; /* データカラム */ |
| 26 |
public $sortColumn; /* 現在ソート中のフィールド */ |
| 27 |
public $sortOldColumn; |
| 28 |
public $sortSwitchs; /* 各フィールド毎の昇順降順スイッチ */ |
| 29 |
public $userHeaderNames; /* ユーザー指定のヘッダ名 */ |
| 30 |
public $action_status, $action_message; |
| 31 |
public $pageLimit; /* ページ制限 */ |
| 32 |
public $exportMode; /* IDのみ */ |
| 33 |
public $data_cookie; |
| 34 |
public $totalRow; |
| 35 |
public $selectedRow; |
| 36 |
public $headers; |
| 37 |
|
| 38 |
/** |
| 39 |
* Constructor. |
| 40 |
* |
| 41 |
* @param string $tableName Table name. |
| 42 |
* @param array $arr_column Columns. |
| 43 |
*/ |
| 44 |
public function __construct( $tableName, $arr_column ) { |
| 45 |
$this->table = $tableName; |
| 46 |
$this->columns = $arr_column; |
| 47 |
$this->rows = array(); |
| 48 |
|
| 49 |
$this->maxRow = apply_filters( 'usces_filter_itemlist_maxrow', 30 ); |
| 50 |
$this->naviMaxButton = 11; |
| 51 |
$this->firstPage = 1; |
| 52 |
$this->action_status = 'none'; |
| 53 |
$this->action_message = ''; |
| 54 |
$this->pageLimit = 'on'; |
| 55 |
$this->exportMode = false; |
| 56 |
$this->searchSql = ''; |
| 57 |
$this->getCookie(); |
| 58 |
$this->SetDefaultParam(); |
| 59 |
$this->SetParamByQuery(); |
| 60 |
$this->validationSearchParameters(); |
| 61 |
$this->setSearchSql(); |
| 62 |
|
| 63 |
$this->arr_period = array( |
| 64 |
__( 'This month', 'usces' ), |
| 65 |
__( 'Last month', 'usces' ), |
| 66 |
__( 'The past one week', 'usces' ), |
| 67 |
__( 'Last 30 days', 'usces' ), |
| 68 |
__( 'Last 90days', 'usces' ), |
| 69 |
__( 'All', 'usces' ), |
| 70 |
); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Action. |
| 75 |
* |
| 76 |
* @return bool |
| 77 |
*/ |
| 78 |
public function MakeTable() { |
| 79 |
|
| 80 |
$this->SetParam(); |
| 81 |
$this->SetTotalRow(); |
| 82 |
|
| 83 |
switch ( $this->action ) { |
| 84 |
|
| 85 |
case 'searchIn': |
| 86 |
check_admin_referer( 'item_master_list', 'wc_nonce' ); |
| 87 |
$res = $this->GetRows(); |
| 88 |
break; |
| 89 |
|
| 90 |
case 'searchOut': |
| 91 |
check_admin_referer( 'item_master_list', 'wc_nonce' ); |
| 92 |
$res = $this->GetRows(); |
| 93 |
break; |
| 94 |
|
| 95 |
case 'changeSort': |
| 96 |
check_admin_referer( 'item_master_list', 'wc_nonce' ); |
| 97 |
$res = $this->GetRows(); |
| 98 |
break; |
| 99 |
|
| 100 |
case 'changePage': |
| 101 |
check_admin_referer( 'item_master_list', 'wc_nonce' ); |
| 102 |
$res = $this->GetRows(); |
| 103 |
break; |
| 104 |
|
| 105 |
case 'collective_zaiko': |
| 106 |
if ( ! current_user_can( 'wel_others_products' ) ) { |
| 107 |
wp_die( esc_html__( 'You do not have sufficient privileges to perform this operation.', 'usces' ) ); |
| 108 |
} |
| 109 |
check_admin_referer( 'item_master_list', 'wc_nonce' ); |
| 110 |
usces_all_change_zaiko( $this ); |
| 111 |
$res = $this->GetRows(); |
| 112 |
break; |
| 113 |
|
| 114 |
case 'collective_display_status': |
| 115 |
if ( ! current_user_can( 'wel_others_products' ) ) { |
| 116 |
wp_die( esc_html__( 'You do not have sufficient privileges to perform this operation.', 'usces' ) ); |
| 117 |
} |
| 118 |
check_admin_referer( 'item_master_list', 'wc_nonce' ); |
| 119 |
usces_all_change_itemdisplay( $this ); |
| 120 |
$res = $this->GetRows(); |
| 121 |
break; |
| 122 |
|
| 123 |
case 'collective_delete': |
| 124 |
if ( ! current_user_can( 'wel_others_products' ) ) { |
| 125 |
wp_die( esc_html__( 'You do not have sufficient privileges to perform this operation.', 'usces' ) ); |
| 126 |
} |
| 127 |
check_admin_referer( 'item_master_list', 'wc_nonce' ); |
| 128 |
usces_all_delete_itemdata( $this ); |
| 129 |
$res = $this->GetRows(); |
| 130 |
break; |
| 131 |
|
| 132 |
case 'refresh': |
| 133 |
check_admin_referer( 'item_master_list', 'wc_nonce' ); |
| 134 |
|
| 135 |
default: |
| 136 |
$res = $this->GetRows(); |
| 137 |
break; |
| 138 |
} |
| 139 |
|
| 140 |
if ( ! $this->exportMode ) { |
| 141 |
$this->SetNavi(); |
| 142 |
$this->SetHeaders(); |
| 143 |
} |
| 144 |
|
| 145 |
if ( $res ) { |
| 146 |
return true; |
| 147 |
} else { |
| 148 |
return false; |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* Default Parameters. |
| 154 |
*/ |
| 155 |
public function SetDefaultParam() { |
| 156 |
$this->startRow = isset( $this->data_cookie['startRow'] ) ? $this->data_cookie['startRow'] : 0; |
| 157 |
$this->totalRow = isset( $this->data_cookie['totalRow'] ) ? $this->data_cookie['totalRow'] : 0; |
| 158 |
$this->selectedRow = isset( $this->data_cookie['selectedRow'] ) ? $this->data_cookie['selectedRow'] : 0; |
| 159 |
$this->currentPage = isset( $this->data_cookie['currentPage'] ) ? $this->data_cookie['currentPage'] : 1; |
| 160 |
$this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : apply_filters( 'usces_filter_item_class_sortColumn', 'post.ID' ); |
| 161 |
$this->searchSwitchStatus = ( isset( $this->data_cookie['searchSwitchStatus'] ) ) ? $this->data_cookie['searchSwitchStatus'] : 'OFF'; |
| 162 |
if ( isset( $this->data_cookie['arr_search'] ) ) { |
| 163 |
$this->arr_search = $this->data_cookie['arr_search']; |
| 164 |
} else { |
| 165 |
$arr_search = array( |
| 166 |
'period' => '3', |
| 167 |
'column' => '', |
| 168 |
'word' => array(), |
| 169 |
); |
| 170 |
$this->arr_search = apply_filters( 'usces_filter_item_class_arr_search', $arr_search, $this ); |
| 171 |
} |
| 172 |
if ( isset( $this->data_cookie['sortSwitchs'] ) ) { |
| 173 |
$this->sortSwitchs = $this->data_cookie['sortSwitchs']; |
| 174 |
} else { |
| 175 |
foreach ( $this->columns as $value ) { |
| 176 |
$this->sortSwitchs[ $value ] = 'ASC'; |
| 177 |
} |
| 178 |
$this->sortSwitchs[ $this->sortColumn ] = apply_filters( 'usces_filter_item_class_sortSwitchs', 'DESC' ); |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
/** |
| 183 |
* Set Parameters. |
| 184 |
*/ |
| 185 |
public function SetParam() { |
| 186 |
$this->startRow = ( $this->currentPage - 1 ) * $this->maxRow; |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* Set Parameters. |
| 191 |
*/ |
| 192 |
public function SetParamByQuery() { |
| 193 |
if ( isset( $_REQUEST['changePage'] ) ) { |
| 194 |
|
| 195 |
$this->action = 'changePage'; |
| 196 |
$this->currentPage = (int) $_REQUEST['changePage']; |
| 197 |
$this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn; |
| 198 |
$this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs; |
| 199 |
$this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames; |
| 200 |
$this->searchSwitchStatus = ( isset( $this->data_cookie['searchSwitchStatus'] ) ) ? $this->data_cookie['searchSwitchStatus'] : $this->searchSwitchStatus; |
| 201 |
$this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search; |
| 202 |
$this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow; |
| 203 |
$this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow; |
| 204 |
|
| 205 |
} elseif ( isset( $_REQUEST['changeSort'] ) ) { |
| 206 |
|
| 207 |
$this->action = 'changeSort'; |
| 208 |
$this->sortOldColumn = $this->sortColumn; |
| 209 |
$this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs; |
| 210 |
if ( 'default' === $_REQUEST['switch'] ) { |
| 211 |
// Restore default table. |
| 212 |
$this->sortColumn = 'post.ID'; |
| 213 |
foreach ( $this->sortSwitchs as $key => $val ) { |
| 214 |
if ( $key === $this->sortColumn ) { |
| 215 |
$this->sortSwitchs[ $key ] = 'DESC'; |
| 216 |
continue; |
| 217 |
} |
| 218 |
$this->sortSwitchs[ $key ] = 'ASC'; |
| 219 |
} |
| 220 |
} else { |
| 221 |
// Validate sortColumn. |
| 222 |
if ( in_array( $_REQUEST['changeSort'], $this->columns ) ) { |
| 223 |
$this->sortColumn = $_REQUEST['changeSort']; |
| 224 |
} else { |
| 225 |
$this->sortColumn = 'ID'; // default. |
| 226 |
} |
| 227 |
// Validate sortSwitchs. |
| 228 |
if ( isset( $_REQUEST['switch'] ) && in_array( $_REQUEST['switch'], array( 'ASC', 'DESC' ) ) ) { |
| 229 |
$this->sortSwitchs[ $this->sortColumn ] = $_REQUEST['switch']; |
| 230 |
} else { |
| 231 |
$this->sortSwitchs[ $this->sortColumn ] = 'DESC'; // default. |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
$this->currentPage = ( isset( $this->data_cookie['currentPage'] ) ) ? $this->data_cookie['currentPage'] : $this->userHeaderNames; |
| 236 |
$this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames; |
| 237 |
$this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search; |
| 238 |
$this->searchSwitchStatus = ( isset( $this->data_cookie['searchSwitchStatus'] ) ) ? $this->data_cookie['searchSwitchStatus'] : $this->searchSwitchStatus; |
| 239 |
$this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow; |
| 240 |
$this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow; |
| 241 |
|
| 242 |
} elseif ( isset( $_REQUEST['searchIn'] ) ) { |
| 243 |
|
| 244 |
$this->action = 'searchIn'; |
| 245 |
$this->arr_search['column'] = isset( $_REQUEST['search']['column'] ) ? str_replace( ',', '', $_REQUEST['search']['column'] ) : ''; |
| 246 |
$this->arr_search['word'] = isset( $_REQUEST['search']['word'] ) ? $_REQUEST['search']['word'] : ''; |
| 247 |
$this->arr_search['period'] = isset( $_REQUEST['search']['period'] ) ? (int) $_REQUEST['search']['period'] : ''; |
| 248 |
$this->searchSwitchStatus = 'ON'; |
| 249 |
|
| 250 |
$this->currentPage = 1; |
| 251 |
$this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn; |
| 252 |
$this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs; |
| 253 |
$this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames; |
| 254 |
$this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow; |
| 255 |
|
| 256 |
} elseif ( isset( $_REQUEST['searchOut'] ) ) { |
| 257 |
|
| 258 |
$this->action = 'searchOut'; |
| 259 |
$this->arr_search['column'] = ''; |
| 260 |
$this->arr_search['word'] = ''; |
| 261 |
$this->arr_search['period'] = ( isset( $this->data_cookie['arr_search']['period'] ) ) ? $this->data_cookie['arr_search']['period'] : $this->arr_search['period']; |
| 262 |
$this->searchSwitchStatus = 'OFF'; |
| 263 |
|
| 264 |
$this->currentPage = 1; |
| 265 |
$this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn; |
| 266 |
$this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs; |
| 267 |
$this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames; |
| 268 |
$this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow; |
| 269 |
|
| 270 |
} elseif ( isset( $_REQUEST['refresh'] ) ) { |
| 271 |
|
| 272 |
$this->action = 'refresh'; |
| 273 |
|
| 274 |
$this->currentPage = isset( $this->data_cookie['currentPage'] ) ? $this->data_cookie['currentPage'] : $this->currentPage; |
| 275 |
$this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn; |
| 276 |
$this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs; |
| 277 |
$this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames; |
| 278 |
$this->searchSwitchStatus = ( isset( $this->data_cookie['searchSwitchStatus'] ) ) ? $this->data_cookie['searchSwitchStatus'] : $this->searchSwitchStatus; |
| 279 |
$this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search; |
| 280 |
$this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow; |
| 281 |
$this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow; |
| 282 |
|
| 283 |
} elseif ( isset( $_REQUEST['collective'] ) ) { |
| 284 |
|
| 285 |
$this->action = 'collective_' . str_replace( ',', '', $_POST['allchange']['column'] ); |
| 286 |
$this->currentPage = isset( $this->data_cookie['currentPage'] ) ? $this->data_cookie['currentPage'] : $this->currentPage; |
| 287 |
$this->sortColumn = ( isset( $this->data_cookie['sortColumn'] ) ) ? $this->data_cookie['sortColumn'] : $this->sortColumn; |
| 288 |
$this->sortSwitchs = ( isset( $this->data_cookie['sortSwitchs'] ) ) ? $this->data_cookie['sortSwitchs'] : $this->sortSwitchs; |
| 289 |
$this->userHeaderNames = ( isset( $this->data_cookie['userHeaderNames'] ) ) ? $this->data_cookie['userHeaderNames'] : $this->userHeaderNames; |
| 290 |
$this->searchSwitchStatus = ( isset( $this->data_cookie['searchSwitchStatus'] ) ) ? $this->data_cookie['searchSwitchStatus'] : $this->searchSwitchStatus; |
| 291 |
$this->arr_search = ( isset( $this->data_cookie['arr_search'] ) ) ? $this->data_cookie['arr_search'] : $this->arr_search; |
| 292 |
$this->totalRow = ( isset( $this->data_cookie['totalRow'] ) ) ? $this->data_cookie['totalRow'] : $this->totalRow; |
| 293 |
$this->selectedRow = ( isset( $this->data_cookie['selectedRow'] ) ) ? $this->data_cookie['selectedRow'] : $this->selectedRow; |
| 294 |
|
| 295 |
} else { |
| 296 |
$this->action = 'default'; |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
/** |
| 301 |
* Validation Search Parameters. |
| 302 |
*/ |
| 303 |
public function validationSearchParameters() { |
| 304 |
if ( 'none' != $this->arr_search['column'] && ! in_array( $this->arr_search['column'], $this->columns ) ) { |
| 305 |
if ( is_array( $this->arr_search['word'] ) && count( $this->arr_search['word'] ) && in_array( $key = key( $this->arr_search['word'] ), $this->columns ) ) { |
| 306 |
$this->arr_search['column'] = $key; |
| 307 |
} else { |
| 308 |
$this->arr_search['column'] = 'none'; |
| 309 |
} |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
/** |
| 314 |
* Get Rows. |
| 315 |
* |
| 316 |
* @return array |
| 317 |
*/ |
| 318 |
public function GetRows() { |
| 319 |
global $wpdb; |
| 320 |
$item_table = $wpdb->prefix . 'usces_item'; |
| 321 |
$sku_table = $wpdb->prefix . 'usces_skus'; |
| 322 |
$where = $this->GetWhere(); |
| 323 |
|
| 324 |
$init_column = apply_filters( 'usces_filter_item_class_sortColumn', 'post.ID' ); |
| 325 |
$sort_column = in_array( $this->sortColumn, $this->columns, true ) ? $this->sortColumn : $init_column; |
| 326 |
$init_switch = apply_filters( 'usces_filter_item_class_sortSwitchs', 'DESC' ); |
| 327 |
$sort_switch = $this->sortSwitchs[ $sort_column ] ?? $init_switch; |
| 328 |
$sort_switch = in_array( strtoupper( $sort_switch ), array( 'ASC', 'DESC' ), true ) ? $sort_switch : $init_switch; |
| 329 |
$order = ' ORDER BY ' . esc_sql( $sort_column ) . ' ' . esc_sql( $sort_switch ); |
| 330 |
|
| 331 |
if ( $this->exportMode ) { |
| 332 |
|
| 333 |
$query = |
| 334 |
"SELECT post.ID, item.itemCode AS `item_code`, item.itemName AS `item_name` |
| 335 |
FROM {$this->table} AS `post` |
| 336 |
LEFT JOIN {$item_table} AS `item` ON post.ID = item.post_id |
| 337 |
LEFT JOIN {$sku_table} AS `sku` ON post.ID = sku.post_id |
| 338 |
LEFT JOIN $wpdb->term_relationships AS `tr` ON post.ID = tr.object_id |
| 339 |
LEFT JOIN $wpdb->term_taxonomy AS `tt` ON tt.term_taxonomy_id = tr.term_taxonomy_id "; |
| 340 |
} else { |
| 341 |
|
| 342 |
$query = |
| 343 |
"SELECT post.ID, item.itemCode AS `item_code`, item.itemName AS `item_name`, item.itemPicts AS `pictids` |
| 344 |
FROM {$this->table} AS `post` |
| 345 |
LEFT JOIN {$item_table} AS `item` ON post.ID = item.post_id |
| 346 |
LEFT JOIN {$sku_table} AS `sku` ON post.ID = sku.post_id |
| 347 |
LEFT JOIN $wpdb->term_relationships AS `tr` ON post.ID = tr.object_id |
| 348 |
LEFT JOIN $wpdb->term_taxonomy AS `tt` ON tt.term_taxonomy_id = tr.term_taxonomy_id "; |
| 349 |
} |
| 350 |
|
| 351 |
$query .= $where . $order; // . $limit; |
| 352 |
|
| 353 |
$rows = $wpdb->get_results( $query, ARRAY_A ); |
| 354 |
$this->selectedRow = ( $rows && is_array( $rows ) ) ? count( $rows ) : 0; |
| 355 |
if ( 'off' === $this->pageLimit ) { |
| 356 |
$this->rows = $rows; |
| 357 |
} else { |
| 358 |
$this->rows = array_slice( (array) $rows, $this->startRow, $this->maxRow ); |
| 359 |
} |
| 360 |
|
| 361 |
return $this->rows; |
| 362 |
} |
| 363 |
|
| 364 |
/** |
| 365 |
* Set Total Rows. |
| 366 |
*/ |
| 367 |
public function SetTotalRow() { |
| 368 |
global $wpdb; |
| 369 |
$query = "SELECT COUNT(ID) AS `ct` FROM {$this->table} WHERE post_mime_type = 'item' AND post_type = 'post' AND post_status <> 'trash'"; |
| 370 |
$res = $wpdb->get_var( $query ); |
| 371 |
$this->totalRow = $res; |
| 372 |
} |
| 373 |
|
| 374 |
/** |
| 375 |
* Where Condition. |
| 376 |
* |
| 377 |
* @return string |
| 378 |
*/ |
| 379 |
public function GetWhere() { |
| 380 |
$sql_where = apply_filters( 'usces_filter_item_class_sql_where', '', $this->searchSql, $this ); |
| 381 |
if ( '' != $this->searchSql ) { |
| 382 |
if ( 'display_status' == $this->arr_search['column'] ) { |
| 383 |
$str = "WHERE post.post_mime_type = 'item' AND post.post_type = 'post' AND " . $this->searchSql . $sql_where . ' GROUP BY post.ID'; |
| 384 |
} else { |
| 385 |
$str = "WHERE post.post_mime_type = 'item' AND post.post_type = 'post' AND post.post_status <> 'trash' AND " . $this->searchSql . $sql_where . ' GROUP BY post.ID'; |
| 386 |
} |
| 387 |
} else { |
| 388 |
$str = "WHERE post.post_mime_type = 'item' AND post.post_type = 'post' AND post.post_status <> 'trash'" . $sql_where . ' GROUP BY post.ID'; |
| 389 |
} |
| 390 |
return $str; |
| 391 |
} |
| 392 |
|
| 393 |
/** |
| 394 |
* Set query search sql condition base on arr_search for item list. |
| 395 |
* |
| 396 |
* @return dataList $searchSql string search sql condition. |
| 397 |
*/ |
| 398 |
public function setSearchSql() { |
| 399 |
global $wpdb; |
| 400 |
switch ( $this->arr_search['column'] ) { |
| 401 |
case 'post_id': |
| 402 |
$column = 'post.ID'; |
| 403 |
$post_id_from = isset( $this->arr_search['word']['post_id_from'] ) ? $this->arr_search['word']['post_id_from'] : ''; |
| 404 |
$post_id_to = isset( $this->arr_search['word']['post_id_to'] ) ? $this->arr_search['word']['post_id_to'] : ''; |
| 405 |
|
| 406 |
if ( ! empty( $post_id_from ) ) { |
| 407 |
$this->searchSql = $wpdb->prepare( $column . ' >= %d', (int) $post_id_from ); |
| 408 |
} |
| 409 |
|
| 410 |
if ( ! empty( $post_id_from ) && ! empty( $post_id_to ) ) { |
| 411 |
$this->searchSql .= ' AND '; |
| 412 |
} |
| 413 |
|
| 414 |
if ( ! empty( $post_id_to ) ) { |
| 415 |
$this->searchSql .= $wpdb->prepare( $column . ' <= %d', (int) $post_id_to ); |
| 416 |
} |
| 417 |
break; |
| 418 |
case 'item_code': |
| 419 |
$item_code = isset( $this->arr_search['word']['item_code'] ) ? $this->arr_search['word']['item_code'] : ''; |
| 420 |
$this->searchSql = 'item.itemCode LIKE ' . "'%" . esc_sql( $item_code ) . "%'"; |
| 421 |
break; |
| 422 |
case 'item_name': |
| 423 |
$item_name = isset( $this->arr_search['word']['item_name'] ) ? $this->arr_search['word']['item_name'] : ''; |
| 424 |
$this->searchSql = 'item.itemName LIKE ' . "'%" . esc_sql( $item_name ) . "%'"; |
| 425 |
break; |
| 426 |
case 'post_title': |
| 427 |
$post_title = isset( $this->arr_search['word']['post_title'] ) ? $this->arr_search['word']['post_title'] : ''; |
| 428 |
$this->searchSql = 'post.post_title LIKE ' . "'%" . esc_sql( $post_title ) . "%'"; |
| 429 |
break; |
| 430 |
case 'zaiko_num': |
| 431 |
$this->searchSql = "sku.stocknum = '0'"; |
| 432 |
break; |
| 433 |
case 'zaiko': |
| 434 |
$zaiko = isset( $this->arr_search['word']['zaiko'] ) ? $this->arr_search['word']['zaiko'] : ''; |
| 435 |
$this->searchSql = "sku.stock = '" . esc_sql( $zaiko ) . "'"; |
| 436 |
break; |
| 437 |
case 'category': |
| 438 |
$category = isset( $this->arr_search['word']['category'] ) ? $this->arr_search['word']['category'] : ''; |
| 439 |
$this->searchSql = "tt.term_id = '" . esc_sql( $category ) . "'"; |
| 440 |
break; |
| 441 |
case 'display_status': |
| 442 |
$display_status = isset( $this->arr_search['word']['display_status'] ) ? $this->arr_search['word']['display_status'] : ''; |
| 443 |
$this->searchSql = "post.post_status = '" . esc_sql( $display_status ) . "'"; |
| 444 |
break; |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
/** |
| 449 |
* Set Navigation. |
| 450 |
*/ |
| 451 |
public function SetNavi() { |
| 452 |
|
| 453 |
$this->lastPage = ceil( $this->selectedRow / $this->maxRow ); |
| 454 |
$this->previousPage = ( ( $this->currentPage - 1 ) == 0 ) ? 1 : $this->currentPage - 1; |
| 455 |
$this->nextPage = ( ( $this->currentPage + 1 ) > $this->lastPage ) ? $this->lastPage : $this->currentPage + 1; |
| 456 |
$box = array(); |
| 457 |
|
| 458 |
for ( $i = 0; $i < $this->naviMaxButton; $i++ ) { |
| 459 |
if ( $i > $this->lastPage - 1 ) { |
| 460 |
break; |
| 461 |
} |
| 462 |
if ( $this->lastPage <= $this->naviMaxButton ) { |
| 463 |
$box[] = $i + 1; |
| 464 |
} else { |
| 465 |
if ( $this->currentPage <= 6 ) { |
| 466 |
$label = $i + 1; |
| 467 |
$box[] = $label; |
| 468 |
} else { |
| 469 |
$label = $i + 1 + $this->currentPage - 6; |
| 470 |
$box[] = $label; |
| 471 |
if ( $label == $this->lastPage ) { |
| 472 |
break; |
| 473 |
} |
| 474 |
} |
| 475 |
} |
| 476 |
} |
| 477 |
|
| 478 |
$html = ''; |
| 479 |
$html .= '<ul class="clearfix">'; |
| 480 |
$html .= '<li class="rowsnum">' . $this->selectedRow . ' / ' . $this->totalRow . ' ' . __( 'cases', 'usces' ) . '</li>'; |
| 481 |
if ( ( 1 == $this->currentPage ) || ( 0 == $this->selectedRow ) ) { |
| 482 |
$html .= '<li class="navigationStr">first<<</li>'; |
| 483 |
$html .= '<li class="navigationStr">prev<</li>'; |
| 484 |
} else { |
| 485 |
$url = admin_url( 'admin.php?page=usces_itemedit&changePage=1' ); |
| 486 |
$nonce_url = wp_nonce_url( $url, 'item_master_list', 'wc_nonce' ); |
| 487 |
$html .= '<li class="navigationStr"><a href="' . $nonce_url . '">first<<</a></li>'; |
| 488 |
$url = admin_url( 'admin.php?page=usces_itemedit&changePage=' . $this->previousPage ); |
| 489 |
$nonce_url = wp_nonce_url( $url, 'item_master_list', 'wc_nonce' ); |
| 490 |
$html .= '<li class="navigationStr"><a href="' . $nonce_url . '">prev<</a></li>'; |
| 491 |
} |
| 492 |
if ( $this->selectedRow > 0 ) { |
| 493 |
$box_count = count( $box ); |
| 494 |
for ( $i = 0; $i < $box_count; $i++ ) { |
| 495 |
if ( $box[ $i ] == $this->currentPage ) { |
| 496 |
$html .= '<li class="navigationButtonSelected">' . $box[ $i ] . '</li>'; |
| 497 |
} else { |
| 498 |
$url = admin_url( 'admin.php?page=usces_itemedit&changePage=' . $box[ $i ] ); |
| 499 |
$nonce_url = wp_nonce_url( $url, 'item_master_list', 'wc_nonce' ); |
| 500 |
$html .= '<li class="navigationButton"><a href="' . $nonce_url . '">' . $box[ $i ] . '</a></li>'; |
| 501 |
} |
| 502 |
} |
| 503 |
} |
| 504 |
if ( ( $this->currentPage == $this->lastPage ) || ( 0 == $this->selectedRow ) ) { |
| 505 |
$html .= '<li class="navigationStr">>next</li>'; |
| 506 |
$html .= '<li class="navigationStr">>>last</li>'; |
| 507 |
} else { |
| 508 |
$url = admin_url( 'admin.php?page=usces_itemedit&changePage=' . $this->nextPage ); |
| 509 |
$nonce_url = wp_nonce_url( $url, 'item_master_list', 'wc_nonce' ); |
| 510 |
$html .= '<li class="navigationStr"><a href="' . $nonce_url . '">>next</a></li>'; |
| 511 |
$url = admin_url( 'admin.php?page=usces_itemedit&changePage=' . $this->lastPage ); |
| 512 |
$nonce_url = wp_nonce_url( $url, 'item_master_list', 'wc_nonce' ); |
| 513 |
$html .= '<li class="navigationStr"><a href="' . $nonce_url . '">>>last</a></li>'; |
| 514 |
} |
| 515 |
$this->dataTableNavigationBottom = $html; |
| 516 |
if ( 'OFF' == $this->searchSwitchStatus ) { |
| 517 |
$html .= '<li class="navigationStr"><a style="cursor:pointer;" id="searchVisiLink">' . __( 'Show the Operation field', 'usces' ) . '</a>'; |
| 518 |
} else { |
| 519 |
$html .= '<li class="navigationStr"><a style="cursor:pointer;" id="searchVisiLink">' . __( 'Hide the Operation field', 'usces' ) . '</a>'; |
| 520 |
} |
| 521 |
$url = admin_url( 'admin.php?page=usces_itemedit&refresh' ); |
| 522 |
$nonce_url = wp_nonce_url( $url, 'item_master_list', 'wc_nonce' ); |
| 523 |
$html .= '<li class="refresh"><a href="' . $nonce_url . '">' . __( 'updates it to latest information', 'usces' ) . '</a></li>'; |
| 524 |
$html .= '</ul>'; |
| 525 |
|
| 526 |
$this->dataTableNavigation = $html; |
| 527 |
} |
| 528 |
|
| 529 |
/** |
| 530 |
* Get Cookie. |
| 531 |
*/ |
| 532 |
public function getCookie() { |
| 533 |
$this->data_cookie = ( isset( $_COOKIE[ $this->table ] ) ) ? json_decode( str_replace( "\'", "'", str_replace( '\"', '"', $_COOKIE[ $this->table ] ) ), true ) : array(); |
| 534 |
} |
| 535 |
|
| 536 |
/** |
| 537 |
* Set Headers. |
| 538 |
*/ |
| 539 |
public function SetHeaders() { |
| 540 |
foreach ( $this->columns as $key => $value ) { |
| 541 |
if ( $value == $this->sortColumn ) { |
| 542 |
if ( ( version_compare( USCES_MYSQL_VERSION, '5.0.0', '>=' ) && ( 'item_name' == $value || 'item_code' == $value ) ) || ( version_compare( USCES_MYSQL_VERSION, '5.0.0', '<' ) && 'post_title' == $value ) ) { |
| 543 |
if ( 'ASC' == $this->sortSwitchs[ $value ] ) { |
| 544 |
$str = __( '[ASC]', 'usces' ); |
| 545 |
$switch = 'DESC'; |
| 546 |
} elseif ( 'DESC' == $this->sortSwitchs[ $value ] ) { |
| 547 |
$str = __( '[DESC]', 'usces' ); |
| 548 |
$switch = 'default'; |
| 549 |
} else { |
| 550 |
$str = ''; |
| 551 |
$switch = 'ASC'; |
| 552 |
} |
| 553 |
$url = admin_url( 'admin.php?page=usces_itemedit&changeSort=' . $value . '&switch=' . $switch ); |
| 554 |
$nonce_url = wp_nonce_url( $url, 'item_master_list', 'wc_nonce' ); |
| 555 |
$this->headers[ $value ] = '<a href="' . $nonce_url . '"><span class="sortcolumn">' . $key . ' ' . $str . '</span></a>'; |
| 556 |
} else { |
| 557 |
$this->headers[ $value ] = '<span class="sortcolumn">' . $key . '</span>'; |
| 558 |
} |
| 559 |
} else { |
| 560 |
if ( ( version_compare( USCES_MYSQL_VERSION, '5.0.0', '>=' ) && ( 'item_name' == $value || 'item_code' == $value ) ) || ( version_compare( USCES_MYSQL_VERSION, '5.0.0', '<' ) && 'post_title' == $value ) ) { |
| 561 |
$switch = $this->sortSwitchs[ $value ]; |
| 562 |
$url = admin_url( 'admin.php?page=usces_itemedit&changeSort=' . $value . '&switch=' . $switch ); |
| 563 |
$nonce_url = wp_nonce_url( $url, 'item_master_list', 'wc_nonce' ); |
| 564 |
$this->headers[ $value ] = '<a href="' . $nonce_url . '"><span>' . $key . '</span></a>'; |
| 565 |
} else { |
| 566 |
$this->headers[ $value ] = '<span class="sortcolumn">' . $key . '</span>'; |
| 567 |
} |
| 568 |
} |
| 569 |
} |
| 570 |
} |
| 571 |
|
| 572 |
/** |
| 573 |
* Get Search. |
| 574 |
* |
| 575 |
* @return string |
| 576 |
*/ |
| 577 |
public function GetSearchs() { |
| 578 |
return $this->arr_search; |
| 579 |
} |
| 580 |
|
| 581 |
/** |
| 582 |
* Get Headers. |
| 583 |
* |
| 584 |
* @return string |
| 585 |
*/ |
| 586 |
public function GetListheaders() { |
| 587 |
return $this->headers; |
| 588 |
} |
| 589 |
|
| 590 |
/** |
| 591 |
* Get Navigation. |
| 592 |
* |
| 593 |
* @return string |
| 594 |
*/ |
| 595 |
public function GetDataTableNavigation() { |
| 596 |
return $this->dataTableNavigation; |
| 597 |
} |
| 598 |
|
| 599 |
/** |
| 600 |
* Get Navigation Bottom. |
| 601 |
* |
| 602 |
* @return string |
| 603 |
*/ |
| 604 |
public function GetDataTableNavigationBottom() { |
| 605 |
return $this->dataTableNavigationBottom; |
| 606 |
} |
| 607 |
|
| 608 |
/** |
| 609 |
* Set Action Status and Action Message. |
| 610 |
* |
| 611 |
* @param string $status Action status. |
| 612 |
* @param string $message Action message. |
| 613 |
*/ |
| 614 |
public function set_action_status( $status, $message ) { |
| 615 |
$this->action_status = $status; |
| 616 |
$this->action_message = $message; |
| 617 |
} |
| 618 |
|
| 619 |
/** |
| 620 |
* Get Action Status. |
| 621 |
* |
| 622 |
* @return string |
| 623 |
*/ |
| 624 |
public function get_action_status() { |
| 625 |
return $this->action_status; |
| 626 |
} |
| 627 |
|
| 628 |
/** |
| 629 |
* Get Action Message. |
| 630 |
* |
| 631 |
* @return string |
| 632 |
*/ |
| 633 |
public function get_action_message() { |
| 634 |
return $this->action_message; |
| 635 |
} |
| 636 |
} |
| 637 |
|