Example #1
0
 /**
  * Get list of groups.
  */
 public static function getGroupList()
 {
     $params = $_GET;
     if (isset($params['parent_id'])) {
         // requesting child groups for a given parent
         $params['page'] = 1;
         $params['rp'] = 0;
         $groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
         CRM_Utils_JSON::output($groups);
     } else {
         $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
         $optionalParameters = array('parentsOnly' => 'Integer', 'showOrgInfo' => 'Boolean');
         $params += CRM_Core_Page_AJAX::validateParams(array(), $optionalParameters);
         // get group list
         $groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
         // if no groups found with parent-child hierarchy and logged in user say can view child groups only (an ACL case),
         // go ahead with flat hierarchy, CRM-12225
         if (empty($groups)) {
             $groupsAccessible = CRM_Core_PseudoConstant::group();
             $parentsOnly = CRM_Utils_Array::value('parentsOnly', $params);
             if (!empty($groupsAccessible) && $parentsOnly) {
                 // recompute group list with flat hierarchy
                 $params['parentsOnly'] = 0;
                 $groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
             }
         }
         CRM_Utils_JSON::output($groups);
     }
 }
Example #2
0
 /**
  * @deprecated
  */
 static function getContactList()
 {
     // if context is 'customfield'
     if (CRM_Utils_Array::value('context', $_GET) == 'customfield') {
         return self::contactReference();
     }
     $params = array('version' => 3, 'check_permissions' => TRUE);
     // String params
     // FIXME: param keys don't match input keys, using this array to translate
     $whitelist = array('s' => 'name', 'fieldName' => 'field_name', 'tableName' => 'table_name', 'context' => 'context', 'rel' => 'rel', 'contact_sub_type' => 'contact_sub_type', 'contact_type' => 'contact_type');
     foreach ($whitelist as $key => $param) {
         if (!empty($_GET[$key])) {
             $params[$param] = $_GET[$key];
         }
     }
     //CRM-10687: Allow quicksearch by multiple fields
     if (!empty($params['field_name'])) {
         if ($params['field_name'] == 'phone_numeric') {
             $params['name'] = preg_replace('/[^\\d]/', '', $params['name']);
         }
         if (!$params['name']) {
             CRM_Utils_System::civiExit();
         }
     }
     // Numeric params
     $whitelist = array('limit', 'org', 'employee_id', 'cid', 'id', 'cmsuser');
     foreach ($whitelist as $key) {
         if (!empty($_GET[$key]) && is_numeric($_GET[$key])) {
             $params[$key] = $_GET[$key];
         }
     }
     $result = civicrm_api('Contact', 'getquick', $params);
     CRM_Core_Page_AJAX::autocompleteResults(CRM_Utils_Array::value('values', $result), 'data');
 }
Example #3
0
 /**
  * Retrieve contact mailings.
  */
 public static function getContactMailings()
 {
     $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
     $params += CRM_Core_Page_AJAX::validateParams(array('contact_id' => 'Integer'));
     // get the contact mailings
     $mailings = CRM_Mailing_BAO_Mailing::getContactMailingSelector($params);
     CRM_Utils_JSON::output($mailings);
 }
 public static function getNavigationMenu()
 {
     $contactID = CRM_Core_Session::singleton()->get('userID');
     if ($contactID) {
         CRM_Core_Page_AJAX::setJsHeaders();
         print CRM_Core_Smarty::singleton()->fetchWith('CRM/Menufontawesome/Page/navigation.js.tpl', array('navigation' => CRM_Menufontawesome_BAO_Navigation::createNavigation($contactID)));
     }
     CRM_Utils_System::civiExit();
 }
Example #5
0
 /**
  * Get Soft credit to list in DT
  */
 public static function getSoftContributionRows()
 {
     $requiredParameters = array('cid' => 'Integer', 'context' => 'String');
     $optionalParameters = array('entityID' => 'Integer', 'isTest' => 'Integer');
     $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
     $params += CRM_Core_Page_AJAX::validateParams($requiredParameters, $optionalParameters);
     $softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionSelector($params);
     if (!empty($_GET['is_unit_test'])) {
         return $softCreditList;
     }
     CRM_Utils_JSON::output($softCreditList);
 }
Example #6
0
 public function testCheckAuthz()
 {
     $cases = array();
     $cases[] = array('method', 'CRM_Foo', FALSE, 'method');
     $cases[] = array('method', 'CRM_Foo_Page_AJAX_Bar', FALSE, 'method');
     $cases[] = array('method', 'CRM_Contact_Page_AJAX', TRUE, 'getAddressDisplay');
     $cases[] = array('method', 'CRM_Foo_Page_AJAX', FALSE, 'method(');
     $cases[] = array('method', 'CRM_Foo_Page_AJAX', FALSE, 'method()');
     $cases[] = array('method', 'othermethod;CRM_Foo_Page_AJAX', FALSE, 'method');
     $cases[] = array('method', 'CRM_Foo_Page_AJAX;othermethod', FALSE, 'method');
     $cases[] = array('method', 'CRM_Foo_Page_Inline_Bar', FALSE, '');
     $cases[] = array('method', 'CRM_Foo_Page_Inline_Bar', FALSE, 'method');
     $cases[] = array('method', 'CRM_Foo->method', FALSE);
     $cases[] = array('page', 'CRM_Foo', FALSE);
     $cases[] = array('page', 'CRM_Foo_Bar', FALSE);
     $cases[] = array('page', 'CRM_Foo_Page', FALSE);
     $cases[] = array('page', 'CRM_Foo_Page_Bar', FALSE);
     $cases[] = array('page', 'CRM_Foo_Page_Inline', FALSE);
     $cases[] = array('page', 'CRM_Contact_Page_Inline_CommunicationPreferences', TRUE);
     $cases[] = array('page', 'CRM_Foo_Page_Inline_Bar_Bang', FALSE);
     $cases[] = array('page', 'othermethod;CRM_Foo_Page_Inline_Bar', FALSE);
     $cases[] = array('page', 'CRM_Foo_Page_Inline_Bar;othermethod', FALSE);
     $cases[] = array('page', 'CRM_Foo_Form', FALSE);
     $cases[] = array('page', 'CRM_Foo_Form_Bar', FALSE);
     $cases[] = array('page', 'CRM_Foo_Form_Inline', FALSE);
     $cases[] = array('page', 'CRM_Contact_Form_Inline_Email', TRUE);
     $cases[] = array('page', 'CRM_Foo_Form_Inline_Bar_Bang', FALSE);
     $cases[] = array('page', 'othermethod;CRM_Foo_Form_Inline_Bar', FALSE);
     $cases[] = array('page', 'CRM_Foo_Form_Inline_Bar;othermethod', FALSE);
     // aliases for 'page'
     $cases[] = array('class', 'CRM_Foo_Bar', FALSE);
     $cases[] = array('class', 'CRM_Contact_Page_Inline_Phone', TRUE);
     $cases[] = array('', 'CRM_Foo_Bar', FALSE);
     $cases[] = array('', 'CRM_Contact_Page_Inline_Demographics', TRUE);
     // invalid type
     $cases[] = array('invalidtype', 'CRM_Foo_Page_Inline_Bar', FALSE);
     $cases[] = array('invalidtype', 'CRM_Foo_Page_AJAX::method', FALSE);
     foreach ($cases as $case) {
         list($type, $className, $expectedResult) = $case;
         $methodName = CRM_Utils_Array::value(3, $case);
         $actualResult = CRM_Core_Page_AJAX::checkAuthz($type, $className, $methodName);
         if ($methodName) {
             $this->assertEquals($expectedResult, $actualResult, sprintf('Check type=[%s] value=[%s] method=[%s]', $type, $className, $methodName));
         } else {
             $this->assertEquals($expectedResult, $actualResult, sprintf('Check type=[%s] value=[%s]', $type, $className));
         }
     }
 }
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     parent::preProcess();
     if ($this->_id) {
         $params = array('id' => $this->_id);
         $financialAccount = CRM_Financial_BAO_FinancialAccount::retrieve($params, CRM_Core_DAO::$_nullArray);
         $financialAccountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type');
         if ($financialAccount->financial_account_type_id == array_search('Asset', $financialAccountType) && strtolower($financialAccount->account_type_code) == 'ar' && !CRM_Financial_BAO_FinancialAccount::getARAccounts($this->_id, array_search('Asset', $financialAccountType))) {
             $this->_isARFlag = TRUE;
             if ($this->_action & CRM_Core_Action::DELETE) {
                 $msg = ts("The selected financial account cannot be deleted because at least one Accounts Receivable type account is required (to ensure that accounting transactions are in balance).");
                 if (CRM_Utils_Array::value('snippet', $_REQUEST) == 'json') {
                     CRM_Core_Page_AJAX::returnJsonResponse($msg);
                 }
                 CRM_Core_Session::setStatus($msg, '', 'error');
                 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/financial/financialAccount', "reset=1&action=browse"));
             }
         }
     }
 }
Example #8
0
 /**
  * Redirect to another URL.
  *
  * @param string $url
  *   The URL to provide to the browser via the Location header.
  */
 public static function redirect($url = NULL)
 {
     if (!$url) {
         $url = self::url('civicrm/dashboard', 'reset=1');
     }
     // replace the & characters with &
     // this is kinda hackish but not sure how to do it right
     $url = str_replace('&', '&', $url);
     // If we are in a json context, respond appropriately
     if (CRM_Utils_Array::value('snippet', $_GET) === 'json') {
         CRM_Core_Page_AJAX::returnJsonResponse(array('status' => 'redirect', 'userContext' => $url));
     }
     self::setHttpHeader('Location', $url);
     self::civiExit();
 }
