• [MOD-Ajax-Plugin] - SQL Fields Diagnostic 3 0 5 1
Currently:  

Author Topic: [MOD-Ajax-Plugin] - SQL Fields Diagnostic  (Read 9579 times)

0 Members and 1 Guest are viewing this topic.

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
[MOD-Ajax-Plugin] - SQL Fields Diagnostic
« on: December 18, 2007, 07:57:40 PM »
This is MOD for diagnostic SQL Fields structure in ACP with single click - (Ajax)  8)
- Is easy for support in forum after create fields in phpmyadmin or SQL Patches MOD. -

I post 2 screenshot with instruction for see test for proof of work.

// Step 1

In admin/plugins folder - create file: sql_fields_diagnostic.php .

Add:

Code: [Select]
<?php // PLUGIN_TITLE: SQL Fields Diagnostic

$nozip 1;
define('IN_CP'1);
define('ROOT_PATH'"./../../");
require(
ROOT_PATH.'admin/admin_global.php');

show_admin_header();

if (
$action == "") {
    
$action "main_menu";
}

if (
$action == "main_menu") {
    
    
$tables_info = array();
    
$db = (get_mysql_version() >= 32306)  ? "`$db_name`" $db_name;
    
$result $site_db->query("SHOW tables");    
    if (
$result) {
        
?>

        <form>
        <?php echo $lang['sql_fields_diagnostic_select_table']; ?>
        <select name="users" onchange="showTables(this.value)" class="select" />        
        <option>---</option>                    
        <?php        
        
while ($row $site_db->fetch_array($result)) {            
            if (
preg_match("/^".$table_prefix."/i"$row[0])) {
                
?>

                <option value="<?php echo $row[0]; ?>"><?php echo format_text(trim($row[0]), 2); ?></option>            
                <?php
            
}
        }
        
$site_db->free_result($result);
        
?>

        </select>
        </form>      
        
        <table border="0" width="100%" cellpadding="0" cellspacing="0">
        <tr>
        <td width="100%" class="tableheader">&nbsp;<?php echo $lang['sql_fields_diagnostic_title']; ?></td>
        </tr>
        <tr>
        <td width="100%" class="tablerow">&nbsp;</td>
        </tr>
        <tr>
        <td width="100%"><div id="txtHint">&nbsp;</div></td>
        </tr>        
        </table>
        <?php
    
}
}

if (
$action == "get_sql_table") {
    
    if (isset(
$HTTP_GET_VARS['table_name'])) {
        
$table_name = (isset($HTTP_GET_VARS['table_name'])) ? un_htmlspecialchars(trim((string)$HTTP_GET_VARS['table_name'])) : "";
    } else {
        
$table_name "";
    }
    
    if (isset(
$table_name) && $table_name == "---") {
        exit;
    }
    
    
$result $site_db->query("SHOW FIELDS FROM " $table_name);
    if (isset(
$result) && $result) {
        
$counter 0;
        while (
$row $site_db->fetch_array($result)) {
            
$counter++;
            
?>

            <table border="0" width="100%" cellpadding="0" cellspacing="0">
            <tr>
            <td width="100%" class="tableheader">&nbsp;<?php echo str_replace(array("{counter}""{field_name}"), array($counterformat_text(trim($row['Field']), 2)), $lang['sql_fields_diagnostic_results']); ?></td>
            </tr>
            </table>
            <table border="0" width="100%" cellpadding="0" cellspacing="0">            
            <tr>
            <td width="100%" align="center" class="tablerow">
            <?php
            
if (isset($row['Key']) && $row['Key'] == "PRI") {
                
?>

                <br /><li><?php echo $lang['sql_fields_diagnostic_primary_key']; ?></li>
                <?php
            
}            
            if (isset(
$row['Key']) && $row['Key'] == "MUL") {
                
?>

                <br /><li><?php echo $lang['sql_fields_diagnostic_multiple_key']; ?></li>
                <?php
            
}
            if (isset(
$row['Default']) && !empty($row['Default']) && is_string($row['Default']) || is_numeric($row['Default'])) {
                
?>

                <br /><li><?php echo str_replace("{default_value}"format_text(trim($row['Default']), 2), $lang['sql_fields_diagnostic_default_value']); ?></li>
                <?php
            
} elseif (isset($row['Default']) && empty($row['Default']) && is_string($row['Default'])) {
                
?>

                <br /><li><?php echo str_replace("{default_value}"$lang['sql_fields_diagnostic_empty'], $lang['sql_fields_diagnostic_default_value']); ?></li>
                <?php
            
}            
            if (isset(
$row['Extra']) && !empty($row['Extra'])) {                
                
?>

                <br /><li><?php echo $lang['sql_fields_diagnostic_auto_increment']; ?></li>
                <?php
            
}            
            if (isset(
$row['Type']) && !empty($row['Type'])) {                
                
?>

                <br /><li><?php echo str_replace("{type}"format_text(trim($row['Type']), 2), $lang['sql_fields_diagnostic_type']); ?></li>
                <?php
            
}
            if (isset(
$row['Null']) && is_null($row['Null'])) {
                
?>

                <br /><li><?php echo str_replace("{null}""<font color=\"red\">" $lang['sql_fields_diagnostic_yes'] . "</font>"$lang['sql_fields_diagnostic_null']); ?></li>
                <?php
            
} elseif (isset($row['Null']) && !is_null($row['Null'])) {
                
?>

                <br /><li><?php echo str_replace("{null}""<font color=\"green\">" $lang['sql_fields_diagnostic_no'] . "</font>"$lang['sql_fields_diagnostic_null']); ?></li>
                <?php
            
}
            
?>

            </td>
            </tr>
            </table>
            <table border="0" width="100%" cellpadding="0" cellspacing="0">
            <tr>
            <td width="100%" class="tablerow">&nbsp;</td>
            </tr>
            </table>
            <?php
        
}
        
?>

        <table border="0" width="100%" cellpadding="0" cellspacing="0">
        <tr>
        <td width="100%" class="tableheader">&nbsp;</td>            
        </tr>
        </table>
        <table border="0" width="100%" cellpadding="0" cellspacing="0">
        <tr>
        <td width="100%" align="center" class="tablerow"><br /><span class=\"smalltext\">SQL Fields Diagnostic MOD - created by <a href="http://www.4homepages.de/forum/index.php?topic=19856.0" target="_blank" />Thunderstrike</a> - 2007-2008<br />Version 1.0</span><br /><br /></td>
        </tr>
        </table>
        <table border="0" width="100%" cellpadding="0" cellspacing="0">
        <tr>
        <td width="100%" class="tableheader">&nbsp;</td>            
        </tr>
        </table>
        <?php
    
}
}
show_admin_footer();
?>


