<?php
/*
MGB 0.6.x - OpenSource PHP and MySql Guestbook
Copyright (C) 2004 - 2011 Juergen Grueneisl - http://www.m-gb.org/
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// ====================== //
// convert_ansi.php - 1.2 //
// ====================== //
//
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// Show all errors but no warnings
error_reporting(E_ALL & ~E_NOTICE);
// check if MGB has been already installed
if (file_exists("../includes/config.inc.php"))
{
require ("../includes/config.inc.php");
if(!isset($mgb_installation_complete))
{
echo "It seems as if you haven't installed the MGB yet. You can do that <a href=\"install.php\">here</a>.";
die();
}
}
else
{
echo "The config file could not be found. If you haven't installed the MGB yet, you can do that <a href=\"install.php\">here</a>.";
die();
}
// load includes
require ("../includes/config.inc.php");
if ($_POST['convert'] == 1)
{
// Form was sent, conversion confirmed
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n";
echo "\t\t\"http://www.w3.org/TR/html4/loose.dtd\">\n";
echo "<html>\n";
echo "<head>\n";
echo "<title>MGB OpenSource Guestbook - convert_utf8.php</title>\n";
echo "<meta content='text/html; charset=iso-8859-15' http-equiv='content-type'>";
echo "</head>\n";
echo "<body>\n";
echo "<span style=\"font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; font-weight: bold\">Converting all Umlauts to utf-8...<br /><br /></span>\n";
// connect to database
$link = @mysql_connect($db['hostname'], $db['username'], $db['password']) or die ("(convert_ansi.php) Error, line 63: ".mysql_error());
@mysql_select_db($db['dbname'], $link) or die ("(convert_ansi.php) Error, line 64: ".mysql_error());
// get total number of entries
$link_count = "SELECT COUNT(ID) FROM ".$db['prefix']."entries";
$results = @mysql_query($link_count) or die ("(convert_ansi.php) Error, line 68: ".mysql_error());
$total = @mysql_result($results, 0);
// load guestbook entries
$sql = "SELECT ID, name, city, email, icq, aim, msn, hp, message, comment FROM ".$db['prefix']."entries ORDER BY timestamp DESC LIMIT $total";
$result = @mysql_query($sql, $link) or die ("(convert_ansi.php) Error, line 73: ".mysql_error());
for($i = 0; $i < @mysql_num_rows($result); $i++)
{
$entry[$i] = @mysql_fetch_array($result);
}
echo "<span>\n";
if($total > 0)
{
for($i = 0; $i < count($entry); $i++)
{
$ansi_search = array (
'/¡/',
'/¢/',
'/£/',
'/¤/',
'/¥/',
'/¦/',
'/§/',
'/¨/',
'/©/',
'/ª/',
'/«/',
'/¬/',
'/®/',
'/¯/',
'/°/',
'/±/',
'/²/',
'/³/',
'/´/',
'/µ/',
'/¶/',
'/·/',
'/¸/',
'/¹/',
'/º/',
'/»/',
'/¼/',
'/½/',
'/¾/',
'/¿ /',
'/À/',
'/Á/',
'/Â/',
'/Ã/',
'/Ä/',
'/Å/',
'/Æ/',
'/Ç/',
'/È/',
'/É/',
'/Ê/',
'/Ë/',
'/Ì/',
'/Í/',
'/Î/',
'/Ï/',
'/Ð/',
'/Ñ/',
'/Ò/',
'/Ó/',
'/Ô/',
'/Õ/',
'/Ö/',
'/×/',
'/Ø/',
'/Ù/',
'/Ú/',
'/Û/',
'/Ü/',
'/Ý/',
'/Þ/',
'/ß/',
'/à/',
'/á/',
'/â/',
'/ã/',
'/ä/',
'/å/',
'/æ/',
'/ç/',
'/è/',
'/é/',
'/ê/',
'/ë/',
'/ì/',
'/í/',
'/î/',
'/ï/',
'/ð/',
'/ñ/',
'/ò/',
'/ó/',
'/ô/',
'/õ/',
'/ö/',
'/÷/',
'/ø/',
'/ù/',
'/ú/',
'/û/',
'/ü/',
'/ý/',
'/þ/',
'/ÿ/'
);
$ansi_replace = array (
'¡',
'¢',
'£',
'¤',
'¥',
'¦',
'§',
'¨',
'©',
'ª',
'«',
'¬',
'®',
'¯',
'°',
'±',
'²',
'³',
'´',
'µ',
'¶',
'·',
'¸',
'¹',
'º',
'»',
'¼',
'½',
'¾',
'¿',
'À',
'Á',
'Â',
'Ã',
'Ä',
'Å',
'Æ',
'Ç',
'È',
'É',
'Ê',
'Ë',
'Ì',
'Í',
'Î',
'Ï',
'Ð',
'Ñ',
'Ò',
'Ó',
'Ô',
'Õ',
'Ö',
'×',
'Ø',
'Ù',
'Ú',
'Û',
'Ü',
'Ý',
'Þ',
'ß',
'à',
'á',
'â',
'ã',
'ä',
'å',
'æ',
'ç',
'è',
'é',
'ê',
'ë',
'ì',
'í',
'î',
'ï',
'ð',
'ñ',
'ò',
'ó',
'ô',
'õ',
'ö',
'÷',
'ø',
'ù',
'ú',
'û',
'ü',
'ý',
'þ',
'ÿ '
);
$entry[$i]['name'] = preg_replace($ansi_search, $ansi_replace, $entry[$i]['name']);
$entry[$i]['city'] = preg_replace($ansi_search, $ansi_replace, $entry[$i]['city']);
$entry[$i]['message'] = preg_replace($ansi_search, $ansi_replace, $entry[$i]['message']);
$entry[$i]['comment'] = preg_replace($ansi_search, $ansi_replace, $entry[$i]['comment']);
// save data to database
$sql = "UPDATE ".$db['prefix']."entries SET
`name` = '".$entry[$i]['name']."',
`city` = '".$entry[$i]['city']."',
`message` = '".$entry[$i]['message']."',
`comment` = '".$entry[$i]['comment']."'
WHERE ID=".$entry[$i]['ID']." LIMIT 1";
if ( @mysql_query($sql, $link) or die ("(convert_ansi.php) Error, line 169: ".mysql_error()) )
{
$convert_count = $i + 1;
echo "<span style=\"font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; font-weight: bold\">Entry ".$convert_count.":</span> <span style='font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; font-weight: bold; color: green;'>OK!</span><br>\n";
}
}
}
echo "<br><span style=\"font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; font-weight: bold\">All entries have been converted!</span><br>\n";
echo "</span>\n";
}
else
{
if (date('H') < "12")
{
$greeting = "Good Morning";
}
if (date('H') >= "12")
{
$greeting = "Hello";
}
if (date('H') > "18")
{
$greeting ="Good Evening";
}
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n";
echo "\t\t\"http://www.w3.org/TR/html4/loose.dtd\">\n";
echo "<html>\n";
echo "<head>\n";
echo "<title>MGB OpenSource Guestbook - delete_sql.php</title>\n";
echo "<meta content='text/html; charset=iso-8859-15' http-equiv='content-type'>";
echo "</head>\n";
echo "<body>\n";
echo "<form action=\"convert_ansi.php\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"convert\" value=\"1\">\n";
echo "<span style=\"font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; font-weight: bold\">".$greeting.", Dave.<br /><br />Are you really sure you want to convert all entries to ansi-code?";
echo "<br /><br />\n";
echo "<input type=\"submit\" class=\"button\" name=\"confirm\" value=\"Yes, HAL. I'm sure.\">\n";
echo "</form>\n";
echo "</body>\n";
echo "</html>\n";
}
?>