public static function updateMode()
 {
     $finalResult = array();
     if (CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST) && CRM_Utils_Array::value('entityTable', $_REQUEST)) {
         $mode = CRM_Utils_Type::escape($_REQUEST['mode'], 'Integer');
         $entityId = CRM_Utils_Type::escape($_REQUEST['entityId'], 'Integer');
         $entityTable = CRM_Utils_Type::escape($_REQUEST['entityTable'], 'String');
         if (!empty($_REQUEST['linkedEntityTable'])) {
             $result = CRM_Core_BAO_RecurringEntity::updateModeLinkedEntity($entityId, $_REQUEST['linkedEntityTable'], $entityTable);
         }
         $dao = new CRM_Core_DAO_RecurringEntity();
         if (!empty($result)) {
             $dao->entity_id = $result['entityId'];
             $dao->entity_table = $result['entityTable'];
         } else {
             $dao->entity_id = $entityId;
             $dao->entity_table = $entityTable;
         }
         if ($dao->find(TRUE)) {
             $dao->mode = $mode;
             $dao->save();
             $finalResult['status'] = 'Done';
         } else {
             $finalResult['status'] = 'Error';
         }
     }
     CRM_Utils_JSON::output($finalResult);
 }
Esempio n. 2
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);
     }
 }
Esempio n. 3
0
 /**
  * Function the check whether the field belongs.
  * to multi-record custom set
  */
 public function checkIsMultiRecord()
 {
     $customId = $_GET['customId'];
     $isMultiple = CRM_Core_BAO_CustomField::isMultiRecordField($customId);
     $isMultiple = array('is_multi' => $isMultiple);
     CRM_Utils_JSON::output($isMultiple);
 }
 /**
  * Used to store selected contacts across multiple pages in advanced search.
  */
 public static function selectUnselectRelationships()
 {
     $name = CRM_Utils_Array::value('name', $_REQUEST);
     $cacheKey = CRM_Utils_Array::value('qfKey', $_REQUEST);
     $state = CRM_Utils_Array::value('state', $_REQUEST, 'checked');
     $variableType = CRM_Utils_Array::value('variableType', $_REQUEST, 'single');
     $actionToPerform = CRM_Utils_Array::value('action', $_REQUEST, 'select');
     if ($variableType == 'multiple') {
         // action post value only works with multiple type variable
         if ($name) {
             //multiple names like mark_x_1-mark_x_2 where 1,2 are cids
             $elements = explode('-', $name);
             foreach ($elements as $key => $element) {
                 $elements[$key] = self::_convertToId($element);
             }
             CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $actionToPerform, $elements, 'civicrm_relationship');
         } else {
             CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $actionToPerform, NULL, 'civicrm_relationship');
         }
     } elseif ($variableType == 'single') {
         $cId = self::_convertToId($name);
         $action = $state == 'checked' ? 'select' : 'unselect';
         CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $action, $cId, 'civicrm_relationship');
     }
     $contactIds = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey, 'get', 'civicrm_relationship');
     $countSelectionCids = count($contactIds[$cacheKey]);
     $arrRet = array('getCount' => $countSelectionCids);
     CRM_Utils_JSON::output($arrRet);
 }
Esempio n. 5
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);
 }
Esempio n. 6
0
 /**
  * Get list of teams.
  *
  * @return array
  */
 public static function getTeamList()
 {
     $params = $_REQUEST;
     if (isset($params['parent_id'])) {
         // requesting child groups for a given parent
         $params['page'] = 1;
         $params['rp'] = 0;
         $groups = self::getTeamListSelector($params);
         CRM_Utils_JSON::output($groups);
     } else {
         $sortMapper = array(0 => 'groups.title', 1 => 'count', 2 => 'createdBy.sort_name', 3 => '', 4 => 'groups.group_type', 5 => 'groups.visibility');
         $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
         $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
         $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
         $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
         $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
         if ($sort && $sortOrder) {
             $params['sortBy'] = $sort . ' ' . $sortOrder;
         }
         $params['page'] = $offset / $rowCount + 1;
         $params['rp'] = $rowCount;
         $params['group_type'] = teamGroupType();
         // restrict to teams logged in user may access
         $contact = billing_contact_get();
         //@todo remove for admin
         if (!CRM_Core_Permission::check('edit all contacts')) {
             $params['created_by'] = $contact['sort_name'];
         }
         // get team list
         $groups = self::getTeamListSelector($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
         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 = self::getTeamListSelector($params);
             }
         }
         $iFilteredTotal = $iTotal = count($groups);
         //$params['total'];
         $selectorElements = array('group_name', 'count', 'created_by', 'group_description', 'group_type', 'visibility', 'org_info', 'links', 'class');
         if (empty($params['showOrgInfo'])) {
             unset($selectorElements[6]);
         }
         //add setting so this can be tested by unit test
         //@todo - ideally the portion of this that retrieves the groups should be extracted into a function separate
         // from the one which deals with web inputs & outputs so we have a properly testable & re-usable function
         if (!empty($params['is_unit_test'])) {
             return array($groups, $iFilteredTotal);
         }
         header('Content-Type: application/json');
         echo CRM_Utils_JSON::encodeDataTableSelector($groups, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
         CRM_Utils_System::civiExit();
     }
 }
