Пример #1
0
/**
 * Implementation of hook_civicrm_install
 */
function hrvisa_civicrm_install()
{
    if (!CRM_Core_OptionGroup::getValue('activity_type', 'Visa Expiration', 'name')) {
        // create activity_type 'Visa Expiration'
        $params = array('weight' => 1, 'label' => 'Visa Expiration', 'filter' => 0, 'is_active' => 1, 'is_default' => 0);
        $result = civicrm_api3('activity_type', 'create', $params);
        if (CRM_Utils_Array::value('is_error', $result, FALSE)) {
            CRM_Core_Error::debug_var("Failed to create activity type 'Visa  Expiration'", $result);
            throw new CRM_Core_Exception('Failed to create activity type \'Visa  Expiration\'');
        }
        $activityTypeId = $result['values'][$result['id']]['value'];
    } else {
        $activityTypeId = CRM_Core_OptionGroup::getValue('activity_type', 'Visa Expiration', 'name');
    }
    // set weekly reminder for Visa Expiration activities (not active)
    // will be active when extension is enabled
    if (!empty($activityTypeId)) {
        $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
        $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
        // schedule reminder for Visa Expiration Creation
        $result = civicrm_api3('action_schedule', 'get', array('name' => 'Visa Expiration Reminder'));
        if (empty($result['id'])) {
            $params = array('name' => 'Visa Expiration Reminder', 'title' => 'Visa Expiration Reminder', 'recipient' => $targetID, 'limit_to' => 1, 'entity_value' => $activityTypeId, 'entity_status' => CRM_Core_OptionGroup::getValue('activity_status', 'Scheduled', 'name'), 'start_action_offset' => 1, 'start_action_unit' => 'week', 'start_action_condition' => 'before', 'start_action_date' => 'activity_date_time', 'is_repeat' => 0, 'is_active' => 0, 'body_html' => '<p>Your latest visa expiries on {activity.activity_date_time}</p>', 'subject' => 'Reminder for Visa Expiration', 'record_activity' => 1, 'mapping_id' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', 'activity_type', 'id', 'entity_value'));
            $result = civicrm_api3('action_schedule', 'create', $params);
        }
    }
    return _hrvisa_civix_civicrm_install();
}
Пример #2
0
 function main($component = 'contribute')
 {
     require_once 'CRM/Utils/Request.php';
     //we only get invoice num as a key player from payment gateway response.
     //for ARB we get x_subscription_id and x_subscription_paynum
     $x_subscription_id = self::retrieve('x_subscription_id', 'String');
     if ($x_subscription_id) {
         //Approved
         CRM_Core_Error::debug_var('$_POST', $_POST);
         $ids = $objects = array();
         $input['component'] = $component;
         // load post vars in $input
         $this->getInput($input, $ids);
         // load post ids in $ids
         $this->getIDs($ids, $input);
         CRM_Core_Error::debug_var('$ids', $ids);
         CRM_Core_Error::debug_var('$input', $input);
         if (!$this->validateData($input, $ids, $objects)) {
             return false;
         }
         if ($component == 'contribute' && $ids['contributionRecur']) {
             // check if first contribution is completed, else complete first contribution
             $first = true;
             if ($objects['contribution']->contribution_status_id == 1) {
                 $first = false;
             }
             return $this->recur($input, $ids, $objects, $first);
         }
     }
 }
 public function isConditionValid(CRM_Civirules_EventData_EventData $eventData)
 {
     $contactId = $eventData->getContactId();
     $entityData = $eventData->getEntityData('ContributionSoft');
     $contacts = array();
     $query = $this->conditionParams['smart_group_query'];
     if (!empty($query)) {
         $subQueries = explode(';', $query);
         // To run only first and select statement in query string
         if (!empty($subQueries) && !preg_match('/^(insert|update|delete|create|drop|replace)/i', $subQueries[0])) {
             CRM_Core_Error::debug_var('CiviRules::Custom Query Contact Condition Query', $subQueries[0]);
             CRM_Core_Error::debug_var('CiviRules::Custom Query Contact Condition Param Contribution', $entityData['contribution_id']);
             $dao = CRM_Core_DAO::executeQuery('SELECT ' . $subQueries[0], array(1 => array($entityData['contribution_id'], 'Int')));
             while ($dao->fetch()) {
                 $contacts[] = $dao->contact_id;
             }
         }
     }
     CRM_Core_Error::debug_var('CiviRules::Custom Query Contact Condition Contacts', $contacts);
     if (!empty($contacts)) {
         $eventData->setConditionOutputData('ContributionSoft', $contacts);
         return TRUE;
     } else {
         return FALSE;
     }
 }
 function run()
 {
     if (CRM_Utils_System::authenticateKey()) {
         $request_type = CRM_Utils_Request::retrieve('type', 'String');
         $request_data = CRM_Utils_Request::retrieve('data', 'String');
         $config = CRM_Core_Config::singleton();
         if ($config->debug) {
             $request_data_log = print_r($request_data, TRUE);
             CRM_Core_Error::debug_log_message("Mailchimp Webhook Request [{$request_type}]: \n{$request_data_log}");
         }
         $function_name = 'self::mailchimpWebhook' . ucwords($request_type);
         if (is_callable($function_name)) {
             // Set a canary to prevent CiviMailchimp hooks from firing, which
             // would trigger updates back to Mailchimp, resulting in an endless
             // loop.
             civimailchimp_static('mailchimp_do_not_run_hooks', TRUE);
             try {
                 call_user_func($function_name, $request_data);
             } catch (Exception $e) {
                 $error = array('code' => get_class($e), 'message' => $e->getMessage(), 'exception' => $e);
                 $message = "Mailchimp Webhook Request [{$request_type}]: {$error['code']}: {$error['message']}";
                 CRM_CiviMailchimp_BAO_SyncLog::saveMessage('error', 'mailchimp_to_civicrm', $message, $request_data);
                 CRM_Core_Error::debug_var('Fatal Error Details', $error);
                 CRM_Core_Error::backtrace('backTrace', TRUE);
                 throw $e;
             }
         }
     }
     parent::run();
 }
Пример #5
0
 function run()
 {
     CRM_Core_Error::debug_var('Page_Post', 'CONFIRM', false, true);
     $this->setValues();
     $group_id = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'group_id');
     $this->setGroupStatus($this->contact_id, $group_id);
     $this->setActivityStatus($this->activity_id, 'Completed');
     $country = $this->getCountry($this->campaign_id);
     $url = "{$country}/post_confirm";
     CRM_Utils_System::redirect($url);
 }
