4images Modifications / Modifikationen > Plugins

[MOD-Ajax-Plugin] - SQL Fields Diagnostic

(1/1)

thunderstrike:
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: ---<?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($counter, format_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();
?>

--- End code ---

// Step 2

In admin/admin_functions.php file,

find:


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

--- End code ---

add after:


--- Code: ---<?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    
    }
    ?>

--- End code ---

// Step 3

In admin folder, create file: sql_fields_diagnostic.js .

Add:


--- Code: ---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;
}

--- End code ---

// Step 4

In lang/english/admin.php file,

Find:


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

--- End code ---

add after:


--- Code: ---//-----------------------------------------------------
//--- 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}";

--- End code ---

Finish.

Nicky:
moving to releases.

thank you

Navigation

[0] Message Index

Go to full version