Example #9
0
 /**
  * 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;
 }
Example #10
0
 /**
  * @throws \CiviCRM_API3_Exception
  */
 public function caseDetails()
 {
     $caseId = CRM_Utils_Type::escape($_GET['caseId'], 'Positive');
     $case = civicrm_api3('Case', 'getsingle', array('id' => $caseId, 'check_permissions' => TRUE, 'return' => array('subject', 'case_type_id', 'status_id', 'start_date', 'end_date')));
     $caseStatuses = CRM_Case_PseudoConstant::caseStatus();
     $caseTypes = CRM_Case_PseudoConstant::caseType('title', FALSE);
     $caseDetails = "<table><tr><td>" . ts('Case Subject') . "</td><td>{$case['subject']}</td></tr>\n                                  <tr><td>" . ts('Case Type') . "</td><td>{$caseTypes[$case['case_type_id']]}</td></tr>\n                                  <tr><td>" . ts('Case Status') . "</td><td>{$caseStatuses[$case['status_id']]}</td></tr>\n                                  <tr><td>" . ts('Case Start Date') . "</td><td>" . CRM_Utils_Date::customFormat($case['start_date']) . "</td></tr>\n                                  <tr><td>" . ts('Case End Date') . "</td><td></td></tr>" . CRM_Utils_Date::customFormat($case['end_date']) . "</table>";
     if (CRM_Utils_Array::value('snippet', $_GET) == 'json') {
         CRM_Core_Page_AJAX::returnJsonResponse($caseDetails);
     }
     echo $caseDetails;
     CRM_Utils_System::civiExit();
 }
Example #11
0
 /**
  * Set a status message in the session, then bounce back to the referrer.
  *
  * @param string $status
  *   The status message to set.
  *
  * @param null $redirect
  * @param string $title
  * @return void
  */
 public static function statusBounce($status, $redirect = NULL, $title = NULL)
 {
     $session = CRM_Core_Session::singleton();
     if (!$redirect) {
         $redirect = $session->readUserContext();
     }
     if ($title === NULL) {
         $title = ts('Error');
     }
     $session->setStatus($status, $title, 'alert', array('expires' => 0));
     if (CRM_Utils_Array::value('snippet', $_REQUEST) === CRM_Core_Smarty::PRINT_JSON) {
         CRM_Core_Page_AJAX::returnJsonResponse(array('status' => 'error'));
     }
     CRM_Utils_System::redirect($redirect);
 }
Example #12
0
 /**
  * Create dynamic script for localizing js widgets.
  */
 public static function outputLocalizationJS()
 {
     CRM_Core_Page_AJAX::setJsHeaders();
     $config = CRM_Core_Config::singleton();
     $vars = array('moneyFormat' => json_encode(CRM_Utils_Money::format(1234.56)), 'contactSearch' => json_encode($config->includeEmailInName ? ts('Start typing a name or email...') : ts('Start typing a name...')), 'otherSearch' => json_encode(ts('Enter search term...')), 'entityRef' => array('contactCreate' => CRM_Core_BAO_UFGroup::getCreateLinks(), 'filters' => self::getEntityRefFilters()), 'ajaxPopupsEnabled' => self::singleton()->ajaxPopupsEnabled);
     print CRM_Core_Smarty::singleton()->fetchWith('CRM/common/l10n.js.tpl', $vars);
     CRM_Utils_System::civiExit();
 }
Example #13
0
 /**
  * Function to obtain list of permissioned employer for the given contact-id.
  */
 static function getPermissionedEmployer()
 {
     $cid = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
     $name = trim(CRM_Utils_Type::escape($_GET['s'], 'String'));
     $name = str_replace('*', '%', $name);
     $elements = CRM_Contact_BAO_Relationship::getPermissionedEmployer($cid, $name);
     $results = array();
     if (!empty($elements)) {
         foreach ($elements as $cid => $name) {
             $results[$cid] = $name['name'];
         }
     }
     CRM_Core_Page_AJAX::autocompleteResults($results);
 }
Example #14
0
 /**
  * just a wrapper, so that we can call all the hook functions
  * @param bool $allowAjax
  *   FIXME: This feels kind of hackish, ideally we would take the json-related code from this function.
  *                          and bury it deeper down in the controller
  */
 public function mainProcess($allowAjax = TRUE)
 {
     $this->postProcess();
     $this->postProcessHook();
     // Respond with JSON if in AJAX context (also support legacy value '6')
     if ($allowAjax && !empty($_REQUEST['snippet']) && in_array($_REQUEST['snippet'], array(CRM_Core_Smarty::PRINT_JSON, 6))) {
         $this->ajaxResponse['buttonName'] = str_replace('_qf_' . $this->getAttribute('id') . '_', '', $this->controller->getButtonName());
         $this->ajaxResponse['action'] = $this->_action;
         if (isset($this->_id) || isset($this->id)) {
             $this->ajaxResponse['id'] = isset($this->id) ? $this->id : $this->_id;
         }
         CRM_Core_Page_AJAX::returnJsonResponse($this->ajaxResponse);
     }
 }