Пример #6
0
/**
 * Add a Javascript file to a specific part of the page
 *
 * @param array $params
 *   Array with keys:
 *   - ext: string, extension name. see CRM_Core_Resources::addScriptFile
 *   - file: string, relative file path. see CRM_Core_Resources::addScriptFile
 *   - url: string. see CRM_Core_Resources::addScriptURL
 *   - weight: int; default: CRM_Core_Resources::DEFAULT_WEIGHT (0)
 *   - region: string; default: CRM_Core_Resources::DEFAULT_REGION ('html-header')
 * @param CRM_Core_Smarty $smarty
 *
 * @throws Exception
 */
function smarty_function_crmScript($params, &$smarty)
{
    $params += array('weight' => CRM_Core_Resources::DEFAULT_WEIGHT, 'region' => CRM_Core_Resources::DEFAULT_REGION, 'ext' => 'civicrm');
    if (array_key_exists('file', $params)) {
        Civi::resources()->addScriptFile($params['ext'], $params['file'], $params['weight'], $params['region']);
    } elseif (array_key_exists('url', $params)) {
        Civi::resources()->addScriptUrl($params['url'], $params['weight'], $params['region']);
    } else {
        CRM_Core_Error::debug_var('crmScript_params', $params);
        throw new Exception("crmScript requires url or ext+file");
    }
}
function mailchimpsync_civicrm_navigationMenu(&$params)
{
    // get the id of Administer Menu
    $administerMenuId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Navigation', 'Administer', 'id', 'name');
    CRM_Core_Error::debug_var('$administerMenuId', $administerMenuId);
    // skip adding menu if there is no administer menu
    if ($administerMenuId) {
        // get the maximum key under adminster menu
        $maxKey = max(array_keys($params[$administerMenuId]['child']));
        $params[$administerMenuId]['child'][$maxKey + 1] = array('attributes' => array('label' => 'MailChimp Settings', 'name' => 'MailChimp Settings', 'url' => 'civicrm/mailchimp/apikeyregister', 'permission' => 'administer CiviCRM', 'operator' => NULL, 'separator' => TRUE, 'parentID' => $administerMenuId, 'navID' => $maxKey + 1, 'active' => 1));
        CRM_Core_BAO_Navigation::add($params);
    }
}
Пример #8
0
 function run()
 {
     CRM_Core_Error::debug_var('Page_Post', 'OPTOUT', false, true);
     $this->setValues();
     $params_contact = array('sequential' => 1, 'id' => $this->contact_id, 'is_opt_out' => 1);
     $result = civicrm_api3('Contact', 'create', $params_contact);
     $group_id = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'group_id');
     $this->setGroupStatus($this->contact_id, $group_id);
     $this->setActivityStatus($this->activity_id, 'optout');
     $country = $this->getCountry($this->campaign_id);
     //    $url = "{$country}/post_optout"; // temporary fixed unless I resolve redirect to language versions to this page
     $url = "/post_optout";
     CRM_Utils_System::redirect($url);
 }
 /**
  * Get the next item, even if there's an active lease
  *
  * @param $lease_time seconds
  *
  * @return object with key 'data' that matches the inputted data
  */
 function stealItem($lease_time = 3600)
 {
     $sql = "\n      SELECT id, queue_name, submit_time, release_time, data\n      FROM civicrm_queue_item\n      WHERE queue_name = %1\n      ORDER BY weight ASC, release_time ASC, id ASC\n      LIMIT 1\n    ";
     $params = array(1 => array($this->getName(), 'String'));
     $dao = CRM_Core_DAO::executeQuery($sql, $params, TRUE, 'CRM_Queue_DAO_QueueItem');
     if ($dao->fetch()) {
         $nowEpoch = CRM_Utils_Time::getTimeRaw();
         CRM_Core_DAO::executeQuery("UPDATE civicrm_queue_item SET release_time = %1 WHERE id = %2", array('1' => array(date('YmdHis', $nowEpoch + $lease_time), 'String'), '2' => array($dao->id, 'Integer')));
         $dao->data = unserialize($dao->data);
         return $dao;
     } else {
         CRM_Core_Error::debug_var('no items found');
         return FALSE;
     }
 }
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $donationParams = array('domain_id' => CRM_Core_Config::domainID(), 'simple_donation_page' => $params['simpleDonation']);
     $result = civicrm_api3('setting', 'create', $donationParams);
     if (CRM_Utils_Array::value('is_error', $result, FALSE)) {
         CRM_Core_Error::debug_var('setting-create result for angular_donation', $result);
         throw new CRM_Core_Exception('Failed to create settings for angular_donation');
     }
     $zipParams = array('domain_id' => CRM_Core_Config::domainID(), 'ziptastic_enable' => CRM_Utils_Array::value('ziptastic', $params) ? 1 : 0);
     $result = civicrm_api3('setting', 'create', $zipParams);
     if (CRM_Utils_Array::value('is_error', $result, FALSE)) {
         CRM_Core_Error::debug_var('setting-create result for angular_donation', $result);
         throw new CRM_Core_Exception('Failed to create settings for angular_donation');
     }
 }
