/** * run this page (figure out the action needed and perform it). * * @return void */ function run() { if (!CRM_Core_Permission::check('administer Reports')) { return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/report/list', "reset=1")); } $optionVal = CRM_Report_Utils_Report::getValueFromUrl(); $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value', 'String', FALSE); $extKey = strpos($templateInfo['name'], '.'); $reportClass = NULL; if ($extKey !== FALSE) { $ext = new CRM_Core_Extensions(); $reportClass = $ext->keyToClass($templateInfo['name'], 'report'); $templateInfo['name'] = $reportClass; } if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form') || !is_null($reportClass)) { CRM_Utils_System::setTitle($templateInfo['label'] . ' - Template'); $this->assign('reportTitle', $templateInfo['label']); $session = CRM_Core_Session::singleton(); $session->set('reportDescription', $templateInfo['description']); $wrapper = new CRM_Utils_Wrapper(); return $wrapper->run($templateInfo['name'], NULL, NULL); } if ($optionVal) { CRM_Core_Session::setStatus(ts('Could not find the report template. Make sure the report template is registered and / or url is correct.')); } return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/report/list', "reset=1")); }
/** * Obtains the group name from url and sets the title. * * @return void * @access public * */ function preProcess() { require_once 'CRM/Core/Extensions.php'; $ext = new CRM_Core_Extensions(); if ($ext->enabled === TRUE) { self::$_extInstalled = $ext->getInstalled(TRUE); self::$_extNotInstalled = $ext->getNotInstalled(); } CRM_Utils_System::setTitle(ts('CiviCRM Extensions')); }
function getTemplateFileName() { $ext = new CRM_Core_Extensions(); if ($ext->isExtensionClass(CRM_Utils_System::getClassName($this->_customClass))) { $fileName = $ext->getTemplatePath(CRM_Utils_System::getClassName($this->_customClass)) . '/' . $ext->getTemplateName(CRM_Utils_System::getClassName($this->_customClass)); } else { $fileName = $this->_customClass->templateFile(); } return $fileName ? $fileName : parent::getTemplateFileName(); }
function getTemplateFileName() { require_once 'CRM/Core/Extensions.php'; $ext = new CRM_Core_Extensions(); if ($ext->isExtensionClass(CRM_Utils_System::getClassName($this->_customClass))) { $filename = $ext->getTemplatePath(CRM_Utils_System::getClassName($this->_customClass)); } else { $fileName = $this->_customClass->templateFile(); } return $fileName ? $fileName : parent::getTemplateFileName(); }
/** * Obtains the group name from url and sets the title. * * @return void * @access public * */ function preProcess() { $ext = new CRM_Core_Extensions(); if ($ext->enabled === TRUE) { self::$_extensions = $ext->getExtensions(); } CRM_Utils_System::setTitle(ts('CiviCRM Extensions')); $destination = CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1'); $destination = urlencode($destination); $this->assign('destination', $destination); }
/** * run this page (figure out the action needed and perform it). * * @return void */ function run() { $instanceId = CRM_Report_Utils_Report::getInstanceID(); if (!$instanceId) { $instanceId = CRM_Report_Utils_Report::getInstanceIDForPath(); } $action = CRM_Utils_Request::retrieve('action', 'String', $this); $optionVal = CRM_Report_Utils_Report::getValueFromUrl($instanceId); $reportUrl = CRM_Utils_System::url('civicrm/report/list', "reset=1"); if ($action & CRM_Core_Action::DELETE) { if (!CRM_Core_Permission::check('administer Reports')) { $statusMessage = ts('You do not have permission to Delete Report.'); CRM_Core_Error::statusBounce($statusMessage, $reportUrl); } $navId = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_Instance', $instanceId, 'navigation_id', 'id'); CRM_Report_BAO_Instance::delete($instanceId); //delete navigation if exists if ($navId) { CRM_Core_BAO_Navigation::processDelete($navId); CRM_Core_BAO_Navigation::resetNavigation(); } CRM_Core_Session::setStatus(ts('Selected Instance has been deleted.')); } else { $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value'); if (empty($templateInfo)) { CRM_Core_Session::setStatus(ts('Could not find template for the instance.')); return; } $extKey = strpos($templateInfo['name'], '.'); $reportClass = NULL; if ($extKey !== FALSE) { $ext = new CRM_Core_Extensions(); $reportClass = $ext->keyToClass($templateInfo['name'], 'report'); $templateInfo['name'] = $reportClass; } if (strstr($templateInfo['name'], '_Form') || !is_null($reportClass)) { $instanceInfo = array(); CRM_Report_BAO_Instance::retrieve(array('id' => $instanceId), $instanceInfo); if (!empty($instanceInfo['title'])) { CRM_Utils_System::setTitle($instanceInfo['title']); $this->assign('reportTitle', $instanceInfo['title']); } else { CRM_Utils_System::setTitle($templateInfo['label']); $this->assign('reportTitle', $templateInfo['label']); } $wrapper = new CRM_Utils_Wrapper(); return $wrapper->run($templateInfo['name'], NULL, NULL); } CRM_Core_Session::setStatus(ts('Could not find template for the instance.')); } return CRM_Utils_System::redirect($reportUrl); }
function __construct() { $ext = CRM_Core_Extensions::singleton(); self::$_extensions = $ext->getExtensions(); $config = CRM_Core_Config::singleton(); $this->extDir = $config->extensionsDir; }
/** * Get a list of all known modules */ public static function getAll($fresh = FALSE) { static $result; if ($fresh || !is_array($result)) { $result = array(); $ext = new CRM_Core_Extensions(); if ($ext->enabled) { $result = array_merge($result, $ext->getModules()); } $config = CRM_Core_Config::singleton(); if (is_callable(array($config->userSystem, 'getModules'))) { $result = array_merge($result, $config->userSystem->getModules()); } } return $result; }
static function details($csID, $ssID = null, $gID = null) { $error = array(null, null, null); if (!$csID && !$ssID && !$gID) { return $error; } $customSearchID = $csID; $formValues = array(); if ($ssID || $gID) { if ($gID) { $ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $gID, 'saved_search_id'); } $formValues = CRM_Contact_BAO_SavedSearch::getFormValues($ssID); $customSearchID = CRM_Utils_Array::value('customSearchID', $formValues); } if (!$customSearchID) { return $error; } // check that the csid exists in the db along with the right file // and implements the right interface require_once 'CRM/Core/OptionGroup.php'; $customSearchClass = CRM_Core_OptionGroup::getLabel('custom_search', $customSearchID); if (!$customSearchClass) { return $error; } require_once 'CRM/Core/Extensions.php'; $ext = new CRM_Core_Extensions(); if (!$ext->isExtensionKey($customSearchClass)) { $customSearchFile = str_replace('_', DIRECTORY_SEPARATOR, $customSearchClass) . '.php'; } else { $customSearchFile = $ext->keyToPath($customSearchClass); $customSearchClass = $ext->keyToClass($customSearchClass); } $error = (include_once $customSearchFile); if ($error == false) { CRM_Core_Error::fatal('Custom search file: ' . $customSearchFile . ' does not exist. Please verify your custom search settings in CiviCRM administrative panel.'); } return array($customSearchID, $customSearchClass, $formValues); }
/** * 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]; }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { CRM_Utils_System::flushCache(); if ($this->_action & CRM_Core_Action::DELETE) { $ext = new CRM_Core_Extensions(); if ($ext->uninstall($this->_id, $this->_key)) { CRM_Core_Session::setStatus(ts('Extension has been uninstalled.')); } } if ($this->_action & CRM_Core_Action::ADD) { $ext = new CRM_Core_Extensions(); $ext->install($this->_id, $this->_key); CRM_Core_Session::setStatus(ts('Extension has been installed.')); } if ($this->_action & CRM_Core_Action::ENABLE) { $ext = new CRM_Core_Extensions(); $ext->enable($this->_id, $this->_key); CRM_Core_Session::setStatus(ts('Extension has been enabled.')); } if ($this->_action & CRM_Core_Action::DISABLE) { $ext = new CRM_Core_Extensions(); $ext->disable($this->_id, $this->_key); CRM_Core_Session::setStatus(ts('Extension has been disabled.')); } if ($this->_action & CRM_Core_Action::UPDATE) { $ext = new CRM_Core_Extensions(); $ext->upgrade($this->_id, $this->_key); CRM_Core_Session::setStatus(ts('Extension has been upgraded.')); } CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1&action=browse')); }
/** * Uninstall an extension * * @param array $params input parameters * - key: string, eg "com.example.myextension" * - keys: array of string, eg array("com.example.myextension1", "com.example.myextension2") * using 'keys' should be more performant than making multiple API calls with 'key' * - removeFiles: bool, whether to remove source tree; default: FALSE * * @return array API result * @static void * @access public * @example ExtensionUninstall.php * */ function civicrm_api3_extension_uninstall($params) { $keys = _civicrm_api3_getKeys($params); if (count($keys) == 0) { return civicrm_api3_create_success(); } $ext = new CRM_Core_Extensions(); $exts = $ext->getExtensions(); foreach ($keys as $key) { if (!$ext->isEnabled()) { return civicrm_api3_create_error('Extension support is not enabled'); } elseif (!$ext->isExtensionKey($key) || !array_key_exists($key, $exts)) { // FIXME: is this necesary? if $key is not in $exts, can't we assume it's uninstalled return civicrm_api3_create_error('Invalid extension key: ' . $key); } elseif ($exts[$key]->status != 'installed') { return civicrm_api3_create_error('Can only uninstall extensions which have been previously installed'); } elseif ($exts[$key]->is_active == TRUE) { return civicrm_api3_create_error('Extension must be disabled before uninstalling'); } else { // pre-condition: installed and inactive $removeFiles = CRM_Utils_Array::value('removeFiles', $params, FALSE); $ext->uninstall(NULL, $key, $removeFiles); // FIXME: only rebuild cache one time } } return civicrm_api3_create_success(); }
/** * 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 );'); } }
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(); }
/** * Use the form name to create the tpl file name * * @return string * @access public */ function getTemplateFileName() { require_once 'CRM/Core/Extensions.php'; $ext = new CRM_Core_Extensions(); if ($ext->isExtensionClass(CRM_Utils_System::getClassName($this))) { $filename = $ext->getTemplateName(CRM_Utils_System::getClassName($this)); $tplname = $ext->getTemplatePath(CRM_Utils_System::getClassName($this)) . DIRECTORY_SEPARATOR . $filename; } else { $tplname = str_replace('_', DIRECTORY_SEPARATOR, CRM_Utils_System::getClassName($this)) . '.tpl'; } return $tplname; }
/** * 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__); } }
/** * Sets extension's record active or disabled. * * @access public * @param int $id id of option value record * @param boolean $is_active active state * @return mixed result of CRM_Core_DAO::setFieldValue */ public static function setIsActive($id, $is_active) { $extensions = new CRM_Core_Extensions(); $e = $extensions->getExtensionsByKey(); foreach ($e as $key => $eo) { if ($eo->id == $id) { $ext = $eo; } } $is_active ? $ext->enable() : $ext->disable(); return true; }
/** * 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}); } }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { CRM_Utils_System::flushCache(); if ($this->_action & CRM_Core_Action::DELETE) { require_once 'CRM/Core/Extensions.php'; $ext = new CRM_Core_Extensions(); $ext->uninstall($this->_id, $this->_key); CRM_Core_Session::setStatus(ts('Extension has been uninstalled.')); } if ($this->_action & CRM_Core_Action::ADD) { require_once 'CRM/Core/Extensions.php'; $ext = new CRM_Core_Extensions(); $ext->install($this->_id, $this->_key); CRM_Core_Session::setStatus(ts('Extension has been installed.')); } }
/** * 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(); } }