1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
1 |
<?php
|
2 |
// contacts.php
|
|
3 |
//
|
|
4 |
// SiT (Support Incident Tracker) - Support call tracking system
|
|
1239.1.66
by Paul Heaney
update copyright |
5 |
// Copyright (C) 2010-2014 The Support Incident Tracker Project
|
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
6 |
// Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
|
7 |
//
|
|
8 |
// This software may be used and distributed according to the terms
|
|
9 |
// of the GNU General Public License, incorporated herein by reference.
|
|
10 |
//
|
|
11 |
||
12 |
// Author: Ivan Lucas <ivanlucas[at]users.sourceforge.net>
|
|
13 |
||
762
by Ivan Lucas
Set $permission variable after including core.inc.php to fix Mantis 1632 page security no longer checked. Since we now use constants for permissions we need to include core first so that the constants are defined. (of course) |
14 |
require ('core.php'); |
703.2.26
by Ivan Lucas
Use new permission constants in page headers, Work-in-progress: only done up to perm #33 so far, and menus and other permission checks not even started. |
15 |
$permission = PERM_CONTACT_VIEW; // View Contacts |
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
16 |
require (APPLICATION_LIBPATH . 'functions.inc.php'); |
17 |
// This page requires authentication
|
|
18 |
require (APPLICATION_LIBPATH . 'auth.inc.php'); |
|
19 |
||
20 |
$title = $strBrowseContacts; |
|
21 |
||
22 |
// External variables
|
|
803.1.30
by Ivan Lucas
Filter input parameters better |
23 |
$search_string = clean_dbstring($_REQUEST['search_string']); |
551.1.7
by Ivan Lucas
Show all sites and all contacts in lists when the language being used does not have an alphabet configured. (Mantis 1180) |
24 |
if ($search_string == '') |
25 |
{
|
|
26 |
if (!empty($i18nAlphabet)) |
|
27 |
{
|
|
28 |
$search_string = mb_substr($i18nAlphabet, 0 , 1); |
|
29 |
}
|
|
30 |
else
|
|
31 |
{
|
|
32 |
$search_string = '*'; |
|
33 |
}
|
|
34 |
}
|
|
35 |
||
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
36 |
if ($submit_value == 'go') |
37 |
{
|
|
245
by Paul Heaney
* Switch from mysql_fetch_array to mysql_fetch_object |
38 |
// build SQL
|
39 |
$sql = "SELECT * FROM `{$dbContacts}` "; |
|
281.6.9
by Ivan Lucas
Fix typo |
40 |
$search_string_len = mb_strlen(utf8_decode($search_string)); |
245
by Paul Heaney
* Switch from mysql_fetch_array to mysql_fetch_object |
41 |
if ($search_string != '*') |
42 |
{
|
|
43 |
$sql .= "WHERE "; |
|
44 |
if ($search_string_len <= 6) $sql .= "id=('{$search_string}') OR "; |
|
45 |
if ($search_string_len <= 2) |
|
46 |
{
|
|
47 |
$sql .= "SUBSTRING(surname,1,{$search_string_len})=('$search_string') "; |
|
48 |
}
|
|
49 |
else
|
|
50 |
{
|
|
1239.1.24
by Paul Heaney
Don't show data protection fields on contact browse (Mantis 1253) |
51 |
$sql .= "surname LIKE '%{$search_string}%' OR forenames LIKE '%{$search_string}%' OR "; |
245
by Paul Heaney
* Switch from mysql_fetch_array to mysql_fetch_object |
52 |
$sql .= "CONCAT(forenames,' ',surname) LIKE '%{$search_string}%'"; |
53 |
}
|
|
54 |
}
|
|
55 |
$sql .= " ORDER BY surname ASC, forenames ASC"; |
|
56 |
||
57 |
// execute query
|
|
58 |
$result = mysql_query($sql); |
|
59 |
if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING); |
|
60 |
||
61 |
if (mysql_num_rows($result) == 1) |
|
62 |
{
|
|
63 |
//go straight to the contact
|
|
64 |
$obj = mysql_fetch_object($result); |
|
65 |
$url = "contact_details.php?id={$obj->id}"; |
|
66 |
header("Location: {$url}"); |
|
67 |
}
|
|
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
68 |
}
|
1022
by Paul Heaney
Switch to using scriptaculous for AutoComplete rather than |
69 |
|
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
70 |
include (APPLICATION_INCPATH . 'htmlheader.inc.php'); |
71 |
||
72 |
echo "<h2>".icon('contact', 32)." "; |
|
189
by Paul Heaney
use title variable rather redefine |
73 |
echo "{$title}</h2>"; |
791
by Ivan Lucas
Plugin contexts to follow convention in Mantis 1681, see http://sitracker.org/wiki/Talk:Creating_Plugins |
74 |
plugin_do('contacts'); |
737
by Carsten Jensen
some good night reading for ericthefish: styling tables for centering, submitbuttons as formbuttons, back/return |
75 |
echo "<table summary='alphamenu' class='maintable'>"; |
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
76 |
echo "<tr>"; |
77 |
echo "<td align='center'>"; |
|
78 |
echo "<form action='{$_SERVER['PHP_SELF']}' method='get'>"; |
|
79 |
echo "<p>{$strBrowseContacts}: "; |
|
80 |
echo "<input type='text' id='search_string' style='width: 300px;' name='search_string' />"; |
|
81 |
echo "<input name='submit' type='submit' value=\"{$strGo}\" /></p>"; |
|
1022
by Paul Heaney
Switch to using scriptaculous for AutoComplete rather than |
82 |
echo "<div id='search_string_choices' class='autocomplete'></div>"; |
83 |
echo autocomplete('search_string', 'contact', 'search_string_choices'); |
|
84 |
||
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
85 |
echo "</form>\n"; |
245
by Paul Heaney
* Switch from mysql_fetch_array to mysql_fetch_object |
86 |
if ($displayinactive == "true") |
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
87 |
{
|
1239.1.24
by Paul Heaney
Don't show data protection fields on contact browse (Mantis 1253) |
88 |
echo "<a href='{$_SERVER['PHP_SELF']}?displayinactive=false"; |
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
89 |
if (!empty($search_string)) echo "&search_string={$search_string}"; |
90 |
echo "'>{$strShowActiveOnly}</a>"; |
|
91 |
$inactivestring="displayinactive=true"; |
|
92 |
}
|
|
93 |
else
|
|
94 |
{
|
|
1239.1.24
by Paul Heaney
Don't show data protection fields on contact browse (Mantis 1253) |
95 |
echo "<a href='{$_SERVER['PHP_SELF']}?displayinactive=true"; |
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
96 |
if (!empty($search_string)) echo "&search_string={$search_string}"; |
97 |
echo "'>{$strShowAll}</a>"; |
|
98 |
$inactivestring="displayinactive=false"; |
|
99 |
}
|
|
551.1.5
by Ivan Lucas
Disable alpha index menu for sites and contacts pages when the alphabet is not set in the language file. $i18nalpha. Not all languages have an alphabet that is suitable for indexing results in the way that English does. See Mantis 1180 and 912. |
100 |
echo "</td></tr><tr><td class='alphamenu'>"; |
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
101 |
|
551.1.5
by Ivan Lucas
Disable alpha index menu for sites and contacts pages when the alphabet is not set in the language file. $i18nalpha. Not all languages have an alphabet that is suitable for indexing results in the way that English does. See Mantis 1180 and 912. |
102 |
echo "<a href='contact_new.php'>{$strNew}</a>"; |
103 |
echo alpha_index("{$_SERVER['PHP_SELF']}?search_string=", $inactivestring); |
|
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
104 |
echo "</td></tr></table>"; |
105 |
||
106 |
if (empty($search_string)) |
|
107 |
{
|
|
108 |
echo user_alert(sprintf($strFieldMustNotBeBlank, "'{$strSearch}'"), E_USER_ERROR); |
|
109 |
}
|
|
110 |
else
|
|
111 |
{
|
|
112 |
// perform search
|
|
113 |
// check input
|
|
114 |
if ($search_string == '') |
|
115 |
{
|
|
116 |
$errors = 1; |
|
117 |
echo user_alert(sprintf($strFieldMustNotBeBlank, "'{$strSearch}'"), E_USER_ERROR); |
|
118 |
}
|
|
119 |
// search for criteria
|
|
120 |
if ($errors == 0) |
|
121 |
{
|
|
122 |
if ($submit_value != 'go') |
|
123 |
{
|
|
124 |
// Don't need to do this again, already done above, us the results of that
|
|
125 |
// build SQL
|
|
126 |
$sql = "SELECT c.* FROM `{$dbContacts}` AS c, `{$dbSites}` AS s "; |
|
127 |
$sql .= "WHERE c.siteid = s.id "; |
|
281.6.9
by Ivan Lucas
Fix typo |
128 |
$search_string_len=mb_strlen(utf8_decode($search_string)); |
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
129 |
if ($search_string != '*') |
130 |
{
|
|
131 |
$sql .= " AND ("; |
|
245
by Paul Heaney
* Switch from mysql_fetch_array to mysql_fetch_object |
132 |
if ($search_string_len <= 6) $sql .= "c.id=('{$search_string}') OR "; |
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
133 |
|
134 |
if ($search_string_len <= 2) |
|
135 |
{
|
|
136 |
// $sql .= "SUBSTRING(c.surname,1,$search_string_len)=('$search_string') ";
|
|
137 |
$sql .= "c.surname LIKE '{$search_string}%' "; |
|
138 |
}
|
|
139 |
else
|
|
140 |
{
|
|
245
by Paul Heaney
* Switch from mysql_fetch_array to mysql_fetch_object |
141 |
$sql .= "c.surname LIKE '%$search_string%' OR c.forenames LIKE '%{$search_string}%' OR "; |
142 |
$sql .= "CONCAT(c.forenames,' ',c.surname) LIKE '%{$search_string}%'"; |
|
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
143 |
}
|
144 |
$sql .= " ) "; |
|
145 |
}
|
|
277
by Carsten Jensen
fixing bug 443 - using new instead of add |
146 |
|
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
147 |
if ($displayinactive == "false") |
148 |
{
|
|
149 |
$sql .= " AND c.active = 'true' AND s.active = 'true'"; |
|
150 |
}
|
|
151 |
$sql .= " ORDER BY surname ASC"; |
|
152 |
$result = mysql_query($sql); |
|
153 |
debug_log($sql); |
|
154 |
if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING); |
|
155 |
}
|
|
156 |
||
551.1.7
by Ivan Lucas
Show all sites and all contacts in lists when the language being used does not have an alphabet configured. (Mantis 1180) |
157 |
if ($search_string == '*') |
551.1.6
by Ivan Lucas
Show all contacts instead of those beginning with 'A' when the language in use is configured without an alphabet ($i18nalphabet). |
158 |
{
|
159 |
$search_term = $strAll; |
|
160 |
}
|
|
161 |
else
|
|
162 |
{
|
|
163 |
$search_term = $search_string; |
|
164 |
}
|
|
165 |
||
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
166 |
if (mysql_num_rows($result) == 0) |
167 |
{
|
|
703.2.11
by Ivan Lucas
Standardise the look of messages that we have no records to display by using user_alert() |
168 |
if (empty($search_string)) echo user_alert($strNoRecords, E_USER_NOTICE); |
893.1.3
by Paul Heaney
fix wrongly ordered () |
169 |
else user_alert(sprintf($strSorryNoRecordsMatchingX, "<em>{$search_term}</em>"), E_USER_NOTICE); |
703.2.11
by Ivan Lucas
Standardise the look of messages that we have no records to display by using user_alert() |
170 |
}
|
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
171 |
else
|
172 |
{
|
|
173 |
||
551.1.6
by Ivan Lucas
Show all contacts instead of those beginning with 'A' when the language in use is configured without an alphabet ($i18nalphabet). |
174 |
echo "<p align='center'>".sprintf($strDisplayingXcontactMatchingY, mysql_num_rows($result), "<em>{$search_term}</em>")."</p>"; |
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
175 |
|
736
by Carsten Jensen
fixing styles, puttin into css |
176 |
echo "<table class='maintable'> |
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
177 |
<tr>
|
178 |
<th>{$strName}</th> |
|
179 |
<th>{$strSite}</th> |
|
180 |
<th>{$strEmail}</th> |
|
181 |
<th>{$strTelephone}</th> |
|
182 |
<th>{$strFax}</th> |
|
183 |
<th>{$strAction}</th> |
|
184 |
</tr>"; |
|
185 |
$shade = 'shade1'; |
|
245
by Paul Heaney
* Switch from mysql_fetch_array to mysql_fetch_object |
186 |
while ($results = mysql_fetch_object($result)) |
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
187 |
{
|
245
by Paul Heaney
* Switch from mysql_fetch_array to mysql_fetch_object |
188 |
if ($results->active == 'false') $shade = 'expired'; |
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
189 |
|
190 |
echo "<tr class='{$shade}'>"; |
|
245
by Paul Heaney
* Switch from mysql_fetch_array to mysql_fetch_object |
191 |
echo "<td><a href='contact_details.php?id={$results->id}'>{$results->surname}, {$results->forenames}</a></td>"; |
192 |
echo "<td><a href='site_details.php?id={$results->siteid}'>".site_name($results->siteid)."</a></td>"; |
|
1239.1.24
by Paul Heaney
Don't show data protection fields on contact browse (Mantis 1253) |
193 |
echo "<td>"; |
194 |
if ($results->dataprotection_email == 'Yes') echo "<em>{$strNoEmail}</em>"; |
|
195 |
else echo $results->email; |
|
196 |
echo "</td>"; |
|
197 |
echo "<td>"; |
|
198 |
if ($results->dataprotection_phone == 'Yes') echo "<em>{$strNoCalls}</em>"; |
|
199 |
else
|
|
200 |
{
|
|
201 |
if ($results->phone == '') echo "<em>{$strNone}</em>"; |
|
202 |
else echo $results->phone; |
|
203 |
}
|
|
245
by Paul Heaney
* Switch from mysql_fetch_array to mysql_fetch_object |
204 |
echo "</td>"; |
205 |
echo "<td>"; |
|
206 |
if ($results->fax == '') echo "<em>{$strNone}</em>"; |
|
207 |
else echo $results->fax; |
|
208 |
echo "</td>"; |
|
622.1.13
by Ivan Lucas
use html_action_links() for links |
209 |
echo "<td>"; |
210 |
$operations = array(); |
|
211 |
$operations[$strNewIncident] = "incident_new.php?action=findcontact&contactid={$results->id}"; |
|
212 |
$operations[$strEditContact] = "contact_edit.php?action=edit&contact={$results->id}"; |
|
213 |
echo html_action_links($operations); |
|
1
by Ivan Lucas
Initial commit (ported from sourceforge svn trunk) |
214 |
echo "</td></tr>"; |
215 |
||
216 |
// invert shade
|
|
217 |
if ($shade == 'shade1') $shade = 'shade2'; |
|
218 |
else $shade = 'shade1'; |
|
219 |
}
|
|
220 |
echo "</table>"; |
|
221 |
}
|
|
222 |
}
|
|
223 |
}
|
|
224 |
include (APPLICATION_INCPATH . 'htmlfooter.inc.php'); |
|
225 |
?>
|