Esempio n. 7
0
 /**
  * Function to setDefaults according to Pledge Id
  * for batch entry pledges
  */
 public function getPledgeDefaults()
 {
     $details = array();
     if (!empty($_POST['pid'])) {
         $pledgeID = CRM_Utils_Type::escape($_POST['pid'], 'Integer');
         $details = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeID);
     }
     CRM_Utils_JSON::output($details);
 }
Esempio n. 8
0
 /**
  * Function to fetch the template text/html messages
  */
 public static function template()
 {
     $templateId = CRM_Utils_Type::escape($_POST['tid'], 'Integer');
     $messageTemplate = new CRM_Core_DAO_MessageTemplate();
     $messageTemplate->id = $templateId;
     $messageTemplate->selectAdd();
     $messageTemplate->selectAdd('msg_text, msg_html, msg_subject, pdf_format_id');
     $messageTemplate->find(TRUE);
     $messages = array('subject' => $messageTemplate->msg_subject, 'msg_text' => $messageTemplate->msg_text, 'msg_html' => $messageTemplate->msg_html, 'pdf_format_id' => $messageTemplate->pdf_format_id);
     CRM_Utils_JSON::output($messages);
 }
 /**
  * Provide the legislators for the given address.
  *
  * Echos JSON object of the names, photo URLs, and emails.
  */
 public function run()
 {
     $addressValues = array('Postal_Code_Field' => CRM_Utils_Request::retrieve('zip', 'Int'), 'State_Province_Field' => CRM_Utils_Request::retrieve('state', 'Int'), 'City_Field' => CRM_Utils_Request::retrieve('city', 'String'), 'Street_Address_Field' => CRM_Utils_Request::retrieve('address', 'String'));
     foreach ($addressValues as $val) {
         if (empty($val)) {
             return;
         }
     }
     $recipients = CRM_Petitionemail_Interface_Statelegemail::findRecipients($addressValues);
     CRM_Utils_JSON::output($recipients);
 }
Esempio n. 10
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);
 }
Esempio n. 11
0
 /**
  * Building EventFee combo box.
  * FIXME: This ajax callback could be eliminated in favor of an entityRef field but the priceFieldValue api doesn't currently support filtering on entity_table
  */
 public function eventFee()
 {
     $name = trim(CRM_Utils_Type::escape($_GET['term'], '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[] = array('id' => $dao->id, 'text' => $dao->label);
     }
     CRM_Utils_JSON::output($results);
 }
Esempio n. 12
0
 /**
  * Get list of groups.
  *
  * @return array
  */
 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 {
         $sortMapper = array();
         foreach ($_GET['columns'] as $key => $value) {
             $sortMapper[$key] = $value['data'];
         }
         $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0;
         $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25;
         $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL;
         $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc';
         if ($sort && $sortOrder) {
             $params['sortBy'] = $sort . ' ' . $sortOrder;
         }
         $params['page'] = $offset / $rowCount + 1;
         $params['rp'] = $rowCount;
         // 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);
             }
         }
         //add setting so this can be tested by unit test
         //@todo - ideally the portion of this that retrieves the groups should be extracted into a function separate
         // from the one which deals with web inputs & outputs so we have a properly testable & re-usable function
         if (!empty($params['is_unit_test'])) {
             return array($groups, $iFilteredTotal);
         }
         CRM_Utils_JSON::output($groups);
     }
 }
