This repository has been archived by the owner on Mar 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repoLoader.php
154 lines (131 loc) · 4.54 KB
/
repoLoader.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
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fi" lang="fi">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Taapeli aineiston luku kantaan</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div class="goback">
<a href="index.php">Paluu</a></div>
<h1>Taapeli testilataus</h1>
<p>Luetaan gedcom-tiedostoa.</p>
<?php
include "inc/dbconnect.php";
/*-------------------------- Tiedoston luku ----------------------------*/
/*
* Simple file Upload system with PHP by Tech Stream
* http://techstream.org/Web-Development/PHP/Single-File-Upload-With-PHP
*/
if(isset($_FILES['image']) && $_FILES['image']['name'] != ""){
// Tiedoston käsittelyn muuttujat
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$max_lines = $_POST["maxlines"];
$x=explode('.',$file_name);
$x=end($x);
$file_ext = strtolower($x);
$expensions= array("ged","degcom","txt");
if(in_array($file_ext,$expensions)=== false){
$errors[]="Väärä tiedostopääte. Anna Gedcom -tiedosto, jonka pääte on " .
"ged, degcom tai txt";
}
if($file_size > 2097152){
$errors[].='Tiedostokoko on nyt rajoitettu 2 Mb:een ';
}
if(empty($errors)==true) {
echo "<p><em>Ladattu työtiedosto: " . $file_tmp
. " (size=" . $file_size . ") <-- " . $file_name;
// . ", charset=" . $_POST["charset"]
// . ", käsitellään enintään " . $max_lines
// . " riviä";
//
// if ($_POST["show"] == 'ged') {
// $sg = true; // Näytetään ged-koodi
// }
echo "</em><p>\n";
function idtrim($id) {
// Remove @ signs
return substr(trim($id), 1, -1);
}
$repoLabel = $sukudb->makeLabel('Repo');
$soureLabel = $sukudb->makeLabel('Source');
$n = 0;
/*
** Avataan tiedosto
*/
$file_handle = fopen($file_tmp, "r");
while (!feof($file_handle)) {
$line = fgets($file_handle);
$n++;
$a = explode(' ', $line, 3);
$level = $a[0];
if (sizeof($a) > 1) {
$key = trim($a[1]);
}
else {
// echo "\n\nOnly one argument on line: " . $n . "\n";
$key = "";
}
if (sizeof($a) > 2) {
$arg = $arg0 = trim($a[2]);
}
if ($level == 0) {
$id = idtrim($key);
$source_id = 0; // set the base id for the source
$query_string = "MERGE (n:Repo {id:'" . $id . "'})";
$query = new Everyman\Neo4j\Cypher\Query($sukudb, $query_string);
$result = $query->getResultSet();
}
else if ($level == 1) {
switch ($key) {
case "NAME":
$query_string = "MATCH (n:Repo {id:'" . $id .
"'}) SET n.name='" . $arg0 . "'";
$query = new Everyman\Neo4j\Cypher\Query($sukudb, $query_string);
$result = $query->getResultSet();
break;
case "SOUR":
$query_string = "MATCH (n:Repo {id:'" . $id .
"'}) MERGE (n)-[:REPO_SOURCE]-(:Repo_source {id:'" .
$source_id++ . "', name:'" . $arg0 . "'})";
$query = new Everyman\Neo4j\Cypher\Query($sukudb, $query_string);
$result = $query->getResultSet();
break;
default;
echo "Unknown tag: " . $key . "\n";
}
}
} // while feof
}
echo "</p>\n";
fclose($file_handle);
echo "<p><em>{$file_name} {$n} riviä</em></p>";
}
else {
print_r($errors);
}
/*-------------------------- Tiedoston valintalomake ----------------------------*/
?>
<form action="" method="POST" enctype="multipart/form-data"></p>
<table class="form">
<tr><td>
<h2>Anna ladattava repo-tiedosto</h2>
<p>Syöte: <input type="file" name="image" required/></p>
<!--
<p>Merkistö: <input type="radio" name="charset" value="UTF-8" checked>UTF-8
(<input type="radio" name="charset" value="UTF-16" disabled>UTF-16LE ei tarjolla)
</p>
<p><input type="checkbox" name="show" value="ged" checked>Näytä myös gedcom-tietokentät</p>
<p>Käsiteltävä maksimi rivimäärä
<input type="number" name="maxlines" value="999"></p>
-->
</td><td style="vertical-align: bottom">
<input type="submit"/>
</td></tr>
</table>
</form>
</body>
</html>