Exemplo n.º 1
0
 /**
  * Run the page.
  *
  * This method is called after the page is created.
  *
  * @return void
  * @access public
  *
  */
 function run()
 {
     // get the callback, module and activity id
     $action = CRM_Utils_Request::retrieve('action', $this, false, 'browse');
     $id = CRM_Utils_Request::retrieve('id', $this);
     $dao =& new CRM_Core_DAO_ActivityHistory();
     $dao->activity_id = $id;
     $dao->activity_type = ts('SMS Sent');
     if ($dao->find(true)) {
         $cid = $dao->entity_id;
     }
     require_once 'CRM/SMS/DAO/History.php';
     $dao =& new CRM_SMS_DAO_History();
     $dao->id = $id;
     if ($dao->find(true)) {
         $this->assign('fromName', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $dao->contact_id, 'display_name'));
         $this->assign('toName', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'display_name'));
         $this->assign('sentDate', $dao->sent_date);
         $this->assign('message', $dao->message);
         // get the display name and images for the contact
         list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($dao->contact_id);
         CRM_Utils_System::setTitle($contactImage . ' ' . $displayName);
         require_once 'CRM/Utils/Menu.php';
         // also add the cid params to the Menu array
         CRM_Utils_Menu::addParam('cid', $cid);
         // create menus ..
         $startWeight = CRM_Utils_Menu::getMaxWeight('civicrm/contact/view');
         $startWeight++;
         require_once 'CRM/Core/BAO/CustomGroup.php';
         CRM_Core_BAO_CustomGroup::addMenuTabs(CRM_Contact_BAO_Contact::getContactType($cid), 'civicrm/contact/view/cd', $startWeight);
     }
     parent::run();
 }
Exemplo n.º 2
0
 /**
  * Run the page.
  *
  * This method is called after the page is created.
  */
 public function run()
 {
     // get the emails for this contact
     $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
     $cgId = CRM_Utils_Request::retrieve('groupID', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
     $customRecId = CRM_Utils_Request::retrieve('customRecId', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, 1, $_REQUEST);
     $cgcount = CRM_Utils_Request::retrieve('cgcount', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, 1, $_REQUEST);
     //custom groups Inline
     $entityType = CRM_Contact_BAO_Contact::getContactType($contactId);
     $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($contactId);
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $contactId, $cgId, $entitySubType);
     $details = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $contactId);
     //get the fields of single custom group record
     if ($customRecId == 1) {
         $fields = reset($details[$cgId]);
     } else {
         $fields = CRM_Utils_Array::value($customRecId, $details[$cgId]);
     }
     $this->assign('cgcount', $cgcount);
     $this->assign('customRecId', $customRecId);
     $this->assign('contactId', $contactId);
     $this->assign('customGroupId', $cgId);
     $this->assign_by_ref('cd_edit', $fields);
     // check logged in user permission
     CRM_Contact_Page_View::checkUserPermission($this, $contactId);
     // finally call parent
     parent::run();
 }
Exemplo n.º 3
0
 /**
  * build all the data structures needed to build the form
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     $cid = CRM_Utils_Request::retrieve('cid', $this, false);
     if ($cid) {
         // not sure why this is needed :(
         // also add the cid params to the Menu array
         CRM_Utils_Menu::addParam('cid', $cid);
         // create menus ..
         $startWeight = CRM_Utils_Menu::getMaxWeight('civicrm/contact/view');
         $startWeight++;
         CRM_Core_BAO_CustomGroup::addMenuTabs(CRM_Contact_BAO_Contact::getContactType($cid), 'civicrm/contact/view/cd', $startWeight);
         $this->_contactIds = array($cid);
         $this->_single = true;
         $emails = CRM_Contact_BAO_Contact::allEmails($cid);
         $this->_emails = array();
         $toName = CRM_Contact_BAO_Contact::displayName($cid);
         foreach ($emails as $email => $item) {
             if (!$email && count($emails) <= 1) {
                 $this->_emails[$email] = '"' . $toName . '"';
                 $this->_noEmails = true;
             } else {
                 if ($email) {
                     $this->_emails[$email] = '"' . $toName . '" <' . $email . '> ' . $item['locationType'];
                 }
             }
             if ($item['is_primary']) {
                 $this->_emails[$email] .= ' ' . ts('(preferred)');
             }
             $this->_emails[$email] = htmlspecialchars($this->_emails[$email]);
         }
     } else {
         parent::preProcess();
     }
     $this->assign('single', $this->_single);
 }
Exemplo n.º 4
0
 /**
  * build all the data structures needed to build the form
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, false);
     if ($cid) {
         // not sure why this is needed :(
         // also add the cid params to the Menu array
         CRM_Core_Menu::addParam('cid', $cid);
         // create menus ..
         $startWeight = CRM_Core_Menu::getMaxWeight('civicrm/contact/view');
         $startWeight++;
         CRM_Core_BAO_CustomGroup::addMenuTabs(CRM_Contact_BAO_Contact::getContactType($cid), 'civicrm/contact/view/cd', $startWeight);
         $this->_contactIds = array($cid);
         $this->_single = true;
         $smsNumbers = CRM_Contact_BAO_Contact::allPhones($cid, 'Mobile');
         $this->_emails = array();
         $toName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'display_name');
         foreach ($smsNumbers as $number => $item) {
             $this->_smsNumbers[$number] = '"' . $toName . '" <' . $number . '> ' . $item['locationType'];
             if ($item['is_primary']) {
                 $this->_smsNumbers[$number] .= ' ' . ts('(preferred)');
             }
             $this->_smsNumbers[$number] = htmlspecialchars($this->_emails[$email]);
         }
     } else {
         parent::preProcess();
     }
     $this->assign('single', $this->_single);
 }
Exemplo n.º 5
0
 /** 
  * Heart of the viewing process. The runner gets all the meta data for 
  * the contact and calls the appropriate type of page to view. 
  * 
  * @return void 
  * @access public 
  * 
  */
 function preProcess()
 {
     parent::preProcess();
     //Custom Groups Inline
     $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId);
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this->_contactId);
     CRM_Core_BAO_CustomGroup::buildViewHTML($this, $groupTree);
 }
 /**
  * call preprocess
  */
 public function preProcess()
 {
     //get all the existing email addresses
     $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE, NULL, $_REQUEST);
     $this->assign('contactId', $this->_contactId);
     // Get contact type if not set
     if (empty($this->_contactType)) {
         $this->_contactType = CRM_Contact_BAO_Contact::getContactType($this->_contactId);
     }
 }
 /**
  * call preprocess
  */
 public function preProcess()
 {
     //get all the existing email addresses
     $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE, NULL, $_REQUEST);
     $this->assign('contactId', $this->_contactId);
     $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE, NULL, $_REQUEST);
     $this->assign('customGroupId', $this->_groupID);
     $type = CRM_Contact_BAO_Contact::getContactType($this->_contactId);
     $subType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ',');
     CRM_Custom_Form_CustomData::preProcess($this, null, $subType, 1, $type, $this->_contactId);
 }
Exemplo n.º 8
0
/**
 * Create or update a Contact.
 *
 * @param array $params
 *   Input parameters.
 *
 * @throws API_Exception
 *
 * @return array
 *   API Result Array
 */
function civicrm_api3_contact_create($params)
{
    $contactID = CRM_Utils_Array::value('contact_id', $params, CRM_Utils_Array::value('id', $params));
    if ($contactID && !empty($params['check_permissions']) && !CRM_Contact_BAO_Contact_Permission::allow($contactID, CRM_Core_Permission::EDIT)) {
        throw new \Civi\API\Exception\UnauthorizedException('Permission denied to modify contact record');
    }
    $dupeCheck = CRM_Utils_Array::value('dupe_check', $params, FALSE);
    $values = _civicrm_api3_contact_check_params($params, $dupeCheck);
    if ($values) {
        return $values;
    }
    if (array_key_exists('api_key', $params) && !empty($params['check_permissions'])) {
        if (CRM_Core_Permission::check('edit api keys') || CRM_Core_Permission::check('administer CiviCRM')) {
            // OK
        } elseif ($contactID && CRM_Core_Permission::check('edit own api keys') && CRM_Core_Session::singleton()->get('userID') == $contactID) {
            // OK
        } else {
            throw new \Civi\API\Exception\UnauthorizedException('Permission denied to modify api key');
        }
    }
    if (!$contactID) {
        // If we get here, we're ready to create a new contact
        if (($email = CRM_Utils_Array::value('email', $params)) && !is_array($params['email'])) {
            $defLocType = CRM_Core_BAO_LocationType::getDefault();
            $params['email'] = array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => $defLocType->id ? $defLocType->id : 1));
        }
    }
    if (!empty($params['home_url'])) {
        $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
        $params['website'] = array(1 => array('website_type_id' => key($websiteTypes), 'url' => $params['home_url']));
    }
    _civicrm_api3_greeting_format_params($params);
    $values = array();
    if (empty($params['contact_type']) && $contactID) {
        $params['contact_type'] = CRM_Contact_BAO_Contact::getContactType($contactID);
    }
    if (!isset($params['contact_sub_type']) && $contactID) {
        $params['contact_sub_type'] = CRM_Contact_BAO_Contact::getContactSubType($contactID);
    }
    _civicrm_api3_custom_format_params($params, $values, $params['contact_type'], $contactID);
    $params = array_merge($params, $values);
    //@todo we should just call basic_create here - but need to make contact:create accept 'id' on the bao
    $contact = _civicrm_api3_contact_update($params, $contactID);
    if (is_a($contact, 'CRM_Core_Error')) {
        throw new API_Exception($contact->_errors[0]['message']);
    } else {
        $values = array();
        _civicrm_api3_object_to_array_unique_fields($contact, $values[$contact->id]);
    }
    return civicrm_api3_create_success($values, $params, 'Contact', 'create');
}
Exemplo n.º 9
0
function hrui_civicrm_pageRun($page)
{
    CRM_Core_Resources::singleton()->addStyleFile('org.civicrm.hrui', 'css/hrui.css');
    if ($page instanceof CRM_Contact_Page_DashBoard) {
        CRM_Utils_System::setTitle(ts('CiviHR Home'));
    }
    if ($page instanceof CRM_Contact_Page_View_Summary) {
        CRM_Core_Resources::singleton()->addScriptFile('org.civicrm.hrui', 'js/hrui.js')->addSetting(array('pageName' => 'viewSummary'));
        //set government field value for individual page
        $contactType = CRM_Contact_BAO_Contact::getContactType(CRM_Utils_Request::retrieve('cid', 'Integer'));
        if ($contactType == 'Individual') {
            $hideGId = civicrm_api3('CustomField', 'getvalue', array('custom_group_id' => 'Identify', 'name' => 'is_government', 'return' => 'id'));
            CRM_Core_Resources::singleton()->addSetting(array('cid' => CRM_Utils_Request::retrieve('cid', 'Integer'), 'hideGId' => $hideGId));
        }
    }
}
Exemplo n.º 10
0
 /** 
  * build all the data structures needed to build the form 
  * 
  * @return void 
  * @access public 
  */
 function preProcess()
 {
     $cid = CRM_Utils_Request::retrieve('cid', $this, false);
     if ($cid) {
         // not sure why this is needed :(
         // also add the cid params to the Menu array
         CRM_Utils_Menu::addParam('cid', $cid);
         // create menus ..
         $startWeight = CRM_Utils_Menu::getMaxWeight('civicrm/contact/view');
         $startWeight++;
         CRM_Core_BAO_CustomGroup::addMenuTabs(CRM_Contact_BAO_Contact::getContactType($cid), 'civicrm/contact/view/cd', $startWeight);
         $this->_contactIds = array($cid);
         $this->_single = true;
         $this->assign('totalSelectedContacts', 1);
     } else {
         parent::preProcess();
     }
 }
 /**
  * Run the page.
  *
  * This method is called after the page is created.
  *
  * @return void
  * @access public
  *
  */
 function run()
 {
     // get the emails for this contact
     $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
     $cgId = CRM_Utils_Request::retrieve('groupID', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST);
     //custom groups Inline
     $entityType = CRM_Contact_BAO_Contact::getContactType($contactId);
     $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($contactId);
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $contactId, $cgId, $entitySubType);
     $details = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     $fields = array_pop($details[$cgId]);
     $this->assign('contactId', $contactId);
     $this->assign('customGroupId', $cgId);
     $this->assign_by_ref('cd_edit', $fields);
     // check logged in user permission
     CRM_Contact_Page_View::checkUserPermission($this, $contactId);
     // finally call parent
     parent::run();
 }
 /**
  * Method processAction to execute the action
  *
  * @param CRM_Civirules_EventData_EventData $eventData
  * @access public
  *
  */
 public function processAction(CRM_Civirules_EventData_EventData $eventData)
 {
     $contactId = $eventData->getContactId();
     $subTypes = CRM_Contact_BAO_Contact::getContactSubType($contactId);
     $contactType = CRM_Contact_BAO_Contact::getContactType($contactId);
     $changed = false;
     $action_params = $this->getActionParameters();
     foreach ($action_params['sub_type'] as $sub_type) {
         if (CRM_Contact_BAO_ContactType::isExtendsContactType($sub_type, $contactType)) {
             $subTypes[] = $sub_type;
             $changed = true;
         }
     }
     if ($changed) {
         $params['id'] = $contactId;
         $params['contact_id'] = $contactId;
         $params['contact_type'] = $contactType;
         $params['contact_sub_type'] = $subTypes;
         CRM_Contact_BAO_Contact::add($params);
     }
 }
Exemplo n.º 13
0
/**
 * Create or update a Contact.
 *
 * @param array $params
 *   Input parameters.
 *
 * @throws API_Exception
 *
 * @return array
 *   API Result Array
 */
function civicrm_api3_contact_create($params)
{
    $contactID = CRM_Utils_Array::value('contact_id', $params, CRM_Utils_Array::value('id', $params));
    $dupeCheck = CRM_Utils_Array::value('dupe_check', $params, FALSE);
    $values = _civicrm_api3_contact_check_params($params, $dupeCheck);
    if ($values) {
        return $values;
    }
    if (!$contactID) {
        // If we get here, we're ready to create a new contact
        if (($email = CRM_Utils_Array::value('email', $params)) && !is_array($params['email'])) {
            $defLocType = CRM_Core_BAO_LocationType::getDefault();
            $params['email'] = array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => $defLocType->id ? $defLocType->id : 1));
        }
    }
    if (!empty($params['home_url'])) {
        $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
        $params['website'] = array(1 => array('website_type_id' => key($websiteTypes), 'url' => $params['home_url']));
    }
    _civicrm_api3_greeting_format_params($params);
    $values = array();
    if (empty($params['contact_type']) && $contactID) {
        $params['contact_type'] = CRM_Contact_BAO_Contact::getContactType($contactID);
    }
    if (!isset($params['contact_sub_type']) && $contactID) {
        $params['contact_sub_type'] = CRM_Contact_BAO_Contact::getContactSubType($contactID);
    }
    _civicrm_api3_custom_format_params($params, $values, $params['contact_type'], $contactID);
    $params = array_merge($params, $values);
    //@todo we should just call basic_create here - but need to make contact:create accept 'id' on the bao
    $contact = _civicrm_api3_contact_update($params, $contactID);
    if (is_a($contact, 'CRM_Core_Error')) {
        throw new API_Exception($contact->_errors[0]['message']);
    } else {
        $values = array();
        _civicrm_api3_object_to_array_unique_fields($contact, $values[$contact->id]);
    }
    return civicrm_api3_create_success($values, $params, 'Contact', 'create');
}
Exemplo n.º 14
0
 /**
  * Get list of Multi Record Fields.
  *
  */
 public static function getMultiRecordFieldList()
 {
     $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(0, 10);
     $params['cid'] = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
     $params['cgid'] = CRM_Utils_Type::escape($_GET['cgid'], 'Integer');
     $contactType = CRM_Contact_BAO_Contact::getContactType($params['cid']);
     $obj = new CRM_Profile_Page_MultipleRecordFieldsListing();
     $obj->_pageViewType = 'customDataView';
     $obj->_contactId = $params['cid'];
     $obj->_customGroupId = $params['cgid'];
     $obj->_contactType = $contactType;
     $obj->_DTparams['offset'] = ($params['page'] - 1) * $params['rp'];
     $obj->_DTparams['rowCount'] = $params['rp'];
     if (!empty($params['sortBy'])) {
         $obj->_DTparams['sort'] = $params['sortBy'];
     }
     list($fields, $attributes) = $obj->browse();
     // format params and add class attributes
     $fieldList = array();
     foreach ($fields as $id => $value) {
         $field = array();
         foreach ($value as $fieldId => &$fieldName) {
             if (!empty($attributes[$fieldId][$id]['class'])) {
                 $fieldName = array('data' => $fieldName, 'cellClass' => $attributes[$fieldId][$id]['class']);
             }
             if (is_numeric($fieldId)) {
                 $fName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $fieldId, 'column_name');
                 CRM_Utils_Array::crmReplaceKey($value, $fieldId, $fName);
             }
         }
         $field = $value;
         array_push($fieldList, $field);
     }
     $totalRecords = !empty($obj->_total) ? $obj->_total : 0;
     $multiRecordFields = array();
     $multiRecordFields['data'] = $fieldList;
     $multiRecordFields['recordsTotal'] = $totalRecords;
     $multiRecordFields['recordsFiltered'] = $totalRecords;
     if (!empty($_GET['is_unit_test'])) {
         return $multiRecordFields;
     }
     CRM_Utils_JSON::output($multiRecordFields);
 }