function ukdirectdebitadditional_civicrm_handleSmartDebitMembershipRenewal(&$params)
{
    $ts1 = time();
    $ts2 = strtotime($params['end_date']);
    $year1 = date('Y', $ts1);
    $year2 = date('Y', $ts2);
    $month1 = date('m', $ts1);
    $month2 = date('m', $ts2);
    $diff = ($year2 - $year1) * 12 + ($month2 - $month1);
    CRM_Core_Error::debug_var("diff", $diff);
    CRM_Core_Error::debug_var("params", $params);
    if ($diff > 18) {
        unset($params['end_date']);
    }
    // Set the membership as current
    $params['status_id'] = 2;
}
Пример #12
0
/**
 * Add a stylesheet <LINK> to a specific part of the page
 *
 * @param $params array with keys:
 *  - ext: string, extension name. see CRM_Core_Resources::addStyleFile
 *  - file: string, relative file path. see CRM_Core_Resources::addStyleFile
 *  - url: string. see CRM_Core_Resources::addStyleURL
 *  - weight: int; default: CRM_Core_Resources::DEFAULT_WEIGHT (0)
 *  - region: string; default: CRM_Core_Resources::DEFAULT_REGION ('html-header')
 */
function smarty_function_crmStyle($params, &$smarty)
{
    $res = CRM_Core_Resources::singleton();
    if (empty($params['weight'])) {
        $params['weight'] = CRM_Core_Resources::DEFAULT_WEIGHT;
    }
    if (empty($params['region'])) {
        $params['region'] = CRM_Core_Resources::DEFAULT_REGION;
    }
    if (array_key_exists('file', $params)) {
        $res->addStyleFile($params['ext'], $params['file'], $params['weight'], $params['region']);
    } elseif (array_key_exists('url', $params)) {
        $res->addStyleUrl($params['url'], $params['weight'], $params['region']);
    } else {
        CRM_Core_Error::debug_var('crmStyle_params', $params);
        throw new Exception("crmStyle requires url or ext+file");
    }
}
 static function clear()
 {
     $message_id = CRM_Utils_Request::retrieve('id', 'Integer');
     $civicrm_queue_item_id = CRM_Utils_Request::retrieve('qid', 'Integer');
     try {
         CRM_CiviMailchimp_BAO_SyncLog::clearQueueItem($civicrm_queue_item_id);
         CRM_CiviMailchimp_BAO_SyncLog::clearMessage($message_id);
     } catch (Exception $e) {
         $error = array('status' => 'error', 'code' => get_class($e), 'message' => $e->getMessage(), 'exception' => $e);
         // CRM-11831 @see http://www.malsup.com/jquery/form/#file-upload
         if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
             header('Content-Type: application/json');
         }
         echo json_encode($error);
         CRM_Core_Error::debug_var('Fatal Error Details', $error);
         CRM_Core_Error::backtrace('backTrace', TRUE);
         CRM_Utils_System::civiExit();
     }
 }
