Beispiel #1
0
 /**
  * Build the form object.
  *
  * It consists of
  *    - displaying the QILL (query in local language)
  *    - displaying elements for saving the search
  */
 public function buildQuickForm()
 {
     // @todo sync this more with CRM_Group_Form_Edit.
     $query = new CRM_Contact_BAO_Query($this->get('queryParams'));
     $this->assign('qill', $query->qill());
     // Values from the search form
     $formValues = $this->controller->exportValues();
     // the name and description are actually stored with the group and not the saved search
     $this->add('text', 'title', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'), TRUE);
     $this->addElement('textarea', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description'));
     $groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE);
     unset($groupTypes['Access Control']);
     if (!CRM_Core_Permission::access('CiviMail')) {
         $isWorkFlowEnabled = CRM_Mailing_Info::workflowEnabled();
         if ($isWorkFlowEnabled && !CRM_Core_Permission::check('create mailings') && !CRM_Core_Permission::check('schedule mailings') && !CRM_Core_Permission::check('approve mailings')) {
             unset($groupTypes['Mailing List']);
         }
     }
     if (!empty($groupTypes)) {
         $this->addCheckBox('group_type', ts('Group Type'), $groupTypes, NULL, NULL, NULL, NULL, '   ');
     }
     //CRM-14190
     CRM_Group_Form_Edit::buildParentGroups($this);
     // get the group id for the saved search
     $groupID = NULL;
     if (isset($this->_id)) {
         $groupID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_id, 'id', 'saved_search_id');
         $this->addDefaultButtons(ts('Update Smart Group'));
     } else {
         $this->addDefaultButtons(ts('Save Smart Group'));
         $this->assign('partiallySelected', $formValues['radio_ts'] != 'ts_all');
     }
     $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Group', $groupID, 'title'));
 }
Beispiel #2
0
 static function initTasks()
 {
     if (!self::$_tasks) {
         self::$_tasks = array(1 => array('title' => ts('Add Contacts to Group'), 'class' => 'CRM_Contact_Form_Task_AddToGroup', 'result' => true), 2 => array('title' => ts('Remove Contacts from Group'), 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup', 'result' => true), 3 => array('title' => ts('Tag Contacts (assign tags)'), 'class' => 'CRM_Contact_Form_Task_AddToTag', 'result' => true), 4 => array('title' => ts('Untag Contacts (remove tags)'), 'class' => 'CRM_Contact_Form_Task_RemoveFromTag', 'result' => true), 5 => array('title' => ts('Export Contacts'), 'class' => array('CRM_Export_Form_Select', 'CRM_Export_Form_Map'), 'result' => false), 6 => array('title' => ts('Send Email to Contacts'), 'class' => 'CRM_Contact_Form_Task_Email', 'result' => false), 7 => array('title' => ts('Send SMS to Contacts'), 'class' => 'CRM_Contact_Form_Task_SMS', 'result' => true), 8 => array('title' => ts('Delete Contacts'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => false), 11 => array('title' => ts('Record Activity for Contacts'), 'class' => 'CRM_Activity_Form_Activity', 'result' => true), 13 => array('title' => ts('New Smart Group'), 'class' => 'CRM_Contact_Form_Task_SaveSearch', 'result' => true), 14 => array('title' => ts('Update Smart Group'), 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update', 'result' => true), 15 => array('title' => ts('Print Contacts'), 'class' => 'CRM_Contact_Form_Task_Print', 'result' => false), 16 => array('title' => ts('Mailing Labels'), 'class' => 'CRM_Contact_Form_Task_Label', 'result' => true), 17 => array('title' => ts('Batch Update via Profile'), 'class' => array('CRM_Contact_Form_Task_PickProfile', 'CRM_Contact_Form_Task_Batch'), 'result' => true), 19 => array('title' => ts('Print PDF Letter for Contacts'), 'class' => 'CRM_Contact_Form_Task_PDF', 'result' => true), 21 => array('title' => ts('Merge Contacts'), 'class' => 'CRM_Contact_Form_Task_Merge', 'result' => true));
         if (CRM_Contact_BAO_ContactType::isActive('Household')) {
             $label = CRM_Contact_BAO_ContactType::getLabel('Household');
             self::$_tasks[9] = array('title' => ts('Add Contacts to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToHousehold', 'result' => true);
         }
         if (CRM_Contact_BAO_ContactType::isActive('Organization')) {
             $label = CRM_Contact_BAO_ContactType::getLabel('Organization');
             self::$_tasks[10] = array('title' => ts('Add Contacts to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToOrganization', 'result' => true);
         }
         //CRM-4418, check for delete
         if (!CRM_Core_Permission::check('delete contacts')) {
             unset(self::$_tasks[8]);
         }
         //show map action only if map provider and key is set
         $config =& CRM_Core_Config::singleton();
         if ($config->mapProvider && $config->mapAPIKey) {
             self::$_tasks[12] = array('title' => ts('Map Contacts'), 'class' => 'CRM_Contact_Form_Task_Map', 'result' => false);
         }
         if (CRM_Core_Permission::access('CiviEvent')) {
             self::$_tasks[18] = array('title' => ts('Add Contacts to Event'), 'class' => 'CRM_Event_Form_Participant', 'result' => true);
         }
         if (CRM_Core_Permission::access('CiviMail')) {
             self::$_tasks[20] = array('title' => ts('Schedule/Send a Mass Mailing'), 'class' => array('CRM_Mailing_Form_Group', 'CRM_Mailing_Form_Settings', 'CRM_Mailing_Form_Upload', 'CRM_Mailing_Form_Test', 'CRM_Mailing_Form_Schedule'), 'result' => false);
         }
         self::$_tasks += CRM_Core_Component::taskList();
         require_once 'CRM/Utils/Hook.php';
         CRM_Utils_Hook::searchTasks('contact', self::$_tasks);
         asort(self::$_tasks);
     }
 }
Beispiel #3
0
 /**
  * Class constructor.
  */
 public function __construct()
 {
     // There could be multiple contacts. We not clear on which contact id to display.
     // Lets hide it for now.
     $this->_exposeContactID = FALSE;
     // if navigated from count link of activity summary reports.
     $this->_resetDateFilter = CRM_Utils_Request::retrieve('resetDateFilter', 'Boolean', CRM_Core_DAO::$_nullObject);
     $config = CRM_Core_Config::singleton();
     $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
     $caseEnabled = in_array("CiviCase", $config->enableComponents);
     if ($campaignEnabled) {
         $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
         $this->activeCampaigns = $getCampaigns['campaigns'];
         asort($this->activeCampaigns);
         $this->engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel();
     }
     $components = CRM_Core_Component::getEnabledComponents();
     foreach ($components as $componentName => $componentInfo) {
         // CRM-19201: Add support for reporting CiviCampaign activities
         // For CiviCase, "access all cases and activities" is required here
         // rather than "access my cases and activities" to prevent those with
         // only the later permission from seeing a list of all cases which might
         // present a privacy issue.
         if (CRM_Core_Permission::access($componentName, TRUE, TRUE)) {
             $accessAllowed[] = $componentInfo->componentID;
         }
     }
     $include = '';
     if (!empty($accessAllowed)) {
         $include = 'OR v.component_id IN (' . implode(', ', $accessAllowed) . ')';
     }
     $condition = " AND ( v.component_id IS NULL {$include} )";
     $this->activityTypes = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, $condition);
     asort($this->activityTypes);
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('contact_source' => array('name' => 'sort_name', 'title' => ts('Source Name'), 'alias' => 'civicrm_contact_source', 'no_repeat' => TRUE), 'contact_assignee' => array('name' => 'sort_name', 'title' => ts('Assignee Name'), 'alias' => 'civicrm_contact_assignee', 'dbAlias' => "civicrm_contact_assignee.sort_name", 'default' => TRUE), 'contact_target' => array('name' => 'sort_name', 'title' => ts('Target Name'), 'alias' => 'civicrm_contact_target', 'dbAlias' => "civicrm_contact_target.sort_name", 'default' => TRUE), 'contact_source_id' => array('name' => 'id', 'alias' => 'civicrm_contact_source', 'dbAlias' => "civicrm_contact_source.id", 'no_display' => TRUE, 'default' => TRUE, 'required' => TRUE), 'contact_assignee_id' => array('name' => 'id', 'alias' => 'civicrm_contact_assignee', 'dbAlias' => "civicrm_contact_assignee.id", 'no_display' => TRUE, 'default' => TRUE, 'required' => TRUE), 'contact_target_id' => array('name' => 'id', 'alias' => 'civicrm_contact_target', 'dbAlias' => "civicrm_contact_target.id", 'no_display' => TRUE, 'default' => TRUE, 'required' => TRUE)), 'filters' => array('contact_source' => array('name' => 'sort_name', 'alias' => 'civicrm_contact_source', 'title' => ts('Source Name'), 'operator' => 'like', 'type' => CRM_Report_Form::OP_STRING), 'contact_assignee' => array('name' => 'sort_name', 'alias' => 'civicrm_contact_assignee', 'title' => ts('Assignee Name'), 'operator' => 'like', 'type' => CRM_Report_Form::OP_STRING), 'contact_target' => array('name' => 'sort_name', 'alias' => 'civicrm_contact_target', 'title' => ts('Target Name'), 'operator' => 'like', 'type' => CRM_Report_Form::OP_STRING), 'current_user' => array('name' => 'current_user', 'title' => ts('Limit To Current User'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => array('0' => ts('No'), '1' => ts('Yes')))), 'grouping' => 'contact-fields'), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('contact_source_email' => array('name' => 'email', 'title' => ts('Source Email'), 'alias' => 'civicrm_email_source'), 'contact_assignee_email' => array('name' => 'email', 'title' => ts('Assignee Email'), 'alias' => 'civicrm_email_assignee'), 'contact_target_email' => array('name' => 'email', 'title' => ts('Target Email'), 'alias' => 'civicrm_email_target')), 'order_bys' => array('source_contact_email' => array('name' => 'email', 'title' => ts('Source Email'), 'dbAlias' => 'civicrm_email_contact_source_email'))), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('contact_source_phone' => array('name' => 'phone', 'title' => ts('Source Phone'), 'alias' => 'civicrm_phone_source'), 'contact_assignee_phone' => array('name' => 'phone', 'title' => ts('Assignee Phone'), 'alias' => 'civicrm_phone_assignee'), 'contact_target_phone' => array('name' => 'phone', 'title' => ts('Target Phone'), 'alias' => 'civicrm_phone_target'))), 'civicrm_activity' => array('dao' => 'CRM_Activity_DAO_Activity', 'fields' => array('id' => array('no_display' => TRUE, 'title' => ts('Activity ID'), 'required' => TRUE), 'source_record_id' => array('no_display' => TRUE, 'required' => TRUE), 'activity_type_id' => array('title' => ts('Activity Type'), 'required' => TRUE, 'type' => CRM_Utils_Type::T_STRING), 'activity_subject' => array('title' => ts('Subject'), 'default' => TRUE), 'activity_date_time' => array('title' => ts('Activity Date'), 'required' => TRUE), 'status_id' => array('title' => ts('Activity Status'), 'default' => TRUE, 'type' => CRM_Utils_Type::T_STRING), 'duration' => array('title' => ts('Duration'), 'type' => CRM_Utils_Type::T_INT), 'details' => array('title' => ts('Activity Details'))), 'filters' => array('activity_date_time' => array('default' => 'this.month', 'operatorType' => CRM_Report_Form::OP_DATE), 'activity_subject' => array('title' => ts('Activity Subject')), 'activity_type_id' => array('title' => ts('Activity Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->activityTypes), 'status_id' => array('title' => ts('Activity Status'), 'type' => CRM_Utils_Type::T_STRING, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::activityStatus()), 'details' => array('title' => ts('Activity Details'), 'type' => CRM_Utils_Type::T_TEXT)), 'order_bys' => array('activity_date_time' => array('title' => ts('Activity Date'), 'default_weight' => '1', 'dbAlias' => 'civicrm_activity_activity_date_time'), 'activity_type_id' => array('title' => ts('Activity Type'), 'default_weight' => '2', 'dbAlias' => 'field(civicrm_activity_activity_type_id, ' . implode(', ', array_keys($this->activityTypes)) . ')')), 'grouping' => 'activity-fields', 'alias' => 'activity'), 'civicrm_activity_contact' => array('dao' => 'CRM_Activity_DAO_ActivityContact', 'fields' => array())) + $this->addressFields(TRUE);
     if ($caseEnabled && CRM_Core_Permission::check('access all cases and activities')) {
         $this->_columns['civicrm_activity']['filters']['include_case_activities'] = array('name' => 'include_case_activities', 'title' => ts('Include Case Activities'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => array('0' => ts('No'), '1' => ts('Yes')));
     }
     if ($campaignEnabled) {
         // Add display column and filter for Survey Results, Campaign and Engagement Index if CiviCampaign is enabled
         $this->_columns['civicrm_activity']['fields']['result'] = array('title' => ts('Survey Result'), 'default' => 'false');
         $this->_columns['civicrm_activity']['filters']['result'] = array('title' => ts('Survey Result'), 'operator' => 'like', 'type' => CRM_Utils_Type::T_STRING);
         if (!empty($this->activeCampaigns)) {
             $this->_columns['civicrm_activity']['fields']['campaign_id'] = array('title' => ts('Campaign'), 'default' => 'false');
             $this->_columns['civicrm_activity']['filters']['campaign_id'] = array('title' => ts('Campaign'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->activeCampaigns);
         }
         if (!empty($this->engagementLevels)) {
             $this->_columns['civicrm_activity']['fields']['engagement_level'] = array('title' => ts('Engagement Index'), 'default' => 'false');
             $this->_columns['civicrm_activity']['filters']['engagement_level'] = array('title' => ts('Engagement Index'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->engagementLevels);
         }
     }
     $this->_groupFilter = TRUE;
     $this->_tagFilter = TRUE;
     $this->_tagFilterTable = 'civicrm_activity';
     parent::__construct();
 }
 /**
  * Process the form.
  *
  * @return void
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     // Process / save contact info
     $params['contact_type'] = $this->_contactType;
     $params['contact_id'] = $this->_contactId;
     if (!empty($this->_contactSubType)) {
         $params['contact_sub_type'] = $this->_contactSubType;
     }
     CRM_Contact_BAO_Contact::create($params);
     // Saving current employer affects relationship tab, and possibly related memberships and contributions
     $this->ajaxResponse['updateTabs'] = array('#tab_rel' => CRM_Contact_BAO_Contact::getCountComponent('rel', $this->_contactId));
     if (CRM_Core_Permission::access('CiviContribute')) {
         $this->ajaxResponse['updateTabs']['#tab_contribute'] = CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId);
     }
     if (CRM_Core_Permission::access('CiviMember')) {
         $this->ajaxResponse['updateTabs']['#tab_member'] = CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId);
     }
     $this->response();
 }
Beispiel #5
0
 public static function initTasks()
 {
     if (!self::$_tasks) {
         self::$_tasks = array(self::GROUP_CONTACTS => array('title' => ts('Group - add contacts'), 'class' => 'CRM_Contact_Form_Task_AddToGroup'), self::REMOVE_CONTACTS => array('title' => ts('Group - remove contacts'), 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup'), self::TAG_CONTACTS => array('title' => ts('Tag - add to contacts'), 'class' => 'CRM_Contact_Form_Task_AddToTag'), self::REMOVE_TAGS => array('title' => ts('Tag - remove from contacts'), 'class' => 'CRM_Contact_Form_Task_RemoveFromTag'), self::EXPORT_CONTACTS => array('title' => ts('Export contacts'), 'class' => array('CRM_Export_Form_Select', 'CRM_Export_Form_Map'), 'result' => FALSE), self::EMAIL_CONTACTS => array('title' => ts('Email - send now (to 50 or less)'), 'class' => 'CRM_Contact_Form_Task_Email', 'result' => TRUE), self::DELETE_CONTACTS => array('title' => ts('Delete contacts'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE), self::RECORD_CONTACTS => array('title' => ts('Add activity'), 'class' => 'CRM_Activity_Form_Activity'), self::SAVE_SEARCH => array('title' => ts('Smart group - create'), 'class' => 'CRM_Contact_Form_Task_SaveSearch', 'result' => TRUE), self::SAVE_SEARCH_UPDATE => array('title' => ts('Smart group - update'), 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update', 'result' => TRUE), self::PRINT_CONTACTS => array('title' => ts('Print selected rows'), 'class' => 'CRM_Contact_Form_Task_Print', 'result' => FALSE), self::LABEL_CONTACTS => array('title' => ts('Mailing labels - print'), 'class' => 'CRM_Contact_Form_Task_Label', 'result' => TRUE), self::BATCH_UPDATE => array('title' => ts('Batch update contacts via profile'), 'class' => array('CRM_Contact_Form_Task_PickProfile', 'CRM_Contact_Form_Task_Batch'), 'result' => TRUE), self::PRINT_FOR_CONTACTS => array('title' => ts('PDF letters - print'), 'class' => 'CRM_Contact_Form_Task_PDF', 'result' => TRUE), self::EMAIL_UNHOLD => array('title' => ts('Email - unhold addresses'), 'class' => 'CRM_Contact_Form_Task_Unhold'), self::COMMUNICATION_PREFS => array('title' => ts('Communication preferences - alter'), 'class' => 'CRM_Contact_Form_Task_AlterPreferences'), self::RESTORE => array('title' => ts('Restore contacts from trash'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE), self::DELETE_PERMANENTLY => array('title' => ts('Delete permanently'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE));
         //CRM-16329, if SMS provider is configured show sms action.
         $providersCount = CRM_SMS_BAO_Provider::activeProviderCount();
         if ($providersCount) {
             self::$_tasks[self::SMS_CONTACTS] = array('title' => ts('SMS - schedule/send'), 'class' => 'CRM_Contact_Form_Task_SMS', 'result' => TRUE);
         }
         if (CRM_Contact_BAO_ContactType::isActive('Household')) {
             $label = CRM_Contact_BAO_ContactType::getLabel('household');
             self::$_tasks[self::HOUSEHOLD_CONTACTS] = array('title' => ts('Add relationship - to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToHousehold');
         }
         if (CRM_Contact_BAO_ContactType::isActive('Organization')) {
             $label = CRM_Contact_BAO_ContactType::getLabel('organization');
             self::$_tasks[self::ORGANIZATION_CONTACTS] = array('title' => ts('Add relationship - to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToOrganization');
         }
         if (CRM_Core_Permission::check('merge duplicate contacts')) {
             self::$_tasks[self::MERGE_CONTACTS] = array('title' => ts('Merge contacts'), 'class' => 'CRM_Contact_Form_Task_Merge', 'result' => TRUE);
         }
         //CRM-4418, check for delete
         if (!CRM_Core_Permission::check('delete contacts')) {
             unset(self::$_tasks[self::DELETE_CONTACTS]);
         }
         //show map action only if map provider and geoprovider are set (Google doesn't need geoprovider)
         // should fix this to be more flexible as providers are added ??
         $config = CRM_Core_Config::singleton();
         if ($config->mapProvider && ($config->mapProvider == 'Google' || ($config->mapProvider == 'OpenStreetMaps' || $config->geoProvider == 'Google'))) {
             self::$_tasks[self::MAP_CONTACTS] = array('title' => ts('Map contacts'), 'class' => 'CRM_Contact_Form_Task_Map', 'result' => FALSE);
         }
         if (CRM_Core_Permission::access('CiviEvent')) {
             self::$_tasks[self::ADD_EVENT] = array('title' => ts('Register participants for event'), 'class' => 'CRM_Event_Form_Participant');
         }
         if (CRM_Core_Permission::access('CiviMail') || CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings')) {
             self::$_tasks[self::CREATE_MAILING] = array('title' => ts('Email - schedule/send via CiviMail'), 'class' => 'CRM_Mailing_Form_Task_AdhocMailing', 'result' => FALSE);
         }
         self::$_tasks += CRM_Core_Component::taskList();
         CRM_Utils_Hook::searchTasks('contact', self::$_tasks);
         asort(self::$_tasks);
     }
 }
Beispiel #6
0
 /**
  * The initializer code, called before the processing
  */
 public function init()
 {
     $fields = CRM_Contribute_BAO_Contribution::importableFields($this->_contactType, FALSE);
     $fields = array_merge($fields, array('soft_credit' => array('title' => ts('Soft Credit'), 'softCredit' => TRUE, 'headerPattern' => '/Soft Credit/i')));
     // add pledge fields only if its is enabled
     if (CRM_Core_Permission::access('CiviPledge')) {
         $pledgeFields = array('pledge_payment' => array('title' => ts('Pledge Payment'), 'headerPattern' => '/Pledge Payment/i'), 'pledge_id' => array('title' => ts('Pledge ID'), 'headerPattern' => '/Pledge ID/i'));
         $fields = array_merge($fields, $pledgeFields);
     }
     foreach ($fields as $name => $field) {
         $field['type'] = CRM_Utils_Array::value('type', $field, CRM_Utils_Type::T_INT);
         $field['dataPattern'] = CRM_Utils_Array::value('dataPattern', $field, '//');
         $field['headerPattern'] = CRM_Utils_Array::value('headerPattern', $field, '//');
         $this->addField($name, $field['title'], $field['type'], $field['headerPattern'], $field['dataPattern']);
     }
     $this->_newContributions = array();
     $this->setActiveFields($this->_mapperKeys);
     $this->setActiveFieldSoftCredit($this->_mapperSoftCredit);
     $this->setActiveFieldSoftCreditType($this->_mapperSoftCreditType);
     // FIXME: we should do this in one place together with Form/MapField.php
     $this->_contactIdIndex = -1;
     $this->_totalAmountIndex = -1;
     $this->_contributionTypeIndex = -1;
     $index = 0;
     foreach ($this->_mapperKeys as $key) {
         switch ($key) {
             case 'contribution_contact_id':
                 $this->_contactIdIndex = $index;
                 break;
             case 'total_amount':
                 $this->_totalAmountIndex = $index;
                 break;
             case 'financial_type':
                 $this->_contributionTypeIndex = $index;
                 break;
         }
         $index++;
     }
 }
Beispiel #7
0
 function run()
 {
     require_once 'CRM/Utils/Request.php';
     require_once 'CRM/Core/DAO.php';
     $eid = CRM_Utils_Request::retrieve('eid', 'Positive', $this, true);
     $fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, false);
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, true);
     $quest = CRM_Utils_Request::retrieve('quest', 'String', $this);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this);
     require_once 'CRM/Core/BAO/File.php';
     list($path, $mimeType) = CRM_Core_BAO_File::path($id, $eid, null, $quest);
     if (!$path) {
         CRM_Core_Error::statusBounce('Could not retrieve the file');
     }
     $buffer = file_get_contents($path);
     if (!$buffer) {
         CRM_Core_Error::statusBounce('The file is either empty or you do not have permission to retrieve the file');
     }
     if ($action & CRM_Core_Action::DELETE) {
         if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', CRM_Core_DAO::$_nullObject)) {
             CRM_Core_BAO_File::delete($id, $eid, $fid);
             CRM_Core_Session::setStatus(ts('The attached file has been deleted.'));
             $session =& CRM_Core_Session::singleton();
             $toUrl = $session->popUserContext();
             CRM_Utils_System::redirect($toUrl);
         } else {
             $wrapper =& new CRM_Utils_Wrapper();
             return $wrapper->run('CRM_Custom_Form_DeleteFile', ts('Domain Information Page'), null);
         }
     } else {
         if (CRM_Core_Permission::access('Gcc')) {
             // hack file name for gcc
             require_once 'CRM/Gcc/Form/File.php';
             $path = CRM_Gcc_Form_File::getFileName($path);
         }
         CRM_Utils_System::download(basename($path), $mimeType, $buffer);
     }
 }
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     //create radio buttons to select existing group or add a new group
     $options = array(ts('Add Contact To Existing Group'), ts('Create New Group'));
     if (!$this->_id) {
         $this->addRadio('group_option', ts('Group Options'), $options, array('onclick' => "return showElements();"));
         $this->add('text', 'title', ts('Group Name:') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'));
         $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Group', $this->_id, 'title'));
         $this->add('textarea', 'description', ts('Description:') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description'));
         $groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE);
         if (!CRM_Core_Permission::access('CiviMail')) {
             $isWorkFlowEnabled = CRM_Mailing_Info::workflowEnabled();
             if ($isWorkFlowEnabled && !CRM_Core_Permission::check('create mailings') && !CRM_Core_Permission::check('schedule mailings') && !CRM_Core_Permission::check('approve mailings')) {
                 unset($groupTypes['Mailing List']);
             }
         }
         if (!empty($groupTypes)) {
             $this->addCheckBox('group_type', ts('Group Type'), $groupTypes, NULL, NULL, NULL, NULL, '   ');
         }
     }
     // add select for groups
     $group = array('' => ts('- select group -')) + CRM_Core_PseudoConstant::nestedGroup();
     $groupElement = $this->add('select', 'group_id', ts('Select Group'), $group, FALSE, array('class' => 'crm-select2 huge'));
     $this->_title = $group[$this->_id];
     if ($this->_context === 'amtg') {
         $groupElement->freeze();
         // also set the group title
         $groupValues = array('id' => $this->_id, 'title' => $this->_title);
         $this->assign_by_ref('group', $groupValues);
     }
     // Set dynamic page title for 'Add Members Group (confirm)'
     if ($this->_id) {
         CRM_Utils_System::setTitle(ts('Add Contacts: %1', array(1 => $this->_title)));
     } else {
         CRM_Utils_System::setTitle(ts('Add Contacts to A Group'));
     }
     $this->addDefaultButtons(ts('Add to Group'));
 }
Beispiel #9
0
 static function initTasks()
 {
     if (!self::$_tasks) {
         self::$_tasks = array(1 => array('title' => ts('Add Contacts to Group'), 'class' => 'CRM_Contact_Form_Task_AddToGroup'), 2 => array('title' => ts('Remove Contacts from Group'), 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup'), 3 => array('title' => ts('Tag Contacts (assign tags)'), 'class' => 'CRM_Contact_Form_Task_AddToTag'), 4 => array('title' => ts('Untag Contacts (remove tags)'), 'class' => 'CRM_Contact_Form_Task_RemoveFromTag'), 5 => array('title' => ts('Export Contacts'), 'class' => array('CRM_Export_Form_Select', 'CRM_Export_Form_Map'), 'result' => FALSE), 6 => array('title' => ts('Send Email to Contacts'), 'class' => 'CRM_Contact_Form_Task_Email', 'result' => TRUE), 7 => array('title' => ts('Send SMS to Contacts'), 'class' => 'CRM_Contact_Form_Task_SMS', 'result' => TRUE), 8 => array('title' => ts('Delete Contacts'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE), 11 => array('title' => ts('Record Activity for Contacts'), 'class' => 'CRM_Activity_Form_Activity'), 13 => array('title' => ts('New Smart Group'), 'class' => 'CRM_Contact_Form_Task_SaveSearch', 'result' => TRUE), 14 => array('title' => ts('Update Smart Group'), 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update', 'result' => TRUE), 15 => array('title' => ts('Print Contacts'), 'class' => 'CRM_Contact_Form_Task_Print', 'result' => FALSE), 16 => array('title' => ts('Mailing Labels'), 'class' => 'CRM_Contact_Form_Task_Label', 'result' => TRUE), 17 => array('title' => ts('Batch Update via Profile'), 'class' => array('CRM_Contact_Form_Task_PickProfile', 'CRM_Contact_Form_Task_Batch'), 'result' => TRUE), 19 => array('title' => ts('Print PDF Letter for Contacts'), 'class' => 'CRM_Contact_Form_Task_PDF', 'result' => TRUE), 22 => array('title' => ts('Unhold Emails'), 'class' => 'CRM_Contact_Form_Task_Unhold'), 25 => array('title' => ts('Alter Contact Communication Preferences'), 'class' => 'CRM_Contact_Form_Task_AlterPreferences'), self::RESTORE => array('title' => ts('Restore Contacts'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE), self::DELETE_PERMANENTLY => array('title' => ts('Delete Permanently'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE));
         if (CRM_Contact_BAO_ContactType::isActive('Household')) {
             $label = CRM_Contact_BAO_ContactType::getLabel('Household');
             self::$_tasks[9] = array('title' => ts('Add Contacts to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToHousehold');
         }
         if (CRM_Contact_BAO_ContactType::isActive('Organization')) {
             $label = CRM_Contact_BAO_ContactType::getLabel('Organization');
             self::$_tasks[10] = array('title' => ts('Add Contacts to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToOrganization');
         }
         if (CRM_Core_Permission::check('merge duplicate contacts')) {
             self::$_tasks[21] = array('title' => ts('Merge Contacts'), 'class' => 'CRM_Contact_Form_Task_Merge', 'result' => TRUE);
         }
         //CRM-4418, check for delete
         if (!CRM_Core_Permission::check('delete contacts')) {
             unset(self::$_tasks[8]);
         }
         //show map action only if map provider and geoprovider are set (Google doesn't need geoprovider)
         // should fix this to be more flexible as providers are added ??
         $config = CRM_Core_Config::singleton();
         if ($config->mapProvider && ($config->mapProvider == 'Google' || ($config->mapProvider == 'OpenStreetMaps' || $config->geoProvider == 'Google'))) {
             self::$_tasks[12] = array('title' => ts('Map Contacts'), 'class' => 'CRM_Contact_Form_Task_Map', 'result' => FALSE);
         }
         if (CRM_Core_Permission::access('CiviEvent')) {
             self::$_tasks[18] = array('title' => ts('Add Contacts to Event'), 'class' => 'CRM_Event_Form_Participant');
         }
         if (CRM_Core_Permission::access('CiviMail')) {
             self::$_tasks[20] = array('title' => ts('Schedule/Send a Mass Mailing'), 'class' => array('CRM_Mailing_Form_Group', 'CRM_Mailing_Form_Settings', 'CRM_Mailing_Form_Upload', 'CRM_Mailing_Form_Test', 'CRM_Mailing_Form_Schedule'), 'result' => FALSE);
         } elseif (CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings')) {
             self::$_tasks[20] = array('title' => ts('Create a Mass Mailing'), 'class' => array('CRM_Mailing_Form_Group', 'CRM_Mailing_Form_Settings', 'CRM_Mailing_Form_Upload', 'CRM_Mailing_Form_Test'), 'result' => FALSE);
         }
         self::$_tasks += CRM_Core_Component::taskList();
         CRM_Utils_Hook::searchTasks('contact', self::$_tasks);
         asort(self::$_tasks);
     }
 }
Beispiel #10
0
 static function initTasks()
 {
     if (!self::$_tasks) {
         self::$_tasks = array(self::GROUP_CONTACTS => array('title' => ts('Add Contacts to Group'), 'class' => 'CRM_Contact_Form_Task_AddToGroup'), self::REMOVE_CONTACTS => array('title' => ts('Remove Contacts from Group'), 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup'), self::TAG_CONTACTS => array('title' => ts('Tag Contacts (assign tags)'), 'class' => 'CRM_Contact_Form_Task_AddToTag'), self::REMOVE_TAGS => array('title' => ts('Untag Contacts (remove tags)'), 'class' => 'CRM_Contact_Form_Task_RemoveFromTag'), self::EXPORT_CONTACTS => array('title' => ts('Export Contacts'), 'class' => array('CRM_Export_Form_Select', 'CRM_Export_Form_Map'), 'result' => FALSE), self::EMAIL_CONTACTS => array('title' => ts('Send Email to Contacts'), 'class' => 'CRM_Contact_Form_Task_Email', 'result' => TRUE), self::SMS_CONTACTS => array('title' => ts('Send SMS to Contacts'), 'class' => 'CRM_Contact_Form_Task_SMS', 'result' => TRUE), self::DELETE_CONTACTS => array('title' => ts('Delete Contacts'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE), self::RECORD_CONTACTS => array('title' => ts('Record Activity for Contacts'), 'class' => 'CRM_Activity_Form_Activity'), self::SAVE_SEARCH => array('title' => ts('New Smart Group'), 'class' => 'CRM_Contact_Form_Task_SaveSearch', 'result' => TRUE), self::SAVE_SEARCH_UPDATE => array('title' => ts('Update Smart Group'), 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update', 'result' => TRUE), self::PRINT_CONTACTS => array('title' => ts('Print Selected Rows'), 'class' => 'CRM_Contact_Form_Task_Print', 'result' => FALSE), self::LABEL_CONTACTS => array('title' => ts('Mailing Labels'), 'class' => 'CRM_Contact_Form_Task_Label', 'result' => TRUE), self::BATCH_UPDATE => array('title' => ts('Batch Update via Profile'), 'class' => array('CRM_Contact_Form_Task_PickProfile', 'CRM_Contact_Form_Task_Batch'), 'result' => TRUE), self::PRINT_FOR_CONTACTS => array('title' => ts('Print PDF Letter for Contacts'), 'class' => 'CRM_Contact_Form_Task_PDF', 'result' => TRUE), self::EMAIL_UNHOLD => array('title' => ts('Unhold Emails'), 'class' => 'CRM_Contact_Form_Task_Unhold'), self::COMMUNICATION_PREFS => array('title' => ts('Alter Contact Communication Preferences'), 'class' => 'CRM_Contact_Form_Task_AlterPreferences'), self::RESTORE => array('title' => ts('Restore Contacts'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE), self::DELETE_PERMANENTLY => array('title' => ts('Delete Permanently'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE));
         if (CRM_Contact_BAO_ContactType::isActive('Household')) {
             $label = CRM_Contact_BAO_ContactType::getLabel('Household');
             self::$_tasks[self::HOUSEHOLD_CONTACTS] = array('title' => ts('Add Contacts to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToHousehold');
         }
         if (CRM_Contact_BAO_ContactType::isActive('Organization')) {
             $label = CRM_Contact_BAO_ContactType::getLabel('Organization');
             self::$_tasks[self::ORGANIZATION_CONTACTS] = array('title' => ts('Add Contacts to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToOrganization');
         }
         if (CRM_Core_Permission::check('merge duplicate contacts')) {
             self::$_tasks[self::MERGE_CONTACTS] = array('title' => ts('Merge Contacts'), 'class' => 'CRM_Contact_Form_Task_Merge', 'result' => TRUE);
         }
         //CRM-4418, check for delete
         if (!CRM_Core_Permission::check('delete contacts')) {
             unset(self::$_tasks[self::DELETE_CONTACTS]);
         }
         //show map action only if map provider and geoprovider are set (Google doesn't need geoprovider)
         // should fix this to be more flexible as providers are added ??
         $config = CRM_Core_Config::singleton();
         if ($config->mapProvider && ($config->mapProvider == 'Google' || ($config->mapProvider == 'OpenStreetMaps' || $config->geoProvider == 'Google'))) {
             self::$_tasks[self::MAP_CONTACTS] = array('title' => ts('Map Contacts'), 'class' => 'CRM_Contact_Form_Task_Map', 'result' => FALSE);
         }
         if (CRM_Core_Permission::access('CiviEvent')) {
             self::$_tasks[self::ADD_EVENT] = array('title' => ts('Add Contacts to Event'), 'class' => 'CRM_Event_Form_Participant');
         }
         if (CRM_Core_Permission::access('CiviMail')) {
             self::$_tasks[self::CREATE_MAILING] = array('title' => ts('Schedule/Send a Mass Mailing'), 'class' => array('CRM_Mailing_Form_Group', 'CRM_Mailing_Form_Settings', 'CRM_Mailing_Form_Upload', 'CRM_Mailing_Form_Test', 'CRM_Mailing_Form_Schedule'), 'result' => FALSE);
         } elseif (CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings')) {
             self::$_tasks[self::CREATE_MAILING] = array('title' => ts('Create a Mass Mailing'), 'class' => array('CRM_Mailing_Form_Group', 'CRM_Mailing_Form_Settings', 'CRM_Mailing_Form_Upload', 'CRM_Mailing_Form_Test'), 'result' => FALSE);
         }
         self::$_tasks += CRM_Core_Component::taskList();
         CRM_Utils_Hook::searchTasks('contact', self::$_tasks);
         asort(self::$_tasks);
     }
 }
Beispiel #11
0
 /**
  * the initializer code, called before the processing
  *
  * @return void
  * @access public
  */
 function init()
 {
     require_once 'CRM/Contribute/BAO/Contribution.php';
     $fields =& CRM_Contribute_BAO_Contribution::importableFields($this->_contactType, false);
     $fields = array_merge($fields, array('soft_credit' => array('title' => ts('Soft Credit'), 'softCredit' => true, 'headerPattern' => '/Soft Credit/i')));
     // add pledge fields only if its is enabled
     if (CRM_Core_Permission::access('CiviPledge')) {
         $pledgeFields = array('pledge_payment' => array('title' => ts('Pledge Payment'), 'headerPattern' => '/Pledge Payment/i'), 'pledge_id' => array('title' => ts('Pledge ID'), 'headerPattern' => '/Pledge ID/i'));
         $fields = array_merge($fields, $pledgeFields);
     }
     foreach ($fields as $name => $field) {
         $this->addField($name, $field['title'], $field['type'], $field['headerPattern'], $field['dataPattern']);
     }
     $this->_newContributions = array();
     $this->setActiveFields($this->_mapperKeys);
     $this->setActiveFieldSoftCredit($this->_mapperSoftCredit);
     // FIXME: we should do this in one place together with Form/MapField.php
     $this->_contactIdIndex = -1;
     $this->_totalAmountIndex = -1;
     $this->_contributionTypeIndex = -1;
     $index = 0;
     foreach ($this->_mapperKeys as $key) {
         switch ($key) {
             case 'contribution_contact_id':
                 $this->_contactIdIndex = $index;
                 break;
             case 'total_amount':
                 $this->_totalAmountIndex = $index;
                 break;
             case 'contribution_type':
                 $this->_contributionTypeIndex = $index;
                 break;
         }
         $index++;
     }
 }
Beispiel #12
0
 /**
  * Function to set profile defaults
  *
  * @params int     $contactId      contact id
  * @params array   $fields         associative array of fields
  * @params array   $defaults       defaults array
  * @params boolean $singleProfile  true for single profile else false(batch update)
  * @params int     $componentId    id for specific components like contribute, event etc
  *
  * @return null
  * @static
  * @access public
  */
 static function setProfileDefaults($contactId, &$fields, &$defaults, $singleProfile = true, $componentId = null, $component = null)
 {
     if (!$componentId) {
         //get the contact details
         require_once 'CRM/Contact/BAO/Contact.php';
         list($contactDetails, $options) = CRM_Contact_BAO_Contact::getHierContactDetails($contactId, $fields);
         $details = $contactDetails[$contactId];
         require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php';
         //start of code to set the default values
         foreach ($fields as $name => $field) {
             //set the field name depending upon the profile mode(single/batch)
             if ($singleProfile) {
                 $fldName = $name;
             } else {
                 $fldName = "field[{$contactId}][{$name}]";
             }
             if ($name == 'group') {
                 CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, $fldName);
             }
             if ($name == 'tag') {
                 CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::TAG, $fldName);
             }
             if (CRM_Utils_Array::value($name, $details) || isset($details[$name])) {
                 //to handle custom data (checkbox) to be written
                 // to handle gender / suffix / prefix / greeting_type
                 if ($name == 'gender') {
                     $defaults[$fldName] = $details['gender_id'];
                 } else {
                     if ($name == 'individual_prefix') {
                         $defaults[$fldName] = $details['individual_prefix_id'];
                     } else {
                         if ($name == 'individual_suffix') {
                             $defaults[$fldName] = $details['individual_suffix_id'];
                         } else {
                             if ($name == 'birth_date' || $name == 'deceased_date') {
                                 list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], 'birth');
                             } else {
                                 if ($name == 'email_greeting') {
                                     $defaults[$fldName] = $details['email_greeting_id'];
                                     $defaults['email_greeting_custom'] = $details['email_greeting_custom'];
                                 } else {
                                     if ($name == 'postal_greeting') {
                                         $defaults[$fldName] = $details['postal_greeting_id'];
                                         $defaults['postal_greeting_custom'] = $details['postal_greeting_custom'];
                                     } else {
                                         if ($name == 'addressee') {
                                             $defaults[$fldName] = $details['addressee_id'];
                                             $defaults['addressee_custom'] = $details['addressee_custom'];
                                         } else {
                                             if ($name == 'preferred_communication_method') {
                                                 $v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]);
                                                 foreach ($v as $item) {
                                                     if ($item) {
                                                         $defaults[$fldName . "[{$item}]"] = 1;
                                                     }
                                                 }
                                             } else {
                                                 if ($name == 'world_region') {
                                                     $defaults[$fldName] = $details['worldregion_id'];
                                                 } else {
                                                     if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($name)) {
                                                         //fix for custom fields
                                                         $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('Individual', $values));
                                                         // hack to add custom data for components
                                                         $components = array("Contribution", "Participant", "Membership");
                                                         foreach ($components as $value) {
                                                             $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFieldsForImport($value));
                                                         }
                                                         switch ($customFields[$customFieldId]['html_type']) {
                                                             case 'Multi-Select State/Province':
                                                             case 'Multi-Select Country':
                                                             case 'AdvMulti-Select':
                                                             case 'Multi-Select':
                                                                 $v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]);
                                                                 foreach ($v as $item) {
                                                                     if ($item) {
                                                                         $defaults[$fldName][$item] = $item;
                                                                     }
                                                                 }
                                                                 break;
                                                             case 'CheckBox':
                                                                 $v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]);
                                                                 foreach ($v as $item) {
                                                                     if ($item) {
                                                                         $defaults[$fldName][$item] = 1;
                                                                         // seems like we need this for QF style checkboxes in profile where its multiindexed
                                                                         // CRM-2969
                                                                         $defaults["{$fldName}[{$item}]"] = 1;
                                                                     }
                                                                 }
                                                                 break;
                                                             case 'Autocomplete-Select':
                                                                 if ($customFields[$customFieldId]['data_type'] == "ContactReference") {
                                                                     require_once 'CRM/Contact/BAO/Contact.php';
                                                                     if (is_numeric($details[$name])) {
                                                                         $defaults[$fldName . '_id'] = $details[$name];
                                                                         $defaults[$fldName] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $details[$name], 'sort_name');
                                                                     }
                                                                 } else {
                                                                     $label = CRM_Core_BAO_CustomOption::getOptionLabel($customFieldId, $details[$name]);
                                                                     $defaults[$fldName . '_id'] = $details[$name];
                                                                     $defaults[$fldName] = $label;
                                                                 }
                                                                 break;
                                                             case 'Select Date':
                                                                 list($defaults[$fldName], $defaults[substr($fldName, 0, -1) . '_time]']) = CRM_Utils_Date::setDateDefaults($details[$name]);
                                                                 break;
                                                             default:
                                                                 $defaults[$fldName] = $details[$name];
                                                                 break;
                                                         }
                                                     } else {
                                                         $defaults[$fldName] = $details[$name];
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             } else {
                 list($fieldName, $locTypeId, $phoneTypeId) = CRM_Utils_System::explode('-', $name, 3);
                 if (is_array($details)) {
                     foreach ($details as $key => $value) {
                         // when we fixed CRM-5319 - get primary loc
                         // type as per loc field and removed below code.
                         if ($locTypeId == 'Primary') {
                             $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactId);
                         }
                         if (is_numeric($locTypeId)) {
                             //fixed for CRM-665
                             if ($locTypeId == CRM_Utils_Array::value('location_type_id', $value)) {
                                 if (CRM_Utils_Array::value($fieldName, $value)) {
                                     //to handle stateprovince and country
                                     if ($fieldName == 'state_province') {
                                         $defaults[$fldName] = $value['state_province_id'];
                                     } else {
                                         if ($fieldName == 'county') {
                                             $defaults[$fldName] = $value['county_id'];
                                         } else {
                                             if ($fieldName == 'country') {
                                                 $defaults[$fldName] = $value['country_id'];
                                                 if (!isset($value['country_id']) || !$value['country_id']) {
                                                     $config =& CRM_Core_Config::singleton();
                                                     if ($config->defaultContactCountry) {
                                                         $defaults[$fldName] = $config->defaultContactCountry;
                                                     }
                                                 }
                                             } else {
                                                 if ($fieldName == 'phone') {
                                                     if ($phoneTypeId) {
                                                         if ($value['phone'][$phoneTypeId]) {
                                                             $defaults[$fldName] = $value['phone'][$phoneTypeId];
                                                         }
                                                     } else {
                                                         $defaults[$fldName] = $value['phone'];
                                                     }
                                                 } else {
                                                     if ($fieldName == 'email') {
                                                         //adding the first email (currently we don't support multiple emails of same location type)
                                                         $defaults[$fldName] = $value['email'];
                                                     } else {
                                                         if ($fieldName == 'im') {
                                                             //adding the first im (currently we don't support multiple ims of same location type)
                                                             $defaults[$fldName] = $value['im'];
                                                             $defaults[$fldName . "-provider_id"] = $value['im_provider_id'];
                                                         } else {
                                                             $defaults[$fldName] = $value[$fieldName];
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (CRM_Core_Permission::access('Quest', false)) {
             require_once 'CRM/Quest/BAO/Student.php';
             // Checking whether the database contains quest_student table.
             // Now there are two different schemas for core and quest.
             // So if only core schema in use then withought following check gets the DB error.
             $student = new CRM_Quest_BAO_Student();
             $tableStudent = $student->getTableName();
             if ($tableStudent) {
                 //set student defaults
                 CRM_Quest_BAO_Student::retrieve($details, $studentDefaults, $ids);
                 $studentFields = array('educational_interest', 'college_type', 'college_interest', 'test_tutoring');
                 foreach ($studentFields as $fld) {
                     if ($studentDefaults[$fld]) {
                         $values = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $studentDefaults[$fld]);
                     }
                     $studentDefaults[$fld] = array();
                     if (is_array($values)) {
                         foreach ($values as $v) {
                             $studentDefaults[$fld][$v] = 1;
                         }
                     }
                 }
                 foreach ($fields as $name => $field) {
                     $fldName = "field[{$contactId}][{$name}]";
                     if (array_key_exists($name, $studentDefaults)) {
                         $defaults[$fldName] = $studentDefaults[$name];
                     }
                 }
             }
         }
     }
     //Handling Contribution Part of the batch profile
     if (CRM_Core_Permission::access('CiviContribute') && $component == 'Contribute') {
         self::setComponentDefaults($fields, $componentId, $component, $defaults);
     }
     //Handling Event Participation Part of the batch profile
     if (CRM_Core_Permission::access('CiviEvent') && $component == 'Event') {
         self::setComponentDefaults($fields, $componentId, $component, $defaults);
     }
     //Handling membership Part of the batch profile
     if (CRM_Core_Permission::access('CiviMember') && $component == 'Membership') {
         self::setComponentDefaults($fields, $componentId, $component, $defaults);
     }
 }
Beispiel #13
0
 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     $values = array();
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     // Make sure context is assigned to template for condition where we come here view civicrm/membership/view
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     if ($id) {
         $params = array('id' => $id);
         CRM_Member_BAO_Membership::retrieve($params, $values);
         $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
         // Do the action on related Membership if needed
         $relAction = CRM_Utils_Request::retrieve('relAction', 'String', $this);
         if ($relAction) {
             $this->relAction($relAction, $values);
         }
         // build associated contributions
         $this->assign('accessContribution', FALSE);
         if (CRM_Core_Permission::access('CiviContribute')) {
             $this->assign('accessContribution', TRUE);
             CRM_Member_Page_Tab::associatedContribution($values['contact_id'], $id);
         }
         //Provide information about membership source when it is the result of a relationship (CRM-1901)
         $values['owner_membership_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'owner_membership_id');
         if (isset($values['owner_membership_id'])) {
             $values['owner_contact_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $values['owner_membership_id'], 'contact_id', 'id');
             $values['owner_display_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['owner_contact_id'], 'display_name', 'id');
             $direction = strrev($membershipType['relationship_direction']);
             // To display relationship type in view membership page
             $relTypeIds = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ",", $membershipType['relationship_type_id']);
             $sql = "\nSELECT relationship_type_id,\n  CASE\n  WHEN  contact_id_a = {$values['owner_contact_id']} AND contact_id_b = {$values['contact_id']} THEN 'b_a'\n  WHEN  contact_id_b = {$values['owner_contact_id']} AND contact_id_a = {$values['contact_id']} THEN 'a_b'\nEND AS 'relType'\n  FROM civicrm_relationship\n WHERE relationship_type_id IN ({$relTypeIds})";
             $dao = CRM_Core_DAO::executeQuery($sql);
             $values['relationship'] = NULL;
             while ($dao->fetch()) {
                 $typeId = $dao->relationship_type_id;
                 $direction = $dao->relType;
                 if ($direction && $typeId) {
                     if ($values['relationship']) {
                         $values['relationship'] .= ',';
                     }
                     $values['relationship'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $typeId, "name_{$direction}", 'id');
                 }
             }
         }
         $this->assign('has_related', FALSE);
         // if membership can be granted, and we are the owner of the membership
         if (!empty($membershipType['relationship_type_id']) && empty($values['owner_membership_id'])) {
             // display related contacts/membership block
             $this->assign('has_related', TRUE);
             $this->assign('max_related', CRM_Utils_Array::value('max_related', $values, ts('Unlimited')));
             // split the relations in 2 arrays based on direction
             $relTypeId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_type_id']);
             $relDirection = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_direction']);
             foreach ($relTypeId as $rid) {
                 $dir = each($relDirection);
                 $relTypeDir[substr($dir['value'], 0, 1)][] = $rid;
             }
             // build query in 2 parts with a UNION if necessary
             // _x and _y are replaced with _a and _b first, then vice-versa
             // comment is a qualifier for the relationship - now just job_title
             $select = "\nSELECT r.id, c.id as cid, c.display_name as name, c.job_title as comment,\n       rt.name_x_y as relation, r.start_date, r.end_date,\n       m.id as mid, ms.is_current_member, ms.label as status\n  FROM civicrm_relationship r\n  LEFT JOIN civicrm_relationship_type rt ON rt.id = r.relationship_type_id\n  LEFT JOIN civicrm_contact c ON c.id = r.contact_id_x\n  LEFT JOIN civicrm_membership m ON (m.owner_membership_id = {$values['id']}\n  AND m.contact_id = r.contact_id_x AND m.is_test = 0)\n  LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id\n WHERE r.contact_id_y = {$values['contact_id']} AND r.is_active = 1  AND c.is_deleted = 0";
             $query = '';
             foreach (array('a', 'b') as $dir) {
                 if (isset($relTypeDir[$dir])) {
                     $query .= ($query ? ' UNION ' : '') . str_replace('_y', '_' . $dir, str_replace('_x', '_' . ($dir == 'a' ? 'b' : 'a'), $select)) . ' AND r.relationship_type_id IN (' . implode(',', $relTypeDir[$dir]) . ')';
                 }
             }
             $query .= " ORDER BY is_current_member DESC";
             $dao = CRM_Core_DAO::executeQuery($query);
             $related = array();
             $relatedRemaining = CRM_Utils_Array::value('max_related', $values, PHP_INT_MAX);
             $rowElememts = array('id', 'cid', 'name', 'comment', 'relation', 'mid', 'start_date', 'end_date', 'is_current_member', 'status');
             while ($dao->fetch()) {
                 $row = array();
                 foreach ($rowElememts as $field) {
                     $row[$field] = $dao->{$field};
                 }
                 if ($row['mid'] && $row['is_current_member'] == 1) {
                     $relatedRemaining--;
                     $row['action'] = CRM_Core_Action::formLink(self::links(), CRM_Core_Action::DELETE, array('id' => CRM_Utils_Request::retrieve('id', 'Positive', $this), 'cid' => $row['cid'], 'mid' => $row['mid']), ts('more'), FALSE, 'membership.relationship.action', 'Relationship', CRM_Utils_Request::retrieve('id', 'Positive', $this));
                 } else {
                     if ($relatedRemaining > 0) {
                         $row['action'] = CRM_Core_Action::formLink(self::links(), CRM_Core_Action::ADD, array('id' => CRM_Utils_Request::retrieve('id', 'Positive', $this), 'cid' => $row['cid'], 'rid' => $row['cid']), ts('more'), FALSE, 'membership.relationship.action', 'Relationship', CRM_Utils_Request::retrieve('id', 'Positive', $this));
                     }
                 }
                 $related[] = $row;
             }
             $this->assign('related', $related);
             if ($relatedRemaining <= 0) {
                 $this->assign('related_text', ts('None available'));
             } else {
                 if ($relatedRemaining < 100000) {
                     $this->assign('related_text', ts('%1 available', array(1 => $relatedRemaining)));
                 } else {
                     $this->assign('related_text', ts('Unlimited', array(1 => $relatedRemaining)));
                 }
             }
         }
         $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
         $this->assign('displayName', $displayName);
         // Check if this is default domain contact CRM-10482
         if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) {
             $displayName .= ' (' . ts('default organization') . ')';
         }
         // omitting contactImage from title for now since the summary overlay css doesn't work outside crm-container
         CRM_Utils_System::setTitle(ts('View Membership for') . ' ' . $displayName);
         // add viewed membership to recent items list
         $recentTitle = $displayName . ' - ' . ts('Membership Type:') . ' ' . $values['membership_type'];
         $url = CRM_Utils_System::url('civicrm/contact/view/membership', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         $recentOther = array();
         if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::UPDATE)) {
             $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         }
         if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::DELETE)) {
             $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         }
         CRM_Utils_Recent::add($recentTitle, $url, $values['id'], 'Membership', $values['contact_id'], NULL, $recentOther);
         CRM_Member_Page_Tab::setContext($this, $values['contact_id']);
         $memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $id, "membership_type_id");
         $groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $id, 0, $memType);
         CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
         $isRecur = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'contribution_recur_id');
         $autoRenew = $isRecur ? TRUE : FALSE;
     }
     if (!empty($values['is_test'])) {
         $values['membership_type'] .= ' (test) ';
     }
     $subscriptionCancelled = CRM_Member_BAO_Membership::isSubscriptionCancelled($id);
     $values['auto_renew'] = $autoRenew && !$subscriptionCancelled ? 'Yes' : 'No';
     //do check for campaigns
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
         $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
         $values['campaign'] = $campaigns[$campaignId];
     }
     $this->assign($values);
 }
Beispiel #14
0
 /**
  * Get a list of fields which can be added to profiles.
  *
  * @param int $gid : UF group ID
  * @param array $defaults : Form defaults
  * @return array, multidimensional; e.g. $result['FieldGroup']['field_name']['label']
  */
 public static function getAvailableFields($gid = NULL, $defaults = array())
 {
     $fields = array('Contact' => array(), 'Individual' => CRM_Contact_BAO_Contact::importableFields('Individual', FALSE, FALSE, TRUE, TRUE, TRUE), 'Household' => CRM_Contact_BAO_Contact::importableFields('Household', FALSE, FALSE, TRUE, TRUE, TRUE), 'Organization' => CRM_Contact_BAO_Contact::importableFields('Organization', FALSE, FALSE, TRUE, TRUE, TRUE));
     // include hook injected fields
     $fields['Contact'] = array_merge($fields['Contact'], CRM_Contact_BAO_Query_Hook::singleton()->getFields());
     // add current employer for individuals
     $fields['Individual']['current_employer'] = array('name' => 'organization_name', 'title' => ts('Current Employer'));
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     if (!$addressOptions['county']) {
         unset($fields['Individual']['county'], $fields['Household']['county'], $fields['Organization']['county']);
     }
     // break out common contact fields array CRM-3037.
     // from a UI perspective this makes very little sense
     foreach ($fields['Individual'] as $key => $value) {
         if (!empty($fields['Household'][$key]) && !empty($fields['Organization'][$key])) {
             $fields['Contact'][$key] = $value;
             unset($fields['Individual'][$key], $fields['Household'][$key], $fields['Organization'][$key]);
         }
     }
     // Internal field not exposed to forms
     unset($fields['Contact']['contact_type']);
     unset($fields['Contact']['master_id']);
     // convert phone extension in to psedo-field phone + phone extension
     //unset extension
     unset($fields['Contact']['phone_ext']);
     //add psedo field
     $fields['Contact']['phone_and_ext'] = array('name' => 'phone_and_ext', 'title' => ts('Phone and Extension'), 'hasLocationType' => 1);
     // include Subtypes For Profile
     $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($subTypes as $name => $val) {
         //custom fields for sub type
         $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($name, FALSE, FALSE, FALSE, TRUE, TRUE);
         if (array_key_exists($val['parent'], $fields)) {
             $fields[$name] = $fields[$val['parent']] + $subTypeFields;
         } else {
             $fields[$name] = $subTypeFields;
         }
     }
     if (CRM_Core_Permission::access('CiviContribute')) {
         $contribFields = CRM_Contribute_BAO_Contribution::getContributionFields(FALSE);
         if (!empty($contribFields)) {
             unset($contribFields['is_test']);
             unset($contribFields['is_pay_later']);
             unset($contribFields['contribution_id']);
             $contribFields['contribution_note'] = array('name' => 'contribution_note', 'title' => ts('Contribution Note'));
             $fields['Contribution'] = array_merge($contribFields, self::getContribBatchEntryFields());
         }
     }
     if (CRM_Core_Permission::access('CiviEvent')) {
         $participantFields = CRM_Event_BAO_Query::getParticipantFields();
         if ($participantFields) {
             // Remove fields not supported by profiles
             CRM_Utils_Array::remove($participantFields, 'external_identifier', 'event_id', 'participant_contact_id', 'participant_role_id', 'participant_status_id', 'participant_is_test', 'participant_fee_level', 'participant_id', 'participant_is_pay_later', 'participant_campaign');
             if (isset($participantFields['participant_campaign_id'])) {
                 $participantFields['participant_campaign_id']['title'] = ts('Campaign');
             }
             $fields['Participant'] = $participantFields;
         }
     }
     if (CRM_Core_Permission::access('CiviMember')) {
         $membershipFields = CRM_Member_BAO_Membership::getMembershipFields();
         // Remove fields not supported by profiles
         CRM_Utils_Array::remove($membershipFields, 'membership_id', 'membership_type_id', 'member_is_test', 'is_override', 'status_id', 'member_is_pay_later');
         if ($gid && CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gid, 'name') == 'membership_batch_entry') {
             $fields['Membership'] = array_merge($membershipFields, self::getMemberBatchEntryFields());
         } else {
             $fields['Membership'] = $membershipFields;
         }
     }
     if (CRM_Core_Permission::access('CiviCase')) {
         $caseFields = CRM_Case_BAO_Query::getFields(TRUE);
         $caseFields = array_merge($caseFields, CRM_Core_BAO_CustomField::getFieldsForImport('Case'));
         if ($caseFields) {
             // Remove fields not supported by profiles
             CRM_Utils_Array::remove($caseFields, 'case_id', 'case_type', 'case_start_date', 'case_end_date', 'case_role', 'case_status', 'case_deleted');
         }
         $fields['Case'] = $caseFields;
     }
     $activityFields = CRM_Activity_BAO_Activity::getProfileFields();
     if ($activityFields) {
         // campaign related fields.
         if (isset($activityFields['activity_campaign_id'])) {
             $activityFields['activity_campaign_id']['title'] = ts('Campaign');
         }
         $fields['Activity'] = $activityFields;
     }
     $fields['Formatting']['format_free_html_' . rand(1000, 9999)] = array('name' => 'free_html', 'import' => FALSE, 'export' => FALSE, 'title' => 'Free HTML');
     // Sort by title
     foreach ($fields as &$values) {
         $values = CRM_Utils_Array::crmArraySortByField($values, 'title');
     }
     //group selected and unwanted fields list
     $ufFields = $gid ? CRM_Core_BAO_UFGroup::getFields($gid, FALSE, NULL, NULL, NULL, TRUE, NULL, TRUE) : array();
     $groupFieldList = array_merge($ufFields, array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id'));
     //unset selected fields
     foreach ($groupFieldList as $key => $value) {
         if (is_int($key)) {
             unset($fields['Individual'][$value], $fields['Household'][$value], $fields['Organization'][$value]);
             continue;
         }
         if (!empty($defaults['field_name']) && $defaults['field_name']['0'] == $value['field_type'] && $defaults['field_name']['1'] == $key) {
             continue;
         }
         unset($fields[$value['field_type']][$key]);
     }
     return $fields;
 }
Beispiel #15
0
 /**
  * Given an id creates a subject/content array
  *
  * @param int $id
  *   Id of the block.
  *
  * @return array
  */
 public static function getContent($id)
 {
     // return if upgrade mode
     $config = CRM_Core_Config::singleton();
     if ($config->isUpgradeMode()) {
         return NULL;
     }
     if (!self::getProperty($id, 'active')) {
         return NULL;
     }
     if ($id == self::EVENT && CRM_Core_Permission::check('view event info')) {
         // is CiviEvent enabled?
         if (!CRM_Core_Permission::access('CiviEvent', FALSE)) {
             return NULL;
         }
         // do nothing
     } elseif (!CRM_Core_Permission::check('access CiviCRM') && $id != self::LANGSWITCH) {
         return NULL;
     } elseif ($id == self::ADD) {
         $hasAccess = TRUE;
         if (!CRM_Core_Permission::check('add contacts') && !CRM_Core_Permission::check('edit groups')) {
             $hasAccess = FALSE;
         }
         //validate across edit/view - CRM-5666
         if ($hasAccess) {
             $hasAccess = CRM_Core_Permission::giveMeAllACLs();
         }
         if (!$hasAccess) {
             return NULL;
         }
     }
     self::setTemplateValues($id);
     // Suppress Recent Items block if it's empty - CRM-5188
     if ($id == self::RECENTLY_VIEWED) {
         $recent = self::getProperty($id, 'templateValues');
         if (CRM_Utils_Array::crmIsEmptyArray($recent)) {
             return NULL;
         }
     }
     // Suppress Language switcher if language is inherited from CMS - CRM-9971
     $config = CRM_Core_Config::singleton();
     if ($id == self::LANGSWITCH && property_exists($config, "inheritLocale") && $config->inheritLocale) {
         return NULL;
     }
     $block = array();
     $block['name'] = 'block-civicrm';
     $block['id'] = $block['name'] . '_' . $id;
     $block['subject'] = self::fetch($id, 'Subject.tpl', array('subject' => self::getProperty($id, 'subject')));
     $block['content'] = self::fetch($id, self::getProperty($id, 'template'), self::getProperty($id, 'templateValues'));
     return $block;
 }
Beispiel #16
0
 /**
  * Class constructor.
  *
  * @param array $queryParams
  *   Array of parameters for query.
  * @param \const|int $action - action of search basic or advanced.
  * @param string $activityClause
  *   If the caller wants to further restrict the search (used in activities).
  * @param bool $single
  *   Are we dealing only with one contact?.
  * @param int $limit
  *   How many activities do we want returned.
  *
  * @param string $context
  * @param null $compContext
  *
  * @return \CRM_Activity_Selector_Search
  */
 public function __construct(&$queryParams, $action = CRM_Core_Action::NONE, $activityClause = NULL, $single = FALSE, $limit = NULL, $context = 'search', $compContext = NULL)
 {
     // submitted form values
     $this->_queryParams =& $queryParams;
     $this->_single = $single;
     $this->_limit = $limit;
     $this->_context = $context;
     $this->_compContext = $compContext;
     $this->_activityClause = $activityClause;
     // CRM-12675
     $components = CRM_Core_Component::getNames();
     $componentClause = array();
     foreach ($components as $componentID => $componentName) {
         // CRM-19201: Add support for searching CiviCampaign and CiviCase
         // activities. For CiviCase, "access all cases and activities" is
         // required here rather than "access my cases and activities" to
         // prevent those with only the later permission from seeing a list
         // of all cases which might present a privacy issue.
         if (!CRM_Core_Permission::access($componentName, TRUE, TRUE)) {
             $componentClause[] = " (activity_type.component_id IS NULL OR activity_type.component_id <> {$componentID}) ";
         }
     }
     if (!empty($componentClause)) {
         $componentRestriction = implode(' AND ', $componentClause);
         if (empty($this->_activityClause)) {
             $this->_activityClause = $componentRestriction;
         } else {
             $this->_activityClause .= ' AND ' . $componentRestriction;
         }
     }
     // type of selector
     $this->_action = $action;
     $this->_query = new CRM_Contact_BAO_Query($this->_queryParams, CRM_Activity_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_ACTIVITY, FALSE), NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_ACTIVITY);
     $this->_query->_distinctComponentClause = '( civicrm_activity.id )';
     $this->_query->_groupByComponentClause = " GROUP BY civicrm_activity.id ";
 }
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     $defaults = parent::setDefaultValues();
     $this->_memType = $defaults['membership_type_id'];
     $this->assign('customDataType', 'Membership');
     $this->assign('customDataSubType', $this->_memType);
     $this->assign('entityID', $this->_id);
     $selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -');
     $allMembershipInfo = array();
     //CRM-16950
     $taxRates = CRM_Core_PseudoConstant::getTaxRates();
     $taxRate = CRM_Utils_Array::value($allMemberships[$defaults['membership_type_id']]['financial_type_id'], $taxRates);
     $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
     // auto renew options if enabled for the membership
     $options = CRM_Core_SelectValues::memberAutoRenew();
     foreach ($this->allMembershipTypeDetails as $key => $values) {
         if (!empty($values['is_active'])) {
             if ($this->_mode && empty($values['minimum_fee'])) {
                 continue;
             } else {
                 $memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values);
                 if (empty($selMemTypeOrg[$memberOfContactId])) {
                     $selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $memberOfContactId, 'display_name', 'id');
                     $selOrgMemType[$memberOfContactId][0] = ts('- select -');
                 }
                 if (empty($selOrgMemType[$memberOfContactId][$key])) {
                     $selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values);
                 }
             }
             //CRM-16950
             $taxAmount = NULL;
             $totalAmount = CRM_Utils_Array::value('minimum_fee', $values);
             if (CRM_Utils_Array::value($values['financial_type_id'], $taxRates)) {
                 $taxAmount = $taxRate / 100 * CRM_Utils_Array::value('minimum_fee', $values);
                 $totalAmount = $totalAmount + $taxAmount;
             }
             // build membership info array, which is used to set the payment information block when
             // membership type is selected.
             $allMembershipInfo[$key] = array('financial_type_id' => CRM_Utils_Array::value('financial_type_id', $values), 'total_amount' => CRM_Utils_Money::format($totalAmount, NULL, '%a'), 'total_amount_numeric' => $totalAmount, 'tax_message' => $taxAmount ? ts("Includes %1 amount of %2", array(1 => CRM_Utils_Array::value('tax_term', $invoiceSettings), 2 => CRM_Utils_Money::format($taxAmount))) : $taxAmount);
             if (!empty($values['auto_renew'])) {
                 $allMembershipInfo[$key]['auto_renew'] = $options[$values['auto_renew']];
             }
         }
     }
     $this->assign('allMembershipInfo', json_encode($allMembershipInfo));
     if ($this->_memType) {
         $this->assign('orgName', $selMemTypeOrg[$this->allMembershipTypeDetails[$this->_memType]['member_of_contact_id']]);
         $this->assign('memType', $this->allMembershipTypeDetails[$this->_memType]['name']);
     }
     // force select of organization by default, if only one organization in
     // the list
     if (count($selMemTypeOrg) == 2) {
         unset($selMemTypeOrg[0], $selOrgMemType[0][0]);
     }
     //sort membership organization and type, CRM-6099
     natcasesort($selMemTypeOrg);
     foreach ($selOrgMemType as $index => $orgMembershipType) {
         natcasesort($orgMembershipType);
         $selOrgMemType[$index] = $orgMembershipType;
     }
     $js = array('onChange' => "setPaymentBlock(); CRM.buildCustomData('Membership', this.value);");
     $sel =& $this->addElement('hierselect', 'membership_type_id', ts('Renewal Membership Organization and Type'), $js);
     $sel->setOptions(array($selMemTypeOrg, $selOrgMemType));
     $elements = array();
     if ($sel) {
         $elements[] = $sel;
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->addDate('renewal_date', ts('Date Renewal Entered'), FALSE, array('formatType' => 'activityDate'));
     $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType());
     $this->add('text', 'num_terms', ts('Extend Membership by'), array('onchange' => "setPaymentBlock();"), TRUE);
     $this->addRule('num_terms', ts('Please enter a whole number for how many periods to renew.'), 'integer');
     if (CRM_Core_Permission::access('CiviContribute') && !$this->_mode) {
         $this->addElement('checkbox', 'record_contribution', ts('Record Renewal Payment?'), NULL, array('onclick' => "checkPayment();"));
         $this->add('text', 'total_amount', ts('Amount'));
         $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money');
         $this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
         $this->add('select', 'payment_instrument_id', ts('Payment Method'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
         $this->add('text', 'trxn_id', ts('Transaction ID'));
         $this->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id'));
         $this->add('select', 'contribution_status_id', ts('Payment Status'), CRM_Contribute_PseudoConstant::contributionStatus());
         $this->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number'));
     } else {
         $this->add('text', 'total_amount', ts('Amount'));
         $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money');
     }
     $this->addElement('checkbox', 'send_receipt', ts('Send Confirmation and Receipt?'), NULL, array('onclick' => "showHideByValue( 'send_receipt', '', 'notice', 'table-row', 'radio', false ); showHideByValue( 'send_receipt', '', 'fromEmail', 'table-row', 'radio',false);"));
     $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
     $this->add('textarea', 'receipt_text_renewal', ts('Renewal Message'));
     // Retrieve the name and email of the contact - this will be the TO for receipt email
     list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
     $this->assign('email', $this->_contributorEmail);
     // The member form uses emailExists. Assigning both while we transition / synchronise.
     $this->assign('emailExists', $this->_contributorEmail);
     $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
     $this->assign('outBound_option', $mailingInfo['outBound_option']);
     if (CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'contribution_recur_id')) {
         if (CRM_Member_BAO_Membership::isCancelSubscriptionSupported($this->_id)) {
             $this->assign('cancelAutoRenew', CRM_Utils_System::url('civicrm/contribute/unsubscribe', "reset=1&mid={$this->_id}"));
         }
     }
     $this->addFormRule(array('CRM_Member_Form_MembershipRenewal', 'formRule'));
     $this->addElement('checkbox', 'is_different_contribution_contact', ts('Record Payment from a Different
   Contact?'));
     $this->addSelect('soft_credit_type_id', array('entity' => 'contribution_soft'));
     $this->addEntityRef('soft_credit_contact_id', ts('Payment From'), array('create' => TRUE));
 }
Beispiel #18
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         CRM_Core_BAO_UFField::retrieve($params, $defaults);
         // set it to null if so (avoids crappy E_NOTICE errors below
         $defaults['location_type_id'] = CRM_Utils_Array::value('location_type_id', $defaults);
         $specialFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'county', 'phone', 'email', 'im', 'address_name');
         if (!$defaults['location_type_id'] && in_array($defaults['field_name'], $specialFields)) {
             $defaults['location_type_id'] = 0;
         }
         $defaults['field_name'] = array($defaults['field_type'], $defaults['field_name'], $defaults['location_type_id'], CRM_Utils_Array::value('phone_type_id', $defaults));
         $this->_gid = $defaults['uf_group_id'];
     } else {
         $defaults['is_active'] = 1;
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         $fieldValues = array('uf_group_id' => $this->_gid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFField', $fieldValues);
     }
     // lets trim all the whitespace
     $this->applyFilter('__ALL__', 'trim');
     //hidden field to catch the group id in profile
     $this->add('hidden', 'group_id', $this->_gid);
     //hidden field to catch the field id in profile
     $this->add('hidden', 'field_id', $this->_id);
     $fields = array();
     $fields['Individual'] =& CRM_Contact_BAO_Contact::importableFields('Individual', false, false, true);
     $fields['Household'] =& CRM_Contact_BAO_Contact::importableFields('Household', false, false, true);
     $fields['Organization'] =& CRM_Contact_BAO_Contact::importableFields('Organization', false, false, true);
     // add current employer for individuals
     $fields['Individual']['current_employer'] = array('name' => 'organization_name', 'title' => ts('Current Employer'));
     // unset unwanted fields
     $unsetFieldArray = array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id');
     foreach ($unsetFieldArray as $value) {
         unset($fields['Individual'][$value]);
         unset($fields['Household'][$value]);
         unset($fields['Organization'][$value]);
     }
     require_once 'CRM/Core/BAO/Preferences.php';
     $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
     if (!$addressOptions['county']) {
         unset($fields['Individual']['county']);
         unset($fields['Household']['county']);
         unset($fields['Organization']['county']);
     }
     //build the common contact fields array CRM-3037.
     foreach ($fields['Individual'] as $key => $value) {
         if (CRM_Utils_Array::value($key, $fields['Household']) && CRM_Utils_Array::value($key, $fields['Organization'])) {
             $fields['Contact'][$key] = $value;
             //as we move common fields to contacts. There fore these fields
             //are unset from resoective array's.
             unset($fields['Individual'][$key]);
             unset($fields['Household'][$key]);
             unset($fields['Organization'][$key]);
         }
     }
     // add current employer for individuals
     $fields['Contact']['id'] = array('name' => 'id', 'title' => ts('Internal Contact ID'));
     unset($fields['Contact']['contact_type']);
     // since we need a hierarchical list to display contact types & subtypes,
     // this is what we going to display in first selector
     $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(false, false);
     unset($contactTypes['']);
     // include Subtypes For Profile
     $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($subTypes as $name => $val) {
         //custom fields for sub type
         $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($name);
         if (array_key_exists($val['parent'], $fields)) {
             $fields[$name] = $fields[$val['parent']] + $subTypeFields;
         } else {
             $fields[$name] = $subTypeFields;
         }
     }
     unset($subTypes);
     if (CRM_Core_Permission::access('Quest')) {
         require_once 'CRM/Quest/BAO/Student.php';
         $fields['Student'] =& CRM_Quest_BAO_Student::exportableFields();
     }
     if (CRM_Core_Permission::access('CiviContribute')) {
         $contribFields =& CRM_Contribute_BAO_Contribution::getContributionFields();
         if (!empty($contribFields)) {
             unset($contribFields['is_test']);
             unset($contribFields['is_pay_later']);
             unset($contribFields['contribution_id']);
             $fields['Contribution'] =& $contribFields;
         }
     }
     if (CRM_Core_Permission::access('CiviEvent')) {
         require_once 'CRM/Event/BAO/Query.php';
         $participantFields =& CRM_Event_BAO_Query::getParticipantFields(true);
         if (!empty($participantFields)) {
             unset($participantFields['external_identifier']);
             unset($participantFields['event_id']);
             unset($participantFields['participant_contact_id']);
             unset($participantFields['participant_is_test']);
             unset($participantFields['participant_fee_level']);
             unset($participantFields['participant_id']);
             unset($participantFields['participant_is_pay_later']);
             $fields['Participant'] =& $participantFields;
         }
     }
     if (CRM_Core_Permission::access('CiviMember')) {
         require_once 'CRM/Member/BAO/Membership.php';
         $membershipFields =& CRM_Member_BAO_Membership::getMembershipFields();
         unset($membershipFields['membership_id']);
         unset($membershipFields['join_date']);
         unset($membershipFields['membership_start_date']);
         unset($membershipFields['membership_type_id']);
         unset($membershipFields['membership_end_date']);
         unset($membershipFields['member_is_test']);
         unset($membershipFields['is_override']);
         unset($membershipFields['status_id']);
         unset($membershipFields['member_is_pay_later']);
         $fields['Membership'] =& $membershipFields;
     }
     $noSearchable = array();
     foreach ($fields as $key => $value) {
         foreach ($value as $key1 => $value1) {
             //CRM-2676, replacing the conflict for same custom field name from different custom group.
             require_once 'CRM/Core/BAO/CustomField.php';
             if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key1)) {
                 $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id');
                 $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title');
                 $this->_mapperFields[$key][$key1] = $value1['title'] . ' :: ' . $customGroupName;
             } else {
                 $this->_mapperFields[$key][$key1] = $value1['title'];
             }
             $hasLocationTypes[$key][$key1] = CRM_Utils_Array::value('hasLocationType', $value1);
             // hide the 'is searchable' field for 'File' custom data
             if (isset($value1['data_type']) && isset($value1['html_type']) && ($value1['data_type'] == 'File' && $value1['html_type'] == 'File' || $value1['data_type'] == 'Link' && $value1['html_type'] == 'Link')) {
                 if (!in_array($value1['title'], $noSearchable)) {
                     $noSearchable[] = $value1['title'];
                 }
             }
         }
     }
     $this->assign('noSearchable', $noSearchable);
     require_once 'CRM/Core/BAO/LocationType.php';
     $this->_location_types =& CRM_Core_PseudoConstant::locationType();
     $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault();
     /* FIXME: dirty hack to make the default option show up first.  This
      * avoids a mozilla browser bug with defaults on dynamically constructed
      * selector widgets. */
     if ($defaultLocationType) {
         $defaultLocation = $this->_location_types[$defaultLocationType->id];
         unset($this->_location_types[$defaultLocationType->id]);
         $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types;
     }
     $this->_location_types = array('Primary') + $this->_location_types;
     $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
     $sel1 = array('' => '- select -') + $contactTypes;
     if (CRM_Core_Permission::access('Quest')) {
         $sel1['Student'] = 'Students';
     }
     if (CRM_Core_Permission::access('CiviEvent')) {
         $sel1['Participant'] = 'Participants';
     }
     if (!empty($contribFields)) {
         $sel1['Contribution'] = 'Contributions';
     }
     if (!empty($membershipFields)) {
         $sel1['Membership'] = 'Membership';
     }
     foreach ($sel1 as $key => $sel) {
         if ($key) {
             $sel2[$key] = $this->_mapperFields[$key];
         }
     }
     $sel3[''] = null;
     $phoneTypes = CRM_Core_PseudoConstant::phoneType();
     ksort($phoneTypes);
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             foreach ($this->_location_types as $key => $value) {
                 $sel4[$k]['phone'][$key] =& $phoneTypes;
             }
         }
     }
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             if (is_array($this->_mapperFields[$k])) {
                 foreach ($this->_mapperFields[$k] as $key => $value) {
                     if ($hasLocationTypes[$k][$key]) {
                         $sel3[$k][$key] = $this->_location_types;
                     } else {
                         $sel3[$key] = null;
                     }
                 }
             }
         }
     }
     $this->_defaults = array();
     $js = "<script type='text/javascript'>\n";
     $formName = "document.{$this->_name}";
     $alreadyMixProfile = false;
     if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
         $alreadyMixProfile = true;
     }
     $this->assign('alreadyMixProfile', $alreadyMixProfile);
     $attributes = array('onclick' => "showLabel();mixProfile();", 'onblur' => 'showLabel();mixProfile();');
     $sel =& $this->addElement('hierselect', "field_name", ts('Field Name'), $attributes);
     $formValues = array();
     $formValues = $this->exportValues();
     if (empty($formValues)) {
         for ($k = 1; $k < 4; $k++) {
             if (!$defaults['field_name'][$k]) {
                 $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
             }
         }
     } else {
         if (!empty($formValues['field_name'])) {
             foreach ($formValues['field_name'] as $value) {
                 for ($k = 1; $k < 4; $k++) {
                     if (!isset($formValues['field_name'][$k]) || !$formValues['field_name'][$k]) {
                         $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
                     } else {
                         $js .= "{$formName}['field_name[{$k}]'].style.display = '';\n";
                     }
                 }
             }
         } else {
             for ($k = 1; $k < 4; $k++) {
                 if (!isset($defaults['field_name'][$k])) {
                     $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
                 }
             }
         }
     }
     foreach ($sel2 as $k => $v) {
         if (is_array($sel2[$k])) {
             asort($sel2[$k]);
         }
     }
     $sel->setOptions(array($sel1, $sel2, $sel3, $sel4));
     $js .= "</script>\n";
     $this->assign('initHideBoxes', $js);
     $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), true, array("onChange" => "showHideSeletorSearch(this.value);"));
     //CRM-4363
     $js = array('onclick' => "mixProfile();");
     // should the field appear in selectors (as a column)?
     $this->add('checkbox', 'in_selector', ts('Results Column?'), null, null, $js);
     $this->add('checkbox', 'is_searchable', ts('Searchable?'), null, null, $js);
     // weight
     $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'weight'), true);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'help_post'));
     // listings title
     $this->add('text', 'listings_title', ts('Listings Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'listings_title'));
     $this->addRule('listings_title', ts('Please enter a valid title for this field when displayed in user listings.'), 'title');
     $this->add('checkbox', 'is_required', ts('Required?'));
     $this->add('checkbox', 'is_active', ts('Active?'));
     $this->add('checkbox', 'is_view', ts('View Only?'));
     // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) );
     //$this->add( 'checkbox', 'is_match'       , ts( 'Key to Match Contacts?'        ) );
     $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'label'));
     $js = null;
     if ($this->_hasSearchableORInSelector) {
         $js = array('onclick' => "return verify( );");
     }
     // add buttons
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => true, 'js' => $js), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $js), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'), $this);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'"));
     }
     $this->setDefaults($defaults);
 }
Beispiel #19
0
 /**
  * This function is used for the to show the associated
  * contribution for the participant
  *
  * return null
  * @access public
  */
 function associatedContribution()
 {
     if (CRM_Core_Permission::access('CiviContribute')) {
         $this->assign('accessContribution', TRUE);
         $controller = new CRM_Core_Controller_Simple('CRM_Contribute_Form_Search', ts('Contributions'), NULL, FALSE, FALSE, TRUE);
         $controller->setEmbedded(TRUE);
         $controller->set('force', 1);
         $controller->set('cid', $this->_contactId);
         $controller->set('participantId', $this->_id);
         $controller->set('context', 'contribution');
         $controller->process();
         $controller->run();
     } else {
         $this->assign('accessContribution', FALSE);
     }
 }
Beispiel #20
0
 /**
  * Function to disable/enable the relationship
  *
  * @param int $id relationship id
  *
  * @return null
  * @access public
  * @static
  */
 static function disableEnableRelationship($id, $action)
 {
     $relationship = self::clearCurrentEmployer($id, $action);
     if (CRM_Core_Permission::access('CiviMember')) {
         // create $params array which isrequired to delete memberships
         // of the related contacts.
         $params = array('relationship_type_id' => "{$relationship->relationship_type_id}_a_b", 'contact_check' => array($relationship->contact_id_b => 1));
         $ids = array();
         // calling relatedMemberships to delete/add the memberships of
         // related contacts.
         if ($action & CRM_Core_Action::DISABLE) {
             CRM_Contact_BAO_Relationship::relatedMemberships($relationship->contact_id_a, $params, $ids, CRM_Core_Action::DELETE, FALSE);
         } elseif ($action & CRM_Core_Action::ENABLE) {
             $ids['contact'] = $relationship->contact_id_a;
             CRM_Contact_BAO_Relationship::relatedMemberships($relationship->contact_id_a, $params, $ids, CRM_Core_Action::ADD, FALSE);
         }
     }
 }