Exemplo n.º 15
0
 /**
  * format an address string from address fields and a format string
  *
  * Format an address basing on the address fields provided.
  * Use Setting's address_format if there's no format specified.
  *
  * @param array $fields the address fields
  * @param string $format the desired address format
  * @param boolean $microformat if true indicates, the address to be built in hcard-microformat standard.
  * @param boolean $mailing if true indicates, the call has been made from mailing label
  * @param boolean $individualFormat if true indicates, the call has been made for the contact of type 'individual'
  *
  * @param null $tokenFields
  *
  * @return string  formatted address string
  *
  * @static
  */
 static function format($fields, $format = NULL, $microformat = FALSE, $mailing = FALSE, $individualFormat = FALSE, $tokenFields = NULL)
 {
     static $config = NULL;
     if (!$format) {
         $format = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_format');
     }
     if ($mailing) {
         $format = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'mailing_format');
     }
     $formatted = $format;
     $fullPostalCode = CRM_Utils_Array::value('postal_code', $fields);
     if (!empty($fields['postal_code_suffix'])) {
         $fullPostalCode .= "-{$fields['postal_code_suffix']}";
     }
     // make sure that some of the fields do have values
     $emptyFields = array('supplemental_address_1', 'supplemental_address_2', 'state_province_name', 'county');
     foreach ($emptyFields as $f) {
         if (!isset($fields[$f])) {
             $fields[$f] = NULL;
         }
     }
     $contactName = CRM_Utils_Array::value('display_name', $fields);
     if (!$individualFormat) {
         if (isset($fields['id'])) {
             $type = CRM_Contact_BAO_Contact::getContactType($fields['id']);
         } else {
             $type = 'Individual';
         }
         if ($type == 'Individual') {
             $contactName = CRM_Utils_Array::value('addressee_display', $fields);
         }
     }
     if (!$microformat) {
         // replacements in case of Individual Name Format
         $replacements = array('contact.display_name' => CRM_Utils_Array::value('display_name', $fields), 'contact.individual_prefix' => CRM_Utils_Array::value('individual_prefix', $fields), 'contact.formal_title' => CRM_Utils_Array::value('formal_title', $fields), 'contact.first_name' => CRM_Utils_Array::value('first_name', $fields), 'contact.middle_name' => CRM_Utils_Array::value('middle_name', $fields), 'contact.last_name' => CRM_Utils_Array::value('last_name', $fields), 'contact.individual_suffix' => CRM_Utils_Array::value('individual_suffix', $fields), 'contact.address_name' => CRM_Utils_Array::value('address_name', $fields), 'contact.street_address' => CRM_Utils_Array::value('street_address', $fields), 'contact.supplemental_address_1' => CRM_Utils_Array::value('supplemental_address_1', $fields), 'contact.supplemental_address_2' => CRM_Utils_Array::value('supplemental_address_2', $fields), 'contact.city' => CRM_Utils_Array::value('city', $fields), 'contact.state_province_name' => CRM_Utils_Array::value('state_province_name', $fields), 'contact.county' => CRM_Utils_Array::value('county', $fields), 'contact.state_province' => CRM_Utils_Array::value('state_province', $fields), 'contact.postal_code' => $fullPostalCode, 'contact.country' => CRM_Utils_Array::value('country', $fields), 'contact.world_region' => CRM_Utils_Array::value('world_region', $fields), 'contact.geo_code_1' => CRM_Utils_Array::value('geo_code_1', $fields), 'contact.geo_code_2' => CRM_Utils_Array::value('geo_code_2', $fields), 'contact.current_employer' => CRM_Utils_Array::value('current_employer', $fields), 'contact.nick_name' => CRM_Utils_Array::value('nick_name', $fields), 'contact.email' => CRM_Utils_Array::value('email', $fields), 'contact.im' => CRM_Utils_Array::value('im', $fields), 'contact.do_not_email' => CRM_Utils_Array::value('do_not_email', $fields), 'contact.do_not_phone' => CRM_Utils_Array::value('do_not_phone', $fields), 'contact.do_not_mail' => CRM_Utils_Array::value('do_not_mail', $fields), 'contact.do_not_sms' => CRM_Utils_Array::value('do_not_sms', $fields), 'contact.do_not_trade' => CRM_Utils_Array::value('do_not_trade', $fields), 'contact.job_title' => CRM_Utils_Array::value('job_title', $fields), 'contact.birth_date' => CRM_Utils_Array::value('birth_date', $fields), 'contact.gender' => CRM_Utils_Array::value('gender', $fields), 'contact.is_opt_out' => CRM_Utils_Array::value('is_opt_out', $fields), 'contact.home_URL' => CRM_Utils_Array::value('home_URL', $fields), 'contact.preferred_mail_format' => CRM_Utils_Array::value('preferred_mail_format', $fields), 'contact.phone' => CRM_Utils_Array::value('phone', $fields), 'contact.home_URL' => CRM_Utils_Array::value('home_URL', $fields), 'contact.contact_source' => CRM_Utils_Array::value('contact_source', $fields), 'contact.external_identifier' => CRM_Utils_Array::value('external_identifier', $fields), 'contact.contact_id' => CRM_Utils_Array::value('id', $fields), 'contact.household_name' => CRM_Utils_Array::value('display_name', $fields), 'contact.organization_name' => CRM_Utils_Array::value('display_name', $fields), 'contact.legal_name' => CRM_Utils_Array::value('legal_name', $fields), 'contact.preferred_communication_method' => CRM_Utils_Array::value('preferred_communication_method', $fields), 'contact.communication_style' => CRM_Utils_Array::value('communication_style', $fields), 'contact.addressee' => CRM_Utils_Array::value('addressee_display', $fields), 'contact.email_greeting' => CRM_Utils_Array::value('email_greeting_display', $fields), 'contact.postal_greeting' => CRM_Utils_Array::value('postal_greeting_display', $fields));
     } else {
         $replacements = array('contact.address_name' => "<span class=\"address-name\">" . $fields['address_name'] . "</span>", 'contact.street_address' => "<span class=\"street-address\">" . $fields['street_address'] . "</span>", 'contact.supplemental_address_1' => "<span class=\"extended-address\">" . $fields['supplemental_address_1'] . "</span>", 'contact.supplemental_address_2' => $fields['supplemental_address_2'], 'contact.city' => "<span class=\"locality\">" . $fields['city'] . "</span>", 'contact.state_province_name' => "<span class=\"region\">" . $fields['state_province_name'] . "</span>", 'contact.county' => "<span class=\"region\">" . $fields['county'], 'contact.state_province' => "<span class=\"region\">" . $fields['state_province'] . "</span>", 'contact.postal_code' => "<span class=\"postal-code\">" . $fullPostalCode . "</span>", 'contact.country' => "<span class=\"country-name\">" . $fields['country'] . "</span>", 'contact.world_region' => "<span class=\"region\">" . $fields['world_region'] . "</span>");
         // erase all empty ones, so we dont get blank lines
         foreach (array_keys($replacements) as $key) {
             $exactKey = substr($key, 0, 8) == 'contact.' ? substr($key, 8) : $key;
             if ($key != 'contact.postal_code' && CRM_Utils_Array::value($exactKey, $fields) == NULL) {
                 $replacements[$key] = '';
             }
         }
         if (empty($fullPostalCode)) {
             $replacements['contact.postal_code'] = '';
         }
     }
     // replacements in case of Custom Token
     if (stristr($formatted, 'custom_')) {
         $customToken = array_keys($fields);
         foreach ($customToken as $value) {
             if (substr($value, 0, 7) == 'custom_') {
                 $replacements["contact.{$value}"] = $fields["{$value}"];
             }
         }
     }
     // also sub all token fields
     if ($tokenFields) {
         foreach ($tokenFields as $token) {
             $replacements["{$token}"] = CRM_Utils_Array::value("{$token}", $fields);
         }
     }
     // for every token, replace {fooTOKENbar} with fooVALUEbar if
     // the value is not empty, otherwise drop the whole {fooTOKENbar}
     foreach ($replacements as $token => $value) {
         if ($value && is_string($value) || is_numeric($value)) {
             $formatted = preg_replace("/{([^{}]*)\\b{$token}\\b([^{}]*)}/u", "\${1}{$value}\${2}", $formatted);
         } else {
             $formatted = preg_replace("/{[^{}]*\\b{$token}\\b[^{}]*}/u", '', $formatted);
         }
     }
     // drop any {...} constructs from lines' ends
     if (!$microformat) {
         $formatted = "\n{$formatted}\n";
     } else {
         if ($microformat == 1) {
             $formatted = "\n<div class=\"location vcard\"><span class=\"adr\">\n{$formatted}</span></div>\n";
         } else {
             $formatted = "\n<div class=\"vcard\"><span class=\"adr\">{$formatted}</span></div>\n";
         }
     }
     $formatted = preg_replace('/\\n{[^{}]*}/u', "\n", $formatted);
     $formatted = preg_replace('/{[^{}]*}\\n/u', "\n", $formatted);
     // if there are any 'sibling' {...} constructs, replace them with the
     // contents of the first one; for example, when there's no state_province:
     // 1. {city}{, }{state_province}{ }{postal_code}
     // 2. San Francisco{, }{ }12345
     // 3. San Francisco, 12345
     $formatted = preg_replace('/{([^{}]*)}({[^{}]*})+/u', '\\1', $formatted);
     // drop any remaining curly braces leaving their contents
     $formatted = str_replace(array('{', '}'), '', $formatted);
     // drop any empty lines left after the replacements
     $formatted = preg_replace('/^[ \\t]*[\\r\\n]+/m', '', $formatted);
     if (!$microformat) {
         $finalFormatted = $formatted;
     } else {
         // remove \n from each line and only add at the end
         // this hack solves formatting issue, when we convert nl2br
         $lines = array();
         $count = 1;
         $finalFormatted = NULL;
         $formattedArray = explode("\n", $formatted);
         $formattedArray = array_filter($formattedArray);
         foreach ($formattedArray as $line) {
             $line = trim($line);
             if ($line) {
                 if ($count > 1 && $count < count($formattedArray)) {
                     $line = "{$line}\n";
                 }
                 $finalFormatted .= $line;
                 $count++;
             }
         }
     }
     return $finalFormatted;
 }