Example #15
0
| GNU Affero General Public License or the licensing of CiviCRM,     |
| see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+--------------------------------------------------------------------+
*/
/**
 *
 * @package CRM
 * @copyright CiviCRM LLC (c) 2004-2015
 * $Id$
 */
require_once '../civicrm.config.php';
require_once 'CRM/Core/Config.php';
$config = CRM_Core_Config::singleton();
$template = CRM_Core_Smarty::singleton();
require_once 'CRM/Utils/Request.php';
$cpageId = CRM_Utils_Request::retrieve('cpageId', 'Positive', CRM_Core_DAO::$_nullObject);
$widgetId = CRM_Utils_Request::retrieve('widgetId', 'Positive', CRM_Core_DAO::$_nullObject);
$format = CRM_Utils_Request::retrieve('format', 'Positive', CRM_Core_DAO::$_nullObject);
$includePending = CRM_Utils_Request::retrieve('includePending', 'Boolean', CRM_Core_DAO::$_nullObject);
require_once 'CRM/Contribute/BAO/Widget.php';
$jsonvar = 'jsondata';
if (isset($format)) {
    $jsonvar .= $cpageId;
}
$data = CRM_Contribute_BAO_Widget::getContributionPageData($cpageId, $widgetId, $includePending);
$output = '
    var ' . $jsonvar . ' = ' . json_encode($data) . ';
';
CRM_Core_Page_AJAX::setJsHeaders(60);
echo $output;
CRM_Utils_System::civiExit();
Example #16
0
 public function caseDetails()
 {
     $caseId = CRM_Utils_Type::escape($_GET['caseId'], 'Positive');
     if (!CRM_Case_BAO_Case::accessCase($caseId, FALSE)) {
         CRM_Utils_System::permissionDenied();
     }
     $sql = "SELECT civicrm_case.*, civicrm_case_type.title as case_type\n        FROM civicrm_case\n        INNER JOIN civicrm_case_type ON civicrm_case.case_type_id = civicrm_case_type.id\n        WHERE civicrm_case.id = %1";
     $dao = CRM_Core_DAO::executeQuery($sql, array(1 => array($caseId, 'Integer')));
     if ($dao->fetch()) {
         $caseStatuses = CRM_Case_PseudoConstant::caseStatus();
         $cs = $caseStatuses[$dao->status_id];
         $caseDetails = "<table><tr><td>" . ts('Case Subject') . "</td><td>{$dao->subject}</td></tr>\n                                    <tr><td>" . ts('Case Type') . "</td><td>{$dao->case_type}</td></tr>\n                                    <tr><td>" . ts('Case Status') . "</td><td>{$cs}</td></tr>\n                                    <tr><td>" . ts('Case Start Date') . "</td><td>" . CRM_Utils_Date::customFormat($dao->start_date) . "</td></tr>\n                                    <tr><td>" . ts('Case End Date') . "</td><td></td></tr>" . CRM_Utils_Date::customFormat($dao->end_date) . "</table>";
         if (CRM_Utils_Array::value('snippet', $_GET) == 'json') {
             CRM_Core_Page_AJAX::returnJsonResponse($caseDetails);
         } else {
             echo $caseDetails;
         }
     } else {
         CRM_Core_Error::fatal('Could not find valid Case.');
     }
     CRM_Utils_System::civiExit();
 }
Example #17
0
 /**
  * @param $url
  */
 public static function fixOrderOutput($url)
 {
     if (empty($_GET['snippet']) || $_GET['snippet'] !== 'json') {
         CRM_Utils_System::redirect($url);
     }
     CRM_Core_Page_AJAX::returnJsonResponse(array('userContext' => $url));
 }
