-
Notifications
You must be signed in to change notification settings - Fork 7
/
search.php
executable file
·180 lines (148 loc) · 5.93 KB
/
search.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
<?php
/*************************************************************
* THE ADDRESS BOOK : version 1.04d
*
* CHANGE LOG since 1.04 release on 30 May 05 where + sign indicates if this particular file was modified
* 1.04a - Corrected <? to <?php for all instances due to some servers having short_open_tags set to off.
* 1.04b - Corrected 3 more cases of <? which were missed earlier. Only affects index.php
* 1.04c - Corrected mailsend.php syntax error (extraneous open bracket [).
* 1.04d - Corrected Javascript error in mailto.php
* Corrected improper default country select in edit.php
* Removed use of file_get_contents() from options.php and users.php due to pre php4.3 incompatibility
* + Changed call to charset iso-8859-1 from hard code in header to variable to accomodate greek and other non- 8859-1 languages
****************************************************************
* search.php
* Searches address book entries.
*
*************************************************************/
// ** GET CONFIGURATION DATA **
require_once('constants.inc');
require_once(FILE_FUNCTIONS);
require_once(FILE_CLASS_OPTIONS);
session_start();
$username = $_SESSION['username'];
//echo $username;
// ** OPEN CONNECTION TO THE DATABASE **
$db_link = openDatabase($db_hostname, $db_username, $db_password, $db_name);
// ** CHECK FOR LOGIN **
checkForLogin();
// RETRIEVE OPTIONS THAT PERTAIN TO THIS PAGE
$options = new Options();
$options = mysql_fetch_array(mysql_query("SELECT displayAsPopup FROM " . TABLE_OPTIONS . " LIMIT 1", $db_link))
or die(reportScriptError("Unable to retrieve options."));
$options->displayAsPopup = $options['displayAsPopup'];
// PHP code is placed BEFORE sending any HTML information because we want the script to
// stop processing and send another file instead if a single entry is found.
// Because we don't rely on the browser to redirect, this allows pressing 'back' on the
// browser to take us back to the list, and not keep forwarding.
// See if search terms have been passed to this page.
$goTo = $_POST['goTo'];
if (!$goTo AND !$search) {
echo("<P>".$lang['SEARCH_TERMS']);
exit();
}
// goTo functionality
// Search does not work so we'll make it do the same thing as goTo for now.
if ($search) {
$goTo = $search;
}
if ($goTo) {
$gotosql = "SELECT id, CONCAT(lastname,', ',firstname) AS fullname, lastname, firstname
FROM " . TABLE_CONTACT . "
WHERE
CONCAT(firstname,' ', lastname) LIKE '%$goTo%' OR
CONCAT(firstname,' ', middlename,' ', lastname) LIKE '%$goTo%' OR
nickname LIKE '%$goTo%'
ORDER BY fullname";
$r_goto = mysql_query($gotosql, $db_link);
$numGoTo = mysql_num_rows($r_goto);
}
// print results
if ($numGoTo == 1) {
$t_goto = mysql_fetch_array($r_goto);
$contact_id = $t_goto['id'];
if ($options->displayAsPopup == 1) {
$theAddress = FILE_ADDRESS."?id=".$contact_id;
?>
<HTML>
<HEAD>
<TITLE> <?php echo "$lang[TITLE_TAB] - $lang[SEARCH_LBL]" ?></TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $lang['CHARSET']?>">
<LINK REL="stylesheet" HREF="styles.css" TYPE="text/css">
<SCRIPT LANGUAGE="JavaScript">
<!--
window.open('<?php echo($theAddress); ?>',null,'width=600,height=450,scrollbars,resizable,menubar,status'); history.back();
// -->
</SCRIPT>
</HEAD>
<BODY>
<CENTER>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=570>
<TR>
<TD CLASS="headTitle"><?php echo $lang['SEARCH_RESULTS']?></TD>
</TR>
<TR>
<TD CLASS="infoBox">
<TABLE BORDER=0 CELLPADDING=10 CELLSPACING=0 WIDTH=500><TR VALIGN="top"><TD CLASS="data">
One entry found. It will appear in a new window. If no window appears, <A HREF="#" onClick="window.open('<?php echo($theAddress); ?>',addressWindow,'width=600,height=450,scrollbars,resizable,menubar,status'); return false;">click here</A>.
</TD></TR></TABLE>
</TD>
</TR>
</TABLE>
</CENTER>
</BODY>
</HTML>
<?php
}
else {
header("Location: " . FILE_ADDRESS . "?id=$contact_id");
}
exit;
}
?>
<HTML>
<HEAD>
<TITLE> <?php echo "$lang[TITLE_TAB] - $lang[SEARCH_LBL]" ?></TITLE>
<LINK REL="stylesheet" HREF="styles.css" TYPE="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $lang['CHARSET']?>">
</HEAD>
<BODY>
<CENTER>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=570>
<TR>
<TD CLASS="headTitle"><?php echo $lang['SEARCH_LBL'] ?></TD>
</TR>
<TR>
<TD CLASS="infoBox">
<TABLE BORDER=0 CELLPADDING=10 CELLSPACING=0 WIDTH=500><TR VALIGN="top"><TD CLASS="data">
<?php
// print search info
echo("<B>".$lang['SEARCH_MATCH']. " $goTo ".$lang['SEARCH_IN_NAME']."</B>");
// print results in case $numGoTo did not equal 1
if ($numGoTo == 0) {
echo("<P>".$lang['SEARCH_NONE']);
echo("<P><B><A HREF=\"" . FILE_LIST . "\">".$lang['BTN_RETURN']."</A></B>");
}
else {
echo("<P>".$lang['SEARCH_MULTIPLE']."<P>");
while ($t_goto = mysql_fetch_array($r_goto) ) {
$contact_id = $t_goto['id'];
$contact_name = $t_goto['fullname'];
$contact_firstname = $t_goto['firstname'];
$contact_lastname = $t_goto['lastname'];
if (!$contact_firstname) { $contact_name = $contact_lastname; }
if ($options->displayAsPopup == 1) {
$popupLink = " onClick=\"window.open('" . FILE_ADDRESS . "?id=$contact_id','addressWindow','width=600,height=450,scrollbars,resizable,menubar,status'); return false;\"";
}
echo("<BR><A HREF=\"" . FILE_ADDRESS . "?id=$contact_id\"$popupLink>$contact_name</A>\n");
}
echo("<P><B><A HREF=\"" . FILE_LIST. "\">".$lang['BTN_RETURN']."</A></B>");
}
?>
</TD></TR></TABLE>
</TD>
</TR>
</TABLE>
</CENTER>
</BODY>
</HTML>