|
From: Markus P. <mar...@us...> - 2005-04-19 21:05:31
|
Update of /cvsroot/mxbb/core/admin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2663 Modified Files: admin_mx_chkobjs.php Log Message: Improved Object Integrity Checker (with delete function) Index: admin_mx_chkobjs.php =================================================================== RCS file: /cvsroot/mxbb/core/admin/admin_mx_chkobjs.php,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** admin_mx_chkobjs.php 9 Jan 2005 21:55:43 -0000 1.7 --- admin_mx_chkobjs.php 19 Apr 2005 21:05:20 -0000 1.8 *************** *** 1,179 **** <?php ! /** ------------------------------------------------------------------------ ! * subject : mx-portal, CMS & portal ! * begin : june, 2002 ! * copyright : (C) 2002-2005 MX-System ! * email : jon...@ho... ! * project site : www.mx-system.com ! * ! * description : ! * ------------------------------------------------------------------------- ! * $Id$ ! */ - /** - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - */ // ====================================================== ! // [ ADMINCP COMMON INITIALIZATION ] // ====================================================== - $no_page_header = true; ! if ( !empty( $setmodules ) ) { ! $file = basename( __FILE__ ); ! $module['Portal - System']['Objects_Integrity_Check'] = 'admin/' . $file; return; } ! define( 'IN_PORTAL', 1 ); $mx_root_path = '../'; // Security and page header - require( './pagestart.php' ); // ====================================================== ! // [ GLOBAL DATA ] // ====================================================== - $main_title = "Check MX Objects"; - $main_desc = "This utility allows you to check MX object relationships."; - $main_info = "This report shows the relations between MX tables. " . "You'll see the object name next to its object identifier. " . "Whenever an object is missing (not found on the database), the row is marked with the symbol <font color=red>[?]</font>. " . "In this case, execute phpMyAdmin (or your favorite DB Control Center) and remove that row.<br /><br />" . "DISCLAIMER: This utility is released AS-IS. Please, ensure you have a working backup <u>before</u> you manually edit your DB."; ! $check_args = array( ! array( 'table' => FUNCTION_TABLE, ! 'fkeys' => array( ! array( MODULE_TABLE, 'module_id', 'module_name' ), ! array( FUNCTION_TABLE, 'function_id', 'function_name' ) ! ) ! ), ! array( 'table' => PARAMETER_TABLE, ! 'fkeys' => array( ! array( FUNCTION_TABLE, 'function_id', 'function_name' ), ! array( PARAMETER_TABLE, 'parameter_id', 'parameter_name' ) ! ) ! ), ! array( 'table' => PARAMETER_OPTION_TABLE, ! 'fkeys' => array( ! array( PARAMETER_TABLE, 'parameter_id', 'parameter_name' ), ! array( PARAMETER_OPTION_TABLE, 'option_id', 'option_desc' ) ! ) ! ), ! array( 'table' => BLOCK_TABLE, ! 'fkeys' => array( ! array( FUNCTION_TABLE, 'function_id', 'function_name' ), ! array( BLOCK_TABLE, 'block_id', 'block_title' ) ! ) ! ), ! array( 'table' => BLOCK_SYSTEM_PARAMETER_TABLE, ! 'fkeys' => array( ! array( BLOCK_TABLE, 'block_id', 'block_title' ), ! array( PARAMETER_TABLE, 'parameter_id', 'parameter_name' ) ! ) ! ), ! array( 'table' => COLUMN_TABLE, ! 'fkeys' => array( ! array( PAGE_TABLE, 'page_id', 'page_name' ), ! array( COLUMN_TABLE, 'column_id', 'column_title' ) ! ) ! ), ! array( 'table' => COLUMN_BLOCK_TABLE, ! 'fkeys' => array( ! array( COLUMN_TABLE, 'column_id', 'column_title' ), ! array( BLOCK_TABLE, 'block_id', 'block_title' ) ! ) ! ) ! ); // ====================================================== ! // [ MAIN PROCESS ] // ====================================================== // Check to see if we need to show the table selection box. ! ! if ( isset( $_POST['check_mode'] ) ) { ! $check_mode = $_POST['check_mode']; ! $check_mode = htmlspecialchars( $check_mode ); } else { ! $select_options = '<select name="check_mode">'; ! for( $i = 0; $i < count( $check_args ); $i++ ) { ! $select_options .= '<option value="' . $i . '">' . $check_args[$i]['table'] . '</option>'; ! } ! $select_options .= '</select>'; ! mx_message_die( GENERAL_MESSAGE, ! '<p>' . $main_desc . '</p>' . '<form action="' . append_sid( PORTAL_URL . 'admin/admin_mx_chkobjs.php' ) . '" method="post"> ' . $select_options . ' <input type="submit" name="submit" value="' . $lang[Submit] . '" class="mainoption" /></form>', ! $main_title ); } ! include_once( './page_header_admin.php' ); ! check_relationship( $check_mode ); ! include( './page_footer_admin.php' ); exit; // ====================================================== ! // [ FUNCTIONS ] // ====================================================== - // ------------ - ! function check_relationship( $tb ) { ! global $db, $check_args, $main_title, $main_desc, $main_info; $table = $check_args[$tb]['table']; ! $fkeys = count( $check_args[$tb]['fkeys'] ); ! for( $i = 0; $i < $fkeys; $i++ ) { $ftab[] = $check_args[$tb]['fkeys'][$i][0]; $fkey[] = $check_args[$tb]['fkeys'][$i][1]; $fnam[] = $check_args[$tb]['fkeys'][$i][2]; ! } ! // Build the query and check the table relations. ! ! $sql = "SELECT * FROM " . $table . " ORDER BY " . implode( ',', $fkey ); ! $result = $db->sql_query( $sql ); ! if ( !$result ) { ! mx_message_die( GENERAL_ERROR, "Couldn't obtain the data from database.", "", __LINE__, __FILE__, $sql ); } ! $html = '<h1>' . $main_title . '</h1>' . "\n"; ! $html .= '<p>' . $main_desc . '<br /><br />' . $main_info . '</p>' . "\n"; ! $html .= '<table width="100%" cellpadding="2" cellspacing="1" border="0" class="forumline" align="center">' . "\n"; ! $html .= "\t" . '<tr>' . "\n"; ! $html .= tbHead( 'td', 'catHead', 4, '<b>Checking Table: ' . $table . '</b>' ); ! $html .= "\t" . '</tr>' . "\n"; ! $html .= "\t" . '<tr>' . "\n"; ! $html .= tbHead( 'td', 'cat', 4, '<a href="javascript:history.go(-1);"><b>Go Back</b></a>' ); ! $html .= "\t" . '</tr>' . "\n"; ! $html .= "\t" . '<tr>' . "\n"; ! $html .= tbHead( 'th', 'thCornerL', 1, $fkey[0] ); ! for( $i = 0; $i < ( $fkeys-1 ); $i++ ) { ! $html .= tbHead( 'th', 'thTop' , 1, $fnam[$i] ); ! $html .= tbHead( 'th', 'thTop' , 1, $fkey[$i + 1] ); } ! $html .= tbHead( 'th', 'thCornerR', 1, $fnam[$fkeys-1] ); ! $html .= "\t" . '</tr>' . "\n"; $row_count = 0; ! while ( $row = $db->sql_fetchrow( $result ) ) { ! $row_class = ( ( $row_count % 2 ) == 0 ) ? 'row1' : 'row2'; ! $html .= "\t" . '<tr>' . "\n"; ! for( $i = 0; $i < $fkeys; $i++ ) { $field = $fkey[$i]; ! if ( $ftab[$i] == $table ) { $field_key = $row[$field]; --- 1,256 ---- <?php ! /*************************************************************************** ! * admin_mx_chkobjs.php ! * -------------------- ! * begin : June, 2003 ! * copyright : (C) 2002-2005 mxBB-Portal ! * email : su...@mx... ! * ! * $Id$ ! * ! ***************************************************************************/ ! ! /*************************************************************************** ! * ! * This program is free software; you can redistribute it and/or modify ! * it under the terms of the GNU General Public License as published by ! * the Free Software Foundation; either version 2 of the License, or ! * (at your option) any later version. ! * ! ***************************************************************************/ // ====================================================== ! // [ ADMINCP COMMON INITIALIZATION ] // ====================================================== ! $no_page_header = TRUE; ! ! if( !empty($setmodules) ) { ! $module['Portal - System']['Objects_Integrity_Check'] = 'admin/' . basename(__FILE__); return; } ! define('IN_PORTAL', 1); $mx_root_path = '../'; + // // Security and page header + // + require('./pagestart.php'); + // ====================================================== ! // [ GLOBAL DATA ] // ====================================================== ! $main_title = "Check mxBB Objects"; ! $main_desc = "This utility allows you to check mxBB object relationships."; ! $main_info = "This report shows the relations between mxBB tables. " . ! "You'll see the object name next to its object identifier. " . ! "Whenever an object is missing (not found on the database), the row is marked with the symbol <font color=red>[?]</font>. " . ! "In this case, execute phpMyAdmin (or your favorite DB Control Center) and remove that row.<br /><br />" . ! "DISCLAIMER: This utility is released AS-IS. Please, ensure you have a working backup <u>before</u> you manually edit your DB."; ! ! $check_args = array( ! array( ! 'table' => FUNCTION_TABLE, ! 'fkeys' => array( ! array(MODULE_TABLE, 'module_id', 'module_name'), ! array(FUNCTION_TABLE, 'function_id', 'function_name') ! ) ! ), ! array( ! 'table' => PARAMETER_TABLE, ! 'fkeys' => array( ! array(FUNCTION_TABLE, 'function_id', 'function_name'), ! array(PARAMETER_TABLE, 'parameter_id', 'parameter_name') ! ) ! ), ! array( ! 'table' => PARAMETER_OPTION_TABLE, ! 'fkeys' => array( ! array(PARAMETER_TABLE, 'parameter_id', 'parameter_name'), ! array(PARAMETER_OPTION_TABLE, 'option_id', 'option_desc') ! ) ! ), ! array( ! 'table' => BLOCK_TABLE, ! 'fkeys' => array( ! array(FUNCTION_TABLE, 'function_id', 'function_name'), ! array(BLOCK_TABLE, 'block_id', 'block_title') ! ) ! ), ! array( ! 'table' => BLOCK_SYSTEM_PARAMETER_TABLE, ! 'fkeys' => array( ! array(BLOCK_TABLE, 'block_id', 'block_title'), ! array(PARAMETER_TABLE, 'parameter_id', 'parameter_name') ! ) ! ), ! array( ! 'table' => COLUMN_TABLE, ! 'fkeys' => array( ! array(PAGE_TABLE, 'page_id', 'page_name'), ! array(COLUMN_TABLE, 'column_id', 'column_title') ! ) ! ), ! array( ! 'table' => COLUMN_BLOCK_TABLE, ! 'fkeys' => array( ! array(COLUMN_TABLE, 'column_id', 'column_title'), ! array(BLOCK_TABLE, 'block_id', 'block_title') ! ) ! ) ! ); ! ! // ====================================================== ! // [ MAIN PROCESS ] // ====================================================== + // // Check to see if we need to show the table selection box. ! // ! if( isset($HTTP_POST_VARS['check_mode']) || isset($HTTP_GET_VARS['check_mode']) ) { ! $check_mode = ( isset($HTTP_POST_VARS['check_mode']) ? $HTTP_POST_VARS['check_mode'] : $HTTP_GET_VARS['check_mode'] ); } else { ! if( !isset($HTTP_GET_VARS['mode']) ) { ! $select_options = '<select name="check_mode">'; ! for( $i=0; $i < count($check_args); $i++ ) ! { ! $selected = ( $i == $HTTP_GET_VARS['table'] ? ' selected="selected"' : '' ); ! $select_options .= '<option value="'.$i.'"'.$selected.'>'.$check_args[$i]['table'].'</option>'; ! } ! $select_options .= '</select>'; ! mx_message_die(GENERAL_MESSAGE, ! '<p>'.$main_desc.'</p>' . ! '<form action="' . append_sid(PORTAL_URL . "admin/admin_mx_chkobjs.$phpEx") . '" method="post"> ' . ! $select_options . ! ' <input type="submit" name="submit" value="' . $lang[Submit].'" class="mainoption" /></form>', ! $main_title ); ! } ! $mode = $HTTP_GET_VARS['mode']; ! $tb = $HTTP_GET_VARS['table']; ! $table = $check_args[$tb]['table']; ! $val0 = $HTTP_GET_VARS['val0']; ! $val1 = $HTTP_GET_VARS['val1']; ! $tab0 = $check_args[$tb]['fkeys'][0][0]; ! $key0 = $check_args[$tb]['fkeys'][0][1]; ! $tab1 = $check_args[$tb]['fkeys'][1][0]; ! $key1 = $check_args[$tb]['fkeys'][1][1]; ! switch($mode) ! { ! case 'delete': ! $sql = "DELETE FROM ".$table." WHERE $key0 = $val0 AND $key1 = $val1"; ! $get_vars = '&table='.$tb. ! '&val0='.$val0.'&val1='.$val1. ! '&key0='.$key0.'&key1='.$key1; ! $message = '<form method="post" action="' . basename(__FILE__) . '">' . ! '<table border="0" cellpadding="4" cellspacing="0">' . ! '<tr><td colspan="2"><b>' . $table . '</b></td></tr>' . ! '<tr><td><b>' . $key0 . ':</b> </td><td>[ ' . $val0 . ' ]</td></tr>' . ! '<tr><td><b>' . $key1 . ':</b> </td><td>[ ' . $val1 . ' ]</td></tr>' . ! '</table> <br /> <br />' . ! '<div style="width:80%; padding:10px; border:solid red 1px;">' . ! '<b>' . $lang['Confirm'] . '</b>:<br />' . $sql . '<br />' . ! '<br /> <br />' . ! '[ <a href="'.append_sid(basename(__FILE__)."?check_mode=$tb").'">'.$lang['No'].'</a> ]' . ! ' ' . ! '[ <a href="'.append_sid(basename(__FILE__).'?mode=db_delete'.$get_vars).'">'.$lang['Yes'].'</a> ]' . ! '</div><br /> ' . ! '</form>'; ! message_die(GENERAL_MESSAGE, $message, $my_script_title); ! break; ! case 'db_delete': ! $sql = "DELETE FROM ".$table." WHERE $key0 = $val0 AND $key1 = $val1"; ! if( !dbQuery($sql) ) ! { ! message_die(GENERAL_ERROR, "Couldn't DELETE data from table : " . $table, ! "", __LINE__, __FILE__, $sql); ! } ! $check_mode = $tb; ! break; ! default: ! break; ! } } ! include_once('./page_header_admin.php'); ! check_relationship($check_mode); ! include('./page_footer_admin.php'); exit; + + // ====================================================== ! // [ FUNCTIONS ] // ====================================================== ! // ------------ ! // ! // ! function check_relationship($tb) { ! global $db, $lang, $check_args, $main_title, $main_desc, $main_info; $table = $check_args[$tb]['table']; ! $fkeys = count($check_args[$tb]['fkeys']); ! for($i = 0; $i < $fkeys; $i++) { $ftab[] = $check_args[$tb]['fkeys'][$i][0]; $fkey[] = $check_args[$tb]['fkeys'][$i][1]; $fnam[] = $check_args[$tb]['fkeys'][$i][2]; ! } ! ! // // Build the query and check the table relations. ! // ! $sql = "SELECT * FROM ".$table." ORDER BY ".implode(',', $fkey); ! $result = $db->sql_query($sql); ! if( !$result ) { ! mx_message_die(GENERAL_ERROR, "Couldn't obtain the data from database.", '', __LINE__, __FILE__, $sql); } ! $html='<h1>' . $main_title.'</h1>' . "\n"; ! $html.='<p>' . $main_desc.'<br /><br />' . $main_info.'</p>' . "\n"; ! $html.='<table width="100%" cellpadding="2" cellspacing="1" border="0" class="forumline" align="center">' . "\n"; ! $html.="\t" . '<tr>' . "\n"; ! $html.=tbHead('td', 'catHead', 5, '<b>Checking Table: '.$table.'</b>'); ! $html.="\t" . '</tr>' . "\n"; ! $html.="\t" . '<tr>' . "\n"; ! $html.=tbHead('td', 'cat', 5, '<a href="'.append_sid(basename(__FILE__)."?table=$tb").'"><b>Go Back</b></a>'); ! $html.="\t" . '</tr>' . "\n"; ! $html.="\t" . '<tr>' . "\n"; ! $html.=tbHead('th', 'thCornerL', 1, $fkey[0]); ! for($i = 0; $i < ($fkeys-1); $i++) { ! $html.=tbHead('th', 'thTop', 1, $fnam[$i]); ! $html.=tbHead('th', 'thTop', 1, $fkey[$i+1]); } ! $html.=tbHead('th', 'thTop', 1, $fnam[$fkeys-1]); ! $html.=tbHead('th', 'thCornerR', 1, $lang['Action']); ! $html.="\t" . '</tr>' . "\n"; $row_count = 0; ! while( $row = $db->sql_fetchrow($result) ) { ! $row_class = (($row_count % 2) == 0) ? 'row1' : 'row2'; ! $html.= "\t" . '<tr>' . "\n"; ! $get_vars = '&table='.$tb; ! ! for($i = 0; $i < $fkeys; $i++) { $field = $fkey[$i]; ! if( $ftab[$i] == $table ) { $field_key = $row[$field]; *************** *** 183,241 **** else { ! if ( !( $field_value = dbFetchField( $ftab[$i], $field . '=' . $row[$field], $fnam[$i] ) ) ) { ! $field_key = '<font color=red><b>' . $row[$field] . '</b></font>'; $field_value = '<font color=red><b>[?]</b></font>'; } else { ! $field_key = $row[$field]; } } ! $html .= tbItem( 'td', 'row1', 'center', $field_key ); ! $html .= tbItem( 'td', 'row2', 'left' , $field_value ); } ! $html .= "\t" . '</tr>' . "\n"; $row_count++; } ! $html .= "\t" . '<tr>' . "\n"; ! $html .= tbHead( 'td', 'catBottom', 4, '<a href="javascript:history.go(-1);"><b>Go Back</b></a>' ); ! $html .= "\t" . '</tr>' . "\n"; ! $html .= '</table><br />' . "\n"; echo $html; } ! function tbHead( $td, $class, $colspan, $text ) { ! return "\t\t" . '<' . $td . ' class="' . $class . '" colspan="' . $colspan . '" align="center">' . $text . '</' . $td . '>' . "\n"; } ! function tbItem( $td, $class, $align, $text ) { ! return "\t\t" . '<' . $td . ' class="' . $class . '" align="' . $align . '">' . $text . '</' . $td . '>' . "\n"; ! // return '<'.$td.' class="'.$class.'" align="'.$align.'"><span class="gen">'.$text.'</span></'.$td.'>' . "\n"; } // ------------ // DB Utilities ! function dbFetchRow( $sql ) { global $db; ! if ( !( $result = $db->sql_query( $sql ) ) ) return false; ! if ( !( $row = $db->sql_fetchrow( $result ) ) ) return false; return $row; } ! function dbFetchField( $tbname, $where, $field ) { ! $sql = "SELECT * FROM " . $tbname . " WHERE " . $where; ! if ( !( $row = dbFetchRow( $sql ) ) ) return false; ! return $row[$field]; } --- 260,330 ---- else { ! if( !($field_value = dbFetchField($ftab[$i], $field.'='.$row[$field], $fnam[$i])) ) { ! $field_key = '<font color=red><b>'.$row[$field].'</b></font>'; $field_value = '<font color=red><b>[?]</b></font>'; } else { ! $field_key = $row[$field]; } } ! $get_vars .= '&val'.$i.'='.$row[$field]; ! $html.=tbItem('td', 'row1', 'center', $field_key); ! $html.=tbItem('td', 'row2', 'left' , $field_value); } ! $onclick = 'onclick="return confirm(\'Are you sure you want to delete this object?\');"'; ! $html.=tbItem('td', 'row1', 'center', '<a href="'.append_sid(basename(__FILE__).'?mode=delete'.$get_vars).'" '.$onclick.'>'.$lang['Delete'].'</a>'); ! $html.= "\t" . '</tr>' . "\n"; $row_count++; } ! $html.="\t" . '<tr>' . "\n"; ! $html.=tbHead('td', 'catBottom', 5, '<a href="'.append_sid(basename(__FILE__)."?table=$tb").'"><b>Go Back</b></a>'); ! $html.="\t" . '</tr>' . "\n"; ! $html.='</table><br />' . "\n"; echo $html; } ! function tbHead($td, $class, $colspan, $text) { ! return "\t\t" . '<'.$td.' class="'.$class.'" colspan="'.$colspan.'" align="center">'.$text.'</'.$td.'>' . "\n"; } ! function tbItem($td, $class, $align, $text) { ! return "\t\t" . '<'.$td.' class="'.$class.'" align="'.$align.'">'.$text.'</'.$td.'>' . "\n"; ! // return '<'.$td.' class="'.$class.'" align="'.$align.'"><span class="gen">'.$text.'</span></'.$td.'>' . "\n"; } + // ------------ // DB Utilities + // + function dbFetchField($tbname, $where, $field) + { + $sql = "SELECT * FROM ".$tbname." WHERE ".$where; + if( !($row = dbFetchRow($sql)) ) + return false; + return $row[$field]; + } ! function dbFetchRow($sql) { global $db; ! if( !($result = $db->sql_query($sql)) ) return false; ! if( !($row = $db->sql_fetchrow($result)) ) return false; return $row; } ! function dbQuery($sql) { ! global $db; ! if( !($result = $db->sql_query($sql)) ) return false; ! return $result; } |