Browse code

Fix MySQL table creation, TYPE to ENGINE

Rainer Volkrodt authored on 2016/03/21 11:50:45
Showing 1 changed files
... ...
@@ -823,14 +823,14 @@ switch($_GET['step']) {
823 823
   `field_code_out` text,
824 824
   `field_on` tinyint(1) NOT NULL default '0',
825 825
   PRIMARY KEY  (`field_id`)
826
-) TYPE=MyISAM;");
826
+) ENGINE=MyISAM;");
827 827
 $output .= "<tr><td>".TABLEPREFIX."fanfiction_authorfields</td><td align='center'>" . ($authorfields ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
828 828
 				$authorinfo = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_authorinfo` (
829 829
   `uid` int(11) NOT NULL default '0',
830 830
   `field` int(11) NOT NULL default '0',
831 831
   `info` varchar(255) NOT NULL default ' ',
832 832
   PRIMARY KEY  (`uid`,`field`),
833
-  KEY `uid` (`uid`)) TYPE=MyISAM;");
833
+  KEY `uid` (`uid`)) ENGINE=MyISAM;");
834 834
 $output .= "<tr><td>".TABLEPREFIX."fanfiction_authorinfo</td><td align='center'>" . ($authorinfo ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
835 835
 				$authorprefs = dbquery("
836 836
 CREATE TABLE `".TABLEPREFIX."fanfiction_authorprefs` (
... ...
@@ -849,7 +849,7 @@ CREATE TABLE `".TABLEPREFIX."fanfiction_authorprefs` (
849 849
   `contact` tinyint(1) NOT NULL default '0',
850 850
   `stories` int(11) NOT NULL default '0',
851 851
    PRIMARY KEY  (`uid`)
852
-) TYPE=MyISAM;");
852
+) ENGINE=MyISAM;");
853 853
 $output .= "<tr><td>".TABLEPREFIX."fanfiction_authorprefs</td><td align='center'>" . ($authorprefs ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";				
854 854
 				$blocks = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_blocks` (
855 855
   `block_id` int(11) NOT NULL auto_increment,
... ...
@@ -860,7 +860,7 @@ $output .= "<tr><td>".TABLEPREFIX."fanfiction_authorprefs</td><td align='center'
860 860
   `block_variables` text NOT NULL,
861 861
   PRIMARY KEY  (`block_id`),
862 862
   KEY `block_name` (`block_name`)
863
-) TYPE=MyISAM;");
863
+) ENGINE=MyISAM;");
864 864
 $output .= "<tr><td>".TABLEPREFIX."fanfiction_blocks</td><td align='center'>" . ($blocks ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
865 865
 				$classes = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_classes` (
866 866
   `class_id` int(11) NOT NULL auto_increment,
... ...
@@ -868,7 +868,7 @@ $output .= "<tr><td>".TABLEPREFIX."fanfiction_blocks</td><td align='center'>" .
868 868
   `class_name` varchar(100) NOT NULL default '',
869 869
   PRIMARY KEY  (`class_id`),
870 870
   KEY `byname` (`class_type`,`class_name`,`class_id`)
871
-) TYPE=MyISAM;");
871
+) ENGINE=MyISAM;");
872 872
 $output .= "<tr><td>".TABLEPREFIX."fanfiction_classes</td><td align='center'>" . ($classes ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
873 873
 				$classtypes = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_classtypes` (
874 874
   `classtype_id` int(11) NOT NULL auto_increment,
... ...
@@ -876,13 +876,13 @@ $output .= "<tr><td>".TABLEPREFIX."fanfiction_classes</td><td align='center'>" .
876 876
   `classtype_title` varchar(50) NOT NULL default '',
877 877
   PRIMARY KEY  (`classtype_id`),
878 878
   UNIQUE KEY `classtype_name` (`classtype_name`)
879
-) TYPE=MyISAM;");
879
+) ENGINE=MyISAM;");
880 880
 $output .= "<tr><td>".TABLEPREFIX."fanfiction_classtypes</td><td align='center'>" . ($classtypes ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
881 881
 $coauthors = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_coauthors` (
882 882
   `sid` int(11) NOT NULL default '0',
883 883
   `uid` int(11) NOT NULL default '0',
884 884
   PRIMARY KEY  (`sid`,`uid`)
885
-) TYPE=MyISAM;");
885
+) ENGINE=MyISAM;");
886 886
 $output .= "<tr><td>".$tableprefix."fanfiction_coauthors</td><td align='center'>" . ($coauthors ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
887 887
 				$codeblocks = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_codeblocks` (
888 888
   `code_id` int(11) NOT NULL auto_increment,
... ...
@@ -891,7 +891,7 @@ $output .= "<tr><td>".$tableprefix."fanfiction_coauthors</td><td align='center'>
891 891
   `code_module` varchar(60) default NULL,
892 892
   PRIMARY KEY  (`code_id`),
893 893
   KEY `code_type` (`code_type`)
894
-) TYPE=MyISAM;");
894
+) ENGINE=MyISAM;");
895 895
 $output .= "<tr><td>".TABLEPREFIX."fanfiction_codeblocks</td><td align='center'>" . ($codeblocks ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
896 896
 				$favorites = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_favorites` (
897 897
   `uid` int(11) NOT NULL default '0',
... ...
@@ -900,7 +900,7 @@ $output .= "<tr><td>".TABLEPREFIX."fanfiction_codeblocks</td><td align='center'>
900 900
   `comments` text NOT NULL,
901 901
   UNIQUE KEY `byitem` (`item`,`type`,`uid`),
902 902
   UNIQUE KEY `byuid` (`uid`,`type`,`item`)
903
-) TYPE=MyISAM;");
903
+) ENGINE=MyISAM;");
904 904
 $output .= "<tr><td>".TABLEPREFIX."fanfiction_favorites</td><td align='center'>" . ($favorites ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
905 905
 				$logs = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_log` (
906 906
   `log_id` int(11) NOT NULL auto_increment,
... ...
@@ -910,7 +910,7 @@ $output .= "<tr><td>".TABLEPREFIX."fanfiction_favorites</td><td align='center'>"
910 910
   `log_timestamp` timestamp NOT NULL,
911 911
   `log_type` varchar(2) NOT NULL,
912 912
   PRIMARY KEY  (`log_id`)
913
-) TYPE=MyISAM");
913
+) ENGINE=MyISAM");
914 914
 $output .= "<tr><td>".TABLEPREFIX."fanfiction_log</td><td align='center'>" . ($logs ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
915 915
 				$messages = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_messages` (
916 916
   `message_id` int(11) NOT NULL auto_increment,
... ...
@@ -919,7 +919,7 @@ $output .= "<tr><td>".TABLEPREFIX."fanfiction_log</td><td align='center'>" . ($l
919 919
   `message_text` text NOT NULL,
920 920
   PRIMARY KEY  (`message_id`),
921 921
   KEY `message_name` (`message_name`)
922
-) TYPE=MyISAM;");
922
+) ENGINE=MyISAM;");
923 923
 $output .= "<tr><td>".TABLEPREFIX."fanfiction_messages</td><td align='center'>" . ($messages ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
924 924
 				$modules = dbquery("
925 925
 CREATE TABLE `".TABLEPREFIX."fanfiction_modules` (
... ...
@@ -940,7 +940,7 @@ $output .= "<tr><td>".TABLEPREFIX."fanfiction_modules</td><td align='center'>" .
940 940
   `link_access` tinyint(4) NOT NULL default '0',
941 941
   PRIMARY KEY  (`link_id`),
942 942
   KEY `link_name` (`link_name`)
943
-) TYPE=MyISAM;");
943
+) ENGINE=MyISAM;");
944 944
 $output .= "<tr><td>".TABLEPREFIX."fanfiction_pagelinks</td><td align='center'>" . ($pagelinks ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
945 945
 				$panels = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_panels` (
946 946
   `panel_id` int(11) NOT NULL auto_increment,
... ...
@@ -953,7 +953,7 @@ $output .= "<tr><td>".TABLEPREFIX."fanfiction_pagelinks</td><td align='center'>"
953 953
   `panel_type` varchar(20) NOT NULL default 'A',
954 954
   PRIMARY KEY  (`panel_id`),
955 955
   KEY `panel_type` (`panel_type`,`panel_name`)
956
-) TYPE=MyISAM;");
956
+) ENGINE=MyISAM;");
957 957
 $output .= "<tr><td>".TABLEPREFIX."fanfiction_panels</td><td align='center'>" . ($panels ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
958 958
 	$stats = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_stats` (
959 959
   `sitekey` varchar(50) NOT NULL default '0',
... ...
@@ -966,7 +966,7 @@ $output .= "<tr><td>".TABLEPREFIX."fanfiction_panels</td><td align='center'>" .
966 966
   `members` int(11) NOT NULL default '0',
967 967
   `reviewers` int(11) NOT NULL default '0',
968 968
   `newestmember` int(11) NOT NULL default '0'
969
-) TYPE=MyISAM");
969
+) ENGINE=MyISAM");
970 970
 	dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_stats(`sitekey`, `newestmember`) VALUES('".SITEKEY."', '1')");
971 971
 $output .= "<tr><td>".TABLEPREFIX."fanfiction_stats</td><td align='center'>" . ($stats ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
972 972
 $output .= "</table>";
... ...
@@ -1157,7 +1157,7 @@ if(!empty(\$sitekey)) \$dbconnect = dbconnect(\$dbhost, \$dbuser,\$dbpass, \$dbn
1157 1157
   `smtp_username` varchar(50) default NULL,
1158 1158
   `smtp_password` varchar(50) default NULL,
1159 1159
   PRIMARY KEY  (`sitekey`)
1160
-) TYPE=MyISAM;");
1160
+) ENGINE=MyISAM;");
1161 1161
 if($settings) $output .= write_message("<img src=\"../images/check.gif\"> "._SETTINGSTABLESUCCESS." <br /><a href='upgrade20.php?step=2&amp;settingsprefix=".$_POST['settingsprefix']."'>"._CONTINUE."</a>");
1162 1162
 else $output .= write_message(_SETTINGSTABLEAUTOFAIL." <br /><a href='upgrade20.php?step=2&amp;settingsprefix=".$_POST['settingsprefix']."'>"._CONTINUE."</a> ");
1163 1163
 		}
Browse code

Initial uplad w/ php7 fixes

Rainer Volkrodt authored on 2016/03/12 15:54:02
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1186 @@
1
+<?php
2
+// ----------------------------------------------------------------------
3
+// Copyright (c) 2007 by Tammy Keefer
4
+// Based on eFiction 1.1
5
+// Copyright (C) 2003 by Rebecca Smallwood.
6
+// http://efiction.sourceforge.net/
7
+// ----------------------------------------------------------------------
8
+// LICENSE
9
+//
10
+// This program is free software; you can redistribute it and/or
11
+// modify it under the terms of the GNU General Public License (GPL)
12
+// as published by the Free Software Foundation; either version 2
13
+// of the License, or (at your option) any later version.
14
+//
15
+// This program is distributed in the hope that it will be useful,
16
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+// GNU General Public License for more details.
19
+//
20
+// To read the license please visit http://www.gnu.org/copyleft/gpl.html
21
+// ----------------------------------------------------------------------
22
+
23
+function isNumber($num) {
24
+	return preg_match("/^[0-9]+$/", $num);
25
+}
26
+
27
+function random_char($string)
28
+{
29
+	$length = strlen($string);
30
+	$position = mt_rand(0, $length - 1);
31
+	 return $string[$position];
32
+}
33
+
34
+function random_string ($charset_string, $length)
35
+{
36
+	$return_string = random_char($charset_string);
37
+	for ($x = 1; $x < $length; $x++)
38
+	$return_string .= random_char($charset_string);
39
+	return $return_string;
40
+}
41
+
42
+$randomcharset = '23456789' . 'abcdefghijkmnpqrstuvwxyz' . 'ABCDEFGHJKLMNPQRSTUVWXYZ';
43
+
44
+function descript($text, $addbreaks = 0) {
45
+	// Convert problematic ascii characters to their true values
46
+	$search = array("40","41","58","65","66","67","68","69","70",
47
+		"71","72","73","74","75","76","77","78","79","80","81",
48
+		"82","83","84","85","86","87","88","89","90","97","98",
49
+		"99","100","101","102","103","104","105","106","107",
50
+		"108","109","110","111","112","113","114","115","116",
51
+		"117","118","119","120","121","122"
52
+		);
53
+	$replace = array("(",")",":","a","b","c","d","e","f","g","h",
54
+		"i","j","k","l","m","n","o","p","q","r","s","t","u",
55
+		"v","w","x","y","z","a","b","c","d","e","f","g","h",
56
+		"i","j","k","l","m","n","o","p","q","r","s","t","u",
57
+		"v","w","x","y","z"
58
+		);
59
+	$entities = count($search);
60
+	for ($i=0;$i < $entities;$i++) $text = preg_replace("#(&\#)(0*".$search[$i]."+);*#si", $replace[$i], $text);
61
+	// the following is based on code from bitflux (http://blog.bitflux.ch/wiki/)
62
+	// Kill hexadecimal characters completely
63
+	$text = preg_replace('#(&\#x)([0-9A-F]+);*#si', "", $text);
64
+	// remove any attribute starting with "on" or xmlns
65
+	$text = preg_replace('#(<[^>]+[\\"\'\s])(onmouseover|onmousedown|onmouseup|onmouseout|onmousemove|onclick|ondblclick|onload|xmlns)[^>]*>#iUu',">",$text);
66
+	// remove javascript: and vbscript: protocol
67
+	$text = preg_replace('#([a-z]*)=([\`\'\"]*)script:#iUu','$1=$2nojscript...',$text);
68
+	$text = preg_replace('#([a-z]*)=([\`\'\"]*)javascript:#iUu','$1=$2nojavascript...',$text);
69
+	$text = preg_replace('#([a-z]*)=([\'\"]*)vbscript:#iUu','$1=$2novbscript...',$text);
70
+        //<span style="width: expression(alert('Ping!'));"></span> (only affects ie...)
71
+        $text = preg_replace('#(<[^>]+)style=([\`\'\"]*).*expression\([^>]*>#iU',"$1>",$text);
72
+        $text = preg_replace('#(<[^>]+)style=([\`\'\"]*).*behaviour\([^>]*>#iU',"$1>",$text);
73
+	do {
74
+        	$thistext = $text;
75
+		$text = preg_replace('#</*(applet|meta|xml|blink|link|style|script|embed|object|iframe|frame|frameset|ilayer|layer|bgsound|title|base)[^>]*>#i',"",$text);
76
+	} while ($thistext != $text); 
77
+	if($addbreaks && strpos($text, "<br>") === false && strpos($text, "<p>") === false && strpos($text, "<br />") === false) $text = nl2br($text);
78
+	return $text;
79
+}
80
+
81
+function write_message($text) {
82
+	return "<div style='text-align: center; margin: 1em;'>$text</div>";
83
+}
84
+// Strip out slashes if magic quotes isn't on.
85
+if(ini_get("magic_quotes_gpc")) {
86
+	foreach($_POST as $var => $val) {
87
+		$val = is_array( $val ) ? array_map( 'stripslashes', $val ) : stripslashes( $val );
88
+	}
89
+	foreach($_GET as $var => $val) {
90
+		$val = is_array( $val ) ? array_map( 'stripslashes', $val ) : stripslashes( $val );
91
+	}
92
+	foreach($_COOKIE as $var => $val) {
93
+		$val = is_array( $val ) ? array_map( 'stripslashes', $val ) : stripslashes( $val );
94
+	}
95
+}
96
+
97
+function storiesInSeries($thisseries) {
98
+	
99
+		$storylist = array( );
100
+	$serieslist = array( );
101
+	$stinseries = dbquery("SELECT sid, subseriesid FROM ".TABLEPREFIX."fanfiction_inseries WHERE seriesid = '$thisseries'");
102
+	while($st = dbassoc($stinseries)) { 
103
+		if(!empty($st['sid'])) $storylist[] = $st['sid'];
104
+		else if(!empty($st['subseriesid'])) $serieslist[] = $st['subseriesid'];
105
+	}
106
+	if($serieslist) {
107
+		foreach($serieslist as $s) {
108
+			$storylist = array_merge($storylist, storiesInSeries($s));
109
+		}
110
+	}
111
+	return $storylist;
112
+}
113
+
114
+Header('Cache-Control: private, no-cache, must-revalidate, max_age=0, post-check=0, pre-check=0');
115
+header ("Pragma: no-cache"); 
116
+header ("Expires: 0"); 
117
+
118
+//make a new TemplatePower object
119
+echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">
120
+<html><head><title>eFiction $version Install</title>
121
+<style>
122
+#settingsform { margin: 0; padding: 0; border: none; }
123
+#settingsform FORM { width: 100%; margin: 0 10%; }
124
+#settingsform LABEL { float: left; display: block; width: 30%; text-align: right; padding-right: 10px; clear: left; padding-top: 1px;}
125
+#settingsform .textbox { margin: 1px 0; }
126
+#settingsform .fieldset SPAN { float: left; display: block; width: 30%; text-align: right; padding-right: 10px; clear: left;}
127
+#settingsform .fieldset LABEL { float: none; width: auto; display: inline; text-align: left; clear: none; }
128
+#settingsform { float: left; margin: 1ex 10%; }
129
+#settingsform .tinytoggle { text-align: center; }
130
+#settingsform .tinytoggle LABEL { float: none; display: inline; width: auto; text-align: center; padding: 0; clear: none; }
131
+#settingsform #submitdiv { text-align: center; width: 100%;clear: both; height: 3em; }
132
+#settingsform #submitdiv #submit { position: absolute; z-index: 10001; margin: 1em; }
133
+LABEL { float: left; display: block; width: 50%; text-align: right; padding-right: 10px; clear: left;}
134
+.row { float: left; width: 99%; }
135
+a.pophelp{
136
+    position: relative; /*this is the key*/
137
+    z-index:24;
138
+    vertical-align: super;
139
+}
140
+
141
+a.pophelp:hover{z-index:100; border: none;}
142
+
143
+a.pophelp span{display: none; position: absolute;}
144
+
145
+a.pophelp:hover span{ /*the span will display just on :hover state*/
146
+    display:block;
147
+    position:absolute;
148
+    top:2em; left:4em; width: 225px;
149
+    border:1px solid #000;
150
+    background-color:#CCC; color:#000;
151
+    text-decoration: none;
152
+    text-align: left;
153
+    padding: 5px;
154
+    font-weight: normal;
155
+}
156
+</style>
157
+<link rel=\"stylesheet\" type=\"text/css\" href='../default_tpls/style.css'></head>";
158
+
159
+$output = "";
160
+define("_BASEDIR", "../");
161
+
162
+include ("../includes/class.TemplatePower.inc.php");
163
+include("../config.php");
164
+if(isset($_GET['step']) && $_GET['step'] > 2) {
165
+	$settings = dbquery("SELECT tableprefix, language FROM ".$settingsprefix."fanfiction_settings WHERE sitekey = '".$sitekey."'");
166
+	list($tableprefix, $language) = dbrow($settings);
167
+	define("TABLEPREFIX", $tableprefix);
168
+	define("SITEKEY", $sitekey);
169
+}
170
+if(isset($language)) {
171
+if(file_exists("../languages/{$language}.php")) include ("../languages/{$language}.php");
172
+else include ("../languages/en.php");
173
+if(file_exists("../languages/{$language}_admin.php")) include ("../languages/{$language}_admin.php");
174
+else include ("../languages/en_admin.php");
175
+if(file_exists("languages/$language.php")) include ("languages/{$language}.php");
176
+else include("languages/en.php");
177
+}
178
+else {
179
+include ("../languages/en.php");
180
+include ("../languages/en_admin.php");
181
+include("languages/en.php");
182
+}
183
+//  So I don't have to keep updating the version number in 3 different files.
184
+include("../version.php");
185
+
186
+$tpl = new TemplatePower( "../default_tpls/default.tpl" );
187
+$tpl->assignInclude( "header", "./../default_tpls/header.tpl" );
188
+$tpl->assignInclude( "footer", "./../default_tpls/footer.tpl" );
189
+$tpl->prepare( );
190
+$tpl->newBlock("header");
191
+$tpl->assign("sitename", "Upgrade eFiction 2.0.X to eFiction $version");
192
+$tpl->gotoBlock( "_ROOT" );
193
+$tpl->newBlock("footer");
194
+$tpl->assign( "footer", "eFiction $version &copy; 2006. <a href='http://efiction.org/'>http://efiction.org/</a>");
195
+$tpl->gotoBlock( "_ROOT" );
196
+
197
+switch($_GET['step']) {
198
+	case "19":
199
+		$output .= "<div id='pagetitle'>"._OPTIMIZEDB."</div>";
200
+
201
+		if(isset($_GET['install'])) {
202
+			if($_GET['install'] == "automatic") {
203
+				dbquery("alter table ".TABLEPREFIX."fanfiction_categories drop index category;");
204
+				dbquery("alter table ".TABLEPREFIX."fanfiction_categories drop index parentcatid;");
205
+				dbquery("create index byparent on ".TABLEPREFIX."fanfiction_categories (parentcatid,displayorder);");
206
+				dbquery("create index forstoryblock on ".TABLEPREFIX."fanfiction_chapters (sid,validated);");
207
+				dbquery("alter table ".TABLEPREFIX."fanfiction_comments drop index nid;");
208
+				dbquery("alter table ".TABLEPREFIX."fanfiction_comments add index commentlist (nid,time);");
209
+				dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index seriesid;");
210
+				dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index inorder;");
211
+				dbquery("alter table ".TABLEPREFIX."fanfiction_inseries add index (seriesid,inorder);");
212
+				dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index sid;");
213
+				dbquery("alter table ".TABLEPREFIX."fanfiction_inseries add primary key (sid,seriesid,subseriesid);");
214
+				dbquery("create index avgrating on ".TABLEPREFIX."fanfiction_reviews(type,item,rating);");
215
+				dbquery("alter table ".TABLEPREFIX."fanfiction_reviews drop index sid;");
216
+				dbquery("create index bychapter on ".TABLEPREFIX."fanfiction_reviews (chapid,rating);");
217
+				dbquery("alter table ".TABLEPREFIX."fanfiction_reviews add index byuid (uid,item,type);");
218
+				dbquery("alter table ".TABLEPREFIX."fanfiction_series drop index owner;");
219
+				dbquery("create index owner on ".TABLEPREFIX."fanfiction_series (uid,title);");
220
+				dbquery("alter table ".TABLEPREFIX."fanfiction_stories drop index validated;");
221
+				dbquery("create index validateduid on ".TABLEPREFIX."fanfiction_stories (validated,uid);");
222
+				dbquery("create index recent on ".TABLEPREFIX."fanfiction_stories (updated,validated);");
223
+				dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_inseries` DROP `updated`");
224
+				dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_news` ADD `comments` INT NOT NULL DEFAULT '0'");
225
+				dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_series` ADD `numstories` INT NOT NULL DEFAULT '0'");
226
+				$serieslist = dbquery("SELECT seriesid FROM ".TABLEPREFIX."fanfiction_series");
227
+				$totalseries = dbnumrows($serieslist);
228
+				while($s = dbassoc($serieslist)) {
229
+					$numstories = count(storiesInSeries($s['seriesid']));
230
+					dbquery("UPDATE ".TABLEPREFIX."fanfiction_series SET numstories = '$numstories' WHERE seriesid = ".$s['seriesid']." LIMIT 1");
231
+				}
232
+
233
+				$newslist = dbquery("SELECT count(cid) as count, nid FROM ".TABLEPREFIX."fanfiction_comments GROUP BY nid");
234
+				while($n = dbassoc($newslist)) {
235
+					dbquery("UPDATE ".TABLEPREFIX."fanfiction_news SET comments = '".$n['count']."' WHERE nid = ".$n['nid']);
236
+				}
237
+
238
+				$storiesquery =dbquery("SELECT COUNT(sid) as totals, COUNT(DISTINCT uid) as totala, SUM(wordcount) as totalwords FROM ".TABLEPREFIX."fanfiction_stories WHERE validated > 0 ");
239
+				list($stories, $authors, $words) = dbrow($storiesquery);
240
+				dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET stories = '$stories', authors = '$authors', wordcount = '$words' WHERE sitekey = '".SITEKEY."'"); 
241
+
242
+				$chapterquery = dbquery("SELECT COUNT(chapid) as chapters FROM ".TABLEPREFIX."fanfiction_chapters where validated > 0");
243
+				list($chapters) = dbrow($chapterquery);
244
+
245
+				$authorquery = dbquery("SELECT COUNT(uid) as totalm FROM ".TABLEPREFIX."fanfiction_authors");
246
+				list($members) = dbrow($authorquery);
247
+
248
+				list($newest) = dbrow(dbquery("SELECT uid as uid FROM ".TABLEPREFIX."fanfiction_authors ORDER BY uid DESC LIMIT 1"));
249
+				$reviewquery = dbquery("SELECT COUNT(reviewid) as totalr FROM ".TABLEPREFIX."fanfiction_reviews WHERE review != 'No Review'");
250
+				list($reviews) = dbrow($reviewquery);
251
+				$reviewquery = dbquery("SELECT COUNT(uid) FROM ".TABLEPREFIX."fanfiction_reviews WHERE review != 'No Review' AND uid != 0");
252
+				list($reviewers) = dbrow($reviewquery);
253
+				dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET series = '$totalseries', chapters = '$chapters', members = '$members', newestmember = '$newest', reviews = '$reviews', reviewers = '$reviewers' WHERE sitekey = '".SITEKEY."'"); 
254
+				$alltables = dbquery("SHOW TABLES");
255
+				while ($table = dbassoc($alltables)) {
256
+					foreach ($table as $db => $tablename) {
257
+						dbquery("OPTIMIZE TABLE `".$tablename."`");
258
+					}
259
+				}
260
+				$output .= write_message(_DONE."<br />"._UPGRADEEND);
261
+			}
262
+			else {
263
+				$output .= write_message(_OPTIMIZEMANUAL." "._UPGRADEEND);
264
+			}
265
+		}
266
+		else $output .= write_message(_OPTIMIZEINFO."<br /><br /><a href='upgrade20.php?step=19&amp;install=automatic'>"._AUTO."</a> "._OR." <a href='upgrade20.php?step=19&amp;install=manual'>"._MANUAL2."</a>");
267
+	break;
268
+	case "18":
269
+		$output .= "<div id='pagetitle'>"._SERIESREVIEWS."</div>";
270
+		if(isset($_GET['install'])) {
271
+
272
+
273
+	
274
+			$series = dbquery("SELECT seriesid FROM ".TABLEPREFIX."fanfiction_series");
275
+			if(dbnumrows($series)) {
276
+				while($s = dbassoc($series)) {
277
+					$thisseries = $s['seriesid'];
278
+					include("../includes/seriesreviews.php");
279
+				}
280
+			}
281
+			$output .= write_message("<a href='upgrade20.php?step=19'>"._CONTINUE."</a>");				
282
+		}
283
+		else $output .= write_message(_SERIESREVIEWSINFO."<br /><a href='upgrade20.php?step=18&amp;install=automatic'>"._CONTINUE."</a>");
284
+	break;
285
+	case "17":
286
+		$output .= "<div id='pagetitle'>"._NEWSUPDATE."</div>";
287
+		if(isset($_GET['install'])) {
288
+
289
+
290
+
291
+	
292
+			$comments = dbquery("SELECT uname FROM ".TABLEPREFIX."fanfiction_comments GROUP BY uname");
293
+			while($uname = dbassoc($comments)) {
294
+				unset($uid);
295
+				$nameinfo = dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_authors WHERE penname = '".$uname['uname']."'");
296
+				list($uid) = dbrow($nameinfo);
297
+				if(empty($uid)) $uid = 0;
298
+				dbquery("UPDATE ".TABLEPREFIX."fanfiction_comments SET uname = '$uid' WHERE uname = '".$uname['uname']."'");
299
+			}
300
+			$result2 = dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_comments` CHANGE `uname` `uid` INT NOT NULL DEFAULT '0';");
301
+			$output .= write_message(_NEWSUPDATERESULT.($result2 ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));	
302
+			$output .= write_message("<a href='upgrade20.php?step=18'>"._CONTINUE."</a>");				
303
+
304
+		}
305
+		else $output .= write_message(_NEWSUPDATEINFO."<br /><a href='upgrade20.php?step=17&amp;install=automatic'>"._CONTINUE."</a>");
306
+
307
+	break;
308
+	case "16":
309
+		$output .= "<div id='pagetitle'>"._AUTHORUPDATE."</div>";
310
+		if(isset($_GET['install'])) {
311
+
312
+
313
+			$settings = dbquery("SELECT tableprefix, defaultsort, displayindex, tinyMCE FROM ".$settingsprefix."fanfiction_settings WHERE sitekey = '".SITEKEY."'");
314
+			list($defaultsort, $displayindex, $tinyMCE) = dbrow($settings);
315
+			$fix = dbquery("UPDATE ".TABLEPREFIX."fanfiction_authors SET ageconsent = 0 WHERE ageconsent != 1");
316
+			$result = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_authorprefs(`uid`, `newreviews`, `ageconsent`, `alertson`, `validated`, `userskin`, `level`, `categories`, `contact`) SELECT uid, newreviews, ageconsent, alertson, validated, userskin, level, categories, contact FROM ".TABLEPREFIX."fanfiction_authors");
317
+			$result2 = dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs set sortby = '$defaultsort', storyindex = '$displayindex', tinyMCE = '$tinyMCE'");
318
+			$output .= write_message(_AUTHORRESULT.($result ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
319
+			$fields = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_authorfields WHERE field_on = 1");
320
+			while($f = dbassoc($fields)) {
321
+				$result = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_authorinfo(`uid`, `info`) SELECT uid, ".$f['field_name']." FROM ".TABLEPREFIX."fanfiction_authors WHERE ".$f['field_name']." IS NOT NULL AND ".$f['field_name']." != ''");
322
+				$result2 = dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorinfo SET field = ".$f['field_id']." WHERE field = 0");
323
+			}
324
+			$result2 = dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_authors` DROP `newreviews`, DROP `validated`, DROP `userskin`, DROP `level`, DROP `contact`, DROP `categories`, DROP `ageconsent`, DROP `betareader`, DROP `alertson`, DROP `AOL`, DROP `Yahoo`, DROP `ICQ`, DROP `MSN`;");
325
+			$output .= write_message(_AUTHORDROPRESULT.($result2 ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));	
326
+			$output .= write_message("<a href='upgrade20.php?step=17'>"._CONTINUE."</a>");				
327
+
328
+		}
329
+		else $output .= write_message(_AUTHORUPDATEINFO."<br /><a href='upgrade20.php?step=16&amp;install=automatic'>"._CONTINUE."</a>");
330
+	break;
331
+	case "15":
332
+		$output .= "<div id='pagetitle'>"._AUTHORFIELDS."</div>";
333
+		include("../config.php");
334
+		$settings = dbquery("SELECT tableprefix FROM ".$settingsprefix."fanfiction_settings WHERE sitekey = '".SITEKEY."'");
335
+
336
+		if(isset($_GET['install'])) {
337
+			if($_GET['install'] == "automatic") {
338
+				$fields[] = array('4','lj','Live Journal','http://{info}.livejournal.com','','','0');
339
+				$fields[] = array('1','website','Web Site','','','','1');
340
+				$fields[] = array('5','AOL','AIM','','$output .= "<div><label for=\'AOL\'>".$field[\'field_title\'].":</label><INPUT type=\'text\' class=\'textbox\'  name=\'af_".$field[\'field_name\']."\' maxlength=\'40\' value=\'".(!empty($user[\'af_\'.$field[\'field_id\']]) ? $user[\'af_\'.$field[\'field_id\']] : "")."\' size=\'20\'></div>";','$thisfield = "<img src=\"http://big.oscar.aol.com/".$field[\'info\']."?on_url=$url/images/aim.gif&off_url=$url/images/aim.gif\"> <a href=\"aim:goim?{aol}ScreenName=".$field[\'info\']."\">".format_email($field[\'info\'])."</a>";','1');
341
+				$fields[] = array('5','ICQ','ICQ','','$output .= "<div><label for=\'AOL\'>".$field[\'field_title\'].":</label><INPUT type=\'text\' class=\'textbox\'  name=\'af_".$field[\'field_name\']."\' maxlength=\'40\' value=\'".(!empty($user[\'af_\'.$field[\'field_id\']]) ? $user[\'af_\'.$field[\'field_id\']] : "")."\' size=\'20\'></div>";','$thisfield = "<img src=\"http://status.icq.com/online.gif?icq=".$field[\'info\']."&img=5\"> ".$field[\'info\'];','1');
342
+				$fields[] = array('5','MSN','MSN IM','','$output .= "<div><label for=\'AOL\'>".$field[\'field_title\'].":</label><INPUT type=\'text\' class=\'textbox\'  name=\'af_".$field[\'field_name\']."\' maxlength=\'40\' value=\'".(!empty($user[\'af_\'.$field[\'field_id\']]) ? $user[\'af_\'.$field[\'field_id\']] : "")."\' size=\'20\'></div>";','$thisfield = "<img src=\"images/msntalk.gif\" alt=\""._MSN."\"> ".format_email($field[\'info\']);','1');
343
+				$fields[] = array('5','Yahoo','Yahoo IM','','$output .= "<div><label for=\'AOL\'>".$field[\'field_title\'].":</label><INPUT type=\'text\' class=\'textbox\'  name=\'af_".$field[\'field_name\']."\' maxlength=\'40\' value=\'".(!empty($user[\'af_\'.$field[\'field_id\']]) ? $user[\'af_\'.$field[\'field_id\']] : "")."\' size=\'20\'></div>";','$thisfield = "<a href=\"http://edit.yahoo.com/config/send_webmesg?.target=".$field[\'info\']."&.src=pg\"><img border=\'0\' src=\"http://opi.yahoo.com/online?u=".$field[\'info\']."&m=g&t=1\"> ".format_email($field[\'info\'])."</a>";','1');
344
+				$fields[] = array('4','da','Deviant Art','http://{info}.deviantart.com','','','0');
345
+				$fields[] = array('3','betareader','Beta-reader','','','','1');
346
+				$fields[] = array('4','dj','DeadJournal','http://{info}.deadjournal.com/','','','0');
347
+				$fields[] = array('4','xanga','Xanga','http://www.xanga.com/{info}','','','0');
348
+				$fields[] = array('2', 'gender', 'Gender', 'male|#|female|#|undisclosed', '', '', '0');
349
+				$fields[] = array('4','myspace','MySpace','http://www.myspace.com/{info}','','','0');
350
+		
351
+
352
+		
353
+
354
+				$output .= "<table class='tblborder' style='margin: 1em auto; padding: 1em;' cellpadding='5'><tr><th>"._FIELD."</th><th>"._RESULT."</th></tr>";
355
+				foreach($fields as $field) {
356
+					$f = dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_authorfields` (`field_type`, `field_name`, `field_title`, `field_options`, `field_code_in`, `field_code_out`, `field_on`) VALUES('".$field[0]."', '".$field[1]."','".$field[2]."','".escapestring($field[3])."','".escapestring($field[4])."','".escapestring($field[5])."','".$field[6]."');");
357
+					$output .= "<tr><td>".$field[2]."</td><td align='center'>" . ($f ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
358
+				}
359
+				$output .= "</table>";
360
+				$output .= write_message(_FIELDAUTOFAIL." "._FIELDUPDATE."<br /><br /> <a href='upgrade20.php?step=16'>"._CONTINUE."</a>");
361
+			}
362
+			else {
363
+				$output .= write_message(_FIELDMANUAL," "._FIELDUPDATE."<br /><br /><a href='upgrade20.php?step=16'>"._CONTINUE."</a>");
364
+			}
365
+		}
366
+		else $output .= write_message(_FIELDDATAINFO."<br /><br /><a href='upgrade20.php?step=15&amp;install=automatic'>"._AUTO."</a> "._OR." <a href='upgrade20.php?step=15&amp;install=manual'>"._MANUAL2."</a>");
367
+	break;
368
+	case "14":
369
+		$output .= "<div id='pagetitle'>"._CHALLENGEUPDATE."</div>";
370
+		include("../config.php");
371
+		$settings = dbquery("SELECT tableprefix FROM ".$settingsprefix."fanfiction_settings WHERE sitekey = '".SITEKEY."'");
372
+
373
+		$challenges = dbquery("SELECT chalid, characters FROM ".TABLEPREFIX."fanfiction_challenges");
374
+		if(dbnumrows($challenges)) {
375
+			if(isset($_GET['install'])) {
376
+				$altersettings = dbquery("ALTER TABLE `".$settingsprefix."fanfiction_settings` ADD `anonchallenges` TINYINT( 1 ) NOT NULL DEFAULT 0");
377
+				$output .= write_message(_CHALLENGESETTING.($altersettings ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
378
+				$alter = dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_challenges` ADD `responses` int(11) NOT NULL DEFAULT 0");
379
+				$output .= write_message(_CHALLENGESALTER.($alter ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
380
+				dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_codeblocks` (`code_text`, `code_type`, `code_module`) VALUES ( 'include(_BASEDIR.\"modules/challenges/authorof.php\");', 'AO', 'challenges');");
381
+				dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_codeblocks` (`code_text`, `code_type`, `code_module`) VALUES ('include(_BASEDIR.\"modules/challenges/storyblock.php\");', 'storyblock', 'challenges');");
382
+				dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_codeblocks` (`code_text`, `code_type`, `code_module`) VALUES ('include(_BASEDIR.\"modules/challenges/seriesblock.php\");', 'seriesblock', 'challenges');");
383
+				dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_codeblocks` (`code_text`, `code_type`, `code_module`) VALUES ('include(_BASEDIR.\"modules/challenges/seriestitle.php\");', 'seriestitle', 'challenges');");
384
+				dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_codeblocks` (`code_text`, `code_type`, `code_module`) VALUES ('include(_BASEDIR.\"modules/challenges/adminfunctions.php\");', 'delchar', 'challenges');");
385
+				dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_codeblocks` (`code_text`, `code_type`, `code_module`) VALUES ('include(_BASEDIR.\"modules/challenges/adminfunctions.php\");', 'delcategory', 'challenges');");
386
+				dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_codeblocks` (`code_text`, `code_type`, `code_module`) VALUES ('include(_BASEDIR.\"modules/challenges/otherresults.php\");', 'otherresults', 'challenges');");
387
+				dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_codeblocks` (`code_text`, `code_type`, `code_module`) VALUES('include(_BASEDIR.\"modules/challenges/stats.php\");', 'sitestats', 'challenges');");
388
+				$proquery = dbquery("SELECT count(panel_id) FROM `".TABLEPREFIX."fanfiction_panels` WHERE panel_type = 'P' AND panel_hidden = '0'");
389
+				list($profiles) = dbrow($proquery);
390
+				$profiles++;
391
+				dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_panels` (`panel_name`, `panel_title`, `panel_url`, `panel_level`, `panel_order`, `panel_hidden`, `panel_type`) VALUES ('challengesby', 'Challenges by {author}', 'modules/challenges/challengesby.php', 0, $profiles, 0, 'P');");
392
+				$userquery = dbquery("SELECT count(panel_id) FROM `".TABLEPREFIX."fanfiction_panels` WHERE panel_type = 'U' AND panel_hidden = '0'");
393
+				list($userpanels) = dbrow($userquery);
394
+				$userpanels++;
395
+				dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_panels` (`panel_name`, `panel_title`, `panel_url`, `panel_level`, `panel_order`, `panel_hidden`, `panel_type`) VALUES ('challengesby', 'Your Challenges', 'modules/challenges/challengesby.php', 0, $userpanels, 0, 'U');");
396
+				$adminquery = dbquery("SELECT count(panel_id) FROM `".TABLEPREFIX."fanfiction_panels` WHERE panel_type = 'A' AND panel_hidden = '0'");
397
+				list($adminpanels) = dbrow($adminquery);
398
+				$adminpanels++;
399
+				dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_panels` (`panel_name` , `panel_title` , `panel_url` , `panel_level` , `panel_order` , `panel_hidden` , `panel_type` ) VALUES ('challenges', 'Challenges', 'modules/challenges/admin.php', '1', $adminpanels, 0, 'A');");
400
+				$topquery = dbquery("SELECT count(panel_id) FROM `".TABLEPREFIX."fanfiction_panels` WHERE panel_type = 'L' AND panel_hidden = '0'");
401
+				list($listpanels) = dbrow($topquery);
402
+				$listpanels++;
403
+				dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_panels` (`panel_name` , `panel_title` , `panel_url` , `panel_level` , `panel_order` , `panel_hidden` , `panel_type` ) VALUES ('challenges', 'Top 10 Challenges', 'modules/challenges/topchallenges.php', '0', $listpanels, 0, 'L');");
404
+				$browsequery = dbquery("SELECT count(panel_id) FROM `".TABLEPREFIX."fanfiction_panels` WHERE panel_type = 'B' AND panel_hidden = '0'");
405
+				list($browse) = dbrow($browsequery);
406
+				$browse++;
407
+				dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_panels` (`panel_name` , `panel_title` , `panel_url` , `panel_level` , `panel_order` , `panel_hidden` , `panel_type` ) VALUES ('challenges', 'Challenges', 'browse.php?type=challenges', '0', $browse, 0, 'B');");
408
+				dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_pagelinks` (`link_name`, `link_text`, `link_url`, `link_target`, `link_access`) VALUES ('challenges', 'Challenges', 'browse.php?type=challenges', '0', 0);");
409
+				$characters = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_characters");
410
+				while($char = dbassoc($characters)) {
411
+					$charlist[stripslashes($char['charname'])] = $char['charid'];
412
+				}
413
+				while($c = dbassoc($challenges)) {
414
+					unset($newchars, $count, $count1, $count2);
415
+					if($c['characters']) {
416
+						$chars = explode(",", $c['characters']);
417
+						foreach($chars as $char) {
418
+							if(isset($charlist[$char])) $newchars[] = $charlist[$char];
419
+						}
420
+					}
421
+					$stories = dbquery("SELECT COUNT(sid) AS count FROM ".TABLEPREFIX."fanfiction_stories WHERE FIND_IN_SET('".$c['chalid']."', challenges) > 0");
422
+					list($count1) = dbrow($stories);
423
+					$series = dbquery("SELECT COUNT(seriesid) FROM ".TABLEPREFIX."fanfiction_series WHERE FIND_IN_SET('".$c['chalid']."', challenges) > 0");
424
+					list($count2) = dbrow($series);
425
+					$count = $count1 + $count2;
426
+					dbquery("UPDATE ".TABLEPREFIX."fanfiction_challenges SET  responses = '$count', characters = '".(isset($newchars) ? implode(",", $newchars) : "")."' WHERE chalid = $c[chalid]");
427
+				}
428
+				$output .= write_message("<a href='upgrade20.php?step=15'>"._CONTINUE."</a>");				
429
+			}
430
+			else $output .= write_message(_CHALLENGEUPDATEINFO."<br /><a href='upgrade20.php?step=14&amp;install=automatic'>"._CONTINUE."</a>");
431
+		}
432
+		else $output .= write_message(_CHALLENGESEMPTY."<a href='upgrade20.php?step=15'>"._CONTINUE."</a>");
433
+	break;
434
+	case "13":
435
+		$output .= "<div id='pagetitle'>"._FAVUPDATE."</div>";
436
+		if(isset($_GET['install'])) {
437
+
438
+
439
+	
440
+			$favst = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_favorites(uid, item, type) SELECT uid, sid, 'ST' FROM ".TABLEPREFIX."fanfiction_favstor");
441
+			$output .= write_message(_FAV1.($favst ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
442
+			$favse = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_favorites(uid, item, type) SELECT uid, seriesid, 'SE' FROM ".TABLEPREFIX."fanfiction_favseries");
443
+			$output .= write_message(_FAV2.($favse ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
444
+			$favau = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_favorites(uid, item, type) SELECT uid, favuid, 'AU' FROM ".TABLEPREFIX."fanfiction_favauth");
445
+			$output .= write_message(_FAV3.($favau ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
446
+			$drop1 = dbquery("DROP TABLE `".TABLEPREFIX."fanfiction_favstor`");
447
+			$output .= write_message(_FAV4.($drop1 ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
448
+			$drop2 = dbquery("DROP TABLE `".TABLEPREFIX."fanfiction_favseries`");
449
+			$output .= write_message(_FAV5.($drop2 ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
450
+			$drop3 = dbquery("DROP TABLE `".TABLEPREFIX."fanfiction_favauth`");
451
+			$output .= write_message(_FAV6.($drop3 ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
452
+			$output .= write_message("<a href='upgrade20.php?step=14'>"._CONTINUE."</a>");		
453
+		}
454
+		else $output .= write_message(_FAVUPDATEINFO."<br /><a href='upgrade20.php?step=13&amp;install=automatic'>"._CONTINUE."</a>");
455
+	break;
456
+	case "12":
457
+		$output .= "<div id='pagetitle'>"._REVIEWUPDATE."</div>";
458
+		if(isset($_GET['install'])) {
459
+
460
+
461
+	
462
+			$alter = dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_reviews` CHANGE `sid` `item` INT( 11 ) NOT NULL DEFAULT '0'");
463
+			$output .= write_message(_REVIEWALTER1.($alter ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
464
+			$alter2 = dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_reviews` ADD `type` VARCHAR( 2 ) NOT NULL DEFAULT 'ST'");
465
+			$output .= write_message(_REVIEWALTER2.($alter2 ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
466
+			$alter3 = dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_reviews` CHANGE `member` `uid` INT( 11 ) NOT NULL DEFAULT '0'");
467
+			$output .= write_message(_REVIEWALTER3.($alter3 ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
468
+			$update1 = dbquery("UPDATE ".TABLEPREFIX."fanfiction_reviews SET type = 'ST' WHERE item > 0");
469
+			$output .= write_message(_REVIEWUPDATE1.($update1 ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
470
+			$update2 = dbquery("UPDATE ".TABLEPREFIX."fanfiction_reviews SET type = 'SE', item = seriesid WHERE seriesid > 0");
471
+			$output .= write_message(_REVIEWUPDATE2.($update2 ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
472
+			$alter4 = dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_reviews` DROP `seriesid`");
473
+			$output .= write_message(_REVIEWALTER4.($alter4 ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
474
+			$output .= write_message("<a href='upgrade20.php?step=13'>"._CONTINUE."</a>");
475
+		}
476
+		else $output .= write_message(_REVIEWUPDATEINFO."<br /><a href='upgrade20.php?step=12&amp;install=automatic'>"._CONTINUE."</a>");
477
+
478
+	break;
479
+	case "11":
480
+		$output .= "<div id='pagetitle'>"._UPDATESTORIES."</div>";
481
+		if(isset($_GET['install'])) {
482
+
483
+
484
+	
485
+			$characters = dbquery("SELECT charid, charname FROM ".TABLEPREFIX."fanfiction_characters");
486
+				while($char = dbassoc($characters)) {
487
+				$character[stripslashes($char[charname])] = $char[charid];
488
+			}
489
+			$ratlist = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_ratings");
490
+			while($rate = dbassoc($ratlist)) {
491
+				$ratingslist[$rate['rating']] = $rate['rid'];
492
+			}
493
+			$classresults = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_classes");
494
+			while($class = dbassoc($classresults)) {
495
+				$classlist[$class['class_name']] = array("id" => $class['class_id'], "type" => $class['class_type'], "name" => $class['class_name']);
496
+			}
497
+			$offset = isset($_GET['offset']) ? $_GET['offset'] : 0;
498
+			$stories = dbquery("SELECT sid, gid, wid, charid, rid FROM ".TABLEPREFIX."fanfiction_stories LIMIT $offset, 200");
499
+			while($story = dbassoc($stories)) {
500
+				unset($genres, $warnings, $g, $w, $classes, $characters, $c, $clist, $rid);
501
+				$characters = explode(",", $story['charid']);
502
+				foreach($characters as $c) {
503
+					$clist[] = $character[$c];
504
+				}
505
+				$genres = explode(",", $story['gid']);
506
+				foreach($genres as $g) {
507
+					if($g && $g != " " && $classlist[$g]['type'] == 1) $classes[] = $classlist[$g]['id'];
508
+				}
509
+				$warnings = explode(",", $story['wid']);
510
+				foreach($warnings as $w) {
511
+					if($w && $w != " " && $classlist[$w]['type'] == 2) $classes[] = $classlist[$w]['id'];
512
+				}
513
+				$rid = $ratingslist[$story['rid']];
514
+				dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rid = '$rid', classes = '".($classes ? implode(",", $classes) : "")."', charid = '".($clist ? implode(",", $clist) : "")."' WHERE sid = '$story[sid]'");
515
+			}
516
+			if(dbnumrows($stories)) $output .= write_message(_STORIES." ".($offset + 1)."-".($offset + dbnumrows($stories)).".<br /><a href='upgrade20.php?step=11&amp;install=automatic&amp;offset=".($offset+200)."'>"._CONTINUE."</a>");
517
+			else {
518
+				$seriesquery = dbquery("SELECT seriesid, genres, warnings FROM ".TABLEPREFIX."fanfiction_series");
519
+				while($series = dbassoc($seriesquery)) {
520
+					unset($genres, $warnings, $g, $w, $classes);
521
+					$genres = explode(",", $series[genres]);
522
+					foreach($genres as $g) {
523
+						if($g && $g != " " && $classlist[$g]['type'] == 1) $classes[] = $classlist[$g]['id'];
524
+					}
525
+					$warnings = explode(",", $series[warnings]);
526
+					foreach($warnings as $w) {
527
+						if($w && $w != " " && $classlist[$w]['type'] == 2) $classes[] = $classlist[$w]['id'];
528
+					}
529
+					dbquery("UPDATE ".TABLEPREFIX."fanfiction_series SET classes = '".($classes ? implode(",", $classes) : "")."' WHERE seriesid = '$series[seriesid]'");
530
+				}
531
+				dbquery("UPDATE ".TABLEPREFIX."fanfiction_inseries SET confirmed = 1");
532
+				$drop1 = dbquery("ALTER TABLE ".TABLEPREFIX."fanfiction_stories drop `gid`, drop `wid`;");
533
+				$output .= write_message(_DROPGWSTORIES.($drop1 ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));				
534
+				$output .= write_message((dbnumrows($seriesquery) ? _SERIES." 1-".dbnumrows($seriesquery)."<br />" : "")."<a href='upgrade20.php?step=12'>"._CONTINUE."</a>");
535
+			}
536
+		}
537
+		else $output .= write_message(_UPDATESTORIESINFO."<br /><a href='upgrade20.php?step=11&amp;install=automatic'>"._CONTINUE."</a>");
538
+	break;
539
+	case "10":
540
+		$output .= "<div id='pagetitle'>"._UPDATESTORIESTABLE."</div>";
541
+		if(isset($_GET['install'])) {
542
+			if($_GET['install'] == "automatic") {
543
+	
544
+
545
+		
546
+				$result = dbquery("ALTER TABLE ".TABLEPREFIX."fanfiction_stories ADD `classes` VARCHAR( 200 ) NULL AFTER `catid`;");
547
+				$result = dbquery("ALTER TABLE ".TABLEPREFIX."fanfiction_series ADD `classes` VARCHAR( 200 ) NULL AFTER `catid`;");
548
+				$result = dbquery("ALTER TABLE ".TABLEPREFIX."fanfiction_series CHANGE `owner` `uid` INT( 11 ) NOT NULL DEFAULT '0'");
549
+				$result = dbquery("ALTER TABLE ".TABLEPREFIX."fanfiction_stories CHANGE `summary` `summary` TEXT NULL");
550
+				$result = dbquery("ALTER TABLE ".TABLEPREFIX."fanfiction_series CHANGE `summary` `summary` TEXT NULL");
551
+				$result = dbquery("ALTER TABLE ".TABLEPREFIX."fanfiction_stories ADD `coauthors` tinyint(1) NOT NULL default '0' AFTER `uid`");
552
+				$result = dbquery("ALTER TABLE ".TABLEPREFIX."fanfiction_stories ADD `count` INT( 11 ) NOT NULL DEFAULT '0' AFTER `reviews`;");
553
+				$result = dbquery("ALTER TABLE ".TABLEPREFIX."fanfiction_stories ADD `storynotes` TEXT NULL AFTER `summary`;");
554
+				$result = dbquery("ALTER TABLE ".TABLEPREFIX."fanfiction_chapters ADD `endnotes` TEXT NULL AFTER `storytext`;");
555
+				$result = dbquery("ALTER TABLE ".TABLEPREFIX."fanfiction_chapters ADD `count` INT( 11 ) NOT NULL DEFAULT '0' AFTER `uid`;");
556
+
557
+				if($result) $output .= write_message(_ACTIONSUCCESSFUL."<br /> <a href='upgrade20.php?step=11'>"._CONTINUE."</a>");
558
+			}
559
+			else if($_GET['install'] == "manual") {
560
+				$output .= write_message(_UPDATESTORIESTABLEMANUAL."<br /> <a href='upgrade20.php?step=11'>"._CONTINUE."</a>");
561
+			}
562
+		}
563
+		else {
564
+
565
+			$output .= write_message(_UPDATESTORIESTABLEINFO." <a href='upgrade20.php?step=10&amp;install=automatic'>"._AUTO."</a> "._OR." <a href='upgrade20.php?step=10&amp;install=manual'>"._MANUAL2."</a>");
566
+		}
567
+	break;
568
+	case "9":
569
+		$output .= "<div id='pagetitle'>"._MOVECLASSES."</div>";
570
+		if(isset($_GET['install'])) {
571
+
572
+
573
+	
574
+			$newclass = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_classtypes (`classtype_name`, `classtype_title`) VALUES('genres', 'Genres');");
575
+			$genres = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_genres");
576
+			$output .= "<table class='tblborder' style='margin: 1em auto; padding: 1em;' cellpadding='5'><tr><th>Genres</th><th>Result</th></tr>";
577
+			while($g = dbassoc($genres)) {
578
+				$result = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_classes (`class_type`, `class_name`) VALUES('1', '".$g['genre']."')");
579
+				$output .= "<tr><td>".$g['genre']."</td><td align='center'>" . ($result ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
580
+			}
581
+			$output .= "</table>";
582
+			// Ditto with the warnings
583
+			$newclass = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_classtypes (`classtype_name`, `classtype_title`) VALUES('warnings', 'Warnings');");
584
+			$output .= "<table class='tblborder' style='margin: 1em auto; padding: 1em;' cellpadding='5'><tr><th>Warnings</th><th>Result</th></tr>";
585
+			$warnings = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_warnings");
586
+			while($w = dbassoc($warnings)) {
587
+				$result = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_classes (`class_type`, `class_name`) VALUES('2', '$w[warning]')");
588
+				$output .= "<tr><td>".$w['warning']."</td><td align='center'>" . ($result ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
589
+			}
590
+			$output .= "</table>";
591
+			$drop1 = dbquery("DROP TABLE `".TABLEPREFIX."fanfiction_genres`");
592
+			$output .= write_message(_DROPGENRES.($drop1 ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
593
+			$drop2 = dbquery("DROP TABLE `".TABLEPREFIX."fanfiction_warnings`");
594
+			$output .= write_message(_DROPWARNINGS.($drop2 ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">"));
595
+			
596
+			$output .= write_message(_MOVECLASSFAIL."<br /><a href='upgrade20.php?step=10'>continue</a>");
597
+		}
598
+		else $output .= write_message(_MOVECLASSESINFO."<br /><a href='upgrade20.php?step=9&amp;install=automatic'>"._CONTINUE."</a>");
599
+	break;
600
+	case "8":
601
+		$output .= "<div id='pagetitle'>"._MESSAGEDATA."</div>";
602
+		if(isset($_GET['install'])) {
603
+			if($_GET['install'] == "automatic") {
604
+	
605
+
606
+		
607
+				$directory = opendir("../messages");
608
+				$output .= "<table class='tblborder' style='margin: 1em auto; padding: 1em;' cellpadding='5'><tr><th>Message</th><th>Result</th></tr>";
609
+				while($filename = readdir($directory)) {
610
+					if($filename=="." || $filename=="..") continue;
611
+					$text = "";
612
+					$out = fopen ("../messages/".$filename, "r");
613
+					while (!feof($out)) { $text .= fgets($out, 10000); }
614
+					$msgname = substr($filename, 0, strrpos($filename, "."));
615
+					$msg = dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_messages` (`message_name`, `message_title`, `message_text`) VALUES ('$msgname', '".$defaulttitles[$msgname]."', '".addslashes($text)."');");
616
+				$output .= "<tr><td>".$defaulttitles[$msgname]."</td><td align='center'>" . ($msg ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
617
+				}
618
+				$msg = dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_messages` (`message_name`, `message_title`, `message_text`) VALUES('maintenance', 'Site Maintenance', '<p style=\"text-align: center;\">This site is currently undergoing maintenance.  Please check back soon.  Thank you.</p>');");
619
+				$msg = dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_messages` (`message_name`, `message_title`, `message_text`) VALUES ('tos', 'Terms of Service', 'This is the Terms of Service for your site.  It will be displayed when a new member registers to the site.');");
620
+				$output .= "<tr><td>Terms of Service</td><td align='center'>" . ($msg ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
621
+				$output .= "<tr><td>Site Maintenance</td><td align='center'>" . ($msg ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
622
+				$output .= "</table>";
623
+				$output .= write_message(_MESSAGEAUTOFAILUPGRADE."<br /><a href='upgrade20.php?step=9'>continue</a>");
624
+			}
625
+		}
626
+		else $output .= write_message(_MESSAGEDATAUPGRADE."<br /><a href='upgrade20.php?step=8&amp;install=automatic'>"._CONTINUE."</a>");
627
+
628
+	break;
629
+	case "7":
630
+		$output .= "<div id='pagetitle'>"._BLOCKDATA."</div>";
631
+		if(isset($_GET['install'])) {
632
+			if($_GET['install'] == "automatic") {
633
+	
634
+				include("../blocks_config.php");
635
+				$blocks['news']['num'] = 1;
636
+				$blocks['recent']['num'] = 1;
637
+				define("_BASEDIR", "../");
638
+
639
+		
640
+				$output .= "<table class='tblborder' style='margin: 1em auto; padding: 1em;' cellpadding='5'><tr><th>Block</th><th>Result</th></tr>";
641
+				foreach($blocks as $block =>$value) {
642
+					unset($blockvars);
643
+					foreach($value as $var=>$val) {
644
+						if($var != "name" && $var != "title" && $var != "file" && $var != "status") $blockvars[$var] = $val;
645
+					}
646
+					$b = dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_blocks (`block_name`, `block_title`, `block_file`, `block_status`, `block_variables`) VALUES('$block', '".escapestring($value['title'])."', '".$value['file']."', '".$value['status']."', '".($blockvars ? addslashes(serialize($blockvars)) : "")."');");
647
+					$output .= "<tr><td>".$value['title']."</td><td align='center'>" . ($b ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
648
+				}
649
+				$output .= "</table>";
650
+				$output .= write_message(_BLOCKDATAFAILUPGRADE."<br /><a href='upgrade20.php?step=8'>"._CONTINUE."</a>");
651
+			}
652
+		}
653
+		else $output .= write_message(_BLOCKDATAUPGRADE." <br /><a href='upgrade20.php?step=7&amp;install=automatic'>"._CONTINUE."</a>");
654
+	break;
655
+	case "6":
656
+		$output .= "<div id='pagetitle'>"._LINKDATA."</div>";
657
+		if(isset($_GET['install'])) {
658
+			if($_GET['install'] == "automatic") {
659
+	
660
+
661
+		
662
+				$pagelist = array(
663
+					array("home","Home","index.php","0","0"),
664
+					array("recent","Most Recent","browse.php?type=recent","0","0"),
665
+					array("login","Login","user.php?action=login","0","0"),
666
+					array("adminarea","Admin","admin.php","0","2"),
667
+					array("logout","Logout","user.php?action=logout","0","1"),
668
+					array("featured","Featured Stories","browse.php?type=featured","0","0"),
669
+					array("catslink","Categories","browse.php?type=categories","0","0"),
670
+					array("members","Members","authors.php?action=list","0","0"),
671
+					array("authors","Authors","authors.php?list=authors","0","0"),
672
+					array("help","Help","viewpage.php?page=help","0","0"),
673
+					array("search","Search","search.php","0","0"),
674
+					array("series","Series","browse.php?type=series","0","0"),
675
+					array("tens","Top Tens","toplists.php","0","0"),
676
+					array("challenges","Challenges","modules/challenges/challenges.php","0","0"),
677
+					array("contactus","Contact Us","contact.php","0","0"),
678
+					array("rules","Rules","viewpage.php?page=rules","0","0"),
679
+					array("tos","Terms of Service","viewpage.php?page=tos","0","0"),
680
+					array("rss","<img src=\'images/xml.gif\' alt=\'RSS\' border=\'0\'>","rss.php","0","0"),
681
+					array("login","Account Info","user.php","0","1"),
682
+					array("titles","Titles","browse.php?type=titles","0","0"),
683
+					array("register","Register","user.php?action=register","0","0"),
684
+					array("lostpassword","Lost Password","user.php?action=lostpassword","0","0"),
685
+					array("newsarchive","News Archive","news.php","0","0"),
686
+					array("browse","Browse","browse.php","0","0"),
687
+					array("charslink", "Characters", "browse.php?type=characters","0","0"),
688
+					array("ratings", "Ratings", "browse.php?type=ratings", "0", "0"),
689
+					array("genres_link", "Genres", "browse.php?type=class&amp;type_id=1", "0", "0"),
690
+					array("warnings_link", "Warnings", "browse.php?type=class&amp;type_id=2", "0", "0")
691
+				);
692
+				$output .= "<table class='tblborder' style='margin: 1em auto; padding: 1em;' cellpadding='5'><tr><th>Pages</th><th>Result</th></tr>";
693
+				foreach($pagelist as $page) {
694
+					$pages = dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_pagelinks` (`link_name`, `link_text`, `link_url`, `link_target`, `link_access`) VALUES ('".$page[0]."', '".$page[1]."', '".$page[2]."', '".$page[3]."', '".$page[4]."');");
695
+					$output .= "<tr><td>".stripslashes($page[1])."</td><td align='center'>" . ($pages ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
696
+				}
697
+
698
+				$output .= "</table>";
699
+				$output .= write_message(_LINKAUTOFAIL."<br /><a href='upgrade20.php?step=7'>"._CONTINUE."</a>");
700
+			}
701
+			else {
702
+				$output .= write_message(_LINKMANUAL."<br /><a href='upgrade20.php?step=7'>"._CONTINUE."</a>");
703
+			}
704
+		}
705
+		else $output .= write_message(_LINKDATAINFO." "._LINKSETUP." <a href='upgrade20.php?step=6&amp;install=automatic'>automatic</a> "._OR." <a href='upgrade20.php?step=6&amp;install=manual'>manual</a>");
706
+	break;
707
+	case "5":
708
+		$output .= "<div id='pagetitle'>"._PANELDATA."</div>";
709
+		if(isset($_GET['install'])){
710
+			if($_GET['install'] == "automatic") {
711
+	
712
+
713
+		
714
+				$panellist = array(
715
+					array("submitted","Submissions", "","3","5","0","A"),
716
+					array("versioncheck", "Version Check", "", "3", "7", "0", "A"),
717
+					array("newstory","Add New Story","stories.php?action=newstory&admin=1","3","3","0","A"),
718
+					array("addseries","Add New Series","series.php?action=add","3","3","0","A"),
719
+					array("news","News","","3","5","0","A"),
720
+					array("featured","Featured Stories","","3","5","0","A"),
721
+					array("characters","Characters","","2","2","0","A"),
722
+					array("ratings","Ratings","","2","3","0","A"),
723
+					array("members","Members","","2","5","0","A"),
724
+					array("mailusers","Mail Users","","2","6","0","A"),
725
+					array("settings","Settings","","1","2","0","A"),
726
+					array("blocks","Blocks","","1","3","0","A"),
727
+					array("censor","Censor","","1","0","1","A"),
728
+					array("admins","Admins","","1","6","0","A"),
729
+					array("classifications","Classifications","","2","4","0","A"),
730
+					array("categories","Categories","","2","1","0","A"),
731
+					array("custpages","Custom Pages","","1","4","0","A"),
732
+					array("validate","Validate Submission","","3","0","1","A"),
733
+					array("yesletter","Validation Letter","","3","0","1","A"),
734
+					array("noletter","Rejection Letter","","3","0","1","A"),
735
+					array("links","Page Links","","1","5","0","A"),
736
+					array("messages","Message Settings","","2","0","1","A"),
737
+					array("login","Login","","0","0","1","U"),
738
+					array("logout","Logout","","1","5","0","U"),
739
+					array("revreceived","Reviews Received","","1","0","1","U"),
740
+					array("editprefs","Edit Preferences","","1","2","0","U"),
741
+					array("lostpassword","Lost Password","","0","0","1","U"),
742
+					array("editbio","Edit Bio","","1","1","0","U"),
743
+					array("register","Register","","0","0","1","U"),
744
+					array("manageimages","Manage Images","","1","5","0","S"),
745
+					array("manfavs","Manage Favorites","","1","4","0","U"),
746
+					array("revres","Review Response","","1","0","1","U"),
747
+					array("stats","View Your Statistics","","1","3","0","U"),
748
+					array("newstory","Add New Story","stories.php?action=newstory","1","1","0","S"),
749
+					array("newseries","Add New Series","series.php?action=add","1","3","0","S"),
750
+					array("managestories","Manage Stories","stories.php?action=viewstories","1","2","0","S"),
751
+					array("manageseries","Manage Series","series.php?action=manage","1","4","0","S"),
752
+					array("reviewsby","Your Reviews","","1","0","1","U"),
753
+					array("storiesby","Stories by {author}","","0","1","0","P"),
754
+					array("seriesby","Series by {author}","","0","2","0","P"),
755
+					array("reviewsby","Reviews by {author}","","0","3","0","P"),
756
+					array("categories","Categories","","0","1","0","B"),
757
+					array("characters","Characters","","0","2","0","B"),
758
+					array("ratings","Ratings","","0","3","0","B"),
759
+					array("titles","Titles","","0","5","0","B"),
760
+					array("class","Classes","","0","0","1","B"),
761
+					array("recent","Most Recent","","0","0","1","B"),
762
+					array("featured","Featured Stories","","0","0","1","B"),
763
+					array("panels","Panels","","1","1","0","A"),
764
+					array("phpinfo","PHP Info","","1","7","0","A"),
765
+					array("contact","Contact","","0","0","1","P"),
766
+					array("series", "Series", "", "0", "4", "0", "B"),
767
+					array("viewlog", "Action Log", "", "1", "8", "0", "A"),
768
+					array("shortstories","10 Shortest Stories","toplists/default.php","0","6","0","L"), 
769
+					array("longstories","10 Longest Stories","toplists/default.php","0","5","0","L"), 
770
+					array("largeseries","10 Largest Series","toplists/default.php","0","1","0","L"), 
771
+					array("smallseries","10 Smallest Series","toplists/default.php","0","2","0","L"), 
772
+					array("reviewedseries","10 Most Reviewed Series","toplists/default.php","0","4","0","L"), 
773
+					array("prolificauthors","10 Most Prolific Authors","toplists/default.php","0","10","0","L"), 
774
+					array("prolificreviewers","10 Most Prolific Reviewers","toplists/default.php","0","12","0","L"), 
775
+					array("reviewedstories","10 Most Reviewed Stories","toplists/default.php","0","8","0","L"), 
776
+					array("readstories","10 Most Read Stories","toplists/default.php","0","9","0","L"),
777
+					array("favstories","10 Most Favorite Stories","toplists/default.php","0","7","0","L"), 
778
+					array("favauthors","10 Most Favorite Authors","toplists/default.php","0","11","0","L"), 
779
+					array("favseries","10 Most Favorite Series","toplists/default.php","0","3","0","L"), 
780
+					array("favst","Favorite Stories","","0","0","1","F"),
781
+					array("favse","Favorite Series","","0","0","1","F"),
782
+					array("favau","Favorite Authors","","0","0","1","F"),
783
+					array("favst","Favorite Stories","","0","0","1","U"),
784
+					array("favse","Favorite Series","","0","0","1","U"),
785
+					array("favau","Favorite Authors","","0","0","1","U"),
786
+					array("favlist","{author}\'s Favorites","viewuser.php?action=manfavs","0","5","0","F"),
787
+					array("skins", "Skins", "", "3", "6", "0", "A"),
788
+					array("authorfields", "Profile Information", "", "1", "9", "0", "A"),
789
+					array("maintenance", "Archive Maintenance", "", "1", "10", "0", "A"),
790
+					array("manual", "Admin Manual", "", "3", "6", "0", "A"),
791
+					array('modules', 'Modules', '', 1, "11", 0, 'A')
792
+				);
793
+				$output .= "<table class='tblborder' style='margin: 1em auto; padding: 1em;' cellpadding='5'><tr><th>Panel</th><th>Result</th></tr>";
794
+				foreach($panellist as $panel) {
795
+					unset($panels);
796
+					$panels = dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_panels` (`panel_name`, `panel_title`, `panel_url`, `panel_level`, `panel_order`, `panel_hidden`, `panel_type`) VALUES ('".$panel[0]."', '".$panel[1]."', '".$panel[2]."', '".$panel[3]."', '".$panel[4]."', '".$panel[5]."', '".$panel[6]."');");
797
+					$output .= "<tr><td>".stripslashes($panel[1])."</td><td align='center'>" . ($panels ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
798
+				}
799
+				$output .= "</table>";
800
+				$output .= write_message(_PANELAUTOFAIL."<br /> <a href='upgrade20.php?step=6'>"._CONTINUE."</a>");
801
+			}
802
+			else {
803
+				$output .= write_message(_PANELMANUAL."<br /> <a href='upgrade20.php?step=6'>"._CONTINUE."</a>");
804
+			}
805
+		}
806
+		else $output .= write_message(_PANELDATAINFO." "._PANELSETUP." <a href='upgrade20.php?step=5&amp;install=automatic'>"._AUTO."</a> "._OR." <a href='upgrade20.php?step=5&amp;install=manual'>"._MANUAL2."</a>");
807
+	break;
808
+	case "4":
809
+		$output .= "<div id='pagetitle'>"._INSTALLTABLES."</div>";
810
+		if(isset($_GET['install'])) {
811
+			if($_GET['install'] == "automatic") {
812
+	
813
+
814
+		
815
+				$output .= "<table class='tblborder' style='margin: 1em auto; padding: 1em;' cellpadding='5'><tr><th>Table</th><th>Result</th></tr>";
816
+				$authorfields = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_authorfields` (
817
+  `field_id` int(11) NOT NULL AUTO_INCREMENT,
818
+  `field_type` tinyint(4) NOT NULL default '0',
819
+  `field_name` varchar(30) NOT NULL default ' ',
820
+  `field_title` varchar(255) NOT NULL default ' ',
821
+  `field_options` text,
822
+  `field_code_in` text,
823
+  `field_code_out` text,
824
+  `field_on` tinyint(1) NOT NULL default '0',
825
+  PRIMARY KEY  (`field_id`)
826
+) TYPE=MyISAM;");
827
+$output .= "<tr><td>".TABLEPREFIX."fanfiction_authorfields</td><td align='center'>" . ($authorfields ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
828
+				$authorinfo = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_authorinfo` (
829
+  `uid` int(11) NOT NULL default '0',
830
+  `field` int(11) NOT NULL default '0',
831
+  `info` varchar(255) NOT NULL default ' ',
832
+  PRIMARY KEY  (`uid`,`field`),
833
+  KEY `uid` (`uid`)) TYPE=MyISAM;");
834
+$output .= "<tr><td>".TABLEPREFIX."fanfiction_authorinfo</td><td align='center'>" . ($authorinfo ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
835
+				$authorprefs = dbquery("
836
+CREATE TABLE `".TABLEPREFIX."fanfiction_authorprefs` (
837
+  `uid` int(11) NOT NULL default '0',
838
+  `newreviews` tinyint(1) NOT NULL default '0',
839
+  `newrespond` tinyint(1) NOT NULL default '0',
840
+  `ageconsent` tinyint(1) NOT NULL default '0',
841
+  `alertson` tinyint(1) NOT NULL default '0',
842
+  `tinyMCE` tinyint(1) NOT NULL default '0',
843
+  `sortby` tinyint(1) NOT NULL default '0',
844
+  `storyindex` tinyint(1) NOT NULL default '0',
845
+  `validated` tinyint(1) NOT NULL default '0',
846
+  `userskin` varchar(60) NOT NULL default 'default',
847
+  `level` tinyint(1) NOT NULL default '0',
848
+  `categories` varchar(200) NOT NULL default '0',
849
+  `contact` tinyint(1) NOT NULL default '0',
850
+  `stories` int(11) NOT NULL default '0',
851
+   PRIMARY KEY  (`uid`)
852
+) TYPE=MyISAM;");
853
+$output .= "<tr><td>".TABLEPREFIX."fanfiction_authorprefs</td><td align='center'>" . ($authorprefs ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";				
854
+				$blocks = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_blocks` (
855
+  `block_id` int(11) NOT NULL auto_increment,
856
+  `block_name` varchar(30) NOT NULL default '',
857
+  `block_title` varchar(150) NOT NULL default '',
858
+  `block_file` varchar(200) NOT NULL default '',
859
+  `block_status` tinyint(1) NOT NULL default '0',
860
+  `block_variables` text NOT NULL,
861
+  PRIMARY KEY  (`block_id`),
862
+  KEY `block_name` (`block_name`)
863
+) TYPE=MyISAM;");
864
+$output .= "<tr><td>".TABLEPREFIX."fanfiction_blocks</td><td align='center'>" . ($blocks ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
865
+				$classes = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_classes` (
866
+  `class_id` int(11) NOT NULL auto_increment,
867
+  `class_type` int(11) NOT NULL default '0',
868
+  `class_name` varchar(100) NOT NULL default '',
869
+  PRIMARY KEY  (`class_id`),
870
+  KEY `byname` (`class_type`,`class_name`,`class_id`)
871
+) TYPE=MyISAM;");
872
+$output .= "<tr><td>".TABLEPREFIX."fanfiction_classes</td><td align='center'>" . ($classes ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
873
+				$classtypes = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_classtypes` (
874
+  `classtype_id` int(11) NOT NULL auto_increment,
875
+  `classtype_name` varchar(50) NOT NULL default '',
876
+  `classtype_title` varchar(50) NOT NULL default '',
877
+  PRIMARY KEY  (`classtype_id`),
878
+  UNIQUE KEY `classtype_name` (`classtype_name`)
879
+) TYPE=MyISAM;");
880
+$output .= "<tr><td>".TABLEPREFIX."fanfiction_classtypes</td><td align='center'>" . ($classtypes ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
881
+$coauthors = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_coauthors` (
882
+  `sid` int(11) NOT NULL default '0',
883
+  `uid` int(11) NOT NULL default '0',
884
+  PRIMARY KEY  (`sid`,`uid`)
885
+) TYPE=MyISAM;");
886
+$output .= "<tr><td>".$tableprefix."fanfiction_coauthors</td><td align='center'>" . ($coauthors ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
887
+				$codeblocks = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_codeblocks` (
888
+  `code_id` int(11) NOT NULL auto_increment,
889
+  `code_text` text NOT NULL,
890
+  `code_type` varchar(20) default NULL,
891
+  `code_module` varchar(60) default NULL,
892
+  PRIMARY KEY  (`code_id`),
893
+  KEY `code_type` (`code_type`)
894
+) TYPE=MyISAM;");
895
+$output .= "<tr><td>".TABLEPREFIX."fanfiction_codeblocks</td><td align='center'>" . ($codeblocks ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
896
+				$favorites = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_favorites` (
897
+  `uid` int(11) NOT NULL default '0',
898
+  `item` int(11) NOT NULL default '0',
899
+  `type` char(2) NOT NULL default '',
900
+  `comments` text NOT NULL,
901
+  UNIQUE KEY `byitem` (`item`,`type`,`uid`),
902
+  UNIQUE KEY `byuid` (`uid`,`type`,`item`)
903
+) TYPE=MyISAM;");
904
+$output .= "<tr><td>".TABLEPREFIX."fanfiction_favorites</td><td align='center'>" . ($favorites ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
905
+				$logs = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_log` (
906
+  `log_id` int(11) NOT NULL auto_increment,
907
+  `log_action` varchar(255) default NULL,
908
+  `log_uid` int(11) NOT NULL,
909
+  `log_ip` int(11) UNSIGNED default NULL,
910
+  `log_timestamp` timestamp NOT NULL,
911
+  `log_type` varchar(2) NOT NULL,
912
+  PRIMARY KEY  (`log_id`)
913
+) TYPE=MyISAM");
914
+$output .= "<tr><td>".TABLEPREFIX."fanfiction_log</td><td align='center'>" . ($logs ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
915
+				$messages = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_messages` (
916
+  `message_id` int(11) NOT NULL auto_increment,
917
+  `message_name` varchar(50) NOT NULL default '',
918
+  `message_title` varchar(200) NOT NULL default '',
919
+  `message_text` text NOT NULL,
920
+  PRIMARY KEY  (`message_id`),
921
+  KEY `message_name` (`message_name`)
922
+) TYPE=MyISAM;");
923
+$output .= "<tr><td>".TABLEPREFIX."fanfiction_messages</td><td align='center'>" . ($messages ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
924
+				$modules = dbquery("
925
+CREATE TABLE `".TABLEPREFIX."fanfiction_modules` (
926
+  `id` int(11) NOT NULL auto_increment,
927
+  `name` varchar(100) NOT NULL default 'Test Module',
928
+  `version` varchar(10) NOT NULL default '1.0',
929
+  PRIMARY KEY  (`id`),
930
+  KEY `name_version` (`name`,`version`)
931
+)");
932
+$output .= "<tr><td>".TABLEPREFIX."fanfiction_modules</td><td align='center'>" . ($modules ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
933
+				$pagelinks = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_pagelinks` (
934
+  `link_id` int(11) NOT NULL auto_increment,
935
+  `link_name` varchar(50) NOT NULL default '',
936
+  `link_text` varchar(100) NOT NULL default '',
937
+  `link_key` CHAR( 1 ) NULL,
938
+  `link_url` varchar(250) NOT NULL default '',
939
+  `link_target` char(1) NOT NULL default '0',
940
+  `link_access` tinyint(4) NOT NULL default '0',
941
+  PRIMARY KEY  (`link_id`),
942
+  KEY `link_name` (`link_name`)
943
+) TYPE=MyISAM;");
944
+$output .= "<tr><td>".TABLEPREFIX."fanfiction_pagelinks</td><td align='center'>" . ($pagelinks ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
945
+				$panels = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_panels` (
946
+  `panel_id` int(11) NOT NULL auto_increment,
947
+  `panel_name` varchar(50) NOT NULL default 'unknown',
948
+  `panel_title` varchar(100) NOT NULL default 'Unnamed Panel',
949
+  `panel_url` varchar(100) default NULL,
950
+  `panel_level` tinyint(4) NOT NULL default '3',
951
+  `panel_order` tinyint(4) NOT NULL default '0',
952
+  `panel_hidden` tinyint(1) NOT NULL default '0',
953
+  `panel_type` varchar(20) NOT NULL default 'A',
954
+  PRIMARY KEY  (`panel_id`),
955
+  KEY `panel_type` (`panel_type`,`panel_name`)
956
+) TYPE=MyISAM;");
957
+$output .= "<tr><td>".TABLEPREFIX."fanfiction_panels</td><td align='center'>" . ($panels ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
958
+	$stats = dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_stats` (
959
+  `sitekey` varchar(50) NOT NULL default '0',
960
+  `stories` int(11) NOT NULL default '0',
961
+  `chapters` int(11) NOT NULL default '0',
962
+  `series` int(11) NOT NULL default '0',
963
+  `reviews` int(11) NOT NULL default '0',
964
+  `wordcount` int(11) NOT NULL default '0',
965
+  `authors` int(11) NOT NULL default '0',
966
+  `members` int(11) NOT NULL default '0',
967
+  `reviewers` int(11) NOT NULL default '0',
968
+  `newestmember` int(11) NOT NULL default '0'
969
+) TYPE=MyISAM");
970
+	dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_stats(`sitekey`, `newestmember`) VALUES('".SITEKEY."', '1')");
971
+$output .= "<tr><td>".TABLEPREFIX."fanfiction_stats</td><td align='center'>" . ($stats ? "<img src=\"../images/check.gif\">" : "<img src=\"../images/X.gif\">") ."</td></tr>";
972
+$output .= "</table>";
973
+$output .= write_message(_NEWTABLEAUTOFAIL."<br /> <a href='upgrade20.php?step=5'>"._CONTINUE."</a>");
974
+			}
975
+			else if($_GET['install'] == "manual") {
976
+				$output .= write_message(_NEWTABLESSETUP."<br /> <a href='upgrade20.php?step=5'>"._CONTINUE."</a>");
977
+			}
978
+		}
979
+		else {
980
+
981
+			$output .= write_message(_NEWTABLESSETUP." <a href='upgrade20.php?step=4&amp;install=automatic'>"._AUTO."</a> "._OR." <a href='upgrade20.php?step=4&amp;install=manual'>"._MANUAL2."</a>");
982
+		}
983
+	break;
984
+	case "3":			
985
+		if(!$_GET['sect']) $sect = "main";
986
+		else $sect = $_GET['sect'];
987
+		$settingsresults = dbquery("SELECT * FROM ".$settingsprefix."fanfiction_settings WHERE sitekey = '".$sitekey."'");
988
+		if(dbnumrows($settingsresults) == 0) {
989
+			dbquery("INSERT INTO ".$settingsprefix."fanfiction_settings (`sitekey`) VALUES('".$sitekey."');");
990
+			$settingsresults = dbquery("SELECT * FROM ".$settingsprefix."fanfiction_settings WHERE sitekey = '".SITEKEY."'");
991
+		}
992
+		$settings = dbassoc($settingsresults);
993
+			foreach($settings as $var => $val) {
994
+			$$var = stripslashes($val);
995
+		}
996
+		define("SITEKEY", $sitekey);
997
+		define("TABLEPREFIX", $tableprefix);
998
+		define("STORIESPATH", $settings['storiespath']);
999
+		if($sect == "submissions") {
1000
+			if($_POST['submit']) {
1001
+				$storiespath = descript($_POST['newstoriespath']);
1002
+				if(!file_exists($storiespath) && !file_exists("../".$storiespath)) {
1003
+					if(!strrchr($storiespath, "/") && !strrchr($storiespath, "\\")) $storiespath = "../$storiespath";
1004
+					@mkdir("$storiespath", 0755);
1005
+					@chmod("$storiespath", 0777);
1006
+				}
1007
+			}
1008
+		}
1009
+		if($sect == "main" && !isset($_POST['submit'])) $output .= write_message(_SKINWARNING);
1010
+		if($sect == "email" && $_POST['submit']) {
1011
+			$output .= "<div id=\"pagetitle\">"._SETTINGS."</div>";
1012
+			$smtp_host = $_POST['newsmtp_host'];
1013
+			$smtp_username = $_POST['newsmtp_username'];
1014
+			$smtp_password = $_POST['newsmtp_password'];
1015
+			$result = dbquery("UPDATE ".$settingsprefix."fanfiction_settings SET smtp_host = '$smtp_host', smtp_username = '$smtp_username', smtp_password = '$smtp_password' WHERE sitekey = '".SITEKEY."'");
1016
+			if($result) {
1017
+				$output .= write_message(_ACTIONSUCCESSFUL);
1018
+				$output .= write_message("<a href='upgrade20.php?step=4'>"._CONTINUE."</a>");
1019
+			}
1020
+			else include("../admin/settings.php");
1021
+		}
1022
+		else include("../admin/settings.php");
1023
+	break;
1024
+	case "2":
1025
+		$output .= "<div id='pagetitle'>"._CONFIGDATA."</div>";
1026
+
1027
+		if(isset($_POST['sitekey'])) {
1028
+			include("../naughtywords.php");
1029
+			// relative path
1030
+			if(file_exists("../".$databasepath."/dbconfig.php")) include("../".$databasepath."/dbconfig.php");
1031
+			// absolute path
1032
+			else if(file_exists($databasepath."/dbconfig.php")) include($databasepath."/dbconfig.php");
1033
+			include_once("../includes/dbfunctions.php");
1034
+			$dbconnect = dbconnect($dbhost, $dbuser, $dbpass, $dbname );
1035
+			$sitekey = !empty($_POST['sitekey']) ? descript($_POST['sitekey']) : random_string($randomcharset, 10);
1036
+			$settingsprefix = descript($_POST['settingsprefix']);
1037
+			$sitesettings = dbquery("INSERT INTO ".$settingsprefix."fanfiction_settings(
1038
+				`sitekey`, `sitename`, `slogan`, `url`, `siteemail`, `tableprefix`, `skin`, `language`, 
1039
+				`submissionsoff`, `storiespath`, `store`, `autovalidate`, `maxwords`, `minwords`, 
1040
+				`imageupload`, `imageheight`, `imagewidth`, `roundrobins`, `tinyMCE`, `allowed_tags`, 
1041
+				`favorites`, `multiplecats`, `newscomments`, `recentdays`, `displaycolumns`,
1042
+				`itemsperpage`, `displayindex`, `defaultsort`, `reviewsallowed`, `ratings`, 
1043
+				`anonreviews`, `revdelete`, `rateonly`, `pwdsetting`, `alertson`, `disablepopups`, 
1044
+				`agestatement`, `words`, `smtp_host`, `smtp_username`, `smtp_password`) VALUES(
1045
+				'".$sitekey."', '".addslashes(stripslashes($sitename))."', '".addslashes(stripslashes($slogan))."', '".addslashes($url)."', '".addslashes($siteemail)."',
1046
+				'$tableprefix', '$skin', '$language', $submissionsoff, '".addslashes($storiespath)."', '$store', $autovalidate,
1047
+				".($maxwords ? $maxwords : 0).", ".($minwords ? $minwords : 0).", $imageupload, ".($imageheight ? $imageheight : 0).", 
1048
+				".($imagewidth ? $imagewidth : 0).", $roundrobins, $tinyMCE, '".addslashes($allowed_tags)."',
1049
+				$favorites, ".($numcats == 1 ? 0 : 1).", $newscomments, ".($recentdays ? $recentdays : 0).", ".($columns ? $columns : 1).",
1050
+				".($itemsperpage > 0 ? $itemsperpage : 10).", ".($displayindex ? 1 : 0)." , ".($defaultsort ? 1 : 0).", 
1051
+				".($reviewsallowed ? 1 : 0).", ".($ratings ? $ratings : 0).",
1052
+				".($anonreviews ? 1 : 0).", ".($revdelete  ? 1 : 0).", ".($rateonly ? 1 : 0).", 
1053
+				".($pwdsetting ? 1 : 0).", ".($alertson ? 1 : 0).", ".($disablePopups ? 1 : 0).",
1054
+				 ".($agestatement ? 1 : 0).", '".implode(",", $words)."', '".addslashes($smtp_host)."', 
1055
+				'".addslashes($smtp_username)."', '".addslashes($smtp_password)."');");
1056
+			if($sitesettings) $output .= write_message("<img src=\"../images/check.gif\">"._SITESETTINGSMOVED);
1057
+			$handle = fopen("../config.php", 'w');
1058
+			if(!$handle) {
1059
+				@chmod("../config.php", 0666);
1060
+				$handle = fopen("../config.php", 'w');
1061
+			}
1062
+			if ($handle) {
1063
+				$text = "<?php 
1064
+\$dbhost = \"$dbhost\";
1065
+\$dbname = \"$dbname\";
1066
+\$dbuser= \"$dbuser\";
1067
+\$dbpass = \"$dbpass\";
1068
+\$sitekey = \"$sitekey\";
1069
+\$settingsprefix = \"$settingsprefix\";
1070
+
1071
+include_once(\"includes/dbfunctions.php\");
1072
+if(!empty(\$sitekey)) \$dbconnect = dbconnect(\$dbhost, \$dbuser,\$dbpass, \$dbname);
1073
+
1074
+?>";
1075
+				fwrite($handle, $text);
1076
+				fclose($handle);
1077
+				@chmod("../config.php", 0644);
1078
+				$output .= write_message("<img src=\"../images/check.gif\">"._CONFIG_WRITTEN."<br /><a href='upgrade20.php?step=3'>"._CONTINUE."</a>");
1079
+			}
1080
+			else $output .= write_message(_ERROR_CONFIGWRITE);						
1081
+		}
1082
+		else {
1083
+			$output .=  
1084
+				"<form method='POST' enctype='multipart/form-data' action='upgrade20.php?step=2' class='tblborder' style='width: 325px; margin: 1em auto;'>
1085
+						<label for='sitekey'>"._SITEKEY."</label><input type='text' name='sitekey' value='".random_string($randomcharset, 10)."' id='sitekey'><br />
1086
+						<input type='hidden' name='settingsprefix' value='".$_GET['settingsprefix']."'>
1087
+						<div style='text-align: center; margin: 1em;'><INPUT type=\"submit\"class=\"button\" name=\"submit\" value=\"submit\"></div>
1088
+					</form>";
1089
+			$output .= write_message(_HELP_SITEKEY." "._SITEKEYNOTE);
1090
+		}
1091
+	break;
1092
+	default:
1093
+		$output .= "<div id='pagetitle'>"._SETTINGSTABLE."</div>";
1094
+
1095
+		if(isset($_POST['submit'])) {
1096
+			// relative path
1097
+			if(file_exists("../".$databasepath."/dbconfig.php")) include("../".$databasepath."/dbconfig.php");
1098
+			// absolute path
1099
+			else if(file_exists($databasepath."/dbconfig.php")) include($databasepath."/dbconfig.php");
1100
+			include("../includes/dbfunctions.php");
1101
+			$dbconnect = dbconnect($dbhost, $dbuser, $dbpass, $dbname );
1102
+			$set1 = dbquery("DROP TABLE IF EXISTS ".$_POST['settingsprefix']."fanfiction_settings");
1103
+								$settings = dbquery("CREATE TABLE `".$_POST['settingsprefix']."fanfiction_settings` (
1104
+  `sitekey` varchar(50) NOT NULL default '1',
1105
+  `sitename` varchar(200) NOT NULL default 'Your Site',
1106
+  `slogan` varchar(200) NOT NULL default 'It\'s a cool site!',
1107
+  `url` varchar(200) NOT NULL default 'http://www.yoursite.com',
1108
+  `siteemail` varchar(200) NOT NULL default 'you@yoursite.com',
1109
+  `tableprefix` varchar(50) NOT NULL default '',
1110
+  `skin` varchar(50) NOT NULL default 'default',
1111
+  `hiddenskins` varchar(255) NULL default '',
1112
+  `language` varchar(10) NOT NULL default 'en',
1113
+  `submissionsoff` tinyint(1) NOT NULL default '0',
1114
+  `storiespath` varchar(20) NOT NULL default 'stories',
1115
+  `store` varchar(5) NOT NULL default 'files',
1116
+  `autovalidate` tinyint(1) NOT NULL default '0',
1117
+  `coauthallowed` int(1) NOT NULL default '0',
1118
+  `maxwords` int(11) NOT NULL default '0',
1119
+  `minwords` int(11) NOT NULL default '0',
1120
+  `imageupload` tinyint(1) NOT NULL default '0',
1121
+  `imageheight` int(11) NOT NULL default '200',
1122
+  `imagewidth` int(11) NOT NULL default '200',
1123
+  `roundrobins` tinyint(1) NOT NULL default '0',
1124
+  `allowseries` TINYINT NOT NULL DEFAULT '2',
1125
+  `tinyMCE` tinyint(1) NOT NULL default '0',
1126
+  `allowed_tags` varchar(200) NOT NULL default '<b><i><u><center><hr><p><br /><br><blockquote><ol><ul><li><img><strong><em>',
1127
+  `favorites` tinyint(1) NOT NULL default '0',
1128
+  `multiplecats` tinyint(1) NOT NULL default '0',
1129
+  `newscomments` tinyint(1) NOT NULL default '0',
1130
+  `logging` tinyint(1) NOT NULL default '0',
1131
+  `maintenance` tinyint(1) NOT NULL default '0',
1132
+  `debug` tinyint(1) NOT NULL default '0',
1133
+  `captcha` tinyint(1) NOT NULL default '0',
1134
+  `dateformat` varchar(20) NOT NULL default 'd/m/y',
1135
+  `timeformat` varchar(20) NOT NULL default '- h:i a',
1136
+  `recentdays` tinyint(2) NOT NULL default '7',
1137
+  `displaycolumns` tinyint(1) NOT NULL default '1',
1138
+  `itemsperpage` tinyint(2) NOT NULL default '25',
1139
+  `extendcats` tinyint(1) NOT NULL default '0',
1140
+  `displayindex` tinyint(1) NOT NULL default '0',
1141
+  `defaultsort` tinyint(1) NOT NULL default '0',
1142
+  `displayprofile` tinyint(1) NOT NULL default '0',
1143
+  `linkstyle` tinyint(1) NOT NULL default '0',
1144
+  `linkrange` tinyint(2) NOT NULL default '5',
1145
+  `reviewsallowed` tinyint(1) NOT NULL default '0',
1146
+  `ratings` tinyint(1) NOT NULL default '0',
1147
+  `anonreviews` tinyint(1) NOT NULL default '0',
1148
+  `revdelete` tinyint(1) NOT NULL default '0',
1149
+  `rateonly` tinyint(1) NOT NULL default '0',
1150
+  `pwdsetting` tinyint(1) NOT NULL default '0',
1151
+  `alertson` tinyint(1) NOT NULL default '0',
1152
+  `disablepopups` tinyint(1) NOT NULL default '0',
1153
+  `agestatement` tinyint(1) NOT NULL default '0',
1154
+  `words` text,
1155
+  `version` varchar(10) NOT NULL default '$version',
1156
+  `smtp_host` varchar(200) default NULL,
1157
+  `smtp_username` varchar(50) default NULL,
1158
+  `smtp_password` varchar(50) default NULL,
1159
+  PRIMARY KEY  (`sitekey`)
1160
+) TYPE=MyISAM;");
1161
+if($settings) $output .= write_message("<img src=\"../images/check.gif\"> "._SETTINGSTABLESUCCESS." <br /><a href='upgrade20.php?step=2&amp;settingsprefix=".$_POST['settingsprefix']."'>"._CONTINUE."</a>");
1162
+else $output .= write_message(_SETTINGSTABLEAUTOFAIL." <br /><a href='upgrade20.php?step=2&amp;settingsprefix=".$_POST['settingsprefix']."'>"._CONTINUE."</a> ");
1163
+		}
1164
+		else {
1165
+			$install = isset($_GET['install']) ? $_GET['install'] : false;
1166
+			if($install == "manual") {
1167
+				$output .= write_message(_SETTINGSTABLEMANUALUP."<br /><a href='upgrade20.php?step=2'>"._CONTINUE."</a>");
1168
+			}
1169
+			else if($install == "automatic") {
1170
+				$output .=  
1171
+					"<form method='POST' enctype='multipart/form-data' action='upgrade20.php?step=1' class='tblborder' style='width: 325px; margin: 1em auto;'>
1172
+						<label for='settingsprefix'>"._SETTINGSPREFIX."</label><input type='text' name='settingsprefix' id='settingsprefix' value='".$tableprefix."'><br />
1173
+						<div style='text-align: center; margin: 1em;'><INPUT type=\"submit\"class=\"button\" name=\"submit\" value=\"submit\"></div>
1174
+					</form>";
1175
+				$output .= write_message(_SETTINGSTABLENOTE);
1176
+			}
1177
+			else { 
1178
+				$output .= write_message(_SETTINGSTABLESETUP." <a href='upgrade20.php?install=automatic'>"._AUTO."</a> "._OR." <a href='upgrade20.php?install=manual'>"._MANUAL2."</a>");
1179
+			}
1180
+		}
1181
+}
1182
+$tpl->assign("output", $output);
1183
+
1184
+$tpl->printToScreen();
1185
+dbclose( );
1186
+?>
0 1187
\ No newline at end of file