Пример #1
0
 public function preProcess()
 {
     if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
         CRM_Utils_System::permissionDenied();
     }
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
     $this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
     if ($this->_surveyId) {
         $this->_single = TRUE;
         $params = array('id' => $this->_surveyId);
         CRM_Campaign_BAO_Survey::retrieve($params, $surveyInfo);
         $this->_surveyTitle = $surveyInfo['title'];
         $this->assign('surveyTitle', $this->_surveyTitle);
         CRM_Utils_System::setTitle(ts('Configure Survey - %1', array(1 => $this->_surveyTitle)));
     }
     $this->assign('action', $this->_action);
     $this->assign('surveyId', $this->_surveyId);
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
         $this->set('type', 'Event');
         $this->set('entityId', $this->_surveyId);
         CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Survey', $this->_surveyId);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     // CRM-11480, CRM-11682
     // Preload libraries required by the "Questions" tab
     CRM_UF_Page_ProfileEditor::registerProfileScripts();
     CRM_UF_Page_ProfileEditor::registerSchemas(array('IndividualModel', 'ActivityModel'));
     CRM_Campaign_Form_Survey_TabHeader::build($this);
 }
Пример #2
0
 public function preProcess()
 {
     if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
         CRM_Utils_System::permissionDenied();
     }
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $this->_context);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
     if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::DELETE)) {
         $this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
         if ($this->_action & CRM_Core_Action::UPDATE) {
             CRM_Utils_System::setTitle(ts('Edit Survey'));
         } else {
             CRM_Utils_System::setTitle(ts('Delete Survey'));
         }
     }
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
         $this->set('type', 'Event');
         $this->set('entityId', $this->_surveyId);
         CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Survey', $this->_surveyId);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $session = CRM_Core_Session::singleton();
     $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
     $session->pushUserContext($url);
     $this->_values = $this->get('values');
     if (!is_array($this->_values)) {
         $this->_values = array();
         if ($this->_surveyId) {
             $params = array('id' => $this->_surveyId);
             CRM_Campaign_BAO_Survey::retrieve($params, $this->_values);
         }
         $this->set('values', $this->_values);
     }
     $this->assign('action', $this->_action);
     $this->assign('surveyId', $this->_surveyId);
     // for custom data
     $this->assign('entityID', $this->_surveyId);
     if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::DELETE)) {
         $this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
         if ($this->_action & CRM_Core_Action::UPDATE) {
             CRM_Utils_System::setTitle(ts('Edit Petition'));
         } else {
             CRM_Utils_System::setTitle(ts('Delete Petition'));
         }
     }
     $session = CRM_Core_Session::singleton();
     $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=petition');
     $session->pushUserContext($url);
     CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Petition Dashboard'), 'url' => $url)));
 }
Пример #3
0
 /**
  * Set variables up before form is built.
  */
 public function preProcess()
 {
     parent::preProcess();
     if ($this->_id) {
         $this->assign('entityID', $this->_id);
         $eventType = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'event_type_id');
     } else {
         $eventType = 'null';
     }
     $showLocation = FALSE;
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
         $this->set('type', 'Event');
         $this->set('subType', CRM_Utils_Array::value('event_type_id', $_POST));
         $this->set('entityId', $this->_id);
         CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_eventType, 1, 'Event', $this->_id);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
 }
Пример #4
0
 /**
  * Set default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @param CRM_Core_Form $form
  * @param array $defaults
  */
 public static function setDefaultValues(&$form, &$defaults)
 {
     $defaults += CRM_Custom_Form_CustomData::setDefaultValues($form);
 }
Пример #5
0
 /**
  * Set default values for the form.
  * The default values are retrieved from the database.
  */
 public function setDefaultValues()
 {
     $defaults = $this->_values;
     $fields = array();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return $defaults;
     }
     if (!empty($defaults['is_test'])) {
         $this->assign('is_test', TRUE);
     }
     if ($this->_id) {
         $startDate = CRM_Utils_Array::value('start_date', $this->_values);
         $createDate = CRM_Utils_Array::value('create_date', $this->_values);
         list($defaults['start_date']) = CRM_Utils_Date::setDateDefaults($startDate);
         list($defaults['create_date']) = CRM_Utils_Date::setDateDefaults($createDate);
         if ($ackDate = CRM_Utils_Array::value('acknowledge_date', $this->_values)) {
             list($defaults['acknowledge_date']) = CRM_Utils_Date::setDateDefaults($ackDate);
         }
         // check is this pledge pending.
         // fix the display of the monetary value, CRM-4038.
         if ($this->_isPending) {
             $defaults['eachPaymentAmount'] = $this->_values['amount'] / $this->_values['installments'];
             $defaults['eachPaymentAmount'] = CRM_Utils_Money::format($defaults['eachPaymentAmount'], NULL, '%a');
         } else {
             $this->assign('start_date', $startDate);
             $this->assign('create_date', $createDate);
         }
         // fix the display of the monetary value, CRM-4038
         if (isset($this->_values['amount'])) {
             $defaults['amount'] = CRM_Utils_Money::format($this->_values['amount'], NULL, '%a');
         }
         $this->assign('amount', $this->_values['amount']);
         $this->assign('installments', $defaults['installments']);
     } else {
         // default values.
         list($now) = CRM_Utils_Date::setDateDefaults();
         $defaults['create_date'] = $now;
         $defaults['start_date'] = $now;
         $defaults['installments'] = 12;
         $defaults['frequency_interval'] = 1;
         $defaults['frequency_day'] = 1;
         $defaults['initial_reminder_day'] = 5;
         $defaults['max_reminders'] = 1;
         $defaults['additional_reminder_day'] = 5;
         $defaults['frequency_unit'] = array_search('month', $this->_freqUnits);
         $defaults['financial_type_id'] = array_search('Donation', CRM_Contribute_PseudoConstant::financialType());
     }
     $pledgeStatus = CRM_Contribute_PseudoConstant::contributionStatus();
     $pledgeStatusNames = CRM_Core_OptionGroup::values('contribution_status', FALSE, FALSE, FALSE, NULL, 'name', TRUE);
     // get default status label (pending)
     $defaultPledgeStatus = CRM_Utils_Array::value(array_search('Pending', $pledgeStatusNames), $pledgeStatus);
     // assign status.
     $this->assign('status', CRM_Utils_Array::value(CRM_Utils_Array::value('status_id', $this->_values), $pledgeStatus, $defaultPledgeStatus));
     if (isset($this->userEmail)) {
         $this->assign('email', $this->userEmail);
     }
     // custom data set defaults
     $defaults += CRM_Custom_Form_CustomData::setDefaultValues($this);
     return $defaults;
 }
 /**
  * This function sets the default values for the form.
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return void
  */
 public function setDefaultValues()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = array();
     $defaults = parent::setDefaultValues();
     $this->_memType = $defaults['membership_type_id'];
     // set renewal_date and receive_date to today in correct input format (setDateDefaults uses today if no value passed)
     list($now, $currentTime) = CRM_Utils_Date::setDateDefaults();
     $defaults['renewal_date'] = $now;
     $defaults['receive_date'] = $now;
     $defaults['receive_date_time'] = $currentTime;
     if ($defaults['id']) {
         $defaults['record_contribution'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $defaults['id'], 'contribution_id', 'membership_id');
     }
     if (is_numeric($this->_memType)) {
         $defaults['membership_type_id'] = array();
         $defaults['membership_type_id'][0] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'member_of_contact_id', 'id');
         $defaults['membership_type_id'][1] = $this->_memType;
     } else {
         $defaults['membership_type_id'] = $this->_memType;
     }
     $defaults['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'financial_type_id');
     //CRM-13420
     if (empty($defaults['payment_instrument_id'])) {
         $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
     }
     $defaults['total_amount'] = CRM_Utils_Money::format(CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee'), NULL, '%a');
     $defaults['record_contribution'] = 0;
     $defaults['num_terms'] = 1;
     $defaults['send_receipt'] = 0;
     $renewalDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('renewal_date', $defaults), NULL, NULL, 'Y-m-d');
     $this->assign('renewalDate', $renewalDate);
     $this->assign('member_is_test', CRM_Utils_Array::value('member_is_test', $defaults));
     if ($this->_mode) {
         $fields = array();
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         $names = array('first_name', 'middle_name', 'last_name', "street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}");
         foreach ($names as $name) {
             $fields[$name] = 1;
         }
         $fields["state_province-{$this->_bltID}"] = 1;
         $fields["country-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $fields['email-Primary'] = 1;
         CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $this->_defaults);
         // use primary email address if billing email address is empty
         if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults['email-Primary'])) {
             $defaults["email-{$this->_bltID}"] = $this->_defaults['email-Primary'];
         }
         foreach ($names as $name) {
             if (!empty($this->_defaults[$name])) {
                 $defaults['billing_' . $name] = $this->_defaults[$name];
             }
         }
     }
     return $defaults;
 }
Пример #7
0
 public function preProcess()
 {
     if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
         CRM_Utils_System::permissionDenied();
     }
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $this->_context);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
     $this->_campaignId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $title = NULL;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $title = ts('Edit Campaign');
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         $title = ts('Delete Campaign');
     }
     if ($title) {
         CRM_Utils_System::setTitle($title);
     }
     $session = CRM_Core_Session::singleton();
     $session->pushUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=campaign'));
     $this->assign('action', $this->_action);
     //load the values;
     $this->_values = $this->get('values');
     if (!is_array($this->_values)) {
         $this->_values = array();
         // if we are editing
         if (isset($this->_campaignId) && $this->_campaignId) {
             $params = array('id' => $this->_campaignId);
             CRM_Campaign_BAO_Campaign::retrieve($params, $this->_values);
         }
         //lets use current object session.
         $this->set('values', $this->_values);
     }
     // when custom data is included in form.
     if (!empty($_POST['hidden_custom'])) {
         $campaignTypeId = empty($_POST['campaign_type_id']) ? NULL : $_POST['campaign_type_id'];
         $this->set('type', 'Campaign');
         $this->set('subType', $campaignTypeId);
         $this->set('entityId', $this->_campaignId);
         CRM_Custom_Form_CustomData::preProcess($this, NULL, $campaignTypeId, 1, 'Campaign', $this->_campaignId);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
 }
Пример #8
0
 /**
  * This function sets the default values for the form. For edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 function setDefaultValues()
 {
     if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW || $this->_cdType) {
         return TRUE;
     }
     eval('$defaults = CRM_Case_Form_Activity_' . $this->_activityTypeFile . '::setDefaultValues($this);');
     $defaults = array_merge($defaults, CRM_Custom_Form_CustomData::setDefaultValues($this));
     return $defaults;
 }
Пример #9
0
 /**
  * @param string $type
  *   Eg 'Contribution'.
  * @param string $subType
  * @param int $entityId
  */
 public function applyCustomData($type, $subType, $entityId)
 {
     $this->set('type', $type);
     $this->set('subType', $subType);
     $this->set('entityId', $entityId);
     CRM_Custom_Form_CustomData::preProcess($this, NULL, $subType, 1, $type, $entityId);
     CRM_Custom_Form_CustomData::buildQuickForm($this);
     CRM_Custom_Form_CustomData::setDefaultValues($this);
 }
Пример #10
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @param null
  *
  * @return array    array of default values
  * @access public
  */
 function setDefaultValues()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = $this->_values;
     if ($this->_surveyId) {
         if (!empty($defaults['result_id']) && !empty($defaults['recontact_interval'])) {
             $resultId = $defaults['result_id'];
             $recontactInterval = unserialize($defaults['recontact_interval']);
             unset($defaults['recontact_interval']);
             $defaults['option_group_id'] = $resultId;
         }
     }
     if (!isset($defaults['is_active'])) {
         $defaults['is_active'] = 1;
     }
     $defaultSurveys = CRM_Campaign_BAO_Survey::getSurveys(TRUE, TRUE);
     if (!isset($defaults['is_default']) && empty($defaultSurveys)) {
         $defaults['is_default'] = 1;
     }
     return $defaults;
 }
Пример #11
0
 /**
  * This function sets the default values for the form in edit/view mode
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 public function setDefaultValues()
 {
     if ($this->_showFeeBlock) {
         return CRM_Event_Form_EventFees::setDefaultValues($this);
     }
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = array();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return $defaults;
     }
     if ($this->_participantId) {
         $ids = array();
         $params = array('id' => $this->_participantId);
         require_once "CRM/Event/BAO/Participant.php";
         CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
         $this->_contactID = $defaults[$this->_participantId]['contact_id'];
         $this->_statusId = $defaults[$this->_participantId]['participant_status_id'];
         //set defaults for note
         $noteDetails = CRM_Core_BAO_Note::getNote($this->_participantId, 'civicrm_participant');
         $defaults[$this->_participantId]['note'] = array_pop($noteDetails);
     }
     if ($this->_action & (CRM_Core_Action::VIEW | CRM_Core_Action::BROWSE)) {
         $inactiveNeeded = true;
         $viewMode = true;
     } else {
         $viewMode = false;
         $inactiveNeeded = false;
     }
     //setting default register date
     if ($this->_action == CRM_Core_Action::ADD) {
         if (CRM_Utils_Array::value('event_id', $defaults[$this->_participantId])) {
             $contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $defaults[$this->_participantId]['event_id'], 'contribution_type_id');
             if ($contributionTypeId) {
                 $defaults[$this->_participantId]['contribution_type_id'] = $contributionTypeId;
             }
         }
         if ($this->_mode) {
             $fields["email-{$this->_bltID}"] = 1;
             $fields["email-Primary"] = 1;
             require_once "CRM/Core/BAO/UFGroup.php";
             if ($this->_contactID) {
                 require_once "CRM/Core/BAO/UFGroup.php";
                 CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $defaults);
             }
             if (empty($defaults["email-{$this->_bltID}"]) && !empty($defaults["email-Primary"])) {
                 $defaults[$this->_participantId]["email-{$this->_bltID}"] = $defaults["email-Primary"];
             }
         }
         $submittedRole = $this->getElementValue('role_id');
         if ($submittedRole[0]) {
             $roleID = $submittedRole[0];
         }
         $submittedEvent = $this->getElementValue('event_id');
         if ($submittedEvent[0]) {
             $eventID = $submittedEvent[0];
         }
     } else {
         $defaults[$this->_participantId]['record_contribution'] = 0;
         $recordContribution = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $defaults[$this->_participantId]['id'], 'contribution_id', 'participant_id');
         //contribution record exists for this participation
         if ($recordContribution) {
             foreach (array('contribution_type_id', 'payment_instrument_id', 'contribution_status_id', 'receive_date') as $field) {
                 $defaults[$this->_participantId][$field] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $recordContribution, $field);
             }
         }
         if ($defaults[$this->_participantId]['participant_is_pay_later']) {
             $this->assign('participant_is_pay_later', true);
         }
         $this->assign('participant_status_id', $defaults[$this->_participantId]['participant_status_id']);
         $roleID = $defaults[$this->_participantId]['participant_role_id'];
         $eventID = $defaults[$this->_participantId]['event_id'];
         $this->_discountId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_participantId, 'discount_id');
         if ($this->_discountId) {
             $this->set('discountId', $this->_discountId);
         }
     }
     list($defaults[$this->_participantId]['register_date'], $defaults[$this->_participantId]['register_date_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('register_date', $defaults[$this->_participantId]));
     //assign event and role id, this is needed for Custom data building
     if (isset($_POST['role_id'])) {
         $roleID = $_POST['role_id'];
     }
     if (isset($roleID)) {
         $this->assign('roleID', $roleID);
     }
     if (isset($_POST['event_id'])) {
         $eventID = $_POST['event_id'];
     }
     if (isset($eventID)) {
         $this->assign('eventID', $eventID);
         $this->set('eventId', $eventID);
     }
     $this->assign('event_is_test', CRM_Utils_Array::value('event_is_test', $defaults[$this->_participantId]));
     return $defaults[$this->_participantId];
 }
Пример #12
0
 /**
  * This function sets the default values for the form. For edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  * @return None
  */
 function setDefaultValues()
 {
     if ($this->_cdType) {
         $tempId = (int) CRM_Utils_Request::retrieve('template_id', 'Integer', $this);
         // set template custom data as a default for event, CRM-5596
         if ($tempId && !$this->_id) {
             $defaults = $this->templateCustomDataValues($tempId);
         } else {
             $defaults = CRM_Custom_Form_CustomData::setDefaultValues($this);
         }
         return $defaults;
     }
     $defaults = parent::setDefaultValues();
     // in update mode, we need to set custom data subtype to tpl
     if (CRM_Utils_Array::value('event_type_id', $defaults)) {
         $this->assign('customDataSubType', $defaults["event_type_id"]);
     }
     require_once 'CRM/Core/ShowHideBlocks.php';
     $this->_showHide =& new CRM_Core_ShowHideBlocks();
     // Show waitlist features or event_full_text if max participants set
     if (CRM_Utils_Array::value('max_participants', $defaults)) {
         $this->_showHide->addShow('id-waitlist');
         if (CRM_Utils_Array::value('has_waitlist', $defaults)) {
             $this->_showHide->addShow('id-waitlist-text');
             $this->_showHide->addHide('id-event_full');
         } else {
             $this->_showHide->addHide('id-waitlist-text');
             $this->_showHide->addShow('id-event_full');
         }
     } else {
         $this->_showHide->addHide('id-event_full');
         $this->_showHide->addHide('id-waitlist');
         $this->_showHide->addHide('id-waitlist-text');
     }
     $this->_showHide->addToTemplate();
     $this->assign('elemType', 'table-row');
     $this->assign('description', CRM_Utils_Array::value('description', $defaults));
     // Provide suggested text for event full and waitlist messages if they're empty
     $defaults['event_full_text'] = CRM_Utils_Array::value('event_full_text', $defaults, ts('This event is currently full.'));
     $defaults['waitlist_text'] = CRM_Utils_Array::value('waitlist_text', $defaults, ts('This event is currently full. However you can register now and get added to a waiting list. You will be notified if spaces become available.'));
     list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('start_date', $defaults), 'activityDateTime');
     if (CRM_Utils_Array::value('end_date', $defaults)) {
         list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['end_date'], 'activityDateTime');
     }
     return $defaults;
 }
