$excludeCaseIds = explode(',', $excludeIdStr);
}
$unclosedCases = CRM_Case_BAO_Case::getUnclosedCases($params, $excludeCaseIds);
-
+ $results = array();
foreach ($unclosedCases as $caseId => $details) {
- echo $details['sort_name'] . ' (' . $details['case_type'] . ': ' . $details['case_subject'] . ') ' . "|$caseId|" . $details['contact_id'] . '|' . $details['case_type'] . '|' . $details['sort_name'] . "\n";
+ $results["$caseId|" . $details['contact_id'] . '|' . $details['case_type'] . '|' . $details['sort_name']] = $details['sort_name'] . ' (' . $details['case_type'] . ': ' . $details['case_subject'] . ')';
}
-
- CRM_Utils_System::civiExit();
+ CRM_Core_Page_AJAX::autocompleteResults($results);
}
function processCaseTags() {
}
$result = civicrm_api('Contact', 'getquick', $params);
- if (empty($result['is_error']) && !empty($result['values'])) {
- foreach ($result['values'] as $key => $val) {
- echo "{$val['data']}|{$val['id']}\n";
- }
- }
- CRM_Utils_System::civiExit();
+ CRM_Core_Page_AJAX::autocompleteResults(CRM_Utils_Array::value('values', $result), 'data');
}
static function contactReference() {
$fldValues = array();
CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $cf, $returnProperties);
if (!$cf['id'] || !$cf['is_active'] || $cf['data_type'] != 'ContactReference') {
- echo "$name|error\n";
- CRM_Utils_System::civiExit();
+ CRM_Core_Page_AJAX::autocompleteResults(array('error' => $name));
}
if ($cf['filter']) {
if (!empty($action) &&
!in_array($action, array('get', 'lookup'))
) {
- echo "$name|error\n";
- CRM_Utils_System::civiExit();
+ CRM_Core_Page_AJAX::autocompleteResults(array('error' => $name));
}
}
$contact = civicrm_api('Contact', 'Get', $params);
if (!empty($contact['is_error'])) {
- echo "$name|error\n";
- CRM_Utils_System::civiExit();
+ CRM_Core_Page_AJAX::autocompleteResults(array('error' => $name));
}
- $contactList = '';
+ $contactList = array();
foreach ($contact['values'] as $value) {
$view = array();
foreach ($return as $fld) {
$view[] = $value[$fld];
}
}
- echo $contactList = implode(' :: ', $view) . "|" . $value['id'] . "\n";
+ $contactList[$value['id']] = implode(' :: ', $view);
}
if (!$contactList) {
- echo "$name|$name\n";
+ $contactList = array($name => $name);
}
- CRM_Utils_System::civiExit();
+ CRM_Core_Page_AJAX::autocompleteResults($contactList);
}
/**
";
$dao = CRM_Core_DAO::executeQuery($query);
-
+ $results = array();
while ($dao->fetch()) {
- echo $pcpList = "$dao->data|$dao->id\n";
+ $results[$dao->id] = $dao->data;
}
-
- CRM_Utils_System::civiExit();
+ CRM_Core_Page_AJAX::autocompleteResults($results);
}
/**
$label = CRM_Utils_Type::escape($_GET['s'], 'String');
$selectOption = CRM_Core_BAO_CustomOption::valuesByID($fieldID, $optionGroupID);
-
- $completeList = NULL;
+ $results = array();
foreach ($selectOption as $id => $value) {
if (strtolower($label) == strtolower(substr($value, 0, strlen($label)))) {
- echo $completeList = "$value|$id\n";
+ $results[$id] = $value;
}
}
- CRM_Utils_System::civiExit();
+ CRM_Core_Page_AJAX::autocompleteResults($results);
}
static function relationship() {
$name = str_replace('*', '%', $name);
$elements = CRM_Contact_BAO_Relationship::getPermissionedEmployer($cid, $name);
-
+ $results = array();
if (!empty($elements)) {
foreach ($elements as $cid => $name) {
- echo $element = $name['name'] . "|$cid\n";
+ $results[$cid] = $name['name'];
}
}
- CRM_Utils_System::civiExit();
+ CRM_Core_Page_AJAX::autocompleteResults($results);
}
}
/**
- * Function for building contact combo box
+ * @deprecated
+ * Old quicksearch function. No longer used in core.
+ * @todo: Remove this function and associated menu entry in CiviCRM 5
*/
static function search() {
$json = TRUE;
}
CRM_Utils_System::civiExit();
}
+
+ /**
+ * Send autocomplete results to the client. Input can be a simple or nested array.
+ * @param array $results - If nested array, also provide:
+ * @param string $val - array key to use as the value
+ * @param string $key - array key to use as the key
+ */
+ static function autocompleteResults($results, $val='label', $key='id') {
+ $output = array();
+ if (is_array($results)) {
+ foreach ($results as $k => $v) {
+ if (is_array($v)) {
+ echo $v[$val] . '|' . $v[$key] . "\n";
+ }
+ else {
+ echo "$v|$k\n";
+ }
+ }
+ }
+ CRM_Utils_System::civiExit();
+ }
}
civicrm_event.title
";
$dao = CRM_Core_DAO::executeQuery($query);
+ $results = array();
while ($dao->fetch()) {
$fields = array();
foreach (array('title', 'city') as $field) {
if (isset($dao->start_date)) {
array_push($fields, CRM_Utils_Date::customFormat($dao->start_date));
}
- $eventinfo = implode(' - ', $fields);
- echo $elements = "$eventinfo|$dao->id\n";
+ $results[$dao->id] = implode(' - ', $fields);
}
- CRM_Utils_System::civiExit();
+ CRM_Core_Page_AJAX::autocompleteResults($results);
}
/**
ORDER by v.weight";
$dao = CRM_Core_DAO::executeQuery($query);
+ $results = array();
while ($dao->fetch()) {
- echo $elements = "$dao->label|$dao->value\n";
+ $results[$dao->value] = $dao->label;
}
- CRM_Utils_System::civiExit();
+ CRM_Core_Page_AJAX::autocompleteResults($results);
}
/**
WHERE ce.entity_table = 'civicrm_event' AND {$whereClause}
GROUP BY cv.label";
$dao = CRM_Core_DAO::executeQuery($query);
+ $results = array();
while ($dao->fetch()) {
- echo $elements = "$dao->label|$dao->id\n";
+ $results[$dao->id] = $dao->label;
}
- CRM_Utils_System::civiExit();
+ CRM_Core_Page_AJAX::autocompleteResults($results);
}
function eventList() {
//used in edit mode
$this->_groupOrganizationID = $defaults['group_organization'];
}
-
- $this->assign('organizationID', CRM_Utils_Array::value('organization_id',$defaults));
+ if (!empty($defaults['organization_id'])) {
+ $result = civicrm_api3('contact', 'getquick', array(
+ 'org' => 1,
+ 'id' => $defaults['organization_id']
+ ));
+ $this->assign('organizationName', $result['values'][0]['data']);
+ }
+ else {
+ $this->assign('organizationName', '');
+ }
}
}
<tr class="crm-group-form-block-organization">
<td class="label"> {$form.organization.label}</td>
<td>{$form.organization.html|crmAddClass:huge}
- <div id="organization_address" style="font-size:10px"></div>
+ <div id="organization_address" style="font-size:10px">{$organizationName}</div>
</td>
</tr>
</table>
cj('input[type=checkbox][name="group_type[{/literal}{$hideMailignList}{literal}]"]').hide();
cj('label[for="group_type[{/literal}{$hideMailignList}{literal}]"]').hide();
{/literal}{/if}{literal}
-{/literal}{if $organizationID}{literal}
- cj(document).ready( function() {
- //group organzation default setting
- var dataUrl = "{/literal}{crmURL p='civicrm/ajax/search' h=0 q="org=1&id=$organizationID"}{literal}";
- cj.ajax({
- url : dataUrl,
- async : false,
- success : function(html){
- //fixme for showing address in div
- htmlText = html.split( '|' , 2);
- htmlDiv = htmlText[0].replace( /::/gi, ' ');
- cj('#organization').val(htmlText[0]);
- cj('div#organization_address').html(htmlDiv);
- }
- });
- });
-{/literal}{/if}{literal}
-var dataUrl = "{/literal}{$groupOrgDataURL}{literal}";
-cj('#organization').autocomplete( dataUrl, {
+var dataUrl = "{/literal}{crmURL p='civicrm/ajax/rest' q='className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&org=1&context=groupcontact' h=0 }{literal}";
+cj('#organization').val(cj('#organization_address').text()).autocomplete( dataUrl, {
width : 250, selectFirst : false, matchContains: true
}).result( function(event, data, formatted) {
cj( "#organization_id" ).val( data[1] );