This repository has been archived by the owner on Sep 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathimport.php
142 lines (134 loc) · 5.58 KB
/
import.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php /* begin license *
*
* Tabbie, Debating Tabbing Software
* Copyright Contributors
*
* This file is part of Tabbie
*
* Tabbie is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Tabbie is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tabbie; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* end license */
$ntu_controller = "import";
$moduletype="";
require("ntu_bridge.php");
require("view/header.php");
require("view/mainmenu.php");
require("includes/adjudicator.php");
require("includes/dbimport.php");
require_once("includes/dbconnection.php");
?>
<h2>Import Backup</h2>
<p>
Use this page to import SQL files. SQL files can be created by clicking on "backup".<br/>
<b>Warning: this will erase all current data from your Tabbie installation!</b>
<form enctype="multipart/form-data" action="import.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
<label for="uploadedfile">Choose a file to upload:</label> <input name="uploadedfile" type="file" /><br /><br />
<label for="drop_create">Drop and recreate DB?</label> <input name="drop_create" type="checkbox" value="drop" /><br /><br />
<input type="submit" value="Start Import" />
</form>
</p>
<?php
if ( array_key_exists("uploadedfile", @$_FILES)) {
$problem = false;
echo <<<WARN
<div id='import-warning' style='display: block; width:100%, padding-top: 15px; padding-bottom: 15px; background: #ffcc00; text-align: center; color: #000000; font-size: +1em;'><strong>CAUTION: </strong> Wait for import to complete before navigating away from this page</div>
WARN;
if (isset($_POST['drop_create']) && $_POST['drop_create']=="drop") {
if (!$DBConn->Execute("DROP DATABASE $database_name")) {
$problem = true;
print $DBConn->ErrorMsg() . "<br>";
}
if (!$DBConn->Execute("CREATE DATABASE $database_name")) {
$problem = true;
print $DBConn->ErrorMsg() . "<br>";
}
$DBConn->Execute("USE $database_name");
}
echo ('<p style="font-family: courier; font-size: 10px;">');
$contents = file_get_contents($_FILES['uploadedfile']['tmp_name']);
// Dumps could be generated by us, but also may be taken straight from the server
// If it's a windows system, carriage returns are \r\n;, if unix, \n; Accommodate.
$lines = explode(strpos($contents,";\r\n") ? ";\r\n" : ";\n", $contents);
foreach ($lines as $line) {
$problem = !execute_query_print_result($line) || $problem; // Return false on error, so negate
}
echo('</p>');
//Upgrade files with 'conflicts' in adjudicator table]
$query="SHOW COLUMNS FROM adjudicator";
$result=$DBConn->Execute($query);
while($row=$result->FetchRow()){
if($row['Field']=='conflicts'){
// Does this do what we want? Does it not recreate strikes in many cases?!
$query=" CREATE TABLE strikes (strike_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, adjud_id INT NOT NULL , team_id INT NULL , univ_id INT NULL , INDEX ( adjud_id ))";
$r=$DBConn->Execute($query);
if (!$r) {
print $DBConn->ErrorMsg();
}
$query="SELECT adjud_id, univ_id, conflicts FROM adjudicator";
$strikeresult=$DBConn->Execute($query);
while($adjudicator=$strikeresult->FetchRow()){
$conflicts = preg_split("/, /", $adjudicator['conflicts'], -1, PREG_SPLIT_NO_EMPTY);
foreach ($conflicts as $conflict) {
$parts = preg_split("/\./", $conflict);
if (count($parts) == 1) {
add_strike_judge_univ($adjudicator['adjud_id'],__get_university_id_by_code($conflict));
} elseif (count($parts == 2)) {
add_strike_judge_team($adjudicator['adjud_id'],__get_team_id_by_codes($parts[0], $parts[1]));
}
}
}
add_strike_judge_univ($adjudicator['adjud_id'],$adjudicator['univ_id']); //Strike from own institution.
$query="ALTER TABLE adjudicator DROP COLUMN conflicts";
$r=$DBConn->Execute($query);
if (!$r) {
$problem = true;
print $DBConn->ErrorMsg();
}
print "<p>Conflicts converted to new format.</p>";
}
}
include('draw/adjudicator/simulated_annealing_config.php'); ## Converts settings table
//Upgrade MyISAM dbs to InnoDB
$query="SELECT table_name,engine FROM INFORMATION_SCHEMA.TABLES WHERE table_schema='$database_name';";
$result=$DBConn->Execute($query);
while($row=$result->FetchRow()){
if ($row["engine"] == "MyISAM"){
$query = "ALTER TABLE ".$row["table_name"]." ENGINE=InnoDB;";
$DBConn->Execute($query);
print "<p>Converting ".$row["table_name"]." to InnoDB. ".$DBConn->ErrorMsg()."</p>";
}
}
if (! $problem ) {
echo<<<EOHTML
<p><b>Imported File Succesfully</b></p>
<script type='text/javascript'>
$('#import-warning').css("background", "#00dd00");
$('#import-warning').html("<strong>Success! </strong> Data successfully imported!");
</script>
EOHTML;
} else {
echo<<<EOHTML
<p><b>Imported Encountered Problems</b></p>
<script type='text/javascript'>
$('#import-warning').css("background", "#dd0000");
$('#import-warning').css("color", "#ffffff");
$('#import-warning').html("<strong>Error: </strong> Problem found while importing data, see bold statements below for details");
</script>
EOHTML;
}
}
require('view/footer.php');
?>