Beispiel #21
0
 /**
  * Set profile defaults.
  *
  * @param int $contactId
  *   Contact id.
  * @param array $fields
  *   Associative array of fields.
  * @param array $defaults
  *   Defaults array.
  * @param bool $singleProfile
  *   True for single profile else false(batch update).
  * @param int $componentId
  *   Id for specific components like contribute, event etc.
  * @param null $component
  */
 public static function setProfileDefaults($contactId, &$fields, &$defaults, $singleProfile = TRUE, $componentId = NULL, $component = NULL)
 {
     if (!$componentId) {
         //get the contact details
         list($contactDetails, $options) = CRM_Contact_BAO_Contact::getHierContactDetails($contactId, $fields);
         $details = CRM_Utils_Array::value($contactId, $contactDetails);
         $multipleFields = array('website' => 'url');
         //start of code to set the default values
         foreach ($fields as $name => $field) {
             // skip pseudo fields
             if (substr($name, 0, 9) == 'phone_ext') {
                 continue;
             }
             //set the field name depending upon the profile mode(single/batch)
             if ($singleProfile) {
                 $fldName = $name;
             } else {
                 $fldName = "field[{$contactId}][{$name}]";
             }
             if ($name == 'group') {
                 CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, $fldName);
             }
             if ($name == 'tag') {
                 CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::TAG, $fldName);
             }
             if (!empty($details[$name]) || isset($details[$name])) {
                 //to handle custom data (checkbox) to be written
                 // to handle birth/deceased date, greeting_type and few other fields
                 if ($name == 'birth_date' || $name == 'deceased_date') {
                     list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], 'birth');
                 } elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)) {
                     $defaults[$fldName] = $details[$name . '_id'];
                     $defaults[$name . '_custom'] = $details[$name . '_custom'];
                 } elseif ($name == 'preferred_communication_method') {
                     $v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details[$name]);
                     foreach ($v as $item) {
                         if ($item) {
                             $defaults[$fldName . "[{$item}]"] = 1;
                         }
                     }
                 } elseif ($name == 'contact_sub_type') {
                     $defaults[$fldName] = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($details[$name], CRM_Core_DAO::VALUE_SEPARATOR));
                 } elseif ($name == 'world_region') {
                     $defaults[$fldName] = $details['worldregion_id'];
                 } elseif ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($name)) {
                     //fix for custom fields
                     $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $details));
                     // hack to add custom data for components
                     $components = array('Contribution', 'Participant', 'Membership', 'Activity');
                     foreach ($components as $value) {
                         $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFieldsForImport($value));
                     }
                     switch ($customFields[$customFieldId]['html_type']) {
                         case 'Multi-Select State/Province':
                         case 'Multi-Select Country':
                         case 'AdvMulti-Select':
                         case 'Multi-Select':
                             $v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details[$name]);
                             foreach ($v as $item) {
                                 if ($item) {
                                     $defaults[$fldName][$item] = $item;
                                 }
                             }
                             break;
                         case 'CheckBox':
                             $v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details[$name]);
                             foreach ($v as $item) {
                                 if ($item) {
                                     $defaults[$fldName][$item] = 1;
                                     // seems like we need this for QF style checkboxes in profile where its multiindexed
                                     // CRM-2969
                                     $defaults["{$fldName}[{$item}]"] = 1;
                                 }
                             }
                             break;
                         case 'Select Date':
                             // CRM-6681, set defult values according to date and time format (if any).
                             $dateFormat = NULL;
                             if (!empty($customFields[$customFieldId]['date_format'])) {
                                 $dateFormat = $customFields[$customFieldId]['date_format'];
                             }
                             if (empty($customFields[$customFieldId]['time_format'])) {
                                 list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], NULL, $dateFormat);
                             } else {
                                 $timeElement = $fldName . '_time';
                                 if (substr($fldName, -1) == ']') {
                                     $timeElement = substr($fldName, 0, -1) . '_time]';
                                 }
                                 list($defaults[$fldName], $defaults[$timeElement]) = CRM_Utils_Date::setDateDefaults($details[$name], NULL, $dateFormat, $customFields[$customFieldId]['time_format']);
                             }
                             break;
                         default:
                             $defaults[$fldName] = $details[$name];
                             break;
                     }
                 } else {
                     $defaults[$fldName] = $details[$name];
                 }
             } else {
                 $blocks = array('email', 'phone', 'im', 'openid');
                 list($fieldName, $locTypeId, $phoneTypeId) = CRM_Utils_System::explode('-', $name, 3);
                 if (!in_array($fieldName, $multipleFields)) {
                     if (is_array($details)) {
                         foreach ($details as $key => $value) {
                             // when we fixed CRM-5319 - get primary loc
                             // type as per loc field and removed below code.
                             $primaryLocationType = FALSE;
                             if ($locTypeId == 'Primary') {
                                 if (is_array($value) && array_key_exists($fieldName, $value)) {
                                     $primaryLocationType = TRUE;
                                     if (in_array($fieldName, $blocks)) {
                                         $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactId, FALSE, $fieldName);
                                     } else {
                                         $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactId, FALSE, 'address');
                                     }
                                 }
                             }
                             // fixed for CRM-665
                             if (is_numeric($locTypeId)) {
                                 if ($primaryLocationType || $locTypeId == CRM_Utils_Array::value('location_type_id', $value)) {
                                     if (!empty($value[$fieldName])) {
                                         //to handle stateprovince and country
                                         if ($fieldName == 'state_province') {
                                             $defaults[$fldName] = $value['state_province_id'];
                                         } elseif ($fieldName == 'county') {
                                             $defaults[$fldName] = $value['county_id'];
                                         } elseif ($fieldName == 'country') {
                                             if (!isset($value['country_id']) || !$value['country_id']) {
                                                 $config = CRM_Core_Config::singleton();
                                                 if ($config->defaultContactCountry) {
                                                     $defaults[$fldName] = $config->defaultContactCountry;
                                                 }
                                             } else {
                                                 $defaults[$fldName] = $value['country_id'];
                                             }
                                         } elseif ($fieldName == 'phone') {
                                             if ($phoneTypeId) {
                                                 if (isset($value['phone'][$phoneTypeId])) {
                                                     $defaults[$fldName] = $value['phone'][$phoneTypeId];
                                                 }
                                                 if (isset($value['phone_ext'][$phoneTypeId])) {
                                                     $defaults[str_replace('phone', 'phone_ext', $fldName)] = $value['phone_ext'][$phoneTypeId];
                                                 }
                                             } else {
                                                 $phoneDefault = CRM_Utils_Array::value('phone', $value);
                                                 // CRM-9216
                                                 if (!is_array($phoneDefault)) {
                                                     $defaults[$fldName] = $phoneDefault;
                                                 }
                                             }
                                         } elseif ($fieldName == 'email') {
                                             //adding the first email (currently we don't support multiple emails of same location type)
                                             $defaults[$fldName] = $value['email'];
                                         } elseif ($fieldName == 'im') {
                                             //adding the first im (currently we don't support multiple ims of same location type)
                                             $defaults[$fldName] = $value['im'];
                                             $defaults[$fldName . '-provider_id'] = $value['im_provider_id'];
                                         } else {
                                             $defaults[$fldName] = $value[$fieldName];
                                         }
                                     } elseif (substr($fieldName, 0, 14) === 'address_custom' && CRM_Utils_Array::value(substr($fieldName, 8), $value)) {
                                         $defaults[$fldName] = $value[substr($fieldName, 8)];
                                     }
                                 }
                             }
                         }
                     }
                 } else {
                     if (is_array($details)) {
                         if ($fieldName === 'url' && !empty($details['website']) && !empty($details['website'][$locTypeId])) {
                             $defaults[$fldName] = CRM_Utils_Array::value('url', $details['website'][$locTypeId]);
                         }
                     }
                 }
             }
         }
     }
     //Handling Contribution Part of the batch profile
     if (CRM_Core_Permission::access('CiviContribute') && $component == 'Contribute') {
         self::setComponentDefaults($fields, $componentId, $component, $defaults);
     }
     //Handling Event Participation Part of the batch profile
     if (CRM_Core_Permission::access('CiviEvent') && $component == 'Event') {
         self::setComponentDefaults($fields, $componentId, $component, $defaults);
     }
     //Handling membership Part of the batch profile
     if (CRM_Core_Permission::access('CiviMember') && $component == 'Membership') {
         self::setComponentDefaults($fields, $componentId, $component, $defaults);
     }
     //Handling Activity Part of the batch profile
     if ($component == 'Activity') {
         self::setComponentDefaults($fields, $componentId, $component, $defaults);
     }
 }
