From 42e397d3ef515c6f9e32037e81af82ef2814b31d Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 7 May 2015 10:20:23 -0400 Subject: [PATCH] AJAX cleanup & remove unused functions --- CRM/Core/Page/AJAX/Attachment.php | 4 +- CRM/Pledge/Page/AJAX.php | 54 +------ CRM/Pledge/xml/Menu/Pledge.xml | 5 - CRM/Utils/JSON.php | 73 +-------- tools/bin/scripts/ajax.php | 250 ------------------------------ 5 files changed, 3 insertions(+), 383 deletions(-) delete mode 100644 tools/bin/scripts/ajax.php diff --git a/CRM/Core/Page/AJAX/Attachment.php b/CRM/Core/Page/AJAX/Attachment.php index 7148e05c7c..7aaf3cd5d8 100644 --- a/CRM/Core/Page/AJAX/Attachment.php +++ b/CRM/Core/Page/AJAX/Attachment.php @@ -142,9 +142,7 @@ class CRM_Core_Page_AJAX_Attachment { } } - header('Content-Type: text/javascript'); - echo json_encode(array_merge($result)); - CRM_Utils_System::civiExit(); + CRM_Utils_JSON::output(array_merge($result)); } /** diff --git a/CRM/Pledge/Page/AJAX.php b/CRM/Pledge/Page/AJAX.php index db58096c54..e5c1c622ba 100755 --- a/CRM/Pledge/Page/AJAX.php +++ b/CRM/Pledge/Page/AJAX.php @@ -38,57 +38,6 @@ */ class CRM_Pledge_Page_AJAX { - /** - * Building Pledge Name combo box. - */ - public static function pledgeName() { - - $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 = " -SELECT p.creator_pledge_desc, p.id -FROM civicrm_pb_pledge p -WHERE {$whereClause} -"; - $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, '*'), - ); - } - - header('Content-Type: application/json'); - echo CRM_Utils_JSON::encode($elements, 'value'); - CRM_Utils_System::civiExit(); - } - /** * Function to setDefaults according to Pledge Id * for batch entry pledges @@ -99,8 +48,7 @@ WHERE {$whereClause} $pledgeID = CRM_Utils_Type::escape($_POST['pid'], 'Integer'); $details = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeID); } - echo json_encode($details); - CRM_Utils_System::civiExit(); + CRM_Utils_JSON::output($details); } } diff --git a/CRM/Pledge/xml/Menu/Pledge.xml b/CRM/Pledge/xml/Menu/Pledge.xml index 25fdae88fa..273dee9d1b 100644 --- a/CRM/Pledge/xml/Menu/Pledge.xml +++ b/CRM/Pledge/xml/Menu/Pledge.xml @@ -42,11 +42,6 @@ access CiviPledge 580 - - civicrm/ajax/pledgeName - CRM_Pledge_Page_AJAX::pledgeName - access CiviCRM,access CiviPledge - civicrm/ajax/pledgeAmount CRM_Pledge_Page_AJAX::getPledgeDefaults diff --git a/CRM/Utils/JSON.php b/CRM/Utils/JSON.php index d8b7cb1b89..e92109acb2 100644 --- a/CRM/Utils/JSON.php +++ b/CRM/Utils/JSON.php @@ -48,80 +48,9 @@ class CRM_Utils_JSON { CRM_Utils_System::civiExit(); } - /** - * Create JSON object. - * @deprecated - * - * @param array $params - * Associated array, that needs to be. - * converted to JSON array - * @param string $identifier - * Identifier for the JSON array. - * - * @return string - * JSON array - */ - public static function encode($params, $identifier = 'id') { - $buildObject = array(); - foreach ($params as $value) { - $name = addslashes($value['name']); - $buildObject[] = "{ name: \"$name\", {$identifier}:\"{$value[$identifier]}\"}"; - } - - $jsonObject = '{ identifier: "' . $identifier . '", items: [' . implode(',', $buildObject) . ' ]}'; - - return $jsonObject; - } - - /** - * Encode json format for flexigrid, NOTE: "id" should be present in $params for each row - * - * @param array $params - * Associated array of values rows. - * @param int $page - * Page no for selector. - * @param $total - * @param array $selectorElements - * Selector rows. - * - * @return string - * json encoded string - */ - public static function encodeSelector(&$params, $page, $total, $selectorElements) { - $json = ""; - $json .= "{\n"; - $json .= "page: $page,\n"; - $json .= "total: $total,\n"; - $json .= "rows: ["; - $rc = FALSE; - - foreach ($params as $key => $value) { - if ($rc) { - $json .= ","; - } - $json .= "\n{"; - $json .= "id:'" . $value['id'] . "',"; - $json .= "cell:["; - $addcomma = FALSE; - foreach ($selectorElements as $element) { - if ($addcomma) { - $json .= ","; - } - $json .= "'" . addslashes($value[$element]) . "'"; - $addcomma = TRUE; - } - $json .= "]}"; - $rc = TRUE; - } - - $json .= "]\n"; - $json .= "}"; - - return $json; - } - /** * encode data for dataTable plugin. + * @deprecated * * @param array $params * Associated array of row elements. diff --git a/tools/bin/scripts/ajax.php b/tools/bin/scripts/ajax.php deleted file mode 100644 index 1845414ab0..0000000000 --- a/tools/bin/scripts/ajax.php +++ /dev/null @@ -1,250 +0,0 @@ -fetch()) { - $elements[] = array('name' => ts($dao->name), - 'value' => $dao->id, - ); - } - } - elseif ($stateId) { - while ($dao->fetch()) { - if ($dao->id == $stateId) { - $elements[] = array('name' => ts($dao->name), - 'value' => $dao->id, - ); - } - } - } - else { - $count = 0; - while ($dao->fetch() && $count < 5) { - $elements[] = array('name' => ts($dao->name), - 'value' => $dao->id, - ); - $count++; - } - } - - if (empty($elements)) { - if ($stateName != '- type first letter(s) -') { - $label = '- state n/a -'; - } - else { - $label = '- type first letter(s) -'; - } - $elements[] = array('name' => $label, - 'value' => '', - ); - } - elseif (!$default && !$stateId && (!$stateName || $stateName == '- type first letter(s) -')) { - $elements = array(); - $elements[] = array('name' => '- type first letter(s) -', - 'value' => '', - ); - } - } - else { - $elements[] = array('name' => '- state n/a -', - 'value' => '', - ); - } - } - - require_once "CRM/Utils/JSON.php"; - echo CRM_Utils_JSON::encode($elements, 'value'); -} - -/** - * Test Function used for new hs-widget. - * @param $config - */ -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 = " -SELECT id, name - FROM civicrm_country - WHERE {$countryClause} - AND {$whereClause} -ORDER 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'); -} - -- 2.25.1