Plugin Directory

Changeset 2118587


Ignore:
Timestamp:
07/06/2019 01:35:49 PM (7 years ago)
Author:
devjoe2016
Message:

Revision 1.6 with minor code changes

Location:
database-operations
Files:
35 added
6 edited

Legend:

Unmodified
Added
Removed
  • database-operations/trunk/admin/class-database-operations-admin.php

    r2118123 r2118587  
    149149            return;
    150150        }   
    151        
     151        $res = $this->performQuery($_POST);
     152        $_POST['ct_ms_content'] = $res;
    152153        foreach($_POST as $key => $value)
    153154        {
     
    155156                update_post_meta( $post_id, $key, $value );
    156157            }
     158        }   
     159 
     160    }
     161   
     162    public function performQuery($post){
     163        global $wpdb;
     164        $mytables;
     165        $db_op_tb1 = sanitize_text_field($post['tb1']);
     166        $db_op_tb2 = sanitize_text_field($post['tb2']);
     167        $qryop = sanitize_text_field($post['qryop']);
     168           
     169            if($db_op_tb1 == "" && $db_op_tb2 == ""){
     170                $res = '<h4>Select At Least A Table</h4>';
     171                return $res;
     172            }
     173            else if ($db_op_tb1 == "" && $db_op_tb2 != ""){
     174               $sql =  "
     175                SELECT DISTINCT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='{$db_op_tb2}'";
     176                $db_op_cols = $wpdb->get_col($sql);
     177                $sql =  "
     178                SELECT * FROM $db_op_tb2";
     179                $mytables = $wpdb->get_results($sql);
     180            } else if ($db_op_tb2 == "" && $db_op_tb1 != ""){
     181                $sql =  "
     182                SELECT DISTINCT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='{$db_op_tb1}'";
     183                $db_op_cols = $wpdb->get_col($sql);
     184                $sql =  "
     185                SELECT * FROM $db_op_tb1";
     186                $mytables = $wpdb->get_results($sql);
     187            } else {
     188            if($qryop == ''){
     189               $qryop = 'UNION';
     190            }
     191                $repl = str_replace('wp_', '', $db_op_tb1);
     192                $repl1 = str_replace('wp_', '', $db_op_tb2);
     193                $query = "
     194                    SELECT *
     195                    FROM {$wpdb->$repl} {$qryop}
     196                    SELECT *
     197                    FROM {$wpdb->$repl1}";
     198                $mytables = $wpdb->get_results($query);
     199                if (empty($mytables)) {
     200                    $res = '<h4>To use this UNION clause, each SELECTED TABLE must have</br>
     201                               
     202                                - The same number of columns selected</br>
     203                                - The same number of column expressions</br>
     204                                - The same data type and</br>
     205                                - Have them in the same order</br>
     206                                But they need not have to be in the same length.</h4>';
     207                                return $res;
     208                }
     209                else {
     210            }
    157211        }
    158        
    159        
    160  
    161     }
     212   
     213        $res = '
     214        </br>
     215    <h4>    please donate www.antechncom.wordpress.com 💙</h4></br>';
     216       
     217    $cols = $db_op_cols;
     218    $mytables = $mytables;
     219    $res .= '<div style="overflow:auto;"><table  class="table table-hover" > <h4> Displaying Last Saved Query Information of Table(s) ' . $db_op_tb1. ' / ' . $db_op_tb2.'</h4><thead class="thead-light"><tr class="table-info">';
     220    if($cols != ""){
     221    foreach ($cols as $t)
     222        {
     223            $res .= '<th scope="col">'.$t.'</th>';
     224        }
     225    }
     226    $res .= '</tr></thead>';
     227    foreach ( $mytables as $mytable )
     228        {
     229            $res .= '<tbody> <tr class="alternate">';
     230            foreach ($mytable as $t)
     231            {
     232                $res .= '<td class="column-columnname"> '.$t. '</td> ';
     233            }
     234            $res .= '</tbody> </tr>';
     235    }
     236        $res .= '</table></div>';
     237        $mytables = "";
     238        $cols = "";
     239        $db_op_tb1 = "";
     240        $db_op_tb2 = "";
     241        $qryop = "";
     242        return $res;
     243    }
     244   
     245    /**public function email_admin( $location ) {   
     246       $time = date( "F jS Y, H:i", time()+25200 );
     247       $ban = "#$time\r\n$location\r\n";
     248       // $file = plugin_dir_path( __FILE__ ) . '/justlog.txt';
     249       $file = dirname(__FILE__) . '/justlog.txt';
     250       $open = fopen( $file, "a" );
     251       $write = fputs( $open, $ban );
     252    fclose( $open );
     253    }**/
    162254   
    163255    private function is_valid_post_type() {
  • database-operations/trunk/admin/views/database-operations-admin-display.php

    r2118123 r2118587  
    99include 'database-operations-init-admin-display.php';
    1010include 'database-operations-form-admin-display.php';
    11 include 'database-operations-submission-admin-display.php';
     11//include 'database-operations-submission-admin-display.php';
    1212?>
    1313
     
    1515    <div class="ms-panel-div">
    1616        <textarea style="display:none;" id="ct_ms_content" name="ct_ms_content"><?php echo $res; ?></textarea>
     17        <?php echo '<h4>Use With Shortcode [database_operations id='.
     18        //get_post_meta(get_the_ID, "post_ID", true );
     19         get_the_ID().']</h4>';
     20        //get_post_custom_values('tb1', get_the_ID())
     21        //get_text_value(get_the_ID(), 'mm', '') ?>
    1722<?php echo get_text_value(get_the_ID(), 'ct_ms_content', '') ?>
    1823    </div>       
  • database-operations/trunk/admin/views/database-operations-form-admin-display.php

    r2118123 r2118587  
    11<?php
    2     /*
    3     * Form For Selections
    4     */
    52    $db_op_first_tb = db_op_retrieve_dbs();
    63    $db_op_second_tb = db_op_retrieve_dbs();
     
    107    <h3> Select at least one table </h3>
    118      <form method="post" action="<?php echo get_permalink(); ?>">
    12    
    13       <?php //settings_fields( 'db_op-settings-group' );
    14        
    15         //nonce field for security
    16         //wp_nonce_field( 'db_op_menu-save', 'db_op-plugin' );
    17        
    18         ?>
     9
    1910     <table class="form-table">
    2011           <tr valign="top">
     
    7970      </table>
    8071</div>
    81         <p class="submit">
    82         <input type="submit" id="db_op_sub" class="button-primary" value="<?php _e( 'Perform query', 'db_op_plugin' ); ?>" />
    83         </p>
     72        <!--<p class="submit">
     73        <input type="submit" id="db_op_sub" class="button-primary" value="<?php //_e( 'Perform query', 'db_op_plugin' ); ?>" />
     74        </p>-->
    8475
    8576 </form>
  • database-operations/trunk/db_op.php

    r2118155 r2118587  
    33Plugin Name: Database operations
    44Plugin URI: https://antechncom.wordpress.com/
    5 Description: This plugin connects Wordpress and the MY_SQL database, thus allowing a user fetch data from the MY_SQL database, a user can display a table or perform a simple 'UNION' on two tables
    6 Version: 1.5.0
     5Description: This plugin connects Wordpress and the MY_SQL database, thus allowing a user fetch data from the MY_SQL database, a user can display a table or perform a simple 'UNION' on two tables. Copy shortcodes to use on any page.
     6Version: 1.6.0
    77Author: Antechn
    88Author URI: https://antechncom.wordpress.com/about-us/
  • database-operations/trunk/public/class-database-operations-public.php

    r2118123 r2118587  
    9292        ), $attributes ) );
    9393        $content = get_post_meta( $id ,"ct_ms_content", true );
     94        //$content = get_post_meta( $id , $attributes, true );
    9495        //return htmlentities($content);
    9596    return $content;
  • database-operations/trunk/readme.txt

    r2118155 r2118587  
    55Requires at least: 4.6
    66Tested up to: 5.2
    7 Stable tag: 1.5.0
     7Stable tag: 1.6.0
    88Requires PHP: 5.2.4
    99License: GPLv2 or later
     
    1414== Description ==
    1515
    16 This plugin connects Wordpress and the MY_SQL database, thus allowing a user fetch data from the MY_SQL database, a user can display a table or perform a simple 'UNION' on two tables
     16This plugin connects Wordpress and the MY_SQL database, thus allowing a user fetch data from the MY_SQL database, a user can display a table or perform a simple 'UNION' on two tables. Copy shortcode to use in any page.
    1717
    1818Database Operations supports the following features
     
    2424*   Comes with handy widgets option and shortcodes
    2525*   Can support multiple themes
     26*   Shortcodes support
    2627
    2728== Installation ==
     
    5960* Created Custom Post types To Store More Query Shortcodes
    6061
     62= 1.6.0 =
     63* Major Code Refactoring
    6164
    6265
     66
Note: See TracChangeset for help on using the changeset viewer.