Esempio n. 13
0
 /**
  * Fix Ordering of options
  *
  */
 public static function fixOrdering()
 {
     $params = $_REQUEST;
     $queryParams = array(1 => array($params['start'], 'Integer'), 2 => array($params['end'], 'Integer'), 3 => array($params['gid'], 'Integer'));
     $dao = "SELECT id FROM civicrm_option_value WHERE weight = %1 AND option_group_id = %3";
     $startid = CRM_Core_DAO::singleValueQuery($dao, $queryParams);
     $dao2 = "SELECT id FROM civicrm_option_value WHERE weight = %2 AND option_group_id = %3";
     $endid = CRM_Core_DAO::singleValueQuery($dao2, $queryParams);
     $query = "UPDATE civicrm_option_value SET weight = %2 WHERE id = {$startid}";
     CRM_Core_DAO::executeQuery($query, $queryParams);
     // increment or decrement the rest by one
     if ($params['start'] < $params['end']) {
         $updateRows = "UPDATE civicrm_option_value\n                  SET weight = weight - 1\n                  WHERE weight > %1 AND weight < %2 AND option_group_id = %3\n                  OR id = {$endid}";
     } else {
         $updateRows = "UPDATE civicrm_option_value\n                  SET weight = weight + 1\n                  WHERE weight < %1 AND weight > %2 AND option_group_id = %3\n                  OR id = {$endid}";
     }
     CRM_Core_DAO::executeQuery($updateRows, $queryParams);
     CRM_Utils_JSON::output(TRUE);
 }
Esempio n. 14
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 {
         $sortMapper = array();
         $columns = CRM_Utils_Array::value('columns', $params, array());
         foreach ($columns as $key => $value) {
             $sortMapper[$key] = $value['data'];
         }
         $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0;
         $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25;
         $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL;
         $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc';
         if ($sort && $sortOrder) {
             $params['sortBy'] = $sort . ' ' . $sortOrder;
         }
         $params['page'] = $offset / $rowCount + 1;
         $params['rp'] = $rowCount;
         // 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);
     }
 }
Esempio n. 15
0
 /**
  * Retrieve contact mailings.
  */
 public static function getContactMailings()
 {
     $contactID = CRM_Utils_Type::escape($_GET['contact_id'], 'Integer');
     $sortMapper = array();
     foreach ($_GET['columns'] as $key => $value) {
         $sortMapper[$key] = $value['data'];
     }
     $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0;
     $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25;
     $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL;
     $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc';
     $params = $_GET;
     if ($sort && $sortOrder) {
         $params['sortBy'] = $sort . ' ' . $sortOrder;
     }
     $params['page'] = $offset / $rowCount + 1;
     $params['rp'] = $rowCount;
     $params['contact_id'] = $contactID;
     $params['context'] = $context;
     // get the contact mailings
     $mailings = CRM_Mailing_BAO_Mailing::getContactMailingSelector($params);
     CRM_Utils_JSON::output($mailings);
 }
Esempio n. 16
0
File: AJAX.php Progetto: kidaa30/yes
 /**
  * SetDefaults according to membership type.
  */
 public static function getMemberTypeDefaults()
 {
     if (!$_POST['mtype']) {
         $details['name'] = '';
         $details['auto_renew'] = '';
         $details['total_amount'] = '';
         CRM_Utils_JSON::output($details);
     }
     $memType = CRM_Utils_Type::escape($_POST['mtype'], 'Integer');
     $query = "SELECT name, minimum_fee AS total_amount, financial_type_id, auto_renew\nFROM    civicrm_membership_type\nWHERE   id = %1";
     $dao = CRM_Core_DAO::executeQuery($query, array(1 => array($memType, 'Positive')));
     $properties = array('financial_type_id', 'total_amount', 'name', 'auto_renew');
     while ($dao->fetch()) {
         foreach ($properties as $property) {
             $details[$property] = $dao->{$property};
         }
     }
     $details['total_amount_numeric'] = $details['total_amount'];
     // fix the display of the monetary value, CRM-4038
     $details['total_amount'] = CRM_Utils_Money::format($details['total_amount'], NULL, '%a');
     $options = CRM_Core_SelectValues::memberAutoRenew();
     $details['auto_renew'] = CRM_Utils_Array::value('auto_renew', $options[$details]);
     CRM_Utils_JSON::output($details);
 }
