/**
* Process the form submission.
*/
public function postProcess()
{
CRM_Utils_System::flushCache('CRM_Core_DAO_LocationType');
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Core_BAO_LocationType::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected Location type has been deleted.'), ts('Record Deleted'), 'success');
return;
}
// store the submitted values in an array
$params = $this->exportValues();
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
// action is taken depending upon the mode
$locationType = new CRM_Core_DAO_LocationType();
$locationType->name = $params['name'];
$locationType->display_name = $params['display_name'];
$locationType->vcard_name = $params['vcard_name'];
$locationType->description = $params['description'];
$locationType->is_active = $params['is_active'];
$locationType->is_default = $params['is_default'];
if ($params['is_default']) {
$query = "UPDATE civicrm_location_type SET is_default = 0";
CRM_Core_DAO::executeQuery($query);
}
if ($this->_action & CRM_Core_Action::UPDATE) {
$locationType->id = $this->_id;
}
$locationType->save();
CRM_Core_Session::setStatus(ts("The location type '%1' has been saved.", array(1 => $locationType->name)), ts('Saved'), 'success');
}
/**
* Function to process the form
*
* @access public
* @return None
*/
function postProcess()
{
if ($this->_action & CRM_CORE_ACTION_DELETE) {
CRM_Core_BAO_LocationType::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected Location type has been deleted.'));
} else {
// store the submitted values in an array
$params = $this->exportValues();
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, false);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, false);
// action is taken depending upon the mode
$locationType =& new CRM_Core_DAO_LocationType();
$locationType->domain_id = CRM_Core_Config::domainID();
$locationType->name = $params['name'];
$locationType->vcard_name = $params['vcard_name'];
$locationType->description = $params['description'];
$locationType->is_active = $params['is_active'];
$locationType->is_default = $params['is_default'];
if ($params['is_default']) {
$unsetDefault =& new CRM_Core_DAO();
$query = 'UPDATE civicrm_location_type SET is_default = 0';
$unsetDefault->query($query);
}
if ($this->_action & CRM_CORE_ACTION_UPDATE) {
$locationType->id = $this->_id;
}
$locationType->save();
CRM_Core_Session::setStatus(ts('The location type "%1" has been saved.', array(1 => $locationType->name)));
}
}
/**
* This function sets the default values for the form. For edit/view mode
* the default values are retrieved from the database
*
* @access public
* @return None
*/
function setDefaultValues(&$form)
{
$defaults = array();
if ($form->_context == 'caseActivity') {
return $defaults;
}
require_once 'CRM/Utils/Date.php';
list($defaults['start_date']) = CRM_Utils_Date::setDateDefaults();
// set case status to 'ongoing'
$defaults['status_id'] = 1;
// set default encounter medium, location type and phone type defaults are set in DB
require_once "CRM/Core/OptionGroup.php";
$medium = CRM_Core_OptionGroup::values('encounter_medium', false, false, false, 'AND is_default = 1');
if (count($medium) == 1) {
$defaults['medium_id'] = key($medium);
}
require_once 'CRM/Core/BAO/LocationType.php';
$defaultLocationType =& CRM_Core_BAO_LocationType::getDefault();
if ($defaultLocationType->id) {
$defaults['location[1][location_type_id]'] = $defaultLocationType->id;
}
$phoneType = CRM_Core_OptionGroup::values('phone_type', false, false, false, 'AND is_default = 1');
if (count($phoneType) == 1) {
$defaults['location[1][phone][1][phone_type_id]'] = key($phoneType);
}
return $defaults;
}
/**
* Function to process the form
*
* @access public
* @return None
*/
public function postProcess()
{
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Core_BAO_LocationType::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected Location type has been deleted.'));
return;
}
// store the submitted values in an array
$params = $this->exportValues();
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, false);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, false);
// action is taken depending upon the mode
$locationType =& new CRM_Core_DAO_LocationType();
$locationType->name = $params['name'];
$locationType->vcard_name = $params['vcard_name'];
$locationType->description = $params['description'];
$locationType->is_active = $params['is_active'];
$locationType->is_default = $params['is_default'];
if ($params['is_default']) {
$query = "UPDATE civicrm_location_type SET is_default = 0";
CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
}
if ($this->_action & CRM_Core_Action::UPDATE) {
$locationType->id = $this->_id;
}
$locationType->save();
CRM_Core_Session::setStatus(ts('The location type \'%1\' has been saved.', array(1 => $locationType->name)));
}
/**
* Get billing fields required for this processor.
*
* We apply the existing default of returning fields only for payment processor type 1. Processors can override to
* alter.
*
* @param int $billingLocationID
*
* @return array
*/
public function getBillingAddressFields($billingLocationID = NULL)
{
if (!$billingLocationID) {
// Note that although the billing id is passed around the forms the idea that it would be anything other than
// the result of the function below doesn't seem to have eventuated.
// So taking this as a param is possibly something to be removed in favour of the standard default.
$billingLocationID = CRM_Core_BAO_LocationType::getBilling();
}
// Only handle pseudo-profile billing for now.
if ($this->billingProfile == 'billing') {
// @todo - use profile api to retrieve this - either as pseudo-profile or (better) set up billing
// as a reserved profile in the DB and (even better) allow the profile to be selected
// on the form instead of just 'billing for pay=later bool'
return array('first_name' => 'billing_first_name', 'middle_name' => 'billing_middle_name', 'last_name' => 'billing_last_name', 'street_address' => "billing_street_address-{$billingLocationID}", 'city' => "billing_city-{$billingLocationID}", 'country' => "billing_country_id-{$billingLocationID}", 'state_province' => "billing_state_province_id-{$billingLocationID}", 'postal_code' => "billing_postal_code-{$billingLocationID}");
} else {
return array();
}
}
/**
* Register a subscription event. Create a new contact if one does not
* already exist.
*
* @param int $domain_id The domain id of the new subscription
* @param int $group_id The group id to subscribe to
* @param string $email The email address of the (new) contact
* @return int|null $se_id The id of the subscription event, null on failure
* @access public
* @static
*/
function &subscribe($domain_id, $group_id, $email)
{
/* First, find out if the contact already exists */
$params = array('email' => $email, 'domain_id' => $domain_id);
require_once 'CRM/Core/BAO/UFGroup.php';
$contact_id = CRM_Core_BAO_UFGroup::findContact($params);
CRM_Core_DAO::transaction('BEGIN');
if (is_a($contact_id, CRM_Core_Error)) {
require_once 'CRM/Core/BAO/LocationType.php';
/* If the contact does not exist, create one. */
$formatted = array('contact_type' => 'Individual');
$value = array('email' => $email, 'location_type' => CRM_Core_BAO_LocationType::getDefaultID());
_crm_add_formatted_param($value, $formatted);
$contact =& crm_create_contact_formatted($formatted, CRM_IMPORT_PARSER_DUPLICATE_SKIP);
if (is_a($contact, CRM_Core_Error)) {
return null;
}
$contact_id = $contact->id;
}
require_once 'CRM/Core/BAO/Email.php';
require_once 'CRM/Core/BAO/Location.php';
require_once 'CRM/Contact/BAO/Contact.php';
/* Get the primary email id from the contact to use as a hash input */
$dao =& new CRM_Core_DAO();
$emailTable = CRM_Core_BAO_Email::getTableName();
$locTable = CRM_Core_BAO_Location::getTableName();
$contactTable = CRM_Contact_BAO_Contact::getTableName();
$dao->query("SELECT {$emailTable}.id as email_id\n FROM {$emailTable}\n INNER JOIN {$locTable}\n ON {$emailTable}.location_id = {$locTable}.id\n WHERE {$emailTable}.is_primary = 1\n AND {$locTable}.is_primary = 1\n AND {$locTable}.entity_table = '{$contactTable}'\n AND {$locTable}.entity_id = " . CRM_Utils_Type::escape($contact_id, 'Integer'));
$dao->fetch();
$se =& new CRM_Mailing_Event_BAO_Subscribe();
$se->group_id = $group_id;
$se->contact_id = $contact_id;
$se->time_stamp = date('YmdHis');
$se->hash = sha1("{$group_id}:{$contact_id}:{$dao->email_id}");
$se->save();
$contacts = array($contact_id);
require_once 'CRM/Contact/BAO/GroupContact.php';
CRM_Contact_BAO_GroupContact::addContactsToGroup($contacts, $group_id, 'Email', 'Pending', $se->id);
CRM_Core_DAO::transaction('COMMIT');
return $se;
}
/**
* Build the form object.
*
* @return void
*/
public function buildQuickForm()
{
$this->add('hidden', 'gid', $this->_gid);
switch ($this->_mode) {
case self::MODE_CREATE:
case self::MODE_EDIT:
case self::MODE_REGISTER:
CRM_Utils_Hook::buildProfile($this->_ufGroup['name']);
break;
case self::MODE_SEARCH:
CRM_Utils_Hook::searchProfile($this->_ufGroup['name']);
break;
default:
}
//lets have single status message, CRM-4363
$return = FALSE;
$statusMessage = NULL;
if ($this->_multiRecord & CRM_Core_Action::ADD && $this->_maxRecordLimit) {
return;
}
if ($this->_multiRecord & CRM_Core_Action::DELETE) {
if (!$this->_recordExists) {
CRM_Core_Session::setStatus(ts('The record %1 doesnot exists', array(1 => $this->_recordId)), ts('Record doesnot exists'), 'alert');
} else {
$this->assign('deleteRecord', TRUE);
}
return;
}
CRM_Core_BAO_Address::checkContactSharedAddressFields($this->_fields, $this->_id);
// we should not allow component and mix profiles in search mode
if ($this->_mode != self::MODE_REGISTER) {
//check for mix profile fields (eg: individual + other contact type)
if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
if ($this->_mode & self::MODE_EDIT && $this->_isContactActivityProfile) {
$errors = self::validateContactActivityProfile($this->_activityId, $this->_id, $this->_gid);
if (!empty($errors)) {
$statusMessage = array_pop($errors);
$return = TRUE;
}
} else {
$statusMessage = ts('Profile search, view and edit are not supported for Profiles which include fields for more than one record type.');
$return = TRUE;
}
}
$profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
if ($this->_id) {
$contactTypes = CRM_Contact_BAO_Contact::getContactTypes($this->_id);
$contactType = $contactTypes[0];
array_shift($contactTypes);
$contactSubtypes = $contactTypes;
$profileSubType = FALSE;
if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
$profileSubType = $profileType;
$profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
}
if ($profileType != 'Contact' && !$this->_isContactActivityProfile && ($profileSubType && !empty($contactSubtypes) && !in_array($profileSubType, $contactSubtypes) || $profileType != $contactType)) {
$return = TRUE;
if (!$statusMessage) {
$statusMessage = ts("This profile is configured for contact type '%1'. It cannot be used to edit contacts of other types.", array(1 => $profileSubType ? $profileSubType : $profileType));
}
}
}
if (in_array($profileType, array("Membership", "Participant", "Contribution"))) {
$return = TRUE;
if (!$statusMessage) {
$statusMessage = ts('Profile is not configured for the selected action.');
}
}
}
//lets have single status message,
$this->assign('statusMessage', $statusMessage);
if ($return) {
return FALSE;
}
$this->assign('id', $this->_id);
$this->assign('mode', $this->_mode);
$this->assign('action', $this->_action);
$this->assign('fields', $this->_fields);
$this->assign('fieldset', isset($this->_fieldset) ? $this->_fieldset : "");
// should we restrict what we display
$admin = TRUE;
if ($this->_mode == self::MODE_EDIT) {
$admin = FALSE;
// show all fields that are visibile:
// if we are a admin OR the same user OR acl-user with access to the profile
// or we have checksum access to this contact (i.e. the user without a login) - CRM-5909
if (CRM_Core_Permission::check('administer users') || $this->_id == $this->_currentUserID || $this->_isPermissionedChecksum || in_array($this->_gid, CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_uf_group', CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id')))) {
$admin = TRUE;
}
}
// if false, user is not logged-in.
$anonUser = FALSE;
if (!$this->_currentUserID) {
$defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
$primaryLocationType = $defaultLocationType->id;
//.........这里部分代码省略.........
请发表评论