Esempio n. 1
0
 /**
  * Set variables up before form is built.
  */
 public function preProcess()
 {
     $this->_mid = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE);
     $this->_crid = CRM_Utils_Request::retrieve('crid', 'Integer', $this, FALSE);
     if ($this->_crid) {
         $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_crid, 'recur', 'info');
         $this->_paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_crid, 'recur', 'obj');
         $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_crid);
         // Are we cancelling a recurring contribution that is linked to an auto-renew membership?
         if ($this->_subscriptionDetails->membership_id) {
             $this->_mid = $this->_subscriptionDetails->membership_id;
         }
     }
     $this->_coid = CRM_Utils_Request::retrieve('coid', 'Integer', $this, FALSE);
     if ($this->_coid) {
         $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_coid, 'contribute', 'info');
         $this->_paymentProcessor['object'] = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_coid, 'contribute', 'obj');
         $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_coid, 'contribution');
     }
     if ($this->_mid) {
         $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_mid, 'membership', 'info');
         $this->_paymentProcessor['object'] = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_mid, 'membership', 'obj');
         $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_mid, 'membership');
         $membershipTypes = CRM_Member_PseudoConstant::membershipType();
         $membershipTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_mid, 'membership_type_id');
         $this->assign('membershipType', CRM_Utils_Array::value($membershipTypeId, $membershipTypes));
         $this->_mode = 'auto_renew';
     }
     if (!$this->_crid && !$this->_coid && !$this->_mid || $this->_subscriptionDetails == CRM_Core_DAO::$_nullObject) {
         CRM_Core_Error::fatal('Required information missing.');
     }
     if (!CRM_Core_Permission::check('edit contributions')) {
         $userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this, FALSE);
         if (!CRM_Contact_BAO_Contact_Utils::validChecksum($this->_subscriptionDetails->contact_id, $userChecksum)) {
             CRM_Core_Error::fatal(ts('You do not have permission to cancel subscription.'));
         }
         $this->_selfService = TRUE;
     }
     if (!$this->_paymentProcessor['object']->isSupported('updateSubscriptionBillingInfo')) {
         CRM_Core_Error::fatal(ts("%1 processor doesn't support updating subscription billing details.", array(1 => $this->_paymentProcessor['object']->_processorName)));
     }
     $this->assign('paymentProcessor', $this->_paymentProcessor);
     $this->assignBillingType();
     $this->assign('frequency_unit', $this->_subscriptionDetails->frequency_unit);
     $this->assign('frequency_interval', $this->_subscriptionDetails->frequency_interval);
     $this->assign('amount', $this->_subscriptionDetails->amount);
     $this->assign('installments', $this->_subscriptionDetails->installments);
     $this->assign('mode', $this->_mode);
     // handle context redirection
     CRM_Contribute_BAO_ContributionRecur::setSubscriptionContext();
 }
 public function preProcess()
 {
     $this->_crid = CRM_Utils_Request::retrieve('crid', 'Integer', $this, FALSE);
     if ($this->_crid) {
         $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_crid, 'recur', 'info');
         $this->_paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_crid, 'recur', 'obj');
         $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_crid);
     }
     $this->_coid = CRM_Utils_Request::retrieve('coid', 'Integer', $this, FALSE);
     if ($this->_coid) {
         $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_coid, 'contribute', 'info');
         $this->_paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_coid, 'contribute', 'obj');
         $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_coid, 'contribution');
         $this->_crid = $this->_subscriptionDetails->recur_id;
     } elseif ($this->_crid) {
         $this->_coid = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_crid, 'id', 'contribution_recur_id');
     }
     if (!$this->_crid || $this->_subscriptionDetails == CRM_Core_DAO::$_nullObject) {
         CRM_Core_Error::fatal('Required information missing.');
     }
     if ($this->_subscriptionDetails->membership_id && $this->_subscriptionDetails->auto_renew) {
         CRM_Core_Error::fatal(ts('You cannot update the subscription.'));
     }
     if (!CRM_Core_Permission::check('edit contributions')) {
         $userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this, FALSE);
         if (!CRM_Contact_BAO_Contact_Utils::validChecksum($this->_subscriptionDetails->contact_id, $userChecksum)) {
             CRM_Core_Error::fatal(ts('You do not have permission to update subscription.'));
         }
         $this->_selfService = TRUE;
     }
     $this->assign('self_service', $this->_selfService);
     if (!$this->_paymentProcessorObj->isSupported('changeSubscriptionAmount')) {
         $userAlert = ts('Updates made using this form will change the recurring contribution information stored in your CiviCRM database, but will NOT be sent to the payment processor. You must enter the same changes using the payment processor web site.');
         CRM_Core_Session::setStatus($userAlert, ts('Warning'), 'alert');
     }
     $this->assign('isChangeSupported', $this->_paymentProcessorObj->isSupported('changeSubscriptionAmount'));
     $this->assign('paymentProcessor', $this->_paymentProcessor);
     $this->assign('frequency_unit', $this->_subscriptionDetails->frequency_unit);
     $this->assign('frequency_interval', $this->_subscriptionDetails->frequency_interval);
     if ($this->_subscriptionDetails->contact_id) {
         list($this->_donorDisplayName, $this->_donorEmail) = CRM_Contact_BAO_Contact::getContactDetails($this->_subscriptionDetails->contact_id);
     }
     CRM_Utils_System::setTitle(ts('Update Recurring Contribution'));
     // handle context redirection
     CRM_Contribute_BAO_ContributionRecur::setSubscriptionContext();
 }
