23 define(
'SEARCH_EXTENDED',1);
25 define(
'SEARCH_NORMAL',2);
27 define(
'SEARCH_STRICT',3);
30 define(
'LOGIC_AND',(-1));
34 define(
'LOGIC_NONE',0);
37 define(
'HIGHLIGHT_ON',1);
39 define(
'HIGHLIGHT_OFF',0);
43 include(
"inc/common.php");
59 header(
"Cache-Control: max-age=600");
62 if(!empty($_GET[
'result'])) {
63 $resultIdentifier = $_GET[
'result'];
67 if(!empty($_POST[
'searchterm'])) {
69 $timeStart = microtime(
true);
71 $searchTerm = $_POST[
'searchterm'];
72 $modifiedTerm = trim($searchTerm);
73 if(!empty($_POST[
'similar'])) {
74 $similar = $_POST[
'similar'];
76 if(strcmp($similar,
'similar')==0) {
79 }
else if (strcmp($similar,
'strict')==0) {
90 if(!empty($_POST[
'logicmode'])) {
91 $logicMode = $_POST[
'logicmode'];
92 if(strcmp($logicMode,
'or')==0) {
95 }
else if (strcmp($logicMode,
'and')==0) {
107 if(!empty($_POST[
'highlight'])) {
108 $highlightMode = $_POST[
'highlight'];
109 if(strcmp($highlightMode,
'yes')==0) {
112 }
else if (strcmp($highlightMode,
'no')==0) {
125 $searchColumns = array(
'name',
'position',
'telephone_number',
'mobile_phone_number',
126 'email',
'name',
'position',
'telephone_number',
'mobile_phone_number',
'email',
127 'sponsor_name',
'street',
'house_number',
'zip_code',
'town',
'country',
128 'website',
'sponsor_hints',
'sponsor_logo',
'status_name',
'last_contact_person',
129 'comments',
'production_facility_name',
'hints',
'co_determination',
'car_name',
130 'category_name',
'file_name',
'event',
'object',
'value',
'produced_part_name',
133 $sponsors =
searchDatabase($searchColumns,$modifiedTerm,$searchMode,$logicMode);
136 if(!empty($sponsors)) {
138 foreach ($sponsors as &$sponsor) {
141 $tmp[] = $sponsor[
'id'];
146 $resultIdentifier = $loggedInUser->storeSearchResult($tmp);
148 $smarty->assign(
'resultIdentifier',$resultIdentifier);
151 if(isset($_GET[
'sort']) && ctype_digit($_GET[
'sort'])) {
152 $columnIdx = $_GET[
'sort'];
153 if(isset($_GET[
'dir']) && ctype_digit($_GET[
'dir'])) {
154 $direction = ($_GET[
'dir'] == 0) ? SORT_ASC : SORT_DESC;
156 kdsort($sponsors, $columnIdx, $direction);
158 $smarty->assign(
'sort', array(
'colIdx' => $columnIdx,
159 'direction' => $_GET[
'dir']));
164 $timeSpent = microtime(
true)-$timeStart;
167 if(!empty($sponsors)) {
168 $successes[] = (count($sponsors)==1?
"Ein Ergebnis":count($sponsors).
" Ergebnisse").
" in ".$timeSpent.
" s";
170 $successes[] =
"Leeres Ergebnis in ".$timeSpent.
" s";
175 $smarty->assign(
'sponsors',$sponsors);
176 $smarty->assign(
'oldTerm',$searchTerm);
177 $smarty->assign(
'searchMode', $searchMode);
178 $smarty->assign(
'logicMode', $logicMode);
179 $smarty->assign(
'highlightMode',$highlightMode);
181 }
else if(isset($resultIdentifier)&&$loggedInUser->isResultAvailable($resultIdentifier)) {
183 $sponsorIds = $loggedInUser->loadResult($resultIdentifier);
184 if(!$sponsorIds==FALSE) {
187 foreach($sponsorIds as $sponsorId) {
191 if(!empty($sponsors)) {
193 foreach ($sponsors as &$sponsor) {
196 $tmp[] = $sponsor[
'id'];
200 if(isset($_GET[
'sort']) && ctype_digit($_GET[
'sort'])) {
201 $columnIdx = $_GET[
'sort'];
202 if(isset($_GET[
'dir']) && ctype_digit($_GET[
'dir'])) {
203 $direction = ($_GET[
'dir'] == 0) ? SORT_ASC : SORT_DESC;
205 kdsort($sponsors, $columnIdx, $direction);
207 $smarty->assign(
'sort', array(
'colIdx' => $columnIdx,
208 'direction' => $_GET[
'dir']));
215 $smarty->assign(
'sponsors',$sponsors);
221 $smarty->assign(
'resultIdentifier',$resultIdentifier);
250 $searchterm = htmlspecialchars($searchterm, ENT_QUOTES);
252 $searchterm = ($findSimilar<>
SEARCH_STRICT?
"*":
"").$mysqli->real_escape_string($searchterm).($findSimilar<>
SEARCH_STRICT?
"*":
"");
254 $searchterm = str_replace(array(
'%',
'_',
'?',
'*'), array(
'\%',
'\_',
'_',
'%'), $searchterm);
255 $numElems = count($columns);
259 foreach ($columns as $column) {
261 $retVal = $retVal.(($i<>1)?
"OR ":
"").
"`".$column.
"` LIKE '".$searchterm.
"'\n";
263 $retVal = $retVal.
"OR `".$column.
"` SOUNDS LIKE '".$searchterm.
"'\n";
293 $searchTerm = preg_replace(
"/\s{1,}/",
" ", $searchTerm);
297 $searchTerms = explode(
" ", preg_replace(
"/\s{1,}/",
" ", strtolower($searchTerm)));
299 $searchTerms = array_unique($searchTerms);
301 for ($i = 0; $i < count($searchTerms); $i++) {
302 $whereClause = $whereClause.
"(".
304 if($i < count($searchTerms)-1) {
305 $whereClause .=
" OR\n";
311 $searchTerms = explode(
" ", preg_replace(
"/\s{1,}/",
" ", strtolower($searchTerm)));
313 $searchTerms = array_unique($searchTerms);
315 for ($i = 0; $i < count($searchTerms); $i++) {
316 $whereClause = $whereClause.
"(".
318 if($i < count($searchTerms)-1) {
319 $whereClause .=
" AND\n";
329 sponsor.sponsor_name,
331 sponsor.house_number,
336 sponsor.sponsor_hints,
337 sponsor.sponsor_logo,
338 sponsor.last_contact_date,
339 sponsor.last_contact_person,
343 FROM '.$db[
'sponsor'].
' AS sponsor LEFT JOIN '.$db[
'status'].
' AS status ON sponsor.status_id = status.status_id
344 LEFT JOIN '.$db[
'contact_person'].
' AS person ON sponsor.sponsor_id = person.sponsor_id
345 LEFT JOIN '.$db[
'sp_production_facility'].
' AS spfc ON sponsor.sponsor_id = spfc.sponsor_id
346 LEFT JOIN '.$db[
'production_facility'].
' AS pfc ON spfc.production_facility_id = pfc.production_facility_id
347 LEFT JOIN '.$db[
'sponsor_car'].
' AS sc ON sc.sponsor_id = sponsor.sponsor_id
348 LEFT JOIN '.$db[
'car'].
' AS car ON sc.car_id = car.car_id
349 LEFT JOIN '.$db[
'category'].
' AS cat ON cat.category_id = sc.category_id
350 LEFT JOIN '.$db[
'sc_attachment'].
' AS att ON att.sponsor_car_id = sc.sponsor_car_id
351 LEFT JOIN '.$db[
'sc_event'].
' AS evt ON evt.sponsor_car_id = sc.sponsor_car_id
352 LEFT JOIN '.$db[
'sc_material_donation'].
' AS mat ON mat.sponsor_car_id = sc.sponsor_car_id
353 LEFT JOIN '.$db[
'sc_financial_donation'].
' AS fin ON fin.sponsor_car_id = sc.sponsor_car_id
354 LEFT JOIN '.$db[
'sc_produced_part'].
' AS prp ON prp.sponsor_car_id = sc.sponsor_car_id
355 WHERE '.$whereClause.
356 'GROUP BY sponsor.sponsor_name
357 ORDER BY sponsor.sponsor_name ASC';
358 $stmt = $mysqli->prepare($qry);
361 $stmt->bind_result($id, $name, $street, $houseNumber, $zipCode, $town, $country, $website, $hints, $sponsorLogo, $lastContactDate, $lastContactPerson, $statusId, $statusName, $hits);
362 $stmt->store_result();
364 while ($stmt->fetch()) {
366 $rows [] = array(
'id' => $id,
369 'houseNumber' => $houseNumber,
370 'zipCode' => $zipCode,
372 'country' => $country,
373 'website' => $website,
375 'sponsorLogo' => $sponsorLogo,
376 'lastContactDateTimestamp' => $lastContactDate,
377 'lastContactPerson' => $lastContactPerson,
378 'statusId' => $statusId,
379 'statusName' => $statusName,
380 'lastChangeDateTimestamp' => $lastChange[
'timestamp'],
381 'lastChangeUserId' => $lastChange[
'userId'],
382 'lastChangeUserName' => $lastChange[
'userName'],
386 return isset($rows) ? $rows :
false;