Skip to content
Snippets Groups Projects
Commit 133da98d authored by colemanw's avatar colemanw
Browse files

Move all escaping from Ajax callback to api CRM-12765

parent dd64a29c
No related branches found
No related tags found
No related merge requests found
......@@ -44,17 +44,22 @@ class CRM_Contact_Page_AJAX {
$params = array('version' => 3, 'check_permissions' => TRUE);
if ($context = CRM_Utils_Array::value('context', $_GET)) {
$params['context'] = CRM_Utils_Type::escape($_GET['context'], 'String');
}
if (!empty($_GET['s'])) {
$params['name'] = $_GET['s'];
// String params
// FIXME: param keys don't match input keys, using this array to translate
$whitelist = array(
's' => 'name',
'fieldName' => 'field_name',
'tableName' => 'table_name',
'context' => 'context',
);
foreach ($whitelist as $key => $param) {
if (!empty($_GET[$key])) {
$params[$param] = $_GET[$key];
}
}
//CRM-10687: Allow quicksearch by multiple fields
if (!empty($_GET['fieldName'])) {
$params['field_name'] = $_GET['fieldName'];
if (!empty($params['field_name'])) {
if ($params['field_name'] == 'phone_numeric') {
$params['name'] = preg_replace('/[^\d]/', '', $params['name']);
}
......@@ -63,39 +68,19 @@ class CRM_Contact_Page_AJAX {
}
}
if (!empty($_GET['tableName'])) {
$params['table_name'] = $_GET['tableName'];
}
$params['limit'] = 10;
if (CRM_Utils_Array::value('limit', $_GET)) {
$params['limit'] = CRM_Utils_Type::escape($_GET['limit'], 'Positive');
}
$orgId = $employee_id = $cid = $id = $context = $rel = NULL;
$params['org'] = CRM_Utils_Array::value('org', $_GET);
if (CRM_Utils_Array::value('id', $_GET)) {
$params['orgId'] = CRM_Utils_Type::escape($_GET['id'], 'Positive');
}
if (CRM_Utils_Array::value('employee_id', $_GET)) {
$params['employee_id'] = CRM_Utils_Type::escape($_GET['employee_id'], 'Positive');
}
if (CRM_Utils_Array::value('cid', $_GET)) {
$params['cid'] = CRM_Utils_Type::escape($_GET['cid'], 'Positive');
}
if (CRM_Utils_Array::value('id', $_GET)) {
$params['id'] = CRM_Utils_Type::escape($_GET['id'], 'Positive');
}
if (isset($_GET['rel'])) {
$params['rel'] = $_GET['rel'];
}
if (CRM_Utils_Array::value('cmsuser', $_GET)) {
$params['cmsuser'] = CRM_Utils_Type::escape($_GET['cmsuser'], 'Boolean');
// Numeric params
$whitelist = array(
'limit',
'org',
'employee_id',
'cid',
'id',
'cmsuser',
);
foreach ($whitelist as $key) {
if (!empty($_GET[$key]) && is_numeric($_GET[$key])) {
$params[$key] = $_GET[$key];
}
}
$result = civicrm_api('Contact', 'getquick', $params);
......
......@@ -604,7 +604,7 @@ function civicrm_api3_contact_getquick($params) {
if ($value != 'id') {
$suffix = 'cc';
if (!empty($params['field_name']) && $params['field_name'] == 'value') {
$suffix = CRM_Utils_Array::value('table_name', $params, 'cc');
$suffix = CRM_Utils_String::munge(CRM_Utils_Array::value('table_name', $params, 'cc'));
}
$actualSelectElements[] = $select[] = $suffix . '.' . $value;
}
......@@ -626,7 +626,8 @@ function civicrm_api3_contact_getquick($params) {
$selectAliases = ", $selectAliases";
}
$from = implode(' ', $from);
$limit = CRM_Utils_Array::value('limit', $params, 10);
$limit = (int) CRM_Utils_Array::value('limit', $params);
$limit = $limit > 0 ? $limit : 10;
// add acl clause here
list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause('cc');
......@@ -643,7 +644,7 @@ function civicrm_api3_contact_getquick($params) {
$currEmpDetails = array();
if (CRM_Utils_Array::value('employee_id', $params)) {
if ($currentEmployer = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
CRM_Utils_Array::value('employee_id', $params),
(int) $params['employee_id'],
'employer_id'
)) {
if ($config->includeWildCardInName) {
......@@ -768,8 +769,8 @@ LIMIT 0, {$limit}
// send query to hook to be modified if needed
CRM_Utils_Hook::contactListQuery($query,
$name,
CRM_Utils_Array::value('context', $params),
CRM_Utils_Array::value('id', $params)
empty($params['context']) ? NULL : CRM_Utils_Type::escape($params['context'], 'String'),
empty($params['id']) ? NULL : $params['id']
);
$dao = CRM_Core_DAO::executeQuery($query);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment