/** * Class constructor * * @param array $formValues array of form values imported * @param array $params array of parameters for query * @param int $action - action of search basic or advanced. * * @return CRM_Contact_Selector * @access public */ function __construct($customSearchClass, $formValues = null, $params = null, $returnProperties = null, $action = CRM_Core_Action::NONE, $includeContactIds = false, $searchChildGroups = true, $searchContext = 'search') { $this->_customSearchClass = $customSearchClass; $this->_formValues = $formValues; $this->_includeContactIds = $includeContactIds; require_once 'CRM/Core/Extensions.php'; $ext = new CRM_Core_Extensions(); if (!$ext->isExtensionKey($customSearchClass)) { if ($ext->isExtensionClass($customSearchClass)) { $customSearchFile = $ext->classToPath($customSearchClass); require_once $customSearchFile; } else { require_once str_replace('_', DIRECTORY_SEPARATOR, $customSearchClass) . '.php'; } eval('$this->_search = new ' . $customSearchClass . '( $formValues );'); } else { $customSearchFile = $ext->keyToPath($customSearchClass, 'search'); require_once $customSearchFile; eval('$this->_search = new ' . $ext->keyToClass($customSearchClass, 'search') . '( $formValues );'); } }
/** * add pages to the controller. Note that the controller does not really care * the order in which the pages are added * * @param object $stateMachine the state machine object * @param int $action the mode in which the state machine is operating * typicaly this will be add/view/edit * * @return void * @access public * */ function addPages(&$stateMachine, $action = CRM_Core_Action::NONE) { $pages = $stateMachine->getPages(); foreach ($pages as $name => $value) { $className = CRM_Utils_Array::value('className', $value, $name); $title = CRM_Utils_Array::value('title', $value); $options = CRM_Utils_Array::value('options', $value); $stateName = CRM_Utils_String::getClassName($className); if (CRM_Utils_Array::value('className', $value)) { $formName = $name; } else { $formName = CRM_Utils_String::getClassName($name); } require_once 'CRM/Core/Extensions.php'; $ext = new CRM_Core_Extensions(); if ($ext->isExtensionClass($className)) { require_once $ext->classToPath($className); } else { require_once str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; } ${$stateName} = new $className($stateMachine->find($className), $action, 'post', $formName); if ($title) { ${$stateName}->setTitle($title); } if ($options) { ${$stateName}->setOptions($options); } $this->addPage(${$stateName}); $this->addAction($stateName, new HTML_QuickForm_Action_Direct()); //CRM-6342 -we need kill the reference here, //as we have deprecated reference object creation. unset(${$stateName}); } }
/** * singleton function used to manage this object * * @param string $mode the mode of operation: live or test * * @return object * @static * */ static function &singleton($mode = 'test', &$paymentProcessor, &$paymentForm = null, $force = false) { $cacheKey = "{$mode}_{$paymentProcessor['id']}_" . (int) isset($paymentForm); if (!isset(self::$_singleton[$cacheKey]) || $force) { $config = CRM_Core_Config::singleton(); require_once 'CRM/Core/Extensions.php'; $ext = new CRM_Core_Extensions(); if ($ext->isExtensionKey($paymentProcessor['class_name'])) { $paymentClass = $ext->keyToClass($paymentProcessor['class_name'], 'payment'); require_once $ext->classToPath($paymentClass); } else { $paymentClass = "CRM_Core_" . $paymentProcessor['class_name']; require_once str_replace('_', DIRECTORY_SEPARATOR, $paymentClass) . '.php'; } //load the object. self::$_singleton[$cacheKey] = eval('return ' . $paymentClass . '::singleton( $mode, $paymentProcessor );'); //load the payment form for required processor. if ($paymentForm !== null) { self::$_singleton[$cacheKey]->setForm($paymentForm); } } return self::$_singleton[$cacheKey]; }
/** * Payment callback handler * Load requested payment processor and call that processor's handle<$method> method * * @public */ static function handlePaymentMethod($method, $params = array()) { if (!isset($params['processor_name'])) { CRM_Core_Error::fatal("Missing 'processor_name' param for payment callback"); } // Query db for processor .. $mode = @$params['mode']; $dao = CRM_Core_DAO::executeQuery("\n SELECT ppt.class_name, ppt.name as processor_name, pp.id AS processor_id\n FROM civicrm_payment_processor_type ppt\n INNER JOIN civicrm_payment_processor pp\n ON pp.payment_processor_type = ppt.name\n AND pp.is_active\n AND pp.is_test = %1\n WHERE ppt.name = %2 \n ", array(1 => array($mode == 'test' ? 1 : 0, 'Integer'), 2 => array($params['processor_name'], 'String'))); // Check whether we found anything at all .. if (!$dao->N) { CRM_Core_Error::fatal("No active instances of the '{$params['processor_name']}' payment processor were found."); } $method = 'handle' . $method; $extension_instance_found = FALSE; // In all likelihood, we'll just end up with the one instance returned here. But it's // possible we may get more. Hence, iterate through all instances .. while ($dao->fetch()) { // Check pp is extension $ext = new CRM_Core_Extensions(); if ($ext->isExtensionKey($dao->class_name)) { $extension_instance_found = TRUE; $paymentClass = $ext->keyToClass($dao->class_name, 'payment'); require_once $ext->classToPath($paymentClass); } else { // Legacy instance - but there may also be an extension instance, so // continue on to the next instance and check that one. We'll raise an // error later on if none are found. continue; } $paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($dao->processor_id, $mode); // Should never be empty - we already established this processor_id exists and is active. if (empty($paymentProcessor)) { continue; } // Instantiate PP eval('$processorInstance = ' . $paymentClass . '::singleton( $mode, $paymentProcessor );'); // Does PP implement this method, and can we call it? if (!method_exists($processorInstance, $method) || !is_callable(array($processorInstance, $method))) { // No? This will be the case in all instances, so let's just die now // and not prolong the agony. CRM_Core_Error::fatal("Payment processor does not implement a '{$method}' method"); } // Everything, it seems, is ok - execute pp callback handler $processorInstance->{$method}(); } if (!$extension_instance_found) { CRM_Core_Error::fatal("No extension instances of the '{$params['processor_name']}' payment processor were found.<br />" . "{$method} method is unsupported in legacy payment processors."); } // Exit here on web requests, allowing just the plain text response to be echoed if ($method == 'handlePaymentNotification') { CRM_Utils_System::civiExit(); } }
/** * Function to run hooks in the payment processor class * Load requested payment processor and call the method specified. * * @param string $method - the method to call in the payment processor class * @private */ private function _runPaymentHook($method) { // Not concerned about performance at this stage, as these are seldomly performed tasks // (payment processor enable/disable/install/uninstall). May wish to implement some // kind of registry/caching system if more hooks are added. if (!isset($this->id) || empty($this->id)) { $this->id = 0; } $ext = new CRM_Core_Extensions(); $paymentClass = $ext->keyToClass($this->key, 'payment'); require_once $ext->classToPath($paymentClass); // See if we have any instances of this PP defined .. if ($this->id && ($processor_id = CRM_Core_DAO::singleValueQuery("\n SELECT pp.id\n FROM civicrm_extension ext\n INNER JOIN civicrm_payment_processor pp\n ON pp.payment_processor_type = ext.name\n WHERE ext.type = 'payment'\n AND ext.id = %1\n\n ", array(1 => array($this->id, 'Integer'))))) { // If so, load params in the usual way .. $paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($processor_id, NULL); } else { // Otherwise, do the best we can to construct some .. $dao = CRM_Core_DAO::executeQuery("\n SELECT ppt.*\n FROM civicrm_extension ext\n INNER JOIN civicrm_payment_processor_type ppt\n ON ppt.name = ext.name\n WHERE ext.name = %1\n AND ext.type = 'payment'\n ", array(1 => array($this->name, 'String'))); if ($dao->fetch()) { $paymentProcessor = array('id' => -1, 'name' => $dao->title, 'payment_processor_type' => $dao->name, 'user_name' => 'nothing', 'password' => 'nothing', 'signature' => '', 'url_site' => $dao->url_site_default, 'url_api' => $dao->url_api_default, 'url_recur' => $dao->url_recur_default, 'url_button' => $dao->url_button_default, 'subject' => '', 'class_name' => $dao->class_name, 'is_recur' => $dao->is_recur, 'billing_mode' => $dao->billing_mode, 'payment_type' => $dao->payment_type); } else { CRM_Core_Error::fatal("Unable to find payment processor in " . __CLASS__ . '::' . __METHOD__); } } // In the case of uninstall, check for instances of PP first. // Don't run hook if any are found. if ($method == 'uninstall' && $paymentProcessor['id'] > 0) { return; } switch ($method) { case 'install': case 'uninstall': case 'enable': case 'disable': // Instantiate PP eval('$processorInstance = ' . $paymentClass . '::singleton( null, $paymentProcessor );'); // Does PP implement this method, and can we call it? if (method_exists($processorInstance, $method) && is_callable(array($processorInstance, $method))) { // If so, call it ... $processorInstance->{$method}(); } break; default: CRM_Core_Session::setStatus("Unrecognized payment hook ({$method}) in " . __CLASS__ . '::' . __METHOD__); } }
function exportCustom($customSearchClass, $formValues, $order) { require_once "CRM/Core/Extensions.php"; $ext = new CRM_Core_Extensions(); if (!$ext->isExtensionClass($customSearchClass)) { require_once str_replace('_', DIRECTORY_SEPARATOR, $customSearchClass) . '.php'; } else { require_once $ext->classToPath($customSearchClass); } eval('$search = new ' . $customSearchClass . '( $formValues );'); $includeContactIDs = false; if ($formValues['radio_ts'] == 'ts_sel') { $includeContactIDs = true; } $sql = $search->all(0, 0, $order, $includeContactIDs); $columns = $search->columns(); $header = array_keys($columns); $fields = array_values($columns); $rows = array(); $dao = CRM_Core_DAO::executeQuery($sql); $alterRow = false; if (method_exists($search, 'alterRow')) { $alterRow = true; } while ($dao->fetch()) { $row = array(); foreach ($fields as $field) { $row[$field] = $dao->{$field}; } if ($alterRow) { $search->alterRow($row); } $rows[] = $row; } require_once 'CRM/Core/Report/Excel.php'; CRM_Core_Report_Excel::writeCSVFile(self::getExportFileName(), $header, $rows); CRM_Utils_System::civiExit(); }