add(DBLAN_53, E_MESSAGE_WARNING);
}
else
{
$_POST[$type] = true;
}
}
if(isset($_POST['db_update']) || varset($_GET['mode'])=='db_update')
{
header("location: ".e_ADMIN."e107_update.php");
exit();
}
if(isset($_POST['exportXmlFile']))
{
if(exportXmlFile($_POST['xml_prefs'],$_POST['xml_tables'],$_POST['package_images']))
{
$mes = eMessage::getInstance();
$mes->add(LAN_SUCCESS, E_MESSAGE_SUCCESS);
}
}
require_once ("auth.php");
$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);
$mes->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'),
'correct_perms' => array('diz'=>'Correct File and Directory perms','label'=>'Correct Perms')
);
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']) || varset($_GET['mode'])=='verify_sql')
{
require_once(e_HANDLER."db_verify_class.php");
$dbv = new db_verify;
$dbv->backUrl = e_SELF."?mode=verify_sql";
$dbv->verify();
return;
}
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_class.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('refresh');
}
if(vartrue($_POST['perform_utf8_convert']))
{
$this->perform_utf8_convert();
return;
}
if(varset($_GET['mode'])=='correct_perms')
{
$this->correct_perms();
return;
}
if(!vartrue($_GET['mode']) && !isset($_POST['db_execute']))
{
$this->render_options();
}
}
/**
* Correct Folder and File permissions.
*/
function correct_perms()
{
$mes = e107::getMessage();
$fl = e107::getFile();
ob_start();
$fl->chmod(e_BASE);
$fl->chmod(e_BASE."cron.php",0755);
$errors = ob_get_clean();
if($errors !='')
{
$mes->addError($errors);
}
else
{
$mes->addSuccess("Folder and File permissions have been updated");
}
e107::getRender()->tablerender(DBLAN_10.SEP."Correcting File and Directory Permissions", $mes->render());
}
private function convertUTF8Form()
{
$mes = e107::getMessage();
$frm = e107::getForm();
//TODO a function to call the e107_config information in e107_class.php.
require(e_BASE."e107_config.php");
$dbtable = $mySQLdefaultdb;
//TODO LAN
$message = '
This function will permanently modify all tables in your database. ('.$mySQLdefaultdb.')
It is HIGHLY recommended that you backup your database first.
If possible use a copy of your database.
Do not forget to purge unnecessary input - e.g. old chatbox messages, pm, …
as well as to set the maintenance flag to main admins only.
Be sure to click the “Convert Database” button only once.
The conversion process can take up to one minute or much much more depending on the size of your database.
Known problems (list non-exhaustive):
The MySQL user needs privileges to ALTER the database - this is mandatory.
The conversion does not work with serialised arrays. Be sure you followed all steps of the upgrade process first.
It should work without troubles for databases of sites using only UTF-8 charset. Probably not with other charsets.
The function uses the information_schema database for now.
';
$mes->add($message, E_MESSAGE_WARNING);
$text = "
";
e107::getRender()->tablerender(DBLAN_10.SEP."Convert Database to UTF-8", $mes->render().$text);
}
private function perform_utf8_convert()
{
require(e_BASE."e107_config.php");
$dbtable = $mySQLdefaultdb;
//TODO Add a check to be sure the database is not already utf-8.
// yep, needs more methods - possibly a class in e107_handler
$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 none
*/
private function del_pref_val($mode='core')
{
$mes = e107::getMessage();
$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 .= "