PageRenderTime 56ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/e107_handlers/db_verify_class.php

https://github.com/CasperGemini/e107
PHP | 1534 lines | 669 code | 214 blank | 651 comment | 55 complexity | 43ba0db078baa1da0442ca9d37ce5385 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * e107 website system
  4. *
  5. * Copyright (C) 2008-2009 e107 Inc (e107.org)
  6. * Released under the terms and conditions of the
  7. * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
  8. *
  9. * Administration - DB Verify Class
  10. *
  11. * $URL: /cvs_backup/e107_0.8/e107_admin/db_verify.php,v $
  12. * $Revision: 12255 $
  13. * $Id: 2011-06-07 17:16:42 -0700 (Tue, 07 Jun 2011) $
  14. * $Author: e107coders $
  15. *
  16. */
  17. if (!defined('e107_INIT')) { exit; }
  18. include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_db_verify.php');
  19. class db_verify
  20. {
  21. var $backUrl = "";
  22. var $tables = array();
  23. var $sqlTables = array();
  24. var $sqlLanguageTables = array();
  25. var $results = array();
  26. var $indices = array(); // array(0) - Issue?
  27. var $fixList = array();
  28. var $fieldTypes = array('time','timestamp','datetime','year','tinyblob','blob',
  29. 'mediumblob','longblob','tinytext','mediumtext','longtext','text','date');
  30. var $fieldTypeNum = array('bit','tinyint','smallint','mediumint','integer','int','bigint',
  31. 'real','double','float','decimal','numeric','varchar','char ','binary','varbinary','enum','set'); // space after 'char' required.
  32. var $modes = array(
  33. 'missing_table' => 'create',
  34. 'mismatch' => 'alter',
  35. 'missing_field' => 'insert',
  36. 'missing_index' => 'index',
  37. 'mismatch_index' => '', // TODO
  38. );
  39. var $errors = array();
  40. /**
  41. * Setup
  42. */
  43. function __construct()
  44. {
  45. $ns = e107::getRender();
  46. $pref = e107::getPref();
  47. $mes = e107::getMessage();
  48. $frm = e107::getForm();
  49. $this->backUrl = e_SELF;
  50. $core_data = file_get_contents(e_CORE.'sql/core_sql.php');
  51. $this->tables['core'] = $this->getTables($core_data);
  52. $this->sqlLanguageTables = $this->getSqlLanguages();
  53. if(varset($pref['e_sql_list']))
  54. {
  55. foreach($pref['e_sql_list'] as $path => $file)
  56. {
  57. $filename = e_PLUGIN.$path.'/'.$file.'.php';
  58. if(is_readable($filename))
  59. {
  60. $id = str_replace('_sql','',$file);
  61. $data = file_get_contents($filename);
  62. $this->tables[$id] = $this->getTables($data);
  63. unset($data);
  64. }
  65. else
  66. {
  67. $message = str_replace("[x]",$filename,DBVLAN_22);
  68. $mes->add($message, E_MESSAGE_WARNING);
  69. }
  70. }
  71. }
  72. }
  73. /**
  74. * Main Routine for checking and rendering results.
  75. */
  76. function verify()
  77. {
  78. if(vartrue($_POST['verify_table']))
  79. {
  80. $this->runComparison($_POST['verify_table']);
  81. }
  82. else
  83. {
  84. if(isset($_POST['runfix']))
  85. {
  86. $this->runFix($_POST['fix']);
  87. }
  88. $this->renderTableSelect();
  89. }
  90. }
  91. function runComparison($fileArray)
  92. {
  93. $ns = e107::getRender();
  94. $mes = e107::getMessage();
  95. $frm = e107::getForm();
  96. foreach($fileArray as $tab)
  97. {
  98. $this->compare($tab);
  99. foreach($this->sqlLanguageTables as $lng=>$lantab)
  100. {
  101. $this->compare($tab,$lng);
  102. }
  103. }
  104. if($cnt = count($this->errors))
  105. {
  106. $message = str_replace("[x]",$cnt,DBVLAN_26); // Found [x] issues.
  107. $mes->add($message, E_MESSAGE_WARNING);
  108. $this->renderResults();
  109. }
  110. else
  111. {
  112. $mes->addSuccess("Tables appear to be okay!"); //TODO LAN
  113. $mes->addSuccess("<a class='btn btn-primary' href='".$this->backUrl."'>".LAN_BACK."</a>");
  114. //$debug = "<pre>".print_r($this->results,TRUE)."</pre>";
  115. //$mes->add($debug,E_MESSAGE_DEBUG);
  116. //$text .= "<div class='buttons-bar center'>".$frm->admin_button('back', DBVLAN_17, 'back')."</div>";
  117. $ns->tablerender("Okay",$mes->render().$text);
  118. }
  119. }
  120. // $this->sqlTables = $this->sqlTableList();
  121. // print_a($this->tables);
  122. // $this->renderTableSelect();
  123. // print_a($field);
  124. // print_a($match[2]);
  125. // echo "<pre>".$sql_data."</pre>";
  126. /**
  127. * Check core tables and installed plugin tables
  128. * @param $exclude - array of plugins to exclude.
  129. */
  130. function compareAll($exclude = null)
  131. {
  132. if(is_array($exclude))
  133. {
  134. foreach($exclude as $val)
  135. {
  136. unset($this->tables[$val]);
  137. }
  138. }
  139. $dtables = array_keys($this->tables);
  140. foreach($dtables as $tb)
  141. {
  142. $this->compare($tb);
  143. }
  144. foreach($this->sqlLanguageTables as $lng=>$lantab) // language tables.
  145. {
  146. foreach($dtables as $tb)
  147. {
  148. $this->compare($tb,$lng);
  149. }
  150. }
  151. }
  152. function compare($selection,$language='')
  153. {
  154. foreach($this->tables[$selection]['tables'] as $key=>$tbl)
  155. {
  156. //$this->errors[$tbl]['_status'] = 'ok'; // default table status
  157. $rawSqlData = $this->getSqlData($tbl,$language);
  158. if($rawSqlData === FALSE)
  159. {
  160. if($language) continue;
  161. $this->errors[$tbl]['_status'] = 'missing_table';
  162. $this->results[$tbl]['_file'] = $selection;
  163. // echo "missing table: $tbl";
  164. continue;
  165. }
  166. $sqlDataArr = $this->getTables($rawSqlData);
  167. $fileFieldData = $this->getFields($this->tables[$selection]['data'][$key]);
  168. $sqlFieldData = $this->getFields($sqlDataArr['data'][0]);
  169. $fileIndexData = $this->getIndex($this->tables[$selection]['data'][$key]);
  170. $sqlIndexData = $this->getIndex($sqlDataArr['data'][0]);
  171. /*
  172. $debugA = print_r($fileFieldData,TRUE); // Extracted Field Arrays
  173. $debugA .= "<h2>Index</h2>";
  174. $debugA .= print_r($fileIndexData,TRUE);
  175. $debugB = print_r($sqlFieldData,TRUE); // Extracted Field Arrays
  176. $debugB .= "<h2>Index</h2>";
  177. $debugB .= print_r($sqlIndexData,TRUE);
  178. */
  179. $debugA = $this->tables[$selection]['data'][$key]; // Extracted Raw Field Text
  180. // $debugB = $rawSqlData;
  181. $debugB = $sqlDataArr['data'][0]; // Extracted Raw Field Text
  182. if(isset($debugA) && (e_PAGE == 'db.php'))
  183. {
  184. $debug = "<table class='table' border='1'>
  185. <tr><td style='padding:5px;font-weight:bold'>FILE: ".$tbl." (key=".$key.")</td>
  186. <td style='padding:5px;font-weight:bold'>SQL: ".$tbl."</td>
  187. </tr>
  188. <tr><td style='width:50%'><pre>".$debugA."</pre></td>
  189. <td style='width:50%'><pre>".$debugB."</pre></td></tr></table>";
  190. $mes = e107::getMessage();
  191. $mes->add($debug,E_MESSAGE_DEBUG);
  192. }
  193. if($language)
  194. {
  195. $tbl = "lan_".$language."_".$tbl;
  196. }
  197. // Check Field Data.
  198. foreach($fileFieldData as $field => $info )
  199. {
  200. $this->results[$tbl][$field]['_status'] = 'ok';
  201. if(!is_array($sqlFieldData[$field]))
  202. {
  203. // echo "<h2>".$field."</h2><table><tr><td><pre>".print_r($info,TRUE)."</pre></td>
  204. // <td style='border:1px solid silver'><pre> - ".print_r($sqlFieldData[$field],TRUE)."</pre></td></tr></table>";
  205. $this->errors[$tbl]['_status'] = 'error'; // table status
  206. $this->results[$tbl][$field]['_status'] = 'missing_field'; // field status
  207. $this->results[$tbl][$field]['_valid'] = $info;
  208. $this->results[$tbl][$field]['_file'] = $selection;
  209. }
  210. elseif(count($off = array_diff_assoc($info,$sqlFieldData[$field])))
  211. {
  212. $this->errors[$tbl]['_status'] = 'mismatch';
  213. $this->results[$tbl][$field]['_status'] = 'mismatch';
  214. $this->results[$tbl][$field]['_diff'] = $off;
  215. $this->results[$tbl][$field]['_valid'] = $info;
  216. $this->results[$tbl][$field]['_invalid'] = $sqlFieldData[$field];
  217. $this->results[$tbl][$field]['_file'] = $selection;
  218. }
  219. }
  220. // print_a($fileIndexData);
  221. // print_a($sqlIndexData);
  222. // Check Index data
  223. foreach($fileIndexData as $field => $info )
  224. {
  225. if(!is_array($sqlIndexData[$field])) // missing index.
  226. {
  227. // print_a($info);
  228. // print_a($sqlIndexData[$field]);
  229. $this->errors[$tbl]['_status'] = 'error'; // table status
  230. $this->indices[$tbl][$field]['_status'] = 'missing_index'; // index status
  231. $this->indices[$tbl][$field]['_valid'] = $info;
  232. $this->indices[$tbl][$field]['_file'] = $selection;
  233. }
  234. elseif(count($offin = array_diff_assoc($info,$sqlIndexData[$field]))) // missmatch data
  235. {
  236. // print_a($info);
  237. // print_a($sqlIndexData[$field]);
  238. $this->errors[$tbl]['_status'] = 'mismatch_index';
  239. $this->indices[$tbl][$field]['_status'] = 'mismatch';
  240. $this->indices[$tbl][$field]['_diff'] = $offin;
  241. $this->indices[$tbl][$field]['_valid'] = $info;
  242. $this->indices[$tbl][$field]['_invalid'] = $sqlIndexData[$field];
  243. $this->indices[$tbl][$field]['_file'] = $selection;
  244. }
  245. // TODO Check for additional fields in SQL that should be removed.
  246. // TODO Add support for MYSQL 5 table layout .eg. journal_id INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  247. }
  248. unset($data);
  249. }
  250. }
  251. /**
  252. * Compile Results into a complete list of Fixes that could be run without the need of a form selection.
  253. */
  254. function compileResults()
  255. {
  256. foreach($this->results as $tabs => $field)
  257. {
  258. $file = varset($this->results[$tabs]['_file']);
  259. if(varset($this->errors[$tabs]['_status']) == 'missing_table') // Missing Table
  260. {
  261. $this->fixList[$file][$tabs]['all'][] = 'create';
  262. }
  263. elseif($this->errors[$tabs] != 'ok') // All Other Issues..
  264. {
  265. foreach($field as $k=>$f)
  266. {
  267. if($f['_status']=='ok') continue;
  268. $this->fixList[$f['_file']][$tabs][$k][] = $this->modes[$f['_status']];
  269. }
  270. }
  271. }
  272. // Index
  273. if(count($this->indices))
  274. {
  275. foreach($this->indices as $tabs => $field)
  276. {
  277. if($this->errors[$tabs] != 'ok')
  278. {
  279. foreach($field as $k=>$f)
  280. {
  281. if($f['_status']=='ok') continue;
  282. $this->fixList[$f['_file']][$tabs][$k][] = $this->modes[$f['_status']];
  283. }
  284. }
  285. }
  286. }
  287. }
  288. function renderResults()
  289. {
  290. $frm = e107::getForm();
  291. $ns = e107::getRender();
  292. $mes = e107::getMessage();
  293. $text = "
  294. <form method='post' action='".e_SELF."?".e_QUERY."'>
  295. <fieldset id='core-db-verify-{$selection}'>
  296. <legend id='core-db-verify-{$selection}-legend'>".DBVLAN_16."</legend>
  297. <table class='table adminlist'>
  298. <colgroup>
  299. <col style='width: 25%'></col>
  300. <col style='width: 25%'></col>
  301. <col style='width: 10%'></col>
  302. <col style='width: 30%'></col>
  303. <col style='width: 10%'></col>
  304. </colgroup>
  305. <thead>
  306. <tr>
  307. <th>".DBVLAN_4.": {$k}</th>
  308. <th>".DBVLAN_5."</th>
  309. <th class='center'>".DBVLAN_6."</th>
  310. <th>".DBVLAN_7."</th>
  311. <th class='center last'>".DBVLAN_19."</th>
  312. </tr>
  313. </thead>
  314. <tbody>
  315. ";
  316. $info = array(
  317. 'missing_table' => DBVLAN_13,
  318. 'mismatch' => DBVLAN_8,
  319. 'missing_field' => DBVLAN_11,
  320. 'ok' => ADMIN_TRUE_ICON,
  321. 'missing_index' => DBVLAN_25,
  322. );
  323. foreach($this->results as $tabs => $field)
  324. {
  325. if($this->errors[$tabs]['_status'] == 'missing_table') // Missing Table
  326. {
  327. $text .= "
  328. <tr>
  329. <td>".$this->renderTableName($tabs)."</td>
  330. <td>&nbsp;</td>
  331. <td class='center middle error'>".$info[$this->errors[$tabs]['_status']]."</td>
  332. <td>&nbsp;</td>
  333. <td class='center middle autocheck e-pointer'>".$this->fixForm($this->results[$tabs]['_file'],$tabs, 'all', '', 'create') . "</td>
  334. </tr>
  335. ";
  336. }
  337. elseif($this->errors[$tabs] != 'ok') // All Other Issues..
  338. {
  339. foreach($field as $k=>$f)
  340. {
  341. if($f['_status']=='ok') continue;
  342. $fstat = $info[$f['_status']];
  343. $text .= "
  344. <tr>
  345. <td>".$this->renderTableName($tabs)."</td>
  346. <td>".$k."&nbsp;</td>
  347. <td class='center middle error'>".$fstat."</td>
  348. <td>".$this->renderNotes($f)."&nbsp;</td>
  349. <td class='center middle autocheck e-pointer'>".$this->fixForm($f['_file'],$tabs, $k, $f['_valid'], $this->modes[$f['_status']]) . "</td>
  350. </tr>
  351. ";
  352. }
  353. }
  354. }
  355. // Indices
  356. if(count($this->indices))
  357. {
  358. foreach($this->indices as $tabs => $field)
  359. {
  360. if($this->errors[$tabs] != 'ok')
  361. {
  362. foreach($field as $k=>$f)
  363. {
  364. if($f['_status']=='ok') continue;
  365. $fstat = $info[$f['_status']];
  366. $text .= "
  367. <tr>
  368. <td>".$this->renderTableName($tabs)."</td>
  369. <td>".$k."&nbsp;</td>
  370. <td class='center middle error'>".$fstat."</td>
  371. <td>".$this->renderNotes($f,'index')."&nbsp;</td>
  372. <td class='center middle autocheck e-pointer'>".$this->fixForm($f['_file'],$tabs, $k, $f['_valid'], $this->modes[$f['_status']]) . "</td>
  373. </tr>
  374. ";
  375. }
  376. }
  377. }
  378. }
  379. $text .= "
  380. </tbody>
  381. </table>
  382. <br/>
  383. ";
  384. $text .= "
  385. <div class='buttons-bar right'>
  386. ".$frm->admin_button('runfix', DBVLAN_21, 'execute', '', array('id'=>false))."
  387. ".$frm->admin_button('check_all', 'jstarget:fix', 'action', LAN_CHECKALL, array('id'=>false))."
  388. ".$frm->admin_button('uncheck_all', 'jstarget:fix', 'action', LAN_UNCHECKALL, array('id'=>false))."
  389. </div>
  390. </fieldset>
  391. </form>
  392. ";
  393. $ns->tablerender(DBVLAN_23.' - '.DBVLAN_16, $mes->render().$text);
  394. }
  395. function renderTableName($tabs)
  396. {
  397. if(substr($tabs,0,4)=="lan_")
  398. {
  399. list($tmp,$lang,$table) = explode("_",$tabs,3);
  400. return $table. " (".ucfirst($lang).")";
  401. }
  402. return $tabs;
  403. }
  404. function fixForm($file,$table,$field, $newvalue,$mode,$after ='')
  405. {
  406. $frm = e107::getForm();
  407. $text .= $frm->checkbox("fix[$file][$table][$field][]", $mode, false, array('id'=>false));
  408. return $text;
  409. }
  410. function renderNotes($data,$mode='field')
  411. {
  412. // return "<pre>".print_r($data,TRUE)."</pre>";
  413. $v = $data['_valid'];
  414. $i = $data['_invalid'];
  415. $valid = $this->toMysql($v,$mode);
  416. $invalid = $this->toMysql($i,$mode);
  417. $text = "";
  418. if($invalid)
  419. {
  420. $text .= "<strong>".DBVLAN_9."</strong>
  421. <div class='indent'>".$invalid."</div>";
  422. }
  423. $text .= "<strong>".DBVLAN_10."</strong>
  424. <div class='indent'>".$valid."</div>";
  425. return $text;
  426. }
  427. function toMysql($data,$mode = 'field')
  428. {
  429. if(!$data) return;
  430. if($mode == 'index')
  431. {
  432. // print_a($data);
  433. if($data['type'])
  434. {
  435. return $data['type']." (".$data['field'].");";
  436. }
  437. else
  438. {
  439. return "INDEX `".$data['keyname']."` (".$data['field'].");";
  440. }
  441. }
  442. if(!in_array(strtolower($data['type']), $this->fieldTypes))
  443. {
  444. return $data['type']."(".$data['value'].") ".$data['attributes']." ".$data['null']." ".$data['default'];
  445. }
  446. else
  447. {
  448. return $data['type']." ".$data['attributes']." ".$data['null']." ".$data['default'];
  449. }
  450. }
  451. // returns the previous Field
  452. function getPrevious($array,$cur)
  453. {
  454. $fkeys = array_keys($array);
  455. foreach($fkeys as $fields)
  456. {
  457. if($fields == $cur)
  458. {
  459. $current = prev($fkeys); // required.
  460. $previous = prev($fkeys);
  461. return $previous;
  462. }
  463. }
  464. }
  465. /**
  466. * get the key ID for the current table which is being Fixed.
  467. */
  468. function getId($tabl,$cur)
  469. {
  470. $key = array_flip($tabl);
  471. if(substr($cur,0,4)=="lan_") // language table adjustment.
  472. {
  473. list($tmp,$lang,$cur) = explode("_",$cur,3);
  474. }
  475. if(isset($key[$cur]))
  476. {
  477. return $key[$cur];
  478. }
  479. }
  480. /**
  481. * Fix tables
  482. * FixArray eg. [core][table][field] = alter|create|index| etc.
  483. */
  484. function runFix($fixArray='')
  485. {
  486. $mes = e107::getMessage();
  487. $log = e107::getAdminLog();
  488. if(!is_array($fixArray))
  489. {
  490. $fixArray = $this->fixList; // Fix All
  491. }
  492. foreach($fixArray as $j=>$file)
  493. {
  494. foreach($file as $table=>$val)
  495. {
  496. $id = $this->getId($this->tables[$j]['tables'],$table);
  497. foreach($val as $field=>$fixes)
  498. {
  499. foreach($fixes as $mode)
  500. {
  501. if(substr($mode,0,5)== 'index')
  502. {
  503. $fdata = $this->getIndex($this->tables[$j]['data'][$id]);
  504. $newval = $this->toMysql($fdata[$field],'index');
  505. }
  506. else
  507. {
  508. $fdata = $this->getFields($this->tables[$j]['data'][$id]);
  509. $newval = $this->toMysql($fdata[$field]);
  510. }
  511. switch($mode)
  512. {
  513. case 'alter':
  514. $query = "ALTER TABLE `".MPREFIX.$table."` CHANGE `$field` `$field` $newval";
  515. break;
  516. case 'insert':
  517. $after = ($aft = $this->getPrevious($fdata,$field)) ? " AFTER {$aft}" : "";
  518. $query = "ALTER TABLE `".MPREFIX.$table."` ADD `$field` $newval{$after}";
  519. break;
  520. case 'drop':
  521. $query = "ALTER TABLE `".MPREFIX.$table."` DROP `$field` ";
  522. break;
  523. case 'index':
  524. $query = "ALTER TABLE `".MPREFIX.$table."` ADD $newval ";
  525. break;
  526. case 'indexdrop':
  527. $query = "ALTER TABLE `".MPREFIX.$table."` DROP INDEX `$field`";
  528. break;
  529. case 'create':
  530. $query = "CREATE TABLE `".MPREFIX.$table."` (".$this->tables[$j]['data'][$id].") ENGINE=MyISAM;";
  531. break;
  532. }
  533. // $mes->addDebug("Query: ".$query);
  534. // continue;
  535. if(mysql_query($query))
  536. {
  537. $log->addDebug(LAN_UPDATED.' ['.$query.']');
  538. }
  539. else
  540. {
  541. $log->addWarning(LAN_UPDATED_FAILED.' ['.$query.']');
  542. if(mysql_errno())
  543. {
  544. $log->addWarning('SQL #'.mysql_errno().': '.mysql_error());
  545. }
  546. }
  547. }
  548. }
  549. } //
  550. }
  551. $log->flushMessages();
  552. }
  553. function getTables($sql_data)
  554. {
  555. if(!$sql_data)
  556. {
  557. return;
  558. }
  559. $ret = array();
  560. $sql_data = preg_replace("#\/\*.*?\*\/#mis", '', $sql_data); // remove comments
  561. // $regex = "/CREATE TABLE `?([\w]*)`?\s*?\(([\s\w\+\-_\(\),'\. `]*)\)\s*(ENGINE|TYPE)\s*?=\s?([\w]*)[\w =]*;/i";
  562. $regex = "/CREATE TABLE (?:IF NOT EXISTS )?`?([\w]*)`?\s*?\(([\s\w\+\-_\(\),'\. `]*)\)\s*(ENGINE|TYPE)\s*?=\s?([\w]*)[\w =]*;/i";
  563. $table = preg_match_all($regex,$sql_data,$match);
  564. $tables = array();
  565. foreach($match[1] as $c=>$k)
  566. {
  567. if(substr($k,0, 5) == 'e107_') // remove prefix if found in sql dump.
  568. {
  569. $k = substr($k, 5);
  570. }
  571. $tables[$c] = $k;
  572. }
  573. $ret['tables'] = $tables;
  574. $ret['data'] = $match[2];
  575. return $ret;
  576. }
  577. function getFields($data, $print = false)
  578. {
  579. // Clean $data and add ` ` arond field-names - prevents issues when field == field-type.
  580. $tmp = explode("\n",$data);
  581. $newline = array();
  582. foreach($tmp as $line)
  583. {
  584. $line = trim($line);
  585. $newline[] = preg_replace("/^([^`A-Z\s][a-z_]*)/","`$1`", $line);
  586. }
  587. $data = implode("\n",$newline);
  588. // --------------------
  589. $mes = e107::getMessage();
  590. // $regex = "/`?([\w]*)`?\s*?(".implode("|",$this->fieldTypes)."|".implode("|",$this->fieldTypeNum).")\s?(?:\([\s]?([0-9,]*)[\s]?\))?[\s]?(unsigned)?[\s]?.*?(?:(NOT NULL|NULL))?[\s]*(auto_increment|default .*)?[\s]?(?:PRIMARY KEY)?[\s]*?,?\s*?\n/im";
  591. $regex = "/^\s*?`?([\w]*)`?\s*?(".implode("|",$this->fieldTypes)."|".implode("|",$this->fieldTypeNum).")\s?(?:\([\s]?([0-9,]*)[\s]?\))?[\s]?(unsigned)?[\s]?.*?(?:(NOT NULL|NULL))?[\s]*(auto_increment|default [\w'.-]*)?[\s]?(comment [\w\s'.-]*)?[\s]?(?:PRIMARY KEY)?[\s]*?,?\s*?\n/im";
  592. // echo $regex."<br /><br />";
  593. // $regex = "/`?([\w]*)`?\s*(int|varchar|tinyint|smallint|text|char|tinyint) ?(?:\([\s]?([0-9]*)[\s]?\))?[\s]?(unsigned)?[\s]?.*?(NOT NULL|NULL)?[\s]*(auto_increment|default .*)?[\s]?,/i";
  594. // $regex = "/^\s*?`?([\w]*)`?\s*?(".implode("|",$this->fieldTypes)."|".implode("|",$this->fieldTypeNum).")\s?(?:\([\s]?([0-9,]*)[\s]?\))?[\s]?(unsigned)?[\s]?.*?(?:(NOT NULL|NULL))?[\s]*?(auto_increment|default [\w'\".-]*)?[\s]?(?:PRIMARY KEY)?[\s]*?,?\n/im";
  595. //$regex = "/^\s*?`?([\w]*)`?\s*?(date|time|timestamp|datetime|year|tinyblob|blob|mediumblob|longblob|tinytext|mediumtext|longtext|text|bit|tinyint|smallint|mediumint|integer|int|bigint|real|double|float|decimal|numeric|varchar|char|binary|varbinary|enum|set)\s?(?:\([\s]?([0-9,]*)[\s]?\))?[\s]?(unsigned)?[\s]*?(?:(NOT NULL|NULL))?[\s]*?(auto_increment|default [\w'\".-]*)?[\s]?(?:PRIMARY KEY)?[\s]*?,?\n/im";
  596. // $mes->addDebug($regex);
  597. //$regex = "/^\s*?`?([\w]*)`?\s*?(date|time|timestamp|datetime|year|text|bit|tinyint|smallint|mediumint|integer|int|bigint|real|double|float|decimal|numeric|varchar|char|binary|varbinary|enum|set)\s?(?:\([\s]?([0-9,]*)[\s]?\))?[\s]?(unsigned)?[\s]*?(?:(NOT NULL|NULL))?[\s]*?(auto_increment|default [\w'.-]*)?[\s]?(?:PRIMARY KEY)?[\s]*?,?\n/i";
  598. // echo "reg=".$regex;
  599. preg_match_all($regex,$data,$m);
  600. $ret = array();
  601. if($print) var_dump($regex, $m);
  602. foreach($m[1] as $k=>$val)
  603. {
  604. $ret[$val] = array(
  605. 'type' => trim(strtoupper($m[2][$k])),
  606. 'value' => $m[3][$k],
  607. 'attributes' => strtoupper($m[4][$k]),
  608. 'null' => strtoupper($m[5][$k]),
  609. 'default' => strtoupper($m[6][$k])
  610. );
  611. }
  612. return $ret;
  613. }
  614. function getIndex($data, $print = false)
  615. {
  616. // $regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?`?([\w,]*[\s]?)`?\))?,?/i";
  617. $regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?([\w\s,`]*[\s]?)`?\))?,?/i";
  618. preg_match_all($regex,$data,$m);
  619. $ret = array();
  620. if($print) var_dump($regex, $m);
  621. // Standard Detection Method.
  622. foreach($m[3] as $k=>$val)
  623. {
  624. if(!$val) continue;
  625. $val = str_replace("`","",$val);
  626. $ret[$val] = array(
  627. 'type' => strtoupper($m[1][$k]),
  628. 'keyname' => (vartrue($m[2][$k])) ? str_replace("`","",$m[2][$k]) : str_replace("`","",$m[3][$k]),
  629. 'field' => str_replace("`","",$m[3][$k])
  630. );
  631. }
  632. //Alternate Index detection method.
  633. // eg. `table_id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  634. $regex = "/`?([\w]*)`? .*((?:AUTO_INCREMENT))\s?(PRIMARY|UNIQUE|FULLTEXT)\s?KEY\s?,/i";
  635. preg_match_all($regex,$data,$m);
  636. foreach($m[1] as $k=>$val)
  637. {
  638. if(!$val) continue;
  639. $ret[$val] = array(
  640. 'type' => strtoupper($m[3][$k]),
  641. 'keyname' => $m[1][$k],
  642. 'field' => str_replace("`","",$m[1][$k])
  643. );
  644. }
  645. return $ret;
  646. }
  647. function getSqlData($tbl,$language='')
  648. {
  649. $mes = e107::getMessage();
  650. $prefix = MPREFIX;
  651. if($language)
  652. {
  653. if(!in_array($tbl,$this->sqlLanguageTables[$language]))
  654. {
  655. return FALSE;
  656. }
  657. $prefix .= "lan_".$language."_";
  658. // $mes->addDebug("<h2>Retrieving Language Table Data: ".$prefix . $tbl."</h2>");
  659. }
  660. $sql = e107::getDb();
  661. $sql->gen('SET SQL_QUOTE_SHOW_CREATE = 1');
  662. // mysql_query('SET SQL_QUOTE_SHOW_CREATE = 1');
  663. $qry = 'SHOW CREATE TABLE `' . $prefix . $tbl . "`";
  664. // $z = mysql_query($qry);
  665. $z = $sql->gen($qry);
  666. if($z)
  667. {
  668. // $row = mysql_fetch_row($z);
  669. $row = $sql->fetch(MYSQL_NUM);
  670. //return $row[1];
  671. return stripslashes($row[1]).';'; // backticks needed.
  672. // return str_replace("`", "", stripslashes($row[1])).';';
  673. }
  674. else
  675. {
  676. $mes->addDebug('Failed: '.$qry);
  677. return FALSE;
  678. }
  679. }
  680. function getSqlLanguages()
  681. {
  682. $sql = e107::getDb();
  683. $list = $sql->db_TableList('lan');
  684. $array = array();
  685. foreach($list as $tb)
  686. {
  687. list($tmp,$lang,$table) = explode("_",$tb,3);
  688. $array[$lang][] = $table;
  689. }
  690. return $array;
  691. }
  692. function renderTableSelect()
  693. {
  694. $frm = e107::getForm();
  695. $ns = e107::getRender();
  696. $mes = e107::getMessage();
  697. $text = "
  698. <form method='post' action='".e_SELF.(e_QUERY ? '?'.e_QUERY : '')."' id='core-db-verify-sql-tables-form'>
  699. <fieldset id='core-db-verify-sql-tables'>
  700. <legend>".DBVLAN_14."</legend>
  701. <table class='table adminlist'>
  702. <colgroup>
  703. <col style='width: 100%'></col>
  704. </colgroup>
  705. <thead>
  706. <tr>
  707. <th class='last'>".$frm->checkbox_toggle('check-all-verify', 'verify_table',false,LAN_CHECKALL.' | '.LAN_UNCHECKALL)."</th>
  708. </tr>
  709. </thead>
  710. <tbody>
  711. ";
  712. foreach(array_keys($this->tables) as $x)
  713. {
  714. $text .= "
  715. <tr>
  716. <td>".$frm->checkbox('verify_table[]', $x,false,'label='.$x)."</td>
  717. </tr>
  718. ";
  719. }
  720. $text .= "
  721. </tbody>
  722. </table>
  723. <div class='buttons-bar center'>
  724. ".$frm->admin_button('db_verify', DBVLAN_15)."
  725. ".$frm->admin_button('db_tools_back', LAN_BACK, 'back')."
  726. </div>
  727. </fieldset>
  728. </form>
  729. ";
  730. $ns->tablerender(DBVLAN_23.' - '.DBVLAN_16, $mes->render().$text);
  731. }
  732. }
  733. /*
  734. function check_tables($what)
  735. {
  736. global $tablines, $table_list, $frm, $emessage;
  737. $cur = 0;
  738. $table_list = "";
  739. read_tables($what);
  740. $fix_active = FALSE; // Flag set as soon as there's a fix - enables 'Fix it' button
  741. $text = "
  742. <form method='post' action='".e_SELF."'>
  743. <fieldset id='core-db-verify-{$what}'>
  744. <legend id='core-db-verify-{$what}-legend'>".DBVLAN_16." - $what ".DBVLAN_18."</legend>
  745. ";
  746. foreach(array_keys($table_list) as $k)
  747. { // $k is the DB table name (less prefix)
  748. $ttcount = 0;
  749. $ttext = "
  750. <table class='table adminlist'>
  751. <colgroup >
  752. <col style='width: 25%'></col>
  753. <col style='width: 25%'></col>
  754. <col style='width: 10%'></col>
  755. <col style='width: 30%'></col>
  756. <col style='width: 10%'></col>
  757. </colgroup>
  758. <thead>
  759. <tr>
  760. <th>".DBVLAN_4.": {$k}</th>
  761. <th>".DBVLAN_5."</th>
  762. <th class='center'>".DBVLAN_6."</th>
  763. <th>".DBVLAN_7."</th>
  764. <th class='center last'>".DBVLAN_19."</th>
  765. </tr>
  766. </thead>
  767. <tbody>
  768. ";
  769. $prefix = MPREFIX;
  770. $current_tab = get_current($k, $prefix); // Get list of fields and keys from actual table
  771. unset($fields);
  772. unset($xfields);
  773. $xfield_errors = 0;
  774. if ($current_tab)
  775. {
  776. $lines = explode("\n", $current_tab); // Actual table - create one element of $lines per field or other line of info
  777. $fieldnum = 0;
  778. foreach($tablines[$k] as $x)
  779. { // $x is a line of the DB definition from the *_sql.php file
  780. $x = str_replace(' ',' ',$x); // Remove double spaces
  781. $fieldnum++;
  782. $ffound = 0;
  783. list($fname, $fparams) = explode(' ', $x, 2); // Pull out first word of definition
  784. if ($fname == 'UNIQUE' || $fname == 'FULLTEXT')
  785. {
  786. list($key, $key1, $keyname, $keyparms) = explode(' ', $x, 4);
  787. $fname = $key." ".$key1." ".$keyname;
  788. $fparams = $keyparms;
  789. }
  790. elseif ($fname == 'KEY')
  791. {
  792. list($key, $keyname, $keyparms) = explode(' ', $x, 3);
  793. $fname = $key." ".$keyname;
  794. $fparams = $keyparms;
  795. }
  796. elseif ($fname == 'PRIMARY')
  797. { // Nothing to do ATM
  798. }
  799. else
  800. { // Must be a field name
  801. $fname = str_replace('`','',$fname); // Just remove back ticks if present
  802. }
  803. $fields[$fname] = 1;
  804. $fparams = ltrim(rtrim($fparams));
  805. $fparams = preg_replace("/\r?\n$|\r[^\n]$|,$/", '', $fparams);
  806. if(stristr($k, "lan_") !== FALSE && $cur != 1)
  807. {
  808. $cur = 1;
  809. }
  810. $head_txt = "
  811. <tr>
  812. <td>{$k}</td>
  813. <td>{$fname}
  814. ";
  815. if (strpos($fparams, 'KEY') !== FALSE)
  816. {
  817. $head_txt .= " {$fparams} aa";
  818. }
  819. $head_txt .= "</td>
  820. ";
  821. $xfieldnum = -1;
  822. $body_txt = '';
  823. foreach($lines as $l)
  824. {
  825. $xfieldnum++;
  826. list($xl, $tmp) = explode("\n", $l, 2); // $tmp should be null
  827. $xl = ltrim(rtrim(stripslashes($xl)));
  828. $xl = preg_replace('/\r?\n$|\r[^\n]$/', '', $xl);
  829. $xl = str_replace(' ',' ',$xl); // Remove double spaces
  830. list($xfname, $xfparams) = explode(" ", $xl, 2); // Field name and the rest
  831. if ($xfname == 'UNIQUE' || $xfname == 'FULLTEXT')
  832. {
  833. list($key, $key1, $keyname, $keyparms) = explode(" ", $xl, 4);
  834. $xfname = $key." ".$key1." ".$keyname;
  835. $xfparams = $keyparms;
  836. }
  837. elseif ($xfname == "KEY")
  838. {
  839. list($key, $keyname, $keyparms) = explode(" ", $xl, 3);
  840. $xfname = $key." ".$keyname;
  841. $xfparams = $keyparms;
  842. }
  843. if ($xfname != "CREATE" && $xfname != ")")
  844. {
  845. $xfields[$xfname] = 1;
  846. }
  847. $xfparams = preg_replace('/,$/', '', $xfparams);
  848. $fparams = preg_replace('/,$/', '', $fparams);
  849. if ($xfname == $fname)
  850. { // Field names match - or it could be the word 'KEY' and its name which matches
  851. $ffound = 1;
  852. //echo "Field: ".$xfname." Actuals: ".$xfparams." Expected: ".$fparams."<br />";
  853. $xfsplit = explode(' ',$xfparams);
  854. $fsplit = explode(' ',$fparams);
  855. $skip = FALSE;
  856. $i = 0;
  857. $fld_err = FALSE;
  858. foreach ($xfsplit as $xf)
  859. {
  860. if ($skip)
  861. {
  862. $skip = FALSE;
  863. // echo " Unskip: ".$xf."<br />";
  864. }
  865. elseif (strcasecmp(trim($xf),'collate') == 0)
  866. { // Strip out the collation definition
  867. $skip = TRUE;
  868. // cho "Skip = ".$xf;
  869. }
  870. else
  871. {
  872. // echo "Compare: ".$xf." - ".$fsplit[$i]."<br />";
  873. // Since VARCHAR and CHAR are interchangeable, convert to CHAR (strictly, VARCHAR(3) and smalller becomes CHAR() )
  874. if (stripos($xf,'VARCHAR') === 0) $xf = substr($xf,3);
  875. if (stripos($fsplit[$i],'VARCHAR') === 0) $fsplit[$i] = substr($fsplit[$i],3);
  876. if (strcasecmp(trim($xf),trim($fsplit[$i])) != 0)
  877. {
  878. $fld_err = TRUE;
  879. //echo "Mismatch: ".$xf." - ".$fsplit[$i]."<br />";
  880. }
  881. $i++;
  882. }
  883. }
  884. if ($fld_err)
  885. {
  886. $body_txt .= "
  887. <td class='center middle error'>".DBVLAN_8."</td>
  888. <td>
  889. <strong>".DBVLAN_9."</strong>
  890. <div class='indent'>{$xfparams}</div>
  891. <strong>".DBVLAN_10."</strong>
  892. <div class='indent'>{$fparams}</div>
  893. </td>
  894. <td class='center middle autocheck e-pointer'>".fix_form($k, $fname, $fparams, "alter")."</td>
  895. ";
  896. $fix_active = TRUE;
  897. $xfield_errors++;
  898. }
  899. /* FIXME - can't stay if there is no way of fixing the field numbers (e.g. AFTER query)
  900. elseif ($fieldnum != $xfieldnum)
  901. { // Field numbers different - missing field?
  902. $body_txt .= "
  903. <td class='center middle error'>".DBVLAN_5." ".DBVLAN_8."</td>
  904. <td>
  905. <strong>".DBVLAN_9.": </strong>#{$xfieldnum}
  906. <br />
  907. <strong>".DBVLAN_10.": </strong>#{$fieldnum}
  908. </td>
  909. <td class='center middle'>&nbsp;</td>
  910. ";
  911. }
  912. // DISABLED for now (show only errors), could be page setting
  913. // else
  914. // {
  915. // $body_txt .= "
  916. // <td class='center'>OK</td>
  917. // <td>&nbsp;</td>
  918. // <td class='center middle'>&nbsp;</td>
  919. // ";
  920. // }
  921. //
  922. }
  923. } // Finished checking one field
  924. if ($ffound == 0)
  925. {
  926. $prev_fname = $fname; //FIXME - wrong $prev_fname!
  927. $body_txt .= "
  928. <td class='center middle error'>".DBVLAN_11."</td>
  929. <td>
  930. <strong>".DBVLAN_10."</strong>
  931. <div class='indent'>{$fparams}</div>
  932. </td>
  933. <td class='center middle autocheck e-pointer'>".fix_form($k, $fname, $fparams, "insert", $prev_fname)."</td>
  934. ";
  935. $fix_active = TRUE;
  936. $xfield_errors++;
  937. }
  938. if($xfield_errors && $body_txt)
  939. {
  940. $ttext .= $head_txt.$body_txt."
  941. </tr>
  942. ";
  943. }
  944. }
  945. foreach(array_keys($xfields) as $tf)
  946. {
  947. if (!$fields[$tf] && $k != "user_extended")
  948. {
  949. $fix_active = TRUE;
  950. $xfield_errors++;
  951. $ttext .= "
  952. <tr>
  953. <td>$k</td>
  954. <td>$tf</td>
  955. <td class='center middle'>".DBVLAN_12."</td>
  956. <td>&nbsp;</td>
  957. <td class='center middle autocheck e-pointer'>".fix_form($k, $tf, $fparams, "drop")."</td>
  958. </tr>
  959. ";
  960. }
  961. }
  962. }
  963. else
  964. { // Table Missing.
  965. $ttext .= "
  966. <tr>
  967. <td>{$k}</td>
  968. <td>&nbsp;</td>
  969. <td class='center middle error'>".DBVLAN_13."</td>
  970. <td>&nbsp;</td>
  971. <td class='center middle autocheck e-pointer'>".fix_form($k, $tf, $tablines[$k], "create") . "</td>
  972. </tr>
  973. ";
  974. $fix_active = TRUE;
  975. $xfield_errors++;
  976. }
  977. if(!$xfield_errors)
  978. {
  979. //no errors, so no table rows yet
  980. $ttext .= "
  981. <tr>
  982. <td colspan='5' class='center'>Table status OK</td>
  983. </tr>
  984. ";
  985. }
  986. $ttext .= "
  987. </tbody>
  988. </table>
  989. <br/>
  990. ";
  991. //FIXME - add 'show_if_ok' switch
  992. if($xfield_errors || (!$xfield_errors && varsettrue($_GET['show_if_ok'])))
  993. {
  994. $text .= $ttext;
  995. $ttcount++;
  996. }
  997. }
  998. if(!$fix_active)
  999. {
  1000. //Everything should be OK
  1001. $emessage->add('DB successfully verified - no problems were found.', E_MESSAGE_SUCCESS);
  1002. if(!$ttcount)
  1003. {
  1004. //very tired and sick of this page, so quick and dirty
  1005. $text .= "
  1006. <script type='text/javascript'>
  1007. \$('core-db-verify-{$what}-legend').hide();
  1008. </script>
  1009. ";
  1010. }
  1011. }
  1012. if($fix_active)
  1013. {
  1014. $text .= "
  1015. <div class='buttons-bar right'>
  1016. ".$frm->admin_button('do_fix', DBVLAN_21, 'execute', '', array('id'=>false))."
  1017. ".$frm->admin_button('check_all', 'jstarget:fix_active', 'action', LAN_CHECKALL, array('id'=>false))."
  1018. ".$frm->admin_button('uncheck_all', 'jstarget:fix_active', 'action', LAN_UNCHECKALL, array('id'=>false))."
  1019. </div>
  1020. ";
  1021. }
  1022. foreach(array_keys($_POST) as $j)
  1023. {
  1024. $match = array();
  1025. if (preg_match('/table_(.*)/', $j, $match))
  1026. {
  1027. $lx = $match[1];
  1028. $text .= "<div><input type='hidden' name='table_{$lx}' value='1' /></div>\n";
  1029. }
  1030. }
  1031. $text .= "
  1032. </fieldset>
  1033. <div class='buttons-bar center'>
  1034. ".$frm->admin_button('back', DBVLAN_17, 'back')."
  1035. </div>
  1036. </form>
  1037. ";
  1038. return $text;
  1039. }
  1040. global $table_list;
  1041. // -------------------- Table Fixing ------------------------------
  1042. if(isset($_POST['do_fix']))
  1043. {
  1044. //$emessage->add(DBVLAN_20);
  1045. foreach( $_POST['fix_active'] as $key=>$val)
  1046. {
  1047. if (MAGIC_QUOTES_GPC == TRUE)
  1048. {
  1049. $table = stripslashes($_POST['fix_table'][$key][0]);
  1050. $newval = stripslashes($_POST['fix_newval'][$key][0]);
  1051. $mode = stripslashes($_POST['fix_mode'][$key][0]);
  1052. $after = stripslashes($_POST['fix_after'][$key][0]);
  1053. }
  1054. else
  1055. {
  1056. $table = $_POST['fix_table'][$key][0];
  1057. $newval = $_POST['fix_newval'][$key][0];
  1058. $mode = $_POST['fix_mode'][$key][0];
  1059. $after = $_POST['fix_after'][$key][0];
  1060. }
  1061. $field= $key;
  1062. switch($mode)
  1063. {
  1064. case 'alter':
  1065. $query = "ALTER TABLE `".MPREFIX.$table."` CHANGE `$field` `$field` $newval";
  1066. break;
  1067. case 'insert':
  1068. if($after) $after = " AFTER {$after}";
  1069. $query = "ALTER TABLE `".MPREFIX.$table."` ADD `$field` $newval{$after}";
  1070. break;
  1071. case 'drop':
  1072. $query = "ALTER TABLE `".MPREFIX.$table."` DROP `$field` ";
  1073. break;
  1074. case 'index':
  1075. $query = "ALTER TABLE `".MPREFIX.$table."` ADD INDEX `$field` ($newval)";
  1076. break;
  1077. case 'indexalt':
  1078. $query = "ALTER TABLE `".MPREFIX.$table."` ADD $field ($newval)";
  1079. break;
  1080. case 'indexdrop':
  1081. $query = "ALTER TABLE `".MPREFIX.$table."` DROP INDEX `$field`";
  1082. break;
  1083. case 'create':
  1084. $query = "CREATE TABLE `".MPREFIX.$table."` ({$newval}";
  1085. if (!preg_match('#.*?\s+?(?:TYPE|ENGINE)\s*\=\s*(.*?);#is', $newval))
  1086. {
  1087. $query .= ') TYPE=MyISAM;';
  1088. }
  1089. break;
  1090. }
  1091. return $query;
  1092. //FIXME - db handler!!!
  1093. if(mysql_query($query)) $emessage->add(LAN_UPDATED.' [&nbsp;'.$query.'&nbsp;]', E_MESSAGE_SUCCESS);
  1094. else
  1095. {
  1096. $emessage->add(LAN_UPDATED_FAILED.' [&nbsp;'.$query.'&nbsp;]', E_MESSAGE_WARNING);
  1097. if(mysql_errno())
  1098. {
  1099. $emessage->add('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SQL #'.mysql_errno().': '.mysql_error(), E_MESSAGE_WARNING);
  1100. }
  1101. }
  1102. }
  1103. }
  1104. $text = "
  1105. <form method='post' action='".e_SELF.(e_QUERY ? '?'.e_QUERY : '')."' id='core-db-verify-sql-tables-form'>
  1106. <fieldset id='core-db-verify-sql-tables'>
  1107. <legend>".DBVLAN_14."</legend>
  1108. <table class='table adminlist'>
  1109. <colgroup>
  1110. <col style='width: 100%'></col>
  1111. </colgroup>
  1112. <thead>
  1113. <tr>
  1114. <th class='last'>".$frm->checkbox_toggle('check-all-verify', 'table_').LAN_CHECKALL.' | '.LAN_UNCHECKALL."</th>
  1115. </tr>
  1116. </thead>
  1117. <tbody>
  1118. ";
  1119. foreach(array_keys($tables) as $x) {
  1120. $text .= "
  1121. <tr>
  1122. <td>
  1123. ".$frm->checkbox('table_'.$x, $x).$frm->label($x, 'table_'.$x, $x)."
  1124. </td>
  1125. </tr>
  1126. ";
  1127. }
  1128. $text .= "
  1129. </tbody>
  1130. </table>
  1131. <div class='buttons-bar center'>
  1132. ".$frm->admin_button('db_verify', DBVLAN_15)."
  1133. ".$frm->admin_button('db_tools_back', DBVLAN_17, 'back')."
  1134. </div>
  1135. </fieldset>
  1136. </form>
  1137. ";
  1138. $e107->ns->tablerender(DBVLAN_23.' - '.DBVLAN_16, $emessage->render().$text);
  1139. require_once(e_ADMIN."footer.php");
  1140. exit;
  1141. // --------------------------------------------------------------
  1142. function fix_form($table,$field, $newvalue,$mode,$after ='')
  1143. {
  1144. global $frm;
  1145. if($mode == 'create')
  1146. {
  1147. $newvalue = implode("\n",$newvalue);
  1148. $field = $table; // Value for $field may be rubbish!
  1149. }
  1150. else
  1151. {
  1152. if(stristr($field, 'KEY ') !== FALSE)
  1153. {
  1154. $field = chop(str_replace('KEY ','',$field));
  1155. $mode = ($mode == 'drop') ? 'indexdrop' : 'index';
  1156. $search = array('(', ')');
  1157. $newvalue = str_replace($search,'',$newvalue);
  1158. $after = '';
  1159. }
  1160. if($mode == 'index' && (stristr($field, 'FULLTEXT ') !== FALSE || stristr($field, 'UNIQUE ') !== FALSE))
  1161. {
  1162. $mode = 'indexalt';
  1163. }
  1164. elseif($mode == 'indexdrop' && (stristr($field, 'FULLTEXT ') !== FALSE || stristr($field, 'UNIQUE ') !== FALSE))
  1165. {
  1166. $field = trim(str_replace(array('FULLTEXT ', 'UNIQUE '), '', $field));
  1167. }
  1168. $field = trim($field, '`');
  1169. }
  1170. $text .= "\n\n";
  1171. $text .= $frm->checkbox("fix_active[$field][]", 1, false, array('id'=>false));
  1172. $text .= "<input type='hidden' name=\"fix_newval[$field][]\" value=\"$newvalue\" />\n";
  1173. $text .= "<input type='hidden' name=\"fix_table[$field][]\" value=\"$table\" />\n";
  1174. $text .= "<input type='hidden' name=\"fix_mode[$field][]\" value=\"$mode\" />\n";
  1175. $text .= ($after) ? "<input type='hidden' name=\"fix_after[$field][]\" value=\"$after\" />\n" : "";
  1176. $text .= "\n\n";
  1177. return $text;
  1178. }
  1179. function table_list()
  1180. {
  1181. // grab default language lists.
  1182. global $mySQLdefaultdb;
  1183. $exclude[] = "banlist"; $exclude[] = "banner";
  1184. $exclude[] = "cache"; $exclude[] = "core";
  1185. $exclude[] = "online"; $exclude[] = "parser";
  1186. $exclude[] = "plugin"; $exclude[] = "user";
  1187. $exclude[] = "upload"; $exclude[] = "userclass_classes";
  1188. $exclude[] = "rbinary"; $exclude[] = "session";
  1189. $exclude[] = "tmp"; $exclude[] = "flood";
  1190. $exclude[] = "stat_info"; $exclude[] = "stat_last";
  1191. $exclude[] = "submit_news"; $exclude[] = "rate";
  1192. $exclude[] = "stat_counter";$exclude[] = "user_extended";
  1193. $exclude[] = "user_extended_struct";
  1194. $exclude[] = "pm_messages";
  1195. $exclude[] = "pm_blocks";
  1196. $replace = array();
  1197. $lanlist = explode(",",e_LANLIST);
  1198. foreach($lanlist as $lang)
  1199. {
  1200. if($lang != $pref['sitelanguage'])
  1201. {
  1202. $replace[] = "lan_".strtolower($lang)."_";
  1203. }
  1204. }
  1205. $tables = mysql_list_tables($mySQLdefaultdb);
  1206. while (list($temp) = mysql_fetch_array($tables))
  1207. {
  1208. $prefix = MPREFIX."lan_";
  1209. $match = array();
  1210. if(strpos($temp,$prefix)!==FALSE)
  1211. {
  1212. $e107tab = str_replace(MPREFIX, "", $temp);
  1213. $core = str_replace($replace,"",$e107tab);
  1214. if (str_replace($exclude, "", $e107tab))
  1215. {
  1216. $tabs[$core] = $e107tab;
  1217. }
  1218. }
  1219. }
  1220. return $tabs;
  1221. }
  1222. */
  1223. ?>