Exemplo n.º 16
0
 /**
  * Check if the relationship type selected between two contacts is correct.
  *
  * @param int $contact_a
  *   1st contact id.
  * @param int $contact_b
  *   2nd contact id.
  * @param int $relationshipTypeId
  *   Relationship type id.
  *
  * @return bool
  *   true if it is valid relationship else false
  */
 public static function checkRelationshipType($contact_a, $contact_b, $relationshipTypeId)
 {
     $relationshipType = new CRM_Contact_DAO_RelationshipType();
     $relationshipType->id = $relationshipTypeId;
     $relationshipType->selectAdd();
     $relationshipType->selectAdd('contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b');
     if ($relationshipType->find(TRUE)) {
         $contact_type_a = CRM_Contact_BAO_Contact::getContactType($contact_a);
         $contact_type_b = CRM_Contact_BAO_Contact::getContactType($contact_b);
         $contact_sub_type_a = CRM_Contact_BAO_Contact::getContactSubType($contact_a);
         $contact_sub_type_b = CRM_Contact_BAO_Contact::getContactSubType($contact_b);
         if ((!$relationshipType->contact_type_a || $relationshipType->contact_type_a == $contact_type_a) && (!$relationshipType->contact_type_b || $relationshipType->contact_type_b == $contact_type_b) && (!$relationshipType->contact_sub_type_a || in_array($relationshipType->contact_sub_type_a, $contact_sub_type_a)) && (!$relationshipType->contact_sub_type_b || in_array($relationshipType->contact_sub_type_b, $contact_sub_type_b))) {
             return TRUE;
         } else {
             return FALSE;
         }
     }
     return FALSE;
 }
/**
 * take the input parameter list as specified in the data model and
 * convert it into the same format that we use in QF and BAO object
 *
 * @param array  $params       Associative array of property name/value
 *                             pairs to insert in new contact.
 * @param array  $values       The reformatted properties that we can use internally
 *                            '
 *
 * @return array|CRM_Error
 * @access public
 */