Beispiel #22
0
 /**
  * the main function that is called when the page loads, it decides the which action has to be taken for the page.
  *
  * @return null
  */
 public function run()
 {
     $this->preProcess();
     // check if we can process credit card membership
     $newCredit = CRM_Core_Config::isEnabledBackOfficeCreditCardPayments();
     $this->assign('newCredit', $newCredit);
     if ($newCredit) {
         $this->_isPaymentProcessor = TRUE;
     } else {
         $this->_isPaymentProcessor = FALSE;
     }
     // Only show credit card membership signup if user has CiviContribute permission
     if (CRM_Core_Permission::access('CiviContribute')) {
         $this->_accessContribution = TRUE;
         $this->assign('accessContribution', TRUE);
         //show associated soft credit when contribution payment is paid by different person
         if ($this->_id && $this->_contactId) {
             $filter = " AND cc.id IN (SELECT contribution_id FROM civicrm_membership_payment WHERE membership_id = {$this->_id})";
             $softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, $filter);
             if (!empty($softCreditList)) {
                 $this->assign('softCredit', TRUE);
                 $this->assign('softCreditRows', $softCreditList);
             }
         }
     } else {
         $this->_accessContribution = FALSE;
         $this->assign('accessContribution', FALSE);
         $this->assign('softCredit', FALSE);
     }
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->view();
     } elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE | CRM_Core_Action::RENEW)) {
         self::setContext($this);
         $this->edit();
     } else {
         self::setContext($this);
         $this->browse();
     }
     return parent::run();
 }