Пример #13
0
 /**
  * Set default values for the form.
  *
  * @return array
  */
 public function setDefaultValues()
 {
     $defaults = array();
     if (isset($this->_id)) {
         $defaults = $this->_groupValues;
         if (!empty($defaults['group_type'])) {
             $types = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($defaults['group_type'], 1, -1));
             $defaults['group_type'] = array();
             foreach ($types as $type) {
                 $defaults['group_type'][$type] = 1;
             }
         }
         if (CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_Permission::isMultisiteEnabled()) {
             CRM_Contact_BAO_GroupOrganization::retrieve($this->_id, $defaults);
         }
     }
     if (!(CRM_Core_Permission::check('access CiviMail') || CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings'))) {
         $groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE);
         if ($defaults['group_type'][$groupTypes['Mailing List']] == 1) {
             $this->assign('freezeMailignList', $groupTypes['Mailing List']);
         } else {
             $this->assign('hideMailignList', $groupTypes['Mailing List']);
         }
     }
     if (empty($defaults['parents'])) {
         $defaults['parents'] = CRM_Core_BAO_Domain::getGroupId();
     }
     // custom data set defaults
     $defaults += CRM_Custom_Form_CustomData::setDefaultValues($this);
     return $defaults;
 }
Пример #14
0
 /**
  * Form preProcess function.
  *
  * @throws \Exception
  */
 public function preProcess()
 {
     // This string makes up part of the class names, differentiating them (not sure why) from the membership fields.
     $this->assign('formClass', 'membership');
     parent::preProcess();
     // get price set id.
     $this->_priceSetId = CRM_Utils_Array::value('priceSetId', $_GET);
     $this->set('priceSetId', $this->_priceSetId);
     $this->assign('priceSetId', $this->_priceSetId);
     if ($this->_action & CRM_Core_Action::DELETE) {
         $contributionID = CRM_Member_BAO_Membership::getMembershipContributionId($this->_id);
         // check delete permission for contribution
         if ($this->_id && $contributionID && !CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
             CRM_Core_Error::fatal(ts("This Membership is linked to a contribution. You must have 'delete in CiviContribute' permission in order to delete this record."));
         }
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         if (!CRM_Member_BAO_Membership::statusAvailabilty($this->_contactID)) {
             // all possible statuses are disabled - redirect back to contact form
             CRM_Core_Error::statusBounce(ts('There are no configured membership statuses. You cannot add this membership until your membership statuses are correctly configured'));
         }
         if ($this->_contactID) {
             //check whether contact has a current membership so we can alert user that they may want to do a renewal instead
             $contactMemberships = array();
             $memParams = array('contact_id' => $this->_contactID);
             CRM_Member_BAO_Membership::getValues($memParams, $contactMemberships, TRUE);
             $cMemTypes = array();
             foreach ($contactMemberships as $mem) {
                 $cMemTypes[] = $mem['membership_type_id'];
             }
             if (count($cMemTypes) > 0) {
                 $memberorgs = CRM_Member_BAO_MembershipType::getMemberOfContactByMemTypes($cMemTypes);
                 $mems_by_org = array();
                 foreach ($contactMemberships as $mem) {
                     $mem['member_of_contact_id'] = CRM_Utils_Array::value($mem['membership_type_id'], $memberorgs);
                     if (!empty($mem['membership_end_date'])) {
                         $mem['membership_end_date'] = CRM_Utils_Date::customformat($mem['membership_end_date']);
                     }
                     $mem['membership_type'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $mem['membership_type_id'], 'name', 'id');
                     $mem['membership_status'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $mem['status_id'], 'label', 'id');
                     $mem['renewUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$mem['id']}&context=membership&selectedChild=member" . ($this->_mode ? '&mode=live' : ''));
                     $mem['membershipTab'] = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactID}&selectedChild=member");
                     $mems_by_org[$mem['member_of_contact_id']] = $mem;
                 }
                 $this->assign('existingContactMemberships', $mems_by_org);
             }
         } else {
             // In standalone mode we don't have a contact id yet so lookup will be done client-side with this script:
             $resources = CRM_Core_Resources::singleton();
             $resources->addScriptFile('civicrm', 'templates/CRM/Member/Form/MembershipStandalone.js');
             $passthru = array('typeorgs' => CRM_Member_BAO_MembershipType::getMembershipTypeOrganization(), 'memtypes' => CRM_Core_PseudoConstant::get('CRM_Member_BAO_Membership', 'membership_type_id'), 'statuses' => CRM_Core_PseudoConstant::get('CRM_Member_BAO_Membership', 'status_id'));
             $resources->addSetting(array('existingMems' => $passthru));
         }
     }
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
         CRM_Custom_Form_CustomData::preProcess($this);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     // CRM-4395, get the online pending contribution id.
     $this->_onlinePendingContributionId = NULL;
     if (!$this->_mode && $this->_id && $this->_action & CRM_Core_Action::UPDATE) {
         $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_id, 'Membership');
     }
     $this->assign('onlinePendingContributionId', $this->_onlinePendingContributionId);
     $this->setPageTitle(ts('Membership'));
 }