function civicrm_api3_civi_mailchimp_sync($params)
{
    CRM_CiviMailchimp_BAO_SyncLog::deleteOldMessages();
    $records_to_process = $params['records_to_process_per_run'];
    $queue = CRM_Queue_Service::singleton()->create(array('type' => 'Sql', 'name' => 'mailchimp-sync', 'reset' => FALSE));
    if ($queue->numberOfItems() > 0) {
        $runner = new CRM_Queue_Runner(array('title' => ts('Sync Contacts to Mailchimp'), 'queue' => $queue));
        $continue_to_next_item = TRUE;
        $records_processed = 0;
        while ($continue_to_next_item && $records_processed < $records_to_process) {
            $record = $runner->runNext();
            if ($record['is_error']) {
                // Get the current Queue Item being worked on to allow for better error
                // reporting and logging.
                $query = "\n          SELECT\n            id,\n            data\n          FROM\n            civicrm_queue_item\n          WHERE\n            queue_name = 'mailchimp-sync'\n          ORDER BY\n            weight ASC,\n            id ASC\n          LIMIT 1\n        ";
                $item = CRM_Core_DAO::executeQuery($query);
                while ($item->fetch()) {
                    $item_data = unserialize($item->data);
                    $message = "[{$item_data->arguments[0]}] There was an error syncing contacts to Mailchimp.";
                    $exception_name = '';
                    if (!empty($record['exception'])) {
                        $exception_name = get_class($record['exception']);
                        $message = "[{$item_data->arguments[0]}] {$exception_name}: {$record['exception']->getMessage()}.";
                    }
                    $message .= " Mailchimp List ID: {$item_data->arguments[1]}. {$records_processed} records were successfully synced before this error.";
                    $error = array('code' => $exception_name, 'message' => $message, 'exception' => $record['exception']);
                    CRM_Core_Error::debug_var('Fatal Error Details', $error);
                    CRM_Core_Error::backtrace('backTrace', TRUE);
                    CRM_CiviMailchimp_BAO_SyncLog::saveMessage('error', 'civicrm_to_mailchimp', $message, $item_data, $item->id);
                    return civicrm_api3_create_error($message);
                }
            }
            $continue_to_next_item = $record['is_continue'];
            $records_processed++;
        }
        $message = ts('%1 records were successfully synced to Mailchimp.', array(1 => $records_processed));
        CRM_CiviMailchimp_BAO_SyncLog::saveMessage('success', 'civicrm_to_mailchimp', $message);
        return civicrm_api3_create_success($records_processed);
    }
}
Пример #15
0
 /**
  * Gather and print (and possibly log) amount of used memory.
  *
  * @param string $title
  * @param bool $log
  *   (optional) Whether to log the memory usage information.
  */
 public static function xMemory($title = NULL, $log = FALSE)
 {
     $mem = (double) xdebug_memory_usage() / (double) 1024;
     $mem = number_format($mem, 5) . ", " . time();
     if ($log) {
         echo "<p>{$title}: {$mem}<p>";
         flush();
         CRM_Core_Error::debug_var($title, $mem);
     } else {
         echo "<p>{$title}: {$mem}<p>";
         flush();
     }
 }
 /**
  * This method is handles the response that will be invoked (from extern/googleNotify) every time
  * a notification or request is sent by the Google Server.
  *
  */
 static function main($xml_response)
 {
     require_once 'Google/library/googleresponse.php';
     require_once 'Google/library/googlerequest.php';
     require_once 'Google/library/googlemerchantcalculations.php';
     require_once 'Google/library/googleresult.php';
     require_once 'Google/library/xml-processing/gc_xmlparser.php';
     $config = CRM_Core_Config::singleton();
     // Retrieve the XML sent in the HTTP POST request to the ResponseHandler
     if (get_magic_quotes_gpc()) {
         $xml_response = stripslashes($xml_response);
     }
     $headers = CRM_Utils_System::getAllHeaders();
     if (GOOGLE_DEBUG_PP) {
         CRM_Core_Error::debug_var('RESPONSE', $xml_response, TRUE, TRUE, 'Google');
     }
     // Retrieve the root and data from the xml response
     $response = new GoogleResponse();
     list($root, $data) = $response->GetParsedXML($xml_response);
     // lets retrieve the private-data & order-no
     $privateData = NULL;
     if (array_key_exists('shopping-cart', $data[$root])) {
         $privateData = $data[$root]['shopping-cart']['merchant-private-data']['VALUE'];
     }
     if (empty($privateData) && array_key_exists('order-summary', $data[$root]) && array_key_exists('shopping-cart', $data[$root]['order-summary'])) {
         $privateData = $data[$root]['order-summary']['shopping-cart']['merchant-private-data']['VALUE'];
     }
     $privateData = $privateData ? self::stringToArray($privateData) : '';
     $orderNo = $data[$root]['google-order-number']['VALUE'];
     $serial = $data[$root]['serial-number'];
     // a dummy object to call get context and a parent function inside it.
     $ipn = new CRM_Core_Payment_GoogleIPN('live', $dummyProcessor);
     list($mode, $module, $paymentProcessorID) = $ipn->getContext($privateData, $orderNo, $root, $response, $serial);
     $mode = $mode ? 'test' : 'live';
     $paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($paymentProcessorID, $mode);
     $merchant_id = $paymentProcessor['user_name'];
     $merchant_key = $paymentProcessor['password'];
     $response->SetMerchantAuthentication($merchant_id, $merchant_key);
     $server_type = $mode == 'test' ? 'sandbox' : 'production';
     $request = new GoogleRequest($merchant_id, $merchant_key, $server_type);
     $ipn = self::singleton($mode, $module, $paymentProcessor);
     if (GOOGLE_DEBUG_PP) {
         CRM_Core_Error::debug_var('RESPONSE-ROOT', $response->root, TRUE, TRUE, 'Google');
     }
     //Check status and take appropriate action
     $status = $response->HttpAuthentication($headers);
     switch ($root) {
         case "request-received":
         case "error":
         case "diagnosis":
         case "checkout-redirect":
         case "merchant-calculation-callback":
             break;
         case "new-order-notification":
             $response->SendAck($serial, FALSE);
             $ipn->newOrderNotify($data[$root], $privateData, $module);
             break;
         case "order-state-change-notification":
             $response->SendAck($serial, FALSE);
             $new_financial_state = $data[$root]['new-financial-order-state']['VALUE'];
             $new_fulfillment_order = $data[$root]['new-fulfillment-order-state']['VALUE'];
             switch ($new_financial_state) {
                 case 'CHARGEABLE':
                     break;
                 case 'CHARGED':
                 case 'PAYMENT_DECLINED':
                 case 'CANCELLED':
                 case 'CANCELLED_BY_GOOGLE':
                     $ipn->orderStateChange($new_financial_state, $data[$root], $privateData, $module);
                     break;
                 case 'REVIEWING':
                 case 'CHARGING':
                     break;
                 default:
                     break;
             }
             break;
         case "authorization-amount-notification":
             $response->SendAck($serial, FALSE);
             $new_financial_state = $data[$root]['order-summary']['financial-order-state']['VALUE'];
             $new_fulfillment_order = $data[$root]['order-summary']['fulfillment-order-state']['VALUE'];
             switch ($new_financial_state) {
                 case 'CHARGEABLE':
                     // For google-handled subscriptions chargeorder needn't be initiated,
                     // assuming auto-charging is turned on.
                     //$request->SendProcessOrder($data[$root]['google-order-number']['VALUE']);
                     //$request->SendChargeOrder($data[$root]['google-order-number']['VALUE'],'');
                     break;
                 case 'CHARGED':
                 case 'PAYMENT_DECLINED':
                 case 'CANCELLED':
                     break;
                 case 'REVIEWING':
                 case 'CHARGING':
                 case 'CANCELLED_BY_GOOGLE':
                     break;
                 default:
                     break;
             }
             break;
         case "charge-amount-notification":
         case "chargeback-amount-notification":
         case "refund-amount-notification":
         case "risk-information-notification":
             $response->SendAck($serial);
             break;
         default:
             break;
     }
 }
Пример #17
0
 /**
  * Print an unhandled exception
  *
  * @param $e
  */
 function reportException(Exception $e)
 {
     CRM_Core_Error::debug_var('CRM_Queue_ErrorPolicy_reportException', CRM_Core_Error::formatTextException($e));
     $response = array('is_error' => 1, 'is_continue' => 0);
     $config = CRM_Core_Config::singleton();
     if ($config->backtrace || CRM_Core_Config::isUpgradeMode()) {
         $response['exception'] = CRM_Core_Error::formatHtmlException($e);
     } else {
         $response['exception'] = htmlentities($e->getMessage());
     }
     global $activeQueueRunner;
     if (is_object($activeQueueRunner)) {
         $response['last_task_title'] = $activeQueueRunner->lastTaskTitle;
     }
     CRM_Utils_JSON::output($response);
 }
Пример #18
0
 /**
  * @param string $msg
  * @param bool $log
  */
 public static function backtrace($msg = 'backTrace', $log = FALSE)
 {
     $backTrace = debug_backtrace();
     $message = self::formatBacktrace($backTrace);
     if (!$log) {
         CRM_Core_Error::debug($msg, $message);
     } else {
         CRM_Core_Error::debug_var($msg, $message);
     }
 }