function _civicrm_relationship_format_params(&$params, &$values)
{
    // copy all the relationship fields as is
    $fields = CRM_Contact_DAO_Relationship::fields();
    _civicrm_store_values($fields, $params, $values);
    $relationTypes = CRM_Core_PseudoConstant::relationshipType('name', TRUE);
    foreach ($params as $key => $value) {
        // ignore empty values or empty arrays etc
        require_once 'CRM/Utils/System.php';
        if (CRM_Utils_System::isNull($value)) {
            continue;
        }
        switch ($key) {
            case 'contact_id_a':
            case 'contact_id_b':
                require_once 'CRM/Utils/Rule.php';
                if (!CRM_Utils_Rule::integer($value)) {
                    return civicrm_create_error("contact_id not valid: {$value}");
                }
                $dao = new CRM_Core_DAO();
                $qParams = array();
                $svq = $dao->singleValueQuery("SELECT id FROM civicrm_contact WHERE id = {$value}", $qParams);
                if (!$svq) {
                    return civicrm_create_error("Invalid Contact ID: There is no contact record with contact_id = {$value}.");
                }
                break;
            case 'start_date':
            case 'end_date':
                if (!CRM_Utils_Rule::qfDate($value)) {
                    return civicrm_create_error("{$key} not a valid date: {$value}");
                }
                break;
            case 'relationship_type':
                foreach ($relationTypes as $relTypId => $relValue) {
                    if (CRM_Utils_Array::key(ucfirst($value), $relValue)) {
                        $relationshipTypeId = $relTypId;
                        break;
                    }
                }
                if ($relationshipTypeId) {
                    if (CRM_Utils_Array::value('relationship_type_id', $values) && $relationshipTypeId != $values['relationship_type_id']) {
                        return civicrm_create_error('Mismatched Relationship Type and Relationship Type Id');
                    }
                    $values['relationship_type_id'] = $params['relationship_type_id'] = $relationshipTypeId;
                } else {
                    return civicrm_create_error('Invalid Relationship Type');
                }
            case 'relationship_type_id':
                if ($key == 'relationship_type_id' && !array_key_exists($value, $relationTypes)) {
                    return civicrm_create_error("{$key} not a valid: {$value}");
                }
                // execute for both relationship_type and relationship_type_id
                $relation = $relationTypes[$params['relationship_type_id']];
                require_once 'CRM/Contact/BAO/Contact.php';
                if ($relation['contact_type_a'] && $relation['contact_type_a'] != CRM_Contact_BAO_Contact::getContactType($params['contact_id_a'])) {
                    return civicrm_create_error("Contact ID :{$params['contact_id_a']} is not of contact type {$relation['contact_type_a']}");
                }
                if ($relation['contact_type_b'] && $relation['contact_type_b'] != CRM_Contact_BAO_Contact::getContactType($params['contact_id_b'])) {
                    return civicrm_create_error("Contact ID :{$params['contact_id_b']} is not of contact type {$relation['contact_type_b']}");
                }
                break;
            default:
                break;
        }
    }
    if (array_key_exists('note', $params)) {
        $values['note'] = $params['note'];
    }
    _civicrm_custom_format_params($params, $values, 'Relationship');
    return array();
}
Exemplo n.º 18
0
 /**
  * Process the user submitted custom data values.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     //if the delete record button is clicked
     if ($this->_deleteButtonName) {
         if (!empty($_POST[$this->_deleteButtonName]) && $this->_recordId) {
             $filterParams['id'] = $this->_customGroupId;
             $returnProperties = array('is_multiple', 'table_name');
             CRM_Core_DAO::commonRetrieve("CRM_Core_DAO_CustomGroup", $filterParams, $returnValues, $returnProperties);
             if (!empty($returnValues['is_multiple'])) {
                 if ($tableName = CRM_Utils_Array::value('table_name', $returnValues)) {
                     $sql = "DELETE FROM {$tableName} WHERE id = %1 AND entity_id = %2";
                     $sqlParams = array(1 => array($this->_recordId, 'Integer'), 2 => array($this->_id, 'Integer'));
                     CRM_Core_DAO::executeQuery($sql, $sqlParams);
                     CRM_Core_Session::setStatus(ts('Your record has been deleted.'), ts('Deleted'), 'success');
                 }
             }
             return;
         }
     }
     CRM_Utils_Hook::processProfile($this->_ufGroup['name']);
     if (!empty($params['image_URL'])) {
         CRM_Contact_BAO_Contact::processImageParams($params);
     }
     $greetingTypes = array('addressee' => 'addressee_id', 'email_greeting' => 'email_greeting_id', 'postal_greeting' => 'postal_greeting_id');
     $details = array();
     if ($this->_id) {
         $contactDetails = CRM_Contact_BAO_Contact::getHierContactDetails($this->_id, $greetingTypes);
         $details = $contactDetails[0][$this->_id];
     }
     if (!(!empty($details['addressee_id']) || !empty($details['email_greeting_id']) || CRM_Utils_Array::value('postal_greeting_id', $details))) {
         $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
         //Though Profile type is contact we need
         //Individual/Household/Organization for setting Greetings.
         if ($profileType == 'Contact') {
             $profileType = 'Individual';
             //if we editing Household/Organization.
             if ($this->_id) {
                 $profileType = CRM_Contact_BAO_Contact::getContactType($this->_id);
             }
         }
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         foreach ($greetingTypes as $key => $value) {
             if (!array_key_exists($key, $params)) {
                 $params[$key] = CRM_Contact_BAO_Contact_Utils::defaultGreeting($profileType, $key);
             }
         }
     }
     $transaction = new CRM_Core_Transaction();
     //used to send subscribe mail to the group which user want.
     //if the profile double option in is enabled
     $mailingType = array();
     $result = NULL;
     foreach ($params as $name => $values) {
         if (substr($name, 0, 6) == 'email-') {
             $result['email'] = $values;
         }
     }
     //array of group id, subscribed by contact
     $contactGroup = array();
     if (!empty($params['group']) && CRM_Core_BAO_UFGroup::isProfileDoubleOptin()) {
         $groupSubscribed = array();
         if (!empty($result['email'])) {
             if ($this->_id) {
                 $contactGroups = new CRM_Contact_DAO_GroupContact();
                 $contactGroups->contact_id = $this->_id;
                 $contactGroups->status = 'Added';
                 $contactGroups->find();
                 $contactGroup = array();
                 while ($contactGroups->fetch()) {
                     $contactGroup[] = $contactGroups->group_id;
                     $groupSubscribed[$contactGroups->group_id] = 1;
                 }
             }
             foreach ($params['group'] as $key => $val) {
                 if (!$val) {
                     unset($params['group'][$key]);
                     continue;
                 }
                 $groupTypes = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $key, 'group_type', 'id');
                 $groupType = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($groupTypes, 1, -1));
                 //filter group of mailing type and unset it from params
                 if (in_array(2, $groupType)) {
                     //if group is already subscribed , ignore it
                     $groupExist = CRM_Utils_Array::key($key, $contactGroup);
                     if (!isset($groupExist)) {
                         $mailingType[] = $key;
                         unset($params['group'][$key]);
                     }
                 }
             }
         }
     }
     $addToGroupId = CRM_Utils_Array::value('add_to_group_id', $this->_ufGroup);
     if (!empty($addToGroupId)) {
         //run same check whether group is a mailing list
         $groupTypes = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $addToGroupId, 'group_type', 'id');
         $groupType = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($groupTypes, 1, -1));
         //filter group of mailing type and unset it from params
         if (in_array(2, $groupType) && !empty($result['email']) && CRM_Core_BAO_UFGroup::isProfileAddToGroupDoubleOptin()) {
             if (!count($contactGroup)) {
                 //array of group id, subscribed by contact
                 $contactGroup = array();
                 if ($this->_id) {
                     $contactGroups = new CRM_Contact_DAO_GroupContact();
                     $contactGroups->contact_id = $this->_id;
                     $contactGroups->status = 'Added';
                     $contactGroups->find();
                     $contactGroup = array();
                     while ($contactGroups->fetch()) {
                         $contactGroup[] = $contactGroups->group_id;
                         $groupSubscribed[$contactGroups->group_id] = 1;
                     }
                 }
             }
             //if group is already subscribed , ignore it
             $groupExist = CRM_Utils_Array::key($addToGroupId, $contactGroup);
             if (!isset($groupExist)) {
                 $mailingType[] = $addToGroupId;
                 $addToGroupId = NULL;
             }
         } else {
             // since we are directly adding contact to group lets unset it from mailing
             if ($key = array_search($addToGroupId, $mailingType)) {
                 unset($mailingType[$key]);
             }
         }
     }
     if ($this->_grid) {
         $params['group'] = $groupSubscribed;
     }
     // commenting below code, since we potentially
     // triggered maximum name field formatting cases during CRM-4430.
     // CRM-4343
     // $params['preserveDBName'] = true;
     $profileFields = $this->_fields;
     if ($this->_mode & self::MODE_EDIT && $this->_activityId && $this->_isContactActivityProfile) {
         $profileFields = $activityParams = array();
         foreach ($this->_fields as $fieldName => $field) {
             if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
                 if (isset($params[$fieldName])) {
                     $activityParams[$fieldName] = $params[$fieldName];
                 }
                 if (isset($params['activity_date_time'])) {
                     $activityParams['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']);
                 }
                 if (!empty($params[$fieldName]) && isset($params["{$fieldName}_id"])) {
                     $activityParams[$fieldName] = $params["{$fieldName}_id"];
                 }
             } else {
                 $profileFields[$fieldName] = $field;
             }
         }
         if (!empty($activityParams)) {
             $activityParams['version'] = 3;
             $activityParams['id'] = $this->_activityId;
             $activityParams['skipRecentView'] = TRUE;
             civicrm_api('Activity', 'create', $activityParams);
         }
     }
     if ($this->_multiRecord && $this->_recordId && $this->_multiRecordFields && $this->_recordExists) {
         $params['customRecordValues'][$this->_recordId] = array_keys($this->_multiRecordFields);
     }
     $this->_id = CRM_Contact_BAO_Contact::createProfileContact($params, $profileFields, $this->_id, $addToGroupId, $this->_gid, $this->_ctype, TRUE);
     //mailing type group
     if (!empty($mailingType)) {
         // we send in the contactID so we match the same groups and are exact, rather than relying on email
         // CRM-8710
         CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($mailingType, $result, $this->_id, 'profile');
     }
     $ufGroups = array();
     if ($this->_gid) {
         $ufGroups[$this->_gid] = 1;
     } elseif ($this->_mode == self::MODE_REGISTER) {
         $ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('User Registration');
     }
     foreach ($ufGroups as $gId => $val) {
         if ($notify = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify')) {
             $values = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $this->_id, NULL);
             CRM_Core_BAO_UFGroup::commonSendMail($this->_id, $values);
         }
     }
     //create CMS user (if CMS user option is selected in profile)
     if (!empty($params['cms_create_account']) && $this->_mode == self::MODE_CREATE) {
         $params['contactID'] = $this->_id;
         if (!CRM_Core_BAO_CMSUser::create($params, $this->_mail)) {
             CRM_Core_Session::setStatus(ts('Your profile is not saved and Account is not created.'), ts('Profile Error'), 'error');
             CRM_Core_Error::debug_log_message("Rolling back transaction as CMSUser Create failed in Profile_Form for contact " . $params['contactID']);
             $transaction->rollback();
             return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/profile/create', 'reset=1&gid=' . $this->_gid));
         }
     }
     $transaction->commit();
 }
Exemplo n.º 19
0
 /**
  * Create relationship between contacts who share an address.
  *
  * Note that currently we create relationship only for Individual contacts
  * Individual + Household and Individual + Orgnization
  *
  * @param int $masterAddressId
  *   Master address id.
  * @param array $params
  *   Associated array of submitted values.
  */
 public static function processSharedAddressRelationship($masterAddressId, $params)
 {
     // get the contact type of contact being edited / created
     $currentContactType = CRM_Contact_BAO_Contact::getContactType($params['contact_id']);
     $currentContactId = $params['contact_id'];
     // if current contact is not of type individual return
     if ($currentContactType != 'Individual') {
         return;
     }
     // get the contact id and contact type of shared contact
     // check the contact type of shared contact, return if it is of type Individual
     $query = 'SELECT cc.id, cc.contact_type
              FROM civicrm_contact cc INNER JOIN civicrm_address ca ON cc.id = ca.contact_id
              WHERE ca.id = %1';
     $dao = CRM_Core_DAO::executeQuery($query, array(1 => array($masterAddressId, 'Integer')));
     $dao->fetch();
     // if current contact is not of type individual return, since we don't create relationship between
     // 2 individuals
     if ($dao->contact_type == 'Individual') {
         return;
     }
     $sharedContactType = $dao->contact_type;
     $sharedContactId = $dao->id;
     // create relationship between ontacts who share an address
     if ($sharedContactType == 'Organization') {
         return CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($currentContactId, $sharedContactId);
     }
     // get the relationship type id of "Household Member of"
     $relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Household Member of', 'id', 'name_a_b');
     if (!$relTypeId) {
         CRM_Core_Error::fatal(ts("You seem to have deleted the relationship type 'Household Member of'"));
     }
     $relParam = array('is_active' => TRUE, 'relationship_type_id' => $relTypeId, 'contact_id_a' => $currentContactId, 'contact_id_b' => $sharedContactId);
     // If already there is a relationship record of $relParam criteria, avoid creating relationship again or else
     // it will casue CRM-16588 as the Duplicate Relationship Exception will revert other contact field values on update
     if (CRM_Contact_BAO_Relationship::checkDuplicateRelationship($relParam, $currentContactId, $sharedContactId)) {
         return;
     }
     try {
         // create relationship
         civicrm_api3('relationship', 'create', $relParam);
     } catch (CiviCRM_API3_Exception $e) {
         // We catch and ignore here because this has historically been a best-effort relationship create call.
         // presumably it could refuse due to duplication or similar and we would ignore that.
     }
 }
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  *
  * @access public
  *
  * @param object $page - the view page which created this one
  *
  * @return none
  * @static
  *
  */
 function run()
 {
     $this->preProcess();
     //set the userContext stack
     $doneURL = 'civicrm/contact/view';
     $session = CRM_Core_Session::singleton();
     $session->pushUserContext(CRM_Utils_System::url($doneURL, 'action=browse&selectedChild=custom_' . $this->_groupId), FALSE);
     // get permission detail view or edit
     $permUser = CRM_Core_Permission::getPermission();
     $editCustomData = CRM_Core_Permission::VIEW == $permUser ? 0 : 1;
     $this->assign('editCustomData', $editCustomData);
     //allow to edit own customdata CRM-5518
     $editOwnCustomData = FALSE;
     if ($session->get('userID') == $this->_contactId) {
         $editOwnCustomData = TRUE;
     }
     $this->assign('editOwnCustomData', $editOwnCustomData);
     if ($this->_action == CRM_Core_Action::BROWSE) {
         //Custom Groups Inline
         $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId);
         $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId);
         $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId, $this->_groupId, $entitySubType);
         CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     } else {
         $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_CustomData', ts('Custom Data'), $this->_action);
         $controller->setEmbedded(TRUE);
         $controller->set('tableId', $this->_contactId);
         $controller->set('groupId', $this->_groupId);
         $controller->set('entityType', CRM_Contact_BAO_Contact::getContactType($this->_contactId));
         $controller->set('entitySubType', CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ','));
         $controller->process();
         $controller->run();
     }
     return parent::run();
 }