Пример #15
0
 /**
  * Set the default form values
  *
  * @access protected
  * @return array the default array reference
  */
 function &setDefaultValues()
 {
     if ($this->_cdType) {
         $customDefaultValue = CRM_Custom_Form_CustomData::setDefaultValues($this);
         return $customDefaultValue;
     }
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_tableID, $this->_groupID, $this->_contactSubType);
     if (!CRM_Utils_Array::value("hidden_custom_group_count", $_POST)) {
         // custom data building in edit mode (required to handle multi-value)
         $groupTree =& CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_tableID, $this->_groupID, $this->_contactSubType);
         $customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, true, $this->_groupID);
     } else {
         $customValueCount = $_POST['hidden_custom_group_count'][$this->_groupID];
     }
     $this->assign("customValueCount", $customValueCount);
     $defaults = array();
     return $defaults;
 }
 /**
  * Set default values for the form.
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultValues()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = parent::setDefaultValues();
     $this->_memType = $defaults['membership_type_id'];
     // set renewal_date and receive_date to today in correct input format (setDateDefaults uses today if no value passed)
     list($now, $currentTime) = CRM_Utils_Date::setDateDefaults();
     $defaults['renewal_date'] = $now;
     $defaults['receive_date'] = $now;
     $defaults['receive_date_time'] = $currentTime;
     if ($defaults['id']) {
         $defaults['record_contribution'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $defaults['id'], 'contribution_id', 'membership_id');
     }
     if (is_numeric($this->_memType)) {
         $defaults['membership_type_id'] = array();
         $defaults['membership_type_id'][0] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'member_of_contact_id', 'id');
         $defaults['membership_type_id'][1] = $this->_memType;
     } else {
         $defaults['membership_type_id'] = $this->_memType;
     }
     $defaults['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'financial_type_id');
     //CRM-13420
     if (empty($defaults['payment_instrument_id'])) {
         $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
     }
     $defaults['total_amount'] = CRM_Utils_Money::format(CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee'), NULL, '%a');
     $defaults['record_contribution'] = 0;
     $defaults['num_terms'] = 1;
     $defaults['send_receipt'] = 0;
     //set Soft Credit Type to Gift by default
     $scTypes = CRM_Core_OptionGroup::values("soft_credit_type");
     $defaults['soft_credit_type_id'] = CRM_Utils_Array::value(ts('Gift'), array_flip($scTypes));
     $renewalDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('renewal_date', $defaults), NULL, NULL, 'Y-m-d');
     $this->assign('renewalDate', $renewalDate);
     $this->assign('member_is_test', CRM_Utils_Array::value('member_is_test', $defaults));
     if ($this->_mode) {
         // set default country from config if no country set
         $config = CRM_Core_Config::singleton();
         if (empty($defaults["billing_country_id-{$this->_bltID}"])) {
             $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
         }
         if (empty($defaults["billing_state_province_id-{$this->_bltID}"])) {
             $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
         }
         $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
         $defaults = array_merge($defaults, $billingDefaults);
     }
     return $defaults;
 }
Пример #17
0
 /**
  * Pre-process form.
  *
  * @throws \Exception
  */
 public function preProcess()
 {
     // This string makes up part of the class names, differentiating them (not sure why) from the membership fields.
     $this->assign('formClass', 'membershiprenew');
     parent::preProcess();
     // check for edit permission
     if (!CRM_Core_Permission::check('edit memberships')) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     $this->assign('endDate', CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'end_date')));
     $this->assign('membershipStatus', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'status_id'), 'name'));
     if ($this->_mode) {
         $membershipFee = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee');
         if (!$membershipFee) {
             $statusMsg = ts('Membership Renewal using a credit card requires a Membership fee. Since there is no fee associated with the selected membership type, you can use the normal renewal mode.');
             CRM_Core_Session::setStatus($statusMsg, '', 'info');
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$this->_id}&context=membership"));
         }
     }
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
         CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_memType, 1, 'Membership', $this->_id);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     CRM_Utils_System::setTitle(ts('Renew Membership'));
     parent::preProcess();
 }
 /**
  * This function sets the default values for the form. MobileProvider that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 public function setDefaultValues()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     if ($this->_priceSetId) {
         return CRM_Price_BAO_Set::setDefaultPriceSet($this, $defaults);
     }
     $defaults = parent::setDefaultValues();
     //setting default join date and receive date
     list($now) = CRM_Utils_Date::setDateDefaults();
     if ($this->_action == CRM_Core_Action::ADD) {
         $defaults['receive_date'] = $now;
     }
     if (is_numeric($this->_memType)) {
         $defaults["membership_type_id"] = array();
         $defaults["membership_type_id"][0] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'member_of_contact_id', 'id');
         $defaults["membership_type_id"][1] = $this->_memType;
     } else {
         $defaults["membership_type_id"] = $this->_memType;
     }
     if (CRM_Utils_Array::value('id', $defaults)) {
         if ($this->_onlinePendingContributionId) {
             $defaults['record_contribution'] = $this->_onlinePendingContributionId;
         } else {
             $contributionId = CRM_Core_DAO::singleValueQuery("\n  SELECT contribution_id\n  FROM civicrm_membership_payment\n  WHERE membership_id = {$this->_id}\n  ORDER BY contribution_id\n  DESC limit 1");
             if ($contributionId) {
                 $defaults['record_contribution'] = $contributionId;
             }
         }
     }
     if (CRM_Utils_Array::value('record_contribution', $defaults) && !$this->_mode) {
         $contributionParams = array('id' => $defaults['record_contribution']);
         $contributionIds = array();
         //keep main object campaign in hand.
         $memberCampaignId = CRM_Utils_Array::value('campaign_id', $defaults);
         CRM_Contribute_BAO_Contribution::getValues($contributionParams, $defaults, $contributionIds);
         //get back original object campaign id.
         $defaults['campaign_id'] = $memberCampaignId;
         if (CRM_Utils_Array::value('receive_date', $defaults)) {
             list($defaults['receive_date']) = CRM_Utils_Date::setDateDefaults($defaults['receive_date']);
         }
         // Contribution::getValues() over-writes the membership record's source field value - so we need to restore it.
         if (CRM_Utils_Array::value('membership_source', $defaults)) {
             $defaults['source'] = $defaults['membership_source'];
         }
     }
     // User must explicitly choose to send a receipt in both add and update mode.
     $defaults['send_receipt'] = 0;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         // in this mode by default uncheck this checkbox
         unset($defaults['record_contribution']);
     }
     if (CRM_Utils_Array::value('id', $defaults)) {
         $subscriptionCancelled = CRM_Member_BAO_Membership::isSubscriptionCancelled($this->_id);
     }
     $alreadyAutoRenew = FALSE;
     if (CRM_Utils_Array::value('contribution_recur_id', $defaults) && !$subscriptionCancelled) {
         $defaults['auto_renew'] = 1;
         $alreadyAutoRenew = TRUE;
     }
     $this->assign('alreadyAutoRenew', $alreadyAutoRenew);
     $this->assign("member_is_test", CRM_Utils_Array::value('member_is_test', $defaults));
     $this->assign('membership_status_id', CRM_Utils_Array::value('status_id', $defaults));
     if (CRM_Utils_Array::value('is_pay_later', $defaults)) {
         $this->assign('is_pay_later', TRUE);
     }
     if ($this->_mode) {
         $fields = array();
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         $names = array("first_name", "middle_name", "last_name", "street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}");
         foreach ($names as $name) {
             $fields[$name] = 1;
         }
         $fields["state_province-{$this->_bltID}"] = 1;
         $fields["country-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $fields["email-Primary"] = 1;
         if ($this->_contactID) {
             CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $this->_defaults);
         }
         // use primary email address if billing email address is empty
         if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults["email-Primary"])) {
             $defaults["email-{$this->_bltID}"] = $this->_defaults["email-Primary"];
         }
         foreach ($names as $name) {
             if (!empty($this->_defaults[$name])) {
                 $defaults["billing_" . $name] = $this->_defaults[$name];
             }
         }
         //             // hack to simplify credit card entry for testing
         //             $defaults['credit_card_type']     = 'Visa';
         //             $defaults['credit_card_number']   = '4807731747657838';
         //             $defaults['cvv2']                 = '000';
         //             $defaults['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' );
     }
     $dates = array('join_date', 'start_date', 'end_date');
     foreach ($dates as $key) {
         if (CRM_Utils_Array::value($key, $defaults)) {
             list($defaults[$key]) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value($key, $defaults));
         }
     }
     //setting default join date if there is no join date
     if (!CRM_Utils_Array::value('join_date', $defaults)) {
         $defaults['join_date'] = $now;
     }
     if (CRM_Utils_Array::value('membership_end_date', $defaults)) {
         $this->assign('endDate', $defaults['membership_end_date']);
     }
     return $defaults;
 }
 /**
  * Set default values.
  *
  * @return array
  */
 public function setDefaultValues()
 {
     if ($this->_cdType) {
         // @todo document when this function would be called in this way
         // (and whether it is valid or an overloading of this form).
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = $this->_values;
     // Set defaults for pledge payment.
     if ($this->_ppID) {
         $defaults['total_amount'] = CRM_Utils_Array::value('scheduled_amount', $this->_pledgeValues['pledgePayment']);
         $defaults['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_pledgeValues);
         $defaults['currency'] = CRM_Utils_Array::value('currency', $this->_pledgeValues);
         $defaults['option_type'] = 1;
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         return $defaults;
     }
     $defaults['frequency_interval'] = 1;
     $defaults['frequency_unit'] = 'month';
     // Set soft credit defaults.
     CRM_Contribute_Form_SoftCredit::setDefaultValues($defaults, $this);
     if ($this->_mode) {
         $config = CRM_Core_Config::singleton();
         // Set default country from config if no country set.
         if (empty($defaults["billing_country_id-{$this->_bltID}"])) {
             $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
         }
         if (empty($defaults["billing_state_province_id-{$this->_bltID}"])) {
             $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
         }
         $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
         $defaults = array_merge($defaults, $billingDefaults);
     }
     if ($this->_id) {
         $this->_contactID = $defaults['contact_id'];
     }
     // Set $newCredit variable in template to control whether link to credit card mode is included.
     $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments());
     // Fix the display of the monetary value, CRM-4038.
     if (isset($defaults['total_amount'])) {
         if (!empty($defaults['tax_amount'])) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
             if (!(CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails))) {
                 $defaults['total_amount'] = CRM_Utils_Money::format($defaults['total_amount'] - $defaults['tax_amount'], NULL, '%a');
             }
         } else {
             $defaults['total_amount'] = CRM_Utils_Money::format($defaults['total_amount'], NULL, '%a');
         }
     }
     if (isset($defaults['non_deductible_amount'])) {
         $defaults['non_deductible_amount'] = CRM_Utils_Money::format($defaults['non_deductible_amount'], NULL, '%a');
     }
     if (isset($defaults['fee_amount'])) {
         $defaults['fee_amount'] = CRM_Utils_Money::format($defaults['fee_amount'], NULL, '%a');
     }
     if (isset($defaults['net_amount'])) {
         $defaults['net_amount'] = CRM_Utils_Money::format($defaults['net_amount'], NULL, '%a');
     }
     if ($this->_contributionType) {
         $defaults['financial_type_id'] = $this->_contributionType;
     }
     if (empty($defaults['payment_instrument_id'])) {
         $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
     }
     if (!empty($defaults['is_test'])) {
         $this->assign('is_test', TRUE);
     }
     $this->assign('showOption', TRUE);
     // For Premium section.
     if ($this->_premiumID) {
         $this->assign('showOption', FALSE);
         $options = isset($this->_options[$this->_productDAO->product_id]) ? $this->_options[$this->_productDAO->product_id] : "";
         if (!$options) {
             $this->assign('showOption', TRUE);
         }
         $options_key = CRM_Utils_Array::key($this->_productDAO->product_option, $options);
         if ($options_key) {
             $defaults['product_name'] = array($this->_productDAO->product_id, trim($options_key));
         } else {
             $defaults['product_name'] = array($this->_productDAO->product_id);
         }
         if ($this->_productDAO->fulfilled_date) {
             list($defaults['fulfilled_date']) = CRM_Utils_Date::setDateDefaults($this->_productDAO->fulfilled_date);
         }
     }
     if (isset($this->userEmail)) {
         $this->assign('email', $this->userEmail);
     }
     if (!empty($defaults['is_pay_later'])) {
         $this->assign('is_pay_later', TRUE);
     }
     $this->assign('contribution_status_id', CRM_Utils_Array::value('contribution_status_id', $defaults));
     $dates = array('receive_date', 'receipt_date', 'cancel_date', 'thankyou_date');
     foreach ($dates as $key) {
         if (!empty($defaults[$key])) {
             list($defaults[$key], $defaults[$key . '_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value($key, $defaults), 'activityDateTime');
         }
     }
     if (!$this->_id && empty($defaults['receive_date'])) {
         list($defaults['receive_date'], $defaults['receive_date_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
     }
     $this->assign('receive_date', CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $defaults), CRM_Utils_Array::value('receive_date_time', $defaults)));
     $currency = CRM_Utils_Array::value('currency', $defaults);
     $this->assign('currency', $currency);
     // Hack to get currency info to the js layer. CRM-11440.
     CRM_Utils_Money::format(1);
     $this->assign('currencySymbol', CRM_Utils_Array::value($currency, CRM_Utils_Money::$_currencySymbols));
     $this->assign('totalAmount', CRM_Utils_Array::value('total_amount', $defaults));
     // Inherit campaign from pledge.
     if ($this->_ppID && !empty($this->_pledgeValues['campaign_id'])) {
         $defaults['campaign_id'] = $this->_pledgeValues['campaign_id'];
     }
     $this->_defaults = $defaults;
     return $defaults;
 }
Пример #20
0
 /**
  * Set defaults for the form.
  *
  * @return array
  */
 public function setDefaultValues()
 {
     return CRM_Custom_Form_CustomData::setDefaultValues($this);
 }
Пример #21
0
 /**
  * Set default values for the form.
  */
 public function setDefaultValues()
 {
     if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW) {
         return TRUE;
     }
     $className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}";
     $defaults = $className::setDefaultValues($this);
     $defaults = array_merge($defaults, CRM_Custom_Form_CustomData::setDefaultValues($this));
     return $defaults;
 }
