/
search_lenses.php
103 lines (72 loc) · 2.55 KB
/
search_lenses.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
<?php
//ini_set('display_errors', 1);
//ini_set('log_errors', 1);
//ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
//error_reporting(E_ALL);
//ini_set('html_errors', 'On');
//defined('_JEXEC') or die();
//require_once( JPATH_ROOT.DS."utilities/database.php" );
require_once("utilities/mysqliSingleton.php" );
require_once("utilities/phpClasses/RxObject.php" );
require_once("utilities/phpClasses/RxHelper.php" );
//echo "wazzup.";
$q = strtolower($_REQUEST["term"]);
$which = $_REQUEST["which"];
$which = "scl";
// a flag to eliminate bifocals and hybrid lenses (for when doing autocomplete for power suggestions)
$noSpecial = $_REQUEST["noSpecial"];
if (!isset($noSpecial)) $noSpecial = 0;
//only looks for rx's - does not do database search
$onlyRx = $_REQUEST["onlyRx"];
if (!isset($onlyRx)) $onlyRx = 0;
//kind of the opposite - only looks for lenses - does not look for powers
$powers = $_REQUEST["powers"];
if (!isset($powers)) $powers = 0;
//$dataBase = databaseObj();
$return = array();
//check if the string is a number or a +/- sign
$tempStr = preg_replace( '/\s+/', '', $q );
$isNumber = ( preg_match('/^[+-.\d]/', $tempStr) );
if ($isNumber == 1 && $which == "scl" && $powers != 0) {
$rxObj = rxStringBreaker($q);
$rxString = $rxObj->prettyString();
$mrRow['id'] = $rxString ;
$mrRow['label'] = $rxString . " (refraction)";
$mrRow['type'] = "mr";
$mrRow['rx'] = $rxString;
$pwrRow['id'] = $rxString ;
$pwrRow['label'] = $rxString . " (CL power)";
$pwrRow['type'] = "power";
$pwrRow['rx'] = $rxString;
array_push($return, $mrRow);
array_push($return, $pwrRow);
}
if ($which == "scl" && $onlyRx != 1) {
//break all the words into a single array
$phrase_array=explode(" ", $q);
foreach ($phrase_array as $value){
$name[] = " pn_name LIKE '%$value%' ";
$alias[] = " pn_aliases LIKE '%$value%' ";
$company[] = " pn_comp_name LIKE '%$value%' ";
}
$nameString = implode(" AND ", $name);
$aliasString = implode(" AND ", $alias);
$companyString = implode(" AND ", $company);
$where[]= " ( ($nameString) OR ($aliasString) OR ($companyString) ) ";
$where = implode(" AND ", $where);
$sql = "SELECT pn_tid as id, pn_name as label, '$which' as type
FROM pn_lenses
LEFT JOIN pn_lenses_companies ON pn_comp_tid = pn_comp_id
WHERE
$where
ORDER BY pn_name";
//echo($sql);
//$db = databaseObj();
//$db->setQuery($sql);
$mysqli = DBAccess::getConnection();
$result = $mysqli->selectQuery($sql);
while($row = $result->fetch_assoc() ) {
array_push($return, $row);
}
}
echo json_encode( $return);