function message($message, $error = 0) { if ($error) { return jsonify(array("Error", $message)); } return jsonify(array("OK", $message)); }
function init_catalog_old($jsName, $containerId, $selectCallback, $categories, $products) { echo '<script type="text/javascript" src="inc/catalog-old.js"></script>'; echo '<script type="text/javascript">'; echo "var {$jsName} = new Catalog(\"{$containerId}\", \"{$selectCallback}\");\n"; echo "jQuery(document).ready(function() {\n"; echo "var html = \"<div class=\\\"catalog-categories-container\\\"></div>\";\n"; echo "html += \"<div class=\\\"catalog-products-container\\\"></div>\";\n"; echo "jQuery(\"#{$containerId}\").html(html);\n"; foreach ($categories as $cat) { echo $jsName . ".createCategory(\"" . $jsName . "\", \"" . $cat->id . "\"" . ", \"" . $cat->label . "\", " . ($cat->hasImage ? "true" : "false") . ");\n"; } foreach ($products as $product) { $taxCat = TaxesService::get($product->taxCatId); $tax = $taxCat->getCurrentTax(); $vatPrice = $product->priceSell * (1 + $tax->rate); $prd = '{' . jsonify("id", $product->id) . ', ' . jsonify("label", $product->label) . ', ' . jsonify("reference", $product->reference) . ', ' . jsonify("hasImage", $product->hasImage) . ', ' . jsonify("buy", $product->priceBuy) . ', ' . jsonify("sell", $product->priceSell) . ', ' . jsonify("vatSell", $vatPrice) . '}'; echo $jsName . ".addProductToCat(\"" . $product->id . "\", \"" . $product->categoryId . "\");\n"; echo $jsName . ".addProduct(" . $prd . ");\n"; } if (count($categories) > 0) { echo $jsName . ".changeCategory(\"" . $categories[0]->id . "\");\n"; } echo "});\n</script>"; }
<?php // include("../connection/config.php"); // $con = db_connect(); include "functions.php"; $var = $_GET["id"]; $params = explode(".", $var); $id = $params[0]; $id2 = $params[1]; $mains = getMainCat3ById($id, $id2); $response = array(); // $main = "Sample"; foreach ($mains as $main) { $e = $main['cat3Id']; $f = $main['DESCRIPTION']; $id2 = $main['SUBSUBCATID']; $DIGOFSPEC2 = $main['DIGOFSPEC']; $QTY2 = $main['QTY']; $UNIT2 = $main['UNIT']; $UM2 = number_format(floatval($main['UM']), 2); $M2 = number_format($main['M'], 2); $UL2 = $main['UL']; $L2 = number_format($main['L'], 2); $AMOUNT2 = number_format($main['AMOUNT'], 2); $F2 = $main['F']; $PROFIT_AMOUNT2 = number_format($main['PROFIT_AMOUNT'], 2); $response[] = array("e" => $e, "f" => $f, "id2" => $id2, "DIGOFSPEC2" => $DIGOFSPEC2, "QTY2" => $QTY2, "UNIT2" => $UNIT2, "UM2" => $UM2, "M2" => $M2, "UL2" => $UL2, "L2" => $L2, "AMOUNT2" => $AMOUNT2, "F2" => $F2, "PROFIT_AMOUNT2" => $PROFIT_AMOUNT2); } echo jsonify($response);
function delete_group($group_id) { global $out_fmt; // XXX - Sanity check? Make sure $group_id is an integer, // and negative, and a group that exists? if (db_delete_group($group_id)) { // Group was deleted successfully switch ($out_fmt) { case "json": // XXX - Convert to print_struct()? echo jsonify('state', 'ok'); break; case "console": echo "Deleted\n"; break; case "html": default: echo "Deleted<br/>\n"; break; } return; } else { // Something went wrong switch ($out_fmt) { case "json": // XXX - Convert to print_struct() echo jsonify('state', "error", 'errno', $db_errno, 'error', $db_errmsg), "\n"; break; case "console": echo "Error {$db_errno}: {$db_errmsg}\n"; break; case "html": default: echo "<p>Error {$db_errno}: {$db_errmsg}<p>\n"; break; } } }
{ if( Ingredient::getByName($name) ) { print jsonify(false, "This ingredient already exists", $name); } else { if( Ingredient::add($name, $veg, $all, $side) ) { print jsonify(true, "The ingredient was added successfully", $name); } else { print jsonify(false, "The ingredient could not be added", $name); } } } else { print jsonify(false, "There was an error adding this ingredient", $name); } function jsonify($stat, $msg, $data = null) { $ret = array( "status" => $stat, "message" => $msg, "data" => $data ); return json_encode($ret); } ?>
function error($feed_id, $feed_title, $msg) { // XXX - Convert to print_struct()? echo jsonify('state', "error", 'feed_id', $feed_id, 'title', $feed_title, 'error', $msg), "\n"; }
{ if( Characteristic::getByCharacteristic($name) ) { print jsonify(false, "This characteristic already exists", $name); } else { if( Characteristic::add($name) ) { print jsonify(true, "The characteristic was added successfully", $name); } else { print jsonify(false, "The characteristic could not be added", $name); } } } else { print jsonify(false, "There was an error adding this characteristic", $name); } function jsonify($stat, $msg, $data = null) { $ret = array( "status" => $stat, "message" => $msg, "data" => $data ); return json_encode($ret); } ?>
function wfGetDevelopersJSON($language, $query, $callback) { $data = false; // differ by "language": rfc, php, js, css, ... switch ($language) { // Request For Comments case 'rfc': $rfcId = intval($query); if (empty($rfcId)) { continue; } // fetch RFC file $url = "http://www.faqs.org/rfcs/rfc{$rfcId}.html"; $content = HTTP::get($url); // remove HTML <head> section $content = substr($content, strpos($content, '<HR SIZE=2 NOSHADE>')); //echo '<pre>'.htmlspecialchars($content).'</pre>'; // get title and short summary if (preg_match('/\\- (.+)<\\/h1>/m', $content, $matches)) { $title = $matches[1]; $introIdx = intval(stripos($content, 'introduction') + 12); $abstractIdx = intval(stripos($content, 'abstract') + 8); // use whatever is first $idx = min($introIdx, $abstractIdx) > 100 ? min($introIdx, $abstractIdx) : max($introIdx, $abstractIdx); $summary = trim(strip_tags(substr($content, $idx, 1024))); } else { // RFC not found - return empty title $title = ""; } $data = array('type' => 'rfc', 'id' => $rfcId, 'title' => $title, 'summary' => !empty($summary) ? $summary : '', 'href' => "http://www.rfc-archive.org/getrfc.php?rfc={$rfcId}"); break; // PHP // PHP case 'php': $function = preg_replace('/[^A-Za-z0-9_]/', '', $query); $href = 'http://us.php.net/' . $function; $content = HTTP::get($href); //echo '<pre>'.htmlspecialchars($content).'</pre>'; // grab info from manual page $syntax = wfLimitText('<div class="methodsynopsis dc-description">', '<p class="para rdfs-comment">', $content); if (!empty($syntax)) { $syntax = trim(strip_tags($syntax)); $syntax = preg_replace('/(\\s+)/', ' ', $syntax); } $description = wfLimitText('rdfs-comment">', '<div', $content); if (!empty($description)) { $description = trim(strip_tags($description), "\n. "); $description = preg_replace('/(\\s+)/', ' ', $description); } $params = wfLimitText('<p class="para">', '<div', $content); if (!empty($params)) { $params = trim(strip_tags($params, '<dl><dd><dt>')); $params = preg_replace('/(\\s+)/', ' ', $params); } $returns = wfLimitText('<h3 class="title">Return Values</h3>', '<div', $content); if (!empty($returns)) { $returns = trim(strip_tags($returns, '<p>')); $returns = preg_replace('/(\\s+)/', ' ', $returns); } $data = array('type' => 'php', 'title' => $function, 'syntax' => !empty($syntax) ? $syntax : '', 'params' => !empty($params) ? $params : '', 'desc' => !empty($description) ? $description : '', 'returns' => !empty($returns) ? $returns : '', 'href' => 'http://{{LANG}}.php.net/' . $function); break; // C // C case 'c': $function = preg_replace('/[^A-Za-z0-9_]/', '', $query); $href = "http://www.elook.org/programming/c/{$function}.html"; $content = HTTP::get($href); // grab info from manual page $syntax = wfLimitText('<i>Syntax:</i>', '</pre>', $content); if (!empty($syntax)) { $syntax = trim(strip_tags($syntax)); } $description = wfLimitText('<i>Description:</i>', '<br /><br />', $content); if (!empty($description)) { $description = trim(strip_tags($description, '<br><pre>'), "\n. "); $description = preg_replace('/(\\s+)/', ' ', $description); } $data = array('type' => 'c', 'title' => $function, 'syntax' => !empty($syntax) ? $syntax : '', 'desc' => !empty($description) ? $description : '', 'href' => $href); break; // man page // man page case 'man': $cmd = preg_replace('/[^A-Za-z0-9_]/', '', $query); $href = 'http://unixhelp.ed.ac.uk/CGI/man-cgi?' . $cmd; $content = HTTP::get($href); //echo '<pre>'.htmlspecialchars($content).'</pre>'; // grab info from manual page $description = wfLimitText('<PRE>', '</PRE>', $content); if (!empty($description)) { $description = wfLimitText("\n", "\n", $description); $description = trim(strip_tags($description, '<h2>')); $description = substr($description, 0, -40); // keep headers formatted $description = strtr($description, array('<H2>' => '<b>', '</H2>' => '</b>')); } $data = array('type' => 'man', 'title' => $cmd, 'desc' => !empty($description) ? $description : '', 'href' => $href); break; default: return ''; } // json encode our response $jsonData = jsonify($data); $response = new AjaxResponse(!empty($callback) ? "{$callback}({$jsonData});" : $jsonData); $response->setContentType('application/javascript; charset=utf-8'); return $response; }
function error($message) { jsonify(array('error' => $message), 500); }
$expiration = $now + AUTH_COOKIE_DURATION; $hmac = md5(implode("|", array($user, $expiration, SERVER_SECRET))); setcookie('newsbite_user', implode("|", array($user, $expiration, $hmac)), $expiration); } /* See if the user has already been authenticated through Apache */ if (isset($_SERVER['REMOTE_USER'])) { /* Apache has authenticated this user. Set the cookie and * send the browser back to where the user originally wanted * to go. */ set_auth_cookie($_SERVER['REMOTE_USER']); // If $out_fmt is "json", then send a JSON object saying the // user is authenticated. if ($out_fmt == "json") { // XXX - Convert to print_struct()? echo jsonify('status', "logged in"); exit(0); } // XXX - Do we want to support XML output? I guess we can just // print_result() the 'status' thing above. // Otherwise (HTML output, presumably) redirect to where they // came from. redirect_to($from); ?> <html> <head><title>Authenticated by Apache</title></head> <body> <h1>You've been authenticated through Apache</h1> <p><a href="<?php echo $from; ?>
if( $no ) { if( $no->addItem($id, $comment, $modifiers) ) { print jsonify(true, "The item was added to a new order.", count($no->items)); } else { print jsonify(false, "A new order was created, but the item could not be added."); } } else { print jsonify(false, "The system was unable to create a new order to submit this item."); } } } else { print jsonify(false, "There was an error adding this item to your order."); } function jsonify($stat, $msg, $data = null) { $ret = array( "status" => $stat, "message" => $msg, "data" => $data ); return json_encode($ret); } ?>