public function releaseRespondent() { require_once 'CRM/Core/PseudoConstant.php'; require_once 'CRM/Campaign/BAO/Survey.php'; $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $reserveStatusId = array_search('Scheduled', $activityStatus); $surveyActivityTypes = CRM_Campaign_BAO_Survey::getSurveyActivityType(); $surveyActivityTypesIds = array_keys($surveyActivityTypes); //retrieve all survey activities related to reserve action. $releasedCount = 0; if ($reserveStatusId && !empty($surveyActivityTypesIds)) { $query = ' SELECT activity.id as id, activity.activity_date_time as activity_date_time, survey.id as surveyId, survey.release_frequency as release_frequency FROM civicrm_activity activity INNER JOIN civicrm_survey survey ON ( survey.id = activity.source_record_id ) WHERE activity.is_deleted = 0 AND activity.status_id = %1 AND activity.activity_type_id IN ( ' . implode(', ', $surveyActivityTypesIds) . ' )'; $activity = CRM_Core_DAO::executeQuery($query, array(1 => array($reserveStatusId, 'Positive'))); $releasedIds = array(); while ($activity->fetch()) { if (!$activity->release_frequency) { continue; } $reservedSeconds = CRM_Utils_Date::unixTime($activity->activity_date_time); $releasedSeconds = $activity->release_frequency * 24 * 3600; $totalReservedSeconds = $reservedSeconds + $releasedSeconds; if ($totalReservedSeconds < time()) { $releasedIds[$activity->id] = $activity->id; } } //released respondent. if (!empty($releasedIds)) { $query = ' UPDATE civicrm_activity SET is_deleted = 1 WHERE id IN ( ' . implode(', ', $releasedIds) . ' )'; CRM_Core_DAO::executeQuery($query); $releasedCount = count($releasedIds); } } echo "<br /><br />Number of respondents released = {$releasedCount}"; }
static function validRegistrationDate(&$values, $contactID) { // make sure that we are between registration start date and registration end date $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_start_date', $values)); $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_end_date', $values)); $now = time(); $validDate = true; if ($startDate && $startDate >= $now) { $validDate = false; } if ($endDate && $endDate < $now) { $validDate = false; } // also check that the user has permission to register for this event $hasPermission = CRM_Core_Permission::event(CRM_Core_Permission::EDIT, $contactID); return $validDate && $hasPermission; }
/** * @param $values * * @return bool */ static function validRegistrationDate(&$values) { // make sure that we are between registration start date and registration end date $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_start_date', $values)); $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_end_date', $values)); $eventEnd = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $values)); $now = time(); $validDate = TRUE; if ($startDate && $startDate >= $now) { $validDate = FALSE; } if ($endDate && $endDate < $now) { $validDate = FALSE; } if ($eventEnd && $eventEnd < $now) { $validDate = FALSE; } return $validDate; }
public function updateParticipantStatus() { require_once 'CRM/Event/PseudoConstant.php'; $participantRole = CRM_Event_PseudoConstant::participantRole(); $pendingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'"); $expiredStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"); $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'"); //build the required status ids. $statusIds = '(' . implode(',', array_merge(array_keys($pendingStatuses), array_keys($waitingStatuses))) . ')'; $participantDetails = $fullEvents = array(); $expiredParticipantCount = $waitingConfirmCount = $waitingApprovalCount = 0; //get all participant who's status in class pending and waiting $query = "SELECT * FROM civicrm_participant WHERE status_id IN {$statusIds} ORDER BY register_date"; $query = "\n SELECT participant.id,\n participant.contact_id,\n participant.status_id,\n participant.register_date,\n participant.registered_by_id,\n participant.event_id,\n event.title as eventTitle,\n event.registration_start_date,\n event.registration_end_date,\n event.end_date,\n event.expiration_time,\n event.requires_approval\n FROM civicrm_participant participant\nLEFT JOIN civicrm_event event ON ( event.id = participant.event_id )\n WHERE participant.status_id IN {$statusIds}\n AND (event.end_date > now() OR event.end_date IS NULL)\n AND event.is_active = 1 \n ORDER BY participant.register_date, participant.id \n"; $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { $participantDetails[$dao->id] = array('id' => $dao->id, 'event_id' => $dao->event_id, 'status_id' => $dao->status_id, 'contact_id' => $dao->contact_id, 'register_date' => $dao->register_date, 'registered_by_id' => $dao->registered_by_id, 'eventTitle' => $dao->eventTitle, 'registration_start_date' => $dao->registration_start_date, 'registration_end_date' => $dao->registration_end_date, 'end_date' => $dao->end_date, 'expiration_time' => $dao->expiration_time, 'requires_approval' => $dao->requires_approval); } if (!empty($participantDetails)) { //cron 1. move participant from pending to expire if needed foreach ($participantDetails as $participantId => $values) { //process the additional participant at the time of //primary participant, don't process separately. if (CRM_Utils_Array::value('registered_by_id', $values)) { continue; } $expirationTime = CRM_Utils_Array::value('expiration_time', $values); if ($expirationTime && array_key_exists($values['status_id'], $pendingStatuses)) { //get the expiration and registration pending time. $expirationSeconds = $expirationTime * 3600; $registrationPendingSeconds = CRM_Utils_Date::unixTime($values['register_date']); // expired registration since registration cross allow confirmation time. if ($expirationSeconds + $registrationPendingSeconds < time()) { //lets get the transaction mechanism. require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); require_once 'CRM/Event/BAO/Participant.php'; $ids = array($participantId); $expiredId = array_search('Expired', $expiredStatuses); $results = CRM_Event_BAO_Participant::transitionParticipants($ids, $expiredId, $values['status_id'], TRUE, TRUE); $transaction->commit(); if (!empty($results)) { //diaplay updated participants if (is_array($results['updatedParticipantIds']) && !empty($results['updatedParticipantIds'])) { foreach ($results['updatedParticipantIds'] as $processedId) { $expiredParticipantCount += 1; echo "<br /><br />- status updated to: Expired"; //mailed participants. if (is_array($results['mailedParticipants']) && array_key_exists($processedId, $results['mailedParticipants'])) { echo "<br />Expiration Mail sent to: {$results['mailedParticipants'][$processedId]}"; } } } } } } } //cron 1 end. //cron 2. lets move participants from waiting list to pending status foreach ($participantDetails as $participantId => $values) { //process the additional participant at the time of //primary participant, don't process separately. if (CRM_Utils_Array::value('registered_by_id', $values)) { continue; } if (array_key_exists($values['status_id'], $waitingStatuses) && !array_key_exists($values['event_id'], $fullEvents)) { if ($waitingStatuses[$values['status_id']] == 'On waitlist' && CRM_Event_BAO_Event::validRegistrationDate($values)) { //check the target event having space. require_once 'CRM/Event/BAO/Participant.php'; $eventOpenSpaces = CRM_Event_BAO_Participant::eventFull($values['event_id'], TRUE, FALSE); if ($eventOpenSpaces && is_numeric($eventOpenSpaces) || $eventOpenSpaces === NULL) { //get the additional participant if any. $additionalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId); $allIds = array($participantId); if (!empty($additionalIds)) { $allIds = array_merge($allIds, $additionalIds); } $pClause = ' participant.id IN ( ' . implode(' , ', $allIds) . ' )'; $requiredSpaces = CRM_Event_BAO_Event::eventTotalSeats($values['event_id'], $pClause); //need to check as to see if event has enough speces if ($requiredSpaces <= $eventOpenSpaces || $eventOpenSpaces === NULL) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); require_once 'CRM/Event/BAO/Participant.php'; $ids = array($participantId); $updateStatusId = array_search('Pending from waitlist', $pendingStatuses); //lets take a call to make pending or need approval if ($values['requires_approval']) { $updateStatusId = array_search('Awaiting approval', $waitingStatuses); } $results = CRM_Event_BAO_Participant::transitionParticipants($ids, $updateStatusId, $values['status_id'], TRUE, TRUE); //commit the transaction. $transaction->commit(); if (!empty($results)) { //diaplay updated participants if (is_array($results['updatedParticipantIds']) && !empty($results['updatedParticipantIds'])) { foreach ($results['updatedParticipantIds'] as $processedId) { if ($values['requires_approval']) { $waitingApprovalCount += 1; echo "<br /><br />- status updated to: Awaiting approval"; echo "<br />Will send you Confirmation Mail when registration get approved."; } else { $waitingConfirmCount += 1; echo "<br /><br />- status updated to: Pending from waitlist"; if (is_array($results['mailedParticipants']) && array_key_exists($processedId, $results['mailedParticipants'])) { echo "<br />Confirmation Mail sent to: {$results['mailedParticipants'][$processedId]}"; } } } } } } else { //target event is full. $fullEvents[$values['event_id']] = $values['eventTitle']; } } else { //target event is full. $fullEvents[$values['event_id']] = $values['eventTitle']; } } } } //cron 2 ends. } echo "<br /><br />Number of Expired registration(s) = {$expiredParticipantCount}"; echo "<br />Number of registration(s) require approval = {$waitingApprovalCount}"; echo "<br />Number of registration changed to Pending from waitlist = {$waitingConfirmCount}<br /><br />"; if (!empty($fullEvents)) { foreach ($fullEvents as $eventId => $title) { echo "Full Event : {$title}<br />"; } } }
/** * Gets all campaign related data and returns it as a std class. * * @param int $contributionPageID * @param string $widgetID * * @return object */ public function getContributionPageData($contributionPageID, $widgetID) { $config = CRM_Core_Config::singleton(); self::registerRequest($contributionPageID, $widgetID, __FUNCTION__); $data = new stdClass(); if (empty($contributionPageID) || CRM_Utils_Type::validate($contributionPageID, 'Integer') == NULL) { $data->is_error = TRUE; CRM_Core_Error::debug_log_message("{$contributionPageID} is not set"); return $data; } $widget = new CRM_Contribute_DAO_Widget(); $widget->contribution_page_id = $contributionPageID; if (!$widget->find(TRUE)) { $data->is_error = TRUE; CRM_Core_Error::debug_log_message("{$contributionPageID} is not found"); return $data; } $data->is_error = FALSE; if (!$widget->is_active) { $data->is_active = FALSE; } $data->is_active = TRUE; $data->title = $widget->title; $data->logo = $widget->url_logo; $data->button_title = $widget->button_title; $data->button_url = CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$contributionPageID}", TRUE, NULL, FALSE, TRUE); $data->about = $widget->about; $query = "\nSELECT count( id ) as count,\n sum( total_amount) as amount\nFROM civicrm_contribution\nWHERE is_test = 0\nAND contribution_status_id = 1\nAND contribution_page_id = %1"; $params = array(1 => array($contributionPageID, 'Integer')); $dao = CRM_Core_DAO::executeQuery($query, $params); if ($dao->fetch()) { $data->num_donors = $dao->count; $data->money_raised = $dao->amount; } else { $data->num_donors = $data->money_raised = 0; } $query = "\nSELECT goal_amount, start_date, end_date, is_active\nFROM civicrm_contribution_page\nWHERE id = %1"; $params = array(1 => array($contributionPageID, 'Integer')); $dao = CRM_Core_DAO::executeQuery($query, $params); if ($dao->fetch()) { $data->money_target = $dao->goal_amount; $data->campaign_start = CRM_Utils_Date::customFormat($dao->start_date, $config->dateformatFull); $data->campaign_end = CRM_Utils_Date::customFormat($dao->end_date, $config->dateformatFull); // check for time being between start and end date $now = time(); if ($dao->start_date) { $startDate = CRM_Utils_Date::unixTime($dao->start_date); if ($startDate && $startDate >= $now) { $data->is_active = FALSE; } } if ($dao->end_date) { $endDate = CRM_Utils_Date::unixTime($dao->end_date); if ($endDate && $endDate < $now) { $data->is_active = FALSE; } } } else { $data->is_active = FALSE; } // if is_active is false, show this link and hide the contribute button $data->homepage_link = $widget->url_homepage; // movie clip colors, must be in '0xRRGGBB' format $data->colors = array(); $hexPrefix = '0x'; $data->colors["title"] = str_replace('#', $hexPrefix, $widget->color_title); $data->colors["button"] = str_replace('#', $hexPrefix, $widget->color_button); $data->colors["bar"] = str_replace('#', $hexPrefix, $widget->color_bar); $data->colors["main_text"] = str_replace('#', $hexPrefix, $widget->color_main_text); $data->colors["main"] = str_replace('#', $hexPrefix, $widget->color_main); $data->colors["main_bg"] = str_replace('#', $hexPrefix, $widget->color_main_bg); $data->colors["bg"] = str_replace('#', $hexPrefix, $widget->color_bg); // these two have colors as normal hex format // because they're being used in a CSS object $data->colors["about_link"] = str_replace('#', $hexPrefix, $widget->color_about_link); $data->colors["homepage_link"] = str_replace('#', $hexPrefix, $widget->color_homepage_link); return $data; }
/** * 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(); }
/** * @param array $params * * @return array */ public static function voterClause($params) { $voterClause = array(); $fromClause = $whereClause = NULL; if (!is_array($params) || empty($params)) { return $voterClause; } $surveyId = CRM_Utils_Array::value('campaign_survey_id', $params); $searchVoterFor = CRM_Utils_Array::value('campaign_search_voter_for', $params); //get the survey activities. $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $status = array('Scheduled'); if ($searchVoterFor == 'reserve') { $status[] = 'Completed'; } $completedStatusId = NULL; foreach ($status as $name) { if ($statusId = array_search($name, $activityStatus)) { $statusIds[] = $statusId; if ($name == 'Completed') { $completedStatusId = $statusId; } } } $voterActValues = CRM_Campaign_BAO_Survey::getSurveyVoterInfo($surveyId, NULL, $statusIds); if (!empty($voterActValues)) { $operator = 'IN'; $voterIds = array_keys($voterActValues); if ($searchVoterFor == 'reserve') { $operator = 'NOT IN'; //filter out recontact survey contacts. $recontactInterval = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $surveyId, 'recontact_interval'); $recontactInterval = unserialize($recontactInterval); if ($surveyId && is_array($recontactInterval) && !empty($recontactInterval)) { $voterIds = array(); foreach ($voterActValues as $values) { $numOfDays = CRM_Utils_Array::value($values['result'], $recontactInterval); if ($numOfDays && $values['status_id'] == $completedStatusId) { $recontactIntSeconds = $numOfDays * 24 * 3600; $actDateTimeSeconds = CRM_Utils_Date::unixTime($values['activity_date_time']); $totalSeconds = $recontactIntSeconds + $actDateTimeSeconds; //don't consider completed survey activity //unless it fulfill recontact interval criteria. if ($totalSeconds <= time()) { continue; } } $voterIds[$values['voter_id']] = $values['voter_id']; } } } //lets dump these ids in tmp table and //use appropriate join depend on operator. if (!empty($voterIds)) { $voterIdCount = count($voterIds); //create temporary table to store voter ids. $tempTableName = CRM_Core_DAO::createTempTableName('civicrm_survey_respondent'); CRM_Core_DAO::executeQuery("DROP TEMPORARY TABLE IF EXISTS {$tempTableName}"); $query = "\n CREATE TEMPORARY TABLE {$tempTableName} (\n id int unsigned NOT NULL AUTO_INCREMENT,\n survey_contact_id int unsigned NOT NULL,\n PRIMARY KEY ( id )\n);\n"; CRM_Core_DAO::executeQuery($query); $batch = 100; $insertedCount = 0; do { $processIds = $voterIds; $insertIds = array_splice($processIds, $insertedCount, $batch); if (!empty($insertIds)) { $insertSQL = "INSERT IGNORE INTO {$tempTableName}( survey_contact_id )\n VALUES (" . implode('),(', $insertIds) . ');'; CRM_Core_DAO::executeQuery($insertSQL); } $insertedCount += $batch; } while ($insertedCount < $voterIdCount); if ($operator == 'IN') { $fromClause = " INNER JOIN {$tempTableName} ON ( {$tempTableName}.survey_contact_id = contact_a.id )"; } else { $fromClause = " LEFT JOIN {$tempTableName} ON ( {$tempTableName}.survey_contact_id = contact_a.id )"; $whereClause = "( {$tempTableName}.survey_contact_id IS NULL )"; } } } $voterClause = array('fromClause' => $fromClause, 'whereClause' => $whereClause); return $voterClause; }
/** * @param $values * * @return bool */ public static function validRegistrationDate(&$values) { // make sure that we are between registration start date and end dates // and that if the event has ended, registration is still specifically open $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_start_date', $values)); $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_end_date', $values)); $eventEnd = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $values)); $now = time(); $validDate = TRUE; if ($startDate && $startDate >= $now) { $validDate = FALSE; } elseif ($endDate && $endDate < $now) { $validDate = FALSE; } elseif ($eventEnd && $eventEnd < $now && !$endDate) { $validDate = FALSE; } return $validDate; }
/** * 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() { $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_PCP_DAO_PCP', $prms, $pcpInfo); $this->_component = $pcpInfo['page_type']; 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); $pcpStatus = CRM_Core_OptionGroup::values("pcp_status"); $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->userSystem->getLoginURL(); $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, ts('Success'), 'success'); } else { $statusMessage = ts('The personal campaign page you requested is currently unavailable. However you can still support the campaign by making a contribution here.'); } $pcpBlock = new CRM_PCP_DAO_PCPBlock(); $pcpBlock->entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($pcpInfo['page_type']); $pcpBlock->entity_id = $pcpInfo['page_id']; $pcpBlock->find(TRUE); // Redirect back to source page in case of error. if ($pcpInfo['page_type'] == 'contribute') { $urlBase = 'civicrm/contribute/transact'; } elseif ($pcpInfo['page_type'] == 'event') { $urlBase = 'civicrm/event/register'; } if ($pcpInfo['status_id'] != $approvedId || !$pcpInfo['is_active']) { if ($pcpInfo['contact_id'] != $session->get('userID') && !$permissionCheck) { CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url($urlBase, "reset=1&id=" . $pcpInfo['page_id'], FALSE, NULL, FALSE, TRUE)); } } else { $getStatus = CRM_PCP_BAO_PCP::getStatus($this->_id, $this->_component); if (!$getStatus) { // PCP not enabled for this contribution page. Forward everyone to source page CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url($urlBase, "reset=1&id=" . $pcpInfo['page_id'], FALSE, NULL, FALSE, TRUE)); } } $default = array(); if ($pcpBlock->target_entity_type == 'contribute') { $urlBase = 'civicrm/contribute/transact'; } elseif ($pcpBlock->target_entity_type == 'event') { $urlBase = 'civicrm/event/register'; } if ($pcpBlock->entity_table == 'civicrm_event') { $page_class = 'CRM_Event_DAO_Event'; $this->assign('pageName', CRM_Event_PseudoConstant::event($pcpInfo['page_id'])); CRM_Core_DAO::commonRetrieveAll($page_class, 'id', $pcpInfo['page_id'], $default, array('start_date', 'end_date', 'registration_start_date', 'registration_end_date')); } elseif ($pcpBlock->entity_table == 'civicrm_contribution_page') { $page_class = 'CRM_Contribute_DAO_ContributionPage'; $this->assign('pageName', CRM_Contribute_PseudoConstant::contributionPage($pcpInfo['page_id'], TRUE)); CRM_Core_DAO::commonRetrieveAll($page_class, 'id', $pcpInfo['page_id'], $default, array('start_date', 'end_date')); } $pageInfo = $default[$pcpInfo['page_id']]; if ($pcpInfo['contact_id'] == $session->get('userID')) { $owner = $pageInfo; $owner['status'] = CRM_Utils_Array::value($pcpInfo['status_id'], $pcpStatus); $this->assign('owner', $owner); $link = CRM_PCP_BAO_PCP::pcpLinks(); $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::VIEW => ts('Copy this link to share directly with your network!'), 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::ENABLE => ts('Activate the page (you can de-activate it later)'), CRM_Core_Action::DELETE => ts('Remove the page (this cannot be undone!)')); $replace = array('id' => $this->_id, 'block' => $pcpBlock->id, 'pageComponent' => $this->_component); if (!$pcpBlock->is_tellfriend_enabled || CRM_Utils_Array::value('status_id', $pcpInfo) != $approvedId) { unset($link['all'][CRM_Core_Action::DETACH]); } switch ($pcpInfo['is_active']) { case 1: unset($link['all'][CRM_Core_Action::ENABLE]); break; case 0: unset($link['all'][CRM_Core_Action::DISABLE]); break; } $this->assign('links', $link['all']); $this->assign('hints', $hints); $this->assign('replace', $replace); } $honor = CRM_PCP_BAO_PCP::honorRoll($this->_id); $entityFile = CRM_Core_BAO_File::getEntityFile('civicrm_pcp', $this->_id); if (!empty($entityFile)) { $fileInfo = reset($entityFile); $fileId = $fileInfo['fileID']; $image = '<img src="' . CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$this->_id}") . '" />'; $this->assign('image', $image); } $totalAmount = CRM_PCP_BAO_PCP::thermoMeter($this->_id); $achieved = round($totalAmount / $pcpInfo['goal_amount'] * 100, 2); if ($pcpBlock->is_active == 1) { $linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign', "action=add&reset=1&pageId={$pcpInfo['page_id']}&component={$pcpInfo['page_type']}", TRUE, NULL, TRUE, TRUE); $this->assign('linkTextUrl', $linkTextUrl); $this->assign('linkText', $pcpBlock->link_text); } $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 contribution page start and end dates OR registration start date and end dates if they are set if ($pcpBlock->entity_table == 'civicrm_event') { $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_start_date', $pageInfo)); $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_end_date', $pageInfo)); } else { $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('start_date', $pageInfo)); $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $pageInfo)); } $now = time(); $validDate = TRUE; if ($startDate && $startDate >= $now) { $validDate = FALSE; } if ($endDate && $endDate < $now) { $validDate = FALSE; } $this->assign('validDate', $validDate); // form parent page url if ($action == CRM_Core_Action::PREVIEW) { $parentUrl = CRM_Utils_System::url($urlBase, "id={$pcpInfo['page_id']}&reset=1&action=preview", TRUE, NULL, TRUE, TRUE); } else { $parentUrl = CRM_Utils_System::url($urlBase, "id={$pcpInfo['page_id']}&reset=1", TRUE, NULL, TRUE, TRUE); } $this->assign('parentURL', $parentUrl); if ($validDate) { $contributionText = ts('Contribute Now'); if (!empty($pcpInfo['donate_link_text'])) { $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($urlBase, "id=" . $pcpBlock->target_entity_id . "&pcpId={$this->_id}&reset=1&action=preview", TRUE, NULL, TRUE, TRUE); } else { $url = CRM_Utils_System::url($urlBase, "id=" . $pcpBlock->target_entity_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_PCP_Form_{$subForm}"; $single = TRUE; break; case CRM_Core_Action::UPDATE: $subForm = 'Campaign'; $form = "CRM_PCP_Form_{$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_PCP_DAO_PCP', $this->_id, 'contact_id') == $userID) { $permission = TRUE; } if ($single && $permission) { $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(); }
function voterClause($params) { $voterClause = null; if (!is_array($params) || empty($params)) { return $voterClause; } $surveyId = CRM_Utils_Array::value('campaign_survey_id', $params); $interviewerId = CRM_Utils_Array::value('survey_interviewer_id', $params); $searchVoterFor = CRM_Utils_Array::value('campaign_search_voter_for', $params); //get the survey activities. require_once 'CRM/Core/PseudoConstant.php'; $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $status = array('Scheduled'); if ($searchVoterFor == 'reserve') { $status[] = 'Completed'; } $completedStatusId = null; foreach ($status as $name) { if ($statusId = array_search($name, $activityStatus)) { $statusIds[] = $statusId; if ($name == 'Completed') { $completedStatusId = $statusId; } } } require_once 'CRM/Campaign/BAO/Survey.php'; $voterActValues = CRM_Campaign_BAO_Survey::getSurveyVoterInfo($surveyId, null, $statusIds); if (!empty($voterActValues)) { $operator = 'IN'; $voterIds = array_keys($voterActValues); if ($searchVoterFor == 'reserve') { $operator = 'NOT IN'; //filter out recontact survey contacts. $recontactInterval = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $surveyId, 'recontact_interval'); $recontactInterval = unserialize($recontactInterval); if ($surveyId && is_array($recontactInterval) && !empty($recontactInterval)) { $voterIds = array(); foreach ($voterActValues as $values) { $numOfDays = CRM_Utils_Array::value($values['result'], $recontactInterval); if ($numOfDays && $values['status_id'] == $completedStatusId) { $recontactIntSeconds = $numOfDays * 24 * 3600; $actDateTimeSeconds = CRM_Utils_Date::unixTime($values['activity_date_time']); $totalSeconds = $recontactIntSeconds + $actDateTimeSeconds; //don't consider completed survey activity //unless it fulfill recontact interval criteria. if ($totalSeconds <= time()) { continue; } } $voterIds[$values['voter_id']] = $values['voter_id']; } } } if (!empty($voterIds)) { $voterClause = "( contact_a.id {$operator} ( " . implode(', ', $voterIds) . ' ) )'; } } return $voterClause; }
/** * 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); }
/** * Function to set variables up before form is built * * @return void * @access public */ function preProcess() { $this->_eventId = CRM_Utils_Request::retrieve('id', 'Positive', $this, true); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false); //CRM-4320 $this->_participantId = CRM_Utils_Request::retrieve('participantId', 'Positive', $this); // 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'); //check if participant allow to walk registration wizard. $this->_allowConfirmation = $this->get('allowConfirmation'); // check for Approval $this->_requireApproval = $this->get('requireApproval'); // check for waitlisting. $this->_allowWaitlist = $this->get('allowWaitlist'); //get the additional participant ids. $this->_additionalParticipantIds = $this->get('additionalParticipantIds'); $config =& CRM_Core_Config::singleton(); if (!$this->_values) { // create redirect URL to send folks back to event info page is registration not available $infoUrl = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_eventId}", false, null, false, true); // this is the first time we are hitting this, so check for permissions here if (!CRM_Core_Permission::event(CRM_Core_Permission::EDIT, $this->_eventId)) { CRM_Core_Error::statusBounce(ts('You do not have permission to register for this event'), $infoUrl); } // get all the values from the dao object $this->_values = array(); $this->_fields = array(); // get the participant values, CRM-4320 $this->_allowConfirmation = false; if ($this->_participantId) { require_once 'CRM/Event/BAO/Event.php'; $ids = $participantValues = array(); $participantParams = array('id' => $this->_participantId); require_once 'CRM/Event/BAO/Participant.php'; CRM_Event_BAO_Participant::getValues($participantParams, $participantValues, $ids); $this->_values['participant'] = $participantValues[$this->_participantId]; //allow pending status class walk registration wizard. require_once 'CRM/Core/PseudoConstant.php'; if (array_key_exists($participantValues[$this->_participantId]['status_id'], CRM_Event_PseudoConstant::participantStatus(null, "class = 'Pending'"))) { $this->_allowConfirmation = true; $this->set('allowConfirmation', true); } } //retrieve event information require_once 'CRM/Event/BAO/Event.php'; $params = array('id' => $this->_eventId); CRM_Event_BAO_Event::retrieve($params, $this->_values['event']); require_once 'CRM/Event/BAO/Participant.php'; //check for additional participants. if ($this->_allowConfirmation && $this->_values['event']['is_multiple_registrations']) { $this->_additionalParticipantIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_participantId); $this->set('additionalParticipantIds', $this->_additionalParticipantIds); } $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId); $this->_allowWaitlist = false; if ($eventFull && !$this->_allowConfirmation) { //lets redirecting to info only when to waiting list. $this->_allowWaitlist = CRM_Utils_Array::value('has_waitlist', $this->_values['event']); if (!$this->_allowWaitlist) { CRM_Utils_System::redirect($infoUrl); } } $this->set('allowWaitlist', $this->_allowWaitlist); //check for require requires approval. $this->_requireApproval = false; if (CRM_Utils_Array::value('requires_approval', $this->_values['event']) && !$this->_allowConfirmation) { $this->_requireApproval = true; } $this->set('requireApproval', $this->_requireApproval); // also get the accounting code if (CRM_Utils_Array::value('contribution_type_id', $this->_values['event'])) { $this->_values['event']['accountingCode'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $this->_values['event']['contribution_type_id'], 'accounting_code'); } if (isset($this->_values['event']['default_role_id'])) { require_once 'CRM/Core/OptionGroup.php'; $participant_role = CRM_Core_OptionGroup::values('participant_role'); $this->_values['event']['participant_role'] = $participant_role["{$this->_values['event']['default_role_id']}"]; } // is the event active (enabled)? if (!$this->_values['event']['is_active']) { // form is inactive, die a fatal death CRM_Core_Error::statusBounce(ts('The event you requested is currently unavailable (contact the site administrator for assistance).')); } // is online registration is enabled? if (!$this->_values['event']['is_online_registration']) { CRM_Core_Error::statusBounce(ts('Online registration is not currently available for this event (contact the site administrator for assistance).'), $infoUrl); } // is this an event template ? if (CRM_Utils_Array::value('is_template', $this->_values['event'])) { CRM_Core_Error::statusBounce(ts('Event templates are not meant to be registered.'), $infoUrl); } $now = time(); $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_start_date', $this->_values['event'])); if ($startDate && $startDate >= $now) { CRM_Core_Error::statusBounce(ts('Registration for this event begins on %1', array(1 => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('registration_start_date', $this->_values['event'])))), $infoUrl); } $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_end_date', $this->_values['event'])); if ($endDate && $endDate < $now) { CRM_Core_Error::statusBounce(ts('Registration for this event ended on %1', array(1 => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('registration_end_date', $this->_values['event'])))), $infoUrl); } // check for is_monetary status $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values['event']); //retrieve custom information $eventID = $this->_eventId; $isPayLater = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'is_pay_later'); //check for variour combination for paylater, payment //process with paid event. if ($isMonetary && (!$isPayLater || CRM_Utils_Array::value('payment_processor_id', $this->_values['event']))) { $ppID = CRM_Utils_Array::value('payment_processor_id', $this->_values['event']); if (!$ppID) { CRM_Core_Error::statusBounce(ts('A payment processor must be selected for this event registration page, or the event must be configured to give users the option to pay later (contact the site administrator for assistance).'), $infoUrl); } require_once 'CRM/Core/BAO/PaymentProcessor.php'; $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); // make sure we have a valid payment class, else abort if ($this->_values['event']['is_monetary']) { if (!$this->_paymentProcessor) { CRM_Core_Error::fatal(ts('The site administrator must set a Payment Processor for this event in order to use online registration.')); } // ensure that processor has a valid config $payment =& CRM_Core_Payment::singleton($this->_mode, 'Event', $this->_paymentProcessor, $this); $error = $payment->checkConfig(); if (!empty($error)) { CRM_Core_Error::fatal($error); } } $this->_paymentProcessor['processorName'] = $payment->_processorName; $this->set('paymentProcessor', $this->_paymentProcessor); } // get price info $price = self::initPriceSet($this, $eventID); if ($price == false) { if (!isset($this->_values['fee'])) { $this->_values['fee'] = array(); } require_once 'CRM/Core/OptionGroup.php'; CRM_Core_OptionGroup::getAssoc("civicrm_event.amount.{$eventID}", $this->_values['fee'], true); //fix for non-upgraded price sets.CRM-4256. if ($isMonetary && empty($this->_values['fee'])) { CRM_Core_Error::fatal(ts('No Fee Level(s) or Price Set is configured for this event.<br />Click <a href=\'%1\'>CiviEvent >> Manage Event >> Configure >> Event Fees</a> to configure the Fee Level(s) or Price Set for this event.', array(1 => CRM_Utils_System::url('civicrm/event/manage', 'reset=1&action=update&subPage=Fee&id=' . $this->_eventId)))); } } // get the profile ids require_once 'CRM/Core/BAO/UFJoin.php'; $ufJoinParams = array('entity_table' => 'civicrm_event', 'module' => 'CiviEvent', 'entity_id' => $this->_eventId); list($this->_values['custom_pre_id'], $this->_values['custom_post_id']) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); // set profiles for additional participants if ($this->_values['event']['is_multiple_registrations']) { require_once 'CRM/Core/BAO/UFJoin.php'; $ufJoinParams = array('entity_table' => 'civicrm_event', 'module' => 'CiviEvent_Additional', 'entity_id' => $this->_eventId); list($this->_values['additional_custom_pre_id'], $this->_values['additional_custom_post_id'], $preActive, $postActive) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); // CRM-4377: we need to maintain backward compatibility, hence if there is profile for main contact // set same profile for additional contacts. if ($this->_values['custom_pre_id'] && !$this->_values['additional_custom_pre_id']) { $this->_values['additional_custom_pre_id'] = $this->_values['custom_pre_id']; } if ($this->_values['custom_post_id'] && !$this->_values['additional_custom_post_id']) { $this->_values['additional_custom_post_id'] = $this->_values['custom_post_id']; } // now check for no profile condition, in that case is_active = 0 if (isset($preActive) && !$preActive) { unset($this->_values['additional_custom_pre_id']); } if (isset($postActive) && !$postActive) { unset($this->_values['additional_custom_post_id']); } } $params = array('id' => $this->_eventId); // 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); if ($this->_values['event']['is_monetary'] && $this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) { require_once 'CRM/Core/Payment/Form.php'; CRM_Core_Payment_Form::setCreditCardFields($this); } $params = array('entity_id' => $this->_eventId, 'entity_table' => 'civicrm_event'); require_once 'CRM/Core/BAO/Location.php'; $this->_values['location'] = CRM_Core_BAO_Location::getValues($params, true); $this->set('values', $this->_values); $this->set('fields', $this->_fields); } $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/event/register', "_qf_ThankYou_display=1&qfKey={$this->controller->_key}"); CRM_Utils_System::redirect($url); } $this->_contributeMode = $this->get('contributeMode'); $this->assign('contributeMode', $this->_contributeMode); // setting CMS page title CRM_Utils_System::setTitle($this->_values['event']['title']); $this->assign('title', $this->_values['event']['title']); $this->assign('paidEvent', $this->_values['event']['is_monetary']); // we do not want to display recently viewed items on Registration pages $this->assign('displayRecent', false); // Registration page values are cleared from session, so can't use normal Printer Friendly view. // Use Browser Print instead. $this->assign('browserPrint', true); // assign all event properties so wizard templates can display event info. $this->assign('event', $this->_values['event']); $this->assign('location', $this->_values['location']); $this->assign('bltID', $this->_bltID); $isShowLocation = CRM_Utils_Array::value('is_show_location', $this->_values['event']); $this->assign('isShowLocation', $isShowLocation); }
static function &signoutDetails($startDate = null, $endDate = null, $isMorning = true, $includeDetails = false, $onlyNotSignedOut = false, $studentID = null, $limit = null) { $clauses = array(); if ($startDate && $endDate) { $clauses[] = "( DATE(s.signout_time) >= {$startDate} OR DATE(s.signin_time) >= {$startDate} ) AND\n ( DATE(s.signout_time) <= {$endDate} OR DATE(s.signin_time) <= {$endDate} ) "; } if (!$isMorning) { $clauses[] = "( is_morning = 0 OR is_morning IS NULL )"; } if ($onlyNotSignedOut) { $clauses[] = "( s.signout_time IS NULL )"; } if ($studentID) { $studentID = CRM_Utils_Type::escape($studentID, 'Integer'); $clauses[] = "c.id = {$studentID}"; } $clause = null; if ($clauses) { $clause = implode(' AND ', $clauses); } else { $clause = "( 1 )"; } $sql = "\nSELECT c.id, c.display_name,\n s.signout_time, s.signin_time,\n s.class, s.pickup_person_name,\n s.is_morning, s.at_school_meeting,\n v.extended_care_status , s.id as signout_id\nFROM civicrm_value_extended_care_signout s\nINNER JOIN civicrm_contact c ON c.id = s.entity_id\nINNER JOIN civicrm_value_school_information v ON c.id = v.entity_id\nWHERE {$clause}\nORDER BY c.sort_name, signin_time DESC\n"; if ($limit) { $sql .= " LIMIT 0, {$limit} "; } $dao = CRM_Core_DAO::executeQuery($sql); $freeClasses = array('Volleyball', 'Cross Country', 'Amnesty International', 'SMART', 'Yearbook', 'Basketball Team 3:30-5:00 p.m.', 'Middle School Basketball'); $freeStatus = array('SMART', 'Staff', 'Unlimited'); $summary = array(); while ($dao->fetch()) { $dao->class = trim($dao->class); $studentID = $dao->id; if (!array_key_exists($studentID, $summary)) { $summary[$studentID] = array('id' => $studentID, 'name' => $dao->display_name, 'blockCharge' => 0, 'doNotCharge' => null); if ($includeDetails) { $summary[$studentID]['details'] = array(); } } $blockCharge = 0; $blockMessage = null; if ($dao->is_morning) { if (self::chargeMorningBlock($dao->signin_time)) { $blockCharge = 0.5; } $blockMessage = 'Morning extended care'; $dao->signout_time = $dao->signin_time; } else { if ($dao->at_school_meeting) { $blockMessage = 'At School Meeting / Work - No Charge'; } else { if (in_array($dao->class, $freeClasses)) { $blockMessage = 'Free Class - No Charge'; } else { if ($dao->signout_time) { $blockCode = self::signoutBlock($dao->signout_time); switch ($blockCode) { case 1: break; case 2: $blockCharge = 1; break; case 3: $blockCharge = 1.5; break; case 4: default: $blockCharge = 2.0; break; } } else { // account for the case where the person is signed in but not signed out if ($dao->signin_time) { $blockCharge = 2.0; $dao->signout_time = $dao->signin_time; $blockMessage = 'Signed in but did not sign out'; } } } } } $summary[$studentID]['blockCharge'] += $blockCharge; if (in_array($dao->extended_care_status, $freeStatus)) { $summary[$studentID]['doNotCharge'] = $dao->extended_care_status; } if ($includeDetails) { $summary[$studentID]['details'][$dao->signout_id] = array('charge' => $blockCharge, 'message' => $blockMessage, 'class' => $dao->class, 'pickup' => $dao->pickup_person_name, 'signout' => strftime("%l:%M %p on %a, %b %d", CRM_Utils_Date::unixTime($dao->signout_time))); } } return $summary; }
/** * @param $event_in_cart_1 * @param $event_in_cart_2 * * @return int */ public static function compare_event_dates($event_in_cart_1, $event_in_cart_2) { $date_1 = CRM_Utils_Date::unixTime($event_in_cart_1->event->start_date); $date_2 = CRM_Utils_Date::unixTime($event_in_cart_2->event->start_date); if ($date_1 == $date_2) { return 0; } return $date_1 < $date_2 ? -1 : 1; }
/** * Send mail and create activity * when participant status changed. * * @param int $participantId * Participant id. * @param array $participantValues * Participant detail values. status id for participants. * @param array $eventDetails * Required event details. * @param array $contactDetails * Required contact details. * @param array $domainValues * Required domain values. * @param string $mailType * (eg 'approval', 'confirm', 'expired' ). * * @return bool */ public static function sendTransitionParticipantMail($participantId, $participantValues, $eventDetails, $contactDetails, &$domainValues, $mailType) { //send emails. $mailSent = FALSE; //don't send confirmation mail to additional //since only primary able to confirm registration. if (!empty($participantValues['registered_by_id']) && $mailType == 'Confirm') { return $mailSent; } $toEmail = CRM_Utils_Array::value('email', $contactDetails); if ($toEmail) { $contactId = $participantValues['contact_id']; $participantName = $contactDetails['display_name']; //calculate the checksum value. $checksumValue = NULL; if ($mailType == 'Confirm' && !$participantValues['registered_by_id']) { $checksumLife = 'inf'; $endDate = CRM_Utils_Array::value('end_date', $eventDetails); if ($endDate) { $checksumLife = (CRM_Utils_Date::unixTime($endDate) - time()) / (60 * 60); } $checksumValue = CRM_Contact_BAO_Contact_Utils::generateChecksum($contactId, NULL, $checksumLife); } //take a receipt from as event else domain. $receiptFrom = $domainValues['name'] . ' <' . $domainValues['email'] . '>'; if (!empty($eventDetails['confirm_from_name']) && !empty($eventDetails['confirm_from_email'])) { $receiptFrom = $eventDetails['confirm_from_name'] . ' <' . $eventDetails['confirm_from_email'] . '>'; } list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_event', 'valueName' => 'participant_' . strtolower($mailType), 'contactId' => $contactId, 'tplParams' => array('contact' => $contactDetails, 'domain' => $domainValues, 'participant' => $participantValues, 'event' => $eventDetails, 'paidEvent' => CRM_Utils_Array::value('is_monetary', $eventDetails), 'isShowLocation' => CRM_Utils_Array::value('is_show_location', $eventDetails), 'isAdditional' => $participantValues['registered_by_id'], 'isExpired' => $mailType == 'Expired', 'isConfirm' => $mailType == 'Confirm', 'checksumValue' => $checksumValue), 'from' => $receiptFrom, 'toName' => $participantName, 'toEmail' => $toEmail, 'cc' => CRM_Utils_Array::value('cc_confirm', $eventDetails), 'bcc' => CRM_Utils_Array::value('bcc_confirm', $eventDetails))); // 3. create activity record. if ($mailSent) { $now = date('YmdHis'); $activityType = 'Event Registration'; $activityParams = array('subject' => $subject, 'source_contact_id' => $contactId, 'source_record_id' => $participantId, 'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name'), 'activity_date_time' => CRM_Utils_Date::isoToMysql($now), 'due_date_time' => CRM_Utils_Date::isoToMysql($participantValues['register_date']), 'is_test' => $participantValues['is_test'], 'status_id' => 2); if (is_a(CRM_Activity_BAO_Activity::create($activityParams), 'CRM_Core_Error')) { CRM_Core_Error::fatal('Failed creating Activity for expiration mail'); } } } return $mailSent; }
/** * Gets all campaign related data and returns it as a std class. * * @param int $contributionPageID * @param string $widgetID * * @return stdClass */ public static function getContributionPageData($contributionPageID, $widgetID) { $config = CRM_Core_Config::singleton(); $data = array(); $data['currencySymbol'] = $config->defaultCurrencySymbol; if (empty($contributionPageID) || CRM_Utils_Type::validate($contributionPageID, 'Integer') == NULL) { $data['is_error'] = TRUE; CRM_Core_Error::debug_log_message("{$contributionPageID} is not set"); return $data; } $widget = new CRM_Contribute_DAO_Widget(); $widget->contribution_page_id = $contributionPageID; if (!$widget->find(TRUE)) { $data['is_error'] = TRUE; CRM_Core_Error::debug_log_message("{$contributionPageID} is not found"); return $data; } $data['is_error'] = FALSE; if (!$widget->is_active) { $data['is_active'] = FALSE; } $data['is_active'] = TRUE; $data['title'] = $widget->title; $data['logo'] = $widget->url_logo; $data['button_title'] = $widget->button_title; $data['about'] = $widget->about; $query = "\n SELECT count( id ) as count,\n sum( total_amount) as amount\n FROM civicrm_contribution\n WHERE is_test = 0\n AND contribution_status_id = 1\n AND contribution_page_id = %1"; $params = array(1 => array($contributionPageID, 'Integer')); $dao = CRM_Core_DAO::executeQuery($query, $params); if ($dao->fetch()) { $data['num_donors'] = (int) $dao->count; $data['money_raised'] = (int) $dao->amount; } else { $data['num_donors'] = $data['money_raised'] = $data->money_raised = 0; } $query = "\n SELECT goal_amount, start_date, end_date, is_active\n FROM civicrm_contribution_page\n WHERE id = %1"; $params = array(1 => array($contributionPageID, 'Integer')); $dao = CRM_Core_DAO::executeQuery($query, $params); $data['campaign_start'] = ''; $startDate = NULL; if ($dao->fetch()) { $data['money_target'] = (int) $dao->goal_amount; // conditions that needs to be handled // 1. Campaign is not active - no text // 2. Campaign start date greater than today - show start date // 3. Campaign end date is set and greater than today - show end date // 4. If no start and end date or no end date and start date greater than today, then it's ongoing if ($dao->is_active) { $data['campaign_start'] = ts('Campaign is ongoing'); // check for time being between start and end date $now = time(); if ($dao->start_date) { $startDate = CRM_Utils_Date::unixTime($dao->start_date); if ($startDate && $startDate >= $now) { $data['is_active'] = FALSE; $data['campaign_start'] = ts('Campaign starts on %1', array(1 => CRM_Utils_Date::customFormat($dao->start_date, $config->dateformatFull))); } } if ($dao->end_date) { $endDate = CRM_Utils_Date::unixTime($dao->end_date); if ($endDate && $endDate < $now) { $data['is_active'] = FALSE; $data['campaign_start'] = ts('Campaign ended on %1', array(1 => CRM_Utils_Date::customFormat($dao->end_date, $config->dateformatFull))); } elseif ($startDate >= $now) { $data['campaign_start'] = ts('Campaign starts on %1', array(1 => CRM_Utils_Date::customFormat($dao->start_date, $config->dateformatFull))); } else { $data['campaign_start'] = ts('Campaign ends on %1', array(1 => CRM_Utils_Date::customFormat($dao->end_date, $config->dateformatFull))); } } } else { $data['is_active'] = FALSE; } } else { $data['is_active'] = FALSE; } $data['money_raised_percentage'] = 0; if ($data['money_target'] > 0) { $percent = $data['money_raised'] / $data['money_target']; $data['money_raised_percentage'] = round($percent, 2) * 100 . "%"; $data['money_target_display'] = CRM_Utils_Money::format($data['money_target']); $data['money_raised'] = ts('Raised %1 of %2', array(1 => CRM_Utils_Money::format($data['money_raised']), 2 => $data['money_target_display'])); } else { $data['money_raised'] = ts('Raised %1', array(1 => CRM_Utils_Money::format($data['money_raised']))); } $data['money_low'] = 0; $data['num_donors'] = $data['num_donors'] . " " . ts('Donors'); $data['home_url'] = "<a href='{$config->userFrameworkBaseURL}' class='crm-home-url' style='color:" . $widget->color_homepage_link . "'>" . ts('Learn more.') . "</a>"; // if is_active is false, show this link and hide the contribute button $data['homepage_link'] = $widget->url_homepage; $data['colors'] = array(); $data['colors']["title"] = $widget->color_title; $data['colors']["button"] = $widget->color_button; $data['colors']["bar"] = $widget->color_bar; $data['colors']["main_text"] = $widget->color_main_text; $data['colors']["main"] = $widget->color_main; $data['colors']["main_bg"] = $widget->color_main_bg; $data['colors']["bg"] = $widget->color_bg; $data['colors']["about_link"] = $widget->color_about_link; return $data; }
/** * Process a PCP contribution. * * @param int $pcpId * @param $component * @param $entity * * @return array */ public static function handlePcp($pcpId, $component, $entity) { self::getPcpEntityTable($component); if (!$pcpId) { return FALSE; } $approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name'); $pcpStatus = CRM_Core_OptionGroup::values("pcp_status"); $params = array('id' => $pcpId); CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo); $params = array('id' => $pcpInfo['pcp_block_id']); CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $pcpBlock); $params = array('id' => $pcpInfo['page_id']); $now = time(); if ($component == 'event') { // figure out where to redirect if an exception occurs below based on target entity $urlBase = 'civicrm/event/register'; // ignore startDate for events - PCP's can be active long before event start date $startDate = 0; $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $entity)); } elseif ($component == 'contribute') { $urlBase = 'civicrm/contribute/transact'; //start and end date of the contribution page $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('start_date', $entity)); $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $entity)); } // define redirect url back to contrib page or event if needed $url = CRM_Utils_System::url($urlBase, "reset=1&id={$pcpBlock['entity_id']}", FALSE, NULL, FALSE, TRUE); if ($pcpBlock['target_entity_id'] != $entity['id']) { $statusMessage = ts('This 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, $url); } elseif ($pcpInfo['status_id'] != $approvedId) { $statusMessage = ts('The Personal Campaign Page you have just visited is currently %1. However you can still support the campaign here.', array(1 => $pcpStatus[$pcpInfo['status_id']])); CRM_Core_Error::statusBounce($statusMessage, $url); } elseif (empty($pcpBlock['is_active'])) { $statusMessage = ts('Personal Campaign Pages are currently not enabled for this contribution page. However you can still support the campaign here.'); CRM_Core_Error::statusBounce($statusMessage, $url); } elseif (empty($pcpInfo['is_active'])) { $statusMessage = ts('The Personal Campaign Page you have just visited is currently inactive. However you can still support the campaign here.'); CRM_Core_Error::statusBounce($statusMessage, $url); } elseif ($startDate && $startDate > $now || $endDate && $endDate < $now) { $customStartDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $entity)); $customEndDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $entity)); if ($startDate && $endDate) { $statusMessage = ts('The Personal Campaign Page you have just visited is only active from %1 to %2. However you can still support the campaign here.', array(1 => $customStartDate, 2 => $customEndDate)); CRM_Core_Error::statusBounce($statusMessage, $url); } elseif ($startDate) { $statusMessage = ts('The Personal Campaign Page you have just visited will be active beginning on %1. However you can still support the campaign here.', array(1 => $customStartDate)); CRM_Core_Error::statusBounce($statusMessage, $url); } elseif ($endDate) { if ($component == 'event') { // Target_entity is an event and the event is over, redirect to event info instead of event registration page. $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$pcpBlock['entity_id']}", FALSE, NULL, FALSE, TRUE); $statusMessage = ts('The event linked to the Personal Campaign Page you have just visited is over (as of %1).', array(1 => $customEndDate)); CRM_Core_Error::statusBounce($statusMessage, $url); } else { $statusMessage = ts('The Personal Campaign Page you have just visited is no longer active (as of %1). However you can still support the campaign here.', array(1 => $customEndDate)); CRM_Core_Error::statusBounce($statusMessage, $url); } } } return array('pcpId' => $pcpId, 'pcpBlock' => $pcpBlock, 'pcpInfo' => $pcpInfo); }
static function &feeDetails($startDate, $endDate, $feeType = null, $onlyIndexedTution = false, $includeDetails = true, $studentID = null, $category = null) { $clauses = array(); $params = array(); $count = 1; if ($studentID) { $clauses[] = "c.id = %{$count}"; $params[$count++] = array($studentID, 'Integer'); } if ($feeType) { $clauses[] = "f.fee_type = %{$count}"; $params[$count++] = array($feeType, 'String'); } if ($category) { $clauses[] = "f.category = %{$count}"; $params[$count++] = array($category, 'String'); } if ($onlyIndexedTution) { $clauses[] = "( f.eligible_for_indexed_tuition == 1 )"; } $clause = null; if ($clauses) { $clause = ' AND ' . implode(' AND ', $clauses); } $countPlusOne = $count + 1; $sql = "\nSELECT c.display_name, f.*\nFROM civicrm_value_extended_care_fee_tracker f\nINNER JOIN civicrm_contact c ON c.id = f.entity_id\nWHERE DATE( f.fee_date ) >= %{$count}\nAND DATE( f.fee_date ) <= %{$countPlusOne}\n {$clause}\nORDER BY f.fee_date desc, f.fee_type\n"; $params[$count] = array($startDate, 'Date'); $params[$countPlusOne] = array($endDate, 'Date'); $dao = CRM_Core_DAO::executeQuery($sql, $params); $summary = array(); while ($dao->fetch()) { $studentID = $dao->entity_id; if (!array_key_exists($studentID, $summary)) { $summary[$studentID] = array('id' => $studentID, 'name' => $dao->display_name, 'payments' => 0, 'charges' => 0, 'ecCharges' => 0, 'classCharges' => 0, 'refunds' => 0); if ($includeDetails) { $summary[$studentID]['details'] = array(); } } if ($includeDetails) { $dateFormat = $dao->category == 'Standard Fee' ? "%Y - %b" : "%a, %b %d"; $summary[$studentID]['details'][$dao->id] = array('fee_type' => $dao->fee_type, 'description' => $dao->description, 'category' => $dao->category, 'fee_date' => strftime($dateFormat, CRM_Utils_Date::unixTime($dao->fee_date)), 'total_blocks' => $dao->total_blocks, 'eligible_it' => $dao->eligible_for_indexed_tuition); } switch ($dao->fee_type) { case 'Payment': $summary[$studentID]['payments'] += $dao->total_blocks; break; case 'Charge': $summary[$studentID]['charges'] += $dao->total_blocks; if ($dao->category == 'Standard Fee') { $summary[$studentID]['ecCharges'] += $dao->total_blocks; } else { $summary[$studentID]['classCharges'] += $dao->total_blocks; } break; case 'Charge Back': case 'Credit': $summary[$studentID]['refunds'] += $dao->total_blocks; break; } } return $summary; }