コード例 #1
0
ファイル: index.php プロジェクト: GM-Team/web
/** \brief Updates a ticket with given information
* \param update Array containing fields of ticket to be updated, as well as
*               the interaction_id to locate the ticket
* \returns A json encoded 'success' array on success, null in event of error
*/
function updateTicket($update)
{
    try {
        require "/var/database_config.php";
        $pdo = new PDO('mysql:host=' . $db_config['host'] . ';dbname=' . $db_config['dbname'], $db_config['username'], $db_config['password']);
        $sql_str = "UPDATE tickets SET ";
        $logs = array();
        $return_switch = 0;
        // For efficiency, must do push before update now
        $exec_array = array();
        if (isset($update['affected_service'])) {
            $sql_str .= "affected_service = ?, ";
            $exec_array[] = $update['affected_service'];
            $logs[] = "Updated affected service to '" . $update['affected_service'] . "'.";
        }
        if (isset($update['category'])) {
            $sql_str .= "category = ?, ";
            $exec_array[] = $update['category'];
        }
        if (isset($update['description'])) {
            $sql_str .= "description = ?, ";
            $exec_array[] = $update['description'];
            $logs[] = "Changed description to '" . $update['description'] . "'.";
        }
        if (isset($update['issue'])) {
            $sql_str .= "issue = ?, ";
            $exec_array[] = $update['issue'];
        }
        if (isset($update['notify_type'])) {
            $sql_str .= "notify_type = ?, ";
            $exec_array[] = $update['notify_type'];
        }
        if (isset($update['phase'])) {
            $sql_str .= "phase = ?, ";
            $exec_array[] = $update['phase'];
            $logs[] = "Phase changed to '" . $update['phase'] . "'.";
        }
        if (isset($update['status'])) {
            $sql_str .= "status = ?, ";
            $exec_array[] = $update['status'];
            $logs[] = "Status changed to '" . $update['status'] . "'.";
        }
        if (isset($update['admin_gm_id'])) {
            $sql_str .= "admin_gm_id = ?, ";
            $exec_array[] = $update['admin_gm_id'];
        }
        if (isset($update['notes'])) {
            $sql_str .= "notes = ?, ";
            $exec_array[] = $update['notes'];
        }
        if (isset($update['last_update_date'])) {
            $sql_str .= "last_update_date = ?, ";
            $exec_array[] = $update['last_update_date'];
        } else {
            $sql_str .= "last_update_date = ?, ";
            $date = date('m-d-y, h:i:s A T');
            $exec_array[] = $date;
        }
        if (isset($update['dirty'])) {
            $sql_str .= "dirty = ?, ";
            $exec_array[] = $update['dirty'];
        } else {
            //request_info reset
            $sql_str .= "request = ?, ";
            $exec_array[] = NULL;
        }
        if (isset($update['feedback'])) {
            $sql_str .= "feedback = ?, ";
            $exec_array[] = $update['feedback'];
        }
        if (isset($update['push'])) {
            require "../push.php";
            $return_switch = pushNotifications($update['interaction_id'], UPDATED, '');
            if ($return_switch == 1) {
                $sql_str .= "dirty = ?, ";
                $exec_array[] = "T";
            }
        }
        $sql_str = rtrim($sql_str, ", \t\n");
        $sql_str .= " WHERE interaction_id = ?";
        $exec_array[] = $update['interaction_id'];
        $statement = $pdo->prepare($sql_str);
        $statement->execute($exec_array);
        require "../log.php";
        writeLog($update['interaction_id'], $logs);
        if ($return_switch == 0) {
            return array('status' => 'Successful update');
        } else {
            if ($return_switch == 1) {
                return array('status' => 'Successful update, push notification queued');
            } else {
                if ($return_switch == 2) {
                    return array('status' => 'Successful update, invalid push notification.');
                }
            }
        }
    } catch (PDOException $e) {
        return array('error' => 'Error updating the ticket in the database');
    }
}
コード例 #2
0
ファイル: index.php プロジェクト: GM-Team/web
<?php

/**
* \file /api/v1/request_info/index.php
*
* \author Brian Hart
*/
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $raw_json = file_get_contents('php://input');
    $json = json_decode($raw_json, true);
    if (isset($json['interaction_id']) && isset($json['message'])) {
        $return_switch = 0;
        $id = $json['interaction_id'];
        $additional = $json['message'];
        require "../push.php";
        $return_switch = pushNotifications($id, REQUEST_INFO, $additional);
        // If was able to push notification to database...
        if ($return_switch === 1) {
            require "/var/database_config.php";
            $pdo = new PDO('mysql:host=' . $db_config['host'] . ';dbname=' . $db_config['dbname'], $db_config['username'], $db_config['password']);
            $statement = $pdo->prepare('UPDATE tickets SET dirty = ?, request = ? WHERE interaction_id = ?');
            $statement->execute(array("T", $additional, $id));
            require "../log.php";
            if ($additional === "") {
                writeLog($id, array("Additional information requested."));
            } else {
                writeLog($id, array("Required: " . $additional));
            }
            header('Content-Type: application/json');
            echo json_encode(['success' => 'Request for additional information successful!']);
            exit;