Example #1
0
 /**
  * Function for Case Subject combo box
  */
 function caseSubject(&$config)
 {
     require_once 'CRM/Utils/Type.php';
     $whereclause = $caseIdClause = null;
     if (isset($_GET['name'])) {
         $name = CRM_Utils_Type::escape($_GET['name'], 'String');
         $name = str_replace('*', '%', $name);
         $whereclause = "civicrm_case.subject LIKE '%{$name}'";
     }
     if (isset($_GET['id'])) {
         $caseId = CRM_Utils_Type::escape($_GET['id'], 'Integer');
         $caseIdClause = " AND civicrm_case.id = {$caseId}";
     }
     $elements = array();
     if ($name || $caseIdClause) {
         if (is_numeric($_GET['c'])) {
             $contactID = CRM_Utils_Type::escape($_GET['c'], 'Integer');
             if ($contactID) {
                 $clause = "civicrm_case_contact.contact_id = {$contactID}";
                 $whereclause = $whereclause ? $whereclause . " AND " . $clause : $clause;
             }
         }
         $query = "\nSELECT distinct(civicrm_case.subject) as subject, civicrm_case.id as id\nFROM civicrm_case\nLEFT JOIN civicrm_case_contact ON civicrm_case_contact.case_id = civicrm_case.id\nWHERE {$whereclause} {$caseIdClause}\nORDER BY subject";
         $dao = CRM_Core_DAO::executeQuery($query);
         while ($dao->fetch()) {
             $elements[] = array('name' => $dao->subject, 'id' => $dao->id);
         }
     }
     if (empty($elements)) {
         $name = str_replace('%', '', $name);
         $elements[] = array('name' => $name, 'id' => $name);
     }
     require_once "CRM/Utils/JSON.php";
     echo CRM_Utils_JSON::encode($elements);
 }
 /**
  * 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);
 }
Example #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);
 }
 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);
 }
Example #5
0
 /**
  * Retrieve records.
  */
 public static function getBatchList()
 {
     $sortMapper = array(0 => 'batch.title', 1 => 'batch.type_id', 2 => '', 3 => 'batch.total', 4 => 'batch.status_id', 5 => '');
     $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';
     $context = isset($_REQUEST['context']) ? CRM_Utils_Type::escape($_REQUEST['context'], 'String') : NULL;
     $params = $_REQUEST;
     if ($sort && $sortOrder) {
         $params['sortBy'] = $sort . ' ' . $sortOrder;
     }
     $params['page'] = $offset / $rowCount + 1;
     $params['rp'] = $rowCount;
     if ($context != 'financialBatch') {
         // data entry status batches
         $params['status_id'] = CRM_Core_OptionGroup::getValue('batch_status', 'Data Entry', 'name');
     }
     $params['context'] = $context;
     // get batch list
     $batches = CRM_Batch_BAO_Batch::getBatchListSelector($params);
     $iFilteredTotal = $iTotal = $params['total'];
     if ($context == 'financialBatch') {
         $selectorElements = array('check', 'batch_name', 'payment_instrument', 'item_count', 'total', 'status', 'created_by', 'links');
     } else {
         $selectorElements = array('batch_name', 'type', 'item_count', 'total', 'status', 'created_by', 'links');
     }
     CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($batches, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
Example #6
0
 static function getCaseActivity()
 {
     $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer');
     $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
     $userID = CRM_Utils_Type::escape($_GET['userID'], 'Integer');
     $context = CRM_Utils_Type::escape(CRM_Utils_Array::value('context', $_GET), 'String');
     $sortMapper = array(0 => 'display_date', 1 => 'ca.subject', 2 => 'ca.activity_type_id', 3 => 'acc.sort_name', 4 => 'cc.sort_name', 5 => 'ca.status_id');
     $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';
     $params = $_POST;
     if ($sort && $sortOrder) {
         $params['sortname'] = $sort;
         $params['sortorder'] = $sortOrder;
     }
     $params['page'] = $offset / $rowCount + 1;
     $params['rp'] = $rowCount;
     // get the activities related to given case
     require_once "CRM/Case/BAO/Case.php";
     $activities = CRM_Case_BAO_Case::getCaseActivity($caseID, $params, $contactID, $context, $userID);
     require_once "CRM/Utils/JSON.php";
     $iFilteredTotal = $iTotal = $params['total'];
     $selectorElements = array('display_date', 'subject', 'type', 'with_contacts', 'reporter', 'status', 'links', 'class');
     echo CRM_Utils_JSON::encodeDataTableSelector($activities, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
Example #7
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 #8
0
 /**
  * Function to retrieve contact mailings
  */
 public static function getContactMailings()
 {
     $contactID = CRM_Utils_Type::escape($_GET['contact_id'], 'Integer');
     $sortMapper = array(0 => 'subject', 1 => 'creator_name', 2 => '', 3 => 'start_date', 4 => '', 5 => 'links');
     $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';
     $params = $_POST;
     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);
     $iFilteredTotal = $iTotal = $params['total'];
     $selectorElements = array('subject', 'mailing_creator', 'recipients', 'start_date', 'openstats', 'links');
     header('Content-Type: application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($mailings, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
 /**
  * Function for building Pledge Name combo box
  */
 function pledgeName(&$config)
 {
     $getRecords = FALSE;
     if (isset($_GET['name']) && $_GET['name']) {
         $name = CRM_Utils_Type::escape($_GET['name'], 'String');
         $name = str_replace('*', '%', $name);
         $whereClause = "p.creator_pledge_desc LIKE '%{$name}%' ";
         $getRecords = TRUE;
     }
     if (isset($_GET['id']) && is_numeric($_GET['id'])) {
         $pledgeId = CRM_Utils_Type::escape($_GET['id'], 'Integer');
         $whereClause = "p.id = {$pledgeId} ";
         $getRecords = TRUE;
     }
     if ($getRecords) {
         $query = "\nSELECT p.creator_pledge_desc, p.id\nFROM civicrm_pb_pledge p\nWHERE {$whereClause}\n";
         $dao = CRM_Core_DAO::executeQuery($query);
         $elements = array();
         while ($dao->fetch()) {
             $elements[] = array('name' => $dao->creator_pledge_desc, 'value' => $dao->id);
         }
     }
     if (empty($elements)) {
         $name = $_GET['name'];
         if (!$name && isset($_GET['id'])) {
             $name = $_GET['id'];
         }
         $elements[] = array('name' => trim($name, '*'), 'value' => trim($name, '*'));
     }
     echo CRM_Utils_JSON::encode($elements, 'value');
     CRM_Utils_System::civiExit();
 }
Example #10
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);
 }
Example #11
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();
     }
 }
Example #12
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);
 }
 /**
  * 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);
 }
Example #14
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 #15
0
 static function getCaseActivity()
 {
     $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer');
     $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
     $params = $_POST;
     // get the activities related to given case
     require_once "CRM/Case/BAO/Case.php";
     $activities = CRM_Case_BAO_Case::getCaseActivity($caseID, $params, $contactID);
     $page = CRM_Utils_Array::value('page', $_POST);
     $total = $params['total'];
     require_once "CRM/Utils/JSON.php";
     $selectorElements = array('display_date', 'subject', 'type', 'reporter', 'status', 'links', 'class');
     echo CRM_Utils_JSON::encodeSelector($activities, $page, $total, $selectorElements);
     exit;
 }
Example #16
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);
 }
Example #17
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);
     }
 }
Example #18
0
 static function getGroupList()
 {
     $params = $_REQUEST;
     if (isset($params['parent_id'])) {
         // requesting child groups for a given parent
         $params['page'] = 1;
         $params['rp'] = 25;
         $groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
         echo json_encode($groups);
         CRM_Utils_System::civiExit();
     } else {
         $sortMapper = array(0 => 'groups.title', 1 => 'groups.id', 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;
         // 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);
             }
         }
         $iFilteredTotal = $iTotal = $params['total'];
         $selectorElements = array('group_name', 'group_id', 'created_by', 'group_description', 'group_type', 'visibility', 'org_info', 'links', 'class');
         if (empty($params['showOrgInfo'])) {
             unset($selectorElements[6]);
         }
         echo CRM_Utils_JSON::encodeDataTableSelector($groups, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
         CRM_Utils_System::civiExit();
     }
 }
Example #19
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);
 }
 static function getBatchList()
 {
     $sortMapper = array(0 => 'batch.title', 1 => 'batch.type_id', 2 => '', 3 => 'batch.total', 4 => 'batch.status_id', 5 => '');
     $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';
     $params = $_POST;
     if ($sort && $sortOrder) {
         $params['sortBy'] = $sort . ' ' . $sortOrder;
     }
     $params['page'] = $offset / $rowCount + 1;
     $params['rp'] = $rowCount;
     // get batch list
     $batches = CRM_Core_BAO_Batch::getBatchListSelector($params);
     $iFilteredTotal = $iTotal = $params['total'];
     $selectorElements = array('batch_name', 'batch_type', 'item_count', 'total_amount', 'status', 'created_by', 'links');
     echo CRM_Utils_JSON::encodeDataTableSelector($batches, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
Example #21
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);
     }
 }
Example #22
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);
 }
 static function getGroupList()
 {
     $sortMapper = array(0 => 'groups.title', 1 => 'groups.id', 2 => '', 3 => 'groups.group_type', 4 => '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';
     $params = $_POST;
     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);
     $iFilteredTotal = $iTotal = $params['total'];
     $selectorElements = array('group_name', 'group_id', 'group_description', 'group_type', 'visibility', 'org_info', 'links', 'class');
     if (!CRM_Utils_Array::value('showOrgInfo', $params)) {
         unset($selectorElements[5]);
     }
     echo CRM_Utils_JSON::encodeDataTableSelector($groups, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
Example #24
0
File: AJAX.php Project: 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);
 }
Example #25
0
 /**
  * Override default cancel action.
  *
  * @return void
  */
 public function cancelAction()
 {
     $response = array('status' => 'cancel');
     CRM_Utils_JSON::output($response);
 }
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 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);
 }
Example #28
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);
 }
Example #29
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));
 }
Example #30
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);
 }