/** * Construct the basic widget object. */ public function __construct() { // Widget actual processes. parent::__construct('civicontribute-widget', __('CiviCRM Contribution Page Widget', 'civicontribute-widget'), array('description' => __('Displays contribution page widgets from CiviContribute as native WordPress widgets.', 'civicontribute-widget'))); if (!function_exists('civicrm_initialize')) { return; } civicrm_initialize(); require_once 'CRM/Utils/System.php'; $this->_civiversion = CRM_Utils_System::version(); $this->_civiBasePage = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'wpBasePage'); }
/** * Send an alert email. * * @param $p_eWAY_tran_num * @param $p_trxn_out * @param $p_trxn_back * @param $p_request * @param $p_response */ public function send_alert_email($p_eWAY_tran_num, $p_trxn_out, $p_trxn_back, $p_request, $p_response) { // Initialization call is required to use CiviCRM APIs. civicrm_initialize(TRUE); list($fromName, $fromEmail) = CRM_Core_BAO_Domain::getNameAndEmail(); $from = "{$fromName} <{$fromEmail}>"; $toName = 'Support at eWAY'; $toEmail = '*****@*****.**'; $subject = "ALERT: Unique Trxn Number Failure : eWAY Transaction # = [" . $p_eWAY_tran_num . "]"; $message = "\nTRXN sent out with request = '{$p_trxn_out}'.\nTRXN sent back with response = '{$p_trxn_back}'.\n\nThis is a ['{$this->_mode}'] transaction.\n\n\nRequest XML =\n---------------------------------------------------------------------------\n{$p_request}\n---------------------------------------------------------------------------\n\n\nResponse XML =\n---------------------------------------------------------------------------\n{$p_response}\n---------------------------------------------------------------------------\n\n\nRegards\n\nThe CiviCRM eWAY Payment Processor Module\n"; $params = array(); $params['groupName'] = 'eWay Email Sender'; $params['from'] = $from; $params['toName'] = $toName; $params['toEmail'] = $toEmail; $params['subject'] = $subject; $params['text'] = $message; CRM_Utils_Mail::send($params); }
/** * Retrieves a CiviCRM contact by Drupal user ID. */ function civicrm_custom_user_profile_get_contact($uid) { $contacts =& drupal_static(__FUNCTION__); if (isset($contacts[$uid])) { return $contacts[$uid]; } if (!isset($contacts)) { $contacts = array(); } $contacts[$uid] = FALSE; civicrm_initialize(); require_once 'api/api.php'; $res = civicrm_api('uf_match', 'get', array('uf_id' => $uid, 'version' => 3)); if ($res['is_error'] || empty($res['id']) || empty($res['values'][$res['id']])) { return FALSE; } $id = $res['values'][$res['id']]['contact_id']; $res = civicrm_api('contact', 'get', array('contact_id' => $id, 'version' => 3)); if ($res['is_error']) { return FALSE; } $contacts[$uid] = $res['values'][$res['id']]; return $contacts[$uid]; }
<?php civicrm_initialize(); // ----------------------------- // Get a list of users to update if (!getenv('INSTALL_DASHBOARD_USERS')) { throw new RuntimeException('Missing environment variable: INSTALL_DASHBOARD_USERS'); } $users = explode(';', getenv('INSTALL_DASHBOARD_USERS')); CRM_Core_BAO_CMSUser::synchronize(FALSE); // ------------------------------ // Get list of available dashlets $reportInstanceResult = civicrm_api3('ReportInstance', 'get', array('option.limit' => 0)); $reportInstanceNames = CRM_Utils_Array::index(array('report_id'), $reportInstanceResult['values']); $dashletTypeResult = civicrm_api3('Dashboard', 'get', array('domain_id' => CRM_Core_Config::domainID())); $dashletTypes = CRM_Utils_Array::index(array('name'), $dashletTypeResult['values']); // --------------------------------------- // Build list of specific dashlets to add $dashlets = array(array('dashboard_id' => $dashletTypes['report/' . $reportInstanceNames['event/summary']['id']]['id'], 'column_no' => 0, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 1), array('dashboard_id' => $dashletTypes['report/' . $reportInstanceNames['contribute/topDonor']['id']]['id'], 'column_no' => 0, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 3), array('dashboard_id' => $dashletTypes['report/' . $reportInstanceNames['contribute/summary']['id']]['id'], 'column_no' => 0, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 4), array('dashboard_id' => $dashletTypes['activity']['id'], 'column_no' => 1, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 10), array('dashboard_id' => $dashletTypes['myCases']['id'], 'column_no' => 1, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 11), array('dashboard_id' => $dashletTypes['report/' . $reportInstanceNames['member/summary']['id']]['id'], 'column_no' => 1, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 12)); // ------------------- // Insert the dashlets $tx = new CRM_Core_Transaction(); try { foreach ($users as $user) { foreach ($dashlets as $dashlet) { $dashlet['contact_id'] = "@user:{$user}"; $dashlet['is_active'] = 1; $dashlet['debug'] = 1; civicrm_api3('dashboard_contact', 'create', $dashlet); } }
function send_alert_email($p_eWAY_tran_num, $p_trxn_out, $p_trxn_back, $p_request, $p_response) { // Initialization call is required to use CiviCRM APIs. civicrm_initialize(true); require_once 'CRM/Utils/Mail.php'; require_once 'CRM/Core/BAO/Domain.php'; list($fromName, $fromEmail) = CRM_Core_BAO_Domain::getNameAndEmail(); $from = "{$fromName} <{$fromEmail}>"; $toName = 'Support at eWAY'; $toEmail = '*****@*****.**'; $subject = "ALERT: Unique Trxn Number Failure : eWAY Transaction # = [" . $p_eWAY_tran_num . "]"; $message = "\r\nTRXN sent out with request = '{$p_trxn_out}'.\r\nTRXN sent back with response = '{$p_trxn_back}'.\r\n\r\nThis is a ['{$this->_mode}'] transaction.\r\n\r\n\r\nRequest XML = \r\n---------------------------------------------------------------------------\r\n{$p_request}\r\n---------------------------------------------------------------------------\r\n\r\n\r\nResponse XML = \r\n---------------------------------------------------------------------------\r\n{$p_response}\r\n---------------------------------------------------------------------------\r\n\r\n\r\nRegards\r\n\r\nThe CiviCRM eWAY Payment Processor Module\r\n"; //$cc = 'Name@Domain'; CRM_Utils_Mail::send($from, $toName, $toEmail, $subject, $message, $cc); }
/** * Implementation of hook_civicrm_tokens * * http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_tokenValues * * This hook is called to get all the values for the tokens registered. * Use it to overwrite or reformat existing token values, or supply the * values for custom tokens you have defined in hook_civicrm_tokens. * * * @param $values - array of values, keyed by contact id * @param $cids - array of contactIDs that the system needs values for. * @param null $job - the job_id * @param array $tokens - tokens used in the mailing - use this to check whether a token is being used and avoid fetching data for unneeded tokens * @param null $context - the class name */ function joinrenew_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = array(), $context = null) { if (array_key_exists("FamilyMembershipToken", $_SESSION)) { if (!empty($tokens['FamilyMembership'])) { $data = array('FamilyMembership.token' => $_SESSION['FamilyMembershipToken']); foreach ($cids as $cid) { $values[$cid] = empty($values[$cid]) ? $data : $values[$cid] + $data; } unset($_SESSION['FamilyMembershipToken']); } } if (array_key_exists("GiftMemberships", $_SESSION)) { if (!empty($tokens['GiftMemberships'])) { $data = array('GiftMemberships.name' => $_SESSION['GiftMemberships']['name'], 'GiftMemberships.coupon' => $_SESSION['GiftMemberships']['code']); foreach ($cids as $cid) { $values[$cid] = empty($values[$cid]) ? $data : $values[$cid] + $data; } } } if (!empty($tokens['username'])) { civicrm_initialize(); foreach ($cids as $cid) { $params = array('version' => 3, 'sequential' => 1, 'contact_id' => $cid); $result = civicrm_api('UFMatch', 'get', $params); if (!$result['is_error']) { $drupalinfo = user_load($result['values'][0]['uf_id']); $values[$cid]['username.drupal'] = $drupalinfo->name; } } } }
/** * Implementation of command 'upgrade-db' */ private function upgradeDB() { civicrm_initialize(); if (class_exists('CRM_Upgrade_Headless')) { # Note: CRM_Upgrade_Headless introduced in 4.2 -- at the same time as class auto-loading try { $upgradeHeadless = new CRM_Upgrade_Headless(); $result = $upgradeHeadless->run(); WP_CLI::line("Upgrade outputs: " . "\"" . $result['message'] . "\""); } catch (Exception $e) { WP_CLI::error($e->getMessage()); } } else { require_once 'CRM/Core/Smarty.php'; $template = CRM_Core_Smarty::singleton(); require_once 'CRM/Upgrade/Page/Upgrade.php'; $upgrade = new CRM_Upgrade_Page_Upgrade(); // new since CiviCRM 4.1 if (is_callable(array($upgrade, 'setPrint'))) { $upgrade->setPrint(TRUE); } # to suppress html output /w source code. ob_start(); $upgrade->run(); # capture the required message. $result = $template->get_template_vars('message'); ob_end_clean(); WP_CLI::line("Upgrade outputs: " . "\"{$result}\""); } }
/** * Process a transaction and record it against the contact. * * @param array $params (reference ) input parameters * * @return array (reference ) contribution of created or updated record (or a civicrm error) * @static void * @access public * */ function civicrm_contribute_transact($params) { civicrm_initialize(); if (empty($params)) { return civicrm_create_error(ts('No input parameters present')); } if (!is_array($params)) { return civicrm_create_error(ts('Input parameters is not an array')); } $values = array(); require_once 'CRM/Contribute/BAO/Contribution.php'; $error = _civicrm_contribute_format_params($params, $values); if (civicrm_error($error)) { return $error; } $required = array('amount'); foreach ($required as $key) { if (!isset($params[$key])) { return civicrm_create_error("Missing parameter {$key}: civicrm_contribute_transact() requires a parameter '{$key}'."); } } // allow people to omit some values for convenience $defaults = array('payment_processor_mode' => 'live'); $params = array_merge($defaults, $params); // clean up / adjust some values which if (!isset($params['total_amount'])) { $params['total_amount'] = $params['amount']; } if (!isset($params['net_amount'])) { $params['net_amount'] = $params['amount']; } if (!isset($params['receive_date'])) { $params['receive_date'] = date('Y-m-d'); } if (!isset($params['invoiceID']) && isset($params['invoice_id'])) { $params['invoiceID'] = $params['invoice_id']; } require_once 'CRM/Core/BAO/PaymentProcessor.php'; $paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($params['payment_processor_id'], $params['payment_processor_mode']); if (civicrm_error($paymentProcessor)) { return $paymentProcessor; } require_once 'CRM/Core/Payment.php'; $payment = CRM_Core_Payment::singleton($params['payment_processor_mode'], $paymentProcessor); if (civicrm_error($payment)) { return $payment; } $transaction = $payment->doDirectPayment($params); if (civicrm_error($transaction)) { return $transaction; } // but actually, $payment->doDirectPayment() doesn't return a // CRM_Core_Error by itself if (get_class($transaction) == 'CRM_Core_Error') { $errs = $transaction->getErrors(); if (!empty($errs)) { $last_error = array_shift($errs); return CRM_Core_Error::createApiError($last_error['message']); } } $contribution = civicrm_contribution_add($params); return $contribution; }
function event_calendar_shortcode_includes() { global $post; // don't parse content when there's no post object, eg on 404 pages. if (!is_object($post)) { return; } // check for existence of shortcode in content. if (preg_match('/\\[event_calendar/', $post->post_content)) { if (!civicrm_initialize()) { return; } // do we have functionality provided by plugin version 4.6+ present? $civi = civi_wp(); if (method_exists($civi, 'front_end_page_load')) { // add core resources for front end add_action('wp', array($civi, 'front_end_page_load'), 100); } else { // add CiviCRM core resources. CRM_Core_Resources::singleton()->addCoreResources(); $config = CRM_Core_Config::singleton(); $config->userFrameworkFrontend = $front_end; } } }