Пример #19
0
 /**
  * Migrate any last remaining options from `civicrm_domain.config_backend` to `civicrm_setting`.
  * Cleanup setting schema.
  *
  * @param CRM_Queue_TaskContext $ctx
  * @return bool
  */
 public function migrateSettings(CRM_Queue_TaskContext $ctx)
 {
     CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_setting DROP INDEX index_group_name');
     CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_setting DROP COLUMN group_name');
     CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_setting ADD UNIQUE INDEX index_domain_contact_name (domain_id, contact_id, name)');
     $domainDao = CRM_Core_DAO::executeQuery('SELECT id, config_backend FROM civicrm_domain');
     while ($domainDao->fetch()) {
         $settings = CRM_Upgrade_Incremental_php_FourSeven::convertBackendToSettings($domainDao->id, $domainDao->config_backend);
         CRM_Core_Error::debug_var('convertBackendToSettings', array('domainId' => $domainDao->id, 'backend' => $domainDao->config_backend, 'settings' => $settings));
         foreach ($settings as $name => $value) {
             $rowParams = array(1 => array($domainDao->id, 'Positive'), 2 => array($name, 'String'), 3 => array(serialize($value), 'String'));
             $settingId = CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_setting WHERE domain_id = %1 AND name = %2', $rowParams);
             if (!$settingId) {
                 CRM_Core_DAO::executeQuery('INSERT INTO civicrm_setting (domain_id, name, value, is_domain) VALUES (%1,%2,%3,1)', $rowParams);
             }
         }
     }
     // TODO Should drop config_backend, but keeping it during alpha/beta cycle in case we miss something.
     // CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_domain DROP COLUMN config_backend');
     return TRUE;
 }
Пример #20
0
        continue;
    }
    if (!empty($rows[18])) {
        $membershipParams['end_date'] = date('Y-m-d', strtotime($rows[18]));
    }
    if (!empty($membershipResult['id'])) {
        $membershipParams['id'] = $membershipResult['id'];
    }
    $membership = civicrm_api3('Membership', 'create', $membershipParams);
    if (empty($membership['id'])) {
        CRM_Core_Error::debug_var('$membershipFailed', $membership);
    } else {
        $totalImported++;
    }
    CRM_Core_Error::debug('$totalImported', $totalImported);
}
// print details in log
$logFile = 'Sync-' . date('Y-m-d-h-i-s');
if (!empty($errors['org'])) {
    CRM_Core_Error::debug_log_message('Organization already found in db for CFRA ID:', FALSE, $logFile);
    CRM_Core_Error::debug_var('', $errors['org'], TRUE, TRUE, $logFile);
}
if (!empty($errors['ind'])) {
    CRM_Core_Error::debug_log_message('Individual Contacts already found in db for CFRA ID:', FALSE, $logFile);
    CRM_Core_Error::debug_var('', $errors['ind'], TRUE, TRUE, $logFile);
}
if (!empty($errors['mem'])) {
    CRM_Core_Error::debug_log_message('Ignored membership for CFRA ID:', FALSE, $logFile);
    CRM_Core_Error::debug_var('', $errors['mem'], TRUE, TRUE, $logFile);
}
CRM_Core_Error::debug_log_message("Total imported: {$totalImported}", FALSE, $logFile);
Пример #21
0
 /**
  * Performing any view-layer filtering on result and send to client.
  */
 static function _return($op, $result)
 {
     if ($result['is_error']) {
         if (is_object($result['exception'])) {
             CRM_Core_Error::debug_var("CRM_Queue_Page_AJAX_{$op}_error", CRM_Core_Error::formatTextException($result['exception']));
             $config = CRM_Core_Config::singleton();
             if ($config->backtrace || CRM_Core_Config::isUpgradeMode()) {
                 $result['exception'] = CRM_Core_Error::formatHtmlException($result['exception']);
             } else {
                 $result['exception'] = $result['exception']->getMessage();
             }
         } else {
             CRM_Core_Error::debug_var("CRM_Queue_Page_AJAX_{$op}_error", $result);
         }
     }
     CRM_Utils_JSON::output($result);
 }
 function preProcess()
 {
     parent::preProcess();
     CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "reset=1&id=" . $this->controller->get('component_page_id')));
     CRM_Core_Error::debug_var('$this->controller->get(component_page_id)', $this->controller->get('component_page_id'));
 }
