$file) { $filename = e_PLUGIN.$path.'/'.$file.'.php'; if(is_readable($filename)) { $id = str_replace('_sql','',$file); $temp = file_get_contents($filename); $tables[$id] = preg_replace("#\/\*.*?\*\/#mis", '', $temp); // Strip comments as we copy unset($temp); } else { $emessage->add($filename.DBLAN_22, E_MESSAGE_WARNING); } } function read_tables($tab) { global $tablines, $table_list, $tables, $pref; $mes = e107::getMessage(); $file = explode("\n", $tables[$tab]); foreach($file as $line) { $line = ltrim(stripslashes($line)); if ($line) { $match = array(); if (preg_match('/CREATE TABLE (.*) /', $line, $match)) { if($match[1] != "user_extended") { $table_list[$match[1]] = 1; $current_table = $match[1]; $x = 0; $cnt = 0; } } if (strpos($line, "TYPE=") !== FALSE) { $current_table = ""; } if ($current_table && $x) { $tablines[$current_table][$cnt++] = $line; } $x = 1; } } // Get multi-language tables as well if($pref['multilanguage']) { $langs = table_list(); $mes->add(print_a($langs,TRUE), E_MESSAGE_DEBUG); foreach(array_keys($table_list) as $name) { if($langs[$name]) { $ltab = $langs[$name]; $table_list[$ltab] = 1; $tablines[$ltab] = $tablines[$name]; } } } $mes->add(print_a($table_list,TRUE), E_MESSAGE_DEBUG); } // Get list of fields and keys for a table function get_current($tab, $prefix = "") { if(! $prefix) { $prefix = MPREFIX; } mysql_query('SET SQL_QUOTE_SHOW_CREATE = 1'); $qry = 'SHOW CREATE TABLE `' . $prefix . $tab . "`"; $z = mysql_query($qry); if($z) { $row = mysql_fetch_row($z); return str_replace("`", "", stripslashes($row[1])); } else { return FALSE; } } function check_tables($what) { global $tablines, $table_list, $frm, $emessage; $cur = 0; $table_list = ""; read_tables($what); $fix_active = FALSE; // Flag set as soon as there's a fix - enables 'Fix it' button $text = "
"; return $text; } global $table_list; // -------------------- Table Fixing ------------------------------ if(isset($_POST['do_fix'])) { //$emessage->add(DBLAN_20); foreach( $_POST['fix_active'] as $key=>$val) { if (MAGIC_QUOTES_GPC == TRUE) { $table = stripslashes($_POST['fix_table'][$key][0]); $newval = stripslashes($_POST['fix_newval'][$key][0]); $mode = stripslashes($_POST['fix_mode'][$key][0]); $after = stripslashes($_POST['fix_after'][$key][0]); } else { $table = $_POST['fix_table'][$key][0]; $newval = $_POST['fix_newval'][$key][0]; $mode = $_POST['fix_mode'][$key][0]; $after = $_POST['fix_after'][$key][0]; } $field= $key; switch($mode) { case 'alter': $query = "ALTER TABLE `".MPREFIX.$table."` CHANGE `$field` `$field` $newval"; break; case 'insert': if($after) $after = " AFTER {$after}"; $query = "ALTER TABLE `".MPREFIX.$table."` ADD `$field` $newval{$after}"; break; case 'drop': $query = "ALTER TABLE `".MPREFIX.$table."` DROP `$field` "; break; case 'index': $query = "ALTER TABLE `".MPREFIX.$table."` ADD INDEX `$field` ($newval)"; break; case 'indexalt': $query = "ALTER TABLE `".MPREFIX.$table."` ADD $field ($newval)"; break; case 'indexdrop': $query = "ALTER TABLE `".MPREFIX.$table."` DROP INDEX `$field`"; break; case 'create': $query = "CREATE TABLE `".MPREFIX.$table."` ({$newval}"; if (!preg_match('#.*?\s+?(?:TYPE|ENGINE)\s*\=\s*(.*?);#is', $newval)) { $query .= ') TYPE=MyISAM;'; } break; } //FIXME - db handler!!! if(mysql_query($query)) $emessage->add(LAN_UPDATED.' [ '.$query.' ]', E_MESSAGE_SUCCESS); else { $emessage->add(LAN_UPDATED_FAILED.' [ '.$query.' ]', E_MESSAGE_WARNING); if(mysql_errno()) { $emessage->add(' SQL #'.mysql_errno().': '.mysql_error(), E_MESSAGE_WARNING); } } } } // ---------------------- Main Form and Submit. ------------------------ if (varset($_POST['db_verify']) || varset($_POST['do_fix'])) { $text = ''; foreach(array_keys($_POST) as $k) { $match = array(); if (preg_match("/table_(.*)/", $k, $match)) { $xx = $match[1]; $text .= check_tables($xx); } } if(!$text) $emessage->add(DBLAN_24, E_MESSAGE_WARNING); else { $e107->ns->tablerender(DBLAN_23.' - '.DBLAN_16, $emessage->render().$text); require_once(e_ADMIN."footer.php"); exit; } } $text = " "; $e107->ns->tablerender(DBLAN_23.' - '.DBLAN_16, $emessage->render().$text); require_once(e_ADMIN."footer.php"); exit; // -------------------------------------------------------------- function fix_form($table,$field, $newvalue,$mode,$after ='') { global $frm; if($mode == 'create') { $newvalue = implode("\n",$newvalue); $field = $table; // Value for $field may be rubbish! } else { if(stristr($field, 'KEY ') !== FALSE) { $field = chop(str_replace('KEY ','',$field)); $mode = ($mode == 'drop') ? 'indexdrop' : 'index'; $search = array('(', ')'); $newvalue = str_replace($search,'',$newvalue); $after = ''; } if($mode == 'index' && (stristr($field, 'FULLTEXT ') !== FALSE || stristr($field, 'UNIQUE ') !== FALSE)) { $mode = 'indexalt'; } elseif($mode == 'indexdrop' && (stristr($field, 'FULLTEXT ') !== FALSE || stristr($field, 'UNIQUE ') !== FALSE)) { $field = trim(str_replace(array('FULLTEXT ', 'UNIQUE '), '', $field)); } $field = trim($field, '`'); } $text .= $frm->checkbox("fix_active[$field][]", 1, false, array('id'=>false)); $text .= "\n"; $text .= "\n"; $text .= "\n"; $text .= ($after) ? "\n" : ""; return $text; } function table_list() { // grab default language lists. global $mySQLdefaultdb; $exclude[] = "banlist"; $exclude[] = "banner"; $exclude[] = "cache"; $exclude[] = "core"; $exclude[] = "online"; $exclude[] = "parser"; $exclude[] = "plugin"; $exclude[] = "user"; $exclude[] = "upload"; $exclude[] = "userclass_classes"; $exclude[] = "rbinary"; $exclude[] = "session"; $exclude[] = "tmp"; $exclude[] = "flood"; $exclude[] = "stat_info"; $exclude[] = "stat_last"; $exclude[] = "submit_news"; $exclude[] = "rate"; $exclude[] = "stat_counter";$exclude[] = "user_extended"; $exclude[] = "user_extended_struct"; $exclude[] = "pm_messages"; $exclude[] = "pm_blocks"; $replace = array(); $lanlist = explode(",",e_LANLIST); foreach($lanlist as $lang) { if($lang != $pref['sitelanguage']) { $replace[] = "lan_".strtolower($lang)."_"; } } $tables = mysql_list_tables($mySQLdefaultdb); while (list($temp) = mysql_fetch_array($tables)) { $prefix = MPREFIX."lan_"; $match = array(); if(strpos($temp,$prefix)!==FALSE) { $e107tab = str_replace(MPREFIX, "", $temp); $core = str_replace($replace,"",$e107tab); if (str_replace($exclude, "", $e107tab)) { $tabs[$core] = $e107tab; } } } return $tabs; } /** * Handle page DOM within the page header * * @return string JS source */ function headerjs() { require_once (e_HANDLER.'js_helper.php'); $ret = " "; return $ret; } ?>