From 5d0ddb657ba3f90f66ad1c48268269c051e217ad Mon Sep 17 00:00:00 2001
From: Stephen Packer <github@stevepacker.com>
Date: Wed, 19 Nov 2014 11:50:24 -0800
Subject: [PATCH] XML supports false alert/autorespond, using isset

- Allows the string "false" to be used in the XML payload as the documentation demonstrates, and have that be interpreted as a boolean false.
- Switching $alert/$autorespond to use isset(), and forcing those variables to be type-casted to booleans.
---
 include/api.tickets.php | 8 +++++---
 include/class.api.php   | 4 ++--
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/include/api.tickets.php b/include/api.tickets.php
index 46cb8b6e1..d80b15828 100644
--- a/include/api.tickets.php
+++ b/include/api.tickets.php
@@ -118,9 +118,11 @@ class TicketApiController extends ApiController {
     function createTicket($data) {
 
         # Pull off some meta-data
-        $alert          = array_key_exists('alert',       $data) ? $data['alert']       : true;
-        $autorespond    = array_key_exists('autorespond', $data) ? $data['autorespond'] : true;
-        $data['source'] = array_key_exists('source',      $data) ? $data['source']      : 'API';
+        $alert       = (bool) (isset($data['alert'])       ? $data['alert']       : true);
+        $autorespond = (bool) (isset($data['autorespond']) ? $data['autorespond'] : true);
+
+        # Assign default value to source if not defined, or defined as NULL
+        $data['source'] = isset($data['source']) ? $data['source'] : 'API';
 
         # Create the ticket with the data (attempt to anyway)
         $errors = array();
diff --git a/include/class.api.php b/include/class.api.php
index 0fd2c17e3..2382a70e4 100644
--- a/include/class.api.php
+++ b/include/class.api.php
@@ -330,9 +330,9 @@ class ApiXmlDataParser extends XmlDataParser {
             if ($key == "phone" && is_array($value)) {
                 $value = $value[":text"];
             } else if ($key == "alert") {
-                $value = (bool)$value;
+                $value = (bool) (strtolower($value) === 'false' ? false : $value);
             } else if ($key == "autorespond") {
-                $value = (bool)$value;
+                $value = (bool) (strtolower($value) === 'false' ? false : $value);
             } else if ($key == "message") {
                 if (!is_array($value)) {
                     $value = array(
-- 
GitLab