// Step 2

In admin/admin_functions.php file,

find:

Code: [Select]
<script type="text/javascript" language="javascript" src="<?php echo ROOT_PATH?>admin/calendar.js"></script>

add after:

Code: [Select]
<?php
    
// MOD: SQL Fields Diagnostic
    
if (preg_match("/sql_fields_diagnostic.php/"$self_url)) {
        
?>

        <script src="<?php echo ROOT_PATH?>admin/sql_fields_diagnostic.js"></script>
        <?php
    
// End of MOD: SQL Fields Diagnostic    
    
}
    
?>


// Step 3

In admin folder, create file: sql_fields_diagnostic.js .

Add:

Code: [Select]
var xmlHttp

function showTables(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="./../../admin/plugins/sql_fields_diagnostic.php"
url=url+"?action=get_sql_table&table_name="+str
//url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
 document.getElementById("txtHint").innerHTML=xmlHttp.responseText
 }
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

// Step 4

In lang/english/admin.php file,

Find:

Code: [Select]
//-----------------------------------------------------
//--- Settings ----------------------------------------
//-----------------------------------------------------
$lang['save_settings_success'] = "Settings saved";

add after:

Code: [Select]
//-----------------------------------------------------
//--- SQL Fields Diagnostic ---------------------------
//-----------------------------------------------------
$lang['sql_fields_diagnostic_title'] = "SQL Fields Diagnostic";
$lang['sql_fields_diagnostic_select_table'] = "Select a table: ";
$lang['sql_fields_diagnostic_results'] = "Field {counter}: {field_name}";
$lang['sql_fields_diagnostic_primary_key'] = "Primary key: <font color=\"green\">Found !</font>";
$lang['sql_fields_diagnostic_multiple_key'] = "Multiple key: <font color=\"green\">Found !</font>";
$lang['sql_fields_diagnostic_default_value'] = "Default value: {default_value}";
$lang['sql_fields_diagnostic_auto_increment'] = "Auto increment: <font color=\"green\">Found !</font>";
$lang['sql_fields_diagnostic_found'] = "<font color=\"green\">Found !</font>";
$lang['sql_fields_diagnostic_empty'] = "Empty";
$lang['sql_fields_diagnostic_yes'] = "Yes !";
$lang['sql_fields_diagnostic_no'] = "No !";
$lang['sql_fields_diagnostic_type'] = "Type: {type}";
$lang['sql_fields_diagnostic_null'] = "Null: {null}";

Finish.
« Last Edit: August 27, 2011, 02:17:30 PM by thunderstrike »
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
Re: [MOD-Ajax-Plugin] - SQL Fields Diagnostic
« Reply #1 on: December 19, 2007, 09:29:47 AM »
moving to releases.

thank you
cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi