update_schema::update_from_13()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 8
nop 0
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
1
<?php
2
require_once(dirname(__FILE__).'/../require/settings.php');
3
require_once(dirname(__FILE__).'/../require/class.Connection.php');
4
require_once(dirname(__FILE__).'/../require/class.Scheduler.php');
5
require_once(dirname(__FILE__).'/class.create_db.php');
6
require_once(dirname(__FILE__).'/class.update_db.php');
7
8
class update_schema {
9
10
	public static function update_schedule() {
11
	    $Connection = new Connection();
12
	    $Schedule = new Schedule();
13
	    $query = "SELECT * FROM schedule";
14
            try {
15
            	$sth = $Connection->db->prepare($query);
16
		$sth->execute();
17
    	    } catch(PDOException $e) {
18
		return "error : ".$e->getMessage()."\n";
19
    	    }
20
    	    while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
21
    		$Schedule->addSchedule($row['ident'],$row['departure_airport_icao'],$row['departure_airport_time'],$row['arrival_airport_icao'],$row['arrival_airport_time']);
22
    	    }
23
	
24
	}
25
/*
26
	private static function tableExists($tableName) {
27
	    $Connection = new Connection();
28
	    $query = "SHOW TABLES LIKE :tableName";
29
            try {
30
            	$sth = $Connection->db->prepare($query);
31
		$sth->execute(array(':tableName' => $tableName));
32
    	    } catch(PDOException $e) {
33
		return "error : ".$e->getMessage()."\n";
34
    	    }
35
    	    $row = $sth->fetch(PDO::FETCH_NUM);
36
    	    if ($row[0]) {
37
        	//echo 'table was found';
38
        	return true;
39
    	    } else {
40
        	//echo 'table was not found';
41
        	return false;
42
    	    }
43
    	}
44
*/	
45
	private static function update_from_1() {
46
    		$Connection = new Connection();
47
    		// Add new column to routes table
48
    		//$query = "ALTER TABLE `routes` ADD `FromAirport_Time` VARCHAR(10),`ToAirport_Time` VARCHAR(10),`Source` VARCHAR(255),`date_added` DATETIME DEFAULT CURRENT TIMESTAMP,`date_modified` DATETIME,`date_lastseen` DATETIME";
49
		$query = "ALTER TABLE `routes` ADD `FromAirport_Time` VARCHAR(10) NULL , ADD `ToAirport_Time` VARCHAR(10) NULL , ADD `Source` VARCHAR(255) NULL, ADD `date_added` timestamp DEFAULT CURRENT_TIMESTAMP, ADD `date_modified` timestamp NULL, ADD `date_lastseen` timestamp NULL";
50
        	try {
51
            	    $sth = $Connection->db->prepare($query);
52
		    $sth->execute();
53
    		} catch(PDOException $e) {
54
		    return "error (add new columns to routes table) : ".$e->getMessage()."\n";
55
    		}
56
    		// Copy schedules data to routes table
57
    		self::update_schedule();
58
    		// Delete schedule table
59
		$query = "DROP TABLE `schedule`";
60
        	try {
61
            	    $sth = $Connection->db->prepare($query);
62
		    $sth->execute();
63
    		} catch(PDOException $e) {
64
		    return "error (delete schedule table) : ".$e->getMessage()."\n";
65
    		}
66
    		// Add source column
67
    		$query = "ALTER TABLE `aircraft_modes` ADD `Source` VARCHAR(255) NULL";
68
    		try {
69
            	    $sth = $Connection->db->prepare($query);
70
		    $sth->execute();
71
    		} catch(PDOException $e) {
72
		    return "error (add source column to aircraft_modes) : ".$e->getMessage()."\n";
73
    		}
74
		// Delete unused column
75
		$query = "ALTER TABLE `aircraft_modes`  DROP `SerialNo`,  DROP `OperatorFlagCode`,  DROP `Manufacturer`,  DROP `Type`,  DROP `FirstRegDate`,  DROP `CurrentRegDate`,  DROP `Country`,  DROP `PreviousID`,  DROP `DeRegDate`,  DROP `Status`,  DROP `PopularName`,  DROP `GenericName`,  DROP `AircraftClass`,  DROP `Engines`,  DROP `OwnershipStatus`,  DROP `RegisteredOwners`,  DROP `MTOW`,  DROP `TotalHours`,  DROP `YearBuilt`,  DROP `CofACategory`,  DROP `CofAExpiry`,  DROP `UserNotes`,  DROP `Interested`,  DROP `UserTag`,  DROP `InfoUrl`,  DROP `PictureUrl1`,  DROP `PictureUrl2`,  DROP `PictureUrl3`,  DROP `UserBool1`,  DROP `UserBool2`,  DROP `UserBool3`,  DROP `UserBool4`,  DROP `UserBool5`,  DROP `UserString1`,  DROP `UserString2`,  DROP `UserString3`,  DROP `UserString4`,  DROP `UserString5`,  DROP `UserInt1`,  DROP `UserInt2`,  DROP `UserInt3`,  DROP `UserInt4`,  DROP `UserInt5`";
76
    		try {
77
            	    $sth = $Connection->db->prepare($query);
78
		    $sth->execute();
79
    		} catch(PDOException $e) {
80
		    return "error (Delete unused column of aircraft_modes) : ".$e->getMessage()."\n";
81
    		}
82
		// Add ModeS column
83
		$query = "ALTER TABLE `spotter_output`  ADD `ModeS` VARCHAR(255) NULL";
84
    		try {
85
            	    $sth = $Connection->db->prepare($query);
86
		    $sth->execute();
87
    		} catch(PDOException $e) {
88
		    return "error (Add ModeS column in spotter_output) : ".$e->getMessage()."\n";
89
    		}
90
		$query = "ALTER TABLE `spotter_live`  ADD `ModeS` VARCHAR(255)";
91
    		try {
92
            	    $sth = $Connection->db->prepare($query);
93
		    $sth->execute();
94
    		} catch(PDOException $e) {
95
		    return "error (Add ModeS column in spotter_live) : ".$e->getMessage()."\n";
96
    		}
97
    		// Add auto_increment for aircraft_modes
98
    		$query = "ALTER TABLE `aircraft_modes` CHANGE `AircraftID` `AircraftID` INT(11) NOT NULL AUTO_INCREMENT";
99
    		try {
100
            	    $sth = $Connection->db->prepare($query);
101
		    $sth->execute();
102
    		} catch(PDOException $e) {
103
		    return "error (Add Auto increment in aircraft_modes) : ".$e->getMessage()."\n";
104
    		}
105
    		$error = '';
106
		$error .= create_db::import_file('../db/acars_live.sql');
107
		$error .= create_db::import_file('../db/config.sql');
108
		// Update schema_version to 2
109
		$query = "UPDATE `config` SET `value` = '2' WHERE `name` = 'schema_version'";
110
        	try {
111
            	    $sth = $Connection->db->prepare($query);
112
		    $sth->execute();
113
    		} catch(PDOException $e) {
114
		    return "error (update schema_version) : ".$e->getMessage()."\n";
115
    		}
116
		return $error;
117
        }
118
119
	private static function update_from_2() {
120
    		$Connection = new Connection();
121
    		// Add new column decode to acars_live table
122
		$query = "ALTER TABLE `acars_live` ADD `decode` TEXT";
123
        	try {
124
            	    $sth = $Connection->db->prepare($query);
125
		    $sth->execute();
126
    		} catch(PDOException $e) {
127
		    return "error (add new columns to routes table) : ".$e->getMessage()."\n";
128
    		}
129
    		$error = '';
130
    		// Create table acars_archive
131
		$error .= create_db::import_file('../db/acars_archive.sql');
132
		// Update schema_version to 3
133
		$query = "UPDATE `config` SET `value` = '3' WHERE `name` = 'schema_version'";
134
        	try {
135
            	    $sth = $Connection->db->prepare($query);
136
		    $sth->execute();
137
    		} catch(PDOException $e) {
138
		    return "error (update schema_version) : ".$e->getMessage()."\n";
139
    		}
140
		return $error;
141
	}
142
143
	private static function update_from_3() {
144
    		$Connection = new Connection();
145
    		// Add default CURRENT_TIMESTAMP to aircraft_modes column FirstCreated
146
		$query = "ALTER TABLE `aircraft_modes` CHANGE `FirstCreated` `FirstCreated` timestamp DEFAULT CURRENT_TIMESTAMP";
147
        	try {
148
            	    $sth = $Connection->db->prepare($query);
149
		    $sth->execute();
150
    		} catch(PDOException $e) {
151
		    return "error (add new columns to aircraft_modes) : ".$e->getMessage()."\n";
152
    		}
153
    		// Add image_source_website column to spotter_image
154
		$query = "ALTER TABLE `spotter_image` ADD `image_source_website` VARCHAR(999) NULL";
155
        	try {
156
            	    $sth = $Connection->db->prepare($query);
157
		    $sth->execute();
158
    		} catch(PDOException $e) {
159
		    return "error (add new columns to spotter_image) : ".$e->getMessage()."\n";
160
    		}
161
    		$error = '';
162
		// Update schema_version to 4
163
		$query = "UPDATE `config` SET `value` = '4' WHERE `name` = 'schema_version'";
164
        	try {
165
            	    $sth = $Connection->db->prepare($query);
166
		    $sth->execute();
167
    		} catch(PDOException $e) {
168
		    return "error (update schema_version) : ".$e->getMessage()."\n";
169
    		}
170
		return $error;
171
	}
172
	
173
	private static function update_from_4() {
174
    		$Connection = new Connection();
175
	
176
    		$error = '';
177
    		// Create table acars_label
178
		$error .= create_db::import_file('../db/acars_label.sql');
179
		if ($error == '') {
180
		    // Update schema_version to 5
181
		    $query = "UPDATE `config` SET `value` = '5' WHERE `name` = 'schema_version'";
182
        	    try {
183
            		$sth = $Connection->db->prepare($query);
184
			$sth->execute();
185
    		    } catch(PDOException $e) {
186
			return "error (update schema_version) : ".$e->getMessage()."\n";
187
    		    }
188
    		}
189
		return $error;
190
	}
191
192
	private static function update_from_5() {
193
    		$Connection = new Connection();
194
    		// Add columns to translation
195
		$query = "ALTER TABLE `translation` ADD `Source` VARCHAR(255) NULL, ADD `date_added` timestamp DEFAULT CURRENT_TIMESTAMP , ADD `date_modified` timestamp DEFAULT CURRENT_TIMESTAMP ;";
196
        	try {
197
            	    $sth = $Connection->db->prepare($query);
198
		    $sth->execute();
199
    		} catch(PDOException $e) {
200
		    return "error (add new columns to translation) : ".$e->getMessage()."\n";
201
    		}
202
    		// Add aircraft_shadow column to aircraft
203
    		$query = "ALTER TABLE `aircraft` ADD `aircraft_shadow` VARCHAR(255) NULL";
204
        	try {
205
            	    $sth = $Connection->db->prepare($query);
206
		    $sth->execute();
207
    		} catch(PDOException $e) {
208
		    return "error (add new column to aircraft) : ".$e->getMessage()."\n";
209
    		}
210
    		// Add aircraft_shadow column to spotter_live
211
    		$query = "ALTER TABLE `spotter_live` ADD `aircraft_shadow` VARCHAR(255) NULL";
212
        	try {
213
            	    $sth = $Connection->db->prepare($query);
214
		    $sth->execute();
215
    		} catch(PDOException $e) {
216
		    return "error (add new column to spotter_live) : ".$e->getMessage()."\n";
217
    		}
218
    		$error = '';
219
    		// Update table aircraft
220
		$error .= create_db::import_file('../db/aircraft.sql');
221
		$error .= create_db::import_file('../db/spotter_archive.sql');
222
223
		// Update schema_version to 6
224
		$query = "UPDATE `config` SET `value` = '6' WHERE `name` = 'schema_version'";
225
        	try {
226
            	    $sth = $Connection->db->prepare($query);
227
		    $sth->execute();
228
    		} catch(PDOException $e) {
229
		    return "error (update schema_version) : ".$e->getMessage()."\n";
230
    		}
231
		return $error;
232
	}
233
234
	private static function update_from_6() {
235
    		$Connection = new Connection();
236
    		if (!$Connection->indexExists('spotter_output','flightaware_id')) {
237
    		    $query = "ALTER TABLE spotter_output ADD INDEX(flightaware_id);
238
			ALTER TABLE spotter_output ADD INDEX(date);
239
			ALTER TABLE spotter_output ADD INDEX(ident);
240
			ALTER TABLE spotter_live ADD INDEX(flightaware_id);
241
			ALTER TABLE spotter_live ADD INDEX(ident);
242
			ALTER TABLE spotter_live ADD INDEX(date);
243
			ALTER TABLE spotter_live ADD INDEX(longitude);
244
			ALTER TABLE spotter_live ADD INDEX(latitude);
245
			ALTER TABLE routes ADD INDEX(CallSign);
246
			ALTER TABLE aircraft_modes ADD INDEX(ModeS);
247
			ALTER TABLE aircraft ADD INDEX(icao);
248
			ALTER TABLE airport ADD INDEX(icao);
249
			ALTER TABLE translation ADD INDEX(Operator);";
250
        	    try {
251
            		$sth = $Connection->db->prepare($query);
252
			$sth->execute();
253
    		    } catch(PDOException $e) {
254
			return "error (add some indexes) : ".$e->getMessage()."\n";
255
    		    }
256
    		}
257
    		$error = '';
258
    		// Update table countries
259
    		if ($Connection->tableExists('airspace')) {
260
    		    $error .= update_db::update_countries();
261
		    if ($error != '') return $error;
262
		}
263
		// Update schema_version to 7
264
		$query = "UPDATE `config` SET `value` = '7' WHERE `name` = 'schema_version'";
265
        	try {
266
            	    $sth = $Connection->db->prepare($query);
267
		    $sth->execute();
268
    		} catch(PDOException $e) {
269
		    return "error (update schema_version) : ".$e->getMessage()."\n";
270
    		}
271
		return $error;
272
    	}
273
274
	private static function update_from_7() {
275
		global $globalDBname, $globalDBdriver;
276
    		$Connection = new Connection();
277
    		$query="ALTER TABLE spotter_live ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;
278
    			ALTER TABLE spotter_output ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;";
279
        	try {
280
            	    $sth = $Connection->db->prepare($query);
281
		    $sth->execute();
282
    		} catch(PDOException $e) {
283
		    return "error (add pilot column to spotter_live and spotter_output) : ".$e->getMessage()."\n";
284
    		}
285
    		if ($globalDBdriver == 'mysql') {
286
    		    $query = "SELECT ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = '".$globalDBname."' AND TABLE_NAME = 'spotter_archive'";
287
		    try {
288
            		$sth = $Connection->db->prepare($query);
289
			$sth->execute();
290
    		    } catch(PDOException $e) {
291
			return "error (problem when select engine for spotter_engine) : ".$e->getMessage()."\n";
292
    		    }
293
    		    $row = $sth->fetch(PDO::FETCH_ASSOC);
294
    		    if ($row['engine'] == 'ARCHIVE') {
295
			$query = "CREATE TABLE copy LIKE spotter_archive; 
296
				ALTER TABLE copy ENGINE=ARCHIVE;
297
				ALTER TABLE copy ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL;
298
				INSERT INTO copy SELECT *, '' as pilot_name, '' as pilot_id FROM spotter_archive ORDER BY `spotter_archive_id`;
299
				DROP TABLE spotter_archive;
300
				RENAME TABLE copy TO spotter_archive;";
301
            	    } else {
302
    			$query="ALTER TABLE spotter_archive ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL";
303
            	    }
304
                } else {
305
    		    $query="ALTER TABLE spotter_archive ADD pilot_name VARCHAR(255) NULL, ADD pilot_id VARCHAR(255) NULL";
306
                }
307
        	try {
308
            	    $sth = $Connection->db->prepare($query);
309
		    $sth->execute();
310
    		} catch(PDOException $e) {
311
		    return "error (add pilot column to spotter_archive) : ".$e->getMessage()."\n";
312
    		}
313
314
    		$error = '';
315
    		// Update table aircraft
316
		$error .= create_db::import_file('../db/source_location.sql');
317
		if ($error != '') return $error;
318
		// Update schema_version to 6
319
		$query = "UPDATE `config` SET `value` = '8' WHERE `name` = 'schema_version'";
320
        	try {
321
            	    $sth = $Connection->db->prepare($query);
322
		    $sth->execute();
323
    		} catch(PDOException $e) {
324
		    return "error (update schema_version) : ".$e->getMessage()."\n";
325
    		}
326
		return $error;
327
	}
328
329
	private static function update_from_8() {
330
    		$Connection = new Connection();
331
    		$error = '';
332
    		// Update table aircraft
333
		$error .= create_db::import_file('../db/notam.sql');
334
		if ($error != '') return $error;
335
		$query = "DELETE FROM config WHERE name = 'last_update_db';
336
                        INSERT INTO config (name,value) VALUES ('last_update_db',NOW());
337
                        DELETE FROM config WHERE name = 'last_update_notam_db';
338
                        INSERT INTO config (name,value) VALUES ('last_update_notam_db',NOW());";
339
        	try {
340
            	    $sth = $Connection->db->prepare($query);
341
		    $sth->execute();
342
    		} catch(PDOException $e) {
343
		    return "error (insert last_update values) : ".$e->getMessage()."\n";
344
    		}
345
		$query = "UPDATE `config` SET `value` = '9' WHERE `name` = 'schema_version'";
346
        	try {
347
            	    $sth = $Connection->db->prepare($query);
348
		    $sth->execute();
349
    		} catch(PDOException $e) {
350
		    return "error (update schema_version) : ".$e->getMessage()."\n";
351
    		}
352
		return $error;
353
	}
354
355
	private static function update_from_9() {
356
    		$Connection = new Connection();
357
    		$query="ALTER TABLE spotter_live ADD verticalrate INT(11) NULL;
358
    			ALTER TABLE spotter_output ADD verticalrate INT(11) NULL;";
359
        	try {
360
            	    $sth = $Connection->db->prepare($query);
361
		    $sth->execute();
362
    		} catch(PDOException $e) {
363
		    return "error (add verticalrate column to spotter_live and spotter_output) : ".$e->getMessage()."\n";
364
    		}
365
		$error = '';
366
    		// Update table atc
367
		$error .= create_db::import_file('../db/atc.sql');
368
		if ($error != '') return $error;
369
		
370
		$query = "UPDATE `config` SET `value` = '10' WHERE `name` = 'schema_version'";
371
        	try {
372
            	    $sth = $Connection->db->prepare($query);
373
		    $sth->execute();
374
    		} catch(PDOException $e) {
375
		    return "error (update schema_version) : ".$e->getMessage()."\n";
376
    		}
377
		return $error;
378
	}
379
380
	private static function update_from_10() {
381
    		$Connection = new Connection();
382
    		$query="ALTER TABLE atc CHANGE `type` `type` ENUM('Observer','Flight Information','Delivery','Tower','Approach','ACC','Departure','Ground','Flight Service Station','Control Radar or Centre') CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL";
383
        	try {
384
            	    $sth = $Connection->db->prepare($query);
385
		    $sth->execute();
386
    		} catch(PDOException $e) {
387
		    return "error (add new enum to ATC table) : ".$e->getMessage()."\n";
388
    		}
389
		$error = '';
390
    		// Add tables
391
		$error .= create_db::import_file('../db/aircraft_owner.sql');
392
		if ($error != '') return $error;
393
		$error .= create_db::import_file('../db/metar.sql');
394
		if ($error != '') return $error;
395
		$error .= create_db::import_file('../db/taf.sql');
396
		if ($error != '') return $error;
397
		$error .= create_db::import_file('../db/airport.sql');
398
		if ($error != '') return $error;
399
		
400
		$query = "UPDATE `config` SET `value` = '11' WHERE `name` = 'schema_version'";
401
        	try {
402
            	    $sth = $Connection->db->prepare($query);
403
		    $sth->execute();
404
    		} catch(PDOException $e) {
405
		    return "error (update schema_version) : ".$e->getMessage()."\n";
406
    		}
407
		return $error;
408
	}
409
410
	private static function update_from_11() {
411
		global $globalDBdriver, $globalDBname;
412
    		$Connection = new Connection();
413
    		$query="ALTER TABLE spotter_output ADD owner_name VARCHAR(255) NULL DEFAULT NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE, ADD last_ground BOOLEAN NOT NULL DEFAULT FALSE, ADD last_seen DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, ADD last_latitude FLOAT NULL, ADD last_longitude FLOAT NULL, ADD last_altitude INT(11) NULL, ADD last_ground_speed INT(11), ADD real_arrival_airport_icao VARCHAR(999), ADD real_arrival_airport_time VARCHAR(20),ADD real_departure_airport_icao VARCHAR(999), ADD real_departure_airport_time VARCHAR(20)";
414
        	try {
415
            	    $sth = $Connection->db->prepare($query);
416
		    $sth->execute();
417
    		} catch(PDOException $e) {
418
		    return "error (add owner_name & format_source column to spotter_output) : ".$e->getMessage()."\n";
419
    		}
420
    		$query="ALTER TABLE spotter_live ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
421
        	try {
422
            	    $sth = $Connection->db->prepare($query);
423
		    $sth->execute();
424
    		} catch(PDOException $e) {
425
		    return "error (format_source column to spotter_live) : ".$e->getMessage()."\n";
426
    		}
427
    		if ($globalDBdriver == 'mysql') {
428
    		    $query = "SELECT ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = '".$globalDBname."' AND TABLE_NAME = 'spotter_archive'";
429
		    try {
430
            		$sth = $Connection->db->prepare($query);
431
			$sth->execute();
432
    		    } catch(PDOException $e) {
433
			return "error (problem when select engine for spotter_engine) : ".$e->getMessage()."\n";
434
    		    }
435
    		    $row = $sth->fetch(PDO::FETCH_ASSOC);
436
    		    if ($row['engine'] == 'ARCHIVE') {
437
			$query = "CREATE TABLE copy LIKE spotter_archive; 
438
				ALTER TABLE copy ENGINE=ARCHIVE;
439
				ALTER TABLE copy ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE;
440
				INSERT INTO copy SELECT *, '' as verticalrate, '' as format_source, '0' as ground FROM spotter_archive ORDER BY `spotter_archive_id`;
441
				DROP TABLE spotter_archive;
442
				RENAME TABLE copy TO spotter_archive;";
443
            	    } else {
444
    			$query="ALTER TABLE spotter_archive ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
445
            	    }
446
                } else {
447
    		    $query="ALTER TABLE spotter_archive ADD verticalrate INT(11) NULL, ADD format_source VARCHAR(255) NULL DEFAULT NULL, ADD ground BOOLEAN NOT NULL DEFAULT FALSE";
448
                }
449
        	try {
450
            	    $sth = $Connection->db->prepare($query);
451
		    $sth->execute();
452
    		} catch(PDOException $e) {
453
		    return "error (add columns to spotter_archive) : ".$e->getMessage()."\n";
454
    		}
455
456
		$error = '';
457
		
458
		$query = "UPDATE `config` SET `value` = '12' WHERE `name` = 'schema_version'";
459
        	try {
460
            	    $sth = $Connection->db->prepare($query);
461
		    $sth->execute();
462
    		} catch(PDOException $e) {
463
		    return "error (update schema_version) : ".$e->getMessage()."\n";
464
    		}
465
		return $error;
466
	}
467
	private static function update_from_12() {
468
    		$Connection = new Connection();
469
		$error = '';
470
    		// Add tables
471
		$error .= create_db::import_file('../db/stats.sql');
472
		if ($error != '') return $error;
473
		$error .= create_db::import_file('../db/stats_aircraft.sql');
474
		if ($error != '') return $error;
475
		$error .= create_db::import_file('../db/stats_airline.sql');
476
		if ($error != '') return $error;
477
		$error .= create_db::import_file('../db/stats_airport.sql');
478
		if ($error != '') return $error;
479
		$error .= create_db::import_file('../db/stats_owner.sql');
480
		if ($error != '') return $error;
481
		$error .= create_db::import_file('../db/stats_pilot.sql');
482
		if ($error != '') return $error;
483
		$error .= create_db::import_file('../db/spotter_archive_output.sql');
484
		if ($error != '') return $error;
485
		
486
		$query = "UPDATE `config` SET `value` = '13' WHERE `name` = 'schema_version'";
487
        	try {
488
            	    $sth = $Connection->db->prepare($query);
489
		    $sth->execute();
490
    		} catch(PDOException $e) {
491
		    return "error (update schema_version) : ".$e->getMessage()."\n";
492
    		}
493
		return $error;
494
	}
495
496
	private static function update_from_13() {
497
    		$Connection = new Connection();
498
    		if (!$Connection->checkColumnName('spotter_archive_output','real_departure_airport_icao')) {
499
    			$query="ALTER TABLE spotter_archive_output ADD real_departure_airport_icao VARCHAR(20), ADD real_departure_airport_time VARCHAR(20)";
500
			try {
501
				$sth = $Connection->db->prepare($query);
502
				$sth->execute();
503
	    		} catch(PDOException $e) {
504
				return "error (update spotter_archive_output) : ".$e->getMessage()."\n";
505
    			}
506
		}
507
    		$error = '';
508
		$query = "UPDATE `config` SET `value` = '14' WHERE `name` = 'schema_version'";
509
        	try {
510
            	    $sth = $Connection->db->prepare($query);
511
		    $sth->execute();
512
    		} catch(PDOException $e) {
513
		    return "error (update schema_version) : ".$e->getMessage()."\n";
514
    		}
515
		return $error;
516
	}
517
518
	private static function update_from_14() {
519
    		$Connection = new Connection();
520
		$error = '';
521
    		// Add tables
522
    		if (!$Connection->tableExists('stats_flight')) {
523
			$error .= create_db::import_file('../db/stats_flight.sql');
524
			if ($error != '') return $error;
525
		}
526
		$query = "UPDATE `config` SET `value` = '15' WHERE `name` = 'schema_version'";
527
        	try {
528
            	    $sth = $Connection->db->prepare($query);
529
		    $sth->execute();
530
    		} catch(PDOException $e) {
531
		    return "error (update schema_version) : ".$e->getMessage()."\n";
532
    		}
533
		return $error;
534
	}
535
536
537
	private static function update_from_15() {
538
    		$Connection = new Connection();
539
		$error = '';
540
    		// Add tables
541
    		$query="ALTER TABLE `stats` CHANGE `stats_date` `stats_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP";
542
        	try {
543
            	    $sth = $Connection->db->prepare($query);
544
		    $sth->execute();
545
    		} catch(PDOException $e) {
546
		    return "error (update stats) : ".$e->getMessage()."\n";
547
    		}
548
		if ($error != '') return $error;
549
		$query = "UPDATE `config` SET `value` = '16' WHERE `name` = 'schema_version'";
550
        	try {
551
            	    $sth = $Connection->db->prepare($query);
552
		    $sth->execute();
553
    		} catch(PDOException $e) {
554
		    return "error (update schema_version) : ".$e->getMessage()."\n";
555
    		}
556
		return $error;
557
	}
558
559
	private static function update_from_16() {
560
    		$Connection = new Connection();
561
		$error = '';
562
    		// Add tables
563
    		if (!$Connection->tableExists('stats_registration')) {
564
			$error .= create_db::import_file('../db/stats_registration.sql');
565
		}
566
    		if (!$Connection->tableExists('stats_callsign')) {
567
			$error .= create_db::import_file('../db/stats_callsign.sql');
568
		}
569
		if ($error != '') return $error;
570
		$query = "UPDATE `config` SET `value` = '17' WHERE `name` = 'schema_version'";
571
        	try {
572
            	    $sth = $Connection->db->prepare($query);
573
		    $sth->execute();
574
    		} catch(PDOException $e) {
575
		    return "error (update schema_version) : ".$e->getMessage()."\n";
576
    		}
577
		return $error;
578
	}
579
580
	private static function update_from_17() {
581
    		$Connection = new Connection();
582
		$error = '';
583
    		// Add tables
584
    		if (!$Connection->tableExists('stats_country')) {
585
			$error .= create_db::import_file('../db/stats_country.sql');
586
		}
587
		if ($error != '') return $error;
588
		$query = "UPDATE `config` SET `value` = '18' WHERE `name` = 'schema_version'";
589
        	try {
590
            	    $sth = $Connection->db->prepare($query);
591
		    $sth->execute();
592
    		} catch(PDOException $e) {
593
		    return "error (update schema_version) : ".$e->getMessage()."\n";
594
    		}
595
		return $error;
596
	}
597
	private static function update_from_18() {
598
    		$Connection = new Connection();
599
		$error = '';
600
    		// Modify stats_airport table
601
    		if (!$Connection->checkColumnName('stats_airport','airport_name')) {
602
    			$query = "ALTER TABLE `stats_airport` ADD `stats_type` VARCHAR(50) NOT NULL DEFAULT 'yearly', ADD `airport_name` VARCHAR(255) NOT NULL, ADD `date` DATE NULL DEFAULT NULL, DROP INDEX `airport_icao`, ADD UNIQUE `airport_icao` (`airport_icao`, `type`, `date`)";
603
    	        	try {
604
	            	    $sth = $Connection->db->prepare($query);
605
			    $sth->execute();
606
    			} catch(PDOException $e) {
607
			    return "error (update stats) : ".$e->getMessage()."\n";
608
    			}
609
    		}
610
		if ($error != '') return $error;
611
		$query = "UPDATE `config` SET `value` = '19' WHERE `name` = 'schema_version'";
612
        	try {
613
            	    $sth = $Connection->db->prepare($query);
614
		    $sth->execute();
615
    		} catch(PDOException $e) {
616
		    return "error (update schema_version) : ".$e->getMessage()."\n";
617
    		}
618
		return $error;
619
	}
620
621
	private static function update_from_19() {
622
    		$Connection = new Connection();
623
		$error = '';
624
    		// Update airport table
625
		$error .= create_db::import_file('../db/airport.sql');
626
		if ($error != '') return 'Import airport.sql : '.$error;
627
		// Remove primary key on Spotter_Archive
628
		$query = "alter table spotter_archive drop spotter_archive_id";
629
        	try {
630
            	    $sth = $Connection->db->prepare($query);
631
		    $sth->execute();
632
    		} catch(PDOException $e) {
633
		    return "error (remove primary key on spotter_archive) : ".$e->getMessage()."\n";
634
    		}
635
		$query = "alter table spotter_archive add spotter_archive_id INT(11)";
636
        	try {
637
            	    $sth = $Connection->db->prepare($query);
638
		    $sth->execute();
639
    		} catch(PDOException $e) {
640
		    return "error (add id again on spotter_archive) : ".$e->getMessage()."\n";
641
    		}
642
		if (!$Connection->checkColumnName('spotter_archive','over_country')) {
643
			// Add column over_country
644
    			$query = "ALTER TABLE `spotter_archive` ADD `over_country` VARCHAR(5) NULL DEFAULT NULL";
645
			try {
646
            			$sth = $Connection->db->prepare($query);
647
				$sth->execute();
648
			} catch(PDOException $e) {
649
				return "error (add over_country) : ".$e->getMessage()."\n";
650
			}
651
		}
652
		if (!$Connection->checkColumnName('spotter_live','over_country')) {
653
			// Add column over_country
654
    			$query = "ALTER TABLE `spotter_live` ADD `over_country` VARCHAR(5) NULL DEFAULT NULL";
655
			try {
656
            			$sth = $Connection->db->prepare($query);
657
				$sth->execute();
658
			} catch(PDOException $e) {
659
				return "error (add over_country) : ".$e->getMessage()."\n";
660
			}
661
		}
662
		if (!$Connection->checkColumnName('spotter_output','source_name')) {
663
			// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
664
    			$query = "ALTER TABLE `spotter_output` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
665
			try {
666
				$sth = $Connection->db->prepare($query);
667
				$sth->execute();
668
			} catch(PDOException $e) {
669
				return "error (add source_name column) : ".$e->getMessage()."\n";
670
    			}
671
    		}
672
		if (!$Connection->checkColumnName('spotter_live','source_name')) {
673
			// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
674
    			$query = "ALTER TABLE `spotter_live` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
675
			try {
676
				$sth = $Connection->db->prepare($query);
677
				$sth->execute();
678
			} catch(PDOException $e) {
679
				return "error (add source_name column) : ".$e->getMessage()."\n";
680
    			}
681
    		}
682
		if (!$Connection->checkColumnName('spotter_archive_output','source_name')) {
683
			// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
684
    			$query = "ALTER TABLE `spotter_archive_output` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`";
685
			try {
686
				$sth = $Connection->db->prepare($query);
687
				$sth->execute();
688
			} catch(PDOException $e) {
689
				return "error (add source_name column) : ".$e->getMessage()."\n";
690
    			}
691
    		}
692
		if (!$Connection->checkColumnName('spotter_archive','source_name')) {
693
			// Add source_name to spotter_output, spotter_live, spotter_archive, spotter_archive_output
694
    			$query = "ALTER TABLE `spotter_archive` ADD `source_name` VARCHAR(255) NULL AFTER `format_source`;";
695
			try {
696
				$sth = $Connection->db->prepare($query);
697
				$sth->execute();
698
			} catch(PDOException $e) {
699
				return "error (add source_name column) : ".$e->getMessage()."\n";
700
    			}
701
    		}
702
		if ($error != '') return $error;
703
		$query = "UPDATE `config` SET `value` = '20' WHERE `name` = 'schema_version'";
704
        	try {
705
            	    $sth = $Connection->db->prepare($query);
706
		    $sth->execute();
707
    		} catch(PDOException $e) {
708
		    return "error (update schema_version) : ".$e->getMessage()."\n";
709
    		}
710
		return $error;
711
	}
712
713
	private static function update_from_20() {
714
		global $globalIVAO, $globalVATSIM, $globalphpVMS;
715
    		$Connection = new Connection();
716
		$error = '';
717
    		// Update airline table
718
    		if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
719
			$error .= create_db::import_file('../db/airlines.sql');
720
			if ($error != '') return 'Import airlines.sql : '.$error;
721
		}
722
		if (!$Connection->checkColumnName('aircraft_modes','type_flight')) {
723
			// Add column over_country
724
    			$query = "ALTER TABLE `aircraft_modes` ADD `type_flight` VARCHAR(50) NULL DEFAULT NULL;";
725
        		try {
726
				$sth = $Connection->db->prepare($query);
727
				$sth->execute();
728
			} catch(PDOException $e) {
729
				return "error (add over_country) : ".$e->getMessage()."\n";
730
    			}
731
    		}
732
		if ($error != '') return $error;
733
		/*
734
    		if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS) {
735
			// Force update ModeS (this will put type_flight data
736
			$error .= update_db::update_ModeS;
737
			if ($error != '') return "error (update ModeS) : ".$error;
738
		}
739
		*/
740
		$query = "UPDATE `config` SET `value` = '21' WHERE `name` = 'schema_version'";
741
        	try {
742
            	    $sth = $Connection->db->prepare($query);
743
		    $sth->execute();
744
    		} catch(PDOException $e) {
745
		    return "error (update schema_version) : ".$e->getMessage()."\n";
746
    		}
747
		return $error;
748
	}
749
750
	private static function update_from_21() {
751
		$Connection = new Connection();
752
		$error = '';
753
		if (!$Connection->checkColumnName('stats_airport','stats_type')) {
754
			// Rename type to stats_type
755
			$query = "ALTER TABLE `stats_airport` CHANGE `type` `stats_type` VARCHAR(50);ALTER TABLE `stats` CHANGE `type` `stats_type` VARCHAR(50);ALTER TABLE `stats_flight` CHANGE `type` `stats_type` VARCHAR(50);";
756
			try {
757
				$sth = $Connection->db->prepare($query);
758
				$sth->execute();
759
			} catch(PDOException $e) {
760
				return "error (rename type to stats_type on stats*) : ".$e->getMessage()."\n";
761
			}
762
			if ($error != '') return $error;
763
		}
764
		$query = "UPDATE `config` SET `value` = '22' WHERE `name` = 'schema_version'";
765
        	try {
766
            	    $sth = $Connection->db->prepare($query);
767
		    $sth->execute();
768
    		} catch(PDOException $e) {
769
		    return "error (update schema_version) : ".$e->getMessage()."\n";
770
    		}
771
		return $error;
772
	}
773
774
	private static function update_from_22() {
775
		global $globalDBdriver;
776
    		$Connection = new Connection();
777
		$error = '';
778
		// Add table stats polar
779
    		if (!$Connection->tableExists('stats_source')) {
780
			if ($globalDBdriver == 'mysql') {
781
    				$error .= create_db::import_file('../db/stats_source.sql');
782
			} else {
783
				$error .= create_db::import_file('../db/pgsql/stats_source.sql');
784
			}
785
			if ($error != '') return $error;
786
		}
787
		$query = "UPDATE config SET value = '23' WHERE name = 'schema_version'";
788
        	try {
789
            	    $sth = $Connection->db->prepare($query);
790
		    $sth->execute();
791
    		} catch(PDOException $e) {
792
		    return "error (update schema_version) : ".$e->getMessage()."\n";
793
    		}
794
		return $error;
795
	}
796
797
798
	private static function update_from_23() {
799
		global $globalDBdriver;
800
		$Connection = new Connection();
801
		$error = '';
802
		// Add table tle for satellites
803
		if ($globalDBdriver == 'mysql') {
804
			if (!$Connection->tableExists('tle')) {
805
				$error .= create_db::import_file('../db/tle.sql');
806
				if ($error != '') return $error;
807
			}
808
		} else {
809
			if (!$Connection->tableExists('tle')) {
810
				$error .= create_db::import_file('../db/pgsql/tle.sql');
811
				if ($error != '') return $error;
812
			}
813
			$query = "create index flightaware_id_idx ON spotter_archive USING btree(flightaware_id)";
814
			try {
815
				$sth = $Connection->db->prepare($query);
816
				$sth->execute();
817
			} catch(PDOException $e) {
818
				return "error (create index on spotter_archive) : ".$e->getMessage()."\n";
819
			}
820
		}
821
		if (!$Connection->checkColumnName('stats_aircraft','aircraft_manufacturer')) {
822
			// Add aircraft_manufacturer to stats_aircraft
823
    			$query = "ALTER TABLE stats_aircraft ADD aircraft_manufacturer VARCHAR(255) NULL";
824
			try {
825
				$sth = $Connection->db->prepare($query);
826
				$sth->execute();
827
			} catch(PDOException $e) {
828
				return "error (add aircraft_manufacturer column) : ".$e->getMessage()."\n";
829
    			}
830
    		}
831
		
832
		$query = "UPDATE config SET value = '24' WHERE name = 'schema_version'";
833
		try {
834
			$sth = $Connection->db->prepare($query);
835
			$sth->execute();
836
		} catch(PDOException $e) {
837
			return "error (update schema_version) : ".$e->getMessage()."\n";
838
		}
839
		return $error;
840
	}
841
842
	private static function update_from_24() {
843
		global $globalDBdriver;
844
		$Connection = new Connection();
845
		$error = '';
846
		if ($globalDBdriver == 'mysql') {
847
			$error .= create_db::import_file('../db/airlines.sql');
848
		} else {
849
			$error .= create_db::import_file('../db/pgsql/airlines.sql');
850
		}
851
		if ($error != '') return 'Import airlines.sql : '.$error;
852
		if (!$Connection->checkColumnName('airlines','forsource')) {
853
			// Add forsource to airlines
854
			$query = "ALTER TABLE airlines ADD forsource VARCHAR(255) NULL DEFAULT NULL";
855
			try {
856
				$sth = $Connection->db->prepare($query);
857
				$sth->execute();
858
			} catch(PDOException $e) {
859
				return "error (add forsource column) : ".$e->getMessage()."\n";
860
			}
861
		}
862
		if (!$Connection->checkColumnName('stats_aircraft','stats_airline')) {
863
			// Add forsource to airlines
864
			$query = "ALTER TABLE stats_aircraft ADD stats_airline VARCHAR(255) NULL DEFAULT '', ADD filter_name VARCHAR(255) NULL DEFAULT ''";
865
			try {
866
				$sth = $Connection->db->prepare($query);
867
				$sth->execute();
868
			} catch(PDOException $e) {
869
				return "error (add stats_airline & filter_name column in stats_aircraft) : ".$e->getMessage()."\n";
870
			}
871
			// Add unique key
872
			if ($globalDBdriver == 'mysql') {
873
				$query = "drop index aircraft_icao on stats_aircraft;ALTER TABLE stats_aircraft ADD UNIQUE aircraft_icao (aircraft_icao,stats_airline,filter_name);";
874
			} else {
875
				$query = "alter table stats_aircraft drop constraint stats_aircraft_aircraft_icao_key;ALTER TABLE stats_aircraft ADD CONSTRAINT aircraft_icao UNIQUE (aircraft_icao,stats_airline,filter_name);";
876
			}
877
			try {
878
				$sth = $Connection->db->prepare($query);
879
				$sth->execute();
880
			} catch(PDOException $e) {
881
				return "error (add unique key in stats_aircraft) : ".$e->getMessage()."\n";
882
			}
883
		}
884
		if (!$Connection->checkColumnName('stats_airport','stats_airline')) {
885
			// Add forsource to airlines
886
			$query = "ALTER TABLE stats_airport ADD stats_airline VARCHAR(255) NULL DEFAULT '', ADD filter_name VARCHAR(255) NULL DEFAULT ''";
887
			try {
888
				$sth = $Connection->db->prepare($query);
889
				$sth->execute();
890
			} catch(PDOException $e) {
891
				return "error (add filter_name column in stats_airport) : ".$e->getMessage()."\n";
892
			}
893
			// Add unique key
894
			if ($globalDBdriver == 'mysql') {
895
				$query = "drop index airport_icao on stats_airport;ALTER TABLE stats_airport ADD UNIQUE airport_icao (airport_icao,stats_type,date,stats_airline,filter_name);";
896
			} else {
897
				$query = "alter table stats_airport drop constraint stats_airport_airport_icao_stats_type_date_key;ALTER TABLE stats_airport ADD CONSTRAINT airport_icao UNIQUE (airport_icao,stats_type,date,stats_airline,filter_name);";
898
			}
899
			try {
900
				$sth = $Connection->db->prepare($query);
901
				$sth->execute();
902
			} catch(PDOException $e) {
903
				return "error (add unique key in stats_airport) : ".$e->getMessage()."\n";
904
			}
905
		}
906
		if (!$Connection->checkColumnName('stats_country','stats_airline')) {
907
			// Add forsource to airlines
908
			$query = "ALTER TABLE stats_country ADD stats_airline VARCHAR(255) NULL DEFAULT '', ADD filter_name VARCHAR(255) NULL DEFAULT ''";
909
			try {
910
				$sth = $Connection->db->prepare($query);
911
				$sth->execute();
912
			} catch(PDOException $e) {
913
				return "error (add stats_airline & filter_name column in stats_country) : ".$e->getMessage()."\n";
914
			}
915
			// Add unique key
916
			if ($globalDBdriver == 'mysql') {
917
				$query = "drop index iso2 on stats_country;ALTER TABLE stats_country ADD UNIQUE iso2 (iso2,stats_airline,filter_name);";
918
			} else {
919
				$query = "alter table stats_country drop constraint stats_country_iso2_key;ALTER TABLE stats_country ADD CONSTRAINT iso2 UNIQUE (iso2,stats_airline,filter_name);";
920
			}
921
			try {
922
				$sth = $Connection->db->prepare($query);
923
				$sth->execute();
924
			} catch(PDOException $e) {
925
				return "error (add unique key in stats_airline) : ".$e->getMessage()."\n";
926
			}
927
		}
928
		if (!$Connection->checkColumnName('stats_flight','stats_airline')) {
929
			// Add forsource to airlines
930
			$query = "ALTER TABLE stats_flight ADD stats_airline VARCHAR(255) NULL DEFAULT '', ADD filter_name VARCHAR(255) NULL DEFAULT ''";
931
			try {
932
				$sth = $Connection->db->prepare($query);
933
				$sth->execute();
934
			} catch(PDOException $e) {
935
				return "error (add stats_airline & filter_name column in stats_flight) : ".$e->getMessage()."\n";
936
			}
937
		}
938
		if (!$Connection->checkColumnName('stats','stats_airline')) {
939
			// Add forsource to airlines
940
			$query = "ALTER TABLE stats ADD stats_airline VARCHAR(255) NULL DEFAULT '', ADD filter_name VARCHAR(255) NULL DEFAULT ''";
941
			try {
942
				$sth = $Connection->db->prepare($query);
943
				$sth->execute();
944
			} catch(PDOException $e) {
945
				return "error (add stats_airline & filter_name column in stats) : ".$e->getMessage()."\n";
946
			}
947
			if ($globalDBdriver == 'mysql' && $Connection->indexExists('stats','type')) {
948
				// Add unique key
949
				$query = "drop index type on stats;ALTER TABLE stats ADD UNIQUE stats_type (stats_type,stats_date,stats_airline,filter_name);";
950
				try {
951
					$sth = $Connection->db->prepare($query);
952
					$sth->execute();
953
				} catch(PDOException $e) {
954
					return "error (add unique key in stats) : ".$e->getMessage()."\n";
955
				}
956
			} else {
957
				// Add unique key
958
				if ($globalDBdriver == 'mysql') {
959
					$query = "drop index stats_type on stats;ALTER TABLE stats ADD UNIQUE stats_type (stats_type,stats_date,stats_airline,filter_name);";
960
				} else {
961
					$query = "alter table stats drop constraint stats_stats_type_stats_date_key;ALTER TABLE stats ADD CONSTRAINT stats_type UNIQUE (stats_type,stats_date,stats_airline,filter_name);";
962
				}
963
				try {
964
					$sth = $Connection->db->prepare($query);
965
					$sth->execute();
966
				} catch(PDOException $e) {
967
					return "error (add unique key in stats) : ".$e->getMessage()."\n";
968
				}
969
			}
970
		}
971
		if (!$Connection->checkColumnName('stats_registration','stats_airline')) {
972
			// Add forsource to airlines
973
			$query = "ALTER TABLE stats_registration ADD stats_airline VARCHAR(255) NULL DEFAULT '', ADD filter_name VARCHAR(255) NULL DEFAULT ''";
974
			try {
975
				$sth = $Connection->db->prepare($query);
976
				$sth->execute();
977
			} catch(PDOException $e) {
978
				return "error (add stats_airline & filter_name column in stats_registration) : ".$e->getMessage()."\n";
979
			}
980
			// Add unique key
981
			if ($globalDBdriver == 'mysql') {
982
				$query = "drop index registration on stats_registration;ALTER TABLE stats_registration ADD UNIQUE registration (registration,stats_airline,filter_name);";
983
			} else {
984
				$query = "alter table stats_registration drop constraint stats_registration_registration_key;ALTER TABLE stats_registration ADD CONSTRAINT registration UNIQUE (registration,stats_airline,filter_name);";
985
			}
986
			try {
987
				$sth = $Connection->db->prepare($query);
988
				$sth->execute();
989
			} catch(PDOException $e) {
990
				return "error (add unique key in stats_registration) : ".$e->getMessage()."\n";
991
			}
992
		}
993
		if (!$Connection->checkColumnName('stats_callsign','filter_name')) {
994
			// Add forsource to airlines
995
			$query = "ALTER TABLE stats_callsign ADD filter_name VARCHAR(255) NULL DEFAULT ''";
996
			try {
997
				$sth = $Connection->db->prepare($query);
998
				$sth->execute();
999
			} catch(PDOException $e) {
1000
				return "error (add filter_name column in stats_callsign) : ".$e->getMessage()."\n";
1001
			}
1002
			// Add unique key
1003
			if ($globalDBdriver == 'mysql') {
1004
				$query = "drop index callsign_icao on stats_callsign;ALTER TABLE stats_callsign ADD UNIQUE callsign_icao (callsign_icao,filter_name);";
1005
			} else {
1006
				$query = "drop index stats_callsign_callsign_icao_key;ALTER TABLE stats_callsign ADD CONSTRAINT callsign_icao UNIQUE (callsign_icao,filter_name);";
1007
			}
1008
			try {
1009
				$sth = $Connection->db->prepare($query);
1010
				$sth->execute();
1011
			} catch(PDOException $e) {
1012
				return "error (add unique key in stats_callsign) : ".$e->getMessage()."\n";
1013
			}
1014
		}
1015
		if (!$Connection->checkColumnName('stats_airline','filter_name')) {
1016
			// Add forsource to airlines
1017
			$query = "ALTER TABLE stats_airline ADD filter_name VARCHAR(255) NULL DEFAULT ''";
1018
			try {
1019
				$sth = $Connection->db->prepare($query);
1020
				$sth->execute();
1021
			} catch(PDOException $e) {
1022
				return "error (add filter_name column in stats_airline) : ".$e->getMessage()."\n";
1023
			}
1024
			// Add unique key
1025
			if ($globalDBdriver == 'mysql') {
1026
				$query = "drop index airline_icao on stats_airline;ALTER TABLE stats_airline ADD UNIQUE airline_icao (airline_icao,filter_name);";
1027
			} else {
1028
				$query = "drop index stats_airline_airline_icao_key;ALTER TABLE stats_airline ADD CONSTRAINT airline_icao UNIQUE (airline_icao,filter_name);";
1029
			}
1030
			try {
1031
				$sth = $Connection->db->prepare($query);
1032
				$sth->execute();
1033
			} catch(PDOException $e) {
1034
				return "error (add unique key in stats_callsign) : ".$e->getMessage()."\n";
1035
			}
1036
		}
1037
		
1038
		$query = "UPDATE config SET value = '25' WHERE name = 'schema_version'";
1039
		try {
1040
			$sth = $Connection->db->prepare($query);
1041
			$sth->execute();
1042
		} catch(PDOException $e) {
1043
			return "error (update schema_version) : ".$e->getMessage()."\n";
1044
		}
1045
		return $error;
1046
	}
1047
1048
	private static function update_from_25() {
1049
		global $globalDBdriver;
1050
		$Connection = new Connection();
1051
		$error = '';
1052
		if (!$Connection->checkColumnName('stats_owner','stats_airline')) {
1053
			// Add forsource to airlines
1054
			$query = "ALTER TABLE stats_owner ADD stats_airline VARCHAR(255) NULL DEFAULT '', ADD filter_name VARCHAR(255) NULL DEFAULT ''";
1055
			try {
1056
				$sth = $Connection->db->prepare($query);
1057
				$sth->execute();
1058
			} catch(PDOException $e) {
1059
				return "error (add stats_airline & filter_name column in stats_owner) : ".$e->getMessage()."\n";
1060
			}
1061
			// Add unique key
1062
			if ($globalDBdriver == 'mysql') {
1063
				$query = "drop index owner_name on stats_owner;ALTER TABLE stats_owner ADD UNIQUE owner_name (owner_name,stats_airline,filter_name);";
1064
			} else {
1065
				$query = "drop index stats_owner_owner_name_key;ALTER TABLE stats_owner ADD CONSTRAINT owner_name UNIQUE (owner_name,stats_airline,filter_name);";
1066
			}
1067
			try {
1068
				$sth = $Connection->db->prepare($query);
1069
				$sth->execute();
1070
			} catch(PDOException $e) {
1071
				return "error (add unique key in stats_owner) : ".$e->getMessage()."\n";
1072
			}
1073
		}
1074
		if (!$Connection->checkColumnName('stats_pilot','stats_airline')) {
1075
			// Add forsource to airlines
1076
			$query = "ALTER TABLE stats_pilot ADD stats_airline VARCHAR(255) NULL DEFAULT '', ADD filter_name VARCHAR(255) NULL DEFAULT ''";
1077
			try {
1078
				$sth = $Connection->db->prepare($query);
1079
				$sth->execute();
1080
			} catch(PDOException $e) {
1081
				return "error (add stats_airline & filter_name column in stats_pilot) : ".$e->getMessage()."\n";
1082
			}
1083
			// Add unique key
1084
			if ($globalDBdriver == 'mysql') {
1085
				$query = "drop index pilot_id on stats_pilot;ALTER TABLE stats_pilot ADD UNIQUE pilot_id (pilot_id,stats_airline,filter_name);";
1086
			} else {
1087
				$query = "drop index stats_pilot_pilot_id_key;ALTER TABLE stats_pilot ADD CONSTRAINT pilot_id UNIQUE (pilot_id,stats_airline,filter_name);";
1088
			}
1089
			try {
1090
				$sth = $Connection->db->prepare($query);
1091
				$sth->execute();
1092
			} catch(PDOException $e) {
1093
				return "error (add unique key in stats_pilot) : ".$e->getMessage()."\n";
1094
			}
1095
		}
1096
		$query = "UPDATE config SET value = '26' WHERE name = 'schema_version'";
1097
		try {
1098
			$sth = $Connection->db->prepare($query);
1099
			$sth->execute();
1100
		} catch(PDOException $e) {
1101
			return "error (update schema_version) : ".$e->getMessage()."\n";
1102
		}
1103
		return $error;
1104
	}
1105
1106
	private static function update_from_26() {
1107
		global $globalDBdriver;
1108
		$Connection = new Connection();
1109
		$error = '';
1110
		if (!$Connection->checkColumnName('atc','format_source')) {
1111
			$query = "ALTER TABLE atc ADD format_source VARCHAR(255) DEFAULT NULL, ADD source_name VARCHAR(255) DEFAULT NULL";
1112
			try {
1113
				$sth = $Connection->db->prepare($query);
1114
				$sth->execute();
1115
			} catch(PDOException $e) {
1116
				return "error (add format_source & source_name column in atc) : ".$e->getMessage()."\n";
1117
			}
1118
		}
1119
		$query = "UPDATE config SET value = '27' WHERE name = 'schema_version'";
1120
		try {
1121
			$sth = $Connection->db->prepare($query);
1122
			$sth->execute();
1123
		} catch(PDOException $e) {
1124
			return "error (update schema_version) : ".$e->getMessage()."\n";
1125
		}
1126
		return $error;
1127
	}
1128
1129
	private static function update_from_27() {
1130
		global $globalDBdriver;
1131
		$Connection = new Connection();
1132
		$error = '';
1133
		if (!$Connection->checkColumnName('stats_pilot','format_source')) {
1134
			// Add forsource to airlines
1135
			$query = "ALTER TABLE stats_pilot ADD format_source VARCHAR(255) NULL DEFAULT ''";
1136
			try {
1137
				$sth = $Connection->db->prepare($query);
1138
				$sth->execute();
1139
			} catch(PDOException $e) {
1140
				return "error (add format_source column in stats_pilot) : ".$e->getMessage()."\n";
1141
			}
1142
			// Add unique key
1143
			if ($globalDBdriver == 'mysql') {
1144
				$query = "drop index pilot_id on stats_pilot;ALTER TABLE stats_pilot ADD UNIQUE pilot_id (pilot_id,stats_airline,filter_name,format_source);";
1145
			} else {
1146
				$query = "drop index pilot_id;ALTER TABLE stats_pilot ADD CONSTRAINT pilot_id UNIQUE (pilot_id,stats_airline,filter_name,format_source);";
1147
			}
1148
			try {
1149
				$sth = $Connection->db->prepare($query);
1150
				$sth->execute();
1151
			} catch(PDOException $e) {
1152
				return "error (modify unique key in stats_pilot) : ".$e->getMessage()."\n";
1153
			}
1154
		}
1155
		$query = "UPDATE config SET value = '28' WHERE name = 'schema_version'";
1156
		try {
1157
			$sth = $Connection->db->prepare($query);
1158
			$sth->execute();
1159
		} catch(PDOException $e) {
1160
			return "error (update schema_version) : ".$e->getMessage()."\n";
1161
		}
1162
		return $error;
1163
	}
1164
1165
	private static function update_from_28() {
1166
		global $globalDBdriver;
1167
		$Connection = new Connection();
1168
		$error = '';
1169
		if ($globalDBdriver == 'mysql' && !$Connection->indexExists('spotter_live','latitude')) {
1170
			// Add unique key
1171
			$query = "alter table spotter_live add index(latitude,longitude)";
1172
			try {
1173
				$sth = $Connection->db->prepare($query);
1174
				$sth->execute();
1175
			} catch(PDOException $e) {
1176
				return "error (add index latitude,longitude on spotter_live) : ".$e->getMessage()."\n";
1177
			}
1178
                }
1179
		if (!$Connection->checkColumnName('aircraft','mfr')) {
1180
			// Add mfr to aircraft
1181
			$query = "ALTER TABLE aircraft ADD mfr VARCHAR(255) NULL";
1182
			try {
1183
				$sth = $Connection->db->prepare($query);
1184
				$sth->execute();
1185
			} catch(PDOException $e) {
1186
				return "error (add mfr column in aircraft) : ".$e->getMessage()."\n";
1187
			}
1188
		}
1189
		if (!$Connection->tableExists('accidents')) {
1190
			if ($globalDBdriver == 'mysql') {
1191
				$error .= create_db::import_file('../db/accidents.sql');
1192
			} else {
1193
				$error .= create_db::import_file('../db/pgsql/accidents.sql');
1194
			}
1195
		}
1196
1197
		$query = "UPDATE config SET value = '29' WHERE name = 'schema_version'";
1198
		try {
1199
			$sth = $Connection->db->prepare($query);
1200
			$sth->execute();
1201
		} catch(PDOException $e) {
1202
			return "error (update schema_version) : ".$e->getMessage()."\n";
1203
		}
1204
		return $error;
1205
	}
1206
1207
	private static function update_from_29() {
1208
		global $globalDBdriver;
1209
		$Connection = new Connection();
1210
		$error = '';
1211
		if ($Connection->checkColumnName('aircraft','mfr')) {
1212
			// drop mfr to aircraft
1213
			$query = "ALTER TABLE aircraft DROP COLUMN mfr";
1214
			try {
1215
				$sth = $Connection->db->prepare($query);
1216
				$sth->execute();
1217
			} catch(PDOException $e) {
1218
				return "error (drop mfr column in aircraft) : ".$e->getMessage()."\n";
1219
			}
1220
		}
1221
		if (!$Connection->tableExists('faamfr')) {
1222
			if ($globalDBdriver == 'mysql') {
1223
				$error .= create_db::import_file('../db/faamfr.sql');
1224
			} else {
1225
				$error .= create_db::import_file('../db/pgsql/faamfr.sql');
1226
			}
1227
		}
1228
1229
		$query = "UPDATE config SET value = '30' WHERE name = 'schema_version'";
1230
		try {
1231
			$sth = $Connection->db->prepare($query);
1232
			$sth->execute();
1233
		} catch(PDOException $e) {
1234
			return "error (update schema_version) : ".$e->getMessage()."\n";
1235
		}
1236
		return $error;
1237
	}
1238
1239
	private static function update_from_30() {
1240
		global $globalDBdriver;
1241
		$Connection = new Connection();
1242
		$error = '';
1243
		if (!$Connection->indexExists('notam','ref_idx')) {
1244
			// Add index key
1245
			$query = "create index ref_idx on notam (ref)";
1246
			try {
1247
				$sth = $Connection->db->prepare($query);
1248
				$sth->execute();
1249
			} catch(PDOException $e) {
1250
				return "error (add index ref on notam) : ".$e->getMessage()."\n";
1251
			}
1252
                }
1253
		if (!$Connection->indexExists('accidents','registration_idx')) {
1254
			// Add index key
1255
			$query = "create index registration_idx on accidents (registration)";
1256
			try {
1257
				$sth = $Connection->db->prepare($query);
1258
				$sth->execute();
1259
			} catch(PDOException $e) {
1260
				return "error (add index registration on accidents) : ".$e->getMessage()."\n";
1261
			}
1262
                }
1263
		if (!$Connection->indexExists('accidents','rdts')) {
1264
			// Add index key
1265
			$query = "create index rdts on accidents (registration,date,type,source)";
1266
			try {
1267
				$sth = $Connection->db->prepare($query);
1268
				$sth->execute();
1269
			} catch(PDOException $e) {
1270
				return "error (add index registration, date, type & source on accidents) : ".$e->getMessage()."\n";
1271
			}
1272
                }
1273
1274
		$query = "UPDATE config SET value = '31' WHERE name = 'schema_version'";
1275
		try {
1276
			$sth = $Connection->db->prepare($query);
1277
			$sth->execute();
1278
		} catch(PDOException $e) {
1279
			return "error (update schema_version) : ".$e->getMessage()."\n";
1280
		}
1281
		return $error;
1282
	}
1283
1284
	private static function update_from_31() {
1285
		global $globalDBdriver;
1286
		$Connection = new Connection();
1287
		$error = '';
1288
		if (!$Connection->checkColumnName('accidents','airline_name')) {
1289
			// Add airline_name to accidents
1290
			$query = "ALTER TABLE accidents ADD airline_name VARCHAR(255) NULL";
1291
			try {
1292
				$sth = $Connection->db->prepare($query);
1293
				$sth->execute();
1294
			} catch(PDOException $e) {
1295
				return "error (add airline_name column in accidents) : ".$e->getMessage()."\n";
1296
			}
1297
		}
1298
		if (!$Connection->checkColumnName('accidents','airline_icao')) {
1299
			// Add airline_icao to accidents
1300
			$query = "ALTER TABLE accidents ADD airline_icao VARCHAR(10) NULL";
1301
			try {
1302
				$sth = $Connection->db->prepare($query);
1303
				$sth->execute();
1304
			} catch(PDOException $e) {
1305
				return "error (add airline_icao column in accidents) : ".$e->getMessage()."\n";
1306
			}
1307
		}
1308
		$query = "UPDATE config SET value = '32' WHERE name = 'schema_version'";
1309
		try {
1310
			$sth = $Connection->db->prepare($query);
1311
			$sth->execute();
1312
		} catch(PDOException $e) {
1313
			return "error (update schema_version) : ".$e->getMessage()."\n";
1314
		}
1315
		return $error;
1316
	}
1317
1318
	private static function update_from_32() {
1319
		global $globalDBdriver, $globalVATSIM, $globalIVAO;
1320
		$Connection = new Connection();
1321
		$error = '';
1322
		if (!$Connection->checkColumnName('airlines','alliance')) {
1323
			// Add alliance to airlines
1324
			$query = "ALTER TABLE airlines ADD alliance VARCHAR(255) NULL";
1325
			try {
1326
				$sth = $Connection->db->prepare($query);
1327
				$sth->execute();
1328
			} catch(PDOException $e) {
1329
				return "error (add alliance column in airlines) : ".$e->getMessage()."\n";
1330
			}
1331
		}
1332
		if ($globalDBdriver == 'mysql') {
1333
			$error .= create_db::import_file('../db/airlines.sql');
1334
			if ($error != '') return $error;
1335
		} else {
1336
			$error .= create_db::import_file('../db/pgsql/airlines.sql');
1337
			if ($error != '') return $error;
1338
		}
1339
		if ((isset($globalVATSIM) && $globalVATSIM) || (isset($globalIVAO) && $globalIVAO)) {
1340
			include_once(dirname(__FILE__).'/class.update_db.php');
1341
			if (isset($globalVATSIM) && $globalVATSIM) {
1342
				$error .= update_db::update_vatsim();
1343
				if ($error != '') return $error;
1344
			}
1345
			if (isset($globalIVAO) && $globalIVAO && file_exists('tmp/ivae_feb2013.zip')) {
1346
				$error .= update_db::update_IVAO();
1347
				if ($error != '') return $error;
1348
			}
1349
		}
1350
1351
		$query = "UPDATE config SET value = '33' WHERE name = 'schema_version'";
1352
		try {
1353
			$sth = $Connection->db->prepare($query);
1354
			$sth->execute();
1355
		} catch(PDOException $e) {
1356
			return "error (update schema_version) : ".$e->getMessage()."\n";
1357
		}
1358
		return $error;
1359
	}
1360
1361
	private static function update_from_33() {
1362
		global $globalDBdriver, $globalVATSIM, $globalIVAO;
1363
		$Connection = new Connection();
1364
		$error = '';
1365
		if (!$Connection->checkColumnName('airlines','ban_eu')) {
1366
			// Add ban_eu to airlines
1367
			$query = "ALTER TABLE airlines ADD ban_eu INTEGER NOT NULL DEFAULT '0'";
1368
			try {
1369
				$sth = $Connection->db->prepare($query);
1370
				$sth->execute();
1371
			} catch(PDOException $e) {
1372
				return "error (add ban_eu column in airlines) : ".$e->getMessage()."\n";
1373
			}
1374
		}
1375
		$query = "UPDATE config SET value = '34' WHERE name = 'schema_version'";
1376
		try {
1377
			$sth = $Connection->db->prepare($query);
1378
			$sth->execute();
1379
		} catch(PDOException $e) {
1380
			return "error (update schema_version) : ".$e->getMessage()."\n";
1381
		}
1382
		return $error;
1383
	}
1384
1385
	private static function update_from_34() {
1386
		global $globalDBdriver;
1387
		$Connection = new Connection();
1388
		$error = '';
1389
		if ($globalDBdriver == 'mysql') {
1390
			if ($Connection->getColumnType('spotter_output','date') == 'TIMESTAMP' && $Connection->getColumnType('spotter_output','last_seen') != 'TIMESTAMP') {
1391
				$query = "ALTER TABLE spotter_output CHANGE date date TIMESTAMP NULL DEFAULT NULL";
1392
				try {
1393
					$sth = $Connection->db->prepare($query);
1394
					$sth->execute();
1395
				} catch(PDOException $e) {
1396
					return "error (delete default timestamp spotter_output) : ".$e->getMessage()."\n";
1397
				}
1398
				$query = "ALTER TABLE spotter_output MODIFY COLUMN last_seen timestamp not null default current_timestamp()";
1399
				try {
1400
					$sth = $Connection->db->prepare($query);
1401
					$sth->execute();
1402
				} catch(PDOException $e) {
1403
					return "error (convert spotter_output last_seen to timestamp) : ".$e->getMessage()."\n";
1404
				}
1405
				
1406
				$query = "ALTER TABLE spotter_output ALTER COLUMN last_seen DROP DEFAULT";
1407
				try {
1408
					$sth = $Connection->db->prepare($query);
1409
					$sth->execute();
1410
				} catch(PDOException $e) {
1411
					return "error (delete default timestamp spotter_output) : ".$e->getMessage()."\n";
1412
				}
1413
				/*$query = "SELECT date,last_seen FROM spotter_output WHERE last_seen < date ORDER BY date DESC LIMIT 150";
1414
				try {
1415
					$sth = $Connection->db->prepare($query);
1416
					$sth->execute();
1417
				} catch(PDOException $e) {
1418
					return "error (get date diff from spotter_output) : ".$e->getMessage()."\n";
1419
				}
1420
				$stats = array();
1421
				while($row = $sth->fetch(PDO::FETCH_ASSOC)) {
1422
					$hours = gmdate('H',strtotime($row['last_seen']) - strtotime($row['date']));
1423
					if ($hours < 12) {
1424
						if (isset($stats[$hours])) $stats[$hours] = $stats[$hours] + 1;
1425
						else $stats[$hours] = 1;
1426
					}
1427
				}
1428
				if (!empty($stats)) {
1429
					asort($stats);
1430
					reset($stats);
1431
					$hour = key($stats);
1432
					$i = 1;
1433
					$j = 0;
1434
					$query_chk = "SELECT count(*) as nb FROM spotter_output WHERE last_seen < date";
1435
					while ($i > 0) {
1436
						$query = "UPDATE spotter_output SET last_seen = DATE_ADD(last_seen, INTERVAL ".$hour." HOUR) WHERE last_seen < date";
1437
						try {
1438
							$sth = $Connection->db->prepare($query);
1439
							$sth->execute();
1440
						} catch(PDOException $e) {
1441
							return "error (fix date) : ".$e->getMessage()."\n";
1442
						}
1443
						try {
1444
							$sth_chk = $Connection->db->prepare($query_chk);
1445
							$sth_chk->execute();
1446
							$result = $sth_chk->fetchAll(PDO::FETCH_ASSOC);
1447
						} catch(PDOException $e) {
1448
							return "error (fix date chk) : ".$e->getMessage()."\n";
1449
						}
1450
						$i = $result[0]['nb'];
1451
						$hour = 1;
1452
						$j++;
1453
						if ($j > 12) $i = 0;
1454
					}
1455
				}
1456
				*/
1457
				$query = "UPDATE spotter_output SET last_seen = date WHERE last_seen < date";
1458
				try {
1459
					$sth = $Connection->db->prepare($query);
1460
					$sth->execute();
1461
				} catch(PDOException $e) {
1462
					return "error (fix date) : ".$e->getMessage()."\n";
1463
				}
1464
			}
1465
			/*
1466
			if ($Connection->getColumnType('spotter_archive_output','date') == 'TIMESTAMP' && $Connection->getColumnType('spotter_archive_output','last_seen') != 'TIMESTAMP') {
1467
				$query = "ALTER TABLE spotter_archive_output CHANGE date date TIMESTAMP NULL DEFAULT NULL";
1468
				try {
1469
					$sth = $Connection->db->prepare($query);
1470
					$sth->execute();
1471
				} catch(PDOException $e) {
1472
					return "error (delete default timestamp spotter_output) : ".$e->getMessage()."\n";
1473
				}
1474
				$query = "ALTER TABLE spotter_archive_output MODIFY COLUMN last_seen timestamp not null default current_timestamp()";
1475
				try {
1476
					$sth = $Connection->db->prepare($query);
1477
					$sth->execute();
1478
				} catch(PDOException $e) {
1479
					return "error (convert spotter_archive_output last_seen to timestamp) : ".$e->getMessage()."\n";
1480
				}
1481
				$query = "ALTER TABLE spotter_archive_output ALTER COLUMN last_seen DROP DEFAULT";
1482
				try {
1483
					$sth = $Connection->db->prepare($query);
1484
					$sth->execute();
1485
				} catch(PDOException $e) {
1486
					return "error (delete default timestamp spotter_output) : ".$e->getMessage()."\n";
1487
				}
1488
				$query = "SELECT date,last_seen FROM spotter_archive_output WHERE last_seen < date ORDER BY date DESC LIMIT 150";
1489
				try {
1490
					$sth = $Connection->db->prepare($query);
1491
					$sth->execute();
1492
				} catch(PDOException $e) {
1493
					return "error (get diff from spotter_archive_output) : ".$e->getMessage()."\n";
1494
				}
1495
				$stats = array();
1496
				while($row = $sth->fetch(PDO::FETCH_ASSOC)) {
1497
					$hours = gmdate('H',strtotime($row['last_seen']) - strtotime($row['date']));
1498
					if ($hours < 12) {
1499
						if (isset($stats[$hours])) $stats[$hours] = $stats[$hours] + 1;
1500
						else $stats[$hours] = 1;
1501
					}
1502
				}
1503
				if (!empty($stats)) {
1504
					asort($stats);
1505
					reset($stats);
1506
					$hour = key($stats);
1507
					$i = 1;
1508
					$j = 0;
1509
					$query_chk = "SELECT count(*) as nb FROM spotter_archive_output WHERE last_seen < date";
1510
					while ($i > 0) {
1511
						$query = "UPDATE spotter_archive_output SET last_seen = DATE_ADD(last_seen, INTERVAL ".$hour." HOUR) WHERE last_seen < date";
1512
						try {
1513
							$sth = $Connection->db->prepare($query);
1514
							$sth->execute();
1515
						} catch(PDOException $e) {
1516
							return "error (fix date) : ".$e->getMessage()."\n";
1517
						}
1518
						try {
1519
							$sth_chk = $Connection->db->prepare($query_chk);
1520
							$sth_chk->execute();
1521
							$result = $sth_chk->fetchAll(PDO::FETCH_ASSOC);
1522
						} catch(PDOException $e) {
1523
							return "error (fix date chk) : ".$e->getMessage()."\n";
1524
						}
1525
						$i = $result[0]['nb'];
1526
						$hour = 1;
1527
						$j++;
1528
						if ($j > 12) $i = 0;
1529
					}
1530
				}
1531
				$query = "UPDATE spotter_archive_output SET last_seen = date WHERE last_seen < date";
1532
				try {
1533
					$sth = $Connection->db->prepare($query);
1534
					$sth->execute();
1535
				} catch(PDOException $e) {
1536
					return "error (fix date) : ".$e->getMessage()."\n";
1537
				}
1538
			
1539
			}
1540
			*/
1541
		}
1542
		$query = "UPDATE config SET value = '35' WHERE name = 'schema_version'";
1543
		try {
1544
			$sth = $Connection->db->prepare($query);
1545
			$sth->execute();
1546
		} catch(PDOException $e) {
1547
			return "error (update schema_version) : ".$e->getMessage()."\n";
1548
		}
1549
		return $error;
1550
	}
1551
	private static function update_from_35() {
1552
		global $globalDBdriver;
1553
		$Connection = new Connection();
1554
		$error = '';
1555
		if (!$Connection->indexExists('accidents','type')) {
1556
			// Add index key
1557
			$query = "create index type on accidents (type,date)";
1558
			try {
1559
				$sth = $Connection->db->prepare($query);
1560
				$sth->execute();
1561
			} catch(PDOException $e) {
1562
				return "error (add index type on accidents) : ".$e->getMessage()."\n";
1563
			}
1564
                }
1565
		$query = "UPDATE config SET value = '36' WHERE name = 'schema_version'";
1566
		try {
1567
			$sth = $Connection->db->prepare($query);
1568
			$sth->execute();
1569
		} catch(PDOException $e) {
1570
			return "error (update schema_version) : ".$e->getMessage()."\n";
1571
		}
1572
		return $error;
1573
	}
1574
1575
	private static function update_from_36() {
1576
		global $globalDBdriver;
1577
		$Connection = new Connection();
1578
		$error = '';
1579
		if (!$Connection->checkColumnName('aircraft_modes','source_type')) {
1580
			$query = "ALTER TABLE aircraft_modes ADD source_type VARCHAR(255) DEFAULT 'modes'";
1581
			try {
1582
				$sth = $Connection->db->prepare($query);
1583
				$sth->execute();
1584
			} catch(PDOException $e) {
1585
				return "error (add source_type column in aircraft_modes) : ".$e->getMessage()."\n";
1586
			}
1587
		}
1588
		/*
1589
		if ($globalDBdriver == 'mysql') {
1590
			$query = "ALTER TABLE spotter_output MODIFY COLUMN ModeS VARCHAR(20) DEFAULT NULL; ALTER TABLE spotter_archive_output MODIFY COLUMN ModeS VARCHAR(20) DEFAULT NULL; ALTER TABLE spotter_live MODIFY COLUMN ModeS VARCHAR(20) DEFAULT NULL;ALTER TABLE spotter_archive MODIFY COLUMN ModeS VARCHAR(20) DEFAULT NULL;";
1591
			try {
1592
				$sth = $Connection->db->prepare($query);
1593
				$sth->execute();
1594
			} catch(PDOException $e) {
1595
				return "error (change ModeS column in spotter_* to NULL) : ".$e->getMessage()."\n";
1596
			}
1597
		} else {
1598
			$query = "ALTER TABLE spotter_output ALTER COLUMN ModeS DROP NOT NULL;ALTER TABLE spotter_live ALTER COLUMN ModeS DROP NOT NULL;ALTER TABLE spotter_archive_output ALTER COLUMN ModeS DROP NOT NULL;ALTER TABLE spotter_archive ALTER COLUMN ModeS DROP NOT NULL;";
1599
			try {
1600
				$sth = $Connection->db->prepare($query);
1601
				$sth->execute();
1602
			} catch(PDOException $e) {
1603
				return "error (change ModeS column in spotter_* to NULL) : ".$e->getMessage()."\n";
1604
			}
1605
		}
1606
		*/
1607
		if ($globalDBdriver == 'mysql') {
1608
			if (!$Connection->tableExists('tracker_output')) {
1609
				$error .= create_db::import_file('../db/tracker_output.sql');
1610
				if ($error != '') return $error;
1611
			}
1612
			if (!$Connection->tableExists('tracker_live')) {
1613
				$error .= create_db::import_file('../db/tracker_live.sql');
1614
				if ($error != '') return $error;
1615
			}
1616
			if (!$Connection->tableExists('marine_output')) {
1617
				$error .= create_db::import_file('../db/marine_output.sql');
1618
				if ($error != '') return $error;
1619
			}
1620
			if (!$Connection->tableExists('marine_live')) {
1621
				$error .= create_db::import_file('../db/marine_live.sql');
1622
				if ($error != '') return $error;
1623
			}
1624
			if (!$Connection->tableExists('marine_identity')) {
1625
				$error .= create_db::import_file('../db/marine_identity.sql');
1626
				if ($error != '') return $error;
1627
			}
1628
			if (!$Connection->tableExists('marine_mid')) {
1629
				$error .= create_db::import_file('../db/marine_mid.sql');
1630
				if ($error != '') return $error;
1631
			}
1632
		} else {
1633
			$error .= create_db::import_file('../db/pgsql/tracker_output.sql');
1634
			if ($error != '') return $error;
1635
			$error .= create_db::import_file('../db/pgsql/tracker_live.sql');
1636
			if ($error != '') return $error;
1637
			$error .= create_db::import_file('../db/pgsql/marine_output.sql');
1638
			if ($error != '') return $error;
1639
			$error .= create_db::import_file('../db/pgsql/marine_live.sql');
1640
			if ($error != '') return $error;
1641
			$error .= create_db::import_file('../db/pgsql/marine_identity.sql');
1642
			if ($error != '') return $error;
1643
			$error .= create_db::import_file('../db/pgsql/marine_mid.sql');
1644
			if ($error != '') return $error;
1645
		}
1646
		$query = "UPDATE config SET value = '37' WHERE name = 'schema_version'";
1647
		try {
1648
			$sth = $Connection->db->prepare($query);
1649
			$sth->execute();
1650
		} catch(PDOException $e) {
1651
			return "error (update schema_version) : ".$e->getMessage()."\n";
1652
		}
1653
		return $error;
1654
	}
1655
1656
	private static function update_from_37() {
1657
		global $globalDBdriver, $globalDBname;
1658
		$Connection = new Connection();
1659
		$error = '';
1660
		if ($globalDBdriver == 'mysql') {
1661
			if (!$Connection->tableExists('marine_image')) {
1662
				$error .= create_db::import_file('../db/marine_image.sql');
1663
				if ($error != '') return $error;
1664
			}
1665
			if (!$Connection->tableExists('marine_archive')) {
1666
				$error .= create_db::import_file('../db/marine_archive.sql');
1667
				if ($error != '') return $error;
1668
			}
1669
			if (!$Connection->tableExists('marine_archive_output')) {
1670
				$error .= create_db::import_file('../db/marine_archive_output.sql');
1671
				if ($error != '') return $error;
1672
			}
1673
			if (!$Connection->tableExists('tracker_archive')) {
1674
				$error .= create_db::import_file('../db/tracker_archive.sql');
1675
				if ($error != '') return $error;
1676
			}
1677
			if (!$Connection->tableExists('tracker_archive_output')) {
1678
				$error .= create_db::import_file('../db/tracker_archive_output.sql');
1679
				if ($error != '') return $error;
1680
			}
1681
			if (!$Connection->tableExists('marine_archive_output')) {
1682
				$error .= create_db::import_file('../db/tracker_archive_output.sql');
1683
				if ($error != '') return $error;
1684
			}
1685
		} else {
1686
			$error .= create_db::import_file('../db/pgsql/marine_image.sql');
1687
			if ($error != '') return $error;
1688
			$error .= create_db::import_file('../db/pgsql/marine_archive.sql');
1689
			if ($error != '') return $error;
1690
			$error .= create_db::import_file('../db/pgsql/marine_archive_output.sql');
1691
			if ($error != '') return $error;
1692
			$error .= create_db::import_file('../db/pgsql/tracker_archive.sql');
1693
			if ($error != '') return $error;
1694
			$error .= create_db::import_file('../db/pgsql/tracker_archive_output.sql');
1695
			if ($error != '') return $error;
1696
		}
1697
		if ($globalDBdriver == 'mysql') {
1698
			$query = "SELECT ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = '".$globalDBname."' AND TABLE_NAME = 'spotter_archive'";
1699
			try {
1700
				$sth = $Connection->db->prepare($query);
1701
				$sth->execute();
1702
			} catch(PDOException $e) {
1703
				return "error (problem when select engine for spotter_engine) : ".$e->getMessage()."\n";
1704
			}
1705
			$row = $sth->fetch(PDO::FETCH_ASSOC);
1706
			if ($row['engine'] == 'ARCHIVE') {
1707
				$query = "ALTER TABLE spotter_archive ENGINE=InnoDB";
1708
				try {
1709
					$sth = $Connection->db->prepare($query);
1710
					$sth->execute();
1711
				} catch(PDOException $e) {
1712
					return "error (Change table format from archive to InnoDB for spotter_archive) : ".$e->getMessage()."\n";
1713
				}
1714
			}
1715
		}
1716
		if (!$Connection->indexExists('spotter_archive','flightaware_id_date_idx') && !$Connection->indexExists('spotter_archive','flightaware_id')) {
1717
			// Add index key
1718
			$query = "create index flightaware_id_date_idx on spotter_archive (flightaware_id,date)";
1719
			try {
1720
				$sth = $Connection->db->prepare($query);
1721
				$sth->execute();
1722
			} catch(PDOException $e) {
1723
				return "error (add index flightaware_id, date on spotter_archive) : ".$e->getMessage()."\n";
1724
			}
1725
                }
1726
		$query = "UPDATE config SET value = '38' WHERE name = 'schema_version'";
1727
		try {
1728
			$sth = $Connection->db->prepare($query);
1729
			$sth->execute();
1730
		} catch(PDOException $e) {
1731
			return "error (update schema_version) : ".$e->getMessage()."\n";
1732
		}
1733
		return $error;
1734
	}
1735
1736
	private static function update_from_38() {
1737
		global $globalDBdriver;
1738
		$Connection = new Connection();
1739
		$error = '';
1740
		if ($globalDBdriver == 'mysql') {
1741
			if (!$Connection->checkColumnName('marine_output','type_id')) {
1742
				$query = "ALTER TABLE marine_output ADD COLUMN type_id int(11) DEFAULT NULL";
1743
				try {
1744
					$sth = $Connection->db->prepare($query);
1745
					$sth->execute();
1746
				} catch(PDOException $e) {
1747
					return "error (add column type_id in marine_output) : ".$e->getMessage()."\n";
1748
				}
1749
			}
1750
			if (!$Connection->checkColumnName('marine_live','type_id')) {
1751
				$query = "ALTER TABLE marine_live ADD COLUMN type_id int(11) DEFAULT NULL";
1752
				try {
1753
					$sth = $Connection->db->prepare($query);
1754
					$sth->execute();
1755
				} catch(PDOException $e) {
1756
					return "error (add column type_id in marine_live) : ".$e->getMessage()."\n";
1757
				}
1758
			}
1759
			if (!$Connection->checkColumnName('marine_archive','type_id')) {
1760
				$query = "ALTER TABLE marine_archive ADD COLUMN type_id int(11) DEFAULT NULL";
1761
				try {
1762
					$sth = $Connection->db->prepare($query);
1763
					$sth->execute();
1764
				} catch(PDOException $e) {
1765
					return "error (add column type_id in marine_archive) : ".$e->getMessage()."\n";
1766
				}
1767
			}
1768
			if (!$Connection->checkColumnName('marine_archive_output','type_id')) {
1769
				$query = "ALTER TABLE marine_archive_output ADD COLUMN type_id int(11) DEFAULT NULL";
1770
				try {
1771
					$sth = $Connection->db->prepare($query);
1772
					$sth->execute();
1773
				} catch(PDOException $e) {
1774
					return "error (add column type_id in marine_archive_output) : ".$e->getMessage()."\n";
1775
				}
1776
			}
1777
			if (!$Connection->checkColumnName('marine_output','status_id')) {
1778
				$query = "ALTER TABLE marine_output ADD COLUMN status_id int(11) DEFAULT NULL";
1779
				try {
1780
					$sth = $Connection->db->prepare($query);
1781
					$sth->execute();
1782
				} catch(PDOException $e) {
1783
					return "error (add column status_id in marine_output) : ".$e->getMessage()."\n";
1784
				}
1785
			}
1786
			if (!$Connection->checkColumnName('marine_live','status_id')) {
1787
				$query = "ALTER TABLE marine_live ADD COLUMN status_id int(11) DEFAULT NULL";
1788
				try {
1789
					$sth = $Connection->db->prepare($query);
1790
					$sth->execute();
1791
				} catch(PDOException $e) {
1792
					return "error (add column status_id in marine_live) : ".$e->getMessage()."\n";
1793
				}
1794
			}
1795
			if (!$Connection->checkColumnName('marine_archive','status_id')) {
1796
				$query = "ALTER TABLE marine_archive ADD COLUMN status_id int(11) DEFAULT NULL";
1797
				try {
1798
					$sth = $Connection->db->prepare($query);
1799
					$sth->execute();
1800
				} catch(PDOException $e) {
1801
					return "error (add column status_id in marine_archive) : ".$e->getMessage()."\n";
1802
				}
1803
			}
1804
			if (!$Connection->checkColumnName('marine_archive_output','status_id')) {
1805
				$query = "ALTER TABLE marine_archive_output ADD COLUMN status_id int(11) DEFAULT NULL";
1806
				try {
1807
					$sth = $Connection->db->prepare($query);
1808
					$sth->execute();
1809
				} catch(PDOException $e) {
1810
					return "error (add column status_id in marine_archive_output) : ".$e->getMessage()."\n";
1811
				}
1812
			}
1813
		} else {
1814
			if (!$Connection->checkColumnName('marine_output','type_id')) {
1815
				$query = "ALTER TABLE marine_output ADD COLUMN type_id integer DEFAULT NULL";
1816
				try {
1817
					$sth = $Connection->db->prepare($query);
1818
					$sth->execute();
1819
				} catch(PDOException $e) {
1820
					return "error (add column type_id in marine_output) : ".$e->getMessage()."\n";
1821
				}
1822
			}
1823
			if (!$Connection->checkColumnName('marine_live','type_id')) {
1824
				$query = "ALTER TABLE marine_live ADD COLUMN type_id integer DEFAULT NULL";
1825
				try {
1826
					$sth = $Connection->db->prepare($query);
1827
					$sth->execute();
1828
				} catch(PDOException $e) {
1829
					return "error (add column type_id in marine_live) : ".$e->getMessage()."\n";
1830
				}
1831
			}
1832
			if (!$Connection->checkColumnName('marine_archive','type_id')) {
1833
				$query = "ALTER TABLE marine_archive ADD COLUMN type_id integer DEFAULT NULL";
1834
				try {
1835
					$sth = $Connection->db->prepare($query);
1836
					$sth->execute();
1837
				} catch(PDOException $e) {
1838
					return "error (add column type_id in marine_archive) : ".$e->getMessage()."\n";
1839
				}
1840
			}
1841
			if (!$Connection->checkColumnName('marine_archive_output','type_id')) {
1842
				$query = "ALTER TABLE marine_archive_output ADD COLUMN type_id integer DEFAULT NULL";
1843
				try {
1844
					$sth = $Connection->db->prepare($query);
1845
					$sth->execute();
1846
				} catch(PDOException $e) {
1847
					return "error (add column type_id in marine_archive_output) : ".$e->getMessage()."\n";
1848
				}
1849
			}
1850
			if (!$Connection->checkColumnName('marine_output','status_id')) {
1851
				$query = "ALTER TABLE marine_output ADD COLUMN status_id integer DEFAULT NULL";
1852
				try {
1853
					$sth = $Connection->db->prepare($query);
1854
					$sth->execute();
1855
				} catch(PDOException $e) {
1856
					return "error (add column status_id in marine_output) : ".$e->getMessage()."\n";
1857
				}
1858
			}
1859
			if (!$Connection->checkColumnName('marine_live','status_id')) {
1860
				$query = "ALTER TABLE marine_live ADD COLUMN status_id integer DEFAULT NULL";
1861
				try {
1862
					$sth = $Connection->db->prepare($query);
1863
					$sth->execute();
1864
				} catch(PDOException $e) {
1865
					return "error (add column status_id in marine_live) : ".$e->getMessage()."\n";
1866
				}
1867
			}
1868
			if (!$Connection->checkColumnName('marine_archive','status_id')) {
1869
				$query = "ALTER TABLE marine_archive ADD COLUMN status_id integer DEFAULT NULL";
1870
				try {
1871
					$sth = $Connection->db->prepare($query);
1872
					$sth->execute();
1873
				} catch(PDOException $e) {
1874
					return "error (add column status_id in marine_archive) : ".$e->getMessage()."\n";
1875
				}
1876
			}
1877
			if (!$Connection->checkColumnName('marine_archive_output','status_id')) {
1878
				$query = "ALTER TABLE marine_archive_output ADD COLUMN status_id integer DEFAULT NULL";
1879
				try {
1880
					$sth = $Connection->db->prepare($query);
1881
					$sth->execute();
1882
				} catch(PDOException $e) {
1883
					return "error (add column status_id in marine_archive_output) : ".$e->getMessage()."\n";
1884
				}
1885
			}
1886
		}
1887
		$query = "UPDATE config SET value = '39' WHERE name = 'schema_version'";
1888
		try {
1889
			$sth = $Connection->db->prepare($query);
1890
			$sth->execute();
1891
		} catch(PDOException $e) {
1892
			return "error (update schema_version) : ".$e->getMessage()."\n";
1893
		}
1894
		return $error;
1895
	}
1896
1897
	private static function update_from_39() {
1898
		global $globalDBdriver;
1899
		$Connection = new Connection();
1900
		$error = '';
1901
		if ($globalDBdriver == 'mysql') {
1902
			$query = "ALTER TABLE stats_pilot MODIFY COLUMN pilot_id varchar(255) NOT NULL";
1903
			try {
1904
				$sth = $Connection->db->prepare($query);
1905
				$sth->execute();
1906
			} catch(PDOException $e) {
1907
				return "error (change pilot_id type to varchar in stats_pilot) : ".$e->getMessage()."\n";
1908
			}
1909
			$query = "ALTER TABLE marine_identity MODIFY COLUMN mmsi varchar(255) DEFAULT NULL";
1910
			try {
1911
				$sth = $Connection->db->prepare($query);
1912
				$sth->execute();
1913
			} catch(PDOException $e) {
1914
				return "error (change mmsi type to varchar in marine_identity) : ".$e->getMessage()."\n";
1915
			}
1916
		} else {
1917
			$query = "alter table stats_pilot alter column pilot_id type varchar(255)";
1918
			try {
1919
				$sth = $Connection->db->prepare($query);
1920
				$sth->execute();
1921
			} catch(PDOException $e) {
1922
				return "error (change pilot_id type to varchar in stats_pilot) : ".$e->getMessage()."\n";
1923
			}
1924
			$query = "alter table marine_identity alter column mmsi type varchar(255)";
1925
			try {
1926
				$sth = $Connection->db->prepare($query);
1927
				$sth->execute();
1928
			} catch(PDOException $e) {
1929
				return "error (change mmsi type to varchar in marine_identity) : ".$e->getMessage()."\n";
1930
			}
1931
		}
1932
		$query = "UPDATE config SET value = '40' WHERE name = 'schema_version'";
1933
		try {
1934
			$sth = $Connection->db->prepare($query);
1935
			$sth->execute();
1936
		} catch(PDOException $e) {
1937
			return "error (update schema_version) : ".$e->getMessage()."\n";
1938
		}
1939
		return $error;
1940
	}
1941
1942
	private static function update_from_40() {
1943
		global $globalDBdriver;
1944
		$Connection = new Connection();
1945
		$error = '';
1946
		if (!$Connection->checkColumnName('source_location','last_seen')) {
1947
			$query = "ALTER TABLE source_location ADD COLUMN last_seen timestamp NULL DEFAULT NULL";
1948
			try {
1949
				$sth = $Connection->db->prepare($query);
1950
				$sth->execute();
1951
			} catch(PDOException $e) {
1952
				return "error (add column last_seen in source_location) : ".$e->getMessage()."\n";
1953
			}
1954
		}
1955
		if ($globalDBdriver == 'mysql') {
1956
			if (!$Connection->checkColumnName('source_location','location_id')) {
1957
				$query = "ALTER TABLE source_location ADD COLUMN location_id int(11) DEFAULT NULL";
1958
				try {
1959
					$sth = $Connection->db->prepare($query);
1960
					$sth->execute();
1961
				} catch(PDOException $e) {
1962
					return "error (add column location_id in source_location) : ".$e->getMessage()."\n";
1963
				}
1964
			}
1965
		} else {
1966
			if (!$Connection->checkColumnName('source_location','location_id')) {
1967
				$query = "ALTER TABLE source_location ADD COLUMN location_id integer DEFAULT NULL";
1968
				try {
1969
					$sth = $Connection->db->prepare($query);
1970
					$sth->execute();
1971
				} catch(PDOException $e) {
1972
					return "error (add column location_id in source_location) : ".$e->getMessage()."\n";
1973
				}
1974
			}
1975
		}
1976
		$query = "UPDATE config SET value = '41' WHERE name = 'schema_version'";
1977
		try {
1978
			$sth = $Connection->db->prepare($query);
1979
			$sth->execute();
1980
		} catch(PDOException $e) {
1981
			return "error (update schema_version) : ".$e->getMessage()."\n";
1982
		}
1983
		return $error;
1984
	}
1985
1986
	private static function update_from_41() {
1987
		global $globalDBdriver;
1988
		$Connection = new Connection();
1989
		$error = '';
1990
		if (!$Connection->checkColumnName('source_location','description')) {
1991
			$query = "ALTER TABLE source_location ADD COLUMN description text DEFAULT NULL";
1992
			try {
1993
				$sth = $Connection->db->prepare($query);
1994
				$sth->execute();
1995
			} catch(PDOException $e) {
1996
				return "error (add column description in source_location) : ".$e->getMessage()."\n";
1997
			}
1998
		}
1999
		$query = "UPDATE config SET value = '42' WHERE name = 'schema_version'";
2000
		try {
2001
			$sth = $Connection->db->prepare($query);
2002
			$sth->execute();
2003
		} catch(PDOException $e) {
2004
			return "error (update schema_version) : ".$e->getMessage()."\n";
2005
		}
2006
		return $error;
2007
	}
2008
2009
	private static function update_from_42() {
2010
		global $globalDBdriver;
2011
		$Connection = new Connection();
2012
		$error = '';
2013
		if (!$Connection->checkColumnName('spotter_live','real_altitude')) {
2014
			$query = "ALTER TABLE spotter_live ADD COLUMN real_altitude float DEFAULT NULL";
2015
			try {
2016
				$sth = $Connection->db->prepare($query);
2017
				$sth->execute();
2018
			} catch(PDOException $e) {
2019
				return "error (add column real_altitude in spotter_live) : ".$e->getMessage()."\n";
2020
			}
2021
		}
2022
		if (!$Connection->checkColumnName('spotter_output','real_altitude')) {
2023
			$query = "ALTER TABLE spotter_output ADD COLUMN real_altitude float DEFAULT NULL";
2024
			try {
2025
				$sth = $Connection->db->prepare($query);
2026
				$sth->execute();
2027
			} catch(PDOException $e) {
2028
				return "error (add column real_altitude in spotter_output) : ".$e->getMessage()."\n";
2029
			}
2030
		}
2031
		if (!$Connection->checkColumnName('spotter_archive_output','real_altitude')) {
2032
			$query = "ALTER TABLE spotter_archive_output ADD COLUMN real_altitude float DEFAULT NULL";
2033
			try {
2034
				$sth = $Connection->db->prepare($query);
2035
				$sth->execute();
2036
			} catch(PDOException $e) {
2037
				return "error (add column real_altitude in spotter_archive_output) : ".$e->getMessage()."\n";
2038
			}
2039
		}
2040
		if (!$Connection->checkColumnName('spotter_archive','real_altitude')) {
2041
			$query = "ALTER TABLE spotter_archive ADD COLUMN real_altitude float DEFAULT NULL";
2042
			try {
2043
				$sth = $Connection->db->prepare($query);
2044
				$sth->execute();
2045
			} catch(PDOException $e) {
2046
				return "error (add column real_altitude in spotter_archive) : ".$e->getMessage()."\n";
2047
			}
2048
		}
2049
		$query = "UPDATE config SET value = '43' WHERE name = 'schema_version'";
2050
		try {
2051
			$sth = $Connection->db->prepare($query);
2052
			$sth->execute();
2053
		} catch(PDOException $e) {
2054
			return "error (update schema_version) : ".$e->getMessage()."\n";
2055
		}
2056
		return $error;
2057
	}
2058
2059
	private static function update_from_43() {
2060
		global $globalDBdriver;
2061
		$Connection = new Connection();
2062
		$error = '';
2063
		if ($globalDBdriver == 'mysql') {
2064
			if (!$Connection->tableExists('tracker_archive_output')) {
2065
				$error .= create_db::import_file('../db/tracker_archive_output.sql');
2066
				if ($error != '') return $error;
2067
			}
2068
			$query = "ALTER TABLE tracker_live MODIFY COLUMN altitude float DEFAULT NULL;ALTER TABLE tracker_output MODIFY COLUMN last_altitude float DEFAULT NULL;ALTER TABLE tracker_output MODIFY COLUMN altitude float DEFAULT NULL;ALTER TABLE tracker_archive MODIFY COLUMN altitude float DEFAULT NULL;ALTER TABLE tracker_archive_output MODIFY COLUMN last_altitude float DEFAULT NULL;ALTER TABLE tracker_output MODIFY COLUMN altitude float DEFAULT NULL;";
2069
		} else {
2070
			$query = "ALTER TABLE tracker_live ALTER COLUMN altitude TYPE float;ALTER TABLE tracker_output ALTER COLUMN last_altitude TYPE float;ALTER TABLE tracker_output ALTER COLUMN altitude TYPE float;ALTER TABLE tracker_archive ALTER COLUMN altitude TYPE float;ALTER TABLE tracker_archive_output ALTER COLUMN last_altitude TYPE float;ALTER TABLE tracker_output ALTER COLUMN altitude TYPE float;";
2071
		}
2072
		try {
2073
			$sth = $Connection->db->prepare($query);
2074
			$sth->execute();
2075
		} catch(PDOException $e) {
2076
			return "error (modify column altitude in tracker_*) : ".$e->getMessage()."\n";
2077
		}
2078
		$query = "UPDATE config SET value = '44' WHERE name = 'schema_version'";
2079
		try {
2080
			$sth = $Connection->db->prepare($query);
2081
			$sth->execute();
2082
		} catch(PDOException $e) {
2083
			return "error (update schema_version) : ".$e->getMessage()."\n";
2084
		}
2085
		return $error;
2086
	}
2087
2088
	private static function update_from_44() {
2089
		global $globalDBdriver, $globalVATSIM, $globalIVAO;
2090
		$Connection = new Connection();
2091
		$error = '';
2092
		if ($globalDBdriver == 'mysql') {
2093
			$error .= create_db::import_file('../db/airport.sql');
2094
			if ($error != '') return $error;
2095
			$error .= create_db::import_file('../db/airlines.sql');
2096
			if ($error != '') return $error;
2097
		} else {
2098
			$error .= create_db::import_file('../db/pgsql/airport.sql');
2099
			if ($error != '') return $error;
2100
			$error .= create_db::import_file('../db/pgsql/airlines.sql');
2101
			if ($error != '') return $error;
2102
		}
2103
		if ((isset($globalVATSIM) && $globalVATSIM) && (isset($globalIVAO) && $globalIVAO)) {
2104
			if (file_exists('tmp/ivae_feb2013.zip')) {
2105
				$error .= update_db::update_IVAO();
2106
			} else {
2107
				$error .= update_db::update_vatsim();
2108
			}
2109
		} elseif (isset($globalVATSIM) && $globalVATSIM) {
2110
			$error .= update_db::update_vatsim();
2111
		} elseif (isset($globalIVAO) && $globalIVAO) {
2112
			if (file_exists('tmp/ivae_feb2013.zip')) {
2113
				$error .= update_db::update_IVAO();
2114
			} else {
2115
				$error .= update_db::update_vatsim();
2116
			}
2117
		}
2118
		if ($error != '') return $error;
2119
		$query = "UPDATE config SET value = '45' WHERE name = 'schema_version'";
2120
		try {
2121
			$sth = $Connection->db->prepare($query);
2122
			$sth->execute();
2123
		} catch(PDOException $e) {
2124
			return "error (update schema_version) : ".$e->getMessage()."\n";
2125
		}
2126
		return $error;
2127
	}
2128
2129
	private static function update_from_45() {
2130
		global $globalDBdriver;
2131
		$Connection = new Connection();
2132
		$error = '';
2133
		if (!$Connection->tableExists('satellite')) {
2134
			if ($globalDBdriver == 'mysql') {
2135
				$error .= create_db::import_file('../db/satellite.sql');
2136
				if ($error != '') return $error;
2137
			} else {
2138
				$error .= create_db::import_file('../db/pgsql/satellite.sql');
2139
				if ($error != '') return $error;
2140
			}
2141
		}
2142
		$query = "UPDATE config SET value = '46' WHERE name = 'schema_version'";
2143
		try {
2144
			$sth = $Connection->db->prepare($query);
2145
			$sth->execute();
2146
		} catch(PDOException $e) {
2147
			return "error (update schema_version) : ".$e->getMessage()."\n";
2148
		}
2149
		return $error;
2150
	}
2151
2152
	private static function update_from_46() {
2153
		global $globalDBdriver;
2154
		$Connection = new Connection();
2155
		$error = '';
2156
		if (!$Connection->tableExists('stats_marine')) {
2157
			if ($globalDBdriver == 'mysql') {
2158
				$error .= create_db::import_file('../db/stats_marine.sql');
2159
				if ($error != '') return $error;
2160
			} else {
2161
				$error .= create_db::import_file('../db/pgsql/stats_marine.sql');
2162
				if ($error != '') return $error;
2163
			}
2164
		}
2165
		if (!$Connection->tableExists('stats_marine_country')) {
2166
			if ($globalDBdriver == 'mysql') {
2167
				$error .= create_db::import_file('../db/stats_marine_country.sql');
2168
				if ($error != '') return $error;
2169
			} else {
2170
				$error .= create_db::import_file('../db/pgsql/stats_marine_country.sql');
2171
				if ($error != '') return $error;
2172
			}
2173
		}
2174
		if (!$Connection->tableExists('stats_tracker')) {
2175
			if ($globalDBdriver == 'mysql') {
2176
				$error .= create_db::import_file('../db/stats_tracker.sql');
2177
				if ($error != '') return $error;
2178
			} else {
2179
				$error .= create_db::import_file('../db/pgsql/stats_tracker.sql');
2180
				if ($error != '') return $error;
2181
			}
2182
		}
2183
		if (!$Connection->tableExists('stats_tracker_country')) {
2184
			if ($globalDBdriver == 'mysql') {
2185
				$error .= create_db::import_file('../db/stats_tracker_country.sql');
2186
				if ($error != '') return $error;
2187
			} else {
2188
				$error .= create_db::import_file('../db/pgsql/stats_tracker_country.sql');
2189
				if ($error != '') return $error;
2190
			}
2191
		}
2192
		$query = "UPDATE config SET value = '47' WHERE name = 'schema_version'";
2193
		try {
2194
			$sth = $Connection->db->prepare($query);
2195
			$sth->execute();
2196
		} catch(PDOException $e) {
2197
			return "error (update schema_version) : ".$e->getMessage()."\n";
2198
		}
2199
		return $error;
2200
	}
2201
2202
	private static function update_from_47() {
2203
		global $globalDBdriver;
2204
		$Connection = new Connection();
2205
		$error = '';
2206
		if (!$Connection->tableExists('stats_marine_type')) {
2207
			if ($globalDBdriver == 'mysql') {
2208
				$error .= create_db::import_file('../db/stats_marine_type.sql');
2209
				if ($error != '') return $error;
2210
			} else {
2211
				$error .= create_db::import_file('../db/pgsql/stats_marine_type.sql');
2212
				if ($error != '') return $error;
2213
			}
2214
		}
2215
		$query = "UPDATE config SET value = '48' WHERE name = 'schema_version'";
2216
		try {
2217
			$sth = $Connection->db->prepare($query);
2218
			$sth->execute();
2219
		} catch(PDOException $e) {
2220
			return "error (update schema_version) : ".$e->getMessage()."\n";
2221
		}
2222
		return $error;
2223
	}
2224
2225
	private static function update_from_48() {
2226
		global $globalDBdriver;
2227
		$Connection = new Connection();
2228
		$error = '';
2229
		if (!$Connection->tableExists('stats_tracker_type')) {
2230
			if ($globalDBdriver == 'mysql') {
2231
				$error .= create_db::import_file('../db/stats_tracker_type.sql');
2232
				if ($error != '') return $error;
2233
			} else {
2234
				$error .= create_db::import_file('../db/pgsql/stats_tracker_type.sql');
2235
				if ($error != '') return $error;
2236
			}
2237
		}
2238
		$query = "UPDATE config SET value = '49' WHERE name = 'schema_version'";
2239
		try {
2240
			$sth = $Connection->db->prepare($query);
2241
			$sth->execute();
2242
		} catch(PDOException $e) {
2243
			return "error (update schema_version) : ".$e->getMessage()."\n";
2244
		}
2245
		return $error;
2246
	}
2247
2248
	private static function update_from_49() {
2249
		global $globalDBdriver;
2250
		$Connection = new Connection();
2251
		$error = '';
2252
		if ($globalDBdriver == 'mysql') {
2253
			$error .= create_db::import_file('../db/airport.sql');
2254
			if ($error != '') return $error;
2255
		} else {
2256
			$error .= create_db::import_file('../db/pgsql/airport.sql');
2257
			if ($error != '') return $error;
2258
		}
2259
		$query = "UPDATE config SET value = '50' WHERE name = 'schema_version'";
2260
		try {
2261
			$sth = $Connection->db->prepare($query);
2262
			$sth->execute();
2263
		} catch(PDOException $e) {
2264
			return "error (update schema_version) : ".$e->getMessage()."\n";
2265
		}
2266
		return $error;
2267
	}
2268
2269
	private static function update_from_50() {
2270
		global $globalDBdriver;
2271
		$Connection = new Connection();
2272
		$error = '';
2273
		if ($globalDBdriver == 'mysql') {
2274
			$error .= create_db::import_file('../db/aircraft.sql');
2275
			if ($error != '') return $error;
2276
			$error .= create_db::import_file('../db/aircraft_block.sql');
2277
			if ($error != '') return $error;
2278
		} else {
2279
			$error .= create_db::import_file('../db/pgsql/aircraft.sql');
2280
			if ($error != '') return $error;
2281
			$error .= create_db::import_file('../db/pgsql/aircraft_block.sql');
2282
			if ($error != '') return $error;
2283
		}
2284
		$query = "UPDATE config SET value = '51' WHERE name = 'schema_version'";
2285
		try {
2286
			$sth = $Connection->db->prepare($query);
2287
			$sth->execute();
2288
		} catch(PDOException $e) {
2289
			return "error (update schema_version) : ".$e->getMessage()."\n";
2290
		}
2291
		return $error;
2292
	}
2293
2294
	private static function update_from_51() {
2295
		global $globalDBdriver;
2296
		$Connection = new Connection();
2297
		$error = '';
2298
		if (!$Connection->checkColumnName('marine_live','captain_name')) {
2299
			$query = "ALTER TABLE marine_live ADD COLUMN captain_name varchar(255) DEFAULT NULL,ADD COLUMN captain_id varchar(255) DEFAULT NULL,ADD COLUMN race_name varchar(255) DEFAULT NULL,ADD COLUMN race_id varchar(255) DEFAULT NULL";
2300
			try {
2301
				$sth = $Connection->db->prepare($query);
2302
				$sth->execute();
2303
			} catch(PDOException $e) {
2304
				return "error (add columns captain and race in marine_live) : ".$e->getMessage()."\n";
2305
			}
2306
		}
2307
		if (!$Connection->checkColumnName('marine_output','captain_name')) {
2308
			$query = "ALTER TABLE marine_output ADD COLUMN captain_name varchar(255) DEFAULT NULL,ADD COLUMN captain_id varchar(255) DEFAULT NULL,ADD COLUMN race_name varchar(255) DEFAULT NULL,ADD COLUMN race_id varchar(255) DEFAULT NULL";
2309
			try {
2310
				$sth = $Connection->db->prepare($query);
2311
				$sth->execute();
2312
			} catch(PDOException $e) {
2313
				return "error (add columns captain and race in marine_output) : ".$e->getMessage()."\n";
2314
			}
2315
		}
2316
		if (!$Connection->checkColumnName('marine_archive','captain_name')) {
2317
			$query = "ALTER TABLE marine_archive ADD COLUMN captain_name varchar(255) DEFAULT NULL,ADD COLUMN captain_id varchar(255) DEFAULT NULL,ADD COLUMN race_name varchar(255) DEFAULT NULL,ADD COLUMN race_id varchar(255) DEFAULT NULL";
2318
			try {
2319
				$sth = $Connection->db->prepare($query);
2320
				$sth->execute();
2321
			} catch(PDOException $e) {
2322
				return "error (add columns captain and race in marine_archive) : ".$e->getMessage()."\n";
2323
			}
2324
		}
2325
		if (!$Connection->checkColumnName('marine_archive_output','captain_name')) {
2326
			$query = "ALTER TABLE marine_archive_output ADD COLUMN captain_name varchar(255) DEFAULT NULL,ADD COLUMN captain_id varchar(255) DEFAULT NULL,ADD COLUMN race_name varchar(255) DEFAULT NULL,ADD COLUMN race_id varchar(255) DEFAULT NULL";
2327
			try {
2328
				$sth = $Connection->db->prepare($query);
2329
				$sth->execute();
2330
			} catch(PDOException $e) {
2331
				return "error (add columns captain and race in marine_archive_output) : ".$e->getMessage()."\n";
2332
			}
2333
		}
2334
		$query = "UPDATE config SET value = '52' WHERE name = 'schema_version'";
2335
		try {
2336
			$sth = $Connection->db->prepare($query);
2337
			$sth->execute();
2338
		} catch(PDOException $e) {
2339
			return "error (update schema_version) : ".$e->getMessage()."\n";
2340
		}
2341
		return $error;
2342
	}
2343
2344
	private static function update_from_52() {
2345
		global $globalDBdriver;
2346
		$Connection = new Connection();
2347
		$error = '';
2348
		if ($globalDBdriver == 'mysql') {
2349
			$query = "ALTER TABLE marine_live MODIFY COLUMN ground_speed float DEFAULT NULL;ALTER TABLE marine_output MODIFY COLUMN ground_speed float DEFAULT NULL;ALTER TABLE marine_archive_output MODIFY COLUMN ground_speed float DEFAULT NULL;ALTER TABLE marine_archive MODIFY COLUMN ground_speed float DEFAULT NULL;";
2350
		} else {
2351
			$query = "ALTER TABLE marine_live ALTER COLUMN ground_speed TYPE float;ALTER TABLE marine_output ALTER COLUMN ground_speed TYPE float;ALTER TABLE marine_archive_output ALTER COLUMN ground_speed TYPE float;ALTER TABLE marine_archive ALTER COLUMN ground_speed TYPE float;";
2352
		}
2353
		try {
2354
			$sth = $Connection->db->prepare($query);
2355
			$sth->execute();
2356
		} catch(PDOException $e) {
2357
			return "error (modify column ground_speede in marine_*) : ".$e->getMessage()."\n";
2358
		}
2359
		$query = "UPDATE config SET value = '53' WHERE name = 'schema_version'";
2360
		try {
2361
			$sth = $Connection->db->prepare($query);
2362
			$sth->execute();
2363
		} catch(PDOException $e) {
2364
			return "error (update schema_version) : ".$e->getMessage()."\n";
2365
		}
2366
		return $error;
2367
	}
