src/snac/server/support/OSTicket.php
/**
     * Submit Message as Ticket
     *
     * Submits a message object as a ticket to the OS Ticket system.
     *
     * @param \snac\data\Message $message The message to submit
     */
Submit Message as Ticket
Submits a message object as a ticket to the OS Ticket system.

@param \snac\data\Message $message The message to submit
Submit Message as Ticket Submits a message object as a ticket to the OS Ticket system . @param \ snac \ data \ Message $message The message to submit
public function submitMessageAsTicket(&$message) {
        $payload = array();
        $this->logger->addDebug('Trying to submit message', $message->toArray());
        if ($message->getFromString() !== null) {
            list($name, $email, $junk) = explode("|", $message->getFromString());
            if ($email == null)
                $email = "unknown";
            $payload["email"] = $email;
            $payload["name"] = $name;
        } else {
            $payload["email"] = $message->getFromUser()->getEmail();
            $payload["name"] = $message->getFromUser()->getFullName();
        }
        $payload["subject"] = $message->getSubject();
        $payload["alert"] = true;
        if (isset(Config::$OSTICKET_DEPARTMENT))
            $payload["deptId"] = Config::$OSTICKET_DEPARTMENT;
        $payload["autorespond"] = true;
        $payload["message"] = \Html2Text\Html2Text::convert($message->getBody());
        if ($message->getAttachmentContent() && $message->getAttachmentFilename() == "screenshot.png") {
            $payload["attachments"] = array(
                array($message->getAttachmentFilename() => $message->getAttachmentContent())
            );
        }
        $this->logger->addDebug("Sending the following osTicket query", $payload);
        $data = json_encode($payload);
        try {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, \snac\Config::$OSTICKET_URL);
            curl_setopt($ch, CURLOPT_HTTPHEADER,
                    array (
                            'Content-Type: application/json',
                            'Content-Length: ' . strlen($data),
                            'X-API-Key: ' . \snac\Config::$OSTICKET_KEY
                    ));
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $response = curl_exec($ch);
            $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);
            $this->logger->addDebug("Got the following result: $response");
            if ($responseCode == 201)
                return true;
            $this->logger->addDebug("Errored out on response code $responseCode");
        } catch (\Exception $e) {
            $this->logger->addDebug("CURL ERROR: " . $e->getTraceAsString());
        }
    }
public function submitMessageAsTicket ( & $ message ) { $ payload = array ( ) ; $ this -> logger -> addDebug ( 'Trying to submit message' , $ message -> toArray ( ) ) ; if ( $ message -> getFromString ( ) !== null ) { list ( $ name , $ email , $ junk ) = explode ( " | " , $ message -> getFromString ( ) ) ; if ( $ email == null ) $ email = " unknown " ; $ payload [ " email " ] = $ email ; $ payload [ " name " ] = $ name ; } else { $ payload [ " email " ] = $ message -> getFromUser ( ) -> getEmail ( ) ; $ payload [ " name " ] = $ message -> getFromUser ( ) -> getFullName ( ) ; } $ payload [ " subject " ] = $ message -> getSubject ( ) ; $ payload [ " alert " ] = true ; if ( isset ( Config :: $ OSTICKET_DEPARTMENT ) ) $ payload [ " deptId " ] = Config :: $ OSTICKET_DEPARTMENT ; $ payload [ " autorespond " ] = true ; $ payload [ " message " ] = \ Html2Text \ Html2Text :: convert ( $ message -> getBody ( ) ) ; if ( $ message -> getAttachmentContent ( ) && $ message -> getAttachmentFilename ( ) == " screenshot.png " ) { $ payload [ " attachments " ] = array ( array ( $ message -> getAttachmentFilename ( ) => $ message -> getAttachmentContent ( ) ) ) ; } $ this -> logger -> addDebug ( " Sending the following osTicket query " , $ payload ) ; $ data = json_encode ( $ payload ) ; try { $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , \ snac \ Config :: $ OSTICKET_URL ) ; curl_setopt ( $ ch , CURLOPT_HTTPHEADER , array ( 'Content-Type: application/json' , 'Content-Length: ' . strlen ( $ data ) , 'X-API-Key: ' . \ snac \ Config :: $ OSTICKET_KEY ) ) ; curl_setopt ( $ ch , CURLOPT_CUSTOMREQUEST , 'POST' ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ data ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; $ response = curl_exec ( $ ch ) ; $ responseCode = curl_getinfo ( $ ch , CURLINFO_HTTP_CODE ) ; curl_close ( $ ch ) ; $ this -> logger -> addDebug ( " Got the following result:  $ response " ) ; if ( $ responseCode == 201 ) return true ; $ this -> logger -> addDebug ( " Errored out on response code  $ responseCode " ) ; } catch ( \ Exception $ e ) { $ this -> logger -> addDebug ( " CURL ERROR:  " . $ e -> getTraceAsString ( ) ) ; } }
Submit Message as Ticket
 Submits a message object as a ticket to the OS Ticket system.
Submit Message as Ticket Submits a message object as a ticket to the OS Ticket system .
// If Config has a specific department to send the ticket to, then // send it directly to that department // Encode the query as json // Use CURL to send request to the internal server