public function cleanup425() { $rows = CRM_Upgrade_Incremental_php_FourTwo::deleteInvalidPairs(); $template = CRM_Core_Smarty::singleton(); $columnHeaders = array("Contact ID", "ContributionID", "Contribution Status", "MembershipID", "Membership Type", "Start Date", "End Date", "Membership Status", "Action"); $template->assign('columnHeaders', $columnHeaders); $template->assign('rows', $rows); $preMessage = !empty($rows) ? ts('The following records have been processed. Membership records with action = Un-linked have been disconnected from the listed contribution record:') : ts('Could not find any records to process.'); $template->assign('preMessage', $preMessage); $postMessage = ts('You can <a href="%1">click here</a> to try running the 4.2 upgrade script again. <a href="%2" target="_blank">(Review upgrade documentation)</a>', array(1 => CRM_Utils_System::url('civicrm/upgrade', 'reset=1'), 2 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Installation+and+Upgrades')); $template->assign('postMessage', $postMessage); $content = $template->fetch('CRM/common/upgradeCleanup.tpl'); echo CRM_Utils_System::theme($content, FALSE, TRUE); }
/** * * POST Param 'qrid': string, usually the name of the queue */ function run() { $qrid = CRM_Utils_Request::retrieve('qrid', 'String', $this, TRUE); $runner = CRM_Queue_Runner::instance($qrid); // dpm(array( 'action' => 'CRM_Queue_Page_Runner::run()', 'session' => $_SESSION, 'runner' => $runner, 'qrid' => $qrid )); if (!is_object($runner)) { CRM_Core_Error::fatal('Queue runner must be configured before execution.'); } CRM_Utils_System::setTitle($runner->title); $this->assign('queueRunnerData', array('qrid' => $runner->qrid, 'runNextAjax' => CRM_Utils_System::url($runner->pathPrefix . '/ajax/runNext', NULL, FALSE, NULL, FALSE), 'skipNextAjax' => CRM_Utils_System::url($runner->pathPrefix . '/ajax/skipNext', NULL, FALSE, NULL, FALSE), 'onEndAjax' => CRM_Utils_System::url($runner->pathPrefix . '/ajax/onEnd', NULL, FALSE, NULL, FALSE), 'completed' => 0, 'numberOfItems' => $runner->queue->numberOfItems(), 'buttons' => $runner->buttons)); if ($runner->isMinimal) { $smarty = CRM_Core_Smarty::singleton(); $content = $smarty->fetch('CRM/Queue/Page/Runner.tpl'); echo CRM_Utils_System::theme('page', $content, TRUE, $this->_print, FALSE, TRUE); } else { parent::run(); } }
/** * * POST Param 'qrid': string, usually the name of the queue */ public function run() { $qrid = CRM_Utils_Request::retrieve('qrid', 'String', $this, TRUE); $runner = CRM_Queue_Runner::instance($qrid); if (!is_object($runner)) { CRM_Core_Error::fatal('Queue runner must be configured before execution.'); } CRM_Utils_System::setTitle($runner->title); $this->assign('queueRunnerData', array('qrid' => $runner->qrid, 'runNextAjax' => CRM_Utils_System::url($runner->pathPrefix . '/ajax/runNext', NULL, FALSE, NULL, FALSE), 'skipNextAjax' => CRM_Utils_System::url($runner->pathPrefix . '/ajax/skipNext', NULL, FALSE, NULL, FALSE), 'onEndAjax' => CRM_Utils_System::url($runner->pathPrefix . '/ajax/onEnd', NULL, FALSE, NULL, FALSE), 'completed' => 0, 'numberOfItems' => $runner->queue->numberOfItems(), 'buttons' => $runner->buttons)); if ($runner->isMinimal) { // Render page header if (!defined('CIVICRM_UF_HEAD') && ($region = CRM_Core_Region::instance('html-header', FALSE))) { CRM_Utils_System::addHTMLHead($region->render('')); } $smarty = CRM_Core_Smarty::singleton(); $content = $smarty->fetch('CRM/Queue/Page/Runner.tpl'); echo CRM_Utils_System::theme($content, $this->_print, TRUE); } else { parent::run(); } }
function run() { // lets get around the time limit issue if possible for upgrades if (!ini_get('safe_mode')) { set_time_limit(0); } $latestVer = CRM_Utils_System::version(); $currentVer = CRM_Core_BAO_Domain::version(); if (!$currentVer) { CRM_Core_Error::fatal(ts('Version information missing in civicrm database.')); } else { if (stripos($currentVer, 'upgrade')) { CRM_Core_Error::fatal(ts('Database check failed - the database looks to have been partially upgraded. You may want to reload the database with the backup and try the upgrade process again.')); } } if (!$latestVer) { CRM_Core_Error::fatal(ts('Version information missing in civicrm codebase.')); } // hack to make past ver compatible /w new incremental upgrade process $convertVer = array('2.1' => '2.1.0', '2.2' => '2.2.alpha1', '2.2.alph' => '2.2.alpha3', '3.1.0' => '3.1.1'); if (isset($convertVer[$currentVer])) { $currentVer = $convertVer[$currentVer]; } // since version is suppose to be in valid format at this point, especially after conversion ($convertVer), // lets do a pattern check - if (!CRM_Utils_System::isVersionFormatValid($currentVer)) { CRM_Core_Error::fatal(ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.')); } // This could be removed in later rev if ($currentVer == '2.1.6') { $config =& CRM_Core_Config::singleton(); // also cleanup the templates_c directory $config->cleanup(1, false); if ($config->userFramework !== 'Standalone') { // clean the session $session =& CRM_Core_Session::singleton(); $session->reset(2); } } // end of hack CRM_Utils_System::setTitle(ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer))); $upgrade =& new CRM_Upgrade_Form(); $template =& CRM_Core_Smarty::singleton(); $template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer))); $template->assign('menuRebuildURL', CRM_Utils_System::url('civicrm/menu/rebuild', 'reset=1')); $template->assign('cancelURL', CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); if (version_compare($currentVer, $latestVer) > 0) { // DB version number is higher than codebase being upgraded to. This is unexpected condition-fatal error. $dbToolsLink = CRM_Utils_System::docURL2("Database Troubleshooting Tools", true); $error = ts('Your database is marked with an unexpected version number: %1. The automated upgrade to version %2 can not be run - and the %2 codebase may not be compatible with your database state. You will need to determine the correct version corresponding to your current database state. The database tools utility at %3 may be helpful. You may want to revert to the codebase you were using prior to beginning this upgrade until you resolve this problem.', array(1 => $currentVer, 2 => $latestVer, 3 => $dbToolsLink)); CRM_Core_Error::fatal($error); } else { if (version_compare($currentVer, $latestVer) == 0) { $message = ts('Your database has already been upgraded to CiviCRM %1', array(1 => $latestVer)); $template->assign('upgraded', true); } else { $message = ts('CiviCRM upgrade was successful.'); $template->assign('currentVersion', $currentVer); $template->assign('newVersion', $latestVer); $template->assign('upgradeTitle', ts('Upgrade CiviCRM from v %1 To v %2', array(1 => $currentVer, 2 => $latestVer))); $template->assign('upgraded', false); if (CRM_Utils_Array::value('upgrade', $_POST)) { $revisions = $upgrade->getRevisionSequence(); foreach ($revisions as $rev) { // proceed only if $currentVer < $rev if (version_compare($currentVer, $rev) < 0) { // as soon as we start doing anything we append ".upgrade" to version. // this also helps detect any partial upgrade issues $upgrade->setVersion($rev . '.upgrade'); $phpFunctionName = 'upgrade_' . str_replace('.', '_', $rev); if (is_callable(array($this, $phpFunctionName))) { eval("\$this->{$phpFunctionName}('{$rev}');"); } else { $upgrade->processSQL($rev); } // after an successful intermediate upgrade, set the complete version $upgrade->setVersion($rev); } } $upgrade->setVersion($latestVer); $template->assign('upgraded', true); // also cleanup the templates_c directory $config =& CRM_Core_Config::singleton(); $config->cleanup(1, false); // clear db caching $config->clearDBCache(); // clean the session. Note: In case of standalone this makes the user logout. // So skip this step for standalone. if ($config->userFramework !== 'Standalone') { $session =& CRM_Core_Session::singleton(); $session->reset(2); } } } } $template->assign('message', $message); $content = $template->fetch('CRM/common/success.tpl'); echo CRM_Utils_System::theme('page', $content, true, $this->_print, false, true); }
/** * This function takes care of all the things common to all * pages. This typically involves assigning the appropriate * smarty variable :) * * @return string The content generated by running this page */ function run() { if ($this->_embedded) { return; } $GLOBALS['_CRM_CORE_PAGE']['_template']->assign('mode', $this->_mode); $GLOBALS['_CRM_CORE_PAGE']['_template']->assign('tplFile', $this->getTemplateFileName()); if ($this->_print) { $content = $GLOBALS['_CRM_CORE_PAGE']['_template']->fetch('CRM/print.tpl'); } else { $content = $GLOBALS['_CRM_CORE_PAGE']['_template']->fetch('CRM/index.tpl'); } echo CRM_Utils_System::theme('page', $content, null, $this->_print); return; }
/** * Move the variables from the session to the template * * @return void * @access public */ function moveFromSessionToTemplate() { $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->assign_by_ref('pager', $this->_pager); $rows = $this->_store->get('rows'); if ($rows) { $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->assign('aToZ', $this->_store->get('AToZBar')); } $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->assign_by_ref('sort', $this->_sort); $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->assign('columnHeaders', $this->_store->get('columnHeaders')); $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->assign('rows', $rows); $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->assign('rowsEmpty', $this->_store->get('rowsEmpty')); $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->assign('qill', $this->_store->get('qill')); if ($this->_embedded) { return; } $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->assign('tplFile', $this->_object->getTemplateFileName()); if ($this->_print) { $content = $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->fetch('CRM/print.tpl'); } else { $content = $GLOBALS['_CRM_CORE_SELECTOR_CONTROLLER']['_template']->fetch('CRM/index.tpl'); } echo CRM_Utils_System::theme('page', $content, null, $this->_print); }
/** * Render the page using a custom templating system. * * @param CRM_Core_Form $page * The CRM_Core_Form page. */ public function renderForm(&$page) { $this->_setRenderTemplates($page); $template = CRM_Core_Smarty::singleton(); $form = $page->toSmarty(); // Deprecated - use snippet=6 instead of json=1 $json = CRM_Utils_Request::retrieve('json', 'Boolean', CRM_Core_DAO::$_nullObject); if ($json) { CRM_Utils_JSON::output($form); } $template->assign('form', $form); $template->assign('isForm', 1); $controller =& $page->controller; // Stop here if we are in embedded mode. Exception: displaying form errors via ajax if ($controller->getEmbedded() && !(!empty($form['errors']) && $controller->_QFResponseType == 'json')) { return; } $template->assign('action', $page->getAction()); $pageTemplateFile = $page->getHookedTemplateFileName(); $template->assign('tplFile', $pageTemplateFile); $content = $template->fetch($controller->getTemplateFile()); if (!defined('CIVICRM_UF_HEAD') && ($region = CRM_Core_Region::instance('html-header', FALSE))) { CRM_Utils_System::addHTMLHead($region->render('')); } CRM_Utils_System::appendTPLFile($pageTemplateFile, $content, $page->overrideExtraTemplateFileName()); //its time to call the hook. CRM_Utils_Hook::alterContent($content, 'form', $pageTemplateFile, $page); $print = $controller->getPrint(); if ($print) { $html =& $content; } else { $html = CRM_Utils_System::theme($content, $print); } if ($controller->_QFResponseType == 'json') { $response = array('content' => $html); if (!empty($page->ajaxResponse)) { $response += $page->ajaxResponse; } if (!empty($form['errors'])) { $response['status'] = 'form_error'; $response['errors'] = $form['errors']; } CRM_Core_Page_AJAX::returnJsonResponse($response); } if ($print) { if ($print == CRM_Core_Smarty::PRINT_PDF) { CRM_Utils_PDF_Utils::html2pdf($content, "{$page->_name}.pdf", FALSE, array('paper_size' => 'a3', 'orientation' => 'landscape')); } else { echo $html; } CRM_Utils_System::civiExit(); } print $html; }
/** * Display any final messages, clear caches, etc */ public function runFinish() { $upgrade = new CRM_Upgrade_Form(); $template = CRM_Core_Smarty::singleton(); // If we're redirected from queue-runner, then isUpgradePending=true. // If user then reloads the finish page, the isUpgradePending will be unset. (Because the session has been cleared.) if ($this->get('isUpgradePending')) { // TODO: Use structured message store $postUpgradeMessage = file_get_contents($this->get('postUpgradeMessageFile')); // This destroys $session, so do it after get('postUpgradeMessageFile') CRM_Upgrade_Form::doFinish(); } else { $postUpgradeMessage = ''; // Session was destroyed! Can't recover messages. } // do a version check - after doFinish() sets the final version list($currentVer, $latestVer) = $upgrade->getUpgradeVersions(); if ($error = $upgrade->checkCurrentVersion($currentVer, $latestVer)) { CRM_Core_Error::fatal($error); } $template->assign('message', $postUpgradeMessage); $template->assign('upgraded', TRUE); $template->assign('sid', CRM_Utils_System::getSiteID()); // Render page header if (!defined('CIVICRM_UF_HEAD') && ($region = CRM_Core_Region::instance('html-header', FALSE))) { CRM_Utils_System::addHTMLHead($region->render('')); } $content = $template->fetch('CRM/common/success.tpl'); echo CRM_Utils_System::theme($content, $this->_print, TRUE); }
/** * Output code from error function. * @param string $content */ public function outputError($content) { echo CRM_Utils_System::theme($content); }
function run() { // lets get around the time limit issue if possible for upgrades if (!ini_get('safe_mode')) { set_time_limit(0); } $latestVer = CRM_Utils_System::version(); $currentVer = CRM_Core_BAO_Domain::version(); if (!$currentVer) { CRM_Core_Error::fatal(ts('Version information missing in civicrm database.')); } else { if (stripos($currentVer, 'upgrade')) { CRM_Core_Error::fatal(ts('Database check failed - the database looks to have been partially upgraded. You may want to reload the database with the backup and try the upgrade process again.')); } } if (!$latestVer) { CRM_Core_Error::fatal(ts('Version information missing in civicrm codebase.')); } // hack to make past ver compatible /w new incremental upgrade process $convertVer = array('2.1' => '2.1.0', '2.2' => '2.2.alpha1', '2.2.alph' => '2.2.alpha3', '3.1.0' => '3.1.1'); if (isset($convertVer[$currentVer])) { $currentVer = $convertVer[$currentVer]; } // since version is suppose to be in valid format at this point, especially after conversion ($convertVer), // lets do a pattern check - if (!CRM_Utils_System::isVersionFormatValid($currentVer)) { CRM_Core_Error::fatal(ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.')); } // This could be removed in later rev if ($currentVer == '2.1.6') { $config = CRM_Core_Config::singleton(); // also cleanup the templates_c directory $config->cleanup(1, false); if ($config->userFramework !== 'Standalone') { // clean the session $session = CRM_Core_Session::singleton(); $session->reset(2); } } // end of hack CRM_Utils_System::setTitle(ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer))); $upgrade = new CRM_Upgrade_Form(); $template = CRM_Core_Smarty::singleton(); $template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer))); $template->assign('menuRebuildURL', CRM_Utils_System::url('civicrm/menu/rebuild', 'reset=1')); $template->assign('cancelURL', CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); if (version_compare($currentVer, $latestVer) > 0) { // DB version number is higher than codebase being upgraded to. This is unexpected condition-fatal error. $dbToolsLink = CRM_Utils_System::docURL2("Database Troubleshooting Tools", true); $error = ts('Your database is marked with an unexpected version number: %1. The automated upgrade to version %2 can not be run - and the %2 codebase may not be compatible with your database state. You will need to determine the correct version corresponding to your current database state. The database tools utility at %3 may be helpful. You may want to revert to the codebase you were using prior to beginning this upgrade until you resolve this problem.', array(1 => $currentVer, 2 => $latestVer, 3 => $dbToolsLink)); CRM_Core_Error::fatal($error); } else { if (version_compare($currentVer, $latestVer) == 0) { $message = ts('Your database has already been upgraded to CiviCRM %1', array(1 => $latestVer)); $template->assign('upgraded', true); } else { $message = ts('CiviCRM upgrade was successful.'); if ($latestVer == '3.2.alpha1') { $message .= '<br />' . ts("We have reset the COUNTED flag to false for the event participant status 'Pending from incomplete transaction'. This change ensures that people who have a problem during registration can try again."); } else { if ($latestVer == '3.2.beta3' && version_compare($currentVer, '3.1.alpha1') >= 0) { require_once 'CRM/Contact/BAO/ContactType.php'; $subTypes = CRM_Contact_BAO_ContactType::subTypes(); if (is_array($subTypes) && !empty($subTypes)) { $config = CRM_Core_Config::singleton(); $subTypeTemplates = array(); if (isset($config->customTemplateDir)) { foreach ($subTypes as $key => $subTypeName) { $customContactSubTypeEdit = $config->customTemplateDir . "CRM/Contact/Form/Edit/" . $subTypeName . ".tpl"; $customContactSubTypeView = $config->customTemplateDir . "CRM/Contact/Page/View/" . $subTypeName . ".tpl"; if (file_exists($customContactSubTypeEdit) || file_exists($customContactSubTypeView)) { $subTypeTemplates[$subTypeName] = $subTypeName; } } } foreach ($subTypes as $key => $subTypeName) { $customContactSubTypeEdit = $config->templateDir . "CRM/Contact/Form/Edit/" . $subTypeName . ".tpl"; $customContactSubTypeView = $config->templateDir . "CRM/Contact/Page/View/" . $subTypeName . ".tpl"; if (file_exists($customContactSubTypeEdit) || file_exists($customContactSubTypeView)) { $subTypeTemplates[$subTypeName] = $subTypeName; } } if (!empty($subTypeTemplates)) { $subTypeTemplates = implode(',', $subTypeTemplates); $message .= '<br />' . ts('You are using custom template for contact subtypes: %1.', array(1 => $subTypeTemplates)) . '<br />' . ts('You need to move these subtype templates to the SubType directory in %1 and %2 respectively.', array(1 => 'CRM/Contact/Form/Edit', 2 => 'CRM/Contact/Page/View')); } } } else { if ($latestVer == '3.2.beta4') { $statuses = array('New', 'Current', 'Grace', 'Expired', 'Pending', 'Cancelled', 'Deceased'); $sql = "\nSELECT count( id ) as statusCount \n FROM civicrm_membership_status \n WHERE name IN ( '" . implode("' , '", $statuses) . "' ) "; $count = CRM_Core_DAO::singleValueQuery($sql); if ($count < count($statuses)) { $message .= '<br />' . ts("One or more Membership Status Rules was disabled during the upgrade because it did not match a recognized status name. if custom membership status rules were added to this site - review the disabled statuses and re-enable any that are still needed (Administer > CiviMember > Membership Status Rules)."); } } } } $template->assign('currentVersion', $currentVer); $template->assign('newVersion', $latestVer); $template->assign('upgradeTitle', ts('Upgrade CiviCRM from v %1 To v %2', array(1 => $currentVer, 2 => $latestVer))); $template->assign('upgraded', false); if (CRM_Utils_Array::value('upgrade', $_POST)) { $revisions = $upgrade->getRevisionSequence(); foreach ($revisions as $rev) { // proceed only if $currentVer < $rev if (version_compare($currentVer, $rev) < 0) { // as soon as we start doing anything we append ".upgrade" to version. // this also helps detect any partial upgrade issues $upgrade->setVersion($rev . '.upgrade'); $phpFunctionName = 'upgrade_' . str_replace('.', '_', $rev); // follow old upgrade process for all version // below 3.2.alpha1 if (version_compare($rev, '3.2.alpha1') < 0) { if (is_callable(array($this, $phpFunctionName))) { eval("\$this->{$phpFunctionName}('{$rev}');"); } else { $upgrade->processSQL($rev); } } else { // new upgrade process from version // 3.2.alpha1 $versionObject = $upgrade->incrementalPhpObject($rev); // predb check for major release. if ($upgrade->checkVersionRelease($rev, 'alpha1')) { if (!is_callable(array($versionObject, 'verifyPreDBstate'))) { CRM_Core_Error::fatal("verifyPreDBstate method was not found for {$rev}"); } $error = null; if (!$versionObject->verifyPreDBstate($error)) { if (!isset($error)) { $error = "post-condition failed for current upgrade for {$rev}"; } CRM_Core_Error::fatal($error); } } if (is_callable(array($versionObject, $phpFunctionName))) { $versionObject->{$phpFunctionName}($rev); } else { $upgrade->processSQL($rev); } } // after an successful intermediate upgrade, set the complete version $upgrade->setVersion($rev); } } $upgrade->setVersion($latestVer); $template->assign('upgraded', true); // also cleanup the templates_c directory $config = CRM_Core_Config::singleton(); $config->cleanup(1, false); // clear db caching $config->clearDBCache(); // clear temporary tables $config->clearTempTables(); // clean the session. Note: In case of standalone this makes the user logout. // So skip this step for standalone. if ($config->userFramework !== 'Standalone') { $session = CRM_Core_Session::singleton(); $session->reset(2); } } } } $template->assign('message', $message); $content = $template->fetch('CRM/common/success.tpl'); echo CRM_Utils_System::theme('page', $content, true, $this->_print, false, true); }
/** * display an error page with an error message describing what happened * * @param string message the error message * @param string code the error code if any * @param string email the email address to notify of this situation * * @return void * @static * @acess public */ static function fatal($message = null, $code = null, $email = null) { if (!$message) { $message = ts('We experienced an unexpected error. Please post a detailed description and the backtrace on the CiviCRM forums: %1', array(1 => 'http://forum.civicrm.org/')); } $vars = array('message' => $message, 'code' => $code); $config =& CRM_Core_Config::singleton(); if ($config->fatalErrorHandler && function_exists($config->fatalErrorHandler)) { $name = $config->fatalErrorHandler; $ret = $name($vars); if ($ret) { // the call has been successfully handled // so we just exit exit(CRM_Core_Error::FATAL_ERROR); } } if ($config->backtrace) { self::backtrace(); } $template =& CRM_Core_Smarty::singleton(); $template->assign($vars); CRM_Core_Error::debug_var('Fatal Error Details', $vars); CRM_Core_Error::backtrace('backTrace', true); $content = $template->fetch($config->fatalErrorTemplate); echo CRM_Utils_System::theme('page', $content); // print $content; exit(CRM_Core_Error::FATAL_ERROR); }
/** * Display any final messages, clear caches, etc */ function runFinish() { $upgrade = new CRM_Upgrade_Form(); $template = CRM_Core_Smarty::singleton(); // TODO: Use structured message store $postUpgradeMessage = file_get_contents($this->get('postUpgradeMessageFile')); // This destroys $session, so do it after ge('postUpgradeMessageFile') CRM_Upgrade_Form::doFinish(); // do a version check - after doFinish() sets the final version list($currentVer, $latestVer) = $upgrade->getUpgradeVersions(); if ($error = $upgrade->checkCurrentVersion($currentVer, $latestVer)) { CRM_Core_Error::fatal($error); } $template->assign('message', $postUpgradeMessage); $template->assign('upgraded', TRUE); $content = $template->fetch('CRM/common/success.tpl'); echo CRM_Utils_System::theme('page', $content, TRUE, $this->_print, FALSE, TRUE); }
/** * create the main callback method. this method centralizes error processing. * * the errors we expect are from the pear modules DB, DB_DataObject * which currently use PEAR::raiseError to notify of error messages. * * @param object PEAR_Error * * @return void * @access public */ function handle($pearError) { // setup smarty with config, session and template location. $template =& CRM_Core_Smarty::singleton(); $config =& CRM_Core_Config::singleton(); if ($config->debug && ($_REQUEST['backtrace'] || defined('CIVICRM_BACKTRACE'))) { CRM_Core_Error::backtrace(); } // create the error array $error = array(); $error['callback'] = $pearError->getCallback(); $error['code'] = $pearError->getCode(); $error['message'] = $pearError->getMessage(); $error['mode'] = $pearError->getMode(); $error['debug_info'] = $pearError->getDebugInfo(); $error['type'] = $pearError->getType(); $error['user_info'] = $pearError->getUserInfo(); $error['to_string'] = $pearError->toString(); if (mysql_error()) { $mysql_error = mysql_error() . ', ' . mysql_errno(); $template->assign_by_ref('mysql_code', $mysql_error); // execute a dummy query to clear error stack mysql_query('select 1'); } $template->assign_by_ref('error', $error); $template->assign('tplFile', "CRM/" . CRM_CORE_ERROR_ERROR_TEMPLATE); $content = $template->fetch('CRM/error.tpl'); $content .= CRM_Core_Error::debug('error', $error, false); echo CRM_Utils_System::theme('page', $content); exit(1); }
/** * This function takes care of all the things common to all * pages. This typically involves assigning the appropriate * smarty variable :) * * @return string The content generated by running this page */ function run() { if ($this->_embedded) { return; } self::$_template->assign('mode', $this->_mode); $pageTemplateFile = $this->getTemplateFileName(); self::$_template->assign('tplFile', $pageTemplateFile); // invoke the pagRun hook, CRM-3906 CRM_Utils_Hook::pageRun($this); if ($this->_print) { if (in_array($this->_print, array(CRM_Core_Smarty::PRINT_SNIPPET, CRM_Core_Smarty::PRINT_PDF, CRM_Core_Smarty::PRINT_NOFORM))) { $content = self::$_template->fetch('CRM/common/snippet.tpl'); } else { $content = self::$_template->fetch('CRM/common/print.tpl'); } CRM_Utils_System::appendTPLFile($pageTemplateFile, $content, $this->overrideExtraTemplateFileName()); //its time to call the hook. CRM_Utils_Hook::alterContent($content, 'page', $pageTemplateFile, $this); if ($this->_print == CRM_Core_Smarty::PRINT_PDF) { CRM_Utils_PDF_Utils::html2pdf($content, "{$this->_name}.pdf", FALSE, array('paper_size' => 'a3', 'orientation' => 'landscape')); } else { echo $content; } CRM_Utils_System::civiExit(); } $config = CRM_Core_Config::singleton(); $content = self::$_template->fetch('CRM/common/' . strtolower($config->userFramework) . '.tpl'); if ($region = CRM_Core_Region::instance('html-header', FALSE)) { CRM_Utils_System::addHTMLHead($region->render('')); } CRM_Utils_System::appendTPLFile($pageTemplateFile, $content); //its time to call the hook. CRM_Utils_Hook::alterContent($content, 'page', $pageTemplateFile, $this); echo CRM_Utils_System::theme('page', $content, TRUE, $this->_print); return; }
/** * Move the variables from the session to the template * * @return void * @access public */ function moveFromSessionToTemplate() { self::$_template->assign_by_ref("{$this->_prefix}pager", $this->_pager); $rows = $this->_store->get("{$this->_prefix}rows"); if ($rows) { if ($this->_dynamicAction) { $this->_object->addActions($rows); } self::$_template->assign("{$this->_prefix}aToZ", $this->_store->get("{$this->_prefix}AToZBar")); } self::$_template->assign_by_ref("{$this->_prefix}sort", $this->_sort); self::$_template->assign("{$this->_prefix}columnHeaders", $this->_store->get("{$this->_prefix}columnHeaders")); self::$_template->assign("{$this->_prefix}rows", $rows); self::$_template->assign("{$this->_prefix}rowsEmpty", $this->_store->get("{$this->_prefix}rowsEmpty")); self::$_template->assign("{$this->_prefix}qill", $this->_store->get("{$this->_prefix}qill")); self::$_template->assign("{$this->_prefix}summary", $this->_store->get("{$this->_prefix}summary")); if ($this->_embedded) { return; } self::$_template->assign('tplFile', $this->_object->getTemplateFileName()); if ($this->_print) { $content = self::$_template->fetch('CRM/common/print.tpl'); } else { $config = CRM_Core_Config::singleton(); $content = self::$_template->fetch('CRM/common/' . strtolower($config->userFramework) . '.tpl'); } echo CRM_Utils_System::theme('page', $content, TRUE, $this->_print); }
/** * This function takes care of all the things common to all * pages. This typically involves assigning the appropriate * smarty variable :) * * @return string The content generated by running this page */ function run() { if ($this->_embedded) { return; } self::$_template->assign('mode', $this->_mode); self::$_template->assign('tplFile', $this->getTemplateFileName()); // invoke the pagRun hook, CRM-3906 require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::pageRun($this); if ($this->_print) { if ($this->_print == CRM_Core_Smarty::PRINT_SNIPPET || $this->_print == CRM_Core_Smarty::PRINT_PDF) { $content = self::$_template->fetch('CRM/common/snippet.tpl'); } else { $content = self::$_template->fetch('CRM/common/print.tpl'); } if ($this->_print == CRM_Core_Smarty::PRINT_PDF) { require_once 'CRM/Utils/PDF/Utils.php'; CRM_Utils_PDF_Utils::domlib($content, "{$this->_name}.pdf"); } else { echo $content; } exit; } $config =& CRM_Core_Config::singleton(); $content = self::$_template->fetch('CRM/common/' . strtolower($config->userFramework) . '.tpl'); echo CRM_Utils_System::theme('page', $content, true, $this->_print); return; }
/** * This function takes care of all the things common to all * pages. This typically involves assigning the appropriate * smarty variable :) * * @return string The content generated by running this page */ function run() { if ($this->_embedded) { return; } self::$_template->assign('mode', $this->_mode); $pageTemplateFile = $this->getHookedTemplateFileName(); self::$_template->assign('tplFile', $pageTemplateFile); // invoke the pagRun hook, CRM-3906 CRM_Utils_Hook::pageRun($this); if ($this->_print) { if (in_array($this->_print, array(CRM_Core_Smarty::PRINT_SNIPPET, CRM_Core_Smarty::PRINT_PDF, CRM_Core_Smarty::PRINT_NOFORM, CRM_Core_Smarty::PRINT_JSON))) { $content = self::$_template->fetch('CRM/common/snippet.tpl'); } else { $content = self::$_template->fetch('CRM/common/print.tpl'); } CRM_Utils_System::appendTPLFile($pageTemplateFile, $content, $this->overrideExtraTemplateFileName()); //its time to call the hook. CRM_Utils_Hook::alterContent($content, 'page', $pageTemplateFile, $this); if ($this->_print == CRM_Core_Smarty::PRINT_PDF) { CRM_Utils_PDF_Utils::html2pdf($content, "{$this->_name}.pdf", FALSE, array('paper_size' => 'a3', 'orientation' => 'landscape')); } elseif ($this->_print == CRM_Core_Smarty::PRINT_JSON) { $this->ajaxResponse['content'] = $content; CRM_Core_Page_AJAX::returnJsonResponse($this->ajaxResponse); } else { echo $content; } CRM_Utils_System::civiExit(); } $config = CRM_Core_Config::singleton(); // TODO: Is there a better way to ensure these actions don't happen during AJAX requests? if (empty($_GET['snippet'])) { // Version check and intermittent alert to admins CRM_Utils_VersionCheck::singleton()->versionAlert(); CRM_Utils_Check_Security::singleton()->showPeriodicAlerts(); // Debug msg once per hour if ($config->debug && CRM_Core_Permission::check('administer CiviCRM') && CRM_Core_Session::singleton()->timer('debug_alert', 3600)) { $msg = ts('Warning: Debug is enabled in <a href="%1">system settings</a>. This should not be enabled on production servers.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/debug', 'reset=1'))); CRM_Core_Session::setStatus($msg, ts('Debug Mode')); } } $content = self::$_template->fetch('CRM/common/' . strtolower($config->userFramework) . '.tpl'); // Render page header if (!defined('CIVICRM_UF_HEAD') && ($region = CRM_Core_Region::instance('html-header', FALSE))) { CRM_Utils_System::addHTMLHead($region->render('')); } CRM_Utils_System::appendTPLFile($pageTemplateFile, $content); //its time to call the hook. CRM_Utils_Hook::alterContent($content, 'page', $pageTemplateFile, $this); echo CRM_Utils_System::theme($content, $this->_print); return; }
/** * This function takes care of all the things common to all * pages. This typically involves assigning the appropriate smarty * variable :) * * @return void|string * The content generated by running this page */ public function run() { if ($this->_embedded) { return NULL; } self::$_template->assign('mode', $this->_mode); $pageTemplateFile = $this->getHookedTemplateFileName(); self::$_template->assign('tplFile', $pageTemplateFile); // invoke the pagRun hook, CRM-3906 CRM_Utils_Hook::pageRun($this); if ($this->_print) { if (in_array($this->_print, array(CRM_Core_Smarty::PRINT_SNIPPET, CRM_Core_Smarty::PRINT_PDF, CRM_Core_Smarty::PRINT_NOFORM, CRM_Core_Smarty::PRINT_JSON))) { $content = self::$_template->fetch('CRM/common/snippet.tpl'); } else { $content = self::$_template->fetch('CRM/common/print.tpl'); } CRM_Utils_System::appendTPLFile($pageTemplateFile, $content, $this->overrideExtraTemplateFileName()); //its time to call the hook. CRM_Utils_Hook::alterContent($content, 'page', $pageTemplateFile, $this); if ($this->_print == CRM_Core_Smarty::PRINT_PDF) { CRM_Utils_PDF_Utils::html2pdf($content, "{$this->_name}.pdf", FALSE, array('paper_size' => 'a3', 'orientation' => 'landscape')); } elseif ($this->_print == CRM_Core_Smarty::PRINT_JSON) { $this->ajaxResponse['content'] = $content; CRM_Core_Page_AJAX::returnJsonResponse($this->ajaxResponse); } else { echo $content; } CRM_Utils_System::civiExit(); } $config = CRM_Core_Config::singleton(); // Intermittent alert to admins CRM_Utils_Check::singleton()->showPeriodicAlerts(); if ($this->useLivePageJS && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'ajaxPopupsEnabled', NULL, TRUE)) { CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js', 1, 'html-header'); } $content = self::$_template->fetch('CRM/common/' . strtolower($config->userFramework) . '.tpl'); // Render page header if (!defined('CIVICRM_UF_HEAD') && ($region = CRM_Core_Region::instance('html-header', FALSE))) { CRM_Utils_System::addHTMLHead($region->render('')); } CRM_Utils_System::appendTPLFile($pageTemplateFile, $content); //its time to call the hook. CRM_Utils_Hook::alterContent($content, 'page', $pageTemplateFile, $this); echo CRM_Utils_System::theme($content, $this->_print); }
/** * render the page using a custom templating * system * * @param object $page the CRM_Core_Form page * * @return void * @access public */ function _renderForm(&$page) { $this->_setRenderTemplates($page); $template =& CRM_Core_Smarty::singleton(); $template->assign('form', $page->toSmarty()); $template->assign('isForm', 1); $controller =& $page->controller; if ($controller->getEmbedded()) { return; } $template->assign('action', $page->getAction()); $template->assign('tplFile', $page->getTemplateFileName()); if ($controller->getPrint()) { $content = $template->fetch('CRM/print.tpl'); } else { $content = $template->fetch('CRM/index.tpl'); } echo CRM_Utils_System::theme('page', $content, null, $controller->getPrint()); return; }
/** * Display an error page with an error message describing what happened. * * This function is evil -- it largely replicates fatal(). Hopefully the * entire CRM_Core_Error system can be hollowed out and replaced with * something that follows a cleaner separation of concerns. * * @param Exception $exception * * @return void */ public static function handleUnhandledException($exception) { try { CRM_Utils_Hook::unhandledException($exception); } catch (Exception $other) { // if the exception-handler generates an exception, then that sucks! oh, well. carry on. CRM_Core_Error::debug_var('handleUnhandledException_nestedException', self::formatTextException($other)); } $config = CRM_Core_Config::singleton(); $vars = array('message' => $exception->getMessage(), 'code' => NULL, 'exception' => $exception); if (!$vars['message']) { $vars['message'] = ts('We experienced an unexpected error. Please post a detailed description and the backtrace on the CiviCRM forums: %1', array(1 => 'http://forum.civicrm.org/')); } // Case A: CLI if (php_sapi_name() == "cli") { printf("Sorry. A non-recoverable error has occurred.\n%s\n", $vars['message']); print self::formatTextException($exception); die("\n"); // FIXME: Why doesn't this call abend()? // Difference: abend() will cleanup transaction and (via civiExit) store session state // self::abend(CRM_Core_Error::FATAL_ERROR); } // Case B: Custom error handler if ($config->fatalErrorHandler && function_exists($config->fatalErrorHandler)) { $name = $config->fatalErrorHandler; $ret = $name($vars); if ($ret) { // the call has been successfully handled // so we just exit self::abend(CRM_Core_Error::FATAL_ERROR); } } // Case C: Default error handler // log to file CRM_Core_Error::debug_var('Fatal Error Details', $vars); CRM_Core_Error::backtrace('backTrace', TRUE); // print to screen $template = CRM_Core_Smarty::singleton(); $template->assign($vars); $content = $template->fetch($config->fatalErrorTemplate); if ($config->backtrace) { $content = self::formatHtmlException($exception) . $content; } if ($config->userFramework == 'Joomla' && class_exists('JError')) { JError::raiseError('CiviCRM-001', $content); } else { echo CRM_Utils_System::theme($content); } // fin self::abend(CRM_Core_Error::FATAL_ERROR); }
/** * render the page using a custom templating * system * * @param object $page the CRM_Core_Form page * @param boolean $ret should we echo or return output * * @return void * @access public */ function renderForm(&$page, $ret = false) { $this->_setRenderTemplates($page); $template =& CRM_Core_Smarty::singleton(); $template->assign('form', $page->toSmarty()); $template->assign('isForm', 1); $controller =& $page->controller; if ($controller->getEmbedded()) { return; } $template->assign('action', $page->getAction()); $template->assign('tplFile', $page->getTemplateFileName()); $content = $template->fetch($controller->getTemplateFile()); $print = $controller->getPrint(); if ($print) { $html =& $content; } else { $html = CRM_Utils_System::theme('page', $content, true, $print, $ret); } if ($ret) { return $html; } if ($print) { if ($print == CRM_Core_Smarty::PRINT_PDF) { require_once 'CRM/Utils/PDF/Utils.php'; CRM_Utils_PDF_Utils::domlib($content, "{$page->_name}.pdf"); } else { echo $html; } exit; } }
/** * used to load a template "inline", eg. for ajax, without having to build a menu for each template */ public static function loadTemplate() { $request = CRM_Utils_Request::retrieve('q', 'String'); if (FALSE !== strpos($request, '..')) { die("SECURITY FATAL: the url can't contain '..'. Please report the issue on the forum at civicrm.org"); } $request = explode('/', $request); $entity = _civicrm_api_get_camel_name($request[2]); $tplfile = _civicrm_api_get_camel_name($request[3]); $tpl = 'CRM/' . $entity . '/Page/Inline/' . $tplfile . '.tpl'; $smarty = CRM_Core_Smarty::singleton(); CRM_Utils_System::setTitle("{$entity}::{$tplfile} inline {$tpl}"); if (!$smarty->template_exists($tpl)) { header("Status: 404 Not Found"); die("Can't find the requested template file templates/{$tpl}"); } if (array_key_exists('id', $_GET)) { // special treatmenent, because it's often used $smarty->assign('id', (int) $_GET['id']); // an id is always positive } $pos = strpos(implode(array_keys($_GET)), '<'); if ($pos !== FALSE) { die("SECURITY FATAL: one of the param names contains <"); } $param = array_map('htmlentities', $_GET); unset($param['q']); $smarty->assign_by_ref("request", $param); if (!array_key_exists('HTTP_X_REQUESTED_WITH', $_SERVER) || $_SERVER['HTTP_X_REQUESTED_WITH'] != "XMLHttpRequest") { $smarty->assign('tplFile', $tpl); $config = CRM_Core_Config::singleton(); $content = $smarty->fetch('CRM/common/' . strtolower($config->userFramework) . '.tpl'); if (!defined('CIVICRM_UF_HEAD') && ($region = CRM_Core_Region::instance('html-header', FALSE))) { CRM_Utils_System::addHTMLHead($region->render('')); } CRM_Utils_System::appendTPLFile($tpl, $content); return CRM_Utils_System::theme($content); } else { $content = "<!-- .tpl file embeded: {$tpl} -->\n"; CRM_Utils_System::appendTPLFile($tpl, $content); echo $content . $smarty->fetch($tpl); CRM_Utils_System::civiExit(); } }
/** * render the page using a custom templating * system * * @param object $page the CRM_Core_Form page * @param boolean $ret should we echo or return output * * @return void * @access public */ function renderForm(&$page) { $this->_setRenderTemplates($page); $template = CRM_Core_Smarty::singleton(); $form = $page->toSmarty(); $json = CRM_Utils_Request::retrieve('json', 'Boolean', CRM_Core_DAO::$_nullObject); if ($json) { CRM_Utils_JSON::output($form); } $template->assign('form', $form); $template->assign('isForm', 1); $controller =& $page->controller; if ($controller->getEmbedded()) { return; } $template->assign('action', $page->getAction()); $pageTemplateFile = $page->getHookedTemplateFileName(); $template->assign('tplFile', $pageTemplateFile); $content = $template->fetch($controller->getTemplateFile()); if (!defined('CIVICRM_UF_HEAD') && ($region = CRM_Core_Region::instance('html-header', FALSE))) { CRM_Utils_System::addHTMLHead($region->render('')); } CRM_Utils_System::appendTPLFile($pageTemplateFile, $content, $page->overrideExtraTemplateFileName()); //its time to call the hook. CRM_Utils_Hook::alterContent($content, 'form', $pageTemplateFile, $page); $print = $controller->getPrint(); if ($print) { $html =& $content; } else { $html = CRM_Utils_System::theme($content, $print); } if ($controller->_QFResponseType == 'json') { $response = array('content' => $html); // CRM-11831 @see http://www.malsup.com/jquery/form/#file-upload $xhr = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; if (!$xhr) { echo '<textarea>'; } echo json_encode($response); if (!$xhr) { echo '</textarea>'; } CRM_Utils_System::civiExit(); } if ($print) { if ($print == CRM_Core_Smarty::PRINT_PDF) { CRM_Utils_PDF_Utils::html2pdf($content, "{$page->_name}.pdf", FALSE, array('paper_size' => 'a3', 'orientation' => 'landscape')); } else { echo $html; } CRM_Utils_System::civiExit(); } print $html; }