Example #18
0
 /**
  * Function to build status message while
  * enabling/ disabling various objects
  */
 static function getStatusMsg()
 {
     require_once 'api/v3/utils.php';
     $recordID = CRM_Utils_Type::escape($_GET['id'], 'Integer');
     $entity = CRM_Utils_Type::escape($_GET['entity'], 'String');
     $ret = array();
     if ($recordID && $entity && ($recordBAO = _civicrm_api3_get_BAO($entity))) {
         switch ($recordBAO) {
             case 'CRM_Core_BAO_UFGroup':
                 $method = 'getUFJoinRecord';
                 $result = array($recordBAO, $method);
                 $ufJoin = call_user_func_array($result, array($recordID, TRUE));
                 if (!empty($ufJoin)) {
                     $ret['content'] = ts('This profile is currently used for %1.', array(1 => implode(', ', $ufJoin))) . ' <br/><br/>' . ts('If you disable the profile - it will be removed from these forms and/or modules. Do you want to continue?');
                 } else {
                     $ret['content'] = ts('Are you sure you want to disable this profile?');
                 }
                 break;
             case 'CRM_Price_BAO_PriceSet':
                 $usedBy = CRM_Price_BAO_PriceSet::getUsedBy($recordID);
                 $priceSet = CRM_Price_BAO_PriceSet::getTitle($recordID);
                 if (!CRM_Utils_System::isNull($usedBy)) {
                     $template = CRM_Core_Smarty::singleton();
                     $template->assign('usedBy', $usedBy);
                     $comps = array('Event' => 'civicrm_event', 'Contribution' => 'civicrm_contribution_page', 'EventTemplate' => 'civicrm_event_template');
                     $contexts = array();
                     foreach ($comps as $name => $table) {
                         if (array_key_exists($table, $usedBy)) {
                             $contexts[] = $name;
                         }
                     }
                     $template->assign('contexts', $contexts);
                     $ret['illegal'] = TRUE;
                     $table = $template->fetch('CRM/Price/Page/table.tpl');
                     $ret['content'] = ts('Unable to disable the \'%1\' price set - it is currently in use by one or more active events, contribution pages or contributions.', array(1 => $priceSet)) . "<br/> {$table}";
                 } else {
                     $ret['content'] = ts('Are you sure you want to disable \'%1\' Price Set?', array(1 => $priceSet));
                 }
                 break;
             case 'CRM_Event_BAO_Event':
                 $ret['content'] = ts('Are you sure you want to disable this Event?');
                 break;
             case 'CRM_Core_BAO_UFField':
                 $ret['content'] = ts('Are you sure you want to disable this CiviCRM Profile field?');
                 break;
             case 'CRM_Contribute_BAO_ManagePremiums':
                 $ret['content'] = ts('Are you sure you want to disable this premium? This action will remove the premium from any contribution pages that currently offer it. However it will not delete the premium record - so you can re-enable it and add it back to your contribution page(s) at a later time.');
                 break;
             case 'CRM_Contact_BAO_Relationship':
                 $ret['content'] = ts('Are you sure you want to disable this relationship?');
                 break;
             case 'CRM_Contact_BAO_RelationshipType':
                 $ret['content'] = ts('Are you sure you want to disable this relationship type?') . '<br/><br/>' . ts('Users will no longer be able to select this value when adding or editing relationships between contacts.');
                 break;
             case 'CRM_Financial_BAO_FinancialType':
                 $ret['content'] = ts('Are you sure you want to disable this financial type?');
                 break;
             case 'CRM_Financial_BAO_FinancialAccount':
                 if (!CRM_Financial_BAO_FinancialAccount::getARAccounts($recordID)) {
                     $ret['illegal'] = TRUE;
                     $ret['content'] = ts('The selected financial account cannot be disabled because at least one Accounts Receivable type account is required (to ensure that accounting transactions are in balance).');
                 } else {
                     $ret['content'] = ts('Are you sure you want to disable this financial account?');
                 }
                 break;
             case 'CRM_Financial_BAO_PaymentProcessor':
                 $ret['content'] = ts('Are you sure you want to disable this payment processor?') . ' <br/><br/>' . ts('Users will no longer be able to select this value when adding or editing transaction pages.');
                 break;
             case 'CRM_Financial_BAO_PaymentProcessorType':
                 $ret['content'] = ts('Are you sure you want to disable this payment processor type?');
                 break;
             case 'CRM_Core_BAO_LocationType':
                 $ret['content'] = ts('Are you sure you want to disable this location type?') . ' <br/><br/>' . ts('Users will no longer be able to select this value when adding or editing contact locations.');
                 break;
             case 'CRM_Event_BAO_ParticipantStatusType':
                 $ret['content'] = ts('Are you sure you want to disable this Participant Status?') . '<br/><br/> ' . ts('Users will no longer be able to select this value when adding or editing Participant Status.');
                 break;
             case 'CRM_Mailing_BAO_Component':
                 $ret['content'] = ts('Are you sure you want to disable this component?');
                 break;
             case 'CRM_Core_BAO_CustomField':
                 $ret['content'] = ts('Are you sure you want to disable this custom data field?');
                 break;
             case 'CRM_Core_BAO_CustomGroup':
                 $ret['content'] = ts('Are you sure you want to disable this custom data group? Any profile fields that are linked to custom fields of this group will be disabled.');
                 break;
             case 'CRM_Core_BAO_MessageTemplate':
                 $ret['content'] = ts('Are you sure you want to disable this message tempate?');
                 break;
             case 'CRM_ACL_BAO_ACL':
                 $ret['content'] = ts('Are you sure you want to disable this ACL?');
                 break;
             case 'CRM_ACL_BAO_EntityRole':
                 $ret['content'] = ts('Are you sure you want to disable this ACL Role Assignment?');
                 break;
             case 'CRM_Member_BAO_MembershipType':
                 $ret['content'] = ts('Are you sure you want to disable this membership type?');
                 break;
             case 'CRM_Member_BAO_MembershipStatus':
                 $ret['content'] = ts('Are you sure you want to disable this membership status rule?');
                 break;
             case 'CRM_Price_BAO_PriceField':
                 $ret['content'] = ts('Are you sure you want to disable this price field?');
                 break;
             case 'CRM_Contact_BAO_Group':
                 $ret['content'] = ts('Are you sure you want to disable this Group?');
                 break;
             case 'CRM_Core_BAO_OptionGroup':
                 $ret['content'] = ts('Are you sure you want to disable this Option?');
                 break;
             case 'CRM_Contact_BAO_ContactType':
                 $ret['content'] = ts('Are you sure you want to disable this Contact Type?');
                 break;
             case 'CRM_Core_BAO_OptionValue':
                 $label = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $recordID, 'label');
                 $ret['content'] = ts('Are you sure you want to disable the \'%1\' option ?', array(1 => $label));
                 $ret['content'] .= '<br /><br />' . ts('WARNING - Disabling an option which has been assigned to existing records will result in that option being cleared when the record is edited.');
                 break;
             case 'CRM_Contribute_BAO_ContributionRecur':
                 $recurDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($recordID);
                 $ret['content'] = ts('Are you sure you want to mark this recurring contribution as cancelled?');
                 $ret['content'] .= '<br /><br /><strong>' . ts('WARNING - This action sets the CiviCRM recurring contribution status to Cancelled, but does NOT send a cancellation request to the payment processor. You will need to ensure that this recurring payment (subscription) is cancelled by the payment processor.') . '</strong>';
                 if ($recurDetails->membership_id) {
                     $ret['content'] .= '<br /><br /><strong>' . ts('This recurring contribution is linked to an auto-renew membership. If you cancel it, the associated membership will no longer renew automatically. However, the current membership status will not be affected.') . '</strong>';
                 }
                 break;
             default:
                 $ret['content'] = ts('Are you sure you want to disable this record?');
                 break;
         }
     } else {
         $ret = array('status' => 'error', 'content' => 'Error: Unknown entity type.', 'illegal' => TRUE);
     }
     CRM_Core_Page_AJAX::returnJsonResponse($ret);
 }
Example #19
0
 /**
  * Run this page (figure out the action needed and perform it).
  *
  * @param int $id
  * @param int $contactID
  * @param bool $print
  * @param bool $allowID
  */
 public function run($id = NULL, $contactID = NULL, $print = TRUE, $allowID = FALSE)
 {
     if (is_numeric($id)) {
         $this->_mailingID = $id;
     } else {
         $print = TRUE;
         $this->_mailingID = CRM_Utils_Request::retrieve('id', 'String', CRM_Core_DAO::$_nullObject, TRUE);
     }
     // # CRM-7651
     // override contactID from the function level if passed in
     if (isset($contactID) && is_numeric($contactID)) {
         $this->_contactID = $contactID;
     } else {
         $session = CRM_Core_Session::singleton();
         $this->_contactID = $session->get('userID');
     }
     // mailing key check
     if (Civi::settings()->get('hash_mailing_url')) {
         $this->_mailing = new CRM_Mailing_BAO_Mailing();
         if (!is_numeric($this->_mailingID)) {
             $this->_mailing->hash = $this->_mailingID;
         } elseif (is_numeric($this->_mailingID)) {
             $this->_mailing->id = $this->_mailingID;
             // if mailing is present and associated hash is present
             // while 'hash' is not been used for mailing view : throw 'permissionDenied'
             if ($this->_mailing->find() && CRM_Core_DAO::getFieldValue('CRM_Mailing_BAO_Mailing', $this->_mailingID, 'hash', 'id') && !$allowID) {
                 CRM_Utils_System::permissionDenied();
                 return;
             }
         }
     } else {
         $this->_mailing = new CRM_Mailing_BAO_Mailing();
         $this->_mailing->id = $this->_mailingID;
     }
     if (!$this->_mailing->find(TRUE) || !$this->checkPermission()) {
         CRM_Utils_System::permissionDenied();
         return;
     }
     CRM_Mailing_BAO_Mailing::tokenReplace($this->_mailing);
     // get and format attachments
     $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $this->_mailing->id);
     // get contact detail and compose if contact id exists
     $returnProperties = $this->_mailing->getReturnProperties();
     if (isset($this->_contactID)) {
         // get details of contact with token value including Custom Field Token Values.CRM-3734
         $params = array('contact_id' => $this->_contactID);
         $details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, FALSE, TRUE, NULL, $this->_mailing->getFlattenedTokens(), get_class($this));
         $details = $details[0][$this->_contactID];
         $contactId = $this->_contactID;
     } else {
         // get tokens that are not contact specific resolved
         $params = array('contact_id' => 0);
         $details = CRM_Utils_Token::getAnonymousTokenDetails($params, $returnProperties, TRUE, TRUE, NULL, $this->_mailing->getFlattenedTokens(), get_class($this));
         $details = CRM_Utils_Array::value(0, $details[0]);
         $contactId = 0;
     }
     $mime =& $this->_mailing->compose(NULL, NULL, NULL, $contactId, $this->_mailing->from_email, $this->_mailing->from_email, TRUE, $details, $attachments);
     $title = NULL;
     if (isset($this->_mailing->body_html) && empty($_GET['text'])) {
         $header = 'text/html; charset=utf-8';
         $content = $mime->getHTMLBody();
         if (strpos($content, '<head>') === FALSE && strpos($content, '<title>') === FALSE) {
             $title = '<head><title>' . $this->_mailing->subject . '</title></head>';
         }
     } else {
         $header = 'text/plain; charset=utf-8';
         $content = $mime->getTXTBody();
     }
     CRM_Utils_System::setTitle($this->_mailing->subject);
     if (CRM_Utils_Array::value('snippet', $_GET) === 'json') {
         CRM_Core_Page_AJAX::returnJsonResponse($content);
     }
     if ($print) {
         CRM_Utils_System::setHttpHeader('Content-Type', $header);
         print $title;
         print $content;
         CRM_Utils_System::civiExit();
     } else {
         return $content;
     }
 }