Exemplo n.º 21
0
 /**
  * Filter ufgroups based on logged in user contact type.
  *
  * @param int $ufGroupId
  *   Uf group id (profile id).
  * @param int $contactID
  *
  * @return bool
  *   true or false
  */
 public static function filterUFGroups($ufGroupId, $contactID = NULL)
 {
     if (!$contactID) {
         $session = CRM_Core_Session::singleton();
         $contactID = $session->get('userID');
     }
     if ($contactID) {
         //get the contact type
         $contactType = CRM_Contact_BAO_Contact::getContactType($contactID);
         //match if exixting contact type is same as profile contact type
         $profileType = CRM_Core_BAO_UFField::getProfileType($ufGroupId);
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         //allow special mix profiles for Contribution and Participant
         $specialProfiles = array('Contribution', 'Participant', 'Membership');
         if (in_array($profileType, $specialProfiles)) {
             return TRUE;
         }
         if ($contactType == $profileType || $profileType == 'Contact') {
             return TRUE;
         }
     }
     return FALSE;
 }
Exemplo n.º 22
0
 /**
  * Function to filter ufgroups based on logged in user contact type
  *
  * @params int $ufGroupId uf group id (profile id)
  *
  * @return boolean true or false
  * @static
  * @access public
  */
 static function filterUFGroups($ufGroupId, $contactID = null)
 {
     if (!$contactID) {
         $session =& CRM_Core_Session::singleton();
         $contactID = $session->get('userID');
     }
     if ($contactID) {
         //get the contact type
         require_once "CRM/Contact/BAO/Contact.php";
         $contactType = CRM_Contact_BAO_Contact::getContactType($contactID);
         //match if exixting contact type is same as profile contact type
         require_once "CRM/Core/BAO/UFField.php";
         $profileType = CRM_Core_BAO_UFField::getProfileType($ufGroupId);
         require_once "CRM/Contact/BAO/ContactType.php";
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         //allow special mix profiles for Contribution and Participant
         $specialProfiles = array('Contribution', 'Participant', 'Membership');
         if (in_array($profileType, $specialProfiles)) {
             return true;
         }
         if ($contactType == $profileType || $profileType == 'Contact') {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 23
0
 /**
  * Pre processing work done here.
  *
  * Gets session variables for table name, id of entity in table, type of entity and stores them.
  */
 public function preProcess()
 {
     $this->_cdType = CRM_Utils_Array::value('type', $_GET);
     $this->assign('cdType', FALSE);
     $this->_multiRecordDisplay = CRM_Utils_Request::retrieve('multiRecordDisplay', 'String', $this);
     if ($this->_cdType || $this->_multiRecordDisplay == 'single') {
         if ($this->_cdType) {
             $this->assign('cdType', TRUE);
         }
         // NOTE : group id is not stored in session from within CRM_Custom_Form_CustomData::preProcess func
         // this is due to some condition inside it which restricts it from saving in session
         // so doing this for multi record edit action
         $entityId = CRM_Utils_Request::retrieve('entityID', 'Positive', $this);
         if (!empty($entityId)) {
             $subType = CRM_Contact_BAO_Contact::getContactSubType($entityId, ',');
         }
         CRM_Custom_Form_CustomData::preProcess($this, NULL, $subType, NULL, NULL, $entityId);
         if ($this->_multiRecordDisplay) {
             $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this);
             $this->_tableID = $this->_entityId;
             $this->_contactType = CRM_Contact_BAO_Contact::getContactType($this->_tableID);
             $mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
             $hasReachedMax = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($this->_groupID, $this->_tableID);
             if ($hasReachedMax && $mode == 'add') {
                 CRM_Core_Error::statusBounce(ts('The maximum record limit is reached'));
             }
             $this->_copyValueId = CRM_Utils_Request::retrieve('copyValueId', 'Positive', $this);
             $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupID);
             $mode = CRM_Utils_Request::retrieve('mode', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET');
             $mode = ucfirst($mode);
             CRM_Utils_System::setTitle(ts('%1 %2 Record', array(1 => $mode, 2 => $groupTitle)));
             if (!empty($_POST['hidden_custom'])) {
                 $this->assign('postedInfo', TRUE);
             }
         }
         return;
     }
     $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE);
     $this->_tableID = CRM_Utils_Request::retrieve('tableId', 'Positive', $this, TRUE);
     $this->_contactType = CRM_Contact_BAO_Contact::getContactType($this->_tableID);
     $this->_contactSubType = CRM_Contact_BAO_Contact::getContactSubType($this->_tableID, ',');
     $this->assign('contact_type', $this->_contactType);
     $this->assign('contact_subtype', $this->_contactSubType);
     list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_tableID);
     CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName);
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
         for ($i = 1; $i <= $_POST['hidden_custom_group_count'][$this->_groupID]; $i++) {
             CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_contactSubType, $i, $this->_contactType, $this->_tableID);
             CRM_Custom_Form_CustomData::buildQuickForm($this);
             CRM_Custom_Form_CustomData::setDefaultValues($this);
         }
     }
 }
