示例#1
0
 /**
  * Get all PCP Statuses.
  *
  * The static array pcpStatus is returned
  *
  *
  * @param string $column
  * @return array
  *   array reference of all PCP activity statuses
  */
 public static function &pcpStatus($column = 'label')
 {
     if (NULL === self::$pcpStatus) {
         self::$pcpStatus = array();
     }
     if (!array_key_exists($column, self::$pcpStatus)) {
         self::$pcpStatus[$column] = array();
         self::$pcpStatus[$column] = CRM_Core_OptionGroup::values('pcp_status', FALSE, FALSE, FALSE, NULL, $column);
     }
     return self::$pcpStatus[$column];
 }
示例#2
0
文件: PCP.php 项目: kidaa30/yes
 /**
  * Return PCP  Block info for dashboard.
  *
  * @param int $contactId
  *
  * @return array
  *   array of Pcp if found
  */
 public static function getPcpDashboardInfo($contactId)
 {
     $links = self::pcpLinks();
     $query = "\nSELECT * FROM civicrm_pcp pcp\nWHERE pcp.is_active = 1\n  AND pcp.contact_id = %1\nORDER BY page_type, page_id";
     $params = array(1 => array($contactId, 'Integer'));
     $pcpInfoDao = CRM_Core_DAO::executeQuery($query, $params);
     $pcpInfo = array();
     $hide = $mask = array_sum(array_keys($links['all']));
     $contactPCPPages = array();
     $event = CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
     $contribute = CRM_Contribute_PseudoConstant::contributionPage();
     $pcpStatus = CRM_Contribute_PseudoConstant::pcpStatus();
     $approved = CRM_Utils_Array::key('Approved', $pcpStatus);
     while ($pcpInfoDao->fetch()) {
         $mask = $hide;
         if ($links) {
             $replace = array('pcpId' => $pcpInfoDao->id, 'pcpBlock' => $pcpInfoDao->pcp_block_id, 'pageComponent' => $pcpInfoDao->page_type);
         }
         $pcpLink = $links['all'];
         $class = '';
         if ($pcpInfoDao->status_id != $approved || $pcpInfoDao->is_active != 1) {
             $class = 'disabled';
             if (!$pcpInfoDao->tellfriend) {
                 $mask -= CRM_Core_Action::DETACH;
             }
         }
         if ($pcpInfoDao->is_active == 1) {
             $mask -= CRM_Core_Action::ENABLE;
         } else {
             $mask -= CRM_Core_Action::DISABLE;
         }
         $action = CRM_Core_Action::formLink($pcpLink, $mask, $replace, ts('more'), FALSE, 'pcp.dashboard.active', 'PCP', $pcpInfoDao->id);
         $component = $pcpInfoDao->page_type;
         $pageTitle = CRM_Utils_Array::value($pcpInfoDao->page_id, ${$component});
         $pcpInfo[] = array('pageTitle' => $pageTitle, 'pcpId' => $pcpInfoDao->id, 'pcpTitle' => $pcpInfoDao->title, 'pcpStatus' => $pcpStatus[$pcpInfoDao->status_id], 'action' => $action, 'class' => $class);
         $contactPCPPages[$pcpInfoDao->page_type][] = $pcpInfoDao->page_id;
     }
     $excludePageClause = $clause = NULL;
     if (!empty($contactPCPPages)) {
         foreach ($contactPCPPages as $component => $entityIds) {
             $excludePageClause[] = "\n( target_entity_type = '{$component}'\nAND target_entity_id NOT IN ( " . implode(',', $entityIds) . ") )";
         }
         $clause = ' AND ' . implode(' OR ', $excludePageClause);
     }
     $query = "\nSELECT *\nFROM civicrm_pcp_block block\nLEFT JOIN civicrm_pcp pcp ON pcp.pcp_block_id = block.id\nWHERE block.is_active = 1\n{$clause}\nGROUP BY block.id\nORDER BY target_entity_type, target_entity_id\n";
     $pcpBlockDao = CRM_Core_DAO::executeQuery($query);
     $pcpBlock = array();
     $mask = 0;
     while ($pcpBlockDao->fetch()) {
         if ($links) {
             $replace = array('pageId' => $pcpBlockDao->target_entity_id, 'pageComponent' => $pcpBlockDao->target_entity_type);
         }
         $pcpLink = $links['add'];
         $action = CRM_Core_Action::formLink($pcpLink, $mask, $replace, ts('more'), FALSE, 'pcp.dashboard.other', "{$pcpBlockDao->target_entity_type}_PCP", $pcpBlockDao->target_entity_id);
         $component = $pcpBlockDao->target_entity_type;
         if ($pageTitle = CRM_Utils_Array::value($pcpBlockDao->target_entity_id, ${$component})) {
             $pcpBlock[] = array('pageId' => $pcpBlockDao->target_entity_id, 'pageTitle' => $pageTitle, 'action' => $action);
         }
     }
     return array($pcpBlock, $pcpInfo);
 }
 /** 
  * Function to set variables up before form is built 
  *                                                           
  * @return void 
  * @access public 
  */
 public function preProcess()
 {
     $config = CRM_Core_Config::singleton();
     $session = CRM_Core_Session::singleton();
     // current contribution page id
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     if (!$this->_id) {
         $pastContributionID = $session->get('pastContributionID');
         if (!$pastContributionID) {
             CRM_Core_Error::fatal(ts('We can\'t load the requested web page due to an incomplete link. This can be caused by using your browser\'s Back button or by using an incomplete or invalid link.'));
         } 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);
     }
     $this->_userID = $session->get('userID');
     $this->_mid = null;
     if ($this->_userID) {
         $this->_mid = CRM_Utils_Request::retrieve('mid', 'Positive', $this);
         if ($this->_mid) {
             require_once 'CRM/Member/DAO/Membership.php';
             $membership = new CRM_Member_DAO_Membership();
             $membership->id = $this->_mid;
             if ($membership->find(true)) {
                 $this->_defaultMemTypeId = $membership->membership_type_id;
                 if ($membership->contact_id != $this->_userID) {
                     require_once 'CRM/Contact/BAO/Relationship.php';
                     $employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($this->_userID);
                     if (array_key_exists($membership->contact_id, $employers)) {
                         $this->_membershipContactID = $membership->contact_id;
                         $this->assign('membershipContactID', $this->_membershipContactID);
                         $this->assign('membershipContactName', $employers[$this->_membershipContactID]['name']);
                     } else {
                         CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."));
                     }
                 }
             } else {
                 CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."));
             }
             unset($membership);
         }
     }
     // we do not want to display recently viewed items, so turn off
     $this->assign('displayRecent', false);
     // Contribution page values are cleared from session, so can't use normal Printer Friendly view.
     // Use Browser Print instead.
     $this->assign('browserPrint', true);
     // action
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $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');
     $this->_bltID = $this->get('bltID');
     $this->_paymentProcessor = $this->get('paymentProcessor');
     $this->_priceSetId = $this->get('priceSetId');
     $this->_priceSet = $this->get('priceSet');
     if (!$this->_values) {
         // get all the values from the dao object
         $this->_values = array();
         $this->_fields = array();
         require_once 'CRM/Contribute/BAO/ContributionPage.php';
         CRM_Contribute_BAO_ContributionPage::setValues($this->_id, $this->_values);
         // check if form is active
         if (!$this->_values['is_active']) {
             // form is inactive, die a fatal death
             CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
         }
         // also check for billing informatin
         // get the billing location type
         $locationTypes =& CRM_Core_PseudoConstant::locationType();
         $this->_bltID = array_search('Billing', $locationTypes);
         if (!$this->_bltID) {
             CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
         }
         $this->set('bltID', $this->_bltID);
         // check for is_monetary status
         $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values);
         $isPayLater = CRM_Utils_Array::value('is_pay_later', $this->_values);
         if ($isMonetary && (!$isPayLater || CRM_Utils_Array::value('payment_processor_id', $this->_values))) {
             $ppID = CRM_Utils_Array::value('payment_processor_id', $this->_values);
             if (!$ppID) {
                 CRM_Core_Error::fatal(ts('A payment processor must be selected for this contribution page (contact the site administrator for assistance).'));
             }
             require_once 'CRM/Core/BAO/PaymentProcessor.php';
             $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode);
             // check selected payment processor is active
             if (empty($this->_paymentProcessor)) {
                 CRM_Core_Error::fatal(ts('A payment processor configured for this page might be disabled (contact the site administrator for assistance).'));
             }
             // ensure that processor has a valid config
             $this->_paymentObject =& CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
             $error = $this->_paymentObject->checkConfig();
             if (!empty($error)) {
                 CRM_Core_Error::fatal($error);
             }
             $this->_paymentProcessor['processorName'] = $this->_paymentObject->_processorName;
             $this->set('paymentProcessor', $this->_paymentProcessor);
         }
         // get price info
         // CRM-5095
         require_once 'CRM/Price/BAO/Set.php';
         CRM_Price_BAO_Set::initSet($this, $this->_id, 'civicrm_contribution_page');
         // this avoids getting E_NOTICE errors in php
         $setNullFields = array('amount_block_is_active', 'honor_block_is_active', 'is_allow_other_amount', 'footer_text');
         foreach ($setNullFields as $f) {
             if (!isset($this->_values[$f])) {
                 $this->_values[$f] = null;
             }
         }
         //check if Membership Block is enabled, if Membership Fields are included in profile
         //get membership section for this contribution page
         require_once 'CRM/Member/BAO/Membership.php';
         $this->_membershipBlock = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
         $this->set('membershipBlock', $this->_membershipBlock);
         require_once "CRM/Core/BAO/UFField.php";
         if ($this->_values['custom_pre_id']) {
             $preProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_pre_id']);
         }
         if ($this->_values['custom_post_id']) {
             $postProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_post_id']);
         }
         // also set cancel subscription url
         if (CRM_Utils_Array::value('is_recur', $this->_paymentProcessor) && CRM_Utils_Array::value('is_recur', $this->_values)) {
             $this->_values['cancelSubscriptionUrl'] = $this->_paymentObject->cancelSubscriptionURL();
         }
         if ((isset($postProfileType) && $postProfileType == 'Membership' || isset($preProfileType) && $preProfileType == 'Membership') && !$this->_membershipBlock['is_active']) {
             CRM_Core_Error::fatal(ts('This page includes a Profile with Membership fields - but the Membership Block is NOT enabled. Please notify the site administrator.'));
         }
         require_once 'CRM/Pledge/BAO/PledgeBlock.php';
         $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($this->_id);
         if ($pledgeBlock) {
             $this->_values['pledge_block_id'] = CRM_Utils_Array::value('id', $pledgeBlock);
             $this->_values['max_reminders'] = CRM_Utils_Array::value('max_reminders', $pledgeBlock);
             $this->_values['initial_reminder_day'] = CRM_Utils_Array::value('initial_reminder_day', $pledgeBlock);
             $this->_values['additional_reminder_day'] = CRM_Utils_Array::value('additional_reminder_day', $pledgeBlock);
             //set pledge id in values
             $pledgeId = CRM_Utils_Request::retrieve('pledgeId', 'Positive', $this);
             //authenticate pledge user for pledge payment.
             if ($pledgeId) {
                 $this->_values['pledge_id'] = $pledgeId;
                 self::authenticatePledgeUser();
             }
         }
         $this->set('values', $this->_values);
         $this->set('fields', $this->_fields);
     }
     require_once 'CRM/Contribute/BAO/PCP.php';
     $pcpId = CRM_Utils_Request::retrieve('pcpId', 'Positive', $this);
     if ($pcpId) {
         require_once 'CRM/Core/OptionGroup.php';
         $approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name');
         $prms = array('entity_id' => $this->_values['id'], 'entity_table' => 'civicrm_contribution_page');
         require_once 'CRM/Contribute/PseudoConstant.php';
         $pcpStatus = CRM_Contribute_PseudoConstant::pcpStatus();
         CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_PCPBlock', $prms, $pcpBlock);
         $prms = array('id' => $pcpId);
         CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_PCP', $prms, $pcpInfo);
         //start and end date of the contribution page
         $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('start_date', $this->_values));
         $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $this->_values));
         $now = time();
         if ($pcpInfo['contribution_page_id'] != $this->_values['id']) {
             $statusMessage = ts('This contribution page is not related to the Personal Campaign Page you have just visited. However you can still make a contribution here.');
             CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$this->_values['id']}", false, null, false, true));
         } else {
             if ($pcpInfo['status_id'] != $approvedId) {
                 $statusMessage = ts('The Personal Campaign Page you have just visited is currently %1. However you can still support the campaign by making a contribution here.', array(1 => $pcpStatus[$pcpInfo['status_id']]));
                 CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true));
             } else {
                 if (!CRM_Utils_Array::value('is_active', $pcpBlock)) {
                     $statusMessage = ts('Personal Campaign Pages are currently not enabled for this contribution page. However you can still support the campaign by making a contribution here.');
                     CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true));
                 } else {
                     if (!CRM_Utils_Array::value('is_active', $pcpInfo)) {
                         $statusMessage = ts('The Personal Campaign Page you have just visited is current inactive. However you can still make a contribution here.');
                         CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true));
                     } else {
                         if ($startDate && $startDate > $now || $endDate && $endDate < $now) {
                             $customStartDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $this->_values));
                             $customEndDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $this->_values));
                             if ($startDate && $endDate) {
                                 $statusMessage = ts('The Personal Campaign Page you have just visited is only active between %1 to %2. However you can still support the campaign by making a contribution here.', array(1 => $customStartDate, 2 => $customEndDate));
                                 CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true));
                             } else {
                                 if ($startDate) {
                                     $statusMessage = ts('The Personal Campaign Page you have just visited will be active beginning on %1. However you can still support the campaign by making a contribution here.', array(1 => $customStartDate));
                                     CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true));
                                 } else {
                                     if ($endDate) {
                                         $statusMessage = ts('The Personal Campaign Page you have just visited is not longer active (as of %1). However you can still support the campaign by making a contribution here.', array(1 => $customEndDate));
                                         CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true));
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $this->_pcpId = $pcpId;
         $this->_pcpBlock = $pcpBlock;
         $this->_pcpInfo = $pcpInfo;
     }
     // Link (button) for users to create their own Personal Campaign page
     if ($linkText = CRM_Contribute_BAO_PCP::getPcpBlockStatus($this->_id)) {
         $linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign', "action=add&reset=1&pageId={$this->_id}", false, null, true);
         $this->assign('linkTextUrl', $linkTextUrl);
         $this->assign('linkText', $linkText);
     }
     //set pledge block if block id is set
     if (CRM_Utils_Array::value('pledge_block_id', $this->_values)) {
         $this->assign('pledgeBlock', true);
     }
     // we do this outside of the above conditional to avoid
     // saving the country/state list in the session (which could be huge)
     if ($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM && CRM_Utils_Array::value('is_monetary', $this->_values)) {
         require_once 'CRM/Core/Payment/Form.php';
         require_once 'CRM/Core/Payment.php';
         // payment fields are depending on payment type
         if ($this->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) {
             CRM_Core_Payment_Form::setDirectDebitFields($this);
         } else {
             CRM_Core_Payment_Form::setCreditCardFields($this);
         }
     }
     $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor);
     // check if this is a paypal auto return and redirect accordingly
     if (CRM_Core_Payment::paypalRedirect($this->_paymentProcessor)) {
         $url = CRM_Utils_System::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey={$this->controller->_key}");
         CRM_Utils_System::redirect($url);
     }
     // make sure we have a valid payment class, else abort
     if (CRM_Utils_Array::value('is_monetary', $this->_values) && !$this->_paymentProcessor['class_name'] && !CRM_Utils_Array::value('is_pay_later', $this->_values)) {
         CRM_Core_Error::fatal(ts('Payment processor is not set for this page'));
     }
     // check if one of the (amount , membership)  bloks is active or not
     require_once 'CRM/Member/BAO/Membership.php';
     $this->_membershipBlock = $this->get('membershipBlock');
     if (!$this->_values['amount_block_is_active'] && !$this->_membershipBlock['is_active'] && !$this->_priceSetId) {
         CRM_Core_Error::fatal(ts('The requested online contribution page is missing a required Contribution Amount section or Membership section or Price Set. Please check with the site administrator for assistance.'));
     }
     if ($this->_values['amount_block_is_active']) {
         $this->set('amount_block_is_active', $this->_values['amount_block_is_active']);
     }
     if (!empty($this->_membershipBlock) && CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock) && !($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM)) {
         CRM_Core_Error::fatal(ts('This contribution page is configured to support separate contribution and membership payments. This %1 plugin does not currently support multiple simultaneous payments. Please contact the site administrator and notify them of this error', array(1 => $this->_paymentProcessor['payment_processor_type'])));
     }
     $this->_contributeMode = $this->get('contributeMode');
     $this->assign('contributeMode', $this->_contributeMode);
     //assigning is_monetary and is_email_receipt to template
     $this->assign('is_monetary', $this->_values['is_monetary']);
     $this->assign('is_email_receipt', $this->_values['is_email_receipt']);
     $this->assign('bltID', $this->_bltID);
     //assign cancelSubscription URL to templates
     $this->assign('cancelSubscriptionUrl', CRM_Utils_Array::value('cancelSubscriptionUrl', $this->_values));
     // assigning title to template in case someone wants to use it, also setting CMS page title
     if ($this->_pcpId) {
         $this->assign('title', $pcpInfo['title']);
         CRM_Utils_System::setTitle($pcpInfo['title']);
     } else {
         $this->assign('title', $this->_values['title']);
         CRM_Utils_System::setTitle($this->_values['title']);
     }
     $this->_defaults = array();
     $this->_amount = $this->get('amount');
     //CRM-6907
     $config = CRM_Core_Config::singleton();
     $config->defaultCurrency = CRM_Utils_Array::value('currency', $this->_values, $config->defaultCurrency);
 }
 /**
  * Get all the pcp status
  *
  * @access public
  * @return array - array reference of all pcp status
  * @static
  */
 public static function &pcpStatus()
 {
     self::$pcpStatus = array();
     if (!self::$pcpStatus) {
         self::$pcpStatus = CRM_Core_OptionGroup::values("pcp_status");
     }
     return self::$pcpStatus;
 }
示例#5
0
文件: PCP.php 项目: ksecor/civicrm
 /**
  * Function to send notfication email to supporter 
  * 1. when their PCP status is changed by site admin.
  * 2. when supporter initially creates a Personal Campaign Page ($isInitial set to true).
  * 
  * @param int $pcpId      campaign page id
  * @param int $newStatus  pcp status id
  * @param int $isInitial  is it the first time, campaign page has been created by the user
  *
  * @return null
  * @access public
  * @static
  *
  */
 static function sendStatusUpdate($pcpId, $newStatus, $isInitial = false)
 {
     require_once 'CRM/Contribute/PseudoConstant.php';
     $pcpStatus = CRM_Contribute_PseudoConstant::pcpStatus();
     $config =& CRM_Core_Config::singleton();
     if (!isset($pcpStatus[$newStatus])) {
         return false;
     }
     require_once 'CRM/Utils/Mail.php';
     require_once 'Mail/mime.php';
     require_once 'CRM/Contact/BAO/Contact/Location.php';
     //set loginUrl
     $loginUrl = $config->userFrameworkBaseURL;
     switch (ucfirst($config->userFramework)) {
         case 'Joomla':
             $loginUrl = str_replace('administrator/', '', $loginUrl);
             $loginUrl .= 'index.php?option=com_user&view=login';
             break;
         case 'Drupal':
             $loginUrl .= 'user';
             break;
     }
     // used in subject templates
     $contribPageTitle = self::getPcpContributionPageTitle($pcpId);
     $tplParams = array('loginUrl' => $loginUrl, 'contribPageTitle' => $contribPageTitle);
     //get the default domain email address.
     require_once 'CRM/Core/BAO/Domain.php';
     list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
     if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') {
         CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in Administer CiviCRM &raquo; Configure &raquo; Domain Information. The email address used may need to be a valid mail account with your email service provider.'));
     }
     $receiptFrom = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>';
     // get recipient (supporter) name and email
     $params = array('id' => $pcpId);
     CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_PCP', $params, $pcpInfo);
     list($name, $address) = CRM_Contact_BAO_Contact_Location::getEmailDetails($pcpInfo['contact_id']);
     // get pcp block info
     list($blockId, $eid) = self::getPcpBlockEntityId($pcpId);
     $params = array('id' => $blockId);
     CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_PCPBlock', $params, $pcpBlockInfo);
     // assign urls required in email template
     if ($pcpStatus[$newStatus] == 'Approved') {
         $tplParams['isTellFriendEnabled'] = $pcpBlockInfo['is_tellfriend_enabled'];
         if ($pcpBlockInfo['is_tellfriend_enabled']) {
             $pcpTellFriendURL = CRM_Utils_System::url('civicrm/friend', "reset=1&eid={$eid}&blockId={$blockId}&page=pcp", true, null, false);
             $tplParams['pcpTellFriendURL'] = $pcpTellFriendURL;
         }
     }
     $pcpInfoURL = CRM_Utils_System::url('civicrm/contribute/pcp/info', "reset=1&id={$pcpId}", true, null, false);
     $tplParams['pcpInfoURL'] = $pcpInfoURL;
     $tplParams['contribPageTitle'] = $contribPageTitle;
     if ($emails = CRM_Utils_Array::value('notify_email', $pcpBlockInfo)) {
         $emailArray = explode(',', $emails);
         $tplParams['pcpNotifyEmailAddress'] = $emailArray[0];
     }
     // get appropriate message based on status
     $tplParams['pcpStatus'] = $pcpStatus[$newStatus];
     $tplName = $isInitial ? 'pcp_supporter_notify' : 'pcp_status_change';
     require_once 'CRM/Core/BAO/MessageTemplates.php';
     list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => $tplName, 'contactId' => $pcpInfo['contact_id'], 'tplParams' => $tplParams, 'from' => $receiptFrom, 'toName' => $name, 'toEmail' => $address));
     return $sent;
 }
