Fixed/improved backup, added with and without UTF-8
Fixed/improved backup, added with and without UTF-8

--- a/admin/backup.php
+++ b/admin/backup.php
@@ -6,6 +6,8 @@
 // Based on eFiction 1.1

 // Copyright (C) 2003 by Rebecca Smallwood.

 // http://efiction.sourceforge.net/

+//

+// Size fix / UTF-8 feature 2016-05-18

 // ----------------------------------------------------------------------

 // LICENSE

 //

@@ -51,33 +53,31 @@
 

 // Database backup

 function datadump ($table) {

-    $result .= "# Dump of $table \r\n";

-    $result .= "# Dump DATE : " . date("d-M-Y") ."\r\n\r\n";

+    echo "# Dump of $table \r\n";

+    echo "# Dump DATE : " . date("d-M-Y") ."\r\n\r\n";

 

     $tabledata = dbquery("SELECT * FROM $table");

 

 	while($t = dbassoc($tabledata)) {

-		$result .= "INSERT INTO ".$table." ";

+		echo "INSERT INTO ".$table." ";

 		$row = array( );

 		foreach($t AS $field => $value) {			

 			$value = escapestring($value);

-			$value = ereg_replace("\n","\\n",$value);

+			$value = str_replace("\n","\\n",$value);

 			if (isset($value)) $row[$field] = "\"$value\"";

 			else $row[$field] = "\"\"";

 		}   

-		$result .= "VALUES(".implode(", ", $row).");\r\n";

+		echo "VALUES(".implode(", ", $row).");\r\n";

 	}

-	return $result . "\r\n\r\n\r\n";

+	echo "\r\n\r\n\r\n";

 }

 

 	$alltables = dbquery("SHOW TABLES");

-	$content = "";

+

 	while ($table = dbassoc($alltables)) {

-		foreach ($table as $db => $tablename) {

-			$content .= datadump($tablename);

-		}

+			datadump(current($table));

 	}

-	echo $content;

