/** * Run upgrade. * * @throws \Exception */ public function run() { // lets get around the time limit issue if possible for upgrades if (!ini_get('safe_mode')) { set_time_limit(0); } Civi::resources()->addStyleFile('civicrm', 'css/admin.css'); $upgrade = new CRM_Upgrade_Form(); list($currentVer, $latestVer) = $upgrade->getUpgradeVersions(); CRM_Utils_System::setTitle(ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer))); $template = CRM_Core_Smarty::singleton(); $template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer))); $template->assign('cancelURL', CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); $action = CRM_Utils_Array::value('action', $_REQUEST, 'intro'); switch ($action) { case 'intro': $this->runIntro(); break; case 'begin': $this->runBegin(); break; case 'finish': $this->runFinish(); break; default: CRM_Core_Error::fatal(ts('Unrecognized upgrade action')); } }
/** * Compute any messages which should be displayed before upgrade. * * @param string $preUpgradeMessage * alterable. * @param $currentVer * @param $latestVer */ public static function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVer) { if (version_compare(phpversion(), self::MIN_RECOMMENDED_PHP_VER) < 0) { $preUpgradeMessage .= '<p>' . ts('This webserver is running an outdated version of PHP (%1). It is strongly recommended to upgrade to PHP %2 or later, as older versions can present a security risk.', array(1 => phpversion(), 2 => self::MIN_RECOMMENDED_PHP_VER)) . '</p>'; } // http://issues.civicrm.org/jira/browse/CRM-13572 // Depending on how the code was upgraded, some sites may still have copies of old // source files left behind. This is often a forgivable offense, but it's quite // dangerous for CIVI-SA-2013-001. global $civicrm_root; $ofcFile = "{$civicrm_root}/packages/OpenFlashChart/php-ofc-library/ofc_upload_image.php"; if (file_exists($ofcFile)) { if (@unlink($ofcFile)) { $preUpgradeMessage .= '<br />' . ts('This system included an outdated, insecure script (%1). The file was automatically deleted.', array(1 => $ofcFile)); } else { $preUpgradeMessage .= '<br />' . ts('This system includes an outdated, insecure script (%1). Please delete it.', array(1 => $ofcFile)); } } if (Civi::settings()->get('enable_innodb_fts')) { // The FTS indexing feature dynamically manipulates the schema which could // cause conflicts with other layers that manipulate the schema. The // simplest thing is to turn it off and back on. // It may not always be necessary to do this -- but I doubt we're going to test // systematically in future releases. When it is necessary, one could probably // ignore the matter and simply run CRM_Core_InnoDBIndexer::fixSchemaDifferences // after the upgrade. But that's speculative. For now, we'll leave this // advanced feature in the hands of the sysadmin. $preUpgradeMessage .= '<br />' . ts('This database uses InnoDB Full Text Search for optimized searching. The upgrade procedure has not been tested with this feature. You should disable (and later re-enable) the feature by navigating to "Administer => System Settings => Miscellaneous".'); } }
/** * Add an ics attachment to the input array. * * @param array $attachments * Reference to array in same format returned from CRM_Core_BAO_File::getEntityFile(). * @param array $contacts * Array of contacts (attendees). * * @return string|null * Array index of the added attachment in the $attachments array, else NULL. */ public function addAttachment(&$attachments, $contacts) { // Check preferences setting if (Civi::settings()->get('activity_assignee_notification_ics')) { $config =& CRM_Core_Config::singleton(); $this->icsfile = tempnam($config->customFileUploadDir, 'ics'); if ($this->icsfile !== FALSE) { rename($this->icsfile, $this->icsfile . '.ics'); $this->icsfile .= '.ics'; $icsFileName = basename($this->icsfile); // get logged in user's primary email // TODO: Is there a better way to do this? $organizer = $this->getPrimaryEmail(); $template = CRM_Core_Smarty::singleton(); $template->assign('activity', $this->activity); $template->assign('organizer', $organizer); $template->assign('contacts', $contacts); $template->assign('timezone', date_default_timezone_get()); $calendar = $template->fetch('CRM/Activity/Calendar/ICal.tpl'); if (file_put_contents($this->icsfile, $calendar) !== FALSE) { if (empty($attachments)) { $attachments = array(); } $attachments['activity_ics'] = array('mime_type' => 'text/calendar', 'fileName' => $icsFileName, 'cleanName' => $icsFileName, 'fullPath' => $this->icsfile); return 'activity_ics'; } } } return NULL; }
/** * WARNING: This interface may change. * * This provides information about the setting - similar to the fields concept for DAO information. * As the setting is serialized code creating validation setting input needs to know the data type * This also helps move information out of the form layer into the data layer where people can interact with * it via the API or other mechanisms. In order to keep this consistent it is important the form layer * also leverages it. * * Note that this function should never be called when using the runtime getvalue function. Caching works * around the expectation it will be called during setting administration * * Function is intended for configuration rather than runtime access to settings * * The following params will filter the result. If none are passed all settings will be returns * * @param array $filters * @param int $domainID * * @return array * the following information as appropriate for each setting * - name * - type * - default * - add (CiviCRM version added) * - is_domain * - is_contact * - description * - help_text */ public static function getMetadata($filters = array(), $domainID = NULL) { if ($domainID === NULL) { $domainID = \CRM_Core_Config::domainID(); } $cache = \Civi::cache('settings'); $cacheString = 'settingsMetadata_' . $domainID . '_'; // the caching into 'All' seems to be a duplicate of caching to // settingsMetadata__ - I think the reason was to cache all settings as defined & then those altered by a hook $settingsMetadata = $cache->get($cacheString); $cached = is_array($settingsMetadata); if (!$cached) { $settingsMetadata = $cache->get(self::ALL); if (empty($settingsMetadata)) { global $civicrm_root; $metaDataFolders = array($civicrm_root . '/settings'); \CRM_Utils_Hook::alterSettingsFolders($metaDataFolders); $settingsMetadata = self::loadSettingsMetaDataFolders($metaDataFolders); $cache->set(self::ALL, $settingsMetadata); } } \CRM_Utils_Hook::alterSettingsMetaData($settingsMetadata, $domainID, NULL); if (!$cached) { $cache->set($cacheString, $settingsMetadata); } self::_filterSettingsSpecification($filters, $settingsMetadata); return $settingsMetadata; }
/** * @param array $cxn * @param string $entity * @param string $action * @param array $params * @return mixed */ public static function route($cxn, $entity, $action, $params) { $SUPER_PERM = array('administer CiviCRM'); require_once 'api/v3/utils.php'; // FIXME: Shouldn't the X-Forwarded-Proto check be part of CRM_Utils_System::isSSL()? if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enableSSL') && !CRM_Utils_System::isSSL() && strtolower(CRM_Utils_Array::value('X_FORWARDED_PROTO', CRM_Utils_System::getRequestHeaders())) != 'https') { return civicrm_api3_create_error('System policy requires HTTPS.'); } // Note: $cxn and cxnId are authenticated before router is called. $dao = new CRM_Cxn_DAO_Cxn(); $dao->cxn_id = $cxn['cxnId']; if (empty($cxn['cxnId']) || !$dao->find(TRUE) || !$dao->cxn_id) { return civicrm_api3_create_error('Failed to lookup connection authorizations.'); } if (!$dao->is_active) { return civicrm_api3_create_error('Connection is inactive.'); } if (!is_string($entity) || !is_string($action) || !is_array($params)) { return civicrm_api3_create_error('API parameters are malformed.'); } if (empty($cxn['perm']['api']) || !is_array($cxn['perm']['api']) || empty($cxn['perm']['grant']) || !(is_array($cxn['perm']['grant']) || is_string($cxn['perm']['grant']))) { return civicrm_api3_create_error('Connection has no permissions.'); } $whitelist = \Civi\API\WhitelistRule::createAll($cxn['perm']['api']); \Civi::service('dispatcher')->addSubscriber(new \Civi\API\Subscriber\WhitelistSubscriber($whitelist)); CRM_Core_Config::singleton()->userPermissionTemp = new CRM_Core_Permission_Temp(); if ($cxn['perm']['grant'] === '*') { CRM_Core_Config::singleton()->userPermissionTemp->grant($SUPER_PERM); } else { CRM_Core_Config::singleton()->userPermissionTemp->grant($cxn['perm']['grant']); } $params['check_permissions'] = 'whitelist'; return civicrm_api($entity, $action, $params); }
/** * @param string $title * Title of the page. * @param int $mode * Mode of the page. * @param \CRM_Core_Resources|null $res * Resource manager. */ public function __construct($title = NULL, $mode = NULL, $res = NULL) { parent::__construct($title, $mode); $this->res = \CRM_Core_Resources::singleton(); $this->angular = \Civi::service('angular'); $this->region = \CRM_Utils_Request::retrieve('snippet', 'String') ? 'ajax-snippet' : 'html-header'; }
/** * Get available api actions. * * @param array $apiRequest * * @return array * @throws API_Exception */ function civicrm_api3_generic_getActions($apiRequest) { civicrm_api3_verify_mandatory($apiRequest, NULL, array('entity')); $mfp = \Civi::service('magic_function_provider'); $actions = $mfp->getActionNames($apiRequest['version'], $apiRequest['entity']); return civicrm_api3_create_success($actions, $apiRequest['params'], $apiRequest['entity'], 'getactions'); }
public function preProcess() { $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE); $this->_system = CRM_Utils_Request::retrieve('system', 'Boolean', $this, FALSE, TRUE); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'update'); if (isset($action)) { $this->assign('action', $action); } $session = CRM_Core_Session::singleton(); $this->_config = new CRM_Core_DAO(); if ($this->_system) { if (CRM_Core_Permission::check('administer CiviCRM')) { $this->_contactID = NULL; } else { CRM_Utils_System::fatal('You do not have permission to edit preferences'); } $this->_config->contact_id = NULL; } else { if (!$this->_contactID) { $this->_contactID = $session->get('userID'); if (!$this->_contactID) { CRM_Utils_System::fatal('Could not retrieve contact id'); } $this->set('cid', $this->_contactID); } $this->_config->contact_id = $this->_contactID; } $settings = Civi::settings(); foreach ($this->_varNames as $groupName => $settingNames) { foreach ($settingNames as $settingName => $options) { $this->_config->{$settingName} = $settings->get($settingName); } } $session->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1')); }
/** * Check whether the install has run before. * * Circa v4.7.betaX, we introduced a new mechanism for tracking installation * and firing a post-install event. However, it's fairly difficult to test the * edge-cases directly, so this canary should fire if there are any problems * in the design/implementation of the installation-tracker. * * This should not exist. It should be removed in a future version. * * @param \Civi\Core\Event\SystemInstallEvent $event * @throws \CRM_Core_Exception */ public static function check(SystemInstallEvent $event) { if (\CRM_Core_DAO::checkTableExists('civicrm_install_canary')) { throw new \CRM_Core_Exception("Found installation canary. This suggests that something went wrong with tracking installation process. Please post to forum or JIRA."); } \Civi::log()->info('Creating canary table'); \CRM_Core_DAO::executeQuery('CREATE TABLE civicrm_install_canary (id int(10) unsigned NOT NULL)'); }
/** * Obtains the group name from url and sets the title. */ public function preProcess() { Civi::resources()->addStyleFile('civicrm', 'css/admin.css'); CRM_Utils_System::setTitle(ts('CiviCRM Extensions')); $destination = CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1'); $destination = urlencode($destination); $this->assign('destination', $destination); }
/** * @param bool $fresh * @return CRM_Utils_QueryFormatter */ public static function singleton($fresh = FALSE) { if ($fresh || self::$singleton === NULL) { $mode = Civi::settings()->get('fts_query_mode'); self::$singleton = new CRM_Utils_QueryFormatter($mode); } return self::$singleton; }
/** * @param bool $fresh * @return CRM_Cxn_CiviCxnHttp */ public static function singleton($fresh = FALSE) { if (self::$singleton === NULL || $fresh) { $cache = CRM_Utils_Cache::create(array('name' => 'CiviCxnHttp', 'type' => Civi::settings()->get('debug_enabled') ? 'ArrayCache' : array('SqlGroup', 'ArrayCache'), 'prefetch' => FALSE)); self::$singleton = new CRM_Cxn_CiviCxnHttp($cache); } return self::$singleton; }
/** * Build all the data structures needed to build the form. */ public function preProcess() { $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE); $this->_searchKey = CRM_Utils_Request::retrieve('key', 'String', $this); // sort out whether it’s a delete-to-trash, delete-into-oblivion or restore (and let the template know) $values = $this->controller->exportValues(); $this->_skipUndelete = (CRM_Core_Permission::check('access deleted contacts') and (CRM_Utils_Request::retrieve('skip_undelete', 'Boolean', $this) or CRM_Utils_Array::value('task', $values) == CRM_Contact_Task::DELETE_PERMANENTLY)); $this->_restore = (CRM_Utils_Request::retrieve('restore', 'Boolean', $this) or CRM_Utils_Array::value('task', $values) == CRM_Contact_Task::RESTORE); if ($this->_restore && !CRM_Core_Permission::check('access deleted contacts')) { CRM_Core_Error::fatal(ts('You do not have permission to access this contact.')); } elseif (!CRM_Core_Permission::check('delete contacts')) { CRM_Core_Error::fatal(ts('You do not have permission to delete this contact.')); } $this->assign('trash', Civi::settings()->get('contact_undelete') and !$this->_skipUndelete); $this->assign('restore', $this->_restore); if ($this->_restore) { CRM_Utils_System::setTitle(ts('Restore Contact')); } if ($cid) { if (!CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::EDIT)) { CRM_Core_Error::fatal(ts('You do not have permission to delete this contact. Note: you can delete contacts if you can edit them.')); } elseif (CRM_Contact_BAO_Contact::checkDomainContact($cid)) { CRM_Core_Error::fatal(ts('This contact is a special one for the contact information associated with the CiviCRM installation for this domain. No one is allowed to delete it because the information is used for special system purposes.')); } $this->_contactIds = array($cid); $this->_single = TRUE; $this->assign('totalSelectedContacts', 1); } else { parent::preProcess(); } $this->_sharedAddressMessage = $this->get('sharedAddressMessage'); if (!$this->_restore && !$this->_sharedAddressMessage) { // we check for each contact for shared contact address $sharedContactList = array(); $sharedAddressCount = 0; foreach ($this->_contactIds as $contactId) { // check if a contact that is being deleted has any shared addresses $sharedAddressMessage = CRM_Core_BAO_Address::setSharedAddressDeleteStatus(NULL, $contactId, TRUE); if ($sharedAddressMessage['count'] > 0) { $sharedAddressCount += $sharedAddressMessage['count']; $sharedContactList = array_merge($sharedContactList, $sharedAddressMessage['contactList']); } } $this->_sharedAddressMessage = array('count' => $sharedAddressCount, 'contactList' => $sharedContactList); if ($sharedAddressCount > 0) { if (count($this->_contactIds) > 1) { // more than one contact deleted $message = ts('One of the selected contacts has an address record that is shared with 1 other contact.', array('plural' => 'One or more selected contacts have address records which are shared with %count other contacts.', 'count' => $sharedAddressCount)); } else { // only one contact deleted $message = ts('This contact has an address record which is shared with 1 other contact.', array('plural' => 'This contact has an address record which is shared with %count other contacts.', 'count' => $sharedAddressCount)); } CRM_Core_Session::setStatus($message . ' ' . ts('Shared addresses will not be removed or altered but will no longer be shared.'), ts('Shared Addesses Owner')); } // set in form controller so that queries are not fired again $this->set('sharedAddressMessage', $this->_sharedAddressMessage); } }
/** * @return array */ public function readActiveConfig() { if (!defined('CIVICRM_SETTINGS_PATH') || CIVICRM_SETTINGS_PATH !== $this->settingsFile) { return array(); } $paths = is_callable(array('Civi', 'paths')) ? \Civi::paths() : NULL; $data = array('CMS_DB_DSN' => CIVICRM_UF_DSN, 'CMS_VERSION' => \CRM_Core_Config::singleton()->userSystem->getVersion(), 'CIVI_DB_DSN' => CIVICRM_DSN, 'CIVI_SITE_KEY' => CIVICRM_SITE_KEY, 'CIVI_VERSION' => \CRM_Utils_System::version(), 'CIVI_SETTINGS' => CIVICRM_SETTINGS_PATH, 'CIVI_TEMPLATEC' => \CRM_Core_Config::singleton()->templateCompileDir, 'CIVI_UF' => \CRM_Core_Config::singleton()->userFramework, 'IS_INSTALLED' => '1', 'SITE_TYPE' => 'cv-auto', 'CMS_URL' => $paths ? \Civi::paths()->getUrl('[cms.root]/', 'absolute') : \CRM_Utils_System::languageNegotiationURL(\CRM_Utils_System::baseCMSURL(), FALSE, TRUE), 'CMS_ROOT' => $paths ? \Civi::paths()->getPath('[cms.root]/.') : \CRM_Core_Config::singleton()->userSystem->cmsRootPath(), 'CIVI_CORE' => $paths ? \Civi::paths()->getPath('[civicrm.root]/.') : $GLOBALS['civicrm_root'], 'CIVI_URL' => $paths ? \Civi::paths()->getUrl('[civicrm.root]/', 'absolute') : '', 'CIVI_FILES' => $paths ? \Civi::paths()->getPath('[civicrm.root]/.') : dirname(\CRM_Core_Config::singleton()->templateCompileDir)); return $data; }
/** * @param bool $fresh * @return CRM_Core_InnoDBIndexer */ public static function singleton($fresh = FALSE) { if ($fresh || self::$singleton === NULL) { $indices = array('civicrm_address' => array(array('street_address', 'city', 'postal_code')), 'civicrm_activity' => array(array('subject', 'details')), 'civicrm_contact' => array(array('sort_name', 'nick_name', 'display_name')), 'civicrm_contribution' => array(array('source', 'amount_level', 'trxn_Id', 'invoice_id')), 'civicrm_email' => array(array('email')), 'civicrm_membership' => array(array('source')), 'civicrm_note' => array(array('subject', 'note')), 'civicrm_participant' => array(array('source', 'fee_level')), 'civicrm_phone' => array(array('phone')), 'civicrm_tag' => array(array('name'))); $active = Civi::settings()->get('enable_innodb_fts'); self::$singleton = new self($active, $indices); } return self::$singleton; }
/** * Version 3 wrapper for civicrm_api. * * Throws exception. * * @param string $entity * Type of entities to deal with. * @param string $action * Create, get, delete or some special action name. * @param array $params * Array to be passed to function. * * @throws CiviCRM_API3_Exception * @return array */ function civicrm_api3($entity, $action, $params = array()) { $params['version'] = 3; $result = \Civi::service('civi_api_kernel')->runSafe($entity, $action, $params); if (is_array($result) && !empty($result['is_error'])) { throw new CiviCRM_API3_Exception($result['error_message'], CRM_Utils_Array::value('error_code', $result, 'undefined'), $result); } return $result; }
/** * @return array */ public function checkOutboundMail() { $messages = array(); $mailingInfo = Civi::settings()->get('mailing_backend'); if ($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_REDIRECT_TO_DB || defined('CIVICRM_MAIL_LOG') && CIVICRM_MAIL_LOG || $mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED || $mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_MOCK) { $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('Warning: Outbound email is disabled in <a href="%1">system settings</a>. Proper settings should be enabled on production servers.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))), ts('Outbound Email Disabled'), \Psr\Log\LogLevel::WARNING, 'fa-envelope'); } return $messages; }
/** * Set default values for the form. * * default values are retrieved from the database */ public function setDefaultValues() { $defaults = Civi::settings()->get('contribution_invoice_settings'); //CRM-16691: Changes made related to settings of 'CVV'. foreach ($this->_settings as $setting => $group) { $settingMetaData = civicrm_api3('setting', 'getfields', array('name' => $setting)); $defaults[$setting] = civicrm_api3('setting', 'getvalue', array('name' => $setting, 'group' => $group, 'default_value' => CRM_Utils_Array::value('default', $settingMetaData['values'][$setting]))); } return $defaults; }
/** * This virtual function is used to set the default values of * various form elements * * access public * * @return array * reference to the array of default values */ public function setDefaultValues() { // CRM-11761 retrieve user's activity filter preferences $defaults = array(); $userID = CRM_Core_Session::getLoggedInContactID(); if ($userID) { $defaults = Civi::service('settings_manager')->getBagByContact(NULL, $userID)->get('activity_tab_filter'); } return $defaults; }
/** * Run page. * * @return string */ public function run() { Civi::resources()->addStyleFile('civicrm', 'css/admin.css'); CRM_Utils_System::setTitle(ts("Configuration Checklist")); $this->assign('recentlyViewed', FALSE); $destination = CRM_Utils_System::url('civicrm/admin/configtask', 'reset=1', FALSE, NULL, FALSE); $destination = urlencode($destination); $this->assign('destination', $destination); return parent::run(); }
/** * Get the final, usable URL string (after interpolating any variables) * * @return FALSE|string */ public function gettingStartedUrl() { // Note: We use "*default*" as the default (rather than self::GETTING_STARTED_URL) so that future // developers can change GETTING_STARTED_URL without needing to update {civicrm_setting}. $url = Civi::settings()->get('gettingStartedUrl'); if ($url === '*default*') { $url = self::GETTING_STARTED_URL; } return CRM_Utils_System::evalUrl($url); }
/** * @return string|'' * Class name, or empty. */ public static function getProviderClass() { $settings = Civi::settings(); if ($settings->get('geoProvider')) { return 'CRM_Utils_Geocode_' . $settings->get('geoProvider'); } elseif ($settings->get('mapProvider')) { return 'CRM_Utils_Geocode_' . $settings->get('mapProvider'); } else { return ''; } }
/** * Run page. * * @return string */ public function run() { Civi::resources()->addStyleFile('civicrm', 'css/admin.css'); CRM_Utils_System::setTitle(ts("Configuration Checklist")); $this->assign('recentlyViewed', FALSE); $destination = CRM_Utils_System::url('civicrm/admin/configtask', 'reset=1', FALSE, NULL, FALSE); $destination = urlencode($destination); $this->assign('destination', $destination); $this->assign('registerSite', htmlspecialchars('https://civicrm.org/register-your-site?src=iam&sid=' . CRM_Utils_System::getSiteID())); return parent::run(); }
/** * This is some kind of special-purpose router/front-controller for the various profile URLs. * * @param array $args * this array contains the arguments of the url. * * @return string|void */ public function run($args = NULL) { if ($args[1] !== 'profile') { return NULL; } $secondArg = CRM_Utils_Array::value(2, $args, ''); if ($secondArg == 'map') { $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_Task_Map', ts('Map Contact'), NULL, FALSE, FALSE, TRUE); $gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET')); if (count($gids) > 1) { foreach ($gids as $pfId) { $profileIds[] = CRM_Utils_Type::escape($pfId, 'Positive'); } $controller->set('gid', $profileIds[0]); $profileGID = $profileIds[0]; } else { $profileGID = CRM_Utils_Request::retrieve('gid', 'Integer', $controller, TRUE); } // make sure that this profile enables mapping // CRM-8609 $isMap = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileGID, 'is_map'); if (!$isMap) { CRM_Core_Error::statusBounce(ts('This profile does not have the map feature turned on.')); } $profileView = CRM_Utils_Request::retrieve('pv', 'Integer', $controller, FALSE); // set the userContext stack $session = CRM_Core_Session::singleton(); if ($profileView) { $session->pushUserContext(CRM_Utils_System::url('civicrm/profile/view')); } else { $session->pushUserContext(CRM_Utils_System::url('civicrm/profile', 'force=1')); } $controller->set('profileGID', $profileGID); $controller->process(); return $controller->run(); } if ($secondArg == 'edit' || $secondArg == 'create') { $allowRemoteSubmit = Civi::settings()->get('remote_profile_submissions'); if ($secondArg == 'edit') { $controller = new CRM_Core_Controller_Simple('CRM_Profile_Form_Edit', ts('Create Profile'), CRM_Core_Action::UPDATE, FALSE, FALSE, $allowRemoteSubmit); $controller->set('edit', 1); $controller->process(); return $controller->run(); } else { $wrapper = new CRM_Utils_Wrapper(); return $wrapper->run('CRM_Profile_Form_Edit', ts('Create Profile'), array('mode' => CRM_Core_Action::ADD, 'ignoreKey' => $allowRemoteSubmit)); } } if ($secondArg == 'view' || empty($secondArg)) { $page = new CRM_Profile_Page_Listings(); return $page->run(); } CRM_Utils_System::permissionDenied(); }
protected function createStreamOpts($verb, $url, $blob, $headers) { $result = parent::createStreamOpts($verb, $url, $blob, $headers); $caConfig = CA_Config_Stream::probe(array('verify_peer' => (bool) Civi::settings()->get('verifySSL'))); if ($caConfig->isEnableSSL()) { $result['ssl'] = $caConfig->toStreamOptions(); } if (!$caConfig->isEnableSSL() && preg_match('/^https:/', $url)) { CRM_Core_Error::fatal('Cannot fetch document - system does not support SSL'); } return $result; }
/** * 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"); } }
/** * Basic setup. */ public function preProcess() { Civi::resources()->addStyleFile('civicrm', 'css/admin.css'); $this->_id = $this->get('id'); $this->_BAOName = $this->get('BAOName'); $this->_values = array(); if (isset($this->_id)) { $params = array('id' => $this->_id); // this is needed if the form is outside the CRM name space $baoName = $this->_BAOName; $baoName::retrieve($params, $this->_values); } }
/** * @param CRM_Utils_Cache_Interface $cache * @param CRM_Utils_HttpClient $client * @param null $messagesUrl */ public function __construct($cache, $client, $messagesUrl = NULL) { $this->cache = $cache; $this->client = $client; if ($messagesUrl === NULL) { $this->messagesUrl = Civi::settings()->get('communityMessagesUrl'); } else { $this->messagesUrl = $messagesUrl; } if ($this->messagesUrl === '*default*') { $this->messagesUrl = self::DEFAULT_MESSAGES_URL; } }
/** * @param $values * * @return bool */ public static function checkAddress(&$values) { if (self::$_disabled) { return FALSE; } if (!isset($values['street_address']) || !isset($values['city']) && !isset($values['state_province']) && !isset($values['postal_code'])) { return FALSE; } $userID = Civi::settings()->get('address_standardization_userid'); $url = Civi::settings()->get('address_standardization_url'); if (empty($userID) || empty($url)) { return FALSE; } $address2 = str_replace(',', '', $values['street_address']); $XMLQuery = '<AddressValidateRequest USERID="' . $userID . '"><Address ID="0"><Address1>' . CRM_Utils_Array::value('supplemental_address_1', $values, '') . '</Address1><Address2>' . $address2 . '</Address2><City>' . $values['city'] . '</City><State>' . $values['state_province'] . '</State><Zip5>' . $values['postal_code'] . '</Zip5><Zip4>' . CRM_Utils_Array::value('postal_code_suffix', $values, '') . '</Zip4></Address></AddressValidateRequest>'; require_once 'HTTP/Request.php'; $request = new HTTP_Request(); $request->setURL($url); $request->addQueryString('API', 'Verify'); $request->addQueryString('XML', $XMLQuery); $response = $request->sendRequest(); $session = CRM_Core_Session::singleton(); $code = $request->getResponseCode(); if ($code != 200) { $session->setStatus(ts('USPS Address Lookup Failed with HTTP status code: %1', array(1 => $code))); return FALSE; } $responseBody = $request->getResponseBody(); $xml = simplexml_load_string($responseBody); if (is_null($xml) || is_null($xml->Address)) { $session->setStatus(ts('Your USPS API Lookup has Failed.')); return FALSE; } if ($xml->Number == '80040b1a') { $session->setStatus(ts('Your USPS API Authorization has Failed.')); return FALSE; } if (array_key_exists('Error', $xml->Address)) { $session->setStatus(ts('Address not found in USPS database.')); return FALSE; } $values['street_address'] = (string) $xml->Address->Address2; $values['city'] = (string) $xml->Address->City; $values['state_province'] = (string) $xml->Address->State; $values['postal_code'] = (string) $xml->Address->Zip5; $values['postal_code_suffix'] = (string) $xml->Address->Zip4; if (array_key_exists('Address1', $xml->Address)) { $values['supplemental_address_1'] = (string) $xml->Address->Address1; } return TRUE; }
/** * Retrieve unclosed cases. */ public static function unclosedCases() { $params = array('limit' => Civi::settings()->get('search_autocomplete_count'), 'sort_name' => CRM_Utils_Type::escape(CRM_Utils_Array::value('term', $_GET, ''), 'String')); $excludeCaseIds = array(); if (!empty($_GET['excludeCaseIds'])) { $excludeCaseIds = explode(',', CRM_Utils_Type::escape($_GET['excludeCaseIds'], 'String')); } $unclosedCases = CRM_Case_BAO_Case::getUnclosedCases($params, $excludeCaseIds, TRUE, TRUE); $results = array(); foreach ($unclosedCases as $caseId => $details) { $results[] = array('id' => $caseId, 'label' => $details['sort_name'] . ' - ' . $details['case_type'] . ($details['end_date'] ? ' (' . ts('closed') . ')' : ''), 'label_class' => $details['end_date'] ? 'strikethrough' : '', 'description' => array("#{$caseId}: " . $details['case_subject'] . ' (' . $details['case_status'] . ')'), 'extra' => $details); } CRM_Utils_JSON::output($results); }