|
|
@@ -827,31 +827,23 @@ jQuery('#typeahead-{$fName}').typeahead({
|
|
|
$query = trim($query);
|
|
|
$sqlWhereAdd = "";
|
|
|
if (!empty($query)) {
|
|
|
- $qArr = array();
|
|
|
- $queryArr = explode(' ', $query);
|
|
|
- foreach ($queryArr as $q) {
|
|
|
- $q = trim($q);
|
|
|
- if (!empty($q)) {
|
|
|
- $qArr[] = $q;
|
|
|
- }
|
|
|
- }
|
|
|
+ Lib::loadClass('SqlQueryWhereBuilder');
|
|
|
+ $queryWhereBuilder = new SqlQueryWhereBuilder();
|
|
|
+ $qArr = $queryWhereBuilder->splitQueryToWords($query);
|
|
|
DBG::log(['msg'=>"qArr", $qArr]);
|
|
|
-
|
|
|
if (!empty($qArr)) {
|
|
|
$sqlWhereAnd = array();
|
|
|
foreach ($qArr as $q) {
|
|
|
- $dbQ = $db->_($q);
|
|
|
- if (is_numeric($dbQ)) {
|
|
|
- $dbQ = "{$dbQ}%";
|
|
|
- } else {
|
|
|
- $dbQ = "%{$dbQ}%";
|
|
|
- }
|
|
|
+ $sqlSearchWord = DB::getPDO()->quote(
|
|
|
+ (is_numeric($q)) ? "{$q}%" : "%{$q}%",
|
|
|
+ PDO::PARAM_STR
|
|
|
+ );
|
|
|
$sqlWhereOr = array();
|
|
|
foreach ($this->param_out->alias as $fldID => $fldName) {
|
|
|
if (false === strpos($this->param_out->format, "{{$fldName}}")) continue;
|
|
|
$tblInfo = V::get($fldID, null, $_SESSION['Typespecial_Cache']['sqlTablesInfo']);
|
|
|
if ($tblInfo) {
|
|
|
- $sqlWhereOr[] = "`t_{$tblInfo->tbl_id}`.`{$fldName}` like '{$dbQ}'";
|
|
|
+ $sqlWhereOr[] = "`t_{$tblInfo->tbl_id}`.`{$fldName}` like {$sqlSearchWord}";
|
|
|
}
|
|
|
}
|
|
|
if (!empty($sqlWhereOr)) {
|
|
|
@@ -863,10 +855,13 @@ jQuery('#typeahead-{$fName}').typeahead({
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ DBG::log(['msg'=>"this", $this]);
|
|
|
+ // TODO: for all tables filter rows by acl groups
|
|
|
+ // 'tblAliasList' => [
|
|
|
+ // 4095 => 'ADMIN_USERS',
|
|
|
+ // ),
|
|
|
$sqlLimit = V::get('limit', 0, $this->sqlQuery, 'int');
|
|
|
- if ($sqlLimit <= 0) {
|
|
|
- $sqlLimit = 20;
|
|
|
- }
|
|
|
+ $sqlLimit = ($sqlLimit > 0) ? $sqlLimit : 20;
|
|
|
|
|
|
$histRows = array();
|
|
|
{
|
|
|
@@ -912,17 +907,16 @@ jQuery('#typeahead-{$fName}').typeahead({
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- $sql = "select " . implode("\n\t\t,", $this->sqlQuery->select) . "
|
|
|
+ $rawRows = DB::getPDO()->fetchAll("
|
|
|
+ select " . implode("\n\t\t,", $this->sqlQuery->select) . "
|
|
|
from " . implode(", ", $this->sqlQuery->from) . "
|
|
|
where {$this->sqlQuery->where}
|
|
|
{$sqlWhereAdd}
|
|
|
limit {$sqlLimit}
|
|
|
- ";
|
|
|
- DBG::log($sql, 'sql');
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
+ ");
|
|
|
+ foreach ($rawRows as $r) {
|
|
|
$retID = V::get("f_{$this->param_out->retID}", '', $r);
|
|
|
- $rows[$retID] = $r;
|
|
|
+ $rows[$retID] = (object)$r;
|
|
|
}
|
|
|
if (!empty($histRows)) {
|
|
|
$sordedRows = array();
|
|
|
@@ -1215,13 +1209,13 @@ if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:au
|
|
|
}
|
|
|
|
|
|
private function saveCache() {
|
|
|
-if(V::get('DBG_TS', 0, $_GET) > 3){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial_Cache (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($_SESSION['Typespecial_Cache']);echo'</pre>';}
|
|
|
+ if(V::get('DBG_TS', 0, $_GET) > 3){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial_Cache (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($_SESSION['Typespecial_Cache']);echo'</pre>';}
|
|
|
$typeSpecialID = $_SESSION['Typespecial_Cache']['map'][$this->fldID];
|
|
|
$_SESSION['Typespecial_Cache'][$typeSpecialID] = array('param_out'=>$this->param_out, 'sqlQuery'=>$this->sqlQuery, 'tblAliasList'=>$this->tblAliasList);
|
|
|
}
|
|
|
|
|
|
public static function getInstance($fieldID, $colName) {
|
|
|
- if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$fieldID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($colName);echo'</pre>';}
|
|
|
+ DBG::log("Typespecial::getInstance({$fieldID}, {$colName})");
|
|
|
if (!empty($colName)) {
|
|
|
Lib::loadClass('Config');
|
|
|
$LIB_CLASS_NAME_PREFIX = Config::get('LIB_CLASS_NAME_PREFIX');
|
|
|
@@ -1237,9 +1231,8 @@ if(V::get('DBG_TS', 0, $_GET) > 3){echo'<pre style="max-height:200px;overflow:au
|
|
|
}
|
|
|
|
|
|
Lib::loadClass('TypespecialVariable');
|
|
|
- if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial2('.$fieldID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($colName);echo'</pre>';}
|
|
|
$typeSpecial = TypespecialVariable::getInstance($fieldID, $colName);
|
|
|
- if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$fieldID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'</pre>';}
|
|
|
+ DBG::log($typeSpecial, 'array', "TypespecialVariable::getInstance({$fieldID}, {$colName})");
|
|
|
if ($typeSpecial) {
|
|
|
return $typeSpecial;
|
|
|
}
|