Skip to content
Snippets Groups Projects
  • Jared Hancock's avatar
    9e75169e
    Dynamic data for osTicket · 9e75169e
    Jared Hancock authored
    *This is a major redesign / rework of the osTicket base*
    
    This patch drops the concept of static ticket metadata and allows for an
    admin-configurable arbitrary data that is attachable to tickets
    
    The system is architected such that the base osTicket install now comes with
    a "default" form that has fields for subject, name, email, and phone number.
    This form is editable to allow for the addition of arbitrary other fields;
    however, the basic fields must remain in order to be associated with a
    help-topic and attached to a ticket.
    
    This concept can be expanded to allow for arbitrary data associated with
    registered clients or ticket thread items.
    
    Forms are comprised of sections. Sections have a title and instructions
    properties and a list of fields. Fields have various implementations to
    represent different data such as text, long answer, phone number, datetime,
    yes/no, and selections, and are configurable to define the look and feel and
    interpretation of the respective form field.
    
    Dropdown lists are represented as "Dynamic Lists", which are
    admin-configurable lists of items. Dropdowns can be optionally represented
    as Bootstrap typeahead fields.
    
    This also adds the start of a simple ORM which will hopefully be expanded in
    the future to support multiple database platforms. Currently, only MySQL is
    implemented.
    9e75169e
    History
    Dynamic data for osTicket
    Jared Hancock authored
    *This is a major redesign / rework of the osTicket base*
    
    This patch drops the concept of static ticket metadata and allows for an
    admin-configurable arbitrary data that is attachable to tickets
    
    The system is architected such that the base osTicket install now comes with
    a "default" form that has fields for subject, name, email, and phone number.
    This form is editable to allow for the addition of arbitrary other fields;
    however, the basic fields must remain in order to be associated with a
    help-topic and attached to a ticket.
    
    This concept can be expanded to allow for arbitrary data associated with
    registered clients or ticket thread items.
    
    Forms are comprised of sections. Sections have a title and instructions
    properties and a list of fields. Fields have various implementations to
    represent different data such as text, long answer, phone number, datetime,
    yes/no, and selections, and are configurable to define the look and feel and
    interpretation of the respective form field.
    
    Dropdown lists are represented as "Dynamic Lists", which are
    admin-configurable lists of items. Dropdowns can be optionally represented
    as Bootstrap typeahead fields.
    
    This also adds the start of a simple ORM which will hopefully be expanded in
    the future to support multiple database platforms. Currently, only MySQL is
    implemented.
class.json.php 2.34 KiB
<?php
/*********************************************************************
    class.json.php

    Parses JSON text data to PHP associative array. Useful mainly for API
    JSON requests. The module will attempt to use the json_* functions
    builtin to PHP5.2+ if they exist and will fall back to a pure-php
    implementation included in JSON.php.

    Jared Hancock
    Copyright (c)  2006-2010 osTicket
    http://www.osticket.com

    Released under the GNU General Public License WITHOUT ANY WARRANTY.
    See LICENSE.TXT for details.

    vim: expandtab sw=4 ts=4 sts=4:
    $Id: $
**********************************************************************/

include_once "JSON.php";

class JsonDataParser {
    function parse($stream) {
        if (is_resource($stream)) {
            $contents = '';
            while (!feof($stream))
                $contents .= fread($stream, 8192);
        } else
            $contents = $stream;
        return self::decode($contents);
    }

    function decode($contents) {
        if (function_exists("json_decode")) {
            return json_decode($contents, true);
        } else {
            # Create associative arrays rather than 'objects'
            $decoder = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
            return $decoder->decode($contents);
        }
    }
    function lastError() {
        if (function_exists("json_last_error")) {
            $errors = array(
            JSON_ERROR_NONE => 'No errors',
            JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
            JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch',
            JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
            JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
            JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
            );
            if ($message = $errors[json_last_error()])
                return $message;
            return "Unknown error";
        } else {
            # Doesn't look like Servies_JSON supports errors for decode()
            return "Unknown JSON parsing error";
        }
    }
}

class JsonDataEncoder {
    function encode($var) {
        if (function_exists('json_encode'))
            return json_encode($var);
        else {
            $decoder = new Services_JSON();
            return $decoder->encode($var);
        }
    }
}