<?php include_once '../lib/session.inc.php'; include_once '../lib/user.inc.php'; $userId = requireLogin(); $mode = $_POST['mode']; if ($mode == 'load') { print json_encode(array('success' => TRUE, 'data' => getAutoReply($userId))); } else { if ($mode == 'save') { $active = trim($_POST['active']); $begins = trim($_POST['begins']); $ends = trim($_POST['ends']); $message = trim($_POST['message']); if ($active == 'on') { $active = TRUE; } else { $active = FALSE; } if ($active && !$begins) { print json_encode(array('success' => FALSE, 'errors' => array('begins' => 'This field is required if active is enabled'))); exit; } if (saveAutoReply($userId, $active, $begins, $ends, $message)) { print json_encode(array('success' => TRUE)); } else { print json_encode(array('success' => FALSE, 'errors' => array('message' => 'Error saving auto reply'))); } } }
//include the classes for recording outbound messages to database require_once "classes/connection.php"; //include format checking function and notification module require_once "classes/formatting.php"; //pull in the list of existing keywords from keywords table $mysqli = openConnection(); $keyword_array = getAllKeywordArray($mysqli); //we set the default assignment of msgs to admin account $assoc_user = "******"; //we match the inbound msg to the appropriate user by keyword foreach ($keyword_array as $keyword => $user_name) { //we check for each $keyword if the $msg contains it if (containsKeyword($msg, $keyword)) { $assoc_user = $user_name; //we send the autoreply if it is not null $autoreply = getAutoReply($mysqli, $keyword); if (!is_null($autoreply['text'])) { //we setup the necessary fields for the API call $api_fields = array('from' => '6590249973', 'to' => array($sender), 'text' => $autoreply['text']); $api_result = APISendSMS($api_fields); $json_result = json_decode($api_result, true); //we log the SMS as an outbound message in the database $outbound_data = array('api_ref_id' => $json_result['bulkId'], 'title' => 'Auto-Reply [' . $keyword . ']', 'from' => '6590249973', 'to' => implode(', ', $api_fields['to']), 'text' => $autoreply['text'], 'status' => $json_result['messages'][0]['status']['groupName'], 'credits_used' => $autoreply['num_msg']); //enter details of outbound msg into outbound table and deduct appropriate user credits uploadOutboundInfo($mysqli, $outbound_data); subtractUserCredits($mysqli, $outbound_data['credits_used']); } break; } } //we upload the inbound msg