Changeset 2253769
- Timestamp:
- 03/03/2020 05:31:24 PM (6 years ago)
- Location:
- wp-db-table-editor/trunk
- Files:
-
- 4 edited
-
DBTableEditor.class.php (modified) (8 diffs)
-
ReleaseNotes.txt (modified) (1 diff)
-
assets/db-table-editor.js (modified) (4 diffs)
-
db-table-editor.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-db-table-editor/trunk/DBTableEditor.class.php
r2253723 r2253769 44 44 45 45 class DBTE_DataTable { 46 var $rows,$columns, $columnNames ;46 var $rows,$columns, $columnNames, $totalRows, $offset, $page_size, $page_idx; 47 47 function __construct($args=null){ 48 48 global $wpdb; … … 50 50 $sql = @$args['sql']; 51 51 $where = @$args['where']; 52 $limit = @$args['limit']; 53 if(!$limit) $limit = 25000; 54 $offset = @$args['offset']; 55 if(!$offset) $offset = 0; 52 $this->page_size = @$args['page_size']; 53 $this->page_idx = @$args['page_idx']; 54 $limit = $this->page_size; 55 $offset = $this->page_size * $this->page_idx; 56 56 57 if($sql){ 58 $sql = preg_replace('/SELECT/i', 'SELECT SQL_CALC_FOUND_ROWS', $sql, 1); 57 59 if($where){ 58 60 // this has sometimes gone wrong … … 65 67 // error_log("Got sql:\n".$sql); 66 68 $this->rows = $wpdb->get_results($sql, ARRAY_N); 69 $this->$offset = $offset; 67 70 if($wpdb->last_error){ 68 71 error_log("Failed to execute query:\n$sql\nERR:".$wpdb->last_error."\n"); … … 78 81 } 79 82 } 83 $this->totalRows = intval($wpdb->get_var('SELECT FOUND_ROWS();')); 84 80 85 }else if(@$args['rows']){ 81 86 $this->rows = $args['rows']; … … 84 89 $this->columns = $args['columns']; 85 90 } 86 else{ // handle building columns from wpdb87 $this->columnNames = $cnames = $wpdb->get_col_info('name');88 $ctypes = $wpdb->get_col_info('type');89 $this->columns = Array();90 for($i=0; $i < count($cnames) ; $i++){91 $this->columns[]=Array('name'=>$cnames[$i], 'type'=>$ctypes[$i]);92 }93 }94 91 } 95 92 } … … 105 102 $columnFilters, $columnNameMap, $save_cb, $insert_cb, $update_cb, $delete_cb, 106 103 $export_id_field, 107 $id_column, $auto_date, $async_data; 104 $id_column, $auto_date, $async_data, $page_size, $page_idx, $offset; 105 108 106 function __construct($args=null){ 109 107 $args = wp_parse_args($args, array('cap'=>'edit_others_posts')); … … 112 110 if(!$this->title) $this->title = $this->table; 113 111 if(!$this->id_column) $this->id_column = 'id'; 112 if(!$this->page_size) $this->page_size = 10000; 113 if(!$this->page_idx) $this->page_idx = rval('dbte_page_num'); 114 if(!$this->page_idx) $this->page_idx = 0; 115 if(!$this->offset) $this->offset = $this->page_size * $this->page_idx; 114 116 if(!isset($args['auto_date'])) $this->auto_date=true; 117 if(is_null($this->nodelete)) $this->nodelete = $this->noedit; 118 if(is_null($this->noinsert)) $this->noinsert = $this->noedit; 115 119 } 116 120 /* … … 126 130 else if($fn) $args['rows'] = $fn($args); 127 131 else $args["sql"] ="SELECT * FROM $this->table"; 132 133 $args['page_idx'] = $this->page_idx; 134 $args['page_size'] = $this->page_size; 135 $args['offset'] = $this->offset; 136 128 137 $this->data = new DBTE_DataTable($args); 129 138 return $this->data; -
wp-db-table-editor/trunk/ReleaseNotes.txt
r2253723 r2253769 1 Version: 1.8.2 - 2019-03-03 2 * Get automatic results paging working again 3 1 4 Version: 1.8.1 - 2019-02-27 2 5 * A bad merge deleted my automatic paging that was added -
wp-db-table-editor/trunk/assets/db-table-editor.js
r2251550 r2253769 27 27 for (var i = 0; i < vars.length; i++) { 28 28 var pair = vars[i].split('='); 29 obj[decodeURIComponent(pair[0])]=decodeURIComponent(pair[1]); 29 if(pair[0]){ 30 obj[decodeURIComponent(pair[0])]=decodeURIComponent(pair[1]); 31 } 30 32 } 31 33 return obj; … … 264 266 DBTableEditor.updatePagingInfo = function(){ 265 267 var cnt = DBTableEditor.dataView.getPagingInfo()["totalRows"]; 266 jQuery('.db-table-editor-row-count').text (sprintf(translations['row_count'], cnt, DBTableEditor.data.rows.length)); 268 var max = DBTableEditor.offset + DBTableEditor.data.rows.length; 269 jQuery('.db-table-editor-row-count').text ( 270 sprintf(translations['row_count'], 271 cnt, DBTableEditor.offset, max, 272 DBTableEditor.data.totalRows)); 273 jQuery('.dbte-page .prev').toggle(DBTableEditor.data.page_idx > 0); 274 jQuery('.dbte-page .next').toggle(max < DBTableEditor.data.totalRows); 275 267 276 }; 268 277 … … 581 590 }; 582 591 592 DBTableEditor.refresh = function dbte_refresh(){ 593 newL = window.location.pathname +'?'; 594 jQuery.each(DBTableEditor.query, function(k, v){ 595 newL+="&"+encodeURIComponent(k)+"="; 596 if(v) newL += encodeURIComponent(v); 597 }); 598 window.location = newL; 599 } 600 601 DBTableEditor.next = function dbte_next(){ 602 console.log('Nav to next page'); 603 DBTableEditor.query['dbte_page_num'] = Number(DBTableEditor.data.page_idx)+1; 604 DBTableEditor.refresh(); 605 } 606 607 DBTableEditor.prev = function dbte_prev(){ 608 console.log('Nav to prev page'); 609 DBTableEditor.query['dbte_page_num'] = Number(DBTableEditor.data.page_idx)-1; 610 DBTableEditor.refresh(); 611 } 612 613 583 614 DBTableEditor.onload = function(opts){ 584 615 // TODO: switch to objects so there can be more than one table to edit *sigh* … … 600 631 } 601 632 else return console.log("No Data for DBTableEditor"); 602 }; 633 jQuery('body').on('click', '.dbte-page .prev', DBTableEditor.prev); 634 jQuery('body').on('click', '.dbte-page .next', DBTableEditor.next); 635 }; -
wp-db-table-editor/trunk/db-table-editor.php
r2253723 r2253769 5 5 Plugin URI: http://github.com/AcceleratioNet/wp-db-table-editor 6 6 Description: A plugin that adds "tools" pages to edit database tables 7 Version: 1.8. 17 Version: 1.8.2 8 8 Author: Russ Tyndall @ Acceleration.net 9 9 Author URI: http://www.acceleration.net … … 43 43 * the currently selected instance 44 44 */ 45 46 if ( !function_exists('prep_name') ) { 47 function prep_name($n){ 48 $n = str_replace(" ", "_", trim($n)); 49 return $n; 50 } 51 } 52 53 if ( !function_exists('prepped_dict_value') ) { 54 function pdv_names($name){ 55 $o = $name; 56 $n = trim($name); 57 return array( 58 $o, $n, 59 preg_replace('/ /', "_", $n), 60 preg_replace('/-/', "_",$n), 61 preg_replace('/(-|\s)+/', "_",$n) 62 ); 63 } 64 function pdv_clean_v($v){ 65 $v = trim(strip_tags( rawurldecode($v) )); 66 if($v === "") $v = null; 67 return $v; 68 } 69 function pdv_prep_v($v, $implode=true){ 70 if (is_array($v)){ 71 foreach($v as $k=>$d){ 72 $v[$k]=pdv_clean_v($d); 73 } 74 if($implode) $v = implode(',', $v); 75 } 76 else if (is_string($v)){ 77 $v = pdv_clean_v($v); 78 } 79 return $v; 80 } 81 function prepped_dict_value($name, $dict, $implode=true){ 82 $names = pdv_names($name); 83 foreach($names as $n){ 84 $v = isset($dict[$n]) ? $dict[$n] : null; 85 if($v !== null){ 86 $pv = pdv_prep_v($v, $implode); 87 return $pv; 88 } 89 } 90 return null; 91 } 92 } 93 94 95 if ( !function_exists('rval') ) { 96 // gets a value from the request collection 97 // Duplicated from functions for completeness 98 function rval( $name, $implode=true ){ 99 return prepped_dict_value($name, $_REQUEST, $implode); 100 } 101 } 102 103 45 104 global $DBTE_INSTANCES, $DBTE_CURRENT; 46 105 $DBTE_INSTANCES = Array(); … … 156 215 array('slick-grid-js', 'jquery', 'json2', 'moment-js', 'dbte-date-editor-js', 'sprintf-js')); 157 216 $translation_array = array( 158 'row_count' => __( 'Showing %d of %d rows - items with unsaved changes are not filtered', 'wp-db-table-editor' ),217 'row_count' => __( 'Showing %d rows in %d-%d of %d rows - items with unsaved changes are not filtered', 'wp-db-table-editor' ), 159 218 'confirm_delete_row' => __( 'Are you sure you wish to remove this row', 'wp-db-table-editor' ), 160 219 'delete_button' => __( 'Delete this Row', 'wp-db-table-editor' ) … … 254 313 $exportButtonLabel = __('Export to CSV', 'wp-db-table-editor'); 255 314 $clearFiltersButtonLabel = __('Clear Filters', 'wp-db-table-editor'); 256 $rowCountLabel = __('Showing 0 of 0 rows', 'wp-db-table-editor');315 $rowCountLabel = __('Showing 0 rows in 0-0 of 0 rows', 'wp-db-table-editor'); 257 316 $confirmationMessage = __('You have unsaved data, are you sure you want to quit', 'wp-db-table-editor'); 258 317 $o = <<<EOT … … 274 333 </div> 275 334 <div class="db-table-editor-row-count" >$rowCountLabel</div> 335 <button class="prev">← prev</button> 336 <button class="next">next →</button> 276 337 <div class="db-table-editor"></div> 277 338 <script type="text/javascript"> … … 378 439 global $wpdb; // this is how you get access to the database 379 440 $d = $_REQUEST['data']; 380 $tbl= $_REQUEST['table'];441 $tbl= rval('table'); 381 442 $cur = dbte_current($tbl); 382 443 if(!$cur) return; … … 488 549 function dbte_delete_cb(){ 489 550 global $wpdb; 490 $id = $_REQUEST['dataid'];491 $tbl= $_REQUEST['table'];551 $id = rval('dataid'); 552 $tbl= rval('table'); 492 553 $cur = dbte_current($tbl); 493 554 if(!$cur) return; … … 547 608 function dbte_export_csv(){ 548 609 global $wpdb; 549 $cur = dbte_current( @$_REQUEST['table']);610 $cur = dbte_current(rval('table')); 550 611 if(!$cur) return; 551 612 // if($cur->editcap && !current_user_can($cur->editcap)) return; 552 613 $id_col = $cur->id_column; 553 $ids = @$_REQUEST['ids'];614 $ids = rval('ids'); 554 615 $tbl = $cur->table; 555 616 $exidf = $cur->export_id_field;
Note: See TracChangeset
for help on using the changeset viewer.