Source for file AjaxUtil.class.php
Documentation is available at AjaxUtil.class.php
* Zikula Application Framework
* @copyright (c) 2001, Zikula Development Team
* @link http://www.zikula.org
* @version $Id: AjaxUtil.class.php 24342 2008-06-06 12:03:14Z markwest $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @author Frank Schummertz
* Immediately stops execution and returns an error message
* @param error - error text
* @param code - optional error code, default '400 Bad data'
* @author Frank Schummertz
function error($error= '', $code= '400 Bad data')
* encode data in JSON and return
* This functions can add a new authid if requested to do so (default).
* If the supplied args is not an array, it will be converted to an
* array with 'data' as key.
* Authid field will always be named 'authid'. Any other field 'authid'
* Script execution stops here
* @param args - string or array of data
* @param createauthid - create a new authid and send it back to the calling javascript
* @param xjsonheader - send result in X-JSON: header for prototype.js
* @author Frank Schummertz
function output($args, $createauthid = false, $xjsonheader = false)
// check if an error message is set
if ($msgs != false && !empty($msgs)) {
// now check if a status message is set
$data = array('data' => $args);
$data['statusmsg'] = $msgs;
if ($createauthid == true) {
// set locale to en_US to ensure correct decimal delimiters
// convert the data to UTF-8 if not already encoded as such
// Note: this isn't strict test but relying on the site language pack encoding seems to be a good compromise
// correct, but wrong: check PHP version and use internal json_encode if >=5.2.0
// better in order to satisfy some weird webhosters (like goneo - forget them) who think they know PHP better
// than the PHP guys and install >=5.2.0 without JSON-support: check if json_encode() exists
// found - use built-in json encoding
// not found - use external JSON library
$output = $json->encode($data);
if ($xjsonheader == true) {
header('X-JSON:(' . $output . ')');
|