public static function search($post) { if (isempty($post['formList'])) { return FALSE; } // Save the post for later use (like pagination pages) sessionSet('searchPOST', $post); if (!isempty($post['startDate']) && !isempty($post['endDate'])) { $date = TRUE; // @tODO build where clause for date here } else { $date = FALSE; } // build query for idno searches if ($post['fieldList'] == "idno" && preg_match('/^\\\\"(.+?)\\\\"/', trim($post['query']), $matches)) { $queryString = sprintf("LOWER(`idno`)='%s'", strtolower($matches[1])); } else { if ($post['fieldList'] == "idno" && preg_match('/^(.+?)\\*$/', trim($post['query']), $matches)) { $queryString = sprintf("LOWER(`idno`) LIKE '%s%%'", strtolower($matches[1])); } else { if ($post['fieldList'] == "idno" && preg_match('/^\\*(.+?)$/', trim($post['query']), $matches)) { $queryString = sprintf("LOWER(`idno`) LIKE '%%%s'", strtolower($matches[1])); } else { $queryString = sprintf("LOWER(`idno`) LIKE '%%%s%%'", strtolower($post['query'])); } } } // if idno search, build mysql here and search if ($post['fieldList'] == "idno" && $date === TRUE) { $sql = sprintf("SELECT * FROM `objects` WHERE `idno` LIKE '%%%s%%' AND `formID`='%s' AND `createTime` >= '%s' AND `createTime` <= '%s' ORDER BY LENGTH(idno), `idno`", $post['query'], $post['formList'], strtotime($post['startDate']), strtotime($post['endDate'])); $objects = objects::getObjectsForSQL($sql); } else { if ($post['fieldList'] == "idno") { $sql = sprintf("SELECT * FROM `objects` WHERE %s AND `formID`='%s' ORDER BY LENGTH(idno), `idno`", $queryString, $post['formList']); $objects = objects::getObjectsForSQL($sql); } else { if ($date === TRUE) { $sql = sprintf("SELECT * FROM `objects` WHERE AND `formID`='%s' AND `createTime` >= '%s' AND `createTime` <= '%s' ORDER BY LENGTH(idno), `idno`", $post['formList'], strtotime($post['startDate']), strtotime($post['endDate'])); $objects = objects::getObjectsForSQL($sql); } else { $objects = objects::getAllObjectsForForm($post['formList'], "idno", TRUE); } } } $results = array(); foreach ($objects as $object) { // check that the item is in the date range, if a date range is specified. // if ($date === TRUE && ($object['createTime'] < strtotime($post['startDate']) || $object['createTime'] > strtotime($post['endDate']))) { // continue; // } $found = FALSE; if (!isempty($post['query'])) { if ($post['fieldList'] == "idno") { $found = TRUE; } else { if (isset($object['data'][$post['fieldList']]) && stripos($object['data'][$post['fieldList']], $post['query']) !== FALSE) { $found = TRUE; } } } else { if (is_empty($post['query'])) { $found = TRUE; } } if ($found === TRUE) { $results[$object['ID']] = $object; } } return $results; }