Esempio n. 3
0
 /**
  * @param int $contactID
  * @param CRM_Core_Form $form
  * @param bool $redirect
  *
  * @return bool
  */
 public static function validateOnlyChecksum($contactID, &$form, $redirect = TRUE)
 {
     // check if this is of the format cs=XXX
     if (!CRM_Contact_BAO_Contact_Utils::validChecksum($contactID, CRM_Utils_Request::retrieve('cs', 'String', $form, FALSE))) {
         if ($redirect) {
             // also set a message in the UF framework
             $message = ts('You do not have permission to edit this contact record. Contact the site administrator if you need assistance.');
             CRM_Utils_System::setUFMessage($message);
             $config = CRM_Core_Config::singleton();
             CRM_Core_Error::statusBounce($message, $config->userFrameworkBaseURL);
             // does not come here, we redirect in the above statement
         }
         return FALSE;
     }
     // set appropriate AUTH source
     self::initChecksumAuthSrc(TRUE, $form);
     // so here the contact is posing as $contactID, lets set the logging contact ID variable
     // CRM-8965
     CRM_Core_DAO::executeQuery('SET @civicrm_user_id = %1', array(1 => array($contactID, 'Integer')));
     return TRUE;
 }
Esempio n. 4
0
 /**
  * Function to authenticate pledge user during online payment.
  *
  * @access public
  *
  * @return None
  */
 public function authenticatePledgeUser()
 {
     //get the userChecksum and contact id
     $userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this);
     $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     //get pledge status and contact id
     $pledgeValues = array();
     $pledgeParams = array('id' => $this->_values['pledge_id']);
     $returnProperties = array('contact_id', 'status_id');
     CRM_Core_DAO::commonRetrieve('CRM_Pledge_DAO_Pledge', $pledgeParams, $pledgeValues, $returnProperties);
     //get all status
     $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     $validStatus = array(array_search('Pending', $allStatus), array_search('In Progress', $allStatus), array_search('Overdue', $allStatus));
     $validUser = FALSE;
     if ($this->_userID && $this->_userID == $pledgeValues['contact_id']) {
         //check for authenticated  user.
         $validUser = TRUE;
     } elseif ($userChecksum && $pledgeValues['contact_id']) {
         //check for anonymous user.
         $validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($pledgeValues['contact_id'], $userChecksum);
         //make sure cid is same as pledge contact id
         if ($validUser && $pledgeValues['contact_id'] != $contactID) {
             $validUser = FALSE;
         }
     }
     if (!$validUser) {
         CRM_Core_Error::fatal(ts("Oops. It looks like you have an incorrect or incomplete link (URL). Please make sure you've copied the entire link, and try again. Contact the site administrator if this error persists."));
     }
     //check for valid pledge status.
     if (!in_array($pledgeValues['status_id'], $validStatus)) {
         CRM_Core_Error::fatal(ts('Oops. You cannot make a payment for this pledge - pledge status is %1.', array(1 => CRM_Utils_Array::value($pledgeValues['status_id'], $allStatus))));
     }
 }
Esempio n. 5
0
 /**
  * @return mixed
  */
 function getContactID()
 {
     //XXX when do we query 'cid' ?
     $tempID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     //check if this is a checksum authentication
     $userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this);
     if ($userChecksum) {
         //check for anonymous user.
         $validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($tempID, $userChecksum);
         if ($validUser) {
             return $tempID;
         }
     }
     // check if the user is registered and we have a contact ID
     $session = CRM_Core_Session::singleton();
     return $session->get('userID');
 }
Esempio n. 6
0
 /**
  * Get contact if for a form object. Prioritise
  *   - cid in URL if 0 (on behalf on someoneelse)
  *      (@todo consider setting a variable if onbehalf for clarity of downstream 'if's
  *   - logged in user id if it matches the one in the cid in the URL
  *   - contact id validated from a checksum from a checksum
  *   - cid from the url if the caller has ACL permission to view
  *   - fallback is logged in user (or ? NULL if no logged in user) (@todo wouldn't 0 be more intuitive?)
  *
  * @return NULL|int
  */
 protected function setContactID()
 {
     $tempID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     if (isset($this->_params) && isset($this->_params['select_contact_id'])) {
         $tempID = $this->_params['select_contact_id'];
     }
     if (isset($this->_params, $this->_params[0]) && !empty($this->_params[0]['select_contact_id'])) {
         // event form stores as an indexed array, contribution form not so much...
         $tempID = $this->_params[0]['select_contact_id'];
     }
     // force to ignore the authenticated user
     if ($tempID === '0' || $tempID === 0) {
         // we set the cid on the form so that this will be retained for the Confirm page
         // in the multi-page form & prevent us returning the $userID when this is called
         // from that page
         // we don't really need to set it when $tempID is set because the params have that stored
         $this->set('cid', 0);
         CRM_Core_Resources::singleton()->addVars('coreForm', array('contact_id' => (int) $tempID));
         return (int) $tempID;
     }
     $userID = $this->getLoggedInUserContactID();
     if (!is_null($tempID) && $tempID === $userID) {
         CRM_Core_Resources::singleton()->addVars('coreForm', array('contact_id' => (int) $tempID));
         return (int) $userID;
     }
     //check if this is a checksum authentication
     $userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this);
     if ($userChecksum) {
         //check for anonymous user.
         $validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($tempID, $userChecksum);
         if ($validUser) {
             CRM_Core_Resources::singleton()->addVars('coreForm', array('contact_id' => (int) $tempID));
             CRM_Core_Resources::singleton()->addVars('coreForm', array('checksum' => (int) $tempID));
             return $tempID;
         }
     } elseif ($tempID && CRM_Contact_BAO_Contact_Permission::allow($tempID)) {
         CRM_Core_Resources::singleton()->addVars('coreForm', array('contact_id' => (int) $tempID));
         return $tempID;
     }
     if (is_numeric($userID)) {
         CRM_Core_Resources::singleton()->addVars('coreForm', array('contact_id' => (int) $userID));
     }
     return is_numeric($userID) ? $userID : NULL;
 }
Esempio n. 7
0
 /**
  * Set variables up before form is built based on participant ID from URL
  *
  * @return void
  */
 public function preProcess()
 {
     $config = CRM_Core_Config::singleton();
     $session = CRM_Core_Session::singleton();
     $this->_userContext = $session->readUserContext();
     $participant = $values = array();
     $this->_participant_id = CRM_Utils_Request::retrieve('pid', 'Positive', $this, FALSE, NULL, 'REQUEST');
     $this->_userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this, FALSE, NULL, 'REQUEST');
     $params = array('id' => $this->_participant_id);
     $this->_participant = CRM_Event_BAO_Participant::getValues($params, $values, $participant);
     $this->_part_values = $values[$this->_participant_id];
     $this->set('values', $this->_part_values);
     //fetch Event by event_id, verify that this event can still be xferred/cancelled
     $this->_event_id = $this->_part_values['event_id'];
     $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}");
     $this->_contact_id = $this->_part_values['participant_contact_id'];
     $validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($this->_contact_id, $this->_userChecksum);
     if (!$validUser && !CRM_Core_Permission::check('edit all events')) {
         CRM_Core_Error::statusBounce(ts('You do not have sufficient permission to transfer/cancel this participant.'), $url);
     }
     $this->assign('action', $this->_action);
     if ($this->_participant_id) {
         $this->assign('participantId', $this->_participant_id);
     }
     $event = array();
     $daoName = 'title';
     $this->_event_title = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName);
     $daoName = 'start_date';
     $this->_event_start_date = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName);
     list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contact_id);
     $this->_contact_name = $displayName;
     $this->_contact_email = $email;
     $details = array();
     $details = CRM_Event_BAO_Participant::participantDetails($this->_participant_id);
     $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'participant_role', 'id', 'name');
     $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participant_id, 'contribution_id', 'participant_id');
     $this->assign('contributionId', $contributionId);
     $query = "\n      SELECT cpst.name as status, cov.name as role, cp.fee_level, cp.fee_amount, cp.register_date, cp.status_id, civicrm_event.start_date\n      FROM civicrm_participant cp\n      LEFT JOIN civicrm_participant_status_type cpst ON cpst.id = cp.status_id\n      LEFT JOIN civicrm_option_value cov ON cov.value = cp.role_id and cov.option_group_id = {$optionGroupId}\n      LEFT JOIN civicrm_event ON civicrm_event.id = cp.event_id\n      WHERE cp.id = {$this->_participant_id}";
     $dao = CRM_Core_DAO::executeQuery($query);
     while ($dao->fetch()) {
         $details['status'] = $dao->status;
         $details['role'] = $dao->role;
         $details['fee_level'] = $dao->fee_level;
         $details['fee_amount'] = $dao->fee_amount;
         $details['register_date'] = $dao->register_date;
         $details['event_start_date'] = $dao->start_date;
     }
     //verify participant status is still Registered
     if ($details['status'] != "Registered") {
         $status = "You cannot transfer or cancel your registration for " . $this->_event_title . ' as you are not currently registered for this event.';
         CRM_Core_Session::setStatus($status, ts('Sorry'), 'alert');
         CRM_Utils_System::redirect($url);
     }
     $query = "select start_date as start, selfcancelxfer_time as time from civicrm_event where id = " . $this->_event_id;
     $dao = CRM_Core_DAO::executeQuery($query);
     while ($dao->fetch()) {
         $time_limit = $dao->time;
         $start_date = $dao->start;
     }
     $start_time = new Datetime($start_date);
     $timenow = new Datetime();
     if (!empty($start_time) && $start_time < $timenow) {
         $status = ts("Registration for this event cannot be cancelled or transferred once the event has begun. Contact the event organizer if you have questions.");
         CRM_Core_Error::statusBounce($status, $url, ts('Sorry'));
     }
     if (!empty($time_limit) && $time_limit > 0) {
         $interval = $timenow->diff($start_time);
         $days = $interval->format('%d');
         $hours = $interval->format('%h');
         if ($hours <= $time_limit && $days < 1) {
             $status = ts("Registration for this event cannot be cancelled or transferred less than %1 hours prior to the event's start time. Contact the event organizer if you have questions.", array(1 => $time_limit));
             CRM_Core_Error::statusBounce($status, $url, ts('Sorry'));
         }
     }
     $this->assign('details', $details);
     $this->selfsvcupdateUrl = CRM_Utils_System::url('civicrm/event/selfsvcupdate', "reset=1&id={$this->_participant_id}&id=0");
     $this->selfsvcupdateText = ts('Update');
     $this->selfsvcupdateButtonText = ts('Update');
     // Based on those ids retrieve event and verify it is eligible
     // for self update (event.start_date > today, event can be 'self_updated'
     // retrieve contact name and email, and let user verify his/her identity
 }
Esempio n. 8
0
 static function validateOnlyChecksum($contactID, &$form)
 {
     // check if this is of the format cs=XXX
     require_once 'CRM/Contact/BAO/Contact/Utils.php';
     if (!CRM_Contact_BAO_Contact_Utils::validChecksum($contactID, CRM_Utils_Request::retrieve('cs', 'String', $form, false))) {
         $config = CRM_Core_Config::singleton();
         CRM_Core_Error::statusBounce(ts('You do not have permission to edit this contact record. Contact the site administrator if you need assistance.'), $config->userFrameworkBaseURL);
         // does not come here, we redirect in the above statement
     }
     return true;
 }
function _cividiscount_get_form_contact_id($form)
{
    if (!empty($form->_pId)) {
        $contact_id = $form->_pId;
    } else {
        if ($form->getVar('_contactID')) {
            $contact_id = $form->getVar('_contactID');
        } else {
            if ($form->getVar('_contactId')) {
                $contact_id = $form->getVar('_contactId');
            } else {
                if (!empty($form->_submitValues['contact_select_id'][1])) {
                    $contact_id = $form->_submitValues['contact_select_id'][1];
                } else {
                    $contact_id = CRM_Core_Session::singleton()->get('userID');
                }
            }
        }
    }
    //For anonymous user fetch contact ID on basis of checksum
    if (empty($contact_id)) {
        $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $form);
        if (!empty($cid)) {
            //check if this is a checksum authentication
            $userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $form);
            if ($userChecksum) {
                //check for anonymous user.
                $validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($cid, $userChecksum);
                if ($validUser) {
                    return $cid;
                }
            }
        }
    }
    return $contact_id;
}
Esempio n. 10
0
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     $this->_mid = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE);
     $this->_crid = CRM_Utils_Request::retrieve('crid', 'Integer', $this, FALSE);
     if ($this->_crid) {
         $this->_paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_crid, 'recur', 'obj');
         $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_crid);
         $this->assign('frequency_unit', $this->_subscriptionDetails->frequency_unit);
         $this->assign('frequency_interval', $this->_subscriptionDetails->frequency_interval);
         $this->assign('amount', $this->_subscriptionDetails->amount);
         $this->assign('installments', $this->_subscriptionDetails->installments);
         // Are we cancelling a recurring contribution that is linked to an auto-renew membership?
         if ($this->_subscriptionDetails->membership_id) {
             $this->_mid = $this->_subscriptionDetails->membership_id;
         }
     }
     if ($this->_mid) {
         if (CRM_Member_BAO_Membership::isSubscriptionCancelled($this->_mid)) {
             CRM_Core_Error::fatal(ts('The auto renewal option for this membership looks to have been cancelled already.'));
         }
         $this->_mode = 'auto_renew';
         $this->_paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_mid, 'membership', 'obj');
         $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_mid, 'membership');
         $membershipTypes = CRM_Member_PseudoConstant::membershipType();
         $membershipTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_mid, 'membership_type_id');
         $this->assign('membershipType', CRM_Utils_Array::value($membershipTypeId, $membershipTypes));
     }
     $this->_coid = CRM_Utils_Request::retrieve('coid', 'Integer', $this, FALSE);
     if ($this->_coid) {
         if (CRM_Contribute_BAO_Contribution::isSubscriptionCancelled($this->_coid)) {
             CRM_Core_Error::fatal(ts('The recurring contribution looks to have been cancelled already.'));
         }
         $this->_paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_coid, 'contribute', 'obj');
         $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_coid, 'contribution');
         $this->assign('frequency_unit', $this->_subscriptionDetails->frequency_unit);
         $this->assign('frequency_interval', $this->_subscriptionDetails->frequency_interval);
         $this->assign('amount', $this->_subscriptionDetails->amount);
         $this->assign('installments', $this->_subscriptionDetails->installments);
     }
     if (!$this->_crid && !$this->_coid && !$this->_mid || $this->_subscriptionDetails == CRM_Core_DAO::$_nullObject) {
         CRM_Core_Error::fatal('Required information missing.');
     }
     if (!CRM_Core_Permission::check('edit contributions')) {
         $userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this, FALSE);
         if (!CRM_Contact_BAO_Contact_Utils::validChecksum($this->_subscriptionDetails->contact_id, $userChecksum)) {
             CRM_Core_Error::fatal(ts('You do not have permission to cancel this recurring contribution.'));
         }
         $this->_selfService = TRUE;
     }
     $this->assign('self_service', $this->_selfService);
     // handle context redirection
     CRM_Contribute_BAO_ContributionRecur::setSubscriptionContext();
     CRM_Utils_System::setTitle($this->_mid ? ts('Cancel Auto-renewal') : ts('Cancel Recurring Contribution'));
     $this->assign('mode', $this->_mode);
     if ($this->_subscriptionDetails->contact_id) {
         list($this->_donorDisplayName, $this->_donorEmail) = CRM_Contact_BAO_Contact::getContactDetails($this->_subscriptionDetails->contact_id);
     }
 }
Esempio n. 11
0
 /**
  * Get source values for transfer based on participant id in URL. Line items will
  * be transferred to this participant - at this point no transaction changes processed
  *
  * return @void
  */
 public function preProcess()
 {
     $config = CRM_Core_Config::singleton();
     $session = CRM_Core_Session::singleton();
     $this->_userContext = $session->readUserContext();
     $this->_from_participant_id = CRM_Utils_Request::retrieve('pid', 'Positive', $this, FALSE, NULL, 'REQUEST');
     $this->_userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this, FALSE, NULL, 'REQUEST');
     $params = array('id' => $this->_from_participant_id);
     $participant = $values = array();
     $this->_participant = CRM_Event_BAO_Participant::getValues($params, $values, $participant);
     $this->_part_values = $values[$this->_from_participant_id];
     $this->set('values', $this->_part_values);
     $this->_event_id = $this->_part_values['event_id'];
     $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}");
     $this->_from_contact_id = $this->_part_values['participant_contact_id'];
     $validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($this->_from_contact_id, $this->_userChecksum);
     if (!$validUser && !CRM_Core_Permission::check('edit all events')) {
         CRM_Core_Error::statusBounce(ts('You do not have sufficient permission to transfer/cancel this participant.'), $url);
     }
     $this->assign('action', $this->_action);
     if ($this->_from_participant_id) {
         $this->assign('participantId', $this->_from_participant_id);
     }
     $event = array();
     $daoName = 'title';
     $this->_event_title = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName);
     $daoName = 'start_date';
     $this->_event_start_date = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName);
     list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_from_contact_id);
     $this->_contact_name = $displayName;
     $this->_contact_email = $email;
     $details = array();
     $details = CRM_Event_BAO_Participant::participantDetails($this->_from_participant_id);
     $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'participant_role', 'id', 'name');
     $query = "\n      SELECT cpst.name as status, cov.name as role, cp.fee_level, cp.fee_amount, cp.register_date, civicrm_event.start_date\n      FROM civicrm_participant cp\n      LEFT JOIN civicrm_participant_status_type cpst ON cpst.id = cp.status_id\n      LEFT JOIN civicrm_option_value cov ON cov.value = cp.role_id and cov.option_group_id = {$optionGroupId}\n      LEFT JOIN civicrm_event ON civicrm_event.id = cp.event_id\n      WHERE cp.id = {$this->_from_participant_id}";
     $dao = CRM_Core_DAO::executeQuery($query);
     while ($dao->fetch()) {
         $details['status'] = $dao->status;
         $details['role'] = $dao->role;
         $details['fee_level'] = $dao->fee_level;
         $details['fee_amount'] = $dao->fee_amount;
         $details['register_date'] = $dao->register_date;
         $details['event_start_date'] = $dao->start_date;
     }
     $this->assign('details', $details);
     //This participant row will be cancelled.  Get line item(s) to cancel
     $this->selfsvctransferUrl = CRM_Utils_System::url('civicrm/event/selfsvcupdate', "reset=1&id={$this->_from_participant_id}&id=0");
     $this->selfsvctransferText = ts('Update');
     $this->selfsvctransferButtonText = ts('Update');
 }
 /**
  * Pre-processing for the form.
  *
  * @throws \Exception
  */
 public function preProcess()
 {
     $this->contributionRecurID = CRM_Utils_Request::retrieve('crid', 'Integer', $this, FALSE);
     if ($this->contributionRecurID) {
         $this->_paymentProcessor = CRM_Contribute_BAO_ContributionRecur::getPaymentProcessor($this->contributionRecurID);
         if (!$this->_paymentProcessor) {
             CRM_Core_Error::statusBounce(ts('There is no valid processor for this subscription so it cannot be edited.'));
         }
         $this->_paymentProcessorObj = $this->_paymentProcessor['object'];
         $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->contributionRecurID);
     }
     $this->_coid = CRM_Utils_Request::retrieve('coid', 'Integer', $this, FALSE);
     if ($this->_coid) {
         $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_coid, 'contribute', 'info');
         $this->_paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_coid, 'contribute', 'obj');
         $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_coid, 'contribution');
         $this->contributionRecurID = $this->_subscriptionDetails->recur_id;
     } elseif ($this->contributionRecurID) {
         $this->_coid = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->contributionRecurID, 'id', 'contribution_recur_id');
     }
     if (!$this->contributionRecurID || $this->_subscriptionDetails == CRM_Core_DAO::$_nullObject) {
         CRM_Core_Error::fatal('Required information missing.');
     }
     if ($this->_subscriptionDetails->membership_id && $this->_subscriptionDetails->auto_renew) {
         CRM_Core_Error::fatal(ts('You cannot update the subscription.'));
     }
     if (!CRM_Core_Permission::check('edit contributions')) {
         $userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this, FALSE);
         if (!CRM_Contact_BAO_Contact_Utils::validChecksum($this->_subscriptionDetails->contact_id, $userChecksum)) {
             CRM_Core_Error::fatal(ts('You do not have permission to update subscription.'));
         }
         $this->_selfService = TRUE;
     }
     $this->assign('self_service', $this->_selfService);
     $this->editableScheduleFields = $this->_paymentProcessorObj->getEditableRecurringScheduleFields();
     $changeHelpText = $this->_paymentProcessorObj->getRecurringScheduleUpdateHelpText();
     if (!in_array('amount', $this->editableScheduleFields)) {
         // Not sure if this is good behaviour - maintaining this existing behaviour for now.
         CRM_Core_Session::setStatus($changeHelpText, ts('Warning'), 'alert');
     } else {
         $this->assign('changeHelpText', $changeHelpText);
     }
     $alreadyHardCodedFields = array('amount', 'installments');
     foreach ($this->editableScheduleFields as $editableScheduleField) {
         if (!in_array($editableScheduleField, $alreadyHardCodedFields)) {
             $this->addField($editableScheduleField, array('entity' => 'ContributionRecur'));
         }
     }
     $this->assign('editableScheduleFields', array_diff($this->editableScheduleFields, $alreadyHardCodedFields));
     $this->assign('paymentProcessor', $this->_paymentProcessor);
     $this->assign('frequency_unit', $this->_subscriptionDetails->frequency_unit);
     $this->assign('frequency_interval', $this->_subscriptionDetails->frequency_interval);
     if ($this->_subscriptionDetails->contact_id) {
         list($this->_donorDisplayName, $this->_donorEmail) = CRM_Contact_BAO_Contact::getContactDetails($this->_subscriptionDetails->contact_id);
     }
     CRM_Utils_System::setTitle(ts('Update Recurring Contribution'));
     // Handle context redirection.
     CRM_Contribute_BAO_ContributionRecur::setSubscriptionContext();
 }
 /** 
  * Function to set variables up before form is built 
  *                                                           
  * @return void 
  * @access public 
  */
 public function preProcess()
 {
     $mid = CRM_Utils_Request::retrieve('mid', 'Integer', $this, true);
     if (!CRM_Core_Permission::check('edit memberships')) {
         require_once 'CRM/Contact/BAO/Contact/Utils.php';
         $userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this, false);
         $contactID = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $mid, "contact_id");
         if (!CRM_Contact_BAO_Contact_Utils::validChecksum($contactID, $userChecksum)) {
             CRM_Core_Error::fatal(ts('You do not have permission to cancel subscription.'));
         }
     }
     $cid = CRM_Utils_Request::retrieve('cid', 'Integer', $this, false);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this, false);
     $selectedChild = CRM_Utils_Request::retrieve('selectedChild', 'String', $this, false);
     if (!$context) {
         $context = CRM_Utils_Request::retrieve('compContext', 'String', $this, false);
     }
     $qfkey = CRM_Utils_Request::retrieve('key', 'String', $this, false);
     if ($cid) {
         $this->_userContext = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&selectedChild={$selectedChild}&cid={$cid}");
     } else {
         if ($mid) {
             $this->_userContext = CRM_Utils_System::url('civicrm/member/search', "force=1&context={$context}&key={$qfkey}");
             if ($context == 'dashboard') {
                 $this->_userContext = CRM_Utils_System::url('civicrm/member', "force=1&context={$context}&key={$qfkey}");
             }
         }
     }
     $session = CRM_Core_Session::singleton();
     if ($session->get('userID')) {
         $session->pushUserContext($this->_userContext);
     }
     if ($mid) {
         $membershipTypes = CRM_Member_PseudoConstant::membershipType();
         $membershipTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $mid, 'membership_type_id');
         $this->assign('membershipType', CRM_Utils_Array::value($membershipTypeId, $membershipTypes));
         require_once 'CRM/Member/BAO/Membership.php';
         if (CRM_Member_BAO_Membership::isSubscriptionCancelled($mid)) {
             CRM_Core_Error::fatal(ts('The auto renew membership looks to have been cancelled already.'));
         }
         $isCancelSupported = CRM_Member_BAO_Membership::isCancelSubscriptionSupported($mid, false);
     }
     if ($isCancelSupported) {
         $sql = " \n    SELECT mp.contribution_id, rec.id as recur_id, rec.processor_id \n      FROM civicrm_membership_payment mp \nINNER JOIN civicrm_membership         mem ON ( mp.membership_id = mem.id ) \nINNER JOIN civicrm_contribution_recur rec ON ( mem.contribution_recur_id = rec.id )\nINNER JOIN civicrm_contribution       con ON ( con.id = mp.contribution_id )\n     WHERE mp.membership_id = {$mid}";
         $dao = CRM_Core_DAO::executeQuery($sql);
         if ($dao->fetch()) {
             $this->_contributionRecurId = $dao->recur_id;
             $this->_subscriptionId = $dao->processor_id;
             $contributionId = $dao->contribution_id;
         }
         if ($contributionId) {
             require_once 'CRM/Contribute/BAO/Contribution.php';
             $contribution = new CRM_Contribute_DAO_Contribution();
             $contribution->id = $contributionId;
             $contribution->find(true);
             $contribution->receive_date = CRM_Utils_Date::isoToMysql($contribution->receive_date);
             $contribution->receipt_date = CRM_Utils_Date::isoToMysql($contribution->receipt_date);
             $this->_objects['contribution'] = $contribution;
             $this->_paymentObject = CRM_Core_BAO_PaymentProcessor::getProcessorForEntity($mid, 'membership', 'obj');
         }
     } else {
         CRM_Core_Error::fatal(ts('Could not detect payment processor OR the processor does not support cancellation of auto renew.'));
     }
 }
Esempio n. 14
0
 function getContactID()
 {
     $tempID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     // force to ignore the authenticated user
     if ($tempID === '0') {
         return;
     }
     //check if this is a checksum authentication
     $userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this);
     if ($userChecksum) {
         //check for anonymous user.
         require_once 'CRM/Contact/BAO/Contact/Utils.php';
         $validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($tempID, $userChecksum);
         if ($validUser) {
             return $tempID;
         }
     }
     // check if the user is registered and we have a contact ID
     $session = CRM_Core_Session::singleton();
     return $session->get('userID');
 }