Beispiel #23
0
 /**
  * Build the form
  *
  * @access public
  *
  * @return void
  */
 function buildQuickForm()
 {
     $this->set('context', 'advanced');
     $this->_searchPane = CRM_Utils_Array::value('searchPane', $_GET);
     $this->_searchOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'advanced_search_options');
     if (!$this->_searchPane || $this->_searchPane == 'basic') {
         CRM_Contact_Form_Search_Criteria::basic($this);
     }
     $allPanes = array();
     $paneNames = array(ts('Address Fields') => 'location', ts('Custom Fields') => 'custom', ts('Activities') => 'activity', ts('Relationships') => 'relationship', ts('Demographics') => 'demographics', ts('Notes') => 'notes', ts('Change Log') => 'changeLog');
     //check if there are any custom data searchable fields
     $groupDetails = array();
     $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'), CRM_Contact_BAO_ContactType::subTypes());
     $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
     // if no searchable fields unset panel
     if (empty($groupDetails)) {
         unset($paneNames[ts('Custom Fields')]);
     }
     foreach ($paneNames as $name => $type) {
         if (!$this->_searchOptions[$type]) {
             unset($paneNames[$name]);
         }
     }
     $components = CRM_Core_Component::getEnabledComponents();
     $componentPanes = array();
     foreach ($components as $name => $component) {
         if (in_array($name, array_keys($this->_searchOptions)) && $this->_searchOptions[$name] && CRM_Core_Permission::access($component->name)) {
             $componentPanes[$name] = $component->registerAdvancedSearchPane();
             $componentPanes[$name]['name'] = $name;
         }
     }
     usort($componentPanes, array('CRM_Utils_Sort', 'cmpFunc'));
     foreach ($componentPanes as $name => $pane) {
         // FIXME: we should change the use of $name here to keyword
         $paneNames[$pane['title']] = $pane['name'];
     }
     $hookPanes = array();
     CRM_Contact_BAO_Query_Hook::singleton()->registerAdvancedSearchPane($hookPanes);
     $paneNames = array_merge($paneNames, $hookPanes);
     $this->_paneTemplatePath = array();
     foreach ($paneNames as $name => $type) {
         if (!array_key_exists($type, $this->_searchOptions) && !in_array($type, $hookPanes)) {
             continue;
         }
         $allPanes[$name] = array('url' => CRM_Utils_System::url('civicrm/contact/search/advanced', "snippet=1&searchPane={$type}&qfKey={$this->controller->_key}"), 'open' => 'false', 'id' => $type);
         // see if we need to include this paneName in the current form
         if ($this->_searchPane == $type || CRM_Utils_Array::value("hidden_{$type}", $_POST) || CRM_Utils_Array::value("hidden_{$type}", $this->_formValues)) {
             $allPanes[$name]['open'] = 'true';
             if (CRM_Utils_Array::value($type, $components)) {
                 $c = $components[$type];
                 $this->add('hidden', "hidden_{$type}", 1);
                 $c->buildAdvancedSearchPaneForm($this);
                 $this->_paneTemplatePath[$type] = $c->getAdvancedSearchPaneTemplatePath();
             } else {
                 if (in_array($type, $hookPanes)) {
                     CRM_Contact_BAO_Query_Hook::singleton()->buildAdvancedSearchPaneForm($this, $type);
                     CRM_Contact_BAO_Query_Hook::singleton()->setAdvancedSearchPaneTemplatePath($this->_paneTemplatePath, $type);
                 } else {
                     CRM_Contact_Form_Search_Criteria::$type($this);
                     $template = ucfirst($type);
                     $this->_paneTemplatePath[$type] = "CRM/Contact/Form/Search/Criteria/{$template}.tpl";
                 }
             }
         }
     }
     $this->assign('allPanes', $allPanes);
     if (!$this->_searchPane) {
         parent::buildQuickForm();
     } else {
         $this->assign('suppressForm', TRUE);
     }
 }
 /**
  * This function is used for the to show the associated
  * contribution for the membership
  * @form array $form (ref.) an assoc array of name/value pairs
  * return null
  * @access public
  */
 function associatedContribution($contactId = NULL, $membershipId = NULL)
 {
     if (!$contactId) {
         $contactId = $this->_contactId;
     }
     if (!$membershipId) {
         $membershipId = $this->_id;
     }
     // retrieive membership contributions if the $membershipId is set
     if (CRM_Core_Permission::access('CiviContribute') && $membershipId) {
         $this->assign('accessContribution', TRUE);
         $controller = new CRM_Core_Controller_Simple('CRM_Contribute_Form_Search', ts('Contributions'), NULL);
         $controller->setEmbedded(TRUE);
         $controller->reset();
         $controller->set('force', 1);
         $controller->set('cid', $contactId);
         $controller->set('memberId', $membershipId);
         $controller->set('context', 'contribution');
         $controller->process();
         $controller->run();
     } else {
         $this->assign('accessContribution', FALSE);
     }
 }
Beispiel #25
0
 /**
  * @return array
  */
 public static function getModeSelect()
 {
     self::setModeValues();
     $select = array();
     foreach (self::$_modeValues as $id => &$value) {
         $select[$id] = $value['selectorLabel'];
     }
     // unset contributions or participants if user does not have
     // permission on them
     if (!CRM_Core_Permission::access('CiviContribute')) {
         unset($select['2']);
     }
     if (!CRM_Core_Permission::access('CiviEvent')) {
         unset($select['3']);
     }
     if (!CRM_Core_Permission::check('view all activities')) {
         unset($select['4']);
     }
     return $select;
 }
