-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_action.php
171 lines (134 loc) · 4.76 KB
/
search_action.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
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php function get_board_types ($dbc){
$table_name = "FTK_parts";
$column_name = "board_type";
$q = "SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = '$table_name' AND COLUMN_NAME = '$column_name'";
$r = mysqli_query($dbc, $q);
$row = mysqli_fetch_array($r);
$enumList = explode(",", str_replace("'", "", substr($row['COLUMN_TYPE'], 5, (strlen($row['COLUMN_TYPE'])-6))));
//print(count($enumList));
$array = array(
"foo" => "bar",
"bar" => "foo");
// return $array;
return $enumList;
} ?>
<?php
//ini_set('display_errors', 'On');
session_start();
// If the session vars aren't set, try to set them with a cookie
if (!isset($_SESSION['user_id'])) {
if (isset($_COOKIE['user_id']) && isset($_COOKIE['username'])) {
$_SESSION['user_id'] = $_COOKIE['user_id'];
$_SESSION['username'] = $_COOKIE['username'];
}
}
?>
<!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="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Module Reception Test</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h3>FTK Reception Test - Query FTK Results</h3>
<?php
//ini_set('display_errors', 'On');
require_once('appvars.php');
require_once('connectvars.php');
// Make sure the user is logged in before going any further.
if (!isset($_SESSION['user_id'])) {
echo '<p class="login">Please <a href="login.php">log in</a> to access this page.</p>';
exit();
}
else {
echo('<p class="login">You are logged in as ' . $_SESSION['username'] . '. <a href="logout.php">Log out</a>.<br /> Go back to the <a href="index.php">Index</a>.</p>');
}
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$enumList2=get_board_types($dbc);
mysqli_close($dbc);
//if (isset($_POST['submit'])) {
// echo $searchphrase;
// }
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
include('connectvars.php');
$sql = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
mysql_select_db(DB_NAME) or die(mysql_error());
$searchphrase = $_POST["searchphrase"];
if($_POST["item_type"]=='bd') {
$table='ftk_parts';
} elseif ($_POST["item_type"]=='cb'){
$table='ftk_cables';
} else {
$table='ftk_other';
}
$sql_search = "select * from " . $table . " where ";
$sql_search_fields = Array();
$sql = "SHOW COLUMNS FROM " . $table;
$rs = mysql_query($sql);
while ($r = mysql_fetch_array($rs)) {
$colum = $r[0];
$sql_search_fields[] = $colum . " like('%" . $searchphrase . "%')";
}
$sql_search .= implode(" OR ", $sql_search_fields);
$rs2 = mysql_query($sql_search);
$out = mysql_num_rows($rs2) . "\n";
echo "Number of search hits in $table " . $out."<br />";
echo'<table border="1">';
echo'<tr><td>Type</td>
<td>Id</td>
<td>Location</td>
<td>Rack</td>
<td>Crate</td>
<td>Slot</td>
<td>InstStatus</td>
<td>CERN receival_date</td>
<td>TEST date</td>
<td>Production date</td>
<td>Owner</td>
<td>Last user</td>
<td>MB_SN</td>
<td>MB_Pos</td>
<td>FPGA</td>
<td>Firmware version</td>
<td>Status</td>
<td>Board type ID</td>
</tr>';
while ($results = mysql_fetch_array($rs2)){
//print $results[0].
//echo '<br />';
echo'<tr><td>'.$results['board_type'].'</td>
<td>'.$results['board_id'].'</td>
<td>'.$results['location'].'</td>
<td>'.$results['rack'].'</td>
<td>'.$results['crate'].'</td>
<td>'.$results['slot'].'</td>
<td>'.$results['inst_status'].'</td>
<td>'.$results['CERN_receival_date'].'</td>
<td>'.$results['TEST_date'].'</td>
<td>'.$results['Prod_date'].'</td>
<td>'.$results['owner'].'</td>
<td>'.$results['last_user'].'</td>
<td>'.$results['MB_SN'].'</td>
<td>'.$results['MB_Pos'].'</td>
<td>'.$results['FPGA'].'</td>
<td>'.$results['firmware_version'].'</td>
<td>'.$results['Status'].'</td>
<td>'.$results['board_type_ID'].'</td>
</tr>';
}
echo'</table>';
?>
</body>
</html>