-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.html
executable file
·987 lines (872 loc) · 31.9 KB
/
search.html
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
<?php
// purpose: This code searches the database for the user specified search terms and displays matching items
//get and set url protocol
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://';
//set and sanitize global variables for URL construction
$server = isset($_SERVER['SERVER_NAME']) ? htmlentities(strip_tags($_SERVER['SERVER_NAME'])) : null;
$path = isset($_SERVER['PHP_SELF']) ? htmlentities(strip_tags(dirname($_SERVER['PHP_SELF']))) : null;
$fileName = isset($_SERVER['SCRIPT_NAME']) ? htmlentities(strip_tags(basename($_SERVER['SCRIPT_NAME']))) : null;
$fileNameURI = isset($_SERVER['REQUEST_URI']) ? htmlentities(strip_tags($_SERVER['REQUEST_URI'])) : null;
$fileExtension = isset($_SERVER['PATH_INFO']) ? pathinfo($fileName, PATHINFO_EXTENSION) : null;
//set title, description, and keywords
$pageTitle = 'Linked People (Demo) - Search';
$pageDescription = 'Search page and search results for querying the Linked People database.';
//declare filname for additional css - default is "none"
$customCSS = 'people.css';
//get database parameters and connect to database
include_once './meta/assets/database-params.inc';
//create an array with filepaths for multiple page scipts - default is "none"
$customScript[0] = 'none';
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8"/>
<meta http-equiv="x-ua-compatible" content="ie=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title><?php echo($pageTitle); ?>: Montana State University (MSU) Library</title>
<meta name="description" content="<?php echo($pageTitle); ?>: Code prototype for Linked People"/>
<link rel="canonical" href="<?php echo $protocol.$server.$path; ?>/<?php echo $fileName; ?>"/>
<link rel="stylesheet prefetch" href="https://fonts.googleapis.com/css?family=Oswald"/>
<style>
html {-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;box-sizing:border-box;}
*,:before,:after {box-sizing:inherit;}
html,body {-webkit-font-smoothing:antialiased;background-color:#eee;color:#333;font-family:Oswald,Helvetica,arial,sans-serif;font-size:100%;font-stretch:normal;font-style:normal;font-variant:normal;font-weight:400;height:100%;line-height:1.5;margin:0;padding:0;width:100%;}
header {background-color:#002a61;color:#fff;line-height:70px;padding:0 70px;width:100%;}
nav {color:#828282;display:inline;font-size:.7em;padding:0 10px;}
a {color:#002a61;transition:all .3s;}
nav a {color:#bebebe;text-decoration:none;}
nav a:hover {text-decoration:underline;}
header .nav a,footer .nav a {font-size:14px;}
header .nav a:not(:last-child),footer .nav a:not(:last-child) {border-right:.0725em solid #c4c4c4;margin-right:5px;padding-right:10px;}
main {/*height:100vh;*/min-height:396px;padding:20px 40px;}
.content {column-gap:40px;column-width:300px;}
.content {display:grid;grid-gap:40px;grid-template-columns:repeat(1, 100%);}
section {-webkit-column-break-inside:avoid;background-color:#fff;break-inside:avoid;padding:30px;page-break-inside:avoid;}
@supports (column-width:300px;) {
section+section {margin:20px 0;}
}
@supports (display:grid) {
section+section {margin:0;}
}
header h1 {color:#fff;display:inline-block;font-size:2em;font-weight:bold;margin:10px 0;padding:0;}
h1 {color:#1a202c;font-size:1.5em;font-weight:normal;padding:10px 30px;}
h2 {color:#5d5d5d;font-size:1.17em;font-weight:normal;margin-bottom:.4em;}
p+p {margin-top:.7em;}
hr {border:0;border-bottom:0 solid #fff;border-top:.0725em solid #c4c4c4;box-sizing:content-box;height:0;margin:2em auto 1em;}
a.home {text-decoration:none;color:#fff;}
.border-ftr {width:90%;}
.center {text-align:center;}
.copyright {font-size:12px;}
.text {padding:5px;width:250px;}
/*medium screen view < 1030px (based on 16px browser default)*/
@media all and (max-width:64.375em) {
/*.content {grid-template-columns: repeat(2, 48%);}*/
}
/*small screen view < 801px (based on 16px browser default)*/
@media all and (max-width:50.063em) {
header {line-height:40px;padding:0 45px;}
header nav {display:block;padding:0;}
main {padding-left:15px;padding-right:15px;}
.content {grid-template-columns: repeat(1, 100%);}
}
</style>
<?php
if ($customCSS = (empty($customCSS)) ? null : $customCSS) {
$countedCSS = count($customCSS);
for ($i = 0; $i < $countedCSS; $i++) {
?>
<link rel="stylesheet" href="<?php echo $customCSS[$i]; ?>">
<?php
}
}
?>
</head>
<body id="page" vocab="https://schema.org/" typeof="SearchResultsPage" resource="<?php echo $protocol.$server.$path; ?>/<?php echo $fileName; ?>#page">
<link property="isPartOf" typeof="CollectionPage" href="<?php echo $protocol.$server.$path; ?>/"/>
<header>
<h1><a class="home" href="index.html">Linked People</a></h1>
<nav class="nav"><a href="index.html">Home</a> <a href="search.html">Search</a> <a href="browse-expertise.html">Browse</a></nav>
</header>
<main>
<h1>Search</h1>
<div class="content">
<section>
<form class="search" name="searchform" action="search.html" method="get">
<input class="text" type="text" name="q" id="q" maxlength="55" placeholder="Enter people or topics..."/>
<select name="facet">
<option id="keyword" name="keyword" selected value="keyword">People</option>
<option id="topic" name="topic" value="topic">Topics</option>
</select>
<button class="submit" id="submit" role="button" type="submit">Search</button>
</form>
<?php
//number of records to display per page
$recordsPerPage = 15;
//maximum length of description to be displayed
$maxLengthDescription = 150;
/**
* Mapping of possible query elements to their corresponding mods fields
*
* Note: To add a new query element type, simply add another line to this array.
* Each query element type can map to one or more comma-separated mods fields.
*/
$queryToModsMap = array (
"q" => "",
"facet" => "",
"team" => "",
"staff" => "",
"liaison" => "",
"expertise" => ""
);
// QueryData Class
class QueryData
{
// mapping of query elements to mods fields
protected $queryToModsMap;
// number of records to display per page
protected $recordsPerPage;
// array that holds the query elements and corresponding values
protected $queryArray = Array();
// array that holds exploded (separated) mods fields and their
// corresponding query values used to highlight matched query values
protected $highlightArray;
// starting record to pull on the next query
protected $start;
// number of records to pull on the next query
protected $limit;
// database connection
protected $connectLibstaff;
// facet if set
protected $facet;
/**
* QueryData Constructor
*
* Parameters:
* $queryToModsMap - mapping of query elements to mods fields
* $recordsPerPage - number of records to display per page
*/
public function __construct($queryToModsMap, $recordsPerPage, $connectLibstaff)
{
$this->queryToModsMap = $queryToModsMap;
$this->recordsPerPage = $recordsPerPage;
$this->connectLibstaff = $connectLibstaff;
}
/**
* add - add query element and corresponding query value to QueryData object
*
* Parameters:
* $element - element from query string
* $value - corresponding value from query string
*/
function add($element, $value)
{
// Save value in queryArray
if (!isset($this->queryArray[$element]))
{
$this->queryArray[$element] = $value;
}
else
{
$this->queryArray[$element] .= " $value";
}
// Separate comma-separated mods fields into individual mods fields
$modsFields = explode(",", $this->queryToModsMap[$element]);
// Save query value for each mods field
foreach ($modsFields as $field)
{
// Remove quote marks and leading + or -
$value = preg_replace("/(?:[\"\'])|(?:^[-+])/", "", $value);
// Save value for highlighting
$this->highlightArray[trim($field)][] = $value;
}
}
/**
* setFacet - set value of facet
*
* Parameter:
* $facet - value of the facet parameter
*/
public function setFacet($facet)
{
$this->facet = $facet;
}
/**
* setStart - Set value of start property
*
* Parameter:
* $start - value for start property
*/
public function setStart($start)
{
// Check for valid starting row variable
if (is_numeric($start))
{
// Escape it for mysql
$start = $this->connectLibstaff->real_escape_string((int)$start);
if ($start < 0) {
// Use default
$start = 0;
}
}
else
{
// Default value
$start = '0';
}
// Store in class property
$this->start = $start;
}
/**
* getStart - Get value of start property
*
* Returns:
* start property value
*/
public function getStart()
{
return $this->start;
}
/**
* setLimit - Set value of limit property
*
* Parameter:
* $limit - value for limit property
*/
public function setLimit($limit)
{
// Check for valid limit result set variable
if (is_numeric($limit))
{
// Escape it for mysql
$limit = $this->connectLibstaff->real_escape_string((int)$limit);
if ($limit <= 0)
{
// Use default
$limit = $this->recordsPerPage;
}
}
else
{
// Default value
$limit = $this->recordsPerPage;
}
// Store in class property
$this->limit = $limit;
}
/**
* getLimit - Get value of limit property
*
* Returns:
* limit property value
*/
public function getLimit()
{
return $this->limit;
}
/**
* getSqlQueryString - Get the sql query string
*
* Returns:
* sql query string
*/
function getSqlQueryString()
{
$scoreCounter = 0;
$useLike = TRUE;
foreach ($this->queryArray as $element => $value)
{
// get mods field(s) that correspond(s) to search element
$modsField = $this->queryToModsMap[$element];
// Explode value into multiple values and then check length of each item
$newValue = str_replace(array(" ", ",", ".", "-", "|", ":", "\"", "'"), "-", $value);
$explodedValues = explode("-", $newValue);
foreach ($explodedValues as $explodedValue)
{
if (strlen($explodedValue) > 2)
{
// If length of any item is greater than 2, use MATCH. Otherwise use LIKE.
$useLike = FALSE;
break;
}
}
}
$queryString = 'SELECT person.person_id, jobTitle, givenName, familyName, memberOf, workLocation, telephone, email, person_vita, url, image, person_privacy, person_libcal_id ';
if ($this->facet === "topic")
{
$queryString .= " FROM person, interact_action, interact_action_match, create_action, create_action_match";
}
else if ($element === "liaison")
{
$queryString .= " FROM person, interact_action, interact_action_match ";
}
else if ($element === "expertise")
{
$queryString .= " FROM person, create_action, create_action_match ";
}
else
{
$queryString .= " FROM person ";
}
$queryString .= " WHERE person.person_status = 'a' ";
foreach ($this->queryArray as $element => $value)
{
// get mods field(s) that correspond(s) to search element
$modsField = $this->queryToModsMap[$element];
if ($modsField === "")
{
if ($element === "q" && $this->facet === "keyword")
{
$value = $this->connectLibstaff->real_escape_string($value);
$queryString .= "AND MATCH (givenName, familyName, jobTitle, memberOf) AGAINST ('+$value*' IN BOOLEAN MODE)";
}
else if ($element === "q" && $this->facet === "topic")
{
$value = $this->connectLibstaff->real_escape_string($value);
$queryString .= "
AND MATCH (create_action.object) AGAINST ('+$value*' IN BOOLEAN MODE)
AND create_action_match.create_id = create_action.create_id
AND create_action_match.person_id = person.person_id
OR MATCH (interact_action.object) AGAINST ('+$value*' IN BOOLEAN MODE)
AND interact_action_match.interact_id = interact_action.interact_id
AND interact_action_match.person_id = person.person_id
AND person_status='a'
";
}
else if ($element === "team")
{
$value = $this->connectLibstaff->real_escape_string($value);
$queryString .= " AND memberOf LIKE '$value' ";
}
else if ($element === "liaison")
{
$value = $this->connectLibstaff->real_escape_string($value);
$queryString .= "
AND interact_action.object = '$value'
AND interact_action_match.interact_id = interact_action.interact_id
AND interact_action_match.person_id = person.person_id
";
}
else if ($element === "expertise")
{
$value = $this->connectLibstaff->real_escape_string($value);
$value_url = "http://dbpedia.org/resource/" . urldecode($value);
$queryString .= "
AND create_action.object_uri = '$value_url'
AND create_action_match.create_id = create_action.create_id
AND create_action_match.person_id = person.person_id
";
}
}
else
{
// remove enclosing double quotes if present and prepare value for use by mysql
$value = $this->connectLibstaff->real_escape_string(trim($value, '"'));
$queryString .= "AND (";
$explodedFields = explode(",", $modsField);
$continuation = "";
foreach ($explodedFields as $explodedField)
{
if ($useLike)
{
$queryString .= "$continuation$explodedField LIKE '%$value%' ";
}
else
{
$queryString .= "$continuation$explodedField = '$value' ";
}
$continuation = "OR ";
}
$queryString .= ") ";
}
}
$queryString .= "GROUP BY person.person_id ORDER BY person.familyName ASC";
$queryString .= " LIMIT $this->start, $this->limit;";
return $queryString;
}
/**
* getSqlQueryCountString - Get the sql query count string
*
* Returns:
* sql query count string
*/
function getSqlQueryCountString()
{
foreach ($this->queryArray as $element => $value)
{
// get mods field(s) that correspond(s) to search element
$modsField = $this->queryToModsMap[$element];
// explode value into multiple values and then check length of each item
$newValue = str_replace(array(" ", ",", ".", "-", "|", ":", "\"", "'"), "-", $value);
$explodedValues = explode("-", $newValue);
foreach ($explodedValues as $explodedValue)
{
if (strlen($explodedValue) > 2)
{
// If length of any item is greater than 2, use MATCH. Otherwise use LIKE.
$useLike = FALSE;
break;
}
}
}
if ($this->facet === "topic")
{
$queryCountString = "SELECT COUNT(t.person_id) as matchCount";
}
else
{
$queryCountString = "SELECT COUNT(*) AS matchCount";
}
if ($this->facet === "topic")
{
$queryCountString .= "
FROM
(SELECT person.person_id
FROM person
INNER JOIN create_action_match ON person.person_id = create_action_match.person_id
INNER JOIN create_action ON create_action_match.create_id = create_action.create_id
LEFT JOIN interact_action_match ON interact_action_match.person_id = person.person_id
LEFT JOIN interact_action ON interact_action_match.interact_id = interact_action.interact_id
";
}
else if ($element === "liaison")
{
$queryCountString .= " FROM person, interact_action, interact_action_match ";
}
else if ($element === "expertise")
{
$queryCountString .= " FROM person, create_action, create_action_match ";
}
else
{
$queryCountString .= " FROM person";
}
$queryCountString .= " WHERE person_status = 'a' ";
$useLike = TRUE;
foreach ($this->queryArray as $element => $value)
{
// Get mods field(s) that correspond(s) to search element
$modsField = $this->queryToModsMap[$element];
if ($modsField === "")
{
if ($element === "q" && $this->facet === "keyword")
{
$value = $this->connectLibstaff->real_escape_string($value);
$queryCountString .= "AND MATCH (givenName, familyName, jobTitle, memberOf) AGAINST ('+$value*' IN BOOLEAN MODE)";
}
else if ($element === "q" && $this->facet === "topic")
{
$value = $this->connectLibstaff->real_escape_string($value);
$queryCountString .= "
AND MATCH (create_action.object) AGAINST ('+$value*' IN BOOLEAN MODE)
OR MATCH (interact_action.object) AGAINST ('+$value*' IN BOOLEAN MODE)
GROUP BY person.person_id
ORDER BY person.familyName
) as t
";
}
else if ($element === "team")
{
$value = $this->connectLibstaff->real_escape_string($value);
$queryCountString .= " AND memberOf LIKE '$value' ";
}
else if ($element === "liaison")
{
$value = $this->connectLibstaff->real_escape_string($value);
$queryCountString .= "
AND interact_action.object = '$value'
AND interact_action_match.interact_id = interact_action.interact_id
AND interact_action_match.person_id = person.person_id
";
}
else if ($element === "expertise")
{
$value = $this->connectLibstaff->real_escape_string($value);
$value_url = "http://dbpedia.org/resource/" . urldecode($value);
$queryCountString .= "
AND create_action.object_uri = '$value_url'
AND create_action_match.create_id = create_action.create_id
AND create_action_match.person_id = person.person_id
";
}
}
else
{
// explode value into multiple values and then check length of each item
$newValue = str_replace(array(" ", ",", ".", "-", "|", ":", "\"", "'"), "-", $value);
$explodedValues = explode("-", $newValue);
foreach ($explodedValues as $explodedValue)
{
if (strlen($explodedValue) > 2)
{
// If length of any item is greater than 2, use MATCH. Otherwise use LIKE.
$useLike = FALSE;
break;
}
}
// remove enclosing double quotes if present and prepare value for use by mysql
$value = $this->connectLibstaff->real_escape_string(trim($value, '"'));
$queryCountString .= "AND (";
$explodedFields = explode(",", $modsField);
$continuation = "";
foreach ($explodedFields as $explodedField)
{
if ($useLike)
{
$queryCountString .= "$continuation$explodedField LIKE '%$value%' ";
}
else
{
$queryCountString .= " FROM person";
}
{
$queryCountString .= "$continuation$explodedField = '$value' ";
}
$continuation = "OR ";
}
$queryCountString .= ") ";
}
// Finish the query count string
$queryCountString .= ";";
return $queryCountString;
}
}
/**
* getQueryString - Get the query string for previous and next links
*
* Returns:
* query string used by previous and next links
*/
function getQueryString()
{
$queryString = "";
$continuation = "";
foreach ($this->queryArray as $element => $value)
{
$queryString .= "$continuation$element=" . urlencode($value);
$continuation = "&";
}
return $queryString;
}
/**
* getSearchTerms - Gets the search terms
*
* Returns:
* string of search terms
*/
function getSearchTerms()
{
$searchTerms = "";
$continuation = "";
foreach ($this->queryArray as $element => $value)
{
$searchTerms .= $continuation . (($element != "q") ? ($element . " ") : "") . "<strong>$value</strong>";
$continuation = " and ";
}
return $searchTerms;
}
/**
* getFieldWithHighlight - Gets field value and highlights matching query values
*
* Parameters:
* $record - mysql record
* $modsField - mods field to extract from the record
*
* Returns:
* highlighted field value
*/
function getFieldWithHighlight($record, $modsField)
{
// get the field value
$fieldValue = $record->{$modsField};
// check if search includes value(s) for this mods field
if (isset($this->highlightArray[$modsField]))
{
foreach ($this->highlightArray[$modsField] as $matchValue)
{
// Quote regular expression characters that appear in matchValue
$matchValue = preg_quote($matchValue, "/");
// Add the span class around all matches that occur outside of html tags
$fieldValue = preg_replace("/(?![^<]+>)$matchValue/i", "<span class=\"match\">$0</span>", $fieldValue);
}
}
return $fieldValue;
}
} //end QueryData class
//begin display and data population for markup
function formatEmailLink() {
// if they supplied no e-mail address, return nothing.
if(func_num_args() == 0) { return ""; }
// get the e-mail address.
$person_email = func_get_arg(0);
// bounce back if the e-mail address is missing the @ sign.
if(!preg_match("/@/", $person_email)) { return $person_email; }
// break the address into two pieces, removing any single quotes.
$piece = explode("@", preg_replace("/'/", "\\'", $person_email));
// if they supplied a name get that too.
if(func_num_args() == 2)
{
$name = func_get_arg(1);
$name = preg_replace("/'/", "\\'", $name);
}
else
{
$name = "' + a + '@' + b + '";
}
// Assemble the javascript
$javaScript = '<script type="text/javascript">' . "
a = '" . $piece[0] . "';
b = '" . $piece[1] . "';
document.write('<a href=\"mailto:' + a + '@' + b + '\">" . $name . "</a>');
</script>";
return $javaScript;
}
// true if validation fails
$validationFailure = FALSE;
// create the QueryData object
$queryData = new QueryData($queryToModsMap, $recordsPerPage, $connectLibstaff);
foreach ($_REQUEST as $queryElement => $queryValue)
{
if (!isset($facet) && $queryElement === "facet" && $queryValue === "topic")
{
$facet = "topic";
$queryData->setFacet($facet);
}
else if (!isset($facet) && $queryElement === "facet" && $queryValue === "keyword")
{
$facet = "keyword";
$queryData->setFacet($facet);
}
else
{
// check for valid query element
if (isset($queryToModsMap[$queryElement])) {
// string of allowed symbols
// Don't allow <, <, \u003c or >, >, \u003e
$allowedSymbols = preg_quote("\"',.?&:;_+-()[]/", "/");
// Add additional special characters to whitelist
$allowedSymbols .= "\x{e0}";
// check for invalid characters
if ($invalidCount = preg_match_all("/[^a-z0-9 $allowedSymbols]/i", $queryValue, $matches))
{
$queryValue = htmlspecialchars($queryValue);
foreach ($matches[0] as $invalid)
{
$invalid = htmlspecialchars($invalid);
if (!isset($replaced[$invalid]))
{
$queryValue = str_replace("$invalid", "<strong>$invalid</strong>", $queryValue);
$replaced[$invalid] = TRUE;
}
}
$validationFailure = TRUE;
break;
}
// separate the search entries -- keep quoted text together
preg_match_all("/\"[^\"]+\"|[^\" ]+/", $queryValue, $separatedValuesArray);
/*
* // filter out commas
* $queryValuesArray = preg_replace("/[,]/", "", $separatedValuesArray[0]);
*/
// trim results and remove empty values
foreach($separatedValuesArray[0] as $queryValue)
{
$queryValue = trim($queryValue);
if ($queryValue != "")
{
// Add queryValue to the queryData object
$queryData->add($queryElement, $queryValue);
}
}
}
}
}
if ($validationFailure)
{
// invalid characters detected
echo "<h2><strong>Your search contains " . (($invalidCount == 1) ? "an " : "") .
"invalid character" . (($invalidCount == 1) ? "" : "s") . "</strong></h2>";
echo "<hr />";
echo "<h3>The search string \"$queryValue\" contains " . (($invalidCount == 1) ? "an " : "") .
"invalid character" . (($invalidCount == 1) ? "" : "s") . ".<br/><br/>
Please use your browser's <strong>BACK</strong> button and fix the error. Then resubmit your request.</h3>";
}
elseif ($queryData->getQueryString() == "")
{
// no search element found
echo "<h2><strong>Are you looking to search?</strong></h2>";
echo "<hr />";
echo "<h3>We don't have your complete query or are waiting for you to start your search.<br />";
echo "<br />Use our search form above to enter the missing information.</h3>";
}
else
{
// Valid request
// set the start and limit parameters
$queryData->setStart(isSet($_REQUEST['start']) ? $_REQUEST['start'] : 0);
$queryData->setLimit(isSet($_REQUEST['limit']) ? $_REQUEST['limit'] : $recordsPerPage);
// perform the query and queryCount
//echo $queryData->getSqlQueryString() . "\n";
//echo "</br>";
//echo $queryData->getSqlQueryCountString() . "\n";
$result = $connectLibstaff->query($queryData->getSqlQueryString()) or die("Data query error");
$countResult = $connectLibstaff->query($queryData->getSqlQueryCountString()) or die("Count query error");
$count = $countResult->fetch_object();
$numRecords = $count->matchCount;
if ($numRecords == 0)
{
echo "<h2><strong>There are no resulting matches</strong></h2>\n";
echo "<hr />\n";
echo "<h3>There are no items in the database that match your search value(s): " . $queryData->getSearchTerms() .
"<br /><br />Please try again!!!</h3>\n";
}
else
{
echo "<h2>Your search for " . $queryData->getSearchTerms() .
" resulted in <strong>$numRecords</strong> item" .
(($numRecords == 1) ? "" : "s") . ".</h2>\n";
echo "<p class=\"nav\"><a href=\"./search.html\">Run new search?</a> <a class=\"bck\" href=\"./index.html\">Back to Homepage</a></p>";
$start = $queryData->getStart();
$limit = $queryData->getLimit();
// Create links to more items if there are more than $limit items
$prevLink = "";
$nextLink = "";
if ($numRecords > $limit)
{
// create a link to the previous items if there are previous items to display
if ($start > 0)
{
$prevStart = $start - $limit;
$prevGroup = $limit;
if ($prevStart < 0)
{
// This condition should only be hit if the url is altered manually
$prevGroup += $prevStart;
$prevStart = 0;
}
$prevLink = "<a class=\"bck\" href=\"./search.html?{$queryData->getQueryString()}&start=$prevStart&limit=$prevGroup\">" .
"View previous $prevGroup result" . (($prevGroup == 1) ? "" : "s") . "</a> ";
}
// create a link to the next items if there are more items to display
$nextStart = $start + $limit;
if ($nextStart < $numRecords)
{
$remainingRecords = $numRecords - $nextStart;
$nextGroup = ($remainingRecords < $limit) ? $remainingRecords : $limit;
$nextLink = "<a class=\"fwd\" href=\"./search.html?{$queryData->getQueryString()}&start=$nextStart&limit=$limit\">" .
"View next $nextGroup result" . (($nextGroup == 1) ? "" : "s") . "</a>";
}
}
else
{
// Set the max number of items to the number of records if less than $limit
$limit = $numRecords;
}
// display links to more items at top of results page if there are more than $limit items
if ($prevLink != "" || $nextLink != "")
{
?>
<p class="nav">
<?php echo $prevLink.$nextLink; ?>
</p>
<?php
}
// display all summary information about matching item(s)
while ($row = $result->fetch_object())
{
$person_id = $row->person_id;
$person_title = stripslashes($row->jobTitle);
$person_name = html_entity_decode(stripslashes($row->givenName . ' ' . $row->familyName));
$person_dept = stripslashes($row->memberOf);
$person_room = $row->workLocation;
$person_phone = $row->telephone;
$person_email = $row->email;
$person_vita = $row->person_vita;
$person_web = $row->url;
$person_image = $protocol.$server.$path.'/meta/img/photos/'.stripslashes($row->image);
$person_privacy = $row->person_privacy;
$person_libcal_id = $row->person_libcal_id;
// print HTML to page
?>
<ul class="aboutList">
<li class="photo"><a href="./about.html?id=<?php echo $person_id; ?>"><img alt="photo of <?php echo $person_name; ?>" src="<?php echo $person_image; ?>"/></a></li>
<li class="infoContact">
<h3><a href="./about.html?id=<?php echo $person_id; ?>"><?php echo $person_name; ?></a></h3>
<p><span class="about-heading"><strong>Title: </strong></span><?php echo $person_title; ?></p>
<p><span class="about-heading"><strong>Department: </strong></span><?php echo $person_dept; ?></p>
<p><span class="about-heading"><strong>Phone: </strong></span><?php echo $person_phone; ?></p>
<p><span class="about-heading"><strong>Email: </strong></span><?php echo formatEmailLink($person_email); ?></p>
<?php
if (!empty($person_libcal_id)) {
?>
<p>
<span class="about-heading"><strong>Calendar: </strong></span>
<a href="http://calendar.lib.montana.edu/appointment/<?php echo $person_libcal_id; ?>" onclick="javascript:void window.open('http://calendar.lib.montana.edu/appointment/<?php echo $person_libcal_id; ?>','1364572273698','width=820,height=600');return false;">Schedule Appointment</a>
</p>
<?php
}
?>
</li>
<li class="infoLocation">
<p><span class="about-heading"><strong>Room: </strong></span><?php echo $person_room; ?></p>
<?php
if (strlen($person_vita) > 3) {
?>
<p><a class="vita" title="vita of <?php echo $person_name; ?>" href="<?php echo $person_vita; ?>">Vita</a></p>
<?php
}
if(strlen($person_web) > 3) {
?>
<p><a class="homepage" title="homepage of <?php echo $person_name; ?>" href="<?php echo $person_web; ?>">Homepage</a></p>
<?php
}
if($person_privacy == 'n') {
?>
<p><a class="code" title="QR code for <?php echo $person_name; ?>" href="./about.html?id=<?php echo $person_id; ?>">Get QR code</a></p>
<?php
}
?>
</li>
</ul>
<?php
}
// display links to more items at bottom of results page if there are more than $limit items
if ($prevLink != "" || $nextLink != "") {
?>
<p class="nav">
<?php echo $prevLink.$nextLink; ?>
</p>
<?php
}
} // end - if ($numRecords == 0) else
?>
<p class="nav"><a href="./search.html">Run new search?</a> <a class="bck" href="./index.html">Back to Homepage</a></p>
<?php
} // end - else // Valid request
?>
</section>
</div>
</main>
<footer>
<hr class="border-ftr">
<p class="nav center">
<a property="relatedLink" href="https://github.com/msulibrary/linked-people">GitHub</a>
<a property="relatedLink" href="http://journal.code4lib.org/articles/12320">Article</a>
<a property="relatedLink" href="https://www.lib.montana.edu/">Library</a>
</p>
<p class="copyright center">
© <a property="author creator copyrightHolder reviewedBy" rel="author" href="https://www.wikidata.org/wiki/Q15255419">Montana State University (MSU) Library</a> <time property="dateModified lastReviewed" datetime="2017-04-17T18:57:03-07:00" title="published 2017-04-17T18:57:03-07:00">2017</time>
</p>
</footer>
<?php
if ($customScript = (empty($customScript)) ? null : $customScript) {
$counted = count($customScript);
for ($i = 0; $i < $counted; $i++) {
?>
<script type="text/javascript" src="<?php echo $customScript[$i]; ?>"></script>
<?php
}
}
?>
</body>
</html>