Пример #23
0
 /**
  * function that takes an address array and gets the latitude / longitude
  * and postal code for this address. Note that at a later stage, we could
  * make this function also clean up the address into a more valid format
  *
  * @param array $values associative array of address data: country, street_address, city, state_province, postal code
  * @param boolean $stateName this parameter currently has no function
  *
  * @return boolean true if we modified the address, false otherwise
  * @static
  */
 static function format(&$values, $stateName = FALSE)
 {
     CRM_Utils_System::checkPHPVersion(5, TRUE);
     $config = CRM_Core_Config::singleton();
     $whereComponents = array();
     if (CRM_Utils_Array::value('street_address', $values)) {
         $whereComponents['street'] = $values['street_address'];
     }
     if ($city = CRM_Utils_Array::value('city', $values)) {
         $whereComponents['city'] = $city;
     }
     if (CRM_Utils_Array::value('state_province', $values)) {
         if (CRM_Utils_Array::value('state_province_id', $values)) {
             $stateProvince = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_StateProvince', $values['state_province_id']);
         } else {
             if (!$stateName) {
                 $stateProvince = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_StateProvince', $values['state_province'], 'name', 'abbreviation');
             } else {
                 $stateProvince = $values['state_province'];
             }
         }
         // dont add state twice if replicated in city (happens in NZ and other countries, CRM-2632)
         if ($stateProvince != $city) {
             $whereComponents['state'] = $stateProvince;
         }
     }
     if (CRM_Utils_Array::value('postal_code', $values)) {
         $whereComponents['postal'] = $values['postal_code'];
     }
     if (CRM_Utils_Array::value('country', $values)) {
         $whereComponents['country'] = $values['country'];
     }
     foreach ($whereComponents as $componentName => $componentValue) {
         $whereComponents[$componentName] = urlencode("{$componentName}=\"{$componentValue}\"");
     }
     $add = 'q=' . urlencode('select * from geo.placefinder where ');
     $add .= join(urlencode(' and '), $whereComponents);
     $add .= "&appid=" . urlencode($config->mapAPIKey);
     $query = 'http://' . self::$_server . self::$_uri . '?' . $add;
     require_once 'HTTP/Request.php';
     $request = new HTTP_Request($query);
     $request->sendRequest();
     $string = $request->getResponseBody();
     // see CRM-11359 for why we suppress errors with @
     $xml = @simplexml_load_string($string);
     if ($xml === FALSE) {
         // account blocked maybe?
         CRM_Core_Error::debug_var('Geocoding failed.  Message from Yahoo:', $string);
         return FALSE;
     }
     if ($xml->getName() == 'error') {
         CRM_Core_Error::debug_var('query', $query);
         CRM_Core_Error::debug_log_message('Geocoding failed.  Message from Yahoo: ' . (string) $xml->description);
         return FALSE;
     }
     if (is_a($xml->results->Result, 'SimpleXMLElement')) {
         $result = array();
         $result = get_object_vars($xml->results->Result);
         foreach ($result as $key => $val) {
             if (is_scalar($val) && strlen($val)) {
                 $ret[(string) $key] = (string) $val;
             }
         }
         $values['geo_code_1'] = $ret['latitude'];
         $values['geo_code_2'] = $ret['longitude'];
         if ($ret['postal']) {
             $current_pc = CRM_Utils_Array::value('postal_code', $values);
             $skip_postal = FALSE;
             if ($current_pc) {
                 $current_pc_suffix = CRM_Utils_Array::value('postal_code_suffix', $values);
                 $current_pc_complete = $current_pc . $current_pc_suffix;
                 $new_pc_complete = preg_replace("/[+-]/", '', $ret['postal']);
                 // if a postal code was already entered, don't change it, except to make it more precise
                 if (strpos($new_pc_complete, $current_pc_complete) !== 0) {
                     // Don't bother anonymous users with the message - they can't change a form they just submitted anyway
                     if (CRM_Utils_System::isUserLoggedIn()) {
                         $msg = ts('The Yahoo Geocoding system returned a different postal code (%1) than the one you entered (%2). If you want the Yahoo value, please delete the current postal code and save again.', array(1 => $ret['postal'], 2 => $current_pc_suffix ? "{$current_pc}-{$current_pc_suffix}" : $current_pc));
                         CRM_Core_Session::setStatus($msg, ts('Postal Code Mismatch'), 'error');
                     }
                     $skip_postal = TRUE;
                 }
             }
             if (!$skip_postal) {
                 $values['postal_code'] = $ret['postal'];
                 /* the following logic to split the string was borrowed from
                       CRM/Core/BAO/Address.php -- CRM_Core_BAO_Address::fixAddress.
                       This is actually the function that calls the geocoding
                       script to begin with, but the postal code business takes
                       place before geocoding gets called.
                    */
                 if (preg_match('/^(\\d{4,5})[+-](\\d{4})$/', $ret['postal'], $match)) {
                     $values['postal_code'] = $match[1];
                     $values['postal_code_suffix'] = $match[2];
                 }
             }
         }
         return TRUE;
     }
     // reset the geo code values if we did not get any good values
     $values['geo_code_1'] = $values['geo_code_2'] = 'null';
     return FALSE;
 }
Пример #24
0
 /**
  * This function writes an entry about the intrusion to the database.
  *
  * @param array $result
  * @param int $reaction
  *
  * @return bool
  */
 private function log($result, $reaction = 0)
 {
     $ip = isset($_SERVER['SERVER_ADDR']) && $_SERVER['SERVER_ADDR'] != '127.0.0.1' ? $_SERVER['SERVER_ADDR'] : (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '127.0.0.1');
     $data = array();
     $session = CRM_Core_Session::singleton();
     foreach ($result as $event) {
         $data[] = array('name' => $event->getName(), 'value' => stripslashes($event->getValue()), 'page' => $_SERVER['REQUEST_URI'], 'userid' => $session->get('userID'), 'session' => session_id() ? session_id() : '0', 'ip' => $ip, 'reaction' => $reaction, 'impact' => $result->getImpact());
     }
     CRM_Core_Error::debug_var('IDS Detector Details', $data);
     return TRUE;
 }
Пример #25
0
 /**
  * This method is handles the response that will be invoked (from extern/googleNotify) every time
  * a notification or request is sent by the Google Server.
  *
  */
 static function main($xml_response)
 {
     require_once 'Google/library/googleresponse.php';
     require_once 'Google/library/googlemerchantcalculations.php';
     require_once 'Google/library/googleresult.php';
     require_once 'Google/library/xml-processing/xmlparser.php';
     $config = CRM_Core_Config::singleton();
     // Retrieve the XML sent in the HTTP POST request to the ResponseHandler
     if (get_magic_quotes_gpc()) {
         $xml_response = stripslashes($xml_response);
     }
     require_once 'CRM/Utils/System.php';
     $headers = CRM_Utils_System::getAllHeaders();
     if (GOOGLE_DEBUG_PP) {
         CRM_Core_Error::debug_var('RESPONSE', $xml_response, TRUE, TRUE, 'Google');
     }
     // Retrieve the root and data from the xml response
     $xmlParser = new XmlParser($xml_response);
     $root = $xmlParser->GetRoot();
     $data = $xmlParser->GetData();
     $orderNo = $data[$root]['google-order-number']['VALUE'];
     // lets retrieve the private-data
     $privateData = $data[$root]['shopping-cart']['merchant-private-data']['VALUE'];
     $privateData = $privateData ? self::stringToArray($privateData) : '';
     list($mode, $module, $paymentProcessorID) = self::getContext($xml_response, $privateData, $orderNo, $root);
     $mode = $mode ? 'test' : 'live';
     require_once 'CRM/Financial/BAO/PaymentProcessor.php';
     $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID, $mode);
     $ipn =& self::singleton($mode, $module, $paymentProcessor);
     // Create new response object
     $merchant_id = $paymentProcessor['user_name'];
     $merchant_key = $paymentProcessor['password'];
     $server_type = $mode == 'test' ? "sandbox" : '';
     $response = new GoogleResponse($merchant_id, $merchant_key, $xml_response, $server_type);
     if (GOOGLE_DEBUG_PP) {
         CRM_Core_Error::debug_var('RESPONSE-ROOT', $response->root, TRUE, TRUE, 'Google');
     }
     //Check status and take appropriate action
     $status = $response->HttpAuthentication($headers);
     switch ($root) {
         case "request-received":
         case "error":
         case "diagnosis":
         case "checkout-redirect":
         case "merchant-calculation-callback":
             break;
         case "new-order-notification":
             $response->SendAck();
             $ipn->newOrderNotify($data[$root], $privateData, $module);
             break;
         case "order-state-change-notification":
             $response->SendAck();
             $new_financial_state = $data[$root]['new-financial-order-state']['VALUE'];
             $new_fulfillment_order = $data[$root]['new-fulfillment-order-state']['VALUE'];
             switch ($new_financial_state) {
                 case 'CHARGEABLE':
                     $amount = $ipn->getAmount($orderNo);
                     if ($amount) {
                         $response->SendChargeOrder($data[$root]['google-order-number']['VALUE'], $amount, $message_log);
                         $response->SendProcessOrder($data[$root]['google-order-number']['VALUE'], $message_log);
                     }
                     break;
                 case 'CHARGED':
                 case 'PAYMENT_DECLINED':
                 case 'CANCELLED':
                     $ipn->orderStateChange($new_financial_state, $data[$root], $module);
                     break;
                 case 'REVIEWING':
                 case 'CHARGING':
                 case 'CANCELLED_BY_GOOGLE':
                     break;
                 default:
                     break;
             }
         case "charge-amount-notification":
         case "chargeback-amount-notification":
         case "refund-amount-notification":
         case "risk-information-notification":
             $response->SendAck();
             break;
         default:
             break;
     }
 }
Пример #26
0
 function main($component = 'contribute')
 {
     CRM_Core_Error::debug_var('GET', $_GET, true, true);
     CRM_Core_Error::debug_var('POST', $_POST, true, true);
     require_once 'CRM/Utils/Request.php';
     $objects = $ids = $input = array();
     $input['component'] = $component;
     // get the contribution and contact ids from the GET params
     $ids['contact'] = self::getValue('c', true);
     $ids['contribution'] = self::getValue('b', true);
     $this->getInput($input, $ids);
     if ($component == 'event') {
         $ids['event'] = self::getValue('e', true);
         $ids['participant'] = self::getValue('p', true);
         $ids['contributionRecur'] = self::getValue('r', false);
     } else {
         // get the optional ids
         $ids['membership'] = self::retrieve('membershipID', 'Integer', 'GET', false);
         $ids['contributionRecur'] = self::getValue('r', false);
         $ids['contributionPage'] = self::getValue('p', false);
         $ids['related_contact'] = self::retrieve('relatedContactID', 'Integer', 'GET', false);
         $ids['onbehalf_dupe_alert'] = self::retrieve('onBehalfDupeAlert', 'Integer', 'GET', false);
     }
     if (!$this->validateData($input, $ids, $objects)) {
         return false;
     }
     self::$_paymentProcessor =& $objects['paymentProcessor'];
     if ($component == 'contribute' || $component == 'event') {
         if ($ids['contributionRecur']) {
             // check if first contribution is completed, else complete first contribution
             $first = true;
             if ($objects['contribution']->contribution_status_id == 1) {
                 $first = false;
             }
             return $this->recur($input, $ids, $objects, $first);
         } else {
             return $this->single($input, $ids, $objects, false, false);
         }
     } else {
         return $this->single($input, $ids, $objects, false, false);
     }
 }
Пример #27
0
 /**
  * @param string $message
  * @param array $params
  *
  * @return array|bool|object
  */
 public function changeSubscriptionAmount(&$message = '', $params = array())
 {
     if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal') {
         $config = CRM_Core_Config::singleton();
         $args = array();
         $this->initialize($args, 'UpdateRecurringPaymentsProfile');
         $args['PROFILEID'] = $params['subscriptionId'];
         $args['AMT'] = $params['amount'];
         $args['CURRENCYCODE'] = $config->defaultCurrency;
         $args['BILLINGFREQUENCY'] = $params['installments'];
         $result = $this->invokeAPI($args);
         CRM_Core_Error::debug_var('$result', $result);
         if (is_a($result, 'CRM_Core_Error')) {
             return $result;
         }
         $message = "{$result['ack']}: profileid={$result['profileid']}";
         return TRUE;
     }
     return FALSE;
 }