Example #20
0
 /**
  * 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;
 }
Example #21
0
File: REST.php Project: kidaa30/yes
 /**
  * @param $args
  * @param array $params
  *
  * @return array|int
  */
 public static function process(&$args, $params)
 {
     $params['check_permissions'] = TRUE;
     $fnName = $apiFile = NULL;
     // clean up all function / class names. they should be alphanumeric and _ only
     for ($i = 1; $i <= 3; $i++) {
         if (!empty($args[$i])) {
             $args[$i] = CRM_Utils_String::munge($args[$i]);
         }
     }
     // incase of ajax functions className is passed in url
     if (isset($params['className'])) {
         $params['className'] = CRM_Utils_String::munge($params['className']);
         // functions that are defined only in AJAX.php can be called via
         // rest interface
         if (!CRM_Core_Page_AJAX::checkAuthz('method', $params['className'], $params['fnName'])) {
             return self::error('Unknown function invocation.');
         }
         return call_user_func(array($params['className'], $params['fnName']), $params);
     }
     if (!array_key_exists('version', $params)) {
         $params['version'] = 3;
     }
     if ($params['version'] == 2) {
         $result['is_error'] = 1;
         $result['error_message'] = "FATAL: API v2 not accessible from ajax/REST";
         $result['deprecated'] = "Please upgrade to API v3";
         return $result;
     }
     if ($_SERVER['REQUEST_METHOD'] == 'GET' && strtolower(substr($args[2], 0, 3)) != 'get' && strtolower($args[2] != 'check')) {
         // get only valid for non destructive methods
         require_once 'api/v3/utils.php';
         return civicrm_api3_create_error("SECURITY: All requests that modify the database must be http POST, not GET.", array('IP' => $_SERVER['REMOTE_ADDR'], 'level' => 'security', 'referer' => $_SERVER['HTTP_REFERER'], 'reason' => 'Destructive HTTP GET'));
     }
     // trap all fatal errors
     $errorScope = CRM_Core_TemporaryErrorScope::create(array('CRM_Utils_REST', 'fatal'));
     $result = civicrm_api($args[1], $args[2], $params);
     unset($errorScope);
     if ($result === FALSE) {
         return self::error('Unknown error.');
     }
     return $result;
 }
Example #22
0
 /**
  * Get list of Multi Record Fields.
  *
  */
 public static function getMultiRecordFieldList()
 {
     $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(0, 10);
     $params['cid'] = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
     $params['cgid'] = CRM_Utils_Type::escape($_GET['cgid'], 'Integer');
     $contactType = CRM_Contact_BAO_Contact::getContactType($params['cid']);
     $obj = new CRM_Profile_Page_MultipleRecordFieldsListing();
     $obj->_pageViewType = 'customDataView';
     $obj->_contactId = $params['cid'];
     $obj->_customGroupId = $params['cgid'];
     $obj->_contactType = $contactType;
     $obj->_DTparams['offset'] = ($params['page'] - 1) * $params['rp'];
     $obj->_DTparams['rowCount'] = $params['rp'];
     if (!empty($params['sortBy'])) {
         $obj->_DTparams['sort'] = $params['sortBy'];
     }
     list($fields, $attributes) = $obj->browse();
     // format params and add class attributes
     $fieldList = array();
     foreach ($fields as $id => $value) {
         $field = array();
         foreach ($value as $fieldId => &$fieldName) {
             if (!empty($attributes[$fieldId][$id]['class'])) {
                 $fieldName = array('data' => $fieldName, 'cellClass' => $attributes[$fieldId][$id]['class']);
             }
             if (is_numeric($fieldId)) {
                 $fName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $fieldId, 'column_name');
                 CRM_Utils_Array::crmReplaceKey($value, $fieldId, $fName);
             }
         }
         $field = $value;
         array_push($fieldList, $field);
     }
     $totalRecords = !empty($obj->_total) ? $obj->_total : 0;
     $multiRecordFields = array();
     $multiRecordFields['data'] = $fieldList;
     $multiRecordFields['recordsTotal'] = $totalRecords;
     $multiRecordFields['recordsFiltered'] = $totalRecords;
     if (!empty($_GET['is_unit_test'])) {
         return $multiRecordFields;
     }
     CRM_Utils_JSON::output($multiRecordFields);
 }
