Skip to content

Instantly share code, notes, and snippets.

/Ticket.php Secret

Created July 9, 2013 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e6b84e3ce6d4b9ca4bbf to your computer and use it in GitHub Desktop.
Save anonymous/e6b84e3ce6d4b9ca4bbf to your computer and use it in GitHub Desktop.
<?php
// Declare common variables
$dbhost = "localhost";
$dbuser = "xxxxxxxxx";
$dbpassword = "xxxxxxx";
$dbdatabase = "xxxxxx";
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
define('SYS_NAME', "xxxxxxxxx");
define('SYS_EMAIL', "xxxxxxxx@xxxxxxx.com");
function checkLoginCredentials($username, $password) {
//set POST variables
$url = 'https://xxxxxx.net/_external_auth_connector.php';
$fields = array(
'username' => urlencode($username),
'password' => urlencode($password),
'secret' => urlencode("xxxxxxxxxxxxxxx")
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the data instead of outputting it.
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
return $result;
}
function getTicketDetails($ticketID, $fields) {
$fields = implode(", ",$fields);
$SQL_Select = "SELECT $fields from `tickets` WHERE `ticket_id` = '".$ticketID."' LIMIT 1";
$result = mysql_fetch_assoc(mysql_query($SQL_Select));
//$result = $SQL_Select;
return $result;
}
function getAdminDetails($adminID, $fields) {
$fields = implode(", ",$fields);
$SQL_Select = "SELECT name, email, sms_email from `admins` WHERE `admin_id` = '".$adminID."' LIMIT 1";
$result = mysql_fetch_assoc(mysql_query($SQL_Select));
//$result = $SQL_Select;
return $result;
}
function sendEmail($from_email, $from_name, $to_email, $to_name, $subject, $message, $priority) {
//$transport = Swift_SmtpTransport::newInstance('localhost', 25);
$transport = Swift_MailTransport::newInstance(); // Create the transport; use php mail
$mailer = Swift_Mailer::newInstance($transport); // Create the Mailer using your created Transport
$message = Swift_Message::newInstance() // Create the message
->setPriority($priority) // Give the message a priority, 1 through 5, 1 being the highest.
->setSubject($subject) // Give the message a subject
->setFrom(array($from_email => $from_name)) // Set the From address with an associative array
->setTo(array($to_email => $to_name)) // Set the To addresses with an associative array
->setReadReceiptTo(SYS_EMAIL) // Send read receipts to Support
->setBody('Here is the message itself') // Give it a body
->addPart('<q>Here is the message itself</q>', 'text/html') // And optionally an alternative body
;
$result = $mailer->send($message); // Send the message
return $to_email;
}
?>
<?php
/*
Title: Ticket
Tagline: Handle Ticket related actions
Tags: basic
Requires: PHP >= 5.3
*/
require_once('../../Swift/lib/swift_required.php');
require_once '../includes/common.php';
require_once '../includes/language.php';
require_once '../../Restler/vendor/restler.php';
use Luracast\Restler\Restler;
$r = new Restler();
$r->addAPIClass('Ticket',''); // Live code
$r->addAPIClass('Remind');
$r->setSupportedFormats('JsonFormat', 'UploadFormat'); // UploadFormat is required for multipart/form-data to work correctly
$r->handle();
<?php
$Exception = array ("400" => "Check the API Documentation for the correct syntax.");
define('LANG_REMIND_SUBJ', "Reminder: Status Update Request");
?>
<?php
class Remind {
/*
Paramters:
ticketID - int
*/
function post($request_data=NULL) {
//$request_data will never be null
//instead it can be an empty array
if ( (empty($request_data['username'])) || (empty($request_data['password'])) ) {
throw new RestException(400, $GLOBALS["Exception"]["400"]);
}
// Check the user's login credentials; a result of "1" denotes sucessful authentication
if (checkLoginCredentials($request_data['username'], $request_data['password']) == "1") {
// Get the admin_id on the referenced ticket
$fields = array("admin_id");
$a = getTicketDetails($request_data['ticketID'], $fields);
// Get the admin's name, email, and sms_email
$fields = array("name","email","sms_email");
$b = getAdminDetails($a['admin_id'], $fields);
$c = sendEmail(SYS_EMAIL, SYS_NAME, $b['email'], $b['name'], LANG_REMIND_SUBJ, "message goes here", 1);
return array(
'request_success' => true,
'auth_success' => true,
'data' => $c
); //end return
} //end if
else { throw new RestException(401, $GLOBALS["Exception"]["401"]); }
} //end post function
} //end Remind class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment