Browse code

update

Jimako authored on 2023/09/07 15:28:52
Showing 1 changed files
... ...
@@ -29,306 +29,172 @@ $blocks['news']['status'] = 0;
29 29
 $blocks['info']['status'] = 0;
30 30
 
31 31
 //make a new TemplatePower object
32
-if(file_exists("$skindir/default.tpl")) $tpl = new TemplatePower( "$skindir/default.tpl" );
32
+if (file_exists("$skindir/default.tpl")) $tpl = new TemplatePower("$skindir/default.tpl");
33 33
 else $tpl = new TemplatePower("default_tpls/default.tpl");
34 34
 include("includes/pagesetup.php");
35
-if(file_exists("languages/".$language."_admin.php")) include_once("languages/".$language."_admin.php");
35
+if (file_exists("languages/" . $language . "_admin.php")) include_once("languages/" . $language . "_admin.php");
36 36
 else include_once("languages/en_admin.php");
37 37
 // end basic page setup
38 38
 
39
-if(!isADMIN) {
40
-$output .= "<script language=\"javascript\" type=\"text/javascript\">
39
+if (!isADMIN)
40
+{
41
+	$output .= "<script language=\"javascript\" type=\"text/javascript\">
41 42
 location = \"maintenance.php\";
42 43
 </script>";
43
-$tpl->assign( "output", $output );
44
-$tpl->printToScreen();
45
-dbclose( );
46
-exit( );
44
+	$tpl->assign("output", $output);
45
+	$tpl->printToScreen();
46
+	dbclose();
47
+	exit();
47 48
 }
48 49
 $oldVersion = explode(".", $settings['version']);
50
+
49 51
 $confirm = isset($_GET['confirm']) ? $_GET['confirm'] : false;
50
-if($oldVersion[0] == 3 && ($oldVersion[1] < 5 || $oldVersion[2] < 3)) {
51
-if($confirm == "yes") {
52
-	// For the slow-pokes who haven't updated to 3.1
53
-	if($oldVersion[1] == 0 ) {
54
-		list($field) = dbrow(dbquery("SELECT field_id FROM ".TABLEPREFIX."fanfiction_authorfields WHERE field_name = 'betareader'"));
55
-		dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorinfo SET info = '"._YES."' WHERE field = '$field' AND info = '1'");
56
-		dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorinfo SET info = '"._NO."' WHERE field = '$field' AND info != '"._YES."'");
57
-		dbquery("alter table ".TABLEPREFIX."fanfiction_authorinfo add primary key(uid,field);");
58
-		dbquery("alter table ".TABLEPREFIX."fanfiction_blocks drop index block_name;");
59
-		dbquery("alter table ".TABLEPREFIX."fanfiction_blocks add unique index block_name (block_name);");
60
-		dbquery("alter table ".TABLEPREFIX."fanfiction_categories drop index category;");
61
-		dbquery("alter table ".TABLEPREFIX."fanfiction_categories drop index parentcatid;");
62
-		dbquery("create index byparent on ".TABLEPREFIX."fanfiction_categories (parentcatid,displayorder);");
63
-		dbquery("create index forstoryblock on ".TABLEPREFIX."fanfiction_chapters (sid,validated);");
64
-		dbquery("create index byname on ".TABLEPREFIX."fanfiction_classes (class_type,class_name,class_id);");
65
-		dbquery("alter table ".TABLEPREFIX."fanfiction_classtypes drop index classtype_title;");
66
-		dbquery("create unique index classtype_name on ".TABLEPREFIX."fanfiction_classtypes(classtype_name);");
67
-		dbquery("create index code_type on ".TABLEPREFIX."fanfiction_codeblocks(code_type);");
68
-		dbquery("alter table ".TABLEPREFIX."fanfiction_comments drop index nid;");
69
-		dbquery("alter table ".TABLEPREFIX."fanfiction_comments add index commentlist (nid,time);");
70
-		dbquery("alter table ".TABLEPREFIX."fanfiction_favorites drop index uid;");
71
-		dbquery("create unique index byitem on ".TABLEPREFIX."fanfiction_favorites (item,type,uid);");
72
-		dbquery("create unique index byuid on ".TABLEPREFIX."fanfiction_favorites (uid,type,item);");
73
-		dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index seriesid;");
74
-		dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index inorder;");
75
-		dbquery("alter table ".TABLEPREFIX."fanfiction_inseries add index (seriesid,inorder);");
76
-		dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index sid;");
77
-		dbquery("alter table ".TABLEPREFIX."fanfiction_inseries add primary key (sid,seriesid);");
78
-		dbquery("create index message_name on ".TABLEPREFIX."fanfiction_messages (message_name);");
79
-		dbquery("alter table ".TABLEPREFIX."fanfiction_pagelinks drop index link_text;");
80
-		dbquery("alter table ".TABLEPREFIX."fanfiction_panels drop index panel_hidden;");
81
-		dbquery("alter table ".TABLEPREFIX."fanfiction_panels drop index panel_type;");
82
-		dbquery("alter table ".TABLEPREFIX."fanfiction_panels add index panel_type (panel_type,panel_name);");
83
-		dbquery("create index avgrating on ".TABLEPREFIX."fanfiction_reviews(type,item,rating);");
84
-		dbquery("alter table ".TABLEPREFIX."fanfiction_reviews drop index sid;");
85
-		dbquery("create index bychapter on ".TABLEPREFIX."fanfiction_reviews (chapid,rating);");
86
-		dbquery("alter table ".TABLEPREFIX."fanfiction_reviews add index byuid (uid,item,type);");
87
-		dbquery("alter table ".TABLEPREFIX."fanfiction_series drop index owner;");
88
-		dbquery("create index owner on ".TABLEPREFIX."fanfiction_series (uid,title);");
89
-		dbquery("alter table ".TABLEPREFIX."fanfiction_stories drop index validated;");
90
-		dbquery("create index validateduid on ".TABLEPREFIX."fanfiction_stories (validated,uid);");
91
-		dbquery("create index recent on ".TABLEPREFIX."fanfiction_stories (updated,validated);");
92
-		$alltables = dbquery("SHOW TABLES");
93
-	}
94
-	// Still a little behind.
95
-	if($oldVersion[1] < 2) { 
96
-		dbquery("
97
-CREATE TABLE `".TABLEPREFIX."fanfiction_stats` (
98
-  `sitekey` varchar(50) NOT NULL default '0',
99
-  `stories` int(11) NOT NULL default '0',
100
-  `chapters` int(11) NOT NULL default '0',
101
-  `series` int(11) NOT NULL default '0',
102
-  `reviews` int(11) NOT NULL default '0',
103
-  `wordcount` int(11) NOT NULL default '0',
104
-  `authors` int(11) NOT NULL default '0',
105
-  `members` int(11) NOT NULL default '0',
106
-  `reviewers` int(11) NOT NULL default '0',
107
-  `newestmember` int(11) NOT NULL default '0'
108
-) ENGINE=MyISAM");
109
-		dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_stats(`sitekey`) VALUES('SITEKEY')");
110
-		dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_inseries` DROP `updated`");
111
-		dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_news` ADD `comments` INT NOT NULL DEFAULT '0'");
112
-		dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_series` ADD `numstories` INT NOT NULL DEFAULT '0'");
113
-		dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_pagelinks` ADD `link_key` CHAR( 1 ) NULL AFTER `link_text`");
114
-		if(!isset($allowseries)) dbquery("ALTER TABLE `".$settingsprefix."fanfiction_settings` ADD `allowseries` TINYINT NOT NULL DEFAULT '2' AFTER `roundrobins`");
115
-		dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_log` CHANGE `log_ip` `log_ip` INT( 11 ) UNSIGNED NULL DEFAULT NULL");
116
-		dbquery("UPDATE ".TABLEPREFIX."fanfiction_inseries SET confirmed = 1");
117
-		$serieslist = dbquery("SELECT seriesid FROM ".TABLEPREFIX."fanfiction_series");
118
-		$totalseries = dbnumrows($serieslist);
119
-		while($s = dbassoc($serieslist)) {
120
-			$numstories = count(storiesInSeries($s['seriesid']));
121
-			dbquery("UPDATE ".TABLEPREFIX."fanfiction_series SET numstories = '$numstories' WHERE seriesid = ".$s['seriesid']." LIMIT 1");
122
-		}
52
+if ($oldVersion[0] == 3 && ($oldVersion[1] < 5 || $oldVersion[2] < 6))  //3.5.5
53
+{
54
+	if ($confirm == "yes")
55
+	{
56
+		if ($oldVersion[1] == 5 && $oldVersion[2] < 6)
57
+		{
58
+			/****************************************************************************************************************/
59
+			$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_authors LIKE 'date'"));
60
+			if ($tmp['Type'] == "datetime")
61
+			{ 
62
+				$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_authors LIKE 'date_tmp'"));
63
+				if (!$updated)
64
+				{
65
+					dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_authors` ADD `date_tmp` int(11) NOT NULL default '0'");
66
+				}
123 67
 
124
-		$newslist = dbquery("SELECT count(cid) as count, nid FROM ".TABLEPREFIX."fanfiction_comments GROUP BY nid");
125
-		while($n = dbassoc($newslist)) {
126
-			dbquery("UPDATE ".TABLEPREFIX."fanfiction_news SET comments = '".$n['count']."' WHERE nid = ".$n['nid']);
127
-		}
128
-	
129
-		$storiesquery =dbquery("SELECT COUNT(sid) as totals, COUNT(DISTINCT uid) as totala, SUM(wordcount) as totalwords FROM ".TABLEPREFIX."fanfiction_stories WHERE validated > 0 ");
130
-		list($stories, $authors, $words) = dbrow($storiesquery);
131
-		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET stories = '$stories', authors = '$authors', wordcount = '$words' WHERE sitekey = 'SITEKEY'"); 
68
+				dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_authors` SET `date_tmp` = UNIX_TIMESTAMP( `date` )");
69
+				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_authors` CHANGE `date` `date` INT NOT NULL");
70
+				dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_authors` set date = date_tmp");
71
+				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_authors` DROP `date_tmp`");
72
+			}
73
+			/****************************************************************************************************************/
74
+			$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_log LIKE 'log_timestamp'"));
132 75
 
133
-		$chapterquery = dbquery("SELECT COUNT(chapid) as chapters FROM ".TABLEPREFIX."fanfiction_chapters where validated > 0");
134
-		list($chapters) = dbrow($chapterquery);
76
+			if ($tmp['Type'] == "datetime")
77
+			{ 
78
+				$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_log LIKE 'log_timestamp_tmp'"));
79
+				if (!$updated)
80
+				{
81
+					dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_log` ADD `log_timestamp_tmp` int(11) NOT NULL default '0'");
82
+				}
135 83
 
136
-		$authorquery = dbquery("SELECT COUNT("._UIDFIELD.") as totalm FROM "._AUTHORTABLE);
137
-		list($members) = dbrow($authorquery);
84
+				dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_log` SET `log_timestamp_tmp` = UNIX_TIMESTAMP( `log_timestamp` )");
85
+				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_log` CHANGE `log_timestamp` `log_timestamp` INT NOT NULL");
86
+				dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_log` set log_timestamp = log_timestamp_tmp");
87
+				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_log` DROP `log_timestamp_tmp`");
88
+			}
89
+			/****************************************************************************************************************/
90
+			/* fanfiction_comments   `time` datetime NOT NULL default '0000-00-00 00:00:00'  */
91
+			$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_comments LIKE 'date'"));
92
+			if ($tmp['Type'] == "datetime")
93
+			{
94
+				$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_comments LIKE 'time_tmp'"));
95
+				if (!$updated)
96
+				{
97
+					dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_comments` ADD `time_tmp` int(11) NOT NULL default '0'");
98
+				}
138 99
 
139
-		list($newest) = dbrow(dbquery("SELECT "._UIDFIELD." as uid FROM "._AUTHORTABLE." ORDER BY "._UIDFIELD." DESC LIMIT 1"));
140
-		$reviewquery = dbquery("SELECT COUNT(reviewid) as totalr FROM ".TABLEPREFIX."fanfiction_reviews WHERE review != 'No Review'");
141
-		list($reviews) = dbrow($reviewquery);
142
-		$reviewquery = dbquery("SELECT COUNT(DISTINCT uid) FROM ".TABLEPREFIX."fanfiction_reviews WHERE review != 'No Review' AND uid > 0");
143
-		list($reviewers) = dbrow($reviewquery);
144
-		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET series = '$totalseries', chapters = '$chapters', members = '$members', newestmember = '$newest', reviews = '$reviews', reviewers = '$reviewers' WHERE sitekey = 'SITEKEY'"); 
145
-		$news = dbquery("SELECT count(nid) as count, nid FROM ".TABLEPREFIX."fanfiction_comments GROUP BY nid");
146
-		while($n = dbassoc($news)) {
147
-			dbquery("UPDATE ".TABLEPREFIX."fanfiction_news SET comments = '".$n['count']."' WHERE nid = '".$n['nid']."' LIMIT 1");
148
-		}
149
-	} // End version 3.2 updates.
150
-	if($oldVersion[1] < 3) {
151
-	dbquery("
152
-CREATE TABLE `".TABLEPREFIX."fanfiction_modules` (
153
-  `id` int(11) NOT NULL auto_increment,
154
-  `name` varchar(100) NOT NULL default 'Test Module',
155
-  `version` varchar(10) NOT NULL default '1.0',
156
-  PRIMARY KEY  (`id`),
157
-  KEY `name_version` (`name`,`version`)
158
-)");
159
-	list($panelCount) = dbrow(dbquery("SELECT count(panel_name) AS count FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_type = 'A' AND panel_level = '1' AND panel_hidden = '0'"));
160
-	$panelCount++;
161
-	dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_panels` (`panel_name`, `panel_title`, `panel_url`, `panel_level`, `panel_order`, `panel_hidden`, `panel_type`) VALUES ('modules', 'Modules', '', 1, ".$panelCount.", 0, 'A')");
162
-	// Insert the modules into the table.
163
-	$dir = opendir(_BASEDIR."modules");
164
-	while($folder = readdir($dir)) {
165
-		if($folder == "." || $folder == ".." || !is_dir("modules/$folder")) continue;
166
-		if(file_exists("modules/$folder/version.php")) {
167
-			$moduleVersion = ""; $moduleName = ""; 
168
-			include("modules/$folder/version.php");
169
-			if(empty($moduleName)) $moduleName = $folder;
170
-			// The next few lines try to determine if the module is installed.  
171
-			if($folder == "challenges" && !isset($anonchallenges)) continue;
172
-			if($folder == "recommendations" && !isset($anonrecs)) continue;
173
-			
174
-			dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_modules(`name`, `version`) VALUES('$moduleName', '1.0')");
175
-		}
176
-	}
177
-	if($ratings == "1") dbquery("UPDATE ".TABLEPREFIX."fanfiction_reviews SET rating = '-1' WHERE rating = '0'");
178
-	dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '0', reviews = '0'"); // Set them all to 0 before we re-insert.
179
-	$stories = dbquery("SELECT AVG(rating) as average, item FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY item");
180
-	while($s = dbassoc($stories)) {
181
-		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '".round($s['average'])."' WHERE sid = '".$s['item']."'");
182
-	}
183
-	$stories = dbquery("SELECT COUNT(reviewid) as count, item FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND review != 'No Review' GROUP BY item");
184
-	while($s = dbassoc($stories)) {
185
-		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET reviews = '".$s['count']."' WHERE sid = '".$s['item']."'");
186
-	}
187
-	dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET rating = '0', reviews = '0'");
188
-	$chapters = dbquery("SELECT AVG(rating) as average, chapid FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY chapid");
189
-	while($c = dbassoc($chapters)) {
190
-		dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET rating = '".round($c['average'])."' WHERE chapid = '".$c['chapid']."'");
191
-	}
192
-	$chapters = dbquery("SELECT COUNT(reviewid) as count, chapid FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND review != 'No Review' GROUP BY chapid");
193
-	while($c = dbassoc($chapters)) {
194
-		dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET reviews = '".$c['count']."' WHERE chapid = '".$c['chapid']."'");
195
-	}
196
-	dbquery("UPDATE ".TABLEPREFIX."fanfiction_series SET rating = '0', reviews = '0'");
197
-	$series = dbquery("SELECT seriesid FROM ".TABLEPREFIX."fanfiction_series");
198
-	while($s = dbassoc($series)) {
199
-		$thisseries = $s['seriesid'];
200
-		include("includes/seriesreviews.php");
201
-	}
202
-	} // End 3.3 updates
203
-	// Version 3.3.1 updates
204
-	if($oldVersion[1] == 3 && empty($oldVersion[2])) {
205
-		if(isset($anonchallenges)) dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_codeblocks` (`code_text`, `code_type`, `code_module`) VALUES('include(_BASEDIR.\"modules/challenges/stats.php\");', 'sitestats', 'challenges');");
206
-	}
207
-	// Versin 3.4 updates
208
-	if($oldVersion[1] < 4) {
209
-		dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_coauthors` (
210
-  `sid` int(11) NOT NULL default '0',
211
-  `uid` int(11) NOT NULL default '0',
212
-  PRIMARY KEY  (`sid`,`uid`)
213
-) ENGINE=MyISAM;");
214
-		dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_authorprefs` ADD `stories` INT NOT NULL DEFAULT '0'");
215
-		$alist = array( );
216
-		$authors = dbquery("SELECT uid, count(uid) AS count FROM ".TABLEPREFIX."fanfiction_stories WHERE validated > 0 GROUP BY uid");
217
-		while($a = dbassoc($authors)) {
218
-			$alist[$a['uid']] = $a['count'];
219
-		}
220
-		$coauthors = dbquery("SELECT coauthors,sid FROM ".TABLEPREFIX."fanfiction_stories WHERE coauthors != '0'");
221
-		while($ca = dbassoc($coauthors)) {
222
-			$co = explode(",", $ca['coauthors']);
223
-			foreach($co AS $a) {
224
-				if(!isNumber($a)) continue;
225
-				if(in_array($a, $alist)) $alist[$a]++;
226
-				else $alist[$a] = 1;
227
-				dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_coauthors(`uid`, `sid`) VALUES('$a', '".$ca['sid']."')");
100
+				dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_comments` SET `time_tmp` = UNIX_TIMESTAMP( `time` )");
101
+				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_comments` CHANGE `time` `time` INT NOT NULL");
102
+				dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_comments` set time = time_tmp");
103
+				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_comments` DROP `time_tmp`");
228 104
 			}
229
-		}
230
-		foreach($alist AS $a => $s) {
231
-			dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET stories = '$s' WHERE uid = '$a' LIMIT 1");
232
-		}
233
-		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET coauthors = '1' WHERE coauthors != '0'");
234
-	}
235
-	if($oldVersion[1] == 4 && !isset($oldVersion[2])) {
236
-		$statsupdate = dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET sitekey = '".SITEKEY."' WHERE sitekey = 'SITEKEY' LIMIT 1");
237
-		$coauthors = dbquery("SHOW TABLES LIKE '".TABLEPREFIX."fanfiction_coauthors'"); 
238
-		if(!dbnumrows($coauthors)) { 
239
-			dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_coauthors` (
240
-			  `sid` int(11) NOT NULL default '0',
241
-			  `uid` int(11) NOT NULL default '0',
242
-			  PRIMARY KEY  (`sid`,`uid`)
243
-			) ENGINE=MyISAM;");
244
-			dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_authorprefs` ADD `stories` INT NOT NULL DEFAULT '0'");
245
-		}		
246
-		$authors = dbquery("SELECT uid, count(uid) AS count FROM ".TABLEPREFIX."fanfiction_stories WHERE validated > 0 GROUP BY uid");
247
-		while($a = dbassoc($authors)) {
248
-			$alist[$a['uid']] = $a['count'];
249
-		}
250
-		$coauthors = dbquery("SELECT uid, count(sid) AS count FROM ".TABLEPREFIX."fanfiction_coauthors GROUP BY uid");
251
-		while($ca = dbassoc($coauthors)) {
252
-			if(in_array($ca['uid'], $alist)) $alist[$ca['uid']] = $alist[$ca['uid']] + $ca['count'];
253
-			else $alist[$ca['uid']] = $ca['count'];
254
-		}
255
-		foreach($alist AS $a => $s) {
256
-			dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET stories = '$s' WHERE uid = '$a' LIMIT 1");
257
-		}
258
-	}
259
-	if($oldVersion[1] == 4 && $oldVersion[2] < 2) {
260
-		$coauthors = dbquery("SHOW TABLES LIKE '".TABLEPREFIX."fanfiction_coauthors'"); 
261
-		if(!dbnumrows($coauthors)) { 
262
-			dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_coauthors` (
263
-			  `sid` int(11) NOT NULL default '0',
264
-			  `uid` int(11) NOT NULL default '0',
265
-			  PRIMARY KEY  (`sid`,`uid`)
266
-			) ENGINE=MyISAM;");
267
-			dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_authorprefs` ADD `stories` INT NOT NULL DEFAULT '0'");
268
-		}
269
-		$storiesAdded = dbquery("SHOW COLUMNS FROM ".TABLEPREFIX."fanfiction_authorprefs LIKE 'stories'");
270
-		if(!$storiesAdded) {
271
-			dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_authorprefs` ADD `stories` INT NOT NULL DEFAULT '0'");
272
-			$authors = dbquery("SELECT uid, count(uid) AS count FROM ".TABLEPREFIX."fanfiction_stories WHERE validated > 0 GROUP BY uid");
273
-			while($a = dbassoc($authors)) {
274
-				$alist[$a['uid']] = $a['count'];
105
+			/****************************************************************************************************************/
106
+			/* fanfiction_reviews   `date` datetime NOT NULL default '0000-00-00 00:00:00', */
107
+			$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_reviews LIKE 'date'"));
108
+			if ($tmp['Type'] == "datetime")
109
+			{
110
+				$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_reviews LIKE 'date_tmp'"));
111
+				if (!$updated)
112
+				{
113
+					dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_reviews` ADD `date_tmp` int(11) NOT NULL default '0'");
114
+				}
115
+
116
+				dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_reviews` SET `date_tmp` = UNIX_TIMESTAMP( `date` )");
117
+				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_reviews` CHANGE `date` `date` INT NOT NULL");
118
+				dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_reviews` set date = date_tmp");
119
+				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_reviews` DROP `date_tmp`");
120
+			}
121
+			/****************************************************************************************************************/
122
+			/* fanfiction_stories `date` datetime NOT NULL default '0000-00-00 00:00:00',   */
123
+			$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_stories LIKE 'date'"));
124
+			if($tmp['Type'] == "datetime") {
125
+				$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_stories LIKE 'date_tmp'"));
126
+				if (!$updated)
127
+				{
128
+					dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_stories` ADD `date_tmp` int(11) NOT NULL default '0'");
129
+				}
130
+
131
+				dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_stories` SET `date_tmp` = UNIX_TIMESTAMP( `date` )");
132
+				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_stories` CHANGE `date` `date` INT NOT NULL");
133
+				dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_stories` set date = date_tmp");
134
+				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_stories` DROP `date_tmp`");
275 135
 			}
276
-			$coauthors = dbquery("SELECT uid, count(sid) AS count FROM ".TABLEPREFIX."fanfiction_coauthors GROUP BY uid");
277
-			while($ca = dbassoc($coauthors)) {
278
-				if(in_array($ca['uid'], $alist)) $alist[$ca['uid']] = $alist[$ca['uid']] + $ca['count'];
279
-				else $alist[$ca['uid']] = $ca['count'];
136
+
137
+			/****************************************************************************************************************/
138
+			/* fanfiction_stories `updated` datetime NOT NULL default '0000-00-00 00:00:00', */
139
+			$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_stories LIKE 'updated'"));
140
+			if ($tmp['Type'] == "datetime")
141
+			{				
142
+				$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_stories LIKE 'updated_tmp'"));
143
+				if (!$updated)
144
+				{
145
+					dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_stories` ADD `updated_tmp` int(11) NOT NULL default '0'");
146
+				}
147
+
148
+				dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_stories` SET `updated_tmp` = UNIX_TIMESTAMP( `updated` )");
149
+				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_stories` CHANGE `updated` `updated` INT NOT NULL");
150
+				dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_stories` set updated = updated_tmp");
151
+				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_stories` DROP `updated_tmp`");
280 152
 			}
281
-			foreach($alist AS $a => $s) {
282
-				dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET stories = '$s' WHERE uid = '$a' LIMIT 1");
153
+
154
+			/****************************************************************************************************************/
155
+			/* fanfiction_news `time` datetime default NULL,  */
156
+			$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_news LIKE 'time'"));
157
+			
158
+			if ($tmp['Type'] == "datetime")
159
+			{		
160
+				$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_news LIKE 'time_tmp'"));
161
+				if (!$updated)
162
+				{
163
+					dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_news` ADD `time_tmp` int(11) NOT NULL default '0'");
164
+				}
165
+
166
+				dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_news` SET `time_tmp` = UNIX_TIMESTAMP( `time` )");
167
+				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_news` CHANGE `time` `time` INT NOT NULL");
168
+				dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_news` set time = time_tmp");
169
+				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_news` DROP `time_tmp`");
283 170
 			}
171
+
172
+			/* todo */
173
+			/* ALTER TABLE `e107_fanfiction_stories` CHANGE `coauthors` `coauthors` TINYINT NOT NULL DEFAULT '0'; */
284 174
 		}
175
+		$update = dbquery("UPDATE " . $settingsprefix . "fanfiction_settings SET version = '" . $version . "' WHERE sitekey = '" . SITEKEY . "'");
176
+		if ($update) $output .= write_message(_ACTIONSUCCESSFUL);
177
+		else $output .= write_error(_ERROR);
285 178
 	}
286
-	if($oldVersion[1] == 5) { // Try to fix some errors for people
287
-		// Recalculate the story count for authors.
288
-		$authors = dbquery("SELECT uid, count(uid) AS count FROM ".TABLEPREFIX."fanfiction_stories WHERE validated > 0 GROUP BY uid");
289
-		$alist = array( );
290
-		while($a = dbassoc($authors)) {
291
-			$alist[$a['uid']] = $a['count'];
292
-		}
293
-		$coauthors = dbquery("SELECT uid, count(sid) AS count FROM ".TABLEPREFIX."fanfiction_coauthors GROUP BY uid");
294
-		while($ca = dbassoc($coauthors)) {
295
-			if(isset($alist[$ca['uid']])) $alist[$ca['uid']] = $alist[$ca['uid']] + $ca['count'];
296
-			else $alist[$ca['uid']] = $ca['count'];
297
-		}
298
-		foreach($alist AS $a => $s) {
299
-			dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET stories = '$s' WHERE uid = '$a' LIMIT 1");
300
-		}
301
-		// Recalculate the number of authors
302
-		list($authors) = dbrow(dbquery("SELECT count(uid) FROM ".TABLEPREFIX."fanfiction_authorprefs WHERE stories > 0"));
303
-		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET authors = '$authors' WHERE sitekey = '".SITEKEY."'"); 
179
+	else if ($confirm == "no")
180
+	{
181
+		$output .= write_message(_ACTIONCANCELLED);
182
+	}
183
+	else
184
+	{
185
+		if ($oldVersion[0] == 3 && ($oldVersion[1] < 4 || $oldVersion[1] == 4 && (!isset($oldVersion[2]) || $oldVersion[2] < 6)))
186
+			$output .= write_message(_CONFIRMUPDATE . "<br /> <a href='update.php?confirm=yes'>" . _YES . "</a> " . _OR . " <a href='update.php?confirm=no'>" . _NO . "</a>");
187
+		else $output .= write_message("Are you ready to update? <a href='update.php?confirm=yes'>" . _YES . "</a> " . _OR . " <a href='update.php?confirm=no'>" . _NO . "</a>");
304 188
 	}
305
-	if($oldVersion[1] == 5 && $oldVersion[2] < 3) {
306
-		// fix the indexes for the inseries table.
307
-		$exists = dbnumrows(dbquery("SHOW INDEX FROM ".TABLEPREFIX."fanfiction_inseries WHERE Key_name = 'seriesid'"));
308
-		if($exists) dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index seriesid;");
309
-		$exists = dbnumrows(dbquery("SHOW INDEX FROM ".TABLEPREFIX."fanfiction_inseries WHERE Key_name = 'inorder'"));
310
-		if($exists) dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index inorder;");
311
-		dbquery("alter table ".TABLEPREFIX."fanfiction_inseries add index (seriesid,inorder);");
312
-		$exists = dbnumrows(dbquery("SHOW INDEX FROM ".TABLEPREFIX."fanfiction_inseries WHERE Key_name = 'sid'"));
313
-		if($exists) dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index sid;");
314
-		$exists = dbnumrows(dbquery("SHOW INDEX FROM ".TABLEPREFIX."fanfiction_inseries WHERE Key_name = 'PRIMARY'"));
315
-		if($exists) dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop primary key");
316
-		dbquery("alter ignore table ".TABLEPREFIX."fanfiction_inseries add primary key (sid,seriesid,subseriesid);");
317
-	}	
318
-	$update = dbquery("UPDATE ".$settingsprefix."fanfiction_settings SET version = '".$version."' WHERE sitekey = '".SITEKEY."'");
319
-	if($update) $output .= write_message(_ACTIONSUCCESSFUL);
320
-	else $output .= write_error(_ERROR);
321
-}
322
-else if($confirm == "no") {
323
-	$output .= write_message(_ACTIONCANCELLED);
324
-}
325
-else {
326
-  	if($oldVersion[0] == 3 && ($oldVersion[1] < 4 || $oldVersion[1] == 4 && (!isset($oldVersion[2]) || $oldVersion[2] < 3))) $output .= write_message(_CONFIRMUPDATE."<br /> <a href='update.php?confirm=yes'>"._YES."</a> "._OR." <a href='update.php?confirm=no'>"._NO."</a>");
327
-	else $output .= write_message("Are you ready to update? <a href='update.php?confirm=yes'>"._YES."</a> "._OR." <a href='update.php?confirm=no'>"._NO."</a>");
328 189
 }
190
+elseif ($oldVersion[0] == 4) //3.5.5
191
+{
192
+	/* quick fix for switching between version on dev */
193
+	$update = dbquery("UPDATE " . $settingsprefix . "fanfiction_settings SET version = '3.5.5' WHERE sitekey = '" . SITEKEY . "'");
194
+	header("Location: update.php");
195
+	exit();
329 196
 }
330 197
 else $output .= write_message(_ALREADYUPDATED);
331
-$tpl->assign( "output", $output );
198
+$tpl->assign("output", $output);
332 199
 $tpl->printToScreen();
333
-dbclose( );
334
-?>
335 200
\ No newline at end of file
201
+dbclose();
Browse code

backup 3.52

Jimmi08 authored on 2021/04/02 11:08:04
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,334 @@
1
+<?php
2
+// ----------------------------------------------------------------------
3
+// eFiction 3.0
4
+// Copyright (c) 2007 by Tammy Keefer
5
+// Valid HTML 4.01 Transitional
6
+// Based on eFiction 1.1
7
+// Copyright (C) 2003 by Rebecca Smallwood.
8
+// http://efiction.sourceforge.net/
9
+// ----------------------------------------------------------------------
10
+// LICENSE
11
+//
12
+// This program is free software; you can redistribute it and/or
13
+// modify it under the terms of the GNU General Public License (GPL)
14
+// as published by the Free Software Foundation; either version 2
15
+// of the License, or (at your option) any later version.
16
+//
17
+// This program is distributed in the hope that it will be useful,
18
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+// GNU General Public License for more details.
21
+//
22
+// To read the license please visit http://www.gnu.org/copyleft/gpl.html
23
+// ----------------------------------------------------------------------
24
+$current = "update";
25
+
26
+include("header.php");
27
+
28
+$blocks['news']['status'] = 0;
29
+$blocks['info']['status'] = 0;
30
+
31
+//make a new TemplatePower object
32
+if(file_exists("$skindir/default.tpl")) $tpl = new TemplatePower( "$skindir/default.tpl" );
33
+else $tpl = new TemplatePower("default_tpls/default.tpl");
34
+include("includes/pagesetup.php");
35
+if(file_exists("languages/".$language."_admin.php")) include_once("languages/".$language."_admin.php");
36
+else include_once("languages/en_admin.php");
37
+// end basic page setup
38
+
39
+if(!isADMIN) {
40
+$output .= "<script language=\"javascript\" type=\"text/javascript\">
41
+location = \"maintenance.php\";
42
+</script>";
43
+$tpl->assign( "output", $output );
44
+$tpl->printToScreen();
45
+dbclose( );
46
+exit( );
47
+}
48
+$oldVersion = explode(".", $settings['version']);
49
+$confirm = isset($_GET['confirm']) ? $_GET['confirm'] : false;
50
+if($oldVersion[0] == 3 && ($oldVersion[1] < 5 || $oldVersion[2] < 3)) {
51
+if($confirm == "yes") {
52
+	// For the slow-pokes who haven't updated to 3.1
53
+	if($oldVersion[1] == 0 ) {
54
+		list($field) = dbrow(dbquery("SELECT field_id FROM ".TABLEPREFIX."fanfiction_authorfields WHERE field_name = 'betareader'"));
55
+		dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorinfo SET info = '"._YES."' WHERE field = '$field' AND info = '1'");
56
+		dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorinfo SET info = '"._NO."' WHERE field = '$field' AND info != '"._YES."'");
57
+		dbquery("alter table ".TABLEPREFIX."fanfiction_authorinfo add primary key(uid,field);");
58
+		dbquery("alter table ".TABLEPREFIX."fanfiction_blocks drop index block_name;");
59
+		dbquery("alter table ".TABLEPREFIX."fanfiction_blocks add unique index block_name (block_name);");
60
+		dbquery("alter table ".TABLEPREFIX."fanfiction_categories drop index category;");
61
+		dbquery("alter table ".TABLEPREFIX."fanfiction_categories drop index parentcatid;");
62
+		dbquery("create index byparent on ".TABLEPREFIX."fanfiction_categories (parentcatid,displayorder);");
63
+		dbquery("create index forstoryblock on ".TABLEPREFIX."fanfiction_chapters (sid,validated);");
64
+		dbquery("create index byname on ".TABLEPREFIX."fanfiction_classes (class_type,class_name,class_id);");
65
+		dbquery("alter table ".TABLEPREFIX."fanfiction_classtypes drop index classtype_title;");
66
+		dbquery("create unique index classtype_name on ".TABLEPREFIX."fanfiction_classtypes(classtype_name);");
67
+		dbquery("create index code_type on ".TABLEPREFIX."fanfiction_codeblocks(code_type);");
68
+		dbquery("alter table ".TABLEPREFIX."fanfiction_comments drop index nid;");
69
+		dbquery("alter table ".TABLEPREFIX."fanfiction_comments add index commentlist (nid,time);");
70
+		dbquery("alter table ".TABLEPREFIX."fanfiction_favorites drop index uid;");
71
+		dbquery("create unique index byitem on ".TABLEPREFIX."fanfiction_favorites (item,type,uid);");
72
+		dbquery("create unique index byuid on ".TABLEPREFIX."fanfiction_favorites (uid,type,item);");
73
+		dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index seriesid;");
74
+		dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index inorder;");
75
+		dbquery("alter table ".TABLEPREFIX."fanfiction_inseries add index (seriesid,inorder);");
76
+		dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index sid;");
77
+		dbquery("alter table ".TABLEPREFIX."fanfiction_inseries add primary key (sid,seriesid);");
78
+		dbquery("create index message_name on ".TABLEPREFIX."fanfiction_messages (message_name);");
79
+		dbquery("alter table ".TABLEPREFIX."fanfiction_pagelinks drop index link_text;");
80
+		dbquery("alter table ".TABLEPREFIX."fanfiction_panels drop index panel_hidden;");
81
+		dbquery("alter table ".TABLEPREFIX."fanfiction_panels drop index panel_type;");
82
+		dbquery("alter table ".TABLEPREFIX."fanfiction_panels add index panel_type (panel_type,panel_name);");
83
+		dbquery("create index avgrating on ".TABLEPREFIX."fanfiction_reviews(type,item,rating);");
84
+		dbquery("alter table ".TABLEPREFIX."fanfiction_reviews drop index sid;");
85
+		dbquery("create index bychapter on ".TABLEPREFIX."fanfiction_reviews (chapid,rating);");
86
+		dbquery("alter table ".TABLEPREFIX."fanfiction_reviews add index byuid (uid,item,type);");
87
+		dbquery("alter table ".TABLEPREFIX."fanfiction_series drop index owner;");
88
+		dbquery("create index owner on ".TABLEPREFIX."fanfiction_series (uid,title);");
89
+		dbquery("alter table ".TABLEPREFIX."fanfiction_stories drop index validated;");
90
+		dbquery("create index validateduid on ".TABLEPREFIX."fanfiction_stories (validated,uid);");
91
+		dbquery("create index recent on ".TABLEPREFIX."fanfiction_stories (updated,validated);");
92
+		$alltables = dbquery("SHOW TABLES");
93
+	}
94
+	// Still a little behind.
95
+	if($oldVersion[1] < 2) { 
96
+		dbquery("
97
+CREATE TABLE `".TABLEPREFIX."fanfiction_stats` (
98
+  `sitekey` varchar(50) NOT NULL default '0',
99
+  `stories` int(11) NOT NULL default '0',
100
+  `chapters` int(11) NOT NULL default '0',
101
+  `series` int(11) NOT NULL default '0',
102
+  `reviews` int(11) NOT NULL default '0',
103
+  `wordcount` int(11) NOT NULL default '0',
104
+  `authors` int(11) NOT NULL default '0',
105
+  `members` int(11) NOT NULL default '0',
106
+  `reviewers` int(11) NOT NULL default '0',
107
+  `newestmember` int(11) NOT NULL default '0'
108
+) ENGINE=MyISAM");
109
+		dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_stats(`sitekey`) VALUES('SITEKEY')");
110
+		dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_inseries` DROP `updated`");
111
+		dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_news` ADD `comments` INT NOT NULL DEFAULT '0'");
112
+		dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_series` ADD `numstories` INT NOT NULL DEFAULT '0'");
113
+		dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_pagelinks` ADD `link_key` CHAR( 1 ) NULL AFTER `link_text`");
114
+		if(!isset($allowseries)) dbquery("ALTER TABLE `".$settingsprefix."fanfiction_settings` ADD `allowseries` TINYINT NOT NULL DEFAULT '2' AFTER `roundrobins`");
115
+		dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_log` CHANGE `log_ip` `log_ip` INT( 11 ) UNSIGNED NULL DEFAULT NULL");
116
+		dbquery("UPDATE ".TABLEPREFIX."fanfiction_inseries SET confirmed = 1");
117
+		$serieslist = dbquery("SELECT seriesid FROM ".TABLEPREFIX."fanfiction_series");
118
+		$totalseries = dbnumrows($serieslist);
119
+		while($s = dbassoc($serieslist)) {
120
+			$numstories = count(storiesInSeries($s['seriesid']));
121
+			dbquery("UPDATE ".TABLEPREFIX."fanfiction_series SET numstories = '$numstories' WHERE seriesid = ".$s['seriesid']." LIMIT 1");
122
+		}
123
+
124
+		$newslist = dbquery("SELECT count(cid) as count, nid FROM ".TABLEPREFIX."fanfiction_comments GROUP BY nid");
125
+		while($n = dbassoc($newslist)) {
126
+			dbquery("UPDATE ".TABLEPREFIX."fanfiction_news SET comments = '".$n['count']."' WHERE nid = ".$n['nid']);
127
+		}
128
+	
129
+		$storiesquery =dbquery("SELECT COUNT(sid) as totals, COUNT(DISTINCT uid) as totala, SUM(wordcount) as totalwords FROM ".TABLEPREFIX."fanfiction_stories WHERE validated > 0 ");
130
+		list($stories, $authors, $words) = dbrow($storiesquery);
131
+		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET stories = '$stories', authors = '$authors', wordcount = '$words' WHERE sitekey = 'SITEKEY'"); 
132
+
133
+		$chapterquery = dbquery("SELECT COUNT(chapid) as chapters FROM ".TABLEPREFIX."fanfiction_chapters where validated > 0");
134
+		list($chapters) = dbrow($chapterquery);
135
+
136
+		$authorquery = dbquery("SELECT COUNT("._UIDFIELD.") as totalm FROM "._AUTHORTABLE);
137
+		list($members) = dbrow($authorquery);
138
+
139
+		list($newest) = dbrow(dbquery("SELECT "._UIDFIELD." as uid FROM "._AUTHORTABLE." ORDER BY "._UIDFIELD." DESC LIMIT 1"));
140
+		$reviewquery = dbquery("SELECT COUNT(reviewid) as totalr FROM ".TABLEPREFIX."fanfiction_reviews WHERE review != 'No Review'");
141
+		list($reviews) = dbrow($reviewquery);
142
+		$reviewquery = dbquery("SELECT COUNT(DISTINCT uid) FROM ".TABLEPREFIX."fanfiction_reviews WHERE review != 'No Review' AND uid > 0");
143
+		list($reviewers) = dbrow($reviewquery);
144
+		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET series = '$totalseries', chapters = '$chapters', members = '$members', newestmember = '$newest', reviews = '$reviews', reviewers = '$reviewers' WHERE sitekey = 'SITEKEY'"); 
145
+		$news = dbquery("SELECT count(nid) as count, nid FROM ".TABLEPREFIX."fanfiction_comments GROUP BY nid");
146
+		while($n = dbassoc($news)) {
147
+			dbquery("UPDATE ".TABLEPREFIX."fanfiction_news SET comments = '".$n['count']."' WHERE nid = '".$n['nid']."' LIMIT 1");
148
+		}
149
+	} // End version 3.2 updates.
150
+	if($oldVersion[1] < 3) {
151
+	dbquery("
152
+CREATE TABLE `".TABLEPREFIX."fanfiction_modules` (
153
+  `id` int(11) NOT NULL auto_increment,
154
+  `name` varchar(100) NOT NULL default 'Test Module',
155
+  `version` varchar(10) NOT NULL default '1.0',
156
+  PRIMARY KEY  (`id`),
157
+  KEY `name_version` (`name`,`version`)
158
+)");
159
+	list($panelCount) = dbrow(dbquery("SELECT count(panel_name) AS count FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_type = 'A' AND panel_level = '1' AND panel_hidden = '0'"));
160
+	$panelCount++;
161
+	dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_panels` (`panel_name`, `panel_title`, `panel_url`, `panel_level`, `panel_order`, `panel_hidden`, `panel_type`) VALUES ('modules', 'Modules', '', 1, ".$panelCount.", 0, 'A')");
162
+	// Insert the modules into the table.
163
+	$dir = opendir(_BASEDIR."modules");
164
+	while($folder = readdir($dir)) {
165
+		if($folder == "." || $folder == ".." || !is_dir("modules/$folder")) continue;
166
+		if(file_exists("modules/$folder/version.php")) {
167
+			$moduleVersion = ""; $moduleName = ""; 
168
+			include("modules/$folder/version.php");
169
+			if(empty($moduleName)) $moduleName = $folder;
170
+			// The next few lines try to determine if the module is installed.  
171
+			if($folder == "challenges" && !isset($anonchallenges)) continue;
172
+			if($folder == "recommendations" && !isset($anonrecs)) continue;
173
+			
174
+			dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_modules(`name`, `version`) VALUES('$moduleName', '1.0')");
175
+		}
176
+	}
177
+	if($ratings == "1") dbquery("UPDATE ".TABLEPREFIX."fanfiction_reviews SET rating = '-1' WHERE rating = '0'");
178
+	dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '0', reviews = '0'"); // Set them all to 0 before we re-insert.
179
+	$stories = dbquery("SELECT AVG(rating) as average, item FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY item");
180
+	while($s = dbassoc($stories)) {
181
+		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '".round($s['average'])."' WHERE sid = '".$s['item']."'");
182
+	}
183
+	$stories = dbquery("SELECT COUNT(reviewid) as count, item FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND review != 'No Review' GROUP BY item");
184
+	while($s = dbassoc($stories)) {
185
+		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET reviews = '".$s['count']."' WHERE sid = '".$s['item']."'");
186
+	}
187
+	dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET rating = '0', reviews = '0'");
188
+	$chapters = dbquery("SELECT AVG(rating) as average, chapid FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY chapid");
189
+	while($c = dbassoc($chapters)) {
190
+		dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET rating = '".round($c['average'])."' WHERE chapid = '".$c['chapid']."'");
191
+	}
192
+	$chapters = dbquery("SELECT COUNT(reviewid) as count, chapid FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND review != 'No Review' GROUP BY chapid");
193
+	while($c = dbassoc($chapters)) {
194
+		dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET reviews = '".$c['count']."' WHERE chapid = '".$c['chapid']."'");
195
+	}
196
+	dbquery("UPDATE ".TABLEPREFIX."fanfiction_series SET rating = '0', reviews = '0'");
197
+	$series = dbquery("SELECT seriesid FROM ".TABLEPREFIX."fanfiction_series");
198
+	while($s = dbassoc($series)) {
199
+		$thisseries = $s['seriesid'];
200
+		include("includes/seriesreviews.php");
201
+	}
202
+	} // End 3.3 updates
203
+	// Version 3.3.1 updates
204
+	if($oldVersion[1] == 3 && empty($oldVersion[2])) {
205
+		if(isset($anonchallenges)) dbquery("INSERT INTO `".TABLEPREFIX."fanfiction_codeblocks` (`code_text`, `code_type`, `code_module`) VALUES('include(_BASEDIR.\"modules/challenges/stats.php\");', 'sitestats', 'challenges');");
206
+	}
207
+	// Versin 3.4 updates
208
+	if($oldVersion[1] < 4) {
209
+		dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_coauthors` (
210
+  `sid` int(11) NOT NULL default '0',
211
+  `uid` int(11) NOT NULL default '0',
212
+  PRIMARY KEY  (`sid`,`uid`)
213
+) ENGINE=MyISAM;");
214
+		dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_authorprefs` ADD `stories` INT NOT NULL DEFAULT '0'");
215
+		$alist = array( );
216
+		$authors = dbquery("SELECT uid, count(uid) AS count FROM ".TABLEPREFIX."fanfiction_stories WHERE validated > 0 GROUP BY uid");
217
+		while($a = dbassoc($authors)) {
218
+			$alist[$a['uid']] = $a['count'];
219
+		}
220
+		$coauthors = dbquery("SELECT coauthors,sid FROM ".TABLEPREFIX."fanfiction_stories WHERE coauthors != '0'");
221
+		while($ca = dbassoc($coauthors)) {
222
+			$co = explode(",", $ca['coauthors']);
223
+			foreach($co AS $a) {
224
+				if(!isNumber($a)) continue;
225
+				if(in_array($a, $alist)) $alist[$a]++;
226
+				else $alist[$a] = 1;
227
+				dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_coauthors(`uid`, `sid`) VALUES('$a', '".$ca['sid']."')");
228
+			}
229
+		}
230
+		foreach($alist AS $a => $s) {
231
+			dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET stories = '$s' WHERE uid = '$a' LIMIT 1");
232
+		}
233
+		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET coauthors = '1' WHERE coauthors != '0'");
234
+	}
235
+	if($oldVersion[1] == 4 && !isset($oldVersion[2])) {
236
+		$statsupdate = dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET sitekey = '".SITEKEY."' WHERE sitekey = 'SITEKEY' LIMIT 1");
237
+		$coauthors = dbquery("SHOW TABLES LIKE '".TABLEPREFIX."fanfiction_coauthors'"); 
238
+		if(!dbnumrows($coauthors)) { 
239
+			dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_coauthors` (
240
+			  `sid` int(11) NOT NULL default '0',
241
+			  `uid` int(11) NOT NULL default '0',
242
+			  PRIMARY KEY  (`sid`,`uid`)
243
+			) ENGINE=MyISAM;");
244
+			dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_authorprefs` ADD `stories` INT NOT NULL DEFAULT '0'");
245
+		}		
246
+		$authors = dbquery("SELECT uid, count(uid) AS count FROM ".TABLEPREFIX."fanfiction_stories WHERE validated > 0 GROUP BY uid");
247
+		while($a = dbassoc($authors)) {
248
+			$alist[$a['uid']] = $a['count'];
249
+		}
250
+		$coauthors = dbquery("SELECT uid, count(sid) AS count FROM ".TABLEPREFIX."fanfiction_coauthors GROUP BY uid");
251
+		while($ca = dbassoc($coauthors)) {
252
+			if(in_array($ca['uid'], $alist)) $alist[$ca['uid']] = $alist[$ca['uid']] + $ca['count'];
253
+			else $alist[$ca['uid']] = $ca['count'];
254
+		}
255
+		foreach($alist AS $a => $s) {
256
+			dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET stories = '$s' WHERE uid = '$a' LIMIT 1");
257
+		}
258
+	}
259
+	if($oldVersion[1] == 4 && $oldVersion[2] < 2) {
260
+		$coauthors = dbquery("SHOW TABLES LIKE '".TABLEPREFIX."fanfiction_coauthors'"); 
261
+		if(!dbnumrows($coauthors)) { 
262
+			dbquery("CREATE TABLE `".TABLEPREFIX."fanfiction_coauthors` (
263
+			  `sid` int(11) NOT NULL default '0',
264
+			  `uid` int(11) NOT NULL default '0',
265
+			  PRIMARY KEY  (`sid`,`uid`)
266
+			) ENGINE=MyISAM;");
267
+			dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_authorprefs` ADD `stories` INT NOT NULL DEFAULT '0'");
268
+		}
269
+		$storiesAdded = dbquery("SHOW COLUMNS FROM ".TABLEPREFIX."fanfiction_authorprefs LIKE 'stories'");
270
+		if(!$storiesAdded) {
271
+			dbquery("ALTER TABLE `".TABLEPREFIX."fanfiction_authorprefs` ADD `stories` INT NOT NULL DEFAULT '0'");
272
+			$authors = dbquery("SELECT uid, count(uid) AS count FROM ".TABLEPREFIX."fanfiction_stories WHERE validated > 0 GROUP BY uid");
273
+			while($a = dbassoc($authors)) {
274
+				$alist[$a['uid']] = $a['count'];
275
+			}
276
+			$coauthors = dbquery("SELECT uid, count(sid) AS count FROM ".TABLEPREFIX."fanfiction_coauthors GROUP BY uid");
277
+			while($ca = dbassoc($coauthors)) {
278
+				if(in_array($ca['uid'], $alist)) $alist[$ca['uid']] = $alist[$ca['uid']] + $ca['count'];
279
+				else $alist[$ca['uid']] = $ca['count'];
280
+			}
281
+			foreach($alist AS $a => $s) {
282
+				dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET stories = '$s' WHERE uid = '$a' LIMIT 1");
283
+			}
284
+		}
285
+	}
286
+	if($oldVersion[1] == 5) { // Try to fix some errors for people
287
+		// Recalculate the story count for authors.
288
+		$authors = dbquery("SELECT uid, count(uid) AS count FROM ".TABLEPREFIX."fanfiction_stories WHERE validated > 0 GROUP BY uid");
289
+		$alist = array( );
290
+		while($a = dbassoc($authors)) {
291
+			$alist[$a['uid']] = $a['count'];
292
+		}
293
+		$coauthors = dbquery("SELECT uid, count(sid) AS count FROM ".TABLEPREFIX."fanfiction_coauthors GROUP BY uid");
294
+		while($ca = dbassoc($coauthors)) {
295
+			if(isset($alist[$ca['uid']])) $alist[$ca['uid']] = $alist[$ca['uid']] + $ca['count'];
296
+			else $alist[$ca['uid']] = $ca['count'];
297
+		}
298
+		foreach($alist AS $a => $s) {
299
+			dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET stories = '$s' WHERE uid = '$a' LIMIT 1");
300
+		}
301
+		// Recalculate the number of authors
302
+		list($authors) = dbrow(dbquery("SELECT count(uid) FROM ".TABLEPREFIX."fanfiction_authorprefs WHERE stories > 0"));
303
+		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET authors = '$authors' WHERE sitekey = '".SITEKEY."'"); 
304
+	}
305
+	if($oldVersion[1] == 5 && $oldVersion[2] < 3) {
306
+		// fix the indexes for the inseries table.
307
+		$exists = dbnumrows(dbquery("SHOW INDEX FROM ".TABLEPREFIX."fanfiction_inseries WHERE Key_name = 'seriesid'"));
308
+		if($exists) dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index seriesid;");
309
+		$exists = dbnumrows(dbquery("SHOW INDEX FROM ".TABLEPREFIX."fanfiction_inseries WHERE Key_name = 'inorder'"));
310
+		if($exists) dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index inorder;");
311
+		dbquery("alter table ".TABLEPREFIX."fanfiction_inseries add index (seriesid,inorder);");
312
+		$exists = dbnumrows(dbquery("SHOW INDEX FROM ".TABLEPREFIX."fanfiction_inseries WHERE Key_name = 'sid'"));
313
+		if($exists) dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop index sid;");
314
+		$exists = dbnumrows(dbquery("SHOW INDEX FROM ".TABLEPREFIX."fanfiction_inseries WHERE Key_name = 'PRIMARY'"));
315
+		if($exists) dbquery("alter table ".TABLEPREFIX."fanfiction_inseries drop primary key");
316
+		dbquery("alter ignore table ".TABLEPREFIX."fanfiction_inseries add primary key (sid,seriesid,subseriesid);");
317
+	}	
318
+	$update = dbquery("UPDATE ".$settingsprefix."fanfiction_settings SET version = '".$version."' WHERE sitekey = '".SITEKEY."'");
319
+	if($update) $output .= write_message(_ACTIONSUCCESSFUL);
320
+	else $output .= write_error(_ERROR);
321
+}
322
+else if($confirm == "no") {
323
+	$output .= write_message(_ACTIONCANCELLED);
324
+}
325
+else {
326
+  	if($oldVersion[0] == 3 && ($oldVersion[1] < 4 || $oldVersion[1] == 4 && (!isset($oldVersion[2]) || $oldVersion[2] < 3))) $output .= write_message(_CONFIRMUPDATE."<br /> <a href='update.php?confirm=yes'>"._YES."</a> "._OR." <a href='update.php?confirm=no'>"._NO."</a>");
327
+	else $output .= write_message("Are you ready to update? <a href='update.php?confirm=yes'>"._YES."</a> "._OR." <a href='update.php?confirm=no'>"._NO."</a>");
328
+}
329
+}
330
+else $output .= write_message(_ALREADYUPDATED);
331
+$tpl->assign( "output", $output );
332
+$tpl->printToScreen();
333
+dbclose( );
334
+?>
0 335
\ No newline at end of file