Exemplo n.º 24
0
/**
 * take the input parameter list as specified in the data model and
 * convert it into the same format that we use in QF and BAO object
 *
 * @param array $params Associative array of property name/value
 *                             pairs to insert in new contact.
 * @param array $values The reformatted properties that we can use internally
 *                            '
 *
 * @throws Exception
 * @return array|CRM_Error
 * @access public
 */
function _civicrm_api3_relationship_format_params($params, &$values)
{
    // copy all the relationship fields as is
    $fields = CRM_Contact_DAO_Relationship::fields();
    _civicrm_api3_store_values($fields, $params, $values);
    $relationTypes = CRM_Core_PseudoConstant::relationshipType('name');
    if (!empty($params['id'])) {
        $relation = new CRM_Contact_BAO_Relationship();
        $relation->id = $params['id'];
        if (!$relation->find(TRUE)) {
            throw new Exception('Relationship id is not valid');
        } else {
            if (isset($params['contact_id_a']) && $params['contact_id_a'] != $relation->contact_id_a || isset($params['contact_id_b']) && $params['contact_id_b'] != $relation->contact_id_b) {
                throw new Exception('Cannot change the contacts once relationship has been created');
            } else {
                // since the BAO function is not std & won't accept just 'id' (aargh) let's
                // at least return our BAO here
                $values = array();
                _civicrm_api3_object_to_array($relation, $values);
                $values = array_merge($values, $params);
                // and we need to reformat our date fields....
                $dateFields = array('start_date', 'end_date');
                foreach ($dateFields as $dateField) {
                    $values[$dateField] = CRM_Utils_Date::processDate($values[$dateField]);
                }
            }
        }
    }
    foreach ($params as $key => $value) {
        // ignore empty values or empty arrays etc
        if (CRM_Utils_System::isNull($value)) {
            continue;
        }
        switch ($key) {
            case 'contact_id_a':
            case 'contact_id_b':
                if (!CRM_Utils_Rule::integer($value)) {
                    throw new Exception("contact_id not valid: {$value}");
                }
                $dao = new CRM_Core_DAO();
                $qParams = array();
                $svq = $dao->singleValueQuery("SELECT id FROM civicrm_contact WHERE id = {$value}", $qParams);
                if (!$svq) {
                    throw new Exception("Invalid Contact ID: There is no contact record with contact_id = {$value}.");
                }
                break;
            case 'relationship_type':
                foreach ($relationTypes as $relTypId => $relValue) {
                    if (CRM_Utils_Array::key(ucfirst($value), $relValue)) {
                        $relationshipTypeId = $relTypId;
                        break;
                    }
                }
                if ($relationshipTypeId) {
                    if (!empty($values['relationship_type_id']) && $relationshipTypeId != $values['relationship_type_id']) {
                        throw new Exception('Mismatched Relationship Type and Relationship Type Id');
                    }
                    $values['relationship_type_id'] = $params['relationship_type_id'] = $relationshipTypeId;
                } else {
                    throw new Exception('Invalid Relationship Type');
                }
            case 'relationship_type_id':
                if ($key == 'relationship_type_id' && !array_key_exists($value, $relationTypes)) {
                    throw new Exception("{$key} not a valid: {$value}");
                }
                // execute for both relationship_type and relationship_type_id
                $relation = $relationTypes[$params['relationship_type_id']];
                if (!empty($params['contact_id_a']) && $relation['contact_type_a'] && $relation['contact_type_a'] != CRM_Contact_BAO_Contact::getContactType($params['contact_id_a'])) {
                    throw new Exception("Contact ID :{$params['contact_id_a']} is not of contact type {$relation['contact_type_a']}");
                }
                if (!empty($params['contact_id_b']) && $relation['contact_type_b'] && $relation['contact_type_b'] != CRM_Contact_BAO_Contact::getContactType($params['contact_id_b'])) {
                    throw new Exception("Contact ID :{$params['contact_id_b']} is not of contact type {$relation['contact_type_b']}");
                }
                break;
            default:
                break;
        }
    }
    if (array_key_exists('note', $params)) {
        $values['note'] = $params['note'];
    }
    _civicrm_api3_custom_format_params($params, $values, 'Relationship');
    return array();
}
Exemplo n.º 25
0
/**
 * @todo Write sth
 * @todo Serious FIXMES in the code! File issues.
 */
function civicrm_contact_update(&$params, $create_new = FALSE)
{
    _civicrm_initialize();
    try {
        civicrm_api_check_permission(__FUNCTION__, $params, TRUE);
    } catch (Exception $e) {
        return civicrm_create_error($e->getMessage());
    }
    require_once 'CRM/Utils/Array.php';
    $entityId = CRM_Utils_Array::value('contact_id', $params, NULL);
    if (!CRM_Utils_Array::value('contact_type', $params) && $entityId) {
        $params['contact_type'] = CRM_Contact_BAO_Contact::getContactType($entityId);
    }
    $dupeCheck = CRM_Utils_Array::value('dupe_check', $params, FALSE);
    $values = civicrm_contact_check_params($params, $dupeCheck);
    if ($values) {
        return $values;
    }
    if ($create_new) {
        // Make sure nothing is screwed up before we create a new contact
        if (!empty($entityId)) {
            return civicrm_create_error('Cannot create new contact when contact_id is present');
        }
        if (empty($params['contact_type'])) {
            return civicrm_create_error('Contact Type not specified');
        }
        // If we get here, we're ready to create a new contact
        if (($email = CRM_Utils_Array::value('email', $params)) && !is_array($params['email'])) {
            require_once 'CRM/Core/BAO/LocationType.php';
            $defLocType = CRM_Core_BAO_LocationType::getDefault();
            $params['email'] = array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => $defLocType->id ? $defLocType->id : 1));
        }
    }
    if ($homeUrl = CRM_Utils_Array::value('home_url', $params)) {
        require_once 'CRM/Core/PseudoConstant.php';
        $websiteTypes = CRM_Core_PseudoConstant::websiteType();
        $params['website'] = array(1 => array('website_type_id' => key($websiteTypes), 'url' => $homeUrl));
    }
    // FIXME: Some legacy support cruft, should get rid of this in 3.1
    $change = array('individual_prefix' => 'prefix', 'prefix' => 'prefix_id', 'individual_suffix' => 'suffix', 'suffix' => 'suffix_id', 'gender' => 'gender_id');
    foreach ($change as $field => $changeAs) {
        if (array_key_exists($field, $params)) {
            $params[$changeAs] = $params[$field];
            unset($params[$field]);
        }
    }
    // End legacy support cruft
    if (isset($params['suffix_id']) && !is_numeric($params['suffix_id'])) {
        $params['suffix_id'] = array_search($params['suffix_id'], CRM_Core_PseudoConstant::individualSuffix());
    }
    if (isset($params['prefix_id']) && !is_numeric($params['prefix_id'])) {
        $params['prefix_id'] = array_search($params['prefix_id'], CRM_Core_PseudoConstant::individualPrefix());
    }
    if (isset($params['gender_id']) && !is_numeric($params['gender_id'])) {
        $params['gender_id'] = array_search($params['gender_id'], CRM_Core_PseudoConstant::gender());
    }
    $error = _civicrm_greeting_format_params($params);
    if (civicrm_error($error)) {
        return $error;
    }
    $values = array();
    if (!($csType = CRM_Utils_Array::value('contact_sub_type', $params)) && $entityId) {
        require_once 'CRM/Contact/BAO/Contact.php';
        $csType = CRM_Contact_BAO_Contact::getContactSubType($entityId);
    }
    $customValue = civicrm_contact_check_custom_params($params, $csType);
    if ($customValue) {
        return $customValue;
    }
    _civicrm_custom_format_params($params, $values, $params['contact_type'], $entityId);
    $params = array_merge($params, $values);
    $contact =& _civicrm_contact_update($params, $entityId);
    if (is_a($contact, 'CRM_Core_Error')) {
        return civicrm_create_error($contact->_errors[0]['message']);
    } else {
        $values = array();
        $values['contact_id'] = $contact->id;
        $values['is_error'] = 0;
    }
    return $values;
}
Exemplo n.º 26
0
 /**
  * Global form rule.
  *
  * @param array $fields
  *   The input form values.
  *
  * @param $errors
  * @param $self
  *
  * @return array
  *   Array of errors
  */
 public static function formRule($fields, $errors, $self)
 {
     $errors = array();
     // if honor roll fields are populated but no PCP is selected
     if (empty($fields['pcp_made_through_id'])) {
         if (!empty($fields['pcp_display_in_roll']) || !empty($fields['pcp_roll_nickname']) || CRM_Utils_Array::value('pcp_personal_note', $fields)) {
             $errors['pcp_made_through_id'] = ts('Please select a Personal Campaign Page, OR uncheck Display in Honor Roll and clear both the Honor Roll Name and the Personal Note field.');
         }
     }
     if (!empty($fields['soft_credit_amount'])) {
         $repeat = array_count_values($fields['soft_credit_contact_id']);
         foreach ($fields['soft_credit_amount'] as $key => $val) {
             if (!empty($fields['soft_credit_contact_id'][$key])) {
                 if ($repeat[$fields['soft_credit_contact_id'][$key]] > 1) {
                     $errors["soft_credit_contact[{$key}]"] = ts('You cannot enter multiple soft credits for the same contact.');
                 }
                 if ($self->_action == CRM_Core_Action::ADD && $fields['soft_credit_amount'][$key] && CRM_Utils_Rule::cleanMoney($fields['soft_credit_amount'][$key]) > CRM_Utils_Rule::cleanMoney($fields['total_amount'])) {
                     $errors["soft_credit_amount[{$key}]"] = ts('Soft credit amount cannot be more than the total amount.');
                 }
                 if (empty($fields['soft_credit_amount'][$key])) {
                     $errors["soft_credit_amount[{$key}]"] = ts('Please enter the soft credit amount.');
                 }
                 $contactType = CRM_Contact_BAO_Contact::getContactType($fields['soft_credit_contact_id'][$key]);
                 if ($self->_honoreeProfileType && $self->_honoreeProfileType != $contactType) {
                     $errors["soft_credit_contact[{$key}]"] = ts('Please choose a contact of type %1', array(1 => $self->_honoreeProfileType));
                 }
             }
         }
     }
     return $errors;
 }