Example #23
0
 /**
  * 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);
 }
Example #24
0
 /**
  * Function for building EventFee combo box
  */
 function eventFee()
 {
     $name = trim(CRM_Utils_Type::escape($_GET['s'], 'String'));
     if (!$name) {
         $name = '%';
     }
     $whereClause = "cv.label LIKE '{$name}%' ";
     $query = "SELECT DISTINCT (\ncv.label\n), cv.id\nFROM civicrm_price_field_value cv\nLEFT JOIN civicrm_price_field cf ON cv.price_field_id = cf.id\nLEFT JOIN civicrm_price_set_entity ce ON ce.price_set_id = cf.price_set_id\nWHERE ce.entity_table = 'civicrm_event' AND {$whereClause}\nGROUP BY cv.label";
     $dao = CRM_Core_DAO::executeQuery($query);
     $results = array();
     while ($dao->fetch()) {
         $results[$dao->id] = $dao->label;
     }
     CRM_Core_Page_AJAX::autocompleteResults($results);
 }
 public function displayStatusMessage($messageTitle, $message)
 {
     $out = array('status' => 'fatal', 'content' => '<div class="messages status no-popup"><div class="icon inform-icon"></div>' . ts($message) . '</div>');
     CRM_Core_Session::setStatus($message, ts($messageTitle), 'error');
     CRM_Core_Page_AJAX::returnJsonResponse($out);
 }
Example #26
0
 /**
  * Retrieve contact relationships.
  */
 public static function getContactRelationships()
 {
     $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
     $context = CRM_Utils_Type::escape($_GET['context'], 'String');
     $relationship_type_id = CRM_Utils_Type::escape(CRM_Utils_Array::value('relationship_type_id', $_GET), 'Integer', FALSE);
     if (!CRM_Contact_BAO_Contact_Permission::allow($contactID)) {
         return CRM_Utils_System::permissionDenied();
     }
     $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
     $params['contact_id'] = $contactID;
     $params['context'] = $context;
     if ($relationship_type_id) {
         $params['relationship_type_id'] = $relationship_type_id;
     }
     // get the contact relationships
     $relationships = CRM_Contact_BAO_Relationship::getContactRelationshipSelector($params);
     CRM_Utils_JSON::output($relationships);
 }
Example #27
0
 public static function getContactActivity()
 {
     $requiredParameters = array('cid' => 'Integer');
     $optionalParameters = array('context' => 'String', 'activity_type_id' => 'Integer', 'activity_type_exclude_id' => 'Integer');
     $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
     $params += CRM_Core_Page_AJAX::validateParams($requiredParameters, $optionalParameters);
     // To be consistent, the cid parameter should be renamed to contact_id in
     // the template file, see templates/CRM/Activity/Selector/Selector.tpl
     $params['contact_id'] = $params['cid'];
     unset($params['cid']);
     // get the contact activities
     $activities = CRM_Activity_BAO_Activity::getContactActivitySelector($params);
     if (!empty($_GET['is_unit_test'])) {
         return $activities;
     }
     foreach ($activities['data'] as $key => $value) {
         // Check if recurring activity.
         if (!empty($value['is_recurring_activity'])) {
             $repeat = $value['is_recurring_activity'];
             $activities['data'][$key]['activity_type'] .= '<br/><span class="bold">' . ts('Repeating (%1 of %2)', array(1 => $repeat[0], 2 => $repeat[1])) . '</span>';
         }
     }
     // store the activity filter preference CRM-11761
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     if ($userID) {
         $activityFilter = array('activity_type_filter_id' => empty($params['activity_type_id']) ? '' : CRM_Utils_Type::escape($params['activity_type_id'], 'Integer'), 'activity_type_exclude_filter_id' => empty($params['activity_type_exclude_id']) ? '' : CRM_Utils_Type::escape($params['activity_type_exclude_id'], 'Integer'));
         /**
          * @var \Civi\Core\SettingsBag $cSettings
          */
         $cSettings = Civi::service('settings_manager')->getBagByContact(CRM_Core_Config::domainID(), $userID);
         $cSettings->set('activity_tab_filter', $activityFilter);
     }
     CRM_Utils_JSON::output($activities);
 }