Example #1
0
 /**
  * This function takes care of all the things common to all pages.
  *
  * This typically involves assigning the appropriate smarty variables :)
  */
 public function run()
 {
     $transaction = new CRM_Core_Transaction();
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW, $this->_id, 'register for events')) {
         CRM_Core_Error::fatal(ts('You do not have permission to register for this event'));
     }
     $cart = CRM_Event_Cart_BAO_Cart::find_or_create_for_current_session();
     $event_in_cart = $cart->add_event($this->_id);
     $url = CRM_Utils_System::url('civicrm/event/view_cart');
     CRM_Utils_System::setUFMessage(ts("<b>%1</b> has been added to your cart. <a href='%2'>View your cart.</a>", array(1 => $event_in_cart->event->title, 2 => $url)));
     $transaction->commit();
     return CRM_Utils_System::redirect($_SERVER['HTTP_REFERER']);
 }
 function run()
 {
     // Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml
     CRM_Utils_System::setTitle(ts('Prinsclear'));
     $this->assign('startTime', date('Y-m-d H:i:s'));
     try {
         $conv = new CRM_Prinsimport_Pages_Importhandling();
         foreach ($GLOBALS['CONVERSIE'] as $def) {
             $conv->clearTable($def);
         }
     } catch (CiviCRM_API3_Exception $e) {
         $error = $e->getMessage();
         CRM_Utils_System::setUFMessage('API error: ' . $error);
     }
     // Example: Assign a variable for use in a template
     $this->assign('currentTime', date('Y-m-d H:i:s'));
     $this->assign('homeCiviUrl', CRM_Utils_System::url('civicrm', null, true));
     parent::run();
 }
 function run()
 {
     // Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml
     CRM_Utils_System::setTitle(ts('Prinsread'));
     $this->assign('startTime', date('Y-m-d H:i:s'));
     $this->assign('message', 'starting');
     // message to produce on the page
     try {
         $conv = new CRM_Prinsimport_Pages_Importhandling();
         //$con = $conv->dbConnect();
         //CRM_Core_Error::Debug('CONNECTION', $con);
         //exit();
         // open files
         //CRM_Core_Error::Debug('GLOBALS', dirname(__FILE__));
         //exit();
         //dpm($GLOBALS['CONVERSIE']);
         foreach ($GLOBALS['CONVERSIE'] as $def) {
             //CRM_Core_Error::Debug($def);
             //exit();
             // create tables (if not available)
             $this->assign('message', 'create table ' . key($GLOBALS['CONVERSIE']));
             $conv->createTable($def);
             $conv->importFile($def);
         }
         // read lines
         // insert into table
         // close files
         // report "done"
         $this->assign('message', 'ready');
         // Example: Assign a variable for use in a template
         $this->assign('currentTime', date('Y-m-d H:i:s'));
     } catch (CiviCRM_API3_Exception $e) {
         $error = $e->getMessage();
         CRM_Utils_System::setUFMessage('API error: ' . $error);
         $this->assign('message', $this->message . ': ' . $error);
     }
     // Example: Assign a variable for use in a template
     $this->assign('currentTime', date('Y-m-d H:i:s'));
     $this->assign('homeCiviUrl', CRM_Utils_System::url('civicrm', null, true));
     parent::run();
 }
Example #4
0
 function preProcess()
 {
     $params = array();
     $defaults = array();
     $ids = array();
     $session =& CRM_Core_Session::singleton();
     $uid = $session->get('userID');
     if (!$uid) {
         require_once 'CRM/Utils/System.php';
         CRM_Utils_System::setUFMessage(ts('We could not find a user id. You must be logged in to access the CiviCRM Home Page and menus.'));
         CRM_Core_Error::statusBounce(ts('We could not find a user id. You must be logged in to access the CiviCRM Home Page and menus.'));
     }
     $this->assign('contactId', $uid);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'view');
     $this->assign('action', $this->_action);
     // a user can always view their own activity history
     // if they have access CiviCRM permission
     $this->_permission = CRM_Core_Permission::VIEW;
     // make the permission edit if the user has edit permission on the contact
     require_once 'CRM/Contact/BAO/Contact/Permission.php';
     if (CRM_Contact_BAO_Contact_Permission::allow($uid, CRM_Core_Permission::EDIT)) {
         $this->_permission = CRM_Core_Permission::EDIT;
     }
     $displayName = $this->get('displayName');
     list($displayName, $contactImage, $contactType) = CRM_Contact_BAO_Contact::getDisplayAndImage($uid, true);
     $this->set('displayName', $displayName);
     $this->set('contactImage', $contactImage);
     CRM_Utils_System::setTitle($contactImage . ' ' . $displayName, $displayName);
     CRM_Utils_Recent::add($displayName, CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $uid), $uid, $contactType, $uid, $displayName);
     // call hook to get html from other modules
     require_once 'CRM/Utils/Hook.php';
     $contentPlacement = CRM_Utils_Hook::DASHBOARD_BELOW;
     // ignored but needed to prevent warnings
     $html = CRM_Utils_Hook::dashboard($uid, $contentPlacement);
     if (is_array($html)) {
         $this->assign_by_ref('hookContent', $html);
         $this->assign('hookContentPlacement', $contentPlacement);
     }
 }
Example #5
0
 /**
  * Send subscribe mail.
  *
  * @param array $groups
  *   The list of group ids for subscribe.
  * @param array $params
  *   The list of email.
  * @param int $contactId
  *   Currently used during event registration/contribution.
  *   Specifically to avoid linking group to wrong duplicate contact
  *   during event registration.
  * @param string $context
  *
  * @return void
  */
 public static function commonSubscribe(&$groups, &$params, $contactId = NULL, $context = NULL)
 {
     $contactGroups = CRM_Mailing_Event_BAO_Subscribe::getContactGroups($params['email'], $contactId);
     $group = array();
     $success = NULL;
     foreach ($groups as $groupID) {
         $title = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $groupID, 'title');
         if (array_key_exists($groupID, $contactGroups) && $contactGroups[$groupID]['status'] != 'Removed') {
             $group[$groupID]['title'] = $contactGroups[$groupID]['title'];
             $group[$groupID]['status'] = $contactGroups[$groupID]['status'];
             $status = ts('You are already subscribed in %1, your subscription is %2.', array(1 => $group[$groupID]['title'], 2 => ts($group[$groupID]['status'])));
             CRM_Utils_System::setUFMessage($status);
             continue;
         }
         $se = self::subscribe($groupID, $params['email'], $contactId, $context);
         if ($se !== NULL) {
             $success = TRUE;
             $groupAdded[] = $title;
             // Ask the contact for confirmation
             $se->send_confirm_request($params['email']);
         } else {
             $success = FALSE;
             $groupFailed[] = $title;
         }
     }
     if ($success) {
         $groupTitle = implode(', ', $groupAdded);
         CRM_Utils_System::setUFMessage(ts('Your subscription request has been submitted for %1. Check your inbox shortly for the confirmation email(s). If you do not see a confirmation email, please check your spam/junk mail folder.', array(1 => $groupTitle)));
     } elseif ($success === FALSE) {
         $groupTitle = implode(',', $groupFailed);
         CRM_Utils_System::setUFMessage(ts('We had a problem processing your subscription request for %1. You have tried to subscribe to a private group and/or we encountered a database error. Please contact the site administrator.', array(1 => $groupTitle)));
     }
 }
Example #6
0
 /**
  * Intercept QF validation and do our own redirection.
  *
  * We use this to send control back to the user for a user formatted page
  * This allows the user to maintain the same state and display the error messages
  * in their own theme along with any modifications
  *
  * This is a first version and will be tweaked over a period of time
  *
  *
  * @return bool
  *   true if no error found
  */
 public function validate()
 {
     $errors = parent::validate();
     if (!$errors && !empty($_POST['errorURL'])) {
         $message = NULL;
         foreach ($this->_errors as $name => $mess) {
             $message .= $mess;
             $message .= '<p>';
         }
         CRM_Utils_System::setUFMessage($message);
         $message = urlencode($message);
         $errorURL = $_POST['errorURL'];
         if (strpos($errorURL, '?') !== FALSE) {
             $errorURL .= '&';
         } else {
             $errorURL .= '?';
         }
         $errorURL .= "gid={$this->_gid}&msg={$message}";
         CRM_Utils_System::redirect($errorURL);
     }
     return $errors;
 }
 /**
  * called after the user submits the form.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->exportValues();
     if ($this->_selfService && $this->_donorEmail) {
         // for self service force notify
         $params['is_notify'] = 1;
     }
     // if this is an update of an existing recurring contribution, pass the ID
     $params['id'] = $this->_subscriptionDetails->recur_id;
     $message = '';
     $params['subscriptionId'] = $this->_subscriptionDetails->subscription_id;
     $updateSubscription = TRUE;
     if ($this->_paymentProcessorObj->isSupported('changeSubscriptionAmount')) {
         $updateSubscription = $this->_paymentProcessorObj->changeSubscriptionAmount($message, $params);
     }
     if (is_a($updateSubscription, 'CRM_Core_Error')) {
         CRM_Core_Error::displaySessionError($updateSubscription);
         $status = ts('Could not update the Recurring contribution details');
         $msgTitle = ts('Update Error');
         $msgType = 'error';
     } elseif ($updateSubscription) {
         // save the changes
         $result = CRM_Contribute_BAO_ContributionRecur::add($params);
         $status = ts('Recurring contribution has been updated to: %1, every %2 %3(s) for %4 installments.', array(1 => CRM_Utils_Money::format($params['amount'], $this->_subscriptionDetails->currency), 2 => $this->_subscriptionDetails->frequency_interval, 3 => $this->_subscriptionDetails->frequency_unit, 4 => $params['installments']));
         $msgTitle = ts('Update Success');
         $msgType = 'success';
         $contactID = $this->_subscriptionDetails->contact_id;
         if ($this->_subscriptionDetails->amount != $params['amount']) {
             $message .= "<br /> " . ts("Recurring contribution amount has been updated from %1 to %2 for this subscription.", array(1 => CRM_Utils_Money::format($this->_subscriptionDetails->amount, $this->_subscriptionDetails->currency), 2 => CRM_Utils_Money::format($params['amount'], $this->_subscriptionDetails->currency))) . ' ';
         }
         if ($this->_subscriptionDetails->installments != $params['installments']) {
             $message .= "<br /> " . ts("Recurring contribution installments have been updated from %1 to %2 for this subscription.", array(1 => $this->_subscriptionDetails->installments, 2 => $params['installments'])) . ' ';
         }
         $activityParams = array('source_contact_id' => $contactID, 'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type', 'Update Recurring Contribution', 'name'), 'subject' => ts('Recurring Contribution Updated'), 'details' => $message, 'activity_date_time' => date('YmdHis'), 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name'));
         $session = CRM_Core_Session::singleton();
         $cid = $session->get('userID');
         if ($cid) {
             $activityParams['target_contact_id'][] = $activityParams['source_contact_id'];
             $activityParams['source_contact_id'] = $cid;
         }
         CRM_Activity_BAO_Activity::create($activityParams);
         if (!empty($params['is_notify'])) {
             // send notification
             if ($this->_subscriptionDetails->contribution_page_id) {
                 CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $this->_subscriptionDetails->contribution_page_id, $value, array('title', 'receipt_from_name', 'receipt_from_email'));
                 $receiptFrom = '"' . CRM_Utils_Array::value('receipt_from_name', $value[$this->_subscriptionDetails->contribution_page_id]) . '" <' . $value[$this->_subscriptionDetails->contribution_page_id]['receipt_from_email'] . '>';
             } else {
                 $domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
                 $receiptFrom = "{$domainValues['0']} <{$domainValues['1']}>";
             }
             list($donorDisplayName, $donorEmail) = CRM_Contact_BAO_Contact::getContactDetails($contactID);
             $tplParams = array('recur_frequency_interval' => $this->_subscriptionDetails->frequency_interval, 'recur_frequency_unit' => $this->_subscriptionDetails->frequency_unit, 'amount' => CRM_Utils_Money::format($params['amount']), 'installments' => $params['installments']);
             $tplParams['contact'] = array('display_name' => $donorDisplayName);
             $tplParams['receipt_from_email'] = $receiptFrom;
             $sendTemplateParams = array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'contribution_recurring_edit', 'contactId' => $contactID, 'tplParams' => $tplParams, 'isTest' => $this->_subscriptionDetails->is_test, 'PDFFilename' => 'receipt.pdf', 'from' => $receiptFrom, 'toName' => $donorDisplayName, 'toEmail' => $donorEmail);
             list($sent) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
         }
     }
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     if ($userID && $status) {
         CRM_Core_Session::setStatus($status, $msgTitle, $msgType);
     } elseif (!$userID) {
         if ($status) {
             CRM_Utils_System::setUFMessage($status);
         }
         // keep result as 1, since we not displaying anything on the redirected page anyway
         return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/subscriptionstatus', "reset=1&task=update&result=1"));
     }
 }
Example #8
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  * Finally it calls the parent's run method.
  *
  * @return void
  */
 public function run()
 {
     //get the event id.
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $config = CRM_Core_Config::singleton();
     // ensure that the user has permission to see this page
     if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW, $this->_id, 'view event info')) {
         CRM_Utils_System::setUFMessage(ts('You do not have permission to view this event'));
         return CRM_Utils_System::permissionDenied();
     }
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'register');
     $this->assign('context', $context);
     // Sometimes we want to suppress the Event Full msg
     $noFullMsg = CRM_Utils_Request::retrieve('noFullMsg', 'String', $this, FALSE, 'false');
     // set breadcrumb to append to 2nd layer pages
     $breadCrumbPath = CRM_Utils_System::url('civicrm/event/info', "id={$this->_id}&reset=1");
     //retrieve event information
     $params = array('id' => $this->_id);
     CRM_Event_BAO_Event::retrieve($params, $values['event']);
     if (!$values['event']['is_active']) {
         // form is inactive, die a fatal death
         CRM_Utils_System::setUFMessage(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
         return CRM_Utils_System::permissionDenied();
     }
     if (!empty($values['event']['is_template'])) {
         // form is an Event Template
         CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
     }
     // Add Event Type to $values in case folks want to display it
     $values['event']['event_type'] = CRM_Utils_Array::value($values['event']['event_type_id'], CRM_Event_PseudoConstant::eventType());
     $this->assign('isShowLocation', CRM_Utils_Array::value('is_show_location', $values['event']));
     // show event fees.
     if ($this->_id && !empty($values['event']['is_monetary'])) {
         //CRM-6907
         $config = CRM_Core_Config::singleton();
         $config->defaultCurrency = CRM_Utils_Array::value('currency', $values['event'], $config->defaultCurrency);
         //CRM-10434
         $discountId = CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event');
         if ($discountId) {
             $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'price_set_id');
         } else {
             $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_id);
         }
         // get price set options, - CRM-5209
         if ($priceSetId) {
             $setDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, TRUE);
             $priceSetFields = $setDetails[$priceSetId]['fields'];
             if (is_array($priceSetFields)) {
                 $fieldCnt = 1;
                 $visibility = CRM_Core_PseudoConstant::visibility('name');
                 // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
                 $adminFieldVisible = FALSE;
                 if (CRM_Core_Permission::check('administer CiviCRM')) {
                     $adminFieldVisible = TRUE;
                 }
                 foreach ($priceSetFields as $fid => $fieldValues) {
                     if (!is_array($fieldValues['options']) || empty($fieldValues['options']) || CRM_Utils_Array::value('visibility_id', $fieldValues) != array_search('public', $visibility) && $adminFieldVisible == FALSE) {
                         continue;
                     }
                     if (count($fieldValues['options']) > 1) {
                         $values['feeBlock']['value'][$fieldCnt] = '';
                         $values['feeBlock']['label'][$fieldCnt] = $fieldValues['label'];
                         $values['feeBlock']['lClass'][$fieldCnt] = 'price_set_option_group-label';
                         $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
                         $fieldCnt++;
                         $labelClass = 'price_set_option-label';
                     } else {
                         $labelClass = 'price_set_field-label';
                     }
                     // show tax rate with amount
                     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
                     $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
                     $displayOpt = CRM_Utils_Array::value('tax_display_settings', $invoiceSettings);
                     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
                     foreach ($fieldValues['options'] as $optionId => $optionVal) {
                         $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
                         if ($invoicing && isset($optionVal['tax_amount'])) {
                             $values['feeBlock']['value'][$fieldCnt] = CRM_Price_BAO_PriceField::getTaxLabel($optionVal, 'amount', $displayOpt, $taxTerm);
                             $values['feeBlock']['tax_amount'][$fieldCnt] = $optionVal['tax_amount'];
                         } else {
                             $values['feeBlock']['value'][$fieldCnt] = $optionVal['amount'];
                         }
                         $values['feeBlock']['label'][$fieldCnt] = $optionVal['label'];
                         $values['feeBlock']['lClass'][$fieldCnt] = $labelClass;
                         $fieldCnt++;
                     }
                 }
             }
             // Tell tpl we have price set fee data and whether it's a quick_config price set
             $this->assign('isPriceSet', 1);
             $this->assign('isQuickConfig', $setDetails[$priceSetId]['is_quick_config']);
         }
     }
     $params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event');
     $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
     // fix phone type labels
     if (!empty($values['location']['phone'])) {
         $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
         foreach ($values['location']['phone'] as &$val) {
             if (!empty($val['phone_type_id'])) {
                 $val['phone_type_display'] = $phoneTypes[$val['phone_type_id']];
             }
         }
     }
     //retrieve custom field information
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_id, 0, $values['event']['event_type_id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
     $this->assign('action', CRM_Core_Action::VIEW);
     //To show the event location on maps directly on event info page
     $locations = CRM_Event_BAO_Event::getMapInfo($this->_id);
     if (!empty($locations) && !empty($values['event']['is_map'])) {
         $this->assign('locations', $locations);
         $this->assign('mapProvider', $config->mapProvider);
         $this->assign('mapKey', $config->mapAPIKey);
         $sumLat = $sumLng = 0;
         $maxLat = $maxLng = -400;
         $minLat = $minLng = 400;
         foreach ($locations as $location) {
             $sumLat += $location['lat'];
             $sumLng += $location['lng'];
             if ($location['lat'] > $maxLat) {
                 $maxLat = $location['lat'];
             }
             if ($location['lat'] < $minLat) {
                 $minLat = $location['lat'];
             }
             if ($location['lng'] > $maxLng) {
                 $maxLng = $location['lng'];
             }
             if ($location['lng'] < $minLng) {
                 $minLng = $location['lng'];
             }
         }
         $center = array('lat' => (double) $sumLat / count($locations), 'lng' => (double) $sumLng / count($locations));
         $span = array('lat' => (double) ($maxLat - $minLat), 'lng' => (double) ($maxLng - $minLng));
         $this->assign_by_ref('center', $center);
         $this->assign_by_ref('span', $span);
         if ($action == CRM_Core_Action::PREVIEW) {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1&action=preview", TRUE, NULL, TRUE, TRUE);
         } else {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1", TRUE, NULL, TRUE, TRUE);
         }
         $this->assign('skipLocationType', TRUE);
         $this->assign('mapURL', $mapURL);
     }
     if (CRM_Core_Permission::check('view event participants') && CRM_Core_Permission::check('view all contacts')) {
         $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1', 'label');
         $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0', 'label');
         $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
         $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
         $this->assign('findParticipants', $findParticipants);
     }
     $participantListingID = CRM_Utils_Array::value('participant_listing_id', $values['event']);
     if ($participantListingID) {
         $participantListingURL = CRM_Utils_System::url('civicrm/event/participant', "reset=1&id={$this->_id}", TRUE, NULL, TRUE, TRUE);
         $this->assign('participantListingURL', $participantListingURL);
     }
     $hasWaitingList = CRM_Utils_Array::value('has_waitlist', $values['event']);
     $eventFullMessage = CRM_Event_BAO_Participant::eventFull($this->_id, FALSE, $hasWaitingList);
     $allowRegistration = FALSE;
     if (!empty($values['event']['is_online_registration'])) {
         if (CRM_Event_BAO_Event::validRegistrationRequest($values['event'], $this->_id)) {
             // we always generate urls for the front end in joomla
             $action_query = $action === CRM_Core_Action::PREVIEW ? "&action={$action}" : '';
             $url = CRM_Utils_System::url('civicrm/event/register', "id={$this->_id}&reset=1{$action_query}", TRUE, NULL, TRUE, TRUE);
             if (!$eventFullMessage || $hasWaitingList) {
                 $registerText = ts('Register Now');
                 if (!empty($values['event']['registration_link_text'])) {
                     $registerText = $values['event']['registration_link_text'];
                 }
                 // check if we're in shopping cart mode for events
                 $enable_cart = Civi::settings()->get('enable_cart');
                 if ($enable_cart) {
                     $link = CRM_Event_Cart_BAO_EventInCart::get_registration_link($this->_id);
                     $registerText = $link['label'];
                     $url = CRM_Utils_System::url($link['path'], $link['query'] . $action_query, TRUE, NULL, TRUE, TRUE);
                 }
                 //Fixed for CRM-4855
                 $allowRegistration = CRM_Event_BAO_Event::showHideRegistrationLink($values);
                 $this->assign('registerText', $registerText);
                 $this->assign('registerURL', $url);
                 $this->assign('eventCartEnabled', $enable_cart);
             }
         } elseif (CRM_Core_Permission::check('register for events')) {
             $this->assign('registerClosed', TRUE);
         }
     }
     $this->assign('allowRegistration', $allowRegistration);
     $session = CRM_Core_Session::singleton();
     $params = array('contact_id' => $session->get('userID'), 'event_id' => CRM_Utils_Array::value('id', $values['event']), 'role_id' => CRM_Utils_Array::value('default_role_id', $values['event']));
     if ($eventFullMessage && $noFullMsg == 'false' || CRM_Event_BAO_Event::checkRegistration($params)) {
         $statusMessage = $eventFullMessage;
         if (CRM_Event_BAO_Event::checkRegistration($params)) {
             if ($noFullMsg == 'false') {
                 if ($values['event']['allow_same_participant_emails']) {
                     $statusMessage = ts('It looks like you are already registered for this event.  You may proceed if you want to create an additional registration.');
                 } else {
                     $registerUrl = CRM_Utils_System::url('civicrm/event/register', "reset=1&id={$values['event']['id']}&cid=0");
                     $statusMessage = ts("It looks like you are already registered for this event. If you want to change your registration, or you feel that you've gotten this message in error, please contact the site administrator.") . ' ' . ts('You can also <a href="%1">register another participant</a>.', array(1 => $registerUrl));
                 }
             }
         } elseif ($hasWaitingList) {
             $statusMessage = CRM_Utils_Array::value('waitlist_text', $values['event']);
             if (!$statusMessage) {
                 $statusMessage = ts('Event is currently full, but you can register and be a part of waiting list.');
             }
         }
         CRM_Core_Session::setStatus($statusMessage);
     }
     // we do not want to display recently viewed items, so turn off
     $this->assign('displayRecent', FALSE);
     // set page title = event title
     CRM_Utils_System::setTitle($values['event']['title']);
     $this->assign('event', $values['event']);
     if (isset($values['feeBlock'])) {
         $this->assign('feeBlock', $values['feeBlock']);
     }
     $this->assign('location', $values['location']);
     if (CRM_Core_Permission::check('access CiviEvent')) {
         $enableCart = Civi::settings()->get('enable_cart');
         $this->assign('manageEventLinks', CRM_Event_Page_ManageEvent::tabs($enableCart));
     }
     return parent::run();
 }
Example #9
0
 /**
  * Function to send subscribe mail
  * @params  array  $groups the list of group ids for subscribe
  * @params  array  $params the list of email
  * @params  int    $contactId  Currently used during event registration/contribution. 
  *                             Specifically to avoid linking group to wrong duplicate contact 
  *                             during event registration.
  * @public
  * @return void
  */
 function commonSubscribe(&$groups, &$params, $contactId = null)
 {
     $success = true;
     foreach ($groups as $groupID) {
         $se = self::subscribe($groupID, $params['email'], $contactId);
         if ($se !== null) {
             /* Ask the contact for confirmation */
             $se->send_confirm_request($params['email']);
         } else {
             $success = false;
         }
     }
     if ($success) {
         CRM_Utils_System::setUFMessage(ts("Your subscription request has been submitted. Check your inbox shortly for the confirmation email(s). If you do not see a confirmation email, please check your spam/junk mail folder."));
     } else {
         CRM_Utils_System::setUFMessage(ts("We had a problem processing your subscription request. You have tried to subscribe to a private group and/or we encountered a database error. Please contact the site administrator"));
     }
 }
Example #10
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 function buildQuickForm()
 {
     if ($this->_mode != CRM_PROFILE_FORM_MODE_REGISTER) {
         //check for mix profile (eg:  individual + other contact type)
         require_once "CRM/Core/BAO/UFField.php";
         if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
             CRM_Utils_System::setUFMessage(ts("This Profile includes fields for contact types other than 'Individuals' and can not be used to create/update contacts."));
             $config =& CRM_Core_Config::singleton();
             CRM_Utils_System::redirect($config->userFrameworkBaseURL);
         }
     }
     $this->assign('mode', $this->_mode);
     $this->assign('action', $this->_action);
     $this->assign('fields', $this->_fields);
     $this->assign('fieldset', $this->_fieldset);
     /*  if ($this->_mode & self::MODE_EDIT) {
             $group =& new CRM_Core_DAO_UFGroup();
             $group->id = $this->_gid;
             if ($group->find(true)) {
                 $this->assign('help_pre',  $group->help_pre);
                 $this->assign('help_post', $group->help_post);
             }
         }*/
     // do we need inactive options ?
     if ($this->_action & CRM_CORE_ACTION_VIEW) {
         $inactiveNeeded = true;
     } else {
         $inactiveNeeded = false;
     }
     // should we restrict what we display
     $admin = true;
     if ($this->_mode == CRM_PROFILE_FORM_MODE_EDIT) {
         $admin = false;
         $session =& CRM_Core_Session::singleton();
         // show all fields that are visibile: if we are a admin or the same user or in registration mode
         if (CRM_Utils_System::checkPermission('administer users') || $this->_id == $session->get('userID')) {
             $admin = true;
         }
     }
     require_once "CRM/Contribute/PseudoConstant.php";
     // add the form elements
     foreach ($this->_fields as $name => $field) {
         // make sure that there is enough permission to expose this field
         if (!$admin && $field['visibility'] == 'User and User Admin Only') {
             unset($this->_fields[$name]);
             continue;
         }
         // since the CMS manages the email field, suppress the email display if in
         // register mode which occur within the CMS form
         if ($this->_mode == CRM_PROFILE_FORM_MODE_REGISTER && substr($name, 0, 5) == 'email') {
             unset($this->_fields[$name]);
             continue;
         }
         $required = $this->_mode == CRM_PROFILE_FORM_MODE_SEARCH ? false : $field['is_required'];
         //if ( $field['name'] === 'state_province' ) {
         if (substr($field['name'], 0, 14) === 'state_province') {
             $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
         } else {
             if (substr($field['name'], 0, 7) === 'country') {
                 $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required);
             } else {
                 if ($field['name'] === 'birth_date') {
                     $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('birth'), $required);
                 } else {
                     if ($field['name'] === 'gender') {
                         $genderOptions = array();
                         $gender = CRM_Core_PseudoConstant::gender();
                         foreach ($gender as $key => $var) {
                             $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key);
                         }
                         $this->addGroup($genderOptions, $field['name'], $field['title']);
                         if ($required) {
                             $this->addRule($field['name'], ts('%1 is a required field.', array(1 => $field['title'])), 'required');
                         }
                     } else {
                         if ($field['name'] === 'individual_prefix') {
                             $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required);
                         } else {
                             if ($field['name'] === 'individual_suffix') {
                                 $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required);
                             } else {
                                 if ($field['name'] === 'preferred_communication_method') {
                                     $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_SelectValues::pcm());
                                 } else {
                                     if ($field['name'] === 'preferred_mail_format') {
                                         $this->add('select', $name, $field['title'], CRM_Core_SelectValues::pmf());
                                     } else {
                                         if (substr($field['name'], 0, 3) === 'is_' or substr($field['name'], 0, 7) === 'do_not_') {
                                             $this->add('checkbox', $name, $field['title'], $field['attributes'], $required);
                                         } else {
                                             if ($field['name'] === 'group') {
                                                 require_once 'CRM/Contact/Form/GroupTag.php';
                                                 CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_GROUP, true, $required, $field['title'], null);
                                             } else {
                                                 if ($field['name'] === 'tag') {
                                                     require_once 'CRM/Contact/Form/GroupTag.php';
                                                     CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_TAG, false, $required, null, $field['title']);
                                                 } else {
                                                     if (substr($field['name'], 0, 6) === 'custom') {
                                                         $customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name']);
                                                         CRM_Core_BAO_CustomField::addQuickFormElement($this, $name, $customFieldID, $inactiveNeeded, $required, false, $field['title']);
                                                         CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, $this->_id, $this->_mode);
                                                     } else {
                                                         if (in_array($field['name'], array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) {
                                                             $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('manual', 3, 1), $required);
                                                             $this->addRule($field['name'], ts('Select a valid date.'), 'qfDate');
                                                         } else {
                                                             if ($field['name'] == 'payment_instrument') {
                                                                 $this->add('select', 'payment_instrument', ts('Paid By'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required);
                                                             } else {
                                                                 if ($field['name'] == 'contribution_type') {
                                                                     $this->add('select', 'contribution_type', ts('Contribution Type'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::contributionType(), $required);
                                                                 } else {
                                                                     $this->add('text', $name, $field['title'], $field['attributes'], $required);
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (in_array($field['name'], array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
             $this->addRule($field['name'], ts('Please enter a valid amount.'), 'money');
         }
         if ($field['rule']) {
             if ($field['rule'] == 'email' && $this->_mode == CRM_PROFILE_FORM_MODE_SEARCH) {
                 continue;
             } else {
                 $this->addRule($name, ts('Please enter a valid %1', array(1 => $field['title'])), $field['rule']);
             }
         }
     }
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_CORE_ACTION_VIEW) {
         $this->freeze();
     }
     $this->setDefaults($defaults);
 }
Example #11
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     $status = $message = NULL;
     $cancelSubscription = TRUE;
     $params = $this->controller->exportValues($this->_name);
     if ($this->_selfService) {
         // for self service force sending-request & notify
         if ($this->_paymentProcessorObj->isSupported('cancelSubscription')) {
             $params['send_cancel_request'] = 1;
         }
         if ($this->_donorEmail) {
             $params['is_notify'] = 1;
         }
     }
     if (CRM_Utils_Array::value('send_cancel_request', $params) == 1) {
         $cancelParams = array('subscriptionId' => $this->_subscriptionDetails->subscription_id);
         $cancelSubscription = $this->_paymentProcessorObj->cancelSubscription($message, $cancelParams);
     }
     if (is_a($cancelSubscription, 'CRM_Core_Error')) {
         CRM_Core_Error::displaySessionError($cancelSubscription);
     } elseif ($cancelSubscription) {
         $activityParams = array('subject' => $this->_mid ? ts('Auto-renewal membership cancelled') : ts('Recurring contribution cancelled'), 'details' => $message);
         $cancelStatus = CRM_Contribute_BAO_ContributionRecur::cancelRecurContribution($this->_subscriptionDetails->recur_id, CRM_Core_DAO::$_nullObject, $activityParams);
         if ($cancelStatus) {
             $tplParams = array();
             if ($this->_mid) {
                 $inputParams = array('id' => $this->_mid);
                 CRM_Member_BAO_Membership::getValues($inputParams, $tplParams);
                 $tplParams = $tplParams[$this->_mid];
                 $tplParams['membership_status'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $tplParams['status_id']);
                 $tplParams['membershipType'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $tplParams['membership_type_id']);
                 $status = ts('The automatic renewal of your %1 membership has been cancelled as requested. This does not affect the status of your membership - you will receive a separate notification when your membership is up for renewal.', array(1 => $tplParams['membershipType']));
                 $msgTitle = 'Membership Renewal Cancelled';
                 $msgType = 'info';
             } else {
                 $tplParams['recur_frequency_interval'] = $this->_subscriptionDetails->frequency_interval;
                 $tplParams['recur_frequency_unit'] = $this->_subscriptionDetails->frequency_unit;
                 $tplParams['amount'] = $this->_subscriptionDetails->amount;
                 $tplParams['contact'] = array('display_name' => $this->_donorDisplayName);
                 $status = ts('The recurring contribution of %1, every %2 %3 has been cancelled.', array(1 => $this->_subscriptionDetails->amount, 2 => $this->_subscriptionDetails->frequency_interval, 3 => $this->_subscriptionDetails->frequency_unit));
                 $msgTitle = 'Contribution Cancelled';
                 $msgType = 'success';
             }
             if (CRM_Utils_Array::value('is_notify', $params) == 1) {
                 if ($this->_subscriptionDetails->contribution_page_id) {
                     CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $this->_subscriptionDetails->contribution_page_id, $value, array('title', 'receipt_from_name', 'receipt_from_email'));
                     $receiptFrom = '"' . CRM_Utils_Array::value('receipt_from_name', $value[$this->_subscriptionDetails->contribution_page_id]) . '" <' . $value[$this->_subscriptionDetails->contribution_page_id]['receipt_from_email'] . '>';
                 } else {
                     $domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
                     $receiptFrom = "{$domainValues['0']} <{$domainValues['1']}>";
                 }
                 // send notification
                 $sendTemplateParams = array('groupName' => $this->_mode == 'auto_renew' ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution', 'valueName' => $this->_mode == 'auto_renew' ? 'membership_autorenew_cancelled' : 'contribution_recurring_cancelled', 'contactId' => $this->_subscriptionDetails->contact_id, 'tplParams' => $tplParams, 'PDFFilename' => 'receipt.pdf', 'from' => $receiptFrom, 'toName' => $this->_donorDisplayName, 'toEmail' => $this->_donorEmail);
                 list($sent) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
             }
         } else {
             $msgType = 'error';
             $msgTitle = ts('Error');
             if ($params['send_cancel_request'] == 1) {
                 $status = ts('Recurring contribution was cancelled successfully by the processor, but could not be marked as cancelled in the database.');
             } else {
                 $status = ts('Recurring contribution could not be cancelled in the database.');
             }
         }
     } else {
         $status = ts('The recurring contribution could not be cancelled.');
         $msgTitle = 'Error Cancelling Contribution';
         $msgType = 'error';
     }
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     if ($userID && $status) {
         $session->setStatus($status, $msgTitle, $msgType);
     } elseif (!$userID) {
         if ($status) {
             CRM_Utils_System::setUFMessage($status);
         }
         // keep result as 1, since we not displaying anything on the redirected page anyway
         return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/subscriptionstatus', "reset=1&task=cancel&result=1"));
     }
 }
 /**
  * Transforms a single line from a conversion file to an sql statement, based on the details in its definition array
  */
 private function processLine($specs, $line)
 {
     $values = explode(',', $line);
     $sqlcolnames = '';
     $sqlcolvalues = '';
     for ($i = 0; $i < count($values); $i++) {
         try {
             $sqlcol = '';
             $colval = $this->decodeValue($values[$i]);
             $colname = $specs['COLS'][$i]['NAME'];
             $coltype = $specs['COLS'][$i]['TYPE'];
             $colsize = $specs['COLS'][$i]['SIZE'];
             switch ($coltype) {
                 case 'varchar':
                     if (isset($colsize)) {
                         $colval = substr($colval, 0, $colsize);
                     }
                     break;
                 case 'text':
                     // ignore $colsize;
                 // ignore $colsize;
                 case 'date':
                     // ignore $colsize; date is already formatted 'yyyy-mm-dd'
                     break;
                 case 'int':
                     // ignore $colsize
                     // ?: $colval = intval($colval);
                     // min/max
                     break;
                 case 'double':
                     // ignore $colsize
                     // ?: rounding to decimals
                     // min/max
                     break;
                 default:
                     // do not add field to sql statement
                     // report undefined data type
                     $colval = NULL;
             }
             if (isset($colval)) {
                 if (strlen($sqlcolnames) > 0) {
                     $sqlcolnames .= ', ';
                     $sqlcolvalues .= ', ';
                 }
                 if (strpos($colval, '\\') > -1) {
                     //CRM_Core_Error::Debug('VALUE ALERT', $colval);
                     //CRM_Core_Error::Debug('POS', strpos($colval, '\\'));
                     $colval = str_ireplace('\\', '\\\\', $colval);
                 }
                 if (strpos($colval, chr(39)) > -1) {
                     //CRM_Core_Error::Debug('VALUE ALERT', $colval);
                     //CRM_Core_Error::Debug('POS', strpos($colval, chr(39)));
                     $colval = str_ireplace(chr(39), '\\' . chr(39), $colval);
                 }
                 if (strpos($colval, chr(34)) > -1) {
                     //CRM_Core_Error::Debug('VALUE ALERT', $colval);
                     //CRM_Core_Error::Debug('POS', strpos($colval, chr(34)));
                     $colval = str_ireplace(chr(34), '\\' . chr(34), $colval);
                 }
                 $sqlcolnames .= '`' . $colname . '`';
                 $sqlcolvalues .= '\'' . $colval . '\'';
             }
         } catch (CiviCRM_API3_Exception $e) {
             $error = $e->getMessage();
             CRM_Utils_System::setUFMessage('API error: ' . $error . '(col=' . $i . ')');
         }
     }
     return 'INSERT INTO `' . $specs['TBL'] . '` (' . $sqlcolnames . ') VALUES (' . $sqlcolvalues . ')';
 }
Example #13
0
 /**
  * Form submission of new/edit contact is processed.
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     $queue_id = $this->get('queue_id');
     $job_id = $this->get('job_id');
     $hash = $this->get('hash');
     $formValues = $this->controller->exportValues($this->_name);
     $params = array();
     $params['body_text'] = $formValues['forward_comment'];
     $html_comment = $formValues['html_comment'];
     $params['body_html'] = str_replace('%7B', '{', str_replace('%7D', '}', $html_comment));
     $emails = array();
     for ($i = 0; $i < 5; $i++) {
         $email = $this->controller->exportValue($this->_name, "email_{$i}");
         if (!empty($email)) {
             $emails[] = $email;
         }
     }
     $forwarded = null;
     foreach ($emails as $email) {
         $result = crm_mailer_event_forward($job_id, $queue_id, $hash, $email, $this->_fromEmail, $params);
         if ($result) {
             $forwarded++;
         }
     }
     $status = ts('Mailing is not forwarded to the given email address.', array('count' => count($emails), 'plural' => 'Mailing is not forwarded to the given email addresses.'));
     if ($forwarded) {
         $status = ts('Mailing is forwarded successfully to %count email address.', array('count' => $forwarded, 'plural' => 'Mailing is forwarded successfully to %count email addresses.'));
     }
     require_once 'CRM/Utils/System.php';
     CRM_Utils_System::setUFMessage($status);
     // always redirect to front page of url
     $session =& CRM_Core_Session::singleton();
     $config =& CRM_Core_Config::singleton();
     $session->pushUserContext($config->userFrameworkBaseURL);
 }
Example #14
0
 /**
  * Form submission of new/edit contact is processed.
  */
 public function postProcess()
 {
     $queue_id = $this->get('queue_id');
     $job_id = $this->get('job_id');
     $hash = $this->get('hash');
     $timeStamp = date('YmdHis');
     $formValues = $this->controller->exportValues($this->_name);
     $params = array();
     $params['body_text'] = $formValues['forward_comment'];
     $html_comment = $formValues['html_comment'];
     $params['body_html'] = str_replace('%7B', '{', str_replace('%7D', '}', $html_comment));
     $emails = array();
     for ($i = 0; $i < 5; $i++) {
         $email = $this->controller->exportValue($this->_name, "email_{$i}");
         if (!empty($email)) {
             $emails[] = $email;
         }
     }
     $forwarded = NULL;
     foreach ($emails as $email) {
         $params = array('version' => 3, 'job_id' => $job_id, 'event_queue_id' => $queue_id, 'hash' => $hash, 'email' => $email, 'time_stamp' => $timeStamp, 'fromEmail' => $this->_fromEmail, 'params' => $params);
         $result = civicrm_api('Mailing', 'event_forward', $params);
         if (!civicrm_error($result)) {
             $forwarded++;
         }
     }
     $status = ts('Mailing is not forwarded to the given email address.', array('count' => count($emails), 'plural' => 'Mailing is not forwarded to the given email addresses.'));
     if ($forwarded) {
         $status = ts('Mailing is forwarded successfully to %count email address.', array('count' => $forwarded, 'plural' => 'Mailing is forwarded successfully to %count email addresses.'));
     }
     CRM_Utils_System::setUFMessage($status);
     // always redirect to front page of url
     $session = CRM_Core_Session::singleton();
     $config = CRM_Core_Config::singleton();
     $session->pushUserContext($config->userFrameworkBaseURL);
 }
Example #15
0
 /**
  * Process the form.
  *
  * @return void
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $status = NULL;
     // now set the values for the billing location.
     foreach ($this->_fields as $name => $value) {
         $fields[$name] = 1;
     }
     $fields["email-{$this->_bltID}"] = 1;
     $processorParams = array();
     foreach ($params as $key => $val) {
         $key = str_replace('billing_', '', $key);
         list($key) = explode('-', $key);
         $processorParams[$key] = $val;
     }
     $processorParams['state_province'] = CRM_Core_PseudoConstant::stateProvince($params["billing_state_province_id-{$this->_bltID}"], FALSE);
     $processorParams['country'] = CRM_Core_PseudoConstant::country($params["billing_country_id-{$this->_bltID}"], FALSE);
     $processorParams['month'] = $processorParams['credit_card_exp_date']['M'];
     $processorParams['year'] = $processorParams['credit_card_exp_date']['Y'];
     $processorParams['subscriptionId'] = $this->_subscriptionDetails->subscription_id;
     $processorParams['amount'] = $this->_subscriptionDetails->amount;
     $updateSubscription = $this->_paymentProcessorObj->updateSubscriptionBillingInfo($message, $processorParams);
     if (is_a($updateSubscription, 'CRM_Core_Error')) {
         CRM_Core_Error::displaySessionError($updateSubscription);
     } elseif ($updateSubscription) {
         $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_subscriptionDetails->contact_id, 'contact_type');
         $contact =& CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $this->_subscriptionDetails->contact_id, NULL, NULL, $ctype);
         // build tpl params
         if ($this->_subscriptionDetails->membership_id) {
             $inputParams = array('id' => $this->_subscriptionDetails->membership_id);
             CRM_Member_BAO_Membership::getValues($inputParams, $tplParams);
             $tplParams = $tplParams[$this->_subscriptionDetails->membership_id];
             $tplParams['membership_status'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $tplParams['status_id']);
             $tplParams['membershipType'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $tplParams['membership_type_id']);
             $status = ts('Billing details for your automatically renewed %1 membership have been updated.', array(1 => $tplParams['membershipType']));
             $msgTitle = ts('Details Updated');
             $msgType = 'success';
         } else {
             $status = ts('Billing details for the recurring contribution of %1, every %2 %3 have been updated.', array(1 => $this->_subscriptionDetails->amount, 2 => $this->_subscriptionDetails->frequency_interval, 3 => $this->_subscriptionDetails->frequency_unit));
             $msgTitle = ts('Details Updated');
             $msgType = 'success';
             $tplParams = array('recur_frequency_interval' => $this->_subscriptionDetails->frequency_interval, 'recur_frequency_unit' => $this->_subscriptionDetails->frequency_unit, 'amount' => $this->_subscriptionDetails->amount);
         }
         // format new address for display
         $addressParts = array("street_address", "city", "postal_code", "state_province", "country");
         foreach ($addressParts as $part) {
             $addressParts[$part] = CRM_Utils_Array::value($part, $processorParams);
         }
         $tplParams['address'] = CRM_Utils_Address::format($addressParts);
         // format old address to store in activity details
         $this->_defaults["state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvince($this->_defaults["state_province-{$this->_bltID}"], FALSE);
         $this->_defaults["country-{$this->_bltID}"] = CRM_Core_PseudoConstant::country($this->_defaults["country-{$this->_bltID}"], FALSE);
         $addressParts = array("street_address", "city", "postal_code", "state_province", "country");
         foreach ($addressParts as $part) {
             $key = "{$part}-{$this->_bltID}";
             $addressParts[$part] = CRM_Utils_Array::value($key, $this->_defaults);
         }
         $this->_defaults['address'] = CRM_Utils_Address::format($addressParts);
         // format new billing name
         $name = $processorParams['first_name'];
         if (!empty($processorParams['middle_name'])) {
             $name .= " {$processorParams['middle_name']}";
         }
         $name .= ' ' . $processorParams['last_name'];
         $name = trim($name);
         $tplParams['billingName'] = $name;
         // format old billing name
         $name = $this->_defaults['first_name'];
         if (!empty($this->_defaults['middle_name'])) {
             $name .= " {$this->_defaults['middle_name']}";
         }
         $name .= ' ' . $this->_defaults['last_name'];
         $name = trim($name);
         $this->_defaults['billingName'] = $name;
         $message .= "\n<br/><br/>New Billing Name and Address\n<br/>==============================\n<br/>{$tplParams['billingName']}\n<br/>{$tplParams['address']}\n\n<br/><br/>Previous Billing Name and Address\n<br/>==================================\n<br/>{$this->_defaults['billingName']}\n<br/>{$this->_defaults['address']}";
         $activityParams = array('source_contact_id' => $this->_subscriptionDetails->contact_id, 'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type', 'Update Recurring Contribution Billing Details', 'name'), 'subject' => ts('Recurring Contribution Billing Details Updated'), 'details' => $message, 'activity_date_time' => date('YmdHis'), 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name'));
         $session = CRM_Core_Session::singleton();
         $cid = $session->get('userID');
         if ($cid) {
             $activityParams['target_contact_id'][] = $activityParams['source_contact_id'];
             $activityParams['source_contact_id'] = $cid;
         }
         CRM_Activity_BAO_Activity::create($activityParams);
         // send notification
         if ($this->_subscriptionDetails->contribution_page_id) {
             CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $this->_subscriptionDetails->contribution_page_id, $value, array('title', 'receipt_from_name', 'receipt_from_email'));
             $receiptFrom = '"' . CRM_Utils_Array::value('receipt_from_name', $value[$this->_subscriptionDetails->contribution_page_id]) . '" <' . $value[$this->_subscriptionDetails->contribution_page_id]['receipt_from_email'] . '>';
         } else {
             $domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
             $receiptFrom = "{$domainValues['0']} <{$domainValues['1']}>";
         }
         list($donorDisplayName, $donorEmail) = CRM_Contact_BAO_Contact::getContactDetails($this->_subscriptionDetails->contact_id);
         $tplParams['contact'] = array('display_name' => $donorDisplayName);
         $date = CRM_Utils_Date::format($processorParams['credit_card_exp_date']);
         $tplParams['credit_card_exp_date'] = CRM_Utils_Date::mysqlToIso($date);
         $tplParams['credit_card_number'] = CRM_Utils_System::mungeCreditCard($processorParams['credit_card_number']);
         $tplParams['credit_card_type'] = $processorParams['credit_card_type'];
         $sendTemplateParams = array('groupName' => $this->_subscriptionDetails->membership_id ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution', 'valueName' => $this->_subscriptionDetails->membership_id ? 'membership_autorenew_billing' : 'contribution_recurring_billing', 'contactId' => $this->_subscriptionDetails->contact_id, 'tplParams' => $tplParams, 'isTest' => $this->_subscriptionDetails->is_test, 'PDFFilename' => 'receipt.pdf', 'from' => $receiptFrom, 'toName' => $donorDisplayName, 'toEmail' => $donorEmail);
         list($sent) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
     } else {
         $status = ts('There was some problem updating the billing details.');
         $msgTitle = ts('Update Error');
         $msgType = 'error';
     }
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     if ($userID && $status) {
         $session->setStatus($status, $msgTitle, $msgType);
     } elseif (!$userID) {
         if ($status) {
             CRM_Utils_System::setUFMessage($status);
         }
         $result = (int) ($updateSubscription && isset($ctype));
         if (isset($tplParams)) {
             $session->set('resultParams', $tplParams);
         }
         return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/subscriptionstatus', "reset=1&task=billing&result={$result}"));
     }
 }
Example #16
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;
 }
 /** 
  * Function to set variables up before form is built 
  *                                                           
  * @return void 
  * @access public 
  */
 function preProcess()
 {
     $config =& CRM_Core_Config::singleton();
     $session =& CRM_Core_Session::singleton();
     // make sure we have a valid payment class, else abort
     if (!$config->paymentClass) {
         CRM_Utils_System::setUFMessage(ts('%1 is not set in the config file.', array(1 => 'CIVICRM_CONTRIBUTE_PAYMENT_PROCESSOR')));
         CRM_Utils_System::redirect($config->userFrameworkBaseURL);
     }
     // current contribution page id
     $this->_id = CRM_Utils_Request::retrieve('id', $this);
     if (!$this->_id) {
         $pastContributionId = $session->get('pastContributionId');
         if (!$pastContributionId) {
             CRM_Core_Error::fatal(ts('We could not find contribution details for your request. Please try your request again.'));
         } else {
             CRM_Core_Error::fatal(ts('This contribution has already been submitted. Click <a href="%1">here</a> if you want to make another contribution.', array(1 => CRM_Utils_System::url('civicrm/contribute/transact', 'reset=1&id=' . $pastContributionId))));
         }
     } else {
         $session->set('pastContributionId', $this->_id);
     }
     // we do not want to display recently viewed items, so turn off
     $this->assign('displayRecent', false);
     // action
     $this->_action = CRM_Utils_Request::retrieve('action', $this, false, 'add');
     $this->assign('action', $this->_action);
     // current mode
     $this->_mode = $this->_action == 1024 ? 'test' : 'live';
     $this->_values = $this->get('values');
     $this->_fields = $this->get('fields');
     if (!$this->_values) {
         // get all the values from the dao object
         $params = array('id' => $this->_id);
         $this->_values = array();
         $this->_fields = array();
         CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values);
         // check if form is active
         if (!$this->_values['is_active']) {
             // form is inactive, bounce user back to front page of CMS
             CRM_Utils_System::setUFMessage(ts('The page you requested is currently unavailable.'));
             CRM_Utils_System::redirect($config->userFrameworkBaseURL);
         }
         // get the amounts and the label
         require_once 'CRM/Core/BAO/CustomOption.php';
         CRM_Core_BAO_CustomOption::getAssoc('civicrm_contribution_page', $this->_id, $this->_values);
         // get the profile ids
         require_once 'CRM/Core/BAO/UFJoin.php';
         $ufJoinParams = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id, 'weight' => 1);
         $this->_values['custom_pre_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams);
         $ufJoinParams['weight'] = 2;
         $this->_values['custom_post_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams);
         if ($config->paymentBillingMode & CRM_CONTRIBUTE_PAYMENT_BILLING_MODE_FORM) {
             $this->setCreditCardFields();
         }
         $this->set('values', $this->_values);
         $this->set('fields', $this->_fields);
     }
     $this->_contributeMode = $this->get('contributeMode');
     $this->assign('contributeMode', $this->_contributeMode);
     // assigning title to template in case someone wants to use it, also setting CMS page title
     $this->assign('title', $this->_values['title']);
     CRM_Utils_System::setTitle($this->_values['title']);
     $this->_defaults = array();
 }