Exemplo n.º 27
0
 function createUser(&$params, $mail)
 {
     $user_data = array('ID' => '', 'user_pass' => $params['cms_pass'], 'user_login' => $params['cms_name'], 'user_email' => $params[$mail], 'nickname' => $params['cms_name'], 'role' => get_option('default_role'));
     if (isset($params['contactID'])) {
         $contactType = CRM_Contact_BAO_Contact::getContactType($params['contactID']);
         if ($contactType == 'Individual') {
             $user_data['first_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['contactID'], 'first_name');
             $user_data['last_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['contactID'], 'last_name');
         }
     }
     $uid = wp_insert_user($user_data);
     $creds = array();
     $creds['user_login'] = $params['cms_name'];
     $creds['user_password'] = $params['cms_pass'];
     $creds['remember'] = TRUE;
     $user = wp_signon($creds, FALSE);
     wp_new_user_notification($uid, $user_data['user_pass']);
     return $uid;
 }
Exemplo n.º 28
0
 /**
  * pre processing work done here.
  *
  * gets session variables for table name, id of entity in table, type of entity and stores them.
  *
  * @param
  * @return void
  *
  * @access public
  *
  */
 function preProcess()
 {
     $this->_cdType = CRM_Utils_Array::value('type', $_GET);
     $this->assign('cdType', false);
     if ($this->_cdType) {
         $this->assign('cdType', true);
         return CRM_Custom_Form_CustomData::preProcess($this);
     }
     $this->_groupID = CRM_Utils_Request::retrieve('groupId', 'Positive', $this, true);
     $this->_tableID = CRM_Utils_Request::retrieve('tableId', 'Positive', $this, true);
     require_once "CRM/Contact/BAO/Contact.php";
     $this->_contactType = CRM_Contact_BAO_Contact::getContactType($this->_tableID);
     $this->_contactSubType = CRM_Contact_BAO_Contact::getContactSubType($this->_tableID);
     $this->assign('contact_type', $this->_contactType);
     $this->assign('contact_subtype', $this->_contactSubType);
     list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_tableID);
     CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName);
     // when custom data is included in this page
     if (CRM_Utils_Array::value("hidden_custom", $_POST)) {
         for ($i; $i <= $_POST['hidden_custom_group_count'][$this->_groupID]; $i++) {
             CRM_Custom_Form_CustomData::preProcess($this, null, null, $i);
             CRM_Custom_Form_CustomData::buildQuickForm($this);
             CRM_Custom_Form_CustomData::setDefaultValues($this);
         }
     }
 }
Exemplo n.º 29
0
 /**
  * Test case for getContactType( ).
  */
 public function testGetContactType()
 {
     //get the contact params
     $params = $this->contactParams();
     //create contact
     $contact = CRM_Contact_BAO_Contact::create($params);
     $contactId = $contact->id;
     //get contact type.
     $contactType = CRM_Contact_BAO_Contact::getContactType($contactId);
     $this->assertEquals($contactType, $params['contact_type'], 'Check For Contact Type');
     //cleanup DB by deleting the contact
     $this->contactDelete($contactId);
     $this->quickCleanup(array('civicrm_contact'));
 }
Exemplo n.º 30
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  *
  *
  * @return void
  */
 public function run()
 {
     $this->preProcess();
     //set the userContext stack
     $doneURL = 'civicrm/contact/view';
     $session = CRM_Core_Session::singleton();
     $session->pushUserContext(CRM_Utils_System::url($doneURL, 'action=browse&selectedChild=custom_' . $this->_groupId), FALSE);
     // get permission detail view or edit
     // use a comtact id specific function which gives us much better granularity
     // CRM-12646
     $editCustomData = CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT);
     $this->assign('editCustomData', $editCustomData);
     //allow to edit own customdata CRM-5518
     $editOwnCustomData = FALSE;
     if ($session->get('userID') == $this->_contactId) {
         $editOwnCustomData = TRUE;
     }
     $this->assign('editOwnCustomData', $editOwnCustomData);
     if ($this->_action == CRM_Core_Action::BROWSE) {
         //Custom Groups Inline
         $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId);
         $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId);
         $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId, $this->_groupId, $entitySubType);
         $displayStyle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupId, 'style');
         if ($this->_multiRecordDisplay != 'single') {
             $id = "custom_{$this->_groupId}";
             $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $groupTree[$this->_groupId]['table_name']);
         }
         if ($displayStyle === 'Tab with table' && $this->_multiRecordDisplay != 'single') {
             $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'contact_type');
             $this->assign('displayStyle', 'tableOriented');
             // here the multi custom data listing code will go
             $multiRecordFieldListing = TRUE;
             $page = new CRM_Profile_Page_MultipleRecordFieldsListing();
             $page->set('contactId', $this->_contactId);
             $page->set('customGroupId', $this->_groupId);
             $page->set('action', CRM_Core_Action::BROWSE);
             $page->set('multiRecordFieldListing', $multiRecordFieldListing);
             $page->set('pageViewType', 'customDataView');
             $page->set('contactType', $ctype);
             $page->run();
         } else {
             $recId = NULL;
             if ($this->_multiRecordDisplay == 'single') {
                 $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupId);
                 CRM_Utils_System::setTitle(ts('View %1 Record', array(1 => $groupTitle)));
                 $recId = $this->_recId;
                 $this->assign('multiRecordDisplay', $this->_multiRecordDisplay);
                 $this->assign('skipTitle', 1);
             }
             CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, $recId);
         }
     } else {
         $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_CustomData', ts('Custom Data'), $this->_action);
         $controller->setEmbedded(TRUE);
         $controller->set('tableId', $this->_contactId);
         $controller->set('groupId', $this->_groupId);
         $controller->set('entityType', CRM_Contact_BAO_Contact::getContactType($this->_contactId));
         $controller->set('entitySubType', CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ','));
         $controller->process();
         $controller->run();
     }
     return parent::run();
 }