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
|
<?php
class Pbs_Search{
private $searchTerm = '';
private $searcha;
private $searchb;
private $module;
public function searchForm(){
$str = "<form style='float:left;' action='/user/".$this->module."/search'>
<input type='text' id='search' name='search' ".(($this->searchTerm != '')?'value="'.$this->searchTerm.'"':'').">
<button type='submit' class='searchbutton' value='search'> Search</button>";
$highlight = array();
if($this->searchTerm != ''){
$str .= "<a href='/user/client/'><img src='/media/img/delete.png' alt='Delete Client'/></a>
<script type='text/javascript' src='/media/js/jquery.highlight-3.js'></script>";
foreach($this->getSearchTerms() as $term){
$highlight[] = "$('table').highlight('".$term."');";
}
}
$str .= "<script>
$(document).ready(function(){";
$str .= implode("\n",$highlight);
$str .= "$('#search')
.focus(function() {
$('table th .code').show();
}).focusout(function() {
$('table th .code').hide();
});
$('table th').click(function(){
$('#search').val($('#search').val()+' '+$(this).find('.code').text()+':');
});";
$str .= "});
</script>";
$str .= "</form>";
return $str;
}
public function setModule($m){
$this->module = $m;
}
public function setSearchTerm($search){
$this->searchTerm = trim($search);
$parts = explode(" ",$this->searchTerm);
foreach($parts as $this->searchTerm){
if(stristr($this->searchTerm,":") && ctype_alpha(substr($this->searchTerm,0,strpos($this->searchTerm,":")))){
$key = substr($this->searchTerm,0,strpos($this->searchTerm,":"));
$value = substr($this->searchTerm,strpos($this->searchTerm,":")+1);
$searcha[$key] = $value;
}
else{
$searchb[] = $search;
}
}
$this->searcha = $searcha;
$this->searchb = $searchb;
}
public function getSearchTerm(){
return $this->searchTerm;
}
public function getSearchTerms(){
$beta = $this->searcha;
foreach($this->searchb as $b)
$beta[] = $b;
return $beta;
}
public function search($array){
foreach($array as $counter => $cig){
if(is_object($cig)){
$cig = $cig->toArray();
}
foreach($cig as $k => $v){
if(count($this->searcha) > 0){
foreach($this->searcha as $sk => $sv){
if($k == $sk){
if(stristr($v,$sv)){
$com1[] = $counter;
}
}
}
}
if(count($searchb) >= 0){
foreach($this->searchb as $sk => $sv){
$comm = stristr($v,$sv);
if($comm != false){
$com2[] = $counter;
break;
}
}
}
}
}
if (count($this->searcha) == 0){
$data = $com2;
}
if (count($this->searchb) == 0){
$data = $com1;
}
if (count($this->searcha) > 0 && count($this->searchb) > 0){
$data = array_intersect($com1,$com2);
}
$data = array_unique($data);
foreach( $data as $c)
$ges[] = $array[$c];
return $ges;
}
}
|