+

  	if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`) VALUES('".escapestring(sprintf(_LOG_BACKUP, USERPENNAME, USERUID))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'AM')");

 	exit( );

 


file:a/admin/backup_mk2.php (deleted)
--- a/admin/backup_mk2.php
+++ /dev/null
@@ -1,85 +1,1 @@
-<?php

-// ----------------------------------------------------------------------

-// eFiction 3.0

-// Copyright (c) 2007 by Tammy Keefer

-// Valid HTML 4.01 Transitional

-// Based on eFiction 1.1

-// Copyright (C) 2003 by Rebecca Smallwood.

-// http://efiction.sourceforge.net/

-//

-// Size fix / UTF-8 feature 2016-05-18

-// ----------------------------------------------------------------------

-// LICENSE

-//

-// This program is free software; you can redistribute it and/or

-// modify it under the terms of the GNU General Public License (GPL)

-// 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.

-//

-// To read the license please visit http://www.gnu.org/copyleft/gpl.html

-// ----------------------------------------------------------------------

-

-define("_BASEDIR", "../");

-include("../config.php");

-

-$settingsresults = dbquery("SELECT * FROM ".$settingsprefix."fanfiction_settings WHERE sitekey = '$sitekey'");

-$settings = dbassoc($settingsresults);

-foreach($settings as $var => $val) {

-	$$var = stripslashes($val);

-	$settings[$var] = htmlspecialchars($val);

-}

-if(!defined("SITEKEY")) define("SITEKEY", $settings['sitekey']);

-unset($settings['sitekey']);

-if(!defined("TABLEPREFIX")) define("TABLEPREFIX", $settings['tableprefix']);

-unset($settings['tableprefix']);

-$debug = 0;

-include("../languages/".$language.".php");

-include("../languages/".$language."_admin.php");

-$file_name = str_replace(" ", "_", $sitename).date("m-d-Y").".sql";

-header("Content-Type: text/html; charset=utf-8");

-Header("Content-type: application/octet-stream");

-Header("Content-Disposition: attachment; filename='$file_name'");

-

-session_start( );

-require_once("../includes/queries.php");

-require_once("../includes/get_session_vars.php");

-$debug = false;  // Because we don't want debug info mucking up our backup.

-

-if(!isADMIN) die( );

-

-// Database backup

-function datadump ($table) {

-    echo "# Dump of $table \r\n";

-    echo "# Dump DATE : " . date("d-M-Y") ."\r\n\r\n";

-

-    $tabledata = dbquery("SELECT * FROM $table");

-

-	while($t = dbassoc($tabledata)) {

-		echo "INSERT INTO ".$table." ";

-		$row = array( );

-		foreach($t AS $field => $value) {			

-			$value = utf8_encode (escapestring($value) );

-			$value = str_replace("\n","\\n",$value);

-			if (isset($value)) $row[$field] = "\"$value\"";

-			else $row[$field] = "\"\"";

-		}   

-		echo "VALUES(".implode(", ", $row).");\r\n";

-	}

-	echo "\r\n\r\n\r\n";

-}

-

-	$alltables = dbquery("SHOW TABLES");

-

-	while ($table = dbassoc($alltables)) {

-			datadump(current($table));

-	}

-

- 	if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`) VALUES('".escapestring(sprintf(_LOG_BACKUP, USERPENNAME, USERUID))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'AM')");

-	exit( );

-

-?>
+

--- /dev/null
+++ b/admin/backup_utf8.php
@@ -1,1 +1,85 @@
-
+<?php

+// ----------------------------------------------------------------------

+// eFiction 3.0

+// Copyright (c) 2007 by Tammy Keefer

+// Valid HTML 4.01 Transitional

+// Based on eFiction 1.1

+// Copyright (C) 2003 by Rebecca Smallwood.

+// http://efiction.sourceforge.net/

+//

+// Size fix / UTF-8 feature 2016-05-18

+// ----------------------------------------------------------------------

+// LICENSE

+//

+// This program is free software; you can redistribute it and/or

+// modify it under the terms of the GNU General Public License (GPL)

+// 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.

+//

+// To read the license please visit http://www.gnu.org/copyleft/gpl.html

+// ----------------------------------------------------------------------

+

+define("_BASEDIR", "../");

+include("../config.php");

+

+$settingsresults = dbquery("SELECT * FROM ".$settingsprefix."fanfiction_settings WHERE sitekey = '$sitekey'");

+$settings = dbassoc($settingsresults);

+foreach($settings as $var => $val) {

+	$$var = stripslashes($val);

+	$settings[$var] = htmlspecialchars($val);

+}

+if(!defined("SITEKEY")) define("SITEKEY", $settings['sitekey']);

+unset($settings['sitekey']);

+if(!defined("TABLEPREFIX")) define("TABLEPREFIX", $settings['tableprefix']);

+unset($settings['tableprefix']);

+$debug = 0;

+include("../languages/".$language.".php");

+include("../languages/".$language."_admin.php");

+$file_name = str_replace(" ", "_", $sitename).date("m-d-Y").".sql";

+header("Content-Type: text/html; charset=utf-8");

+Header("Content-type: application/octet-stream");

+Header("Content-Disposition: attachment; filename='$file_name'");

+

+session_start( );

+require_once("../includes/queries.php");

+require_once("../includes/get_session_vars.php");

+$debug = false;  // Because we don't want debug info mucking up our backup.

+

+if(!isADMIN) die( );

+

+// Database backup

+function datadump ($table) {

+    echo "# Dump of $table \r\n";

+    echo "# Dump DATE : " . date("d-M-Y") ."\r\n\r\n";

+

+    $tabledata = dbquery("SELECT * FROM $table");

+

+	while($t = dbassoc($tabledata)) {

+		echo "INSERT INTO ".$table." ";

+		$row = array( );

+		foreach($t AS $field => $value) {			

+			$value = utf8_encode (escapestring($value) );

+			$value = str_replace("\n","\\n",$value);

+			if (isset($value)) $row[$field] = "\"$value\"";

+			else $row[$field] = "\"\"";

+		}   

+		echo "VALUES(".implode(", ", $row).");\r\n";

+	}

+	echo "\r\n\r\n\r\n";

+}

+

+	$alltables = dbquery("SHOW TABLES");

+

+	while ($table = dbassoc($alltables)) {

+			datadump(current($table));

+	}

+

+ 	if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`) VALUES('".escapestring(sprintf(_LOG_BACKUP, USERPENNAME, USERUID))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'AM')");

+	exit( );

+

+?>

--- a/admin/maintenance.php
+++ b/admin/maintenance.php
@@ -208,7 +208,7 @@
 	<li><a href='admin.php?action=maintenance&amp;maint=panels'>"._PANELORDER."</a> <A HREF=\"#\" class=\"pophelp\">[?]<span>"._HELP_PANELORDER."</span></A></li>

 	<li><a href='admin.php?action=maintenance&amp;maint=optimize'>"._OPTIMIZE."</a> <A HREF=\"#\" class=\"pophelp\">[?]<span>"._HELP_OPTIMIZE."</span></A></li>

 	<li><a href='admin/backup.php' target='_new'>"._BACKUP."</a> <A HREF=\"#\" class=\"pophelp\">[?]<span>"._HELP_BACKUP."</span></A></li>

-	<li><a href='admin/backup_mk2.php' target='_new'>"._BACKUP."</a> (mk2) <A HREF=\"#\" class=\"pophelp\">[?]<span>"._HELP_BACKUP."</span></A></li>

+	<li><a href='admin/backup_utf8.php' target='_new'>"._BACKUP."</a> (UTF-8) <A HREF=\"#\" class=\"pophelp\">[?]<span>"._HELP_BACKUP."</span></A></li>

 	<li><a href='admin.php?action=maintenance&amp;maint=update'>"._UPDATE."</a>  <A HREF=\"#\" class=\"pophelp\">[?]<span>"._HELP_UPDATE."</span></A></li>

 </ul>";

 }