| @@ -1,607 +1,636 @@ | ||
| 1 | -<?php | |
| 2 | -class dataList | |
| 3 | -{ | |
| 4 | - var $table; //テーブル名 | |
| 5 | - var $rows; //データ | |
| 6 | - var $action; //アクション | |
| 7 | - var $startRow; //表示開始行番号 | |
| 8 | - var $maxRow; //最大表示行数 | |
| 9 | - var $currentPage; //現在のページNo | |
| 10 | - var $firstPage; //最初のページNo | |
| 11 | - var $previousPage; //前のページNo | |
| 12 | - var $nextPage; //次のページNo | |
| 13 | - var $lastPage; //最終ページNo | |
| 14 | - var $naviMaxButton; //ページネーション・ナビのボタンの数 | |
| 15 | - var $dataTableNavigation; //ナヴィゲーションhtmlコード | |
| 16 | - var $arr_period; //表示データ期間 | |
| 17 | - var $arr_search; //サーチ条件 | |
| 18 | - var $searchSql; //簡易絞込みSQL | |
| 19 | - var $searchSwitchStatus; //サーチ表示スイッチ | |
| 20 | - var $columns; //データカラム | |
| 21 | - var $sortColumn; //現在ソート中のフィールド | |
| 22 | - var $sortOldColumn; | |
| 23 | - var $sortSwitchs; //各フィールド毎の昇順降順スイッチ | |
| 24 | - var $userHeaderNames; //ユーザー指定のヘッダ名 | |
| 25 | - var $action_status, $action_message; | |
| 26 | -//20101202ysk start | |
| 27 | - var $pageLimit; //ページ制限 | |
| 28 | -//20101202ysk end | |
| 29 | - var $exportMode; //IDのみ | |
| 30 | - | |
| 31 | - //Constructor | |
| 32 | - function dataList($tableName, $arr_column) | |
| 33 | - { | |
| 34 | - $this->table = $tableName; | |
| 35 | - $this->columns = $arr_column; | |
| 36 | - //$this->parent_term = $parent_term; | |
| 37 | - $this->rows = array(); | |
| 38 | - | |
| 39 | - $this->maxRow = 30; | |
| 40 | - $this->naviMaxButton = 11; | |
| 41 | - $this->firstPage = 1; | |
| 42 | - $this->action_status = 'none'; | |
| 43 | - $this->action_message = ''; | |
| 44 | -//20101202ysk start | |
| 45 | - $this->pageLimit = 'on'; | |
| 46 | -//20101202ysk end | |
| 47 | - $this->exportMode = false; | |
| 48 | - | |
| 49 | - $this->SetParamByQuery(); | |
| 50 | - | |
| 51 | - $this->arr_period = array(__('This month', 'usces'), __('Last month', 'usces'), __('The past one week', 'usces'), __('Last 30 days', 'usces'), __('Last 90days', 'usces'), __('All', 'usces')); | |
| 52 | - | |
| 53 | - | |
| 54 | - } | |
| 55 | - | |
| 56 | - function MakeTable() | |
| 57 | - { | |
| 58 | - | |
| 59 | - $this->SetParam(); | |
| 60 | - | |
| 61 | - switch ($this->action){ | |
| 62 | - | |
| 63 | - case 'searchIn': | |
| 64 | - $this->SearchIn(); | |
| 65 | - //$this->SetSelectedRow(); | |
| 66 | - $res = $this->GetRows(); | |
| 67 | - break; | |
| 68 | - | |
| 69 | - case 'searchOut': | |
| 70 | - $this->SearchOut(); | |
| 71 | - //$this->SetSelectedRow(); | |
| 72 | - $res = $this->GetRows(); | |
| 73 | - break; | |
| 74 | - | |
| 75 | - case 'changeSort': | |
| 76 | - $res = $this->GetRows(); | |
| 77 | - break; | |
| 78 | - | |
| 79 | - case 'changePage': | |
| 80 | - $res = $this->GetRows(); | |
| 81 | - break; | |
| 82 | - | |
| 83 | - case 'collective_zaiko': | |
| 84 | - usces_all_change_zaiko($this); | |
| 85 | - $res = $this->GetRows(); | |
| 86 | - break; | |
| 87 | - | |
| 88 | - case 'collective_display_status': | |
| 89 | - usces_all_change_itemdisplay($this); | |
| 90 | - $res = $this->GetRows(); | |
| 91 | - break; | |
| 92 | - | |
| 93 | - case 'collective_delete': | |
| 94 | - usces_all_delete_itemdata($this); | |
| 95 | - $this->SetTotalRow(); | |
| 96 | - $res = $this->GetRows(); | |
| 97 | - break; | |
| 98 | - | |
| 99 | - case 'refresh': | |
| 100 | - default: | |
| 101 | - $this->SetDefaultParam(); | |
| 102 | - $res = $this->GetRows(); | |
| 103 | - break; | |
| 104 | - } | |
| 105 | - | |
| 106 | - if( ! $this->exportMode ){ | |
| 107 | - $this->SetNavi(); | |
| 108 | - $this->SetHeaders(); | |
| 109 | - $this->SetSESSION(); | |
| 110 | - } | |
| 111 | - | |
| 112 | - if($res){ | |
| 113 | - | |
| 114 | - return TRUE; | |
| 115 | - | |
| 116 | - }else{ | |
| 117 | - return FALSE; | |
| 118 | - } | |
| 119 | - } | |
| 120 | - | |
| 121 | - //DefaultParam | |
| 122 | - function SetDefaultParam() | |
| 123 | - { | |
| 124 | - unset($_SESSION[$this->table]); | |
| 125 | - $this->startRow = 0; | |
| 126 | - $this->currentPage = 1; | |
| 127 | - if(isset($_SESSION[$this->table]['arr_search'])){ | |
| 128 | - $this->arr_search = $_SESSION[$this->table]['arr_search']; | |
| 129 | - }else{ | |
| 130 | - $this->arr_search = array('period'=>'3', 'column'=>'', 'word'=>array()); | |
| 131 | - } | |
| 132 | - if(isset($_SESSION[$this->table]['searchSwitchStatus'])){ | |
| 133 | - $this->searchSwitchStatus = $_SESSION[$this->table]['searchSwitchStatus']; | |
| 134 | - }else{ | |
| 135 | - $this->searchSwitchStatus = 'OFF'; | |
| 136 | - } | |
| 137 | - $this->searchSql = ''; | |
| 138 | - $column = apply_filters( 'usces_filter_item_class_sortColumn', 'post.ID'); | |
| 139 | - $this->sortColumn = $column; | |
| 140 | - $this->sortSwitchs[$column] = apply_filters( 'usces_filter_item_class_sortSwitchs', 'DESC'); | |
| 141 | - | |
| 142 | - foreach($this->columns as $value ){ | |
| 143 | - $this->sortSwitchs[$value] = 'ASC'; | |
| 144 | - } | |
| 145 | - | |
| 146 | - | |
| 147 | - $this->SetTotalRow(); | |
| 148 | - //$this->SetSelectedRow(); | |
| 149 | - | |
| 150 | - } | |
| 151 | - | |
| 152 | - function SetParam() | |
| 153 | - { | |
| 154 | - $this->startRow = ($this->currentPage-1) * $this->maxRow; | |
| 155 | - } | |
| 156 | - | |
| 157 | - function SetParamByQuery() | |
| 158 | - { | |
| 159 | - | |
| 160 | - if(isset($_REQUEST['changePage'])){ | |
| 161 | - | |
| 162 | - $this->action = 'changePage'; | |
| 163 | - $this->currentPage = $_REQUEST['changePage']; | |
| 164 | - | |
| 165 | - $this->sortColumn = $_SESSION[$this->table]['sortColumn']; | |
| 166 | - $this->sortSwitchs = $_SESSION[$this->table]['sortSwitchs']; | |
| 167 | - $this->userHeaderNames = $_SESSION[$this->table]['userHeaderNames']; | |
| 168 | - $this->searchSwitchStatus = $_SESSION[$this->table]['searchSwitchStatus']; | |
| 169 | - $this->searchSql = $_SESSION[$this->table]['searchSql']; | |
| 170 | - $this->arr_search = $_SESSION[$this->table]['arr_search']; | |
| 171 | - $this->totalRow = $_SESSION[$this->table]['totalRow']; | |
| 172 | - $this->selectedRow = $_SESSION[$this->table]['selectedRow']; | |
| 173 | - | |
| 174 | - }else if(isset($_REQUEST['changeSort'])){ | |
| 175 | - | |
| 176 | - $this->action = 'changeSort'; | |
| 177 | - $this->sortOldColumn = $this->sortColumn; | |
| 178 | - $this->sortColumn = $_REQUEST['changeSort']; | |
| 179 | - $this->sortSwitchs = $_SESSION[$this->table]['sortSwitchs']; | |
| 180 | - $this->sortSwitchs[$this->sortColumn] = $_REQUEST['switch']; | |
| 181 | - | |
| 182 | - $this->currentPage = $_SESSION[$this->table]['currentPage']; | |
| 183 | - $this->userHeaderNames = $_SESSION[$this->table]['userHeaderNames']; | |
| 184 | - $this->searchSql = $_SESSION[$this->table]['searchSql']; | |
| 185 | - $this->arr_search = $_SESSION[$this->table]['arr_search']; | |
| 186 | - $this->searchSwitchStatus = $_SESSION[$this->table]['searchSwitchStatus']; | |
| 187 | - $this->totalRow = $_SESSION[$this->table]['totalRow']; | |
| 188 | - $this->selectedRow = $_SESSION[$this->table]['selectedRow']; | |
| 189 | - | |
| 190 | - } else if(isset($_REQUEST['searchIn'])){ | |
| 191 | - | |
| 192 | - $this->action = 'searchIn'; | |
| 193 | - $this->arr_search['column'] = isset($_REQUEST['search']['column']) ? $_REQUEST['search']['column'] : ''; | |
| 194 | - $this->arr_search['word'] = isset($_REQUEST['search']['word']) ? $_REQUEST['search']['word'] : ''; | |
| 195 | - $this->arr_search['period'] = isset($_REQUEST['search']['period']) ? (int)$_REQUEST['search']['period'] : ''; | |
| 196 | - $this->searchSwitchStatus = isset($_REQUEST['searchSwitchStatus']) ? $_REQUEST['searchSwitchStatus'] : ''; | |
| 197 | - | |
| 198 | - $this->currentPage = 1; | |
| 199 | - $this->sortColumn = $_SESSION[$this->table]['sortColumn']; | |
| 200 | - $this->sortSwitchs = $_SESSION[$this->table]['sortSwitchs']; | |
| 201 | - $this->userHeaderNames = $_SESSION[$this->table]['userHeaderNames']; | |
| 202 | - $this->totalRow = $_SESSION[$this->table]['totalRow']; | |
| 203 | - | |
| 204 | - }else if(isset($_REQUEST['searchOut'])){ | |
| 205 | - | |
| 206 | - $this->action = 'searchOut'; | |
| 207 | - $this->arr_search['column'] = ''; | |
| 208 | - $this->arr_search['word'] = ''; | |
| 209 | - $this->arr_search['period'] = $_SESSION[$this->table]['arr_search']['period']; | |
| 210 | - $this->searchSwitchStatus = isset($_REQUEST['searchSwitchStatus']) ? $_REQUEST['searchSwitchStatus'] : ''; | |
| 211 | - | |
| 212 | - $this->currentPage = 1; | |
| 213 | - $this->sortColumn = $_SESSION[$this->table]['sortColumn']; | |
| 214 | - $this->sortSwitchs = $_SESSION[$this->table]['sortSwitchs']; | |
| 215 | - $this->userHeaderNames = $_SESSION[$this->table]['userHeaderNames']; | |
| 216 | - $this->totalRow = $_SESSION[$this->table]['totalRow']; | |
| 217 | - | |
| 218 | - | |
| 219 | - }else if(isset($_REQUEST['refresh'])){ | |
| 220 | - | |
| 221 | - $this->action = 'refresh'; | |
| 222 | - | |
| 223 | - $this->currentPage = $_SESSION[$this->table]['currentPage']; | |
| 224 | - $this->sortColumn = $_SESSION[$this->table]['sortColumn']; | |
| 225 | - $this->sortSwitchs = $_SESSION[$this->table]['sortSwitchs']; | |
| 226 | - $this->userHeaderNames = $_SESSION[$this->table]['userHeaderNames']; | |
| 227 | - $this->searchSql = $_SESSION[$this->table]['searchSql']; | |
| 228 | - $this->arr_search = $_SESSION[$this->table]['arr_search']; | |
| 229 | - $this->searchSwitchStatus = $_SESSION[$this->table]['searchSwitchStatus']; | |
| 230 | - $this->totalRow = $_SESSION[$this->table]['totalRow']; | |
| 231 | - $this->selectedRow = $_SESSION[$this->table]['selectedRow']; | |
| 232 | - | |
| 233 | - }else if(isset($_REQUEST['collective'])){ | |
| 234 | - | |
| 235 | - $this->action = 'collective_' . $_POST['allchange']['column']; | |
| 236 | - $this->currentPage = $_SESSION[$this->table]['currentPage']; | |
| 237 | - $this->sortColumn = $_SESSION[$this->table]['sortColumn']; | |
| 238 | - $this->sortSwitchs = $_SESSION[$this->table]['sortSwitchs']; | |
| 239 | - $this->userHeaderNames = $_SESSION[$this->table]['userHeaderNames']; | |
| 240 | - $this->searchSql = $_SESSION[$this->table]['searchSql']; | |
| 241 | - $this->arr_search = $_SESSION[$this->table]['arr_search']; | |
| 242 | - $this->searchSwitchStatus = $_SESSION[$this->table]['searchSwitchStatus']; | |
| 243 | - $this->totalRow = $_SESSION[$this->table]['totalRow']; | |
| 244 | - $this->selectedRow = $_SESSION[$this->table]['selectedRow']; | |
| 245 | - | |
| 246 | - }else{ | |
| 247 | - | |
| 248 | - $this->action = 'default'; | |
| 249 | - } | |
| 250 | - } | |
| 251 | - | |
| 252 | - //GetRows | |
| 253 | - function GetRows() | |
| 254 | - { | |
| 255 | - global $wpdb; | |
| 256 | - //$wpdb->show_errors(); | |
| 257 | - $where = $this->GetWhere(); | |
| 258 | - $order = ' ORDER BY ' . $this->sortColumn . ' ' . $this->sortSwitchs[$this->sortColumn]; | |
| 259 | - //$limit = ' LIMIT ' . $this->startRow . ', ' . $this->maxRow; | |
| 260 | - | |
| 261 | - if(USCES_MYSQL_VERSION >= 5){ | |
| 262 | - if( $this->exportMode ){ | |
| 263 | - $query = $wpdb->prepare("SELECT post.ID | |
| 264 | - FROM {$this->table} AS post | |
| 265 | - LEFT JOIN $wpdb->postmeta AS mc ON post.ID = mc.post_id AND %s = mc.meta_key | |
| 266 | - LEFT JOIN $wpdb->postmeta AS mn ON post.ID = mn.post_id AND %s = mn.meta_key | |
| 267 | - LEFT JOIN $wpdb->postmeta AS meta ON post.ID = meta.post_id AND %s = meta.meta_key | |
| 268 | - LEFT JOIN $wpdb->term_relationships AS tr ON post.ID = tr.object_id | |
| 269 | - LEFT JOIN $wpdb->term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id " | |
| 270 | - , '_itemCode', '_itemName', '_isku_'); | |
| 271 | - }else{ | |
| 272 | -// $query = $wpdb->prepare("SELECT mc.meta_value AS item_code, mn.meta_value AS item_name, | |
| 273 | -// meta.meta_key AS sku_key, meta.meta_value AS sku_value, te.term_id AS category, post.post_status, | |
| 274 | -// CASE post.post_status | |
| 275 | -// WHEN 'publish' THEN '" . __('Published', 'usces') . "' | |
| 276 | -// WHEN 'future' THEN '" . __('Scheduled', 'usces') . "' | |
| 277 | -// WHEN 'draft' THEN '" . __('Draft', 'usces') . "' | |
| 278 | -// WHEN 'pending' THEN '" . __('Pending Review', 'usces') . "' | |
| 279 | -// WHEN 'trash' THEN '" . __('Trash', 'usces') . "' | |
| 280 | -// ELSE '" . __('Closed', 'usces') . "' | |
| 281 | -// END AS display_status, | |
| 282 | -// post.post_type, post.post_mime_type, post.ID | |
| 283 | -// FROM {$this->table} AS post | |
| 284 | -// LEFT JOIN $wpdb->postmeta AS mc ON post.ID = mc.post_id AND mc.meta_key = '_itemCode' | |
| 285 | -// LEFT JOIN $wpdb->postmeta AS mn ON post.ID = mn.post_id AND mn.meta_key = '_itemName' | |
| 286 | -// LEFT JOIN $wpdb->postmeta AS meta ON post.ID = meta.post_id AND meta.meta_key = %s | |
| 287 | -// LEFT JOIN $wpdb->term_relationships AS tr ON tr.object_id = post.ID | |
| 288 | -// LEFT JOIN $wpdb->term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id | |
| 289 | -// LEFT JOIN $wpdb->terms AS te ON te.term_id = tt.term_id ", | |
| 290 | -// '_isku_'); | |
| 291 | - $query = $wpdb->prepare("SELECT post.ID, mc.meta_value AS item_code, mn.meta_value AS item_name | |
| 292 | - FROM {$this->table} AS post | |
| 293 | - LEFT JOIN $wpdb->postmeta AS mc ON post.ID = mc.post_id AND %s = mc.meta_key | |
| 294 | - LEFT JOIN $wpdb->postmeta AS mn ON post.ID = mn.post_id AND %s = mn.meta_key | |
| 295 | - LEFT JOIN $wpdb->postmeta AS meta ON post.ID = meta.post_id AND %s = meta.meta_key | |
| 296 | - LEFT JOIN $wpdb->term_relationships AS tr ON post.ID = tr.object_id | |
| 297 | - LEFT JOIN $wpdb->term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id " | |
| 298 | - , '_itemCode', '_itemName', '_isku_'); | |
| 299 | -// $query = $wpdb->prepare("SELECT | |
| 300 | -// (SELECT meta_value FROM $wpdb->postmeta WHERE post_id = post.ID AND meta_key = '_itemCode') AS item_code, | |
| 301 | -// (SELECT meta_value FROM $wpdb->postmeta WHERE post_id = post.ID AND meta_key = '_itemName') AS item_name, | |
| 302 | -// meta.meta_key AS sku_key, meta.meta_value AS sku_value, te.name AS category, post.post_status, | |
| 303 | -// CASE post.post_status | |
| 304 | -// WHEN 'publish' THEN '" . __('Published', 'usces') . "' | |
| 305 | -// WHEN 'future' THEN '" . __('Scheduled', 'usces') . "' | |
| 306 | -// WHEN 'draft' THEN '" . __('Draft', 'usces') . "' | |
| 307 | -// WHEN 'pending' THEN '" . __('Pending Review', 'usces') . "' | |
| 308 | -// WHEN 'trash' THEN '" . __('Trash', 'usces') . "' | |
| 309 | -// ELSE '" . __('Closed', 'usces') . "' | |
| 310 | -// END AS display_status, | |
| 311 | -// post.post_type, post.post_mime_type, post.ID | |
| 312 | -// FROM {$this->table} AS post | |
| 313 | -// LEFT JOIN $wpdb->postmeta AS meta ON post.ID = meta.post_id AND SUBSTRING(meta.meta_key, 1, 6) = %s | |
| 314 | -// LEFT JOIN $wpdb->term_relationships AS tr ON tr.object_id = post.ID | |
| 315 | -// LEFT JOIN $wpdb->term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id | |
| 316 | -// LEFT JOIN $wpdb->terms AS te ON te.term_id = tt.term_id ", | |
| 317 | -// '_isku_'); | |
| 318 | - } | |
| 319 | - } else { | |
| 320 | - if( $this->exportMode ){ | |
| 321 | -// $query = $wpdb->prepare("SELECT mc.meta_value AS item_code, mn.meta_value AS item_name, | |
| 322 | -// CASE post.post_status | |
| 323 | -// WHEN 'publish' THEN '" . __('Published', 'usces') . "' | |
| 324 | -// WHEN 'future' THEN '" . __('Scheduled', 'usces') . "' | |
| 325 | -// WHEN 'draft' THEN '" . __('Draft', 'usces') . "' | |
| 326 | -// WHEN 'pending' THEN '" . __('Pending Review', 'usces') . "' | |
| 327 | -// WHEN 'trash' THEN '" . __('Trash', 'usces') . "' | |
| 328 | -// ELSE '" . __('Closed', 'usces') . "' | |
| 329 | -// END AS display_status, post.post_status, post.ID | |
| 330 | -// FROM {$this->table} AS post | |
| 331 | -// LEFT JOIN $wpdb->postmeta AS mc ON post.ID = mc.post_id AND mc.meta_key = '_itemCode' | |
| 332 | -// LEFT JOIN $wpdb->postmeta AS mn ON post.ID = mn.post_id AND mn.meta_key = '_itemName' | |
| 333 | -// LEFT JOIN $wpdb->postmeta AS meta ON post.ID = meta.post_id AND meta.meta_key = %s | |
| 334 | -// LEFT JOIN $wpdb->term_relationships AS tr ON tr.object_id = post.ID | |
| 335 | -// LEFT JOIN $wpdb->term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id | |
| 336 | -// LEFT JOIN $wpdb->terms AS te ON te.term_id = tt.term_id ", | |
| 337 | -// '_isku_'); | |
| 338 | - }else{ | |
| 339 | - $query = $wpdb->prepare("SELECT | |
| 340 | - 'item_code' AS item_code, | |
| 341 | - post.post_title, | |
| 342 | - meta.meta_key AS sku_key, meta.meta_value AS sku_value, te.name AS category, post.post_status, | |
| 343 | - CASE post.post_status | |
| 344 | - WHEN 'publish' THEN '" . __('Published', 'usces') . "' | |
| 345 | - WHEN 'future' THEN '" . __('Scheduled', 'usces') . "' | |
| 346 | - WHEN 'draft' THEN '" . __('Draft', 'usces') . "' | |
| 347 | - WHEN 'pending' THEN '" . __('Pending Review', 'usces') . "' | |
| 348 | - WHEN 'trash' THEN '" . __('Trash', 'usces') . "' | |
| 349 | - ELSE '" . __('Closed', 'usces') . "' | |
| 350 | - END AS display_status, | |
| 351 | - post.post_type, post.post_mime_type, post.ID | |
| 352 | - FROM {$this->table} AS post | |
| 353 | - LEFT JOIN $wpdb->postmeta AS meta ON post.ID = meta.post_id AND meta.meta_key = %s | |
| 354 | - LEFT JOIN $wpdb->term_relationships AS tr ON tr.object_id = post.ID | |
| 355 | - LEFT JOIN $wpdb->term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id | |
| 356 | - LEFT JOIN $wpdb->terms AS te ON te.term_id = tt.term_id ", | |
| 357 | - '_isku_'); | |
| 358 | - } | |
| 359 | - } | |
| 360 | - | |
| 361 | - $query .= $where . $order;// . $limit; | |
| 362 | - //var_dump($query); | |
| 363 | - | |
| 364 | - $rows = $wpdb->get_results($query, ARRAY_A); | |
| 365 | - $this->selectedRow = count($rows); | |
| 366 | - if($this->pageLimit == 'off') { | |
| 367 | - $this->rows = $rows; | |
| 368 | - } else { | |
| 369 | - $this->rows = array_slice((array)$rows, $this->startRow, $this->maxRow); | |
| 370 | - } | |
| 371 | - | |
| 372 | - return $this->rows; | |
| 373 | - } | |
| 374 | - | |
| 375 | - function SetTotalRow() | |
| 376 | - { | |
| 377 | - global $wpdb; | |
| 378 | - $query = "SELECT COUNT(ID) AS ct FROM {$this->table} WHERE post_mime_type = 'item' AND post_type = 'post' AND post_status <> 'trash'"; | |
| 379 | - $res = $wpdb->get_var($query); | |
| 380 | - $this->totalRow = $res; | |
| 381 | - } | |
| 382 | - | |
| 383 | -// function SetSelectedRow() | |
| 384 | -// { | |
| 385 | -// global $wpdb; | |
| 386 | -// $where = $this->GetWhere(); | |
| 387 | -// $query = $wpdb->prepare("SELECT | |
| 388 | -// (SELECT meta_value FROM $wpdb->postmeta WHERE post_id = post.ID AND meta_key = '_itemCode') AS item_code, | |
| 389 | -// (SELECT meta_value FROM $wpdb->postmeta WHERE post_id = post.ID AND meta_key = '_itemName') AS item_name, | |
| 390 | -// meta.meta_key AS sku_key, meta.meta_value AS sku_value, te.name AS category, | |
| 391 | -// CASE WHEN post.post_status = 'publish' THEN '公開済み' ELSE '非公開' END AS display_status, | |
| 392 | -// post.post_type, post.post_mime_type, post.ID | |
| 393 | -// (FROM {$this->table} AS post | |
| 394 | -// LEFT JOIN $wpdb->postmeta AS meta ON post.ID = meta.post_id AND SUBSTRING(meta.meta_key, 1, 6) = %s | |
| 395 | -// LEFT JOIN $wpdb->term_relationships AS tr ON tr.object_id = post.ID | |
| 396 | -// LEFT JOIN $wpdb->term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id) | |
| 397 | -// LEFT JOIN $wpdb->terms AS te ON te.term_id = tt.term_id ", | |
| 398 | -// '_isku_'); | |
| 399 | -// | |
| 400 | -// $query .= $where; | |
| 401 | -// $rows = $wpdb->get_results($query, ARRAY_A); | |
| 402 | -// $this->selectedRow = count($rows); | |
| 403 | -// | |
| 404 | -// } | |
| 405 | - | |
| 406 | - function GetWhere() | |
| 407 | - { | |
| 408 | - if( $this->searchSql != '' ){ | |
| 409 | - if( 'display_status' == $this->arr_search['column'] ) | |
| 410 | - $str = "WHERE post.post_mime_type = 'item' AND post.post_type = 'post' AND " . $this->searchSql . " GROUP BY post.ID"; | |
| 411 | -// if( 'item_code' == $this->arr_search['column'] || 'item_name' == $this->arr_search['column'] ) | |
| 412 | -// $str = "WHERE post.post_mime_type = 'item' AND post.post_type = 'post' AND post.post_status <> 'trash' GROUP BY post.ID HAVING " . $this->searchSql; | |
| 413 | - else | |
| 414 | - $str = "WHERE post.post_mime_type = 'item' AND post.post_type = 'post' AND post.post_status <> 'trash' AND " . $this->searchSql . " GROUP BY post.ID"; | |
| 415 | - }else{ | |
| 416 | - $str = "WHERE post.post_mime_type = 'item' AND post.post_type = 'post' AND post.post_status <> 'trash' GROUP BY post.ID"; | |
| 417 | - } | |
| 418 | - return $str; | |
| 419 | - } | |
| 420 | - | |
| 421 | - function SearchIn() | |
| 422 | - { | |
| 423 | - switch ($this->arr_search['column']) { | |
| 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; | |
| 424 | 418 | case 'item_code': |
| 425 | - $column = 'mc.meta_value'; | |
| 426 | - $this->searchSql = $column . ' LIKE '."'%" . esc_sql($this->arr_search['word']['item_code']) . "%'"; | |
| 427 | - break; | |
| 428 | - case 'item_name': | |
| 429 | - $column = 'mn.meta_value'; | |
| 430 | - $this->searchSql = $column . ' LIKE '."'%" . esc_sql($this->arr_search['word']['item_name']) . "%'"; | |
| 431 | - break; | |
| 432 | - case 'post_title': | |
| 433 | - $column = 'post.post_title'; | |
| 434 | - $this->searchSql = $column . ' LIKE '."'%" . esc_sql($this->arr_search['word']['post_title']) . "%'"; | |
| 435 | - break; | |
| 436 | - case 'zaiko_num': | |
| 437 | - $column = 'meta.meta_value'; | |
| 438 | - $this->searchSql = '(' . $column . ' LIKE '."'%" . esc_sql('"stocknum";i:0') . "%' OR " . $column . ' LIKE '."'%" . esc_sql('"stocknum";s:1:"0"')."%')"; | |
| 439 | - break; | |
| 440 | - case 'zaiko': | |
| 441 | - $column = 'meta.meta_value'; | |
| 442 | - $this->searchSql = '(' . $column . ' LIKE '."'%" . esc_sql('stock";i:'.$this->arr_search['word']['zaiko']) . "%' OR " . $column . ' LIKE '."'%" . esc_sql('stock";s:1:"'.$this->arr_search['word']['zaiko']) . "%')"; | |
| 443 | - break; | |
| 444 | - case 'category': | |
| 445 | - $column = 'tt.term_id'; | |
| 446 | - $this->searchSql = $column . " = '" . esc_sql($this->arr_search['word']['category']) . "'"; | |
| 447 | - break; | |
| 448 | - case 'display_status': | |
| 449 | - $column = 'post_status'; | |
| 450 | - $this->searchSql = $column . " = '" . esc_sql($this->arr_search['word']['display_status']) . "'"; | |
| 451 | - break; | |
| 452 | -// case 'post_status': | |
| 453 | -// $column = 'post.post_status'; | |
| 454 | -// $this->searchSql = $column . " = 'trash'"; | |
| 455 | -// break; | |
| 456 | - } | |
| 457 | -// if($this->arr_search['column'] == 'none' || $this->arr_search['column'] == '' || $this->arr_search['word'] == '') | |
| 458 | -// return;//$this->searchSql = $sql; | |
| 459 | -// else | |
| 460 | -// $this->searchSql = $column . ' LIKE '."'%" . esc_sql($this->arr_search['word']) . "%'"; | |
| 461 | - } | |
| 462 | - | |
| 463 | - function SearchOut() | |
| 464 | - { | |
| 465 | - $this->searchSql = ''; | |
| 466 | - } | |
| 467 | - | |
| 468 | - function SetNavi() | |
| 469 | - { | |
| 470 | - | |
| 471 | - $this->lastPage = ceil($this->selectedRow / $this->maxRow); | |
| 472 | - $this->previousPage = ($this->currentPage - 1 == 0) ? 1 : $this->currentPage - 1; | |
| 473 | - $this->nextPage = ($this->currentPage + 1 > $this->lastPage) ? $this->lastPage : $this->currentPage + 1; | |
| 474 | - | |
| 475 | - for($i=0; $i<$this->naviMaxButton; $i++){ | |
| 476 | - if($i > $this->lastPage-1) break; | |
| 477 | - if($this->lastPage <= $this->naviMaxButton) { | |
| 478 | - $box[] = $i+1; | |
| 479 | - }else{ | |
| 480 | - if($this->currentPage <= 6) { | |
| 481 | - $label = $i + 1; | |
| 482 | - $box[] = $label; | |
| 483 | - }else{ | |
| 484 | - $label = $i + 1 + $this->currentPage - 6; | |
| 485 | - $box[] = $label; | |
| 486 | - if($label == $this->lastPage) break; | |
| 487 | - } | |
| 488 | - } | |
| 489 | - } | |
| 490 | - | |
| 491 | - $html = ''; | |
| 492 | - $html .= '<ul class="clearfix">'."\n"; | |
| 493 | - $html .= '<li class="rowsnum">' . $this->selectedRow . ' / ' . $this->totalRow . ' '.__('cases', 'usces').'' . "\n"; | |
| 494 | - if(($this->currentPage == 1) || ($this->selectedRow == 0)){ | |
| 495 | - $html .= '<li class="navigationStr">first<<</li>' . "\n"; | |
| 496 | - $html .= '<li class="navigationStr">prev<</li>'."\n"; | |
| 497 | - }else{ | |
| 498 | - $html .= '<li class="navigationStr"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_itemedit&changePage=1">first<<</a></li>' . "\n"; | |
| 499 | - $html .= '<li class="navigationStr"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_itemedit&changePage=' . $this->previousPage . '">prev<</a></li>'."\n"; | |
| 500 | - } | |
| 501 | - if($this->selectedRow > 0) { | |
| 502 | - for($i=0; $i<count($box); $i++){ | |
| 503 | - if($box[$i] == $this->currentPage){ | |
| 504 | - $html .= '<li class="navigationButtonSelected">' . $box[$i] . '</li>'."\n"; | |
| 505 | - }else{ | |
| 506 | - $html .= '<li class="navigationButton"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_itemedit&changePage=' . $box[$i] . '">' . $box[$i] . '</a></li>'."\n"; | |
| 507 | - } | |
| 508 | - } | |
| 509 | - } | |
| 510 | - if(($this->currentPage == $this->lastPage) || ($this->selectedRow == 0)){ | |
| 511 | - $html .= '<li class="navigationStr">>next</li>'."\n"; | |
| 512 | - $html .= '<li class="navigationStr">>>last</li>'."\n"; | |
| 513 | - }else{ | |
| 514 | - $html .= '<li class="navigationStr"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_itemedit&changePage=' . $this->nextPage . '">>next</a></li>'."\n"; | |
| 515 | - $html .= '<li class="navigationStr"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_itemedit&changePage=' . $this->lastPage . '">>>last</a></li>'."\n"; | |
| 516 | - } | |
| 517 | - if($this->searchSwitchStatus == 'OFF'){ | |
| 518 | - $html .= '<li class="navigationStr"><a style="cursor:pointer;" id="searchVisiLink" onclick="toggleVisibility(\'searchBox\');">' . __('Show the Operation field', 'usces') . '</a>'."\n"; | |
| 519 | - }else{ | |
| 520 | - $html .= '<li class="navigationStr"><a style="cursor:pointer;" id="searchVisiLink" onclick="toggleVisibility(\'searchBox\');">' . __('hide the Operation field', 'usces') . '</a>'."\n"; | |
| 521 | - } | |
| 522 | - | |
| 523 | - $html .= '<li class="refresh"><a href="' . site_url() . '/wp-admin/admin.php?page=usces_itemedit&refresh">' . __('updates it to latest information', 'usces') . '</a></li>' . "\n"; | |
| 524 | - $html .= '</ul>'."\n"; | |
| 525 | - | |
| 526 | - $this->dataTableNavigation = $html; | |
| 527 | - } | |
| 528 | - | |
| 529 | - function SetSESSION() | |
| 530 | - { | |
| 531 | - | |
| 532 | - $_SESSION[$this->table]['startRow'] = $this->startRow; //表示開始行番号 | |
| 533 | - $_SESSION[$this->table]['sortColumn'] = $this->sortColumn; //現在ソート中のフィールド | |
| 534 | - $_SESSION[$this->table]['totalRow'] = $this->totalRow; //全行数 | |
| 535 | - $_SESSION[$this->table]['selectedRow'] = $this->selectedRow; //絞り込まれた行数 | |
| 536 | - $_SESSION[$this->table]['currentPage'] = $this->currentPage; //現在のページNo | |
| 537 | - $_SESSION[$this->table]['previousPage'] = $this->previousPage; //前のページNo | |
| 538 | - $_SESSION[$this->table]['nextPage'] = $this->nextPage; //次のページNo | |
| 539 | - $_SESSION[$this->table]['lastPage'] = $this->lastPage; //最終ページNo | |
| 540 | - $_SESSION[$this->table]['userHeaderNames'] = $this->userHeaderNames;//全てのフィールド | |
| 541 | - $_SESSION[$this->table]['headers'] = $this->headers;//表示するヘッダ文字列 | |
| 542 | - $_SESSION[$this->table]['rows'] = $this->rows; //表示する行オブジェクト | |
| 543 | - $_SESSION[$this->table]['sortSwitchs'] = $this->sortSwitchs; //各フィールド毎の昇順降順スイッチ | |
| 544 | - $_SESSION[$this->table]['dataTableNavigation'] = $this->dataTableNavigation; | |
| 545 | - $_SESSION[$this->table]['searchSql'] = $this->searchSql; | |
| 546 | - $_SESSION[$this->table]['arr_search'] = $this->arr_search; | |
| 547 | - $_SESSION[$this->table]['searchSwitchStatus'] = $this->searchSwitchStatus; | |
| 548 | - } | |
| 549 | - | |
| 550 | - function SetHeaders() | |
| 551 | - { | |
| 552 | - foreach ($this->columns as $key => $value){ | |
| 553 | - if($value == $this->sortColumn){ | |
| 554 | - if($this->sortSwitchs[$value] == 'ASC'){ | |
| 555 | - $str = __('[ASC]', 'usces'); | |
| 556 | - $switch = 'DESC'; | |
| 557 | - }else{ | |
| 558 | - $str = __('[DESC]', 'usces'); | |
| 559 | - $switch = 'ASC'; | |
| 560 | - } | |
| 561 | - if( (USCES_MYSQL_VERSION >= 5 AND ($value == 'item_name' || $value == 'item_code')) || (USCES_MYSQL_VERSION < 5 AND $value == 'post_title') ) | |
| 562 | - $this->headers[$value] = '<a href="' . site_url() . '/wp-admin/admin.php?page=usces_itemedit&changeSort=' . $value . '&switch=' . $switch . '"><span class="sortcolumn">' . $key . ' ' . $str . '</span></a>'; | |
| 563 | - else | |
| 564 | - $this->headers[$value] = '<span class="sortcolumn">' . $key . '</span>'; | |
| 565 | - }else{ | |
| 566 | - $switch = $this->sortSwitchs[$value]; | |
| 567 | - if( (USCES_MYSQL_VERSION >= 5 AND ($value == 'item_name' || $value == 'item_code')) || (USCES_MYSQL_VERSION < 5 AND $value == 'post_title') ) | |
| 568 | - $this->headers[$value] = '<a href="' . site_url() . '/wp-admin/admin.php?page=usces_itemedit&changeSort=' . $value . '&switch=' . $switch . '"><span>' . $key . '</span></a>'; | |
| 569 | - else | |
| 570 | - $this->headers[$value] = '<span class="sortcolumn">' . $key . '</span>'; | |
| 571 | - } | |
| 572 | - } | |
| 573 | - //$this->headers = array_keys($this->columns); | |
| 574 | - } | |
| 575 | - | |
| 576 | - function GetSearchs() | |
| 577 | - { | |
| 578 | - return $this->arr_search; | |
| 579 | - } | |
| 580 | - | |
| 581 | - function GetListheaders() | |
| 582 | - { | |
| 583 | - return $this->headers; | |
| 584 | - } | |
| 585 | - | |
| 586 | - function GetDataTableNavigation() | |
| 587 | - { | |
| 588 | - return $this->dataTableNavigation; | |
| 589 | - } | |
| 590 | - | |
| 591 | - function set_action_status($status, $message) | |
| 592 | - { | |
| 593 | - $this->action_status = $status; | |
| 594 | - $this->action_message = $message; | |
| 595 | - } | |
| 596 | - function get_action_status() | |
| 597 | - { | |
| 598 | - return $this->action_status; | |
| 599 | - } | |
| 600 | - function get_action_message() | |
| 601 | - { | |
| 602 | - return $this->action_message; | |
| 603 | - } | |
| 604 | -} | |
| 605 | - | |
| 606 | - | |
| 607 | -?> | |
| 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 | +} | |