Beispiel #26
0
 /**
  * Function to get the list the export fields
  *
  * @param int    $selectAll user preference while export
  * @param array  $ids  contact ids
  * @param array  $params associated array of fields
  * @param string $order order by clause
  * @param array  $associated array of fields
  * @param array  $moreReturnProperties additional return fields
  * @param int    $exportMode export mode
  * @param string $componentClause component clause
  *
  * @static
  * @access public
  */
 static function exportComponents($selectAll, $ids, $params, $order = null, $fields = null, $moreReturnProperties = null, $exportMode = CRM_Export_Form_Select::CONTACT_EXPORT, $componentClause = null)
 {
     $headerRows = array();
     $primary = false;
     $returnProperties = array();
     $origFields = $fields;
     $queryMode = null;
     $paymentFields = false;
     $phoneTypes = CRM_Core_PseudoConstant::phoneType();
     $imProviders = CRM_Core_PseudoConstant::IMProvider();
     $contactRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, null, true, 'label', false);
     $queryMode = CRM_Contact_BAO_Query::MODE_CONTACTS;
     switch ($exportMode) {
         case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
             $queryMode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE;
             break;
         case CRM_Export_Form_Select::EVENT_EXPORT:
             $queryMode = CRM_Contact_BAO_Query::MODE_EVENT;
             break;
         case CRM_Export_Form_Select::MEMBER_EXPORT:
             $queryMode = CRM_Contact_BAO_Query::MODE_MEMBER;
             break;
         case CRM_Export_Form_Select::PLEDGE_EXPORT:
             $queryMode = CRM_Contact_BAO_Query::MODE_PLEDGE;
             break;
         case CRM_Export_Form_Select::CASE_EXPORT:
             $queryMode = CRM_Contact_BAO_Query::MODE_CASE;
             break;
         case CRM_Export_Form_Select::GRANT_EXPORT:
             $queryMode = CRM_Contact_BAO_Query::MODE_GRANT;
             break;
     }
     require_once 'CRM/Core/BAO/CustomField.php';
     if ($fields) {
         //construct return properties
         $locationTypes =& CRM_Core_PseudoConstant::locationType();
         $locationTypeFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'phone', 'email', 'im');
         foreach ($fields as $key => $value) {
             $phoneTypeId = null;
             $imProviderId = null;
             $relationshipTypes = $fieldName = CRM_Utils_Array::value(1, $value);
             if (!$fieldName) {
                 continue;
             }
             // get phoneType id and IM service provider id seperately
             if ($fieldName == 'phone') {
                 $phoneTypeId = CRM_Utils_Array::value(3, $value);
             } else {
                 if ($fieldName == 'im') {
                     $imProviderId = CRM_Utils_Array::value(3, $value);
                 }
             }
             if (array_key_exists($relationshipTypes, $contactRelationshipTypes)) {
                 if (CRM_Utils_Array::value(2, $value)) {
                     $relationField = CRM_Utils_Array::value(2, $value);
                     if (trim(CRM_Utils_Array::value(3, $value))) {
                         $relLocTypeId = CRM_Utils_Array::value(3, $value);
                     } else {
                         $relLocTypeId = 1;
                     }
                     if ($relationField == 'phone') {
                         $relPhoneTypeId = CRM_Utils_Array::value(4, $value);
                     } else {
                         if ($relationField == 'im') {
                             $relIMProviderId = CRM_Utils_Array::value(4, $value);
                         }
                     }
                 } else {
                     if (CRM_Utils_Array::value(4, $value)) {
                         $relationField = CRM_Utils_Array::value(4, $value);
                         $relLocTypeId = CRM_Utils_Array::value(5, $value);
                         if ($relationField == 'phone') {
                             $relPhoneTypeId = CRM_Utils_Array::value(6, $value);
                         } else {
                             if ($relationField == 'im') {
                                 $relIMProviderId = CRM_Utils_Array::value(6, $value);
                             }
                         }
                     }
                 }
             }
             $contactType = CRM_Utils_Array::value(0, $value);
             $locTypeId = CRM_Utils_Array::value(2, $value);
             $phoneTypeId = CRM_Utils_Array::value(3, $value);
             if ($relationField) {
                 if (in_array($relationField, $locationTypeFields)) {
                     if ($relPhoneTypeId) {
                         $returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]]['phone-' . $relPhoneTypeId] = 1;
                     } else {
                         if ($relIMProviderId) {
                             $returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]]['im-' . $relIMProviderId] = 1;
                         } else {
                             $returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]][$relationField] = 1;
                         }
                     }
                     $relPhoneTypeId = $relIMProviderId = null;
                 } else {
                     $returnProperties[$relationshipTypes][$relationField] = 1;
                 }
             } else {
                 if (is_numeric($locTypeId)) {
                     if ($phoneTypeId) {
                         $returnProperties['location'][$locationTypes[$locTypeId]]['phone-' . $phoneTypeId] = 1;
                     } else {
                         if (isset($imProviderId)) {
                             //build returnProperties for IM service provider
                             $returnProperties['location'][$locationTypes[$locTypeId]]['im-' . $imProviderId] = 1;
                         } else {
                             $returnProperties['location'][$locationTypes[$locTypeId]][$fieldName] = 1;
                         }
                     }
                 } else {
                     //hack to fix component fields
                     if ($fieldName == 'event_id') {
                         $returnProperties['event_title'] = 1;
                     } else {
                         $returnProperties[$fieldName] = 1;
                     }
                 }
             }
         }
         // hack to add default returnproperty based on export mode
         if ($exportMode == CRM_Export_Form_Select::CONTRIBUTE_EXPORT) {
             $returnProperties['contribution_id'] = 1;
         } else {
             if ($exportMode == CRM_Export_Form_Select::EVENT_EXPORT) {
                 $returnProperties['participant_id'] = 1;
             } else {
                 if ($exportMode == CRM_Export_Form_Select::MEMBER_EXPORT) {
                     $returnProperties['membership_id'] = 1;
                 } else {
                     if ($exportMode == CRM_Export_Form_Select::PLEDGE_EXPORT) {
                         $returnProperties['pledge_id'] = 1;
                     } else {
                         if ($exportMode == CRM_Export_Form_Select::CASE_EXPORT) {
                             $returnProperties['case_id'] = 1;
                         } else {
                             if ($exportMode == CRM_Export_Form_Select::GRANT_EXPORT) {
                                 $returnProperties['grant_id'] = 1;
                             }
                         }
                     }
                 }
             }
         }
     } else {
         $primary = true;
         $fields = CRM_Contact_BAO_Contact::exportableFields('All', true, true);
         foreach ($fields as $key => $var) {
             if ($key && substr($key, 0, 6) != 'custom') {
                 //for CRM=952
                 $returnProperties[$key] = 1;
             }
         }
         if ($primary) {
             $returnProperties['location_type'] = 1;
             $returnProperties['im_provider'] = 1;
             $returnProperties['phone_type_id'] = 1;
             $returnProperties['provider_id'] = 1;
             $returnProperties['current_employer'] = 1;
         }
         $extraReturnProperties = array();
         $paymentFields = false;
         switch ($queryMode) {
             case CRM_Contact_BAO_Query::MODE_EVENT:
                 $paymentFields = true;
                 $paymentTableId = "participant_id";
                 break;
             case CRM_Contact_BAO_Query::MODE_MEMBER:
                 $paymentFields = true;
                 $paymentTableId = "membership_id";
                 break;
             case CRM_Contact_BAO_Query::MODE_PLEDGE:
                 require_once 'CRM/Pledge/BAO/Query.php';
                 $extraReturnProperties = CRM_Pledge_BAO_Query::extraReturnProperties($queryMode);
                 $paymentFields = true;
                 $paymentTableId = "pledge_payment_id";
                 break;
             case CRM_Contact_BAO_Query::MODE_CASE:
                 require_once 'CRM/Case/BAO/Query.php';
                 $extraReturnProperties = CRM_Case_BAO_Query::extraReturnProperties($queryMode);
                 break;
         }
         if ($queryMode != CRM_Contact_BAO_Query::MODE_CONTACTS) {
             $componentReturnProperties =& CRM_Contact_BAO_Query::defaultReturnProperties($queryMode);
             $returnProperties = array_merge($returnProperties, $componentReturnProperties);
             if (!empty($extraReturnProperties)) {
                 $returnProperties = array_merge($returnProperties, $extraReturnProperties);
             }
             // unset groups, tags, notes for components
             foreach (array('groups', 'tags', 'notes') as $value) {
                 unset($returnProperties[$value]);
             }
         }
     }
     if ($moreReturnProperties) {
         $returnProperties = array_merge($returnProperties, $moreReturnProperties);
     }
     $query =& new CRM_Contact_BAO_Query(0, $returnProperties, null, false, false, $queryMode);
     list($select, $from, $where) = $query->query();
     $allRelContactArray = $relationQuery = array();
     foreach ($contactRelationshipTypes as $rel => $dnt) {
         if ($relationReturnProperties = CRM_Utils_Array::value($rel, $returnProperties)) {
             $allRelContactArray[$rel] = array();
             // build Query for each relationship
             $relationQuery[$rel] =& new CRM_Contact_BAO_Query(0, $relationReturnProperties, null, false, false, $queryMode);
             list($relationSelect, $relationFrom, $relationWhere) = $relationQuery[$rel]->query();
             list($id, $direction) = explode('_', $rel, 2);
             // identify the relationship direction
             $contactA = 'contact_id_a';
             $contactB = 'contact_id_b';
             if ($direction == 'b_a') {
                 $contactA = 'contact_id_b';
                 $contactB = 'contact_id_a';
             }
             $relIDs = implode(',', $ids);
             $relSQL = "SELECT {$contactB} as relContact,{$contactA} as refContact  FROM civicrm_relationship \n                           WHERE  relationship_type_id = {$id} AND\n                                  {$contactA} IN ({$relIDs})\n                           GROUP BY {$contactA}";
             // Get the related contacts
             $relContactDAO = CRM_Core_DAO::executeQuery($relSQL);
             $relContactArray = array();
             while ($relContactDAO->fetch()) {
                 $relContactArray[$relContactDAO->refContact] = $relContactDAO->relContact;
             }
             $uniqueContacts = array_unique($relContactArray);
             if (!empty($uniqueContacts)) {
                 $relationWhere = " WHERE contact_a.id IN (" . implode(',', $uniqueContacts) . ") GROUP BY contact_id";
                 $relationQueryString = "{$relationSelect} {$relationFrom} {$relationWhere}";
                 $allRelContactDAO = CRM_Core_DAO::executeQuery($relationQueryString);
                 while ($allRelContactDAO->fetch()) {
                     foreach ($relContactArray as $k => $v) {
                         if ($allRelContactDAO->contact_id == $v) {
                             //$allRelContactArray[$rel][$k] = array();
                             // build the array of all related contacts
                             $allRelContactArray[$rel][$k] = clone $allRelContactDAO;
                         }
                     }
                 }
             }
         }
     }
     // make sure the groups stuff is included only if specifically specified
     // by the fields param (CRM-1969), else we limit the contacts outputted to only
     // ones that are part of a group
     if (CRM_Utils_Array::value('groups', $returnProperties)) {
         $oldClause = "contact_a.id = civicrm_group_contact.contact_id";
         $newClause = " ( {$oldClause} AND civicrm_group_contact.status = 'Added' OR civicrm_group_contact.status IS NULL ) ";
         // total hack for export, CRM-3618
         $from = str_replace($oldClause, $newClause, $from);
     }
     if ($componentClause) {
         if (empty($where)) {
             $where = "WHERE {$componentClause}";
         } else {
             $where .= " AND {$componentClause}";
         }
     }
     $queryString = "{$select} {$from} {$where}";
     if (CRM_Utils_Array::value('tags', $returnProperties) || CRM_Utils_Array::value('groups', $returnProperties) || CRM_Utils_Array::value('notes', $returnProperties) || $query->_useGroupBy) {
         $queryString .= " GROUP BY contact_a.id";
     }
     if ($order) {
         list($field, $dir) = explode(' ', $order, 2);
         $field = trim($field);
         if (CRM_Utils_Array::value($field, $returnProperties)) {
             $queryString .= " ORDER BY {$order}";
         }
     }
     //hack for student data
     require_once 'CRM/Core/OptionGroup.php';
     $multipleSelectFields = array('preferred_communication_method' => 1);
     if (CRM_Core_Permission::access('Quest')) {
         require_once 'CRM/Quest/BAO/Student.php';
         $studentFields = array();
         $studentFields = CRM_Quest_BAO_Student::$multipleSelectFields;
         $multipleSelectFields = array_merge($multipleSelectFields, $studentFields);
     }
     $dao =& CRM_Core_DAO::executeQuery($queryString, CRM_Core_DAO::$_nullArray);
     $header = false;
     $addPaymentHeader = false;
     if ($paymentFields) {
         $addPaymentHeader = true;
         //special return properties for event and members
         $paymentHeaders = array(ts('Total Amount'), ts('Contribution Status'), ts('Received Date'), ts('Payment Instrument'), ts('Transaction ID'));
         // get payment related in for event and members
         require_once 'CRM/Contribute/BAO/Contribution.php';
         $paymentDetails = CRM_Contribute_BAO_Contribution::getContributionDetails($exportMode, $ids);
     }
     $componentDetails = $headerRows = array();
     $setHeader = true;
     while ($dao->fetch()) {
         $row = array();
         //first loop through returnproperties so that we return what is required, and in same order.
         $relationshipField = 0;
         foreach ($returnProperties as $field => $value) {
             //we should set header only once
             if ($setHeader) {
                 if (isset($query->_fields[$field]['title'])) {
                     $headerRows[] = $query->_fields[$field]['title'];
                 } else {
                     if ($field == 'phone_type_id') {
                         $headerRows[] = 'Phone Type';
                     } else {
                         if ($field == 'provider_id') {
                             $headerRows[] = 'Im Service Provider';
                         } else {
                             if (is_array($value) && $field == 'location') {
                                 // fix header for location type case
                                 foreach ($value as $ltype => $val) {
                                     foreach (array_keys($val) as $fld) {
                                         $type = explode('-', $fld);
                                         $hdr = "{$ltype}-" . $query->_fields[$type[0]]['title'];
                                         if (CRM_Utils_Array::value(1, $type)) {
                                             if (CRM_Utils_Array::value(0, $type) == 'phone') {
                                                 $hdr .= "-" . CRM_Utils_Array::value($type[1], $phoneTypes);
                                             } else {
                                                 if (CRM_Utils_Array::value(0, $type) == 'im') {
                                                     $hdr .= "-" . CRM_Utils_Array::value($type[1], $imProviders);
                                                 }
                                             }
                                         }
                                         $headerRows[] = $hdr;
                                     }
                                 }
                             } else {
                                 if (substr($field, 0, 5) == 'case_') {
                                     if ($query->_fields['case'][$field]['title']) {
                                         $headerRows[] = $query->_fields['case'][$field]['title'];
                                     } else {
                                         if ($query->_fields['activity'][$field]['title']) {
                                             $headerRows[] = $query->_fields['activity'][$field]['title'];
                                         }
                                     }
                                 } else {
                                     if (array_key_exists($field, $contactRelationshipTypes)) {
                                         $relName = CRM_Utils_Array::value($field, $contactRelationshipTypes);
                                         foreach ($value as $relationField => $relationValue) {
                                             // below block is same as primary block (duplicate)
                                             if (isset($relationQuery[$field]->_fields[$relationField]['title'])) {
                                                 $headerRows[] = $relName . '-' . $relationQuery[$field]->_fields[$relationField]['title'];
                                             } else {
                                                 if ($relationField == 'phone_type_id') {
                                                     $headerRows[] = $relName . '-' . 'Phone Type';
                                                 } else {
                                                     if ($relationField == 'provider_id') {
                                                         $headerRows[] = $relName . '-' . 'Im Service Provider';
                                                     } else {
                                                         if (is_array($relationValue) && $relationField == 'location') {
                                                             // fix header for location type case
                                                             foreach ($relationValue as $ltype => $val) {
                                                                 foreach (array_keys($val) as $fld) {
                                                                     $type = explode('-', $fld);
                                                                     $hdr = "{$ltype}-" . $relationQuery[$field]->_fields[$type[0]]['title'];
                                                                     if (CRM_Utils_Array::value(1, $type)) {
                                                                         if (CRM_Utils_Array::value(0, $type) == 'phone') {
                                                                             $hdr .= "-" . CRM_Utils_Array::value($type[1], $phoneTypes);
                                                                         } else {
                                                                             if (CRM_Utils_Array::value(0, $type) == 'im') {
                                                                                 $hdr .= "-" . CRM_Utils_Array::value($type[1], $imProviders);
                                                                             }
                                                                         }
                                                                     }
                                                                     $headerRows[] = $relName . '-' . $hdr;
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     } else {
                                         $headerRows[] = $field;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             //build row values (data)
             if (property_exists($dao, $field)) {
                 $fieldValue = $dao->{$field};
                 // to get phone type from phone type id
                 if ($field == 'phone_type_id') {
                     $fieldValue = $phoneTypes[$fieldValue];
                 } else {
                     if ($field == 'provider_id') {
                         $fieldValue = CRM_Utils_Array::value($fieldValue, $imProviders);
                     }
                 }
             } else {
                 $fieldValue = '';
             }
             if ($field == 'id') {
                 $row[$field] = $dao->contact_id;
             } else {
                 if ($field == 'pledge_balance_amount') {
                     //special case for calculated field
                     $row[$field] = $dao->pledge_amount - $dao->pledge_total_paid;
                 } else {
                     if ($field == 'pledge_next_pay_amount') {
                         //special case for calculated field
                         $row[$field] = $dao->pledge_next_pay_amount + $dao->pledge_outstanding_amount;
                     } else {
                         if (is_array($value) && $field == 'location') {
                             // fix header for location type case
                             foreach ($value as $ltype => $val) {
                                 foreach (array_keys($val) as $fld) {
                                     $type = explode('-', $fld);
                                     $fldValue = "{$ltype}-" . $type[0];
                                     if (CRM_Utils_Array::value(1, $type)) {
                                         $fldValue .= "-" . $type[1];
                                     }
                                     $row[$fldValue] = $dao->{$fldValue};
                                 }
                             }
                         } else {
                             if (array_key_exists($field, $contactRelationshipTypes)) {
                                 $relDAO = $allRelContactArray[$field][$dao->contact_id];
                                 foreach ($value as $relationField => $relationValue) {
                                     if (is_object($relDAO) && property_exists($relDAO, $relationField)) {
                                         $fieldValue = $relDAO->{$relationField};
                                         if ($relationField == 'phone_type_id') {
                                             $fieldValue = $phoneTypes[$relationValue];
                                         } else {
                                             if ($relationField == 'provider_id') {
                                                 $fieldValue = CRM_Utils_Array::value($relationValue, $imProviders);
                                             }
                                         }
                                     } else {
                                         $fieldValue = '';
                                     }
                                     if ($relationField == 'id') {
                                         $row[$field . $relationField] = $relDAO->contact_id;
                                     } else {
                                         if (is_array($relationValue) && $relationField == 'location') {
                                             foreach ($relationValue as $ltype => $val) {
                                                 foreach (array_keys($val) as $fld) {
                                                     $type = explode('-', $fld);
                                                     $fldValue = "{$ltype}-" . $type[0];
                                                     if (CRM_Utils_Array::value(1, $type)) {
                                                         $fldValue .= "-" . $type[1];
                                                     }
                                                     $row[$field . $fldValue] = $relDAO->{$fldValue};
                                                 }
                                             }
                                         } else {
                                             if (isset($fieldValue) && $fieldValue != '') {
                                                 //check for custom data
                                                 if ($cfID = CRM_Core_BAO_CustomField::getKeyID($relationField)) {
                                                     $row[$field . $relationField] = CRM_Core_BAO_CustomField::getDisplayValue($fieldValue, $cfID, $relationQuery[$field]->_options);
                                                 } else {
                                                     if (in_array($relationField, array('email_greeting', 'postal_greeting', 'addressee'))) {
                                                         //special case for greeting replacement
                                                         $fldValue = "{$relationField}_display";
                                                         $row[$field . $relationField] = $relDAO->{$fldValue};
                                                     } else {
                                                         //normal relationship fields
                                                         $row[$field . $relationField] = $fieldValue;
                                                     }
                                                 }
                                             } else {
                                                 // if relation field is empty or null
                                                 $row[$field . $relationField] = '';
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if (isset($fieldValue) && $fieldValue != '') {
                                     //check for custom data
                                     if ($cfID = CRM_Core_BAO_CustomField::getKeyID($field)) {
                                         $row[$field] = CRM_Core_BAO_CustomField::getDisplayValue($fieldValue, $cfID, $query->_options);
                                     } else {
                                         if (array_key_exists($field, $multipleSelectFields)) {
                                             //option group fixes
                                             $paramsNew = array($field => $fieldValue);
                                             if ($field == 'test_tutoring') {
                                                 $name = array($field => array('newName' => $field, 'groupName' => 'test'));
                                             } else {
                                                 if (substr($field, 0, 4) == 'cmr_') {
                                                     //for  readers group
                                                     $name = array($field => array('newName' => $field, 'groupName' => substr($field, 0, -3)));
                                                 } else {
                                                     $name = array($field => array('newName' => $field, 'groupName' => $field));
                                                 }
                                             }
                                             CRM_Core_OptionGroup::lookupValues($paramsNew, $name, false);
                                             $row[$field] = $paramsNew[$field];
                                         } else {
                                             if (in_array($field, array('email_greeting', 'postal_greeting', 'addressee'))) {
                                                 //special case for greeting replacement
                                                 $fldValue = "{$field}_display";
                                                 $row[$field] = $dao->{$fldValue};
                                             } else {
                                                 //normal fields
                                                 $row[$field] = $fieldValue;
                                             }
                                         }
                                     }
                                 } else {
                                     // if field is empty or null
                                     $row[$field] = '';
                                 }
                             }
                         }
                     }
                 }
             }
         }
         //build header only once
         $setHeader = false;
         // add payment headers if required
         if ($addPaymentHeader && $paymentFields) {
             $headerRows = array_merge($headerRows, $paymentHeaders);
             $addPaymentHeader = false;
         }
         // add payment related information
         if ($paymentFields && isset($paymentDetails[$row[$paymentTableId]])) {
             $row = array_merge($row, $paymentDetails[$row[$paymentTableId]]);
         }
         //remove organization name for individuals if it is set for current employer
         if (CRM_Utils_Array::value('contact_type', $row) && $row['contact_type'] == 'Individual') {
             $row['organization_name'] = '';
         }
         // CRM-3157: localise the output
         // FIXME: we should move this to multilingual stack some day
         require_once 'CRM/Core/I18n.php';
         $i18n =& CRM_Core_I18n::singleton();
         $translatable = array('preferred_communication_method', 'preferred_mail_format', 'gender', 'state_province', 'country', 'world_region');
         foreach ($translatable as $column) {
             if (isset($row[$column]) and $row[$column]) {
                 $row[$column] = $i18n->translate($row[$column]);
             }
         }
         // add component info
         $componentDetails[] = $row;
     }
     require_once 'CRM/Core/Report/Excel.php';
     CRM_Core_Report_Excel::writeCSVFile(self::getExportFileName('csv', $exportMode), $headerRows, $componentDetails);
     exit;
 }
Beispiel #27
0
 /**
  * returns all the rows in the given offset and rowCount
  *
  * @param enum   $action   the action being performed
  * @param int    $offset   the row number to start from
  * @param int    $rowCount the number of rows to return
  * @param string $sort     the sql string that describes the sort order
  * @param enum   $output   what should the result set include (web/email/csv)
  *
  * @return int   the total number of rows for this action
  */
 function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     // check if we can process credit card registration
     $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
     if (count($processors) > 0) {
         $this->_isPaymentProcessor = TRUE;
     } else {
         $this->_isPaymentProcessor = FALSE;
     }
     // Only show credit card membership signup and renewal if user has CiviContribute permission
     if (CRM_Core_Permission::access('CiviContribute')) {
         $this->_accessContribution = TRUE;
     } else {
         $this->_accessContribution = FALSE;
     }
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_memberClause);
     // process the result of the query
     $rows = array();
     //CRM-4418 check for view, edit, delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit memberships')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviMember')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (property_exists($result, $property)) {
                 $row[$property] = $result->{$property};
             }
         }
         //carry campaign on selectors.
         $row['campaign'] = CRM_Utils_Array::value($result->member_campaign_id, $allCampaigns);
         $row['campaign_id'] = $result->member_campaign_id;
         if (!empty($row['member_is_test'])) {
             $row['membership_type'] = $row['membership_type'] . " (test)";
         }
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->membership_id;
         if (!isset($result->owner_membership_id)) {
             // unset renew and followup link for deceased membership
             $currentMask = $mask;
             if ($result->membership_status == 'Deceased') {
                 $currentMask = $currentMask & ~CRM_Core_Action::RENEW & ~CRM_Core_Action::FOLLOWUP;
             }
             $isCancelSupported = CRM_Member_BAO_Membership::isCancelSubscriptionSupported($row['membership_id']);
             $row['action'] = CRM_Core_Action::formLink(self::links('all', $this->_isPaymentProcessor, $this->_accessContribution, $this->_key, $this->_context, $isCancelSupported), $currentMask, array('id' => $result->membership_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'membership.selector.row', 'Membership', $result->membership_id);
         } else {
             $row['action'] = CRM_Core_Action::formLink(self::links('view'), $mask, array('id' => $result->membership_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'membership.selector.row', 'Membership', $result->membership_id);
         }
         //does membership have auto renew CRM-7137.
         $autoRenew = FALSE;
         if (isset($result->membership_recur_id) && $result->membership_recur_id && !CRM_Member_BAO_Membership::isSubscriptionCancelled($row['membership_id'])) {
             $autoRenew = TRUE;
         }
         $row['auto_renew'] = $autoRenew;
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id);
         $rows[] = $row;
     }
     return $rows;
 }
 /**
  *  This function is called when the form is submitted 
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     $quickSave = false;
     if (CRM_Utils_Array::value('_qf_Relationship_refresh_save', $_POST) || CRM_Utils_Array::value('_qf_Relationship_refresh_savedetails', $_POST)) {
         $quickSave = true;
     }
     $this->set('searchDone', 0);
     $this->set('callAjax', false);
     if (CRM_Utils_Array::value('_qf_Relationship_refresh', $_POST) || $quickSave) {
         if (is_numeric($params['rel_contact_id'])) {
             if ($quickSave) {
                 $params['contact_check'] = array($params['rel_contact_id'] => 1);
             } else {
                 $this->search($params);
                 $quickSave = false;
             }
         } else {
             $this->set('callAjax', true);
             $this->set('relType', $params['relationship_type_id']);
             $this->set('relContact', $params['rel_contact']);
             $quickSave = false;
         }
         $this->set('searchDone', 1);
         if (!$quickSave) {
             return;
         }
     }
     // action is taken depending upon the mode
     $ids = array();
     $ids['contact'] = $this->_contactId;
     // modify params for ajax call
     $this->modifyParams($params);
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Contact_BAO_Relationship::del($this->_relationshipId);
         return;
     }
     $relationshipTypeId = str_replace(array('_a_b', '_b_a'), array('', ''), $params['relationship_type_id']);
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $ids['relationship'] = $this->_relationshipId;
         $relation = CRM_Contact_BAO_Relationship::getContactIds($this->_relationshipId);
         $ids['contactTarget'] = $relation->contact_id_a == $this->_contactId ? $relation->contact_id_b : $relation->contact_id_a;
         //if relationship type change and previously it was
         //employer / emplyee relationship with current employer
         //than clear the current employer. CRM-3235.
         //make sure we has to have employer id before firing queries, CRM-7306
         $employerId = CRM_Utils_Array::value('current_employee_id', $this->_values);
         $isDisabled = true;
         if (CRM_Utils_Array::value('is_active', $params)) {
             $isDisabled = false;
         }
         $relChanged = true;
         if ($relationshipTypeId == $this->_values['relationship_type_id']) {
             $relChanged = false;
         }
         if ($employerId && ($isDisabled || $relChanged)) {
             require_once 'CRM/Contact/BAO/Contact/Utils.php';
             CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_values['current_employee_id']);
         }
     } elseif ($quickSave) {
         if ($params['add_current_employee'] && $this->_allRelationshipNames[$relationshipTypeId]["name_a_b"] == 'Employee of') {
             $params['employee_of'] = $params['rel_contact_id'];
         } elseif ($params['add_current_employer'] && $this->_allRelationshipNames[$relationshipTypeId]["name_b_a"] == 'Employer of') {
             $params['employer_of'] = array($params['rel_contact_id'] => 1);
         }
         if (!$this->_rtype) {
             $this->_rtype = str_replace($relationshipTypeId . '_', '', $params['relationship_type_id']);
         }
     }
     $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], null, true);
     $params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], null, true);
     //special case to handle if all checkboxes are unchecked
     $customFields = CRM_Core_BAO_CustomField::getFields('Relationship', false, false, $relationshipTypeId);
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_relationshipId, 'Relationship');
     list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::create($params, $ids);
     // if this is called from case view,
     //create an activity for case role removal.CRM-4480
     if ($this->_caseId) {
         require_once "CRM/Case/BAO/Case.php";
         CRM_Case_BAO_Case::createCaseRoleActivity($this->_caseId, $relationshipIds, $params['contact_check'], $this->_contactId);
     }
     $status = '';
     if ($valid) {
         $status .= ' ' . ts('%count new relationship record created.', array('count' => $valid, 'plural' => '%count new relationship records created.'));
     }
     if ($invalid) {
         $status .= ' ' . ts('%count relationship record not created due to invalid target contact type.', array('count' => $invalid, 'plural' => '%count relationship records not created due to invalid target contact type.'));
     }
     if ($duplicate) {
         $status .= ' ' . ts('%count relationship record not created - duplicate of existing relationship.', array('count' => $duplicate, 'plural' => '%count relationship records not created - duplicate of existing relationship.'));
     }
     if ($saved) {
         $status .= ts('Relationship record has been updated.');
     }
     $note = new CRM_Core_DAO_Note();
     $note->entity_id = $relationshipIds[0];
     $note->entity_table = 'civicrm_relationship';
     $noteIds = array();
     if ($note->find(true)) {
         $id = $note->id;
         $noteIds["id"] = $id;
     }
     $noteParams = array('entity_id' => $relationshipIds[0], 'entity_table' => 'civicrm_relationship', 'note' => $params['note'], 'contact_id' => $this->_contactId);
     CRM_Core_BAO_Note::add($noteParams, $noteIds);
     // Membership for related contacts CRM-1657
     if (CRM_Core_Permission::access('CiviMember') && !$duplicate) {
         CRM_Contact_BAO_Relationship::relatedMemberships($this->_contactId, $params, $ids, $this->_action);
     }
     //handle current employee/employer relationship, CRM-3532
     if ($this->_allRelationshipNames[$relationshipTypeId]["name_{$this->_rtype}"] == 'Employee of') {
         $orgId = null;
         if (CRM_Utils_Array::value('employee_of', $params)) {
             $orgId = $params['employee_of'];
         } else {
             if ($this->_action & CRM_Core_Action::UPDATE) {
                 if (CRM_Utils_Array::value('is_current_employer', $params) && CRM_Utils_Array::value('is_active', $params)) {
                     if (CRM_Utils_Array::value('contactTarget', $ids) != CRM_Utils_Array::value('current_employer_id', $this->_values)) {
                         $orgId = CRM_Utils_Array::value('contactTarget', $ids);
                     }
                 } else {
                     if (CRM_Utils_Array::value('contactTarget', $ids) == CRM_Utils_Array::value('current_employer_id', $this->_values)) {
                         //clear current employer.
                         require_once 'CRM/Contact/BAO/Contact/Utils.php';
                         CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($this->_contactId);
                     }
                 }
             }
         }
         //set current employer
         if ($orgId) {
             $currentEmpParams[$this->_contactId] = $orgId;
             require_once 'CRM/Contact/BAO/Contact/Utils.php';
             CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams);
         }
     } else {
         if ($this->_allRelationshipNames[$relationshipTypeId]["name_{$this->_rtype}"] == 'Employer of') {
             $individualIds = array();
             if (CRM_Utils_Array::value('employer_of', $params)) {
                 $individualIds = array_keys($params['employer_of']);
             } else {
                 if ($this->_action & CRM_Core_Action::UPDATE) {
                     if (CRM_Utils_Array::value('is_current_employer', $params)) {
                         if (CRM_Utils_Array::value('contactTarget', $ids) != CRM_Utils_Array::value('current_employee_id', $this->_values)) {
                             $individualIds[] = CRM_Utils_Array::value('contactTarget', $ids);
                         }
                     } else {
                         if (CRM_Utils_Array::value('contactTarget', $ids) == CRM_Utils_Array::value('current_employee_id', $this->_values)) {
                             // clear current employee
                             require_once 'CRM/Contact/BAO/Contact/Utils.php';
                             CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($ids['contactTarget']);
                         }
                     }
                 }
             }
             //set current employee
             if (!empty($individualIds)) {
                 //build the employee params.
                 foreach ($individualIds as $key => $Id) {
                     $currentEmpParams[$Id] = $this->_contactId;
                 }
                 require_once 'CRM/Contact/BAO/Contact/Utils.php';
                 CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams);
             }
         }
     }
     CRM_Core_Session::setStatus($status);
     if ($quickSave) {
         $session =& CRM_Core_Session::singleton();
         CRM_Utils_System::redirect($session->popUserContext());
     }
 }
 /**
  * Delete the relationship.
  *
  * @param int $id
  *   Relationship id.
  *
  * @return null
  */
 public static function del($id)
 {
     // delete from relationship table
     CRM_Utils_Hook::pre('delete', 'Relationship', $id, CRM_Core_DAO::$_nullArray);
     $relationship = self::clearCurrentEmployer($id, CRM_Core_Action::DELETE);
     if (CRM_Core_Permission::access('CiviMember')) {
         // create $params array which isrequired to delete memberships
         // of the related contacts.
         $params = array('relationship_type_id' => "{$relationship->relationship_type_id}_a_b", 'contact_check' => array($relationship->contact_id_b => 1));
         $ids = array();
         // calling relatedMemberships to delete the memberships of
         // related contacts.
         self::relatedMemberships($relationship->contact_id_a, $params, $ids, CRM_Core_Action::DELETE, FALSE);
     }
     $relationship->delete();
     CRM_Core_Session::setStatus(ts('Selected relationship has been deleted successfully.'), ts('Record Deleted'), 'success');
     CRM_Utils_Hook::post('delete', 'Relationship', $id, $relationship);
     // delete the recently created Relationship
     $relationshipRecent = array('id' => $id, 'type' => 'Relationship');
     CRM_Utils_Recent::del($relationshipRecent);
     return $relationship;
 }
Beispiel #30
-1
 function isPermissioned($components)
 {
     if (empty($components)) {
         return TRUE;
     }
     if (is_array($components)) {
         foreach ($components as $component) {
             if (!CRM_Core_Permission::access($component)) {
                 return FALSE;
             }
         }
     } else {
         if (!CRM_Core_Permission::access($components)) {
             return FALSE;
         }
     }
     return TRUE;
 }