/
search-form.php
269 lines (256 loc) · 9.79 KB
/
search-form.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<?php
if (!empty($formActionUri)):
$formAttributes['action'] = $formActionUri;
else:
$formAttributes['action'] = url(array('controller' => 'items',
'action' => 'browse'));
endif;
$formAttributes['method'] = 'GET';
// adjusting field drop down to show the alternate names for fields
$renamed_fields = array(
'Creator' => 'Authors',
'Description' => 'Notes'
);
$ab_fields = get_table_options('Element', null, array(
'record_types' => array('Item', 'All'),
'sort' => 'orderBySet')
);
// $field_count = count($ab_fields);
foreach ($ab_fields as $key => $val) {
// if (in_array($ab_fields[$i], $hidden_fields)) {
// unset($ab_fields[$i]);
// }
if (array_key_exists($val, $renamed_fields)) {
$ab_fields[$key] = $renamed_fields[$val];
}
}
?>
<form <?php echo tag_attributes($formAttributes); ?>>
<div id="search-keywords" class="field<?php if (is_current_url(url('/'))): ?> ab-index-hide<?php endif ?>">
<?php echo $this->formLabel('keyword-search', __('Search for Keywords')); ?>
<div class="inputs">
<?php
echo $this->formText(
'search',
@$_REQUEST['search'],
array('id' => 'keyword-search', 'size' => '40')
);
?>
</div>
</div>
<div id="search-narrow-by-fields" class="field">
<div class="label<?php if (is_current_url(url('/'))): ?> ab-index-hide<?php endif ?>"><?php echo __('Narrow by Specific Fields'); ?></div>
<div class="inputs">
<?php
// If the form has been submitted, retain the number of search
// fields used and rebuild the form
if (!empty($_GET['advanced'])) {
$search = $_GET['advanced'];
} else {
$search = array(array('field' => '', 'type' => '', 'value' => ''));
}
//Here is where we actually build the search form
foreach ($search as $i => $rows): ?>
<div class="search-entry">
<?php
//The POST looks like =>
// advanced[0] =>
//[field] = 'description'
//[type] = 'contains'
//[terms] = 'foobar'
//etc
echo $this->formSelect(
"advanced[$i][joiner]",
@$rows['joiner'],
array(
'title' => __("Search Joiner"),
'id' => null,
'class' => 'advanced-search-joiner'
),
array(
'and' => __('AND'),
'or' => __('OR'),
)
);
if (is_current_url(url('/')) and get_theme_option('Asearch Fields') != "") {
// $bibElementSet= get_record('ElementSet',array('name'=>"Item Type Metadata"));
$asearch_fields = get_theme_option('Asearch Fields');
$fields_array = array_map('trim', explode(',', $asearch_fields));
$db = get_db();
$bibElements=array();
foreach ($fields_array as $afield){
$bibElementSet = $db->getTable('Element')->fetchObjects("SELECT * FROM {$db->prefix}elements e WHERE e.name = '{$afield}'");
foreach($bibElementSet as $element) {
if ($ab_fields[$element->id]){
$bibElements[$element->id]=$ab_fields[$element->id];
} else {
$bibElements[$element->id]=$element->name;
}
}
}
echo $this->formSelect(
"advanced[$i][element_id]",
@$rows['element_id'],
array(
'title' => __("Search Field"),
'id' => null,
'class' => 'advanced-search-element'
),
$bibElements
);
} else {
echo $this->formSelect(
"advanced[$i][element_id]",
@$rows['element_id'],
array(
'title' => __("Search Field"),
'id' => null,
'class' => 'advanced-search-element'
),
$ab_fields
);
}
echo $this->formSelect(
"advanced[$i][type]",
@$rows['type'],
array(
'title' => __("Search Type"),
'id' => null,
'class' => 'advanced-search-type'
),
array(
'contains' => __('contains'),
'does not contain' => __('does not contain'),
'is exactly' => __('is exactly'),
'is empty' => __('is empty'),
'is not empty' => __('is not empty'),
'starts with' => __('starts with'),
'ends with' => __('ends with'))
);
echo $this->formText(
"advanced[$i][terms]",
@$rows['terms'],
array(
'size' => '20',
'title' => __("Search Terms"),
'id' => null,
'class' => 'advanced-search-terms'
)
);
?>
<button type="button" class="remove_search" disabled="disabled" style="display: none;"><?php echo __('Remove field'); ?></button>
</div>
<?php endforeach; ?>
</div>
<button type="button" class="add_search"><?php echo __('Add a Field'); ?></button>
</div>
<div id="search-by-range" class="field<?php if (is_current_url(url('/'))): ?> ab-index-hide<?php endif ?>">
<?php echo $this->formLabel('range', __('Search by a range of ID#s (example: 1-4, 156, 79)')); ?>
<div class="inputs">
<?php
echo $this->formText('range', @$_GET['range'],
array('size' => '40')
);
?>
</div>
</div>
<div class="field<?php if (is_current_url(url('/'))): ?> ab-index-hide<?php endif ?>">
<?php echo $this->formLabel('collection-search', __('Search By Collection')); ?>
<div class="inputs">
<?php
echo $this->formSelect(
'collection',
@$_REQUEST['collection'],
array('id' => 'collection-search'),
get_table_options('Collection', null, array('include_no_collection' => true))
);
?>
</div>
</div>
<div class="field">
<?php echo $this->formLabel('item-type-search', __('Search By Type')); ?>
<div class="inputs">
<?php
echo $this->formSelect(
'type',
@$_REQUEST['type'],
array('id' => 'item-type-search'),
get_table_options('ItemType')
);
?>
</div>
</div>
<?php if (is_allowed('Users', 'browse')): ?>
<div class="field<?php if (is_current_url(url('/'))): ?> ab-index-hide<?php endif ?>">
<?php
echo $this->formLabel('user-search', __('Search By User'));?>
<div class="inputs">
<?php
echo $this->formSelect(
'user',
@$_REQUEST['user'],
array('id' => 'user-search'),
get_table_options('User')
);
?>
</div>
</div>
<?php endif; ?>
<div class="field">
<?php echo $this->formLabel('tag-search', __('Search By Keywords')); ?>
<div class="inputs">
<?php
echo $this->formText('tags', @$_REQUEST['tags'],
array('size' => '40', 'id' => 'tag-search')
);
?>
</div>
</div>
<?php if (is_allowed('Items', 'showNotPublic')): ?>
<div class="field<?php if (is_current_url(url('/'))): ?> ab-index-hide<?php endif ?>">
<?php echo $this->formLabel('public', __('Public/Non-Public')); ?>
<div class="inputs">
<?php
echo $this->formSelect(
'public',
@$_REQUEST['public'],
array(),
label_table_options(array(
'1' => __('Only Public Items'),
'0' => __('Only Non-Public Items')
))
);
?>
</div>
</div>
<?php endif; ?>
<div class="field<?php if (is_current_url(url('/'))): ?> ab-index-hide<?php endif ?>">
<?php echo $this->formLabel('featured', __('Featured/Non-Featured')); ?>
<div class="inputs">
<?php
echo $this->formSelect(
'featured',
@$_REQUEST['featured'],
array(),
label_table_options(array(
'1' => __('Only Featured Items'),
'0' => __('Only Non-Featured Items')
))
);
?>
</div>
</div>
<?php if (!isset($buttonText)) {
$buttonText = __('Search for items');
} ?>
<input type="submit" class="submit" name="submit_search" id="submit_search_advanced" value="<?php echo $buttonText ?>">
<?php if (!is_current_url(url('/'))): ?>
<?php fire_plugin_hook('public_items_search', array('view' => $this)); ?>
<?php endif ?>
</form>
<?php echo js_tag('items-search'); ?>
<script type="text/javascript">
jQuery(document).ready(function () {
Omeka.Search.activateSearchButtons();
});
</script>