<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.4 |
+ | CiviCRM version 4.5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
*
*/
// check that this is a valid, active custom field of Contact Reference type
$params = array('id' => $cfID);
$returnProperties = array('filter', 'data_type', 'is_active');
- $fldValues = array();
+ $fldValues = $cf = array();
CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $cf, $returnProperties);
if (!$cf['id'] || !$cf['is_active'] || $cf['data_type'] != 'ContactReference') {
CRM_Core_Page_AJAX::autocompleteResults(array('error' => $name));
}
- if ($cf['filter']) {
+ if (!empty($cf['filter'])) {
$filterParams = array();
parse_str($cf['filter'], $filterParams);
SELECT pcp.id as id, CONCAT_WS( ' :: ', {$select} ) as data, sort_name
FROM civicrm_pcp pcp, civicrm_contribution_page cp, civicrm_contact cc
{$includeEmailFrom}
- {$whereClause}
+ {$whereClause} AND pcp.page_type = 'contribute'
+ UNION ALL
+ SELECT pcp.id as id, CONCAT_WS( ' :: ', {$select} ) as data, sort_name
+ FROM civicrm_pcp pcp, civicrm_event cp, civicrm_contact cc
+ {$includeEmailFrom}
+ {$whereClause} AND pcp.page_type = 'event'
LIMIT 0, {$limit}
) t
ORDER BY sort_name
$dao = CRM_Core_DAO::executeQuery($query);
$results = array();
while ($dao->fetch()) {
- $results[$dao->id] = $dao->data;
- }
- CRM_Core_Page_AJAX::autocompleteResults($results);
- }
-
- /**
- * Function to fetch the values
- */
- static function autocomplete() {
- $fieldID = CRM_Utils_Type::escape($_GET['cfid'], 'Integer');
- $optionGroupID = CRM_Utils_Type::escape($_GET['ogid'], 'Integer');
- $label = CRM_Utils_Type::escape($_GET['s'], 'String');
-
- $selectOption = CRM_Core_BAO_CustomOption::valuesByID($fieldID, $optionGroupID);
- $results = array();
- foreach ($selectOption as $id => $value) {
- if (strtolower($label) == strtolower(substr($value, 0, strlen($label)))) {
- $results[$id] = $value;
- }
+ $results[] = array('id' => $dao->id, 'text' => $dao->data);
}
- CRM_Core_Page_AJAX::autocompleteResults($results);
+ print json_encode($results);
+ CRM_Utils_System::civiExit();
}
static function relationship() {
- $relType = CRM_Utils_Array::value('rel_type', $_REQUEST);
- $relContactID = CRM_Utils_Array::value('rel_contact', $_REQUEST);
- $sourceContactID = CRM_Utils_Array::value('contact_id', $_REQUEST); // we no longer need this.
- $relationshipID = CRM_Utils_Array::value('rel_id', $_REQUEST); // this used only to determine add or update mode
- $caseID = CRM_Utils_Array::value('case_id', $_REQUEST);
+ $relType = CRM_Utils_Request::retrieve('rel_type', 'Positive', CRM_Core_DAO::$_nullObject, TRUE);
+ $relContactID = CRM_Utils_Request::retrieve('rel_contact', 'Positive', CRM_Core_DAO::$_nullObject, TRUE);
+ $relationshipID = CRM_Utils_Array::value('rel_id', $_REQUEST); // this used only to determine add or update mode
+ $caseID = CRM_Utils_Request::retrieve('case_id', 'Positive', CRM_Core_DAO::$_nullObject, TRUE);
// check if there are multiple clients for this case, if so then we need create
// relationship and also activities for each contacts
// get case client list
$clientList = CRM_Case_BAO_Case::getCaseClients($caseID);
+ $ret = array('is_error' => 0);
+
foreach($clientList as $sourceContactID) {
$relationParams = array(
'relationship_type_id' => $relType . '_a_b',
// create new or update existing relationship
$return = CRM_Contact_BAO_Relationship::create($relationParams, $relationIds);
- $status = 'process-relationship-fail';
if (!empty($return[4][0])) {
$relationshipID = $return[4][0];
- $status = 'process-relationship-success';
//create an activity for case role assignment.CRM-4480
CRM_Case_BAO_Case::createCaseRoleActivity($caseID, $relationshipID, $relContactID);
}
+ else {
+ $ret = array(
+ 'is_error' => 1,
+ 'error_message' => ts('The relationship type definition for the case role is not valid for the client and / or staff contact types. You can review and edit relationship types at <a href="%1">Administer >> Option Lists >> Relationship Types</a>.',
+ array(1 => CRM_Utils_System::url('civicrm/admin/reltype', 'reset=1')))
+ );
+ }
}
- $relation['status'] = $status;
- echo json_encode($relation);
+ echo json_encode($ret);
CRM_Utils_System::civiExit();
}
//check for mobile type
$phoneTypes = CRM_Core_OptionGroup::values('phone_type', TRUE, FALSE, FALSE, NULL, 'name');
$mobileType = CRM_Utils_Array::value('Mobile', $phoneTypes);
-
+
$name = CRM_Utils_Array::value('name', $_GET);
if ($name) {
$name = CRM_Utils_Type::escape($name, 'String');
CRM_Utils_System::civiExit();
}
- static function relationshipContacts() {
- $searchValues = $searchRows = array();
- $addCount = 0;
-
- $relType = CRM_Utils_Type::escape($_REQUEST['relType'], 'String');
- $typeName = isset($_REQUEST['typeName']) ? CRM_Utils_Type::escape($_REQUEST['typeName'], 'String') : '';
- $relContact = CRM_Utils_Type::escape($_REQUEST['relContact'], 'String');
- $currentContactId = CRM_Utils_Type::escape($_REQUEST['cid'], 'Integer');
-
- if (in_array($typeName, array(
- 'Employee of', 'Employer of'))) {
- $addCount = 1;
- }
-
- $sortMapper = array(
- 1 => 'sort_name', (2 + $addCount) => 'city', (3 + $addCount) => 'state_province',
- (4 + $addCount) => 'email', (5 + $addCount) => 'phone',
- );
-
- $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
- $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
- $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
- $sort = isset($_REQUEST['iSortCol_0']) ? $sortMapper[CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer')] : 'sort_name';
- $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
-
- $searchValues[] = array('sort_name', 'LIKE', $relContact, 0, 1);
-
- list($rid, $direction) = explode('_', $relType, 2);
-
- $relationshipType = new CRM_Contact_DAO_RelationshipType();
-
- $relationshipType->id = $rid;
- if ($relationshipType->find(TRUE)) {
- if ($direction == 'a_b') {
- $type = $relationshipType->contact_type_b;
- $subType = $relationshipType->contact_sub_type_b;
- }
- else {
- $type = $relationshipType->contact_type_a;
- $subType = $relationshipType->contact_sub_type_a;
- }
-
- if ($type == 'Individual' || $type == 'Organization' || $type == 'Household') {
- $searchValues[] = array('contact_type', '=', $type, 0, 0);
- }
-
- if ($subType) {
- $searchValues[] = array('contact_sub_type', '=', $subType, 0, 0);
- }
- }
-
- // exclude current contact
- $searchValues[] = array('contact_id', '!=', $currentContactId, 0, 0);
-
- $query = new CRM_Contact_BAO_Query($searchValues);
- $searchCount = $query->searchQuery(0, 0, NULL, TRUE);
- $iTotal = $searchCount;
-
- if ($searchCount > 0) {
- // get the result of the search
- $result = $query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE,
- FALSE, FALSE, FALSE, NULL, $sortOrder
- );
-
- $config = CRM_Core_Config::singleton();
-
- while ($result->fetch()) {
- $query->convertToPseudoNames($result);
- $contactID = $result->contact_id;
- $typeImage = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ?
- $result->contact_sub_type : $result->contact_type,
- FALSE, $contactID
- );
-
- $searchRows[$contactID]['id'] = $contactID;
- $searchRows[$contactID]['name'] = $typeImage . ' ' . $result->sort_name;
- $searchRows[$contactID]['city'] = $result->city;
- $searchRows[$contactID]['state'] = $result->state_province;
- $searchRows[$contactID]['email'] = $result->email;
- $searchRows[$contactID]['phone'] = $result->phone;
- }
- }
-
- foreach ($searchRows as $cid => $row) {
- $searchRows[$cid]['check'] = '<input type="checkbox" id="contact_check[' . $cid . ']" name="contact_check[' . $cid . ']" value=' . $cid . ' />';
-
- if ($typeName == 'Employee of') {
- $searchRows[$cid]['employee_of'] = '<input type="radio" name="employee_of" value=' . $cid . ' >';
- }
- elseif ($typeName == 'Employer of') {
- $searchRows[$cid]['employer_of'] = '<input type="checkbox" name="employer_of[' . $cid . ']" value=' . $cid . ' />';
- }
- }
-
- $selectorElements = array('check', 'name');
- if ($typeName == 'Employee of') {
- $selectorElements[] = 'employee_of';
- }
- elseif ($typeName == 'Employer of') {
- $selectorElements[] = 'employer_of';
- }
- $selectorElements = array_merge($selectorElements, array('city', 'state', 'email', 'phone'));
-
- $iFilteredTotal = $iTotal;
- echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
- CRM_Utils_System::civiExit();
- }
-
/**
* Function to process dupes.
*
$sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
$offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
$rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
+ $sort = 'sort_name';
+ $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
$gid = isset($_REQUEST['gid']) ? CRM_Utils_Type::escape($_REQUEST['gid'], 'Integer') : 0;
$rgid = isset($_REQUEST['rgid']) ? CRM_Utils_Type::escape($_REQUEST['rgid'], 'Integer') : 0;
echo json_encode($addressVal);
CRM_Utils_System::civiExit();
}
+
+ /**
+ * Function to retrieve contact relationships
+ */
+ public static function getContactRelationships() {
+ $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
+ $context = CRM_Utils_Type::escape($_GET['context'], 'String');
+
+ $sortMapper = array(
+ 0 => 'relation',
+ 1 => 'sort_name',
+ 2 => 'start_date',
+ 3 => 'end_date',
+ 4 => 'city',
+ 5 => 'state',
+ 6 => 'email',
+ 7 => 'phone',
+ 8 => 'links',
+ 9 => '',
+ 10 => '',
+ );
+
+ $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
+ $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
+ $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
+ $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
+ $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
+
+ $params = $_POST;
+ if ($sort && $sortOrder) {
+ $params['sortBy'] = $sort . ' ' . $sortOrder;
+ }
+
+ $params['page'] = ($offset / $rowCount) + 1;
+ $params['rp'] = $rowCount;
+
+ $params['contact_id'] = $contactID;
+ $params['context'] = $context;
+
+ // get the contact relationships
+ $relationships = CRM_Contact_BAO_Relationship::getContactRelationshipSelector($params);
+
+ $iFilteredTotal = $iTotal = $params['total'];
+ $selectorElements = array(
+ 'relation',
+ 'name',
+ 'start_date',
+ 'end_date',
+ 'city',
+ 'state',
+ 'email',
+ 'phone',
+ 'links',
+ 'id',
+ 'is_active',
+ );
+
+ echo CRM_Utils_JSON::encodeDataTableSelector($relationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
+ CRM_Utils_System::civiExit();
+ }
}