$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; } /** * This function is used to encode data for dataTable plugin * * @param array $params associated array of row elements * @param int $sEcho datatable needs this to make it more secure * @param int $iTotal total records * @param int $iFilteredTotal total records on a page * @param array $selectorElements selector elements * @return string * */ static function encodeDataTableSelector($params, $sEcho, $iTotal, $iFilteredTotal, $selectorElements) { $sOutput = '{'; $sOutput .= '"sEcho": ' . intval($sEcho) . ', '; $sOutput .= '"iTotalRecords": ' . $iTotal . ', '; $sOutput .= '"iTotalDisplayRecords": ' . $iFilteredTotal . ', '; $sOutput .= '"aaData": [ '; foreach ($params as $key => $value) { $addcomma = FALSE; $sOutput .= "["; foreach ($selectorElements as $element) { if ($addcomma) { $sOutput .= ","; } //CRM-7130 --lets addslashes to only double quotes, //since we are using it to quote the field value. //str_replace helps to provide a break for new-line $sOutput .= '"' . addcslashes(str_replace(array("\r\n", "\n", "\r"), '
', $value[$element]), '"\\') . '"'; //remove extra spaces and tab character that breaks dataTable CRM-12551 $sOutput = preg_replace("/\s+/", " ", $sOutput); $addcomma = TRUE; } $sOutput .= "],"; } $sOutput = substr_replace($sOutput, "", -1); $sOutput .= '] }'; return $sOutput; } }