/**
  * 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 #2
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);
 }
Example #3
0
/**
 * Test Function used for new hs-widget.
 */
function countries(&$config)
{
    //get the country limit and restrict the combo select options
    $limitCodes = $config->countryLimit();
    if (!is_array($limitCodes)) {
        $limitCodes = array($config->countryLimit => 1);
    }
    $limitCodes = array_intersect(CRM_Core_PseudoConstant::countryIsoCode(), $limitCodes);
    // added for testing purpose
    //$limitCodes['1101'] = 'IN';
    if (count($limitCodes)) {
        $whereClause = " iso_code IN ('" . implode("', '", $limitCodes) . "')";
    } else {
        $whereClause = " 1";
    }
    $elements = array();
    require_once 'CRM/Utils/Type.php';
    $name = NULL;
    if (isset($_GET['name'])) {
        $name = CRM_Utils_Type::escape($_GET['name'], 'String');
    }
    $countryId = NULL;
    if (isset($_GET['id'])) {
        $countryId = CRM_Utils_Type::escape($_GET['id'], 'Positive', FALSE);
    }
    //temporary fix to handle locales other than default US,
    // CRM-2653
    if (!$countryId && $name && $config->lcMessages != 'en_US') {
        $countries = CRM_Core_PseudoConstant::country();
        // get the country name in en_US, since db has this locale
        $countryName = array_search($name, $countries);
        if ($countryName) {
            $countryId = $countryName;
        }
    }
    $validValue = TRUE;
    if (!$name && !$countryId) {
        $validValue = FALSE;
    }
    if ($validValue) {
        if (!$countryId) {
            $name = str_replace('*', '%', $name);
            $countryClause = " civicrm_country.name LIKE LOWER('{$name}%') ";
        } else {
            $countryClause = " civicrm_country.id = {$countryId} ";
        }
        $query = "\nSELECT id, name\n  FROM civicrm_country\n WHERE {$countryClause}\n   AND {$whereClause} \nORDER BY name";
        $nullArray = array();
        $dao = CRM_Core_DAO::executeQuery($query, $nullArray);
        $count = 0;
        while ($dao->fetch() && $count < 5) {
            $elements[] = array('name' => ts($dao->name), 'value' => $dao->id);
            $count++;
        }
    }
    if (empty($elements)) {
        if (isset($_GET['id'])) {
            $name = $_GET['id'];
        }
        $elements[] = array('name' => trim($name, "%"), 'value' => trim($name, "%"));
    }
    require_once "CRM/Utils/JSON.php";
    echo CRM_Utils_JSON::encode($elements, 'value');
}