-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathname_lookup.php
More file actions
155 lines (143 loc) · 4.51 KB
/
name_lookup.php
File metadata and controls
155 lines (143 loc) · 4.51 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
144
145
146
147
148
149
150
151
152
153
154
155
<?php
// This file is part of Music Match.
// Copyright (C) 2022 David P. Anderson
//
// Music Match is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// Music Match 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Music Match. If not, see <http://www.gnu.org/licenses/>.
// --------------------------------------------------------------------
require_once("../inc/boinc_db.inc");
require_once("../inc/util.inc");
require_once("../inc/user.inc");
require_once("../inc/mm_db.inc");
function show_user($user) {
row_array([
"<a href=user.php?user_id=$user->id>$user->name</a>",
"$user->country",
time_str($user->create_time)
]);
}
function show_ensemble($e) {
$user = BoincUser::lookup_id($e->user_id);
$profile = read_profile($e->id, ENSEMBLE);
row_array([
"<a href=ensemble.php?ens_id=$e->id>$e->name</a>",
"<a href=user.php?user_id=$user->id>$user->name</a>",
ensemble_type_str($profile->type)
]);
}
function user_search_form() {
page_head(tra("User name lookup"));
form_start("name_lookup.php", "post", "name=f");
form_input_text("User name contains", 'search_string');
form_general(
"Country",
'<select class="form-control" name="country"><option value="any" selected>Any</option>'.country_select_options("asdf")."</select>"
);
form_submit('Search', 'name=submit value=on');
echo "
<script>document.f.search_string.focus()</script>
";
page_tail();
}
function ensemble_search_form() {
page_head(tra("Ensemble name lookup"));
form_start("name_lookup.php", "post", "name=f");
form_input_hidden('ensemble', 1);
form_input_text("Ensemble name contains", 'search_string');
form_submit('Search', 'name=submit value=on');
echo "
<script>document.f.search_string.focus()</script>
";
page_tail();
}
function user_search_action() {
$where = "true";
$search_string = post_str('search_string');
if (strlen($search_string)<3) {
error_page(tra("search string must be at least 3 characters"));
}
$s = BoincDb::escape_string($search_string);
$s = escape_pattern($s);
$where .= " and name like '%$s%'";
$country = post_str('country');
if ($country != 'any') {
$s = BoincDb::escape_string($country);
$where .= " and country='$s'";
}
$order_clause = "name desc";
$users = BoincUser::enum($where, "order by $order_clause limit 100");
page_head(tra("User name lookup results"));
if ($users) {
start_table('table-striped');
row_heading_array(
array(
tra("Name"),
tra("Country"),
tra("Joined")
)
);
foreach ($users as $user) {
show_user($user);
}
end_table();
} else {
echo tra("No users have matching names.");
}
page_tail();
}
function ensemble_search_action() {
$where = "true";
$search_string = post_str('search_string');
if (strlen($search_string)<3) {
error_page(tra("search string must be at least 3 characters"));
}
$s = BoincDb::escape_string($search_string);
$s = escape_pattern($s);
$where .= " and name like '%$s%'";
$ensembles = Ensemble::enum($where, "order by name desc limit 100");
page_head(tra("Ensemble name lookup results"));
if ($ensembles) {
start_table('table-striped');
row_heading_array(
array(
"Name",
"Founder",
"Type"
)
);
foreach ($ensembles as $e) {
show_ensemble($e);
}
end_table();
} else {
echo tra("No ensembles have matching names.");
}
page_tail();
}
$user = get_logged_in_user();
update_visit_time($user);
$submit = post_str('submit', true);
if ($submit) {
if (post_int('ensemble', true)) {
ensemble_search_action();
} else {
user_search_action();
}
} else {
if (get_int('ensemble', true)) {
ensemble_search_form();
} else {
user_search_form();
}
}
?>