. */ // This is a development branch, please use with caution as things will frequently be changing. ini_set('display_errors', 1); //Display errors in case something occurs header('Content-Type: application/json'); //Set the header to return JSON, required by Slack require_once 'config.php'; require_once 'functions.php'; // Authorization array. Auto encodes API key for auhtorization above. $header_data = authHeader($companyname, $apipublickey, $apiprivatekey); // Authorization array, with extra json content-type used in patch commands to change tickets. $header_data2 = postHeader($companyname, $apipublickey, $apiprivatekey); //echo "$companyname, $apipublickey, $apiprivatekey"; //echo "auth header is $header_data2[1]"; $command=NULL; //Create a command variable and set it to Null $option3=NULL; //Create a option variable and set it to Null //Set URLs $ticketurl = $connectwise . "/v4_6_release/services/system_io/Service/fv_sr100_request.rails?service_recid="; //Ticket URL for connectwise. //Need to create 3 arrays before hand to ensure no errors occur. $dataTNotes = array(); $dataTData = array(); $dataTCmd = array(); //Always a new ticket $cwCompany="CP Test Company"; $cwBoard="Connecting Point: Internet"; // $cwBoard="Managed Services"; $cwSummary="Wifi not working"; $contactName="Mark Richart"; $contactEmail="mrrichart@hotmail.com"; $cwStatus="New (email)"; $cwType="Connectivity"; $building="Burkhardt"; $room="201"; $cwSummary="Wifi Problems in " . $building . " " . $room; $ticketMessage="Reported problems: Not able to connect Slow when connected"; $companyurl = $connectwise . "/v4_6_release/apis/3.0/company/companies?conditions=name%20contains%20%27" . urlencode($cwCompany) . "%27"; $companydata = cURL($companyurl, $header_data); $boardurl = $connectwise . "/v4_6_release/apis/3.0/service/boards?conditions=name%20contains%20%27" . urlencode($cwBoard) . "%27"; $boarddata = cURL($boardurl, $header_data); $boardID = $boarddata[0]->id; $statusurl = $connectwise . "/v4_6_release/apis/3.0/service/boards/" . $boardID . "/statuses?conditions=name%20contains%20%27" . urlencode($cwStatus) . "%27"; $statusdata = cURL($statusurl, $header_data); $typeurl = $connectwise . "/v4_6_release/apis/3.0/service/boards/" . $boardID . "/types?conditions=name%20contains%20%27" . urlencode($cwType) . "%27"; $typedata = cURL($typeurl, $header_data); // $priorityurl = $connectwise . "/v4_6_release/apis/3.0/service/priorities?conditions=name%20contains%20%27" . urlencode("Priority 2 - Normal") . "%27"; // $prioritydata = cURL($priorityurl, $header_data); // $priorityID = $prioritydata[0]->id; // echo $priorityID; // die(); $postarray = array( "summary" => $cwSummary, "initialDescription" => $ticketMessage, "contactName" => $contactName, "contactEmailAddress" => $contactEmail, "company" => array( "id" => $companydata[0]->id ), "board" => array( "id" => $boarddata[0]->id ), "status" => array( "id" => $statusdata[0]->id ), "type" => array( "id" => $typedata[0]->id ), "priority" => array( "id" => 6 ) ); $dataTCmd = cURLPost( //Function for POST requests in cURL $connectwise . "/v4_6_release/apis/3.0/service/tickets", //URL $header_data2, //Header "POST", //Request type $postarray ); die(); //- //Ticket data section //- $dataTData = cURL($urlticketdata, $header_data); //Decode the JSON returned by the CW API. if($dataTData==NULL) { if ($timeoutfix == true) { cURLPost($_GET["response_url"], array("Content-Type: application/json"), "POST", array("parse" => "full", "response_type" => "ephemeral","text" => "Array not returned in line 195. Please check your connectwise URL variable in config.php and ensure it is accessible via the web at " . $urlticketdata)); } else { die("Array not returned in line 195. Please check your connectwise URL variable in config.php and ensure it is accessible via the web at " . $urlticketdata); //Return properly encoded arrays in JSON for Slack parsing. } die(); } //- //Priority command //- if($command=="priority") { //Check if the second string in the text array from the slash command is priority $priority = "0"; //Set priority = 0. $priorityname = ""; $priorityurl = $connectwise . "/v4_6_release/apis/3.0/service/priorities?conditions=name%20like%20%27" . $option3 . "%27"; $dataTCmd = cURL($priorityurl, $header_data); if(array_key_exists(0,$dataTCmd)) { $priority = $dataTCmd[0]->id; $priorityname = $dataTCmd[0]->name; } //Check what $option3 was set to, the third string in the text array from the slash command. if ($priority==0) { if ($timeoutfix == true) { cURLPost($_GET["response_url"], array("Content-Type: application/json"), "POST", array("parse" => "full", "response_type" => "ephemeral","text" => "Failed to get priority code: " . $option3)); } else { die("Failed to get priority code: " . $option3); //Return properly encoded arrays in JSON for Slack parsing. } die(); } $dataTCmd = cURLPost( //Function for POST requests in cURL $urlticketdata, //URL $header_data2, //Header "PATCH", //Request type array(array("op" => "replace", "path" => "/priority/id", "value" => $priority)) //POST Body ); $return =array( "parse" => "full", //Parse all text. "response_type" => "ephemeral", //Send the response to the user only "attachments"=>array(array( "fallback" => "Info on Ticket #" . $dataTData->id, //Fallback for notifications "title" => "Ticket Summary: " . $dataTData->summary, //Set bolded title text "pretext" => "Ticket #" . $dataTData->id . "'s priority has been set to " . $priorityname, //Set pretext "text" => "Click <" . $ticketurl . $dataTData -> id . "&companyName" . $companyname . "|here> to open the ticket.", //Set text to be returned "mrkdwn_in" => array( //Set markdown values "text", "pretext" ) )) ); if ($timeoutfix == true) { cURLPost($_GET["response_url"], array("Content-Type: application/json"), "POST", $return); } else { die(json_encode($return, JSON_PRETTY_PRINT)); //Return properly encoded arrays in JSON for Slack parsing. } die(); } //- //Ticket Status change command. //- if($command=="status") { $status = "0"; $statusname = ""; $statusurl = $dataTData->board->_info->board_href . "/statuses?conditions=name%20like%20%27" . $option3 . "%27"; $dataTCmd = cURL($statusurl, $header_data); if(array_key_exists(0,$dataTCmd)) { $status = $dataTCmd[0]->id; $statusname = $dataTCmd[0]->name; } if ($status == 0) { if ($timeoutfix == true) { cURLPost($_GET["response_url"], array("Content-Type: application/json"), "POST", array("parse" => "full", "response_type" => "ephemeral","text" => "Failed to get status code: " . $status)); } else { die("Failed to get status code: " . $status); //Return properly encoded arrays in JSON for Slack parsing. } die(); } $dataTCmd = cURLPost( $urlticketdata, $header_data2, "PATCH", array(array("op" => "replace", "path" => "/status/id", "value" => $status)) ); $return = array( "parse" => "full", "response_type" => "ephemeral", //Send the response to the user only "attachments" => array(array( "fallback" => "Info on Ticket #" . $dataTData->id, //Fallback for notifications "title" => "Ticket Summary: " . $dataTData->summary, "pretext" => "Ticket #" . $dataTData->id . "'s status has been set to " . $statusname, "text" => "Click <" . $ticketurl . $dataTData->id . "&companyName" . $companyname . "|here> to open the ticket.", "mrkdwn_in" => array( "text", "pretext" ) )) ); if ($timeoutfix == true) { cURLPost($_GET["response_url"], array("Content-Type: application/json"), "POST", $return); } else { die(json_encode($return, JSON_PRETTY_PRINT)); //Return properly encoded arrays in JSON for Slack parsing. } die(); } if($command=="scheduleme") { $cwuser = NULL; //Username mapping code if($usedatabase==1) { $mysql = mysqli_connect($dbhost, $dbusername, $dbpassword, $dbdatabase); //Connect MySQL if (!$mysql) //Check for errors { if ($timeoutfix == true) { cURLPost($_GET["response_url"], array("Content-Type: application/json"), "POST", array("parse" => "full", "response_type" => "ephemeral","text" => "Connection Error: " . mysqli_connect_error())); } else { die("Connection Error: " . mysqli_connect_error()); //Return properly encoded arrays in JSON for Slack parsing. } die(); } $val1 = mysqli_real_escape_string($mysql,$_GET["user_name"]); $sql = "SELECT * FROM `usermap` WHERE `slackuser`=\"" . $val1 . "\""; //SQL Query to select all ticket number entries $result = mysqli_query($mysql, $sql); //Run result $rowcount = mysqli_num_rows($result); if($rowcount > 1) //If there were too many rows matching query { die("Error: too many users somehow?"); //This should NEVER happen. } else if ($rowcount == 1) //If exactly 1 row is found. { $row = mysqli_fetch_assoc($result); //Row association. $cwuser = $row["cwname"]; //Return the connectwise name of the row found as the CW member name. } else //If no rows are found { if($usecwname==1) //If variable enabled { $cwuser = $_GET['user_name']; } } } else { if($usecwname==1) { $cwuser = $_GET['user_name']; } else { if ($timeoutfix == true) { cURLPost($_GET["response_url"], array("Content-Type: application/json"), "POST", array("parse" => "full", "response_type" => "ephemeral","text" => "Error: Name " . $_GET['user_name'] . " not found")); } else { die("Error: Name " . $_GET['user_name'] . " not found"); //Return properly encoded arrays in JSON for Slack parsing. } die(); } } unset($exploded[0]); unset($exploded[1]); $removal = implode(" ", $exploded); if($removal==NULL) { $datestart = gmdate("Y-m-d\TH:i:s\Z", strtotime("12:00AM")); $timingdate = explode("T", $datestart); $datestart = $timingdate[0] . "T00:00:00Z"; } else { $datestart = gmdate("Y-m-d\TH:i:s\Z", strtotime($removal)); $dateend = gmdate("Y-m-d\TH:i:s\Z", strtotime($removal. " +30 minutes")); } if(strpos($datestart, 'T06:00:00Z') !== false) { $timingdate = explode("T", $datestart); $datestart = $timingdate[0] . "T00:00:00Z"; } if(strpos($datestart, 'T00:00:00Z') !== false) { $dateend = $datestart; } $postarray = array("objectId" => $ticketnumber, "member" => array("identifier" => $cwuser), "type" => array("id" => 4), "dateStart" => $datestart, "dateEnd" => $dateend, "allowScheduleConflictsFlag" => true); $dataTCmd = cURLPost( $connectwise . "/v4_6_release/apis/3.0/schedule/entries", $header_data2, "POST", $postarray ); if($removal==NULL) { $timingdate = explode("T", $datestart); if ($timeoutfix == true) { cURLPost($_GET["response_url"], array("Content-Type: application/json"), "POST", array("parse" => "full", "response_type" => "ephemeral","text" => "You have been properly scheduled for ticket #" . $dataTCmd->objectId . " for $timingdate[0]","mrkdwn"=>true)); } else { die("You have been properly scheduled for ticket #" . $dataTCmd->objectId . " for $timingdate[0]"); //Return properly encoded arrays in JSON for Slack parsing. } die(); } else { if ($timeoutfix == true) { cURLPost($_GET["response_url"], array("Content-Type: application/json"), "POST", array("parse" => "full", "response_type" => "ephemeral","text" => "You have been properly scheduled for ticket #" . $dataTCmd->objectId . " at " . $removal,"mrkdwn"=>true)); } else { die("You have been properly scheduled for ticket #" . $dataTCmd->objectId . " at " . $removal); //Return properly encoded arrays in JSON for Slack parsing. } die(); } } if($command=="schedule") { $cwuser = NULL; if($option3 == NULL) { if ($timeoutfix == true) { cURLPost($_GET["response_url"], array("Content-Type: application/json"), "POST", array("parse" => "full", "response_type" => "ephemeral","text" => "No user specified.")); } else { die("No user specified."); //Return properly encoded arrays in JSON for Slack parsing. } die(); } $username = $option3; //Username mapping code if($usedatabase==1) { $mysql = mysqli_connect($dbhost, $dbusername, $dbpassword, $dbdatabase); //Connect MySQL if (!$mysql) //Check for errors { if ($timeoutfix == true) { cURLPost($_GET["response_url"], array("Content-Type: application/json"), "POST", array("parse" => "full", "response_type" => "ephemeral","text" => "Connection Error: " . mysqli_connect_error())); } else { die("Connection Error: " . mysqli_connect_error()); //Return properly encoded arrays in JSON for Slack parsing. } die(); } $val1 = mysqli_real_escape_string($mysql,$username); $sql = "SELECT * FROM `usermap` WHERE `slackuser`=\"" . $val1 . "\""; //SQL Query to select all ticket number entries $result = mysqli_query($mysql, $sql); //Run result $rowcount = mysqli_num_rows($result); if($rowcount > 1) //If there were too many rows matching query { die("Error: too many users somehow?"); //This should NEVER happen. } else if ($rowcount == 1) //If exactly 1 row is found. { $row = mysqli_fetch_assoc($result); //Row association. $cwuser = $row["cwname"]; //Return the connectwise name of the row found as the CW member name. } else //If no rows are found { if($usecwname==1) //If variable enabled { $cwuser = $username; } } } else { if($usecwname==1) { $cwuser = $username; } else { if ($timeoutfix == true) { cURLPost($_GET["response_url"], array("Content-Type: application/json"), "POST", array("parse" => "full", "response_type" => "ephemeral","text" => "Error: Name " . $username . " not found")); } else { die("Error: Name " . $username . " not found"); //Return properly encoded arrays in JSON for Slack parsing. } die(); } } unset($exploded[0]); unset($exploded[1]); unset($exploded[2]); $removal = implode(" ", $exploded); if($removal==NULL) { $datestart = gmdate("Y-m-d\TH:i:s\Z", strtotime("12:00AM")); $timingdate = explode("T", $datestart); $datestart = $timingdate[0] . "T00:00:00Z"; } else { $datestart = gmdate("Y-m-d\TH:i:s\Z", strtotime($removal)); $dateend = gmdate("Y-m-d\TH:i:s\Z", strtotime($removal. " +30 minutes")); } if(strpos($datestart, 'T06:00:00Z') !== false) { $timingdate = explode("T", $datestart); $datestart = $timingdate[0] . "T00:00:00Z"; } if(strpos($datestart, 'T00:00:00Z') !== false) { $dateend = $datestart; } $postarray = array("objectId" => $ticketnumber, "member" => array("identifier" => $cwuser), "type" => array("id" => 4), "dateStart" => $datestart, "dateEnd" => $dateend, "allowScheduleConflictsFlag" => true); $dataTCmd = cURLPost( $connectwise . "/v4_6_release/apis/3.0/schedule/entries", $header_data2, "POST", $postarray ); if($removal==NULL) { $timingdate = explode("T", $datestart); if ($timeoutfix == true) { cURLPost($_GET["response_url"], array("Content-Type: application/json"), "POST", array("parse" => "full", "response_type" => "ephemeral","text" => "$username has been properly scheduled for ticket #" . $dataTCmd->objectId . " for $timingdate[0]","mrkdwn"=>true)); } else { die("$username has been properly scheduled for ticket #" . $dataTCmd->objectId . " for $timingdate[0]"); //Return properly encoded arrays in JSON for Slack parsing. } die(); } else { if ($timeoutfix == true) { cURLPost($_GET["response_url"], array("Content-Type: application/json"), "POST", array("parse" => "full", "response_type" => "ephemeral","text" => "$username has been properly scheduled for ticket #" . $dataTCmd->objectId . " at " . $removal,"mrkdwn"=>true)); } else { die("$username has been properly scheduled for ticket #" . $dataTCmd->objectId . " at " . $removal); //Return properly encoded arrays in JSON for Slack parsing. } die(); } } if($posttext==1) //Block for curl to get latest note { $createdby = "Error"; //Create with error just in case. $notetext = "Error"; //Create with error just in case. $dataTNotes = cURL($noteurl, $header_data); // Get the JSON returned by the CW API for $noteurl. $dataTimeData = cURL($timeurl, $header_data); // Get the JSON returned by the CW API for $timeurl. if($command == "full" || $command == "notes" || $command == "all") { $dataTNotes2 = cURL($connectwise . "/v4_6_release/apis/3.0/service/tickets/" . $ticketnumber . "/notes?orderBy=id%20asc", $header_data); // Get the JSON returned by the CW API for ticket notes. } if(!array_key_exists(0, $dataTNotes)) { if(array_key_exists(0, $dataTimeData)) { $createdby = $dataTimeData[0]->enteredBy; //Set $createdby to the time entry creator. $text = $dataTimeData[0]->notes; //Set $text to the time entry text. $notedate = $dataTimeData[0]->dateEntered; $date2 = strtotime($notedate); $date2format = date('m-d-Y g:i:sa', $date2); $internalflag = $dataTimeData[0]->addToInternalAnalysisFlag; } else { $posttext=0; } } else if($dataTNotes[0]->text != NULL || $dataTimeData[0]->text != NULL) //Makes sure that if both text values == null, then there is no text to post. { if($dataTNotes[0]->text != NULL) { $createdby = $dataTNotes[0]->createdBy; //Set $createdby to the ticket note creator. $notetime = new DateTime($dataTNotes[0]->dateCreated); //Create new datetime object based on ticketnote note. $notedate = $dataTNotes[0]->dateCreated; $internalflag = $dataTNotes[0]->internalAnalysisFlag; $text = $dataTNotes[0]->text; //Set $text to the ticket text. if (array_key_exists(0, $dataTNotes) && array_key_exists(0, $dataTimeData) && $command != "initial" && $command != "first" && $command != "note") //Check if arrays exist properly. { $timetime = new DateTime($dataTimeData[0]->dateEntered); //Create new time object based on time entry note. if ($timetime > $notetime) //If the time entry is newer than latest ticket note. { $createdby = $dataTimeData[0]->enteredBy; //Set $createdby to the time entry creator. $text = $dataTimeData[0]->notes; //Set $text to the time entry text. $notedate = $dataTimeData[0]->dateEntered; $internalflag = $dataTimeData[0]->addToInternalAnalysisFlag; } } $date2 = strtotime($notedate); $date2format = date('m-d-Y g:i:sa', $date2); } else { $createdby = $dataTimeData[0]->enteredBy; //Set $createdby to the time entry creator. $text = $dataTimeData[0]->notes; //Set $text to the time entry text. $notedate = $dataTimeData[0]->dateEntered; $date2 = strtotime($notedate); $date2format = date('m-d-Y g:i:sa', $date2); $internalflag = $dataTimeData[0]->addToInternalAnalysisFlag; } } else { $posttext=0; } } //Scheduled resource block $resourceset = cURL($dataTData->_info->scheduleentries_href,$header_data); //Get URL and send that to curl function, retrieve response. if($resourceset == NULL) { $resourceline = false; } else { $latestres = end($resourceset); $latestsched = cURL($latestres->_info->schedule_href,$header_data); if($latestsched->dateStart==NULL) { $resourceline = false; } else { $scheddate = date("m-d-y",strtotime($latestsched->dateStart)); $schedstart = date("g:iA",strtotime($latestsched->dateStart)); $schedend = date("g:iA",strtotime($latestsched->dateEnd)); $resourceline = "\nNext: " . $latestsched->member->identifier . " at " . $scheddate . " " . $schedstart . "-" . $schedend; } } $date=strtotime($dataTData->dateEntered); //Convert date entered JSON result to time. $dateformat=date('m-d-Y g:i:sa',$date); //Convert previously converted time to a better time string. $return="Nothing!"; //Create return value and set to a basic message just in case. $contact="None"; //Set None for contact in case no contact exists for "Catch All" tickets. $resources="No resources"; //Just in case resources are null, have something to return. $hours="No time entered."; //Just in case time is null, have something to return. if($dataTData->actualHours != NULL) //If time is not NULL { $hours="Time: ". $dataTData->actualHours . " Hours"; //Set $hours to a formatted time line. } if($dataTData->resources != NULL) { $resources=$dataTData->resources; } if(!$dataTData->contact==NULL) { //Check if contact name exists in array. $contact = $dataTData->contact->name; //Set contact variable to contact name. } if($command == "initial" || $command == "first" || $command == "note") { if($posttext==0) { $return =array( "parse" => "full", "response_type" => "in_channel", "attachments"=>array(array( "fallback" => "Info on Ticket #" . $dataTData->id, //Fallback for notifications "title" => "<" . $ticketurl . $dataTData -> id . "&companyName=" . $companyname . "|#" . $dataTData->id . ">: " . $dataTData->summary, //Return clickable link to ticket with ticket summary. "pretext" => "Info on Ticket #" . $dataTData->id, //Return info string with ticket number. "text" => $dataTData->company->identifier . " / " . $contact . //Return "Company / Contact" string "\n" . $dateformat . " | " . $dataTData->status->name . //Return "Date Entered / Status" string "\n" . $resources . " | " . $hours . //Return assigned resources (!$resourceline ? "" : $resourceline), //Return next resource "mrkdwn_in" => array( "text", "pretext" ) )) ); } else { $return =array( "parse" => "full", "response_type" => "ephemeral", "attachments"=>array(array( "fallback" => "Info on Ticket #" . $dataTData->id, //Fallback for notifications "title" => "<" . $ticketurl . $dataTData -> id . "&companyName=" . $companyname . "|#" . $dataTData->id . ">: " . $dataTData->summary, //Return clickable link to ticket with ticket summary. "pretext" => "Info on Ticket #" . $dataTData->id, //Return info string with ticket number. "text" => $dataTData->company->identifier . " / " . $contact . //Return "Company / Contact" string "\n" . $dateformat . " | " . $dataTData->status->name . //Return "Date Entered / Status" string "\n" . $resources . " | " . $hours . //Return assigned resources (!$resourceline ? "" : $resourceline), //Return next resource "mrkdwn_in" => array( "text", "pretext" ) ), array( "pretext" => "Initial " . ($internalflag == "true" ? "Internal" : "External") . " ticket note (" . $date2format . ") from: " . $createdby, "text" => $text, "mrkdwn_in" => array( "text", "pretext", "title" ) )) ); } } else if($command == "full" || $command == "notes" || $command == "all") { if($posttext==0) { $return =array( "parse" => "full", "response_type" => "in_channel", "attachments"=>array(array( "fallback" => "Info on Ticket #" . $dataTData->id, //Fallback for notifications "title" => "<" . $ticketurl . $dataTData -> id . "&companyName=" . $companyname . "|#" . $dataTData->id . ">: " . $dataTData->summary, //Return clickable link to ticket with ticket summary. "pretext" => "Info on Ticket #" . $dataTData->id, //Return info string with ticket number. "text" => $dataTData->company->identifier . " / " . $contact . //Return "Company / Contact" string "\n" . $dateformat . " | " . $dataTData->status->name . //Return "Date Entered / Status" string "\n" . $resources . " | " . $hours . //Return assigned resources (!$resourceline ? "" : $resourceline), //Return next resource "mrkdwn_in" => array( "text", "pretext" ) )) ); } else { $date3=strtotime($dataTNotes2[0]->dateCreated); $date3format=date('m-d-Y g:i:sa',$date3); if(array_key_exists("internalAnalysisFlag", $dataTNotes2)) { $internalflag2 = $dataTNotes2[0]->internalAnalysisFlag; } else if(array_key_exists("addToInternalAnalysisFlag", $dataTNotes2)) { $internalflag2 = $dataTNotes2[0]->addToInternalAnalysisFlag; } else if(array_key_exists("internalFlag", $dataTNotes2)) { $internalflag2 = $dataTNotes2[0]->internalFlag; } else { $internalflag2 = ""; } $initialinfoarray = array( array( "fallback" => "Info on Ticket #" . $dataTData->id, //Fallback for notifications "title" => "<" . $ticketurl . $dataTData -> id . "&companyName=" . $companyname . "|#" . $dataTData->id . ">: " . $dataTData->summary, //Return clickable link to ticket with ticket summary. "pretext" => "Info on Ticket #" . $dataTData->id, //Return info string with ticket number. "text" => $dataTData->company->identifier . " / " . $contact . //Return "Company / Contact" string "\n" . $dateformat . " | " . $dataTData->status->name . //Return "Date Entered / Status" string "\n" . $resources . " | " . $hours . //Return assigned resources (!$resourceline ? "" : $resourceline), //Return next resource "mrkdwn_in" => array( "text", "pretext" ) )); $temparray = array(); if(array_key_exists(0, $dataTNotes)) { foreach ($dataTNotes as $singlenote) { $createdby = $singlenote->createdBy; //Set $createdby to the ticket note creator. $notetime = new DateTime($singlenote->dateCreated); //Create new datetime object based on ticketnote note. $notedate = $singlenote->dateCreated; $internalflag = $singlenote->internalAnalysisFlag; $text = $singlenote->text; //Set $text to the ticket text. $date2 = strtotime($notedate); $date2format = date('m-d-Y g:i:sa', $date2); $temparray[$date2] = array( "pretext" => ($internalflag == "true" ? "Internal" : "External") . " Note (" . $date2format . ") from: " . $createdby, "text" => $text, "mrkdwn_in" => array( "text", "pretext", "title" )); } } if(array_key_exists(0, $dataTimeData)) { foreach($dataTimeData as $singletime) { $createdby = $singletime->enteredBy; //Set $createdby to the time entry creator. $notedate = $singletime->dateEntered; $internalflag = $singletime->addToInternalAnalysisFlag; $text = $singletime->notes; //Set $text to the time entry text. $date2 = strtotime($notedate); $date2format = date('m-d-Y g:i:sa', $date2); $temparray[$date2] = array( "pretext" => ($internalflag == "true" ? "Internal" : "External") . " Time Entry (" . $date2format . ") from: " . $createdby, "text" => $text, "mrkdwn_in" => array( "text", "pretext", "title" )); } } ksort($temparray); $notesandtimes = array_merge($initialinfoarray, $temparray); $return =array( "parse" => "full", "response_type" => "ephemeral", "attachments"=>$notesandtimes ); } } else //If no command is set, or if it's just random gibberish after ticket number. { if($posttext==0) { $return =array( "parse" => "full", "response_type" => "in_channel", "attachments"=>array(array( "fallback" => "Info on Ticket #" . $dataTData->id, //Fallback for notifications "title" => "<" . $ticketurl . $dataTData -> id . "&companyName=" . $companyname . "|#" . $dataTData->id . ">: " . $dataTData->summary, //Return clickable link to ticket with ticket summary. "pretext" => "Info on Ticket #" . $dataTData->id, //Return info string with ticket number. "text" => $dataTData->company->identifier . " / " . $contact . //Return "Company / Contact" string "\n" . $dateformat . " | " . $dataTData->status->name . //Return "Date Entered / Status" string "\n" . $resources . " | " . $hours . //Return assigned resources (!$resourceline ? "" : $resourceline), //Return next resource "mrkdwn_in" => array( "text", "pretext" ) )) ); } else { $return =array( "parse" => "full", "response_type" => "in_channel", "attachments"=>array(array( "fallback" => "Info on Ticket #" . $dataTData->id, //Fallback for notifications "title" => "<" . $ticketurl . $dataTData -> id . "&companyName=" . $companyname . "|#" . $dataTData->id . ">: " . $dataTData->summary, //Return clickable link to ticket with ticket summary. "pretext" => "Info on Ticket #" . $dataTData->id, //Return info string with ticket number. "text" => $dataTData->company->identifier . " / " . $contact . //Return "Company / Contact" string "\n" . $dateformat . " | " . $dataTData->status->name . //Return "Date Entered / Status" string "\n" . $resources . " | " . $hours . //Return assigned resources (!$resourceline ? "" : $resourceline), //Return next resource "mrkdwn_in" => array( "text", "pretext" ) ), array( "pretext" => "Latest " . ($internalflag == "true" ? "Internal" : "External") . " Note (" . $date2format . ") from: " . $createdby, "text" => $text, "mrkdwn_in" => array( "text", "pretext", "title" ) )) ); } } if ($timeoutfix == true) { cURLPost($_GET["response_url"], array("Content-Type: application/json"), "POST", $return); } else { die(json_encode($return, JSON_PRETTY_PRINT)); //Return properly encoded arrays in JSON for Slack parsing. } die(); ?>