Пример #22
0
 /**
  * Build the form object.
  */
 public function preProcess()
 {
     CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity');
     $this->_atypefile = CRM_Utils_Array::value('atypefile', $_GET);
     $this->assign('atypefile', FALSE);
     if ($this->_atypefile) {
         $this->assign('atypefile', TRUE);
     }
     $session = CRM_Core_Session::singleton();
     $this->_currentUserId = $session->get('userID');
     $this->_currentlyViewedContactId = $this->get('contactId');
     if (!$this->_currentlyViewedContactId) {
         $this->_currentlyViewedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     }
     $this->assign('contactId', $this->_currentlyViewedContactId);
     // Give the context.
     if (!isset($this->_context)) {
         $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
         if (CRM_Contact_Form_Search::isSearchContext($this->_context)) {
             $this->_context = 'search';
         } elseif (!in_array($this->_context, array('dashlet', 'dashletFullscreen')) && $this->_currentlyViewedContactId) {
             $this->_context = 'activity';
         }
         $this->_compContext = CRM_Utils_Request::retrieve('compContext', 'String', $this);
     }
     $this->assign('context', $this->_context);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
     if ($this->_action & CRM_Core_Action::DELETE) {
         if (!CRM_Core_Permission::check('delete activities')) {
             CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
         }
     }
     // CRM-6957
     // When we come from contact search, activity id never comes.
     // So don't try to get from object, it might gives you wrong one.
     // if we're not adding new one, there must be an id to
     // an activity we're trying to work on.
     if ($this->_action != CRM_Core_Action::ADD && get_class($this->controller) != 'CRM_Contact_Controller_Search') {
         $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     }
     $this->_activityTypeId = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
     $this->assign('atype', $this->_activityTypeId);
     $this->assign('activityId', $this->_activityId);
     // Check for required permissions, CRM-6264.
     if ($this->_activityId && in_array($this->_action, array(CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW)) && !CRM_Activity_BAO_Activity::checkPermission($this->_activityId, $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     if ($this->_action & CRM_Core_Action::VIEW && CRM_Activity_BAO_Activity::checkPermission($this->_activityId, CRM_Core_Action::UPDATE)) {
         $this->assign('permission', 'edit');
     }
     if (!$this->_activityTypeId && $this->_activityId) {
         $this->_activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'activity_type_id');
     }
     // Assigning Activity type name.
     if ($this->_activityTypeId) {
         $activityTName = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, 'AND v.value = ' . $this->_activityTypeId, 'label');
         if ($activityTName[$this->_activityTypeId]) {
             $this->_activityTypeName = $activityTName[$this->_activityTypeId];
             $this->assign('activityTName', $activityTName[$this->_activityTypeId]);
         }
     }
     // Set title.
     if (isset($activityTName)) {
         $activityName = CRM_Utils_Array::value($this->_activityTypeId, $activityTName);
         $this->assign('pageTitle', ts('%1 Activity', array(1 => $activityName)));
         if ($this->_currentlyViewedContactId) {
             $displayName = CRM_Contact_BAO_Contact::displayName($this->_currentlyViewedContactId);
             // Check if this is default domain contact CRM-10482.
             if (CRM_Contact_BAO_Contact::checkDomainContact($this->_currentlyViewedContactId)) {
                 $displayName .= ' (' . ts('default organization') . ')';
             }
             CRM_Utils_System::setTitle($displayName . ' - ' . $activityName);
         } else {
             CRM_Utils_System::setTitle(ts('%1 Activity', array(1 => $activityName)));
         }
     }
     // Check the mode when this form is called either single or as
     // search task action.
     if ($this->_activityTypeId || $this->_context == 'standalone' || $this->_currentlyViewedContactId) {
         $this->_single = TRUE;
         $this->assign('urlPath', 'civicrm/activity');
     } else {
         // Set the appropriate action.
         $url = CRM_Utils_System::currentPath();
         $urlArray = explode('/', $url);
         $searchPath = array_pop($urlArray);
         $searchType = 'basic';
         $this->_action = CRM_Core_Action::BASIC;
         switch ($searchPath) {
             case 'basic':
                 $searchType = $searchPath;
                 $this->_action = CRM_Core_Action::BASIC;
                 break;
             case 'advanced':
                 $searchType = $searchPath;
                 $this->_action = CRM_Core_Action::ADVANCED;
                 break;
             case 'builder':
                 $searchType = $searchPath;
                 $this->_action = CRM_Core_Action::PROFILE;
                 break;
             case 'custom':
                 $this->_action = CRM_Core_Action::COPY;
                 $searchType = $searchPath;
                 break;
         }
         parent::preProcess();
         $this->_single = FALSE;
         $this->assign('urlPath', "civicrm/contact/search/{$searchType}");
         $this->assign('urlPathVar', "_qf_Activity_display=true&qfKey={$this->controller->_key}");
     }
     $this->assign('single', $this->_single);
     $this->assign('action', $this->_action);
     if ($this->_action & CRM_Core_Action::VIEW) {
         // Get the tree of custom fields.
         $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Activity', $this, $this->_activityId, 0, $this->_activityTypeId);
     }
     if ($this->_activityTypeId) {
         // Set activity type name and description to template.
         list($this->_activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($this->_activityTypeId);
         $this->assign('activityTypeName', $this->_activityTypeName);
         $this->assign('activityTypeDescription', $activityTypeDescription);
     }
     // set user context
     $urlParams = $urlString = NULL;
     $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
     if (!$qfKey) {
         $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
     }
     // Validate the qfKey.
     if (!CRM_Utils_Rule::qfKey($qfKey)) {
         $qfKey = NULL;
     }
     if ($this->_context == 'fulltext') {
         $keyName = '&qfKey';
         $urlParams = 'force=1';
         $urlString = 'civicrm/contact/search/custom';
         if ($this->_action == CRM_Core_Action::UPDATE) {
             $keyName = '&key';
             $urlParams .= '&context=fulltext&action=view';
             $urlString = 'civicrm/contact/view/activity';
         }
         if ($qfKey) {
             $urlParams .= "{$keyName}={$qfKey}";
         }
         $this->assign('searchKey', $qfKey);
     } elseif (in_array($this->_context, array('standalone', 'home', 'dashlet', 'dashletFullscreen'))) {
         $urlParams = 'reset=1';
         $urlString = 'civicrm/dashboard';
     } elseif ($this->_context == 'search') {
         $urlParams = 'force=1';
         if ($qfKey) {
             $urlParams .= "&qfKey={$qfKey}";
         }
         $path = CRM_Utils_System::currentPath();
         if ($this->_compContext == 'advanced') {
             $urlString = 'civicrm/contact/search/advanced';
         } elseif ($path == 'civicrm/group/search' || $path == 'civicrm/contact/search' || $path == 'civicrm/contact/search/advanced' || $path == 'civicrm/contact/search/custom' || $path == 'civicrm/group/search') {
             $urlString = $path;
         } else {
             $urlString = 'civicrm/activity/search';
         }
         $this->assign('searchKey', $qfKey);
     } elseif ($this->_context != 'caseActivity') {
         $urlParams = "action=browse&reset=1&cid={$this->_currentlyViewedContactId}&selectedChild=activity";
         $urlString = 'civicrm/contact/view';
     }
     if ($urlString) {
         $session->pushUserContext(CRM_Utils_System::url($urlString, $urlParams));
     }
     // hack to retrieve activity type id from post variables
     if (!$this->_activityTypeId) {
         $this->_activityTypeId = CRM_Utils_Array::value('activity_type_id', $_POST);
     }
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
         // We need to set it in the session for the code below to work.
         // CRM-3014
         // Need to assign custom data subtype to the template.
         $this->set('type', 'Activity');
         $this->set('subType', $this->_activityTypeId);
         $this->set('entityId', $this->_activityId);
         CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeId, 1, 'Activity', $this->_activityId);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     // add attachments part
     CRM_Core_BAO_File::buildAttachment($this, 'civicrm_activity', $this->_activityId, NULL, TRUE);
     // figure out the file name for activity type, if any
     if ($this->_activityTypeId && ($this->_activityTypeFile = CRM_Activity_BAO_Activity::getFileForActivityTypeId($this->_activityTypeId, $this->_crmDir))) {
         $this->assign('activityTypeFile', $this->_activityTypeFile);
         $this->assign('crmDir', $this->_crmDir);
     }
     $this->setFields();
     if ($this->_activityTypeFile) {
         $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}";
         $className::preProcess($this);
     }
     $this->_values = $this->get('values');
     if (!is_array($this->_values)) {
         $this->_values = array();
         if (isset($this->_activityId) && $this->_activityId) {
             $params = array('id' => $this->_activityId);
             CRM_Activity_BAO_Activity::retrieve($params, $this->_values);
         }
         $this->set('values', $this->_values);
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity');
     }
 }
Пример #23
0
 /**
  * This function sets the default values for the form. Relationship that in edit/view mode
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 function setDefaultValues()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = array();
     if ($this->_action & CRM_Core_Action::UPDATE) {
         if (!empty($this->_values)) {
             $defaults['relationship_type_id'] = $this->_rtypeId;
             if (CRM_Utils_Array::value('start_date', $this->_values)) {
                 list($defaults['start_date']) = CRM_Utils_Date::setDateDefaults($this->_values['start_date']);
             }
             if (CRM_Utils_Array::value('end_date', $this->_values)) {
                 list($defaults['end_date']) = CRM_Utils_Date::setDateDefaults($this->_values['end_date']);
             }
             $defaults['description'] = CRM_Utils_Array::value('description', $this->_values);
             $defaults['is_active'] = CRM_Utils_Array::value('is_active', $this->_values);
             $defaults['is_permission_a_b'] = CRM_Utils_Array::value('is_permission_a_b', $this->_values);
             $defaults['is_permission_b_a'] = CRM_Utils_Array::value('is_permission_b_a', $this->_values);
             $contact = new CRM_Contact_DAO_Contact();
             if ($this->_rtype == 'a_b' && $this->_values['contact_id_a'] == $this->_contactId) {
                 $contact->id = $this->_values['contact_id_b'];
             } else {
                 $contact->id = $this->_values['contact_id_a'];
             }
             if ($contact->find(true)) {
                 $this->_display_name_b = $contact->display_name;
                 $this->assign('sort_name_b', $this->_display_name_b);
                 //is current employee/employer.
                 if ($this->_allRelationshipNames[$this->_relationshipTypeId]["name_{$this->_rtype}"] == 'Employee of' && $contact->id == CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'employer_id')) {
                     $defaults['is_current_employer'] = 1;
                     $this->_values['current_employee_id'] = $this->_contactId;
                     $this->_values['current_employer_id'] = $contact->id;
                 } else {
                     if ($this->_allRelationshipNames[$this->_relationshipTypeId]["name_{$this->_rtype}"] == 'Employer of' && $this->_contactId == $contact->employer_id) {
                         $defaults['is_current_employer'] = 1;
                         $this->_values['current_employee_id'] = $contact->id;
                         $this->_values['current_employer_id'] = $this->_contactId;
                     }
                 }
             }
             $relationshipID = $this->_values['id'];
             $query = "SELECT id, note FROM civicrm_note where entity_table = 'civicrm_relationship' and entity_id = {$relationshipID}  order by modified_date desc";
             $dao = new CRM_Core_DAO();
             $dao->query($query);
             if ($dao->fetch($query)) {
                 $defaults['note'] = $dao->note;
             }
         }
     } else {
         $defaults['is_active'] = 1;
         $defaults['relationship_type_id'] = $this->_rtypeId;
     }
     return $defaults;
 }
Пример #24
0
 /**
  * Set default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return array
  */
 public function setDefaultValues()
 {
     $defaults = $this->_values;
     //load only custom data defaults.
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     if (isset($defaults['start_date'])) {
         list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['start_date'], 'activityDateTime');
     } else {
         list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults();
     }
     if (isset($defaults['end_date'])) {
         list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['end_date'], 'activityDateTime');
     }
     if (!isset($defaults['is_active'])) {
         $defaults['is_active'] = 1;
     }
     if (!$this->_campaignId) {
         return $defaults;
     }
     $dao = new CRM_Campaign_DAO_CampaignGroup();
     $campaignGroups = array();
     $dao->campaign_id = $this->_campaignId;
     $dao->find();
     while ($dao->fetch()) {
         $campaignGroups[$dao->entity_table][$dao->group_type][] = $dao->entity_id;
     }
     if (!empty($campaignGroups)) {
         $defaults['includeGroups'] = $campaignGroups['civicrm_group']['Include'];
     }
     return $defaults;
 }
Пример #25
0
 /**
  * Set the default form values.
  *
  *
  * @return array
  *   the default array reference
  */
 public function setDefaultValues()
 {
     if ($this->_cdType || $this->_multiRecordDisplay == 'single') {
         if ($this->_copyValueId) {
             // cached tree is fetched
             $groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_type, $this, $this->_entityId, $this->_groupID);
             $valueIdDefaults = array();
             $groupTreeValueId = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $this->_copyValueId, $this);
             CRM_Core_BAO_CustomGroup::setDefaults($groupTreeValueId, $valueIdDefaults, FALSE, FALSE, $this->get('action'));
             $tableId = $groupTreeValueId[$this->_groupID]['table_id'];
             foreach ($valueIdDefaults as $valueIdElementName => $value) {
                 // build defaults for COPY action for new record saving
                 $valueIdElementNamePieces = explode('_', $valueIdElementName);
                 $valueIdElementNamePieces[2] = "-{$this->_groupCount}";
                 $elementName = implode('_', $valueIdElementNamePieces);
                 $customDefaultValue[$elementName] = $value;
             }
         } else {
             $customDefaultValue = CRM_Custom_Form_CustomData::setDefaultValues($this);
         }
         return $customDefaultValue;
     }
     $groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_tableID, $this->_groupID, $this->_contactSubType);
     if (empty($_POST['hidden_custom_group_count'])) {
         // custom data building in edit mode (required to handle multi-value)
         $groupTree = CRM_Core_BAO_CustomGroup::getTree($this->_contactType, $this, $this->_tableID, $this->_groupID, $this->_contactSubType);
         $customValueCount = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, TRUE, $this->_groupID, NULL, NULL, $this->_tableID);
     } else {
         $customValueCount = $_POST['hidden_custom_group_count'][$this->_groupID];
     }
     $this->assign('customValueCount', $customValueCount);
     $defaults = array();
     return $defaults;
 }