Esempio n. 17
0
File: REST.php Progetto: kidaa30/yes
 /**
  * Run ajax request.
  *
  * @return array
  */
 public static function ajax()
 {
     $requestParams = CRM_Utils_Request::exportValues();
     // this is driven by the menu system, so we can use permissioning to
     // restrict calls to this etc
     // the request has to be sent by an ajax call. First line of protection against csrf
     $config = CRM_Core_Config::singleton();
     if (!$config->debug && (!array_key_exists('HTTP_X_REQUESTED_WITH', $_SERVER) || $_SERVER['HTTP_X_REQUESTED_WITH'] != "XMLHttpRequest")) {
         require_once 'api/v3/utils.php';
         $error = civicrm_api3_create_error("SECURITY ALERT: Ajax requests can only be issued by javascript clients, eg. CRM.api3().", array('IP' => $_SERVER['REMOTE_ADDR'], 'level' => 'security', 'referer' => $_SERVER['HTTP_REFERER'], 'reason' => 'CSRF suspected'));
         CRM_Utils_JSON::output($error);
     }
     $q = CRM_Utils_Array::value('fnName', $requestParams);
     if (!$q) {
         $entity = CRM_Utils_Array::value('entity', $requestParams);
         $action = CRM_Utils_Array::value('action', $requestParams);
         if (!$entity || !$action) {
             $err = array('error_message' => 'missing mandatory params "entity=" or "action="', 'is_error' => 1);
             echo self::output($err);
             CRM_Utils_System::civiExit();
         }
         $args = array('civicrm', $entity, $action);
     } else {
         $args = explode('/', $q);
     }
     // get the class name, since all ajax functions pass className
     $className = CRM_Utils_Array::value('className', $requestParams);
     // If the function isn't in the civicrm namespace, reject the request.
     if ($args[0] != 'civicrm' && count($args) != 3 && !$className) {
         return self::error('Unknown function invocation.');
     }
     // Support for multiple api calls
     if (isset($entity) && $entity === 'api3') {
         $result = self::processMultiple();
     } else {
         $result = self::process($args, self::buildParamList());
     }
     echo self::output($result);
     CRM_Utils_System::civiExit();
 }
Esempio n. 18
0
 /**
  * Print an unhandled exception
  *
  * @param $e
  */
 function reportException(Exception $e)
 {
     CRM_Core_Error::debug_var('CRM_Queue_ErrorPolicy_reportException', CRM_Core_Error::formatTextException($e));
     $response = array('is_error' => 1, 'is_continue' => 0);
     $config = CRM_Core_Config::singleton();
     if ($config->backtrace || CRM_Core_Config::isUpgradeMode()) {
         $response['exception'] = CRM_Core_Error::formatHtmlException($e);
     } else {
         $response['exception'] = htmlentities($e->getMessage());
     }
     global $activeQueueRunner;
     if (is_object($activeQueueRunner)) {
         $response['last_task_title'] = $activeQueueRunner->lastTaskTitle;
     }
     CRM_Utils_JSON::output($response);
 }
Esempio n. 19
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;
 }
Esempio n. 20
0
 /**
  * Performing any view-layer filtering on result and send to client.
  */
 static function _return($op, $result)
 {
     if ($result['is_error']) {
         if (is_object($result['exception'])) {
             CRM_Core_Error::debug_var("CRM_Queue_Page_AJAX_{$op}_error", CRM_Core_Error::formatTextException($result['exception']));
             $config = CRM_Core_Config::singleton();
             if ($config->backtrace || CRM_Core_Config::isUpgradeMode()) {
                 $result['exception'] = CRM_Core_Error::formatHtmlException($result['exception']);
             } else {
                 $result['exception'] = $result['exception']->getMessage();
             }
         } else {
             CRM_Core_Error::debug_var("CRM_Queue_Page_AJAX_{$op}_error", $result);
         }
     }
     CRM_Utils_JSON::output($result);
 }
Esempio n. 21
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();
     }
     $sortMapper = array();
     foreach ($_GET['columns'] as $key => $value) {
         $sortMapper[$key] = $value['data'];
     }
     $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0;
     $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25;
     $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL;
     $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc';
     $params = $_GET;
     if ($sort && $sortOrder) {
         $params['sortBy'] = $sort . ' ' . $sortOrder;
     }
     $params['page'] = $offset / $rowCount + 1;
     $params['rp'] = $rowCount;
     $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);
 }
Esempio n. 22
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);
 }
Esempio n. 23
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);
 }
Esempio n. 24
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);
 }
Esempio n. 25
0
 /**
  * @param array $result
  *   List of API responses, keyed by file.
  */
 public static function sendResponse($result)
 {
     $isError = FALSE;
     foreach ($result as $item) {
         $isError = $isError || $item['is_error'];
     }
     if ($isError) {
         $sapi_type = php_sapi_name();
         if (substr($sapi_type, 0, 3) == 'cgi') {
             CRM_Utils_System::setHttpHeader("Status", "500 Internal Server Error");
         } else {
             header("HTTP/1.1 500 Internal Server Error");
         }
     }
     CRM_Utils_JSON::output(array_merge($result));
 }
