From 34a05b3bb270d738fa0a6ab6a5e6cca84c8a6481 Mon Sep 17 00:00:00 2001
From: soif <wxopwx@gmail.com>
Date: Sat, 28 Jul 2012 16:03:17 +0200
Subject: [PATCH] Add topicId to supported vars (else we can't create a Ticket)
 & Prevent api posts without attachements to trigger an uggly php error

Reviewed-By: Jared Hancock <jared@osticket.com>
---
 include/api.ticket.php   | 10 ++++++----
 include/class.ticket.php |  2 +-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/include/api.ticket.php b/include/api.ticket.php
index d767e2128..4fcae4b18 100644
--- a/include/api.ticket.php
+++ b/include/api.ticket.php
@@ -10,7 +10,7 @@ class TicketController extends ApiController {
     # so that all supported input formats should be supported
     function getRequestStructure($format) {
         $supported = array(
-            "alert", "autorespond", "source",
+            "alert", "autorespond", "source", "topicId",
             "name", "email", "subject", "phone", "phone_ext",
             "attachments" => array("*" => 
                 array("name", "type", "data", "encoding")
@@ -33,8 +33,10 @@ class TicketController extends ApiController {
         $autorespond = $data['autorespond'] ? $data['autorespond'] : true;
         $source = $data['source'] ? $data['source'] : 'API';
 
-        # TODO: Handle attachment encoding (base64)
-        foreach ($data["attachments"] as $filename=>&$info) {
+        $attachments = $data['attachments'] ? $data['attachments'] : array();
+
+		# TODO: Handle attachment encoding (base64)
+        foreach ($attachments as $filename=>&$info) {
             if ($info["encoding"] == "base64") {
                 # XXX: May fail on large inputs. See
                 #      http://us.php.net/manual/en/function.base64-decode.php#105512
@@ -60,7 +62,7 @@ class TicketController extends ApiController {
         }
 
         # Save attachment(s)
-        foreach ($data["attachments"] as &$info)
+        foreach ($attachments as &$info)
             $ticket->saveAttachment($info, $ticket->getLastMsgId(), "M");
 
         # All done. Return HTTP/201 --> Created
diff --git a/include/class.ticket.php b/include/class.ticket.php
index c6329ed33..46e7d8636 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -1494,7 +1494,7 @@ class Ticket{
     function postNote($title,$note,$alert=true,$poster='') {        
         global $thisstaff,$cfg;
 		
-		$poster=($poster || !$thisstaff)?$poster:$thisstaff->getName();
+        $poster=($poster || !$thisstaff)?$poster:$thisstaff->getName();
 		
         $sql= 'INSERT INTO '.TICKET_THREAD_TABLE.' SET created=NOW() '.
                 ',thread_type="N"'.
-- 
GitLab