Example #1
0
function output($var, $response = '200', $method = false)
{
    if (!$method) {
        global $default_config;
        $method = $default_config['standard_response_type'];
    }
    switch ($method) {
        case 'json':
            echo array_to_json($var);
            break;
        case 'xml':
            $xml = new SimpleXMLElement('<root/>');
            array_walk_recursive($var, array($xml, 'addChild'));
            print $xml->asXML();
            break;
        case 'plain':
            if (is_array($var)) {
                var_dump($var);
            } else {
                print $var;
            }
            break;
        case 'dump':
            echo '<pre>';
            var_dump($var);
            echo '</pre>';
            break;
        default:
            //	log_write('Error: render document not defined');
            break;
    }
    http_response_code($response);
}
Example #2
0
function array_to_json($array)
{
    if (!is_array($array)) {
        return false;
    }
    $associative = count(array_diff(array_keys($array), array_keys(array_keys($array))));
    if ($associative) {
        $construct = array();
        foreach ($array as $key => $value) {
            // We first copy each key/value pair into a staging array,
            // formatting each key and value properly as we go.
            // Format the key:
            if (is_numeric($key)) {
                $key = "key_{$key}";
            }
            $key = "\"" . addslashes($key) . "\"";
            // Format the value:
            if (is_array($value)) {
                $value = array_to_json($value);
            } else {
                if (!is_numeric($value) || is_string($value)) {
                    $value = "\"" . addslashes($value) . "\"";
                }
            }
            // Add to staging array:
            $construct[] = "{$key}: {$value}";
        }
        // Then we collapse the staging array into the JSON form:
        $result = "{ " . implode(", ", $construct) . " }";
    } else {
        // If the array is a vector (not associative):
        $construct = array();
        foreach ($array as $value) {
            // Format the value:
            if (is_array($value)) {
                $value = array_to_json($value);
            } else {
                if (!is_numeric($value) || is_string($value)) {
                    $value = "'" . addslashes($value) . "'";
                }
            }
            // Add to staging array:
            $construct[] = $value;
        }
        // Then we collapse the staging array into the JSON form:
        $result = "[ " . implode(", ", $construct) . " ]";
    }
    return $result;
}
         }
     }
     if (count($itemsToCancel) > 0) {
         //Compare total quantity of order items with cancel items to update order status
         $orderItems = db_getOrderItems($dborder->id);
         $Gresponse->log->LogResponse("From " . count($orderItems) . " items, " . count($itemsToCancel) . " will be cancelled");
         $response = $Grequest->SendRefundOrder($dborder->ordernumber, $refundAmount, "Items could not be processed in Quota System. The most common reason " . "is that there were not enough resources to satisfy this request", "Contact the administrator for further details.");
         $response = $Grequest->SendCancelItems($dborder->ordernumber, $itemsToCancel, "Items could not be processed in Quota System. The most common reason " . "is that there were not enough resources to satisfy this request");
         db_setOrderRefund($dborder->id, $dborder->refund + $refundAmount);
     }
     break;
 case 'PAYMENT_DECLINED':
     $Gresponse->log->LogResponse("Canceling order " . $data[$root]['google-order-number']['VALUE']);
     $response = $Grequest->SendCancelOrder($data[$root]['google-order-number']['VALUE'], "Payment Declined", "Contact Google Checkout for further details.");
     $Grequest->SendBuyerMessage($data[$root]['google-order-number']['VALUE'], "Sorry, your payment has been declined", true);
     $Gresponse->log->LogResponse("Response: " . array_to_json($response));
     break;
 case 'CANCELLED':
     $Gresponse->log->LogResponse("Cancelled " + $data[$root]['google-order-number']['VALUE']);
     $order = db_getOrderByOrderNumber($data[$root]['google-order-number']['VALUE']);
     cancelTransaction($order->id);
     $orderItems = db_getOrderItems($orderid);
     foreach ($orderItems as $orderItem) {
         db_cancelOrderItem($orderid, $orderItem->itemid);
     }
     $Grequest->SendBuyerMessage($data[$root]['google-order-number']['VALUE'], "Sorry, your order is cancelled by the store", true);
     break;
 case 'CANCELLED_BY_GOOGLE':
     $Gresponse->log->LogResponse("Cancelled by Google " + $data[$root]['google-order-number']['VALUE']);
     $order = db_getOrderByOrderNumber($data[$root]['google-order-number']['VALUE']);
     cancelTransaction($order->id);
Example #4
0
include_once "config.php";
// подключаем БД
include_once "myJson.php";
// подключаем альтернативу JSON
header('Content-Type: text/html; charset=utf-8');
// Передаем заголовкам кодировку
$date = array();
// массив хранения событий
$query = "SELECT id, title, new_date FROM news";
// общий запрос к таблице news
/*if(isset($_REQUEST['start-min']) && $_REQUEST['start-max']) // если присутствуют начальные и конечные значения дат(присланы из скрипта календаря)
{
	$start_date = substr($_REQUEST['start-min'], 0, strpos($_REQUEST['start-min'], "T")); // начальная дата
	$end_date = substr($_REQUEST['start-max'], 0, strpos($_REQUEST['start-max'], "T")); // конечная дата
	$query .= " WHERE UNIX_TIMESTAMP('{$start_date}') <= UNIX_TIMESTAMP(new_date) AND UNIX_TIMESTAMP(new_date) <= UNIX_TIMESTAMP('{$end_date}')"; // условие выборки за период между начальной и конечной датой
}*/
$resource = mysql_query($query);
// обращаемся к БД
if (mysql_num_rows($resource) != 0) {
    // если есть события
    while ($array = mysql_fetch_assoc($resource)) {
        $date[] = $array;
    }
    // заносим в масиив $date поочередно все события из выборки
}
// ручное добавление, наглядный пример(закомментированно)
//$date[] = array('id' => 1, 'title' => "Двухдневный", 'start' => date("Y-m-d H:i:s",mktime(16, 0, 0, 9, 2, 2009)),'end' => date("Y-m-d",mktime(0, 0, 0, 9, 8, 2009)));
//$date[] = array('id' => 2, 'title' => "Однодневный", 'start' => date("Y-m-d",mktime(0, 0, 0, 9, 2, 2009)));
echo array_to_json($date);
// выводим на экран(отправляем обратно) сжатый массив $date с помощью JSON
Example #5
0
                    $max = intval($_GET['pmax']);
                    $page = intval($_GET['page']);
                    $start = $max * $page;
                    $end = $start + $max;
                    $ret = array();
                    foreach ($res['file'] as $f) {
                        if ($f['cpos'] >= $start && $f['cpos'] < $end) {
                            $ret[] = $f;
                        }
                        if ($f['cpos'] >= $end) {
                            break;
                        }
                    }
                    if (count($ret) > 0) {
                        $json['plchanges'] =& $ret;
                    }
                } else {
                    $json["plchanges"] =& $res['file'];
                }
            }
        }
        $pl->disconnect();
    } catch (PEAR_Exception $e) {
    }
    array_to_json($json);
} else {
    try {
        $pl->disconnect();
    } catch (PEAR_Exception $e) {
    }
}
<?php

require_once '../config.php';
$cerca = $db->real_escape_string($_GET['term']);
$query = "SELECT `codiceFiscale`, `ragioneSociale`, `estero`\n\tFROM avcp_ditta\n\tWHERE\n\t\tragioneSociale LIKE '%" . $cerca . "%'\n\t\tOR\n\t\tcodiceFiscale LIKE '%" . $cerca . "%'";
$res = $db->query($query);
$num = $res->num_rows;
$matches = null;
for ($x = 0; $x < $num; $x++) {
    $row = $res->fetch_assoc();
    $row_set['codiceFiscale'] = $row['codiceFiscale'];
    $row_set['ragioneSociale'] = $row['ragioneSociale'];
    $row_set['estero'] = $row['estero'];
    $row_set['value'] = $row['ragioneSociale'];
    $row_set['label'] = "{$row['ragioneSociale']}, {$row['codiceFiscale']}";
    $matches[] = $row_set;
}
$res->free();
// Patch json per versioni php < 5.2
if (version_compare(PHP_VERSION, '5.2', '<')) {
    require_once 'ajaxFunctions.php';
    echo array_to_json($matches);
} else {
    echo json_encode($matches);
}
Example #7
0
 function get_fields($type_id)
 {
     $this->load->model('custom_fields_model');
     $this->load->model('publish/content_type_model');
     $this->load->helper('array_to_json');
     $type = $this->content_type_model->get_content_type($type_id);
     $custom_fields = $this->custom_fields_model->get_custom_fields(array('group' => $type['custom_field_group_id']));
     $options = array();
     $options['0'] = 'Do not include a summary for each item in the RSS feed.';
     $options['content_title'] = 'Title';
     $options['content_date'] = 'Date Created';
     $options['content_modified'] = 'Date Modified';
     $options['link_url_path'] = 'URL Path';
     foreach ($custom_fields as $field) {
         $options[$field['name']] = $field['friendly_name'];
     }
     echo array_to_json($options);
 }
Example #8
0
function response_text($response)
{
	ob_clean();
	if(is_array($response)) {
		$response=array_to_json($response);
	}
	echo ($response); exit;
}
Example #9
0
 function get_product_files()
 {
     $this->load->helper('array_to_json');
     $files = $this->map_product_files();
     echo array_to_json($files);
 }
Example #10
0
 function member_search()
 {
     $members = $this->user_model->get_users(array('keyword' => $this->input->post('keyword'), 'limit' => '50'));
     $this->load->helper('array_to_json');
     if (empty($members)) {
         return print array_to_json(array());
     }
     $results = array();
     foreach ($members as $member) {
         $results[$member['id']] = $member['last_name'] . ', ' . $member['first_name'] . ' (' . $member['email'] . ')';
     }
     return print array_to_json($results);
 }
Example #11
0
mysql_select_db($database, $connection);
$query_conexion = "SELECT * FROM " . $table . "  WHERE ";
if ($filterField != '') {
    $query_conexion .= $filterField . " = " . $filterValue;
    $query_conexion .= " AND ";
}
$query_conexion .= " (";
foreach ($fieldSearch as $field) {
    $query_conexion .= $field . " LIKE '" . $valueSearch . "' OR ";
}
$query_conexion = substr($query_conexion, 0, -3);
//quitamos el último OR
$query_conexion .= ")";
$conexion = mysql_query($query_conexion, $connection) or die(mysql_error());
$row = mysql_fetch_assoc($conexion);
$result = array();
do {
    $label = '';
    foreach ($fieldSearch as $field) {
        if ($field == "image") {
            $label .= '<img src="images/' . $row[$field] . '"></img>, ';
        } else {
            $label .= $row[$field] . ", ";
        }
    }
    $label = substr($label, 0, -2);
    //quitamos la última coma
    array_push($result, array("ret" => $row[$fieldRet], "label" => $label));
} while ($row = mysql_fetch_assoc($conexion));
echo array_to_json($result);
mysql_free_result($conexion);