Пример #28
0
 /**
  * Function that takes an address object and gets the latitude / longitude for this
  * address. Note that at a later stage, we could make this function also clean up
  * the address into a more valid format
  *
  * @param array $values
  * @param bool $stateName
  *
  * @return bool
  *   true if we modified the address, false otherwise
  */
 public static function format(&$values, $stateName = FALSE)
 {
     // we need a valid country, else we ignore
     if (empty($values['country'])) {
         return FALSE;
     }
     $config = CRM_Core_Config::singleton();
     $add = '';
     if (!empty($values['street_address'])) {
         $add = urlencode(str_replace('', '+', $values['street_address']));
         $add .= ',+';
     }
     $city = CRM_Utils_Array::value('city', $values);
     if ($city) {
         $add .= '+' . urlencode(str_replace('', '+', $city));
         $add .= ',+';
     }
     if (!empty($values['state_province'])) {
         if (!empty($values['state_province_id'])) {
             $stateProvince = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_StateProvince', $values['state_province_id']);
         } else {
             if (!$stateName) {
                 $stateProvince = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_StateProvince', $values['state_province'], 'name', 'abbreviation');
             } else {
                 $stateProvince = $values['state_province'];
             }
         }
         // dont add state twice if replicated in city (happens in NZ and other countries, CRM-2632)
         if ($stateProvince != $city) {
             $add .= '+' . urlencode(str_replace('', '+', $stateProvince));
             $add .= ',+';
         }
     }
     if (!empty($values['postal_code'])) {
         $add .= '+' . urlencode(str_replace('', '+', $values['postal_code']));
         $add .= ',+';
     }
     if (!empty($values['country'])) {
         $add .= '+' . urlencode(str_replace('', '+', $values['country']));
     }
     $query = 'http://' . self::$_server . self::$_uri . $add;
     require_once 'HTTP/Request.php';
     $request = new HTTP_Request($query);
     $request->sendRequest();
     $string = $request->getResponseBody();
     libxml_use_internal_errors(TRUE);
     $xml = @simplexml_load_string($string);
     if ($xml === FALSE) {
         // account blocked maybe?
         CRM_Core_Error::debug_var('Geocoding failed.  Message from Google:', $string);
         return FALSE;
     }
     if (isset($xml->status)) {
         if ($xml->status == 'OK' && is_a($xml->result->geometry->location, 'SimpleXMLElement')) {
             $ret = $xml->result->geometry->location->children();
             if ($ret->lat && $ret->lng) {
                 $values['geo_code_1'] = (double) $ret->lat;
                 $values['geo_code_2'] = (double) $ret->lng;
                 return TRUE;
             }
         } elseif ($xml->status == 'OVER_QUERY_LIMIT') {
             CRM_Core_Error::debug_var('Geocoding failed. Message from Google: ', (string) $xml->status);
             $values['geo_code_1'] = $values['geo_code_2'] = 'null';
             $values['geo_code_error'] = $xml->status;
             return FALSE;
         }
     }
     // reset the geo code values if we did not get any good values
     $values['geo_code_1'] = $values['geo_code_2'] = 'null';
     return FALSE;
 }
Пример #29
0
 /**
  * This is the main function to call. It should be sufficient to instantiate the class
  * (with the input parameters) & call this & all will be done
  *
  * @todo the references to POST throughout this class need to be removed
  * @return void|boolean|Ambigous <void, boolean>
  */
 function main()
 {
     CRM_Core_Error::debug_var('GET', $_GET, TRUE, TRUE);
     CRM_Core_Error::debug_var('POST', $_POST, TRUE, TRUE);
     if ($this->_isPaymentExpress) {
         $this->handlePaymentExpress();
         return;
     }
     $objects = $ids = $input = array();
     $this->_component = $input['component'] = self::getValue('m');
     $input['invoice'] = self::getValue('i', TRUE);
     // get the contribution and contact ids from the GET params
     $ids['contact'] = self::getValue('c', TRUE);
     $ids['contribution'] = self::getValue('b', TRUE);
     $this->getInput($input, $ids);
     if ($this->_component == 'event') {
         $ids['event'] = self::getValue('e', TRUE);
         $ids['participant'] = self::getValue('p', TRUE);
         $ids['contributionRecur'] = self::getValue('r', FALSE);
     } else {
         // get the optional ids
         //@ how can this not be broken retrieving from GET as we are dealing with a POST request?
         // copy & paste? Note the retrieve function now uses data from _REQUEST so this will be included
         $ids['membership'] = self::retrieve('membershipID', 'Integer', 'GET', FALSE);
         $ids['contributionRecur'] = self::getValue('r', FALSE);
         $ids['contributionPage'] = self::getValue('p', FALSE);
         $ids['related_contact'] = self::retrieve('relatedContactID', 'Integer', 'GET', FALSE);
         $ids['onbehalf_dupe_alert'] = self::retrieve('onBehalfDupeAlert', 'Integer', 'GET', FALSE);
     }
     if (!$ids['membership'] && $ids['contributionRecur']) {
         $sql = "\n    SELECT m.id\n      FROM civicrm_membership m\nINNER JOIN civicrm_membership_payment mp ON m.id = mp.membership_id AND mp.contribution_id = %1\n     WHERE m.contribution_recur_id = %2\n     LIMIT 1";
         $sqlParams = array(1 => array($ids['contribution'], 'Integer'), 2 => array($ids['contributionRecur'], 'Integer'));
         if ($membershipId = CRM_Core_DAO::singleValueQuery($sql, $sqlParams)) {
             $ids['membership'] = $membershipId;
         }
     }
     $paymentProcessorID = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType', 'PayPal', 'id', 'name');
     if (!$this->validateData($input, $ids, $objects, TRUE, $paymentProcessorID)) {
         return FALSE;
     }
     self::$_paymentProcessor =& $objects['paymentProcessor'];
     //?? how on earth would we not have component be one of these?
     // they are the only valid settings & this IPN file can't even be called without one of them
     // grepping for this class doesn't find other paths to call this class
     if ($this->_component == 'contribute' || $this->_component == 'event') {
         if ($ids['contributionRecur']) {
             // check if first contribution is completed, else complete first contribution
             $first = TRUE;
             if ($objects['contribution']->contribution_status_id == 1) {
                 $first = FALSE;
             }
             return $this->recur($input, $ids, $objects, $first);
         } else {
             return $this->single($input, $ids, $objects, FALSE, FALSE);
         }
     } else {
         return $this->single($input, $ids, $objects, FALSE, FALSE);
     }
 }
Пример #30
0
 /**
  * Set Added status for group. If group is not assigned to contact, It is added.
  *
  * @param int $contact_id
  * @param int $group_id
  *
  * @throws CiviCRM_API3_Exception
  */
 public function setGroupStatus($contact_id, $group_id)
 {
     $result = civicrm_api3('GroupContact', 'get', array('sequential' => 1, 'contact_id' => $contact_id, 'group_id' => $group_id, 'status' => "Pending"));
     CRM_Core_Error::debug_var('$resultGroupContact-get', $result, false, true);
     if ($result['count'] == 1) {
         $params = array('id' => $result["id"], 'status' => "Added");
     } else {
         $params = array('sequential' => 1, 'contact_id' => $contact_id, 'group_id' => $group_id, 'status' => "Added");
     }
     CRM_Core_Error::debug_var('$paramsGroupContact-create', $params, false, true);
     $result = civicrm_api3('GroupContact', 'create', $params);
     CRM_Core_Error::debug_var('$resultGroupContact-create', $result, false, true);
 }