-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathretrieve.php
More file actions
143 lines (121 loc) · 4.27 KB
/
Copy pathretrieve.php
File metadata and controls
143 lines (121 loc) · 4.27 KB
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
<html>
<head>
<title>Pipoca</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
<style>
img {
float: left;
margin: 0 20px 10px 0;
width: 150px;
}
td {
padding: 5px 5px 15px 5px;
}
</style>
<script>
function ajax_post(){
// Create our XMLHttpRequest object
var hr = new XMLHttpRequest();
hr.open("POST", "doRetrieve.php", true);
// Set content type header information for sending url encoded variables in the request
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// Access the onreadystatechange event for the XMLHttpRequest object
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("result").innerHTML = return_data;
}
}
//montando a string do mysql
var comando = "string=SELECT DISTINCT * FROM sources"; //basico
//primeiro os atributos
var conector = 0;
var listIds=document.getElementsByName('idAttributes[]');
var listValues=document.getElementsByName('values[]');
var i;
for (i=0; i < document.getElementById("totalA").value; i++) {
if (listValues[i].value != "") {
if (conector==0) {
comando = comando + " WHERE";
conector = 1;
} else {
comando = comando + " AND";
}
comando = comando + " sources.id IN (SELECT source_id FROM sourceAttributes WHERE attributes_id=" + listIds[i].value + " AND value='" + listValues[i].value + "')";
}
}
//agora os codes
if (document.getElementById("codes_id").value != 'default') {
if (conector==0) {
comando = comando + " WHERE";
conector = 1;
} else {
comando = comando + " AND";
}
comando = comando + " sources.id IN (SELECT source_id FROM sourceCoding WHERE codes_id=" + document.getElementById("codes_id").value + ")";
}
// Actually execute the request
hr.send(comando);
document.getElementById("result").innerHTML = "processing...";
}
</script>
</head>
<body>
<div id="#tudo">
<object data="css/logo.svg" type="image/svg+xml" height=200 width=900></object>
<div id="menu">
<?php include("menu.html"); ?>
</div>
<div id="centro">
<?php
include("connection.php");
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
//montando a lista de atributos
$sql = "SELECT * FROM attributes";
$result = mysqli_query($conn, $sql);
echo "<h2>Retrieve sources</h2>";
echo "<input type=hidden name='idImage' value='" . $_GET["idImage"] . "'>\n";
$i = 0;
echo "<table border=0>";
while($row = mysqli_fetch_assoc($result)) {
echo "<tr><td>";
echo "<input type=hidden name='idAttributes[]' value='" . $row["id"] . "'>\n";
echo "<span class='fieldname'>" . $row["name"] . "</span></td><td><input type=text name='values[]' value=''></td>\n";
echo "<td><span class='discrete'>" . $row["memo"] . "</span><br>\n";
//getting the values of this attribute
echo "<span class='discrete'>Registered values: ";
$result2 = mysqli_query($conn, "SELECT DISTINCT value FROM sourceAttributes WHERE attributes_id='" . $row["id"] . "'");
while($row2 = mysqli_fetch_assoc($result2)) {
echo $row2["value"] . ", ";
}
echo "</span></td></tr>\n";
$i =$i+1;
}
//total of attributes
echo "<tr><td><input type=hidden id='totalA' value='" . $i . "'>\n";
//montando o seletor de codigos disponiveis
$sql = "SELECT name, id FROM codes";
$result = mysqli_query($conn, $sql);
echo "<span class='fieldname'>Codings</span></td><td colspan=2><select id='codes_id'>";
echo "<option value='default' selected='selected'>Select a code</option>";
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "<option value='" . $row["id"] . "'>" . $row["name"] . "</option>";
}
}
echo "</select></td></tr>\n";
mysqli_close($conn);
?>
<tr><td colspan=3><br/><center><input type=Submit value="Retrieve images" onclick="ajax_post();"></center></td></tr>
</table>
<br>
<div id="result"></div>
</div>
</div>
</body>
</html>