示例#6
0
 /**
  * Get all the pcp status
  *
  * @access public
  * @return array - array reference of all pcp status
  * @static
  */
 public static function &pcpStatus()
 {
     self::$pcpStatus = array();
     if (!self::$pcpStatus) {
         require_once "CRM/Core/OptionGroup.php";
         self::$pcpStatus = CRM_Core_OptionGroup::values("pcp_status");
     }
     return self::$pcpStatus;
 }
示例#7
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
  * @access public
  *
  */
 function run()
 {
     $session =& CRM_Core_Session::singleton();
     $config =& CRM_Core_Config::singleton();
     $permissionCheck = false;
     $statusMessage = '';
     if ($config->userFramework != 'Joomla') {
         $permissionCheck = CRM_Core_Permission::check('administer CiviCRM');
     }
     //get the pcp id.
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, true);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, false);
     $prms = array('id' => $this->_id);
     CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_PCP', $prms, $pcpInfo);
     if (empty($pcpInfo)) {
         $statusMessage = ts('The personal campaign page you requested is currently unavailable.');
         CRM_Core_Error::statusBounce($statusMessage, $config->userFrameworkBaseURL);
     }
     CRM_Utils_System::setTitle($pcpInfo['title']);
     $this->assign('pcp', $pcpInfo);
     require_once 'CRM/Contribute/PseudoConstant.php';
     require_once 'CRM/Core/OptionGroup.php';
     $pcpStatus = CRM_Contribute_PseudoConstant::pcpStatus();
     $approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name');
     // check if PCP is created by anonymous user
     $anonymousPCP = CRM_Utils_Request::retrieve('ap', 'Boolean', $this);
     if ($anonymousPCP) {
         $loginUrl = $config->userFrameworkBaseURL;
         switch (ucfirst($config->userFramework)) {
             case 'Joomla':
                 $loginUrl = str_replace('administrator/', '', $loginUrl);
                 $loginUrl .= 'index.php?option=com_user&view=login';
                 break;
             case 'Drupal':
                 $loginUrl .= 'user';
                 break;
         }
         $anonMessage = ts('Once you\'ve received your new account welcome email, you can <a href=%1>click here</a> to login and promote your campaign page.', array(1 => $loginUrl));
         CRM_Core_Session::setStatus($anonMessage);
     } else {
         $statusMessage = ts('The personal campaign page you requested is currently unavailable. However you can still support the campaign by making a contribution here.');
     }
     if (!$pcpInfo['is_active']) {
         // form is inactive, forward to main contribution page
         CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true));
     } else {
         if ($pcpInfo['status_id'] != $approvedId && !$permissionCheck) {
             if ($pcpInfo['contact_id'] != $session->get('userID')) {
                 // PCP not approved. Forward everyone except admin and owner to main contribution page
                 CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true));
             }
         } else {
             $getStatus = CRM_Contribute_BAO_PCP::getStatus($this->_id);
             if (!$getStatus) {
                 // PCP not enabled for this contribution page. Forward everyone to main contribution page
                 CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true));
             }
         }
     }
     $default = array();
     CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pcpInfo['contribution_page_id'], $default, array('start_date', 'end_date'));
     require_once "CRM/Contribute/PseudoConstant.php";
     $this->assign('pageName', CRM_Contribute_PseudoConstant::contributionPage($pcpInfo['contribution_page_id'], true));
     if ($pcpInfo['contact_id'] == $session->get('userID')) {
         $owner = $default[$pcpInfo['contribution_page_id']];
         $owner['status'] = CRM_Utils_Array::value($pcpInfo['status_id'], $pcpStatus);
         $this->assign('owner', $owner);
         require_once 'CRM/Contribute/BAO/PCP.php';
         $link = CRM_Contribute_BAO_PCP::pcpLinks();
         unset($link['all'][CRM_Core_Action::ENABLE]);
         $hints = array(CRM_Core_Action::UPDATE => ts('Change the content and appearance of your page'), CRM_Core_Action::DETACH => ts('Send emails inviting your friends to support your campaign!'), CRM_Core_Action::BROWSE => ts('Update your personal contact information'), CRM_Core_Action::DISABLE => ts('De-activate the page (you can re-activate it later)'), CRM_Core_Action::DELETE => ts('Remove the page (this cannot be undone!)'));
         CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_PCPBlock', $pcpInfo['contribution_page_id'], 'entity_id', $blockValues, array('is_tellfriend_enabled'));
         $blockId = array_pop($blockValues);
         $replace = array('id' => $this->_id, 'block' => $blockId['id']);
         if (!CRM_Utils_Array::value('is_tellfriend_enabled', $blockId) || CRM_Utils_Array::value('status_id', $pcpInfo) != $approvedId) {
             unset($link['all'][CRM_Core_Action::DETACH]);
         }
         $this->assign('links', $link['all']);
         $this->assign('hints', $hints);
         $this->assign('replace', $replace);
     }
     $honor = CRM_Contribute_BAO_PCP::honorRoll($this->_id);
     if ($file_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $this->_id, 'file_id', 'entity_id')) {
         $image = '<img src="' . CRM_Utils_System::url('civicrm/file', "reset=1&id={$file_id}&eid={$this->_id}") . '" />';
         $this->assign('image', $image);
     }
     $totalAmount = CRM_Contribute_BAO_PCP::thermoMeter($this->_id);
     $achieved = round($totalAmount / $pcpInfo['goal_amount'] * 100, 2);
     if ($linkText = CRM_Contribute_BAO_PCP::getPcpBlockStatus($pcpInfo['contribution_page_id'])) {
         $linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign', "action=add&reset=1&pageId={$pcpInfo['contribution_page_id']}", true, null, true, true);
         $this->assign('linkTextUrl', $linkTextUrl);
         $this->assign('linkText', $linkText);
     }
     $this->assign('honor', $honor);
     $this->assign('total', $totalAmount ? $totalAmount : '0.0');
     $this->assign('achieved', $achieved <= 100 ? $achieved : 100);
     if ($achieved <= 100) {
         $this->assign('remaining', 100 - $achieved);
     }
     // make sure that we are between  registration start date and registration end date
     $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('start_date', $owner));
     $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $owner));
     $now = time();
     $validDate = true;
     if ($startDate && $startDate >= $now) {
         $validDate = false;
     }
     if ($endDate && $endDate < $now) {
         $validDate = false;
     }
     $this->assign('validDate', true);
     if ($validDate) {
         $contributionText = ts('Contribute Now');
         if (CRM_Utils_Array::value('donate_link_text', $pcpInfo)) {
             $contributionText = $pcpInfo['donate_link_text'];
         }
         $this->assign('contributionText', $contributionText);
         // we always generate urls for the front end in joomla
         if ($action == CRM_Core_Action::PREVIEW) {
             $url = CRM_Utils_System::url('civicrm/contribute/transact', "id={$pcpInfo['contribution_page_id']}&pcpId={$this->_id}&reset=1&action=preview", true, null, true, true);
         } else {
             $url = CRM_Utils_System::url('civicrm/contribute/transact', "id={$pcpInfo['contribution_page_id']}&pcpId={$this->_id}&reset=1", true, null, true, true);
         }
         $this->assign('contributeURL', $url);
     }
     // we do not want to display recently viewed items, so turn off
     $this->assign('displayRecent', false);
     $single = $permission = false;
     switch ($action) {
         case CRM_Core_Action::BROWSE:
             $subForm = 'PCPAccount';
             $form = "CRM_Contribute_Form_PCP_{$subForm}";
             $single = true;
             break;
         case CRM_Core_Action::UPDATE:
             $subForm = 'Campaign';
             $form = "CRM_Contribute_Form_PCP_{$subForm}";
             $single = true;
             break;
     }
     $userID = $session->get('userID');
     //make sure the user has "administer CiviCRM" permission
     //OR has created the PCP
     if (CRM_Core_Permission::check('administer CiviCRM') || $userID && CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PCP', $this->_id, 'contact_id') == $userID) {
         $permission = true;
     }
     if ($single && $permission) {
         require_once 'CRM/Core/Controller/Simple.php';
         $controller =& new CRM_Core_Controller_Simple($form, $subForm, $action);
         $controller->set('id', $this->_id);
         $controller->set('single', true);
         $controller->process();
         return $controller->run();
     }
     $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1&id=' . $this->_id));
     parent::run();
 }