add(DBLAN_53, E_MESSAGE_WARNING);
}
else
{
$_POST[$_POST['db_execute']] = true;
}
}
if(isset($_POST['db_update']) || varset($_GET['mode'])=='db_update')
{
header("location: ".e_ADMIN."e107_update.php");
exit();
}
if(isset($_POST['verify_sql']) || varset($_GET['mode'])=='verify_sql')
{
header("location: ".e_ADMIN."db_verify.php");
exit();
}
if(isset($_POST['exportXmlFile']))
{
if(exportXmlFile($_POST['xml_prefs'],$_POST['xml_tables'],$_POST['package_images']))
{
$emessage = eMessage::getInstance();
$emessage->add(LAN_SUCCESS, E_MESSAGE_SUCCESS);
}
}
require_once ("auth.php");
require_once (e_HANDLER."form_handler.php");
$frm = new e_form();
$st = new system_tools;
/* No longer needed after XML feature added.
if(isset($_POST['backup_core']) || $_GET['mode']=='backup_core')
{
backup_core();
//message_handler("MESSAGE", DBLAN_1);
$emessage->add(DBLAN_1, E_MESSAGE_SUCCESS);
}
*/
require_once ("footer.php");
class system_tools
{
public $_options = array();
function __construct()
{
global $mySQLdefaultdb;
$this->_options = array(
"db_update" => array('diz'=>DBLAN_15, 'label'=>DBLAN_16),
"verify_sql" => array('diz'=>DBLAN_4, 'label'=>DBLAN_5),
'optimize_sql' => array('diz'=>DBLAN_6, 'label'=> DBLAN_7),
'plugin_scan' => array('diz'=>DBLAN_28, 'label'=> DBLAN_29),
'pref_editor' => array('diz'=>DBLAN_19, 'label'=> DBLAN_20),
// 'backup_core' => array('diz'=>DBLAN_8, 'label'=> DBLAN_9),
'verify_sql_record' => array('diz'=>DBLAN_35, 'label'=> DBLAN_36),
'importForm' => array('diz'=>DBLAN_59, 'label'=> DBLAN_59),
'exportForm' => array('diz'=>DBLAN_58, 'label'=> DBLAN_58),
'sc_override_scan' => array('diz'=>DBLAN_55, 'label'=> DBLAN_56),
'convert_to_utf8' => array('diz'=>'Convert Database to UTF-8','label'=>'Convert DB to UTF-8')
);
//TODO Merge db_verify.php into db.php
if(isset($_POST['delplug']))
{
$this->delete_plugin_entry($_POST['pref_type']);
}
if(isset($_POST['upload']))
{
$this->importXmlFile();
}
if(isset($_POST['delpref']) || (isset($_POST['delpref_checked']) && isset($_POST['delpref2'])))
{
$this->del_pref_val($_POST['pref_type']);
}
if(isset($_POST['verify_sql_record']) || varset($_GET['mode'])=='verify_sql_record' || isset($_POST['check_verify_sql_record']) || isset($_POST['delete_verify_sql_record']))
{
// $this->verify_sql_record(); - currently performed in db_verify.php
}
if(isset($_POST['importForm']) || $_GET['mode']=='importForm')
{
$this->importForm();
}
if(isset($_POST['convert_to_utf8']) || $_GET['mode']=='convert_to_utf8')
{
$this->convertUTF8Form();
}
if(isset($_POST['exportForm']) || $_GET['mode']=='exportForm')
{
$this->exportXmlForm();
}
if(isset($_POST['optimize_sql']) || $_GET['mode']=='optimize_sql')
{
$this->optimizesql($mySQLdefaultdb);
}
if(isset($_POST['pref_editor']) || $_GET['mode']=='pref_editor' || isset($_POST['delpref']) || isset($_POST['delpref_checked']))
{
$type = isset($_GET['type']) ? $_GET['type'] : "core";
$this->pref_editor($type);
}
if(isset($_POST['sc_override_scan']) || $_GET['mode']=='sc_override_scan')
{
$this->scan_override();
}
if(isset($_POST['plugin_scan']) || e_QUERY == "plugin" || isset($_POST['delplug']) || $_GET['mode']=='plugin_scan')
{
$this->plugin_viewscan();
}
if(vartrue($_POST['perform_utf8_convert']))
{
$this->perform_utf8_convert();
}
if(!vartrue($_GET['mode']))
{
$this->render_options();
}
}
private function convertUTF8Form()
{
$mes = e107::getMessage();
$frm = e107::getForm();
//TODO a function to call the e107_config information in e107_class.php.
require_once(e_BASE."e107_config.php");
$dbtable = $mySQLdefaultdb;
//TODO LAN
$message = "
This function will permanantly modify all tables in your database. (".$mySQLdefaultdb.")
It is HIGHLY recommended that you backup your database first.
Be sure to click the 'Convert Database' button only once.
The conversion process can take as up to one 1 minute or more depending on the size of your database.
";
$mes->add($message, E_MESSAGE_WARNING);
$text = "
";
e107::getRender()->tablerender("Convert", $mes->render().$text);
}
private function perform_utf8_convert()
{
require_once(e_BASE."e107_config.php");
$dbtable = $mySQLdefaultdb;
//TODO Add a check to be sure the database is not already utf-8.
$sql = e107::getDb();
$mes = e107::getMessage();
$ERROR = FALSE;
if(!mysql_query("USE information_schema;"))
{
$mes->add("Couldn't read information_schema", E_MESSAGE_ERROR);
return;
}
$queries = array();
$queries[] = $this->getQueries("SELECT CONCAT('ALTER TABLE ', table_name, ' MODIFY ', column_name, ' ', REPLACE(column_type, 'char', 'binary'), ';') FROM columns WHERE table_schema = '".$dbtable."' and data_type LIKE '%char%';");
$queries[] = $this->getQueries("SELECT CONCAT('ALTER TABLE ', table_name, ' MODIFY ', column_name, ' ', REPLACE(column_type, 'text', 'blob'), ';') FROM columns WHERE table_schema = '".$dbtable."' and data_type LIKE '%text%';");
$queries2 = array();
$queries2[] = $this->getQueries("SELECT CONCAT('ALTER TABLE ', table_name, ' MODIFY ', column_name, ' ', column_type, ' CHARACTER SET utf8;') FROM columns WHERE table_schema = '".$dbtable."' and data_type LIKE '%char%';");
$queries2[] = $this->getQueries("SELECT CONCAT('ALTER TABLE ', table_name, ' MODIFY ', column_name, ' ', column_type, ' CHARACTER SET utf8;') FROM columns WHERE table_schema = '".$dbtable."' and data_type LIKE '%text%';");
mysql_query("USE ".$dbtable);
foreach($queries as $qry)
{
foreach($qry as $q)
{
if(!$sql->db_Query($q))
{
$mes->add($q, E_MESSAGE_ERROR);
$ERROR = TRUE;
}
}
}
//------------
$result = mysql_list_tables($dbtable);
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
$table = $row[0];
$tab_query = "ALTER TABLE ".$table." charset=utf8; ";
if(!$sql->db_Query($tab_query))
{
$mes->add($tab_query, E_MESSAGE_ERROR);
$ERROR = TRUE;
}
}
// ---------------
foreach($queries2 as $qry)
{
foreach($qry as $q)
{
if(!$sql->db_Query($q))
{
$mes->add($q, E_MESSAGE_ERROR);
$ERROR = TRUE;
}
}
}
//------------
$lastQry = "ALTER DATABASE `".$dbtable."` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;";
if(!$sql->db_Query($lastQry))
{
$mes->add($lastQry, E_MESSAGE_ERROR);
}
elseif($ERROR != TRUE)
{
$message = "Database Converted successfully to UTF-8.
Please now add the following line to your e107_config.php file:
\$mySQLcharset = 'utf8';
";
$mes->add($message, E_MESSAGE_SUCCESS);
}
}
function getQueries($query)
{
if(!$result = mysql_query($query))
{
$mes->add("Query Failed", E_MESSAGE_ERROR);
return;
}
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
$qry[] = $row[0];
}
return $qry;
}
/**
* Delete selected preferences.
* @return
*/
private function del_pref_val($mode='core')
{
global $emessage;
$deleted_list = "";
$config = ($mode == 'core' || $mode='') ? e107::getConfig('core') : e107::getPlugConfig($mode);
// Single Pref Deletion using button
if(varset($_POST['delpref']))
{
$delpref = key($_POST['delpref']);
if($config->remove($delpref))
{
$deleted_list .= "".$delpref."";
}
}
// Multiple Pref deletion using checkboxes
if(varset($_POST['delpref2']))
{
foreach($_POST['delpref2'] as $k => $v)
{
if($config->remove($k))
{
$deleted_list .= "".$k."";
}
}
}
if($deleted_list && $config->save())
{
$emessage->add(LAN_DELETED."");
e107::getCache()->clear();
}
}
private function delete_plugin_entry()
{
global $sql, $emessage;
$del = array_keys($_POST['delplug']);
if($sql->db_Delete("plugin", "plugin_id='".intval($del[0])."' LIMIT 1"))
{
$emessage->add(LAN_DELETED, E_MESSAGE_SUCCESS);
}
else
{
$emessage->add(LAN_DELETED_FAILED, E_MESSAGE_WARNING);
}
}
/**
* Render Options
* @return
*/
private function render_options()
{
$frm = e107::getSingleton('e_form');
$text = "
";
$emessage = eMessage::getInstance();
e107::getRender()->tablerender(DBLAN_10, $emessage->render().$text);
}
/**
* Import XML Form
* @return
*/
private function importForm()
{
// Get largest allowable file upload
$frm = e107::getSingleton('e_form');
require_once(e_HANDLER.'upload_handler.php');
$max_file_size = get_user_max_upload();
$text = "
\n";
$emessage = eMessage::getInstance();
e107::getRender()->tablerender(DBLAN_59, $emessage->render().$text);
}
/**
* Export XML Dump
* @return
*/
private function exportXmlForm()
{
$emessage = eMessage::getInstance();
$frm = e107::getSingleton('e_form');
//TODO LANs
$text = " ";
e107::getRender()->tablerender("Export Options",$emessage->render(). $text);
}
/**
* Import XML Dump
* @return
*/
private function importXmlFile()
{
$ret = e107::getSingleton('xmlClass')->e107Import($_FILES['file_userfile']['tmp_name'][0]);
foreach($ret['success'] as $table)
{
eMessage::getInstance()->add("Inserted $table", E_MESSAGE_SUCCESS);
}
foreach($ret['failed'] as $table)
{
eMessage::getInstance()->add("Failed to Insert $table", E_MESSAGE_ERROR);
}
}
/**
* Optimize SQL
* @return
*/
private function optimizesql($mySQLdefaultdb)
{
// global $emessage;
$result = mysql_list_tables($mySQLdefaultdb);
while($row = mysql_fetch_row($result))
{
mysql_query("OPTIMIZE TABLE ".$row[0]);
}
// $emessage->add(DBLAN_11." $mySQLdefaultdb ".DBLAN_12, E_MESSAGE_SUCCESS);
e107::getRender()->tablerender(DBLAN_7, DBLAN_11." $mySQLdefaultdb ".DBLAN_12);
}
/**
* Preferences Editor
* @return
*/
private function pref_editor($type='core')
{
//TODO Add drop-down filter for editing plugin prefs also.
global $pref, $e107, $emessage, $frm;
$config = ($type == 'core') ? e107::getConfig('core') : e107::getPlugConfig($type);
$spref = $config->getPref();
ksort($spref);
$text = "
\n\n";
e107::getRender()->tablerender(DBLAN_10.' :: '.DBLAN_20." :: ".ucwords($type), $emessage->render().$text);
return $text;
}
/**
* Preferences Editor
* @return
*/
private function scan_override()
{
global $pref, $emessage;
require_once(e_HANDLER.'file_class.php');
$f = new e_file;
$scList = '';
$fList = $f->get_files(e_FILE.'shortcode/override', '\.sc$');
if(count($fList))
{
$tmp = array();
foreach($fList as $file)
{
$tmp[] = strtoupper(substr($file['fname'], 0, -3));
}
$scList = implode(',', $tmp);
unset($tmp);
}
$pref['sc_override'] = $scList;
save_prefs();
// $emessage->add(DBLAN_57.':
'.$pref['sc_override'], E_MESSAGE_SUCCESS);
e107::getRender()->tablerender(DBLAN_56, DBLAN_57.':
'.$pref['sc_override']);
}
/**
* Plugin Folder Scanner
* @return
*/
private function plugin_viewscan()
{
$error_messages = array(0 => DBLAN_31, 1 => DBLAN_32, 2 => DBLAN_33, 3 => DBLAN_34);
$error_image = array("integrity_pass.png", "integrity_fail.png", "warning.png", "blank.png");
global $e107;
$sql = e107::getDb();
$tp = e107::getParser();
$frm = e107::getForm();
$emessage = e107::getMessage();
require_once (e_HANDLER."plugin_class.php");
$ep = new e107plugin();
$ep->update_plugins_table(); // scan for e_xxx changes and save to plugin table.
$ep->save_addon_prefs(); // generate global e_xxx_list prefs from plugin table.
/* we all are awaiting for PHP5 only support - method chaining...
$emessage->add(DBLAN_22.' - '.DBLAN_23, E_MESSAGE_SUCCESS)
->add("".LAN_BACK."", E_MESSAGE_SUCCESS)
->add(DBLAN_30);
*/
$emessage->add(DBLAN_23, E_MESSAGE_SUCCESS);
$emessage->add("".LAN_BACK."", E_MESSAGE_SUCCESS);
$emessage->add(DBLAN_30);
$text = "
";
e107::getRender()->tablerender(DBLAN_10.' - '.DBLAN_22, $emessage->render().$text);
}
}
//XXX - what is this for (backup core)?
function db_adminmenu()
{
global $st;
foreach($st->_options as $key=>$val)
{
$var[$key]['text'] = $val['label'];
$var[$key]['link'] = e_SELF."?mode=".$key;
}
e_admin_menu(DBLAN_10, $_GET['mode'], $var);
}
/**
* Export XML File and Copy Images.
* @param object $prefs
* @param object $tables
* @param object $debug [optional]
* @return
*/
function exportXmlFile($prefs,$tables,$package=FALSE,$debug=FALSE)
{
$xml = e107::getSingleton('xmlClass');
$tp = e107::getParser();
$emessage = eMessage::getInstance();
//TODO LANs
if(vartrue($package))
{
$xml->convertFilePaths = TRUE;
$xml->filePathDestination = EXPORT_PATH;
$xml->filePathPrepend = array(
'news_thumbnail' => "{e_IMAGE}newspost_images/"
);
$desinationFolder = $tp->replaceConstants($xml->filePathDestination);
if(!is_writable($desinationFolder))
{
$emessage->add($desinationFolder." is not writable", E_MESSAGE_ERROR);
return ;
}
}
if($xml->e107Export($prefs,$tables,$debug))
{
$emessage->add("Created: ".$desinationFolder."install.xml", E_MESSAGE_SUCCESS);
if(varset($xml->fileConvertLog))
{
foreach($xml->fileConvertLog as $oldfile)
{
$file = basename($oldfile);
$newfile = $desinationFolder.$file;
if($oldfile == $newfile || (copy($oldfile,$newfile)))
{
$emessage->add("Copied: ".$newfile, E_MESSAGE_SUCCESS);
}
else
{
$emessage->add("Couldn't copy: ".$newfile, E_MESSAGE_ERROR);
}
}
}
}
}
function table_list()
{
// grab default language lists.
//TODO - a similar function is in db_verify.php. Should probably all be moved to mysql_class.php.
$exclude = array();
$exclude[] = "core";
$exclude[] = "rbinary";
$exclude[] = "parser";
$exclude[] = "tmp";
$exclude[] = "online";
$exclude[] = "upload";
$exclude[] = "user_extended_country";
$exclude[] = "plugin";
$coreTables = e107::getDb()->db_TableList('nolan');
$tables = array_diff($coreTables,$exclude);
foreach($tables as $e107tab)
{
$count = e107::getDb()->db_Select_gen("SELECT * FROM #".$e107tab);
if($count)
{
$tabs[$e107tab] = $count;
}
}
return $tabs;
}
/* Still needed?
function backup_core()
{
global $pref, $sql;
$tmp = base64_encode((serialize($pref)));
if(!$sql->db_Insert("core", "'pref_backup', '{$tmp}' "))
{
$sql->db_Update("core", "e107_value='{$tmp}' WHERE e107_name='pref_backup'");
}
}
*/
function verify_sql_record() // deprecated by db_verify.php ( i think).
{
global $emessage, $sql, $sql2, $sql3, $frm, $e107, $tp;
$sql = e107::getDb();
$sql2 = e107::getDb('sql2');
$sql3 = e107::getDb('sql3');
$tables = array();
$tables[] = 'rate';
$tables[] = 'comments';
if(isset($_POST['delete_verify_sql_record']))
{
if(!varset($_POST['del_dbrec']))
{
$emessage->add('Nothing to delete', E_MESSAGE_DEBUG);
}
else
{
$msg = "ok, so you want to delete some records? not a problem at all!
";
$msg .= "but, since this is still an experimental procedure, i won't actually delete anything
";
$msg .= "instead, i will show you the queries that would be performed
";
$text .= "
";
$emessage->add($msg, E_MESSAGE_DEBUG);
foreach($_POST['del_dbrec'] as $k => $v)
{
if($k == 'rate')
{
$keys = implode(", ", array_keys($v));
$qry .= "DELETE * FROM rate WHERE rate_id IN (".$keys.")
";
}
elseif($k == 'comments')
{
$keys = implode(", ", array_keys($v));
$qry .= "DELETE * FROM comments WHERE comment_id IN (".$keys.")
";
}
}
$emessage->add($qry, E_MESSAGE_DEBUG);
$emessage->add("".LAN_BACK."", E_MESSAGE_DEBUG);
}
}
//Nothing selected
if(isset($_POST['check_verify_sql_record']) && (!isset($_POST['table_rate']) && !isset($_POST['table_comments'])))
{
$_POST['check_verify_sql_record'] = '';
unset($_POST['check_verify_sql_record']);
$emessage->add(DBLAN_53, E_MESSAGE_WARNING);
}
if(!isset($_POST['check_verify_sql_record']))
{
//select table to verify
$text = "
";
$e107->ns->tablerender(DBLAN_10.' - '.DBLAN_39, $emessage->render().$text);
}
else
{
//function to sort the results
function verify_sql_record_cmp($a, $b)
{
$orderby = array('type' => 'asc', 'itemid' => 'asc');
$result = 0;
foreach($orderby as $key => $value)
{
if($a[$key] == $b[$key])
continue;
$result = ($a[$key] < $b[$key]) ? - 1 : 1;
if($value == 'desc')
$result = - $result;
break;
}
return $result;
}
//function to display the results
//$err holds the error data
//$ctype holds the tablename
function verify_sql_record_displayresult($err, $ctype)
{
global $frm;
usort($err, 'verify_sql_record_cmp');
$text = "
";
return $text;
}
function verify_sql_record_gettables()
{
global $sql2;
//array which will hold all db tables
$dbtables = array();
//get all tables in the db
$sql2->db_Select_gen("SHOW TABLES");
while($row2 = $sql2->db_Fetch())
{
$dbtables[] = $row2[0];
}
return $dbtables;
}
$text = "
";
$e107->ns->tablerender(DBLAN_10.' - '.DBLAN_50, $emessage->render().$text);
}
}
/**
* Handle page DOM within the page header
*
* @return string JS source
*/
function headerjs()
{
require_once (e_HANDLER.'js_helper.php');
$ret = "
";
return $ret;
}
?>