2368
2369
	private static function update_from_53() {
2370
		global $globalDBdriver;
2371
		$Connection = new Connection();
2372
		$error = '';
2373
		if (!$Connection->checkColumnName('marine_live','distance')) {
2374
			$query = "ALTER TABLE marine_live ADD COLUMN distance float DEFAULT NULL";
2375
			try {
2376
				$sth = $Connection->db->prepare($query);
2377
				$sth->execute();
2378
			} catch(PDOException $e) {
2379
				return "error (add columns distance in marine_live) : ".$e->getMessage()."\n";
2380
			}
2381
		}
2382
		if (!$Connection->checkColumnName('marine_live','race_time')) {
2383
			$query = "ALTER TABLE marine_live ADD COLUMN race_time float DEFAULT NULL";
2384
			try {
2385
				$sth = $Connection->db->prepare($query);
2386
				$sth->execute();
2387
			} catch(PDOException $e) {
2388
				return "error (add columns race_time in marine_live) : ".$e->getMessage()."\n";
2389
			}
2390
		}
2391
		if (!$Connection->checkColumnName('marine_live','race_rank')) {
2392
			if ($globalDBdriver == 'mysql') {
2393
				$query = "ALTER TABLE marine_live ADD COLUMN race_rank int(11) DEFAULT NULL";
2394
			} else {
2395
				$query = "ALTER TABLE marine_live ADD COLUMN race_rank integer DEFAULT NULL";
2396
			}
2397
			try {
2398
				$sth = $Connection->db->prepare($query);
2399
				$sth->execute();
2400
			} catch(PDOException $e) {
2401
				return "error (add columns race_rank in marine_live) : ".$e->getMessage()."\n";
2402
			}
2403
		}
2404
		if (!$Connection->checkColumnName('marine_output','distance')) {
2405
			$query = "ALTER TABLE marine_output ADD COLUMN distance float DEFAULT NULL";
2406
			try {
2407
				$sth = $Connection->db->prepare($query);
2408
				$sth->execute();
2409
			} catch(PDOException $e) {
2410
				return "error (add columns distance in marine_output) : ".$e->getMessage()."\n";
2411
			}
2412
		}
2413
		if (!$Connection->checkColumnName('marine_output','race_time')) {
2414
			$query = "ALTER TABLE marine_output ADD COLUMN race_time float DEFAULT NULL";
2415
			try {
2416
				$sth = $Connection->db->prepare($query);
2417
				$sth->execute();
2418
			} catch(PDOException $e) {
2419
				return "error (add columns race_time in marine_output) : ".$e->getMessage()."\n";
2420
			}
2421
		}
2422
		if (!$Connection->checkColumnName('marine_output','race_rank')) {
2423
			if ($globalDBdriver == 'mysql') {
2424
				$query = "ALTER TABLE marine_output ADD COLUMN race_rank int(11) DEFAULT NULL";
2425
			} else {
2426
				$query = "ALTER TABLE marine_output ADD COLUMN race_rank integer DEFAULT NULL";
2427
			}
2428
			try {
2429
				$sth = $Connection->db->prepare($query);
2430
				$sth->execute();
2431
			} catch(PDOException $e) {
2432
				return "error (add columns race_rank in marine_output) : ".$e->getMessage()."\n";
2433
			}
2434
		}
2435
		if (!$Connection->checkColumnName('marine_archive','distance')) {
2436
			$query = "ALTER TABLE marine_archive ADD COLUMN distance float DEFAULT NULL";
2437
			try {
2438
				$sth = $Connection->db->prepare($query);
2439
				$sth->execute();
2440
			} catch(PDOException $e) {
2441
				return "error (add columns distance in marine_archive) : ".$e->getMessage()."\n";
2442
			}
2443
		}
2444
		if (!$Connection->checkColumnName('marine_archive','race_time')) {
2445
			$query = "ALTER TABLE marine_archive ADD COLUMN race_time float DEFAULT NULL";
2446
			try {
2447
				$sth = $Connection->db->prepare($query);
2448
				$sth->execute();
2449
			} catch(PDOException $e) {
2450
				return "error (add columns race_time in marine_archive) : ".$e->getMessage()."\n";
2451
			}
2452
		}
2453
		if (!$Connection->checkColumnName('marine_archive','race_rank')) {
2454
			if ($globalDBdriver == 'mysql') {
2455
				$query = "ALTER TABLE marine_archive ADD COLUMN race_rank int(11) DEFAULT NULL";
2456
			} else {
2457
				$query = "ALTER TABLE marine_archive ADD COLUMN race_rank integer DEFAULT NULL";
2458
			}
2459
			try {
2460
				$sth = $Connection->db->prepare($query);
2461
				$sth->execute();
2462
			} catch(PDOException $e) {
2463
				return "error (add columns race_rank in marine_archive) : ".$e->getMessage()."\n";
2464
			}
2465
		}
2466
		if (!$Connection->checkColumnName('marine_archive_output','distance')) {
2467
			$query = "ALTER TABLE marine_archive_output ADD COLUMN distance float DEFAULT NULL";
2468
			try {
2469
				$sth = $Connection->db->prepare($query);
2470
				$sth->execute();
2471
			} catch(PDOException $e) {
2472
				return "error (add columns distance in marine_archive_output) : ".$e->getMessage()."\n";
2473
			}
2474
		}
2475
		if (!$Connection->checkColumnName('marine_archive_output','race_time')) {
2476
			$query = "ALTER TABLE marine_archive_output ADD COLUMN race_time float DEFAULT NULL";
2477
			try {
2478
				$sth = $Connection->db->prepare($query);
2479
				$sth->execute();
2480
			} catch(PDOException $e) {
2481
				return "error (add columns race_time in marine_archive_output) : ".$e->getMessage()."\n";
2482
			}
2483
		}
2484
		if (!$Connection->checkColumnName('marine_archive_output','race_rank')) {
2485
			if ($globalDBdriver == 'mysql') {
2486
				$query = "ALTER TABLE marine_archive_output ADD COLUMN race_rank int(11) DEFAULT NULL";
2487
			} else {
2488
				$query = "ALTER TABLE marine_archive_output ADD COLUMN race_rank integer DEFAULT NULL";
2489
			}
2490
			try {
2491
				$sth = $Connection->db->prepare($query);
2492
				$sth->execute();
2493
			} catch(PDOException $e) {
2494
				return "error (add columns race_rank in marine_live) : ".$e->getMessage()."\n";
2495
			}
2496
		}
2497
		if ($Connection->checkColumnName('marine_output','last_altitude')) {
2498
			$query = "ALTER TABLE marine_output DROP COLUMN last_altitude";
2499
			try {
2500
				$sth = $Connection->db->prepare($query);
2501
				$sth->execute();
2502
			} catch(PDOException $e) {
2503
				return "error (drop columns last_altitude in marine_output) : ".$e->getMessage()."\n";
2504
			}
2505
		}
2506
		if ($Connection->checkColumnName('marine_archive_output','last_altitude')) {
2507
			$query = "ALTER TABLE marine_archive_output DROP COLUMN last_altitude";
2508
			try {
2509
				$sth = $Connection->db->prepare($query);
2510
				$sth->execute();
2511
			} catch(PDOException $e) {
2512
				return "error (drop columns last_altitude in marine_archive_output) : ".$e->getMessage()."\n";
2513
			}
2514
		}
2515
		$query = "UPDATE config SET value = '54' WHERE name = 'schema_version'";
2516
		try {
2517
			$sth = $Connection->db->prepare($query);
2518
			$sth->execute();
2519
		} catch(PDOException $e) {
2520
			return "error (update schema_version) : ".$e->getMessage()."\n";
2521
		}
2522
		return $error;
2523
	}
2524
2525
	private static function update_from_54() {
2526
		global $globalDBdriver;
2527
		$Connection = new Connection();
2528
		$error = '';
2529
		if ($globalDBdriver == 'mysql') {
2530
			$error .= create_db::import_file('../db/marine_race.sql');
2531
			if ($error != '') return $error;
2532
		} else {
2533
			$error .= create_db::import_file('../db/pgsql/marine_race.sql');
2534
			if ($error != '') return $error;
2535
		}
2536
		$query = "UPDATE config SET value = '55' WHERE name = 'schema_version'";
2537
		try {
2538
			$sth = $Connection->db->prepare($query);
2539
			$sth->execute();
2540
		} catch(PDOException $e) {
2541
			return "error (update schema_version) : ".$e->getMessage()."\n";
2542
		}
2543
		return $error;
2544
	}
2545
2546
2547
	public static function check_version($update = false) {
2548
		global $globalDBname;
2549
		$version = 0;
2550
		$Connection = new Connection();
2551
		if (!$Connection->connectionExists()) {
2552
			return "error (check_version): Can't connect to ".$globalDBname."\n";
2553
		} else {
2554
			if ($Connection->tableExists('aircraft')) {
2555
				if (!$Connection->tableExists('config')) {
2556
					$version = '1';
2557
					if ($update) return self::update_from_1();
2558
					else return $version;
2559
				} else {
2560
					$query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1";
2561
					try {
2562
						$sth = $Connection->db->prepare($query);
2563
						$sth->execute();
2564
					} catch(PDOException $e) {
2565
						return "error (check_version): ".$e->getMessage()."\n";
2566
					}
2567
					$result = $sth->fetch(PDO::FETCH_ASSOC);
2568
					if ($update) {
2569
						if ($result['value'] == '2') {
2570
							$error = self::update_from_2();
2571
							if ($error != '') return $error;
2572
							else return self::check_version(true);
2573
						} elseif ($result['value'] == '3') {
2574
							$error = self::update_from_3();
2575
							if ($error != '') return $error;
2576
							else return self::check_version(true);
2577
						} elseif ($result['value'] == '4') {
2578
							$error = self::update_from_4();
2579
							if ($error != '') return $error;
2580
							else return self::check_version(true);
2581
						} elseif ($result['value'] == '5') {
2582
							$error = self::update_from_5();
2583
							if ($error != '') return $error;
2584
							else return self::check_version(true);
2585
						} elseif ($result['value'] == '6') {
2586
							$error = self::update_from_6();
2587
							if ($error != '') return $error;
2588
							else return self::check_version(true);
2589
						} elseif ($result['value'] == '7') {
2590
							$error = self::update_from_7();
2591
							if ($error != '') return $error;
2592
							else return self::check_version(true);
2593
						} elseif ($result['value'] == '8') {
2594
							$error = self::update_from_8();
2595
							if ($error != '') return $error;
2596
							else return self::check_version(true);
2597
						} elseif ($result['value'] == '9') {
2598
							$error = self::update_from_9();
2599
							if ($error != '') return $error;
2600
							else return self::check_version(true);
2601
						} elseif ($result['value'] == '10') {
2602
							$error = self::update_from_10();
2603
							if ($error != '') return $error;
2604
							else return self::check_version(true);
2605
						} elseif ($result['value'] == '11') {
2606
							$error = self::update_from_11();
2607
							if ($error != '') return $error;
2608
							else return self::check_version(true);
2609
						} elseif ($result['value'] == '12') {
2610
							$error = self::update_from_12();
2611
							if ($error != '') return $error;
2612
							else return self::check_version(true);
2613
						} elseif ($result['value'] == '13') {
2614
							$error = self::update_from_13();
2615
							if ($error != '') return $error;
2616
							else return self::check_version(true);
2617
						} elseif ($result['value'] == '14') {
2618
							$error = self::update_from_14();
2619
							if ($error != '') return $error;
2620
							else return self::check_version(true);
2621
						} elseif ($result['value'] == '15') {
2622
							$error = self::update_from_15();
2623
							if ($error != '') return $error;
2624
							else return self::check_version(true);
2625
						} elseif ($result['value'] == '16') {
2626
							$error = self::update_from_16();
2627
							if ($error != '') return $error;
2628
							else return self::check_version(true);
2629
						} elseif ($result['value'] == '17') {
2630
							$error = self::update_from_17();
2631
							if ($error != '') return $error;
2632
							else return self::check_version(true);
2633
						} elseif ($result['value'] == '18') {
2634
							$error = self::update_from_18();
2635
							if ($error != '') return $error;
2636
							else return self::check_version(true);
2637
						} elseif ($result['value'] == '19') {
2638
							$error = self::update_from_19();
2639
							if ($error != '') return $error;
2640
							else return self::check_version(true);
2641
						} elseif ($result['value'] == '20') {
2642
							$error = self::update_from_20();
2643
							if ($error != '') return $error;
2644
							else return self::check_version(true);
2645
						} elseif ($result['value'] == '21') {
2646
							$error = self::update_from_21();
2647
							if ($error != '') return $error;
2648
							else return self::check_version(true);
2649
						} elseif ($result['value'] == '22') {
2650
							$error = self::update_from_22();
2651
							if ($error != '') return $error;
2652
							else return self::check_version(true);
2653
						} elseif ($result['value'] == '23') {
2654
							$error = self::update_from_23();
2655
							if ($error != '') return $error;
2656
							else return self::check_version(true);
2657
						} elseif ($result['value'] == '24') {
2658
							$error = self::update_from_24();
2659
							if ($error != '') return $error;
2660
							else return self::check_version(true);
2661
						} elseif ($result['value'] == '25') {
2662
							$error = self::update_from_25();
2663
							if ($error != '') return $error;
2664
							else return self::check_version(true);
2665
						} elseif ($result['value'] == '26') {
2666
							$error = self::update_from_26();
2667
							if ($error != '') return $error;
2668
							else return self::check_version(true);
2669
						} elseif ($result['value'] == '27') {
2670
							$error = self::update_from_27();
2671
							if ($error != '') return $error;
2672
							else return self::check_version(true);
2673
						} elseif ($result['value'] == '28') {
2674
							$error = self::update_from_28();
2675
							if ($error != '') return $error;
2676
							else return self::check_version(true);
2677
						} elseif ($result['value'] == '29') {
2678
							$error = self::update_from_29();
2679
							if ($error != '') return $error;
2680
							else return self::check_version(true);
2681
						} elseif ($result['value'] == '30') {
2682
							$error = self::update_from_30();
2683
							if ($error != '') return $error;
2684
							else return self::check_version(true);
2685
						} elseif ($result['value'] == '31') {
2686
							$error = self::update_from_31();
2687
							if ($error != '') return $error;
2688
							else return self::check_version(true);
2689
						} elseif ($result['value'] == '32') {
2690
							$error = self::update_from_32();
2691
							if ($error != '') return $error;
2692
							else return self::check_version(true);
2693
						} elseif ($result['value'] == '33') {
2694
							$error = self::update_from_33();
2695
							if ($error != '') return $error;
2696
							else return self::check_version(true);
2697
						} elseif ($result['value'] == '34') {
2698
							$error = self::update_from_34();
2699
							if ($error != '') return $error;
2700
							else return self::check_version(true);
2701
						} elseif ($result['value'] == '35') {
2702
							$error = self::update_from_35();
2703
							if ($error != '') return $error;
2704
							else return self::check_version(true);
2705
						} elseif ($result['value'] == '36') {
2706
							$error = self::update_from_36();
2707
							if ($error != '') return $error;
2708
							else return self::check_version(true);
2709
						} elseif ($result['value'] == '37') {
2710
							$error = self::update_from_37();
2711
							if ($error != '') return $error;
2712
							else return self::check_version(true);
2713
						} elseif ($result['value'] == '38') {
2714
							$error = self::update_from_38();
2715
							if ($error != '') return $error;
2716
							else return self::check_version(true);
2717
						} elseif ($result['value'] == '39') {
2718
							$error = self::update_from_39();
2719
							if ($error != '') return $error;
2720
							else return self::check_version(true);
2721
						} elseif ($result['value'] == '40') {
2722
							$error = self::update_from_40();
2723
							if ($error != '') return $error;
2724
							else return self::check_version(true);
2725
						} elseif ($result['value'] == '41') {
2726
							$error = self::update_from_41();
2727
							if ($error != '') return $error;
2728
							else return self::check_version(true);
2729
						} elseif ($result['value'] == '42') {
2730
							$error = self::update_from_42();
2731
							if ($error != '') return $error;
2732
							else return self::check_version(true);
2733
						} elseif ($result['value'] == '43') {
2734
							$error = self::update_from_43();
2735
							if ($error != '') return $error;
2736
							else return self::check_version(true);
2737
						} elseif ($result['value'] == '44') {
2738
							$error = self::update_from_44();
2739
							if ($error != '') return $error;
2740
							else return self::check_version(true);
2741
						} elseif ($result['value'] == '45') {
2742
							$error = self::update_from_45();
2743
							if ($error != '') return $error;
2744
							else return self::check_version(true);
2745
						} elseif ($result['value'] == '46') {
2746
							$error = self::update_from_46();
2747
							if ($error != '') return $error;
2748
							else return self::check_version(true);
2749
						} elseif ($result['value'] == '47') {
2750
							$error = self::update_from_47();
2751
							if ($error != '') return $error;
2752
							else return self::check_version(true);
2753
						} elseif ($result['value'] == '48') {
2754
							$error = self::update_from_48();
2755
							if ($error != '') return $error;
2756
							else return self::check_version(true);
2757
						} elseif ($result['value'] == '49') {
2758
							$error = self::update_from_49();
2759
							if ($error != '') return $error;
2760
							else return self::check_version(true);
2761
						} elseif ($result['value'] == '50') {
2762
							$error = self::update_from_50();
2763
							if ($error != '') return $error;
2764
							else return self::check_version(true);
2765
						} elseif ($result['value'] == '51') {
2766
							$error = self::update_from_51();
2767
							if ($error != '') return $error;
2768
							else return self::check_version(true);
2769
						} elseif ($result['value'] == '52') {
2770
							$error = self::update_from_52();
2771
							if ($error != '') return $error;
2772
							else return self::check_version(true);
2773
						} elseif ($result['value'] == '53') {
2774
							$error = self::update_from_53();
2775
							if ($error != '') return $error;
2776
							else return self::check_version(true);
2777
						} elseif ($result['value'] == '54') {
2778
							$error = self::update_from_54();
2779
							if ($error != '') return $error;
2780
							else return self::check_version(true);
2781
						} else return '';
2782
					} else {
2783
						if (isset($result['value']) && $result['value'] != '') return $result['value'];
2784
						else return 0;
2785
					}
2786
				}
2787
			} else return $version;
2788
		}
2789
	}
2790
}
2791
//echo update_schema::check_version();
2792
?>