Esempio n. 26
0
 public static function getImageProp()
 {
     $img = $_GET['img'];
     list($w, $h) = CRM_Badge_BAO_Badge::getImageProperties($img);
     CRM_Utils_JSON::output(array('width' => $w, 'height' => $h));
 }
Esempio n. 27
0
 public function addClient()
 {
     $caseId = CRM_Utils_Type::escape($_POST['caseID'], 'Positive');
     $contactId = CRM_Utils_Type::escape($_POST['contactID'], 'Positive');
     if (!$contactId || !CRM_Case_BAO_Case::accessCase($caseId)) {
         CRM_Utils_System::permissionDenied();
     }
     $params = array('case_id' => $caseId, 'contact_id' => $contactId);
     CRM_Case_BAO_Case::addCaseToContact($params);
     // add case relationships
     CRM_Case_BAO_Case::addCaseRelationships($caseId, $contactId);
     $session = CRM_Core_Session::singleton();
     $activityParams = array();
     $activityParams['source_contact_id'] = $session->get('userID');
     $activityParams['activity_type_id'] = CRM_Core_OptionGroup::getValue('activity_type', 'Add Client To Case', 'name');
     $activityParams['activity_date_time'] = date('YmdHis');
     $activityParams['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name');
     $activityParams['case_id'] = $caseId;
     $activityParams['is_auto'] = 0;
     $activityParams['subject'] = 'Client Added To Case';
     $activity = CRM_Activity_BAO_Activity::create($activityParams);
     $caseParams = array('activity_id' => $activity->id, 'case_id' => $caseId);
     CRM_Case_BAO_Case::processCaseActivity($caseParams);
     CRM_Utils_JSON::output(TRUE);
 }
Esempio n. 28
0
 public static function getLocBlock()
 {
     // i wish i could retrieve loc block info based on loc_block_id,
     // Anyway, lets retrieve an event which has loc_block_id set to 'lbid'.
     if ($_REQUEST['lbid']) {
         $params = array('1' => array($_REQUEST['lbid'], 'Integer'));
         $eventId = CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_event WHERE loc_block_id=%1 LIMIT 1', $params);
     }
     // now lets use the event-id obtained above, to retrieve loc block information.
     if ($eventId) {
         $params = array('entity_id' => $eventId, 'entity_table' => 'civicrm_event');
         // second parameter is of no use, but since required, lets use the same variable.
         $location = CRM_Core_BAO_Location::getValues($params, $params);
     }
     $result = array();
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     // lets output only required fields.
     foreach ($addressOptions as $element => $isSet) {
         if ($isSet && !in_array($element, array('im', 'openid'))) {
             if (in_array($element, array('country', 'state_province', 'county'))) {
                 $element .= '_id';
             } elseif ($element == 'address_name') {
                 $element = 'name';
             }
             $fld = "address[1][{$element}]";
             $value = CRM_Utils_Array::value($element, $location['address'][1]);
             $value = $value ? $value : "";
             $result[str_replace(array('][', '[', "]"), array('_', '_', ''), $fld)] = $value;
         }
     }
     foreach (array('email', 'phone_type_id', 'phone') as $element) {
         $block = $element == 'phone_type_id' ? 'phone' : $element;
         for ($i = 1; $i < 3; $i++) {
             $fld = "{$block}[{$i}][{$element}]";
             $value = CRM_Utils_Array::value($element, $location[$block][$i]);
             $value = $value ? $value : "";
             $result[str_replace(array('][', '[', "]"), array('_', '_', ''), $fld)] = $value;
         }
     }
     // set the message if loc block is being used by more than one event.
     $result['count_loc_used'] = CRM_Event_BAO_Event::countEventsUsingLocBlockId($_REQUEST['lbid']);
     CRM_Utils_JSON::output($result);
 }
Esempio n. 29
0
 /**
  * Override default cancel action.
  *
  * @return void
  */
 public function cancelAction()
 {
     $response = array('status' => 'cancel');
     CRM_Utils_JSON::output($response);
 }
 /**
  * AJAX callback.
  */
 public static function getSchemaJSON()
 {
     $entityTypes = explode(',', $_REQUEST['entityTypes']);
     CRM_Utils_JSON::output(self::getSchema($entityTypes));
 }