Пример #26
0
 /**
  * Set default values for the form. For edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultValues()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = $this->_values + CRM_Core_Form_RecurringEntity::setDefaultValues();
     // if we're editing...
     if (isset($this->_activityId)) {
         if (empty($defaults['activity_date_time'])) {
             list($defaults['activity_date_time'], $defaults['activity_date_time_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
         } elseif ($this->_action & CRM_Core_Action::UPDATE) {
             $this->assign('current_activity_date_time', $defaults['activity_date_time']);
             list($defaults['activity_date_time'], $defaults['activity_date_time_time']) = CRM_Utils_Date::setDateDefaults($defaults['activity_date_time'], 'activityDateTime');
             list($defaults['repetition_start_date'], $defaults['repetition_start_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['activity_date_time'], 'activityDateTime');
         }
         if ($this->_context != 'standalone') {
             $this->assign('target_contact_value', CRM_Utils_Array::value('target_contact_value', $defaults));
             $this->assign('assignee_contact_value', CRM_Utils_Array::value('assignee_contact_value', $defaults));
         }
         // Fixme: why are we getting the wrong keys from upstream?
         $defaults['target_contact_id'] = CRM_Utils_Array::value('target_contact', $defaults);
         $defaults['assignee_contact_id'] = CRM_Utils_Array::value('assignee_contact', $defaults);
         // set default tags if exists
         $defaults['tag'] = CRM_Core_BAO_EntityTag::getTag($this->_activityId, 'civicrm_activity');
     } else {
         // if it's a new activity, we need to set default values for associated contact fields
         $this->_sourceContactId = $this->_currentUserId;
         $this->_targetContactId = $this->_currentlyViewedContactId;
         $defaults['source_contact_id'] = $this->_sourceContactId;
         $defaults['target_contact_id'] = $this->_targetContactId;
         list($defaults['activity_date_time'], $defaults['activity_date_time_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
     }
     if ($this->_activityTypeId) {
         $defaults['activity_type_id'] = $this->_activityTypeId;
     }
     if (!$this->_single && !empty($this->_contactIds)) {
         $defaults['target_contact_id'] = $this->_contactIds;
     }
     // CRM-15472 - 50 is around the practial limit of how many items a select2 entityRef can handle
     if (!empty($defaults['target_contact_id'])) {
         $count = count(is_array($defaults['target_contact_id']) ? $defaults['target_contact_id'] : explode(',', $defaults['target_contact_id']));
         if ($count > 50) {
             $this->freeze(array('target_contact_id'));
         }
     }
     if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::RENEW)) {
         $this->assign('delName', CRM_Utils_Array::value('subject', $defaults));
     }
     if ($this->_activityTypeFile) {
         $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}";
         $defaults += $className::setDefaultValues($this);
     }
     if (empty($defaults['priority_id'])) {
         $priority = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id');
         $defaults['priority_id'] = array_search('Normal', $priority);
     }
     if (empty($defaults['status_id'])) {
         $defaults['status_id'] = CRM_Core_OptionGroup::getDefaultValue('activity_status');
     }
     return $defaults;
 }
Пример #27
0
 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     $this->_showFeeBlock = CRM_Utils_Array::value('eventId', $_GET);
     $this->assign('showFeeBlock', FALSE);
     $this->assign('feeBlockPaid', FALSE);
     $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
     $this->_eID = CRM_Utils_Request::retrieve('eid', 'Positive', $this);
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $this->_context);
     if ($this->_contactId) {
         $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
         $this->assign('displayName', $displayName);
         $this->setPageTitle(ts('Event Registration for %1', array(1 => $displayName)));
     } else {
         $this->setPageTitle(ts('Event Registration'));
     }
     // check the current path, if search based, then dont get participantID
     // CRM-5792
     $path = CRM_Utils_System::currentPath();
     if (strpos($path, 'civicrm/contact/search') === 0 || strpos($path, 'civicrm/group/search') === 0) {
         $this->_id = NULL;
     } else {
         $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     }
     if ($this->_id) {
         $this->assign('participantId', $this->_id);
         $this->_paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'id', 'participant_id');
         $this->assign('hasPayment', $this->_paymentId);
         // CRM-12615 - Get payment information from the primary registration
         if (!$this->_paymentId && $this->_action == CRM_Core_Action::UPDATE) {
             $registered_by_id = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'registered_by_id', 'id');
             if ($registered_by_id) {
                 $this->_paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $registered_by_id, 'id', 'participant_id');
                 $this->assign('registeredByParticipantId', $registered_by_id);
             }
         }
     }
     // get the option value for custom data type
     $this->_roleCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantRole', 'name');
     $this->_eventNameCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventName', 'name');
     $this->_eventTypeCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventType', 'name');
     $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID);
     $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID);
     $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID);
     if ($this->_mode) {
         $this->assign('participantMode', $this->_mode);
         $this->assignPaymentRelatedVariables();
     }
     if ($this->_showFeeBlock) {
         $this->assign('showFeeBlock', TRUE);
         $isMonetary = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock, 'is_monetary');
         if ($isMonetary) {
             $this->assign('feeBlockPaid', TRUE);
         }
         return CRM_Event_Form_EventFees::preProcess($this);
     }
     //check the mode when this form is called either single or as
     //search task action
     if ($this->_id || $this->_contactId || $this->_context == 'standalone') {
         $this->_single = TRUE;
         $this->assign('urlPath', 'civicrm/contact/view/participant');
         if (!$this->_id && !$this->_contactId) {
             $breadCrumbs = array(array('title' => ts('CiviEvent Dashboard'), 'url' => CRM_Utils_System::url('civicrm/event', 'reset=1')));
             CRM_Utils_System::appendBreadCrumb($breadCrumbs);
         }
     } else {
         //set the appropriate action
         $context = $this->get('context');
         $urlString = 'civicrm/contact/search';
         $this->_action = CRM_Core_Action::BASIC;
         switch ($context) {
             case 'advanced':
                 $urlString = 'civicrm/contact/search/advanced';
                 $this->_action = CRM_Core_Action::ADVANCED;
                 break;
             case 'builder':
                 $urlString = 'civicrm/contact/search/builder';
                 $this->_action = CRM_Core_Action::PROFILE;
                 break;
             case 'basic':
                 $urlString = 'civicrm/contact/search/basic';
                 $this->_action = CRM_Core_Action::BASIC;
                 break;
             case 'custom':
                 $urlString = 'civicrm/contact/search/custom';
                 $this->_action = CRM_Core_Action::COPY;
                 break;
         }
         CRM_Contact_Form_Task::preProcessCommon($this);
         $this->_single = FALSE;
         $this->_contactId = NULL;
         //set ajax path, this used for custom data building
         $this->assign('urlPath', $urlString);
         $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}");
     }
     $this->assign('single', $this->_single);
     if (!$this->_id) {
         $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
     }
     $this->assign('action', $this->_action);
     // check for edit permission
     if (!CRM_Core_Permission::checkActionPermission('CiviEvent', $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         // check delete permission for contribution
         if ($this->_id && $this->_paymentId && !CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
             CRM_Core_Error::fatal(ts("This Participant is linked to a contribution. You must have 'delete in CiviContribute' permission in order to delete this record."));
         }
         return;
     }
     if ($this->_id) {
         // assign participant id to the template
         $this->assign('participantId', $this->_id);
         $this->_roleId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'role_id');
     }
     // when fee amount is included in form
     if (!empty($_POST['hidden_feeblock']) || !empty($_POST['send_receipt'])) {
         CRM_Event_Form_EventFees::preProcess($this);
         CRM_Event_Form_EventFees::buildQuickForm($this);
         CRM_Event_Form_EventFees::setDefaultValues($this);
     }
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
         // Custom data of type participant role
         // Note: Some earlier commits imply $_POST['role_id'] could be a comma separated string,
         //       not sure if that ever really happens
         if (!empty($_POST['role_id'])) {
             foreach ($_POST['role_id'] as $roleID) {
                 CRM_Custom_Form_CustomData::preProcess($this, $this->_roleCustomDataTypeID, $roleID, 1, 'Participant', $this->_id);
                 CRM_Custom_Form_CustomData::buildQuickForm($this);
                 CRM_Custom_Form_CustomData::setDefaultValues($this);
             }
         }
         //custom data of type participant event
         CRM_Custom_Form_CustomData::preProcess($this, $this->_eventNameCustomDataTypeID, $_POST['event_id'], 1, 'Participant', $this->_id);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
         // custom data of type participant event type
         $eventTypeId = NULL;
         if ($eventId = CRM_Utils_Array::value('event_id', $_POST)) {
             $eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'event_type_id', 'id');
         }
         CRM_Custom_Form_CustomData::preProcess($this, $this->_eventTypeCustomDataTypeID, $eventTypeId, 1, 'Participant', $this->_id);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
         //custom data of type participant, ( we 'null' to reset subType and subName)
         CRM_Custom_Form_CustomData::preProcess($this, 'null', 'null', 1, 'Participant', $this->_id);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     // CRM-4395, get the online pending contribution id.
     $this->_onlinePendingContributionId = NULL;
     if (!$this->_mode && $this->_id && $this->_action & CRM_Core_Action::UPDATE) {
         $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_id, 'Event');
     }
     $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId);
 }
Пример #28
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 public function setDefaultValues()
 {
     $defaults = array('contacts_id' => $this->_targetContactID ? $this->_targetContactID : NULL);
     if ($this->_activityId && $this->_action != CRM_Core_Action::VIEW) {
         $defaults += CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     return $defaults;
 }
Пример #29
0
 /**
  * Set default values for the form. MobileProvider that in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultValues()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     if ($this->_priceSetId) {
         return CRM_Price_BAO_PriceSet::setDefaultPriceSet($this, $defaults);
     }
     $defaults = parent::setDefaultValues();
     //setting default join date and receive date
     list($now, $currentTime) = CRM_Utils_Date::setDateDefaults();
     if ($this->_action == CRM_Core_Action::ADD) {
         $defaults['receive_date'] = $now;
         $defaults['receive_date_time'] = $currentTime;
     }
     if (is_numeric($this->_memType)) {
         $defaults['membership_type_id'] = array();
         $defaults['membership_type_id'][0] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'member_of_contact_id', 'id');
         $defaults['membership_type_id'][1] = $this->_memType;
     } else {
         $defaults['membership_type_id'] = $this->_memType;
     }
     $defaults['num_terms'] = 1;
     if (!empty($defaults['id'])) {
         if ($this->_onlinePendingContributionId) {
             $defaults['record_contribution'] = $this->_onlinePendingContributionId;
         } else {
             $contributionId = CRM_Core_DAO::singleValueQuery("\n  SELECT contribution_id\n  FROM civicrm_membership_payment\n  WHERE membership_id = {$this->_id}\n  ORDER BY contribution_id\n  DESC limit 1");
             if ($contributionId) {
                 $defaults['record_contribution'] = $contributionId;
             }
         }
     }
     //set Soft Credit Type to Gift by default
     $scTypes = CRM_Core_OptionGroup::values("soft_credit_type");
     $defaults['soft_credit_type_id'] = CRM_Utils_Array::value(ts('Gift'), array_flip($scTypes));
     if (!empty($defaults['record_contribution']) && !$this->_mode) {
         $contributionParams = array('id' => $defaults['record_contribution']);
         $contributionIds = array();
         //keep main object campaign in hand.
         $memberCampaignId = CRM_Utils_Array::value('campaign_id', $defaults);
         CRM_Contribute_BAO_Contribution::getValues($contributionParams, $defaults, $contributionIds);
         //get back original object campaign id.
         $defaults['campaign_id'] = $memberCampaignId;
         if (!empty($defaults['receive_date'])) {
             list($defaults['receive_date']) = CRM_Utils_Date::setDateDefaults($defaults['receive_date']);
         }
         // Contribution::getValues() over-writes the membership record's source field value - so we need to restore it.
         if (!empty($defaults['membership_source'])) {
             $defaults['source'] = $defaults['membership_source'];
         }
     }
     //CRM-13420
     if (empty($defaults['payment_instrument_id'])) {
         $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
     }
     // User must explicitly choose to send a receipt in both add and update mode.
     $defaults['send_receipt'] = 0;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         // in this mode by default uncheck this checkbox
         unset($defaults['record_contribution']);
     }
     if (!empty($defaults['id'])) {
         $subscriptionCancelled = CRM_Member_BAO_Membership::isSubscriptionCancelled($this->_id);
     }
     $alreadyAutoRenew = FALSE;
     if (!empty($defaults['contribution_recur_id']) && !$subscriptionCancelled) {
         $defaults['auto_renew'] = 1;
         $alreadyAutoRenew = TRUE;
     }
     $this->assign('alreadyAutoRenew', $alreadyAutoRenew);
     $this->assign('member_is_test', CRM_Utils_Array::value('member_is_test', $defaults));
     $this->assign('membership_status_id', CRM_Utils_Array::value('status_id', $defaults));
     if (!empty($defaults['is_pay_later'])) {
         $this->assign('is_pay_later', TRUE);
     }
     if ($this->_mode) {
         // set default country from config if no country set
         $config = CRM_Core_Config::singleton();
         if (empty($defaults["billing_country_id-{$this->_bltID}"])) {
             $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
         }
         if (empty($defaults["billing_state_province_id-{$this->_bltID}"])) {
             $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
         }
         $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
         $defaults = array_merge($defaults, $billingDefaults);
         //             // hack to simplify credit card entry for testing
         //             $defaults['credit_card_type']     = 'Visa';
         //             $defaults['credit_card_number']   = '4807731747657838';
         //             $defaults['cvv2']                 = '000';
         //             $defaults['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' );
     }
     $dates = array('join_date', 'start_date', 'end_date');
     foreach ($dates as $key) {
         if (!empty($defaults[$key])) {
             list($defaults[$key]) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value($key, $defaults));
         }
     }
     //setting default join date if there is no join date
     if (empty($defaults['join_date'])) {
         $defaults['join_date'] = $now;
     }
     if (!empty($defaults['membership_end_date'])) {
         $this->assign('endDate', $defaults['membership_end_date']);
     }
     return $defaults;
 }
Пример #30
0
 /**
  * This function sets the default values for the form in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultValues()
 {
     if ($this->_showFeeBlock) {
         return CRM_Event_Form_EventFees::setDefaultValues($this);
     }
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = array();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return $defaults;
     }
     if ($this->_id) {
         $ids = array();
         $params = array('id' => $this->_id);
         CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
         $sep = CRM_Core_DAO::VALUE_SEPARATOR;
         if ($defaults[$this->_id]['role_id']) {
             $roleIDs = explode($sep, $defaults[$this->_id]['role_id']);
         }
         $this->_contactId = $defaults[$this->_id]['contact_id'];
         $this->_statusId = $defaults[$this->_id]['participant_status_id'];
         //set defaults for note
         $noteDetails = CRM_Core_BAO_Note::getNote($this->_id, 'civicrm_participant');
         $defaults[$this->_id]['note'] = array_pop($noteDetails);
         // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true  (CRM-4859)
         if (CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) {
             $this->assign('additionalParticipants', CRM_Event_BAO_Participant::getAdditionalParticipants($this->_id));
         }
         // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
         if (!empty($defaults[$this->_id]['participant_registered_by_id'])) {
             $registered_by_contact_id = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $defaults[$this->_id]['participant_registered_by_id'], 'contact_id', 'id');
             $this->assign('participant_registered_by_id', $defaults[$this->_id]['participant_registered_by_id']);
             $this->assign('registered_by_contact_id', $registered_by_contact_id);
             $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact::displayName($registered_by_contact_id));
         }
     }
     if ($this->_action & (CRM_Core_Action::VIEW | CRM_Core_Action::BROWSE)) {
         $inactiveNeeded = TRUE;
         $viewMode = TRUE;
     } else {
         $viewMode = FALSE;
         $inactiveNeeded = FALSE;
     }
     //setting default register date
     if ($this->_action == CRM_Core_Action::ADD) {
         $statuses = array_flip($this->_participantStatuses);
         $defaults[$this->_id]['status_id'] = CRM_Utils_Array::value(ts('Registered'), $statuses);
         if (!empty($defaults[$this->_id]['event_id'])) {
             $contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $defaults[$this->_id]['event_id'], 'financial_type_id');
             if ($contributionTypeId) {
                 $defaults[$this->_id]['financial_type_id'] = $contributionTypeId;
             }
         }
         if ($this->_mode) {
             $fields["email-{$this->_bltID}"] = 1;
             $fields['email-Primary'] = 1;
             if ($this->_contactId) {
                 CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $fields, $defaults);
             }
             if (empty($defaults["email-{$this->_bltID}"]) && !empty($defaults['email-Primary'])) {
                 $defaults[$this->_id]["email-{$this->_bltID}"] = $defaults['email-Primary'];
             }
         }
         $submittedRole = $this->getElementValue('role_id');
         if (!empty($submittedRole[0])) {
             $roleID = $submittedRole[0];
         }
         $submittedEvent = $this->getElementValue('event_id');
         if (!empty($submittedEvent[0])) {
             $eventID = $submittedEvent[0];
         }
     } else {
         $defaults[$this->_id]['record_contribution'] = 0;
         if ($defaults[$this->_id]['participant_is_pay_later']) {
             $this->assign('participant_is_pay_later', TRUE);
         }
         $this->assign('participant_status_id', $defaults[$this->_id]['participant_status_id']);
         $eventID = $defaults[$this->_id]['event_id'];
         $this->_eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
         $this->_discountId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'discount_id');
         if ($this->_discountId) {
             $this->set('discountId', $this->_discountId);
         }
     }
     list($defaults[$this->_id]['register_date'], $defaults[$this->_id]['register_date_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('register_date', $defaults[$this->_id]), 'activityDateTime');
     //assign event and role id, this is needed for Custom data building
     $sep = CRM_Core_DAO::VALUE_SEPARATOR;
     if (!empty($defaults[$this->_id]['participant_role_id'])) {
         $roleIDs = explode($sep, $defaults[$this->_id]['participant_role_id']);
     }
     if (isset($_POST['event_id'])) {
         $eventID = $_POST['event_id'];
     }
     if ($this->_eID) {
         $eventID = $this->_eID;
         //@todo - rationalise the $this->_eID with $POST['event_id'],  $this->_eid is set when eid=x is in the url
         $roleID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eID, 'default_role_id');
         if (empty($roleIDs)) {
             $roleIDs = (array) ($defaults[$this->_id]['participant_role_id'] = $roleID);
         }
         $defaults[$this->_id]['event_id'] = $eventID;
     }
     if (!empty($eventID)) {
         $this->_eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
     }
     //these should take precedence so we state them last
     $urlRoleIDS = CRM_Utils_Request::retrieve('roles', 'String');
     if ($urlRoleIDS) {
         $roleIDs = explode(',', $urlRoleIDS);
     }
     if (isset($roleIDs)) {
         $defaults[$this->_id]['role_id'] = implode(',', $roleIDs);
     }
     if (isset($eventID)) {
         $this->assign('eventID', $eventID);
         $this->set('eventId', $eventID);
     }
     if (isset($this->_eventTypeId)) {
         $this->assign('eventTypeID', $this->_eventTypeId);
     }
     $this->assign('event_is_test', CRM_Utils_Array::value('event_is_test', $defaults[$this->_id]));
     return $defaults[$this->_id];
 }