Changeset 914131
- Timestamp:
- 05/14/2014 07:59:04 PM (12 years ago)
- Location:
- edit-any-table/trunk
- Files:
-
- 2 edited
-
EditAnyTable.php (modified) (16 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
edit-any-table/trunk/EditAnyTable.php
r847919 r914131 4 4 Plugin URI: http://redeyedmonster.co.uk/edit-any-table/ 5 5 Description: Dashboard widget which allows the editing of all tables in any database 6 Version: 2.0. 06 Version: 2.0.1 7 7 Author: Nigel Bachmann 8 8 Text Domain: EditAnyTable … … 31 31 function EditAnyTable_init() 32 32 { 33 //$plugin_dir = plugin_dir_url(__FILE__);//$plugin_dir.'languages'34 33 load_plugin_textdomain( 'EditAnyTable', false, basename(dirname(__FILE__)).'/languages/'); 35 34 } … … 57 56 } 58 57 59 //$result = $eat_db->get_col($eat_db->prepare("show tables",null));60 61 58 ?> 62 59 … … 195 192 $eat_db = new wpdb($options['eat_user'],$options['eat_pwd'],$options['eat_db'],$options['eat_host']); 196 193 197 //Get a single record for column info 198 $sql = $eat_db->prepare("select * from ".$table2Edit." LIMIT 1",null); 199 //echo $sql."<br />"; 200 $records = $eat_db->get_results($sql,'ARRAY_N'); 201 202 //get column information 203 $cols = $eat_db->get_col_info('name',-1); 204 $numeric = $eat_db->get_col_info('numeric',-1); 205 194 $cols = $eat_db->get_results("show columns from ".$table2Edit); 195 206 196 //build where 207 197 $where = ""; … … 209 199 for($i = 0;$i < count($keysArray); $i++) 210 200 { 211 212 //need to find out if the value is for a numeric field or not213 201 $isNumeric = 0; 214 for($in = 0; $in < count($cols); $in++) 215 { 216 if($cols[$in] == $keysArray[$i]) 217 { 218 $isNumeric = $numeric[$in] == 1; 219 } 220 } 202 foreach($cols as $col) 203 { 204 if($col->Field == $keysArray[$i]) 205 { 206 $isNumeric = 207 strpos($col->Type,"int") !== false || 208 strpos($col->Type,"decimal") !== false || 209 strpos($col->Type,"float") !== false || 210 strpos($col->Type,"double") !== false || 211 strpos($col->Type,"real") !== false || 212 strpos($col->Type,"bit") !== false || 213 strpos($col->Type,"boolean") !== false || 214 strpos($col->Type,"serial") !== false ; 215 } 216 } 221 217 222 218 if($keysArray[$i] != "") … … 239 235 } 240 236 } 241 //echo $where; 242 237 243 238 //prepare the delete statement 244 239 $sql = $eat_db->prepare("DELETE from ".$table2Edit." where ".$where, $vals); 245 //echo $sql;246 240 $result = $eat_db->query($sql); 247 241 if($result) … … 342 336 $keysArray = explode("~", $keys); 343 337 $valsArray = explode("~", $values); 338 344 339 //Connect to the database 345 340 $options = get_option('eat_options'); 346 341 $eat_db = new wpdb($options['eat_user'],$options['eat_pwd'],$options['eat_db'],$options['eat_host']); 347 342 348 //Get a single record for column info 349 $sql = $eat_db->prepare("select * from ".$table2Edit." LIMIT 1",null); 350 //echo $sql."<br />"; 351 $records = $eat_db->get_results($sql,'ARRAY_N'); 352 353 //get column information 354 $cols = $eat_db->get_col_info('name',-1); 355 $types = $eat_db->get_col_info('type',-1); 356 $primary = $eat_db->get_col_info('primary_key',-1); 357 $numeric = $eat_db->get_col_info('numeric',-1); 343 //Get column information 344 $cols = $eat_db->get_results("show columns from ".$table2Edit); 358 345 359 346 //build where … … 365 352 //need to find out if the value is for a numeric field or not 366 353 $isNumeric = 0; 367 for($in = 0; $in < count($cols); $in++) 368 { 369 if($cols[$in] == $keysArray[$i]) 370 { 371 $isNumeric = $numeric[$in] == 1; 354 foreach($cols as $col) 355 { 356 if($col->Field == $keysArray[$i]) 357 { 358 $isNumeric = 359 strpos($col->Type,"int") !== false || 360 strpos($col->Type,"decimal") !== false || 361 strpos($col->Type,"float") !== false || 362 strpos($col->Type,"double") !== false || 363 strpos($col->Type,"real") !== false || 364 strpos($col->Type,"bit") !== false || 365 strpos($col->Type,"boolean") !== false || 366 strpos($col->Type,"serial") !== false ; 372 367 } 373 368 } … … 412 407 $sql = $eat_db->prepare("select * from ".$table2Edit." LIMIT ".$offSet.", ".$eat_cols."",null); 413 408 } 414 $records = $eat_db->get_results($sql,'ARRAY_N'); 409 410 $records = $eat_db->get_results($sql,'ARRAY_A'); 415 411 416 412 //lets work out how many columns we're going to display (max from options) … … 433 429 if($numCols > 0) 434 430 { 435 431 $primaryKeyExists = false; 436 432 ?> 437 433 <div style="overflow: auto"> … … 453 449 <?php 454 450 //need to write the results vertically 455 for ($i = 0; $i < count($cols); $i++)451 foreach($cols as $col) 456 452 { 457 453 ?> 458 454 <tr> 459 <td><?php echo $col s[$i]; ?></td>455 <td><?php echo $col->Field; ?></td> 460 456 <?php 461 457 … … 463 459 { 464 460 $row = $records[$in]; 465 if($ primary[$i] == 1)461 if($col->Key == "PRI") 466 462 { 463 $primaryKeyExists=true; 467 464 ?> 468 <td style="background-color:white" id="PRIMARY:<?php echo $col s[$i]; ?>"><?php echo $row[$i]; ?></td>465 <td style="background-color:white" id="PRIMARY:<?php echo $col->Field; ?>"><?php echo $row[$col->Field]; ?></td> 469 466 <?php 470 467 } … … 472 469 { 473 470 ?> 474 <td id="<?php echo $col s[$i]; ?>"><input type="text" value="<?php echo sanitize_text_field($row[$i]); ?>" /></td>471 <td id="<?php echo $col->Field; ?>"><input type="text" value="<?php echo sanitize_text_field($row[$col->Field]); ?>" /></td> 475 472 <?php 476 473 } … … 486 483 for($i = 0; $i < $numCols; $i++) 487 484 { 488 if( in_array(1,$primary)) //Do not show save or delete buttons if there is no primary key485 if($primaryKeyExists) //Do not show save or delete buttons if there is no primary key 489 486 { 490 487 … … 532 529 function TableDetails() 533 530 { 534 //get options 535 $options = get_option('eat_options'); 536 537 //Get required values 531 //Get required values 538 532 $table2Edit = $_POST['table2Edit']; 539 533 $eat_cols = $_POST['eat_cols']; … … 543 537 $eat_db = new wpdb($options['eat_user'],$options['eat_pwd'],$options['eat_db'],$options['eat_host']); 544 538 545 //get a sample row 546 $result = $eat_db->get_results("select * from ".$table2Edit." LIMIT 0, 1"); 547 548 //get column information 549 $cols = $eat_db->get_col_info('name',-1); 550 $types = $eat_db->get_col_info('type',-1); 551 $primary = $eat_db->get_col_info('primary_key',-1); 552 553 554 //build the table 555 //if($eat_db->num_rows > 0) Removed for 1.3.0 556 //{ 557 ?> 558 <hr> 559 <div> 560 <button class="button-primary" title="Find records matching the values entered" id="buttonFind"><?php _e('Find','EditAnyTable'); ?></button> 561 562 <input type="checkbox" id="fuzzy" /> <?php _e('Fuzzy','EditAnyTable'); ?> 563 <?php 564 // Check that editor has rights to add 565 if(current_user_can('administrator') || (current_user_can('editor') && $options['eat_editorPrivAdd']=='yes')) 539 // Get column info 540 $cols = $eat_db->get_results("show columns from ".$table2Edit) 541 542 543 ?> 544 <hr> 545 <div> 546 <button class="button-primary" title="Find records matching the values entered" id="buttonFind"><?php _e('Find','EditAnyTable'); ?></button> 547 548 <input type="checkbox" id="fuzzy" /> <?php _e('Fuzzy','EditAnyTable'); ?> 549 <?php 550 // Check that editor has rights to add 551 if(current_user_can('administrator') || (current_user_can('editor') && $options['eat_editorPrivAdd']=='yes')) 552 { 553 ?> 554 555 <button class="button-primary" title="<?php _e('Add a new record with the values entered','EditAnyTable');?>" id="buttonAdd"><?php _e('Add','EditAnyTable'); ?></button> 556 <?php 557 } 558 ?> 559 560 <button class="button" title="<?php _e('Clear all the values','EditAnyTable');?>" id="buttonReset"><?php _e('Reset','EditAnyTable');?></button> 561 </div> 562 <hr> 563 <div style="overflow: auto"> 564 <table id="tableCols"> 565 <tr> 566 <td><strong><?php _e('Column','EditAnyTable');?></strong></td> 567 <td><strong><?php _e('Value','EditAnyTable');?></strong></td> 568 </tr> 569 <?php 570 foreach($cols as $col) 566 571 { 567 572 ?> 568 569 <button class="button-primary" title="<?php _e('Add a new record with the values entered','EditAnyTable');?>" id="buttonAdd"><?php _e('Add','EditAnyTable'); ?></button> 573 <tr> 574 <td> 575 <?php 576 echo $col->Field." (".$col->Type.")"; 577 if($col->Key=="PRI") 578 { 579 echo " [PRI]"; 580 } 581 ?> 582 583 </td> 584 <td> 585 <input type="text" id="<?php echo sanitize_text_field($col->Field); ?>" /> 586 </td> 587 588 </tr> 570 589 <?php 571 590 } 572 591 ?> 573 574 <button class="button" title="<?php _e('Clear all the values','EditAnyTable');?>" id="buttonReset"><?php _e('Reset','EditAnyTable');?></button> 575 </div> 576 <hr> 577 <div style="overflow: auto"> 578 <table id="tableCols"> 579 <tr> 580 <td><strong><?php _e('Column','EditAnyTable');?></strong></td> 581 <td><strong><?php _e('Value','EditAnyTable');?></strong></td> 582 </tr> 583 <?php 584 for($i=0;$i<count($cols);$i++) 585 { 586 ?> 587 <tr> 588 <td> 589 <?php 590 echo $cols[$i]." (".$types[$i].")"; 591 if($primary[$i]==1) 592 { 593 echo " [PRIMARY]"; 594 } 595 ?> 596 597 </td> 598 <td> 599 <input type="text" id="<?php echo sanitize_text_field($cols[$i]); ?>" /> 600 </td> 601 602 </tr> 603 <?php 604 } 605 ?> 606 </table> 607 </div> 608 <?php 609 //} 592 </table> 593 </div> 594 <?php 595 610 596 611 597 die(); -
edit-any-table/trunk/readme.txt
r911659 r914131 89 89 == Changelog == 90 90 91 = 2.0.1 = 92 * FIX Due to a change in the wpdb class in WordPress 3.9 Edit Any Table was unable to identify primary keys on some MySQL/PHP platforms - this has now been rectified. 93 91 94 = 2.0.0 = 92 95 * Localization Added … … 124 127 125 128 == Upgrade Notice == 129 130 = 2.0.1 = 131 * FIX Due to a change in the wpdb class in WordPress 3.9 Edit Any Table was unable to identify primary keys on some MySQL/PHP platforms - this has now been rectified. 126 132 127 133 = 2.0.0 =
Note: See TracChangeset
for help on using the changeset viewer.